OrderItemMapper.xml 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  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. </sql>
  13. <sql id="Base_Column_List_Response">
  14. 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,
  15. 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,
  16. sys.f_remove_zero(t.return_qty) as return_qty, t.return_amt, t.remarks, t.flg_valid, t.cp_id, t.wh_id
  17. ,t.box,t.piece,t.sub_unit_id,t.unit_id,t.pack_box
  18. </sql>
  19. <!-- 通用查询映射结果 -->
  20. <resultMap id="BaseResultMap" type="com.dk.mdm.model.pojo.sale.OrderItem">
  21. <id column="item_id" property="itemId"/>
  22. <result column="order_id" property="orderId" typeHandler="UuidTypeHandler"/>
  23. <result column="item_index" property="itemIndex"/>
  24. <result column="sku_id" property="skuId" typeHandler="UuidTypeHandler"/>
  25. <result column="unit_id" property="unitId" typeHandler="UuidTypeHandler"/>
  26. <result column="sub_unit_id" property="subUnitId" typeHandler="UuidTypeHandler"/>
  27. <result column="pack_box" property="packBox"/>
  28. <result column="box" property="box"/>
  29. <result column="piece" property="piece"/>
  30. <result column="item_qty" property="itemQty"/>
  31. <result column="price_std" property="priceStd"/>
  32. <result column="amt_std" property="amtStd"/>
  33. <result column="price_sale" property="priceSale"/>
  34. <result column="item_amt" property="itemAmt"/>
  35. <result column="price_discount" property="priceDiscount"/>
  36. <result column="non_std_code" property="nonStdCode"/>
  37. <result column="out_status" property="outStatus"/>
  38. <result column="outing_qty" property="outingQty"/>
  39. <result column="outing_amt" property="outingAmt"/>
  40. <result column="out_qty" property="outQty"/>
  41. <result column="out_amt" property="outAmt"/>
  42. <result column="return_qty" property="returnQty"/>
  43. <result column="return_amt" property="returnAmt"/>
  44. <result column="remarks" property="remarks"/>
  45. <result column="flg_valid" property="flgValid"/>
  46. <result column="cp_id" property="cpId"/>
  47. <result column="wh_id" property="whId"/>
  48. </resultMap>
  49. <!-- 通用查询映射结果 -->
  50. <resultMap id="BaseResultMapResponse" type="com.dk.mdm.model.response.sale.OrderItemResponse">
  51. <id column="item_id" property="itemId"/>
  52. <result column="order_id" property="orderId" typeHandler="UuidTypeHandler"/>
  53. <result column="item_index" property="itemIndex"/>
  54. <result column="sku_id" property="skuId" typeHandler="UuidTypeHandler"/>
  55. <result column="unit_id" property="unitId" typeHandler="UuidTypeHandler"/>
  56. <result column="sub_unit_id" property="subUnitId" typeHandler="UuidTypeHandler"/>
  57. <result column="pack_box" property="packBox"/>
  58. <result column="item_qty" property="itemQty"/>
  59. <result column="price_std" property="priceStd"/>
  60. <result column="amt_std" property="amtStd"/>
  61. <result column="price_sale" property="priceSale"/>
  62. <result column="item_amt" property="itemAmt"/>
  63. <result column="price_discount" property="priceDiscount"/>
  64. <result column="non_std_code" property="nonStdCode"/>
  65. <result column="out_status" property="outStatus"/>
  66. <result column="outing_qty" property="outingQty"/>
  67. <result column="outing_amt" property="outingAmt"/>
  68. <result column="out_qty" property="outQty"/>
  69. <result column="out_amt" property="outAmt"/>
  70. <result column="return_qty" property="returnQty"/>
  71. <result column="return_amt" property="returnAmt"/>
  72. <result column="remarks" property="remarks"/>
  73. <result column="flg_valid" property="flgValid"/>
  74. <result column="cp_id" property="cpId"/>
  75. <result column="wh_id" property="whId"/>
  76. <result column="wh_name" property="whName"/>
  77. <result column="order_no" property="orderNo"/>
  78. <result column="brand_name" property="brandName"/>
  79. <result column="short_name" property="shortName"/>
  80. <result column="sku_images" property="skuImages" typeHandler="JsonTypeHandler"/>
  81. <result column="transferableQuantity" property="transferableQuantity"/>
  82. <result column="skuImages" property="skuImages" typeHandler="JsonTypeHandler"/>
  83. </resultMap>
  84. <!-- 通用条件列 -->
  85. <sql id="Condition">
  86. <where>
  87. <if test="orderId != null and orderId != ''">
  88. AND t.order_id = #{orderId}::uuid
  89. </if>
  90. <if test="itemIndex != null">
  91. AND t.item_index = #{itemIndex}
  92. </if>
  93. <if test="skuId != null and skuId != ''">
  94. AND t.sku_id = #{skuId}
  95. </if>
  96. <if test="itemQty != null">
  97. AND t.item_qty = #{itemQty}
  98. </if>
  99. <if test="priceStd != null">
  100. AND t.price_std = #{priceStd}
  101. </if>
  102. <if test="amtStd != null">
  103. AND t.amt_std = #{amtStd}
  104. </if>
  105. <if test="priceSale != null">
  106. AND t.price_sale = #{priceSale}
  107. </if>
  108. <if test="itemAmt != null">
  109. AND t.item_amt = #{itemAmt}
  110. </if>
  111. <if test="priceDiscount != null">
  112. AND t.price_discount = #{priceDiscount}
  113. </if>
  114. <if test="nonStdCode != null and nonStdCode != ''">
  115. AND t.non_std_code = #{nonStdCode}
  116. </if>
  117. <if test="outStatus != null and outStatus != ''">
  118. AND t.out_status = #{outStatus}
  119. </if>
  120. <if test="outingQty != null">
  121. AND t.outing_qty = #{outingQty}
  122. </if>
  123. <if test="outingAmt != null">
  124. AND t.outing_amt = #{outingAmt}
  125. </if>
  126. <if test="outQty != null">
  127. AND t.out_qty = #{outQty}
  128. </if>
  129. <if test="outAmt != null">
  130. AND t.out_amt = #{outAmt}
  131. </if>
  132. <if test="returnQty != null">
  133. AND t.return_qty = #{returnQty}
  134. </if>
  135. <if test="returnAmt != null">
  136. AND t.return_amt = #{returnAmt}
  137. </if>
  138. <if test="remarks != null and remarks != ''">
  139. AND t.remarks = #{remarks}
  140. </if>
  141. <if test="flgValid != null">
  142. AND t.flg_valid = #{flgValid}
  143. </if>
  144. <if test="cpId != null">
  145. AND t.cp_id = #{cpId}
  146. </if>
  147. </where>
  148. </sql>
  149. <sql id="idsForeach">
  150. <!-- 根据主键itemId批量操作 -->
  151. WHERE item_id in
  152. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  153. #{item}
  154. </foreach>
  155. </sql>
  156. <!-- 查询表t_psi_order_item,(条件查询+分页)列表 -->
  157. <select id="selectByCond" resultMap="BaseResultMapResponse">
  158. SELECT t.item_id,
  159. t.order_id,
  160. t.item_index,
  161. t.sku_id,
  162. tmgs.sku_code as "skuCode",
  163. tmgs.sku_model as "skuModel",
  164. tmgs.sku_name as "skuName",
  165. tmgs.sku_images,
  166. tmgb.brand_name,
  167. tmgb.short_name,
  168. dkic_b.f_box_piece(u2.unit_name,ul.unit_name,t.box,t.piece) AS "boxPiece",
  169. t.pack_box,
  170. t.box,
  171. t.piece,
  172. sys.f_remove_zero(t.item_qty) as item_qty,
  173. t.price_std,
  174. t.amt_std,
  175. t.price_sale,
  176. t.item_amt,
  177. t.price_discount,
  178. t.non_std_code,
  179. t.out_status,
  180. sys.f_remove_zero(t.outing_qty) as outing_qty,
  181. t.outing_amt,
  182. sys.f_remove_zero(t.out_qty) as out_qty,
  183. t.out_amt,
  184. sys.f_remove_zero(t.return_qty) as return_qty,
  185. t.return_amt,
  186. t.remarks,
  187. t.wh_id,
  188. tmw.wh_name
  189. FROM dkic_b.t_psi_order_item as t
  190. inner join dkic_b.t_mst_goods_sku tmgs on t.sku_id = tmgs.sku_id
  191. LEFT JOIN dkic_b.t_mst_unit AS ul ON tmgs.unit_id = ul.unit_id
  192. LEFT JOIN dkic_b.t_mst_unit AS u2 ON tmgs.sub_unit_id = u2.unit_id
  193. inner join dkic_b.t_mst_goods_brand tmgb on tmgb.brand_id = tmgs.brand_id
  194. left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = t.wh_id
  195. <include refid="Condition"/>
  196. order by t.item_index
  197. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  198. limit #{end} offset #{start}
  199. </if>
  200. </select>
  201. <!-- 查询表t_psi_order_item,(条件查询)个数 -->
  202. <select id="countByCond" resultType="Long">
  203. SELECT
  204. count(1)
  205. FROM dkic_b.t_psi_order_item as t
  206. <include refid="Condition"/>
  207. </select>
  208. <!-- 根据主键查询表t_psi_order_item的一行数据 -->
  209. <select id="selectById" resultMap="BaseResultMapResponse">
  210. SELECT
  211. <include refid="Base_Column_List_Response"/>
  212. FROM dkic_b.t_psi_order_item t
  213. WHERE t.item_id = #{id}::uuid
  214. </select>
  215. <!-- 根据主键锁定表t_psi_order_item的一行数据 -->
  216. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  217. SELECT
  218. <include refid="Base_Column_List"/>
  219. FROM dkic_b.t_psi_order_item
  220. WHERE item_id = #{id}::uuid
  221. for update
  222. </select>
  223. <!-- 根据主表主键锁定表t_psi_order_item的一行数据 -->
  224. <select id="selectByZIdForUpdate" resultMap="BaseResultMap">
  225. SELECT
  226. <include refid="Base_Column_List"/>
  227. FROM dkic_b.t_psi_order_item
  228. WHERE order_id = #{id}::uuid
  229. for update
  230. </select>
  231. <!-- 根据主键锁定表t_psi_order_item的多行数据 -->
  232. <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
  233. SELECT
  234. <include refid="Base_Column_List"/>
  235. FROM dkic_b.t_psi_order_item
  236. <include refid="idsForeach"/>
  237. for update
  238. </select>
  239. <insert id="insertBatch">
  240. insert into dkic_b.t_psi_order_item
  241. (
  242. <trim suffixOverrides=",">
  243. order_id,
  244. item_index,
  245. sku_id,
  246. item_qty,
  247. price_std,
  248. amt_std,
  249. price_sale,
  250. item_amt,
  251. price_discount,
  252. non_std_code,
  253. out_status,
  254. outing_qty,
  255. outing_amt,
  256. out_qty,
  257. out_amt,
  258. return_qty,
  259. return_amt,
  260. remarks,
  261. cp_id,
  262. wh_id,
  263. </trim>
  264. )
  265. values
  266. <foreach collection="list" index="index" item="item" separator=",">
  267. (
  268. <trim suffixOverrides=",">
  269. #{item.orderId}::uuid,
  270. #{item.itemIndex},
  271. #{item.skuId}::uuid,
  272. #{item.itemQty},
  273. #{item.priceStd},
  274. #{item.amtStd},
  275. #{item.priceSale},
  276. #{item.itemAmt},
  277. #{item.priceDiscount},
  278. #{item.nonStdCode},
  279. #{item.outStatus},
  280. #{item.outingQty},
  281. #{item.outingAmt},
  282. #{item.outQty},
  283. #{item.outAmt},
  284. #{item.returnQty},
  285. #{item.returnAmt},
  286. #{item.remarks},
  287. #{item.cpId},
  288. #{item.whId},
  289. </trim>
  290. )
  291. </foreach>
  292. </insert>
  293. <delete id="deleteById">
  294. DELETE FROM dkic_b.t_psi_order_item
  295. WHERE item_id = #{id}::UUID;
  296. </delete>
  297. <!-- 根据条件进行查询(出库用) -->
  298. <select id="selectByCondForOut" resultMap="BaseResultMapResponse">
  299. SELECT t.item_id as "fromItemId",
  300. t.order_id as "fromId",
  301. t.item_index,
  302. t.sku_id,
  303. tmgs.sku_code as "skuCode",
  304. tmgs.sku_model as "skuModel",
  305. tmgs.sku_name as "skuName",
  306. tmgs.sku_images AS "skuImages",
  307. t.pack_box ,
  308. sys.f_remove_zero(t.item_qty) as "orderQty",
  309. t.box,
  310. t.piece,
  311. sys.f_remove_zero(t.item_qty - t.outing_qty - t.out_qty) as "canOutingQty",
  312. sys.f_remove_zero(t.item_qty - t.outing_qty - t.out_qty) as outing_qty,
  313. (t.item_qty - t.outing_qty - t.out_qty)/t.pack_box as "outingBox",
  314. (t.item_qty - t.outing_qty - t.out_qty)%t.pack_box as "outingPiece",
  315. t.price_sale as "priceOut",
  316. t.price_sale * (t.item_qty - t.outing_qty - t.out_qty) as outing_amt,
  317. t.non_std_code,
  318. t.remarks,
  319. t.wh_id,
  320. t.unit_id,
  321. t.sub_unit_id,
  322. tmw.wh_name,
  323. tpi.inv_id as "invId",
  324. sys.f_remove_zero(tpi.inv_qty) as "invQty",
  325. sys.f_remove_zero(tpi.usable_qty) as "usableQty"
  326. FROM dkic_b.t_psi_order_item as t
  327. inner join dkic_b.t_mst_goods_sku tmgs on t.sku_id = tmgs.sku_id
  328. left join dkic_b.t_mst_warehouse as tmw on tmw.wh_id = t.wh_id
  329. left join dkic_b.t_psi_inventory as tpi
  330. on tpi.sku_id = t.sku_id and tpi.non_std_code = t.non_std_code
  331. and tpi.wh_id = t.wh_id and tpi.cp_id = t.cp_id
  332. where t.flg_valid
  333. and t.item_qty > t.outing_qty
  334. and t.order_id = #{orderId}::uuid
  335. order by t.item_index
  336. </select>
  337. <!-- 根据条件进行查询(退货用) -->
  338. <select id="selectByCondForReturn" resultMap="BaseResultMapResponse">
  339. SELECT tpobi.out_id as "sOutId",
  340. tpobi.item_id as "sOutItemId",
  341. t.order_id as "sOrderId",
  342. t.item_id as "sOrderItemId",
  343. t.sku_id,
  344. tmgs.sku_code as "skuCode",
  345. tmgs.sku_model as "skuModel",
  346. tmgs.sku_name as "skuName",
  347. tpobi.out_qty as "outboundOutQty",
  348. sys.f_remove_zero(tpobi.out_qty - tpobi.return_qty) as "canReturnQty",
  349. - sys.f_remove_zero(tpobi.out_qty - tpobi.return_qty) as outing_qty,
  350. t.price_sale as "priceOut",
  351. - t.price_sale * (tpobi.out_qty - tpobi.return_qty) as outing_amt,
  352. tpobi.inv_id as "invId",
  353. 0 as out_qty,
  354. 0 as out_amt,
  355. t.non_std_code,
  356. tpobi.remarks,
  357. t.wh_id,
  358. tmw.wh_name
  359. FROM dkic_b.t_psi_outbound_item as tpobi
  360. inner join dkic_b.t_psi_order_item as t on t.item_id = tpobi.from_item_id
  361. inner join dkic_b.t_mst_goods_sku tmgs on t.sku_id = tmgs.sku_id
  362. left join dkic_b.t_mst_warehouse as tmw on tmw.wh_id = t.wh_id
  363. where tpobi.flg_valid
  364. and tpobi.out_type = '出库类型-销售出库'
  365. and tpobi.out_qty > tpobi.return_qty
  366. and t.order_id = #{orderId}::uuid
  367. order by t.item_index
  368. </select>
  369. <!-- 根据id修改-->
  370. <update id="updateById" parameterType="com.dk.mdm.model.pojo.sale.OrderItem">
  371. update dkic_b.t_psi_order_item
  372. <set>
  373. <if test=" et!=null and et.itemIndex != null">
  374. item_index = #{et.itemIndex,jdbcType=INTEGER},
  375. </if>
  376. <if test=" et!=null and et.skuId != null">
  377. sku_id = #{et.skuId,typeHandler=UuidTypeHandler},
  378. </if>
  379. <if test=" et!=null and et.itemQty != null">
  380. item_qty = #{et.itemQty,jdbcType=NUMERIC},
  381. </if>
  382. <if test=" et!=null and et.priceStd != null">
  383. price_std = #{et.priceStd,jdbcType=NUMERIC},
  384. </if>
  385. <if test=" et!=null and et.amtStd != null">
  386. amt_std = #{et.amtStd,jdbcType=NUMERIC},
  387. </if>
  388. <if test=" et!=null and et.priceSale != null">
  389. price_sale = #{et.priceSale,jdbcType=NUMERIC},
  390. </if>
  391. <if test=" et!=null and et.itemAmt != null">
  392. item_amt = #{et.itemAmt,jdbcType=NUMERIC},
  393. </if>
  394. <if test=" et!=null and et.priceDiscount != null">
  395. price_discount = #{et.priceDiscount,jdbcType=NUMERIC},
  396. </if>
  397. <if test=" et!=null and et.nonStdCode != null">
  398. non_std_code = #{et.nonStdCode,jdbcType=VARCHAR},
  399. </if>
  400. <if test=" et!=null and et.outStatus != null">
  401. out_status = #{et.outStatus,jdbcType=VARCHAR},
  402. </if>
  403. <if test=" et!=null and et.outingQty != null">
  404. outing_qty = outing_qty + #{et.outingQty,jdbcType=NUMERIC},
  405. </if>
  406. <if test=" et!=null and et.outingAmt != null">
  407. outing_amt = outing_amt + #{et.outingAmt,jdbcType=NUMERIC},
  408. </if>
  409. <if test=" et!=null and et.outQty != null">
  410. out_qty = out_qty + #{et.outQty,jdbcType=NUMERIC},
  411. </if>
  412. <if test=" et!=null and et.outAmt != null">
  413. out_amt = out_amt + #{et.outAmt,jdbcType=NUMERIC},
  414. </if>
  415. <if test=" et!=null and et.returnQty != null">
  416. return_qty = #{et.returnQty,jdbcType=NUMERIC},
  417. </if>
  418. <if test=" et!=null and et.returnAmt != null">
  419. return_amt = #{et.returnAmt,jdbcType=NUMERIC},
  420. </if>
  421. <if test=" et!=null and et.remarks != null">
  422. remarks = #{et.remarks,jdbcType=VARCHAR},
  423. </if>
  424. <if test=" et!=null and et.flgValid != null">
  425. flg_valid = #{et.flgValid,jdbcType=BOOLEAN},
  426. </if>
  427. <if test=" et!=null and et.cpId != null">
  428. cp_id = #{et.cpId,jdbcType=INTEGER},
  429. </if>
  430. </set>
  431. where item_id = #{et.itemId,typeHandler=UuidTypeHandler}
  432. and item_qty >=(out_qty + outing_qty)
  433. </update>
  434. <!--修改退货信息 -->
  435. <update id="updateReturnMessage" parameterType="com.dk.mdm.model.pojo.sale.OrderItem">
  436. update dkic_b.t_psi_order_item
  437. <set>
  438. <if test=" returnQty != null">
  439. return_qty = return_qty + #{returnQty,jdbcType=NUMERIC},
  440. </if>
  441. <if test=" returnAmt != null">
  442. return_amt = return_amt + #{returnAmt,jdbcType=NUMERIC},
  443. </if>
  444. </set>
  445. where item_id = #{itemId,typeHandler=UuidTypeHandler}
  446. and item_qty >= return_qty
  447. </update>
  448. <!-- 通用条件列 -->
  449. <sql id="Condition_pur">
  450. <where>
  451. <if test="orderNo != null">
  452. AND tpo.order_no like concat('%', my_ex.likequery(#{orderNo}) , '%')
  453. </if>
  454. <if test="orderId != null and orderId != ''">
  455. AND t.order_id = #{orderId}::uuid
  456. </if>
  457. <if test="itemIndex != null">
  458. AND t.item_index = #{itemIndex}
  459. </if>
  460. <if test="skuId != null and skuId != ''">
  461. AND t.sku_id = #{skuId}
  462. </if>
  463. <if test="itemQty != null">
  464. AND t.item_qty = #{itemQty}
  465. </if>
  466. <if test="priceStd != null">
  467. AND t.price_std = #{priceStd}
  468. </if>
  469. <if test="amtStd != null">
  470. AND t.amt_std = #{amtStd}
  471. </if>
  472. <if test="priceSale != null">
  473. AND t.price_sale = #{priceSale}
  474. </if>
  475. <if test="itemAmt != null">
  476. AND t.item_amt = #{itemAmt}
  477. </if>
  478. <if test="priceDiscount != null">
  479. AND t.price_discount = #{priceDiscount}
  480. </if>
  481. <if test="nonStdCode != null and nonStdCode != ''">
  482. AND t.non_std_code = #{nonStdCode}
  483. </if>
  484. <if test="outStatus != null and outStatus != ''">
  485. AND t.out_status = #{outStatus}
  486. </if>
  487. <if test="outingQty != null">
  488. AND t.outing_qty = #{outingQty}
  489. </if>
  490. <if test="outingAmt != null">
  491. AND t.outing_amt = #{outingAmt}
  492. </if>
  493. <if test="outQty != null">
  494. AND t.out_qty = #{outQty}
  495. </if>
  496. <if test="outAmt != null">
  497. AND t.out_amt = #{outAmt}
  498. </if>
  499. <if test="returnQty != null">
  500. AND t.return_qty = #{returnQty}
  501. </if>
  502. <if test="returnAmt != null">
  503. AND t.return_amt = #{returnAmt}
  504. </if>
  505. <if test="remarks != null and remarks != ''">
  506. AND t.remarks = #{remarks}
  507. </if>
  508. <if test="flgValid != null">
  509. AND t.flg_valid = #{flgValid}
  510. </if>
  511. <if test="cpId != null">
  512. AND t.cp_id = #{cpId}
  513. </if>
  514. </where>
  515. </sql>
  516. <!-- 查询表t_psi_order_item,(条件查询+分页)列表 -->
  517. <select id="purchaseBasedOnSaleSelectByCond" resultMap="BaseResultMapResponse">
  518. SELECT t.item_id,
  519. t.order_id,
  520. tpo.order_no,
  521. t.item_index,
  522. t.sku_id,
  523. tmgs.sku_code as "skuCode",
  524. tmgs.sku_model as "skuModel",
  525. tmgs.sku_name as "skuName",
  526. sys.f_remove_zero(t.item_qty) as item_qty,
  527. t.price_std,
  528. t.amt_std,
  529. t.price_sale,
  530. t.item_amt,
  531. t.price_discount,
  532. t.non_std_code,
  533. t.out_status,
  534. sys.f_remove_zero(t.outing_qty) as outing_qty,
  535. t.outing_amt,
  536. sys.f_remove_zero(t.out_qty) as out_qty,
  537. t.out_amt,
  538. sys.f_remove_zero(t.return_qty) as return_qty,
  539. t.return_amt,
  540. t.remarks,
  541. t.item_qty - coalesce(sumQty,0) as "transferableQuantity"
  542. FROM dkic_b.t_psi_order_item as t
  543. left join dkic_b.t_psi_order as tpo on tpo.order_id = t.order_id
  544. inner join dkic_b.t_mst_goods_sku tmgs on t.sku_id = tmgs.sku_id
  545. left join(select from_item_id,sum(item_qty) as sumQty from dkic_b.t_psi_purchase_item
  546. group by from_item_id) as pi on pi.from_item_id = t.item_id
  547. <where>
  548. t.item_qty - coalesce(sumQty,0) > 0
  549. <if test="orderNo != null">
  550. AND tpo.order_no like concat('%', my_ex.likequery(#{orderNo}) , '%')
  551. </if>
  552. </where>
  553. order by t.item_id
  554. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  555. limit #{end} offset #{start}
  556. </if>
  557. </select>
  558. <!-- 查询表t_psi_order_item,(条件查询+分页)列表 -->
  559. <select id="purchaseBasedOnSaleContByCond" resultType="Long">
  560. SELECT count(1)
  561. FROM dkic_b.t_psi_order_item as t
  562. left join dkic_b.t_psi_order as tpo on tpo.order_id = t.order_id
  563. inner join dkic_b.t_mst_goods_sku tmgs on t.sku_id = tmgs.sku_id
  564. left join(select from_item_id,sum(item_qty) as sumQty from dkic_b.t_psi_purchase_item
  565. group by from_item_id) as pi on pi.from_item_id = t.item_id
  566. <where>
  567. t.item_qty - coalesce(sumQty,0) > 0
  568. <if test="orderNo != null">
  569. AND tpo.order_no like concat('%', my_ex.likequery(#{orderNo}) , '%')
  570. </if>
  571. </where>
  572. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  573. limit #{end} offset #{start}
  574. </if>
  575. </select>
  576. </mapper>