ActHxpapplyMapper.xml 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  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
  90. WHERE ur.`user_id`
  91. IN (
  92. SELECT
  93. SUBSTRING_INDEX(SUBSTRING_INDEX(xx.currentApprover,',', b.help_topic_id + 1), ',', -1) result
  94. FROM
  95. mysql.help_topic b
  96. WHERE
  97. b.help_topic_id &lt; (LENGTH(xx.currentApprover) - LENGTH(REPLACE(xx.currentApprover, ',', '')) + 1)
  98. )
  99. )
  100. ELSE ''
  101. END currentApprover,
  102. CASE WHEN xx.approvalStatus = 3 THEN ''
  103. ELSE (SELECT GROUP_CONCAT(ur.user_id,';',ur.nick_name) FROM sys_user ur
  104. WHERE ur.`user_id`
  105. IN (
  106. SELECT
  107. SUBSTRING_INDEX(SUBSTRING_INDEX(xx.historyApprover,',', b.help_topic_id + 1), ',', -1) result
  108. FROM
  109. mysql.help_topic b
  110. WHERE
  111. b.help_topic_id &lt; (LENGTH(xx.historyApprover) - LENGTH(REPLACE(xx.historyApprover, ',', '')) + 1)
  112. )
  113. )
  114. END historyApprover,
  115. xx.currentApprover currentApproverIds,xx.userId
  116. FROM (
  117. SELECT ah.id,ah.`apply_num` applyNum,
  118. su.nick_name subscriber,
  119. st.`name` subName,
  120. GROUP_CONCAT(CONCAT(hd.chemical_name,'-申购量:' ,hd.apply_num ,'g') ORDER BY hd.chemical_name DESC,hd.apply_num DESC SEPARATOR '; ') chemicalNames,
  121. ah.`create_time` createTime,
  122. ak.`over_time` overTime,
  123. CASE WHEN ak.approval_status=0 THEN '审批中'
  124. ELSE CASE WHEN ak.approval_status=1 THEN '已通过'
  125. ELSE CASE WHEN ak.approval_status=2 THEN '已拒绝'
  126. ELSE '已撤销'
  127. END
  128. END
  129. END approvalContent,
  130. ak.approval_status approvalStatus,
  131. (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
  132. AND apk.approval_status=0 ORDER BY an.node_order ASC LIMIT 1) currentApprover,
  133. (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)
  134. AND (apk.approval_status=0 OR apk.approval_status=1) ORDER BY an.node_order DESC LIMIT 1) historyApprover,
  135. ah.user_id userId
  136. FROM act_hxpapply ah LEFT JOIN sys_user su ON su.user_id = ah.`user_id`
  137. LEFT JOIN lab_subject st ON st.id = ah.`sub_id`
  138. LEFT JOIN act_hxpapply_detail hd ON hd.hxpapply_id = ah.id
  139. LEFT JOIN act_applytask ak ON ak.`task_id` = ah.`id`
  140. <where>
  141. ah.apply_status in(1,3)
  142. <if test="ids != null">
  143. and ah.id in
  144. <foreach item="id" collection="ids" open="(" separator="," close=")">
  145. #{id}
  146. </foreach>
  147. </if>
  148. <if test="searchValue != null ">
  149. and (
  150. ah.apply_num like concat('%', #{searchValue}, '%') or
  151. su.nick_name like concat('%', #{searchValue}, '%') or
  152. hd.chemical_name like concat('%', #{searchValue}, '%') or
  153. st.name like concat('%', #{searchValue}, '%')
  154. )
  155. </if>
  156. <if test="approvalStatus != null ">
  157. and ak.approval_status = #{approvalStatus}
  158. </if>
  159. <if test="beginCreateTime != null and beginCreateTime != ''"><!-- 申请开始时间 -->
  160. AND date_format(ak.create_time,'%y%m%d') &gt;= date_format(#{beginCreateTime},'%y%m%d')
  161. </if>
  162. <if test="endCreateTime != null and endCreateTime != ''"><!-- 申请结束时间 -->
  163. AND date_format(ak.create_time,'%y%m%d') &lt;= date_format(#{endCreateTime},'%y%m%d')
  164. </if>
  165. <if test="beginOverTime != null and beginOverTime != ''"><!-- 完成开始时间 -->
  166. AND date_format(ak.over_time,'%y%m%d') &gt;= date_format(#{beginOverTime},'%y%m%d')
  167. </if>
  168. <if test="endOverTime != null and endOverTime != ''"><!-- 完成结束时间 -->
  169. AND date_format(ak.over_time,'%y%m%d') &lt;= date_format(#{endOverTime},'%y%m%d')
  170. </if>
  171. <if test="userId != null and userId != ''"><!-- 创建人id -->
  172. and ah.user_id = #{userId}
  173. </if>
  174. <!-- 数据范围过滤 -->
  175. ${params.dataScope}
  176. </where>
  177. GROUP BY ah.`id`
  178. )xx WHERE FIND_IN_SET(#{loginUserId},xx.currentApprover) ORDER BY xx.createTime DESC
  179. )xx1
  180. UNION
  181. SELECT xx1.* FROM (
  182. SELECT xx.id,xx.applyNum,xx.subscriber,xx.subName,xx.chemicalNames,xx.createTime,xx.overTime,xx.approvalContent,xx.approvalStatus,
  183. CASE WHEN xx.approvalStatus = 0 THEN
  184. (SELECT GROUP_CONCAT(ur.user_id,';',ur.nick_name) FROM sys_user ur
  185. WHERE ur.`user_id`
  186. IN (
  187. SELECT
  188. SUBSTRING_INDEX(SUBSTRING_INDEX(xx.currentApprover,',', b.help_topic_id + 1), ',', -1) result
  189. FROM
  190. mysql.help_topic b
  191. WHERE
  192. b.help_topic_id &lt; (LENGTH(xx.currentApprover) - LENGTH(REPLACE(xx.currentApprover, ',', '')) + 1)
  193. )
  194. )
  195. ELSE ''
  196. END currentApprover,
  197. CASE WHEN xx.approvalStatus = 3 THEN ''
  198. ELSE (SELECT GROUP_CONCAT(ur.user_id,';',ur.nick_name) FROM sys_user ur
  199. WHERE ur.`user_id`
  200. IN (
  201. SELECT
  202. SUBSTRING_INDEX(SUBSTRING_INDEX(xx.historyApprover,',', b.help_topic_id + 1), ',', -1) result
  203. FROM
  204. mysql.help_topic b
  205. WHERE
  206. b.help_topic_id &lt; (LENGTH(xx.historyApprover) - LENGTH(REPLACE(xx.historyApprover, ',', '')) + 1)
  207. )
  208. )
  209. END historyApprover,
  210. xx.currentApprover currentApproverIds,xx.userId
  211. FROM (
  212. SELECT ah.id,ah.`apply_num` applyNum,
  213. su.nick_name subscriber,
  214. st.`name` subName,
  215. GROUP_CONCAT(CONCAT(hd.chemical_name,'-申购量:' ,hd.apply_num ,'g') ORDER BY hd.chemical_name DESC,hd.apply_num DESC SEPARATOR '; ') chemicalNames,
  216. ah.`create_time` createTime,
  217. ak.`over_time` overTime,
  218. CASE WHEN ak.approval_status=0 THEN '审批中'
  219. ELSE CASE WHEN ak.approval_status=1 THEN '已通过'
  220. ELSE CASE WHEN ak.approval_status=2 THEN '已拒绝'
  221. ELSE '已撤销'
  222. END
  223. END
  224. END approvalContent,
  225. ak.approval_status approvalStatus,
  226. (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
  227. AND apk.approval_status=0 ORDER BY an.node_order ASC LIMIT 1) currentApprover,
  228. (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)
  229. AND (apk.approval_status=0 OR apk.approval_status=1) ORDER BY an.node_order DESC LIMIT 1) historyApprover,
  230. ah.user_id userId
  231. FROM act_hxpapply ah LEFT JOIN sys_user su ON su.user_id = ah.`user_id`
  232. LEFT JOIN lab_subject st ON st.id = ah.`sub_id`
  233. LEFT JOIN act_hxpapply_detail hd ON hd.hxpapply_id = ah.id
  234. LEFT JOIN act_applytask ak ON ak.`task_id` = ah.`id`
  235. <where>
  236. ah.apply_status in(1,3)
  237. <if test="ids != null">
  238. and ah.id in
  239. <foreach item="id" collection="ids" open="(" separator="," close=")">
  240. #{id}
  241. </foreach>
  242. </if>
  243. <if test="searchValue != null ">
  244. and (
  245. ah.apply_num like concat('%', #{searchValue}, '%') or
  246. su.nick_name like concat('%', #{searchValue}, '%') or
  247. hd.chemical_name like concat('%', #{searchValue}, '%') or
  248. st.name like concat('%', #{searchValue}, '%')
  249. )
  250. </if>
  251. <if test="approvalStatus != null ">
  252. and ak.approval_status = #{approvalStatus}
  253. </if>
  254. <if test="beginCreateTime != null and beginCreateTime != ''"><!-- 申请开始时间 -->
  255. AND date_format(ak.create_time,'%y%m%d') &gt;= date_format(#{beginCreateTime},'%y%m%d')
  256. </if>
  257. <if test="endCreateTime != null and endCreateTime != ''"><!-- 申请结束时间 -->
  258. AND date_format(ak.create_time,'%y%m%d') &lt;= date_format(#{endCreateTime},'%y%m%d')
  259. </if>
  260. <if test="beginOverTime != null and beginOverTime != ''"><!-- 完成开始时间 -->
  261. AND date_format(ak.over_time,'%y%m%d') &gt;= date_format(#{beginOverTime},'%y%m%d')
  262. </if>
  263. <if test="endOverTime != null and endOverTime != ''"><!-- 完成结束时间 -->
  264. AND date_format(ak.over_time,'%y%m%d') &lt;= date_format(#{endOverTime},'%y%m%d')
  265. </if>
  266. <if test="userId != null and userId != ''"><!-- 创建人id -->
  267. and ah.user_id = #{userId}
  268. </if>
  269. <!-- 数据范围过滤 -->
  270. ${params.dataScope}
  271. </where>
  272. GROUP BY ah.`id`
  273. )xx ORDER BY xx.createTime DESC
  274. )xx1
  275. </select>
  276. <select id="draftsList" parameterType="com.zd.chemical.domain.vo.ActHxpapplySearch" resultType="com.zd.chemical.domain.vo.ActHxpapplyDraftsListVo">
  277. SELECT xx.id,xx.applyNum,xx.subscriber,xx.subName,xx.chemicalNames,xx.createTime,xx.overTime,xx.approvalContent,xx.approvalStatus,
  278. CASE WHEN xx.approvalStatus = 0 THEN
  279. (SELECT GROUP_CONCAT(ur.user_id,';',ur.nick_name) FROM sys_user ur WHERE FIND_IN_SET(ur.user_id,xx.currentApprover))
  280. ELSE ''
  281. END currentApprover,
  282. CASE WHEN xx.approvalStatus = 3 THEN ''
  283. ELSE (SELECT GROUP_CONCAT(ur.user_id,';',ur.nick_name) FROM sys_user ur WHERE FIND_IN_SET(ur.user_id,xx.historyApprover))
  284. END historyApprover,
  285. xx.currentApprover currentApproverIds
  286. FROM (
  287. SELECT ah.id,ah.`apply_num` applyNum,
  288. su.nick_name subscriber,
  289. st.`name` subName,
  290. GROUP_CONCAT(hd.chemical_name,'-申购量:',hd.apply_num,'g' SEPARATOR '; ') chemicalNames,
  291. ah.`create_time` createTime,
  292. ak.`over_time` overTime,
  293. CASE WHEN ak.approval_status=0 THEN '审批中'
  294. ELSE CASE WHEN ak.approval_status=1 THEN '已通过'
  295. ELSE CASE WHEN ak.approval_status=2 THEN '已拒绝'
  296. ELSE '已撤销'
  297. END
  298. END
  299. END approvalContent,
  300. ak.approval_status approvalStatus,
  301. (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
  302. AND apk.approval_status=0 ORDER BY an.node_order ASC LIMIT 1) currentApprover,
  303. (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)
  304. AND (apk.approval_status=0 OR apk.approval_status=1) ORDER BY an.node_order DESC LIMIT 1) historyApprover
  305. FROM act_hxpapply ah LEFT JOIN sys_user su ON su.user_id = ah.`user_id`
  306. LEFT JOIN lab_subject st ON st.id = ah.`sub_id`
  307. LEFT JOIN act_hxpapply_detail hd ON hd.hxpapply_id = ah.id
  308. LEFT JOIN act_applytask ak ON ak.`task_id` = ah.`id`
  309. <where>
  310. ah.apply_status =2
  311. <if test="searchValue != null ">
  312. and (
  313. ah.apply_num like concat('%', #{searchValue}, '%') or
  314. hd.chemical_name like concat('%', #{searchValue}, '%') or
  315. st.name like concat('%', #{searchValue}, '%')
  316. )
  317. </if>
  318. <if test="approvalStatus != null ">
  319. and ak.approval_status = #{approvalStatus}
  320. </if>
  321. <if test="beginCreateTime != null and beginCreateTime != ''"><!-- 申请开始时间 -->
  322. AND date_format(ah.create_time,'%y%m%d') &gt;= date_format(#{beginCreateTime},'%y%m%d')
  323. </if>
  324. <if test="endCreateTime != null and endCreateTime != ''"><!-- 申请结束时间 -->
  325. AND date_format(ah.create_time,'%y%m%d') &lt;= date_format(#{endCreateTime},'%y%m%d')
  326. </if>
  327. <if test="beginOverTime != null and beginOverTime != ''"><!-- 完成开始时间 -->
  328. AND date_format(ah.over_time,'%y%m%d') &gt;= date_format(#{beginOverTime},'%y%m%d')
  329. </if>
  330. <if test="endOverTime != null and endOverTime != ''"><!-- 完成结束时间 -->
  331. AND date_format(ah.over_time,'%y%m%d') &lt;= date_format(#{endOverTime},'%y%m%d')
  332. </if>
  333. <if test="userId != null and userId != ''"><!-- 创建人id -->
  334. and ah.user_id = #{userId}
  335. </if>
  336. </where>
  337. GROUP BY ah.`id`
  338. )xx ORDER BY xx.createTime DESC
  339. </select>
  340. <select id="getListByIds" resultMap="ActHxpapplyResult">
  341. <include refid="selectActHxpapplyVo"/>
  342. <where>
  343. id in
  344. <foreach item="id" collection="list" open="(" separator="," close=")">
  345. #{id}
  346. </foreach>
  347. </where>
  348. </select>
  349. <select id="selectActHxpapplyById" resultType="com.zd.chemical.domain.vo.ActHxpapplyInfoVo">
  350. 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
  351. , a.update_time, a.remark,
  352. (select ur.nick_name from sys_user ur where ur.user_id = a.user_id) applyUserName,
  353. st.name subName,st.dept_id deptId
  354. from act_hxpapply a left join lab_subject st on st.id = a.sub_id
  355. where a.id = #{id}
  356. </select>
  357. <select id="getRestStock" resultType="java.util.Map">
  358. SELECT x1.chemical_id chemicalId,CASE WHEN CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.applyNum,0)),'g')>0
  359. THEN CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.applyNum,0)),'g') ELSE CONCAT(0,'g') END 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="subId != null ">
  369. AND ah.sub_id = #{subId}
  370. </if>
  371. <if test="chemicalId != null ">
  372. AND hd.`chemical_id` = #{chemicalId}
  373. </if>
  374. <if test="cabinetId != null ">
  375. AND hd.`cabinet_id` = #{cabinetId}
  376. </if>
  377. <if test="applyUserId != null ">
  378. AND ah.`user_id` = #{applyUserId}
  379. </if>
  380. </where>
  381. GROUP BY hd.`chemical_id`
  382. )x1 LEFT JOIN
  383. (
  384. 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`
  385. LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
  386. LEFT JOIN lab_subject st ON ah.sub_id = st.id
  387. inner join hxp_chemical_join_cabinet cjc on hd.`cabinet_id` = cjc.`cabinet_id` and hd.`chemical_id` = cjc.`chemical_id`
  388. <where>
  389. ak.`approval_status`=1 AND hd.`tick_status`=1
  390. <if test="deptId != null ">
  391. AND st.dept_id = #{deptId}
  392. </if>
  393. <if test="subId != null ">
  394. AND ah.sub_id = #{subId}
  395. </if>
  396. <if test="chemicalId != null ">
  397. AND hd.`chemical_id` = #{chemicalId}
  398. </if>
  399. <if test="cabinetId != null ">
  400. AND hd.`cabinet_id` = #{cabinetId}
  401. </if>
  402. <if test="applyUserId != null ">
  403. AND ah.`user_id` = #{applyUserId}
  404. </if>
  405. </where>
  406. GROUP BY hd.`chemical_id`
  407. )x2 ON x1.chemical_id = x2.chemical_id
  408. <!-- SELECT x1.chemical_id chemicalId,CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0)),'g') restStock FROM (
  409. 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`
  410. LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
  411. LEFT JOIN lab_subject st ON ah.sub_id = st.id
  412. <where>
  413. ak.`approval_status`=1 AND hd.`tick_status`=1
  414. <if test="deptId != null ">
  415. and st.dept_id = #{deptId}
  416. </if>
  417. <if test="subId != null ">
  418. and ah.sub_id = #{subId}
  419. </if>
  420. <if test="chemicalId != null ">
  421. and hd.`chemical_id` = #{chemicalId}
  422. </if>
  423. <if test="cabinetId != null ">
  424. and hd.`cabinet_id` = #{cabinetId}
  425. </if>
  426. </where>
  427. GROUP BY hd.`chemical_id`
  428. )x1 LEFT JOIN
  429. (
  430. SELECT cjc.`chemical_id`,SUM(s.usages-s.tare) stockNum FROM hxp_stock s
  431. LEFT JOIN hxp_chemical_join_cabinet cjc ON s.`join_id` = cjc.`id`
  432. LEFT JOIN lab_subject st ON s.sub_id = st.id
  433. <where>
  434. s.status = 1
  435. <if test="deptId != null ">
  436. and st.dept_id = #{deptId}
  437. </if>
  438. <if test="subId != null ">
  439. and s.sub_id = #{subId}
  440. </if>
  441. <if test="chemicalId != null ">
  442. and cjc.`chemical_id` = #{chemicalId}
  443. </if>
  444. <if test="cabinetId != null ">
  445. and cjc.`cabinet_id` = #{cabinetId}
  446. </if>
  447. </where>
  448. GROUP BY cjc.`chemical_id`
  449. )x2 ON x1.chemical_id = x2.chemical_id-->
  450. </select>
  451. <select id="getRestStockClassif" resultType="com.zd.chemical.domain.vo.ActRestStockVo">
  452. SELECT 1 chemicalId,CONCAT(IFNULL(x1.stockNum,0),'g') restStock FROM (
  453. SELECT cjc.`chemical_id`,SUM(s.usages-s.tare) stockNum FROM hxp_stock s
  454. LEFT JOIN hxp_chemical_join_cabinet cjc ON s.`join_id` = cjc.`id`
  455. LEFT JOIN lab_subject st ON s.sub_id = st.id
  456. <where>
  457. s.status = 1
  458. <if test="deptId != null ">
  459. AND st.dept_id = #{deptId}
  460. </if>
  461. <if test="chemicalId != null ">
  462. AND cjc.`chemical_id` = #{chemicalId}
  463. </if>
  464. </where>
  465. GROUP BY cjc.`chemical_id`
  466. )x1
  467. UNION ALL
  468. SELECT 2 chemicalId,CONCAT(IFNULL(x1.stockNum,0),'g') restStock FROM (
  469. SELECT cjc.`chemical_id`,SUM(s.usages-s.tare) stockNum FROM hxp_stock s
  470. LEFT JOIN hxp_chemical_join_cabinet cjc ON s.`join_id` = cjc.`id`
  471. LEFT JOIN lab_subject st ON s.sub_id = st.id
  472. <where>
  473. s.status = 1
  474. <if test="subId != null ">
  475. AND s.sub_id = #{subId}
  476. </if>
  477. <if test="chemicalId != null ">
  478. AND cjc.`chemical_id` = #{chemicalId}
  479. </if>
  480. </where>
  481. GROUP BY cjc.`chemical_id`
  482. )x1
  483. UNION ALL
  484. SELECT 3 chemicalId,CONCAT(IFNULL(x1.stockNum,0),'g') restStock FROM (
  485. SELECT cjc.`chemical_id`,SUM(s.usages-s.tare) stockNum FROM hxp_stock s
  486. LEFT JOIN hxp_chemical_join_cabinet cjc ON s.`join_id` = cjc.`id`
  487. LEFT JOIN lab_subject st ON s.sub_id = st.id
  488. <where>
  489. s.status = 1
  490. <if test="chemicalId != null ">
  491. AND cjc.`chemical_id` = #{chemicalId}
  492. </if>
  493. <if test="cabinetId != null ">
  494. AND cjc.`cabinet_id` = #{cabinetId}
  495. </if>
  496. </where>
  497. GROUP BY cjc.`chemical_id`
  498. )x1
  499. UNION ALL
  500. SELECT 4 chemicalId,CASE WHEN CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.applyNum,0)),'g')>0
  501. THEN CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.applyNum,0)),'g') ELSE CONCAT(0,'g') END restStock FROM (
  502. 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`
  503. LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
  504. LEFT JOIN lab_subject st ON ah.sub_id = st.id
  505. <where>
  506. ak.`approval_status`=1 AND hd.`tick_status`=1
  507. <if test="deptId != null ">
  508. AND st.dept_id = #{deptId}
  509. </if>
  510. <if test="subId != null ">
  511. AND ah.sub_id = #{subId}
  512. </if>
  513. <if test="chemicalId != null ">
  514. AND hd.`chemical_id` = #{chemicalId}
  515. </if>
  516. <if test="cabinetId != null ">
  517. AND hd.`cabinet_id` = #{cabinetId}
  518. </if>
  519. <if test="applyUserId != null ">
  520. AND ah.`user_id` = #{applyUserId}
  521. </if>
  522. </where>
  523. GROUP BY hd.`chemical_id`
  524. )x1 LEFT JOIN
  525. (
  526. 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`
  527. LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
  528. LEFT JOIN lab_subject st ON ah.sub_id = st.id
  529. inner join hxp_chemical_join_cabinet cjc on hd.`cabinet_id` = cjc.`cabinet_id` and hd.`chemical_id` = cjc.`chemical_id`
  530. <where>
  531. ak.`approval_status`=1 AND hd.`tick_status`=1
  532. <if test="deptId != null ">
  533. AND st.dept_id = #{deptId}
  534. </if>
  535. <if test="subId != null ">
  536. AND ah.sub_id = #{subId}
  537. </if>
  538. <if test="chemicalId != null ">
  539. AND hd.`chemical_id` = #{chemicalId}
  540. </if>
  541. <if test="cabinetId != null ">
  542. AND hd.`cabinet_id` = #{cabinetId}
  543. </if>
  544. <if test="applyUserId != null ">
  545. AND ah.`user_id` = #{applyUserId}
  546. </if>
  547. </where>
  548. GROUP BY hd.`chemical_id`
  549. )x2 ON x1.chemical_id = x2.chemical_id
  550. </select>
  551. <select id="getRestStockByManyCabinet" parameterType="com.zd.chemical.domain.vo.ActRestStockManySearch" resultType="com.zd.chemical.domain.vo.ActRestStockManyVo">
  552. <!--SELECT x1.cabinet_id cabinetId,CASE WHEN CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0)))>0
  553. THEN CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0))) ELSE 0 END restStock FROM (
  554. 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`
  555. LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
  556. LEFT JOIN lab_subject st ON ah.sub_id = st.id
  557. <where>
  558. ak.`approval_status`=1 AND hd.`tick_status`=1
  559. <if test="chemicalId != null ">
  560. and hd.`chemical_id` = #{chemicalId}
  561. </if>
  562. <if test="cabinetIds != null ">
  563. and hd.`cabinet_id` in
  564. <foreach item="id" collection="cabinetIds" open="(" separator="," close=")">
  565. #{id}
  566. </foreach>
  567. </if>
  568. </where>
  569. GROUP BY hd.`cabinet_id`
  570. )x1 LEFT JOIN
  571. (
  572. SELECT cjc.`cabinet_id`,SUM(cjc.chemical_amount-cjc.tare) stockNum FROM
  573. hxp_chemical_join_cabinet cjc
  574. <where>
  575. cjc.`status` IN(0,1)
  576. <if test="chemicalId != null ">
  577. and cjc.`chemical_id` = #{chemicalId}
  578. </if>
  579. <if test="cabinetIds != null ">
  580. and cjc.`cabinet_id` in
  581. <foreach item="id" collection="cabinetIds" open="(" separator="," close=")">
  582. #{id}
  583. </foreach>
  584. </if>
  585. </where>
  586. GROUP BY cjc.`cabinet_id`
  587. )x2 ON x1.cabinet_id = x2.cabinet_id
  588. -->
  589. SELECT x1.cabinet_id cabinetId,CASE WHEN CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0)))>0
  590. THEN CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0))) ELSE 0 END restStock FROM (
  591. 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`
  592. LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
  593. LEFT JOIN lab_subject st ON ah.sub_id = st.id
  594. <where>
  595. ak.`approval_status`=1 AND hd.`tick_status`=1
  596. <if test="chemicalId != null ">
  597. and hd.`chemical_id` = #{chemicalId}
  598. </if>
  599. <if test="cabinetIds != null ">
  600. and hd.`cabinet_id` in
  601. <foreach item="id" collection="cabinetIds" open="(" separator="," close=")">
  602. #{id}
  603. </foreach>
  604. </if>
  605. <if test="applyUserId != null ">
  606. AND ah.`user_id` = #{applyUserId}
  607. </if>
  608. </where>
  609. GROUP BY hd.`cabinet_id`
  610. )x1 LEFT JOIN
  611. (
  612. SELECT cjc.`chemical_id`,cjc.`cabinet_id`,SUM(cjc.chemical_amount-cjc.tare) stockNum FROM
  613. act_hxpapply ah LEFT JOIN act_hxpapply_detail hd ON ah.`id` = hd.`hxpapply_id`
  614. LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
  615. INNER JOIN hxp_chemical_join_cabinet cjc ON hd.`cabinet_id` = cjc.`cabinet_id` AND hd.`chemical_id` = cjc.`chemical_id`
  616. <where>
  617. ak.`approval_status`=1 AND hd.`tick_status`=1
  618. <if test="chemicalId != null ">
  619. and cjc.`chemical_id` = #{chemicalId}
  620. </if>
  621. <if test="cabinetIds != null ">
  622. and cjc.`cabinet_id` in
  623. <foreach item="id" collection="cabinetIds" open="(" separator="," close=")">
  624. #{id}
  625. </foreach>
  626. </if>
  627. <if test="applyUserId != null ">
  628. AND ah.`user_id` = #{applyUserId}
  629. </if>
  630. </where>
  631. GROUP BY cjc.`cabinet_id`
  632. )x2 ON x1.cabinet_id = x2.cabinet_id
  633. </select>
  634. <select id="getRestStockByManyCabinetAndChemical" parameterType="com.zd.chemical.domain.vo.ActRestStockManySearch" resultType="com.zd.chemical.domain.vo.ActRestStockManyVo">
  635. SELECT x1.chemical_id chemicalId,x1.cabinet_id cabinetId,CASE WHEN CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0)))>0
  636. THEN CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0))) ELSE 0 END restStock FROM (
  637. 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`
  638. LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
  639. LEFT JOIN lab_subject st ON ah.sub_id = st.id
  640. WHERE
  641. ak.`approval_status`=1 AND hd.`tick_status`=1
  642. <if test="chemicalIds != null ">
  643. AND hd.`chemical_id` IN
  644. <foreach item="id" collection="chemicalIds" open="(" separator="," close=")">
  645. #{id}
  646. </foreach>
  647. </if>
  648. <if test="cabinetIds != null ">
  649. AND hd.`cabinet_id` IN
  650. <foreach item="id" collection="cabinetIds" open="(" separator="," close=")">
  651. #{id}
  652. </foreach>
  653. </if>
  654. <if test="applyUserId != null ">
  655. AND ah.`user_id` = #{applyUserId}
  656. </if>
  657. GROUP BY hd.`chemical_id`,hd.`cabinet_id`
  658. )x1 LEFT JOIN
  659. (
  660. SELECT cjc.`chemical_id`,cjc.`cabinet_id`,SUM(cjc.chemical_amount-cjc.tare) stockNum FROM
  661. act_hxpapply ah LEFT JOIN act_hxpapply_detail hd ON ah.`id` = hd.`hxpapply_id`
  662. LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
  663. INNER JOIN hxp_chemical_join_cabinet cjc ON hd.`cabinet_id` = cjc.`cabinet_id` AND hd.`chemical_id` = cjc.`chemical_id`
  664. WHERE
  665. ak.`approval_status`=1 AND hd.`tick_status`=1
  666. <if test="chemicalIds != null ">
  667. AND cjc.`chemical_id` IN
  668. <foreach item="id" collection="chemicalIds" open="(" separator="," close=")">
  669. #{id}
  670. </foreach>
  671. </if>
  672. <if test="cabinetIds != null ">
  673. AND cjc.`cabinet_id` IN
  674. <foreach item="id" collection="cabinetIds" open="(" separator="," close=")">
  675. #{id}
  676. </foreach>
  677. </if>
  678. <if test="applyUserId != null ">
  679. AND ah.`user_id` = #{applyUserId}
  680. </if>
  681. GROUP BY cjc.`chemical_id`,cjc.`cabinet_id`
  682. )x2 ON x1.chemical_id = x2.chemical_id AND x1.cabinet_id = x2.cabinet_id
  683. </select>
  684. <insert id="insertActHxpapply" parameterType="com.zd.chemical.domain.ActHxpapply" useGeneratedKeys="true" keyProperty="id">
  685. insert into act_hxpapply
  686. <trim prefix="(" suffix=")" suffixOverrides=",">
  687. <if test="applyNum != null">apply_num,</if>
  688. <if test="applyReason != null">apply_reason,</if>
  689. <if test="subId != null">sub_id,</if>
  690. <if test="applyStatus != null">apply_status,</if>
  691. <if test="userId != null">user_id,</if>
  692. <if test="createBy != null">create_by,</if>
  693. <if test="createTime != null">create_time,</if>
  694. <if test="updateBy != null">update_by,</if>
  695. <if test="updateTime != null">update_time,</if>
  696. <if test="remark != null">remark,</if>
  697. </trim>
  698. <trim prefix="values (" suffix=")" suffixOverrides=",">
  699. <if test="applyNum != null">#{applyNum},</if>
  700. <if test="applyReason != null">#{applyReason},</if>
  701. <if test="subId != null">#{subId},</if>
  702. <if test="applyStatus != null">#{applyStatus},</if>
  703. <if test="userId != null">#{userId},</if>
  704. <if test="createBy != null">#{createBy},</if>
  705. <if test="createTime != null">#{createTime},</if>
  706. <if test="updateBy != null">#{updateBy},</if>
  707. <if test="updateTime != null">#{updateTime},</if>
  708. <if test="remark != null">#{remark},</if>
  709. </trim>
  710. </insert>
  711. <update id="updateActHxpapply" parameterType="com.zd.chemical.domain.ActHxpapply">
  712. update act_hxpapply
  713. <trim prefix="SET" suffixOverrides=",">
  714. <if test="applyNum != null">apply_num = #{applyNum},</if>
  715. <if test="applyReason != null">apply_reason = #{applyReason},</if>
  716. <if test="subId != null">sub_id = #{subId},</if>
  717. <if test="applyStatus != null">apply_status = #{applyStatus},</if>
  718. <if test="userId != null">user_id = #{userId},</if>
  719. <if test="createBy != null">create_by = #{createBy},</if>
  720. <if test="createTime != null">create_time = #{createTime},</if>
  721. <if test="updateBy != null">update_by = #{updateBy},</if>
  722. <if test="updateTime != null">update_time = #{updateTime},</if>
  723. <if test="remark != null">remark = #{remark},</if>
  724. </trim>
  725. where id = #{id}
  726. </update>
  727. <delete id="deleteActHxpapplyById">
  728. delete from act_hxpapply where id = #{id}
  729. </delete>
  730. <delete id="deleteActHxpapplyByIds">
  731. delete from act_hxpapply where id in
  732. <foreach item="id" collection="array" open="(" separator="," close=")">
  733. #{id}
  734. </foreach>
  735. </delete>
  736. </mapper>