OrderItemMapper.xml 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  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.sale.OrderItemMapper">
  4. <!-- 通用设置 -->
  5. <!-- 通用查询列 -->
  6. <sql id="Base_Column_List">
  7. item_id
  8. , order_id, item_index, sku_id, sub_unit_id, unit_id,pack_box,box, piece,
  9. sys.f_remove_zero(item_qty) as item_qty, price_std, amt_std, price_sale, item_amt, price_discount, non_std_code, out_status,
  10. sys.f_remove_zero(outing_qty) as outing_qty, outing_amt, sys.f_remove_zero(out_qty) as out_qty, out_amt,
  11. sys.f_remove_zero(return_qty) as return_qty, return_amt, remarks, flg_valid, cp_id, wh_id,
  12. fact_price,fact_amt,use_place,discount
  13. </sql>
  14. <sql id="Base_Column_List_Response">
  15. t.item_id, t.order_id, t.item_index, t.sku_id, sys.f_remove_zero(t.item_qty) as item_qty, t.price_std, t.amt_std, t.price_sale, t.item_amt, t.price_discount, t.non_std_code,
  16. t.out_status, sys.f_remove_zero(t.outing_qty) as outing_qty, t.outing_amt, sys.f_remove_zero(t.out_qty) as out_qty, t.out_amt,
  17. sys.f_remove_zero(t.return_qty) as return_qty, t.return_amt, t.remarks, t.flg_valid, t.cp_id, t.wh_id
  18. ,t.box,t.piece,t.sub_unit_id,t.unit_id,t.pack_box,
  19. t.fact_price,t.fact_amt,t.use_place,t.discount
  20. </sql>
  21. <!-- 通用查询映射结果 -->
  22. <resultMap id="BaseResultMap" type="com.dk.mdm.model.pojo.sale.OrderItem">
  23. <id column="item_id" property="itemId"/>
  24. <result column="order_id" property="orderId" typeHandler="UuidTypeHandler"/>
  25. <result column="item_index" property="itemIndex"/>
  26. <result column="sku_id" property="skuId" typeHandler="UuidTypeHandler"/>
  27. <result column="unit_id" property="unitId" typeHandler="UuidTypeHandler"/>
  28. <result column="sub_unit_id" property="subUnitId" typeHandler="UuidTypeHandler"/>
  29. <result column="pack_box" property="packBox"/>
  30. <result column="box" property="box"/>
  31. <result column="piece" property="piece"/>
  32. <result column="item_qty" property="itemQty"/>
  33. <result column="price_std" property="priceStd"/>
  34. <result column="amt_std" property="amtStd"/>
  35. <result column="price_sale" property="priceSale"/>
  36. <result column="item_amt" property="itemAmt"/>
  37. <result column="price_discount" property="priceDiscount"/>
  38. <result column="non_std_code" property="nonStdCode"/>
  39. <result column="out_status" property="outStatus"/>
  40. <result column="outing_qty" property="outingQty"/>
  41. <result column="outing_amt" property="outingAmt"/>
  42. <result column="out_qty" property="outQty"/>
  43. <result column="out_amt" property="outAmt"/>
  44. <result column="return_qty" property="returnQty"/>
  45. <result column="return_amt" property="returnAmt"/>
  46. <result column="remarks" property="remarks"/>
  47. <result column="flg_valid" property="flgValid"/>
  48. <result column="cp_id" property="cpId"/>
  49. <result column="wh_id" property="whId"/>
  50. <result column="decimalPlaces" property="decimalPlaces"/>
  51. <result column="fact_price" property="factPrice"/>
  52. <result column="fact_amt" property="factAmt"/>
  53. <result column="use_place" property="usePlace"/>
  54. <result column="discount" property="discount"/>
  55. <result column="sup_id" property="supId"/>
  56. </resultMap>
  57. <!-- 通用查询映射结果 -->
  58. <resultMap id="BaseResultMapResponse" type="com.dk.mdm.model.response.sale.OrderItemResponse">
  59. <id column="item_id" property="itemId"/>
  60. <result column="order_id" property="orderId" typeHandler="UuidTypeHandler"/>
  61. <result column="item_index" property="itemIndex"/>
  62. <result column="sku_id" property="skuId" typeHandler="UuidTypeHandler"/>
  63. <result column="unit_id" property="unitId" typeHandler="UuidTypeHandler"/>
  64. <result column="sub_unit_id" property="subUnitId" typeHandler="UuidTypeHandler"/>
  65. <result column="pack_box" property="packBox"/>
  66. <result column="item_qty" property="itemQty"/>
  67. <result column="price_std" property="priceStd"/>
  68. <result column="amt_std" property="amtStd"/>
  69. <result column="price_sale" property="priceSale"/>
  70. <result column="item_amt" property="itemAmt"/>
  71. <result column="price_discount" property="priceDiscount"/>
  72. <result column="non_std_code" property="nonStdCode"/>
  73. <result column="out_status" property="outStatus"/>
  74. <result column="outing_qty" property="outingQty"/>
  75. <result column="outing_amt" property="outingAmt"/>
  76. <result column="out_qty" property="outQty"/>
  77. <result column="out_amt" property="outAmt"/>
  78. <result column="return_qty" property="returnQty"/>
  79. <result column="return_amt" property="returnAmt"/>
  80. <result column="remarks" property="remarks"/>
  81. <result column="flg_valid" property="flgValid"/>
  82. <result column="cp_id" property="cpId"/>
  83. <result column="wh_id" property="whId"/>
  84. <result column="wh_name" property="whName"/>
  85. <result column="order_no" property="orderNo"/>
  86. <result column="brand_name" property="brandName"/>
  87. <result column="short_name" property="shortName"/>
  88. <result column="sku_images" property="skuImages" typeHandler="JsonTypeHandler"/>
  89. <result column="transferableQuantity" property="transferableQuantity"/>
  90. <result column="skuImages" property="skuImages" typeHandler="JsonTypeHandler"/>
  91. <result column="decimalPlaces" property="decimalPlaces"/>
  92. <result column="fact_price" property="factPrice"/>
  93. <result column="fact_amt" property="factAmt"/>
  94. <result column="use_place" property="usePlace"/>
  95. <result column="discount" property="discount"/>
  96. <result column="sup_id" property="supId" typeHandler="UuidTypeHandler"/>
  97. <result column="canOutingQty" property="canOutingQty"/>
  98. <result column="canReturnQty" property="canReturnQty"/>
  99. <result column="cus_code" property="cusCode"/>
  100. <result column="cus_name" property="cusName"/>
  101. <result column="cus_phone" property="cusPhone"/>
  102. <result column="address_full" property="addressFull"/>
  103. <result column="channel_name" property="channelName"/>
  104. <result column="sku_code" property="skuCode"/>
  105. <result column="sku_model" property="skuModel"/>
  106. <result column="sku_name" property="skuName"/>
  107. <result column="skuModel" property="skuModel"/>
  108. <result column="skuName" property="skuName"/>
  109. <result column="can_out_qty" property="canOutQty"/>
  110. <result column="cost_price" property="costPrice"/>
  111. <result column="cost_amt" property="costAmt"/>
  112. <result column="into_id" property="intoId" typeHandler="UuidTypeHandler"/>
  113. <result column="price_purchase" property="pricePurchase"/>
  114. </resultMap>
  115. <!-- 通用条件列 -->
  116. <sql id="Condition">
  117. <where>
  118. <if test="orderId != null and orderId != ''">
  119. AND t.order_id = #{orderId}::uuid
  120. </if>
  121. <if test="itemIndex != null">
  122. AND t.item_index = #{itemIndex}
  123. </if>
  124. <if test="skuId != null and skuId != ''">
  125. AND t.sku_id = #{skuId}
  126. </if>
  127. <if test="itemQty != null">
  128. AND t.item_qty = #{itemQty}
  129. </if>
  130. <if test="priceStd != null">
  131. AND t.price_std = #{priceStd}
  132. </if>
  133. <if test="amtStd != null">
  134. AND t.amt_std = #{amtStd}
  135. </if>
  136. <if test="priceSale != null">
  137. AND t.price_sale = #{priceSale}
  138. </if>
  139. <if test="itemAmt != null">
  140. AND t.item_amt = #{itemAmt}
  141. </if>
  142. <if test="priceDiscount != null">
  143. AND t.price_discount = #{priceDiscount}
  144. </if>
  145. <if test="nonStdCode != null and nonStdCode != ''">
  146. AND t.non_std_code = #{nonStdCode}
  147. </if>
  148. <if test="outStatus != null and outStatus != ''">
  149. AND t.out_status = #{outStatus}
  150. </if>
  151. <if test="outingQty != null">
  152. AND t.outing_qty = #{outingQty}
  153. </if>
  154. <if test="outingAmt != null">
  155. AND t.outing_amt = #{outingAmt}
  156. </if>
  157. <if test="outQty != null">
  158. AND t.out_qty = #{outQty}
  159. </if>
  160. <if test="outAmt != null">
  161. AND t.out_amt = #{outAmt}
  162. </if>
  163. <if test="returnQty != null">
  164. AND t.return_qty = #{returnQty}
  165. </if>
  166. <if test="returnAmt != null">
  167. AND t.return_amt = #{returnAmt}
  168. </if>
  169. <if test="remarks != null and remarks != ''">
  170. AND t.remarks = #{remarks}
  171. </if>
  172. <if test="flgValid != null">
  173. AND t.flg_valid = #{flgValid}
  174. </if>
  175. <if test="cpId != null">
  176. AND t.cp_id = #{cpId}
  177. </if>
  178. </where>
  179. </sql>
  180. <sql id="idsForeach">
  181. <!-- 根据主键itemId批量操作 -->
  182. WHERE item_id in
  183. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  184. #{item}
  185. </foreach>
  186. </sql>
  187. <!-- 查询表t_psi_order_item,(条件查询+分页)列表 -->
  188. <select id="selectByCond" resultMap="BaseResultMapResponse">
  189. SELECT t.item_id,
  190. t.order_id,
  191. t.item_index,
  192. t.sku_id,
  193. tmgs.sku_code as "skuCode",
  194. t.sku_model as "skuModel",
  195. t.sku_name as "skuName",
  196. tmgs.sku_images,
  197. case when t.sku_id is null then '外协' else tmgb.brand_name end AS brand_name,
  198. tmgb.short_name,
  199. dkic_b.f_box_piece(u2.unit_name,ul.unit_name,t.box,t.piece) AS "boxPiece",
  200. t.pack_box,
  201. t.box,
  202. t.piece,
  203. sys.f_remove_zero(t.item_qty) as item_qty,
  204. t.price_std,
  205. t.amt_std,
  206. t.price_sale,
  207. t.item_amt,
  208. t.price_discount,
  209. t.fact_price,
  210. t.fact_amt,
  211. t.use_place,
  212. t.discount,
  213. t.non_std_code,
  214. t.out_status,
  215. sys.f_remove_zero(t.outing_qty) as outing_qty,
  216. t.outing_amt,
  217. sys.f_remove_zero(t.out_qty) as out_qty,
  218. t.out_amt,
  219. sys.f_remove_zero(t.return_qty) as return_qty,
  220. t.return_amt,
  221. t.remarks,
  222. t.wh_id,
  223. tmw.wh_name
  224. ,ul.decimal_places as "decimalPlaces"
  225. ,t.unit_id
  226. ,t.sup_id
  227. ,t.sub_unit_id
  228. ,ul.unit_name as "unitName"
  229. ,u2.unit_name as "subUnitName"
  230. ,t.cost_price
  231. ,t.cost_amt
  232. ,tpii.into_id
  233. FROM dkic_b.t_psi_order_item as t
  234. LEFT join dkic_b.t_psi_inbound_item tpii on t.item_id = tpii.from_item_id
  235. LEFT join dkic_b.t_mst_goods_sku tmgs on t.sku_id = tmgs.sku_id
  236. LEFT JOIN dkic_b.t_mst_unit AS ul ON tmgs.unit_id = ul.unit_id
  237. LEFT JOIN dkic_b.t_mst_unit AS u2 ON tmgs.sub_unit_id = u2.unit_id
  238. LEFT join dkic_b.t_mst_goods_brand tmgb on tmgb.brand_id = tmgs.brand_id
  239. left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = t.wh_id
  240. <include refid="Condition"/>
  241. order by t.item_index
  242. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  243. limit #{end} offset #{start}
  244. </if>
  245. </select>
  246. <!-- 查询表t_psi_order_item,(条件查询)个数 -->
  247. <select id="countByCond" resultType="Long">
  248. SELECT
  249. count(1)
  250. FROM dkic_b.t_psi_order_item as t
  251. <include refid="Condition"/>
  252. </select>
  253. <!-- 根据主键查询表t_psi_order_item的一行数据 -->
  254. <select id="selectById" resultMap="BaseResultMapResponse">
  255. SELECT
  256. <include refid="Base_Column_List_Response"/>
  257. ,(select ul.decimal_places from dkic_b.t_mst_unit ul where t.unit_id = ul.unit_id) as "decimalPlaces"
  258. FROM dkic_b.t_psi_order_item t
  259. WHERE t.item_id = #{id}::uuid
  260. </select>
  261. <!-- 根据主键锁定表t_psi_order_item的一行数据 -->
  262. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  263. SELECT
  264. <include refid="Base_Column_List"/>
  265. ,(select ul.decimal_places from dkic_b.t_mst_unit ul where dkic_b.t_psi_order_item.unit_id = ul.unit_id) as "decimalPlaces"
  266. FROM dkic_b.t_psi_order_item
  267. WHERE item_id = #{id}::uuid
  268. for update
  269. </select>
  270. <!-- 根据主表主键锁定表t_psi_order_item的一行数据 -->
  271. <select id="selectByZIdForUpdate" resultMap="BaseResultMap">
  272. SELECT
  273. <include refid="Base_Column_List"/>
  274. ,(select ul.decimal_places from dkic_b.t_mst_unit ul where dkic_b.t_psi_order_item.unit_id = ul.unit_id) as "decimalPlaces"
  275. FROM dkic_b.t_psi_order_item
  276. WHERE order_id = #{id}::uuid
  277. for update
  278. </select>
  279. <!-- 根据主键锁定表t_psi_order_item的多行数据 -->
  280. <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
  281. SELECT
  282. <include refid="Base_Column_List"/>
  283. ,(select ul.decimal_places from dkic_b.t_mst_unit ul where dkic_b.t_psi_order_item.unit_id = ul.unit_id) as "decimalPlaces"
  284. FROM dkic_b.t_psi_order_item
  285. <include refid="idsForeach"/>
  286. for update
  287. </select>
  288. <insert id="insertBatch">
  289. insert into dkic_b.t_psi_order_item
  290. (
  291. <trim suffixOverrides=",">
  292. order_id,
  293. item_index,
  294. sku_id,
  295. item_qty,
  296. price_std,
  297. amt_std,
  298. price_sale,
  299. item_amt,
  300. price_discount,
  301. non_std_code,
  302. out_status,
  303. outing_qty,
  304. outing_amt,
  305. out_qty,
  306. out_amt,
  307. return_qty,
  308. return_amt,
  309. remarks,
  310. cp_id,
  311. wh_id,
  312. </trim>
  313. )
  314. values
  315. <foreach collection="list" index="index" item="item" separator=",">
  316. (
  317. <trim suffixOverrides=",">
  318. #{item.orderId}::uuid,
  319. #{item.itemIndex},
  320. #{item.skuId}::uuid,
  321. #{item.itemQty},
  322. #{item.priceStd},
  323. #{item.amtStd},
  324. #{item.priceSale},
  325. #{item.itemAmt},
  326. #{item.priceDiscount},
  327. #{item.nonStdCode},
  328. #{item.outStatus},
  329. #{item.outingQty},
  330. #{item.outingAmt},
  331. #{item.outQty},
  332. #{item.outAmt},
  333. #{item.returnQty},
  334. #{item.returnAmt},
  335. #{item.remarks},
  336. #{item.cpId},
  337. #{item.whId},
  338. </trim>
  339. )
  340. </foreach>
  341. </insert>
  342. <delete id="deleteById">
  343. DELETE FROM dkic_b.t_psi_order_item
  344. WHERE item_id = #{id}::UUID;
  345. </delete>
  346. <!-- 根据条件进行查询(出库用) -->
  347. <select id="selectByCondForOut" resultMap="BaseResultMapResponse">
  348. SELECT t.item_id as "fromItemId",
  349. t.order_id as "fromId",
  350. t.item_index,
  351. t.sku_id,
  352. tmgs.sku_code as "skuCode",
  353. t.sku_model as "skuModel",
  354. t.sku_name as "skuName",
  355. tmgs.sku_images AS "skuImages",
  356. t.pack_box ,
  357. sys.f_remove_zero(t.item_qty) as "orderQty",
  358. t.box,
  359. t.piece,
  360. sys.f_remove_zero(t.item_qty - t.outing_qty - t.out_qty) as "canOutingQty",
  361. sys.f_remove_zero(t.item_qty - t.outing_qty - t.out_qty) as outing_qty,
  362. -- (t.item_qty - t.outing_qty - t.out_qty)/t.pack_box as "outingBox",
  363. -- (t.item_qty - t.outing_qty - t.out_qty)%t.pack_box as "outingPiece",
  364. case
  365. when t.sub_unit_id ISNULL
  366. then 0
  367. else
  368. floor((T.item_qty - T.outing_qty - T.out_qty) / T.pack_box)
  369. end AS "outingBox",
  370. case
  371. when t.sub_unit_id ISNULL
  372. then floor(T.item_qty - T.outing_qty - T.out_qty)
  373. else
  374. floor((T.item_qty - T.outing_qty - T.out_qty) % T.pack_box)
  375. end AS "outingPiece",
  376. case
  377. when t.sub_unit_id ISNULL
  378. then dkic_b.f_box_piece(u2.unit_name, ul.unit_name, 0,
  379. floor(T.item_qty - T.outing_qty - T.out_qty)::INT)
  380. else
  381. dkic_b.f_box_piece(u2.unit_name, ul.unit_name,
  382. floor((T.item_qty - T.outing_qty - T.out_qty) / T.pack_box)::INT,
  383. floor((T.item_qty - T.outing_qty - T.out_qty) % T.pack_box)::INT)
  384. end AS "thisOutBoxPiece",
  385. t.price_sale as "priceOut",
  386. t.price_sale * (t.item_qty - t.outing_qty - t.out_qty) as outing_amt,
  387. t.fact_price,
  388. t.fact_amt,
  389. t.discount,
  390. t.non_std_code,
  391. t.remarks,
  392. t.wh_id,
  393. t.sup_id,
  394. t.unit_id,
  395. t.sub_unit_id,
  396. tmw.wh_name,
  397. tpi.inv_id as "invId",
  398. sys.f_remove_zero(tpi.inv_qty) as "invQty",
  399. sys.f_remove_zero(tpi.usable_qty) as "usableQty"
  400. ,(select ul.decimal_places from dkic_b.t_mst_unit ul where t.unit_id = ul.unit_id) as "decimalPlaces"
  401. ,ul.unit_name as "unitName"
  402. ,u2.unit_name as "subUnitName"
  403. ,tmgb.brand_name
  404. ,tmgb.short_name
  405. ,dkic_b.f_box_piece(u2.unit_name,ul.unit_name,t.box,t.piece) as "boxPiece"
  406. FROM dkic_b.t_psi_order_item as t
  407. LEFT join dkic_b.t_mst_goods_sku tmgs on t.sku_id = tmgs.sku_id
  408. left join dkic_b.t_mst_warehouse as tmw on tmw.wh_id = t.wh_id
  409. left join dkic_b.t_psi_inventory as tpi
  410. on tpi.sku_id = t.sku_id and tpi.non_std_code = t.non_std_code
  411. and tpi.wh_id = t.wh_id and tpi.cp_id = t.cp_id
  412. LEFT JOIN dkic_b.t_mst_unit AS ul ON t.unit_id = ul.unit_id
  413. LEFT JOIN dkic_b.t_mst_unit AS u2 ON t.sub_unit_id = u2.unit_id
  414. LEFT join dkic_b.t_mst_goods_brand tmgb on tmgb.brand_id = tmgs.brand_id
  415. where t.flg_valid
  416. and t.item_qty > t.outing_qty
  417. and t.order_id = #{orderId}::uuid
  418. order by t.item_index
  419. </select>
  420. <!-- 根据条件进行查询(退货用) -->
  421. <select id="selectByCondForReturn" resultMap="BaseResultMapResponse">
  422. SELECT tpobi.out_id as "sOutId",
  423. tpobi.item_id as "sOutItemId",
  424. t.order_id as "sOrderId",
  425. t.item_id as "sOrderItemId",
  426. t.sku_id,
  427. tmgs.sku_code as "skuCode",
  428. tpobi.sku_model as "skuModel",
  429. tpobi.sku_name as "skuName",
  430. tmgs.sku_images as "skuImages",
  431. tpobi.out_qty as "outboundOutQty",
  432. sys.f_remove_zero(tpobi.out_qty - tpobi.return_qty) as "canReturnQty",
  433. - sys.f_remove_zero(tpobi.out_qty - tpobi.return_qty) as outing_qty,
  434. t.price_sale as "priceOut",
  435. - t.price_sale * (tpobi.out_qty - tpobi.return_qty) as outing_amt,
  436. tpobi.inv_id as "invId",
  437. 0 as out_qty,
  438. 0 as out_amt,
  439. t.non_std_code,
  440. t.sup_id,
  441. tpobi.remarks,
  442. t.wh_id,
  443. tmw.wh_name
  444. ,(select ul.decimal_places from dkic_b.t_mst_unit ul where tpobi.unit_id = ul.unit_id) as "decimalPlaces"
  445. ,tpobi.pack_box
  446. ,tpobi.unit_id
  447. ,tpobi.sub_unit_id
  448. ,ul.unit_name as "unitName"
  449. ,u2.unit_name as "subUnitName"
  450. ,dkic_b.f_box_piece(u2.unit_name,ul.unit_name,tpobi.outing_box,tpobi.outing_piece) AS "outingBoxPiece"
  451. ,dkic_b.f_box_piece(u2.unit_name,ul.unit_name,tpobi.out_box,tpobi.out_piece) AS "outBoxPiece"
  452. ,tpobi.cost_price
  453. ,tpobi.cost_amt
  454. FROM dkic_b.t_psi_outbound_item as tpobi
  455. inner join dkic_b.t_psi_order_item as t on t.item_id = tpobi.from_item_id
  456. LEFT join dkic_b.t_mst_goods_sku tmgs on t.sku_id = tmgs.sku_id
  457. left join dkic_b.t_mst_warehouse as tmw on tmw.wh_id = t.wh_id
  458. LEFT JOIN dkic_b.t_mst_unit AS ul ON tpobi.unit_id = ul.unit_id
  459. LEFT JOIN dkic_b.t_mst_unit AS u2 ON tpobi.sub_unit_id = u2.unit_id
  460. where tpobi.flg_valid
  461. and tpobi.out_type = '出库类型-销售出库'
  462. and tpobi.out_qty > tpobi.return_qty
  463. and t.order_id = #{orderId}::uuid
  464. order by t.item_index
  465. </select>
  466. <!-- 根据id修改-->
  467. <update id="updateById" parameterType="com.dk.mdm.model.pojo.sale.OrderItem">
  468. update dkic_b.t_psi_order_item
  469. <set>
  470. <if test=" et!=null and et.itemIndex != null">
  471. item_index = #{et.itemIndex,jdbcType=INTEGER},
  472. </if>
  473. <if test=" et!=null and et.skuId != null">
  474. sku_id = #{et.skuId,typeHandler=UuidTypeHandler},
  475. </if>
  476. <if test=" et!=null and et.itemQty != null">
  477. item_qty = #{et.itemQty,jdbcType=NUMERIC},
  478. </if>
  479. <if test=" et!=null and et.priceStd != null">
  480. price_std = #{et.priceStd,jdbcType=NUMERIC},
  481. </if>
  482. <if test=" et!=null and et.amtStd != null">
  483. amt_std = #{et.amtStd,jdbcType=NUMERIC},
  484. </if>
  485. <if test=" et!=null and et.priceSale != null">
  486. price_sale = #{et.priceSale,jdbcType=NUMERIC},
  487. </if>
  488. <if test=" et!=null and et.itemAmt != null">
  489. item_amt = #{et.itemAmt,jdbcType=NUMERIC},
  490. </if>
  491. <if test=" et!=null and et.priceDiscount != null">
  492. price_discount = #{et.priceDiscount,jdbcType=NUMERIC},
  493. </if>
  494. <if test=" et!=null and et.nonStdCode != null">
  495. non_std_code = #{et.nonStdCode,jdbcType=VARCHAR},
  496. </if>
  497. <if test=" et!=null and et.outStatus != null">
  498. out_status = #{et.outStatus,jdbcType=VARCHAR},
  499. </if>
  500. <if test=" et!=null and et.outingQty != null">
  501. outing_qty = outing_qty + #{et.outingQty,jdbcType=NUMERIC},
  502. </if>
  503. <if test=" et!=null and et.outingAmt != null">
  504. outing_amt = outing_amt + #{et.outingAmt,jdbcType=NUMERIC},
  505. </if>
  506. <if test=" et!=null and et.outQty != null">
  507. out_qty = out_qty + #{et.outQty,jdbcType=NUMERIC},
  508. </if>
  509. <if test=" et!=null and et.outAmt != null">
  510. out_amt = out_amt + #{et.outAmt,jdbcType=NUMERIC},
  511. </if>
  512. <if test=" et!=null and et.returnQty != null">
  513. return_qty = #{et.returnQty,jdbcType=NUMERIC},
  514. </if>
  515. <if test=" et!=null and et.returnAmt != null">
  516. return_amt = #{et.returnAmt,jdbcType=NUMERIC},
  517. </if>
  518. <if test=" et!=null and et.remarks != null">
  519. remarks = #{et.remarks,jdbcType=VARCHAR},
  520. </if>
  521. <if test=" et!=null and et.flgValid != null">
  522. flg_valid = #{et.flgValid,jdbcType=BOOLEAN},
  523. </if>
  524. <if test=" et!=null and et.cpId != null">
  525. cp_id = #{et.cpId,jdbcType=INTEGER},
  526. </if>
  527. <if test=" et!=null and et.factPrice != null">
  528. fact_price = #{et.factPrice,jdbcType=NUMERIC},
  529. </if>
  530. <if test=" et!=null and et.factAmt != null">
  531. fact_amt = #{et.factAmt,jdbcType=NUMERIC},
  532. </if>
  533. <if test=" et!=null and et.usePlace != null">
  534. use_place = #{et.usePlace,jdbcType=VARCHAR},
  535. </if>
  536. <if test=" et!=null and et.discount != null">
  537. discount = #{et.discount,jdbcType=VARCHAR},
  538. </if>
  539. <if test=" et!=null and et.costPrice != null">
  540. cost_price = #{et.costPrice,jdbcType=NUMERIC},
  541. </if>
  542. <if test=" et!=null and et.costAmt != null">
  543. cost_amt = #{et.costAmt,jdbcType=NUMERIC},
  544. </if>
  545. </set>
  546. where item_id = #{et.itemId,typeHandler=UuidTypeHandler}
  547. and item_qty >=(
  548. out_qty
  549. <if test=" et!=null and et.updateOutMessageFlag != null and et.updateOutMessageFlag ">
  550. + #{et.outQty,jdbcType=NUMERIC}
  551. </if>
  552. + outing_qty
  553. <if test=" et!=null and et.updateOutingMessageFlag != null and et.updateOutingMessageFlag ">
  554. + #{et.outingQty,jdbcType=NUMERIC}
  555. </if>
  556. )
  557. </update>
  558. <!--修改退货信息 -->
  559. <update id="updateReturnMessage" parameterType="com.dk.mdm.model.pojo.sale.OrderItem">
  560. update dkic_b.t_psi_order_item
  561. <set>
  562. <if test=" returnQty != null">
  563. return_qty = return_qty + #{returnQty,jdbcType=NUMERIC},
  564. </if>
  565. <if test=" returnAmt != null">
  566. return_amt = return_amt + #{returnAmt,jdbcType=NUMERIC},
  567. </if>
  568. </set>
  569. where item_id = #{itemId,typeHandler=UuidTypeHandler}
  570. and item_qty >= return_qty
  571. </update>
  572. <!-- 通用条件列 -->
  573. <sql id="Condition_pur">
  574. <where>
  575. <if test="orderNo != null">
  576. AND tpo.order_no like concat('%', my_ex.likequery(#{orderNo}) , '%')
  577. </if>
  578. <if test="orderId != null and orderId != ''">
  579. AND t.order_id = #{orderId}::uuid
  580. </if>
  581. <if test="itemIndex != null">
  582. AND t.item_index = #{itemIndex}
  583. </if>
  584. <if test="skuId != null and skuId != ''">
  585. AND t.sku_id = #{skuId}
  586. </if>
  587. <if test="itemQty != null">
  588. AND t.item_qty = #{itemQty}
  589. </if>
  590. <if test="priceStd != null">
  591. AND t.price_std = #{priceStd}
  592. </if>
  593. <if test="amtStd != null">
  594. AND t.amt_std = #{amtStd}
  595. </if>
  596. <if test="priceSale != null">
  597. AND t.price_sale = #{priceSale}
  598. </if>
  599. <if test="itemAmt != null">
  600. AND t.item_amt = #{itemAmt}
  601. </if>
  602. <if test="priceDiscount != null">
  603. AND t.price_discount = #{priceDiscount}
  604. </if>
  605. <if test="nonStdCode != null and nonStdCode != ''">
  606. AND t.non_std_code = #{nonStdCode}
  607. </if>
  608. <if test="outStatus != null and outStatus != ''">
  609. AND t.out_status = #{outStatus}
  610. </if>
  611. <if test="outingQty != null">
  612. AND t.outing_qty = #{outingQty}
  613. </if>
  614. <if test="outingAmt != null">
  615. AND t.outing_amt = #{outingAmt}
  616. </if>
  617. <if test="outQty != null">
  618. AND t.out_qty = #{outQty}
  619. </if>
  620. <if test="outAmt != null">
  621. AND t.out_amt = #{outAmt}
  622. </if>
  623. <if test="returnQty != null">
  624. AND t.return_qty = #{returnQty}
  625. </if>
  626. <if test="returnAmt != null">
  627. AND t.return_amt = #{returnAmt}
  628. </if>
  629. <if test="remarks != null and remarks != ''">
  630. AND t.remarks = #{remarks}
  631. </if>
  632. <if test="flgValid != null">
  633. AND t.flg_valid = #{flgValid}
  634. </if>
  635. <if test="cpId != null">
  636. AND t.cp_id = #{cpId}
  637. </if>
  638. </where>
  639. </sql>
  640. <!-- 查询表t_psi_order_item,(条件查询+分页)列表 -->
  641. <select id="purchaseBasedOnSaleSelectByCond" resultMap="BaseResultMapResponse">
  642. SELECT t.item_id,
  643. t.order_id,
  644. tpo.order_no,
  645. tms.cus_code,
  646. tms.cus_name,
  647. tms.cus_phone,
  648. tpo.make_time AS "makingTime",
  649. t.item_index,
  650. t.sku_id,
  651. tmgs.sku_code,
  652. tmgs.sku_model as "skuModel",
  653. tmgs.sku_name as "skuName",
  654. sys.f_remove_zero(t.item_qty) as item_qty,
  655. t.price_std,
  656. t.amt_std,
  657. t.price_sale,
  658. t.item_amt,
  659. t.price_discount,
  660. t.fact_price,
  661. t.fact_amt,
  662. t.use_place,
  663. t.discount,
  664. t.non_std_code AS "nonStdCode",
  665. t.out_status,
  666. sys.f_remove_zero(t.outing_qty) as outing_qty,
  667. t.outing_amt,
  668. sys.f_remove_zero(t.out_qty) as out_qty,
  669. t.out_amt,
  670. sys.f_remove_zero(t.return_qty) as return_qty,
  671. t.return_amt,
  672. t.remarks,
  673. t.item_qty - coalesce(sumQty,0) as "transferableQuantity"
  674. ,ul.decimal_places as "decimalPlaces"
  675. ,t.box
  676. ,t.piece
  677. ,t.pack_box
  678. ,t.unit_id
  679. ,t.sub_unit_id
  680. ,ul.unit_name as "unitName"
  681. ,u2.unit_name as "subUnitName"
  682. ,dkic_b.f_box_piece(u2.unit_name,ul.unit_name,t.box,t.piece) as "boxPiece"
  683. ,tmgs.price_purchase
  684. FROM dkic_b.t_psi_order_item as t
  685. left join dkic_b.t_psi_order as tpo on tpo.order_id = t.order_id
  686. left join dkic_b.t_mst_customer as tms on tpo.cus_id = tms.cus_id
  687. LEFT join dkic_b.t_mst_goods_sku tmgs on t.sku_id = tmgs.sku_id
  688. left join dkic_b.t_mst_unit ul on t.unit_id = ul.unit_id
  689. left join dkic_b.t_mst_unit u2 on t.sub_unit_id = u2.unit_id
  690. left join(select from_item_id,sum(item_qty) as sumQty from dkic_b.t_psi_purchase_item
  691. group by from_item_id) as pi on pi.from_item_id = t.item_id
  692. <where>
  693. t.item_qty - coalesce(sumQty,0) > 0
  694. AND t.sku_id is not null
  695. AND t.flg_valid
  696. AND tpo.flg_valid
  697. <if test="cpId != null">
  698. AND t.cp_id = #{cpId}
  699. </if>
  700. <if test="orderNo != null">
  701. AND tpo.order_no like concat('%', my_ex.likequery(#{orderNo}) , '%')
  702. </if>
  703. </where>
  704. order by t.item_id
  705. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  706. limit #{end} offset #{start}
  707. </if>
  708. </select>
  709. <!-- 查询表t_psi_order_item,(条件查询+分页)列表 -->
  710. <select id="purchaseBasedOnSaleContByCond" resultType="Long">
  711. SELECT count(1)
  712. FROM dkic_b.t_psi_order_item as t
  713. left join dkic_b.t_psi_order as tpo on tpo.order_id = t.order_id
  714. inner join dkic_b.t_mst_goods_sku tmgs on t.sku_id = tmgs.sku_id
  715. left join(select from_item_id,sum(item_qty) as sumQty from dkic_b.t_psi_purchase_item
  716. group by from_item_id) as pi on pi.from_item_id = t.item_id
  717. <where>
  718. t.item_qty - coalesce(sumQty,0) > 0
  719. AND t.sku_id is not null
  720. AND t.flg_valid
  721. AND tpo.flg_valid
  722. <if test="cpId != null">
  723. AND t.cp_id = #{cpId}
  724. </if>
  725. <if test="orderNo != null">
  726. AND tpo.order_no like concat('%', my_ex.likequery(#{orderNo}) , '%')
  727. </if>
  728. </where>
  729. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  730. limit #{end} offset #{start}
  731. </if>
  732. </select>
  733. <!-- 销售出库页面选择源单 -->
  734. <select id="selectBySaleOut" resultMap="BaseResultMapResponse">
  735. SELECT
  736. <include refid="Base_Column_List_Response"/>,
  737. tpo.order_no ,
  738. tmc.cus_code ,
  739. tmc.cus_name ,
  740. tmc.cus_phone ,
  741. tmc.address_full ,
  742. tmsc.channel_name ,
  743. tmgs.sku_code ,
  744. tmgs.sku_model ,
  745. tmgs.sku_name ,
  746. tmgb.brand_name ,
  747. tmgb.short_name,
  748. t.item_qty - (t.outing_qty + t.out_qty) as can_out_qty
  749. FROM dkic_b.t_psi_order_item t
  750. LEFT JOIN dkic_b.t_psi_order as tpo ON t.order_id = tpo.order_id
  751. LEFT JOIN dkic_b.t_mst_customer tmc ON tmc.cus_id = tpo.cus_id
  752. LEFT JOIN dkic_b.t_mst_sale_channel tmsc ON tpo.sales_channel = tmsc.channel_id
  753. LEFT JOIN dkic_b.t_mst_goods_sku tmgs ON tmgs.sku_id = t.sku_id
  754. LEFT JOIN dkic_b.t_mst_goods_brand tmgb ON tmgb.brand_id = tmgs.brand_id
  755. WHERE
  756. t.cp_id = #{cpId}
  757. and t.item_qty - t.outing_qty - t.out_qty > 0
  758. <if test="orderNo != null">
  759. AND tpo.order_no like concat('%', my_ex.likequery(#{orderNo}) , '%')
  760. </if>
  761. order by t.op_create_time desc
  762. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  763. limit #{end} offset #{start}
  764. </if>
  765. </select>
  766. <!-- 销售出库页面选择源单个数 -->
  767. <select id="selectBySaleOutByCound" resultMap="BaseResultMapResponse">
  768. SELECT
  769. count(1)
  770. FROM dkic_b.t_psi_order_item t
  771. LEFT JOIN dkic_b.t_psi_order as tpo ON t.order_id = tpo.order_id
  772. LEFT JOIN dkic_b.t_mst_customer tmc ON tmc.cus_id = tpo.cus_id
  773. LEFT JOIN dkic_b.t_mst_sale_channel tmsc ON tpo.sales_channel = tmsc.channel_id
  774. LEFT JOIN dkic_b.t_mst_goods_sku tmgs ON tmgs.sku_id = t.sku_id
  775. LEFT JOIN dkic_b.t_mst_goods_brand tmgb ON tmgb.brand_id = tmgs.brand_id
  776. WHERE
  777. t.cp_id = #{cpId}
  778. and t.item_qty - t.outing_qty - t.out_qty > 0
  779. <if test="orderNo != null">
  780. AND tpo.order_no like concat('%', my_ex.likequery(#{orderNo}) , '%')
  781. </if>
  782. </select>
  783. <update id="updateCost" parameterType="com.dk.mdm.model.pojo.sale.OrderItem">
  784. update dkic_b.t_psi_order_item
  785. <set>
  786. <if test="costPrice!= null">
  787. cost_price= #{costPrice},
  788. </if>
  789. <if test="costAmt!= null">
  790. cost_amt = #{costAmt},
  791. </if>
  792. </set>
  793. where item_id = #{itemId}::uuid
  794. </update>
  795. </mapper>