PurchaseApplyServiceDaoImplMapper.xml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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="purchaseApplyServiceDaoImpl">
  6. <resultMap type="com.java110.dto.purchaseApply.PurchaseApplyDto" id="applyMap">
  7. <id column="applyOrderId" property="applyOrderId"/>
  8. <result column="description" property="description"/>
  9. <result column="resOrderType" property="resOrderType"/>
  10. <result column="statusCd" property="statusCd"/>
  11. <result column="state" property="state"/>
  12. <result column="storeId" property="storeId"/>
  13. <result column="userName" property="userName"/>
  14. <result column="bId" property="bId"/>
  15. <result column="userId" property="userId"/>
  16. <result column="createTime" property="createTime"/>
  17. <result column="stateName" property="stateName"/>
  18. <result column="endUserName" property="endUserName"/>
  19. <result column="endUserTel" property="endUserTel"/>
  20. <result column="communityId" property="communityId"/>
  21. <!-- 一对多关系 -->
  22. <collection property="purchaseApplyDetailVo" ofType="com.java110.vo.api.purchaseApply.PurchaseApplyDetailVo"
  23. javaType="java.util.ArrayList">
  24. <id property="id" column="id"/>
  25. <result property="applyOrderId" column="applyOrderId"/>
  26. <result property="resId" column="resId"/>
  27. <result column="rsId" property="rsId"/>
  28. <result property="quantity" column="quantity"/>
  29. <result property="resName" column="resName"/>
  30. <result property="remark" column="remark"/>
  31. <result property="resCode" column="resCode"/>
  32. <result property="price" column="price"/>
  33. <result property="stock" column="stock"/>
  34. <result property="description" column="description"/>
  35. </collection>
  36. </resultMap>
  37. <!-- 保存采购申请信息 add by wuxw 2018-07-03 -->
  38. <insert id="saveBusinessPurchaseApplyInfo" parameterType="Map">
  39. insert into business_purchase_apply
  40. (operate,res_order_type,description,apply_order_id,state,store_id,user_id,user_name,b_id,end_user_name,end_user_tel,community_id)
  41. values
  42. (#{operate},#{resOrderType},#{description},#{applyOrderId},#{state},#{storeId},#{userId},#{userName},#{bId},#{endUserName},#{endUserTel},#{communityId})
  43. </insert>
  44. <!-- 保存采购明细表备份表 -->
  45. <insert id="saveBusinessPurchaseApplyDetailInfo" parameterType="List">
  46. insert into business_purchase_apply_detail (apply_order_id,res_id,quantity,remark,b_id,operate,status_cd)
  47. values
  48. <foreach collection="list" item="item" index="index" separator=",">
  49. (
  50. #{item.applyOrderId},
  51. #{item.resId},
  52. #{item.quantity},
  53. #{item.remark},
  54. #{item.bId},
  55. #{item.operate},
  56. #{item.statusCd}
  57. )
  58. </foreach>
  59. </insert>
  60. <!-- 保存采购明细表-->
  61. <insert id="savePurchaseApplyDetailInfo" parameterType="List">
  62. insert into purchase_apply_detail
  63. (id,rs_id,apply_order_id,res_id,quantity,remark,b_id,operate,status_cd,price,purchase_quantity,purchase_remark,original_stock,times_id)
  64. values
  65. <foreach collection="list" item="item" index="index" separator=",">
  66. (
  67. #{item.id},
  68. #{item.rsId},
  69. #{item.applyOrderId},
  70. #{item.resId},
  71. #{item.quantity},
  72. #{item.remark},
  73. '-1',
  74. 'ADD',
  75. '0',
  76. #{item.price},
  77. #{item.purchaseQuantity},
  78. #{item.purchaseRemark},
  79. #{item.originalStock},
  80. #{item.timesId}
  81. )
  82. </foreach>
  83. </insert>
  84. <!-- 查询采购申请信息(Business) add by wuxw 2018-07-03 -->
  85. <select id="getBusinessPurchaseApplyInfo" parameterType="Map" resultType="Map">
  86. select
  87. t.operate,
  88. t.res_order_type,
  89. t.res_order_type resOrderType,
  90. t.description,
  91. t.apply_order_id,
  92. t.apply_order_id applyOrderId,
  93. t.state,
  94. t.store_id,
  95. t.store_id storeId,
  96. t.user_name userName,
  97. t.b_id bId,
  98. t.b_id,
  99. t.user_id,
  100. t.user_id userId,
  101. t.status_cd statusCd,
  102. t.end_user_name,
  103. t.end_user_tel,
  104. t.end_user_name endUserName,
  105. t.end_user_tel endUserTel,
  106. t.community_id communityId
  107. from business_purchase_apply t
  108. where 1 =1
  109. <if test="operate !=null and operate != ''">
  110. and t.operate= #{operate}
  111. </if>
  112. <if test="resOrderType !=null and resOrderType != ''">
  113. and t.res_order_type= #{resOrderType}
  114. </if>
  115. <if test="description !=null and description != ''">
  116. and t.description= #{description}
  117. </if>
  118. <if test="applyOrderId !=null and applyOrderId != ''">
  119. and t.apply_order_id= #{applyOrderId}
  120. </if>
  121. <if test="state !=null and state != ''">
  122. and t.state= #{state}
  123. </if>
  124. <if test="storeId !=null and storeId != ''">
  125. and t.store_id= #{storeId}
  126. </if>
  127. <if test="bId !=null and bId != ''">
  128. and t.b_id= #{bId}
  129. </if>
  130. <if test="userId !=null and userId != ''">
  131. and t.user_id= #{userId}
  132. </if>
  133. <if test="endUserName !=null and endUserName != ''">
  134. and t.end_user_name= #{endUserName}
  135. </if>
  136. <if test="endUserTel !=null and endUserTel != ''">
  137. and t.end_user_tel= #{endUserTel}
  138. </if>
  139. <if test="communityId !=null and communityId != ''">
  140. and t.community_id= #{communityId}
  141. </if>
  142. </select>
  143. <select id="getBusinessPurchaseApplyDetailInfo" parameterType="Map" resultType="Map">
  144. select
  145. t.apply_order_id applyOrderId,t.b_id bId,t.res_id resId,t.quantity,t.remark,t.operate,t.status_cd statusCd
  146. from business_purchase_apply_detail t
  147. where 1 =1
  148. <if test="operate !=null and operate != ''">
  149. and t.operate= #{operate}
  150. </if>
  151. <if test="description !=null and description != ''">
  152. and t.description= #{description}
  153. </if>
  154. <if test="applyOrderId !=null and applyOrderId != ''">
  155. and t.apply_order_id= #{applyOrderId}
  156. </if>
  157. <if test="bId !=null and bId != ''">
  158. and t.b_id= #{bId}
  159. </if>
  160. </select>
  161. <!-- 保存采购申请信息至 instance表中 add by wuxw 2018-07-03 -->
  162. <insert id="savePurchaseApplyInfoInstance" parameterType="Map">
  163. insert into purchase_apply
  164. (res_order_type,description,apply_order_id,status_cd,state,store_id,user_name,b_id,user_id,end_user_name,end_user_tel,community_id)
  165. select
  166. t.res_order_type,t.description,t.apply_order_id,'0',t.state,t.store_id,t.user_name,t.b_id,t.user_id,t.end_user_name,t.end_user_tel,
  167. t.community_id
  168. from business_purchase_apply t where 1=1
  169. and t.operate= 'ADD'
  170. <if test="resOrderType !=null and resOrderType != ''">
  171. and t.res_order_type= #{resOrderType}
  172. </if>
  173. <if test="description !=null and description != ''">
  174. and t.description= #{description}
  175. </if>
  176. <if test="applyOrderId !=null and applyOrderId != ''">
  177. and t.apply_order_id= #{applyOrderId}
  178. </if>
  179. <if test="state !=null and state != ''">
  180. and t.state= #{state}
  181. </if>
  182. <if test="storeId !=null and storeId != ''">
  183. and t.store_id= #{storeId}
  184. </if>
  185. <if test="bId !=null and bId != ''">
  186. and t.b_id= #{bId}
  187. </if>
  188. <if test="userId !=null and userId != ''">
  189. and t.user_id= #{userId}
  190. </if>
  191. <if test="communityId !=null and communityId != ''">
  192. and t.community_id= #{communityId}
  193. </if>
  194. </insert>
  195. <!-- 查询采购申请信息 add by wuxw 2018-07-03 -->
  196. <select id="getPurchaseApplyInfo" parameterType="Map" resultType="Map">
  197. select
  198. t.res_order_type resOrderType,t.description,
  199. t.apply_order_id applyOrderId,t.status_cd statusCd,t.state,
  200. t.store_id storeId,t.user_name userName,
  201. t.b_id bId,t.user_id userId,t.create_time createTime,d.name stateName,
  202. t.end_user_name,
  203. t.end_user_tel,
  204. t.end_user_name endUserName,
  205. t.end_user_tel endUserTel,
  206. t.description,
  207. t.create_user_id createUserId,
  208. t.create_user_name createUserName,
  209. t.warehousing_way warehousingWay,
  210. t.community_id communityId
  211. from purchase_apply t
  212. inner join t_dict d on t.state = d.status_cd and d.table_name = 'purchase_apply' and d.table_columns = 'state'
  213. where 1 = 1
  214. <if test="resOrderType !=null and resOrderType != ''">
  215. and t.res_order_type= #{resOrderType}
  216. </if>
  217. <if test="description !=null and description != ''">
  218. and t.description= #{description}
  219. </if>
  220. <if test="applyOrderId !=null and applyOrderId != ''">
  221. and t.apply_order_id= #{applyOrderId}
  222. </if>
  223. <if test="applyOrderIds !=null ">
  224. and t.apply_order_id in
  225. <foreach open="(" close=")"
  226. separator="," collection="applyOrderIds" item="item">
  227. #{item}
  228. </foreach>
  229. </if>
  230. <if test="userName !=null and userName != ''">
  231. and t.user_name like concat('%',#{userName},'%')
  232. </if>
  233. <if test="statusCd !=null and statusCd != ''">
  234. and t.status_cd= #{statusCd}
  235. </if>
  236. <if test="state !=null and state != ''">
  237. and t.state= #{state}
  238. </if>
  239. <if test="storeId !=null and storeId != ''">
  240. and t.store_id= #{storeId}
  241. </if>
  242. <if test="bId !=null and bId != ''">
  243. and t.b_id= #{bId}
  244. </if>
  245. <if test="endUserName !=null and endUserName != ''">
  246. and t.end_user_name= #{endUserName}
  247. </if>
  248. <if test="endUserTel !=null and endUserTel != ''">
  249. and t.end_user_tel= #{endUserTel}
  250. </if>
  251. <if test="userId !=null and userId != ''">
  252. and t.user_id= #{userId}
  253. </if>
  254. <if test="communityId !=null and communityId != ''">
  255. and t.community_id= #{communityId}
  256. </if>
  257. order by t.create_time desc
  258. <if test="page != -1 and page != null ">
  259. limit #{page}, #{row}
  260. </if>
  261. </select>
  262. <select id="getPurchaseApplyInfo2" parameterType="Map" resultMap="applyMap">
  263. select
  264. t.res_order_type resOrderType,t.description,
  265. t.apply_order_id applyOrderId,t.status_cd statusCd,t.state,
  266. t.store_id storeId,t.user_name userName,
  267. t.b_id bId,t.user_id userId,t.create_time createTime,d.name stateName,
  268. de.apply_order_id applyOrderId,de.res_id resId,de.quantity,de.remark,rs.res_name
  269. resName,rs.price,rs.stock,rs.res_code resCode,rs.description,
  270. t.end_user_name,
  271. t.end_user_tel,
  272. t.end_user_name endUserName,
  273. t.end_user_tel endUserTel,
  274. t.community_id communityId
  275. from purchase_apply t
  276. inner join t_dict d on t.state = d.status_cd and d.table_name = 'purchase_apply' and d.table_columns = 'state'
  277. inner join purchase_apply_detail de on de.apply_order_id = t.apply_order_id
  278. inner join resource_store rs on de.res_id = rs.res_id
  279. where 1 =1
  280. <if test="resOrderType !=null and resOrderType != ''">
  281. and t.res_order_type= #{resOrderType}
  282. </if>
  283. <if test="applyOrderId !=null and applyOrderId != ''">
  284. and t.apply_order_id= #{applyOrderId}
  285. </if>
  286. <if test="statusCd !=null and statusCd != ''">
  287. and t.status_cd= #{statusCd}
  288. </if>
  289. <if test="state !=null and state != ''">
  290. and t.state= #{state}
  291. </if>
  292. <if test="storeId !=null and storeId != ''">
  293. and t.store_id= #{storeId}
  294. </if>
  295. <if test="bId !=null and bId != ''">
  296. and t.b_id= #{bId}
  297. </if>
  298. <if test="endUserName !=null and endUserName != ''">
  299. and t.end_user_name= #{endUserName}
  300. </if>
  301. <if test="endUserTel !=null and endUserTel != ''">
  302. and t.end_user_tel= #{endUserTel}
  303. </if>
  304. <if test="communityId !=null and communityId != ''">
  305. and t.community_id= #{communityId}
  306. </if>
  307. order by t.create_time desc
  308. <if test="page != -1 and page != null ">
  309. limit #{page}, #{row}
  310. </if>
  311. </select>
  312. <!-- 查询采购明细 -->
  313. <select id="getPurchaseApplyDetailInfo" parameterType="Map" resultType="Map">
  314. select
  315. p.id,
  316. p.apply_order_id applyOrderId,
  317. p.res_id resId,p.quantity,p.remark,p.purchase_quantity purchaseQuantity,p.purchase_remark purchaseRemark,p.price
  318. purchasePrice,p.original_stock originalStock,
  319. r.res_name resName,r.res_code resCode,
  320. r.price,r.price standardPrice,rstime.stock,rst.name rstName,rst1.name parentRstName,rss.spec_name specName,rs.supplier_name supplierName,
  321. td1.name unitCodeName,
  322. td2.name miniUnitCodeName
  323. from
  324. purchase_apply_detail p
  325. inner join resource_store r on p.res_id = r.res_id and r.status_cd = '0'
  326. left join t_dict td1 on r.unit_code = td1.status_cd and td1.table_name = 'resource_store' and td1.table_columns = 'unit_code'
  327. left join t_dict td2 on r.mini_unit_code = td2.status_cd and td2.table_name = 'resource_store' and td2.table_columns = 'unit_code'
  328. LEFT JOIN resource_supplier rs on p.rs_id=rs.rs_id
  329. LEFT JOIN resource_store_type rst on r.rst_id=rst.rst_id
  330. LEFT JOIN resource_store_type rst1 on r.parent_rst_id=rst1.rst_id
  331. LEFT JOIN resource_store_specification rss on r.rss_id=rss.rss_id
  332. left join resource_store_times rstime on p.times_id = rstime.times_id and rstime.status_cd = '0'
  333. where 1=1
  334. and p.status_cd = '0'
  335. <if test="applyOrderIds !=null">
  336. and p.apply_order_id in
  337. <foreach collection="applyOrderIds" item="item" open="(" close=")" separator=",">
  338. #{item}
  339. </foreach>
  340. </if>
  341. <if test="resOrderType !=null and resOrderType != ''">
  342. and t.res_order_type= #{resOrderType}
  343. </if>
  344. <if test="bId !=null and bId != ''">
  345. and p.b_id= #{bId}
  346. </if>
  347. <if test="operate !=null and operate != ''">
  348. and p.operate= #{operate}
  349. </if>
  350. </select>
  351. <!-- 修改采购申请信息 add by wuxw 2018-07-03 -->
  352. <update id="updatePurchaseApplyInfoInstance" parameterType="Map">
  353. update purchase_apply t set t.status_cd = #{statusCd}
  354. <if test="newBId != null and newBId != ''">
  355. ,t.b_id = #{newBId}
  356. </if>
  357. <if test="applyDetailId !=null and applyDetailId != ''">
  358. , t.apply_detail_id= #{applyDetailId}
  359. </if>
  360. <if test="resOrderType !=null and resOrderType != ''">
  361. , t.res_order_type= #{resOrderType}
  362. </if>
  363. <if test="description !=null and description != ''">
  364. , t.description= #{description}
  365. </if>
  366. <if test="state !=null and state != ''">
  367. , t.state= #{state}
  368. </if>
  369. <if test="storeId !=null and storeId != ''">
  370. , t.store_id= #{storeId}
  371. </if>
  372. <if test="userId !=null and userId != ''">
  373. , t.user_id= #{userId}
  374. </if>
  375. <if test="endUserName !=null and endUserName != ''">
  376. , t.end_user_name= #{endUserName}
  377. </if>
  378. <if test="endUserTel !=null and endUserTel != ''">
  379. , t.end_user_tel= #{endUserTel}
  380. </if>
  381. <if test="communityId !=null and communityId != ''">
  382. , t.community_id= #{communityId}
  383. </if>
  384. where 1=1
  385. <if test="applyOrderId !=null and applyOrderId != ''">
  386. and t.apply_order_id= #{applyOrderId}
  387. </if>
  388. <if test="bId !=null and bId != ''">
  389. and t.b_id= #{bId}
  390. </if>
  391. </update>
  392. <!-- 查询采购申请数量 add by wuxw 2018-07-03 -->
  393. <select id="queryPurchaseApplysCount" parameterType="Map" resultType="Map">
  394. select count(1) count
  395. from purchase_apply t
  396. where 1 = 1
  397. <if test="resOrderType !=null and resOrderType != ''">
  398. and t.res_order_type= #{resOrderType}
  399. </if>
  400. <if test="description !=null and description != ''">
  401. and t.description= #{description}
  402. </if>
  403. <if test="applyOrderId !=null and applyOrderId != ''">
  404. and t.apply_order_id= #{applyOrderId}
  405. </if>
  406. <if test="applyOrderIds !=null ">
  407. and t.apply_order_id in
  408. <foreach open="(" close=")"
  409. separator="," collection="applyOrderIds" item="item">
  410. #{item}
  411. </foreach>
  412. </if>
  413. <if test="userName !=null and userName != ''">
  414. and t.user_name like concat('%',#{userName},'%')
  415. </if>
  416. <if test="statusCd !=null and statusCd != ''">
  417. and t.status_cd= #{statusCd}
  418. </if>
  419. <if test="warehousingWay !=null and warehousingWay != ''">
  420. and t.warehousing_way= #{warehousingWay}
  421. </if>
  422. <if test="state !=null and state != ''">
  423. and t.state= #{state}
  424. </if>
  425. <if test="storeId !=null and storeId != ''">
  426. and t.store_id= #{storeId}
  427. </if>
  428. <if test="bId !=null and bId != ''">
  429. and t.b_id= #{bId}
  430. </if>
  431. <if test="endUserName !=null and endUserName != ''">
  432. and t.end_user_name= #{endUserName}
  433. </if>
  434. <if test="endUserTel !=null and endUserTel != ''">
  435. and t.end_user_tel= #{endUserTel}
  436. </if>
  437. <if test="userId !=null and userId != ''">
  438. and t.user_id= #{userId}
  439. </if>
  440. <if test="communityId !=null and communityId != ''">
  441. and t.community_id = #{communityId}
  442. </if>
  443. <if test='urgentFlag !=null and urgentFlag == "1"'>
  444. and date_format(t.create_time,'%Y-%m') = date_format(now(),'%Y-%m')
  445. </if>
  446. </select>
  447. <!-- 保存采购申请信息 add by wuxw 2018-07-03 -->
  448. <insert id="savePurchaseApply" parameterType="Map">
  449. insert into purchase_apply
  450. (status_cd,res_order_type,description,apply_order_id,state,store_id,user_id,user_name,b_id,end_user_name,end_user_tel,
  451. create_time,create_user_id,create_user_name,warehousing_way,community_id)
  452. values
  453. ('0',#{resOrderType},#{description},#{applyOrderId},#{state},#{storeId},#{userId},#{userName},'-1',#{endUserName},#{endUserTel},
  454. #{createTime},#{createUserId},#{createUserName},#{warehousingWay},#{communityId})
  455. </insert>
  456. <!--查询下级用户id-->
  457. <select id="getActRuTaskUserId" parameterType="Map" resultType="Map">
  458. SELECT ASSIGNEE_ taskUserId FROM ACT_RU_TASK t
  459. LEFT JOIN ACT_HI_PROCINST ahp on t.PROC_INST_ID_=ahp.ID_
  460. LEFT JOIN ACT_RU_EXECUTION are on t.EXECUTION_ID_=are.ID_
  461. where 1 = 1
  462. <if test="actRuTaskId !=null and actRuTaskId != ''">
  463. and ahp.ID_ = #{actRuTaskId}
  464. </if>
  465. <if test="procDefId !=null and procDefId != ''">
  466. and t.PROC_DEF_ID_ = #{procDefId}
  467. </if>
  468. <if test="businessKey !=null and businessKey != ''">
  469. and ahp.BUSINESS_KEY_ = #{businessKey}
  470. </if>
  471. </select>
  472. <!--获得获取流程任务id-->
  473. <select id="getActRuTaskId" parameterType="Map" resultType="Map">
  474. SELECT art.ID_ actRuTaskId FROM ACT_RU_EXECUTION are
  475. LEFT JOIN ACT_RU_TASK art ON are.PROC_INST_ID_=art.PROC_INST_ID_
  476. where 1 = 1
  477. <if test="businessKey !=null and businessKey != ''">
  478. and are.BUSINESS_KEY_ = #{businessKey}
  479. </if>
  480. </select>
  481. <!-- 修改流程任务信息 -->
  482. <update id="updateActRuTaskById" parameterType="Map">
  483. update ACT_RU_TASK t set SUSPENSION_STATE_=1
  484. <if test="assigneeUser != null and assigneeUser != ''">
  485. ,t.ASSIGNEE_ = #{assigneeUser}
  486. </if>
  487. where 1=1
  488. <if test="actRuTaskId !=null and actRuTaskId != ''">
  489. and t.ID_= #{actRuTaskId}
  490. </if>
  491. </update>
  492. </mapper>