InboundMapper.xml 56 KB

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