| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797 |
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE mapper
- PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
- "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.zd.chemical.mapper.ActHxpapplyMapper">
- <resultMap type="com.zd.chemical.domain.ActHxpapply" id="ActHxpapplyResult">
- <result property="id" column="id" />
- <result property="applyNum" column="apply_num" />
- <result property="applyReason" column="apply_reason" />
- <result property="subId" column="sub_id" />
- <result property="applyStatus" column="apply_status" />
- <result property="userId" column="user_id" />
- <result property="createBy" column="create_by" />
- <result property="createTime" column="create_time" />
- <result property="updateBy" column="update_by" />
- <result property="updateTime" column="update_time" />
- <result property="remark" column="remark" />
- </resultMap>
- <sql id="selectActHxpapplyVo">
- select id, apply_num, apply_reason, sub_id, apply_status, user_id, create_by, create_time, update_by, update_time, remark from act_hxpapply
- </sql>
- <sql id="selectActHxpapplyListVo">
- select t.id, t.apply_num, t.apply_reason, t.sub_id, t.apply_status, t.user_id, t.create_by, t.create_time, t.update_by, t.update_time, t.remark from act_hxpapply as t
- </sql>
- <select id="selectActHxpapplyList" parameterType="com.zd.chemical.domain.vo.ActHxpapplySearch" resultType="com.zd.chemical.domain.vo.ActHxpapplyListVo">
- <!--SELECT xx.applyNum,xx.subscriber,xx.subName,xx.chemicalNames,xx.createTime,xx.overTime,xx.approvalContent,xx.approvalStatus,-->
- <!--CASE WHEN xx.approvalStatus = 0 THEN-->
- <!--(SELECT GROUP_CONCAT(ur.user_id,';',ur.nick_name) FROM sys_user ur WHERE FIND_IN_SET(ur.user_id,xx.currentApprover))-->
- <!--ELSE ''-->
- <!--END currentApprover,-->
- <!--CASE WHEN xx.approvalStatus = 3 THEN ''-->
- <!--ELSE (SELECT GROUP_CONCAT(ur.user_id,';',ur.nick_name) FROM sys_user ur WHERE FIND_IN_SET(ur.user_id,xx.historyApprover))-->
- <!--END historyApprover,-->
- <!--xx.currentApprover currentApproverIds-->
- <!--FROM (-->
- <!--SELECT ah.`apply_num` applyNum,-->
- <!--su.nick_name subscriber,-->
- <!--st.`name` subName,-->
- <!--GROUP_CONCAT(hd.chemical_name) chemicalNames,-->
- <!--ah.`create_time` createTime,-->
- <!--ak.`over_time` overTime,-->
- <!--CASE WHEN ak.approval_status=0 THEN '审批中'-->
- <!--ELSE CASE WHEN ak.approval_status=1 THEN '已通过'-->
- <!--ELSE CASE WHEN ak.approval_status=2 THEN '已拒绝'-->
- <!--ELSE '已撤销'-->
- <!--END-->
- <!--END-->
- <!--END approvalContent,-->
- <!--ak.approval_status approvalStatus,-->
- <!--(SELECT an.apply_user_ids FROM act_applytask apk,act_applytask_node an WHERE an.applytask_id = apk.id AND apk.id = ak.id AND an.node_status = 0-->
- <!--AND apk.approval_status=0 ORDER BY an.node_order ASC LIMIT 1) currentApprover,-->
- <!--(SELECT an.apply_user_ids FROM act_applytask apk,act_applytask_node an WHERE an.applytask_id = apk.id AND apk.id = ak.id AND (an.node_status = 1 OR an.node_status = 2)-->
- <!--AND (apk.approval_status=0 OR apk.approval_status=1) ORDER BY an.node_order DESC LIMIT 1) historyApprover-->
- <!--FROM act_hxpapply ah LEFT JOIN sys_user su ON su.user_id = ah.`user_id`-->
- <!--LEFT JOIN lab_subject st ON st.id = ah.`sub_id`-->
- <!--LEFT JOIN act_hxpapply_detail hd ON hd.hxpapply_id = ah.id-->
- <!--LEFT JOIN act_applytask ak ON ak.`task_id` = ah.`id`-->
- <!--<where>-->
- <!--ah.apply_status in(1,3)-->
- <!--<if test="searchValue != null ">-->
- <!--and (-->
- <!--ah.apply_num like concat('%', #{searchValue}, '%') or-->
- <!--su.nick_name like concat('%', #{searchValue}, '%') or-->
- <!--hd.chemical_name like concat('%', #{searchValue}, '%') or-->
- <!--st.name like concat('%', #{searchValue}, '%')-->
- <!--)-->
- <!--</if>-->
- <!--<if test="approvalStatus != null ">-->
- <!--and ak.approval_status = #{approvalStatus}-->
- <!--</if>-->
- <!--<if test="beginCreateTime != null and beginCreateTime != ''"><!– 申请开始时间 –>-->
- <!--AND date_format(ak.create_time,'%y%m%d') >= date_format(#{beginCreateTime},'%y%m%d')-->
- <!--</if>-->
- <!--<if test="endCreateTime != null and endCreateTime != ''"><!– 申请结束时间 –>-->
- <!--AND date_format(ak.create_time,'%y%m%d') <= date_format(#{endCreateTime},'%y%m%d')-->
- <!--</if>-->
- <!--<if test="beginOverTime != null and beginOverTime != ''"><!– 完成开始时间 –>-->
- <!--AND date_format(ak.over_time,'%y%m%d') >= date_format(#{beginOverTime},'%y%m%d')-->
- <!--</if>-->
- <!--<if test="endOverTime != null and endOverTime != ''"><!– 完成结束时间 –>-->
- <!--AND date_format(ak.over_time,'%y%m%d') <= date_format(#{endOverTime},'%y%m%d')-->
- <!--</if>-->
- <!--</where>-->
- <!--GROUP BY ah.`id`-->
- <!--)xx ORDER BY xx.createTime DESC-->
- SELECT xx1.* FROM (
- SELECT xx.id,xx.applyNum,xx.subscriber,xx.subName,xx.chemicalNames,xx.createTime,xx.overTime,xx.approvalContent,xx.approvalStatus,
- CASE WHEN xx.approvalStatus = 0 THEN
- (SELECT GROUP_CONCAT(ur.user_id,';',ur.nick_name) FROM sys_user ur
- WHERE ur.`user_id`
- IN (
- SELECT
- SUBSTRING_INDEX(SUBSTRING_INDEX(xx.currentApprover,',', b.help_topic_id + 1), ',', -1) result
- FROM
- mysql.help_topic b
- WHERE
- b.help_topic_id < (LENGTH(xx.currentApprover) - LENGTH(REPLACE(xx.currentApprover, ',', '')) + 1)
- )
- )
- ELSE ''
- END currentApprover,
- CASE WHEN xx.approvalStatus = 3 THEN ''
- ELSE (SELECT GROUP_CONCAT(ur.user_id,';',ur.nick_name) FROM sys_user ur
- WHERE ur.`user_id`
- IN (
- SELECT
- SUBSTRING_INDEX(SUBSTRING_INDEX(xx.historyApprover,',', b.help_topic_id + 1), ',', -1) result
- FROM
- mysql.help_topic b
- WHERE
- b.help_topic_id < (LENGTH(xx.historyApprover) - LENGTH(REPLACE(xx.historyApprover, ',', '')) + 1)
- )
- )
- END historyApprover,
- xx.currentApprover currentApproverIds,xx.userId
- FROM (
- SELECT ah.id,ah.`apply_num` applyNum,
- su.nick_name subscriber,
- st.`name` subName,
- GROUP_CONCAT(CONCAT(hd.chemical_name,'-申购量:' ,hd.apply_num ,'g') ORDER BY hd.chemical_name DESC,hd.apply_num DESC SEPARATOR '; ') chemicalNames,
- ah.`create_time` createTime,
- ak.`over_time` overTime,
- CASE WHEN ak.approval_status=0 THEN '审批中'
- ELSE CASE WHEN ak.approval_status=1 THEN '已通过'
- ELSE CASE WHEN ak.approval_status=2 THEN '已拒绝'
- ELSE '已撤销'
- END
- END
- END approvalContent,
- ak.approval_status approvalStatus,
- (SELECT an.apply_user_ids FROM act_applytask apk,act_applytask_node an WHERE an.applytask_id = apk.id AND apk.id = ak.id AND an.node_status = 0
- AND apk.approval_status=0 ORDER BY an.node_order ASC LIMIT 1) currentApprover,
- (SELECT an.apply_user_ids FROM act_applytask apk,act_applytask_node an WHERE an.applytask_id = apk.id AND apk.id = ak.id AND (an.node_status = 1 OR an.node_status = 2)
- AND (apk.approval_status=0 OR apk.approval_status=1) ORDER BY an.node_order DESC LIMIT 1) historyApprover,
- ah.user_id userId
- FROM act_hxpapply ah LEFT JOIN sys_user su ON su.user_id = ah.`user_id`
- LEFT JOIN lab_subject st ON st.id = ah.`sub_id`
- LEFT JOIN act_hxpapply_detail hd ON hd.hxpapply_id = ah.id
- LEFT JOIN act_applytask ak ON ak.`task_id` = ah.`id`
- <where>
- ah.apply_status in(1,3)
- <if test="ids != null">
- and ah.id in
- <foreach item="id" collection="ids" open="(" separator="," close=")">
- #{id}
- </foreach>
- </if>
- <if test="searchValue != null ">
- and (
- ah.apply_num like concat('%', #{searchValue}, '%') or
- su.nick_name like concat('%', #{searchValue}, '%') or
- hd.chemical_name like concat('%', #{searchValue}, '%') or
- st.name like concat('%', #{searchValue}, '%')
- )
- </if>
- <if test="approvalStatus != null ">
- and ak.approval_status = #{approvalStatus}
- </if>
- <if test="beginCreateTime != null and beginCreateTime != ''"><!-- 申请开始时间 -->
- AND date_format(ak.create_time,'%y%m%d') >= date_format(#{beginCreateTime},'%y%m%d')
- </if>
- <if test="endCreateTime != null and endCreateTime != ''"><!-- 申请结束时间 -->
- AND date_format(ak.create_time,'%y%m%d') <= date_format(#{endCreateTime},'%y%m%d')
- </if>
- <if test="beginOverTime != null and beginOverTime != ''"><!-- 完成开始时间 -->
- AND date_format(ak.over_time,'%y%m%d') >= date_format(#{beginOverTime},'%y%m%d')
- </if>
- <if test="endOverTime != null and endOverTime != ''"><!-- 完成结束时间 -->
- AND date_format(ak.over_time,'%y%m%d') <= date_format(#{endOverTime},'%y%m%d')
- </if>
- <if test="userId != null and userId != ''"><!-- 创建人id -->
- and ah.user_id = #{userId}
- </if>
- <!-- 数据范围过滤 -->
- ${params.dataScope}
- </where>
- GROUP BY ah.`id`
- )xx WHERE FIND_IN_SET(#{loginUserId},xx.currentApprover) ORDER BY xx.createTime DESC
- )xx1
- UNION
- SELECT xx1.* FROM (
- SELECT xx.id,xx.applyNum,xx.subscriber,xx.subName,xx.chemicalNames,xx.createTime,xx.overTime,xx.approvalContent,xx.approvalStatus,
- CASE WHEN xx.approvalStatus = 0 THEN
- (SELECT GROUP_CONCAT(ur.user_id,';',ur.nick_name) FROM sys_user ur
- WHERE ur.`user_id`
- IN (
- SELECT
- SUBSTRING_INDEX(SUBSTRING_INDEX(xx.currentApprover,',', b.help_topic_id + 1), ',', -1) result
- FROM
- mysql.help_topic b
- WHERE
- b.help_topic_id < (LENGTH(xx.currentApprover) - LENGTH(REPLACE(xx.currentApprover, ',', '')) + 1)
- )
- )
- ELSE ''
- END currentApprover,
- CASE WHEN xx.approvalStatus = 3 THEN ''
- ELSE (SELECT GROUP_CONCAT(ur.user_id,';',ur.nick_name) FROM sys_user ur
- WHERE ur.`user_id`
- IN (
- SELECT
- SUBSTRING_INDEX(SUBSTRING_INDEX(xx.historyApprover,',', b.help_topic_id + 1), ',', -1) result
- FROM
- mysql.help_topic b
- WHERE
- b.help_topic_id < (LENGTH(xx.historyApprover) - LENGTH(REPLACE(xx.historyApprover, ',', '')) + 1)
- )
- )
- END historyApprover,
- xx.currentApprover currentApproverIds,xx.userId
- FROM (
- SELECT ah.id,ah.`apply_num` applyNum,
- su.nick_name subscriber,
- st.`name` subName,
- GROUP_CONCAT(CONCAT(hd.chemical_name,'-申购量:' ,hd.apply_num ,'g') ORDER BY hd.chemical_name DESC,hd.apply_num DESC SEPARATOR '; ') chemicalNames,
- ah.`create_time` createTime,
- ak.`over_time` overTime,
- CASE WHEN ak.approval_status=0 THEN '审批中'
- ELSE CASE WHEN ak.approval_status=1 THEN '已通过'
- ELSE CASE WHEN ak.approval_status=2 THEN '已拒绝'
- ELSE '已撤销'
- END
- END
- END approvalContent,
- ak.approval_status approvalStatus,
- (SELECT an.apply_user_ids FROM act_applytask apk,act_applytask_node an WHERE an.applytask_id = apk.id AND apk.id = ak.id AND an.node_status = 0
- AND apk.approval_status=0 ORDER BY an.node_order ASC LIMIT 1) currentApprover,
- (SELECT an.apply_user_ids FROM act_applytask apk,act_applytask_node an WHERE an.applytask_id = apk.id AND apk.id = ak.id AND (an.node_status = 1 OR an.node_status = 2)
- AND (apk.approval_status=0 OR apk.approval_status=1) ORDER BY an.node_order DESC LIMIT 1) historyApprover,
- ah.user_id userId
- FROM act_hxpapply ah LEFT JOIN sys_user su ON su.user_id = ah.`user_id`
- LEFT JOIN lab_subject st ON st.id = ah.`sub_id`
- LEFT JOIN act_hxpapply_detail hd ON hd.hxpapply_id = ah.id
- LEFT JOIN act_applytask ak ON ak.`task_id` = ah.`id`
- <where>
- ah.apply_status in(1,3)
- <if test="ids != null">
- and ah.id in
- <foreach item="id" collection="ids" open="(" separator="," close=")">
- #{id}
- </foreach>
- </if>
- <if test="searchValue != null ">
- and (
- ah.apply_num like concat('%', #{searchValue}, '%') or
- su.nick_name like concat('%', #{searchValue}, '%') or
- hd.chemical_name like concat('%', #{searchValue}, '%') or
- st.name like concat('%', #{searchValue}, '%')
- )
- </if>
- <if test="approvalStatus != null ">
- and ak.approval_status = #{approvalStatus}
- </if>
- <if test="beginCreateTime != null and beginCreateTime != ''"><!-- 申请开始时间 -->
- AND date_format(ak.create_time,'%y%m%d') >= date_format(#{beginCreateTime},'%y%m%d')
- </if>
- <if test="endCreateTime != null and endCreateTime != ''"><!-- 申请结束时间 -->
- AND date_format(ak.create_time,'%y%m%d') <= date_format(#{endCreateTime},'%y%m%d')
- </if>
- <if test="beginOverTime != null and beginOverTime != ''"><!-- 完成开始时间 -->
- AND date_format(ak.over_time,'%y%m%d') >= date_format(#{beginOverTime},'%y%m%d')
- </if>
- <if test="endOverTime != null and endOverTime != ''"><!-- 完成结束时间 -->
- AND date_format(ak.over_time,'%y%m%d') <= date_format(#{endOverTime},'%y%m%d')
- </if>
- <if test="userId != null and userId != ''"><!-- 创建人id -->
- and ah.user_id = #{userId}
- </if>
- <!-- 数据范围过滤 -->
- ${params.dataScope}
- </where>
- GROUP BY ah.`id`
- )xx ORDER BY xx.createTime DESC
- )xx1
- </select>
- <select id="draftsList" parameterType="com.zd.chemical.domain.vo.ActHxpapplySearch" resultType="com.zd.chemical.domain.vo.ActHxpapplyDraftsListVo">
- SELECT xx.id,xx.applyNum,xx.subscriber,xx.subName,xx.chemicalNames,xx.createTime,xx.overTime,xx.approvalContent,xx.approvalStatus,
- CASE WHEN xx.approvalStatus = 0 THEN
- (SELECT GROUP_CONCAT(ur.user_id,';',ur.nick_name) FROM sys_user ur WHERE FIND_IN_SET(ur.user_id,xx.currentApprover))
- ELSE ''
- END currentApprover,
- CASE WHEN xx.approvalStatus = 3 THEN ''
- ELSE (SELECT GROUP_CONCAT(ur.user_id,';',ur.nick_name) FROM sys_user ur WHERE FIND_IN_SET(ur.user_id,xx.historyApprover))
- END historyApprover,
- xx.currentApprover currentApproverIds
- FROM (
- SELECT ah.id,ah.`apply_num` applyNum,
- su.nick_name subscriber,
- st.`name` subName,
- GROUP_CONCAT(hd.chemical_name,'-申购量:',hd.apply_num,'g' SEPARATOR '; ') chemicalNames,
- ah.`create_time` createTime,
- ak.`over_time` overTime,
- CASE WHEN ak.approval_status=0 THEN '审批中'
- ELSE CASE WHEN ak.approval_status=1 THEN '已通过'
- ELSE CASE WHEN ak.approval_status=2 THEN '已拒绝'
- ELSE '已撤销'
- END
- END
- END approvalContent,
- ak.approval_status approvalStatus,
- (SELECT an.apply_user_ids FROM act_applytask apk,act_applytask_node an WHERE an.applytask_id = apk.id AND apk.id = ak.id AND an.node_status = 0
- AND apk.approval_status=0 ORDER BY an.node_order ASC LIMIT 1) currentApprover,
- (SELECT an.apply_user_ids FROM act_applytask apk,act_applytask_node an WHERE an.applytask_id = apk.id AND apk.id = ak.id AND (an.node_status = 1 OR an.node_status = 2)
- AND (apk.approval_status=0 OR apk.approval_status=1) ORDER BY an.node_order DESC LIMIT 1) historyApprover
- FROM act_hxpapply ah LEFT JOIN sys_user su ON su.user_id = ah.`user_id`
- LEFT JOIN lab_subject st ON st.id = ah.`sub_id`
- LEFT JOIN act_hxpapply_detail hd ON hd.hxpapply_id = ah.id
- LEFT JOIN act_applytask ak ON ak.`task_id` = ah.`id`
- <where>
- ah.apply_status =2
- <if test="searchValue != null ">
- and (
- ah.apply_num like concat('%', #{searchValue}, '%') or
- hd.chemical_name like concat('%', #{searchValue}, '%') or
- st.name like concat('%', #{searchValue}, '%')
- )
- </if>
- <if test="approvalStatus != null ">
- and ak.approval_status = #{approvalStatus}
- </if>
- <if test="beginCreateTime != null and beginCreateTime != ''"><!-- 申请开始时间 -->
- AND date_format(ah.create_time,'%y%m%d') >= date_format(#{beginCreateTime},'%y%m%d')
- </if>
- <if test="endCreateTime != null and endCreateTime != ''"><!-- 申请结束时间 -->
- AND date_format(ah.create_time,'%y%m%d') <= date_format(#{endCreateTime},'%y%m%d')
- </if>
- <if test="beginOverTime != null and beginOverTime != ''"><!-- 完成开始时间 -->
- AND date_format(ah.over_time,'%y%m%d') >= date_format(#{beginOverTime},'%y%m%d')
- </if>
- <if test="endOverTime != null and endOverTime != ''"><!-- 完成结束时间 -->
- AND date_format(ah.over_time,'%y%m%d') <= date_format(#{endOverTime},'%y%m%d')
- </if>
- <if test="userId != null and userId != ''"><!-- 创建人id -->
- and ah.user_id = #{userId}
- </if>
- </where>
- GROUP BY ah.`id`
- )xx ORDER BY xx.createTime DESC
- </select>
- <select id="getListByIds" resultMap="ActHxpapplyResult">
- <include refid="selectActHxpapplyVo"/>
- <where>
- id in
- <foreach item="id" collection="list" open="(" separator="," close=")">
- #{id}
- </foreach>
- </where>
- </select>
- <select id="selectActHxpapplyById" resultType="com.zd.chemical.domain.vo.ActHxpapplyInfoVo">
- select a.id, a.apply_num, a.apply_reason, a.sub_id, a.apply_status, a.user_id, a.create_by, a.create_time, a.update_by
- , a.update_time, a.remark,
- (select ur.nick_name from sys_user ur where ur.user_id = a.user_id) applyUserName,
- st.name subName,st.dept_id deptId
- from act_hxpapply a left join lab_subject st on st.id = a.sub_id
- where a.id = #{id}
- </select>
- <select id="getRestStock" resultType="java.util.Map">
- SELECT x1.chemical_id chemicalId,CASE WHEN CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.applyNum,0)),'g')>0
- THEN CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.applyNum,0)),'g') ELSE CONCAT(0,'g') END restStock FROM (
- SELECT hd.`chemical_id`,IFNULL(SUM(hd.`apply_num`),0) applyNum FROM act_hxpapply ah LEFT JOIN act_hxpapply_detail hd ON ah.`id` = hd.`hxpapply_id`
- LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
- LEFT JOIN lab_subject st ON ah.sub_id = st.id
- <where>
- ak.`approval_status`=1 AND hd.`tick_status`=1
- <if test="deptId != null ">
- AND st.dept_id = #{deptId}
- </if>
- <if test="subId != null ">
- AND ah.sub_id = #{subId}
- </if>
- <if test="chemicalId != null ">
- AND hd.`chemical_id` = #{chemicalId}
- </if>
- <if test="cabinetId != null ">
- AND hd.`cabinet_id` = #{cabinetId}
- </if>
- <if test="applyUserId != null ">
- AND ah.`user_id` = #{applyUserId}
- </if>
- </where>
- GROUP BY hd.`chemical_id`
- )x1 LEFT JOIN
- (
- SELECT hd.`chemical_id`,SUM(IFNULL(cjc.`chemical_amount`,0)-IFNULL(cjc.`tare`,0)) applyNum FROM act_hxpapply ah LEFT JOIN act_hxpapply_detail hd ON ah.`id` = hd.`hxpapply_id`
- LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
- LEFT JOIN lab_subject st ON ah.sub_id = st.id
- inner join hxp_chemical_join_cabinet cjc on hd.`cabinet_id` = cjc.`cabinet_id` and hd.`chemical_id` = cjc.`chemical_id`
- <where>
- ak.`approval_status`=1 AND hd.`tick_status`=1
- <if test="deptId != null ">
- AND st.dept_id = #{deptId}
- </if>
- <if test="subId != null ">
- AND ah.sub_id = #{subId}
- </if>
- <if test="chemicalId != null ">
- AND hd.`chemical_id` = #{chemicalId}
- </if>
- <if test="cabinetId != null ">
- AND hd.`cabinet_id` = #{cabinetId}
- </if>
- <if test="applyUserId != null ">
- AND ah.`user_id` = #{applyUserId}
- </if>
- </where>
- GROUP BY hd.`chemical_id`
- )x2 ON x1.chemical_id = x2.chemical_id
- <!-- SELECT x1.chemical_id chemicalId,CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0)),'g') restStock FROM (
- SELECT hd.`chemical_id`,IFNULL(SUM(hd.`apply_num`),0) applyNum FROM act_hxpapply ah LEFT JOIN act_hxpapply_detail hd ON ah.`id` = hd.`hxpapply_id`
- LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
- LEFT JOIN lab_subject st ON ah.sub_id = st.id
- <where>
- ak.`approval_status`=1 AND hd.`tick_status`=1
- <if test="deptId != null ">
- and st.dept_id = #{deptId}
- </if>
- <if test="subId != null ">
- and ah.sub_id = #{subId}
- </if>
- <if test="chemicalId != null ">
- and hd.`chemical_id` = #{chemicalId}
- </if>
- <if test="cabinetId != null ">
- and hd.`cabinet_id` = #{cabinetId}
- </if>
- </where>
- GROUP BY hd.`chemical_id`
- )x1 LEFT JOIN
- (
- SELECT cjc.`chemical_id`,SUM(s.usages-s.tare) stockNum FROM hxp_stock s
- LEFT JOIN hxp_chemical_join_cabinet cjc ON s.`join_id` = cjc.`id`
- LEFT JOIN lab_subject st ON s.sub_id = st.id
- <where>
- s.status = 1
- <if test="deptId != null ">
- and st.dept_id = #{deptId}
- </if>
- <if test="subId != null ">
- and s.sub_id = #{subId}
- </if>
- <if test="chemicalId != null ">
- and cjc.`chemical_id` = #{chemicalId}
- </if>
- <if test="cabinetId != null ">
- and cjc.`cabinet_id` = #{cabinetId}
- </if>
- </where>
- GROUP BY cjc.`chemical_id`
- )x2 ON x1.chemical_id = x2.chemical_id-->
- </select>
- <select id="getRestStockClassif" resultType="com.zd.chemical.domain.vo.ActRestStockVo">
- SELECT 1 chemicalId,CONCAT(IFNULL(x1.stockNum,0),'g') restStock FROM (
- SELECT cjc.`chemical_id`,SUM(s.usages-s.tare) stockNum FROM hxp_stock s
- LEFT JOIN hxp_chemical_join_cabinet cjc ON s.`join_id` = cjc.`id`
- LEFT JOIN lab_subject st ON s.sub_id = st.id
- <where>
- s.status = 1
- <if test="deptId != null ">
- AND st.dept_id = #{deptId}
- </if>
- <if test="chemicalId != null ">
- AND cjc.`chemical_id` = #{chemicalId}
- </if>
- </where>
- GROUP BY cjc.`chemical_id`
- )x1
- UNION ALL
- SELECT 2 chemicalId,CONCAT(IFNULL(x1.stockNum,0),'g') restStock FROM (
- SELECT cjc.`chemical_id`,SUM(s.usages-s.tare) stockNum FROM hxp_stock s
- LEFT JOIN hxp_chemical_join_cabinet cjc ON s.`join_id` = cjc.`id`
- LEFT JOIN lab_subject st ON s.sub_id = st.id
- <where>
- s.status = 1
- <if test="subId != null ">
- AND s.sub_id = #{subId}
- </if>
- <if test="chemicalId != null ">
- AND cjc.`chemical_id` = #{chemicalId}
- </if>
- </where>
- GROUP BY cjc.`chemical_id`
- )x1
- UNION ALL
- SELECT 3 chemicalId,CONCAT(IFNULL(x1.stockNum,0),'g') restStock FROM (
- SELECT cjc.`chemical_id`,SUM(s.usages-s.tare) stockNum FROM hxp_stock s
- LEFT JOIN hxp_chemical_join_cabinet cjc ON s.`join_id` = cjc.`id`
- LEFT JOIN lab_subject st ON s.sub_id = st.id
- <where>
- s.status = 1
- <if test="chemicalId != null ">
- AND cjc.`chemical_id` = #{chemicalId}
- </if>
- <if test="cabinetId != null ">
- AND cjc.`cabinet_id` = #{cabinetId}
- </if>
- </where>
- GROUP BY cjc.`chemical_id`
- )x1
- UNION ALL
- SELECT 4 chemicalId,CASE WHEN CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.applyNum,0)),'g')>0
- THEN CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.applyNum,0)),'g') ELSE CONCAT(0,'g') END restStock FROM (
- SELECT hd.`chemical_id`,IFNULL(SUM(hd.`apply_num`),0) applyNum FROM act_hxpapply ah LEFT JOIN act_hxpapply_detail hd ON ah.`id` = hd.`hxpapply_id`
- LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
- LEFT JOIN lab_subject st ON ah.sub_id = st.id
- <where>
- ak.`approval_status`=1 AND hd.`tick_status`=1
- <if test="deptId != null ">
- AND st.dept_id = #{deptId}
- </if>
- <if test="subId != null ">
- AND ah.sub_id = #{subId}
- </if>
- <if test="chemicalId != null ">
- AND hd.`chemical_id` = #{chemicalId}
- </if>
- <if test="cabinetId != null ">
- AND hd.`cabinet_id` = #{cabinetId}
- </if>
- <if test="applyUserId != null ">
- AND ah.`user_id` = #{applyUserId}
- </if>
- </where>
- GROUP BY hd.`chemical_id`
- )x1 LEFT JOIN
- (
- SELECT hd.`chemical_id`,SUM(IFNULL(cjc.`chemical_amount`,0)-IFNULL(cjc.`tare`,0)) applyNum FROM act_hxpapply ah LEFT JOIN act_hxpapply_detail hd ON ah.`id` = hd.`hxpapply_id`
- LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
- LEFT JOIN lab_subject st ON ah.sub_id = st.id
- inner join hxp_chemical_join_cabinet cjc on hd.`cabinet_id` = cjc.`cabinet_id` and hd.`chemical_id` = cjc.`chemical_id`
- <where>
- ak.`approval_status`=1 AND hd.`tick_status`=1
- <if test="deptId != null ">
- AND st.dept_id = #{deptId}
- </if>
- <if test="subId != null ">
- AND ah.sub_id = #{subId}
- </if>
- <if test="chemicalId != null ">
- AND hd.`chemical_id` = #{chemicalId}
- </if>
- <if test="cabinetId != null ">
- AND hd.`cabinet_id` = #{cabinetId}
- </if>
- <if test="applyUserId != null ">
- AND ah.`user_id` = #{applyUserId}
- </if>
- </where>
- GROUP BY hd.`chemical_id`
- )x2 ON x1.chemical_id = x2.chemical_id
- </select>
- <select id="getRestStockByManyCabinet" parameterType="com.zd.chemical.domain.vo.ActRestStockManySearch" resultType="com.zd.chemical.domain.vo.ActRestStockManyVo">
- <!--SELECT x1.cabinet_id cabinetId,CASE WHEN CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0)))>0
- THEN CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0))) ELSE 0 END restStock FROM (
- SELECT hd.`cabinet_id`,IFNULL(SUM(hd.`apply_num`),0) applyNum FROM act_hxpapply ah LEFT JOIN act_hxpapply_detail hd ON ah.`id` = hd.`hxpapply_id`
- LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
- LEFT JOIN lab_subject st ON ah.sub_id = st.id
- <where>
- ak.`approval_status`=1 AND hd.`tick_status`=1
- <if test="chemicalId != null ">
- and hd.`chemical_id` = #{chemicalId}
- </if>
- <if test="cabinetIds != null ">
- and hd.`cabinet_id` in
- <foreach item="id" collection="cabinetIds" open="(" separator="," close=")">
- #{id}
- </foreach>
- </if>
- </where>
- GROUP BY hd.`cabinet_id`
- )x1 LEFT JOIN
- (
- SELECT cjc.`cabinet_id`,SUM(cjc.chemical_amount-cjc.tare) stockNum FROM
- hxp_chemical_join_cabinet cjc
- <where>
- cjc.`status` IN(0,1)
- <if test="chemicalId != null ">
- and cjc.`chemical_id` = #{chemicalId}
- </if>
- <if test="cabinetIds != null ">
- and cjc.`cabinet_id` in
- <foreach item="id" collection="cabinetIds" open="(" separator="," close=")">
- #{id}
- </foreach>
- </if>
- </where>
- GROUP BY cjc.`cabinet_id`
- )x2 ON x1.cabinet_id = x2.cabinet_id
- -->
- SELECT x1.cabinet_id cabinetId,CASE WHEN CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0)))>0
- THEN CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0))) ELSE 0 END restStock FROM (
- SELECT hd.`cabinet_id`,IFNULL(SUM(hd.`apply_num`),0) applyNum FROM act_hxpapply ah LEFT JOIN act_hxpapply_detail hd ON ah.`id` = hd.`hxpapply_id`
- LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
- LEFT JOIN lab_subject st ON ah.sub_id = st.id
- <where>
- ak.`approval_status`=1 AND hd.`tick_status`=1
- <if test="chemicalId != null ">
- and hd.`chemical_id` = #{chemicalId}
- </if>
- <if test="cabinetIds != null ">
- and hd.`cabinet_id` in
- <foreach item="id" collection="cabinetIds" open="(" separator="," close=")">
- #{id}
- </foreach>
- </if>
- <if test="applyUserId != null ">
- AND ah.`user_id` = #{applyUserId}
- </if>
- </where>
- GROUP BY hd.`cabinet_id`
- )x1 LEFT JOIN
- (
- SELECT cjc.`chemical_id`,cjc.`cabinet_id`,SUM(cjc.chemical_amount-cjc.tare) stockNum FROM
- act_hxpapply ah LEFT JOIN act_hxpapply_detail hd ON ah.`id` = hd.`hxpapply_id`
- LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
- INNER JOIN hxp_chemical_join_cabinet cjc ON hd.`cabinet_id` = cjc.`cabinet_id` AND hd.`chemical_id` = cjc.`chemical_id`
- <where>
- ak.`approval_status`=1 AND hd.`tick_status`=1
- <if test="chemicalId != null ">
- and cjc.`chemical_id` = #{chemicalId}
- </if>
- <if test="cabinetIds != null ">
- and cjc.`cabinet_id` in
- <foreach item="id" collection="cabinetIds" open="(" separator="," close=")">
- #{id}
- </foreach>
- </if>
- <if test="applyUserId != null ">
- AND ah.`user_id` = #{applyUserId}
- </if>
- </where>
- GROUP BY cjc.`cabinet_id`
- )x2 ON x1.cabinet_id = x2.cabinet_id
- </select>
- <select id="getRestStockByManyCabinetAndChemical" parameterType="com.zd.chemical.domain.vo.ActRestStockManySearch" resultType="com.zd.chemical.domain.vo.ActRestStockManyVo">
- SELECT x1.chemical_id chemicalId,x1.cabinet_id cabinetId,CASE WHEN CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0)))>0
- THEN CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0))) ELSE 0 END restStock FROM (
- SELECT hd.`chemical_id`,hd.`cabinet_id`,IFNULL(SUM(hd.`apply_num`),0) applyNum FROM act_hxpapply ah LEFT JOIN act_hxpapply_detail hd ON ah.`id` = hd.`hxpapply_id`
- LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
- LEFT JOIN lab_subject st ON ah.sub_id = st.id
- WHERE
- ak.`approval_status`=1 AND hd.`tick_status`=1
- <if test="chemicalIds != null ">
- AND hd.`chemical_id` IN
- <foreach item="id" collection="chemicalIds" open="(" separator="," close=")">
- #{id}
- </foreach>
- </if>
- <if test="cabinetIds != null ">
- AND hd.`cabinet_id` IN
- <foreach item="id" collection="cabinetIds" open="(" separator="," close=")">
- #{id}
- </foreach>
- </if>
- <if test="applyUserId != null ">
- AND ah.`user_id` = #{applyUserId}
- </if>
- GROUP BY hd.`chemical_id`,hd.`cabinet_id`
- )x1 LEFT JOIN
- (
- SELECT cjc.`chemical_id`,cjc.`cabinet_id`,SUM(cjc.chemical_amount-cjc.tare) stockNum FROM
- act_hxpapply ah LEFT JOIN act_hxpapply_detail hd ON ah.`id` = hd.`hxpapply_id`
- LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
- INNER JOIN hxp_chemical_join_cabinet cjc ON hd.`cabinet_id` = cjc.`cabinet_id` AND hd.`chemical_id` = cjc.`chemical_id`
- WHERE
- ak.`approval_status`=1 AND hd.`tick_status`=1
- <if test="chemicalIds != null ">
- AND cjc.`chemical_id` IN
- <foreach item="id" collection="chemicalIds" open="(" separator="," close=")">
- #{id}
- </foreach>
- </if>
- <if test="cabinetIds != null ">
- AND cjc.`cabinet_id` IN
- <foreach item="id" collection="cabinetIds" open="(" separator="," close=")">
- #{id}
- </foreach>
- </if>
- <if test="applyUserId != null ">
- AND ah.`user_id` = #{applyUserId}
- </if>
- GROUP BY cjc.`chemical_id`,cjc.`cabinet_id`
- )x2 ON x1.chemical_id = x2.chemical_id AND x1.cabinet_id = x2.cabinet_id
- </select>
- <insert id="insertActHxpapply" parameterType="com.zd.chemical.domain.ActHxpapply" useGeneratedKeys="true" keyProperty="id">
- insert into act_hxpapply
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="applyNum != null">apply_num,</if>
- <if test="applyReason != null">apply_reason,</if>
- <if test="subId != null">sub_id,</if>
- <if test="applyStatus != null">apply_status,</if>
- <if test="userId != null">user_id,</if>
- <if test="createBy != null">create_by,</if>
- <if test="createTime != null">create_time,</if>
- <if test="updateBy != null">update_by,</if>
- <if test="updateTime != null">update_time,</if>
- <if test="remark != null">remark,</if>
- </trim>
- <trim prefix="values (" suffix=")" suffixOverrides=",">
- <if test="applyNum != null">#{applyNum},</if>
- <if test="applyReason != null">#{applyReason},</if>
- <if test="subId != null">#{subId},</if>
- <if test="applyStatus != null">#{applyStatus},</if>
- <if test="userId != null">#{userId},</if>
- <if test="createBy != null">#{createBy},</if>
- <if test="createTime != null">#{createTime},</if>
- <if test="updateBy != null">#{updateBy},</if>
- <if test="updateTime != null">#{updateTime},</if>
- <if test="remark != null">#{remark},</if>
- </trim>
- </insert>
- <update id="updateActHxpapply" parameterType="com.zd.chemical.domain.ActHxpapply">
- update act_hxpapply
- <trim prefix="SET" suffixOverrides=",">
- <if test="applyNum != null">apply_num = #{applyNum},</if>
- <if test="applyReason != null">apply_reason = #{applyReason},</if>
- <if test="subId != null">sub_id = #{subId},</if>
- <if test="applyStatus != null">apply_status = #{applyStatus},</if>
- <if test="userId != null">user_id = #{userId},</if>
- <if test="createBy != null">create_by = #{createBy},</if>
- <if test="createTime != null">create_time = #{createTime},</if>
- <if test="updateBy != null">update_by = #{updateBy},</if>
- <if test="updateTime != null">update_time = #{updateTime},</if>
- <if test="remark != null">remark = #{remark},</if>
- </trim>
- where id = #{id}
- </update>
- <delete id="deleteActHxpapplyById">
- delete from act_hxpapply where id = #{id}
- </delete>
- <delete id="deleteActHxpapplyByIds">
- delete from act_hxpapply where id in
- <foreach item="id" collection="array" open="(" separator="," close=")">
- #{id}
- </foreach>
- </delete>
- </mapper>
|