OutboundMapper.xml 58 KB

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