PurchaseMapper.xml 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033
  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, sys.f_remove_zero(sum_quantity) as sum_quantity, sum_standard, sum_amount, pur_discount, pur_status,
  9. into_status, sys.f_remove_zero(intoing_qty) as intoing_qty, intoing_amt, sys.f_remove_zero(into_qty) as into_qty, into_amt,
  10. sys.f_remove_zero(return_qty) as return_qty, return_amt,
  11. amt_payable, amt_handle, amt_residue, remarks, annex_paths, make_staff, make_time, flg_valid, cp_id,
  12. op_create_time, op_create_user_id, op_update_time, op_update_user_id, op_app_code, op_timestamp, op_db_user,
  13. flg_auto_handle,inbound_processing_flag
  14. </sql>
  15. <!-- 通用查询列 -->
  16. <sql id="Base_Column_List_Left_join">
  17. tpp.pur_id,
  18. tpp.pur_no,
  19. tpp.pur_type,
  20. tpp.org_id,
  21. tpp.staff_id,
  22. tpp.sup_id,
  23. tpp.contact_name,
  24. tpp.contact_phone,
  25. tpp.pickup_date,
  26. sys.f_remove_zero(tpp.sum_quantity) as sum_quantity,
  27. tpp.sum_standard,
  28. tpp.sum_amount,
  29. tpp.pur_discount,
  30. tpp.pur_status,
  31. tpp.into_status,
  32. sys.f_remove_zero(tpp.intoing_qty) as intoing_qty,
  33. tpp.intoing_amt,
  34. sys.f_remove_zero(tpp.into_qty) as into_qty,
  35. tpp.into_amt,
  36. sys.f_remove_zero(tpp.return_qty) as return_qty,
  37. tpp.return_amt,
  38. tpp.amt_payable,
  39. tpp.amt_handle,
  40. tpp.amt_residue,
  41. tpp.remarks,
  42. tpp.annex_paths,
  43. tpp.make_staff,
  44. tpp.make_time,
  45. tpp.flg_valid,
  46. tpp.cp_id,
  47. tpp.op_create_time,
  48. tpp.op_create_user_id,
  49. tpp.op_update_time,
  50. tpp.op_update_user_id,
  51. tpp.op_app_code,
  52. tpp.op_timestamp,
  53. tpp.op_db_user,
  54. tpp.wh_id,
  55. tpp.from_ids,
  56. tpp.from_nos,
  57. tpp.flg_auto_handle,
  58. tpp.inbound_processing_flag
  59. </sql>
  60. <!-- 通用查询映射结果 -->
  61. <resultMap id="BaseResultMap" type="com.dk.mdm.model.pojo.pur.Purchase">
  62. <id column="pur_id" property="purId"/>
  63. <result column="pur_no" property="purNo"/>
  64. <result column="pur_type" property="purType"/>
  65. <result column="org_id" property="orgId" typeHandler="UuidTypeHandler"/>
  66. <result column="staff_id" property="staffId" typeHandler="UuidTypeHandler"/>
  67. <result column="sup_id" property="supId" typeHandler="UuidTypeHandler"/>
  68. <result column="contact_name" property="contactName"/>
  69. <result column="contact_phone" property="contactPhone"/>
  70. <result column="pickup_date" property="pickupDate" typeHandler="TimestampTypeHandler"/>
  71. <result column="sum_quantity" property="sumQuantity"/>
  72. <result column="sum_standard" property="sumStandard"/>
  73. <result column="sum_amount" property="sumAmount"/>
  74. <result column="pur_discount" property="purDiscount"/>
  75. <result column="pur_status" property="purStatus"/>
  76. <result column="into_status" property="intoStatus"/>
  77. <result column="intoing_qty" property="intoingQty"/>
  78. <result column="intoing_amt" property="intoingAmt"/>
  79. <result column="into_qty" property="intoQty"/>
  80. <result column="into_amt" property="intoAmt"/>
  81. <result column="return_qty" property="returnQty"/>
  82. <result column="return_amt" property="returnAmt"/>
  83. <result column="amt_payable" property="amtPayable"/>
  84. <result column="amt_handle" property="amtHandle"/>
  85. <result column="amt_residue" property="amtResidue"/>
  86. <result column="remarks" property="remarks"/>
  87. <result column="annex_paths" property="annexPaths" typeHandler="JsonTypeHandler"/>
  88. <result column="make_staff" property="makeStaff" typeHandler="UuidTypeHandler"/>
  89. <result column="make_time" property="makeTime" typeHandler="TimestampTypeHandler"/>
  90. <result column="flg_valid" property="flgValid"/>
  91. <result column="cp_id" property="cpId"/>
  92. <result column="op_create_time" property="opCreateTime" typeHandler="TimestampTypeHandler"/>
  93. <result column="op_create_user_id" property="opCreateUserId" typeHandler="UuidTypeHandler"/>
  94. <result column="op_update_time" property="opUpdateTime" typeHandler="TimestampTypeHandler"/>
  95. <result column="op_update_user_id" property="opUpdateUserId" typeHandler="UuidTypeHandler"/>
  96. <result column="op_app_code" property="opAppCode"/>
  97. <result column="op_timestamp" property="opTimestamp" typeHandler="TimestampTypeHandler"/>
  98. <result column="op_db_user" property="opDbUser"/>
  99. <result column="wh_id" property="whId"/>
  100. <result column="flg_auto_handle" property="flgAutoHandle"/>
  101. <result column="inbound_processing_flag" property="inboundProcessingFlag"/>
  102. </resultMap>
  103. <!-- 通用查询映射结果 -->
  104. <resultMap id="BaseResultMapResponse" type="com.dk.mdm.model.response.pur.PurchaseResponse">
  105. <id column="pur_id" property="purId"/>
  106. <result column="pur_no" property="purNo"/>
  107. <result column="pur_type" property="purType"/>
  108. <result column="org_id" property="orgId" typeHandler="UuidTypeHandler"/>
  109. <result column="staff_id" property="staffId" typeHandler="UuidTypeHandler"/>
  110. <result column="sup_id" property="supId" typeHandler="UuidTypeHandler"/>
  111. <result column="contact_name" property="contactName"/>
  112. <result column="contact_phone" property="contactPhone"/>
  113. <result column="pickup_date" property="pickupDate" typeHandler="TimestampTypeHandler"/>
  114. <result column="sum_quantity" property="sumQuantity"/>
  115. <result column="sum_standard" property="sumStandard"/>
  116. <result column="sum_amount" property="sumAmount"/>
  117. <result column="pur_discount" property="purDiscount"/>
  118. <result column="pur_status" property="purStatus"/>
  119. <result column="into_status" property="intoStatus"/>
  120. <result column="intoing_qty" property="intoingQty"/>
  121. <result column="intoing_amt" property="intoingAmt"/>
  122. <result column="into_qty" property="intoQty"/>
  123. <result column="into_amt" property="intoAmt"/>
  124. <result column="return_qty" property="returnQty"/>
  125. <result column="return_amt" property="returnAmt"/>
  126. <result column="amt_payable" property="amtPayable"/>
  127. <result column="amt_handle" property="amtHandle"/>
  128. <result column="amt_residue" property="amtResidue"/>
  129. <result column="remarks" property="remarks"/>
  130. <result column="annex_paths" property="annexPaths" typeHandler="JsonTypeHandler"/>
  131. <result column="make_staff" property="makeStaff" typeHandler="UuidTypeHandler"/>
  132. <result column="make_time" property="makeTime" typeHandler="TimestampTypeHandler"/>
  133. <result column="flg_valid" property="flgValid"/>
  134. <result column="cp_id" property="cpId"/>
  135. <result column="op_create_time" property="opCreateTime" typeHandler="TimestampTypeHandler"/>
  136. <result column="op_create_user_id" property="opCreateUserId" typeHandler="UuidTypeHandler"/>
  137. <result column="op_update_time" property="opUpdateTime" typeHandler="TimestampTypeHandler"/>
  138. <result column="op_update_user_id" property="opUpdateUserId" typeHandler="UuidTypeHandler"/>
  139. <result column="op_app_code" property="opAppCode"/>
  140. <result column="op_timestamp" property="opTimestamp" typeHandler="TimestampTypeHandler"/>
  141. <result column="op_db_user" property="opDbUser"/>
  142. <result column="wh_id" property="whId"/>
  143. <result column="orgName" property="orgName"/>
  144. <result column="staffName" property="staffName"/>
  145. <result column="makeStaffName" property="makeStaffName"/>
  146. <result column="supplierName" property="supplierName"/>
  147. <result column="whName" property="whName"/>
  148. <result column="displayedStatus" property="displayedStatus"/>
  149. <result column="intoStatusName" property="intoStatusName"/>
  150. <result column="purStatusName" property="purStatusName"/>
  151. <result column="returnAddress" property="returnAddress"/>
  152. <result column="from_ids" property="fromIds" typeHandler="StringListTypeHandler"/>
  153. <result column="from_nos" property="fromNos" typeHandler="StringListTypeHandler"/>
  154. <result column="inboundReturnQty" property="inboundReturnQty"/>
  155. <result column="flg_auto_handle" property="flgAutoHandle"/>
  156. <result column="inbound_processing_flag" property="inboundProcessingFlag"/>
  157. <result column="category_count" property="categoryCount"/>
  158. <collection property="purchaseItemResponseList" resultMap="purchaseItemListMap" columnPrefix="list_"/>
  159. </resultMap>
  160. <!-- 关联映射-->
  161. <resultMap id="purchaseItemListMap" type="java.util.Map">
  162. <id column="item_id" property="itemId"/>
  163. <result column="pur_id" property="purId" typeHandler="UuidTypeHandler"/>
  164. <result column="pur_no" property="purNo"/>
  165. <result column="item_index" property="itemIndex"/>
  166. <result column="sku_id" property="skuId" typeHandler="UuidTypeHandler"/>
  167. <result column="item_qty" property="itemQty"/>
  168. <result column="price_std" property="priceStd"/>
  169. <result column="amt_std" property="amtStd"/>
  170. <result column="price_pur" property="pricePur"/>
  171. <result column="item_amt" property="itemAmt"/>
  172. <result column="price_discount" property="priceDiscount"/>
  173. <result column="non_std_code" property="nonStdCode"/>
  174. <result column="into_status" property="intoStatus"/>
  175. <result column="intoing_qty" property="intoingQty"/>
  176. <result column="intoing_amt" property="intoingAmt"/>
  177. <result column="into_qty" property="intoQty"/>
  178. <result column="into_amt" property="intoAmt"/>
  179. <result column="return_qty" property="returnQty"/>
  180. <result column="return_amt" property="returnAmt"/>
  181. <result column="remarks" property="remarks"/>
  182. <result column="flg_valid" property="flgValid"/>
  183. <result column="cp_id" property="cpId"/>
  184. <result column="sku_code" property="skuCode"/>
  185. <result column="sku_name" property="skuName"/>
  186. <result column="price_standard" property="priceStandard"/>
  187. <result column="sku_model" property="skuModel"/>
  188. <result column="short_name" property="shortName"/>
  189. <result column="op_create_time" property="opCreateTime" typeHandler="TimestampTypeHandler"/>
  190. <result column="op_create_user_id" property="opCreateUserId" typeHandler="UuidTypeHandler"/>
  191. <result column="op_update_time" property="opUpdateTime" typeHandler="TimestampTypeHandler"/>
  192. <result column="op_update_user_id" property="opUpdateUserId" typeHandler="UuidTypeHandler"/>
  193. <result column="op_app_code" property="opAppCode"/>
  194. <result column="op_timestamp" property="opTimestamp" typeHandler="TimestampTypeHandler"/>
  195. <result column="op_db_user" property="opDbUser"/>
  196. <result column="brand_name" property="brandName"/>
  197. <result column="sku_images" property="skuImages"/>
  198. </resultMap>
  199. <!-- 通用条件列 -->
  200. <sql id="Condition">
  201. <where>
  202. <if test="purNo != null and purNo != ''">
  203. AND pur_no = #{purNo}
  204. </if>
  205. <if test="purType != null and purType != ''">
  206. AND pur_type = #{purType}
  207. </if>
  208. <if test="orgId != null and orgId != ''">
  209. AND org_id = #{orgId}
  210. </if>
  211. <if test="staffId != null and staffId != ''">
  212. AND staff_id = #{staffId}
  213. </if>
  214. <if test="supId != null and supId != ''">
  215. AND sup_id = #{supId}
  216. </if>
  217. <if test="contactName != null and contactName != ''">
  218. AND contact_name = #{contactName}
  219. </if>
  220. <if test="contactPhone != null and contactPhone != ''">
  221. AND contact_phone = #{contactPhone}
  222. </if>
  223. <if test="pickupDate != null">
  224. AND pickup_date = #{pickupDate}
  225. </if>
  226. <if test="sumQuantity != null">
  227. AND sum_quantity = #{sumQuantity}
  228. </if>
  229. <if test="sumStandard != null">
  230. AND sum_standard = #{sumStandard}
  231. </if>
  232. <if test="sumAmount != null">
  233. AND sum_amount = #{sumAmount}
  234. </if>
  235. <if test="purDiscount != null">
  236. AND pur_discount = #{purDiscount}
  237. </if>
  238. <if test="purStatus != null and purStatus != ''">
  239. AND pur_status = #{purStatus}
  240. </if>
  241. <if test="intoStatus != null and intoStatus != ''">
  242. AND into_status = #{intoStatus}
  243. </if>
  244. <if test="intoingQty != null">
  245. AND intoing_qty = #{intoingQty}
  246. </if>
  247. <if test="intoingAmt != null">
  248. AND intoing_amt = #{intoingAmt}
  249. </if>
  250. <if test="intoQty != null">
  251. AND into_qty = #{intoQty}
  252. </if>
  253. <if test="intoAmt != null">
  254. AND into_amt = #{intoAmt}
  255. </if>
  256. <if test="returnQty != null">
  257. AND return_qty = #{returnQty}
  258. </if>
  259. <if test="returnAmt != null">
  260. AND return_amt = #{returnAmt}
  261. </if>
  262. <if test="amtPayable != null">
  263. AND amt_payable = #{amtPayable}
  264. </if>
  265. <if test="amtHandle != null">
  266. AND amt_handle = #{amtHandle}
  267. </if>
  268. <if test="amtResidue != null">
  269. AND amt_residue = #{amtResidue}
  270. </if>
  271. <if test="remarks != null and remarks != ''">
  272. AND remarks = #{remarks}
  273. </if>
  274. <if test="annexPaths != null and annexPaths != ''">
  275. AND annex_paths = #{annexPaths}
  276. </if>
  277. <if test="makeStaff != null and makeStaff != ''">
  278. AND make_staff = #{makeStaff}
  279. </if>
  280. <if test="makeTime != null">
  281. AND make_time = #{makeTime}
  282. </if>
  283. <if test="flgValid != null">
  284. AND flg_valid = #{flgValid}
  285. </if>
  286. <if test="cpId != null">
  287. AND cp_id = #{cpId}
  288. </if>
  289. <if test="opCreateTime != null">
  290. AND op_create_time = #{opCreateTime}
  291. </if>
  292. <if test="opCreateUserId != null and opCreateUserId != ''">
  293. AND op_create_user_id = #{opCreateUserId}
  294. </if>
  295. <if test="opUpdateTime != null">
  296. AND op_update_time = #{opUpdateTime}
  297. </if>
  298. <if test="opUpdateUserId != null and opUpdateUserId != ''">
  299. AND op_update_user_id = #{opUpdateUserId}
  300. </if>
  301. <if test="opAppCode != null and opAppCode != ''">
  302. AND op_app_code = #{opAppCode}
  303. </if>
  304. <if test="opTimestamp != null">
  305. AND op_timestamp = #{opTimestamp}
  306. </if>
  307. <if test="opDbUser != null and opDbUser != ''">
  308. AND op_db_user = #{opDbUser}
  309. </if>
  310. </where>
  311. </sql>
  312. <!-- 通用条件列 -->
  313. <sql id="Condition_1">
  314. <where>
  315. <if test="orgName != null and orgName != ''">
  316. AND tmo.org_name LIKE concat('%',my_ex.likequery(#{orgName}),'%')
  317. </if>
  318. <if test="staffName != null and staffName != ''">
  319. AND tms.staff_name LIKE concat('%',my_ex.likequery(#{staffName}),'%')
  320. </if>
  321. <if test="purId != null and purId != ''">
  322. AND tpp.pur_id = #{purId}::uuid
  323. </if>
  324. <if test="purNo != null and purNo != ''">
  325. AND tpp.pur_no like concat('%', my_ex.likequery(#{purNo}) , '%')
  326. </if>
  327. <if test="purType != null and purType != ''">
  328. AND tpp.pur_type = #{purType}
  329. </if>
  330. <if test="orgId != null and orgId != ''">
  331. AND tpp.org_id = #{orgId}
  332. </if>
  333. <if test="staffId != null and staffId != ''">
  334. AND tpp.staff_id = #{staffId}
  335. </if>
  336. <if test="supId != null and supId != ''">
  337. AND tpp.sup_id = #{supId}::uuid
  338. </if>
  339. <if test="contactName != null and contactName != ''">
  340. AND tpp.contact_name like concat('%', my_ex.likequery(#{contactName}) , '%')
  341. </if>
  342. <if test="contactPhone != null and contactPhone != ''">
  343. AND tpp.contact_phone like concat('%', my_ex.likequery(#{contactPhone}) , '%')
  344. </if>
  345. <if test="pickupDate != null">
  346. AND tpp.pickup_date = #{pickupDate}
  347. </if>
  348. <if test="sumQuantity != null">
  349. AND tpp.sum_quantity = #{sumQuantity}
  350. </if>
  351. <if test="sumStandard != null">
  352. AND tpp.sum_standard = #{sumStandard}
  353. </if>
  354. <if test="sumAmount != null">
  355. AND tpp.sum_amount = #{sumAmount}
  356. </if>
  357. <if test="purDiscount != null">
  358. AND tpp.pur_discount = #{purDiscount}
  359. </if>
  360. <if test="purStatus != null and purStatus != ''">
  361. AND tpp.pur_status = #{purStatus}
  362. </if>
  363. <if test="intoStatus != null and intoStatus != ''">
  364. AND tpp.into_status = #{intoStatus}
  365. </if>
  366. <if test="intoingQty != null">
  367. AND tpp.intoing_qty = #{intoingQty}
  368. </if>
  369. <if test="intoingAmt != null">
  370. AND tpp.intoing_amt = #{intoingAmt}
  371. </if>
  372. <if test="intoQty != null">
  373. AND tpp.into_qty = #{intoQty}
  374. </if>
  375. <if test="intoAmt != null">
  376. AND tpp.into_amt = #{intoAmt}
  377. </if>
  378. <if test="returnQty != null">
  379. AND tpp.return_qty = #{returnQty}
  380. </if>
  381. <if test="returnAmt != null">
  382. AND tpp.return_amt = #{returnAmt}
  383. </if>
  384. <if test="amtPayable != null">
  385. AND tpp.amt_payable = #{amtPayable}
  386. </if>
  387. <if test="amtHandle != null">
  388. AND tpp.amt_handle = #{amtHandle}
  389. </if>
  390. <if test="amtResidue != null">
  391. AND tpp.amt_residue = #{amtResidue}
  392. </if>
  393. <if test="remarks != null and remarks != ''">
  394. AND tpp.remarks = #{remarks}
  395. </if>
  396. <if test="annexPaths != null and annexPaths != ''">
  397. AND tpp.annex_paths = #{annexPaths}
  398. </if>
  399. <if test="makeStaff != null and makeStaff != ''">
  400. AND tpp.make_staff = #{makeStaff}
  401. </if>
  402. <if test="makeTime != null">
  403. AND tpp.make_time = #{makeTime}
  404. </if>
  405. <if test="makeTimeStart != null and makeTimeEnd != null">
  406. AND tpp.make_time &gt;= #{makeTimeStart}::timestamp with time zone
  407. AND tpp.make_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
  408. </if>
  409. <if test="opCreateTime != null">
  410. AND tpp.op_create_time = #{opCreateTime}
  411. </if>
  412. <if test="opCreateUserId != null and opCreateUserId != ''">
  413. AND tpp.op_create_user_id = #{opCreateUserId}
  414. </if>
  415. <if test="opUpdateTime != null">
  416. AND tpp.op_update_time = #{opUpdateTime}
  417. </if>
  418. <if test="opUpdateUserId != null and opUpdateUserId != ''">
  419. AND tpp.op_update_user_id = #{opUpdateUserId}
  420. </if>
  421. <if test="opAppCode != null and opAppCode != ''">
  422. AND tpp.op_app_code = #{opAppCode}
  423. </if>
  424. <if test="opTimestamp != null">
  425. AND tpp.op_timestamp = #{opTimestamp}
  426. </if>
  427. <if test="opDbUser != null and opDbUser != ''">
  428. AND tpp.op_db_user = #{opDbUser}
  429. </if>
  430. <if test="intoStatus != null and intoStatus != ''">
  431. AND tpp.into_status = #{intoStatus}
  432. </if>
  433. <if test="intoStatusList != null and intoStatusList.size()>0">
  434. AND tpp.into_status =
  435. any(#{intoStatusList,typeHandler=StringListTypeHandler})
  436. </if>
  437. <if test="skuName != null and skuName!='' ">
  438. and exists (select 1 from dkic_b.t_psi_purchase_item tppi
  439. left join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tppi.sku_id
  440. where
  441. tpp.pur_id = tppi.pur_id
  442. and tppi.flg_valid
  443. AND position(#{skuName} in tmgs.sku_name) > 0
  444. )
  445. </if>
  446. <if test="pickupDateStart != null">
  447. AND tpp.pickup_date &gt;= #{pickupDateStart}::timestamp with time zone
  448. </if>
  449. <if test="pickupDateEnd != null">
  450. AND tpp.pickup_date &lt; #{pickupDateEnd}::timestamp with time zone + interval '1 day'
  451. </if>
  452. <if test="searchText !=null and searchText!='' " >
  453. AND ( tmp.sup_name LIKE concat('%',my_ex.likequery(#{searchText}), '%')or
  454. tpp.pur_no LIKE concat('%',my_ex.likequery(#{searchText}), '%'))
  455. </if>
  456. <if test="flgValid != null">
  457. AND tpp.flg_valid = #{flgValid}
  458. </if>
  459. <if test="cpId != null">
  460. AND tpp.cp_id = #{cpId}
  461. </if>
  462. <if test="orgIds != null and orgIds.size()>0">
  463. AND tpp.org_id = any(#{orgIds, typeHandler=UuidListTypeHandler})
  464. </if>
  465. <if test="staffIds != null and staffIds.size()>0">
  466. AND tpp.staff_id = any(#{staffIds, typeHandler=uuidListTypeHandler})
  467. </if>
  468. </where>
  469. </sql>
  470. <sql id="idsForeach">
  471. <!-- 根据主键purId批量操作 -->
  472. WHERE pur_id in
  473. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  474. #{item}
  475. </foreach>
  476. </sql>
  477. <!-- 查询表dkic_b.t_psi_purchase,(条件查询+分页)列表 -->
  478. <select id="selectByCond" resultMap="BaseResultMapResponse">
  479. SELECT
  480. <include refid="Base_Column_List_Left_join"/>
  481. ,tmo.org_name as "orgName"
  482. ,tms.staff_name as "staffName"
  483. ,tms1.staff_name as "makeStaffName"
  484. ,tmp.sup_name as "supplierName"
  485. ,tmp.return_address as "returnAddress"
  486. ,tmw.wh_name as "whName"
  487. ,sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "intoStatusName"
  488. ,sys.f_get_name_i18n(tdk2.kind_name_i18n, #{i18n}) as "purStatusName"
  489. ,CASE
  490. WHEN tpp.pur_status = '订单状态-暂存' THEN sys.f_get_name_i18n(tdk2.kind_name_i18n, #{i18n})
  491. WHEN tpp.pur_status != '订单状态-暂存' THEN sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n})
  492. END AS "displayedStatus"
  493. FROM dkic_b.t_psi_purchase tpp
  494. Left join dkic_b.t_mst_org tmo on tpp.org_id = tmo.org_id
  495. Left join dkic_b.t_mst_supplier tmp on tpp.sup_id = tmp.sup_id
  496. Left join dkic_b.t_mst_staff tms on tpp.staff_id = tms.staff_id
  497. Left join dkic_b.t_mst_staff tms1 on tpp.make_staff = tms1.staff_id
  498. Left join dkic_b.t_mst_warehouse tmw on tpp.wh_id = tmw.wh_id
  499. left join sys.t_data_kind tdk1 on tdk1.kind_code = tpp.into_status
  500. left join sys.t_data_kind tdk2 on tdk2.kind_code = tpp.pur_status
  501. <include refid="Condition_1"/>
  502. order by tpp.make_time desc
  503. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  504. limit #{end} offset #{start}
  505. </if>
  506. </select>
  507. <sql id="Base_Column_List_Item_Response_Join">
  508. ,tppi.item_id as "List_item_id",
  509. tppi.pur_id as "List_pur_id",
  510. tpp.pur_no as "List_pur_no",
  511. tppi.item_index as "List_item_index",
  512. tppi.sku_id as "List_sku_id",
  513. sys.f_remove_zero(tppi.item_qty) as "List_item_qty",
  514. tppi.price_std as "pricePurchase",
  515. tppi.amt_std as "List_amt_std",
  516. tppi.price_pur as "List_price_pur",
  517. tppi.item_amt as "List_item_amt",
  518. tppi.price_discount as "List_price_discount",
  519. tppi.non_std_code as "List_non_std_code",
  520. tppi.into_status as "List_into_status",
  521. sys.f_remove_zero(tppi.intoing_qty) as "List_intoing_qty",
  522. tppi.intoing_amt as "List_intoing_amt",
  523. sys.f_remove_zero(tppi.into_qty) as "List_into_qty",
  524. tppi.into_amt as "List_into_amt",
  525. sys.f_remove_zero(tppi.return_qty) as "List_return_qty",
  526. tppi.return_amt as "List_return_amt",
  527. tppi.remarks as "List_remarks",
  528. tppi.flg_valid as "List_flg_valid",
  529. tppi.cp_id as "List_cp_id",
  530. tppi.op_create_time as "List_op_create_time",
  531. tppi.op_create_user_id as "List_op_create_user_id",
  532. tppi.op_update_time as "List_op_update_time",
  533. tppi.op_update_user_id as "List_op_update_user_id",
  534. tppi.op_app_code as "List_op_app_code",
  535. tppi.op_timestamp as "List_op_timestamp",
  536. tppi.op_db_user as "List_op_db_user",
  537. tmgs.sku_code AS list_sku_code,
  538. tmgs.sku_name AS list_sku_name,
  539. tmgb.short_name AS list_short_name,
  540. tmgs.sku_model AS list_sku_model,
  541. tmgs.price_purchase AS list_price_purchase,
  542. tmgs.price_standard AS list_price_standard,
  543. tmgs.sku_images AS list_sku_images,
  544. sys.f_remove_zero(tpit.usable_qty) AS list_usable_qty,
  545. sys.f_remove_zero(tpit.inv_qty) AS list_inv_qty,
  546. tpit.outing_qty AS list_outing_qty,
  547. sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "intoStatusName",
  548. sys.f_get_name_i18n(tdk2.kind_name_i18n, #{i18n}) as "purStatusName"
  549. </sql>
  550. <!-- 查询表dkic_b.t_psi_purchase,(条件查询+分页)列表 -->
  551. <select id="selectByCondItem" resultMap="BaseResultMapResponse">
  552. SELECT
  553. <include refid="Base_Column_List_Left_join"/>
  554. <include refid="Base_Column_List_Item_Response_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. ,tmw.wh_name as "whName"
  561. ,tmw.wh_name as "whName"
  562. FROM dkic_b.t_psi_purchase tpp
  563. left join dkic_b.t_psi_purchase_item tppi on tppi.pur_id = tpp.pur_id
  564. left join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tppi.sku_id
  565. left join dkic_b.t_mst_goods_brand tmgb on tmgb.brand_id = tmgs.brand_id
  566. left join dkic_b.t_psi_inventory tpit on tpit.sku_id = tppi.sku_id
  567. Left join dkic_b.t_mst_org tmo on tpp.org_id = tmo.org_id
  568. Left join dkic_b.t_mst_supplier tmp on tpp.sup_id = tmp.sup_id
  569. Left join dkic_b.t_mst_staff tms on tpp.staff_id = tms.staff_id
  570. Left join dkic_b.t_mst_staff tms1 on tpp.make_staff = tms1.staff_id
  571. Left join dkic_b.t_mst_warehouse tmw on tpp.wh_id = tmw.wh_id
  572. <include refid="Condition_1"/>
  573. ORDER BY tpp.make_time
  574. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  575. limit #{end} offset #{start}
  576. </if>
  577. </select>
  578. <!-- 根据主键查询表dkic_b.t_psi_purchase的一行数据 -->
  579. <select id="selectById" resultMap="BaseResultMapResponse">
  580. SELECT
  581. <include refid="Base_Column_List_Left_join"/>
  582. ,tmo.org_name as "orgName"
  583. ,tms.staff_name as "staffName"
  584. ,tms1.staff_name as "makeStaffName"
  585. ,tmp.sup_name as "supplierName"
  586. ,tmw.wh_name as "whName"
  587. ,(SELECT sum(tpid.return_qty) FROM dkic_b.t_psi_inbound tpid where tpid.from_id = tpp.pur_id ) as "inboundReturnQty"
  588. FROM dkic_b.t_psi_purchase tpp
  589. Left join dkic_b.t_mst_org tmo on tpp.org_id = tmo.org_id
  590. Left join dkic_b.t_mst_supplier tmp on tpp.sup_id = tmp.sup_id
  591. Left join dkic_b.t_mst_staff tms on tpp.staff_id = tms.staff_id
  592. Left join dkic_b.t_mst_staff tms1 on tpp.make_staff = tms1.staff_id
  593. Left join dkic_b.t_mst_warehouse tmw on tpp.wh_id = tmw.wh_id
  594. WHERE pur_id = #{id}::uuid
  595. </select>
  596. <!-- 根据主键锁定表dkic_b.t_psi_purchase的一行数据 -->
  597. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  598. SELECT
  599. <include refid="Base_Column_List"/>
  600. FROM dkic_b.t_psi_purchase
  601. WHERE pur_id = #{id}::uuid
  602. for update
  603. </select>
  604. <!-- 根据主键锁定表dkic_b.t_psi_purchase的多行数据 -->
  605. <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
  606. SELECT
  607. <include refid="Base_Column_List"/>
  608. FROM dkic_b.t_psi_purchase
  609. <include refid="idsForeach"/>
  610. for update
  611. </select>
  612. <!-- 查询表dkic_b.t_psi_purchase,(条件查询)个数 -->
  613. <select id="countByCond" resultType="Long">
  614. SELECT
  615. count(1)
  616. FROM dkic_b.t_psi_purchase tpp
  617. Left join dkic_b.t_mst_org tmo on tpp.org_id = tmo.org_id
  618. Left join dkic_b.t_mst_supplier tmp on tpp.sup_id = tmp.sup_id
  619. Left join dkic_b.t_mst_staff tms on tpp.staff_id = tms.staff_id
  620. Left join dkic_b.t_mst_staff tms1 on tpp.make_staff = tms1.staff_id
  621. Left join dkic_b.t_mst_warehouse tmw on tpp.wh_id = tmw.wh_id
  622. left join sys.t_data_kind tdk1 on tdk1.kind_code = tpp.into_status
  623. left join sys.t_data_kind tdk2 on tdk2.kind_code = tpp.pur_status
  624. <include refid="Condition_1"/>
  625. </select>
  626. <!-- 查询表dkic_b.t_psi_purchase,(条件查询+分页)列表 -->
  627. <select id="noStoredSelectByCond" resultMap="BaseResultMapResponse">
  628. SELECT
  629. <include refid="Base_Column_List_Left_join"/>
  630. ,tmo.org_name as "orgName"
  631. ,tms.staff_name as "staffName"
  632. ,tms1.staff_name as "makeStaffName"
  633. ,tmp.sup_name as "supplierName"
  634. ,tmw.wh_name as "whName",
  635. sys.f_get_name_i18n(tdk.kind_name_i18n, #{i18n}) AS "intoStatusName"
  636. FROM dkic_b.t_psi_purchase tpp
  637. Left join dkic_b.t_mst_org tmo on tpp.org_id = tmo.org_id
  638. Left join dkic_b.t_mst_supplier tmp on tpp.sup_id = tmp.sup_id
  639. Left join dkic_b.t_mst_staff tms on tpp.staff_id = tms.staff_id
  640. Left join dkic_b.t_mst_staff tms1 on tpp.make_staff = tms1.staff_id
  641. Left join dkic_b.t_mst_warehouse tmw on tpp.wh_id = tmw.wh_id
  642. LEFT JOIN sys.t_data_kind tdk ON tdk.kind_code = tpp.into_status
  643. <include refid="Condition_1"/>
  644. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  645. limit #{end} offset #{start}
  646. </if>
  647. </select>
  648. <!-- 查询表dkic_b.t_psi_purchase,(条件查询)个数 -->
  649. <select id="noStoredCountByCond" resultType="Long">
  650. SELECT
  651. count(1)
  652. FROM dkic_b.t_psi_purchase tpp
  653. <include refid="Condition_1"/>
  654. </select>
  655. <update id="updateAmount" parameterType="com.dk.mdm.model.pojo.pur.Purchase">
  656. update dkic_b.t_psi_purchase
  657. <set>
  658. <if test="returnQty!= null">
  659. return_qty= #{returnQty},
  660. </if>
  661. <if test="returnAmt!= null">
  662. return_amt = #{returnAmt},
  663. </if>
  664. </set>
  665. where pur_id = #{purId}::uuid
  666. </update>
  667. <!-- 查询原始数据 冲正用-->
  668. <select id="selectPurchaseByRighting" resultMap="BaseResultMap">
  669. SELECT
  670. <include refid="Base_Column_List_Left_join"/>
  671. FROM dkic_b.t_psi_purchase tpp
  672. <where>
  673. <if test="orderId!=null">
  674. tpp.pur_id = #{purId}::uuid
  675. </if>
  676. </where>
  677. </select>
  678. <!-- 根据id修改-->
  679. <update id="updateById" parameterType="com.dk.mdm.model.pojo.pur.Purchase">
  680. update dkic_b.t_psi_purchase
  681. <set>
  682. <if test=" et!=null and et.purNo != null">
  683. pur_no = #{et.purNo,jdbcType=VARCHAR},
  684. </if>
  685. <if test=" et!=null and et.purType != null">
  686. pur_type = #{et.purType,jdbcType=VARCHAR},
  687. </if>
  688. <if test=" et!=null and et.orgId != null">
  689. org_id = #{et.orgId,typeHandler=UuidTypeHandler},
  690. </if>
  691. <if test=" et!=null and et.staffId != null">
  692. staff_id = #{et.staffId,typeHandler=UuidTypeHandler},
  693. </if>
  694. <if test=" et!=null and et.supId != null">
  695. sup_id = #{et.supId,typeHandler=UuidTypeHandler},
  696. </if>
  697. <if test=" et!=null and et.contactName != null">
  698. contact_name = #{et.contactName,jdbcType=VARCHAR},
  699. </if>
  700. <if test=" et!=null and et.contactPhone != null">
  701. contact_phone = #{et.contactPhone,jdbcType=VARCHAR},
  702. </if>
  703. <if test=" et!=null and et.pickupDate != null">
  704. pickup_date = #{et.pickupDate,jdbcType=DATE},
  705. </if>
  706. <if test=" et!=null and et.sumQuantity != null">
  707. sum_quantity = #{et.sumQuantity,jdbcType=NUMERIC},
  708. </if>
  709. <if test=" et!=null and et.sumStandard != null">
  710. sum_standard = #{et.sumStandard,jdbcType=NUMERIC},
  711. </if>
  712. <if test=" et!=null and et.sumAmount != null">
  713. sum_amount = #{et.sumAmount,jdbcType=NUMERIC},
  714. </if>
  715. <if test=" et!=null and et.purDiscount != null">
  716. pur_discount = #{et.purDiscount,jdbcType=NUMERIC},
  717. </if>
  718. <if test=" et!=null and et.purStatus != null">
  719. pur_status = #{et.purStatus,jdbcType=VARCHAR},
  720. </if>
  721. <if test=" et!=null and et.intoStatus != null">
  722. into_status = #{et.intoStatus,jdbcType=VARCHAR},
  723. </if>
  724. <if test=" et!=null and et.intoingQty != null">
  725. intoing_qty = intoing_qty + #{et.intoingQty,jdbcType=NUMERIC},
  726. </if>
  727. <if test=" et!=null and et.intoingAmt != null">
  728. intoing_amt = intoing_amt + #{et.intoingAmt,jdbcType=NUMERIC},
  729. </if>
  730. <if test=" et!=null and et.intoQty != null">
  731. into_qty = into_qty + #{et.intoQty,jdbcType=NUMERIC},
  732. </if>
  733. <if test=" et!=null and et.intoAmt != null">
  734. into_amt = into_amt + #{et.intoAmt,jdbcType=NUMERIC},
  735. </if>
  736. <if test=" et!=null and et.returnQty != null">
  737. return_qty = #{et.returnQty,jdbcType=NUMERIC},
  738. </if>
  739. <if test=" et!=null and et.returnAmt != null">
  740. return_amt = #{et.returnAmt,jdbcType=NUMERIC},
  741. </if>
  742. <if test=" et!=null and et.amtPayable != null">
  743. amt_payable = #{et.amtPayable,jdbcType=NUMERIC},
  744. </if>
  745. <if test=" et!=null and et.amtHandle != null">
  746. amt_handle = #{et.amtHandle,jdbcType=NUMERIC},
  747. </if>
  748. <if test=" et!=null and et.amtResidue != null">
  749. amt_residue = #{et.amtResidue,jdbcType=NUMERIC},
  750. </if>
  751. <if test=" et!=null and et.remarks != null">
  752. remarks = #{et.remarks,jdbcType=VARCHAR},
  753. </if>
  754. <if test=" et!=null and et.annexPaths != null">
  755. annex_paths = #{et.annexPaths,typeHandler=JsonTypeHandler},
  756. </if>
  757. <if test=" et!=null and et.makeStaff != null">
  758. make_staff = #{et.makeStaff,jdbcType=OTHER},
  759. </if>
  760. <if test=" et!=null and et.makeTime != null">
  761. make_time = #{et.makeTime,jdbcType=TIMESTAMP},
  762. </if>
  763. <if test=" et!=null and et.flgValid != null">
  764. flg_valid = #{et.flgValid,jdbcType=BOOLEAN},
  765. </if>
  766. <if test=" et!=null and et.cpId != null">
  767. cp_id = #{et.cpId,jdbcType=INTEGER},
  768. </if>
  769. <if test=" et!=null and et.whId != null">
  770. wh_id = #{et.whId,typeHandler=UuidTypeHandler},
  771. </if>
  772. <if test=" et!=null and et.flgAutoHandle != null">
  773. flg_auto_handle = #{et.flgAutoHandle,jdbcType=BOOLEAN},
  774. </if>
  775. <if test=" et!=null and et.inboundProcessingFlag != null">
  776. inbound_processing_flag = #{et.inboundProcessingFlag,jdbcType=BOOLEAN},
  777. </if>
  778. </set>
  779. where pur_id = #{et.purId,typeHandler=UuidTypeHandler}
  780. and sum_quantity >= (into_qty + intoing_qty)
  781. </update>
  782. <!-- 采购跟踪-->
  783. <select id="selectTrackReport" resultType="java.util.Map">
  784. SELECT *
  785. FROM dkic_b.f_query_pur_for_track(#{purId}::uuid,#{cpId},#{i18n})
  786. </select>
  787. <select id="selectPurOrderAndDeatil" resultType="java.util.Map">
  788. SELECT
  789. tpp.pur_id AS "purId"
  790. ,tpp.pur_no AS "purNo"
  791. ,tpp.pur_type AS "purType"
  792. ,tpp.org_id AS "orgId"
  793. ,tpp.staff_id AS "staffId"
  794. ,tpp.sup_id AS "supId"
  795. ,tpp.contact_name AS "contactName"
  796. ,tpp.contact_phone AS "contactPhone"
  797. ,tpp.pickup_date AS "pickupDate"
  798. ,sys.f_remove_zero(tpp.sum_quantity) AS "sumQuantity"
  799. ,tpp.sum_standard AS "sumStandard"
  800. ,tpp.sum_amount AS "sumAmount"
  801. ,tpp.pur_discount AS "purDiscount"
  802. ,tpp.pur_status AS "purStatus"
  803. ,tpp.into_status AS "intoStatus"
  804. ,sys.f_remove_zero(tpp.intoing_qty) AS "intoingQty"
  805. ,tpp.intoing_amt AS "intoingAmt"
  806. ,sys.f_remove_zero(tpp.into_qty) AS "intoQty"
  807. ,tpp.into_amt AS "intoAmt"
  808. ,sys.f_remove_zero(tpp.return_qty) AS "returnQty"
  809. ,tpp.return_amt AS "returnAmt"
  810. ,tpp.amt_payable AS "amtPayable"
  811. ,tpp.amt_handle AS "amtHandle"
  812. ,tpp.amt_residue AS "amtResidue"
  813. ,tpp.remarks AS "remarks"
  814. ,tpp.annex_paths AS "annexPaths"
  815. ,tpp.make_staff AS "makeStaff"
  816. ,tpp.make_time AS "makeTime"
  817. ,tpp.flg_valid AS "flgValid"
  818. ,tpp.cp_id AS "cpId"
  819. ,tpp.op_create_time AS "opCreateTime"
  820. ,tpp.op_create_user_id AS "opCreateUserId"
  821. ,tpp.op_update_time AS "opUpdateTime"
  822. ,tpp.op_update_user_id AS "opUpdateUserId"
  823. ,tpp.op_app_code AS "opAppCode"
  824. ,tpp.op_timestamp AS "opTimestamp"
  825. ,tpp.op_db_user AS "opDbUser"
  826. ,tpp.wh_id AS "whId"
  827. ,tpp.from_ids AS "fromIds"
  828. ,tpp.from_nos AS "fromNos"
  829. ,tmo.org_name as "orgName"
  830. ,tms.staff_name as "staffName"
  831. ,tms1.staff_name as "makeStaffName"
  832. ,tmp.sup_name as "supplierName"
  833. ,tmp.return_address as "returnAddress"
  834. ,tmw.wh_name as "whName"
  835. ,sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "intoStatusName"
  836. ,sys.f_get_name_i18n(tdk2.kind_name_i18n, #{i18n}) as "purStatusName"
  837. ,CASE
  838. WHEN tpp.pur_status = '订单状态-暂存' THEN sys.f_get_name_i18n(tdk2.kind_name_i18n, #{i18n})
  839. WHEN tpp.pur_status != '订单状态-暂存' THEN sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n})
  840. END AS "displayedStatus"
  841. , (
  842. SELECT
  843. json_agg ( row_to_json ( item ) )
  844. FROM
  845. ( SELECT
  846. tppi.item_id AS "itemId"
  847. ,tppi.pur_id AS "purId"
  848. ,tppi.item_index AS "itemIndex"
  849. ,tppi.sku_id AS "skuId"
  850. ,tppi.item_qty AS "itemQty"
  851. ,tppi.price_std as "priceStd"
  852. ,tppi.amt_std AS "amtStd"
  853. ,tppi.price_pur AS "pricePur"
  854. ,tppi.item_amt AS "itemAmt"
  855. ,tppi.price_discount AS "priceDiscount"
  856. ,tppi.non_std_code AS "nonStdCode"
  857. ,tppi.into_status AS "intoStatus"
  858. ,tppi.intoing_qty AS "intoingQty"
  859. ,tppi.intoing_amt AS "intoingAmt"
  860. ,tppi.into_qty AS "intoQty"
  861. ,tppi.into_amt AS "intoAmt"
  862. ,tppi.return_qty AS "returnQty"
  863. ,tppi.return_amt AS "returnAmt"
  864. ,tppi.remarks AS "remarks"
  865. ,tppi.flg_valid AS "flagValid"
  866. ,tppi.cp_id AS "cpId"
  867. ,tppi.op_create_time AS "opCreateTime"
  868. ,tppi.op_create_user_id AS "opCreateUserId"
  869. ,tppi.op_update_time AS "opUpdateTime"
  870. ,tppi.op_update_user_id AS "opUpdateUserId"
  871. ,tppi.op_app_code AS "opAppCode"
  872. ,tppi.op_timestamp AS "opTimestamp"
  873. ,tppi.op_db_user AS "opDbUser"
  874. ,tppi.from_id AS "fromId"
  875. ,tppi.from_item_id AS "fromItemId"
  876. ,tpoitem.order_no as "orderNo"
  877. ,tmgsitem.sku_code as "skuCode"
  878. ,tmgsitem.sku_model as "skuModel"
  879. ,tmgsitem.sku_name as "skuName"
  880. ,tmgsitem.sku_images as "skuImages"
  881. ,tmgbitem.brand_name as "brandName"
  882. ,tmgbitem.short_name as "shortName"
  883. ,tmgsitem.sku_spec as "skuSpec"
  884. ,tmgsitem.price_purchase as "pricePurchase"
  885. ,tmgsitem.price_standard as "priceStandard"
  886. ,sys.f_get_name_i18n(tdk1item.kind_name_i18n, #{i18n}) as "intoStatusName"
  887. ,i.inv_id AS "invId"
  888. ,i.inv_qty AS "invQty"
  889. ,i.usable_qty AS "usableQty"
  890. ,tppitem.pur_no as "purNo"
  891. ,tppi.unit_id AS "unitId"
  892. ,tppi.sub_unit_id AS "subUnitId"
  893. ,tppi.pack_box AS "packBox"
  894. ,tppi.box AS "box"
  895. ,tppi.piece AS "piece"
  896. ,tmguitems.unit_name as "subUnitName"
  897. ,tmguitem.unit_name as "unitName"
  898. ,tmgsitem.flg_sub_unit as "flgSubUnit"
  899. FROM dkic_b.t_psi_purchase_item tppi
  900. left join(SELECT T.*
  901. FROM (select tpi.inv_id,
  902. tpi.wh_id,
  903. tpi.inv_qty,
  904. tpi.usable_qty,
  905. tpi.sku_id,
  906. tpi.non_std_code,
  907. tpi.cp_id,
  908. tmwitem.wh_name,
  909. rank()
  910. over (partition by tpi.cp_id,tpi.sku_id,tpi.non_std_code order by tpi.inv_id) as RK
  911. from dkic_b.t_psi_inventory as tpi
  912. left join dkic_b.t_mst_warehouse as tmwitem on tmwitem.wh_id = tpi.wh_id) T
  913. WHERE T.RK = 1) as i on i.sku_id = tppi.sku_id and i.non_std_code = tppi.non_std_code and i.cp_id = tppi.cp_id
  914. left join dkic_b.t_psi_order tpoitem on tpoitem.order_id = tppi.from_id
  915. left join dkic_b.t_mst_goods_sku tmgsitem on tppi.sku_id = tmgsitem.sku_id
  916. left join dkic_b.t_mst_goods_brand tmgbitem on tmgbitem.brand_id = tmgsitem.brand_id
  917. left join sys.t_data_kind tdk1item on tdk1item.kind_code = tppi.into_status
  918. left join dkic_b.t_psi_purchase tppitem on tppitem.pur_id = tppi.pur_id
  919. left join dkic_b.t_mst_unit as tmguitem on tppi.unit_id = tmguitem.unit_id
  920. left join dkic_b.t_mst_unit as tmguitems on tppi.sub_unit_id = tmguitems.unit_id
  921. WHERE
  922. tppi.pur_id = tpp.pur_id
  923. AND tppi.into_status != '入库状态-已入库'
  924. <if test="cpId != null">
  925. AND tppi.cp_id = #{cpId}
  926. </if>
  927. <if test="flgValid != null">
  928. AND tppi.flg_valid = #{flgValid}
  929. </if>
  930. ) item
  931. ) AS "purchaseItemResponseList"
  932. FROM dkic_b.t_psi_purchase tpp
  933. Left join dkic_b.t_mst_org tmo on tpp.org_id = tmo.org_id
  934. Left join dkic_b.t_mst_supplier tmp on tpp.sup_id = tmp.sup_id
  935. Left join dkic_b.t_mst_staff tms on tpp.staff_id = tms.staff_id
  936. Left join dkic_b.t_mst_staff tms1 on tpp.make_staff = tms1.staff_id
  937. Left join dkic_b.t_mst_warehouse tmw on tpp.wh_id = tmw.wh_id
  938. left join sys.t_data_kind tdk1 on tdk1.kind_code = tpp.into_status
  939. left join sys.t_data_kind tdk2 on tdk2.kind_code = tpp.pur_status
  940. where tpp.into_status != '入库状态-已入库'
  941. <if test="searchText !=null and searchText!='' " >
  942. AND ( tmp.sup_name LIKE concat('%',my_ex.likequery(#{searchText}), '%')or
  943. tpp.pur_no LIKE concat('%',my_ex.likequery(#{searchText}), '%'))
  944. </if>
  945. <if test="flgValid != null">
  946. AND tpp.flg_valid = #{flgValid}
  947. </if>
  948. <if test="cpId != null">
  949. AND tpp.cp_id = #{cpId}
  950. </if>
  951. order by tpp.make_time desc
  952. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  953. limit #{end} offset #{start}
  954. </if>
  955. </select>
  956. <!-- 查询表dkic_b.t_psi_purchase,(条件查询+分页)列表 -->
  957. <select id="selectTotalDetail" resultMap="BaseResultMapResponse">
  958. SELECT
  959. <include refid="Base_Column_List_Left_join"/>
  960. <include refid="Base_Column_List_Item_Response_Join"/>
  961. ,tmgb.brand_name as "list_brand_name"
  962. ,(select count(DISTINCT tmgss.category_id) from dkic_b.t_psi_purchase_item ti
  963. LEFT JOIN dkic_b.t_mst_goods_sku tmgss ON tmgss.sku_id = ti.sku_id
  964. where ti.pur_id = tpp.pur_id and ti.flg_valid) as "category_count"
  965. ,tmo.org_name as "orgName"
  966. ,tms.staff_name as "staffName"
  967. ,tms1.staff_name as "makeStaffName"
  968. ,tmp.sup_name as "supplierName"
  969. ,tmw.wh_name as "whName"
  970. FROM dkic_b.t_psi_purchase tpp
  971. left join dkic_b.t_psi_purchase_item tppi on tppi.pur_id = tpp.pur_id
  972. left join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tppi.sku_id
  973. left join dkic_b.t_mst_goods_brand tmgb on tmgb.brand_id = tmgs.brand_id
  974. left join dkic_b.t_psi_inventory tpit on tpit.sku_id = tppi.sku_id
  975. Left join dkic_b.t_mst_org tmo on tpp.org_id = tmo.org_id
  976. Left join dkic_b.t_mst_supplier tmp on tpp.sup_id = tmp.sup_id
  977. Left join dkic_b.t_mst_staff tms on tpp.staff_id = tms.staff_id
  978. Left join dkic_b.t_mst_staff tms1 on tpp.make_staff = tms1.staff_id
  979. Left join dkic_b.t_mst_warehouse tmw on tpp.wh_id = tmw.wh_id
  980. left join sys.t_data_kind tdk1 on tdk1.kind_code = tpp.into_status
  981. left join sys.t_data_kind tdk2 on tdk2.kind_code = tpp.pur_status
  982. <include refid="Condition_1"/>
  983. ORDER BY tpp.make_time
  984. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  985. limit #{end} offset #{start}
  986. </if>
  987. </select>
  988. <select id="selectTotalDetailCount" resultType="Long">
  989. SELECT
  990. count(1)
  991. FROM dkic_b.t_psi_purchase tpp
  992. Left join dkic_b.t_mst_org tmo on tpp.org_id = tmo.org_id
  993. Left join dkic_b.t_mst_supplier tmp on tpp.sup_id = tmp.sup_id
  994. Left join dkic_b.t_mst_staff tms on tpp.staff_id = tms.staff_id
  995. Left join dkic_b.t_mst_staff tms1 on tpp.make_staff = tms1.staff_id
  996. Left join dkic_b.t_mst_warehouse tmw on tpp.wh_id = tmw.wh_id
  997. left join sys.t_data_kind tdk1 on tdk1.kind_code = tpp.into_status
  998. left join sys.t_data_kind tdk2 on tdk2.kind_code = tpp.pur_status
  999. <include refid="Condition_1"/>
  1000. </select>
  1001. </mapper>