PurchaseMapper.xml 32 KB

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