PurchaseMapper.xml 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.dk.mdm.mapper.pur.PurchaseMapper">
  4. <!-- 通用设置 -->
  5. <!-- 通用查询列 -->
  6. <sql id="Base_Column_List">
  7. pur_id, pur_no, pur_type, org_id, staff_id, sup_id, contact_name, contact_phone,
  8. pickup_date, sum_quantity, sum_standard, sum_amount, pur_discount, pur_status,
  9. into_status, intoing_qty, intoing_amt, into_qty, into_amt, return_qty, return_amt,
  10. amt_payable, amt_handle, amt_residue, remarks, annex_paths, make_staff, make_time, flg_valid, cp_id,
  11. op_create_time, op_create_user_id, op_update_time, op_update_user_id, op_app_code, op_timestamp, op_db_user
  12. </sql>
  13. <!-- 通用查询列 -->
  14. <sql id="Base_Column_List_Left_join">
  15. tpp.pur_id,
  16. tpp.pur_no,
  17. tpp.pur_type,
  18. tpp.org_id,
  19. tpp.staff_id,
  20. tpp.sup_id,
  21. tpp.contact_name,
  22. tpp.contact_phone,
  23. tpp.pickup_date,
  24. tpp.sum_quantity,
  25. tpp.sum_standard,
  26. tpp.sum_amount,
  27. tpp.pur_discount,
  28. tpp.pur_status,
  29. tpp.into_status,
  30. tpp.intoing_qty,
  31. tpp.intoing_amt,
  32. tpp.into_qty,
  33. tpp.into_amt,
  34. tpp.return_qty,
  35. tpp.return_amt,
  36. tpp.amt_payable,
  37. tpp.amt_handle,
  38. tpp.amt_residue,
  39. tpp.remarks,
  40. tpp.annex_paths,
  41. tpp.make_staff,
  42. tpp.make_time,
  43. tpp.flg_valid,
  44. tpp.cp_id,
  45. tpp.op_create_time,
  46. tpp.op_create_user_id,
  47. tpp.op_update_time,
  48. tpp.op_update_user_id,
  49. tpp.op_app_code,
  50. tpp.op_timestamp,
  51. tpp.op_db_user,
  52. tpp.wh_id
  53. </sql>
  54. <!-- 通用查询映射结果 -->
  55. <resultMap id="BaseResultMap" type="com.dk.mdm.model.pojo.pur.Purchase">
  56. <id column="pur_id" property="purId"/>
  57. <result column="pur_no" property="purNo"/>
  58. <result column="pur_type" property="purType"/>
  59. <result column="org_id" property="orgId" typeHandler="UuidTypeHandler"/>
  60. <result column="staff_id" property="staffId" typeHandler="UuidTypeHandler"/>
  61. <result column="sup_id" property="supId" typeHandler="UuidTypeHandler"/>
  62. <result column="contact_name" property="contactName"/>
  63. <result column="contact_phone" property="contactPhone"/>
  64. <result column="pickup_date" property="pickupDate" typeHandler="TimestampTypeHandler"/>
  65. <result column="sum_quantity" property="sumQuantity"/>
  66. <result column="sum_standard" property="sumStandard"/>
  67. <result column="sum_amount" property="sumAmount"/>
  68. <result column="pur_discount" property="purDiscount"/>
  69. <result column="pur_status" property="purStatus"/>
  70. <result column="into_status" property="intoStatus"/>
  71. <result column="intoing_qty" property="intoingQty"/>
  72. <result column="intoing_amt" property="intoingAmt"/>
  73. <result column="into_qty" property="intoQty"/>
  74. <result column="into_amt" property="intoAmt"/>
  75. <result column="return_qty" property="returnQty"/>
  76. <result column="return_amt" property="returnAmt"/>
  77. <result column="amt_payable" property="amtPayable"/>
  78. <result column="amt_handle" property="amtHandle"/>
  79. <result column="amt_residue" property="amtResidue"/>
  80. <result column="remarks" property="remarks"/>
  81. <result column="annex_paths" property="annexPaths" typeHandler="JsonTypeHandler"/>
  82. <result column="make_staff" property="makeStaff" typeHandler="UuidTypeHandler"/>
  83. <result column="make_time" property="makeTime" typeHandler="TimestampTypeHandler"/>
  84. <result column="flg_valid" property="flgValid"/>
  85. <result column="cp_id" property="cpId"/>
  86. <result column="op_create_time" property="opCreateTime" typeHandler="TimestampTypeHandler"/>
  87. <result column="op_create_user_id" property="opCreateUserId" typeHandler="UuidTypeHandler"/>
  88. <result column="op_update_time" property="opUpdateTime" typeHandler="TimestampTypeHandler"/>
  89. <result column="op_update_user_id" property="opUpdateUserId" typeHandler="UuidTypeHandler"/>
  90. <result column="op_app_code" property="opAppCode"/>
  91. <result column="op_timestamp" property="opTimestamp" typeHandler="TimestampTypeHandler"/>
  92. <result column="op_db_user" property="opDbUser"/>
  93. <result column="wh_id" property="whId"/>
  94. </resultMap>
  95. <!-- 通用查询映射结果 -->
  96. <resultMap id="BaseResultMapResponse" type="com.dk.mdm.model.response.pur.PurchaseResponse">
  97. <id column="pur_id" property="purId"/>
  98. <result column="pur_no" property="purNo"/>
  99. <result column="pur_type" property="purType"/>
  100. <result column="org_id" property="orgId" typeHandler="UuidTypeHandler"/>
  101. <result column="staff_id" property="staffId" typeHandler="UuidTypeHandler"/>
  102. <result column="sup_id" property="supId" typeHandler="UuidTypeHandler"/>
  103. <result column="contact_name" property="contactName"/>
  104. <result column="contact_phone" property="contactPhone"/>
  105. <result column="pickup_date" property="pickupDate" typeHandler="TimestampTypeHandler"/>
  106. <result column="sum_quantity" property="sumQuantity"/>
  107. <result column="sum_standard" property="sumStandard"/>
  108. <result column="sum_amount" property="sumAmount"/>
  109. <result column="pur_discount" property="purDiscount"/>
  110. <result column="pur_status" property="purStatus"/>
  111. <result column="into_status" property="intoStatus"/>
  112. <result column="intoing_qty" property="intoingQty"/>
  113. <result column="intoing_amt" property="intoingAmt"/>
  114. <result column="into_qty" property="intoQty"/>
  115. <result column="into_amt" property="intoAmt"/>
  116. <result column="return_qty" property="returnQty"/>
  117. <result column="return_amt" property="returnAmt"/>
  118. <result column="amt_payable" property="amtPayable"/>
  119. <result column="amt_handle" property="amtHandle"/>
  120. <result column="amt_residue" property="amtResidue"/>
  121. <result column="remarks" property="remarks"/>
  122. <result column="annex_paths" property="annexPaths" typeHandler="JsonTypeHandler"/>
  123. <result column="make_staff" property="makeStaff" typeHandler="UuidTypeHandler"/>
  124. <result column="make_time" property="makeTime" typeHandler="TimestampTypeHandler"/>
  125. <result column="flg_valid" property="flgValid"/>
  126. <result column="cp_id" property="cpId"/>
  127. <result column="op_create_time" property="opCreateTime" typeHandler="TimestampTypeHandler"/>
  128. <result column="op_create_user_id" property="opCreateUserId" typeHandler="UuidTypeHandler"/>
  129. <result column="op_update_time" property="opUpdateTime" typeHandler="TimestampTypeHandler"/>
  130. <result column="op_update_user_id" property="opUpdateUserId" typeHandler="UuidTypeHandler"/>
  131. <result column="op_app_code" property="opAppCode"/>
  132. <result column="op_timestamp" property="opTimestamp" typeHandler="TimestampTypeHandler"/>
  133. <result column="op_db_user" property="opDbUser"/>
  134. <result column="wh_id" property="whId"/>
  135. <result column="orgName" property="orgName"/>
  136. <result column="staffName" property="staffName"/>
  137. <result column="makeStaffName" property="makeStaffName"/>
  138. <result column="supplierName" property="supplierName"/>
  139. <result column="whName" property="whName"/>
  140. <result column="displayedStatus" property="displayedStatus"/>
  141. <result column="intoStatusName" property="intoStatusName"/>
  142. <result column="purStatusName" property="purStatusName"/>
  143. <result column="returnAddress" property="returnAddress"/>
  144. <collection property="purchaseItemResponseList" resultMap="purchaseItemListMap" columnPrefix="list_"/>
  145. </resultMap>
  146. <!-- 关联映射-->
  147. <resultMap id="purchaseItemListMap" type="java.util.Map">
  148. <id column="item_id" property="itemId"/>
  149. <result column="pur_id" property="purId" typeHandler="UuidTypeHandler"/>
  150. <result column="pur_no" property="purNo"/>
  151. <result column="item_index" property="itemIndex"/>
  152. <result column="sku_id" property="skuId" typeHandler="UuidTypeHandler"/>
  153. <result column="item_qty" property="itemQty"/>
  154. <result column="price_std" property="priceStd"/>
  155. <result column="amt_std" property="amtStd"/>
  156. <result column="price_pur" property="pricePur"/>
  157. <result column="item_amt" property="itemAmt"/>
  158. <result column="price_discount" property="priceDiscount"/>
  159. <result column="non_std_code" property="nonStdCode"/>
  160. <result column="into_status" property="intoStatus"/>
  161. <result column="intoing_qty" property="intoingQty"/>
  162. <result column="intoing_amt" property="intoingAmt"/>
  163. <result column="into_qty" property="intoQty"/>
  164. <result column="into_amt" property="intoAmt"/>
  165. <result column="return_qty" property="returnQty"/>
  166. <result column="return_amt" property="returnAmt"/>
  167. <result column="remarks" property="remarks"/>
  168. <result column="flg_valid" property="flgValid"/>
  169. <result column="cp_id" property="cpId"/>
  170. <result column="sku_code" property="skuCode"/>
  171. <result column="sku_name" property="skuName"/>
  172. <result column="price_standard" property="priceStandard"/>
  173. <result column="sku_model" property="skuModel"/>
  174. <result column="short_name" property="shortName"/>
  175. <result column="op_create_time" property="opCreateTime" typeHandler="TimestampTypeHandler"/>
  176. <result column="op_create_user_id" property="opCreateUserId" typeHandler="UuidTypeHandler"/>
  177. <result column="op_update_time" property="opUpdateTime" typeHandler="TimestampTypeHandler"/>
  178. <result column="op_update_user_id" property="opUpdateUserId" typeHandler="UuidTypeHandler"/>
  179. <result column="op_app_code" property="opAppCode"/>
  180. <result column="op_timestamp" property="opTimestamp" typeHandler="TimestampTypeHandler"/>
  181. <result column="op_db_user" property="opDbUser"/>
  182. </resultMap>
  183. <!-- 通用条件列 -->
  184. <sql id="Condition">
  185. <where>
  186. <if test="purNo != null and purNo != ''">
  187. AND pur_no = #{purNo}
  188. </if>
  189. <if test="purType != null and purType != ''">
  190. AND pur_type = #{purType}
  191. </if>
  192. <if test="orgId != null and orgId != ''">
  193. AND org_id = #{orgId}
  194. </if>
  195. <if test="staffId != null and staffId != ''">
  196. AND staff_id = #{staffId}
  197. </if>
  198. <if test="supId != null and supId != ''">
  199. AND sup_id = #{supId}
  200. </if>
  201. <if test="contactName != null and contactName != ''">
  202. AND contact_name = #{contactName}
  203. </if>
  204. <if test="contactPhone != null and contactPhone != ''">
  205. AND contact_phone = #{contactPhone}
  206. </if>
  207. <if test="pickupDate != null">
  208. AND pickup_date = #{pickupDate}
  209. </if>
  210. <if test="sumQuantity != null">
  211. AND sum_quantity = #{sumQuantity}
  212. </if>
  213. <if test="sumStandard != null">
  214. AND sum_standard = #{sumStandard}
  215. </if>
  216. <if test="sumAmount != null">
  217. AND sum_amount = #{sumAmount}
  218. </if>
  219. <if test="purDiscount != null">
  220. AND pur_discount = #{purDiscount}
  221. </if>
  222. <if test="purStatus != null and purStatus != ''">
  223. AND pur_status = #{purStatus}
  224. </if>
  225. <if test="intoStatus != null and intoStatus != ''">
  226. AND into_status = #{intoStatus}
  227. </if>
  228. <if test="intoingQty != null">
  229. AND intoing_qty = #{intoingQty}
  230. </if>
  231. <if test="intoingAmt != null">
  232. AND intoing_amt = #{intoingAmt}
  233. </if>
  234. <if test="intoQty != null">
  235. AND into_qty = #{intoQty}
  236. </if>
  237. <if test="intoAmt != null">
  238. AND into_amt = #{intoAmt}
  239. </if>
  240. <if test="returnQty != null">
  241. AND return_qty = #{returnQty}
  242. </if>
  243. <if test="returnAmt != null">
  244. AND return_amt = #{returnAmt}
  245. </if>
  246. <if test="amtPayable != null">
  247. AND amt_payable = #{amtPayable}
  248. </if>
  249. <if test="amtHandle != null">
  250. AND amt_handle = #{amtHandle}
  251. </if>
  252. <if test="amtResidue != null">
  253. AND amt_residue = #{amtResidue}
  254. </if>
  255. <if test="remarks != null and remarks != ''">
  256. AND remarks = #{remarks}
  257. </if>
  258. <if test="annexPaths != null and annexPaths != ''">
  259. AND annex_paths = #{annexPaths}
  260. </if>
  261. <if test="makeStaff != null and makeStaff != ''">
  262. AND make_staff = #{makeStaff}
  263. </if>
  264. <if test="makeTime != null">
  265. AND make_time = #{makeTime}
  266. </if>
  267. <if test="flgValid != null">
  268. AND flg_valid = #{flgValid}
  269. </if>
  270. <if test="cpId != null">
  271. AND cp_id = #{cpId}
  272. </if>
  273. <if test="opCreateTime != null">
  274. AND op_create_time = #{opCreateTime}
  275. </if>
  276. <if test="opCreateUserId != null and opCreateUserId != ''">
  277. AND op_create_user_id = #{opCreateUserId}
  278. </if>
  279. <if test="opUpdateTime != null">
  280. AND op_update_time = #{opUpdateTime}
  281. </if>
  282. <if test="opUpdateUserId != null and opUpdateUserId != ''">
  283. AND op_update_user_id = #{opUpdateUserId}
  284. </if>
  285. <if test="opAppCode != null and opAppCode != ''">
  286. AND op_app_code = #{opAppCode}
  287. </if>
  288. <if test="opTimestamp != null">
  289. AND op_timestamp = #{opTimestamp}
  290. </if>
  291. <if test="opDbUser != null and opDbUser != ''">
  292. AND op_db_user = #{opDbUser}
  293. </if>
  294. </where>
  295. </sql>
  296. <!-- 通用条件列 -->
  297. <sql id="Condition_1">
  298. <where>
  299. <if test="purId != null and purId != ''">
  300. AND tpp.pur_id = #{purId}::uuid
  301. </if>
  302. <if test="purNo != null and purNo != ''">
  303. AND tpp.pur_no like concat('%', my_ex.likequery(#{purNo}) , '%')
  304. </if>
  305. <if test="purType != null and purType != ''">
  306. AND tpp.pur_type = #{purType}
  307. </if>
  308. <if test="orgId != null and orgId != ''">
  309. AND tpp.org_id = #{orgId}
  310. </if>
  311. <if test="staffId != null and staffId != ''">
  312. AND tpp.staff_id = #{staffId}
  313. </if>
  314. <if test="supId != null and supId != ''">
  315. AND tpp.sup_id = #{supId}::uuid
  316. </if>
  317. <if test="contactName != null and contactName != ''">
  318. AND tpp.contact_name like concat('%', my_ex.likequery(#{contactName}) , '%')
  319. </if>
  320. <if test="contactPhone != null and contactPhone != ''">
  321. AND tpp.contact_phone like concat('%', my_ex.likequery(#{contactPhone}) , '%')
  322. </if>
  323. <if test="pickupDate != null">
  324. AND tpp.pickup_date = #{pickupDate}
  325. </if>
  326. <if test="sumQuantity != null">
  327. AND tpp.sum_quantity = #{sumQuantity}
  328. </if>
  329. <if test="sumStandard != null">
  330. AND tpp.sum_standard = #{sumStandard}
  331. </if>
  332. <if test="sumAmount != null">
  333. AND tpp.sum_amount = #{sumAmount}
  334. </if>
  335. <if test="purDiscount != null">
  336. AND tpp.pur_discount = #{purDiscount}
  337. </if>
  338. <if test="purStatus != null and purStatus != ''">
  339. AND tpp.pur_status = #{purStatus}
  340. </if>
  341. <if test="intoStatus != null and intoStatus != ''">
  342. AND tpp.into_status = #{intoStatus}
  343. </if>
  344. <if test="intoingQty != null">
  345. AND tpp.intoing_qty = #{intoingQty}
  346. </if>
  347. <if test="intoingAmt != null">
  348. AND tpp.intoing_amt = #{intoingAmt}
  349. </if>
  350. <if test="intoQty != null">
  351. AND tpp.into_qty = #{intoQty}
  352. </if>
  353. <if test="intoAmt != null">
  354. AND tpp.into_amt = #{intoAmt}
  355. </if>
  356. <if test="returnQty != null">
  357. AND tpp.return_qty = #{returnQty}
  358. </if>
  359. <if test="returnAmt != null">
  360. AND tpp.return_amt = #{returnAmt}
  361. </if>
  362. <if test="amtPayable != null">
  363. AND tpp.amt_payable = #{amtPayable}
  364. </if>
  365. <if test="amtHandle != null">
  366. AND tpp.amt_handle = #{amtHandle}
  367. </if>
  368. <if test="amtResidue != null">
  369. AND tpp.amt_residue = #{amtResidue}
  370. </if>
  371. <if test="remarks != null and remarks != ''">
  372. AND tpp.remarks = #{remarks}
  373. </if>
  374. <if test="annexPaths != null and annexPaths != ''">
  375. AND tpp.annex_paths = #{annexPaths}
  376. </if>
  377. <if test="makeStaff != null and makeStaff != ''">
  378. AND tpp.make_staff = #{makeStaff}
  379. </if>
  380. <if test="makeTime != null">
  381. AND tpp.make_time = #{makeTime}
  382. </if>
  383. <if test="flgValid != null">
  384. AND tpp.flg_valid = #{flgValid}
  385. </if>
  386. <if test="cpId != null">
  387. AND tpp.cp_id = #{cpId}
  388. </if>
  389. <if test="opCreateTime != null">
  390. AND tpp.op_create_time = #{opCreateTime}
  391. </if>
  392. <if test="opCreateUserId != null and opCreateUserId != ''">
  393. AND tpp.op_create_user_id = #{opCreateUserId}
  394. </if>
  395. <if test="opUpdateTime != null">
  396. AND tpp.op_update_time = #{opUpdateTime}
  397. </if>
  398. <if test="opUpdateUserId != null and opUpdateUserId != ''">
  399. AND tpp.op_update_user_id = #{opUpdateUserId}
  400. </if>
  401. <if test="opAppCode != null and opAppCode != ''">
  402. AND tpp.op_app_code = #{opAppCode}
  403. </if>
  404. <if test="opTimestamp != null">
  405. AND tpp.op_timestamp = #{opTimestamp}
  406. </if>
  407. <if test="opDbUser != null and opDbUser != ''">
  408. AND tpp.op_db_user = #{opDbUser}
  409. </if>
  410. <if test="intoStatus != null and intoStatus != ''">
  411. AND tpp.into_status = #{intoStatus}
  412. </if>
  413. <if test="intoStatusList != null and intoStatusList.size()>0">
  414. AND tpp.into_status =
  415. any(#{intoStatusList,typeHandler=StringListTypeHandler})
  416. </if>
  417. <if test="skuName != null and skuName!='' ">
  418. and exists (select 1 from dkic_b.t_psi_purchase_item tppi
  419. left join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tppi.sku_id
  420. where
  421. tpp.pur_id = tppi.pur_id
  422. and tppi.flg_valid
  423. AND position(#{skuName} in tmgs.sku_name) > 0
  424. )
  425. </if>
  426. <if test="pickupDateStart != null">
  427. AND tpp.pickup_date &gt;= #{pickupDateStart}::timestamp with time zone
  428. </if>
  429. <if test="pickupDateEnd != null">
  430. AND tpp.pickup_date &lt; #{pickupDateEnd}::timestamp with time zone + interval '1 day'
  431. </if>
  432. </where>
  433. </sql>
  434. <sql id="idsForeach">
  435. <!-- 根据主键purId批量操作 -->
  436. WHERE pur_id in
  437. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  438. #{item}
  439. </foreach>
  440. </sql>
  441. <!-- 查询表dkic_b.t_psi_purchase,(条件查询+分页)列表 -->
  442. <select id="selectByCond" resultMap="BaseResultMapResponse">
  443. SELECT
  444. <include refid="Base_Column_List_Left_join"/>
  445. ,tmo.org_name as "orgName"
  446. ,tms.staff_name as "staffName"
  447. ,tms1.staff_name as "makeStaffName"
  448. ,tmp.sup_name as "supplierName"
  449. ,tmp.return_address as "returnAddress"
  450. ,tmw.wh_name as "whName"
  451. ,sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "intoStatusName"
  452. ,sys.f_get_name_i18n(tdk2.kind_name_i18n, #{i18n}) as "purStatusName"
  453. ,CASE
  454. WHEN tpp.pur_status = '订单状态-暂存' THEN sys.f_get_name_i18n(tdk2.kind_name_i18n, #{i18n})
  455. WHEN tpp.pur_status != '订单状态-暂存' THEN sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n})
  456. END AS "displayedStatus"
  457. FROM dkic_b.t_psi_purchase tpp
  458. Left join dkic_b.t_mst_org tmo on tpp.org_id = tmo.org_id
  459. Left join dkic_b.t_mst_supplier tmp on tpp.sup_id = tmp.sup_id
  460. Left join dkic_b.t_mst_staff tms on tpp.staff_id = tms.staff_id
  461. Left join dkic_b.t_mst_staff tms1 on tpp.make_staff = tms1.staff_id
  462. Left join dkic_b.t_mst_warehouse tmw on tpp.wh_id = tmw.wh_id
  463. left join sys.t_data_kind tdk1 on tdk1.kind_code = tpp.into_status
  464. left join sys.t_data_kind tdk2 on tdk2.kind_code = tpp.pur_status
  465. <include refid="Condition_1"/>
  466. order by tpp.op_create_time desc
  467. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  468. limit #{end} offset #{start}
  469. </if>
  470. </select>
  471. <sql id="Base_Column_List_Item_Response_Join">
  472. ,tppi.item_id as "List_item_id",
  473. tppi.pur_id as "List_pur_id",
  474. tpp.pur_no as "List_pur_no",
  475. tppi.item_index as "List_item_index",
  476. tppi.sku_id as "List_sku_id",
  477. tppi.item_qty as "List_item_qty",
  478. tppi.price_std as "pricePurchase",
  479. tppi.amt_std as "List_amt_std",
  480. tppi.price_pur as "List_price_pur",
  481. tppi.item_amt as "List_item_amt",
  482. tppi.price_discount as "List_price_discount",
  483. tppi.non_std_code as "List_non_std_code",
  484. tppi.into_status as "List_into_status",
  485. tppi.intoing_qty as "List_intoing_qty",
  486. tppi.intoing_amt as "List_intoing_amt",
  487. tppi.into_qty as "List_into_qty",
  488. tppi.into_amt as "List_into_amt",
  489. tppi.return_qty as "List_return_qty",
  490. tppi.return_amt as "List_return_amt",
  491. tppi.remarks as "List_remarks",
  492. tppi.flg_valid as "List_flg_valid",
  493. tppi.cp_id as "List_cp_id",
  494. tppi.op_create_time as "List_op_create_time",
  495. tppi.op_create_user_id as "List_op_create_user_id",
  496. tppi.op_update_time as "List_op_update_time",
  497. tppi.op_update_user_id as "List_op_update_user_id",
  498. tppi.op_app_code as "List_op_app_code",
  499. tppi.op_timestamp as "List_op_timestamp",
  500. tppi.op_db_user as "List_op_db_user",
  501. tmgs.sku_code AS list_sku_code,
  502. tmgs.sku_name AS list_sku_name,
  503. tmgb.short_name AS list_short_name,
  504. tmgs.sku_model AS list_sku_model,
  505. tmgs.price_purchase AS list_price_purchase,
  506. tmgs.price_standard AS list_price_standard,
  507. tmgs.sku_images AS list_sku_images,
  508. tpit.usable_qty AS list_usable_qty,
  509. tpit.inv_qty AS list_inv_qty,
  510. tpit.outing_qty AS list_outing_qty
  511. </sql>
  512. <!-- 查询表dkic_b.t_psi_purchase,(条件查询+分页)列表 -->
  513. <select id="selectByCondItem" resultMap="BaseResultMapResponse">
  514. SELECT
  515. <include refid="Base_Column_List_Left_join"/>
  516. <include refid="Base_Column_List_Item_Response_Join"/>
  517. ,tmo.org_name as "orgName"
  518. ,tms.staff_name as "staffName"
  519. ,tms1.staff_name as "makeStaffName"
  520. ,tmp.sup_name as "supplierName"
  521. ,tmw.wh_name as "whName"
  522. FROM dkic_b.t_psi_purchase tpp
  523. left join dkic_b.t_psi_purchase_item tppi on tppi.pur_id = tpp.pur_id
  524. left join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tppi.sku_id
  525. left join dkic_b.t_mst_goods_brand tmgb on tmgb.brand_id = tmgs.brand_id
  526. left join dkic_b.t_psi_inventory tpit on tpit.sku_id = tppi.sku_id
  527. Left join dkic_b.t_mst_org tmo on tpp.org_id = tmo.org_id
  528. Left join dkic_b.t_mst_supplier tmp on tpp.sup_id = tmp.sup_id
  529. Left join dkic_b.t_mst_staff tms on tpp.staff_id = tms.staff_id
  530. Left join dkic_b.t_mst_staff tms1 on tpp.make_staff = tms1.staff_id
  531. Left join dkic_b.t_mst_warehouse tmw on tpp.wh_id = tmw.wh_id
  532. <include refid="Condition_1"/>
  533. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  534. limit #{end} offset #{start}
  535. </if>
  536. </select>
  537. <!-- 根据主键查询表dkic_b.t_psi_purchase的一行数据 -->
  538. <select id="selectById" resultMap="BaseResultMapResponse">
  539. SELECT
  540. <include refid="Base_Column_List_Left_join"/>
  541. ,tmo.org_name as "orgName"
  542. ,tms.staff_name as "staffName"
  543. ,tms1.staff_name as "makeStaffName"
  544. ,tmp.sup_name as "supplierName"
  545. ,tmw.wh_name as "whName"
  546. FROM dkic_b.t_psi_purchase tpp
  547. Left join dkic_b.t_mst_org tmo on tpp.org_id = tmo.org_id
  548. Left join dkic_b.t_mst_supplier tmp on tpp.sup_id = tmp.sup_id
  549. Left join dkic_b.t_mst_staff tms on tpp.staff_id = tms.staff_id
  550. Left join dkic_b.t_mst_staff tms1 on tpp.make_staff = tms1.staff_id
  551. Left join dkic_b.t_mst_warehouse tmw on tpp.wh_id = tmw.wh_id
  552. WHERE pur_id = #{purId}::uuid
  553. </select>
  554. <!-- 根据主键锁定表dkic_b.t_psi_purchase的一行数据 -->
  555. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  556. SELECT
  557. <include refid="Base_Column_List"/>
  558. FROM dkic_b.t_psi_purchase
  559. WHERE pur_id = #{id}
  560. for update
  561. </select>
  562. <!-- 根据主键锁定表dkic_b.t_psi_purchase的多行数据 -->
  563. <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
  564. SELECT
  565. <include refid="Base_Column_List"/>
  566. FROM dkic_b.t_psi_purchase
  567. <include refid="idsForeach"/>
  568. for update
  569. </select>
  570. <!-- 查询表dkic_b.t_psi_purchase,(条件查询)个数 -->
  571. <select id="countByCond" resultType="Long">
  572. SELECT
  573. count(1)
  574. FROM dkic_b.t_psi_purchase tpp
  575. <include refid="Condition_1"/>
  576. </select>
  577. <!-- 查询表dkic_b.t_psi_purchase,(条件查询+分页)列表 -->
  578. <select id="noStoredSelectByCond" resultMap="BaseResultMapResponse">
  579. SELECT
  580. <include refid="Base_Column_List_Left_join"/>
  581. ,tmo.org_name as "orgName"
  582. ,tms.staff_name as "staffName"
  583. ,tms1.staff_name as "makeStaffName"
  584. ,tmp.sup_name as "supplierName"
  585. ,tmw.wh_name as "whName",
  586. sys.f_get_name_i18n(tdk.kind_name_i18n, #{i18n}) AS "intoStatusName"
  587. FROM dkic_b.t_psi_purchase tpp
  588. Left join dkic_b.t_mst_org tmo on tpp.org_id = tmo.org_id
  589. Left join dkic_b.t_mst_supplier tmp on tpp.sup_id = tmp.sup_id
  590. Left join dkic_b.t_mst_staff tms on tpp.staff_id = tms.staff_id
  591. Left join dkic_b.t_mst_staff tms1 on tpp.make_staff = tms1.staff_id
  592. Left join dkic_b.t_mst_warehouse tmw on tpp.wh_id = tmw.wh_id
  593. LEFT JOIN sys.t_data_kind tdk ON tdk.kind_code = tpp.into_status
  594. <include refid="Condition_1"/>
  595. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  596. limit #{end} offset #{start}
  597. </if>
  598. </select>
  599. <!-- 查询表dkic_b.t_psi_purchase,(条件查询)个数 -->
  600. <select id="noStoredCountByCond" resultType="Long">
  601. SELECT
  602. count(1)
  603. FROM dkic_b.t_psi_purchase tpp
  604. <include refid="Condition_1"/>
  605. </select>
  606. <update id="updateAmount" parameterType="com.dk.mdm.model.pojo.pur.Purchase">
  607. update dkic_b.t_psi_purchase
  608. <set>
  609. <if test="returnQty!= null">
  610. return_qty= #{returnQty},
  611. </if>
  612. <if test="returnAmt!= null">
  613. return_amt = #{returnAmt},
  614. </if>
  615. </set>
  616. where pur_id = #{purId}::uuid
  617. </update>
  618. <!-- 查询原始数据 冲正用-->
  619. <select id="selectPurchaseByRighting" resultMap="BaseResultMap">
  620. SELECT
  621. <include refid="Base_Column_List_Left_join"/>
  622. FROM dkic_b.t_psi_purchase tpp
  623. <where>
  624. <if test="orderId!=null">
  625. tpp.pur_id = #{purId}::uuid
  626. </if>
  627. </where>
  628. </select>
  629. <!-- 根据id修改-->
  630. <update id="updateById" parameterType="com.dk.mdm.model.pojo.pur.Purchase">
  631. update dkic_b.t_psi_purchase
  632. <set>
  633. <if test=" et!=null and et.purNo != null">
  634. pur_no = #{et.purNo,jdbcType=VARCHAR},
  635. </if>
  636. <if test=" et!=null and et.purType != null">
  637. pur_type = #{et.purType,jdbcType=VARCHAR},
  638. </if>
  639. <if test=" et!=null and et.orgId != null">
  640. org_id = #{et.orgId,typeHandler=UuidTypeHandler},
  641. </if>
  642. <if test=" et!=null and et.staffId != null">
  643. staff_id = #{et.staffId,typeHandler=UuidTypeHandler},
  644. </if>
  645. <if test=" et!=null and et.supId != null">
  646. sup_id = #{et.supId,typeHandler=UuidTypeHandler},
  647. </if>
  648. <if test=" et!=null and et.contactName != null">
  649. contact_name = #{et.contactName,jdbcType=VARCHAR},
  650. </if>
  651. <if test=" et!=null and et.contactPhone != null">
  652. contact_phone = #{et.contactPhone,jdbcType=VARCHAR},
  653. </if>
  654. <if test=" et!=null and et.pickupDate != null">
  655. pickup_date = #{et.pickupDate,jdbcType=DATE},
  656. </if>
  657. <if test=" et!=null and et.sumQuantity != null">
  658. sum_quantity = #{et.sumQuantity,jdbcType=NUMERIC},
  659. </if>
  660. <if test=" et!=null and et.sumStandard != null">
  661. sum_standard = #{et.sumStandard,jdbcType=NUMERIC},
  662. </if>
  663. <if test=" et!=null and et.sumAmount != null">
  664. sum_amount = #{et.sumAmount,jdbcType=NUMERIC},
  665. </if>
  666. <if test=" et!=null and et.purDiscount != null">
  667. pur_discount = #{et.purDiscount,jdbcType=NUMERIC},
  668. </if>
  669. <if test=" et!=null and et.purStatus != null">
  670. pur_status = #{et.purStatus,jdbcType=VARCHAR},
  671. </if>
  672. <if test=" et!=null and et.intoStatus != null">
  673. into_status = #{et.intoStatus,jdbcType=VARCHAR},
  674. </if>
  675. <if test=" et!=null and et.intoingQty != null">
  676. intoing_qty = intoing_qty + #{et.intoingQty,jdbcType=NUMERIC},
  677. </if>
  678. <if test=" et!=null and et.intoingAmt != null">
  679. intoing_amt = intoing_amt + #{et.intoingAmt,jdbcType=NUMERIC},
  680. </if>
  681. <if test=" et!=null and et.intoQty != null">
  682. into_qty = into_qty + #{et.intoQty,jdbcType=NUMERIC},
  683. </if>
  684. <if test=" et!=null and et.intoAmt != null">
  685. into_amt = into_amt + #{et.intoAmt,jdbcType=NUMERIC},
  686. </if>
  687. <if test=" et!=null and et.returnQty != null">
  688. return_qty = #{et.returnQty,jdbcType=NUMERIC},
  689. </if>
  690. <if test=" et!=null and et.returnAmt != null">
  691. return_amt = #{et.returnAmt,jdbcType=NUMERIC},
  692. </if>
  693. <if test=" et!=null and et.amtPayable != null">
  694. amt_payable = #{et.amtPayable,jdbcType=NUMERIC},
  695. </if>
  696. <if test=" et!=null and et.amtHandle != null">
  697. amt_handle = #{et.amtHandle,jdbcType=NUMERIC},
  698. </if>
  699. <if test=" et!=null and et.amtResidue != null">
  700. amt_residue = #{et.amtResidue,jdbcType=NUMERIC},
  701. </if>
  702. <if test=" et!=null and et.remarks != null">
  703. remarks = #{et.remarks,jdbcType=VARCHAR},
  704. </if>
  705. <if test=" et!=null and et.annexPaths != null">
  706. annex_paths = #{et.annexPaths,typeHandler=JsonTypeHandler},
  707. </if>
  708. <if test=" et!=null and et.makeStaff != null">
  709. make_staff = #{et.makeStaff,jdbcType=OTHER},
  710. </if>
  711. <if test=" et!=null and et.makeTime != null">
  712. make_time = #{et.makeTime,jdbcType=TIMESTAMP},
  713. </if>
  714. <if test=" et!=null and et.flgValid != null">
  715. flg_valid = #{et.flgValid,jdbcType=BOOLEAN},
  716. </if>
  717. <if test=" et!=null and et.cpId != null">
  718. cp_id = #{et.cpId,jdbcType=INTEGER},
  719. </if>
  720. <if test=" et!=null and et.whId != null">
  721. wh_id = #{et.whId,typeHandler=UuidTypeHandler},
  722. </if>
  723. </set>
  724. where pur_id = #{et.purId,typeHandler=UuidTypeHandler}
  725. and sum_quantity >= (into_qty + intoing_qty)
  726. </update>
  727. </mapper>