OutboundMapper.xml 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180
  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, sys.f_remove_zero(outing_qty) as outing_qty, outing_amt,
  9. sys.f_remove_zero(out_qty) as out_qty, out_amt, sys.f_remove_zero(return_qty) as return_qty, return_amt,
  10. out_date, remarks, annex_paths, make_staff, make_time, receivable_id,
  11. flg_valid, cp_id,out_reason,flg_auto_handle,flg_handle_setting
  12. </sql>
  13. <sql id="Base_Column_List_Response">
  14. tpo.out_id, tpo.out_no, tpo.out_type, tpo.from_id, tpo.from_no, tpo.org_id, tpo.staff_id,
  15. tpo.cus_id, tpo.sup_id, tpo.out_status, sys.f_remove_zero(tpo.outing_qty) as outing_qty, tpo.outing_amt,
  16. sys.f_remove_zero(tpo.out_qty) as out_qty, tpo.out_amt,
  17. sys.f_remove_zero(tpo.return_qty) as return_qty, tpo.return_amt, tpo.out_date, tpo.remarks, tpo.annex_paths, tpo.make_staff,
  18. tpo.make_time, tpo.receivable_id, tpo.flg_valid, tpo.cp_id,tpo.out_reason,
  19. tpo.flg_auto_handle,tpo.flg_handle_setting
  20. </sql>
  21. <!-- 通用查询映射结果 -->
  22. <resultMap id="BaseResultMap" type="com.dk.mdm.model.pojo.ivt.Outbound">
  23. <id column="out_id" property="outId"/>
  24. <result column="out_no" property="outNo"/>
  25. <result column="out_type" property="outType"/>
  26. <result column="from_id" property="fromId" typeHandler="UuidTypeHandler"/>
  27. <result column="from_no" property="fromNo"/>
  28. <result column="org_id" property="orgId" typeHandler="UuidTypeHandler"/>
  29. <result column="staff_id" property="staffId" typeHandler="UuidTypeHandler"/>
  30. <result column="cus_id" property="cusId" typeHandler="UuidTypeHandler"/>
  31. <result column="sup_id" property="supId" typeHandler="UuidTypeHandler"/>
  32. <result column="out_status" property="outStatus"/>
  33. <result column="outing_qty" property="outingQty"/>
  34. <result column="outing_amt" property="outingAmt"/>
  35. <result column="out_qty" property="outQty"/>
  36. <result column="out_amt" property="outAmt"/>
  37. <result column="return_qty" property="returnQty"/>
  38. <result column="return_amt" property="returnAmt"/>
  39. <result column="out_date" property="outDate" typeHandler="TimestampTypeHandler"/>
  40. <result column="remarks" property="remarks"/>
  41. <result column="annex_paths" property="annexPaths" typeHandler="JsonTypeHandler"/>
  42. <result column="make_staff" property="makeStaff" typeHandler="UuidTypeHandler"/>
  43. <result column="make_time" property="makeTime" typeHandler="TimestampTypeHandler"/>
  44. <result column="receivable_id" property="receivableId" typeHandler="UuidTypeHandler"/>
  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. <result column="out_reason" property="outReason" typeHandler="UuidTypeHandler"/>
  55. <result column="flg_auto_handle" property="flgAutoHandle"/>
  56. <result column="flg_handle_setting" property="flgHandleSetting"/>
  57. </resultMap>
  58. <!-- 通用查询映射结果 -->
  59. <resultMap id="BaseResultMapResponse" type="com.dk.mdm.model.response.ivt.OutboundResponse">
  60. <id column="out_id" property="outId"/>
  61. <result column="out_no" property="outNo"/>
  62. <result column="out_type" property="outType"/>
  63. <result column="from_id" property="fromId" typeHandler="UuidTypeHandler"/>
  64. <result column="from_no" property="fromNo"/>
  65. <result column="org_id" property="orgId" typeHandler="UuidTypeHandler"/>
  66. <result column="staff_id" property="staffId" typeHandler="UuidTypeHandler"/>
  67. <result column="cus_id" property="cusId" typeHandler="UuidTypeHandler"/>
  68. <result column="sup_id" property="supId" typeHandler="UuidTypeHandler"/>
  69. <result column="out_status" property="outStatus"/>
  70. <result column="outing_qty" property="outingQty"/>
  71. <result column="outing_amt" property="outingAmt"/>
  72. <result column="out_qty" property="outQty"/>
  73. <result column="out_amt" property="outAmt"/>
  74. <result column="return_qty" property="returnQty"/>
  75. <result column="return_amt" property="returnAmt"/>
  76. <result column="out_date" property="outDate" typeHandler="TimestampTypeHandler"/>
  77. <result column="remarks" property="remarks"/>
  78. <result column="annex_paths" property="annexPaths" typeHandler="JsonTypeHandler"/>
  79. <result column="make_staff" property="makeStaff" typeHandler="UuidTypeHandler"/>
  80. <result column="make_time" property="makeTime" typeHandler="TimestampTypeHandler"/>
  81. <result column="receivable_id" property="receivableId" 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="channel_id" property="channelId"/>
  100. <result column="cus_from_name" property="cusFromName"/>
  101. <result column="out_reason" property="outReason" typeHandler="UuidTypeHandler"/>
  102. <result column="out_reason_name" property="outReasonName" />
  103. <result column="sumOutAmt" property="sumOutAmt" />
  104. <result column="sumOutQty" property="sumOutQty" />
  105. <result column="op_update_time" property="opUpdateTime" typeHandler="TimestampTypeHandler"/>
  106. <result column="fact_amt" property="factAmt"/>
  107. <result column="discount" property="discount"/>
  108. <result column="disc_amt" property="discAmt"/>
  109. </resultMap>
  110. <resultMap id="BaseResultMapDetailResponse" type="com.dk.mdm.model.response.ivt.OutboundResponse">
  111. <id column="out_id" property="outId"/>
  112. <result column="out_no" property="outNo"/>
  113. <result column="out_type" property="outType"/>
  114. <result column="from_id" property="fromId" typeHandler="UuidTypeHandler"/>
  115. <result column="from_no" property="fromNo"/>
  116. <result column="org_id" property="orgId" typeHandler="UuidTypeHandler"/>
  117. <result column="staff_id" property="staffId" typeHandler="UuidTypeHandler"/>
  118. <result column="staffName" property="staffName" />
  119. <result column="orgName" property="orgName" />
  120. <result column="cus_id" property="cusId" typeHandler="UuidTypeHandler"/>
  121. <result column="sup_id" property="supId" typeHandler="UuidTypeHandler"/>
  122. <result column="out_status" property="outStatus"/>
  123. <result column="outing_qty" property="outingQty"/>
  124. <result column="outing_amt" property="outingAmt"/>
  125. <result column="out_qty" property="outQty"/>
  126. <result column="out_amt" property="outAmt"/>
  127. <result column="return_qty" property="returnQty"/>
  128. <result column="return_amt" property="returnAmt"/>
  129. <result column="out_date" property="outDate" typeHandler="TimestampTypeHandler"/>
  130. <result column="remarks" property="remarks"/>
  131. <result column="annex_paths" property="annexPaths" typeHandler="JsonTypeHandler"/>
  132. <result column="make_staff" property="makeStaff" typeHandler="UuidTypeHandler"/>
  133. <result column="make_time" property="makeTime" typeHandler="TimestampTypeHandler"/>
  134. <result column="receivable_id" property="receivableId" typeHandler="UuidTypeHandler"/>
  135. <result column="flg_valid" property="flgValid"/>
  136. <result column="cp_id" property="cpId"/>
  137. <result column="flg_auto_handle" property="flgAutoHandle"/>
  138. <result column="flg_handle_setting" property="flgHandleSetting"/>
  139. <result column="cusCode" property="cusCode"/>
  140. <result column="cusName" property="cusName"/>
  141. <result column="cusPhone" property="cusPhone"/>
  142. <result column="contact_phone" property="contactPhone"/>
  143. <result column="contact_name" property="contactName"/>
  144. <result column="address_area" property="addressArea" typeHandler="JsonTypeHandler"/>
  145. <result column="address_name" property="addressName"/>
  146. <result column="address_no" property="addressNo"/>
  147. <result column="address_gcj02" property="addressGcj02" typeHandler="JsonTypeHandler"/>
  148. <result column="addressFull" property="addressFull"/>
  149. <result column="channel_name" property="channelName"/>
  150. <result column="cus_from_name" property="cusFromName"/>
  151. <result column="out_reason" property="outReason" typeHandler="UuidTypeHandler"/>
  152. <result column="out_reason_name" property="outReasonName" />
  153. <result column="outStatusName" property="outStatusName"/>
  154. <collection property="goodsList" resultMap="itemListMap" columnPrefix="list_"/>
  155. </resultMap>
  156. <resultMap id="itemListMap" type="java.util.Map">
  157. <id column="item_id" property="itemId"/>
  158. <result column="sup_id" property="supId" typeHandler="UuidTypeHandler"/>
  159. <result column="out_id" property="outId" typeHandler="UuidTypeHandler"/>
  160. <result column="out_no" property="outNo" />
  161. <result column="out_type" property="outType"/>
  162. <result column="from_id" property="fromId" typeHandler="UuidTypeHandler"/>
  163. <result column="from_item_id" property="fromItemId" typeHandler="UuidTypeHandler"/>
  164. <result column="item_index" property="itemIndex"/>
  165. <result column="sku_id" property="skuId" typeHandler="UuidTypeHandler"/>
  166. <result column="price_out" property="priceOut"/>
  167. <result column="non_std_code" property="nonStdCode"/>
  168. <result column="out_status" property="outStatus"/>
  169. <result column="outing_qty" property="outingQty"/>
  170. <result column="outing_amt" property="outingAmt"/>
  171. <result column="out_qty" property="outQty"/>
  172. <result column="out_amt" property="outAmt"/>
  173. <result column="return_qty" property="returnQty"/>
  174. <result column="return_amt" property="returnAmt"/>
  175. <result column="remarks" property="remarks"/>
  176. <result column="inv_id" property="invId" typeHandler="UuidTypeHandler"/>
  177. <result column="cost_price" property="costPrice"/>
  178. <result column="cost_amt" property="costAmt"/>
  179. <result column="flg_valid" property="flgValid"/>
  180. <result column="cp_id" property="cpId"/>
  181. <result column="s_out_id" property="sOutId" typeHandler="UuidTypeHandler"/>
  182. <result column="s_out_item_id" property="sOutItemId" typeHandler="UuidTypeHandler"/>
  183. <result column="s_order_id" property="sOrderId" typeHandler="UuidTypeHandler"/>
  184. <result column="s_order_item_id" property="sOrderItemId" typeHandler="UuidTypeHandler"/>
  185. <result column="sku_code" property="skuCode"/>
  186. <result column="sku_model" property="skuModel"/>
  187. <result column="sku_spec" property="skuSpec"/>
  188. <result column="pack_box_text" property="packBoxText"/>
  189. <result column="sku_name" property="skuName"/>
  190. <result column="brand_name" property="brandName"/>
  191. <result column="price_purchase" property="pricePurchase"/>
  192. <result column="price_standard" property="priceStandard"/>
  193. <result column="sku_images" property="skuImages"/>
  194. <result column="wh_id" property="whId"/>
  195. <result column="wh_name" property="whName"/>
  196. <result column="invQty" property="invQty"/>
  197. <result column="usableQty" property="usableQty"/>
  198. <result column="pack_box" property="packBox"/>
  199. <result column="flgSubUnit" property="flgSubUnit"/>
  200. <result column="subUnitName" property="subUnitName"/>
  201. <result column="unitName" property="unitName"/>
  202. <result column="outing_box" property="outingBox"/>
  203. <result column="outing_piece" property="outingPiece"/>
  204. <result column="out_box" property="box"/>
  205. <result column="out_piece" property="piece"/>
  206. <result column="decimal_places" property="decimalPlaces"/>
  207. </resultMap>
  208. <!-- 通用条件列 -->
  209. <sql id="Condition">
  210. <where>
  211. <if test="outNo != null and outNo != ''">
  212. AND t.out_no LIKE concat('%',my_ex.likequery(#{outNo}),'%')
  213. </if>
  214. <if test="outType != null and outType != ''">
  215. AND t.out_type = #{outType}
  216. </if>
  217. <if test="outTypeList != null and outTypeList.size()>0">
  218. AND t.out_type =any(#{outTypeList,typeHandler=StringListTypeHandler})
  219. </if>
  220. <if test="outReasonList != null and outReasonList.size()>0">
  221. AND t.out_reason =any(#{outReasonList,typeHandler=UuidListTypeHandler})
  222. </if>
  223. <if test="searchText !=null and searchText != ''">
  224. AND (
  225. t.out_no LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  226. or t.from_no LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  227. or tmc.cus_phone LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  228. or tmc.cus_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  229. or tmo.org_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  230. or tmp.sup_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  231. or tms.staff_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  232. )
  233. </if>
  234. <if test="orgName != null and orgName != ''">
  235. AND tmo.org_name LIKE concat('%',my_ex.likequery(#{orgName}),'%')
  236. </if>
  237. <if test="addressFull != null and addressFull != ''">
  238. AND tmc.address_full LIKE concat('%',my_ex.likequery(#{addressFull}),'%')
  239. </if>
  240. <if test="staffIds != null and staffIds.size()>0">
  241. AND t.staff_id = any(#{staffIds, typeHandler=uuidListTypeHandler})
  242. </if>
  243. <if test="orgIds != null and orgIds.size()>0">
  244. AND t.org_id = any(#{orgIds, typeHandler=uuidListTypeHandler})
  245. </if>
  246. <if test="supName != null and supName != ''">
  247. AND tmp.sup_name LIKE concat('%',my_ex.likequery(#{supName}),'%')
  248. </if>
  249. <if test="staffName != null and staffName != ''">
  250. AND tms.staff_name LIKE concat('%',my_ex.likequery(#{staffName}),'%')
  251. </if>
  252. <if test="fromId != null and fromId != ''">
  253. AND t.from_id = #{fromId}
  254. </if>
  255. <if test="fromNo != null and fromNo != ''">
  256. AND t.from_no = #{fromNo}
  257. </if>
  258. <if test="orgId != null and orgId != ''">
  259. AND t.org_id = #{orgId}
  260. </if>
  261. <if test="staffId != null and staffId != ''">
  262. AND t.staff_id = #{staffId}
  263. </if>
  264. <if test="cusId != null and cusId != ''">
  265. AND t.cus_id = #{cusId}::uuid
  266. </if>
  267. <if test="supId != null and supId != ''">
  268. AND t.sup_id = #{supId}
  269. </if>
  270. <if test="outStatus != null and outStatus != ''">
  271. AND t.out_status = #{outStatus}
  272. </if>
  273. <if test="outingQty != null">
  274. AND t.outing_qty = #{outingQty}
  275. </if>
  276. <if test="outingAmt != null">
  277. AND t.outing_amt = #{outingAmt}
  278. </if>
  279. <if test="outQty != null">
  280. AND t.out_qty = #{outQty}
  281. </if>
  282. <if test="outAmt != null">
  283. AND t.out_amt = #{outAmt}
  284. </if>
  285. <if test="returnQty != null">
  286. AND t.return_qty = #{returnQty}
  287. </if>
  288. <if test="returnAmt != null">
  289. AND t.return_amt = #{returnAmt}
  290. </if>
  291. <if test="remarks != null and remarks != ''">
  292. AND t.remarks = #{remarks}
  293. </if>
  294. <if test="annexPaths != null and annexPaths != ''">
  295. AND t.annex_paths = #{annexPaths}
  296. </if>
  297. <if test="makeStaff != null and makeStaff != ''">
  298. AND t.make_staff = #{makeStaff}
  299. </if>
  300. <if test="receivableId != null and receivableId != ''">
  301. AND t.receivable_id = #{receivableId}
  302. </if>
  303. <if test="cpId != null">
  304. AND t.cp_id = #{cpId}
  305. </if>
  306. <if test="orderNo != null and orderNo != ''">
  307. AND t.from_no LIKE concat('%',my_ex.likequery(#{orderNo}),'%')
  308. </if>
  309. <if test="cusPhone != null and cusPhone != ''">
  310. AND tmc.cus_phone LIKE concat('%',my_ex.likequery(#{cusPhone}),'%')
  311. </if>
  312. <if test="cusName != null and cusName != ''">
  313. AND tmc.cus_name LIKE concat('%',my_ex.likequery(#{cusName}),'%')
  314. </if>
  315. <if test="orgIdList != null and orgIdList.size() > 0">
  316. AND t.org_id =any(#{orgIdList, typeHandler=uuidListTypeHandler})
  317. </if>
  318. <if test="staffIdList != null and staffIdList.size() > 0">
  319. AND t.staff_id =any(#{staffIdList, typeHandler=uuidListTypeHandler})
  320. </if>
  321. <if test="outStatusList != null and outStatusList.size() > 0">
  322. AND t.out_status =any(#{outStatusList, typeHandler=StringListTypeHandler})
  323. </if>
  324. <if test="outDateStart != null and outDateEnd != null">
  325. AND t.out_date &gt;= #{outDateStart}::timestamp with time zone
  326. AND t.out_date &lt; #{outDateEnd}::timestamp with time zone + interval '1 day'
  327. </if>
  328. <if test="makeTimeStart != null and makeTimeEnd != null">
  329. AND t.make_time &gt;= #{makeTimeStart}::timestamp with time zone
  330. AND t.make_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
  331. </if>
  332. <if test="flgValidList != null and flgValidList.size()>0">
  333. AND t.flg_valid =any(#{flgValidList, typeHandler=BooleanListTypeHandler})
  334. </if>
  335. <if test="viewVoidedDocuments !=null and viewVoidedDocuments == false">
  336. AND t.flg_valid = true
  337. </if>
  338. <if test="flgValid != null">
  339. AND t.flg_valid = #{flgValid}
  340. </if>
  341. <if test="flgFilterReturn != null">
  342. AND tpoi.out_qty - tpoi.return_qty > 0
  343. </if>
  344. </where>
  345. </sql>
  346. <sql id="idsForeach">
  347. <!-- 根据主键outId批量操作 -->
  348. WHERE out_id in
  349. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  350. #{item}
  351. </foreach>
  352. </sql>
  353. <!-- 查询表dkic_b.t_psi_outbound,(条件查询+分页)列表 -->
  354. <select id="selectByCond" resultMap="BaseResultMapResponse">
  355. SELECT t.out_id,
  356. t.out_no,
  357. t.out_type,
  358. t.from_id,
  359. t.from_no,
  360. t.from_no as "biznisNo",
  361. t.org_id,
  362. tmo.org_name as "orgName",
  363. t.staff_id,
  364. tms.staff_name as "staffName",
  365. t.cus_id,
  366. tmc.cus_code as "cusCode",
  367. tmc.cus_name as "cusName",
  368. tmc.cus_phone as "cusPhone",
  369. tmc.cus_from as "cusFrom",
  370. tmc.contact_phone as "contactPhone",
  371. tmc.address_full as "addressFull",
  372. tmdd.data_value as cus_from_name,
  373. t.sup_id,
  374. tmp.sup_name AS "supplierName",
  375. t.out_status,
  376. sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "outStatusName",
  377. sys.f_get_name_i18n(tdktype.kind_name_i18n, #{i18n}) AS "outTypeName",
  378. sys.f_remove_zero(t.outing_qty) as outing_qty,
  379. t.outing_amt,
  380. CAST(t.outing_amt AS DECIMAL(10,2)) + CAST(t.out_amt AS DECIMAL(10,2)) AS "sumOutAmt",
  381. sys.f_remove_zero(CAST(t.outing_qty AS DECIMAL(10,6)) + CAST(t.out_qty AS DECIMAL(10,6))) AS "sumOutQty",
  382. sys.f_remove_zero(t.out_qty) as out_qty,
  383. t.out_amt,
  384. sys.f_remove_zero(t.return_qty) as return_qty,
  385. t.return_amt,
  386. t.out_date,
  387. t.remarks,
  388. t.annex_paths,
  389. t.make_staff,
  390. makestaff.staff_name as "makeStaffName",
  391. t.make_time,
  392. t.receivable_id,
  393. t.cp_id,
  394. t.flg_valid,
  395. tmd.data_value as out_reason_name
  396. FROM dkic_b.t_psi_outbound as t
  397. left join dkic_b.t_mst_org tmo on tmo.org_id = t.org_id
  398. Left join dkic_b.t_mst_supplier tmp on tmp.sup_id = t.sup_id
  399. left join dkic_b.t_mst_staff tms on tms.staff_id = t.staff_id
  400. left join dkic_b.t_mst_staff as makestaff on makestaff.staff_id = t.make_staff
  401. left join dkic_b.t_mst_customer tmc on tmc.cus_id = t.cus_id
  402. left join dkic_b.t_mst_dictionary_data tmdd on tmdd.data_id = tmc.cus_from
  403. left join sys.t_data_kind as tdk1 on tdk1.kind_code = t.out_status
  404. LEFT JOIN sys.t_data_kind tdktype ON tdktype.kind_code = t.out_type
  405. left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = t.out_reason
  406. <include refid="Condition"/>
  407. order by t.make_time desc
  408. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  409. limit #{end} offset #{start}
  410. </if>
  411. </select>
  412. <!-- 查询表dkic_b.t_psi_outbound,(条件查询)个数 -->
  413. <select id="countByCond" resultType="Long">
  414. SELECT
  415. count(1)
  416. FROM dkic_b.t_psi_outbound as t
  417. left join dkic_b.t_mst_org tmo on tmo.org_id = t.org_id
  418. Left join dkic_b.t_mst_supplier tmp on tmp.sup_id = t.sup_id
  419. left join dkic_b.t_mst_staff tms on tms.staff_id = t.staff_id
  420. left join dkic_b.t_mst_staff as makestaff on makestaff.staff_id = t.make_staff
  421. left join dkic_b.t_mst_customer tmc on tmc.cus_id = t.cus_id
  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 sys.t_data_kind tdktype ON tdktype.kind_code = t.out_type
  425. left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = t.out_reason
  426. <include refid="Condition"/>
  427. </select>
  428. <!-- 根据主键查询表dkic_b.t_psi_outbound的一行数据 -->
  429. <select id="selectById" resultMap="BaseResultMapResponse">
  430. SELECT t.out_id,
  431. t.out_no,
  432. t.out_type,
  433. t.from_id,
  434. t.from_no,
  435. t.from_no as "orderNo",
  436. t.org_id,
  437. tmo.org_name as "orgName",
  438. t.staff_id,
  439. tms.staff_name as "staffName",
  440. t.cus_id,
  441. tmc.cus_code as "cusCode",
  442. tmc.cus_name as "cusName",
  443. tmc.cus_phone as "cusPhone",
  444. tmc.cus_from as "cusFrom",
  445. tmc.contact_phone as "contactPhone",
  446. tmc.address_full as "addressFull",
  447. tmdd.data_value as cus_from_name,
  448. tmc.address_area,
  449. tmc.address_name,
  450. tmc.address_no,
  451. tmc.address_gcj02,
  452. tmc.address_full,
  453. tmc.contact_name,
  454. tmc.contact_phone,
  455. tmc.channel_id as sales_channel,
  456. tmc.channel_id ,
  457. tmsc.channel_name as channel_name,
  458. t.sup_id,
  459. t.out_status,
  460. sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "outStatusName",
  461. sys.f_remove_zero(t.outing_qty) as outing_qty,
  462. t.outing_amt,
  463. sys.f_remove_zero(t.out_qty) as out_qty,
  464. t.out_amt,
  465. sys.f_remove_zero(t.return_qty) as return_qty,
  466. t.return_amt,
  467. t.out_date,
  468. t.remarks,
  469. t.annex_paths,
  470. t.make_staff,
  471. makestaff.staff_name as "makeStaffName",
  472. t.make_time,
  473. t.receivable_id,
  474. t.cp_id,
  475. t.flg_valid,
  476. tmp.sup_name AS "supplierName",
  477. t.out_reason,
  478. t.flg_auto_handle,
  479. t.flg_handle_setting,
  480. tmd.data_value as out_reason_name,
  481. t.fact_amt,
  482. t.discount,
  483. t.disc_amt
  484. FROM dkic_b.t_psi_outbound as t
  485. left join dkic_b.t_mst_customer tmc on tmc.cus_id = t.cus_id
  486. left join dkic_b.t_mst_sale_channel tmsc on tmsc.channel_id = tmc.channel_id
  487. left join dkic_b.t_mst_org tmo on tmo.org_id = t.org_id
  488. left join dkic_b.t_mst_staff tms on tms.staff_id = t.staff_id
  489. left join dkic_b.t_mst_staff as makestaff on makestaff.staff_id = t.make_staff
  490. left join dkic_b.t_mst_dictionary_data tmdd on tmdd.data_id = tmc.cus_from
  491. left join sys.t_data_kind as tdk1 on tdk1.kind_code = t.out_status
  492. left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = t.out_reason
  493. Left join dkic_b.t_mst_supplier tmp on tmp.sup_id = t.sup_id
  494. WHERE t.out_id = #{id}::uuid
  495. </select>
  496. <!-- 获取出库信息(新建退货用) -->
  497. <select id="selectByIdForReturn" resultMap="BaseResultMapResponse">
  498. SELECT t.out_id,
  499. t.out_no,
  500. t.out_type,
  501. t.from_id,
  502. t.from_no,
  503. t.from_no as "orderNo",
  504. t.org_id,
  505. tmo.org_name as "orgName",
  506. t.staff_id,
  507. tms.staff_name as "staffName",
  508. t.cus_id,
  509. tmc.cus_code as "cusCode",
  510. tmc.cus_name as "cusName",
  511. tmc.cus_phone as "cusPhone",
  512. tmc.cus_from as "cusFrom",
  513. tmc.contact_phone as "contactPhone",
  514. tmc.address_full as "addressFull",
  515. tmdd.data_value as cus_from_name,
  516. tmc.address_area,
  517. tmc.address_name,
  518. tmc.address_no,
  519. tmc.address_gcj02,
  520. tmc.address_full,
  521. tmc.contact_name,
  522. tmc.contact_phone,
  523. tmc.channel_id as sales_channel,
  524. tmsc.channel_name as channel_name,
  525. t.sup_id,
  526. t.out_status,
  527. sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "outStatusName",
  528. sys.f_remove_zero(t.outing_qty) as outing_qty,
  529. t.outing_amt,
  530. sys.f_remove_zero(t.out_qty) as out_qty,
  531. t.out_amt,
  532. sys.f_remove_zero(t.return_qty) as return_qty,
  533. t.return_amt,
  534. t.out_date,
  535. t.remarks,
  536. t.annex_paths,
  537. t.make_staff,
  538. makestaff.staff_name as "makeStaffName",
  539. t.make_time,
  540. t.receivable_id,
  541. t.cp_id,
  542. t.flg_valid,
  543. tmd.data_value as out_reason_name
  544. FROM dkic_b.t_psi_outbound as t
  545. left join dkic_b.t_mst_customer tmc on tmc.cus_id = t.cus_id
  546. left join dkic_b.t_mst_sale_channel tmsc on tmsc.channel_id = tmc.channel_id
  547. left join dkic_b.t_mst_org tmo on tmo.org_id = t.org_id
  548. left join dkic_b.t_mst_staff tms on tms.staff_id = t.staff_id
  549. left join dkic_b.t_mst_staff as makestaff on makestaff.staff_id = t.make_staff
  550. left join dkic_b.t_mst_dictionary_data tmdd on tmdd.data_id = tmc.cus_from
  551. left join sys.t_data_kind as tdk1 on tdk1.kind_code = t.out_status
  552. left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = t.out_reason
  553. WHERE t.out_id = #{id}::uuid
  554. </select>
  555. <!-- 根据主键锁定表dkic_b.t_psi_outbound的一行数据 -->
  556. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  557. SELECT
  558. <include refid="Base_Column_List"/>
  559. FROM dkic_b.t_psi_outbound
  560. WHERE out_id = #{id}::uuid
  561. for update
  562. </select>
  563. <!-- 根据主键锁定表dkic_b.t_psi_outbound的多行数据 -->
  564. <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
  565. SELECT
  566. <include refid="Base_Column_List"/>
  567. FROM dkic_b.t_psi_outbound
  568. <include refid="idsForeach"/>
  569. for update
  570. </select>
  571. <insert id="insertBatch">
  572. insert into dkic_b.t_psi_outbound
  573. (
  574. <trim suffixOverrides=",">
  575. out_no,
  576. out_type,
  577. from_id,
  578. from_no,
  579. org_id,
  580. staff_id,
  581. order_id,
  582. order_no,
  583. into_return_id,
  584. into_return_no,
  585. cus_id,
  586. sup_id,
  587. out_status,
  588. outing_qty,
  589. outing_amt,
  590. out_qty,
  591. out_amt,
  592. return_qty,
  593. return_amt,
  594. out_date,
  595. remarks,
  596. annex_paths,
  597. make_staff,
  598. make_time,
  599. receivable_id,
  600. cp_id,
  601. op_app_code,
  602. </trim>
  603. )
  604. values
  605. <foreach collection="list" index="index" item="item" separator=",">
  606. (
  607. <trim suffixOverrides=",">
  608. #{item.outNo},
  609. #{item.outType},
  610. #{item.fromId}::uuid,
  611. #{item.fromNo},
  612. #{item.orgId}::uuid,
  613. #{item.staffId}::uuid,
  614. #{item.cusId}::uuid,
  615. #{item.supId}::uuid,
  616. #{item.outStatus},
  617. #{item.outingQty},
  618. #{item.outingAmt},
  619. #{item.outQty},
  620. #{item.outAmt},
  621. #{item.returnQty},
  622. #{item.returnAmt},
  623. #{item.outDate},
  624. #{item.remarks},
  625. #{item.annexPaths},
  626. #{item.makeStaff}::uuid,
  627. #{item.makeTime},
  628. #{item.receivableId}::uuid,
  629. #{item.cpId},
  630. #{item.opAppCode},
  631. </trim>
  632. )
  633. </foreach>
  634. </insert>
  635. <!-- 根据id查询带出销售退货单数据(销售退货出库办理用)-->
  636. <select id="selectMessageByOtherQuery" resultMap="BaseResultMapResponse">
  637. SELECT
  638. <include refid="Base_Column_List_Response"/>
  639. ,tmo.org_name
  640. ,tms.staff_name as "staffName"
  641. ,tmc.cus_code
  642. ,tmc.cus_name
  643. ,tmc.cus_phone
  644. ,tmc.contact_phone
  645. ,tmc.contact_name
  646. ,tmc.address_area
  647. ,tmc.address_name
  648. ,tmc.address_no
  649. ,tmc.address_gcj02
  650. ,tmc.address_full
  651. ,tmsc.channel_name
  652. ,tmsc.channel_name
  653. ,tmsc.channel_name
  654. ,tmd.data_value as cus_from_name
  655. FROM dkic_b.t_psi_outbound tpo
  656. Left join dkic_b.t_mst_org tmo on tmo.org_id = tpo.org_id
  657. Left join dkic_b.t_mst_staff tms on tms.staff_id = tpo.staff_id
  658. left join dkic_b.t_mst_customer tmc on tpo.cus_id = tmc.cus_id
  659. left join dkic_b.t_mst_sale_channel tmsc on tmc.channel_id = tmsc.channel_id
  660. left join dkic_b.t_mst_dictionary_data tmd on tmc.cus_from = tmd.data_id
  661. <where>
  662. <if test="outId != null and outId != ''">
  663. AND tpo.out_id = #{outId}::uuid
  664. </if>
  665. <if test="outStatus != null and outStatus != ''">
  666. AND tpo.out_status = #{outStatus}
  667. </if>
  668. </where>
  669. </select>
  670. <!--修改退货信息 -->
  671. <update id="updateReturnMessage" parameterType="com.dk.mdm.model.pojo.sale.OrderItem">
  672. update dkic_b.t_psi_outbound
  673. <set>
  674. <if test="returnQty != null">
  675. return_qty = return_qty + #{returnQty,jdbcType=NUMERIC},
  676. </if>
  677. <if test="returnAmt != null">
  678. return_amt = return_amt + #{returnAmt,jdbcType=NUMERIC},
  679. </if>
  680. </set>
  681. where out_id = #{outId,typeHandler=UuidTypeHandler}
  682. and out_qty >= return_qty
  683. </update>
  684. <!-- 出库办理显示字段 -->
  685. <sql id="Base_Column_List_Response_Out">
  686. tpo.out_id ,
  687. tpo.out_no ,
  688. tpo.out_type ,
  689. tpo.from_id,
  690. tpo.from_no,
  691. tpo.org_id,
  692. tpo.staff_id,
  693. tpo.cus_id,
  694. tpo.sup_id,
  695. tpo.out_status,
  696. sys.f_remove_zero(tpo.outing_qty) as outing_qty ,
  697. tpo.outing_amt,
  698. sys.f_remove_zero(tpo.out_qty) as out_qty ,
  699. tpo.out_amt ,
  700. sys.f_remove_zero(tpo.return_qty) as return_qty,
  701. tpo.return_amt,
  702. tpo.out_date ,
  703. tpo.remarks,
  704. tpo.annex_paths,
  705. tpo.make_staff,
  706. tpo.make_time,
  707. tpo.out_reason,
  708. tpo.flg_valid,
  709. tpo.flg_auto_handle,
  710. tpo.flg_handle_setting,
  711. tpo.op_update_time
  712. </sql>
  713. <sql id="Base_Column_List_Response_Into">
  714. tpi.into_id as out_id,
  715. tpi.into_no as out_no,
  716. tpi.into_type as out_type,
  717. tpi.from_id,
  718. tpi.from_no,
  719. tpi.org_id,
  720. tpi.staff_id,
  721. tpi.cus_id,
  722. tpi.sup_id,
  723. tpi.into_status as out_status ,
  724. sys.f_remove_zero(tpi.intoing_qty) as outing_qty ,
  725. tpi.intoing_amt as outing_amt ,
  726. sys.f_remove_zero(tpi.into_qty) as out_qty ,
  727. tpi.into_amt as out_amt,
  728. sys.f_remove_zero(tpi.return_qty) as return_qty,
  729. tpi.return_amt,
  730. tpi.into_date as out_date,
  731. tpi.remarks,
  732. tpi.annex_paths,
  733. tpi.make_staff,
  734. tpi.make_time,
  735. tpi.into_reason as out_reason,
  736. tpi.flg_valid,
  737. tpi.flg_auto_handle,
  738. tpi.flg_handle_setting,
  739. tpi.op_update_time
  740. </sql>
  741. <!-- 条件查询 web端入库办理用,-->
  742. <select id="selectOutbound" resultMap="BaseResultMapResponse">
  743. select * from (
  744. select
  745. <include refid="Base_Column_List_Response_Out"/>,
  746. tmo.org_name AS "orgName",
  747. tmp.sup_name AS "supplierName",
  748. tms.staff_name AS "staffName",
  749. tms.staff_name AS "makeStaffName",
  750. tmc.cus_name as "cusName",
  751. tmc.cus_phone as "cusPhone",
  752. tmc.cus_from as "cusFrom",
  753. makestaff.staff_name as "makeStaffName",
  754. sys.f_get_name_i18n(tdktype.kind_name_i18n, #{i18n}) AS "outTypeName",
  755. sys.f_get_name_i18n(tdk.kind_name_i18n, #{i18n}) AS "outStatusName",
  756. tmd.data_value as out_reason_name
  757. from dkic_b.t_psi_outbound tpo
  758. <include refid="Select_Inbound_Join_Table_Out"/>
  759. <where>
  760. AND tpo.cp_id = #{cpId}
  761. <if test="outTypes != null and outTypes.size()>0">
  762. AND tpo.out_type =any(#{outTypes,typeHandler=StringListTypeHandler})
  763. </if>
  764. <if test="outTypes == null || outTypes.size()==0">
  765. AND (tpo.out_type = '出库类型-其他出库'
  766. or tpo.out_type = '出库类型-销售出库')
  767. </if>
  768. <if test="outStatus != null and outStatus != '' ">
  769. AND tpo.out_status LIKE concat('%',my_ex.likequery(#{outStatus}),'%')
  770. </if>
  771. <if test="makeTimeStart != null and makeTimeEnd != null">
  772. AND tpo.make_time &gt;= #{makeTimeStart}::timestamp with time zone
  773. AND tpo.make_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
  774. </if>
  775. <if test="outNo != null and outNo != ''">
  776. AND tpo.out_no LIKE concat('%',my_ex.likequery(#{outNo}),'%')
  777. </if>
  778. <if test="cusPhone != null and cusPhone != ''">
  779. AND tmc.cus_phone LIKE concat('%',my_ex.likequery(#{cusPhone}),'%')
  780. </if>
  781. <if test="cusName != null and cusName != ''">
  782. AND tmc.cus_name LIKE concat('%',my_ex.likequery(#{cusName}),'%')
  783. </if>
  784. <if test="supId != null and supId != ''">
  785. AND tpo.sup_id = #{supId}::uuid
  786. </if>
  787. <if test="orgIdList != null and orgIdList.size() > 0">
  788. AND tmo.org_id =any(#{orgIdList, typeHandler=uuidListTypeHandler})
  789. </if>
  790. <if test="staffIdList != null and staffIdList.size() > 0">
  791. AND tms.staff_id =any(#{staffIdList, typeHandler=uuidListTypeHandler})
  792. </if>
  793. <if test="flgValidList != null and flgValidList.size()>0">
  794. AND tpo.flg_valid =any(#{flgValidList, typeHandler=BooleanListTypeHandler})
  795. </if>
  796. </where>
  797. union all
  798. SELECT
  799. <include refid="Base_Column_List_Response_Into"/>,
  800. tmo.org_name AS "orgName",
  801. tmp.sup_name AS "supplierName",
  802. tms.staff_name AS "staffName",
  803. tms.staff_name AS "makeStaffName",
  804. tmc.cus_name as "cusName",
  805. tmc.cus_phone as "cusPhone",
  806. tmc.cus_from as "cusFrom",
  807. makestaff.staff_name as "makeStaffName",
  808. sys.f_get_name_i18n(tdktype.kind_name_i18n, #{i18n}) AS "outTypeName",
  809. sys.f_get_name_i18n(tdk.kind_name_i18n, #{i18n}) AS "outStatusName",
  810. tmd.data_value as out_reason_name
  811. FROM dkic_b.t_psi_inbound tpi
  812. <include refid="Select_Inbound_Join_Table_Into"/>
  813. <where>
  814. AND tpi.cp_id = #{cpId}
  815. <if test="outTypes != null and outTypes.size()>0">
  816. AND tpi.into_type =any(#{outTypes,typeHandler=StringListTypeHandler})
  817. </if>
  818. <if test="outTypes == null || outTypes.size()==0">
  819. AND tpi.into_type = '入库类型-采退入库'
  820. </if>
  821. <if test="intoStatus != null and intoStatus != '' ">
  822. AND tpi.into_status LIKE concat('%',my_ex.likequery(#{intoStatus}),'%')
  823. </if>
  824. <if test="makeTimeStart != null and makeTimeEnd != null">
  825. AND tpi.make_time &gt;= #{makeTimeStart}::timestamp with time zone
  826. AND tpi.make_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
  827. </if>
  828. <if test="outNo != null and outNo != ''">
  829. AND tpi.into_no LIKE concat('%',my_ex.likequery(#{outNo}),'%')
  830. </if>
  831. <if test="cusPhone != null and cusPhone != ''">
  832. AND tmc.cus_phone LIKE concat('%',my_ex.likequery(#{cusPhone}),'%')
  833. </if>
  834. <if test="cusName != null and cusName != ''">
  835. AND tmc.cus_name LIKE concat('%',my_ex.likequery(#{cusName}),'%')
  836. </if>
  837. <if test="supId != null and supId != ''">
  838. AND tpi.sup_id = #{supId}::uuid
  839. </if>
  840. <if test="orgIdList != null and orgIdList.size() > 0">
  841. AND tmo.org_id =any(#{orgIdList, typeHandler=uuidListTypeHandler})
  842. </if>
  843. <if test="staffIdList != null and staffIdList.size() > 0">
  844. AND tms.staff_id =any(#{staffIdList, typeHandler=uuidListTypeHandler})
  845. </if>
  846. <if test="flgValidList != null and flgValidList.size()>0">
  847. AND tpi.flg_valid =any(#{flgValidList, typeHandler=BooleanListTypeHandler})
  848. </if>
  849. </where>
  850. ) tt order by tt.op_update_time desc
  851. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  852. limit #{end} offset #{start}
  853. </if>
  854. </select>
  855. <!-- 条件查询 web端入库办理用个数 -->
  856. <select id="selectOutboundCond" resultType="Long">
  857. SELECT
  858. count(1) from (
  859. select
  860. <include refid="Base_Column_List_Response_Out"/>,
  861. tmo.org_name AS "orgName",
  862. tmp.sup_name AS "supplierName",
  863. tms.staff_name AS "staffName",
  864. tms.staff_name AS "makeStaffName",
  865. tmc.cus_name as "cusName",
  866. tmc.cus_phone as "cusPhone",
  867. tmc.cus_from as "cusFrom",
  868. makestaff.staff_name as "makeStaffName",
  869. sys.f_get_name_i18n(tdktype.kind_name_i18n, #{i18n}) AS "outTypeName",
  870. sys.f_get_name_i18n(tdk.kind_name_i18n, #{i18n}) AS "outStatusName",
  871. tmd.data_value as out_reason_name
  872. from dkic_b.t_psi_outbound tpo
  873. <include refid="Select_Inbound_Join_Table_Out"/>
  874. <where>
  875. AND tpo.cp_id = #{cpId}
  876. <if test="outTypes != null and outTypes.size()>0">
  877. AND tpo.out_type =any(#{outTypes,typeHandler=StringListTypeHandler})
  878. </if>
  879. <if test="outTypes == null || outTypes.size()==0">
  880. AND (tpo.out_type = '出库类型-其他出库'
  881. or tpo.out_type = '出库类型-销售出库')
  882. </if>
  883. <if test="outStatus != null and outStatus != '' ">
  884. AND tpo.out_status LIKE concat('%',my_ex.likequery(#{outStatus}),'%')
  885. </if>
  886. <if test="makeTimeStart != null and makeTimeEnd != null">
  887. AND tpo.make_time &gt;= #{makeTimeStart}::timestamp with time zone
  888. AND tpo.make_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
  889. </if>
  890. <if test="outNo != null and outNo != ''">
  891. AND tpo.out_no LIKE concat('%',my_ex.likequery(#{outNo}),'%')
  892. </if>
  893. <if test="cusPhone != null and cusPhone != ''">
  894. AND tmc.cus_phone LIKE concat('%',my_ex.likequery(#{cusPhone}),'%')
  895. </if>
  896. <if test="cusName != null and cusName != ''">
  897. AND tmc.cus_name LIKE concat('%',my_ex.likequery(#{cusName}),'%')
  898. </if>
  899. <if test="supId != null and supId != ''">
  900. AND tpo.sup_id = #{supId}::uuid
  901. </if>
  902. <if test="orgIdList != null and orgIdList.size() > 0">
  903. AND tmo.org_id =any(#{orgIdList, typeHandler=uuidListTypeHandler})
  904. </if>
  905. <if test="staffIdList != null and staffIdList.size() > 0">
  906. AND tms.staff_id =any(#{staffIdList, typeHandler=uuidListTypeHandler})
  907. </if>
  908. <if test="flgValidList != null and flgValidList.size()>0">
  909. AND tpo.flg_valid =any(#{flgValidList, typeHandler=BooleanListTypeHandler})
  910. </if>
  911. </where>
  912. union all
  913. SELECT
  914. <include refid="Base_Column_List_Response_Into"/>,
  915. tmo.org_name AS "orgName",
  916. tmp.sup_name AS "supplierName",
  917. tms.staff_name AS "staffName",
  918. tms.staff_name AS "makeStaffName",
  919. tmc.cus_name as "cusName",
  920. tmc.cus_phone as "cusPhone",
  921. tmc.cus_from as "cusFrom",
  922. makestaff.staff_name as "makeStaffName",
  923. sys.f_get_name_i18n(tdktype.kind_name_i18n, #{i18n}) AS "outTypeName",
  924. sys.f_get_name_i18n(tdk.kind_name_i18n, #{i18n}) AS "outStatusName",
  925. tmd.data_value as out_reason_name
  926. FROM dkic_b.t_psi_inbound tpi
  927. <include refid="Select_Inbound_Join_Table_Into"/>
  928. <where>
  929. AND tpi.cp_id = #{cpId}
  930. <if test="outTypes != null and outTypes.size()>0">
  931. AND tpi.into_type =any(#{outTypes,typeHandler=StringListTypeHandler})
  932. </if>
  933. <if test="outTypes == null || outTypes.size()==0">
  934. AND tpi.into_type = '入库类型-采退入库'
  935. </if>
  936. <if test="intoStatus != null and intoStatus != '' ">
  937. AND tpi.into_status LIKE concat('%',my_ex.likequery(#{intoStatus}),'%')
  938. </if>
  939. <if test="makeTimeStart != null and makeTimeEnd != null">
  940. AND tpi.make_time &gt;= #{makeTimeStart}::timestamp with time zone
  941. AND tpi.make_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
  942. </if>
  943. <if test="outNo != null and outNo != ''">
  944. AND tpi.into_no LIKE concat('%',my_ex.likequery(#{outNo}),'%')
  945. </if>
  946. <if test="cusPhone != null and cusPhone != ''">
  947. AND tmc.cus_phone LIKE concat('%',my_ex.likequery(#{cusPhone}),'%')
  948. </if>
  949. <if test="cusName != null and cusName != ''">
  950. AND tmc.cus_name LIKE concat('%',my_ex.likequery(#{cusName}),'%')
  951. </if>
  952. <if test="supId != null and supId != ''">
  953. AND tpi.sup_id = #{supId}::uuid
  954. </if>
  955. <if test="orgIdList != null and orgIdList.size() > 0">
  956. AND tmo.org_id =any(#{orgIdList, typeHandler=uuidListTypeHandler})
  957. </if>
  958. <if test="staffIdList != null and staffIdList.size() > 0">
  959. AND tms.staff_id =any(#{staffIdList, typeHandler=uuidListTypeHandler})
  960. </if>
  961. <if test="flgValidList != null and flgValidList.size()>0">
  962. AND tpi.flg_valid =any(#{flgValidList, typeHandler=BooleanListTypeHandler})
  963. </if>
  964. </where>
  965. ) tt
  966. </select>
  967. <!--出库办理显示出库关联表-->
  968. <sql id="Select_Inbound_Join_Table_Out">
  969. Left join dkic_b.t_mst_org tmo on tmo.org_id = tpo.org_id
  970. Left join dkic_b.t_mst_supplier tmp on tmp.sup_id = tpo.sup_id
  971. Left join dkic_b.t_mst_staff tms on tms.staff_id = tpo.staff_id
  972. Left join dkic_b.t_mst_staff makestaff on makestaff.staff_id = tpo.make_staff
  973. LEFT JOIN sys.t_data_kind tdk ON tdk.kind_code = tpo.out_status
  974. LEFT JOIN sys.t_data_kind tdktype ON tdktype.kind_code = tpo.out_type
  975. left join dkic_b.t_mst_customer tmc on tpo.cus_id = tmc.cus_id
  976. left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = tpo.out_reason
  977. </sql>
  978. <!--出库办理显示入库关联表-->
  979. <sql id="Select_Inbound_Join_Table_Into">
  980. Left join dkic_b.t_mst_org tmo on tmo.org_id = tpi.org_id
  981. Left join dkic_b.t_mst_supplier tmp on tmp.sup_id = tpi.sup_id
  982. Left join dkic_b.t_mst_staff tms on tms.staff_id = tpi.staff_id
  983. Left join dkic_b.t_mst_staff makestaff on makestaff.staff_id = tpi.make_staff
  984. LEFT JOIN sys.t_data_kind tdk ON tdk.kind_code = tpi.into_status
  985. LEFT JOIN sys.t_data_kind tdktype ON tdktype.kind_code = tpi.into_type
  986. left join dkic_b.t_mst_customer tmc on tpi.cus_id = tmc.cus_id
  987. left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = tpi.into_reason
  988. </sql>
  989. <!-- 根据来源id查询 -->
  990. <select id="selectByFromId" resultMap="BaseResultMapResponse">
  991. SELECT
  992. <include refid="Base_Column_List_Response"/>
  993. FROM dkic_b.t_psi_outbound tpo
  994. WHERE tpo.from_id = #{fromId}::uuid
  995. and tpo.flg_valid
  996. </select>
  997. <!-- 查询总单带明细 -->
  998. <select id="selectByCondDetail" resultMap="BaseResultMapDetailResponse">
  999. SELECT t.out_id,
  1000. t.out_no,
  1001. t.out_type,
  1002. t.from_id,
  1003. t.from_no,
  1004. t.from_no as "orderNo",
  1005. t.org_id,
  1006. tmo.org_name as "orgName",
  1007. t.staff_id,
  1008. tms.staff_name as "staffName",
  1009. t.cus_id,
  1010. tmc.cus_code as "cusCode",
  1011. tmc.cus_name as "cusName",
  1012. tmc.cus_phone as "cusPhone",
  1013. tmc.cus_from as "cusFrom",
  1014. tmc.contact_phone as "contactPhone",
  1015. tmc.address_full as "addressFull",
  1016. tmdd.data_value as cus_from_name,
  1017. tmc.address_area,
  1018. tmc.address_name,
  1019. tmc.address_no,
  1020. tmc.address_gcj02,
  1021. tmc.address_full,
  1022. tmc.contact_name,
  1023. tmc.contact_phone,
  1024. tmc.channel_id as sales_channel,
  1025. tmsc.channel_name as channel_name,
  1026. t.sup_id,
  1027. t.out_status,
  1028. sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "outStatusName",
  1029. sys.f_remove_zero(t.outing_qty) as outing_qty,
  1030. t.outing_amt,
  1031. sys.f_remove_zero(t.out_qty) as out_qty,
  1032. t.out_amt,
  1033. sys.f_remove_zero(t.return_qty) as return_qty,
  1034. t.return_amt,
  1035. t.out_date,
  1036. t.remarks,
  1037. t.annex_paths,
  1038. t.make_staff,
  1039. makestaff.staff_name as "makeStaffName",
  1040. t.make_time,
  1041. t.receivable_id,
  1042. t.cp_id,
  1043. t.flg_valid,
  1044. tmp.sup_name AS "supplierName",
  1045. t.out_reason,
  1046. t.flg_auto_handle,
  1047. t.flg_handle_setting,
  1048. tmd.data_value as out_reason_name,
  1049. <include refid="Base_Column_List_Item_Response_Detail_Join"/>
  1050. FROM dkic_b.t_psi_outbound as t
  1051. left join dkic_b.t_mst_customer tmc on tmc.cus_id = t.cus_id
  1052. left join dkic_b.t_mst_sale_channel tmsc on tmsc.channel_id = tmc.channel_id
  1053. left join dkic_b.t_mst_org tmo on tmo.org_id = t.org_id
  1054. left join dkic_b.t_mst_staff tms on tms.staff_id = t.staff_id
  1055. left join dkic_b.t_mst_staff as makestaff on makestaff.staff_id = t.make_staff
  1056. left join dkic_b.t_mst_dictionary_data tmdd on tmdd.data_id = tmc.cus_from
  1057. left join sys.t_data_kind as tdk1 on tdk1.kind_code = t.out_status
  1058. left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = t.out_reason
  1059. left join dkic_b.t_psi_outbound_item tpoi on tpoi.out_id = t.out_id
  1060. Left join dkic_b.t_mst_supplier tmp on tmp.sup_id = tpoi.sup_id
  1061. left join dkic_b.t_psi_inventory tpi on tpi.inv_id = tpoi.inv_id
  1062. left join dkic_b.t_mst_unit as tmgu on tpoi.unit_id = tmgu.unit_id
  1063. left join dkic_b.t_mst_unit as tmgus on tpoi.sub_unit_id = tmgus.unit_id
  1064. left join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tpoi.sku_id
  1065. left join dkic_b.t_mst_goods_brand tmgb on tmgb.brand_id = tmgs.brand_id
  1066. left join dkic_b.t_psi_inventory tpity on tpity.inv_id = tpoi.inv_id
  1067. left join dkic_b.t_mst_warehouse as tmw on tpity.wh_id = tmw.wh_id
  1068. <include refid="Condition"/>
  1069. order by t.make_time desc
  1070. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  1071. limit #{end} offset #{start}
  1072. </if>
  1073. </select>
  1074. <sql id="Base_Column_List_Item_Response_Detail_Join">
  1075. tpoi.item_id AS "list_item_id",
  1076. tpoi.out_id AS "list_out_id",
  1077. tpoi.sup_id AS "list_sup_id",
  1078. t.out_no AS "list_out_no",
  1079. tpoi.out_type AS "list_out_type",
  1080. tpoi.from_id AS "list_from_id",
  1081. tpoi.from_item_id AS "list_from_item_id",
  1082. tpoi.item_index AS "list_item_index",
  1083. tpoi.sku_id AS "list_sku_id",
  1084. tpoi.price_out AS "list_price_out",
  1085. tpoi.non_std_code AS "list_non_std_code",
  1086. tpoi.out_status AS "list_out_status",
  1087. sys.f_remove_zero(tpoi.outing_qty) AS "list_outing_qty",
  1088. tpoi.outing_amt AS "list_outing_amt",
  1089. sys.f_remove_zero(tpoi.out_qty) AS "list_out_qty",
  1090. tpoi.out_amt AS "list_out_amt",
  1091. sys.f_remove_zero(tpoi.return_qty) AS "list_return_qty",
  1092. tpoi.return_amt AS "list_return_amt",
  1093. tpoi.remarks AS "list_remarks",
  1094. tpoi.inv_id AS "list_inv_id",
  1095. tpoi.cost_price AS "list_cost_price",
  1096. tpoi.cost_amt AS "list_cost_amt",
  1097. tpoi.flg_valid AS "list_flg_valid",
  1098. tpoi.cp_id AS "list_cp_id",
  1099. tpoi.s_out_id AS "list_s_out_id",
  1100. tpoi.s_out_item_id AS "list_s_out_item_id",
  1101. tpoi.s_order_id AS "list_s_order_id",
  1102. tpoi.s_order_item_id AS "list_s_order_item_id",
  1103. tmgs.sku_code AS list_sku_code,
  1104. tpoi.sku_model AS list_sku_model,
  1105. tpoi.sku_name AS list_sku_name,
  1106. tmgs.sku_spec AS list_sku_spec,
  1107. case when tpoi.sku_id is null then tmp.sup_name || '(外协)' else tmgb.brand_name end AS list_brand_name,
  1108. tmgb.short_name AS list_short_name,
  1109. tmgs.price_purchase AS list_price_purchase,
  1110. tmgs.price_standard AS list_price_standard,
  1111. tmgs.sku_images AS list_sku_images,
  1112. tpity.wh_id AS list_wh_id,
  1113. tmw.wh_name AS list_wh_name
  1114. ,sys.f_remove_zero(tpi.inv_qty) as "list_invQty"
  1115. ,sys.f_remove_zero(tpi.usable_qty) as "list_usableQty"
  1116. ,tmgus.unit_name as "list_subUnitName"
  1117. ,tmgu.unit_name as "list_unitName"
  1118. ,tpoi.pack_box as "list_pack_box"
  1119. ,tmgs.flg_sub_unit as "list_flgSubUnit"
  1120. ,tpoi.outing_box as "list_outing_box"
  1121. ,tpoi.outing_piece as "list_outing_piece"
  1122. ,tpoi.out_box as "list_out_box"
  1123. ,tpoi.out_piece as "list_out_piece"
  1124. ,case when t.out_status = '出库状态-已出库' then dkic_b.f_box_piece(tmgus.unit_name,tmgu.unit_name,tpoi.out_box,tpoi.out_piece)
  1125. else dkic_b.f_box_piece(tmgus.unit_name,tmgu.unit_name,tpoi.outing_box,tpoi.outing_piece) end as "list_pack_box_text"
  1126. ,tmgu.decimal_places as "list_decimal_places"
  1127. </sql>
  1128. <select id="countByCondDetail" resultType="Long">
  1129. SELECT
  1130. count(1)
  1131. FROM dkic_b.t_psi_outbound as t
  1132. left join dkic_b.t_mst_customer tmc on tmc.cus_id = t.cus_id
  1133. left join dkic_b.t_mst_sale_channel tmsc on tmsc.channel_id = tmc.channel_id
  1134. left join dkic_b.t_mst_org tmo on tmo.org_id = t.org_id
  1135. left join dkic_b.t_mst_staff tms on tms.staff_id = t.staff_id
  1136. left join dkic_b.t_mst_staff as makestaff on makestaff.staff_id = t.make_staff
  1137. left join dkic_b.t_mst_dictionary_data tmdd on tmdd.data_id = tmc.cus_from
  1138. left join sys.t_data_kind as tdk1 on tdk1.kind_code = t.out_status
  1139. left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = t.out_reason
  1140. Left join dkic_b.t_mst_supplier tmp on tmp.sup_id = t.sup_id
  1141. left join dkic_b.t_psi_outbound_item tpoi on tpoi.out_id = t.out_id
  1142. left join dkic_b.t_psi_inventory tpi on tpi.inv_id = tpoi.inv_id
  1143. left join dkic_b.t_mst_unit as tmgu on tpoi.unit_id = tmgu.unit_id
  1144. left join dkic_b.t_mst_unit as tmgus on tpoi.sub_unit_id = tmgus.unit_id
  1145. left join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tpoi.sku_id
  1146. left join dkic_b.t_mst_goods_brand tmgb on tmgb.brand_id = tmgs.brand_id
  1147. left join dkic_b.t_psi_inventory tpity on tpity.inv_id = tpoi.inv_id
  1148. left join dkic_b.t_mst_warehouse as tmw on tpity.wh_id = tmw.wh_id
  1149. <include refid="Condition"/>
  1150. </select>
  1151. </mapper>