OrderItemMapper.xml 34 KB

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