PurchaseMapper.xml 34 KB

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