InboundMapper.xml 56 KB

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