OrderMapper.xml 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103
  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. <sql id="Base_Column_List_Item_Response_Join">
  544. toi.item_id AS toi_item_id,
  545. t.order_id AS toi_order_id,
  546. t.order_no AS toi_order_no,
  547. toi.order_id AS toi_order_id,
  548. toi.item_index AS toi_item_index,
  549. toi.sku_id AS toi_sku_id,
  550. sys.f_remove_zero(toi.item_qty) AS toi_item_qty,
  551. toi.price_std AS toi_price_std,
  552. toi.amt_std AS toi_amt_std,
  553. toi.price_sale AS toi_price_sale,
  554. toi.item_amt AS toi_item_amt,
  555. toi.price_discount AS toi_price_discount,
  556. toi.non_std_code AS toi_non_std_code,
  557. toi.out_status AS toi_out_status,
  558. sys.f_remove_zero(toi.outing_qty) AS toi_outing_qty,
  559. toi.outing_amt AS toi_outing_amt,
  560. sys.f_remove_zero(toi.out_qty) AS toi_out_qty,
  561. toi.out_amt AS toi_out_amt,
  562. sys.f_remove_zero(toi.return_qty) AS toi_return_qty,
  563. toi.return_amt AS toi_return_amt,
  564. toi.remarks AS toi_remarks,
  565. toi.flg_valid AS toi_flg_valid,
  566. toi.cp_id AS toi_cp_id,
  567. tmgs.sku_code AS toi_sku_code,
  568. tmgs.sku_model AS toi_sku_model,
  569. tmgs.sku_name AS toi_sku_name,
  570. tmgb.brand_name AS toi_brand_name,
  571. tmgb.short_name AS toi_short_name,
  572. tmgs.price_purchase AS toi_price_purchase,
  573. tmgs.price_standard AS toi_price_standard
  574. </sql>
  575. <!-- 查询表t_psi_order,(条件查询+分页)列表 -->
  576. <select id="purSaleSelectByCond" resultType="Map">
  577. SELECT T
  578. .order_no AS "orderNo",
  579. T.order_type AS "orderType",
  580. sys.f_get_name_i18n ( tdk1.kind_name_i18n, #{ i18n } ) AS "orderTypeName",
  581. T.org_id AS "orgId",
  582. tmo.org_name AS "orgName",
  583. T.staff_id AS "staffId",
  584. tms.staff_name AS "staffName",
  585. T.cus_id AS "cusId",
  586. tmc.cus_code AS "cusCode",
  587. tmc.cus_name AS "cusName",
  588. tmc.cus_phone AS "cusPhone",
  589. tmc.cus_from AS "cusFrom",
  590. tmdd.data_value AS "dataValue",
  591. T.address_area AS "addressArea",
  592. T.address_name AS "addressName",
  593. T.address_no AS "addressNo",
  594. T.address_gcj02 AS "addressGcj02",
  595. T.address_full AS "addressFull",
  596. T.contact_name AS "contactName",
  597. T.contact_phone AS "contactPhone",
  598. T.sales_channel AS "salesChannel",
  599. tmsc.channel_name AS "channelName",
  600. T.delivery_date AS "deliveryDate",
  601. sys.f_remove_zero(T.sum_quantity) AS "sumQuantity",
  602. T.sum_standard AS "sumStandard",
  603. T.sum_amount AS "sumAmount",
  604. T.sale_discount AS "saleDiscount",
  605. T.order_status AS "orderStatus",
  606. sys.f_get_name_i18n ( tdk2.kind_name_i18n, #{ i18n } ) AS "orderStatusName",
  607. T.out_status AS "outStatus",
  608. sys.f_get_name_i18n ( tdk3.kind_name_i18n, #{ i18n } ) AS "outStatusName",
  609. sys.f_remove_zero(T.outing_qty) AS "outingQty",
  610. T.outing_amt AS "outingAmt",
  611. sys.f_remove_zero(T.out_qty) AS "outQty",
  612. T.out_amt AS "outAmt",
  613. sys.f_remove_zero(T.return_qty) AS "returnQty",
  614. T.return_amt AS "returnAmt",
  615. T.amt_receivable AS "amtReceivable",
  616. T.amt_handle AS "amtHandle",
  617. T.amt_residue AS "amtResidue",
  618. T.remarks AS "remarks",
  619. T.annex_paths AS "annexPaths",
  620. makestaff.staff_name AS "makeStaffName",
  621. T.make_time AS "annexPaths",
  622. T.cp_id AS "cpId",
  623. T.flg_valid AS "flgValid",
  624. (
  625. SELECT
  626. json_agg ( row_to_json ( item ) )
  627. FROM
  628. (
  629. SELECT
  630. toi.item_id AS "itemId",
  631. T.order_id AS "orderId",
  632. T.order_no AS "orderNo",
  633. toi.order_id AS "orderId",
  634. toi.item_index AS "itemIndex",
  635. toi.sku_id AS "skuId",
  636. toi.item_qty AS "itemQty",
  637. toi.price_std AS "priceStd",
  638. toi.amt_std AS "amtStd",
  639. toi.price_sale AS "priceSale",
  640. toi.item_amt AS "itemAmt",
  641. toi.price_discount AS "priceDiscount",
  642. toi.non_std_code AS "nonStdCode",
  643. toi.out_status AS "outStatus",
  644. toi.outing_qty AS "outingQty",
  645. toi.outing_amt AS "outingAmt",
  646. toi.out_qty AS "outQty",
  647. toi.out_amt AS "outAmt",
  648. toi.return_qty AS "returnQty",
  649. toi.return_amt AS "returnAmt",
  650. toi.remarks AS "remarks",
  651. toi.flg_valid AS "flgValid",
  652. toi.cp_id AS "cpId",
  653. tmgs.sku_code AS "skuCode",
  654. tmgs.sku_model AS "skuModel",
  655. tmgs.sku_name AS "skuName",
  656. tmgb.brand_name AS "brandName",
  657. tmgb.short_name AS "shortName",
  658. tmgs.price_purchase AS "pricePurchase",
  659. tmgs.price_standard AS "priceStandard",
  660. tmgs.sku_images AS "skuImages"
  661. ,toi.unit_id AS "unitId"
  662. ,toi.sub_unit_id AS "subUnitId"
  663. ,toi.pack_box AS "packBox"
  664. ,toi.box AS "box"
  665. ,toi.piece AS "piece"
  666. ,tmgus.unit_name as "subUnitName"
  667. ,tmgu.unit_name as "unitName"
  668. ,tmgs.flg_sub_unit as "flgSubUnit"
  669. FROM
  670. dkic_b.t_psi_order_item toi
  671. LEFT JOIN dkic_b.t_mst_goods_sku tmgs ON tmgs.sku_id = toi.sku_id
  672. LEFT JOIN dkic_b.t_mst_goods_brand tmgb ON tmgb.brand_id = tmgs.brand_id
  673. left join dkic_b.t_mst_unit as tmgu on toi.unit_id = tmgu.unit_id
  674. left join dkic_b.t_mst_unit as tmgus on toi.sub_unit_id = tmgus.unit_id
  675. WHERE
  676. toi.order_id = T.order_id
  677. ) item
  678. ) AS "orderItemResponseList"
  679. FROM
  680. dkic_b.t_psi_order
  681. AS T LEFT JOIN dkic_b.t_psi_order_item toi ON toi.order_id = T.order_id
  682. LEFT JOIN dkic_b.t_mst_sale_channel tmsc ON T.sales_channel = tmsc.channel_id
  683. LEFT JOIN dkic_b.t_mst_org tmo ON T.org_id = tmo.org_id
  684. LEFT JOIN dkic_b.t_mst_staff tms ON T.staff_id = tms.staff_id
  685. LEFT JOIN dkic_b.t_mst_staff AS makestaff ON T.make_staff = makestaff.staff_id
  686. LEFT JOIN dkic_b.t_mst_customer tmc ON T.cus_id = tmc.cus_id
  687. LEFT JOIN dkic_b.t_mst_dictionary_data tmdd ON tmc.cus_from = tmdd.data_id
  688. LEFT JOIN sys.t_data_kind AS tdk1 ON T.order_type = tdk1.kind_code
  689. LEFT JOIN sys.t_data_kind AS tdk2 ON T.order_status = tdk2.kind_code
  690. LEFT JOIN sys.t_data_kind AS tdk3 ON T.out_status = tdk3.kind_code
  691. <include refid="Condition"/>
  692. order by t.op_create_time desc
  693. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  694. limit #{end} offset #{start}
  695. </if>
  696. </select>
  697. <!-- 查询表t_psi_order,(条件查询)个数 -->
  698. <select id="countByCond" resultType="Long">
  699. SELECT
  700. count(1)
  701. FROM dkic_b.t_psi_order as t
  702. left join dkic_b.t_mst_customer tmc on t.cus_id = tmc.cus_id
  703. left join dkic_b.t_psi_order_item toi on toi.order_id = t.order_id
  704. <include refid="Condition"/>
  705. </select>
  706. <!-- 根据主键查询表t_psi_order的一行数据 -->
  707. <select id="selectById" resultMap="BaseResultMapResponse">
  708. SELECT t.order_id,
  709. t.order_no,
  710. t.order_type,
  711. sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "orderTypeName",
  712. t.org_id,
  713. tmo.org_name as "orgName",
  714. t.staff_id,
  715. tms.staff_name as "staffName",
  716. t.cus_id,
  717. tmc.cus_code as "cusCode",
  718. tmc.cus_name as "cusName",
  719. tmc.cus_phone as "cusPhone",
  720. tmc.cus_from as "cusFrom",
  721. tmdd.data_value as "cusFromName",
  722. t.address_area,
  723. t.address_name,
  724. t.address_no,
  725. t.address_gcj02,
  726. t.address_full,
  727. t.contact_name,
  728. t.contact_phone,
  729. t.sales_channel,
  730. tmsc.channel_name as "channelName",
  731. t.delivery_date,
  732. sys.f_remove_zero(t.sum_quantity) as sum_quantity,
  733. t.sum_standard,
  734. t.sum_amount,
  735. t.sale_discount,
  736. t.order_status,
  737. sys.f_get_name_i18n(tdk2.kind_name_i18n, #{i18n}) as "orderStatusName",
  738. t.out_status,
  739. sys.f_get_name_i18n(tdk3.kind_name_i18n, #{i18n}) as "outStatusName",
  740. sys.f_remove_zero(t.outing_qty) as outing_qty,
  741. t.outing_amt,
  742. sys.f_remove_zero(t.out_qty) as out_qty,
  743. t.out_amt,
  744. sys.f_remove_zero(t.return_qty) as return_qty,
  745. t.return_amt,
  746. t.amt_receivable,
  747. t.amt_handle,
  748. t.amt_residue,
  749. t.remarks,
  750. t.annex_paths,
  751. t.make_staff,
  752. makestaff.staff_name as "makeStaffName",
  753. t.make_time,
  754. t.cp_id
  755. FROM dkic_b.t_psi_order as t
  756. left join dkic_b.t_mst_sale_channel tmsc on t.sales_channel = tmsc.channel_id
  757. left join dkic_b.t_mst_org tmo on t.org_id = tmo.org_id
  758. left join dkic_b.t_mst_staff tms on t.staff_id = tms.staff_id
  759. left join dkic_b.t_mst_staff as makestaff on t.make_staff = makestaff.staff_id
  760. left join dkic_b.t_mst_customer tmc on t.cus_id = tmc.cus_id
  761. left join dkic_b.t_mst_dictionary_data tmdd on tmc.cus_from = tmdd.data_id
  762. left join sys.t_data_kind as tdk1 on t.order_type = tdk1.kind_code
  763. left join sys.t_data_kind as tdk2 on t.order_status = tdk2.kind_code
  764. left join sys.t_data_kind as tdk3 on t.out_status = tdk3.kind_code
  765. WHERE t.order_id = #{id}::uuid
  766. </select>
  767. <!-- 根据主键锁定表t_psi_order的一行数据 -->
  768. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  769. SELECT
  770. <include refid="Base_Column_List"/>
  771. FROM dkic_b.t_psi_order
  772. WHERE order_id = #{id}::uuid
  773. for update
  774. </select>
  775. <!-- 根据主键锁定表t_psi_order的多行数据 -->
  776. <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
  777. SELECT
  778. <include refid="Base_Column_List"/>
  779. FROM dkic_b.t_psi_order
  780. <include refid="idsForeach"/>
  781. for update
  782. </select>
  783. <insert id="insertBatch">
  784. insert into dkic_b.t_psi_order
  785. (
  786. <trim suffixOverrides=",">
  787. order_no,
  788. order_type,
  789. org_id,
  790. staff_id,
  791. cus_id,
  792. address_area,
  793. address_name,
  794. address_no,
  795. address_gcj02,
  796. address_full,
  797. contact_name,
  798. contact_phone,
  799. sales_channel,
  800. delivery_date,
  801. sum_quantity,
  802. sum_standard,
  803. sum_amount,
  804. sale_discount,
  805. order_status,
  806. out_status,
  807. outing_qty,
  808. outing_amt,
  809. out_qty,
  810. out_amt,
  811. return_qty,
  812. return_amt,
  813. amt_receivable,
  814. amt_handle,
  815. amt_residue,
  816. remarks,
  817. annex_paths,
  818. make_staff,
  819. make_time,
  820. cp_id,
  821. op_app_code,
  822. fact_amt,
  823. disc_amt,
  824. discount,
  825. flg_auto_handle,
  826. flg_handle_setting,
  827. </trim>
  828. )
  829. values
  830. <foreach collection="list" index="index" item="item" separator=",">
  831. (
  832. <trim suffixOverrides=",">
  833. #{item.orderNo},
  834. #{item.orderType},
  835. #{item.orgId}::uuid,
  836. #{item.staffId}::uuid,
  837. #{item.cusId}::uuid,
  838. #{item.addressArea},
  839. #{item.addressName},
  840. #{item.addressNo},
  841. #{item.addressGcj02},
  842. #{item.addressFull},
  843. #{item.contactName},
  844. #{item.contactPhone},
  845. #{item.salesChannel}::uuid,
  846. #{item.deliveryDate},
  847. #{item.sumQuantity},
  848. #{item.sumStandard},
  849. #{item.sumAmount},
  850. #{item.saleDiscount},
  851. #{item.orderStatus},
  852. #{item.outStatus},
  853. #{item.outingQty},
  854. #{item.outingAmt},
  855. #{item.outQty},
  856. #{item.outAmt},
  857. #{item.returnQty},
  858. #{item.returnAmt},
  859. #{item.amtReceivable},
  860. #{item.amtHandle},
  861. #{item.amtResidue},
  862. #{item.remarks},
  863. #{item.annexPaths},
  864. #{item.makeStaff}::uuid,
  865. #{item.makeTime},
  866. #{item.cpId},
  867. #{item.opAppCode},
  868. #{item.factAmt},
  869. #{item.discAmt},
  870. #{item.discount},
  871. #{item.flgAutoHandle},
  872. #{item.flgHandleSetting},
  873. </trim>
  874. )
  875. </foreach>
  876. </insert>
  877. <!-- 根据id修改-->
  878. <update id="updateById" parameterType="com.dk.mdm.model.pojo.sale.Order">
  879. update dkic_b.t_psi_order
  880. <set>
  881. <if test=" et!=null and et.orderType != null">
  882. order_type =#{et.orderType,jdbcType=VARCHAR},
  883. </if>
  884. <if test=" et!=null and et.orgId != null">
  885. org_id =#{et.orgId,typeHandler=UuidTypeHandler},
  886. </if>
  887. <if test=" et!=null and et.staffId != null">
  888. staff_id =#{et.staffId,typeHandler=UuidTypeHandler},
  889. </if>
  890. <if test=" et!=null and et.cusId != null">
  891. cus_id =#{et.cusId,typeHandler=UuidTypeHandler},
  892. </if>
  893. <if test=" et!=null and et.addressArea != null">
  894. address_area =#{et.addressArea,typeHandler=JsonTypeHandler},
  895. </if>
  896. <if test=" et!=null and et.addressName != null">
  897. address_name =#{et.addressName,jdbcType=VARCHAR},
  898. </if>
  899. <if test=" et!=null and et.addressNo != null">
  900. address_no =#{et.addressNo,jdbcType=VARCHAR},
  901. </if>
  902. <if test=" et!=null and et.addressGcj02 != null">
  903. address_gcj02 =#{et.addressGcj02,typeHandler=JsonTypeHandler},
  904. </if>
  905. <if test=" et!=null and et.addressFull != null">
  906. address_full =#{et.addressFull,jdbcType=VARCHAR},
  907. </if>
  908. <if test=" et!=null and et.contactName != null">
  909. contact_name =#{et.contactName,jdbcType=VARCHAR},
  910. </if>
  911. <if test=" et!=null and et.contactPhone != null">
  912. contact_phone =#{et.contactPhone,jdbcType=VARCHAR},
  913. </if>
  914. <if test=" et!=null and et.salesChannel != null">
  915. sales_channel =#{et.salesChannel,jdbcType=OTHER},
  916. </if>
  917. <if test=" et!=null and et.deliveryDate != null">
  918. delivery_date =#{et.deliveryDate,jdbcType=DATE},
  919. </if>
  920. <if test=" et!=null and et.sumQuantity != null">
  921. sum_quantity =#{et.sumQuantity,jdbcType=NUMERIC},
  922. </if>
  923. <if test=" et!=null and et.sumStandard != null">
  924. sum_standard =#{et.sumStandard,jdbcType=NUMERIC},
  925. </if>
  926. <if test=" et!=null and et.sumAmount != null">
  927. sum_amount =#{et.sumAmount,jdbcType=NUMERIC},
  928. </if>
  929. <if test=" et!=null and et.saleDiscount != null">
  930. sale_discount =#{et.saleDiscount,jdbcType=NUMERIC},
  931. </if>
  932. <if test=" et!=null and et.orderStatus != null">
  933. order_status =#{et.orderStatus,jdbcType=VARCHAR},
  934. </if>
  935. <if test=" et!=null and et.outStatus != null">
  936. out_status =#{et.outStatus,jdbcType=VARCHAR},
  937. </if>
  938. <if test=" et!=null and et.outingQty != null">
  939. outing_qty = outing_qty + #{et.outingQty,jdbcType=NUMERIC},
  940. </if>
  941. <if test=" et!=null and et.outingAmt != null">
  942. outing_amt = outing_amt + #{et.outingAmt,jdbcType=NUMERIC},
  943. </if>
  944. <if test=" et!=null and et.outQty != null">
  945. out_qty =out_qty + #{et.outQty,jdbcType=NUMERIC},
  946. </if>
  947. <if test=" et!=null and et.outAmt != null">
  948. out_amt = out_amt + #{et.outAmt,jdbcType=NUMERIC},
  949. </if>
  950. <if test=" et!=null and et.returnQty != null">
  951. return_qty =#{et.returnQty,jdbcType=NUMERIC},
  952. </if>
  953. <if test=" et!=null and et.returnAmt != null">
  954. return_amt =#{et.returnAmt,jdbcType=NUMERIC},
  955. </if>
  956. <if test=" et!=null and et.amtReceivable != null">
  957. amt_receivable =#{et.amtReceivable,jdbcType=NUMERIC},
  958. </if>
  959. <if test=" et!=null and et.amtHandle != null">
  960. amt_handle =#{et.amtHandle,jdbcType=NUMERIC},
  961. </if>
  962. <if test=" et!=null and et.amtResidue != null">
  963. amt_residue =#{et.amtResidue,jdbcType=NUMERIC},
  964. </if>
  965. <if test=" et!=null and et.remarks != null">
  966. remarks =#{et.remarks,jdbcType=VARCHAR},
  967. </if>
  968. <if test=" et!=null and et.annexPaths != null">
  969. annex_paths =#{et..annexPaths,typeHandler=JsonTypeHandler},
  970. </if>
  971. <if test=" et!=null and et.makeStaff != null">
  972. make_staff =#{et.makeStaff,jdbcType=OTHER},
  973. </if>
  974. <if test=" et!=null and et.makeTime != null">
  975. make_time =#{et.makeTime,jdbcType=TIMESTAMP},
  976. </if>
  977. <if test=" et!=null and et.flgValid != null">
  978. flg_valid =#{et.flgValid,jdbcType=BOOLEAN},
  979. </if>
  980. <if test=" et!=null and et.cpId != null">
  981. cp_id =#{et.cpId,jdbcType=INTEGER},
  982. </if>
  983. <if test=" et!=null and et.factAmt != null">
  984. fact_amt =#{et.factAmt,jdbcType=NUMERIC},
  985. </if>
  986. <if test=" et!=null and et.discAmt != null">
  987. disc_amt =#{et.discAmt,jdbcType=NUMERIC},
  988. </if>
  989. <if test=" et!=null and et.discount != null">
  990. discount =#{et.discount,jdbcType=NUMERIC},
  991. </if>
  992. <if test=" et!=null and et.flgAutoHandle != null">
  993. flg_auto_handle =#{et.flgAutoHandle,jdbcType=BOOLEAN},
  994. </if>
  995. <if test=" et!=null and et.flgHandleSetting != null">
  996. flg_handle_setting =#{et.flgHandleSetting,jdbcType=BOOLEAN},
  997. </if>
  998. </set>
  999. where order_id =#{et.orderId,typeHandler=UuidTypeHandler}
  1000. and sum_quantity >= (out_qty + outing_qty)
  1001. </update>
  1002. <!-- 小程序 条件查询(总单带明细)-->
  1003. <select id="selectByCondDetail" resultMap="BaseResultMapDetailResponse">
  1004. SELECT
  1005. <include refid="Base_Column_List_Detail_Join"/>,
  1006. tmc.cus_code,tmc.cus_name, tmc.cus_phone, tmc.address_area, tmc.address_name, tmc.address_no,
  1007. tmc.address_gcj02, tmc.address_full, tmc.contact_name, tmc.contact_phone, tmc.cus_from, tmc.channel_id,
  1008. tmsc.channel_name as "channelName",
  1009. <include refid="Base_Column_List_Item_Response_Detail_Join"/>
  1010. FROM dkic_b.t_psi_order as t
  1011. left join dkic_b.t_mst_customer tmc on tmc.cus_id = t.cus_id
  1012. left join dkic_b.t_psi_order_item toi on toi.order_id = t.order_id
  1013. inner join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = toi.sku_id
  1014. left join dkic_b.t_mst_goods_brand tmgb on tmgb.brand_id = tmgs.brand_id
  1015. left join dkic_b.t_mst_org tmo on t.org_id = tmo.org_id
  1016. left join dkic_b.t_mst_sale_channel tmsc on t.sales_channel = tmsc.channel_id
  1017. left join dkic_b.t_mst_staff tms on t.staff_id = tms.staff_id
  1018. left join(SELECT T.*
  1019. FROM (select tpi.inv_id,
  1020. tpi.wh_id,
  1021. tpi.inv_qty,
  1022. tpi.usable_qty,
  1023. tpi.sku_id,
  1024. tpi.non_std_code,
  1025. tpi.cp_id,
  1026. tmw.wh_name,
  1027. rank()
  1028. over (partition by tpi.cp_id,tpi.sku_id,tpi.non_std_code order by tpi.inv_id) as RK
  1029. from dkic_b.t_psi_inventory as tpi
  1030. left join dkic_b.t_mst_warehouse as tmw on tmw.wh_id = tpi.wh_id) T
  1031. WHERE T.RK = 1) as i
  1032. on i.sku_id = toi.sku_id and i.non_std_code = toi.non_std_code and i.cp_id = toi.cp_id
  1033. <include refid="Condition"/>
  1034. order by t.op_create_time desc
  1035. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  1036. limit #{end} offset #{start}
  1037. </if>
  1038. </select>
  1039. <!--小程序-->
  1040. <select id="countByCondDetail" resultType="Long">
  1041. SELECT
  1042. count(1)
  1043. FROM dkic_b.t_psi_order as t
  1044. <include refid="Condition"/>
  1045. </select>
  1046. <!--修改退货信息 -->
  1047. <update id="updateReturnMessage" parameterType="com.dk.mdm.model.pojo.sale.Order">
  1048. update dkic_b.t_psi_order
  1049. <set>
  1050. <if test=" returnQty != null">
  1051. return_qty = return_qty + #{returnQty,jdbcType=NUMERIC},
  1052. </if>
  1053. <if test=" returnAmt != null">
  1054. return_amt = return_amt + #{returnAmt,jdbcType=NUMERIC},
  1055. </if>
  1056. </set>
  1057. where order_id = #{orderId,typeHandler=UuidTypeHandler}
  1058. and out_qty >= return_qty
  1059. </update>
  1060. <!--销售跟踪报表 -->
  1061. <select id="getOrderTrackReport" resultType="java.util.Map">
  1062. SELECT *
  1063. FROM dkic_b.f_query_ord_for_track(#{ordId}::uuid,#{i18n})
  1064. </select>
  1065. <!-- 获取实收金额 -->
  1066. <select id="getFactReceipt" resultType="java.util.Map">
  1067. SELECT COALESCE(sum(t.amt_handle - t.amt_waive), 0) as "sumFactReceipt"
  1068. FROM dkic_b.t_mac_account_item as t
  1069. inner join dkic_b.t_psi_outbound as tpo on tpo.receivable_id = t.item_id
  1070. where t.flg_valid
  1071. and t.acc_item_type = '账款类型-应收'
  1072. and tpo.from_id = #{id}::uuid
  1073. </select>
  1074. </mapper>