PurchaseMapper.xml 48 KB

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