OrderMapper.xml 22 KB

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