ActHxpapplyMapper.xml 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.zd.chemical.mapper.ActHxpapplyMapper">
  6. <resultMap type="com.zd.chemical.domain.ActHxpapply" id="ActHxpapplyResult">
  7. <result property="id" column="id" />
  8. <result property="applyNum" column="apply_num" />
  9. <result property="applyReason" column="apply_reason" />
  10. <result property="subId" column="sub_id" />
  11. <result property="applyStatus" column="apply_status" />
  12. <result property="userId" column="user_id" />
  13. <result property="createBy" column="create_by" />
  14. <result property="createTime" column="create_time" />
  15. <result property="updateBy" column="update_by" />
  16. <result property="updateTime" column="update_time" />
  17. <result property="remark" column="remark" />
  18. </resultMap>
  19. <sql id="selectActHxpapplyVo">
  20. select id, apply_num, apply_reason, sub_id, apply_status, user_id, create_by, create_time, update_by, update_time, remark from act_hxpapply
  21. </sql>
  22. <sql id="selectActHxpapplyListVo">
  23. 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
  24. </sql>
  25. <select id="selectActHxpapplyList" parameterType="com.zd.chemical.domain.vo.ActHxpapplySearch" resultType="com.zd.chemical.domain.vo.ActHxpapplyListVo">
  26. <!--SELECT xx.applyNum,xx.subscriber,xx.subName,xx.chemicalNames,xx.createTime,xx.overTime,xx.approvalContent,xx.approvalStatus,-->
  27. <!--CASE WHEN xx.approvalStatus = 0 THEN-->
  28. <!--(SELECT GROUP_CONCAT(ur.user_id,';',ur.nick_name) FROM sys_user ur WHERE FIND_IN_SET(ur.user_id,xx.currentApprover))-->
  29. <!--ELSE ''-->
  30. <!--END currentApprover,-->
  31. <!--CASE WHEN xx.approvalStatus = 3 THEN ''-->
  32. <!--ELSE (SELECT GROUP_CONCAT(ur.user_id,';',ur.nick_name) FROM sys_user ur WHERE FIND_IN_SET(ur.user_id,xx.historyApprover))-->
  33. <!--END historyApprover,-->
  34. <!--xx.currentApprover currentApproverIds-->
  35. <!--FROM (-->
  36. <!--SELECT ah.`apply_num` applyNum,-->
  37. <!--su.nick_name subscriber,-->
  38. <!--st.`name` subName,-->
  39. <!--GROUP_CONCAT(hd.chemical_name) chemicalNames,-->
  40. <!--ah.`create_time` createTime,-->
  41. <!--ak.`over_time` overTime,-->
  42. <!--CASE WHEN ak.approval_status=0 THEN '审批中'-->
  43. <!--ELSE CASE WHEN ak.approval_status=1 THEN '已通过'-->
  44. <!--ELSE CASE WHEN ak.approval_status=2 THEN '已拒绝'-->
  45. <!--ELSE '已撤销'-->
  46. <!--END-->
  47. <!--END-->
  48. <!--END approvalContent,-->
  49. <!--ak.approval_status approvalStatus,-->
  50. <!--(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-->
  51. <!--AND apk.approval_status=0 ORDER BY an.node_order ASC LIMIT 1) currentApprover,-->
  52. <!--(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)-->
  53. <!--AND (apk.approval_status=0 OR apk.approval_status=1) ORDER BY an.node_order DESC LIMIT 1) historyApprover-->
  54. <!--FROM act_hxpapply ah LEFT JOIN sys_user su ON su.user_id = ah.`user_id`-->
  55. <!--LEFT JOIN lab_subject st ON st.id = ah.`sub_id`-->
  56. <!--LEFT JOIN act_hxpapply_detail hd ON hd.hxpapply_id = ah.id-->
  57. <!--LEFT JOIN act_applytask ak ON ak.`task_id` = ah.`id`-->
  58. <!--<where>-->
  59. <!--ah.apply_status in(1,3)-->
  60. <!--<if test="searchValue != null ">-->
  61. <!--and (-->
  62. <!--ah.apply_num like concat('%', #{searchValue}, '%') or-->
  63. <!--su.nick_name like concat('%', #{searchValue}, '%') or-->
  64. <!--hd.chemical_name like concat('%', #{searchValue}, '%') or-->
  65. <!--st.name like concat('%', #{searchValue}, '%')-->
  66. <!--)-->
  67. <!--</if>-->
  68. <!--<if test="approvalStatus != null ">-->
  69. <!--and ak.approval_status = #{approvalStatus}-->
  70. <!--</if>-->
  71. <!--<if test="beginCreateTime != null and beginCreateTime != ''">&lt;!&ndash; 申请开始时间 &ndash;&gt;-->
  72. <!--AND date_format(ak.create_time,'%y%m%d') &gt;= date_format(#{beginCreateTime},'%y%m%d')-->
  73. <!--</if>-->
  74. <!--<if test="endCreateTime != null and endCreateTime != ''">&lt;!&ndash; 申请结束时间 &ndash;&gt;-->
  75. <!--AND date_format(ak.create_time,'%y%m%d') &lt;= date_format(#{endCreateTime},'%y%m%d')-->
  76. <!--</if>-->
  77. <!--<if test="beginOverTime != null and beginOverTime != ''">&lt;!&ndash; 完成开始时间 &ndash;&gt;-->
  78. <!--AND date_format(ak.over_time,'%y%m%d') &gt;= date_format(#{beginOverTime},'%y%m%d')-->
  79. <!--</if>-->
  80. <!--<if test="endOverTime != null and endOverTime != ''">&lt;!&ndash; 完成结束时间 &ndash;&gt;-->
  81. <!--AND date_format(ak.over_time,'%y%m%d') &lt;= date_format(#{endOverTime},'%y%m%d')-->
  82. <!--</if>-->
  83. <!--</where>-->
  84. <!--GROUP BY ah.`id`-->
  85. <!--)xx ORDER BY xx.createTime DESC-->
  86. SELECT xx1.* FROM (
  87. SELECT xx.id,xx.applyNum,xx.subscriber,xx.subName,xx.chemicalNames,xx.createTime,xx.overTime,xx.approvalContent,xx.approvalStatus,
  88. CASE WHEN xx.approvalStatus = 0 THEN
  89. (SELECT GROUP_CONCAT(ur.user_id,';',ur.nick_name) FROM sys_user ur WHERE FIND_IN_SET(ur.user_id,xx.currentApprover))
  90. ELSE ''
  91. END currentApprover,
  92. CASE WHEN xx.approvalStatus = 3 THEN ''
  93. ELSE (SELECT GROUP_CONCAT(ur.user_id,';',ur.nick_name) FROM sys_user ur WHERE FIND_IN_SET(ur.user_id,xx.historyApprover))
  94. END historyApprover,
  95. xx.currentApprover currentApproverIds,xx.userId
  96. FROM (
  97. SELECT ah.id,ah.`apply_num` applyNum,
  98. su.nick_name subscriber,
  99. st.`name` subName,
  100. GROUP_CONCAT(hd.chemical_name ORDER BY hd.chemical_name DESC,'-申购量:',hd.apply_num,'g' SEPARATOR '; ') chemicalNames,
  101. ah.`create_time` createTime,
  102. ak.`over_time` overTime,
  103. CASE WHEN ak.approval_status=0 THEN '审批中'
  104. ELSE CASE WHEN ak.approval_status=1 THEN '已通过'
  105. ELSE CASE WHEN ak.approval_status=2 THEN '已拒绝'
  106. ELSE '已撤销'
  107. END
  108. END
  109. END approvalContent,
  110. ak.approval_status approvalStatus,
  111. (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
  112. AND apk.approval_status=0 ORDER BY an.node_order ASC LIMIT 1) currentApprover,
  113. (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)
  114. AND (apk.approval_status=0 OR apk.approval_status=1) ORDER BY an.node_order DESC LIMIT 1) historyApprover,
  115. ah.user_id userId
  116. FROM act_hxpapply ah LEFT JOIN sys_user su ON su.user_id = ah.`user_id`
  117. LEFT JOIN lab_subject st ON st.id = ah.`sub_id`
  118. LEFT JOIN act_hxpapply_detail hd ON hd.hxpapply_id = ah.id
  119. LEFT JOIN act_applytask ak ON ak.`task_id` = ah.`id`
  120. <where>
  121. ah.apply_status in(1,3)
  122. <if test="ids != null">
  123. and ah.id in
  124. <foreach item="id" collection="ids" open="(" separator="," close=")">
  125. #{id}
  126. </foreach>
  127. </if>
  128. <if test="searchValue != null ">
  129. and (
  130. ah.apply_num like concat('%', #{searchValue}, '%') or
  131. su.nick_name like concat('%', #{searchValue}, '%') or
  132. hd.chemical_name like concat('%', #{searchValue}, '%') or
  133. st.name like concat('%', #{searchValue}, '%')
  134. )
  135. </if>
  136. <if test="approvalStatus != null ">
  137. and ak.approval_status = #{approvalStatus}
  138. </if>
  139. <if test="beginCreateTime != null and beginCreateTime != ''"><!-- 申请开始时间 -->
  140. AND date_format(ak.create_time,'%y%m%d') &gt;= date_format(#{beginCreateTime},'%y%m%d')
  141. </if>
  142. <if test="endCreateTime != null and endCreateTime != ''"><!-- 申请结束时间 -->
  143. AND date_format(ak.create_time,'%y%m%d') &lt;= date_format(#{endCreateTime},'%y%m%d')
  144. </if>
  145. <if test="beginOverTime != null and beginOverTime != ''"><!-- 完成开始时间 -->
  146. AND date_format(ak.over_time,'%y%m%d') &gt;= date_format(#{beginOverTime},'%y%m%d')
  147. </if>
  148. <if test="endOverTime != null and endOverTime != ''"><!-- 完成结束时间 -->
  149. AND date_format(ak.over_time,'%y%m%d') &lt;= date_format(#{endOverTime},'%y%m%d')
  150. </if>
  151. <if test="userId != null and userId != ''"><!-- 创建人id -->
  152. and ah.user_id = #{userId}
  153. </if>
  154. <!-- 数据范围过滤 -->
  155. ${params.dataScope}
  156. </where>
  157. GROUP BY ah.`id`
  158. )xx WHERE FIND_IN_SET(#{loginUserId},xx.currentApprover) ORDER BY xx.createTime DESC
  159. )xx1
  160. UNION
  161. SELECT xx1.* FROM (
  162. SELECT xx.id,xx.applyNum,xx.subscriber,xx.subName,xx.chemicalNames,xx.createTime,xx.overTime,xx.approvalContent,xx.approvalStatus,
  163. CASE WHEN xx.approvalStatus = 0 THEN
  164. (SELECT GROUP_CONCAT(ur.user_id,';',ur.nick_name) FROM sys_user ur WHERE FIND_IN_SET(ur.user_id,xx.currentApprover))
  165. ELSE ''
  166. END currentApprover,
  167. CASE WHEN xx.approvalStatus = 3 THEN ''
  168. ELSE (SELECT GROUP_CONCAT(ur.user_id,';',ur.nick_name) FROM sys_user ur WHERE FIND_IN_SET(ur.user_id,xx.historyApprover))
  169. END historyApprover,
  170. xx.currentApprover currentApproverIds,xx.userId
  171. FROM (
  172. SELECT ah.id,ah.`apply_num` applyNum,
  173. su.nick_name subscriber,
  174. st.`name` subName,
  175. GROUP_CONCAT(hd.chemical_name ORDER BY hd.chemical_name DESC,'-申购量:',hd.apply_num,'g' SEPARATOR '; ') chemicalNames,
  176. ah.`create_time` createTime,
  177. ak.`over_time` overTime,
  178. CASE WHEN ak.approval_status=0 THEN '审批中'
  179. ELSE CASE WHEN ak.approval_status=1 THEN '已通过'
  180. ELSE CASE WHEN ak.approval_status=2 THEN '已拒绝'
  181. ELSE '已撤销'
  182. END
  183. END
  184. END approvalContent,
  185. ak.approval_status approvalStatus,
  186. (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
  187. AND apk.approval_status=0 ORDER BY an.node_order ASC LIMIT 1) currentApprover,
  188. (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)
  189. AND (apk.approval_status=0 OR apk.approval_status=1) ORDER BY an.node_order DESC LIMIT 1) historyApprover,
  190. ah.user_id userId
  191. FROM act_hxpapply ah LEFT JOIN sys_user su ON su.user_id = ah.`user_id`
  192. LEFT JOIN lab_subject st ON st.id = ah.`sub_id`
  193. LEFT JOIN act_hxpapply_detail hd ON hd.hxpapply_id = ah.id
  194. LEFT JOIN act_applytask ak ON ak.`task_id` = ah.`id`
  195. <where>
  196. ah.apply_status in(1,3)
  197. <if test="ids != null">
  198. and ah.id in
  199. <foreach item="id" collection="ids" open="(" separator="," close=")">
  200. #{id}
  201. </foreach>
  202. </if>
  203. <if test="searchValue != null ">
  204. and (
  205. ah.apply_num like concat('%', #{searchValue}, '%') or
  206. su.nick_name like concat('%', #{searchValue}, '%') or
  207. hd.chemical_name like concat('%', #{searchValue}, '%') or
  208. st.name like concat('%', #{searchValue}, '%')
  209. )
  210. </if>
  211. <if test="approvalStatus != null ">
  212. and ak.approval_status = #{approvalStatus}
  213. </if>
  214. <if test="beginCreateTime != null and beginCreateTime != ''"><!-- 申请开始时间 -->
  215. AND date_format(ak.create_time,'%y%m%d') &gt;= date_format(#{beginCreateTime},'%y%m%d')
  216. </if>
  217. <if test="endCreateTime != null and endCreateTime != ''"><!-- 申请结束时间 -->
  218. AND date_format(ak.create_time,'%y%m%d') &lt;= date_format(#{endCreateTime},'%y%m%d')
  219. </if>
  220. <if test="beginOverTime != null and beginOverTime != ''"><!-- 完成开始时间 -->
  221. AND date_format(ak.over_time,'%y%m%d') &gt;= date_format(#{beginOverTime},'%y%m%d')
  222. </if>
  223. <if test="endOverTime != null and endOverTime != ''"><!-- 完成结束时间 -->
  224. AND date_format(ak.over_time,'%y%m%d') &lt;= date_format(#{endOverTime},'%y%m%d')
  225. </if>
  226. <if test="userId != null and userId != ''"><!-- 创建人id -->
  227. and ah.user_id = #{userId}
  228. </if>
  229. <!-- 数据范围过滤 -->
  230. ${params.dataScope}
  231. </where>
  232. GROUP BY ah.`id`
  233. )xx ORDER BY xx.createTime DESC
  234. )xx1
  235. </select>
  236. <select id="draftsList" parameterType="com.zd.chemical.domain.vo.ActHxpapplySearch" resultType="com.zd.chemical.domain.vo.ActHxpapplyDraftsListVo">
  237. SELECT xx.id,xx.applyNum,xx.subscriber,xx.subName,xx.chemicalNames,xx.createTime,xx.overTime,xx.approvalContent,xx.approvalStatus,
  238. CASE WHEN xx.approvalStatus = 0 THEN
  239. (SELECT GROUP_CONCAT(ur.user_id,';',ur.nick_name) FROM sys_user ur WHERE FIND_IN_SET(ur.user_id,xx.currentApprover))
  240. ELSE ''
  241. END currentApprover,
  242. CASE WHEN xx.approvalStatus = 3 THEN ''
  243. ELSE (SELECT GROUP_CONCAT(ur.user_id,';',ur.nick_name) FROM sys_user ur WHERE FIND_IN_SET(ur.user_id,xx.historyApprover))
  244. END historyApprover,
  245. xx.currentApprover currentApproverIds
  246. FROM (
  247. SELECT ah.id,ah.`apply_num` applyNum,
  248. su.nick_name subscriber,
  249. st.`name` subName,
  250. GROUP_CONCAT(hd.chemical_name,'-申购量:',hd.apply_num,'g' SEPARATOR '; ') chemicalNames,
  251. ah.`create_time` createTime,
  252. ak.`over_time` overTime,
  253. CASE WHEN ak.approval_status=0 THEN '审批中'
  254. ELSE CASE WHEN ak.approval_status=1 THEN '已通过'
  255. ELSE CASE WHEN ak.approval_status=2 THEN '已拒绝'
  256. ELSE '已撤销'
  257. END
  258. END
  259. END approvalContent,
  260. ak.approval_status approvalStatus,
  261. (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
  262. AND apk.approval_status=0 ORDER BY an.node_order ASC LIMIT 1) currentApprover,
  263. (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)
  264. AND (apk.approval_status=0 OR apk.approval_status=1) ORDER BY an.node_order DESC LIMIT 1) historyApprover
  265. FROM act_hxpapply ah LEFT JOIN sys_user su ON su.user_id = ah.`user_id`
  266. LEFT JOIN lab_subject st ON st.id = ah.`sub_id`
  267. LEFT JOIN act_hxpapply_detail hd ON hd.hxpapply_id = ah.id
  268. LEFT JOIN act_applytask ak ON ak.`task_id` = ah.`id`
  269. <where>
  270. ah.apply_status =2
  271. <if test="searchValue != null ">
  272. and (
  273. ah.apply_num like concat('%', #{searchValue}, '%') or
  274. su.nick_name like concat('%', #{searchValue}, '%') or
  275. hd.chemical_name like concat('%', #{searchValue}, '%') or
  276. st.name like concat('%', #{searchValue}, '%')
  277. )
  278. </if>
  279. <if test="approvalStatus != null ">
  280. and ak.approval_status = #{approvalStatus}
  281. </if>
  282. <if test="beginCreateTime != null and beginCreateTime != ''"><!-- 申请开始时间 -->
  283. AND date_format(ah.create_time,'%y%m%d') &gt;= date_format(#{beginCreateTime},'%y%m%d')
  284. </if>
  285. <if test="endCreateTime != null and endCreateTime != ''"><!-- 申请结束时间 -->
  286. AND date_format(ah.create_time,'%y%m%d') &lt;= date_format(#{endCreateTime},'%y%m%d')
  287. </if>
  288. <if test="beginOverTime != null and beginOverTime != ''"><!-- 完成开始时间 -->
  289. AND date_format(ah.over_time,'%y%m%d') &gt;= date_format(#{beginOverTime},'%y%m%d')
  290. </if>
  291. <if test="endOverTime != null and endOverTime != ''"><!-- 完成结束时间 -->
  292. AND date_format(ah.over_time,'%y%m%d') &lt;= date_format(#{endOverTime},'%y%m%d')
  293. </if>
  294. <if test="userId != null and userId != ''"><!-- 创建人id -->
  295. and ah.user_id = #{userId}
  296. </if>
  297. </where>
  298. GROUP BY ah.`id`
  299. )xx ORDER BY xx.createTime DESC
  300. </select>
  301. <select id="getListByIds" resultMap="ActHxpapplyResult">
  302. <include refid="selectActHxpapplyVo"/>
  303. <where>
  304. id in
  305. <foreach item="id" collection="list" open="(" separator="," close=")">
  306. #{id}
  307. </foreach>
  308. </where>
  309. </select>
  310. <select id="selectActHxpapplyById" resultType="com.zd.chemical.domain.vo.ActHxpapplyInfoVo">
  311. 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
  312. , a.update_time, a.remark,
  313. (select ur.nick_name from sys_user ur where ur.user_id = a.user_id) applyUserName,
  314. st.name subName,st.dept_id deptId
  315. from act_hxpapply a left join lab_subject st on st.id = a.sub_id
  316. where a.id = #{id}
  317. </select>
  318. <select id="getRestStock" resultType="java.util.Map">
  319. SELECT x1.chemical_id chemicalId,CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0)),'g') restStock FROM (
  320. 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`
  321. LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
  322. LEFT JOIN lab_subject st ON ah.sub_id = st.id
  323. <where>
  324. ak.`approval_status`=1 AND hd.`tick_status`=1
  325. <if test="deptId != null ">
  326. and st.dept_id = #{deptId}
  327. </if>
  328. <if test="subId != null ">
  329. and ah.sub_id = #{subId}
  330. </if>
  331. <if test="chemicalId != null ">
  332. and hd.`chemical_id` = #{chemicalId}
  333. </if>
  334. <if test="cabinetId != null ">
  335. and hd.`cabinet_id` = #{cabinetId}
  336. </if>
  337. </where>
  338. GROUP BY hd.`chemical_id`
  339. )x1 LEFT JOIN
  340. (
  341. SELECT cjc.`chemical_id`,SUM(s.usages-s.tare) stockNum FROM hxp_stock s
  342. LEFT JOIN hxp_chemical_join_cabinet cjc ON s.`join_id` = cjc.`id`
  343. LEFT JOIN lab_subject st ON s.sub_id = st.id
  344. <where>
  345. s.status = 1
  346. <if test="deptId != null ">
  347. and st.dept_id = #{deptId}
  348. </if>
  349. <if test="subId != null ">
  350. and s.sub_id = #{subId}
  351. </if>
  352. <if test="chemicalId != null ">
  353. and cjc.`chemical_id` = #{chemicalId}
  354. </if>
  355. <if test="cabinetId != null ">
  356. and cjc.`cabinet_id` = #{cabinetId}
  357. </if>
  358. </where>
  359. GROUP BY cjc.`chemical_id`
  360. )x2 ON x1.chemical_id = x2.chemical_id
  361. </select>
  362. <select id="getRestStockClassif" resultType="com.zd.chemical.domain.vo.ActRestStockVo">
  363. SELECT 1 chemicalId,CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0)),'g') restStock FROM (
  364. 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`
  365. LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
  366. LEFT JOIN lab_subject st ON ah.sub_id = st.id
  367. <where>
  368. ak.`approval_status`=1 AND hd.`tick_status`=1
  369. <if test="deptId != null ">
  370. AND st.dept_id = #{deptId}
  371. </if>
  372. <if test="chemicalId != null ">
  373. AND hd.`chemical_id` = #{chemicalId}
  374. </if>
  375. </where>
  376. GROUP BY hd.`chemical_id`
  377. )x1 LEFT JOIN
  378. (
  379. SELECT cjc.`chemical_id`,SUM(s.usages-s.tare) stockNum FROM hxp_stock s
  380. LEFT JOIN hxp_chemical_join_cabinet cjc ON s.`join_id` = cjc.`id`
  381. LEFT JOIN lab_subject st ON s.sub_id = st.id
  382. <where>
  383. s.status = 1
  384. <if test="deptId != null ">
  385. AND st.dept_id = #{deptId}
  386. </if>
  387. <if test="chemicalId != null ">
  388. AND cjc.`chemical_id` = #{chemicalId}
  389. </if>
  390. </where>
  391. GROUP BY cjc.`chemical_id`
  392. )x2 ON x1.chemical_id = x2.chemical_id
  393. UNION ALL
  394. SELECT 2 chemicalId,CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0)),'g') restStock FROM (
  395. 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`
  396. LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
  397. LEFT JOIN lab_subject st ON ah.sub_id = st.id
  398. <where>
  399. ak.`approval_status`=1 AND hd.`tick_status`=1
  400. <if test="subId != null ">
  401. AND ah.sub_id = #{subId}
  402. </if>
  403. <if test="chemicalId != null ">
  404. AND hd.`chemical_id` = #{chemicalId}
  405. </if>
  406. </where>
  407. GROUP BY hd.`chemical_id`
  408. )x1 LEFT JOIN
  409. (
  410. SELECT cjc.`chemical_id`,SUM(s.usages-s.tare) stockNum FROM hxp_stock s
  411. LEFT JOIN hxp_chemical_join_cabinet cjc ON s.`join_id` = cjc.`id`
  412. LEFT JOIN lab_subject st ON s.sub_id = st.id
  413. <where>
  414. s.status = 1
  415. <if test="subId != null ">
  416. AND s.sub_id = #{subId}
  417. </if>
  418. <if test="chemicalId != null ">
  419. AND cjc.`chemical_id` = #{chemicalId}
  420. </if>
  421. </where>
  422. GROUP BY cjc.`chemical_id`
  423. )x2 ON x1.chemical_id = x2.chemical_id
  424. UNION ALL
  425. SELECT 3 chemicalId,CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0)),'g') restStock FROM (
  426. 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`
  427. LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
  428. LEFT JOIN lab_subject st ON ah.sub_id = st.id
  429. <where>
  430. ak.`approval_status`=1 AND hd.`tick_status`=1
  431. <if test="chemicalId != null ">
  432. AND hd.`chemical_id` = #{chemicalId}
  433. </if>
  434. <if test="cabinetId != null ">
  435. AND hd.`cabinet_id` = #{cabinetId}
  436. </if>
  437. </where>
  438. GROUP BY hd.`chemical_id`
  439. )x1 LEFT JOIN
  440. (
  441. SELECT cjc.`chemical_id`,SUM(s.usages-s.tare) stockNum FROM hxp_stock s
  442. LEFT JOIN hxp_chemical_join_cabinet cjc ON s.`join_id` = cjc.`id`
  443. LEFT JOIN lab_subject st ON s.sub_id = st.id
  444. <where>
  445. s.status = 1
  446. <if test="chemicalId != null ">
  447. AND cjc.`chemical_id` = #{chemicalId}
  448. </if>
  449. <if test="cabinetId != null ">
  450. AND cjc.`cabinet_id` = #{cabinetId}
  451. </if>
  452. </where>
  453. GROUP BY cjc.`chemical_id`
  454. )x2 ON x1.chemical_id = x2.chemical_id
  455. UNION ALL
  456. SELECT 4 chemicalId,CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0)),'g') restStock FROM (
  457. 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`
  458. LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
  459. LEFT JOIN lab_subject st ON ah.sub_id = st.id
  460. <where>
  461. ak.`approval_status`=1 AND hd.`tick_status`=1
  462. <if test="deptId != null ">
  463. AND st.dept_id = #{deptId}
  464. </if>
  465. <if test="subId != null ">
  466. AND ah.sub_id = #{subId}
  467. </if>
  468. <if test="chemicalId != null ">
  469. AND hd.`chemical_id` = #{chemicalId}
  470. </if>
  471. <if test="cabinetId != null ">
  472. AND hd.`cabinet_id` = #{cabinetId}
  473. </if>
  474. </where>
  475. GROUP BY hd.`chemical_id`
  476. )x1 LEFT JOIN
  477. (
  478. SELECT cjc.`chemical_id`,SUM(s.usages-s.tare) stockNum FROM hxp_stock s
  479. LEFT JOIN hxp_chemical_join_cabinet cjc ON s.`join_id` = cjc.`id`
  480. LEFT JOIN lab_subject st ON s.sub_id = st.id
  481. <where>
  482. s.status = 1
  483. <if test="deptId != null ">
  484. AND st.dept_id = #{deptId}
  485. </if>
  486. <if test="subId != null ">
  487. AND s.sub_id = #{subId}
  488. </if>
  489. <if test="chemicalId != null ">
  490. AND cjc.`chemical_id` = #{chemicalId}
  491. </if>
  492. <if test="cabinetId != null ">
  493. AND cjc.`cabinet_id` = #{cabinetId}
  494. </if>
  495. </where>
  496. GROUP BY cjc.`chemical_id`
  497. )x2 ON x1.chemical_id = x2.chemical_id
  498. </select>
  499. <select id="getRestStockByManyCabinet" parameterType="com.zd.chemical.domain.vo.ActRestStockManySearch" resultType="com.zd.chemical.domain.vo.ActRestStockManyVo">
  500. SELECT x1.cabinet_id cabinetId,CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0))) restStock FROM (
  501. 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`
  502. LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
  503. LEFT JOIN lab_subject st ON ah.sub_id = st.id
  504. <where>
  505. ak.`approval_status`=1 AND hd.`tick_status`=1
  506. <if test="chemicalId != null ">
  507. and hd.`chemical_id` = #{chemicalId}
  508. </if>
  509. <if test="cabinetIds != null ">
  510. and hd.`cabinet_id` in
  511. <foreach item="id" collection="cabinetIds" open="(" separator="," close=")">
  512. #{id}
  513. </foreach>
  514. </if>
  515. </where>
  516. GROUP BY hd.`cabinet_id`
  517. )x1 LEFT JOIN
  518. (
  519. SELECT cjc.`cabinet_id`,SUM(s.usages-s.tare) stockNum FROM hxp_stock s
  520. LEFT JOIN hxp_chemical_join_cabinet cjc ON s.`join_id` = cjc.`id`
  521. LEFT JOIN lab_subject st ON s.sub_id = st.id
  522. <where>
  523. s.status = 1
  524. <if test="chemicalId != null ">
  525. and cjc.`chemical_id` = #{chemicalId}
  526. </if>
  527. <if test="cabinetIds != null ">
  528. and cjc.`cabinet_id` in
  529. <foreach item="id" collection="cabinetIds" open="(" separator="," close=")">
  530. #{id}
  531. </foreach>
  532. </if>
  533. </where>
  534. GROUP BY cjc.`cabinet_id`
  535. )x2 ON x1.cabinet_id = x2.cabinet_id
  536. </select>
  537. <insert id="insertActHxpapply" parameterType="com.zd.chemical.domain.ActHxpapply" useGeneratedKeys="true" keyProperty="id">
  538. insert into act_hxpapply
  539. <trim prefix="(" suffix=")" suffixOverrides=",">
  540. <if test="applyNum != null">apply_num,</if>
  541. <if test="applyReason != null">apply_reason,</if>
  542. <if test="subId != null">sub_id,</if>
  543. <if test="applyStatus != null">apply_status,</if>
  544. <if test="userId != null">user_id,</if>
  545. <if test="createBy != null">create_by,</if>
  546. <if test="createTime != null">create_time,</if>
  547. <if test="updateBy != null">update_by,</if>
  548. <if test="updateTime != null">update_time,</if>
  549. <if test="remark != null">remark,</if>
  550. </trim>
  551. <trim prefix="values (" suffix=")" suffixOverrides=",">
  552. <if test="applyNum != null">#{applyNum},</if>
  553. <if test="applyReason != null">#{applyReason},</if>
  554. <if test="subId != null">#{subId},</if>
  555. <if test="applyStatus != null">#{applyStatus},</if>
  556. <if test="userId != null">#{userId},</if>
  557. <if test="createBy != null">#{createBy},</if>
  558. <if test="createTime != null">#{createTime},</if>
  559. <if test="updateBy != null">#{updateBy},</if>
  560. <if test="updateTime != null">#{updateTime},</if>
  561. <if test="remark != null">#{remark},</if>
  562. </trim>
  563. </insert>
  564. <update id="updateActHxpapply" parameterType="com.zd.chemical.domain.ActHxpapply">
  565. update act_hxpapply
  566. <trim prefix="SET" suffixOverrides=",">
  567. <if test="applyNum != null">apply_num = #{applyNum},</if>
  568. <if test="applyReason != null">apply_reason = #{applyReason},</if>
  569. <if test="subId != null">sub_id = #{subId},</if>
  570. <if test="applyStatus != null">apply_status = #{applyStatus},</if>
  571. <if test="userId != null">user_id = #{userId},</if>
  572. <if test="createBy != null">create_by = #{createBy},</if>
  573. <if test="createTime != null">create_time = #{createTime},</if>
  574. <if test="updateBy != null">update_by = #{updateBy},</if>
  575. <if test="updateTime != null">update_time = #{updateTime},</if>
  576. <if test="remark != null">remark = #{remark},</if>
  577. </trim>
  578. where id = #{id}
  579. </update>
  580. <delete id="deleteActHxpapplyById">
  581. delete from act_hxpapply where id = #{id}
  582. </delete>
  583. <delete id="deleteActHxpapplyByIds">
  584. delete from act_hxpapply where id in
  585. <foreach item="id" collection="array" open="(" separator="," close=")">
  586. #{id}
  587. </foreach>
  588. </delete>
  589. </mapper>