ActHxpapplyMapper.xml 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  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 t1.`chemical_id`,SUM(IFNULL(t1.`chemical_amount`,0)-IFNULL(t1.`tare`,0)) applyNum from(
  385. SELECT DISTINCT cjc.id,hd.`chemical_id`,cjc.chemical_amount,cjc.tare
  386. FROM act_hxpapply ah LEFT JOIN act_hxpapply_detail hd ON ah.`id` = hd.`hxpapply_id`
  387. LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
  388. LEFT JOIN lab_subject st ON ah.sub_id = st.id
  389. inner join hxp_chemical_join_cabinet cjc on hd.`cabinet_id` = cjc.`cabinet_id` and hd.`chemical_id` = cjc.`chemical_id`
  390. <where>
  391. ak.`approval_status`=1 AND hd.`tick_status`=1
  392. <if test="deptId != null ">
  393. AND st.dept_id = #{deptId}
  394. </if>
  395. <if test="subId != null ">
  396. AND ah.sub_id = #{subId}
  397. </if>
  398. <if test="chemicalId != null ">
  399. AND hd.`chemical_id` = #{chemicalId}
  400. </if>
  401. <if test="cabinetId != null ">
  402. AND hd.`cabinet_id` = #{cabinetId}
  403. </if>
  404. <if test="applyUserId != null ">
  405. AND ah.`user_id` = #{applyUserId} AND cjc.`user_id` = #{applyUserId}
  406. </if>
  407. </where>
  408. )t1
  409. GROUP BY t1.`chemical_id`
  410. )x2 ON x1.chemical_id = x2.chemical_id
  411. <!-- SELECT x1.chemical_id chemicalId,CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0)),'g') restStock FROM (
  412. 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`
  413. LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
  414. LEFT JOIN lab_subject st ON ah.sub_id = st.id
  415. <where>
  416. ak.`approval_status`=1 AND hd.`tick_status`=1
  417. <if test="deptId != null ">
  418. and st.dept_id = #{deptId}
  419. </if>
  420. <if test="subId != null ">
  421. and ah.sub_id = #{subId}
  422. </if>
  423. <if test="chemicalId != null ">
  424. and hd.`chemical_id` = #{chemicalId}
  425. </if>
  426. <if test="cabinetId != null ">
  427. and hd.`cabinet_id` = #{cabinetId}
  428. </if>
  429. </where>
  430. GROUP BY hd.`chemical_id`
  431. )x1 LEFT JOIN
  432. (
  433. SELECT cjc.`chemical_id`,SUM(s.usages-s.tare) stockNum FROM hxp_stock s
  434. LEFT JOIN hxp_chemical_join_cabinet cjc ON s.`join_id` = cjc.`id`
  435. LEFT JOIN lab_subject st ON s.sub_id = st.id
  436. <where>
  437. s.status = 1
  438. <if test="deptId != null ">
  439. and st.dept_id = #{deptId}
  440. </if>
  441. <if test="subId != null ">
  442. and s.sub_id = #{subId}
  443. </if>
  444. <if test="chemicalId != null ">
  445. and cjc.`chemical_id` = #{chemicalId}
  446. </if>
  447. <if test="cabinetId != null ">
  448. and cjc.`cabinet_id` = #{cabinetId}
  449. </if>
  450. </where>
  451. GROUP BY cjc.`chemical_id`
  452. )x2 ON x1.chemical_id = x2.chemical_id-->
  453. </select>
  454. <select id="getRestStockClassif" resultType="com.zd.chemical.domain.vo.ActRestStockVo">
  455. SELECT 1 chemicalId,CONCAT(IFNULL(x1.stockNum,0),'g') restStock FROM (
  456. SELECT cjc.`chemical_id`,SUM(s.usages-s.tare) stockNum FROM hxp_stock s
  457. LEFT JOIN hxp_chemical_join_cabinet cjc ON s.`join_id` = cjc.`id`
  458. LEFT JOIN lab_subject st ON s.sub_id = st.id
  459. <where>
  460. s.status = 1
  461. <if test="deptId != null ">
  462. AND st.dept_id = #{deptId}
  463. </if>
  464. <if test="chemicalId != null ">
  465. AND cjc.`chemical_id` = #{chemicalId}
  466. </if>
  467. </where>
  468. GROUP BY cjc.`chemical_id`
  469. )x1
  470. UNION ALL
  471. SELECT 2 chemicalId,CONCAT(IFNULL(x1.stockNum,0),'g') restStock FROM (
  472. SELECT cjc.`chemical_id`,SUM(s.usages-s.tare) stockNum FROM hxp_stock s
  473. LEFT JOIN hxp_chemical_join_cabinet cjc ON s.`join_id` = cjc.`id`
  474. LEFT JOIN lab_subject st ON s.sub_id = st.id
  475. <where>
  476. s.status = 1
  477. <if test="subId != null ">
  478. AND s.sub_id = #{subId}
  479. </if>
  480. <if test="chemicalId != null ">
  481. AND cjc.`chemical_id` = #{chemicalId}
  482. </if>
  483. </where>
  484. GROUP BY cjc.`chemical_id`
  485. )x1
  486. UNION ALL
  487. SELECT 3 chemicalId,CONCAT(IFNULL(x1.stockNum,0),'g') restStock FROM (
  488. SELECT cjc.`chemical_id`,SUM(s.usages-s.tare) stockNum FROM hxp_stock s
  489. LEFT JOIN hxp_chemical_join_cabinet cjc ON s.`join_id` = cjc.`id`
  490. LEFT JOIN lab_subject st ON s.sub_id = st.id
  491. <where>
  492. s.status = 1
  493. <if test="chemicalId != null ">
  494. AND cjc.`chemical_id` = #{chemicalId}
  495. </if>
  496. <if test="cabinetId != null ">
  497. AND cjc.`cabinet_id` = #{cabinetId}
  498. </if>
  499. </where>
  500. GROUP BY cjc.`chemical_id`
  501. )x1
  502. UNION ALL
  503. SELECT 4 chemicalId,CASE WHEN CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.applyNum,0)),'g')>0
  504. THEN CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.applyNum,0)),'g') ELSE CONCAT(0,'g') END restStock FROM (
  505. 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`
  506. LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
  507. LEFT JOIN lab_subject st ON ah.sub_id = st.id
  508. <where>
  509. ak.`approval_status`=1 AND hd.`tick_status`=1
  510. <if test="deptId != null ">
  511. AND st.dept_id = #{deptId}
  512. </if>
  513. <if test="subId != null ">
  514. AND ah.sub_id = #{subId}
  515. </if>
  516. <if test="chemicalId != null ">
  517. AND hd.`chemical_id` = #{chemicalId}
  518. </if>
  519. <if test="cabinetId != null ">
  520. AND hd.`cabinet_id` = #{cabinetId}
  521. </if>
  522. <if test="applyUserId != null ">
  523. AND ah.`user_id` = #{applyUserId}
  524. </if>
  525. </where>
  526. GROUP BY hd.`chemical_id`
  527. )x1 LEFT JOIN
  528. (
  529. SELECT t1.`chemical_id`,SUM(IFNULL(t1.`chemical_amount`,0)-IFNULL(t1.`tare`,0)) applyNum FROM(
  530. SELECT DISTINCT hd.`chemical_id`,cjc.`chemical_amount`,cjc.`tare`
  531. FROM act_hxpapply ah LEFT JOIN act_hxpapply_detail hd ON ah.`id` = hd.`hxpapply_id`
  532. LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
  533. LEFT JOIN lab_subject st ON ah.sub_id = st.id
  534. inner join hxp_chemical_join_cabinet cjc on hd.`cabinet_id` = cjc.`cabinet_id` and hd.`chemical_id` = cjc.`chemical_id`
  535. <where>
  536. ak.`approval_status`=1 AND hd.`tick_status`=1
  537. <if test="deptId != null ">
  538. AND st.dept_id = #{deptId}
  539. </if>
  540. <if test="subId != null ">
  541. AND ah.sub_id = #{subId}
  542. </if>
  543. <if test="chemicalId != null ">
  544. AND hd.`chemical_id` = #{chemicalId}
  545. </if>
  546. <if test="cabinetId != null ">
  547. AND hd.`cabinet_id` = #{cabinetId}
  548. </if>
  549. <if test="applyUserId != null ">
  550. AND ah.`user_id` = #{applyUserId} AND cjc.`user_id` = #{applyUserId}
  551. </if>
  552. </where>
  553. )t1
  554. GROUP BY t1.`chemical_id`
  555. )x2 ON x1.chemical_id = x2.chemical_id
  556. </select>
  557. <select id="getRestStockByManyCabinet" parameterType="com.zd.chemical.domain.vo.ActRestStockManySearch" resultType="com.zd.chemical.domain.vo.ActRestStockManyVo">
  558. <!--SELECT x1.cabinet_id cabinetId,CASE WHEN CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0)))>0
  559. THEN CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0))) ELSE 0 END restStock FROM (
  560. 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`
  561. LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
  562. LEFT JOIN lab_subject st ON ah.sub_id = st.id
  563. <where>
  564. ak.`approval_status`=1 AND hd.`tick_status`=1
  565. <if test="chemicalId != null ">
  566. and hd.`chemical_id` = #{chemicalId}
  567. </if>
  568. <if test="cabinetIds != null ">
  569. and hd.`cabinet_id` in
  570. <foreach item="id" collection="cabinetIds" open="(" separator="," close=")">
  571. #{id}
  572. </foreach>
  573. </if>
  574. </where>
  575. GROUP BY hd.`cabinet_id`
  576. )x1 LEFT JOIN
  577. (
  578. SELECT cjc.`cabinet_id`,SUM(cjc.chemical_amount-cjc.tare) stockNum FROM
  579. hxp_chemical_join_cabinet cjc
  580. <where>
  581. cjc.`status` IN(0,1)
  582. <if test="chemicalId != null ">
  583. and cjc.`chemical_id` = #{chemicalId}
  584. </if>
  585. <if test="cabinetIds != null ">
  586. and cjc.`cabinet_id` in
  587. <foreach item="id" collection="cabinetIds" open="(" separator="," close=")">
  588. #{id}
  589. </foreach>
  590. </if>
  591. </where>
  592. GROUP BY cjc.`cabinet_id`
  593. )x2 ON x1.cabinet_id = x2.cabinet_id
  594. -->
  595. SELECT x1.cabinet_id cabinetId,CASE WHEN CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0)))>0
  596. THEN CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0))) ELSE 0 END restStock FROM (
  597. 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`
  598. LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
  599. LEFT JOIN lab_subject st ON ah.sub_id = st.id
  600. <where>
  601. ak.`approval_status`=1 AND hd.`tick_status`=1
  602. <if test="chemicalId != null ">
  603. and hd.`chemical_id` = #{chemicalId}
  604. </if>
  605. <if test="cabinetIds != null ">
  606. and hd.`cabinet_id` in
  607. <foreach item="id" collection="cabinetIds" open="(" separator="," close=")">
  608. #{id}
  609. </foreach>
  610. </if>
  611. <if test="applyUserId != null ">
  612. AND ah.`user_id` = #{applyUserId}
  613. </if>
  614. </where>
  615. GROUP BY hd.`cabinet_id`
  616. )x1 LEFT JOIN
  617. (
  618. SELECT t1.`chemical_id`,t1.`cabinet_id`,SUM(t1.chemical_amount-t1.tare) stockNum from(
  619. select distinct cjc.id,cjc.`chemical_id`,cjc.`cabinet_id`,cjc.chemical_amount,cjc.tare FROM
  620. act_hxpapply ah LEFT JOIN act_hxpapply_detail hd ON ah.`id` = hd.`hxpapply_id`
  621. LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
  622. INNER JOIN hxp_chemical_join_cabinet cjc ON hd.`cabinet_id` = cjc.`cabinet_id` AND hd.`chemical_id` = cjc.`chemical_id`
  623. <where>
  624. ak.`approval_status`=1 AND hd.`tick_status`=1
  625. <if test="chemicalId != null ">
  626. and cjc.`chemical_id` = #{chemicalId}
  627. </if>
  628. <if test="cabinetIds != null ">
  629. and cjc.`cabinet_id` in
  630. <foreach item="id" collection="cabinetIds" open="(" separator="," close=")">
  631. #{id}
  632. </foreach>
  633. </if>
  634. <if test="applyUserId != null ">
  635. AND ah.`user_id` = #{applyUserId} AND cjc.`user_id` = #{applyUserId}
  636. </if>
  637. </where>
  638. )t1
  639. GROUP BY t1.`cabinet_id`
  640. )x2 ON x1.cabinet_id = x2.cabinet_id
  641. </select>
  642. <select id="getRestStockByManyCabinetAndChemical" parameterType="com.zd.chemical.domain.vo.ActRestStockManySearch" resultType="com.zd.chemical.domain.vo.ActRestStockManyVo">
  643. SELECT x1.chemical_id chemicalId,x1.cabinet_id cabinetId,CASE WHEN CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0)))>0
  644. THEN CONCAT((IFNULL(x1.applyNum,0)-IFNULL(x2.stockNum,0))) ELSE 0 END restStock FROM (
  645. 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`
  646. LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
  647. LEFT JOIN lab_subject st ON ah.sub_id = st.id
  648. WHERE
  649. ak.`approval_status`=1 AND hd.`tick_status`=1
  650. <if test="chemicalIds != null ">
  651. AND hd.`chemical_id` IN
  652. <foreach item="id" collection="chemicalIds" open="(" separator="," close=")">
  653. #{id}
  654. </foreach>
  655. </if>
  656. <if test="cabinetIds != null ">
  657. AND hd.`cabinet_id` IN
  658. <foreach item="id" collection="cabinetIds" open="(" separator="," close=")">
  659. #{id}
  660. </foreach>
  661. </if>
  662. <if test="applyUserId != null ">
  663. AND ah.`user_id` = #{applyUserId}
  664. </if>
  665. GROUP BY hd.`chemical_id`,hd.`cabinet_id`
  666. )x1 LEFT JOIN
  667. (
  668. SELECT t1.`chemical_id`,t1.`cabinet_id`,SUM(t1.chemical_amount-t1.tare) stockNum FROM(
  669. SELECT DISTINCT cjc.id,cjc.`chemical_id`,cjc.`cabinet_id`,cjc.chemical_amount,cjc.tare FROM
  670. act_hxpapply ah LEFT JOIN act_hxpapply_detail hd ON ah.`id` = hd.`hxpapply_id`
  671. LEFT JOIN act_applytask ak ON ah.`id` = ak.`task_id`
  672. INNER JOIN hxp_chemical_join_cabinet cjc ON hd.`cabinet_id` = cjc.`cabinet_id` AND hd.`chemical_id` = cjc.`chemical_id`
  673. WHERE
  674. ak.`approval_status`=1 AND hd.`tick_status`=1
  675. <if test="chemicalIds != null ">
  676. AND cjc.`chemical_id` IN
  677. <foreach item="id" collection="chemicalIds" open="(" separator="," close=")">
  678. #{id}
  679. </foreach>
  680. </if>
  681. <if test="cabinetIds != null ">
  682. AND cjc.`cabinet_id` IN
  683. <foreach item="id" collection="cabinetIds" open="(" separator="," close=")">
  684. #{id}
  685. </foreach>
  686. </if>
  687. <if test="applyUserId != null ">
  688. AND ah.`user_id` = #{applyUserId} AND cjc.`user_id` = #{applyUserId}
  689. </if>
  690. )t1
  691. GROUP BY t1.`chemical_id`,t1.`cabinet_id`
  692. )x2 ON x1.chemical_id = x2.chemical_id AND x1.cabinet_id = x2.cabinet_id
  693. </select>
  694. <insert id="insertActHxpapply" parameterType="com.zd.chemical.domain.ActHxpapply" useGeneratedKeys="true" keyProperty="id">
  695. insert into act_hxpapply
  696. <trim prefix="(" suffix=")" suffixOverrides=",">
  697. <if test="applyNum != null">apply_num,</if>
  698. <if test="applyReason != null">apply_reason,</if>
  699. <if test="subId != null">sub_id,</if>
  700. <if test="applyStatus != null">apply_status,</if>
  701. <if test="userId != null">user_id,</if>
  702. <if test="createBy != null">create_by,</if>
  703. <if test="createTime != null">create_time,</if>
  704. <if test="updateBy != null">update_by,</if>
  705. <if test="updateTime != null">update_time,</if>
  706. <if test="remark != null">remark,</if>
  707. </trim>
  708. <trim prefix="values (" suffix=")" suffixOverrides=",">
  709. <if test="applyNum != null">#{applyNum},</if>
  710. <if test="applyReason != null">#{applyReason},</if>
  711. <if test="subId != null">#{subId},</if>
  712. <if test="applyStatus != null">#{applyStatus},</if>
  713. <if test="userId != null">#{userId},</if>
  714. <if test="createBy != null">#{createBy},</if>
  715. <if test="createTime != null">#{createTime},</if>
  716. <if test="updateBy != null">#{updateBy},</if>
  717. <if test="updateTime != null">#{updateTime},</if>
  718. <if test="remark != null">#{remark},</if>
  719. </trim>
  720. </insert>
  721. <update id="updateActHxpapply" parameterType="com.zd.chemical.domain.ActHxpapply">
  722. update act_hxpapply
  723. <trim prefix="SET" suffixOverrides=",">
  724. <if test="applyNum != null">apply_num = #{applyNum},</if>
  725. <if test="applyReason != null">apply_reason = #{applyReason},</if>
  726. <if test="subId != null">sub_id = #{subId},</if>
  727. <if test="applyStatus != null">apply_status = #{applyStatus},</if>
  728. <if test="userId != null">user_id = #{userId},</if>
  729. <if test="createBy != null">create_by = #{createBy},</if>
  730. <if test="createTime != null">create_time = #{createTime},</if>
  731. <if test="updateBy != null">update_by = #{updateBy},</if>
  732. <if test="updateTime != null">update_time = #{updateTime},</if>
  733. <if test="remark != null">remark = #{remark},</if>
  734. </trim>
  735. where id = #{id}
  736. </update>
  737. <delete id="deleteActHxpapplyById">
  738. delete from act_hxpapply where id = #{id}
  739. </delete>
  740. <delete id="deleteActHxpapplyByIds">
  741. delete from act_hxpapply where id in
  742. <foreach item="id" collection="array" open="(" separator="," close=")">
  743. #{id}
  744. </foreach>
  745. </delete>
  746. </mapper>