OrderMapper.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  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, address_full, contact_name, contact_phone, sales_channel, delivery_date, sum_quantity, sum_standard, sum_amount, sale_discount, order_status, out_status, outing_qty, outing_amt, out_qty, out_amt, return_qty, return_amt, amt_receivable, amt_handle, amt_residue, remarks, annex_paths, make_staff, make_time, flg_valid, cp_id, op_create_time, op_create_user_id, op_update_time, op_update_user_id, op_app_code, op_timestamp, op_db_user
  8. </sql>
  9. <!-- 通用查询映射结果 -->
  10. <resultMap id="BaseResultMap" type="com.dk.mdm.model.response.sale.OrderResponse">
  11. <id column="order_id" property="orderId"/>
  12. <result column="order_no" property="orderNo"/>
  13. <result column="order_type" property="orderType"/>
  14. <result column="org_id" property="orgId" typeHandler="UuidTypeHandler"/>
  15. <result column="staff_id" property="staffId" typeHandler="UuidTypeHandler"/>
  16. <result column="cus_id" property="cusId" typeHandler="UuidTypeHandler"/>
  17. <result column="address_area" property="addressArea" typeHandler="JsonTypeHandler"/>
  18. <result column="address_name" property="addressName"/>
  19. <result column="address_no" property="addressNo"/>
  20. <result column="address_gcj02" property="addressGcj02" typeHandler="JsonTypeHandler"/>
  21. <result column="address_full" property="addressFull"/>
  22. <result column="contact_name" property="contactName"/>
  23. <result column="contact_phone" property="contactPhone"/>
  24. <result column="sales_channel" property="salesChannel" typeHandler="UuidTypeHandler"/>
  25. <result column="delivery_date" property="deliveryDate" typeHandler="TimestampTypeHandler"/>
  26. <result column="sum_quantity" property="sumQuantity"/>
  27. <result column="sum_standard" property="sumStandard"/>
  28. <result column="sum_amount" property="sumAmount"/>
  29. <result column="sale_discount" property="saleDiscount"/>
  30. <result column="order_status" property="orderStatus"/>
  31. <result column="out_status" property="outStatus"/>
  32. <result column="outing_qty" property="outingQty"/>
  33. <result column="outing_amt" property="outingAmt"/>
  34. <result column="out_qty" property="outQty"/>
  35. <result column="out_amt" property="outAmt"/>
  36. <result column="return_qty" property="returnQty"/>
  37. <result column="return_amt" property="returnAmt"/>
  38. <result column="amt_receivable" property="amtReceivable"/>
  39. <result column="amt_handle" property="amtHandle"/>
  40. <result column="amt_residue" property="amtResidue"/>
  41. <result column="remarks" property="remarks"/>
  42. <result column="annex_paths" property="annexPaths" typeHandler="JsonTypeHandler"/>
  43. <result column="make_staff" property="makeStaff" typeHandler="UuidTypeHandler"/>
  44. <result column="make_time" property="makeTime" typeHandler="TimestampTypeHandler"/>
  45. <result column="flg_valid" property="flgValid"/>
  46. <result column="cp_id" property="cpId"/>
  47. <result column="op_create_time" property="opCreateTime" typeHandler="TimestampTypeHandler"/>
  48. <result column="op_create_user_id" property="opCreateUserId" typeHandler="UuidTypeHandler"/>
  49. <result column="op_update_time" property="opUpdateTime" typeHandler="TimestampTypeHandler"/>
  50. <result column="op_update_user_id" property="opUpdateUserId" typeHandler="UuidTypeHandler"/>
  51. <result column="op_app_code" property="opAppCode"/>
  52. <result column="op_timestamp" property="opTimestamp" typeHandler="TimestampTypeHandler"/>
  53. <result column="op_db_user" property="opDbUser"/>
  54. </resultMap>
  55. <!-- 通用条件列 -->
  56. <sql id="Condition">
  57. <where>
  58. <if test="orderNo != null and orderNo != ''">
  59. AND tpo.order_no = #{orderNo}
  60. </if>
  61. <if test="orderType != null and orderType != ''">
  62. AND tpo.order_type = #{orderType}
  63. </if>
  64. <if test="orgId != null and orgId != ''">
  65. AND tpo.org_id = #{orgId}
  66. </if>
  67. <if test="staffId != null and staffId != ''">
  68. AND tpo.staff_id = #{staffId}
  69. </if>
  70. <if test="cusId != null and cusId != ''">
  71. AND tpo.cus_id = #{cusId}
  72. </if>
  73. <if test="addressArea != null and addressArea != ''">
  74. AND tpo.address_area = #{addressArea}
  75. </if>
  76. <if test="addressName != null and addressName != ''">
  77. AND tpo.address_name = #{addressName}
  78. </if>
  79. <if test="addressNo != null and addressNo != ''">
  80. AND tpo.address_no = #{addressNo}
  81. </if>
  82. <if test="addressGcj02 != null and addressGcj02 != ''">
  83. AND tpo.address_gcj02 = #{addressGcj02}
  84. </if>
  85. <if test="addressFull != null and addressFull != ''">
  86. AND tpo.address_full = #{addressFull}
  87. </if>
  88. <if test="contactName != null and contactName != ''">
  89. AND tpo.contact_name = #{contactName}
  90. </if>
  91. <if test="contactPhone != null and contactPhone != ''">
  92. AND tpo.contact_phone = #{contactPhone}
  93. </if>
  94. <if test="salesChannel != null and salesChannel != ''">
  95. AND tpo.sales_channel = #{salesChannel}
  96. </if>
  97. <if test="deliveryDate != null">
  98. AND tpo.delivery_date = #{deliveryDate}
  99. </if>
  100. <if test="sumQuantity != null">
  101. AND tpo.sum_quantity = #{sumQuantity}
  102. </if>
  103. <if test="sumStandard != null">
  104. AND tpo.sum_standard = #{sumStandard}
  105. </if>
  106. <if test="sumAmount != null">
  107. AND tpo.sum_amount = #{sumAmount}
  108. </if>
  109. <if test="saleDiscount != null">
  110. AND tpo.sale_discount = #{saleDiscount}
  111. </if>
  112. <if test="orderStatus != null and orderStatus != ''">
  113. AND tpo.order_status = #{orderStatus}
  114. </if>
  115. <if test="outStatus != null and outStatus != ''">
  116. AND tpo.out_status = #{outStatus}
  117. </if>
  118. <if test="outingQty != null">
  119. AND tpo.outing_qty = #{outingQty}
  120. </if>
  121. <if test="outingAmt != null">
  122. AND tpo.outing_amt = #{outingAmt}
  123. </if>
  124. <if test="outQty != null">
  125. AND tpo.out_qty = #{outQty}
  126. </if>
  127. <if test="outAmt != null">
  128. AND tpo.out_amt = #{outAmt}
  129. </if>
  130. <if test="returnQty != null">
  131. AND tpo.return_qty = #{returnQty}
  132. </if>
  133. <if test="returnAmt != null">
  134. AND tpo.return_amt = #{returnAmt}
  135. </if>
  136. <if test="amtReceivable != null">
  137. AND tpo.amt_receivable = #{amtReceivable}
  138. </if>
  139. <if test="amtHandle != null">
  140. AND tpo.amt_handle = #{amtHandle}
  141. </if>
  142. <if test="amtResidue != null">
  143. AND tpo.amt_residue = #{amtResidue}
  144. </if>
  145. <if test="remarks != null and remarks != ''">
  146. AND tpo.remarks = #{remarks}
  147. </if>
  148. <if test="annexPaths != null and annexPaths != ''">
  149. AND tpo.annex_paths = #{annexPaths}
  150. </if>
  151. <if test="makeStaff != null and makeStaff != ''">
  152. AND tpo.make_staff = #{makeStaff}
  153. </if>
  154. <if test="makeTime != null">
  155. AND tpo.make_time = #{makeTime}
  156. </if>
  157. <if test="flgValid != null">
  158. AND tpo.flg_valid = #{flgValid}
  159. </if>
  160. <if test="cpId != null">
  161. AND tpo.cp_id = #{cpId}
  162. </if>
  163. <if test="orgIdList != null and orgIdList.size() > 0">
  164. AND tpo.org_id =any(#{orgIdList, typeHandler=uuidListTypeHandler})
  165. </if>
  166. <if test="staffIdList != null and staffIdList.size() > 0">
  167. AND tpo.staff_id =any(#{staffIdList, typeHandler=uuidListTypeHandler})
  168. </if>
  169. <if test="outStatusList != null and outStatusList.size() > 0">
  170. AND tpo.out_status =any(#{outStatusList, typeHandler=StringListTypeHandler})
  171. </if>
  172. <if test="makeTimeStart != null and makeTimeEnd != null">
  173. AND tpo.make_time &gt;= #{makeTimeStart}::timestamp with time zone
  174. AND tpo.make_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
  175. </if>
  176. <if test="deliveryDateStart != null and deliveryDateEnd != null">
  177. AND tpo.delivery_date &gt;= #{deliveryDateStart}::timestamp with time zone
  178. AND tpo.delivery_date &lt; #{deliveryDateEnd}::timestamp with time zone + interval '1 day'
  179. </if>
  180. </where>
  181. </sql>
  182. <sql id="idsForeach">
  183. <!-- 根据主键orderId批量操作 -->
  184. WHERE order_id in
  185. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  186. #{item}
  187. </foreach>
  188. </sql>
  189. <!-- 查询表t_psi_order,(条件查询+分页)列表 -->
  190. <select id="selectByCond" resultMap="BaseResultMap">
  191. SELECT tpo.order_id,
  192. tpo.order_no,
  193. tpo.order_type,
  194. sys.f_get_name_i18n(tdk1.kind_name_i18n, 'zh_CN') as "orderTypeName",
  195. tpo.org_id,
  196. tmo.org_name as "orgName",
  197. tpo.staff_id,
  198. tms.staff_name as "staffName",
  199. tpo.cus_id,
  200. tmc.cus_code as "cusCode",
  201. tmc.cus_name as "cusName",
  202. tmc.cus_phone as "cusPhone",
  203. tmc.cus_from as "cusFrom",
  204. tmdd.data_value as "cusFromName",
  205. tpo.address_area,
  206. tpo.address_name,
  207. tpo.address_no,
  208. tpo.address_gcj02,
  209. tpo.address_full,
  210. tpo.contact_name,
  211. tpo.contact_phone,
  212. tpo.sales_channel,
  213. tmsc.channel_name as "channelName",
  214. tpo.delivery_date,
  215. tpo.sum_quantity,
  216. tpo.sum_standard,
  217. tpo.sum_amount,
  218. tpo.sale_discount,
  219. tpo.order_status,
  220. sys.f_get_name_i18n(tdk2.kind_name_i18n, 'zh_CN') as "orderStatusName",
  221. tpo.out_status,
  222. sys.f_get_name_i18n(tdk3.kind_name_i18n, 'zh_CN') as "outStatusName",
  223. tpo.outing_qty,
  224. tpo.outing_amt,
  225. tpo.out_qty,
  226. tpo.out_amt,
  227. tpo.return_qty,
  228. tpo.return_amt,
  229. tpo.amt_receivable,
  230. tpo.amt_handle,
  231. tpo.amt_residue,
  232. tpo.remarks,
  233. tpo.annex_paths,
  234. makestaff.staff_name as "makeStaffName",
  235. tpo.make_time,
  236. tpo.cp_id
  237. FROM dkic_b.t_psi_order as tpo
  238. left join dkic_b.t_mst_sale_channel tmsc on tpo.sales_channel = tmsc.channel_id
  239. left join dkic_b.t_mst_org tmo on tpo.org_id = tmo.org_id
  240. left join dkic_b.t_mst_staff tms on tpo.staff_id = tms.staff_id
  241. left join dkic_b.t_mst_staff as makestaff on tpo.make_staff = makestaff.staff_id
  242. left join dkic_b.t_mst_customer tmc on tpo.cus_id = tmc.cus_id
  243. left join dkic_b.t_mst_dictionary_data tmdd on tmc.cus_from = tmdd.data_id
  244. left join sys.t_data_kind as tdk1 on tpo.order_type = tdk1.kind_code
  245. left join sys.t_data_kind as tdk2 on tpo.order_status = tdk2.kind_code
  246. left join sys.t_data_kind as tdk3 on tpo.out_status = tdk3.kind_code
  247. <include refid="Condition"/>
  248. order by tpo.op_create_time desc
  249. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  250. limit #{end} offset #{start}
  251. </if>
  252. </select>
  253. <!-- 查询表t_psi_order,(条件查询)个数 -->
  254. <select id="countByCond" resultType="Long">
  255. SELECT
  256. count(1)
  257. FROM dkic_b.t_psi_order as tpo
  258. <include refid="Condition"/>
  259. </select>
  260. <!-- 根据主键查询表t_psi_order的一行数据 -->
  261. <select id="selectById" resultMap="BaseResultMap">
  262. SELECT tpo.order_id,
  263. tpo.order_no,
  264. tpo.order_type,
  265. sys.f_get_name_i18n(tdk1.kind_name_i18n, 'zh_CN') as "orderTypeName",
  266. tpo.org_id,
  267. tmo.org_name as "orgName",
  268. tpo.staff_id,
  269. tms.staff_name as "staffName",
  270. tpo.cus_id,
  271. tmc.cus_code as "cusCode",
  272. tmc.cus_name as "cusName",
  273. tmc.cus_phone as "cusPhone",
  274. tmc.cus_from as "cusFrom",
  275. tmdd.data_value as "cusFromName",
  276. tpo.address_area,
  277. tpo.address_name,
  278. tpo.address_no,
  279. tpo.address_gcj02,
  280. tpo.address_full,
  281. tpo.contact_name,
  282. tpo.contact_phone,
  283. tpo.sales_channel,
  284. tmsc.channel_name as "channelName",
  285. tpo.delivery_date,
  286. tpo.sum_quantity,
  287. tpo.sum_standard,
  288. tpo.sum_amount,
  289. tpo.sale_discount,
  290. tpo.order_status,
  291. sys.f_get_name_i18n(tdk2.kind_name_i18n, 'zh_CN') as "orderStatusName",
  292. tpo.out_status,
  293. sys.f_get_name_i18n(tdk3.kind_name_i18n, 'zh_CN') as "outStatusName",
  294. tpo.outing_qty,
  295. tpo.outing_amt,
  296. tpo.out_qty,
  297. tpo.out_amt,
  298. tpo.return_qty,
  299. tpo.return_amt,
  300. tpo.amt_receivable,
  301. tpo.amt_handle,
  302. tpo.amt_residue,
  303. tpo.remarks,
  304. tpo.annex_paths,
  305. makestaff.staff_name as "makeStaffName",
  306. tpo.make_time,
  307. tpo.cp_id
  308. FROM dkic_b.t_psi_order as tpo
  309. left join dkic_b.t_mst_sale_channel tmsc on tpo.sales_channel = tmsc.channel_id
  310. left join dkic_b.t_mst_org tmo on tpo.org_id = tmo.org_id
  311. left join dkic_b.t_mst_staff tms on tpo.staff_id = tms.staff_id
  312. left join dkic_b.t_mst_staff as makestaff on tpo.make_staff = makestaff.staff_id
  313. left join dkic_b.t_mst_customer tmc on tpo.cus_id = tmc.cus_id
  314. left join dkic_b.t_mst_dictionary_data tmdd on tmc.cus_from = tmdd.data_id
  315. left join sys.t_data_kind as tdk1 on tpo.order_type = tdk1.kind_code
  316. left join sys.t_data_kind as tdk2 on tpo.order_status = tdk2.kind_code
  317. left join sys.t_data_kind as tdk3 on tpo.out_status = tdk3.kind_code
  318. WHERE tpo.order_id = #{orderId}::uuid
  319. </select>
  320. <!-- 根据主键锁定表t_psi_order的一行数据 -->
  321. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  322. SELECT
  323. <include refid="Base_Column_List"/>
  324. FROM t_psi_order
  325. WHERE order_id = #{orderId}
  326. for update
  327. </select>
  328. <!-- 根据主键锁定表t_psi_order的多行数据 -->
  329. <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
  330. SELECT
  331. <include refid="Base_Column_List"/>
  332. FROM t_psi_order
  333. <include refid="idsForeach"/>
  334. for update
  335. </select>
  336. <insert id="insertBatch">
  337. insert into t_psi_order
  338. (
  339. <trim suffixOverrides=",">
  340. order_no,
  341. order_type,
  342. org_id,
  343. staff_id,
  344. cus_id,
  345. address_area,
  346. address_name,
  347. address_no,
  348. address_gcj02,
  349. address_full,
  350. contact_name,
  351. contact_phone,
  352. sales_channel,
  353. delivery_date,
  354. sum_quantity,
  355. sum_standard,
  356. sum_amount,
  357. sale_discount,
  358. order_status,
  359. out_status,
  360. outing_qty,
  361. outing_amt,
  362. out_qty,
  363. out_amt,
  364. return_qty,
  365. return_amt,
  366. amt_receivable,
  367. amt_handle,
  368. amt_residue,
  369. remarks,
  370. annex_paths,
  371. make_staff,
  372. make_time,
  373. cp_id,
  374. op_app_code,
  375. </trim>
  376. )
  377. values
  378. <foreach collection="list" index="index" item="item" separator=",">
  379. (
  380. <trim suffixOverrides=",">
  381. #{item.orderNo},
  382. #{item.orderType},
  383. #{item.orgId}::uuid,
  384. #{item.staffId}::uuid,
  385. #{item.cusId}::uuid,
  386. #{item.addressArea},
  387. #{item.addressName},
  388. #{item.addressNo},
  389. #{item.addressGcj02},
  390. #{item.addressFull},
  391. #{item.contactName},
  392. #{item.contactPhone},
  393. #{item.salesChannel}::uuid,
  394. #{item.deliveryDate},
  395. #{item.sumQuantity},
  396. #{item.sumStandard},
  397. #{item.sumAmount},
  398. #{item.saleDiscount},
  399. #{item.orderStatus},
  400. #{item.outStatus},
  401. #{item.outingQty},
  402. #{item.outingAmt},
  403. #{item.outQty},
  404. #{item.outAmt},
  405. #{item.returnQty},
  406. #{item.returnAmt},
  407. #{item.amtReceivable},
  408. #{item.amtHandle},
  409. #{item.amtResidue},
  410. #{item.remarks},
  411. #{item.annexPaths},
  412. #{item.makeStaff}::uuid,
  413. #{item.makeTime},
  414. #{item.cpId},
  415. #{item.opAppCode},
  416. </trim>
  417. )
  418. </foreach>
  419. </insert>
  420. </mapper>