OutboundMapper.xml 20 KB

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