ActHxpapplyMapper.xml 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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. </where>
  155. GROUP BY ah.`id`
  156. )xx WHERE FIND_IN_SET(#{loginUserId},xx.currentApprover) ORDER BY xx.createTime DESC
  157. )xx1
  158. UNION
  159. SELECT xx1.* FROM (
  160. SELECT xx.id,xx.applyNum,xx.subscriber,xx.subName,xx.chemicalNames,xx.createTime,xx.overTime,xx.approvalContent,xx.approvalStatus,
  161. CASE WHEN xx.approvalStatus = 0 THEN
  162. (SELECT GROUP_CONCAT(ur.user_id,';',ur.nick_name) FROM sys_user ur WHERE FIND_IN_SET(ur.user_id,xx.currentApprover))
  163. ELSE ''
  164. END currentApprover,
  165. CASE WHEN xx.approvalStatus = 3 THEN ''
  166. ELSE (SELECT GROUP_CONCAT(ur.user_id,';',ur.nick_name) FROM sys_user ur WHERE FIND_IN_SET(ur.user_id,xx.historyApprover))
  167. END historyApprover,
  168. xx.currentApprover currentApproverIds,xx.userId
  169. FROM (
  170. SELECT ah.id,ah.`apply_num` applyNum,
  171. su.nick_name subscriber,
  172. st.`name` subName,
  173. GROUP_CONCAT(hd.chemical_name ORDER BY hd.chemical_name DESC,'-申购量:',hd.apply_num,'g' SEPARATOR '; ') chemicalNames,
  174. ah.`create_time` createTime,
  175. ak.`over_time` overTime,
  176. CASE WHEN ak.approval_status=0 THEN '审批中'
  177. ELSE CASE WHEN ak.approval_status=1 THEN '已通过'
  178. ELSE CASE WHEN ak.approval_status=2 THEN '已拒绝'
  179. ELSE '已撤销'
  180. END
  181. END
  182. END approvalContent,
  183. ak.approval_status approvalStatus,
  184. (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
  185. AND apk.approval_status=0 ORDER BY an.node_order ASC LIMIT 1) currentApprover,
  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 = 1 OR an.node_status = 2)
  187. AND (apk.approval_status=0 OR apk.approval_status=1) ORDER BY an.node_order DESC LIMIT 1) historyApprover,
  188. ah.user_id userId
  189. FROM act_hxpapply ah LEFT JOIN sys_user su ON su.user_id = ah.`user_id`
  190. LEFT JOIN lab_subject st ON st.id = ah.`sub_id`
  191. LEFT JOIN act_hxpapply_detail hd ON hd.hxpapply_id = ah.id
  192. LEFT JOIN act_applytask ak ON ak.`task_id` = ah.`id`
  193. <where>
  194. ah.apply_status in(1,3)
  195. <if test="ids != null">
  196. and ah.id in
  197. <foreach item="id" collection="ids" open="(" separator="," close=")">
  198. #{id}
  199. </foreach>
  200. </if>
  201. <if test="searchValue != null ">
  202. and (
  203. ah.apply_num like concat('%', #{searchValue}, '%') or
  204. su.nick_name like concat('%', #{searchValue}, '%') or
  205. hd.chemical_name like concat('%', #{searchValue}, '%') or
  206. st.name like concat('%', #{searchValue}, '%')
  207. )
  208. </if>
  209. <if test="approvalStatus != null ">
  210. and ak.approval_status = #{approvalStatus}
  211. </if>
  212. <if test="beginCreateTime != null and beginCreateTime != ''"><!-- 申请开始时间 -->
  213. AND date_format(ak.create_time,'%y%m%d') &gt;= date_format(#{beginCreateTime},'%y%m%d')
  214. </if>
  215. <if test="endCreateTime != null and endCreateTime != ''"><!-- 申请结束时间 -->
  216. AND date_format(ak.create_time,'%y%m%d') &lt;= date_format(#{endCreateTime},'%y%m%d')
  217. </if>
  218. <if test="beginOverTime != null and beginOverTime != ''"><!-- 完成开始时间 -->
  219. AND date_format(ak.over_time,'%y%m%d') &gt;= date_format(#{beginOverTime},'%y%m%d')
  220. </if>
  221. <if test="endOverTime != null and endOverTime != ''"><!-- 完成结束时间 -->
  222. AND date_format(ak.over_time,'%y%m%d') &lt;= date_format(#{endOverTime},'%y%m%d')
  223. </if>
  224. <if test="userId != null and userId != ''"><!-- 创建人id -->
  225. and ah.user_id = #{userId}
  226. </if>
  227. </where>
  228. GROUP BY ah.`id`
  229. )xx ORDER BY xx.createTime DESC
  230. )xx1
  231. </select>
  232. <select id="draftsList" parameterType="com.zd.chemical.domain.vo.ActHxpapplySearch" resultType="com.zd.chemical.domain.vo.ActHxpapplyDraftsListVo">
  233. SELECT xx.id,xx.applyNum,xx.subscriber,xx.subName,xx.chemicalNames,xx.createTime,xx.overTime,xx.approvalContent,xx.approvalStatus,
  234. CASE WHEN xx.approvalStatus = 0 THEN
  235. (SELECT GROUP_CONCAT(ur.user_id,';',ur.nick_name) FROM sys_user ur WHERE FIND_IN_SET(ur.user_id,xx.currentApprover))
  236. ELSE ''
  237. END currentApprover,
  238. CASE WHEN xx.approvalStatus = 3 THEN ''
  239. ELSE (SELECT GROUP_CONCAT(ur.user_id,';',ur.nick_name) FROM sys_user ur WHERE FIND_IN_SET(ur.user_id,xx.historyApprover))
  240. END historyApprover,
  241. xx.currentApprover currentApproverIds
  242. FROM (
  243. SELECT ah.id,ah.`apply_num` applyNum,
  244. su.nick_name subscriber,
  245. st.`name` subName,
  246. GROUP_CONCAT(hd.chemical_name,'-申购量:',hd.apply_num,'g' SEPARATOR '; ') chemicalNames,
  247. ah.`create_time` createTime,
  248. ak.`over_time` overTime,
  249. CASE WHEN ak.approval_status=0 THEN '审批中'
  250. ELSE CASE WHEN ak.approval_status=1 THEN '已通过'
  251. ELSE CASE WHEN ak.approval_status=2 THEN '已拒绝'
  252. ELSE '已撤销'
  253. END
  254. END
  255. END approvalContent,
  256. ak.approval_status approvalStatus,
  257. (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
  258. AND apk.approval_status=0 ORDER BY an.node_order ASC LIMIT 1) currentApprover,
  259. (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)
  260. AND (apk.approval_status=0 OR apk.approval_status=1) ORDER BY an.node_order DESC LIMIT 1) historyApprover
  261. FROM act_hxpapply ah LEFT JOIN sys_user su ON su.user_id = ah.`user_id`
  262. LEFT JOIN lab_subject st ON st.id = ah.`sub_id`
  263. LEFT JOIN act_hxpapply_detail hd ON hd.hxpapply_id = ah.id
  264. LEFT JOIN act_applytask ak ON ak.`task_id` = ah.`id`
  265. <where>
  266. ah.apply_status =2 and ah.user_id = #{loginUserId}
  267. <if test="searchValue != null ">
  268. and (
  269. ah.apply_num like concat('%', #{searchValue}, '%') or
  270. su.nick_name like concat('%', #{searchValue}, '%') or
  271. hd.chemical_name like concat('%', #{searchValue}, '%') or
  272. st.name like concat('%', #{searchValue}, '%')
  273. )
  274. </if>
  275. <if test="approvalStatus != null ">
  276. and ak.approval_status = #{approvalStatus}
  277. </if>
  278. <if test="beginCreateTime != null and beginCreateTime != ''"><!-- 申请开始时间 -->
  279. AND date_format(ak.create_time,'%y%m%d') &gt;= date_format(#{beginCreateTime},'%y%m%d')
  280. </if>
  281. <if test="endCreateTime != null and endCreateTime != ''"><!-- 申请结束时间 -->
  282. AND date_format(ak.create_time,'%y%m%d') &lt;= date_format(#{endCreateTime},'%y%m%d')
  283. </if>
  284. <if test="beginOverTime != null and beginOverTime != ''"><!-- 完成开始时间 -->
  285. AND date_format(ak.over_time,'%y%m%d') &gt;= date_format(#{beginOverTime},'%y%m%d')
  286. </if>
  287. <if test="endOverTime != null and endOverTime != ''"><!-- 完成结束时间 -->
  288. AND date_format(ak.over_time,'%y%m%d') &lt;= date_format(#{endOverTime},'%y%m%d')
  289. </if>
  290. <if test="userId != null and userId != ''"><!-- 创建人id -->
  291. and ah.user_id = #{userId}
  292. </if>
  293. </where>
  294. GROUP BY ah.`id`
  295. )xx ORDER BY xx.createTime DESC
  296. </select>
  297. <select id="getListByIds" resultMap="ActHxpapplyResult">
  298. <include refid="selectActHxpapplyVo"/>
  299. <where>
  300. id in
  301. <foreach item="id" collection="list" open="(" separator="," close=")">
  302. #{id}
  303. </foreach>
  304. </where>
  305. </select>
  306. <select id="selectActHxpapplyById" resultType="com.zd.chemical.domain.vo.ActHxpapplyInfoVo">
  307. 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
  308. , a.update_time, a.remark,
  309. (select ur.nick_name from sys_user ur where ur.user_id = a.user_id) applyUserName,
  310. st.name subName,st.dept_id deptId
  311. from act_hxpapply a left join lab_subject st on st.id = a.sub_id
  312. where a.id = #{id}
  313. </select>
  314. <select id="getRestStock" resultType="java.util.Map">
  315. SELECT x1.chemical_id chemicalId,CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0)),'g') restStock FROM (
  316. 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`
  317. LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
  318. LEFT JOIN lab_subject st ON ah.sub_id = st.id
  319. <where>
  320. ak.`approval_status`=1 AND hd.`tick_status`=1
  321. <if test="deptId != null ">
  322. and st.dept_id = #{deptId}
  323. </if>
  324. <if test="subId != null ">
  325. and ah.sub_id = #{subId}
  326. </if>
  327. <if test="chemicalId != null ">
  328. and hd.`chemical_id` = #{chemicalId}
  329. </if>
  330. <if test="cabinetId != null ">
  331. and hd.`cabinet_id` = #{cabinetId}
  332. </if>
  333. </where>
  334. GROUP BY hd.`chemical_id`
  335. )x1 LEFT JOIN
  336. (
  337. SELECT cjc.`chemical_id`,SUM(s.usages-s.tare) stockNum FROM hxp_stock s
  338. LEFT JOIN hxp_chemical_join_cabinet cjc ON s.`join_id` = cjc.`id`
  339. LEFT JOIN lab_subject st ON s.sub_id = st.id
  340. <where>
  341. s.status = 1
  342. <if test="deptId != null ">
  343. and st.dept_id = #{deptId}
  344. </if>
  345. <if test="subId != null ">
  346. and s.sub_id = #{subId}
  347. </if>
  348. <if test="chemicalId != null ">
  349. and cjc.`chemical_id` = #{chemicalId}
  350. </if>
  351. <if test="cabinetId != null ">
  352. and cjc.`cabinet_id` = #{cabinetId}
  353. </if>
  354. </where>
  355. GROUP BY cjc.`chemical_id`
  356. )x2 ON x1.chemical_id = x2.chemical_id
  357. </select>
  358. <select id="getRestStockClassif" resultType="com.zd.chemical.domain.vo.ActRestStockVo">
  359. SELECT 1 chemicalId,CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0)),'g') restStock FROM (
  360. 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`
  361. LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
  362. LEFT JOIN lab_subject st ON ah.sub_id = st.id
  363. <where>
  364. ak.`approval_status`=1 AND hd.`tick_status`=1
  365. <if test="deptId != null ">
  366. AND st.dept_id = #{deptId}
  367. </if>
  368. <if test="chemicalId != null ">
  369. AND hd.`chemical_id` = #{chemicalId}
  370. </if>
  371. </where>
  372. GROUP BY hd.`chemical_id`
  373. )x1 LEFT JOIN
  374. (
  375. SELECT cjc.`chemical_id`,SUM(s.usages-s.tare) stockNum FROM hxp_stock s
  376. LEFT JOIN hxp_chemical_join_cabinet cjc ON s.`join_id` = cjc.`id`
  377. LEFT JOIN lab_subject st ON s.sub_id = st.id
  378. <where>
  379. s.status = 1
  380. <if test="deptId != null ">
  381. AND st.dept_id = #{deptId}
  382. </if>
  383. <if test="chemicalId != null ">
  384. AND cjc.`chemical_id` = #{chemicalId}
  385. </if>
  386. </where>
  387. GROUP BY cjc.`chemical_id`
  388. )x2 ON x1.chemical_id = x2.chemical_id
  389. UNION ALL
  390. SELECT 2 chemicalId,CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0)),'g') restStock FROM (
  391. 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`
  392. LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
  393. LEFT JOIN lab_subject st ON ah.sub_id = st.id
  394. <where>
  395. ak.`approval_status`=1 AND hd.`tick_status`=1
  396. <if test="subId != null ">
  397. AND ah.sub_id = #{subId}
  398. </if>
  399. <if test="chemicalId != null ">
  400. AND hd.`chemical_id` = #{chemicalId}
  401. </if>
  402. </where>
  403. GROUP BY hd.`chemical_id`
  404. )x1 LEFT JOIN
  405. (
  406. SELECT cjc.`chemical_id`,SUM(s.usages-s.tare) stockNum FROM hxp_stock s
  407. LEFT JOIN hxp_chemical_join_cabinet cjc ON s.`join_id` = cjc.`id`
  408. LEFT JOIN lab_subject st ON s.sub_id = st.id
  409. <where>
  410. s.status = 1
  411. <if test="subId != null ">
  412. AND s.sub_id = #{subId}
  413. </if>
  414. <if test="chemicalId != null ">
  415. AND cjc.`chemical_id` = #{chemicalId}
  416. </if>
  417. </where>
  418. GROUP BY cjc.`chemical_id`
  419. )x2 ON x1.chemical_id = x2.chemical_id
  420. UNION ALL
  421. SELECT 3 chemicalId,CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0)),'g') restStock FROM (
  422. 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`
  423. LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
  424. LEFT JOIN lab_subject st ON ah.sub_id = st.id
  425. <where>
  426. ak.`approval_status`=1 AND hd.`tick_status`=1
  427. <if test="chemicalId != null ">
  428. AND hd.`chemical_id` = #{chemicalId}
  429. </if>
  430. <if test="cabinetId != null ">
  431. AND hd.`cabinet_id` = #{cabinetId}
  432. </if>
  433. </where>
  434. GROUP BY hd.`chemical_id`
  435. )x1 LEFT JOIN
  436. (
  437. SELECT cjc.`chemical_id`,SUM(s.usages-s.tare) stockNum FROM hxp_stock s
  438. LEFT JOIN hxp_chemical_join_cabinet cjc ON s.`join_id` = cjc.`id`
  439. LEFT JOIN lab_subject st ON s.sub_id = st.id
  440. <where>
  441. s.status = 1
  442. <if test="chemicalId != null ">
  443. AND cjc.`chemical_id` = #{chemicalId}
  444. </if>
  445. <if test="cabinetId != null ">
  446. AND cjc.`cabinet_id` = #{cabinetId}
  447. </if>
  448. </where>
  449. GROUP BY cjc.`chemical_id`
  450. )x2 ON x1.chemical_id = x2.chemical_id
  451. UNION ALL
  452. SELECT 4 chemicalId,CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0)),'g') restStock FROM (
  453. 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`
  454. LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
  455. LEFT JOIN lab_subject st ON ah.sub_id = st.id
  456. <where>
  457. ak.`approval_status`=1 AND hd.`tick_status`=1
  458. <if test="deptId != null ">
  459. AND st.dept_id = #{deptId}
  460. </if>
  461. <if test="subId != null ">
  462. AND ah.sub_id = #{subId}
  463. </if>
  464. <if test="chemicalId != null ">
  465. AND hd.`chemical_id` = #{chemicalId}
  466. </if>
  467. <if test="cabinetId != null ">
  468. AND hd.`cabinet_id` = #{cabinetId}
  469. </if>
  470. </where>
  471. GROUP BY hd.`chemical_id`
  472. )x1 LEFT JOIN
  473. (
  474. SELECT cjc.`chemical_id`,SUM(s.usages-s.tare) stockNum FROM hxp_stock s
  475. LEFT JOIN hxp_chemical_join_cabinet cjc ON s.`join_id` = cjc.`id`
  476. LEFT JOIN lab_subject st ON s.sub_id = st.id
  477. <where>
  478. s.status = 1
  479. <if test="deptId != null ">
  480. AND st.dept_id = #{deptId}
  481. </if>
  482. <if test="subId != null ">
  483. AND s.sub_id = #{subId}
  484. </if>
  485. <if test="chemicalId != null ">
  486. AND cjc.`chemical_id` = #{chemicalId}
  487. </if>
  488. <if test="cabinetId != null ">
  489. AND cjc.`cabinet_id` = #{cabinetId}
  490. </if>
  491. </where>
  492. GROUP BY cjc.`chemical_id`
  493. )x2 ON x1.chemical_id = x2.chemical_id
  494. </select>
  495. <select id="getRestStockByManyCabinet" parameterType="com.zd.chemical.domain.vo.ActRestStockManySearch" resultType="com.zd.chemical.domain.vo.ActRestStockManyVo">
  496. SELECT x1.cabinet_id cabinetId,CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0))) restStock FROM (
  497. 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`
  498. LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
  499. LEFT JOIN lab_subject st ON ah.sub_id = st.id
  500. <where>
  501. ak.`approval_status`=1 AND hd.`tick_status`=1
  502. <if test="chemicalId != null ">
  503. and hd.`chemical_id` = #{chemicalId}
  504. </if>
  505. <if test="cabinetIds != null ">
  506. and hd.`cabinet_id` in
  507. <foreach item="id" collection="cabinetIds" open="(" separator="," close=")">
  508. #{id}
  509. </foreach>
  510. </if>
  511. </where>
  512. GROUP BY hd.`cabinet_id`
  513. )x1 LEFT JOIN
  514. (
  515. SELECT cjc.`cabinet_id`,SUM(s.usages-s.tare) stockNum FROM hxp_stock s
  516. LEFT JOIN hxp_chemical_join_cabinet cjc ON s.`join_id` = cjc.`id`
  517. LEFT JOIN lab_subject st ON s.sub_id = st.id
  518. <where>
  519. s.status = 1
  520. <if test="chemicalId != null ">
  521. and cjc.`chemical_id` = #{chemicalId}
  522. </if>
  523. <if test="cabinetIds != null ">
  524. and cjc.`cabinet_id` in
  525. <foreach item="id" collection="cabinetIds" open="(" separator="," close=")">
  526. #{id}
  527. </foreach>
  528. </if>
  529. </where>
  530. GROUP BY cjc.`cabinet_id`
  531. )x2 ON x1.cabinet_id = x2.cabinet_id
  532. </select>
  533. <insert id="insertActHxpapply" parameterType="com.zd.chemical.domain.ActHxpapply" useGeneratedKeys="true" keyProperty="id">
  534. insert into act_hxpapply
  535. <trim prefix="(" suffix=")" suffixOverrides=",">
  536. <if test="applyNum != null">apply_num,</if>
  537. <if test="applyReason != null">apply_reason,</if>
  538. <if test="subId != null">sub_id,</if>
  539. <if test="applyStatus != null">apply_status,</if>
  540. <if test="userId != null">user_id,</if>
  541. <if test="createBy != null">create_by,</if>
  542. <if test="createTime != null">create_time,</if>
  543. <if test="updateBy != null">update_by,</if>
  544. <if test="updateTime != null">update_time,</if>
  545. <if test="remark != null">remark,</if>
  546. </trim>
  547. <trim prefix="values (" suffix=")" suffixOverrides=",">
  548. <if test="applyNum != null">#{applyNum},</if>
  549. <if test="applyReason != null">#{applyReason},</if>
  550. <if test="subId != null">#{subId},</if>
  551. <if test="applyStatus != null">#{applyStatus},</if>
  552. <if test="userId != null">#{userId},</if>
  553. <if test="createBy != null">#{createBy},</if>
  554. <if test="createTime != null">#{createTime},</if>
  555. <if test="updateBy != null">#{updateBy},</if>
  556. <if test="updateTime != null">#{updateTime},</if>
  557. <if test="remark != null">#{remark},</if>
  558. </trim>
  559. </insert>
  560. <update id="updateActHxpapply" parameterType="com.zd.chemical.domain.ActHxpapply">
  561. update act_hxpapply
  562. <trim prefix="SET" suffixOverrides=",">
  563. <if test="applyNum != null">apply_num = #{applyNum},</if>
  564. <if test="applyReason != null">apply_reason = #{applyReason},</if>
  565. <if test="subId != null">sub_id = #{subId},</if>
  566. <if test="applyStatus != null">apply_status = #{applyStatus},</if>
  567. <if test="userId != null">user_id = #{userId},</if>
  568. <if test="createBy != null">create_by = #{createBy},</if>
  569. <if test="createTime != null">create_time = #{createTime},</if>
  570. <if test="updateBy != null">update_by = #{updateBy},</if>
  571. <if test="updateTime != null">update_time = #{updateTime},</if>
  572. <if test="remark != null">remark = #{remark},</if>
  573. </trim>
  574. where id = #{id}
  575. </update>
  576. <delete id="deleteActHxpapplyById">
  577. delete from act_hxpapply where id = #{id}
  578. </delete>
  579. <delete id="deleteActHxpapplyByIds">
  580. delete from act_hxpapply where id in
  581. <foreach item="id" collection="array" open="(" separator="," close=")">
  582. #{id}
  583. </foreach>
  584. </delete>
  585. </mapper>