OutboundMapper.xml 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869
  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,
  8. out_status, outing_qty, outing_amt, out_qty, out_amt, return_qty, return_amt,
  9. out_date, remarks, annex_paths, make_staff, make_time, receivable_id,
  10. payable_id, flg_valid, cp_id,out_reason,flg_auto_handle,flg_handle_setting
  11. </sql>
  12. <sql id="Base_Column_List_Response">
  13. tpo.out_id, tpo.out_no, tpo.out_type, tpo.from_id, tpo.from_no, tpo.org_id, tpo.staff_id,
  14. tpo.cus_id, tpo.sup_id, tpo.out_status, tpo.outing_qty, tpo.outing_amt, tpo.out_qty, tpo.out_amt,
  15. tpo.return_qty, tpo.return_amt, tpo.out_date, tpo.remarks, tpo.annex_paths, tpo.make_staff,
  16. tpo.make_time, tpo.receivable_id, tpo.payable_id, tpo.flg_valid, tpo.cp_id,tpo.out_reason,
  17. tpo.flg_auto_handle,tpo.flg_handle_setting
  18. </sql>
  19. <!-- 通用查询映射结果 -->
  20. <resultMap id="BaseResultMap" type="com.dk.mdm.model.pojo.ivt.Outbound">
  21. <id column="out_id" property="outId"/>
  22. <result column="out_no" property="outNo"/>
  23. <result column="out_type" property="outType"/>
  24. <result column="from_id" property="fromId" typeHandler="UuidTypeHandler"/>
  25. <result column="from_no" property="fromNo"/>
  26. <result column="org_id" property="orgId" typeHandler="UuidTypeHandler"/>
  27. <result column="staff_id" property="staffId" typeHandler="UuidTypeHandler"/>
  28. <result column="cus_id" property="cusId" typeHandler="UuidTypeHandler"/>
  29. <result column="sup_id" property="supId" typeHandler="UuidTypeHandler"/>
  30. <result column="out_status" property="outStatus"/>
  31. <result column="outing_qty" property="outingQty"/>
  32. <result column="outing_amt" property="outingAmt"/>
  33. <result column="out_qty" property="outQty"/>
  34. <result column="out_amt" property="outAmt"/>
  35. <result column="return_qty" property="returnQty"/>
  36. <result column="return_amt" property="returnAmt"/>
  37. <result column="out_date" property="outDate" typeHandler="TimestampTypeHandler"/>
  38. <result column="remarks" property="remarks"/>
  39. <result column="annex_paths" property="annexPaths" typeHandler="JsonTypeHandler"/>
  40. <result column="make_staff" property="makeStaff" typeHandler="UuidTypeHandler"/>
  41. <result column="make_time" property="makeTime" typeHandler="TimestampTypeHandler"/>
  42. <result column="receivable_id" property="receivableId" typeHandler="UuidTypeHandler"/>
  43. <result column="payable_id" property="payableId" typeHandler="UuidTypeHandler"/>
  44. <result column="flg_valid" property="flgValid"/>
  45. <result column="cp_id" property="cpId"/>
  46. <result column="op_create_time" property="opCreateTime" typeHandler="TimestampTypeHandler"/>
  47. <result column="op_create_user_id" property="opCreateUserId" typeHandler="UuidTypeHandler"/>
  48. <result column="op_update_time" property="opUpdateTime" typeHandler="TimestampTypeHandler"/>
  49. <result column="op_update_user_id" property="opUpdateUserId" typeHandler="UuidTypeHandler"/>
  50. <result column="op_app_code" property="opAppCode"/>
  51. <result column="op_timestamp" property="opTimestamp" typeHandler="TimestampTypeHandler"/>
  52. <result column="op_db_user" property="opDbUser"/>
  53. <result column="out_reason" property="outReason" typeHandler="UuidTypeHandler"/>
  54. <result column="flg_auto_handle" property="flgAutoHandle"/>
  55. <result column="flg_handle_setting" property="flgHandleSetting"/>
  56. </resultMap>
  57. <!-- 通用查询映射结果 -->
  58. <resultMap id="BaseResultMapResponse" type="com.dk.mdm.model.response.ivt.OutboundResponse">
  59. <id column="out_id" property="outId"/>
  60. <result column="out_no" property="outNo"/>
  61. <result column="out_type" property="outType"/>
  62. <result column="from_id" property="fromId" typeHandler="UuidTypeHandler"/>
  63. <result column="from_no" property="fromNo"/>
  64. <result column="org_id" property="orgId" typeHandler="UuidTypeHandler"/>
  65. <result column="staff_id" property="staffId" typeHandler="UuidTypeHandler"/>
  66. <result column="cus_id" property="cusId" typeHandler="UuidTypeHandler"/>
  67. <result column="sup_id" property="supId" typeHandler="UuidTypeHandler"/>
  68. <result column="out_status" property="outStatus"/>
  69. <result column="outing_qty" property="outingQty"/>
  70. <result column="outing_amt" property="outingAmt"/>
  71. <result column="out_qty" property="outQty"/>
  72. <result column="out_amt" property="outAmt"/>
  73. <result column="return_qty" property="returnQty"/>
  74. <result column="return_amt" property="returnAmt"/>
  75. <result column="out_date" property="outDate" typeHandler="TimestampTypeHandler"/>
  76. <result column="remarks" property="remarks"/>
  77. <result column="annex_paths" property="annexPaths" typeHandler="JsonTypeHandler"/>
  78. <result column="make_staff" property="makeStaff" typeHandler="UuidTypeHandler"/>
  79. <result column="make_time" property="makeTime" typeHandler="TimestampTypeHandler"/>
  80. <result column="receivable_id" property="receivableId" typeHandler="UuidTypeHandler"/>
  81. <result column="payable_id" property="payableId" typeHandler="UuidTypeHandler"/>
  82. <result column="flg_valid" property="flgValid"/>
  83. <result column="cp_id" property="cpId"/>
  84. <result column="flg_auto_handle" property="flgAutoHandle"/>
  85. <result column="flg_handle_setting" property="flgHandleSetting"/>
  86. <!-- <result column="org_name" property="orgName"/>-->
  87. <!-- <result column="staff_name" property="staffName"/>-->
  88. <result column="cusCode" property="cusCode"/>
  89. <result column="cusName" property="cusName"/>
  90. <result column="cusPhone" property="cusPhone"/>
  91. <result column="contact_phone" property="contactPhone"/>
  92. <result column="contact_name" property="contactName"/>
  93. <result column="address_area" property="addressArea" typeHandler="JsonTypeHandler"/>
  94. <result column="address_name" property="addressName"/>
  95. <result column="address_no" property="addressNo"/>
  96. <result column="address_gcj02" property="addressGcj02" typeHandler="JsonTypeHandler"/>
  97. <result column="addressFull" property="addressFull"/>
  98. <result column="channel_name" property="channelName"/>
  99. <result column="cus_from_name" property="cusFromName"/>
  100. <result column="out_reason" property="outReason" typeHandler="UuidTypeHandler"/>
  101. <result column="out_reason_name" property="outReasonName" />
  102. </resultMap>
  103. <!-- 通用条件列 -->
  104. <sql id="Condition">
  105. <where>
  106. <if test="outNo != null and outNo != ''">
  107. AND t.out_no LIKE concat('%',my_ex.likequery(#{outNo}),'%')
  108. </if>
  109. <if test="outType != null and outType != ''">
  110. AND t.out_type = #{outType}
  111. </if>
  112. <if test="outTypeList != null and outTypeList.size()>0">
  113. AND t.out_type =any(#{outTypeList,typeHandler=StringListTypeHandler})
  114. </if>
  115. <if test="outReasonList != null and outReasonList.size()>0">
  116. AND t.out_reason =any(#{outReasonList,typeHandler=UuidListTypeHandler})
  117. </if>
  118. <if test="searchText !=null and searchText != ''">
  119. AND (
  120. t.out_no LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  121. or t.from_no LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  122. or tmc.cus_phone LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  123. or tmc.cus_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  124. or tmo.org_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  125. or tmp.sup_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  126. or tms.staff_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  127. )
  128. </if>
  129. <if test="orgName != null and orgName != ''">
  130. AND tmo.org_name LIKE concat('%',my_ex.likequery(#{orgName}),'%')
  131. </if>
  132. <if test="supName != null and supName != ''">
  133. AND tmp.sup_name LIKE concat('%',my_ex.likequery(#{supName}),'%')
  134. </if>
  135. <if test="staffName != null and staffName != ''">
  136. AND tms.staff_name LIKE concat('%',my_ex.likequery(#{staffName}),'%')
  137. </if>
  138. <if test="fromId != null and fromId != ''">
  139. AND t.from_id = #{fromId}
  140. </if>
  141. <if test="fromNo != null and fromNo != ''">
  142. AND t.from_no = #{fromNo}
  143. </if>
  144. <if test="orgId != null and orgId != ''">
  145. AND t.org_id = #{orgId}
  146. </if>
  147. <if test="staffId != null and staffId != ''">
  148. AND t.staff_id = #{staffId}
  149. </if>
  150. <if test="cusId != null and cusId != ''">
  151. AND t.cus_id = #{cusId}
  152. </if>
  153. <if test="supId != null and supId != ''">
  154. AND t.sup_id = #{supId}
  155. </if>
  156. <if test="outStatus != null and outStatus != ''">
  157. AND t.out_status = #{outStatus}
  158. </if>
  159. <if test="outingQty != null">
  160. AND t.outing_qty = #{outingQty}
  161. </if>
  162. <if test="outingAmt != null">
  163. AND t.outing_amt = #{outingAmt}
  164. </if>
  165. <if test="outQty != null">
  166. AND t.out_qty = #{outQty}
  167. </if>
  168. <if test="outAmt != null">
  169. AND t.out_amt = #{outAmt}
  170. </if>
  171. <if test="returnQty != null">
  172. AND t.return_qty = #{returnQty}
  173. </if>
  174. <if test="returnAmt != null">
  175. AND t.return_amt = #{returnAmt}
  176. </if>
  177. <if test="remarks != null and remarks != ''">
  178. AND t.remarks = #{remarks}
  179. </if>
  180. <if test="annexPaths != null and annexPaths != ''">
  181. AND t.annex_paths = #{annexPaths}
  182. </if>
  183. <if test="makeStaff != null and makeStaff != ''">
  184. AND t.make_staff = #{makeStaff}
  185. </if>
  186. <if test="receivableId != null and receivableId != ''">
  187. AND t.receivable_id = #{receivableId}
  188. </if>
  189. <if test="payableId != null and payableId != ''">
  190. AND t.payable_id = #{payableId}
  191. </if>
  192. <if test="cpId != null">
  193. AND t.cp_id = #{cpId}
  194. </if>
  195. <if test="orderNo != null and orderNo != ''">
  196. AND t.from_no LIKE concat('%',my_ex.likequery(#{orderNo}),'%')
  197. </if>
  198. <if test="cusPhone != null and cusPhone != ''">
  199. AND tmc.cus_phone LIKE concat('%',my_ex.likequery(#{cusPhone}),'%')
  200. </if>
  201. <if test="cusName != null and cusName != ''">
  202. AND tmc.cus_name LIKE concat('%',my_ex.likequery(#{cusName}),'%')
  203. </if>
  204. <if test="orgIdList != null and orgIdList.size() > 0">
  205. AND t.org_id =any(#{orgIdList, typeHandler=uuidListTypeHandler})
  206. </if>
  207. <if test="staffIdList != null and staffIdList.size() > 0">
  208. AND t.staff_id =any(#{staffIdList, typeHandler=uuidListTypeHandler})
  209. </if>
  210. <if test="outStatusList != null and outStatusList.size() > 0">
  211. AND t.out_status =any(#{outStatusList, typeHandler=StringListTypeHandler})
  212. </if>
  213. <if test="outDateStart != null and outDateEnd != null">
  214. AND t.out_date &gt;= #{outDateStart}::timestamp with time zone
  215. AND t.out_date &lt; #{outDateEnd}::timestamp with time zone + interval '1 day'
  216. </if>
  217. <if test="makeTimeStart != null and makeTimeEnd != null">
  218. AND t.make_time &gt;= #{makeTimeStart}::timestamp with time zone
  219. AND t.make_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
  220. </if>
  221. <if test="flgValidList != null and flgValidList.size()>0">
  222. AND t.flg_valid =any(#{flgValidList, typeHandler=BooleanListTypeHandler})
  223. </if>
  224. </where>
  225. </sql>
  226. <sql id="idsForeach">
  227. <!-- 根据主键outId批量操作 -->
  228. WHERE out_id in
  229. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  230. #{item}
  231. </foreach>
  232. </sql>
  233. <!-- 查询表dkic_b.t_psi_outbound,(条件查询+分页)列表 -->
  234. <select id="selectByCond" resultMap="BaseResultMapResponse">
  235. SELECT t.out_id,
  236. t.out_no,
  237. t.out_type,
  238. t.from_id,
  239. t.from_no,
  240. t.from_no as "biznisNo",
  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. tmc.contact_phone as "contactPhone",
  251. tmc.address_full as "addressFull",
  252. tmdd.data_value as cus_from_name,
  253. t.sup_id,
  254. tmp.sup_name AS "supplierName",
  255. t.out_status,
  256. sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "outStatusName",
  257. sys.f_get_name_i18n(tdktype.kind_name_i18n, #{i18n}) AS "outTypeName",
  258. t.outing_qty,
  259. t.outing_amt,
  260. t.out_qty,
  261. t.out_amt,
  262. t.return_qty,
  263. t.return_amt,
  264. t.out_date,
  265. t.remarks,
  266. t.annex_paths,
  267. t.make_staff,
  268. makestaff.staff_name as "makeStaffName",
  269. t.make_time,
  270. t.receivable_id,
  271. t.payable_id,
  272. t.cp_id,
  273. t.flg_valid,
  274. tmd.data_value as out_reason_name
  275. FROM dkic_b.t_psi_outbound as t
  276. left join dkic_b.t_mst_org tmo on tmo.org_id = t.org_id
  277. Left join dkic_b.t_mst_supplier tmp on tmp.sup_id = t.sup_id
  278. left join dkic_b.t_mst_staff tms on tms.staff_id = t.staff_id
  279. left join dkic_b.t_mst_staff as makestaff on makestaff.staff_id = t.make_staff
  280. left join dkic_b.t_mst_customer tmc on tmc.cus_id = t.cus_id
  281. left join dkic_b.t_mst_dictionary_data tmdd on tmdd.data_id = tmc.cus_from
  282. left join sys.t_data_kind as tdk1 on tdk1.kind_code = t.out_status
  283. LEFT JOIN sys.t_data_kind tdktype ON tdktype.kind_code = t.out_type
  284. left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = t.out_reason
  285. <include refid="Condition"/>
  286. order by t.make_time desc
  287. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  288. limit #{end} offset #{start}
  289. </if>
  290. </select>
  291. <!-- 查询表dkic_b.t_psi_outbound,(条件查询)个数 -->
  292. <select id="countByCond" resultType="Long">
  293. SELECT
  294. count(1)
  295. FROM dkic_b.t_psi_outbound as t
  296. left join dkic_b.t_mst_org tmo on tmo.org_id = t.org_id
  297. Left join dkic_b.t_mst_supplier tmp on tmp.sup_id = t.sup_id
  298. left join dkic_b.t_mst_staff tms on tms.staff_id = t.staff_id
  299. left join dkic_b.t_mst_staff as makestaff on makestaff.staff_id = t.make_staff
  300. left join dkic_b.t_mst_customer tmc on tmc.cus_id = t.cus_id
  301. left join dkic_b.t_mst_dictionary_data tmdd on tmdd.data_id = tmc.cus_from
  302. left join sys.t_data_kind as tdk1 on tdk1.kind_code = t.out_status
  303. LEFT JOIN sys.t_data_kind tdktype ON tdktype.kind_code = t.out_type
  304. left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = t.out_reason
  305. <include refid="Condition"/>
  306. </select>
  307. <!-- 根据主键查询表dkic_b.t_psi_outbound的一行数据 -->
  308. <select id="selectById" resultMap="BaseResultMapResponse">
  309. SELECT t.out_id,
  310. t.out_no,
  311. t.out_type,
  312. t.from_id,
  313. t.from_no,
  314. t.from_no as "orderNo",
  315. t.org_id,
  316. tmo.org_name as "orgName",
  317. t.staff_id,
  318. tms.staff_name as "staffName",
  319. t.cus_id,
  320. tmc.cus_code as "cusCode",
  321. tmc.cus_name as "cusName",
  322. tmc.cus_phone as "cusPhone",
  323. tmc.cus_from as "cusFrom",
  324. tmc.contact_phone as "contactPhone",
  325. tmc.address_full as "addressFull",
  326. tmdd.data_value as cus_from_name,
  327. tmc.address_area,
  328. tmc.address_name,
  329. tmc.address_no,
  330. tmc.address_gcj02,
  331. tmc.address_full,
  332. tmc.contact_name,
  333. tmc.contact_phone,
  334. tmc.channel_id as sales_channel,
  335. tmsc.channel_name as channel_name,
  336. t.sup_id,
  337. t.out_status,
  338. sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "outStatusName",
  339. t.outing_qty,
  340. t.outing_amt,
  341. t.out_qty,
  342. t.out_amt,
  343. t.return_qty,
  344. t.return_amt,
  345. t.out_date,
  346. t.remarks,
  347. t.annex_paths,
  348. t.make_staff,
  349. makestaff.staff_name as "makeStaffName",
  350. t.make_time,
  351. t.receivable_id,
  352. t.payable_id,
  353. t.cp_id,
  354. t.flg_valid,
  355. tmd.data_value as out_reason_name
  356. FROM dkic_b.t_psi_outbound as t
  357. left join dkic_b.t_mst_customer tmc on tmc.cus_id = t.cus_id
  358. left join dkic_b.t_mst_sale_channel tmsc on tmsc.channel_id = tmc.channel_id
  359. left join dkic_b.t_mst_org tmo on tmo.org_id = t.org_id
  360. left join dkic_b.t_mst_staff tms on tms.staff_id = t.staff_id
  361. left join dkic_b.t_mst_staff as makestaff on makestaff.staff_id = t.make_staff
  362. left join dkic_b.t_mst_dictionary_data tmdd on tmdd.data_id = tmc.cus_from
  363. left join sys.t_data_kind as tdk1 on tdk1.kind_code = t.out_status
  364. left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = t.out_reason
  365. WHERE t.out_id = #{id}::uuid
  366. </select>
  367. <!-- 获取出库信息(新建退货用) -->
  368. <select id="selectByIdForReturn" resultMap="BaseResultMapResponse">
  369. SELECT t.out_id,
  370. t.out_no,
  371. t.out_type,
  372. t.from_id,
  373. t.from_no,
  374. t.from_no as "orderNo",
  375. t.org_id,
  376. tmo.org_name as "orgName",
  377. t.staff_id,
  378. tms.staff_name as "staffName",
  379. t.cus_id,
  380. tmc.cus_code as "cusCode",
  381. tmc.cus_name as "cusName",
  382. tmc.cus_phone as "cusPhone",
  383. tmc.cus_from as "cusFrom",
  384. tmc.contact_phone as "contactPhone",
  385. tmc.address_full as "addressFull",
  386. tmdd.data_value as cus_from_name,
  387. tmc.address_area,
  388. tmc.address_name,
  389. tmc.address_no,
  390. tmc.address_gcj02,
  391. tmc.address_full,
  392. tmc.contact_name,
  393. tmc.contact_phone,
  394. tmc.channel_id as sales_channel,
  395. tmsc.channel_name as channel_name,
  396. t.sup_id,
  397. t.out_status,
  398. sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "outStatusName",
  399. t.outing_qty,
  400. t.outing_amt,
  401. t.out_qty,
  402. t.out_amt,
  403. t.return_qty,
  404. t.return_amt,
  405. t.out_date,
  406. t.remarks,
  407. t.annex_paths,
  408. t.make_staff,
  409. makestaff.staff_name as "makeStaffName",
  410. t.make_time,
  411. t.receivable_id,
  412. t.payable_id,
  413. t.cp_id,
  414. t.flg_valid,
  415. tmd.data_value as out_reason_name
  416. FROM dkic_b.t_psi_outbound as t
  417. left join dkic_b.t_mst_customer tmc on tmc.cus_id = t.cus_id
  418. left join dkic_b.t_mst_sale_channel tmsc on tmsc.channel_id = tmc.channel_id
  419. left join dkic_b.t_mst_org tmo on tmo.org_id = t.org_id
  420. left join dkic_b.t_mst_staff tms on tms.staff_id = t.staff_id
  421. left join dkic_b.t_mst_staff as makestaff on makestaff.staff_id = t.make_staff
  422. left join dkic_b.t_mst_dictionary_data tmdd on tmdd.data_id = tmc.cus_from
  423. left join sys.t_data_kind as tdk1 on tdk1.kind_code = t.out_status
  424. left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = t.out_reason
  425. WHERE t.out_id = #{id}::uuid
  426. </select>
  427. <!-- 根据主键锁定表dkic_b.t_psi_outbound的一行数据 -->
  428. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  429. SELECT
  430. <include refid="Base_Column_List"/>
  431. FROM dkic_b.t_psi_outbound
  432. WHERE out_id = #{id}::uuid
  433. for update
  434. </select>
  435. <!-- 根据主键锁定表dkic_b.t_psi_outbound的多行数据 -->
  436. <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
  437. SELECT
  438. <include refid="Base_Column_List"/>
  439. FROM dkic_b.t_psi_outbound
  440. <include refid="idsForeach"/>
  441. for update
  442. </select>
  443. <insert id="insertBatch">
  444. insert into dkic_b.t_psi_outbound
  445. (
  446. <trim suffixOverrides=",">
  447. out_no,
  448. out_type,
  449. from_id,
  450. from_no,
  451. org_id,
  452. staff_id,
  453. order_id,
  454. order_no,
  455. into_return_id,
  456. into_return_no,
  457. cus_id,
  458. sup_id,
  459. out_status,
  460. outing_qty,
  461. outing_amt,
  462. out_qty,
  463. out_amt,
  464. return_qty,
  465. return_amt,
  466. out_date,
  467. remarks,
  468. annex_paths,
  469. make_staff,
  470. make_time,
  471. receivable_id,
  472. payable_id,
  473. cp_id,
  474. op_app_code,
  475. </trim>
  476. )
  477. values
  478. <foreach collection="list" index="index" item="item" separator=",">
  479. (
  480. <trim suffixOverrides=",">
  481. #{item.outNo},
  482. #{item.outType},
  483. #{item.fromId}::uuid,
  484. #{item.fromNo},
  485. #{item.orgId}::uuid,
  486. #{item.staffId}::uuid,
  487. #{item.cusId}::uuid,
  488. #{item.supId}::uuid,
  489. #{item.outStatus},
  490. #{item.outingQty},
  491. #{item.outingAmt},
  492. #{item.outQty},
  493. #{item.outAmt},
  494. #{item.returnQty},
  495. #{item.returnAmt},
  496. #{item.outDate},
  497. #{item.remarks},
  498. #{item.annexPaths},
  499. #{item.makeStaff}::uuid,
  500. #{item.makeTime},
  501. #{item.receivableId}::uuid,
  502. #{item.payableId}::uuid,
  503. #{item.cpId},
  504. #{item.opAppCode},
  505. </trim>
  506. )
  507. </foreach>
  508. </insert>
  509. <!-- 根据id查询带出销售退货单数据(销售退货出库办理用)-->
  510. <select id="selectMessageByOtherQuery" resultMap="BaseResultMapResponse">
  511. SELECT
  512. <include refid="Base_Column_List_Response"/>
  513. ,tmo.org_name
  514. ,tms.staff_name as "staffName"
  515. ,tmc.cus_code
  516. ,tmc.cus_name
  517. ,tmc.cus_phone
  518. ,tmc.contact_phone
  519. ,tmc.contact_name
  520. ,tmc.address_area
  521. ,tmc.address_name
  522. ,tmc.address_no
  523. ,tmc.address_gcj02
  524. ,tmc.address_full
  525. ,tmsc.channel_name
  526. ,tmsc.channel_name
  527. ,tmsc.channel_name
  528. ,tmd.data_value as cus_from_name
  529. FROM dkic_b.t_psi_outbound tpo
  530. Left join dkic_b.t_mst_org tmo on tmo.org_id = tpo.org_id
  531. Left join dkic_b.t_mst_staff tms on tms.staff_id = tpo.staff_id
  532. left join dkic_b.t_mst_customer tmc on tpo.cus_id = tmc.cus_id
  533. left join dkic_b.t_mst_sale_channel tmsc on tmc.channel_id = tmsc.channel_id
  534. left join dkic_b.t_mst_dictionary_data tmd on tmc.cus_from = tmd.data_id
  535. <where>
  536. <if test="outId != null and outId != ''">
  537. AND tpo.out_id = #{outId}::uuid
  538. </if>
  539. <if test="outStatus != null and outStatus != ''">
  540. AND tpo.out_status = #{outStatus}
  541. </if>
  542. </where>
  543. </select>
  544. <!--修改退货信息 -->
  545. <update id="updateReturnMessage" parameterType="com.dk.mdm.model.pojo.sale.OrderItem">
  546. update dkic_b.t_psi_outbound
  547. <set>
  548. <if test="returnQty != null">
  549. return_qty = return_qty + #{returnQty,jdbcType=NUMERIC},
  550. </if>
  551. <if test="returnAmt != null">
  552. return_amt = return_amt + #{returnAmt,jdbcType=NUMERIC},
  553. </if>
  554. </set>
  555. where out_id = #{outId,typeHandler=UuidTypeHandler}
  556. and out_qty >= return_qty
  557. </update>
  558. <!-- 出库办理显示字段 -->
  559. <sql id="Base_Column_List_Response_Out">
  560. tpo.out_id ,
  561. tpo.out_no ,
  562. tpo.out_type ,
  563. tpo.from_id,
  564. tpo.from_no,
  565. tpo.org_id,
  566. tpo.staff_id,
  567. tpo.cus_id,
  568. tpo.sup_id,
  569. tpo.out_status,
  570. tpo.outing_qty ,
  571. tpo.outing_amt,
  572. tpo.out_qty ,
  573. tpo.out_amt ,
  574. tpo.return_qty,
  575. tpo.return_amt,
  576. tpo.out_date ,
  577. tpo.remarks,
  578. tpo.annex_paths,
  579. tpo.make_staff,
  580. tpo.make_time,
  581. tpo.out_reason
  582. </sql>
  583. <sql id="Base_Column_List_Response_Into">
  584. tpi.into_id as out_id,
  585. tpi.into_no as out_no,
  586. tpi.into_type as out_type,
  587. tpi.from_id,
  588. tpi.from_no,
  589. tpi.org_id,
  590. tpi.staff_id,
  591. tpi.cus_id,
  592. tpi.sup_id,
  593. tpi.into_status as out_status ,
  594. tpi.intoing_qty as outing_qty ,
  595. tpi.intoing_amt as outing_amt ,
  596. tpi.into_qty as out_qty ,
  597. tpi.into_amt as out_amt,
  598. tpi.return_qty,
  599. tpi.return_amt,
  600. tpi.into_date as out_date,
  601. tpi.remarks,
  602. tpi.annex_paths,
  603. tpi.make_staff,
  604. tpi.make_time,
  605. tpi.into_reason as out_reason
  606. </sql>
  607. <!-- 条件查询 web端入库办理用,-->
  608. <select id="selectOutbound" resultMap="BaseResultMapResponse">
  609. select
  610. <include refid="Base_Column_List_Response_Out"/>,
  611. tmo.org_name AS "orgName",
  612. tmp.sup_name AS "supplierName",
  613. tms.staff_name AS "staffName",
  614. tms.staff_name AS "makeStaffName",
  615. tmc.cus_name as "cusName",
  616. tmc.cus_phone as "cusPhone",
  617. tmc.cus_from as "cusFrom",
  618. makestaff.staff_name as "makeStaffName",
  619. sys.f_get_name_i18n(tdktype.kind_name_i18n, 'zh_CN') AS "outTypeName",
  620. sys.f_get_name_i18n(tdk.kind_name_i18n, 'zh_CN') AS "outStatusName",
  621. tmd.data_value as out_reason_name
  622. from dkic_b.t_psi_outbound tpo
  623. <include refid="Select_Inbound_Join_Table_Out"/>
  624. <where>
  625. <if test="outTypes != null and outTypes.size()>0">
  626. AND tpo.out_type =any(#{outTypes,typeHandler=StringListTypeHandler})
  627. </if>
  628. <if test="outTypes == null || outTypes.size()==0">
  629. AND (tpo.out_type = '出库类型-其他出库'
  630. or tpo.out_type = '出库类型-销售出库')
  631. </if>
  632. <if test="outStatus != null and outStatus != '' ">
  633. AND tpo.out_status LIKE concat('%',my_ex.likequery(#{outStatus}),'%')
  634. </if>
  635. <if test="makeTimeStart != null and makeTimeEnd != null">
  636. AND tpo.make_time &gt;= #{makeTimeStart}::timestamp with time zone
  637. AND tpo.make_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
  638. </if>
  639. <if test="outNo != null and outNo != ''">
  640. AND tpo.out_no LIKE concat('%',my_ex.likequery(#{outNo}),'%')
  641. </if>
  642. <if test="cusPhone != null and cusPhone != ''">
  643. AND tmc.cus_phone LIKE concat('%',my_ex.likequery(#{cusPhone}),'%')
  644. </if>
  645. <if test="cusName != null and cusName != ''">
  646. AND tmc.cus_name LIKE concat('%',my_ex.likequery(#{cusName}),'%')
  647. </if>
  648. <if test="supId != null and supId != ''">
  649. AND tpo.sup_id = #{supId}::uuid
  650. </if>
  651. <if test="orgIdList != null and orgIdList.size() > 0">
  652. AND tmo.org_id =any(#{orgIdList, typeHandler=uuidListTypeHandler})
  653. </if>
  654. <if test="staffIdList != null and staffIdList.size() > 0">
  655. AND tms.staff_id =any(#{staffIdList, typeHandler=uuidListTypeHandler})
  656. </if>
  657. <if test="flgValidList != null and flgValidList.size()>0">
  658. AND tpo.flg_valid =any(#{flgValidList, typeHandler=BooleanListTypeHandler})
  659. </if>
  660. </where>
  661. union all
  662. SELECT
  663. <include refid="Base_Column_List_Response_Into"/>,
  664. tmo.org_name AS "orgName",
  665. tmp.sup_name AS "supplierName",
  666. tms.staff_name AS "staffName",
  667. tms.staff_name AS "makeStaffName",
  668. tmc.cus_name as "cusName",
  669. tmc.cus_phone as "cusPhone",
  670. tmc.cus_from as "cusFrom",
  671. makestaff.staff_name as "makeStaffName",
  672. sys.f_get_name_i18n(tdktype.kind_name_i18n, 'zh_CN') AS "outTypeName",
  673. sys.f_get_name_i18n(tdk.kind_name_i18n, 'zh_CN') AS "outStatusName",
  674. tmd.data_value as out_reason_name
  675. FROM dkic_b.t_psi_inbound tpi
  676. <include refid="Select_Inbound_Join_Table_Into"/>
  677. <where>
  678. <if test="outTypes != null and outTypes.size()>0">
  679. AND tpi.into_type =any(#{outTypes,typeHandler=StringListTypeHandler})
  680. </if>
  681. <if test="outTypes == null || outTypes.size()==0">
  682. AND tpi.into_type = '入库类型-采退入库'
  683. </if>
  684. <if test="intoStatus != null and intoStatus != '' ">
  685. AND tpi.into_status LIKE concat('%',my_ex.likequery(#{intoStatus}),'%')
  686. </if>
  687. <if test="makeTimeStart != null and makeTimeEnd != null">
  688. AND tpi.make_time &gt;= #{makeTimeStart}::timestamp with time zone
  689. AND tpi.make_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
  690. </if>
  691. <if test="outNo != null and outNo != ''">
  692. AND tpi.into_no LIKE concat('%',my_ex.likequery(#{outNo}),'%')
  693. </if>
  694. <if test="cusPhone != null and cusPhone != ''">
  695. AND tmc.cus_phone LIKE concat('%',my_ex.likequery(#{cusPhone}),'%')
  696. </if>
  697. <if test="cusName != null and cusName != ''">
  698. AND tmc.cus_name LIKE concat('%',my_ex.likequery(#{cusName}),'%')
  699. </if>
  700. <if test="supId != null and supId != ''">
  701. AND tpi.sup_id = #{supId}::uuid
  702. </if>
  703. <if test="orgIdList != null and orgIdList.size() > 0">
  704. AND tmo.org_id =any(#{orgIdList, typeHandler=uuidListTypeHandler})
  705. </if>
  706. <if test="staffIdList != null and staffIdList.size() > 0">
  707. AND tms.staff_id =any(#{staffIdList, typeHandler=uuidListTypeHandler})
  708. </if>
  709. <if test="flgValidList != null and flgValidList.size()>0">
  710. AND tpi.flg_valid =any(#{flgValidList, typeHandler=BooleanListTypeHandler})
  711. </if>
  712. </where>
  713. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  714. limit #{end} offset #{start}
  715. </if>
  716. </select>
  717. <!-- 条件查询 web端入库办理用个数 -->
  718. <select id="selectOutboundCond" resultType="Long">
  719. SELECT
  720. count(1) from (
  721. select
  722. <include refid="Base_Column_List_Response_Out"/>,
  723. tmo.org_name AS "orgName",
  724. tmp.sup_name AS "supplierName",
  725. tms.staff_name AS "staffName",
  726. tms.staff_name AS "makeStaffName",
  727. tmc.cus_name as "cusName",
  728. tmc.cus_phone as "cusPhone",
  729. tmc.cus_from as "cusFrom",
  730. makestaff.staff_name as "makeStaffName",
  731. sys.f_get_name_i18n(tdktype.kind_name_i18n, 'zh_CN') AS "outTypeName",
  732. sys.f_get_name_i18n(tdk.kind_name_i18n, 'zh_CN') AS "outStatusName",
  733. tmd.data_value as out_reason_name
  734. from dkic_b.t_psi_outbound tpo
  735. <include refid="Select_Inbound_Join_Table_Out"/>
  736. <where>
  737. <if test="outTypes != null and outTypes.size()>0">
  738. AND tpo.out_type =any(#{outTypes,typeHandler=StringListTypeHandler})
  739. </if>
  740. <if test="outTypes == null || outTypes.size()==0">
  741. AND (tpo.out_type = '出库类型-其他出库'
  742. or tpo.out_type = '出库类型-销售出库')
  743. </if>
  744. <if test="outStatus != null and outStatus != '' ">
  745. AND tpo.out_status LIKE concat('%',my_ex.likequery(#{outStatus}),'%')
  746. </if>
  747. <if test="makeTimeStart != null and makeTimeEnd != null">
  748. AND tpo.make_time &gt;= #{makeTimeStart}::timestamp with time zone
  749. AND tpo.make_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
  750. </if>
  751. <if test="outNo != null and outNo != ''">
  752. AND tpo.out_no LIKE concat('%',my_ex.likequery(#{outNo}),'%')
  753. </if>
  754. <if test="cusPhone != null and cusPhone != ''">
  755. AND tmc.cus_phone LIKE concat('%',my_ex.likequery(#{cusPhone}),'%')
  756. </if>
  757. <if test="cusName != null and cusName != ''">
  758. AND tmc.cus_name LIKE concat('%',my_ex.likequery(#{cusName}),'%')
  759. </if>
  760. <if test="supId != null and supId != ''">
  761. AND tpo.sup_id = #{supId}::uuid
  762. </if>
  763. <if test="orgIdList != null and orgIdList.size() > 0">
  764. AND tmo.org_id =any(#{orgIdList, typeHandler=uuidListTypeHandler})
  765. </if>
  766. <if test="staffIdList != null and staffIdList.size() > 0">
  767. AND tms.staff_id =any(#{staffIdList, typeHandler=uuidListTypeHandler})
  768. </if>
  769. <if test="flgValidList != null and flgValidList.size()>0">
  770. AND tpo.flg_valid =any(#{flgValidList, typeHandler=BooleanListTypeHandler})
  771. </if>
  772. </where>
  773. union all
  774. SELECT
  775. <include refid="Base_Column_List_Response_Into"/>,
  776. tmo.org_name AS "orgName",
  777. tmp.sup_name AS "supplierName",
  778. tms.staff_name AS "staffName",
  779. tms.staff_name AS "makeStaffName",
  780. tmc.cus_name as "cusName",
  781. tmc.cus_phone as "cusPhone",
  782. tmc.cus_from as "cusFrom",
  783. makestaff.staff_name as "makeStaffName",
  784. sys.f_get_name_i18n(tdktype.kind_name_i18n, 'zh_CN') AS "outTypeName",
  785. sys.f_get_name_i18n(tdk.kind_name_i18n, 'zh_CN') AS "outStatusName",
  786. tmd.data_value as out_reason_name
  787. FROM dkic_b.t_psi_inbound tpi
  788. <include refid="Select_Inbound_Join_Table_Into"/>
  789. <where>
  790. <if test="outTypes != null and outTypes.size()>0">
  791. AND tpi.into_type =any(#{outTypes,typeHandler=StringListTypeHandler})
  792. </if>
  793. <if test="outTypes == null || outTypes.size()==0">
  794. AND tpi.into_type = '入库类型-采退入库'
  795. </if>
  796. <if test="intoStatus != null and intoStatus != '' ">
  797. AND tpi.into_status LIKE concat('%',my_ex.likequery(#{intoStatus}),'%')
  798. </if>
  799. <if test="makeTimeStart != null and makeTimeEnd != null">
  800. AND tpi.make_time &gt;= #{makeTimeStart}::timestamp with time zone
  801. AND tpi.make_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
  802. </if>
  803. <if test="outNo != null and outNo != ''">
  804. AND tpi.into_no LIKE concat('%',my_ex.likequery(#{outNo}),'%')
  805. </if>
  806. <if test="cusPhone != null and cusPhone != ''">
  807. AND tmc.cus_phone LIKE concat('%',my_ex.likequery(#{cusPhone}),'%')
  808. </if>
  809. <if test="cusName != null and cusName != ''">
  810. AND tmc.cus_name LIKE concat('%',my_ex.likequery(#{cusName}),'%')
  811. </if>
  812. <if test="supId != null and supId != ''">
  813. AND tpi.sup_id = #{supId}::uuid
  814. </if>
  815. <if test="orgIdList != null and orgIdList.size() > 0">
  816. AND tmo.org_id =any(#{orgIdList, typeHandler=uuidListTypeHandler})
  817. </if>
  818. <if test="staffIdList != null and staffIdList.size() > 0">
  819. AND tms.staff_id =any(#{staffIdList, typeHandler=uuidListTypeHandler})
  820. </if>
  821. <if test="flgValidList != null and flgValidList.size()>0">
  822. AND tpi.flg_valid =any(#{flgValidList, typeHandler=BooleanListTypeHandler})
  823. </if>
  824. </where>
  825. ) tt
  826. </select>
  827. <!--出库办理显示出库关联表-->
  828. <sql id="Select_Inbound_Join_Table_Out">
  829. Left join dkic_b.t_mst_org tmo on tmo.org_id = tpo.org_id
  830. Left join dkic_b.t_mst_supplier tmp on tmp.sup_id = tpo.sup_id
  831. Left join dkic_b.t_mst_staff tms on tms.staff_id = tpo.staff_id
  832. Left join dkic_b.t_mst_staff makestaff on makestaff.staff_id = tpo.make_staff
  833. LEFT JOIN sys.t_data_kind tdk ON tdk.kind_code = tpo.out_status
  834. LEFT JOIN sys.t_data_kind tdktype ON tdktype.kind_code = tpo.out_type
  835. left join dkic_b.t_mst_customer tmc on tpo.cus_id = tmc.cus_id
  836. left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = tpo.out_reason
  837. </sql>
  838. <!--出库办理显示入库关联表-->
  839. <sql id="Select_Inbound_Join_Table_Into">
  840. Left join dkic_b.t_mst_org tmo on tmo.org_id = tpi.org_id
  841. Left join dkic_b.t_mst_supplier tmp on tmp.sup_id = tpi.sup_id
  842. Left join dkic_b.t_mst_staff tms on tms.staff_id = tpi.staff_id
  843. Left join dkic_b.t_mst_staff makestaff on makestaff.staff_id = tpi.make_staff
  844. LEFT JOIN sys.t_data_kind tdk ON tdk.kind_code = tpi.into_status
  845. LEFT JOIN sys.t_data_kind tdktype ON tdktype.kind_code = tpi.into_type
  846. left join dkic_b.t_mst_customer tmc on tpi.cus_id = tmc.cus_id
  847. left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = tpi.into_reason
  848. </sql>
  849. </mapper>