InboundMapper.xml 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081
  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.InboundMapper">
  4. <!-- 通用设置 -->
  5. <!-- 通用查询列 -->
  6. <sql id="Base_Column_List">
  7. into_id ,into_no, into_type, from_id, from_no, org_id, staff_id, cus_id, sup_id,
  8. into_status, intoing_qty, intoing_amt, into_qty, into_amt, return_qty,
  9. return_amt, into_date, remarks, annex_paths, make_staff, make_time,
  10. receivable_id, flg_valid, cp_id, op_create_time, op_create_user_id,
  11. op_update_time, op_update_user_id, op_app_code, op_timestamp, op_db_user,wh_id,
  12. into_reason,flg_auto_handle,flg_handle_setting,flg_neg_into
  13. </sql>
  14. <!-- response通用查询列 -->
  15. <sql id="Base_Column_List_Response">
  16. tpi.into_id, tpi.into_no, tpi.into_type, tpi.from_id, tpi.from_no, tpi.org_id, tpi.staff_id,
  17. tpi.cus_id, tpi.sup_id, tpi.into_status, tpi.intoing_qty, tpi.intoing_amt, tpi.into_qty,
  18. tpi.into_amt, tpi.return_qty, tpi.return_amt, tpi.into_date, tpi.remarks, tpi.annex_paths,
  19. tpi.make_staff, tpi.make_time, tpi.receivable_id, tpi.flg_valid, tpi.cp_id,
  20. tpi.wh_id,tpi.into_reason,tpi.flg_auto_handle,tpi.flg_handle_setting,tpi.flg_neg_into
  21. </sql>
  22. <!-- 通用查询映射结果 -->
  23. <resultMap id="BaseResultMap" type="com.dk.mdm.model.pojo.ivt.Inbound">
  24. <id column="into_id" property="intoId" typeHandler="UuidTypeHandler"/>
  25. <result column="into_no" property="intoNo"/>
  26. <result column="into_type" property="intoType"/>
  27. <result column="from_id" property="fromId" typeHandler="UuidTypeHandler"/>
  28. <result column="from_no" property="fromNo"/>
  29. <result column="org_id" property="orgId" typeHandler="UuidTypeHandler"/>
  30. <result column="staff_id" property="staffId" typeHandler="UuidTypeHandler"/>
  31. <result column="cus_id" property="cusId" typeHandler="UuidTypeHandler"/>
  32. <result column="sup_id" property="supId" typeHandler="UuidTypeHandler"/>
  33. <result column="into_status" property="intoStatus"/>
  34. <result column="intoing_qty" property="intoingQty"/>
  35. <result column="intoing_amt" property="intoingAmt"/>
  36. <result column="into_qty" property="intoQty"/>
  37. <result column="into_amt" property="intoAmt"/>
  38. <result column="return_qty" property="returnQty"/>
  39. <result column="return_amt" property="returnAmt"/>
  40. <result column="into_date" property="intoDate" typeHandler="TimestampTypeHandler"/>
  41. <result column="remarks" property="remarks"/>
  42. <result column="annex_paths" property="annexPaths" typeHandler="JsonTypeHandler"/>
  43. <result column="make_staff" property="makeStaff" typeHandler="UuidTypeHandler"/>
  44. <result column="make_time" property="makeTime" typeHandler="TimestampTypeHandler"/>
  45. <result column="receivable_id" property="receivableId" typeHandler="UuidTypeHandler"/>
  46. <result column="flg_valid" property="flgValid"/>
  47. <result column="cp_id" property="cpId"/>
  48. <result column="op_create_time" property="opCreateTime" typeHandler="TimestampTypeHandler"/>
  49. <result column="op_create_user_id" property="opCreateUserId" typeHandler="UuidTypeHandler"/>
  50. <result column="op_update_time" property="opUpdateTime" typeHandler="TimestampTypeHandler"/>
  51. <result column="op_update_user_id" property="opUpdateUserId" typeHandler="UuidTypeHandler"/>
  52. <result column="op_app_code" property="opAppCode"/>
  53. <result column="op_timestamp" property="opTimestamp" typeHandler="TimestampTypeHandler"/>
  54. <result column="op_db_user" property="opDbUser"/>
  55. <result column="into_reason" property="intoReason" typeHandler="UuidTypeHandler"/>
  56. <result column="wh_id" property="whId"/>
  57. <result column="flg_auto_handle" property="flgAutoHandle"/>
  58. <result column="flg_handle_setting" property="flgHandleSetting"/>
  59. <result column="flg_neg_into" property="flgNegInto"/>
  60. </resultMap>
  61. <!-- response查询映射结果 -->
  62. <resultMap id="BaseResultMapResponse" type="com.dk.mdm.model.response.ivt.InboundResponse">
  63. <id column="into_id" property="intoId" typeHandler="UuidTypeHandler"/>
  64. <result column="into_no" property="intoNo"/>
  65. <result column="into_type" property="intoType"/>
  66. <result column="from_id" property="fromId" typeHandler="UuidTypeHandler"/>
  67. <result column="from_no" property="fromNo"/>
  68. <result column="org_id" property="orgId" typeHandler="UuidTypeHandler"/>
  69. <result column="staff_id" property="staffId" typeHandler="UuidTypeHandler"/>
  70. <result column="cus_id" property="cusId" typeHandler="UuidTypeHandler"/>
  71. <result column="sup_id" property="supId" typeHandler="UuidTypeHandler"/>
  72. <result column="into_status" property="intoStatus"/>
  73. <result column="intoing_qty" property="intoingQty"/>
  74. <result column="intoing_amt" property="intoingAmt"/>
  75. <result column="into_qty" property="intoQty"/>
  76. <result column="into_amt" property="intoAmt"/>
  77. <result column="wh_id" property="whId" typeHandler="UuidTypeHandler"/>
  78. <result column="return_qty" property="returnQty"/>
  79. <result column="return_amt" property="returnAmt"/>
  80. <result column="into_date" property="intoDate" typeHandler="TimestampTypeHandler"/>
  81. <result column="remarks" property="remarks"/>
  82. <result column="annex_paths" property="annexPaths" typeHandler="JsonTypeHandler"/>
  83. <result column="make_staff" property="makeStaff" typeHandler="UuidTypeHandler"/>
  84. <result column="make_time" property="makeTime" typeHandler="TimestampTypeHandler"/>
  85. <result column="receivable_id" property="receivableId" typeHandler="UuidTypeHandler"/>
  86. <result column="flg_valid" property="flgValid"/>
  87. <result column="cp_id" property="cpId"/>
  88. <result column="into_reason" property="intoReason" typeHandler="UuidTypeHandler"/>
  89. <result column="into_reason_name" property="intoReasonName" />
  90. <!-- <result column="orgName" property="orgName" />-->
  91. <!-- <result column="staff_name" property="staffName" />-->
  92. <result column="cus_code" property="cusCode" />
  93. <!-- <result column="cus_name" property="cusName" />-->
  94. <!-- <result column="cus_phone" property="cusPhone" />-->
  95. <result column="contact_phone" property="contactPhone" />
  96. <result column="contact_name" property="contactName" />
  97. <result column="address_area" property="addressArea" typeHandler="JsonTypeHandler"/>
  98. <result column="address_name" property="addressName"/>
  99. <result column="address_no" property="addressNo"/>
  100. <result column="address_gcj02" property="addressGcj02" typeHandler="JsonTypeHandler"/>
  101. <result column="address_full" property="addressFull"/>
  102. <result column="channel_name" property="channelName" />
  103. <result column="cus_from_name" property="cusFromName" />
  104. <result column="return_address" property="returnAddress" />
  105. <result column="flg_auto_handle" property="flgAutoHandle"/>
  106. <result column="flg_handle_setting" property="flgHandleSetting"/>
  107. <result column="flg_neg_into" property="flgNegInto"/>
  108. </resultMap>
  109. <!-- response明细通用查询列 -->
  110. <sql id="Base_Column_List_Item_Response">
  111. tpi.into_id
  112. , tpi.into_no, tpi.into_type, tpi.from_id, tpi.from_no, tpi.org_id, tpi.staff_id, tpi.cus_id, tpi.sup_id, tpi.into_status, tpi.intoing_qty, tpi.intoing_amt,
  113. tpi.into_qty, tpi.into_amt, tpi.return_qty, tpi.return_amt, tpi.into_date, tpi.remarks, tpi.annex_paths, tpi.make_staff, tpi.make_time,
  114. tpi.receivable_id, tpi.flg_valid, tpi.cp_id
  115. </sql>
  116. <!-- response明细关联明细映射-->
  117. <resultMap id="BaseResultMapItemResponse" type="com.dk.mdm.model.response.ivt.InboundResponse">
  118. <id column="into_id" property="intoId" typeHandler="UuidTypeHandler"/>
  119. <result column="into_no" property="intoNo"/>
  120. <result column="into_type" property="intoType"/>
  121. <result column="from_id" property="fromId" typeHandler="UuidTypeHandler"/>
  122. <result column="from_no" property="fromNo"/>
  123. <result column="org_id" property="orgId" typeHandler="UuidTypeHandler"/>
  124. <result column="staff_id" property="staffId" typeHandler="UuidTypeHandler"/>
  125. <result column="cus_id" property="cusId" typeHandler="UuidTypeHandler"/>
  126. <result column="sup_id" property="supId" typeHandler="UuidTypeHandler"/>
  127. <result column="into_status" property="intoStatus"/>
  128. <result column="intoing_qty" property="intoingQty"/>
  129. <result column="intoing_amt" property="intoingAmt"/>
  130. <result column="into_qty" property="intoQty"/>
  131. <result column="into_amt" property="intoAmt"/>
  132. <result column="return_qty" property="returnQty"/>
  133. <result column="return_amt" property="returnAmt"/>
  134. <result column="into_date" property="intoDate" typeHandler="TimestampTypeHandler"/>
  135. <result column="remarks" property="remarks"/>
  136. <result column="annex_paths" property="annexPaths" typeHandler="JsonTypeHandler"/>
  137. <result column="make_staff" property="makeStaff" typeHandler="UuidTypeHandler"/>
  138. <result column="make_time" property="makeTime" typeHandler="TimestampTypeHandler"/>
  139. <result column="receivable_id" property="receivableId" typeHandler="UuidTypeHandler"/>
  140. <result column="flg_valid" property="flgValid"/>
  141. <result column="cp_id" property="cpId"/>
  142. <collection property="inboundItemList" resultMap="inboundItemListMap" columnPrefix="list_"/>
  143. </resultMap>
  144. <!-- 关联映射-->
  145. <resultMap id="inboundItemListMap" type="java.util.Map">
  146. <result column="item_id" property="itemId" typeHandler="UuidTypeHandler"/>
  147. <result column="into_id" property="intoId" typeHandler="UuidTypeHandler"/>
  148. <result column="into_type" property="intoType"/>
  149. <result column="from_id" property="fromId" typeHandler="UuidTypeHandler"/>
  150. <result column="from_item_id" property="fromItemId" typeHandler="UuidTypeHandler"/>
  151. <result column="item_index" property="itemIndex"/>
  152. <result column="sku_id" property="skuId" typeHandler="UuidTypeHandler"/>
  153. <result column="item_qty" property="itemQty"/>
  154. <result column="price_into" property="priceInto"/>
  155. <result column="item_amt" property="itemAmt"/>
  156. <result column="non_std_code" property="nonStdCode"/>
  157. <result column="into_status" property="intoStatus"/>
  158. <result column="intoing_qty" property="intoingQty"/>
  159. <result column="intoing_amt" property="intoingAmt"/>
  160. <result column="into_qty" property="intoQty"/>
  161. <result column="into_amt" property="intoAmt"/>
  162. <result column="return_qty" property="returnQty"/>
  163. <result column="return_amt" property="returnAmt"/>
  164. <result column="remarks" property="remarks"/>
  165. <result column="inv_id" property="invId" typeHandler="UuidTypeHandler"/>
  166. <result column="cost_price" property="costPrice"/>
  167. <result column="cost_amt" property="costAmt"/>
  168. <result column="out_qty" property="outQty"/>
  169. <result column="inv_qty" property="invQty"/>
  170. <result column="flg_valid" property="flgValid"/>
  171. <result column="cp_id" property="cpId"/>
  172. <result column="sku_code" property="skuCode"/>
  173. <result column="sku_name" property="skuName"/>
  174. <result column="sku_model" property="skuModel"/>
  175. <result column="price_purchase" property="pricePurchase"/>
  176. <result column="reject_qty" property="rejectQty"/>
  177. <result column="sku_images" property="skuImages" typeHandler="JsonTypeHandler"/>
  178. <result column="usable_qty" property="usableQty"/>
  179. <result column="inv_qty" property="invQty"/>
  180. <result column="outing_qty" property="outingQty"/>
  181. <result column="price_std" property="priceStd"/>
  182. <result column="into_item_id" property="intoItemId"/>
  183. <result column="inv_id" property="invId"/>
  184. <result column="wh_id" property="whId"/>
  185. <result column="inv_qty" property="invQty"/>
  186. <result column="usable_qty" property="usableQty"/>
  187. <result column="wh_name" property="whName"/>
  188. </resultMap>
  189. <!-- 通用条件列 -->
  190. <sql id="Condition">
  191. <where>
  192. <if test="intoNo != null and intoNo != ''">
  193. AND tpi.into_no LIKE concat('%',my_ex.likequery(#{intoNo}),'%')
  194. </if>
  195. <if test="intoType != null and intoType != ''">
  196. AND tpi.into_type LIKE concat('%',my_ex.likequery(#{intoType}),'%')
  197. </if>
  198. <if test="intoTypes != null and intoTypes.size()>0">
  199. AND tpi.into_type =any(#{intoTypes,typeHandler=StringListTypeHandler})
  200. </if>
  201. <if test="intoReasonList != null and intoReasonList.size()>0">
  202. AND tpi.into_reason =any(#{intoReasonList,typeHandler=UuidListTypeHandler})
  203. </if>
  204. <if test="searchText !=null and searchText != ''">
  205. AND (
  206. tpi.into_no LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  207. or tpi.from_no LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  208. or tmc.cus_phone LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  209. or tmc.cus_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  210. or tmo.org_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  211. or tmp.sup_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  212. or tms.staff_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  213. )
  214. </if>
  215. <if test="fromId != null and fromId != ''">
  216. AND tpi.from_id = #{fromId}::uuid
  217. </if>
  218. <if test="fromNo != null and fromNo != ''">
  219. AND tpi.from_no LIKE concat('%',my_ex.likequery(#{fromNo}),'%')
  220. </if>
  221. <if test="orgId != null and orgId != ''">
  222. AND tpi.org_id = #{orgId}::uuid
  223. </if>
  224. <if test="orgName != null and orgName != ''">
  225. AND tmo.org_name LIKE concat('%',my_ex.likequery(#{orgName}),'%')
  226. </if>
  227. <if test="supName != null and supName != ''">
  228. AND tmp.sup_name LIKE concat('%',my_ex.likequery(#{supName}),'%')
  229. </if>
  230. <if test="staffName != null and staffName != ''">
  231. AND tms.staff_name LIKE concat('%',my_ex.likequery(#{staffName}),'%')
  232. </if>
  233. <if test="whName != null and whName != ''">
  234. AND tmw.wh_name LIKE concat('%',my_ex.likequery(#{whName}),'%')
  235. </if>
  236. <if test="staffId != null and staffId != ''">
  237. AND tpi.staff_id = #{staffId}::uuid
  238. </if>
  239. <if test="cusId != null and cusId != ''">
  240. AND tpi.cus_id = #{cusId}::uuid
  241. </if>
  242. <if test="supId != null and supId != ''">
  243. AND tpi.sup_id = #{supId}::uuid
  244. </if>
  245. <if test="makeStaff != null and makeStaff != ''">
  246. AND tpi.make_staff = #{makeStaff}
  247. </if>
  248. <if test="makeTime != null">
  249. AND tpi.make_time = #{makeTime}
  250. </if>
  251. <if test="receivableId != null and receivableId != ''">
  252. AND tpi.receivable_id = #{receivableId}
  253. </if>
  254. <if test="flgValid != null">
  255. AND tpi.flg_valid = #{flgValid}
  256. </if>
  257. <if test="cpId != null">
  258. AND tpi.cp_id = #{cpId}
  259. </if>
  260. <if test="cusPhone != null and cusPhone != ''">
  261. AND tmc.cus_phone LIKE concat('%',my_ex.likequery(#{cusPhone}),'%')
  262. </if>
  263. <if test="cusName != null and cusName != ''">
  264. AND tmc.cus_name LIKE concat('%',my_ex.likequery(#{cusName}),'%')
  265. </if>
  266. <if test="orgIdList != null and orgIdList.size() > 0">
  267. AND tmo.org_id =any(#{orgIdList, typeHandler=uuidListTypeHandler})
  268. </if>
  269. <if test="staffIdList != null and staffIdList.size() > 0">
  270. AND tms.staff_id =any(#{staffIdList, typeHandler=uuidListTypeHandler})
  271. </if>
  272. <if test="intoDateStart != null and intoDateEnd != null">
  273. AND tpi.into_date &gt;= #{intoDateStart}::timestamp with time zone
  274. AND tpi.into_date &lt; #{intoDateEnd}::timestamp with time zone + interval '1 day'
  275. </if>
  276. <if test="makeTimeStart != null and makeTimeEnd != null">
  277. AND tpi.make_time &gt;= #{makeTimeStart}::timestamp with time zone
  278. AND tpi.make_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
  279. </if>
  280. <if test="intoStatusList != null and intoStatusList.size()>0">
  281. AND tpi.into_status =
  282. any(#{intoStatusList, typeHandler= StringListTypeHandler})
  283. </if>
  284. <if test="intoStatus != null and intoStatus != ''">
  285. AND tpi.into_status LIKE concat('%',my_ex.likequery(#{intoStatus}),'%')
  286. </if>
  287. <if test="skuModel != null and skuModel!='' ">
  288. and exists (select 1 from dkic_b.t_psi_inbound_item tpii
  289. left join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tpii.sku_id
  290. where
  291. tpi.into_id = tpii.into_id
  292. and tpii.flg_valid
  293. AND position(#{skuModel} in tmgs.sku_model) > 0
  294. )
  295. </if>
  296. <if test="skuCode != null and skuCode!='' ">
  297. and exists (select 1 from dkic_b.t_psi_inbound_item tpii
  298. left join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tpii.sku_id
  299. where
  300. tpi.into_id = tpii.into_id
  301. and tpii.flg_valid
  302. AND position(#{skuCode} in tmgs.sku_code) > 0
  303. )
  304. </if>
  305. <if test="skuName != null and skuName!='' ">
  306. and exists (select 1 from dkic_b.t_psi_inbound_item tpii
  307. left join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tpii.sku_id
  308. where
  309. tpi.into_id = tpii.into_id
  310. and tpii.flg_valid
  311. AND position(#{skuName} in tmgs.sku_name) > 0
  312. )
  313. </if>
  314. </where>
  315. </sql>
  316. <sql id="idsForeach">
  317. <!-- 根据主键intoId批量操作 -->
  318. WHERE into_id in
  319. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  320. #{item}
  321. </foreach>
  322. </sql>
  323. <!-- 查询表t_psi_inbound,(条件查询+分页)列表 tpi.sum_quantity, tpi.sum_amount,-->
  324. <select id="selectByCond" resultMap="BaseResultMapResponse">
  325. SELECT
  326. <include refid="Base_Column_List_Response"/>
  327. ,tmo.org_name AS "orgName",
  328. tmp.sup_name AS "supplierName",
  329. tms.staff_name AS "staffName",
  330. tms.staff_name AS "makeStaffName",
  331. tmw.wh_name as "whName",
  332. tmc.cus_name as "cusName",
  333. tmc.cus_phone as "cusPhone",
  334. tmc.cus_from as "cusFrom",
  335. makestaff.staff_name as "makeStaffName",
  336. sys.f_get_name_i18n(tdktype.kind_name_i18n, #{i18n}) AS "intoTypeName",
  337. sys.f_get_name_i18n(tdk.kind_name_i18n, #{i18n}) AS "intoStatusName",
  338. tmd.data_value as into_reason_name,
  339. tmp.return_address,
  340. case when tpi.receivable_id is null then false
  341. when tmai.amt_handle = 0 then false
  342. else true end as "paymentFlag"
  343. FROM dkic_b.t_psi_inbound tpi
  344. <include refid="Join_Table"/>
  345. <include refid="Condition"/>
  346. order by tpi.make_time desc
  347. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  348. limit #{end} offset #{start}
  349. </if>
  350. </select>
  351. <!-- 查询表t_psi_inbound,(条件查询)个数 -->
  352. <select id="countByCond" resultType="Long">
  353. SELECT
  354. count(1)
  355. FROM dkic_b.t_psi_inbound tpi
  356. <include refid="Join_Table"/>
  357. <include refid="Condition"/>
  358. </select>
  359. <sql id="Join_Table">
  360. Left join dkic_b.t_mst_org tmo on tmo.org_id = tpi.org_id
  361. Left join dkic_b.t_mst_supplier tmp on tmp.sup_id = tpi.sup_id
  362. Left join dkic_b.t_mst_staff tms on tms.staff_id = tpi.staff_id
  363. Left join dkic_b.t_mst_staff makestaff on makestaff.staff_id = tpi.make_staff
  364. LEFT JOIN sys.t_data_kind tdk ON tdk.kind_code = tpi.into_status
  365. LEFT JOIN sys.t_data_kind tdktype ON tdktype.kind_code = tpi.into_type
  366. Left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = tpi.wh_id
  367. left join dkic_b.t_mst_customer tmc on tpi.cus_id = tmc.cus_id
  368. left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = tpi.into_reason
  369. left join dkic_b.t_mac_account_item tmai on tmai.item_id = tpi.receivable_id
  370. </sql>
  371. <!-- 根据主键查询表t_psi_inbound的一行数据 -->
  372. <select id="selectById" resultMap="BaseResultMapResponse">
  373. SELECT
  374. <include refid="Base_Column_List_Response"/>
  375. ,tmo.org_name as "orgName"
  376. ,tms.staff_name as "staffName"
  377. ,tms1.staff_name as "makeStaffName"
  378. ,tmp.sup_name as "supplierName"
  379. ,tmw.wh_name as "whName"
  380. ,tmd.data_value as into_reason_name
  381. ,case when tpi.receivable_id is null then false
  382. when tmai.amt_handle = 0 then false
  383. else true end as "paymentFlag"
  384. FROM dkic_b.t_psi_inbound tpi
  385. Left join dkic_b.t_mst_org tmo on tmo.org_id = tpi.org_id
  386. Left join dkic_b.t_mst_supplier tmp on tmp.sup_id = tpi.sup_id
  387. Left join dkic_b.t_mst_staff tms on tms.staff_id = tpi.staff_id
  388. Left join dkic_b.t_mst_staff tms1 on tms1.staff_id = tpi.make_staff
  389. Left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = tpi.wh_id
  390. left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = tpi.into_reason
  391. left join dkic_b.t_mac_account_item tmai on tmai.item_id = tpi.receivable_id
  392. WHERE tpi.into_id = #{id}::uuid
  393. and tpi.flg_valid
  394. </select>
  395. <!-- 根据主键锁定表t_psi_inbound的一行数据 -->
  396. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  397. SELECT
  398. <include refid="Base_Column_List"/>
  399. FROM dkic_b.t_psi_inbound
  400. WHERE into_id = #{id}::uuid
  401. for update
  402. </select>
  403. <!-- 根据主键锁定表t_psi_inbound的多行数据 -->
  404. <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
  405. SELECT
  406. <include refid="Base_Column_List"/>
  407. FROM dkic_b.t_psi_inbound
  408. <include refid="idsForeach"/>
  409. for update
  410. </select>
  411. <insert id="insertBatch">
  412. insert into dkic_b.t_psi_inbound
  413. (
  414. <trim suffixOverrides=",">
  415. into_no,
  416. into_type,
  417. from_id,
  418. from_no,
  419. org_id,
  420. staff_id,
  421. cus_id,
  422. sup_id,
  423. into_status,
  424. intoing_qty,
  425. intoing_amt,
  426. into_qty,
  427. into_amt,
  428. return_qty,
  429. return_amt,
  430. into_date,
  431. remarks,
  432. annex_paths,
  433. make_staff,
  434. make_time,
  435. receivable_id,
  436. cp_id,
  437. op_app_code,
  438. wh_id,
  439. entry_reason,
  440. </trim>
  441. )
  442. values
  443. <foreach collection="list" index="index" item="item" separator=",">
  444. (
  445. <trim suffixOverrides=",">
  446. #{item.intoNo},
  447. #{item.intoType},
  448. #{item.fromId}::uuid,
  449. #{item.fromNo},
  450. #{item.orgId}::uuid,
  451. #{item.staffId}::uuid,
  452. #{item.cusId}::uuid,
  453. #{item.supId}::uuid,
  454. #{item.intoStatus},
  455. #{item.intoingQty},
  456. #{item.intoingAmt},
  457. #{item.intoQty},
  458. #{item.intoAmt},
  459. #{item.returnQty},
  460. #{item.returnAmt},
  461. #{item.intoDate},
  462. #{item.remarks},
  463. #{item.annexPaths},
  464. #{item.makeStaff}::uuid,
  465. #{item.makeTime},
  466. #{item.receivableId}::uuid,
  467. #{item.cpId},
  468. #{item.opAppCode},
  469. #{item.whId},
  470. #{item.intoReason}::uuid,
  471. </trim>
  472. )
  473. </foreach>
  474. </insert>
  475. <sql id="Base_Column_List_Item_Response_Join">
  476. tpii
  477. .
  478. item_id
  479. AS list_item_id,
  480. tpii.item_id AS list_into_item_Id,
  481. tpii.into_id AS list_into_id,
  482. tpii.into_type AS list_into_type,
  483. tpii.from_id AS list_from_id,
  484. tpii.from_item_id AS list_from_item_id,
  485. tpii.item_index AS list_item_index,
  486. tpii.sku_id AS list_sku_id,
  487. tpii.price_into AS list_price_into,
  488. tpii.non_std_code AS list_non_std_code,
  489. tpii.into_status AS list_into_status,
  490. tpii.intoing_qty AS list_intoing_qty,
  491. tpii.intoing_amt AS list_intoing_amt,
  492. tpii.into_qty AS list_into_qty,
  493. tpii.into_amt AS list_into_amt,
  494. tpii.return_qty AS list_return_qty,
  495. tpii.return_amt AS list_return_amt,
  496. tpii.remarks AS list_remarks,
  497. tpii.inv_id AS list_inv_id,
  498. tpii.cost_price AS list_cost_price,
  499. tpii.cost_amt AS list_cost_amt,
  500. tpii.out_qty AS list_out_qty,
  501. tpii.inv_qty AS list_inv_qty,
  502. tpii.flg_valid AS list_flg_valids,
  503. tpii.cp_id AS list_cp_id,
  504. tmgs.sku_code AS list_sku_code,
  505. tmgs.sku_name AS list_sku_name,
  506. tmgs.sku_model AS list_sku_model,
  507. tmgs.price_purchase AS list_price_purchase,
  508. tmgs.sku_images AS list_sku_images,
  509. ( tpii.into_qty - tpii.return_qty) AS list_reject_qty,
  510. -- tpit.usable_qty AS list_usable_qty,
  511. -- tpit.inv_qty AS list_inv_qty,
  512. -- tpit.outing_qty AS list_outing_qty
  513. -- ,
  514. tmgs.price_standard AS list_price_std,
  515. i.inv_id as list_inv_id,
  516. i.wh_id as list_wh_id,
  517. i.inv_qty as list_inv_qty,
  518. i.usable_qty as list_usable_qty,
  519. i.wh_name as list_wh_name
  520. </sql>
  521. <!-- 查询表t_psi_inbound,(条件查询+分页)列表 -->
  522. <select id="selectInboundAndItem" resultMap="BaseResultMapItemResponse">
  523. SELECT
  524. <include refid="Base_Column_List_Item_Response"/>,
  525. <include refid="Base_Column_List_Item_Response_Join"/>
  526. FROM dkic_b.t_psi_inbound tpi
  527. left join dkic_b.t_psi_inbound_item tpii on tpi.into_id = tpii.into_id and ( tpii.into_qty - tpii.return_qty) > 0
  528. left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = tpii.wh_id
  529. inner join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tpii.sku_id
  530. left join(SELECT T.*
  531. FROM (select tpi.inv_id,
  532. tpi.wh_id,
  533. tpi.inv_qty,
  534. tpi.usable_qty,
  535. tpi.sku_id,
  536. tpi.non_std_code,
  537. tpi.cp_id,
  538. tmw.wh_name,
  539. rank()
  540. over (partition by tpi.cp_id,tpi.sku_id,tpi.non_std_code order by tpi.inv_id) as RK
  541. from dkic_b.t_psi_inventory as tpi
  542. left join dkic_b.t_mst_warehouse as tmw on tmw.wh_id = tpi.wh_id) T
  543. WHERE T.RK = 1) as i
  544. on i.sku_id = tpii.sku_id and i.non_std_code = tpii.non_std_code and i.cp_id = tpii.cp_id
  545. <include refid="Condition"/>
  546. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  547. limit #{end} offset #{start}
  548. </if>
  549. </select>
  550. <!-- 查询表t_psi_inbound,(条件查询)个数 -->
  551. <select id="selectInboundAndItemCountByCond" resultType="Long">
  552. SELECT
  553. count(1)
  554. FROM dkic_b.t_psi_inbound tpi
  555. left join dkic_b.t_psi_inbound_item tpii on tpi.into_id = tpii.into_id
  556. <include refid="Condition"/>
  557. </select>
  558. <update id="updateAmount" parameterType="com.dk.mdm.model.pojo.ivt.InboundItem">
  559. update dkic_b.t_psi_inbound
  560. <set>
  561. <if test="returnQty!= null">
  562. return_qty= #{returnQty},
  563. </if>
  564. <if test="returnAmt!= null">
  565. return_amt = #{returnAmt},
  566. </if>
  567. </set>
  568. where into_id = #{intoId}::uuid
  569. </update>
  570. <!-- 根据id查询带出销售退货单数据(采购退货入库办理用)-->
  571. <select id="selectMessageByOtherQuery" resultMap="BaseResultMapResponse">
  572. SELECT
  573. <include refid="Base_Column_List_Response"/>
  574. ,tmo.org_name as "orgName"
  575. ,tms.staff_name as "staffName"
  576. ,tmc.cus_code
  577. ,tmc.cus_name as "cusName"
  578. ,tmc.cus_phone as "cusPhone"
  579. ,tmc.contact_phone
  580. ,tmc.contact_name
  581. ,tmc.address_area
  582. ,tmc.address_name
  583. ,tmc.address_no
  584. ,tmc.address_gcj02
  585. ,tmc.address_full
  586. ,tmsc.channel_name
  587. ,tmsc.channel_name
  588. ,tmsc.channel_name
  589. ,tmd.data_value as cus_from_name
  590. FROM dkic_b.t_psi_inbound tpi
  591. Left join dkic_b.t_mst_org tmo on tmo.org_id = tpi.org_id
  592. Left join dkic_b.t_mst_staff tms on tms.staff_id = tpi.staff_id
  593. left join dkic_b.t_mst_customer tmc on tpi.cus_id = tmc.cus_id
  594. left join dkic_b.t_mst_sale_channel tmsc on tmc.channel_id = tmsc.channel_id
  595. left join dkic_b.t_mst_dictionary_data tmd on tmc.cus_from = tmd.data_id
  596. <where>
  597. <if test="intoId != null and intoId != ''">
  598. AND tpi.into_id = #{intoId}::uuid
  599. </if>
  600. <if test="intoStatus != null and intoStatus != ''">
  601. AND tpi.into_status = #{intoStatus}
  602. </if>
  603. <if test="fromId != null and fromId != ''">
  604. AND tpi.from_id = #{fromId}::uuid
  605. </if>
  606. </where>
  607. </select>
  608. <!-- 入库办理显示字段 -->
  609. <sql id="Base_Column_List_Response_Into">
  610. tpi.into_id,
  611. tpi.into_no,
  612. tpi.into_type,
  613. tpi.from_id,
  614. tpi.from_no,
  615. tpi.org_id,
  616. tpi.staff_id,
  617. tpi.cus_id,
  618. tpi.sup_id,
  619. tpi.into_status,
  620. tpi.intoing_qty,
  621. tpi.intoing_amt,
  622. tpi.into_qty,
  623. tpi.into_amt,
  624. tpi.return_qty,
  625. tpi.return_amt,
  626. tpi.into_date,
  627. tpi.remarks,
  628. tpi.annex_paths,
  629. tpi.make_staff,
  630. tpi.make_time,
  631. tpi.wh_id,
  632. tpi.into_reason,
  633. tpi.flg_valid
  634. </sql>
  635. <sql id="Base_Column_List_Response_Out">
  636. tpo.out_id as into_id,
  637. tpo.out_no as into_no,
  638. tpo.out_type as into_type,
  639. tpo.from_id,
  640. tpo.from_no,
  641. tpo.org_id,
  642. tpo.staff_id,
  643. tpo.cus_id,
  644. tpo.sup_id,
  645. tpo.out_status,
  646. tpo.outing_qty as intoing_qty,
  647. tpo.outing_amt as intoing_amt,
  648. tpo.out_qty as into_qty,
  649. tpo.out_amt as into_amt,
  650. tpo.return_qty,
  651. tpo.return_amt,
  652. tpo.out_date as into_date,
  653. tpo.remarks,
  654. tpo.annex_paths,
  655. tpo.make_staff,
  656. tpo.make_time,
  657. null as wh_id,
  658. tpo.out_reason as into_reason,
  659. tpo.flg_valid
  660. </sql>
  661. <!-- 条件查询 web端入库办理用,-->
  662. <select id="selectInbound" resultMap="BaseResultMapResponse">
  663. SELECT
  664. <include refid="Base_Column_List_Response_Into"/>,
  665. tmo.org_name AS "orgName",
  666. tmp.sup_name AS "supplierName",
  667. tms.staff_name AS "staffName",
  668. tms.staff_name AS "makeStaffName",
  669. tmw.wh_name as "whName",
  670. tmc.cus_name as "cusName",
  671. tmc.cus_phone as "cusPhone",
  672. tmc.cus_from as "cusFrom",
  673. tmc.address_full,
  674. makestaff.staff_name as "makeStaffName",
  675. sys.f_get_name_i18n(tdktype.kind_name_i18n, #{i18n}) AS "intoTypeName",
  676. sys.f_get_name_i18n(tdk.kind_name_i18n, #{i18n}) AS "intoStatusName",
  677. tmd.data_value as into_reason_name
  678. FROM dkic_b.t_psi_inbound tpi
  679. <include refid="Select_Inbound_Join_Table_Into"/>
  680. <where>
  681. AND tpi.cp_id = #{cpId}
  682. <if test="intoTypes != null and intoTypes.size()>0">
  683. AND tpi.into_type =any(#{intoTypes,typeHandler=StringListTypeHandler})
  684. </if>
  685. <if test="intoTypes == null || intoTypes.size()==0">
  686. AND (tpi.into_type = '入库类型-其他入库'
  687. or tpi.into_type = '入库类型-采购入库')
  688. </if>
  689. <if test=" intoStatus != null and intoStatus != '' ">
  690. AND tpi.into_status LIKE concat('%',my_ex.likequery(#{intoStatus}),'%')
  691. </if>
  692. <if test="makeTimeStart != null and makeTimeEnd != null">
  693. AND tpi.make_time &gt;= #{makeTimeStart}::timestamp with time zone
  694. AND tpi.make_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
  695. </if>
  696. <if test="intoNo != null and intoNo != ''">
  697. AND tpi.into_no LIKE concat('%',my_ex.likequery(#{intoNo}),'%')
  698. </if>
  699. <if test="cusPhone != null and cusPhone != ''">
  700. AND tmc.cus_phone LIKE concat('%',my_ex.likequery(#{cusPhone}),'%')
  701. </if>
  702. <if test="cusName != null and cusName != ''">
  703. AND tmc.cus_name LIKE concat('%',my_ex.likequery(#{cusName}),'%')
  704. </if>
  705. <if test="supId != null and supId != ''">
  706. AND tpi.sup_id = #{supId}::uuid
  707. </if>
  708. <if test="orgIdList != null and orgIdList.size() > 0">
  709. AND tmo.org_id =any(#{orgIdList, typeHandler=uuidListTypeHandler})
  710. </if>
  711. <if test="staffIdList != null and staffIdList.size() > 0">
  712. AND tms.staff_id =any(#{staffIdList, typeHandler=uuidListTypeHandler})
  713. </if>
  714. <if test="flgValidList != null and flgValidList.size()>0">
  715. AND tpi.flg_valid =any(#{flgValidList, typeHandler=BooleanListTypeHandler})
  716. </if>
  717. </where>
  718. union all
  719. select
  720. <include refid="Base_Column_List_Response_Out"/>,
  721. tmo.org_name AS "orgName",
  722. tmp.sup_name AS "supplierName",
  723. tms.staff_name AS "staffName",
  724. tms.staff_name AS "makeStaffName",
  725. null as "whName",
  726. tmc.cus_name as "cusName",
  727. tmc.cus_phone as "cusPhone",
  728. tmc.cus_from as "cusFrom",
  729. tmc.address_full,
  730. makestaff.staff_name as "makeStaffName",
  731. sys.f_get_name_i18n(tdktype.kind_name_i18n, #{i18n}) AS "intoTypeName",
  732. sys.f_get_name_i18n(tdk.kind_name_i18n, #{i18n}) AS "intoStatusName",
  733. tmd.data_value as into_reason_name
  734. from dkic_b.t_psi_outbound tpo
  735. <include refid="Select_Inbound_Join_Table_Out"/>
  736. <where>
  737. AND tpo.cp_id = #{cpId}
  738. <if test="intoTypes != null and intoTypes.size()>0">
  739. AND tpo.out_type =any(#{intoTypes,typeHandler=StringListTypeHandler})
  740. </if>
  741. <if test="intoTypes == null || intoTypes.size()==0">
  742. AND tpo.out_type = '出库类型-销退出库'
  743. </if>
  744. <if test="outStatus != null and outStatus != '' ">
  745. AND tpo.out_status LIKE concat('%',my_ex.likequery(#{outStatus}),'%')
  746. </if>
  747. <if test="makeTimeStart != null and makeTimeEnd != null">
  748. AND tpo.make_time &gt;= #{makeTimeStart}::timestamp with time zone
  749. AND tpo.make_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
  750. </if>
  751. <if test="intoNo != null and intoNo != ''">
  752. AND tpo.out_no LIKE concat('%',my_ex.likequery(#{intoNo}),'%')
  753. </if>
  754. <if test="cusPhone != null and cusPhone != ''">
  755. AND tmc.cus_phone LIKE concat('%',my_ex.likequery(#{cusPhone}),'%')
  756. </if>
  757. <if test="cusName != null and cusName != ''">
  758. AND tmc.cus_name LIKE concat('%',my_ex.likequery(#{cusName}),'%')
  759. </if>
  760. <if test="supId != null and supId != ''">
  761. AND tpo.sup_id = #{supId}::uuid
  762. </if>
  763. <if test="orgIdList != null and orgIdList.size() > 0">
  764. AND tmo.org_id =any(#{orgIdList, typeHandler=uuidListTypeHandler})
  765. </if>
  766. <if test="staffIdList != null and staffIdList.size() > 0">
  767. AND tms.staff_id =any(#{staffIdList, typeHandler=uuidListTypeHandler})
  768. </if>
  769. <if test="flgValidList != null and flgValidList.size()>0">
  770. AND tpo.flg_valid =any(#{flgValidList, typeHandler=BooleanListTypeHandler})
  771. </if>
  772. </where>
  773. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  774. limit #{end} offset #{start}
  775. </if>
  776. </select>
  777. <!-- 条件查询 web端入库办理用个数 -->
  778. <select id="selectInboundCond" resultType="Long">
  779. SELECT
  780. count(1) from (
  781. SELECT
  782. <include refid="Base_Column_List_Response_Into"/>,
  783. tmo.org_name AS "orgName",
  784. tmp.sup_name AS "supplierName",
  785. tms.staff_name AS "staffName",
  786. tms.staff_name AS "makeStaffName",
  787. tmw.wh_name as "whName",
  788. tmc.cus_name as "cusName",
  789. tmc.cus_phone as "cusPhone",
  790. tmc.cus_from as "cusFrom",
  791. makestaff.staff_name as "makeStaffName",
  792. sys.f_get_name_i18n(tdktype.kind_name_i18n, #{i18n}) AS "intoTypeName",
  793. sys.f_get_name_i18n(tdk.kind_name_i18n, #{i18n}) AS "intoStatusName",
  794. tmd.data_value as into_reason_name
  795. FROM dkic_b.t_psi_inbound tpi
  796. <include refid="Select_Inbound_Join_Table_Into"/>
  797. <where>
  798. AND tpi.cp_id = #{cpId}
  799. <if test="intoTypes != null and intoTypes.size()>0">
  800. AND tpi.into_type =any(#{intoTypes,typeHandler=StringListTypeHandler})
  801. </if>
  802. <if test="intoTypes == null || intoTypes.size()==0">
  803. AND (tpi.into_type = '入库类型-其他入库'
  804. or tpi.into_type = '入库类型-采购入库')
  805. </if>
  806. <if test=" intoStatus != null and intoStatus != '' ">
  807. AND tpi.into_status LIKE concat('%',my_ex.likequery(#{intoStatus}),'%')
  808. </if>
  809. <if test="makeTimeStart != null and makeTimeEnd != null">
  810. AND tpi.make_time &gt;= #{makeTimeStart}::timestamp with time zone
  811. AND tpi.make_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
  812. </if>
  813. <if test="intoNo != null and intoNo != ''">
  814. AND tpi.into_no LIKE concat('%',my_ex.likequery(#{intoNo}),'%')
  815. </if>
  816. <if test="cusPhone != null and cusPhone != ''">
  817. AND tmc.cus_phone LIKE concat('%',my_ex.likequery(#{cusPhone}),'%')
  818. </if>
  819. <if test="cusName != null and cusName != ''">
  820. AND tmc.cus_name LIKE concat('%',my_ex.likequery(#{cusName}),'%')
  821. </if>
  822. <if test="supId != null and supId != ''">
  823. AND tpi.sup_id = #{supId}::uuid
  824. </if>
  825. <if test="orgIdList != null and orgIdList.size() > 0">
  826. AND tmo.org_id =any(#{orgIdList, typeHandler=uuidListTypeHandler})
  827. </if>
  828. <if test="staffIdList != null and staffIdList.size() > 0">
  829. AND tms.staff_id =any(#{staffIdList, typeHandler=uuidListTypeHandler})
  830. </if>
  831. <if test="flgValidList != null and flgValidList.size()>0">
  832. AND tpi.flg_valid =any(#{flgValidList, typeHandler=BooleanListTypeHandler})
  833. </if>
  834. </where>
  835. union all
  836. select
  837. <include refid="Base_Column_List_Response_Out"/>,
  838. tmo.org_name AS "orgName",
  839. tmp.sup_name AS "supplierName",
  840. tms.staff_name AS "staffName",
  841. tms.staff_name AS "makeStaffName",
  842. null as "whName",
  843. tmc.cus_name as "cusName",
  844. tmc.cus_phone as "cusPhone",
  845. tmc.cus_from as "cusFrom",
  846. makestaff.staff_name as "makeStaffName",
  847. sys.f_get_name_i18n(tdktype.kind_name_i18n, #{i18n}) AS "intoTypeName",
  848. sys.f_get_name_i18n(tdk.kind_name_i18n, #{i18n}) AS "intoStatusName",
  849. tmd.data_value as into_reason_name
  850. from dkic_b.t_psi_outbound tpo
  851. <include refid="Select_Inbound_Join_Table_Out"/>
  852. <where>
  853. AND tpo.cp_id = #{cpId}
  854. <if test="intoTypes != null and intoTypes.size()>0">
  855. AND tpo.out_type =any(#{intoTypes,typeHandler=StringListTypeHandler})
  856. </if>
  857. <if test="intoTypes == null || intoTypes.size()==0">
  858. AND tpo.out_type = '出库类型-销退出库'
  859. </if>
  860. <if test="outStatus != null and outStatus != '' ">
  861. AND tpo.out_status LIKE concat('%',my_ex.likequery(#{outStatus}),'%')
  862. </if>
  863. <if test="makeTimeStart != null and makeTimeEnd != null">
  864. AND tpo.make_time &gt;= #{makeTimeStart}::timestamp with time zone
  865. AND tpo.make_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
  866. </if>
  867. <if test="intoNo != null and intoNo != ''">
  868. AND tpo.out_no LIKE concat('%',my_ex.likequery(#{intoNo}),'%')
  869. </if>
  870. <if test="cusPhone != null and cusPhone != ''">
  871. AND tmc.cus_phone LIKE concat('%',my_ex.likequery(#{cusPhone}),'%')
  872. </if>
  873. <if test="cusName != null and cusName != ''">
  874. AND tmc.cus_name LIKE concat('%',my_ex.likequery(#{cusName}),'%')
  875. </if>
  876. <if test="supId != null and supId != ''">
  877. AND tpo.sup_id = #{supId}::uuid
  878. </if>
  879. <if test="orgIdList != null and orgIdList.size() > 0">
  880. AND tmo.org_id =any(#{orgIdList, typeHandler=uuidListTypeHandler})
  881. </if>
  882. <if test="staffIdList != null and staffIdList.size() > 0">
  883. AND tms.staff_id =any(#{staffIdList, typeHandler=uuidListTypeHandler})
  884. </if>
  885. <if test="flgValidList != null and flgValidList.size()>0">
  886. AND tpo.flg_valid =any(#{flgValidList, typeHandler=BooleanListTypeHandler})
  887. </if>
  888. </where>
  889. ) tt
  890. </select>
  891. <!--入库办理显示入库关联表-->
  892. <sql id="Select_Inbound_Join_Table_Into">
  893. Left join dkic_b.t_mst_org tmo on tmo.org_id = tpi.org_id
  894. Left join dkic_b.t_mst_supplier tmp on tmp.sup_id = tpi.sup_id
  895. Left join dkic_b.t_mst_staff tms on tms.staff_id = tpi.staff_id
  896. Left join dkic_b.t_mst_staff makestaff on makestaff.staff_id = tpi.make_staff
  897. LEFT JOIN sys.t_data_kind tdk ON tdk.kind_code = tpi.into_status
  898. LEFT JOIN sys.t_data_kind tdktype ON tdktype.kind_code = tpi.into_type
  899. Left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = tpi.wh_id
  900. left join dkic_b.t_mst_customer tmc on tpi.cus_id = tmc.cus_id
  901. left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = tpi.into_reason
  902. </sql>
  903. <!--入库办理显示出库关联表-->
  904. <sql id="Select_Inbound_Join_Table_Out">
  905. Left join dkic_b.t_mst_org tmo on tmo.org_id = tpo.org_id
  906. Left join dkic_b.t_mst_supplier tmp on tmp.sup_id = tpo.sup_id
  907. Left join dkic_b.t_mst_staff tms on tms.staff_id = tpo.staff_id
  908. Left join dkic_b.t_mst_staff makestaff on makestaff.staff_id = tpo.make_staff
  909. LEFT JOIN sys.t_data_kind tdk ON tdk.kind_code = tpo.out_status
  910. LEFT JOIN sys.t_data_kind tdktype ON tdktype.kind_code = tpo.out_type
  911. left join dkic_b.t_mst_customer tmc on tpo.cus_id = tmc.cus_id
  912. left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = tpo.out_reason
  913. </sql>
  914. <update id="updateIntoStatus" parameterType="com.dk.mdm.model.pojo.ivt.InboundItem">
  915. update dkic_b.t_psi_inbound
  916. <set>
  917. <if test="intoStatus!= null">
  918. into_status= #{intoStatus},
  919. </if>
  920. </set>
  921. where into_id = #{intoId}::uuid
  922. </update>
  923. <!-- 采购退货用-->
  924. <resultMap id="BaseResultMapInboundReturnResponse" type="com.dk.mdm.model.response.ivt.InboundResponse">
  925. <id column="into_id" property="intoId" typeHandler="UuidTypeHandler"/>
  926. <result column="into_no" property="intoNo"/>
  927. <result column="into_type" property="intoType"/>
  928. <result column="from_id" property="fromId" typeHandler="UuidTypeHandler"/>
  929. <result column="from_no" property="fromNo"/>
  930. <result column="org_id" property="orgId" typeHandler="UuidTypeHandler"/>
  931. <result column="staff_id" property="staffId" typeHandler="UuidTypeHandler"/>
  932. <result column="sup_id" property="supId" typeHandler="UuidTypeHandler"/>
  933. <result column="into_status" property="intoStatus"/>
  934. <result column="intoing_qty" property="intoingQty"/>
  935. <result column="intoing_amt" property="intoingAmt"/>
  936. <result column="into_qty" property="intoQty"/>
  937. <result column="into_amt" property="intoAmt"/>
  938. <result column="wh_id" property="whId" typeHandler="UuidTypeHandler"/>
  939. <result column="return_qty" property="returnQty"/>
  940. <result column="return_amt" property="returnAmt"/>
  941. <result column="into_date" property="intoDate" typeHandler="TimestampTypeHandler"/>
  942. <result column="remarks" property="remarks"/>
  943. <result column="annex_paths" property="annexPaths" typeHandler="JsonTypeHandler"/>
  944. <result column="make_staff" property="makeStaff" typeHandler="UuidTypeHandler"/>
  945. <result column="make_time" property="makeTime" typeHandler="TimestampTypeHandler"/>
  946. <result column="receivable_id" property="receivableId" typeHandler="UuidTypeHandler"/>
  947. <result column="flg_valid" property="flgValid"/>
  948. <result column="cp_id" property="cpId"/>
  949. <result column="sup_name" property="supName"/>
  950. <result column="into_reason" property="intoReason" typeHandler="UuidTypeHandler"/>
  951. <result column="into_reason_name" property="intoReasonName" />
  952. <result column="org_name" property="orgName" />
  953. <result column="staff_name" property="staffName" />
  954. <result column="contact_phone" property="contactPhone" />
  955. <result column="contact_name" property="contactName" />
  956. <result column="channel_name" property="channelName" />
  957. <result column="cus_from_name" property="cusFromName" />
  958. <result column="return_address" property="returnAddress" />
  959. </resultMap>
  960. <sql id="Join_Table_Return">
  961. Left join dkic_b.t_mst_org tmo on tmo.org_id = tpi.org_id
  962. Left join dkic_b.t_mst_supplier tmp on tmp.sup_id = tpi.sup_id
  963. Left join dkic_b.t_mst_staff tms on tms.staff_id = tpi.staff_id
  964. Left join dkic_b.t_mst_staff tms1 on tms1.staff_id = tpi.make_staff
  965. LEFT JOIN sys.t_data_kind tdk ON tdk.kind_code = tpi.into_status
  966. LEFT JOIN sys.t_data_kind tdktype ON tdktype.kind_code = tpi.into_type
  967. Left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = tpi.wh_id
  968. left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = tpi.into_reason
  969. left join dkic_b.t_mac_account_item tmai on tmai.item_id = tpi.receivable_id
  970. </sql>
  971. <!-- 采购退货用-->
  972. <select id="selectByInboundReturnCond" resultMap="BaseResultMapInboundReturnResponse">
  973. SELECT
  974. <include refid="Base_Column_List_Response"/>
  975. ,tmo.org_name
  976. ,tmp.sup_name
  977. ,tms.staff_name
  978. ,tmw.wh_name
  979. ,tms1.staff_name as make_staff_name
  980. ,sys.f_get_name_i18n(tdktype.kind_name_i18n, #{i18n}) AS into_type_name
  981. ,sys.f_get_name_i18n(tdk.kind_name_i18n, #{i18n}) AS into_status_name
  982. ,tmd.data_value as into_reason_name
  983. ,tmp.return_address
  984. ,tmp.contact_name
  985. ,tmp.contact_phone
  986. ,case when tpi.receivable_id is null then false
  987. when tmai.amt_handle = 0 then false
  988. else true end as "paymentFlag"
  989. FROM dkic_b.t_psi_inbound tpi
  990. <include refid="Join_Table_Return"/>
  991. <include refid="Condition"/>
  992. ORDER BY tpi.op_create_time DESC
  993. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  994. limit #{end} offset #{start}
  995. </if>
  996. </select>
  997. <!--采购退货用 查询表t_psi_inbound,(条件查询)个数 -->
  998. <select id="countByInboundReturnCond" resultType="Long">
  999. SELECT
  1000. count(1)
  1001. FROM dkic_b.t_psi_inbound tpi
  1002. <include refid="Join_Table_Return"/>
  1003. <include refid="Condition"/>
  1004. </select>
  1005. <!-- 查看来源单据,总单加明细 采购退货用-->
  1006. <select id="selectInboundReturnById" resultMap="BaseResultMapInboundReturnResponse">
  1007. SELECT
  1008. <include refid="Base_Column_List_Response"/>
  1009. ,tmo.org_name
  1010. ,tms.staff_name as staff_name
  1011. ,tms1.staff_name as make_staff_name
  1012. ,tmp.sup_name
  1013. ,tmw.wh_name
  1014. ,tmd.data_value as into_reason_name
  1015. ,tmp.return_address
  1016. ,tmp.contact_name
  1017. ,tmp.contact_phone
  1018. ,case when tpi.receivable_id is null then false
  1019. when tmai.amt_handle = 0 then false
  1020. else true end as "paymentFlag"
  1021. FROM dkic_b.t_psi_inbound tpi
  1022. Left join dkic_b.t_mst_org tmo on tmo.org_id = tpi.org_id
  1023. Left join dkic_b.t_mst_supplier tmp on tmp.sup_id = tpi.sup_id
  1024. Left join dkic_b.t_mst_staff tms on tms.staff_id = tpi.staff_id
  1025. Left join dkic_b.t_mst_staff tms1 on tms1.staff_id = tpi.make_staff
  1026. Left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = tpi.wh_id
  1027. left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = tpi.into_reason
  1028. left join dkic_b.t_mac_account_item tmai on tmai.item_id = tpi.receivable_id
  1029. WHERE tpi.into_id = #{intoId}::uuid AND tpi.flg_valid = true
  1030. </select>
  1031. <!-- 根据来源id查询 -->
  1032. <select id="selectByFromId" resultMap="BaseResultMapResponse">
  1033. SELECT
  1034. <include refid="Base_Column_List_Response"/>
  1035. FROM dkic_b.t_psi_inbound tpi
  1036. WHERE tpi.from_id = #{id}::uuid
  1037. and tpi.flg_valid
  1038. </select>
  1039. </mapper>