OrderMapper.xml 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116
  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.OrderMapper">
  4. <!-- 通用设置 -->
  5. <!-- 通用查询列 -->
  6. <sql id="Base_Column_List">
  7. order_id, order_no, order_type, org_id, staff_id, cus_id, address_area, address_name, address_no, address_gcj02,
  8. address_full, contact_name, contact_phone, sales_channel, delivery_date, sys.f_remove_zero(sum_quantity) as sum_quantity,
  9. sum_standard, sum_amount, sale_discount, order_status, out_status, sys.f_remove_zero(outing_qty) as outing_qty, outing_amt,
  10. sys.f_remove_zero(out_qty) as out_qty, out_amt, sys.f_remove_zero(return_qty) as return_qty, return_amt, amt_receivable,
  11. amt_handle, amt_residue, remarks, annex_paths, make_staff, make_time, flg_valid, cp_id,
  12. fact_amt,disc_amt,discount,flg_auto_handle,flg_handle_setting
  13. </sql>
  14. <!-- 通用查询映射结果 -->
  15. <resultMap id="BaseResultMap" type="com.dk.mdm.model.pojo.sale.Order">
  16. <id column="order_id" property="orderId"/>
  17. <result column="order_no" property="orderNo"/>
  18. <result column="order_type" property="orderType"/>
  19. <result column="org_id" property="orgId" typeHandler="UuidTypeHandler"/>
  20. <result column="staff_id" property="staffId" typeHandler="UuidTypeHandler"/>
  21. <result column="cus_id" property="cusId" typeHandler="UuidTypeHandler"/>
  22. <result column="address_area" property="addressArea" typeHandler="JsonTypeHandler"/>
  23. <result column="address_name" property="addressName"/>
  24. <result column="address_no" property="addressNo"/>
  25. <result column="address_gcj02" property="addressGcj02" typeHandler="JsonTypeHandler"/>
  26. <result column="address_full" property="addressFull"/>
  27. <result column="contact_name" property="contactName"/>
  28. <result column="contact_phone" property="contactPhone"/>
  29. <result column="sales_channel" property="salesChannel" typeHandler="UuidTypeHandler"/>
  30. <result column="delivery_date" property="deliveryDate" typeHandler="TimestampTypeHandler"/>
  31. <result column="sum_quantity" property="sumQuantity"/>
  32. <result column="sum_standard" property="sumStandard"/>
  33. <result column="sum_amount" property="sumAmount"/>
  34. <result column="sale_discount" property="saleDiscount"/>
  35. <result column="order_status" property="orderStatus"/>
  36. <result column="out_status" property="outStatus"/>
  37. <result column="outing_qty" property="outingQty"/>
  38. <result column="outing_amt" property="outingAmt"/>
  39. <result column="out_qty" property="outQty"/>
  40. <result column="out_amt" property="outAmt"/>
  41. <result column="return_qty" property="returnQty"/>
  42. <result column="return_amt" property="returnAmt"/>
  43. <result column="amt_receivable" property="amtReceivable"/>
  44. <result column="amt_handle" property="amtHandle"/>
  45. <result column="amt_residue" property="amtResidue"/>
  46. <result column="remarks" property="remarks"/>
  47. <result column="annex_paths" property="annexPaths" typeHandler="JsonTypeHandler"/>
  48. <result column="make_staff" property="makeStaff" typeHandler="UuidTypeHandler"/>
  49. <result column="make_time" property="makeTime" typeHandler="TimestampTypeHandler"/>
  50. <result column="flg_valid" property="flgValid"/>
  51. <result column="cp_id" property="cpId"/>
  52. <result column="fact_amt" property="factAmt"/>
  53. <result column="disc_amt" property="discAmt"/>
  54. <result column="discount" property="discount"/>
  55. <result column="flg_auto_handle" property="flgAutoHandle"/>
  56. <result column="flg_handle_setting" property="flgHandleSetting"/>
  57. </resultMap>
  58. <!-- 通用查询映射结果 -->
  59. <resultMap id="BaseResultMapResponse" type="com.dk.mdm.model.response.sale.OrderResponse">
  60. <id column="order_id" property="orderId"/>
  61. <result column="order_no" property="orderNo"/>
  62. <result column="order_type" property="orderType"/>
  63. <result column="org_id" property="orgId" typeHandler="UuidTypeHandler"/>
  64. <result column="staff_id" property="staffId" typeHandler="UuidTypeHandler"/>
  65. <result column="cus_id" property="cusId" typeHandler="UuidTypeHandler"/>
  66. <result column="address_area" property="addressArea" typeHandler="JsonTypeHandler"/>
  67. <result column="address_name" property="addressName"/>
  68. <result column="orgName" property="orgName"/>
  69. <result column="orderTypeName" property="orderTypeName"/>
  70. <result column="staffName" property="staffName"/>
  71. <result column="cusCode" property="cusCode"/>
  72. <result column="cusName" property="cusName"/>
  73. <result column="cusPhone" property="cusPhone"/>
  74. <result column="cusFrom" property="cusFrom"/>
  75. <result column="cusFromName" property="cusFromName"/>
  76. <result column="channelName" property="channelName"/>
  77. <result column="orderStatusName" property="orderStatusName"/>
  78. <result column="outStatusName" property="outStatusName"/>
  79. <result column="makeStaffName" property="makeStaffName"/>
  80. <result column="address_no" property="addressNo"/>
  81. <result column="address_gcj02" property="addressGcj02" typeHandler="JsonTypeHandler"/>
  82. <result column="address_full" property="addressFull"/>
  83. <result column="contact_name" property="contactName"/>
  84. <result column="contact_phone" property="contactPhone"/>
  85. <result column="sales_channel" property="salesChannel" typeHandler="UuidTypeHandler"/>
  86. <result column="delivery_date" property="deliveryDate" typeHandler="TimestampTypeHandler"/>
  87. <result column="sum_quantity" property="sumQuantity"/>
  88. <result column="sum_standard" property="sumStandard"/>
  89. <result column="sum_amount" property="sumAmount"/>
  90. <result column="sale_discount" property="saleDiscount"/>
  91. <result column="order_status" property="orderStatus"/>
  92. <result column="out_status" property="outStatus"/>
  93. <result column="outing_qty" property="outingQty"/>
  94. <result column="outing_amt" property="outingAmt"/>
  95. <result column="out_qty" property="outQty"/>
  96. <result column="out_amt" property="outAmt"/>
  97. <result column="return_qty" property="returnQty"/>
  98. <result column="return_amt" property="returnAmt"/>
  99. <result column="amt_receivable" property="amtReceivable"/>
  100. <result column="amt_handle" property="amtHandle"/>
  101. <result column="amt_residue" property="amtResidue"/>
  102. <result column="remarks" property="remarks"/>
  103. <result column="annex_paths" property="annexPaths" typeHandler="JsonTypeHandler"/>
  104. <result column="make_staff" property="makeStaff" typeHandler="UuidTypeHandler"/>
  105. <result column="make_time" property="makeTime" typeHandler="TimestampTypeHandler"/>
  106. <result column="flg_valid" property="flgValid"/>
  107. <result column="cp_id" property="cpId"/>
  108. <result column="orderItemResponseList" property="orderItemResponseList" typeHandler="JsonTypeHandler"/>
  109. <result column="fact_amt" property="factAmt"/>
  110. <result column="disc_amt" property="discAmt"/>
  111. <result column="discount" property="discount"/>
  112. <result column="flg_auto_handle" property="flgAutoHandle"/>
  113. <result column="flg_handle_setting" property="flgHandleSetting"/>
  114. <!-- <collection property="orderItemResponseList" resultMap="orderItemListMap" />-->
  115. </resultMap>
  116. <resultMap id="orderItemListMap" type="java.util.Map">
  117. <id column="itemId" property="itemId"/>
  118. <result column="orderId" property="orderId" typeHandler="UuidTypeHandler"/>
  119. <result column="itemIndex" property="itemIndex"/>
  120. <result column="orderNo" property="orderNo"/>
  121. <result column="skuId" property="skuId" typeHandler="UuidTypeHandler"/>
  122. <result column="itemQty" property="itemQty"/>
  123. <result column="priceStd" property="priceStd"/>
  124. <result column="amtStd" property="amtStd"/>
  125. <result column="priceStandard" property="priceStandard"/>
  126. <result column="priceSale" property="priceSale"/>
  127. <result column="itemAmt" property="itemAmt"/>
  128. <result column="priceDiscount" property="priceDiscount"/>
  129. <result column="nonStdCode" property="nonStdCode"/>
  130. <result column="outStatus" property="outStatus"/>
  131. <result column="outingQty" property="outingQty"/>
  132. <result column="outingAmt" property="outingAmt"/>
  133. <result column="outQty" property="outQty"/>
  134. <result column="outAmt" property="outAmt"/>
  135. <result column="skuCode" property="skuCode"/>
  136. <result column="skuName" property="skuName"/>
  137. <result column="skuModel" property="skuModel"/>
  138. <result column="returnQty" property="returnQty"/>
  139. <result column="returnAmt" property="returnAmt"/>
  140. <result column="remarks" property="remarks"/>
  141. <result column="flgValid" property="flgValid"/>
  142. <result column="cpId" property="cpId"/>
  143. <result column="pricePurchase" property="pricePurchase"/>
  144. <result column="brandName" property="brandName"/>
  145. <result column="shortName" property="shortName"/>
  146. </resultMap>
  147. <!--小程序用 查询销售订单带明细-->
  148. <resultMap id="BaseResultMapDetailResponse" type="com.dk.mdm.model.response.sale.OrderResponse">
  149. <id column="order_id" property="orderId"/>
  150. <result column="order_no" property="orderNo"/>
  151. <result column="order_type" property="orderType"/>
  152. <result column="org_id" property="orgId" typeHandler="UuidTypeHandler"/>
  153. <result column="staff_id" property="staffId" typeHandler="UuidTypeHandler"/>
  154. <result column="cus_id" property="cusId" typeHandler="UuidTypeHandler"/>
  155. <result column="address_area" property="addressArea" typeHandler="JsonTypeHandler"/>
  156. <result column="address_name" property="addressName"/>
  157. <result column="address_no" property="addressNo"/>
  158. <result column="address_gcj02" property="addressGcj02" typeHandler="JsonTypeHandler"/>
  159. <result column="address_full" property="addressFull"/>
  160. <result column="contact_name" property="contactName"/>
  161. <result column="contact_phone" property="contactPhone"/>
  162. <result column="sales_channel" property="salesChannel" typeHandler="UuidTypeHandler"/>
  163. <result column="delivery_date" property="deliveryDate" typeHandler="TimestampTypeHandler"/>
  164. <result column="sum_quantity" property="sumQuantity"/>
  165. <result column="sum_standard" property="sumStandard"/>
  166. <result column="sum_amount" property="sumAmount"/>
  167. <result column="sale_discount" property="saleDiscount"/>
  168. <result column="order_status" property="orderStatus"/>
  169. <result column="out_status" property="outStatus"/>
  170. <result column="outing_qty" property="outingQty"/>
  171. <result column="outing_amt" property="outingAmt"/>
  172. <result column="out_qty" property="outQty"/>
  173. <result column="out_amt" property="outAmt"/>
  174. <result column="return_qty" property="returnQty"/>
  175. <result column="return_amt" property="returnAmt"/>
  176. <result column="amt_receivable" property="amtReceivable"/>
  177. <result column="amt_handle" property="amtHandle"/>
  178. <result column="amt_residue" property="amtResidue"/>
  179. <result column="remarks" property="remarks"/>
  180. <result column="annex_paths" property="annexPaths" typeHandler="JsonTypeHandler"/>
  181. <result column="make_staff" property="makeStaff" typeHandler="UuidTypeHandler"/>
  182. <result column="make_time" property="makeTime" typeHandler="TimestampTypeHandler"/>
  183. <result column="flg_valid" property="flgValid"/>
  184. <result column="cp_id" property="cpId"/>
  185. <result column="org_name" property="orgName"/>
  186. <result column="staff_name" property="staffName"/>
  187. <result column="cus_code" property="cusCode"/>
  188. <result column="cus_name" property="cusName"/>
  189. <result column="cus_phone" property="cusPhone"/>
  190. <result column="address_area" property="addressArea" typeHandler="JsonTypeHandler"/>
  191. <result column="address_name" property="addressName"/>
  192. <result column="address_no" property="addressNo"/>
  193. <result column="address_gcj02" property="addressGcj02" typeHandler="JsonTypeHandler"/>
  194. <result column="address_full" property="addressFull"/>
  195. <result column="contact_name" property="contactName"/>
  196. <result column="contact_phone" property="contactPhone"/>
  197. <result column="cus_from" property="cusFrom" typeHandler="UuidTypeHandler"/>
  198. <result column="channel_id" property="channelId" typeHandler="UuidTypeHandler"/>
  199. <result column="fact_amt" property="factAmt"/>
  200. <result column="disc_amt" property="discAmt"/>
  201. <result column="discount" property="discount"/>
  202. <result column="flg_auto_handle" property="flgAutoHandle"/>
  203. <result column="flg_handle_setting" property="flgHandleSetting"/>
  204. <result column="channelName" property="channelName"/>
  205. <collection property="orderItemResponseList" resultMap="itemListMap" columnPrefix="list_"/>
  206. </resultMap>
  207. <!--小程序用 关联映射-->
  208. <resultMap id="itemListMap" type="java.util.Map">
  209. <result column="item_id" property="itemId"/>
  210. <result column="order_id" property="orderId"/>
  211. <result column="order_no" property="orderNo"/>
  212. <result column="item_index" property="itemIndex"/>
  213. <result column="sku_id" property="skuId"/>
  214. <result column="item_qty" property="itemQty"/>
  215. <result column="price_std" property="priceStd"/>
  216. <result column="amt_std" property="amtStd"/>
  217. <result column="price_sale" property="priceSale"/>
  218. <result column="item_amt" property="itemAmt"/>
  219. <result column="price_discount" property="priceDiscount"/>
  220. <result column="non_std_code" property="nonStdCode"/>
  221. <result column="out_status" property="outStatus"/>
  222. <result column="outing_qty" property="outingQty"/>
  223. <result column="outing_amt" property="outingAmt"/>
  224. <result column="out_qty" property="outQty"/>
  225. <result column="out_amt" property="outAmt"/>
  226. <result column="return_qty" property="returnQty"/>
  227. <result column="return_amt" property="returnAmt"/>
  228. <result column="remarks" property="remarks"/>
  229. <result column="flg_valid" property="flgValid"/>
  230. <result column="cp_id" property="cpId"/>
  231. <result column="sku_code" property="skuCode"/>
  232. <result column="sku_model" property="skuModel"/>
  233. <result column="sku_name" property="skuName"/>
  234. <result column="brand_name" property="brandName"/>
  235. <result column="short_name" property="shortName"/>
  236. <result column="sku_images" property="skuImages"/>
  237. <result column="price_purchase" property="pricePurchase"/>
  238. <result column="price_standard" property="priceStandard"/>
  239. <result column="order_qty" property="orderQty"/>
  240. <result column="price_out" property="priceOut"/>
  241. <result column="inv_id" property="invId"/>
  242. <result column="wh_id" property="whId"/>
  243. <result column="inv_qty" property="invQty"/>
  244. <result column="usable_qty" property="usableQty"/>
  245. <result column="wh_name" property="whName"/>
  246. </resultMap>
  247. <!--小程序用 总单-->
  248. <sql id="Base_Column_List_Detail_Join">
  249. t
  250. .
  251. order_id
  252. ,
  253. t.order_no,
  254. t.order_type,
  255. t.org_id,
  256. t.staff_id,
  257. t.cus_id,
  258. t.address_area,
  259. t.address_name,
  260. t.address_no,
  261. t.address_gcj02,
  262. t.address_full,
  263. t.contact_name,
  264. t.contact_phone,
  265. t.sales_channel,
  266. t.delivery_date,
  267. sys.f_remove_zero(t.sum_quantity) as sum_quantity,
  268. t.sum_standard,
  269. t.sum_amount, t.sale_discount,
  270. t.order_status, t.out_status,
  271. sys.f_remove_zero(t.outing_qty) as outing_qty, t.outing_amt, sys.f_remove_zero(t.out_qty) as out_qty,
  272. t.out_amt, sys.f_remove_zero(t.return_qty) as return_qty, t.return_amt,
  273. t.amt_receivable, amt_handle, amt_residue,
  274. t.remarks, t.annex_paths, t.make_staff, t.make_time,
  275. t.flg_valid, t.cp_id,
  276. tmo.org_name,
  277. tms.staff_name
  278. </sql>
  279. <!--小程序用 明细-->
  280. <sql id="Base_Column_List_Item_Response_Detail_Join">
  281. toi.item_id AS list_item_id,
  282. toi.order_id AS list_order_id,
  283. t.order_no AS list_order_no,
  284. toi.item_index AS list_item_index,
  285. toi.sku_id AS list_sku_id,
  286. sys.f_remove_zero(toi.item_qty) AS list_item_qty,
  287. sys.f_remove_zero(toi.item_qty) AS list_order_qty,
  288. toi.price_std AS list_price_std,
  289. toi.amt_std AS list_amt_std,
  290. toi.price_sale AS list_price_sale,
  291. toi.price_sale AS list_price_out,
  292. toi.item_amt AS list_item_amt,
  293. toi.price_discount AS list_price_discount,
  294. toi.non_std_code AS list_non_std_code,
  295. toi.out_status AS list_out_status,
  296. sys.f_remove_zero(toi.outing_qty) AS list_outing_qty,
  297. toi.outing_amt AS list_outing_amt,
  298. sys.f_remove_zero(toi.out_qty) AS list_out_qty,
  299. toi.out_amt AS list_out_amt,
  300. sys.f_remove_zero(toi.return_qty) AS list_return_qty,
  301. toi.return_amt AS list_return_amt,
  302. toi.remarks AS list_remarks,
  303. toi.flg_valid AS list_flg_valid,
  304. toi.cp_id AS list_cp_id,
  305. tmgs.sku_code AS list_sku_code,
  306. tmgs.sku_model AS list_sku_model,
  307. tmgs.sku_name AS list_sku_name,
  308. tmgb.brand_name AS list_brand_name,
  309. tmgb.short_name AS list_short_name,
  310. tmgs.sku_images AS list_sku_images,
  311. tmgs.price_purchase AS list_price_purchase,
  312. tmgs.price_standard AS list_price_standard,
  313. i.inv_id as list_inv_id,
  314. i.wh_id as list_wh_id,
  315. sys.f_remove_zero(i.inv_qty) as list_inv_qty,
  316. sys.f_remove_zero(i.usable_qty) as list_usable_qty,
  317. i.wh_name as list_wh_name
  318. </sql>
  319. <!-- 通用条件列 -->
  320. <sql id="Condition">
  321. <where>
  322. <if test="orderNo != null and orderNo != ''">
  323. AND t.order_no LIKE concat('%',my_ex.likequery(#{orderNo}),'%')
  324. </if>
  325. <if test="orderType != null and orderType != ''">
  326. AND t.order_type = #{orderType}
  327. </if>
  328. <if test="orgId != null and orgId != ''">
  329. AND t.org_id = #{orgId}
  330. </if>
  331. <if test="staffId != null and staffId != ''">
  332. AND t.staff_id = #{staffId}
  333. </if>
  334. <if test="cusId != null and cusId != ''">
  335. AND t.cus_id = #{cusId}::uuid
  336. </if>
  337. <if test="addressArea != null and addressArea != ''">
  338. AND t.address_area = #{addressArea}
  339. </if>
  340. <if test="addressName != null and addressName != ''">
  341. AND t.address_name = #{addressName}
  342. </if>
  343. <if test="addressNo != null and addressNo != ''">
  344. AND t.address_no = #{addressNo}
  345. </if>
  346. <if test="addressGcj02 != null and addressGcj02 != ''">
  347. AND t.address_gcj02 = #{addressGcj02}
  348. </if>
  349. <if test="addressFull != null and addressFull != ''">
  350. AND t.address_full LIKE concat('%',my_ex.likequery(#{addressFull}),'%')
  351. </if>
  352. <if test="contactName != null and contactName != ''">
  353. AND t.contact_name LIKE concat('%',my_ex.likequery(#{contactName}),'%')
  354. </if>
  355. <if test="contactPhone != null and contactPhone != ''">
  356. AND t.contact_phone LIKE concat('%',my_ex.likequery(#{contactPhone}),'%')
  357. </if>
  358. <if test="salesChannel != null and salesChannel != ''">
  359. AND t.sales_channel = #{salesChannel}
  360. </if>
  361. <if test="sumQuantity != null">
  362. AND t.sum_quantity = #{sumQuantity}
  363. </if>
  364. <if test="sumStandard != null">
  365. AND t.sum_standard = #{sumStandard}
  366. </if>
  367. <if test="sumAmount != null">
  368. AND t.sum_amount = #{sumAmount}
  369. </if>
  370. <if test="saleDiscount != null">
  371. AND t.sale_discount = #{saleDiscount}
  372. </if>
  373. <if test="orderStatus != null and orderStatus != ''">
  374. AND t.order_status = #{orderStatus}
  375. </if>
  376. <if test="outStatus != null and outStatus != ''">
  377. AND t.out_status = #{outStatus}
  378. </if>
  379. <if test="outingQty != null">
  380. AND t.outing_qty = #{outingQty}
  381. </if>
  382. <if test="outingAmt != null">
  383. AND t.outing_amt = #{outingAmt}
  384. </if>
  385. <if test="outQty != null">
  386. AND t.out_qty = #{outQty}
  387. </if>
  388. <if test="outAmt != null">
  389. AND t.out_amt = #{outAmt}
  390. </if>
  391. <if test="returnQty != null">
  392. AND t.return_qty = #{returnQty}
  393. </if>
  394. <if test="returnAmt != null">
  395. AND t.return_amt = #{returnAmt}
  396. </if>
  397. <if test="amtReceivable != null">
  398. AND t.amt_receivable = #{amtReceivable}
  399. </if>
  400. <if test="amtHandle != null">
  401. AND t.amt_handle = #{amtHandle}
  402. </if>
  403. <if test="amtResidue != null">
  404. AND t.amt_residue = #{amtResidue}
  405. </if>
  406. <if test="remarks != null and remarks != ''">
  407. AND t.remarks LIKE concat('%',my_ex.likequery(#{remarks}),'%')
  408. </if>
  409. <if test="annexPaths != null and annexPaths != ''">
  410. AND t.annex_paths = #{annexPaths}
  411. </if>
  412. <if test="makeStaff != null and makeStaff != ''">
  413. AND t.make_staff = #{makeStaff}
  414. </if>
  415. <if test="makeTime != null">
  416. AND t.make_time = #{makeTime}
  417. </if>
  418. <if test="cpId != null">
  419. AND t.cp_id = #{cpId}
  420. </if>
  421. <if test="cusPhone != null and cusPhone != ''">
  422. AND tmc.cus_phone LIKE concat('%',my_ex.likequery(#{cusPhone}),'%')
  423. </if>
  424. <if test="cusName != null and cusName != ''">
  425. AND tmc.cus_name LIKE concat('%',my_ex.likequery(#{cusName}),'%')
  426. </if>
  427. <if test="orgIdList != null and orgIdList.size() > 0">
  428. AND t.org_id =any(#{orgIdList, typeHandler=uuidListTypeHandler})
  429. </if>
  430. <if test="staffIdList != null and staffIdList.size() > 0">
  431. AND t.staff_id =any(#{staffIdList, typeHandler=uuidListTypeHandler})
  432. </if>
  433. <if test="outStatusList != null and outStatusList.size() > 0">
  434. AND t.out_status =any(#{outStatusList, typeHandler=StringListTypeHandler})
  435. </if>
  436. <if test="deliveryDateStart != null and deliveryDateEnd != null">
  437. AND t.delivery_date &gt;= #{deliveryDateStart}::timestamp with time zone
  438. AND t.delivery_date &lt; #{deliveryDateEnd}::timestamp with time zone + interval '1 day'
  439. </if>
  440. <if test="makeTimeStart != null and makeTimeEnd != null">
  441. AND t.make_time &gt;= #{makeTimeStart}::timestamp with time zone
  442. AND t.make_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
  443. </if>
  444. <if test="flgValidList != null and flgValidList.size()>0">
  445. AND t.flg_valid =any(#{flgValidList, typeHandler=BooleanListTypeHandler})
  446. </if>
  447. <if test="staffIds != null and staffIds.size()>0">
  448. AND t.staff_id = any(#{staffIds, typeHandler=uuidListTypeHandler})
  449. </if>
  450. <if test="orgIds != null and orgIds.size()>0">
  451. AND t.org_id = any(#{orgIds, typeHandler=uuidListTypeHandler})
  452. </if>
  453. <if test="createtimeStart != null and createtimeEnd != null">
  454. AND t.op_create_time &gt;= #{createtimeStart}::timestamp with time zone
  455. AND t.op_create_time &lt; #{createtimeEnd}::timestamp with time zone + interval '1 day'
  456. </if>
  457. <if test="viewVoidedDocuments !=null and viewVoidedDocuments == false">
  458. AND t.flg_valid = true
  459. </if>
  460. <if test="searchText !=null">
  461. AND ( t.order_no LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  462. OR t.contact_phone LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  463. OR tmc.cus_name LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  464. OR tmc.cus_phone LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  465. OR t.address_full LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  466. OR t.remarks LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  467. )
  468. </if>
  469. </where>
  470. </sql>
  471. <sql id="idsForeach">
  472. <!-- 根据主键orderId批量操作 -->
  473. WHERE order_id in
  474. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  475. #{item}
  476. </foreach>
  477. </sql>
  478. <!-- 查询表t_psi_order,(条件查询+分页)列表 -->
  479. <select id="selectByCond" resultMap="BaseResultMapResponse">
  480. SELECT t.order_id,
  481. t.order_no,
  482. t.order_type,
  483. sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "orderTypeName",
  484. t.org_id,
  485. tmo.org_name as "orgName",
  486. t.staff_id,
  487. tms.staff_name as "staffName",
  488. t.cus_id,
  489. tmc.cus_code as "cusCode",
  490. tmc.cus_name as "cusName",
  491. tmc.cus_phone as "cusPhone",
  492. tmc.cus_from as "cusFrom",
  493. tmdd.data_value as "cusFromName",
  494. t.address_area,
  495. t.address_name,
  496. t.address_no,
  497. t.address_gcj02,
  498. t.address_full,
  499. t.contact_name,
  500. t.contact_phone,
  501. t.sales_channel,
  502. tmsc.channel_name as "channelName",
  503. t.delivery_date,
  504. sys.f_remove_zero(t.sum_quantity) as sum_quantity,
  505. t.sum_standard,
  506. t.sum_amount,
  507. t.sale_discount,
  508. t.order_status,
  509. sys.f_get_name_i18n(tdk2.kind_name_i18n, #{i18n}) as "orderStatusName",
  510. t.out_status,
  511. sys.f_get_name_i18n(tdk3.kind_name_i18n, #{i18n}) as "outStatusName",
  512. sys.f_remove_zero(t.outing_qty) as outing_qty,
  513. t.outing_amt,
  514. sys.f_remove_zero(t.out_qty) as out_qty,
  515. t.out_amt,
  516. sys.f_remove_zero(t.return_qty) as return_qty,
  517. t.return_amt,
  518. t.amt_receivable,
  519. t.amt_handle,
  520. t.amt_residue,
  521. t.remarks,
  522. t.annex_paths,
  523. makestaff.staff_name as "makeStaffName",
  524. t.make_time,
  525. t.cp_id,
  526. t.flg_valid
  527. FROM dkic_b.t_psi_order as t
  528. left join dkic_b.t_mst_sale_channel tmsc on t.sales_channel = tmsc.channel_id
  529. left join dkic_b.t_mst_org tmo on t.org_id = tmo.org_id
  530. left join dkic_b.t_mst_staff tms on t.staff_id = tms.staff_id
  531. left join dkic_b.t_mst_staff as makestaff on t.make_staff = makestaff.staff_id
  532. left join dkic_b.t_mst_customer tmc on t.cus_id = tmc.cus_id
  533. left join dkic_b.t_mst_dictionary_data tmdd on tmc.cus_from = tmdd.data_id
  534. left join sys.t_data_kind as tdk1 on t.order_type = tdk1.kind_code
  535. left join sys.t_data_kind as tdk2 on t.order_status = tdk2.kind_code
  536. left join sys.t_data_kind as tdk3 on t.out_status = tdk3.kind_code
  537. <include refid="Condition"/>
  538. order by t.op_create_time desc
  539. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  540. limit #{end} offset #{start}
  541. </if>
  542. </select>
  543. <!-- countByCond被改了,重写一个 -->
  544. <select id="countByCondForSelectByCond" resultType="Long">
  545. SELECT
  546. count(1)
  547. FROM dkic_b.t_psi_order as t
  548. left join dkic_b.t_mst_customer tmc on t.cus_id = tmc.cus_id
  549. <include refid="Condition"/>
  550. </select>
  551. <sql id="Base_Column_List_Item_Response_Join">
  552. toi.item_id AS toi_item_id,
  553. t.order_id AS toi_order_id,
  554. t.order_no AS toi_order_no,
  555. toi.order_id AS toi_order_id,
  556. toi.item_index AS toi_item_index,
  557. toi.sku_id AS toi_sku_id,
  558. sys.f_remove_zero(toi.item_qty) AS toi_item_qty,
  559. toi.price_std AS toi_price_std,
  560. toi.amt_std AS toi_amt_std,
  561. toi.price_sale AS toi_price_sale,
  562. toi.item_amt AS toi_item_amt,
  563. toi.price_discount AS toi_price_discount,
  564. toi.non_std_code AS toi_non_std_code,
  565. toi.out_status AS toi_out_status,
  566. sys.f_remove_zero(toi.outing_qty) AS toi_outing_qty,
  567. toi.outing_amt AS toi_outing_amt,
  568. sys.f_remove_zero(toi.out_qty) AS toi_out_qty,
  569. toi.out_amt AS toi_out_amt,
  570. sys.f_remove_zero(toi.return_qty) AS toi_return_qty,
  571. toi.return_amt AS toi_return_amt,
  572. toi.remarks AS toi_remarks,
  573. toi.flg_valid AS toi_flg_valid,
  574. toi.cp_id AS toi_cp_id,
  575. tmgs.sku_code AS toi_sku_code,
  576. tmgs.sku_model AS toi_sku_model,
  577. tmgs.sku_name AS toi_sku_name,
  578. tmgb.brand_name AS toi_brand_name,
  579. tmgb.short_name AS toi_short_name,
  580. tmgs.price_purchase AS toi_price_purchase,
  581. tmgs.price_standard AS toi_price_standard
  582. </sql>
  583. <!-- 查询表t_psi_order,(条件查询+分页)列表 -->
  584. <select id="purSaleSelectByCond" resultType="Map">
  585. SELECT T
  586. .order_no AS "orderNo",
  587. T.order_type AS "orderType",
  588. sys.f_get_name_i18n ( tdk1.kind_name_i18n, #{ i18n } ) AS "orderTypeName",
  589. T.org_id AS "orgId",
  590. tmo.org_name AS "orgName",
  591. T.staff_id AS "staffId",
  592. tms.staff_name AS "staffName",
  593. T.cus_id AS "cusId",
  594. tmc.cus_code AS "cusCode",
  595. tmc.cus_name AS "cusName",
  596. tmc.cus_phone AS "cusPhone",
  597. tmc.cus_from AS "cusFrom",
  598. tmdd.data_value AS "dataValue",
  599. T.address_area AS "addressArea",
  600. T.address_name AS "addressName",
  601. T.address_no AS "addressNo",
  602. T.address_gcj02 AS "addressGcj02",
  603. T.address_full AS "addressFull",
  604. T.contact_name AS "contactName",
  605. T.contact_phone AS "contactPhone",
  606. T.sales_channel AS "salesChannel",
  607. tmsc.channel_name AS "channelName",
  608. T.delivery_date AS "deliveryDate",
  609. sys.f_remove_zero(T.sum_quantity) AS "sumQuantity",
  610. T.sum_standard AS "sumStandard",
  611. T.sum_amount AS "sumAmount",
  612. T.sale_discount AS "saleDiscount",
  613. T.order_status AS "orderStatus",
  614. sys.f_get_name_i18n ( tdk2.kind_name_i18n, #{ i18n } ) AS "orderStatusName",
  615. T.out_status AS "outStatus",
  616. sys.f_get_name_i18n ( tdk3.kind_name_i18n, #{ i18n } ) AS "outStatusName",
  617. sys.f_remove_zero(T.outing_qty) AS "outingQty",
  618. T.outing_amt AS "outingAmt",
  619. sys.f_remove_zero(T.out_qty) AS "outQty",
  620. T.out_amt AS "outAmt",
  621. sys.f_remove_zero(T.return_qty) AS "returnQty",
  622. T.return_amt AS "returnAmt",
  623. T.amt_receivable AS "amtReceivable",
  624. T.amt_handle AS "amtHandle",
  625. T.amt_residue AS "amtResidue",
  626. T.remarks AS "remarks",
  627. T.annex_paths AS "annexPaths",
  628. makestaff.staff_name AS "makeStaffName",
  629. T.make_time AS "annexPaths",
  630. T.cp_id AS "cpId",
  631. T.flg_valid AS "flgValid",
  632. (
  633. SELECT
  634. json_agg ( row_to_json ( item ) )
  635. FROM
  636. (
  637. SELECT
  638. toi.item_id AS "itemId",
  639. T.order_id AS "orderId",
  640. T.order_no AS "orderNo",
  641. toi.order_id AS "orderId",
  642. toi.item_index AS "itemIndex",
  643. toi.sku_id AS "skuId",
  644. toi.item_qty AS "itemQty",
  645. toi.price_std AS "priceStd",
  646. toi.amt_std AS "amtStd",
  647. toi.price_sale AS "priceSale",
  648. toi.item_amt AS "itemAmt",
  649. toi.price_discount AS "priceDiscount",
  650. toi.non_std_code AS "nonStdCode",
  651. toi.out_status AS "outStatus",
  652. toi.outing_qty AS "outingQty",
  653. toi.outing_amt AS "outingAmt",
  654. toi.out_qty AS "outQty",
  655. toi.out_amt AS "outAmt",
  656. toi.return_qty AS "returnQty",
  657. toi.return_amt AS "returnAmt",
  658. toi.remarks AS "remarks",
  659. toi.flg_valid AS "flgValid",
  660. toi.cp_id AS "cpId",
  661. tmgs.sku_code AS "skuCode",
  662. tmgs.sku_model AS "skuModel",
  663. tmgs.sku_name AS "skuName",
  664. tmgb.brand_name AS "brandName",
  665. tmgb.short_name AS "shortName",
  666. tmgs.price_purchase AS "pricePurchase",
  667. tmgs.price_standard AS "priceStandard",
  668. tmgs.sku_images AS "skuImages"
  669. ,toi.unit_id AS "unitId"
  670. ,toi.sub_unit_id AS "subUnitId"
  671. ,toi.pack_box AS "packBox"
  672. ,toi.box AS "box"
  673. ,toi.piece AS "piece"
  674. ,tmgus.unit_name as "subUnitName"
  675. ,tmgu.unit_name as "unitName"
  676. ,tmgs.flg_sub_unit as "flgSubUnit"
  677. FROM
  678. dkic_b.t_psi_order_item toi
  679. LEFT JOIN dkic_b.t_mst_goods_sku tmgs ON tmgs.sku_id = toi.sku_id
  680. LEFT JOIN dkic_b.t_mst_goods_brand tmgb ON tmgb.brand_id = tmgs.brand_id
  681. left join dkic_b.t_mst_unit as tmgu on toi.unit_id = tmgu.unit_id
  682. left join dkic_b.t_mst_unit as tmgus on toi.sub_unit_id = tmgus.unit_id
  683. WHERE
  684. toi.order_id = T.order_id
  685. ) item
  686. ) AS "orderItemResponseList"
  687. FROM
  688. dkic_b.t_psi_order
  689. AS T LEFT JOIN dkic_b.t_psi_order_item toi ON toi.order_id = T.order_id
  690. LEFT JOIN dkic_b.t_mst_sale_channel tmsc ON T.sales_channel = tmsc.channel_id
  691. LEFT JOIN dkic_b.t_mst_org tmo ON T.org_id = tmo.org_id
  692. LEFT JOIN dkic_b.t_mst_staff tms ON T.staff_id = tms.staff_id
  693. LEFT JOIN dkic_b.t_mst_staff AS makestaff ON T.make_staff = makestaff.staff_id
  694. LEFT JOIN dkic_b.t_mst_customer tmc ON T.cus_id = tmc.cus_id
  695. LEFT JOIN dkic_b.t_mst_dictionary_data tmdd ON tmc.cus_from = tmdd.data_id
  696. LEFT JOIN sys.t_data_kind AS tdk1 ON T.order_type = tdk1.kind_code
  697. LEFT JOIN sys.t_data_kind AS tdk2 ON T.order_status = tdk2.kind_code
  698. LEFT JOIN sys.t_data_kind AS tdk3 ON T.out_status = tdk3.kind_code
  699. <include refid="Condition"/>
  700. order by t.op_create_time desc
  701. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  702. limit #{end} offset #{start}
  703. </if>
  704. </select>
  705. <!-- 查询表t_psi_order,(条件查询)个数 -->
  706. <select id="countByCond" resultType="Long">
  707. SELECT
  708. count(1)
  709. FROM dkic_b.t_psi_order as t
  710. left join dkic_b.t_mst_customer tmc on t.cus_id = tmc.cus_id
  711. left join dkic_b.t_psi_order_item toi on toi.order_id = t.order_id
  712. <include refid="Condition"/>
  713. </select>
  714. <!-- 根据主键查询表t_psi_order的一行数据 -->
  715. <select id="selectById" resultMap="BaseResultMapResponse">
  716. SELECT t.order_id,
  717. t.order_no,
  718. t.order_type,
  719. sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "orderTypeName",
  720. t.org_id,
  721. tmo.org_name as "orgName",
  722. t.staff_id,
  723. tms.staff_name as "staffName",
  724. t.cus_id,
  725. tmc.cus_code as "cusCode",
  726. tmc.cus_name as "cusName",
  727. tmc.cus_phone as "cusPhone",
  728. tmc.cus_from as "cusFrom",
  729. tmdd.data_value as "cusFromName",
  730. t.address_area,
  731. t.address_name,
  732. t.address_no,
  733. t.address_gcj02,
  734. t.address_full,
  735. t.contact_name,
  736. t.contact_phone,
  737. t.sales_channel,
  738. tmsc.channel_name as "channelName",
  739. t.delivery_date,
  740. sys.f_remove_zero(t.sum_quantity) as sum_quantity,
  741. t.sum_standard,
  742. t.sum_amount,
  743. t.sale_discount,
  744. t.order_status,
  745. sys.f_get_name_i18n(tdk2.kind_name_i18n, #{i18n}) as "orderStatusName",
  746. t.out_status,
  747. sys.f_get_name_i18n(tdk3.kind_name_i18n, #{i18n}) as "outStatusName",
  748. sys.f_remove_zero(t.outing_qty) as outing_qty,
  749. t.outing_amt,
  750. sys.f_remove_zero(t.out_qty) as out_qty,
  751. t.out_amt,
  752. sys.f_remove_zero(t.return_qty) as return_qty,
  753. t.return_amt,
  754. t.amt_receivable,
  755. t.amt_handle,
  756. t.amt_residue,
  757. t.remarks,
  758. t.annex_paths,
  759. t.make_staff,
  760. makestaff.staff_name as "makeStaffName",
  761. t.make_time,
  762. t.cp_id,
  763. t.discount,
  764. t.fact_amt,
  765. t.disc_amt
  766. FROM dkic_b.t_psi_order as t
  767. left join dkic_b.t_mst_sale_channel tmsc on t.sales_channel = tmsc.channel_id
  768. left join dkic_b.t_mst_org tmo on t.org_id = tmo.org_id
  769. left join dkic_b.t_mst_staff tms on t.staff_id = tms.staff_id
  770. left join dkic_b.t_mst_staff as makestaff on t.make_staff = makestaff.staff_id
  771. left join dkic_b.t_mst_customer tmc on t.cus_id = tmc.cus_id
  772. left join dkic_b.t_mst_dictionary_data tmdd on tmc.cus_from = tmdd.data_id
  773. left join sys.t_data_kind as tdk1 on t.order_type = tdk1.kind_code
  774. left join sys.t_data_kind as tdk2 on t.order_status = tdk2.kind_code
  775. left join sys.t_data_kind as tdk3 on t.out_status = tdk3.kind_code
  776. WHERE t.order_id = #{id}::uuid
  777. </select>
  778. <!-- 根据主键锁定表t_psi_order的一行数据 -->
  779. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  780. SELECT
  781. <include refid="Base_Column_List"/>
  782. FROM dkic_b.t_psi_order
  783. WHERE order_id = #{id}::uuid
  784. for update
  785. </select>
  786. <!-- 根据主键锁定表t_psi_order的多行数据 -->
  787. <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
  788. SELECT
  789. <include refid="Base_Column_List"/>
  790. FROM dkic_b.t_psi_order
  791. <include refid="idsForeach"/>
  792. for update
  793. </select>
  794. <insert id="insertBatch">
  795. insert into dkic_b.t_psi_order
  796. (
  797. <trim suffixOverrides=",">
  798. order_no,
  799. order_type,
  800. org_id,
  801. staff_id,
  802. cus_id,
  803. address_area,
  804. address_name,
  805. address_no,
  806. address_gcj02,
  807. address_full,
  808. contact_name,
  809. contact_phone,
  810. sales_channel,
  811. delivery_date,
  812. sum_quantity,
  813. sum_standard,
  814. sum_amount,
  815. sale_discount,
  816. order_status,
  817. out_status,
  818. outing_qty,
  819. outing_amt,
  820. out_qty,
  821. out_amt,
  822. return_qty,
  823. return_amt,
  824. amt_receivable,
  825. amt_handle,
  826. amt_residue,
  827. remarks,
  828. annex_paths,
  829. make_staff,
  830. make_time,
  831. cp_id,
  832. op_app_code,
  833. fact_amt,
  834. disc_amt,
  835. discount,
  836. flg_auto_handle,
  837. flg_handle_setting,
  838. </trim>
  839. )
  840. values
  841. <foreach collection="list" index="index" item="item" separator=",">
  842. (
  843. <trim suffixOverrides=",">
  844. #{item.orderNo},
  845. #{item.orderType},
  846. #{item.orgId}::uuid,
  847. #{item.staffId}::uuid,
  848. #{item.cusId}::uuid,
  849. #{item.addressArea},
  850. #{item.addressName},
  851. #{item.addressNo},
  852. #{item.addressGcj02},
  853. #{item.addressFull},
  854. #{item.contactName},
  855. #{item.contactPhone},
  856. #{item.salesChannel}::uuid,
  857. #{item.deliveryDate},
  858. #{item.sumQuantity},
  859. #{item.sumStandard},
  860. #{item.sumAmount},
  861. #{item.saleDiscount},
  862. #{item.orderStatus},
  863. #{item.outStatus},
  864. #{item.outingQty},
  865. #{item.outingAmt},
  866. #{item.outQty},
  867. #{item.outAmt},
  868. #{item.returnQty},
  869. #{item.returnAmt},
  870. #{item.amtReceivable},
  871. #{item.amtHandle},
  872. #{item.amtResidue},
  873. #{item.remarks},
  874. #{item.annexPaths},
  875. #{item.makeStaff}::uuid,
  876. #{item.makeTime},
  877. #{item.cpId},
  878. #{item.opAppCode},
  879. #{item.factAmt},
  880. #{item.discAmt},
  881. #{item.discount},
  882. #{item.flgAutoHandle},
  883. #{item.flgHandleSetting},
  884. </trim>
  885. )
  886. </foreach>
  887. </insert>
  888. <!-- 根据id修改-->
  889. <update id="updateById" parameterType="com.dk.mdm.model.pojo.sale.Order">
  890. update dkic_b.t_psi_order
  891. <set>
  892. <if test=" et!=null and et.orderType != null">
  893. order_type =#{et.orderType,jdbcType=VARCHAR},
  894. </if>
  895. <if test=" et!=null and et.orgId != null">
  896. org_id =#{et.orgId,typeHandler=UuidTypeHandler},
  897. </if>
  898. <if test=" et!=null and et.staffId != null">
  899. staff_id =#{et.staffId,typeHandler=UuidTypeHandler},
  900. </if>
  901. <if test=" et!=null and et.cusId != null">
  902. cus_id =#{et.cusId,typeHandler=UuidTypeHandler},
  903. </if>
  904. <if test=" et!=null and et.addressArea != null">
  905. address_area =#{et.addressArea,typeHandler=JsonTypeHandler},
  906. </if>
  907. <if test=" et!=null and et.addressName != null">
  908. address_name =#{et.addressName,jdbcType=VARCHAR},
  909. </if>
  910. <if test=" et!=null and et.addressNo != null">
  911. address_no =#{et.addressNo,jdbcType=VARCHAR},
  912. </if>
  913. <if test=" et!=null and et.addressGcj02 != null">
  914. address_gcj02 =#{et.addressGcj02,typeHandler=JsonTypeHandler},
  915. </if>
  916. <if test=" et!=null and et.addressFull != null">
  917. address_full =#{et.addressFull,jdbcType=VARCHAR},
  918. </if>
  919. <if test=" et!=null and et.contactName != null">
  920. contact_name =#{et.contactName,jdbcType=VARCHAR},
  921. </if>
  922. <if test=" et!=null and et.contactPhone != null">
  923. contact_phone =#{et.contactPhone,jdbcType=VARCHAR},
  924. </if>
  925. <if test=" et!=null and et.salesChannel != null">
  926. sales_channel =#{et.salesChannel,jdbcType=OTHER},
  927. </if>
  928. <if test=" et!=null and et.deliveryDate != null">
  929. delivery_date =#{et.deliveryDate,jdbcType=DATE},
  930. </if>
  931. <if test=" et!=null and et.sumQuantity != null">
  932. sum_quantity =#{et.sumQuantity,jdbcType=NUMERIC},
  933. </if>
  934. <if test=" et!=null and et.sumStandard != null">
  935. sum_standard =#{et.sumStandard,jdbcType=NUMERIC},
  936. </if>
  937. <if test=" et!=null and et.sumAmount != null">
  938. sum_amount =#{et.sumAmount,jdbcType=NUMERIC},
  939. </if>
  940. <if test=" et!=null and et.saleDiscount != null">
  941. sale_discount =#{et.saleDiscount,jdbcType=NUMERIC},
  942. </if>
  943. <if test=" et!=null and et.orderStatus != null">
  944. order_status =#{et.orderStatus,jdbcType=VARCHAR},
  945. </if>
  946. <if test=" et!=null and et.outStatus != null">
  947. out_status =#{et.outStatus,jdbcType=VARCHAR},
  948. </if>
  949. <if test=" et!=null and et.outingQty != null">
  950. outing_qty = outing_qty + #{et.outingQty,jdbcType=NUMERIC},
  951. </if>
  952. <if test=" et!=null and et.outingAmt != null">
  953. outing_amt = outing_amt + #{et.outingAmt,jdbcType=NUMERIC},
  954. </if>
  955. <if test=" et!=null and et.outQty != null">
  956. out_qty =out_qty + #{et.outQty,jdbcType=NUMERIC},
  957. </if>
  958. <if test=" et!=null and et.outAmt != null">
  959. out_amt = out_amt + #{et.outAmt,jdbcType=NUMERIC},
  960. </if>
  961. <if test=" et!=null and et.returnQty != null">
  962. return_qty =#{et.returnQty,jdbcType=NUMERIC},
  963. </if>
  964. <if test=" et!=null and et.returnAmt != null">
  965. return_amt =#{et.returnAmt,jdbcType=NUMERIC},
  966. </if>
  967. <if test=" et!=null and et.amtReceivable != null">
  968. amt_receivable =#{et.amtReceivable,jdbcType=NUMERIC},
  969. </if>
  970. <if test=" et!=null and et.amtHandle != null">
  971. amt_handle =#{et.amtHandle,jdbcType=NUMERIC},
  972. </if>
  973. <if test=" et!=null and et.amtResidue != null">
  974. amt_residue =#{et.amtResidue,jdbcType=NUMERIC},
  975. </if>
  976. <if test=" et!=null and et.remarks != null">
  977. remarks =#{et.remarks,jdbcType=VARCHAR},
  978. </if>
  979. <if test=" et!=null and et.annexPaths != null">
  980. annex_paths =#{et..annexPaths,typeHandler=JsonTypeHandler},
  981. </if>
  982. <if test=" et!=null and et.makeStaff != null">
  983. make_staff =#{et.makeStaff,jdbcType=OTHER},
  984. </if>
  985. <if test=" et!=null and et.makeTime != null">
  986. make_time =#{et.makeTime,jdbcType=TIMESTAMP},
  987. </if>
  988. <if test=" et!=null and et.flgValid != null">
  989. flg_valid =#{et.flgValid,jdbcType=BOOLEAN},
  990. </if>
  991. <if test=" et!=null and et.cpId != null">
  992. cp_id =#{et.cpId,jdbcType=INTEGER},
  993. </if>
  994. <if test=" et!=null and et.factAmt != null">
  995. fact_amt =#{et.factAmt,jdbcType=NUMERIC},
  996. </if>
  997. <if test=" et!=null and et.discAmt != null">
  998. disc_amt =#{et.discAmt,jdbcType=NUMERIC},
  999. </if>
  1000. <if test=" et!=null and et.discount != null">
  1001. discount =#{et.discount,jdbcType=NUMERIC},
  1002. </if>
  1003. <if test=" et!=null and et.flgAutoHandle != null">
  1004. flg_auto_handle =#{et.flgAutoHandle,jdbcType=BOOLEAN},
  1005. </if>
  1006. <if test=" et!=null and et.flgHandleSetting != null">
  1007. flg_handle_setting =#{et.flgHandleSetting,jdbcType=BOOLEAN},
  1008. </if>
  1009. </set>
  1010. where order_id =#{et.orderId,typeHandler=UuidTypeHandler}
  1011. and sum_quantity >= (out_qty + outing_qty)
  1012. </update>
  1013. <!-- 小程序 条件查询(总单带明细)-->
  1014. <select id="selectByCondDetail" resultMap="BaseResultMapDetailResponse">
  1015. SELECT
  1016. <include refid="Base_Column_List_Detail_Join"/>,
  1017. tmc.cus_code,tmc.cus_name, tmc.cus_phone, tmc.address_area, tmc.address_name, tmc.address_no,
  1018. tmc.address_gcj02, tmc.address_full, tmc.contact_name, tmc.contact_phone, tmc.cus_from, tmc.channel_id,
  1019. tmsc.channel_name as "channelName",
  1020. <include refid="Base_Column_List_Item_Response_Detail_Join"/>
  1021. FROM dkic_b.t_psi_order as t
  1022. left join dkic_b.t_mst_customer tmc on tmc.cus_id = t.cus_id
  1023. left join dkic_b.t_psi_order_item toi on toi.order_id = t.order_id
  1024. inner join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = toi.sku_id
  1025. left join dkic_b.t_mst_goods_brand tmgb on tmgb.brand_id = tmgs.brand_id
  1026. left join dkic_b.t_mst_org tmo on t.org_id = tmo.org_id
  1027. left join dkic_b.t_mst_sale_channel tmsc on t.sales_channel = tmsc.channel_id
  1028. left join dkic_b.t_mst_staff tms on t.staff_id = tms.staff_id
  1029. left join(SELECT T.*
  1030. FROM (select tpi.inv_id,
  1031. tpi.wh_id,
  1032. tpi.inv_qty,
  1033. tpi.usable_qty,
  1034. tpi.sku_id,
  1035. tpi.non_std_code,
  1036. tpi.cp_id,
  1037. tmw.wh_name,
  1038. rank()
  1039. over (partition by tpi.cp_id,tpi.sku_id,tpi.non_std_code order by tpi.inv_id) as RK
  1040. from dkic_b.t_psi_inventory as tpi
  1041. left join dkic_b.t_mst_warehouse as tmw on tmw.wh_id = tpi.wh_id) T
  1042. WHERE T.RK = 1) as i
  1043. on i.sku_id = toi.sku_id and i.non_std_code = toi.non_std_code and i.cp_id = toi.cp_id
  1044. <include refid="Condition"/>
  1045. order by t.op_create_time desc
  1046. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  1047. limit #{end} offset #{start}
  1048. </if>
  1049. </select>
  1050. <!--小程序-->
  1051. <select id="countByCondDetail" resultType="Long">
  1052. SELECT
  1053. count(1)
  1054. FROM dkic_b.t_psi_order as t
  1055. <include refid="Condition"/>
  1056. </select>
  1057. <!--修改退货信息 -->
  1058. <update id="updateReturnMessage" parameterType="com.dk.mdm.model.pojo.sale.Order">
  1059. update dkic_b.t_psi_order
  1060. <set>
  1061. <if test=" returnQty != null">
  1062. return_qty = return_qty + #{returnQty,jdbcType=NUMERIC},
  1063. </if>
  1064. <if test=" returnAmt != null">
  1065. return_amt = return_amt + #{returnAmt,jdbcType=NUMERIC},
  1066. </if>
  1067. </set>
  1068. where order_id = #{orderId,typeHandler=UuidTypeHandler}
  1069. and out_qty >= return_qty
  1070. </update>
  1071. <!--销售跟踪报表 -->
  1072. <select id="getOrderTrackReport" resultType="java.util.Map">
  1073. SELECT *
  1074. FROM dkic_b.f_query_ord_for_track(#{ordId}::uuid,#{i18n})
  1075. </select>
  1076. <!-- 获取实收金额 -->
  1077. <select id="getFactReceipt" resultType="java.util.Map">
  1078. SELECT COALESCE(sum(t.amt_handle - t.amt_waive), 0) as "sumFactReceipt"
  1079. FROM dkic_b.t_mac_account_item as t
  1080. inner join dkic_b.t_psi_outbound as tpo on tpo.receivable_id = t.item_id
  1081. where t.flg_valid
  1082. and t.acc_item_type = '账款类型-应收'
  1083. and tpo.from_id = #{id}::uuid
  1084. </select>
  1085. </mapper>