InboundMapper.xml 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523
  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,inbound_processing_flag
  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.inbound_processing_flag
  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="inbound_processing_flag" property="inboundProcessingFlag"/>
  61. </resultMap>
  62. <!-- response查询映射结果 -->
  63. <resultMap id="BaseResultMapResponse" type="com.dk.mdm.model.response.ivt.InboundResponse">
  64. <id column="into_id" property="intoId" typeHandler="UuidTypeHandler"/>
  65. <result column="into_no" property="intoNo"/>
  66. <result column="into_type" property="intoType"/>
  67. <result column="from_id" property="fromId" typeHandler="UuidTypeHandler"/>
  68. <result column="from_no" property="fromNo"/>
  69. <result column="org_id" property="orgId" typeHandler="UuidTypeHandler"/>
  70. <result column="staff_id" property="staffId" typeHandler="UuidTypeHandler"/>
  71. <result column="cus_id" property="cusId" typeHandler="UuidTypeHandler"/>
  72. <result column="sup_id" property="supId" typeHandler="UuidTypeHandler"/>
  73. <result column="into_status" property="intoStatus"/>
  74. <result column="intoing_qty" property="intoingQty"/>
  75. <result column="intoing_amt" property="intoingAmt"/>
  76. <result column="into_qty" property="intoQty"/>
  77. <result column="into_amt" property="intoAmt"/>
  78. <result column="wh_id" property="whId" typeHandler="UuidTypeHandler"/>
  79. <result column="return_qty" property="returnQty"/>
  80. <result column="return_amt" property="returnAmt"/>
  81. <result column="into_date" property="intoDate" typeHandler="TimestampTypeHandler"/>
  82. <result column="remarks" property="remarks"/>
  83. <result column="annex_paths" property="annexPaths" typeHandler="JsonTypeHandler"/>
  84. <result column="make_staff" property="makeStaff" typeHandler="UuidTypeHandler"/>
  85. <result column="make_time" property="makeTime" typeHandler="TimestampTypeHandler"/>
  86. <result column="receivable_id" property="receivableId" typeHandler="UuidTypeHandler"/>
  87. <result column="flg_valid" property="flgValid"/>
  88. <result column="cp_id" property="cpId"/>
  89. <result column="into_reason" property="intoReason" typeHandler="UuidTypeHandler"/>
  90. <result column="into_reason_name" property="intoReasonName" />
  91. <!-- <result column="orgName" property="orgName" />-->
  92. <!-- <result column="staff_name" property="staffName" />-->
  93. <result column="cus_code" property="cusCode" />
  94. <!-- <result column="cus_name" property="cusName" />-->
  95. <!-- <result column="cus_phone" property="cusPhone" />-->
  96. <result column="contact_phone" property="contactPhone" />
  97. <result column="contact_name" property="contactName" />
  98. <result column="address_area" property="addressArea" typeHandler="JsonTypeHandler"/>
  99. <result column="address_name" property="addressName"/>
  100. <result column="address_no" property="addressNo"/>
  101. <result column="address_gcj02" property="addressGcj02" typeHandler="JsonTypeHandler"/>
  102. <result column="address_full" property="addressFull"/>
  103. <result column="channel_name" property="channelName" />
  104. <result column="cus_from_name" property="cusFromName" />
  105. <result column="return_address" property="returnAddress" />
  106. <result column="flg_auto_handle" property="flgAutoHandle"/>
  107. <result column="inbound_processing_flag" property="inboundProcessingFlag"/>
  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,
  115. tpi.into_status, sys.f_remove_zero(tpi.intoing_qty) as intoing_qty, tpi.intoing_amt,
  116. 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,
  117. tpi.remarks, tpi.annex_paths, tpi.make_staff, tpi.make_time,
  118. tpi.receivable_id, tpi.flg_valid, tpi.cp_id
  119. </sql>
  120. <!-- response明细关联明细映射-->
  121. <resultMap id="BaseResultMapItemResponse" type="com.dk.mdm.model.response.ivt.InboundResponse">
  122. <id column="into_id" property="intoId" typeHandler="UuidTypeHandler"/>
  123. <result column="into_no" property="intoNo"/>
  124. <result column="into_type" property="intoType"/>
  125. <result column="from_id" property="fromId" typeHandler="UuidTypeHandler"/>
  126. <result column="from_no" property="fromNo"/>
  127. <result column="org_id" property="orgId" typeHandler="UuidTypeHandler"/>
  128. <result column="staff_id" property="staffId" typeHandler="UuidTypeHandler"/>
  129. <result column="cus_id" property="cusId" typeHandler="UuidTypeHandler"/>
  130. <result column="sup_id" property="supId" typeHandler="UuidTypeHandler"/>
  131. <result column="into_status" property="intoStatus"/>
  132. <result column="intoStatusName" property="intoStatusName"/>
  133. <result column="intoing_qty" property="intoingQty"/>
  134. <result column="intoing_amt" property="intoingAmt"/>
  135. <result column="into_qty" property="intoQty"/>
  136. <result column="into_amt" property="intoAmt"/>
  137. <result column="return_qty" property="returnQty"/>
  138. <result column="return_amt" property="returnAmt"/>
  139. <result column="into_date" property="intoDate" typeHandler="TimestampTypeHandler"/>
  140. <result column="remarks" property="remarks"/>
  141. <result column="annex_paths" property="annexPaths" typeHandler="JsonTypeHandler"/>
  142. <result column="make_staff" property="makeStaff" typeHandler="UuidTypeHandler"/>
  143. <result column="make_time" property="makeTime" typeHandler="TimestampTypeHandler"/>
  144. <result column="receivable_id" property="receivableId" typeHandler="UuidTypeHandler"/>
  145. <result column="flg_valid" property="flgValid"/>
  146. <result column="cp_id" property="cpId"/>
  147. <result column="orgName" property="orgName"/>
  148. <result column="staffName" property="staffName"/>
  149. <result column="categoryCount" property="categoryCount"/>
  150. <collection property="inboundItemList" resultMap="inboundItemListMap" columnPrefix="list_"/>
  151. </resultMap>
  152. <!-- 关联映射-->
  153. <resultMap id="inboundItemListMap" type="java.util.Map">
  154. <result column="item_id" property="itemId" typeHandler="UuidTypeHandler"/>
  155. <result column="into_id" property="intoId" typeHandler="UuidTypeHandler"/>
  156. <result column="into_no" property="intoNo" typeHandler="UuidTypeHandler"/>
  157. <result column="into_type" property="intoType"/>
  158. <result column="from_id" property="fromId" typeHandler="UuidTypeHandler"/>
  159. <result column="from_item_id" property="fromItemId" typeHandler="UuidTypeHandler"/>
  160. <result column="item_index" property="itemIndex"/>
  161. <result column="sku_id" property="skuId" typeHandler="UuidTypeHandler"/>
  162. <result column="item_qty" property="itemQty"/>
  163. <result column="price_into" property="priceInto"/>
  164. <result column="item_amt" property="itemAmt"/>
  165. <result column="non_std_code" property="nonStdCode"/>
  166. <result column="into_status" property="intoStatus"/>
  167. <result column="intoing_qty" property="intoingQty"/>
  168. <result column="intoing_amt" property="intoingAmt"/>
  169. <result column="into_qty" property="intoQty"/>
  170. <result column="into_amt" property="intoAmt"/>
  171. <result column="return_qty" property="returnQty"/>
  172. <result column="return_amt" property="returnAmt"/>
  173. <result column="remarks" property="remarks"/>
  174. <result column="inv_id" property="invId" typeHandler="UuidTypeHandler"/>
  175. <result column="cost_price" property="costPrice"/>
  176. <result column="cost_amt" property="costAmt"/>
  177. <result column="out_qty" property="outQty"/>
  178. <result column="inv_qty" property="invQty"/>
  179. <result column="flg_valid" property="flgValid"/>
  180. <result column="cp_id" property="cpId"/>
  181. <result column="sku_code" property="skuCode"/>
  182. <result column="sku_name" property="skuName"/>
  183. <result column="sku_model" property="skuModel"/>
  184. <result column="short_name" property="shortName"/>
  185. <result column="price_purchase" property="pricePurchase"/>
  186. <result column="reject_qty" property="rejectQty"/>
  187. <result column="sku_images" property="skuImages" typeHandler="JsonTypeHandler"/>
  188. <result column="skuImages" property="skuImages" />
  189. <result column="usable_qty" property="usableQty"/>
  190. <result column="inv_qty" property="invQty"/>
  191. <result column="outing_qty" property="outingQty"/>
  192. <result column="price_std" property="priceStd"/>
  193. <result column="into_item_id" property="intoItemId"/>
  194. <result column="inv_id" property="invId"/>
  195. <result column="wh_id" property="whId"/>
  196. <result column="inv_qty" property="invQty"/>
  197. <result column="usable_qty" property="usableQty"/>
  198. <result column="wh_name" property="whName"/>
  199. <result column="pack_box_text" property="packBoxText"/>
  200. <result column="can_return_qty" property="canReturnQty"/>
  201. <result column="price_into" property="priceInto"/>
  202. <result column="sku_spec" property="skuSpec"/>
  203. </resultMap>
  204. <!-- 通用条件列 -->
  205. <sql id="Condition">
  206. <where>
  207. <if test="intoNo != null and intoNo != ''">
  208. AND tpi.into_no LIKE concat('%',my_ex.likequery(#{intoNo}),'%')
  209. </if>
  210. <if test="intoType != null and intoType != ''">
  211. AND tpi.into_type LIKE concat('%',my_ex.likequery(#{intoType}),'%')
  212. </if>
  213. <if test="intoTypes != null and intoTypes.size()>0">
  214. AND tpi.into_type =any(#{intoTypes,typeHandler=StringListTypeHandler})
  215. </if>
  216. <if test="intoReasonList != null and intoReasonList.size()>0">
  217. AND tpi.into_reason =any(#{intoReasonList,typeHandler=UuidListTypeHandler})
  218. </if>
  219. <if test="searchText !=null and searchText != ''">
  220. AND (
  221. tpi.into_no LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  222. or tpi.from_no LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  223. or tmc.cus_phone LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  224. or tmc.cus_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  225. or tmo.org_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  226. or tmp.sup_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  227. or tms.staff_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  228. )
  229. </if>
  230. <if test="fromId != null and fromId != ''">
  231. AND tpi.from_id = #{fromId}::uuid
  232. </if>
  233. <if test="fromNo != null and fromNo != ''">
  234. AND tpi.from_no LIKE concat('%',my_ex.likequery(#{fromNo}),'%')
  235. </if>
  236. <if test="orgId != null and orgId != ''">
  237. AND tpi.org_id = #{orgId}::uuid
  238. </if>
  239. <if test="orgName != null and orgName != ''">
  240. AND tmo.org_name LIKE concat('%',my_ex.likequery(#{orgName}),'%')
  241. </if>
  242. <if test="supName != null and supName != ''">
  243. AND tmp.sup_name LIKE concat('%',my_ex.likequery(#{supName}),'%')
  244. </if>
  245. <if test="staffName != null and staffName != ''">
  246. AND tms.staff_name LIKE concat('%',my_ex.likequery(#{staffName}),'%')
  247. </if>
  248. <if test="whName != null and whName != ''">
  249. AND tmw.wh_name LIKE concat('%',my_ex.likequery(#{whName}),'%')
  250. </if>
  251. <if test="staffId != null and staffId != ''">
  252. AND tpi.staff_id = #{staffId}::uuid
  253. </if>
  254. <if test="cusId != null and cusId != ''">
  255. AND tpi.cus_id = #{cusId}::uuid
  256. </if>
  257. <if test="supId != null and supId != ''">
  258. AND tpi.sup_id = #{supId}::uuid
  259. </if>
  260. <if test="makeStaff != null and makeStaff != ''">
  261. AND tpi.make_staff = #{makeStaff}
  262. </if>
  263. <if test="makeTime != null">
  264. AND tpi.make_time = #{makeTime}
  265. </if>
  266. <if test="receivableId != null and receivableId != ''">
  267. AND tpi.receivable_id = #{receivableId}
  268. </if>
  269. <if test="flgValid != null">
  270. AND tpi.flg_valid = #{flgValid}
  271. </if>
  272. <if test="cpId != null">
  273. AND tpi.cp_id = #{cpId}
  274. </if>
  275. <if test="cusPhone != null and cusPhone != ''">
  276. AND tmc.cus_phone LIKE concat('%',my_ex.likequery(#{cusPhone}),'%')
  277. </if>
  278. <if test="cusName != null and cusName != ''">
  279. AND tmc.cus_name LIKE concat('%',my_ex.likequery(#{cusName}),'%')
  280. </if>
  281. <if test="orgIdList != null and orgIdList.size() > 0">
  282. AND tmo.org_id =any(#{orgIdList, typeHandler=uuidListTypeHandler})
  283. </if>
  284. <if test="staffIdList != null and staffIdList.size() > 0">
  285. AND tms.staff_id =any(#{staffIdList, typeHandler=uuidListTypeHandler})
  286. </if>
  287. <if test="intoDateStart != null and intoDateEnd != null">
  288. AND tpi.into_date &gt;= #{intoDateStart}::timestamp with time zone
  289. AND tpi.into_date &lt; #{intoDateEnd}::timestamp with time zone + interval '1 day'
  290. </if>
  291. <if test="makeTimeStart != null and makeTimeEnd != null">
  292. AND tpi.make_time &gt;= #{makeTimeStart}::timestamp with time zone
  293. AND tpi.make_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
  294. </if>
  295. <if test="intoStatusList != null and intoStatusList.size()>0">
  296. AND tpi.into_status =
  297. any(#{intoStatusList, typeHandler= StringListTypeHandler})
  298. </if>
  299. <if test="intoStatus != null and intoStatus != ''">
  300. AND tpi.into_status LIKE concat('%',my_ex.likequery(#{intoStatus}),'%')
  301. </if>
  302. <if test="skuModel != null and skuModel!='' ">
  303. and exists (select 1 from dkic_b.t_psi_inbound_item tpii
  304. left join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tpii.sku_id
  305. where
  306. tpi.into_id = tpii.into_id
  307. and tpii.flg_valid
  308. AND position(#{skuModel} in tmgs.sku_model) > 0
  309. )
  310. </if>
  311. <if test="skuCode != null and skuCode!='' ">
  312. and exists (select 1 from dkic_b.t_psi_inbound_item tpii
  313. left join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tpii.sku_id
  314. where
  315. tpi.into_id = tpii.into_id
  316. and tpii.flg_valid
  317. AND position(#{skuCode} in tmgs.sku_code) > 0
  318. )
  319. </if>
  320. <if test="skuName != null and skuName!='' ">
  321. and exists (select 1 from dkic_b.t_psi_inbound_item tpii
  322. left join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tpii.sku_id
  323. where
  324. tpi.into_id = tpii.into_id
  325. and tpii.flg_valid
  326. AND position(#{skuName} in tmgs.sku_name) > 0
  327. )
  328. </if>
  329. </where>
  330. </sql>
  331. <sql id="ConditionIsSup">
  332. <where>
  333. <if test="intoNo != null and intoNo != ''">
  334. AND tpi.into_no LIKE concat('%',my_ex.likequery(#{intoNo}),'%')
  335. </if>
  336. <if test="intoType != null and intoType != ''">
  337. AND tpi.into_type LIKE concat('%',my_ex.likequery(#{intoType}),'%')
  338. </if>
  339. <if test="intoTypes != null and intoTypes.size()>0">
  340. AND tpi.into_type =any(#{intoTypes,typeHandler=StringListTypeHandler})
  341. </if>
  342. <if test="intoReasonList != null and intoReasonList.size()>0">
  343. AND tpi.into_reason =any(#{intoReasonList,typeHandler=UuidListTypeHandler})
  344. </if>
  345. <if test="fromId != null and fromId != ''">
  346. AND tpi.from_id = #{fromId}::uuid
  347. </if>
  348. <if test="fromNo != null and fromNo != ''">
  349. AND tpi.from_no LIKE concat('%',my_ex.likequery(#{fromNo}),'%')
  350. </if>
  351. <if test="orgId != null and orgId != ''">
  352. AND tpi.org_id = #{orgId}::uuid
  353. </if>
  354. <if test="orgName != null and orgName != ''">
  355. AND tmo.org_name LIKE concat('%',my_ex.likequery(#{orgName}),'%')
  356. </if>
  357. <if test="supName != null and supName != ''">
  358. AND tmp.sup_name LIKE concat('%',my_ex.likequery(#{supName}),'%')
  359. </if>
  360. <if test="staffName != null and staffName != ''">
  361. AND tms.staff_name LIKE concat('%',my_ex.likequery(#{staffName}),'%')
  362. </if>
  363. <if test="whName != null and whName != ''">
  364. AND tmw.wh_name LIKE concat('%',my_ex.likequery(#{whName}),'%')
  365. </if>
  366. <if test="staffId != null and staffId != ''">
  367. AND tpi.staff_id = #{staffId}::uuid
  368. </if>
  369. <if test="cusId != null and cusId != ''">
  370. AND tpi.cus_id = #{cusId}::uuid
  371. </if>
  372. <if test="supId != null and supId != ''">
  373. AND tpi.sup_id = #{supId}::uuid
  374. </if>
  375. <if test="makeStaff != null and makeStaff != ''">
  376. AND tpi.make_staff = #{makeStaff}
  377. </if>
  378. <if test="makeTime != null">
  379. AND tpi.make_time = #{makeTime}
  380. </if>
  381. <if test="receivableId != null and receivableId != ''">
  382. AND tpi.receivable_id = #{receivableId}
  383. </if>
  384. <if test="flgValid != null">
  385. AND tpi.flg_valid = #{flgValid}
  386. </if>
  387. <if test="cpId != null">
  388. AND tpi.cp_id = #{cpId}
  389. </if>
  390. <if test="searchText !=null and searchText != ''">
  391. AND ( tpi.into_no LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  392. or (exists (select 1 from dkic_b.t_psi_inbound_item tpii
  393. left join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tpii.sku_id
  394. where
  395. tpi.into_id = tpii.into_id
  396. and tpii.flg_valid
  397. AND position(#{searchText} in tmgs.sku_model) > 0
  398. ))
  399. )
  400. </if>
  401. </where>
  402. </sql>
  403. <sql id="idsForeach">
  404. <!-- 根据主键intoId批量操作 -->
  405. WHERE into_id in
  406. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  407. #{item}
  408. </foreach>
  409. </sql>
  410. <!-- 查询表t_psi_inbound,(条件查询+分页)列表 tpi.sum_quantity, tpi.sum_amount,-->
  411. <select id="selectByCond" resultMap="BaseResultMapResponse">
  412. SELECT
  413. <include refid="Base_Column_List_Response"/>
  414. ,tmo.org_name AS "orgName",
  415. tmp.sup_name AS "supplierName",
  416. tms.staff_name AS "staffName",
  417. tms.staff_name AS "makeStaffName",
  418. tmw.wh_name as "whName",
  419. tmc.cus_name as "cusName",
  420. tmc.cus_phone as "cusPhone",
  421. tmc.cus_from as "cusFrom",
  422. makestaff.staff_name as "makeStaffName",
  423. sys.f_get_name_i18n(tdktype.kind_name_i18n, #{i18n}) AS "intoTypeName",
  424. sys.f_get_name_i18n(tdk.kind_name_i18n, #{i18n}) AS "intoStatusName",
  425. tmd.data_value as into_reason_name,
  426. tmp.return_address,
  427. case when tpi.receivable_id is null then false
  428. when tmai.amt_handle = 0 then false
  429. else true end as "paymentFlag"
  430. FROM dkic_b.t_psi_inbound tpi
  431. <include refid="Join_Table"/>
  432. <include refid="Condition"/>
  433. order by tpi.make_time desc
  434. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  435. limit #{end} offset #{start}
  436. </if>
  437. </select>
  438. <!-- 查询表t_psi_inbound,(条件查询)个数 -->
  439. <select id="countByCond" resultType="Long">
  440. SELECT
  441. count(1)
  442. FROM dkic_b.t_psi_inbound tpi
  443. <include refid="Join_Table"/>
  444. <include refid="Condition"/>
  445. </select>
  446. <sql id="Join_Table">
  447. Left join dkic_b.t_mst_org tmo on tmo.org_id = tpi.org_id
  448. Left join dkic_b.t_mst_supplier tmp on tmp.sup_id = tpi.sup_id
  449. Left join dkic_b.t_mst_staff tms on tms.staff_id = tpi.staff_id
  450. Left join dkic_b.t_mst_staff makestaff on makestaff.staff_id = tpi.make_staff
  451. LEFT JOIN sys.t_data_kind tdk ON tdk.kind_code = tpi.into_status
  452. LEFT JOIN sys.t_data_kind tdktype ON tdktype.kind_code = tpi.into_type
  453. Left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = tpi.wh_id
  454. left join dkic_b.t_mst_customer tmc on tpi.cus_id = tmc.cus_id
  455. left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = tpi.into_reason
  456. left join dkic_b.t_mac_account_item tmai on tmai.item_id = tpi.receivable_id
  457. </sql>
  458. <!-- 根据主键查询表t_psi_inbound的一行数据 -->
  459. <select id="selectById" resultMap="BaseResultMapResponse">
  460. SELECT
  461. <include refid="Base_Column_List_Response"/>
  462. ,tmo.org_name as "orgName"
  463. ,tms.staff_name as "staffName"
  464. ,tms1.staff_name as "makeStaffName"
  465. ,tmc.cus_name as "cusName"
  466. ,tmc.cus_phone as "cusPhone"
  467. ,tmc.cus_from as "cusFrom"
  468. ,tmp.sup_name as "supplierName"
  469. ,tmw.wh_name as "whName"
  470. ,tmd.data_value as into_reason_name
  471. ,case when tpi.receivable_id is null then false
  472. when tmai.amt_handle = 0 then false
  473. else true end as "paymentFlag"
  474. ,tpp.pickup_date
  475. FROM dkic_b.t_psi_inbound tpi
  476. Left join dkic_b.t_psi_purchase tpp on tpp.pur_id = tpi.from_id
  477. Left join dkic_b.t_mst_org tmo on tmo.org_id = tpi.org_id
  478. Left join dkic_b.t_mst_supplier tmp on tmp.sup_id = tpi.sup_id
  479. left join dkic_b.t_mst_customer tmc on tpi.cus_id = tmc.cus_id
  480. Left join dkic_b.t_mst_staff tms on tms.staff_id = tpi.staff_id
  481. Left join dkic_b.t_mst_staff tms1 on tms1.staff_id = tpi.make_staff
  482. Left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = tpi.wh_id
  483. left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = tpi.into_reason
  484. left join dkic_b.t_mac_account_item tmai on tmai.item_id = tpi.receivable_id
  485. WHERE tpi.into_id = #{id}::uuid
  486. </select>
  487. <!-- 根据主键锁定表t_psi_inbound的一行数据 -->
  488. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  489. SELECT
  490. <include refid="Base_Column_List"/>
  491. FROM dkic_b.t_psi_inbound
  492. WHERE into_id = #{id}::uuid
  493. for update
  494. </select>
  495. <!-- 根据主键锁定表t_psi_inbound的多行数据 -->
  496. <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
  497. SELECT
  498. <include refid="Base_Column_List"/>
  499. FROM dkic_b.t_psi_inbound
  500. <include refid="idsForeach"/>
  501. for update
  502. </select>
  503. <insert id="insertBatch">
  504. insert into dkic_b.t_psi_inbound
  505. (
  506. <trim suffixOverrides=",">
  507. into_no,
  508. into_type,
  509. from_id,
  510. from_no,
  511. org_id,
  512. staff_id,
  513. cus_id,
  514. sup_id,
  515. into_status,
  516. intoing_qty,
  517. intoing_amt,
  518. into_qty,
  519. into_amt,
  520. return_qty,
  521. return_amt,
  522. into_date,
  523. remarks,
  524. annex_paths,
  525. make_staff,
  526. make_time,
  527. receivable_id,
  528. cp_id,
  529. op_app_code,
  530. wh_id,
  531. entry_reason,
  532. </trim>
  533. )
  534. values
  535. <foreach collection="list" index="index" item="item" separator=",">
  536. (
  537. <trim suffixOverrides=",">
  538. #{item.intoNo},
  539. #{item.intoType},
  540. #{item.fromId}::uuid,
  541. #{item.fromNo},
  542. #{item.orgId}::uuid,
  543. #{item.staffId}::uuid,
  544. #{item.cusId}::uuid,
  545. #{item.supId}::uuid,
  546. #{item.intoStatus},
  547. #{item.intoingQty},
  548. #{item.intoingAmt},
  549. #{item.intoQty},
  550. #{item.intoAmt},
  551. #{item.returnQty},
  552. #{item.returnAmt},
  553. #{item.intoDate},
  554. #{item.remarks},
  555. #{item.annexPaths},
  556. #{item.makeStaff}::uuid,
  557. #{item.makeTime},
  558. #{item.receivableId}::uuid,
  559. #{item.cpId},
  560. #{item.opAppCode},
  561. #{item.whId},
  562. #{item.intoReason}::uuid,
  563. </trim>
  564. )
  565. </foreach>
  566. </insert>
  567. <sql id="Base_Column_List_Item_Response_Join">
  568. tpii
  569. .
  570. item_id
  571. AS list_item_id,
  572. tpii.item_id AS list_into_item_Id,
  573. tpii.into_id AS list_into_id,
  574. tpi.into_no AS list_into_no,
  575. tpii.into_type AS list_into_type,
  576. tpii.from_id AS list_from_id,
  577. tpii.from_item_id AS list_from_item_id,
  578. tpii.item_index AS list_item_index,
  579. tpii.sku_id AS list_sku_id,
  580. -- tpii.price_into AS list_price_into,
  581. tpii.non_std_code AS list_non_std_code,
  582. tpii.into_status AS list_into_status,
  583. - sys.f_remove_zero(tpii.into_qty - tpii.return_qty) as list_can_return_qty,
  584. - sys.f_remove_zero(tpii.into_qty - tpii.return_qty) as list_intoing_qty,
  585. - tpii.price_into * (tpii.into_qty - tpii.return_qty) as list_intoing_amt,
  586. tpii.price_into as list_price_into,
  587. sys.f_remove_zero(tpii.into_qty) AS list_into_qty,
  588. tpii.into_amt AS list_into_amt,
  589. sys.f_remove_zero(tpii.return_qty) AS list_return_qty,
  590. tpii.return_amt AS list_return_amt,
  591. tpii.remarks AS list_remarks,
  592. tpii.inv_id AS list_inv_id,
  593. tpii.cost_price AS list_cost_price,
  594. tpii.cost_amt AS list_cost_amt,
  595. sys.f_remove_zero(tpii.out_qty) AS list_out_qty,
  596. sys.f_remove_zero(tpii.inv_qty) AS list_inv_qty,
  597. tpii.flg_valid AS list_flg_valids,
  598. tpii.cp_id AS list_cp_id,
  599. tmgs.sku_code AS list_sku_code,
  600. tmgs.sku_name AS list_sku_name,
  601. tmgs.sku_model AS list_sku_model,
  602. tmgb.short_name AS list_short_name,
  603. tmgs.sku_images AS list_sku_images,
  604. tmgs.price_standard AS list_price_std,
  605. i.inv_id as list_inv_id,
  606. i.wh_id as list_wh_id,
  607. i.inv_qty as list_inv_qty,
  608. i.usable_qty as list_usable_qty,
  609. i.wh_name as list_wh_name
  610. </sql>
  611. <!-- 查询表t_psi_inbound,(条件查询+分页)列表 -->
  612. <select id="selectInboundAndItem" resultMap="BaseResultMapItemResponse">
  613. SELECT
  614. tpi.into_id
  615. , tpi.into_no, tpi.into_type, tpi.from_id, tpi.from_no, tpi.org_id, tpi.staff_id, tpi.cus_id, tpi.sup_id,
  616. tpi.into_status, sys.f_remove_zero(tpi.intoing_qty) as intoing_qty, tpi.intoing_amt,
  617. 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,
  618. tpi.remarks, tpi.annex_paths, tpi.make_staff, tpi.make_time,
  619. tpi.receivable_id, tpi.flg_valid, tpi.cp_id,
  620. tpii
  621. .
  622. item_id
  623. AS list_item_id,
  624. tpii.item_id AS list_into_item_Id,
  625. tpii.into_id AS list_into_id,
  626. tpi.into_no AS list_into_no,
  627. tpii.into_type AS list_into_type,
  628. tpii.from_id AS list_from_id,
  629. tpii.from_item_id AS list_from_item_id,
  630. tpii.item_index AS list_item_index,
  631. tpii.sku_id AS list_sku_id,
  632. -- tpii.price_into AS list_price_into,
  633. tpii.non_std_code AS list_non_std_code,
  634. tpii.into_status AS list_into_status,
  635. - sys.f_remove_zero(tpii.into_qty - tpii.return_qty) as list_can_return_qty,
  636. - sys.f_remove_zero(tpii.into_qty - tpii.return_qty) as list_intoing_qty,
  637. - tpii.price_into * (tpii.into_qty - tpii.return_qty) as list_intoing_amt,
  638. tpii.price_into as list_price_into,
  639. sys.f_remove_zero(tpii.into_qty) AS list_into_qty,
  640. tpii.into_amt AS list_into_amt,
  641. sys.f_remove_zero(tpii.return_qty) AS list_return_qty,
  642. tpii.return_amt AS list_return_amt,
  643. tpii.remarks AS list_remarks,
  644. tpii.inv_id AS list_inv_id,
  645. tpii.cost_price AS list_cost_price,
  646. tpii.cost_amt AS list_cost_amt,
  647. sys.f_remove_zero(tpii.out_qty) AS list_out_qty,
  648. sys.f_remove_zero(tpii.inv_qty) AS list_inv_qty,
  649. tpii.flg_valid AS list_flg_valids,
  650. tpii.cp_id AS list_cp_id,
  651. tmgs.sku_code AS list_sku_code,
  652. tmgs.sku_name AS list_sku_name,
  653. tmgs.sku_model AS list_sku_model,
  654. tmgb.short_name AS list_short_name,
  655. tmgs.sku_images AS list_sku_images,
  656. tmgs.price_standard AS list_price_std,
  657. tmgs.sku_spec as "list_sku_spec",
  658. i.inv_id as list_inv_id,
  659. i.wh_id as list_wh_id,
  660. i.inv_qty as list_inv_qty,
  661. i.usable_qty as list_usable_qty,
  662. i.wh_name as list_wh_name
  663. FROM dkic_b.t_psi_inbound tpi
  664. left join dkic_b.t_psi_inbound_item tpii on tpi.into_id = tpii.into_id and ( tpii.into_qty - tpii.return_qty) > 0
  665. left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = tpii.wh_id
  666. inner join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tpii.sku_id
  667. left join dkic_b.t_mst_goods_brand tmgb on tmgb.brand_id = tmgs.brand_id
  668. left join(SELECT T.*
  669. FROM (select tpi.inv_id,
  670. tpi.wh_id,
  671. tpi.inv_qty,
  672. tpi.usable_qty,
  673. tpi.sku_id,
  674. tpi.non_std_code,
  675. tpi.cp_id,
  676. tmw.wh_name,
  677. rank()
  678. over (partition by tpi.cp_id,tpi.sku_id,tpi.non_std_code order by tpi.inv_id) as RK
  679. from dkic_b.t_psi_inventory as tpi
  680. left join dkic_b.t_mst_warehouse as tmw on tmw.wh_id = tpi.wh_id) T
  681. WHERE T.RK = 1) as i
  682. on i.sku_id = tpii.sku_id and i.non_std_code = tpii.non_std_code and i.cp_id = tpii.cp_id
  683. <include refid="ConditionIsSup"/>
  684. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  685. limit #{end} offset #{start}
  686. </if>
  687. </select>
  688. <!-- 查询表t_psi_inbound,(条件查询)个数 -->
  689. <select id="selectInboundAndItemCountByCond" resultType="Long">
  690. SELECT
  691. count(1)
  692. FROM dkic_b.t_psi_inbound tpi
  693. left join dkic_b.t_psi_inbound_item tpii on tpi.into_id = tpii.into_id
  694. left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = tpii.wh_id
  695. inner join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tpii.sku_id
  696. <include refid="ConditionIsSup"/>
  697. </select>
  698. <update id="updateAmount" parameterType="com.dk.mdm.model.pojo.ivt.InboundItem">
  699. update dkic_b.t_psi_inbound
  700. <set>
  701. <if test="returnQty!= null">
  702. return_qty= #{returnQty},
  703. </if>
  704. <if test="returnAmt!= null">
  705. return_amt = #{returnAmt},
  706. </if>
  707. </set>
  708. where into_id = #{intoId}::uuid
  709. </update>
  710. <!-- 根据id查询带出销售退货单数据(采购退货入库办理用)-->
  711. <select id="selectMessageByOtherQuery" resultMap="BaseResultMapResponse">
  712. SELECT
  713. <include refid="Base_Column_List_Response"/>
  714. ,tmo.org_name as "orgName"
  715. ,tms.staff_name as "staffName"
  716. ,tmc.cus_code
  717. ,tmc.cus_name as "cusName"
  718. ,tmc.cus_phone as "cusPhone"
  719. ,tmc.contact_phone
  720. ,tmc.contact_name
  721. ,tmc.address_area
  722. ,tmc.address_name
  723. ,tmc.address_no
  724. ,tmc.address_gcj02
  725. ,tmc.address_full
  726. ,tmsc.channel_name
  727. ,tmsc.channel_name
  728. ,tmsc.channel_name
  729. ,tmd.data_value as cus_from_name
  730. FROM dkic_b.t_psi_inbound tpi
  731. Left join dkic_b.t_mst_org tmo on tmo.org_id = tpi.org_id
  732. Left join dkic_b.t_mst_staff tms on tms.staff_id = tpi.staff_id
  733. left join dkic_b.t_mst_customer tmc on tpi.cus_id = tmc.cus_id
  734. left join dkic_b.t_mst_sale_channel tmsc on tmc.channel_id = tmsc.channel_id
  735. left join dkic_b.t_mst_dictionary_data tmd on tmc.cus_from = tmd.data_id
  736. <where>
  737. <if test="intoId != null and intoId != ''">
  738. AND tpi.into_id = #{intoId}::uuid
  739. </if>
  740. <if test="intoStatus != null and intoStatus != ''">
  741. AND tpi.into_status = #{intoStatus}
  742. </if>
  743. <if test="fromId != null and fromId != ''">
  744. AND tpi.from_id = #{fromId}::uuid
  745. </if>
  746. </where>
  747. </select>
  748. <!-- 入库办理显示字段 -->
  749. <sql id="Base_Column_List_Response_Into">
  750. tpi.into_id,
  751. tpi.into_no,
  752. tpi.into_type,
  753. tpi.from_id,
  754. tpi.from_no,
  755. tpi.org_id,
  756. tpi.staff_id,
  757. tpi.cus_id,
  758. tpi.sup_id,
  759. tpi.into_status,
  760. sys.f_remove_zero(tpi.intoing_qty) as intoing_qty,
  761. tpi.intoing_amt,
  762. sys.f_remove_zero(tpi.into_qty) as into_qty,
  763. tpi.into_amt,
  764. sys.f_remove_zero(tpi.return_qty) as return_qty,
  765. tpi.return_amt,
  766. tpi.into_date,
  767. tpi.remarks,
  768. tpi.annex_paths,
  769. tpi.make_staff,
  770. tpi.make_time,
  771. tpi.wh_id,
  772. tpi.into_reason,
  773. tpi.flg_valid,
  774. tpi.flg_auto_handle,
  775. tpi.op_update_time
  776. </sql>
  777. <sql id="Base_Column_List_Response_Out">
  778. tpo.out_id as into_id,
  779. tpo.out_no as into_no,
  780. tpo.out_type as into_type,
  781. tpo.from_id,
  782. tpo.from_no,
  783. tpo.org_id,
  784. tpo.staff_id,
  785. tpo.cus_id,
  786. tpo.sup_id,
  787. tpo.out_status,
  788. sys.f_remove_zero(tpo.outing_qty) as intoing_qty,
  789. tpo.outing_amt as intoing_amt,
  790. sys.f_remove_zero(tpo.out_qty) as into_qty,
  791. tpo.out_amt as into_amt,
  792. sys.f_remove_zero(tpo.return_qty) as return_qty,
  793. tpo.return_amt,
  794. tpo.out_date as into_date,
  795. tpo.remarks,
  796. tpo.annex_paths,
  797. tpo.make_staff,
  798. tpo.make_time,
  799. null as wh_id,
  800. tpo.out_reason as into_reason,
  801. tpo.flg_valid,
  802. tpo.flg_auto_handle,
  803. tpo.op_update_time
  804. </sql>
  805. <!-- 条件查询 web端入库办理用,-->
  806. <select id="selectInbound" resultMap="BaseResultMapResponse">
  807. select * from (
  808. SELECT
  809. <include refid="Base_Column_List_Response_Into"/>,
  810. tmo.org_name AS "orgName",
  811. tmp.sup_name AS "supplierName",
  812. tms.staff_name AS "staffName",
  813. tms.staff_name AS "makeStaffName",
  814. tmc.cus_name as "cusName",
  815. tmc.cus_phone as "cusPhone",
  816. tmc.cus_from as "cusFrom",
  817. tmc.address_full,
  818. makestaff.staff_name as "makeStaffName",
  819. sys.f_get_name_i18n(tdktype.kind_name_i18n, #{i18n}) AS "intoTypeName",
  820. sys.f_get_name_i18n(tdk.kind_name_i18n, #{i18n}) AS "intoStatusName",
  821. tmd.data_value as into_reason_name
  822. FROM dkic_b.t_psi_inbound tpi
  823. <include refid="Select_Inbound_Join_Table_Into"/>
  824. <where>
  825. AND tpi.cp_id = #{cpId}
  826. AND tpi.into_type != '入库类型-外协入库'
  827. <if test="intoTypes != null and intoTypes.size()>0">
  828. AND tpi.into_type =any(#{intoTypes,typeHandler=StringListTypeHandler})
  829. </if>
  830. <if test="intoTypes == null || intoTypes.size()==0">
  831. AND (tpi.into_type = '入库类型-其他入库'
  832. or tpi.into_type = '入库类型-采购入库' or tpi.into_type = '入库类型-期初入库')
  833. </if>
  834. <if test=" intoStatus != null and intoStatus != '' ">
  835. AND tpi.into_status LIKE concat('%',my_ex.likequery(#{intoStatus}),'%')
  836. </if>
  837. <if test="makeTimeStart != null and makeTimeEnd != null">
  838. AND tpi.make_time &gt;= #{makeTimeStart}::timestamp with time zone
  839. AND tpi.make_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
  840. </if>
  841. <if test="intoNo != null and intoNo != ''">
  842. AND tpi.into_no LIKE concat('%',my_ex.likequery(#{intoNo}),'%')
  843. </if>
  844. <if test="cusPhone != null and cusPhone != ''">
  845. AND tmc.cus_phone LIKE concat('%',my_ex.likequery(#{cusPhone}),'%')
  846. </if>
  847. <if test="cusName != null and cusName != ''">
  848. AND tmc.cus_name LIKE concat('%',my_ex.likequery(#{cusName}),'%')
  849. </if>
  850. <if test="whName != null and whName != ''">
  851. AND
  852. exists(select 1 from dkic_b.t_psi_inbound_item item
  853. inner join dkic_b.t_mst_warehouse tmw on item.wh_id = tmw.wh_id where tpi.into_id = item.into_id
  854. and item.flg_valid and tmw.wh_name LIKE concat ( '%', my_ex.likequery ( #{whName} ), '%' ) )
  855. </if>
  856. <if test="supId != null and supId != ''">
  857. AND tpi.sup_id = #{supId}::uuid
  858. </if>
  859. <if test="orgIdList != null and orgIdList.size() > 0">
  860. AND tpi.org_id =any(#{orgIdList, typeHandler=uuidListTypeHandler})
  861. </if>
  862. <if test="staffIdList != null and staffIdList.size() > 0">
  863. AND tpi.staff_id =any(#{staffIdList, typeHandler=uuidListTypeHandler})
  864. </if>
  865. <if test="flgValidList != null and flgValidList.size()>0">
  866. AND tpi.flg_valid =any(#{flgValidList, typeHandler=BooleanListTypeHandler})
  867. </if>
  868. <if test="searchText !=null and searchText != ''">
  869. AND (
  870. tpi.into_no LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  871. )
  872. </if>
  873. </where>
  874. union all
  875. select
  876. <include refid="Base_Column_List_Response_Out"/>,
  877. tmo.org_name AS "orgName",
  878. tmp.sup_name AS "supplierName",
  879. tms.staff_name AS "staffName",
  880. tms.staff_name AS "makeStaffName",
  881. tmc.cus_name as "cusName",
  882. tmc.cus_phone as "cusPhone",
  883. tmc.cus_from as "cusFrom",
  884. tmc.address_full,
  885. makestaff.staff_name as "makeStaffName",
  886. sys.f_get_name_i18n(tdktype.kind_name_i18n, #{i18n}) AS "intoTypeName",
  887. sys.f_get_name_i18n(tdk.kind_name_i18n, #{i18n}) AS "intoStatusName",
  888. tmd.data_value as into_reason_name
  889. from dkic_b.t_psi_outbound tpo
  890. <include refid="Select_Inbound_Join_Table_Out"/>
  891. <where>
  892. AND tpo.cp_id = #{cpId}
  893. <if test="intoTypes != null and intoTypes.size()>0">
  894. AND tpo.out_type =any(#{intoTypes,typeHandler=StringListTypeHandler})
  895. </if>
  896. <if test="intoTypes == null || intoTypes.size()==0">
  897. AND tpo.out_type = '出库类型-销退回库'
  898. </if>
  899. <if test="outStatus != null and outStatus != '' ">
  900. AND tpo.out_status LIKE concat('%',my_ex.likequery(#{outStatus}),'%')
  901. </if>
  902. <if test="makeTimeStart != null and makeTimeEnd != null">
  903. AND tpo.make_time &gt;= #{makeTimeStart}::timestamp with time zone
  904. AND tpo.make_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
  905. </if>
  906. <if test="intoNo != null and intoNo != ''">
  907. AND tpo.out_no LIKE concat('%',my_ex.likequery(#{intoNo}),'%')
  908. </if>
  909. <if test="cusPhone != null and cusPhone != ''">
  910. AND tmc.cus_phone LIKE concat('%',my_ex.likequery(#{cusPhone}),'%')
  911. </if>
  912. <if test="cusName != null and cusName != ''">
  913. AND tmc.cus_name LIKE concat('%',my_ex.likequery(#{cusName}),'%')
  914. </if>
  915. <if test="supId != null and supId != ''">
  916. AND tpo.sup_id = #{supId}::uuid
  917. </if>
  918. <if test="orgIdList != null and orgIdList.size() > 0">
  919. AND tpo.org_id =any(#{orgIdList, typeHandler=uuidListTypeHandler})
  920. </if>
  921. <if test="staffIdList != null and staffIdList.size() > 0">
  922. AND tpo.staff_id =any(#{staffIdList, typeHandler=uuidListTypeHandler})
  923. </if>
  924. <if test="flgValidList != null and flgValidList.size()>0">
  925. AND tpo.flg_valid =any(#{flgValidList, typeHandler=BooleanListTypeHandler})
  926. </if>
  927. <if test="searchText !=null and searchText != ''">
  928. AND (
  929. tpo.out_no LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  930. )
  931. </if>
  932. </where>
  933. ) tt order by tt.op_update_time desc
  934. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  935. limit #{end} offset #{start}
  936. </if>
  937. </select>
  938. <!-- 条件查询 web端入库办理用个数 -->
  939. <select id="selectInboundCond" resultType="Long">
  940. SELECT
  941. count(1) from (
  942. SELECT
  943. <include refid="Base_Column_List_Response_Into"/>,
  944. tmo.org_name AS "orgName",
  945. tmp.sup_name AS "supplierName",
  946. tms.staff_name AS "staffName",
  947. tms.staff_name AS "makeStaffName",
  948. tmw.wh_name as "whName",
  949. tmc.cus_name as "cusName",
  950. tmc.cus_phone as "cusPhone",
  951. tmc.cus_from as "cusFrom",
  952. makestaff.staff_name as "makeStaffName",
  953. sys.f_get_name_i18n(tdktype.kind_name_i18n, #{i18n}) AS "intoTypeName",
  954. sys.f_get_name_i18n(tdk.kind_name_i18n, #{i18n}) AS "intoStatusName",
  955. tmd.data_value as into_reason_name
  956. FROM dkic_b.t_psi_inbound tpi
  957. <include refid="Select_Inbound_Join_Table_Into"/>
  958. Left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = tpi.wh_id
  959. <where>
  960. AND tpi.cp_id = #{cpId}
  961. <if test="intoTypes != null and intoTypes.size()>0">
  962. AND tpi.into_type =any(#{intoTypes,typeHandler=StringListTypeHandler})
  963. </if>
  964. <if test="intoTypes == null || intoTypes.size()==0">
  965. AND (tpi.into_type = '入库类型-其他入库'
  966. or tpi.into_type = '入库类型-采购入库'or tpi.into_type = '入库类型-期初入库')
  967. </if>
  968. <if test=" intoStatus != null and intoStatus != '' ">
  969. AND tpi.into_status LIKE concat('%',my_ex.likequery(#{intoStatus}),'%')
  970. </if>
  971. <if test="makeTimeStart != null and makeTimeEnd != null">
  972. AND tpi.make_time &gt;= #{makeTimeStart}::timestamp with time zone
  973. AND tpi.make_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
  974. </if>
  975. <if test="intoNo != null and intoNo != ''">
  976. AND tpi.into_no LIKE concat('%',my_ex.likequery(#{intoNo}),'%')
  977. </if>
  978. <if test="cusPhone != null and cusPhone != ''">
  979. AND tmc.cus_phone LIKE concat('%',my_ex.likequery(#{cusPhone}),'%')
  980. </if>
  981. <if test="cusName != null and cusName != ''">
  982. AND tmc.cus_name LIKE concat('%',my_ex.likequery(#{cusName}),'%')
  983. </if>
  984. <if test="supId != null and supId != ''">
  985. AND tpi.sup_id = #{supId}::uuid
  986. </if>
  987. <if test="orgIdList != null and orgIdList.size() > 0">
  988. AND tmo.org_id =any(#{orgIdList, typeHandler=uuidListTypeHandler})
  989. </if>
  990. <if test="staffIdList != null and staffIdList.size() > 0">
  991. AND tms.staff_id =any(#{staffIdList, typeHandler=uuidListTypeHandler})
  992. </if>
  993. <if test="flgValidList != null and flgValidList.size()>0">
  994. AND tpi.flg_valid =any(#{flgValidList, typeHandler=BooleanListTypeHandler})
  995. </if>
  996. </where>
  997. union all
  998. select
  999. <include refid="Base_Column_List_Response_Out"/>,
  1000. tmo.org_name AS "orgName",
  1001. tmp.sup_name AS "supplierName",
  1002. tms.staff_name AS "staffName",
  1003. tms.staff_name AS "makeStaffName",
  1004. null as "whName",
  1005. tmc.cus_name as "cusName",
  1006. tmc.cus_phone as "cusPhone",
  1007. tmc.cus_from as "cusFrom",
  1008. makestaff.staff_name as "makeStaffName",
  1009. sys.f_get_name_i18n(tdktype.kind_name_i18n, #{i18n}) AS "intoTypeName",
  1010. sys.f_get_name_i18n(tdk.kind_name_i18n, #{i18n}) AS "intoStatusName",
  1011. tmd.data_value as into_reason_name
  1012. from dkic_b.t_psi_outbound tpo
  1013. <include refid="Select_Inbound_Join_Table_Out"/>
  1014. <where>
  1015. AND tpo.cp_id = #{cpId}
  1016. <if test="intoTypes != null and intoTypes.size()>0">
  1017. AND tpo.out_type =any(#{intoTypes,typeHandler=StringListTypeHandler})
  1018. </if>
  1019. <if test="intoTypes == null || intoTypes.size()==0">
  1020. AND tpo.out_type = '出库类型-销退回库'
  1021. </if>
  1022. <if test="outStatus != null and outStatus != '' ">
  1023. AND tpo.out_status LIKE concat('%',my_ex.likequery(#{outStatus}),'%')
  1024. </if>
  1025. <if test="makeTimeStart != null and makeTimeEnd != null">
  1026. AND tpo.make_time &gt;= #{makeTimeStart}::timestamp with time zone
  1027. AND tpo.make_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
  1028. </if>
  1029. <if test="intoNo != null and intoNo != ''">
  1030. AND tpo.out_no LIKE concat('%',my_ex.likequery(#{intoNo}),'%')
  1031. </if>
  1032. <if test="cusPhone != null and cusPhone != ''">
  1033. AND tmc.cus_phone LIKE concat('%',my_ex.likequery(#{cusPhone}),'%')
  1034. </if>
  1035. <if test="cusName != null and cusName != ''">
  1036. AND tmc.cus_name LIKE concat('%',my_ex.likequery(#{cusName}),'%')
  1037. </if>
  1038. <if test="supId != null and supId != ''">
  1039. AND tpo.sup_id = #{supId}::uuid
  1040. </if>
  1041. <if test="orgIdList != null and orgIdList.size() > 0">
  1042. AND tmo.org_id =any(#{orgIdList, typeHandler=uuidListTypeHandler})
  1043. </if>
  1044. <if test="staffIdList != null and staffIdList.size() > 0">
  1045. AND tms.staff_id =any(#{staffIdList, typeHandler=uuidListTypeHandler})
  1046. </if>
  1047. <if test="flgValidList != null and flgValidList.size()>0">
  1048. AND tpo.flg_valid =any(#{flgValidList, typeHandler=BooleanListTypeHandler})
  1049. </if>
  1050. </where>
  1051. ) tt
  1052. </select>
  1053. <!--入库办理显示入库关联表-->
  1054. <sql id="Select_Inbound_Join_Table_Into">
  1055. Left join dkic_b.t_mst_org tmo on tmo.org_id = tpi.org_id
  1056. Left join dkic_b.t_mst_supplier tmp on tmp.sup_id = tpi.sup_id
  1057. Left join dkic_b.t_mst_staff tms on tms.staff_id = tpi.staff_id
  1058. Left join dkic_b.t_mst_staff makestaff on makestaff.staff_id = tpi.make_staff
  1059. LEFT JOIN sys.t_data_kind tdk ON tdk.kind_code = tpi.into_status
  1060. LEFT JOIN sys.t_data_kind tdktype ON tdktype.kind_code = tpi.into_type
  1061. left join dkic_b.t_mst_customer tmc on tpi.cus_id = tmc.cus_id
  1062. left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = tpi.into_reason
  1063. </sql>
  1064. <!--入库办理显示出库关联表-->
  1065. <sql id="Select_Inbound_Join_Table_Out">
  1066. Left join dkic_b.t_mst_org tmo on tmo.org_id = tpo.org_id
  1067. Left join dkic_b.t_mst_supplier tmp on tmp.sup_id = tpo.sup_id
  1068. Left join dkic_b.t_mst_staff tms on tms.staff_id = tpo.staff_id
  1069. Left join dkic_b.t_mst_staff makestaff on makestaff.staff_id = tpo.make_staff
  1070. LEFT JOIN sys.t_data_kind tdk ON tdk.kind_code = tpo.out_status
  1071. LEFT JOIN sys.t_data_kind tdktype ON tdktype.kind_code = tpo.out_type
  1072. left join dkic_b.t_mst_customer tmc on tpo.cus_id = tmc.cus_id
  1073. left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = tpo.out_reason
  1074. </sql>
  1075. <update id="updateIntoStatus" parameterType="com.dk.mdm.model.pojo.ivt.InboundItem">
  1076. update dkic_b.t_psi_inbound
  1077. <set>
  1078. <if test="intoStatus!= null">
  1079. into_status= #{intoStatus},
  1080. </if>
  1081. </set>
  1082. where into_id = #{intoId}::uuid
  1083. </update>
  1084. <!-- 采购退货用-->
  1085. <resultMap id="BaseResultMapInboundReturnResponse" type="com.dk.mdm.model.response.ivt.InboundResponse">
  1086. <id column="into_id" property="intoId" typeHandler="UuidTypeHandler"/>
  1087. <result column="into_no" property="intoNo"/>
  1088. <result column="into_type" property="intoType"/>
  1089. <result column="from_id" property="fromId" typeHandler="UuidTypeHandler"/>
  1090. <result column="from_no" property="fromNo"/>
  1091. <result column="org_id" property="orgId" typeHandler="UuidTypeHandler"/>
  1092. <result column="staff_id" property="staffId" typeHandler="UuidTypeHandler"/>
  1093. <result column="sup_id" property="supId" typeHandler="UuidTypeHandler"/>
  1094. <result column="into_status" property="intoStatus"/>
  1095. <result column="intoing_qty" property="intoingQty"/>
  1096. <result column="intoing_amt" property="intoingAmt"/>
  1097. <result column="into_qty" property="intoQty"/>
  1098. <result column="into_amt" property="intoAmt"/>
  1099. <result column="wh_id" property="whId" typeHandler="UuidTypeHandler"/>
  1100. <result column="return_qty" property="returnQty"/>
  1101. <result column="return_amt" property="returnAmt"/>
  1102. <result column="into_date" property="intoDate" typeHandler="TimestampTypeHandler"/>
  1103. <result column="remarks" property="remarks"/>
  1104. <result column="annex_paths" property="annexPaths" typeHandler="JsonTypeHandler"/>
  1105. <result column="make_staff" property="makeStaff" typeHandler="UuidTypeHandler"/>
  1106. <result column="make_time" property="makeTime" typeHandler="TimestampTypeHandler"/>
  1107. <result column="receivable_id" property="receivableId" typeHandler="UuidTypeHandler"/>
  1108. <result column="flg_valid" property="flgValid"/>
  1109. <result column="cp_id" property="cpId"/>
  1110. <result column="sup_name" property="supName"/>
  1111. <result column="into_reason" property="intoReason" typeHandler="UuidTypeHandler"/>
  1112. <result column="into_reason_name" property="intoReasonName" />
  1113. <result column="org_name" property="orgName" />
  1114. <result column="staff_name" property="staffName" />
  1115. <result column="contact_phone" property="contactPhone" />
  1116. <result column="contact_name" property="contactName" />
  1117. <result column="channel_name" property="channelName" />
  1118. <result column="cus_from_name" property="cusFromName" />
  1119. <result column="return_address" property="returnAddress" />
  1120. <result column="purSumAmount" property="purSumAmount" />
  1121. <result column="purReturnAmt" property="purReturnAmt" />
  1122. <result column="intoStatusName" property="intoStatusName" />
  1123. </resultMap>
  1124. <sql id="Join_Table_Return">
  1125. Left join dkic_b.t_mst_org tmo on tmo.org_id = tpi.org_id
  1126. Left join dkic_b.t_mst_supplier tmp on tmp.sup_id = tpi.sup_id
  1127. Left join dkic_b.t_mst_staff tms on tms.staff_id = tpi.staff_id
  1128. Left join dkic_b.t_mst_staff tms1 on tms1.staff_id = tpi.make_staff
  1129. LEFT JOIN sys.t_data_kind tdk ON tdk.kind_code = tpi.into_status
  1130. LEFT JOIN sys.t_data_kind tdktype ON tdktype.kind_code = tpi.into_type
  1131. Left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = tpi.wh_id
  1132. left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = tpi.into_reason
  1133. left join dkic_b.t_mac_account_item tmai on tmai.item_id = tpi.receivable_id
  1134. </sql>
  1135. <!-- 采购退货用-->
  1136. <select id="selectByInboundReturnCond" resultMap="BaseResultMapInboundReturnResponse">
  1137. SELECT
  1138. <include refid="Base_Column_List_Response"/>
  1139. ,tmo.org_name
  1140. ,tmp.sup_name
  1141. ,tms.staff_name
  1142. ,tmw.wh_name
  1143. ,tms1.staff_name as make_staff_name
  1144. ,sys.f_get_name_i18n(tdktype.kind_name_i18n, #{i18n}) AS into_type_name
  1145. ,sys.f_get_name_i18n(tdk.kind_name_i18n, #{i18n}) AS into_status_name
  1146. ,tmd.data_value as into_reason_name
  1147. ,tmp.return_address
  1148. ,tmp.contact_name
  1149. ,tmp.contact_phone
  1150. ,case when tpi.receivable_id is null then false
  1151. when tmai.amt_handle = 0 then false
  1152. else true end as "paymentFlag"
  1153. FROM dkic_b.t_psi_inbound tpi
  1154. <include refid="Join_Table_Return"/>
  1155. <where>
  1156. <if test="intoNo != null and intoNo != ''">
  1157. AND tpi.into_no LIKE concat('%',my_ex.likequery(#{intoNo}),'%')
  1158. </if>
  1159. <if test="intoType != null and intoType != ''">
  1160. AND tpi.into_type LIKE concat('%',my_ex.likequery(#{intoType}),'%')
  1161. </if>
  1162. <if test="intoTypes != null and intoTypes.size()>0">
  1163. AND tpi.into_type =any(#{intoTypes,typeHandler=StringListTypeHandler})
  1164. </if>
  1165. <if test="intoReasonList != null and intoReasonList.size()>0">
  1166. AND tpi.into_reason =any(#{intoReasonList,typeHandler=UuidListTypeHandler})
  1167. </if>
  1168. <if test="searchText !=null and searchText != ''">
  1169. AND (
  1170. tpi.into_no LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1171. or tmp.return_address LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1172. or tmp.contact_phone LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1173. or tmp.sup_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1174. )
  1175. </if>
  1176. <if test="staffIds != null and staffIds.size()>0">
  1177. AND t.staff_id = any(#{staffIds, typeHandler=uuidListTypeHandler})
  1178. </if>
  1179. <if test="orgIds != null and orgIds.size()>0">
  1180. AND t.org_id = any(#{orgIds, typeHandler=uuidListTypeHandler})
  1181. </if>
  1182. <if test="fromId != null and fromId != ''">
  1183. AND tpi.from_id = #{fromId}::uuid
  1184. </if>
  1185. <if test="fromNo != null and fromNo != ''">
  1186. AND tpi.from_no LIKE concat('%',my_ex.likequery(#{fromNo}),'%')
  1187. </if>
  1188. <if test="orgId != null and orgId != ''">
  1189. AND tpi.org_id = #{orgId}::uuid
  1190. </if>
  1191. <if test="orgName != null and orgName != ''">
  1192. AND tmo.org_name LIKE concat('%',my_ex.likequery(#{orgName}),'%')
  1193. </if>
  1194. <if test="supName != null and supName != ''">
  1195. AND tmp.sup_name LIKE concat('%',my_ex.likequery(#{supName}),'%')
  1196. </if>
  1197. <if test="staffName != null and staffName != ''">
  1198. AND tms.staff_name LIKE concat('%',my_ex.likequery(#{staffName}),'%')
  1199. </if>
  1200. <if test="whName != null and whName != ''">
  1201. AND tmw.wh_name LIKE concat('%',my_ex.likequery(#{whName}),'%')
  1202. </if>
  1203. <if test="staffId != null and staffId != ''">
  1204. AND tpi.staff_id = #{staffId}::uuid
  1205. </if>
  1206. <if test="supId != null and supId != ''">
  1207. AND tpi.sup_id = #{supId}::uuid
  1208. </if>
  1209. <if test="makeStaff != null and makeStaff != ''">
  1210. AND tpi.make_staff = #{makeStaff}
  1211. </if>
  1212. <if test="viewVoidedDocuments !=null and viewVoidedDocuments == false">
  1213. AND tpi.flg_valid = true
  1214. </if>
  1215. <if test="makeTime != null">
  1216. AND tpi.make_time = #{makeTime}
  1217. </if>
  1218. <if test="receivableId != null and receivableId != ''">
  1219. AND tpi.receivable_id = #{receivableId}
  1220. </if>
  1221. <if test="flgValid != null">
  1222. AND tpi.flg_valid = #{flgValid}
  1223. </if>
  1224. <if test="cpId != null">
  1225. AND tpi.cp_id = #{cpId}
  1226. </if>
  1227. <if test="intoDateStart != null and intoDateEnd != null">
  1228. AND tpi.into_date &gt;= #{intoDateStart}::timestamp with time zone
  1229. AND tpi.into_date &lt; #{intoDateEnd}::timestamp with time zone + interval '1 day'
  1230. </if>
  1231. <if test="makeTimeStart != null and makeTimeEnd != null">
  1232. AND tpi.make_time &gt;= #{makeTimeStart}::timestamp with time zone
  1233. AND tpi.make_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
  1234. </if>
  1235. <if test="intoStatusList != null and intoStatusList.size()>0">
  1236. AND tpi.into_status =
  1237. any(#{intoStatusList, typeHandler= StringListTypeHandler})
  1238. </if>
  1239. <if test="intoStatus != null and intoStatus != ''">
  1240. AND tpi.into_status LIKE concat('%',my_ex.likequery(#{intoStatus}),'%')
  1241. </if>
  1242. </where>
  1243. ORDER BY tpi.op_create_time DESC
  1244. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  1245. limit #{end} offset #{start}
  1246. </if>
  1247. </select>
  1248. <!--采购退货用 查询表t_psi_inbound,(条件查询)个数 -->
  1249. <select id="countByInboundReturnCond" resultType="Long">
  1250. SELECT
  1251. count(1)
  1252. FROM dkic_b.t_psi_inbound tpi
  1253. <include refid="Join_Table_Return"/>
  1254. <where>
  1255. <if test="intoNo != null and intoNo != ''">
  1256. AND tpi.into_no LIKE concat('%',my_ex.likequery(#{intoNo}),'%')
  1257. </if>
  1258. <if test="intoType != null and intoType != ''">
  1259. AND tpi.into_type LIKE concat('%',my_ex.likequery(#{intoType}),'%')
  1260. </if>
  1261. <if test="intoTypes != null and intoTypes.size()>0">
  1262. AND tpi.into_type =any(#{intoTypes,typeHandler=StringListTypeHandler})
  1263. </if>
  1264. <if test="intoReasonList != null and intoReasonList.size()>0">
  1265. AND tpi.into_reason =any(#{intoReasonList,typeHandler=UuidListTypeHandler})
  1266. </if>
  1267. <if test="searchText !=null and searchText != ''">
  1268. AND (
  1269. tpi.into_no LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1270. or tmp.return_address LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1271. or tmp.contact_phone LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1272. or tmp.sup_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1273. )
  1274. </if>
  1275. <if test="staffIds != null and staffIds.size()>0">
  1276. AND t.staff_id = any(#{staffIds, typeHandler=uuidListTypeHandler})
  1277. </if>
  1278. <if test="orgIds != null and orgIds.size()>0">
  1279. AND t.org_id = any(#{orgIds, typeHandler=uuidListTypeHandler})
  1280. </if>
  1281. <if test="fromId != null and fromId != ''">
  1282. AND tpi.from_id = #{fromId}::uuid
  1283. </if>
  1284. <if test="fromNo != null and fromNo != ''">
  1285. AND tpi.from_no LIKE concat('%',my_ex.likequery(#{fromNo}),'%')
  1286. </if>
  1287. <if test="orgId != null and orgId != ''">
  1288. AND tpi.org_id = #{orgId}::uuid
  1289. </if>
  1290. <if test="orgName != null and orgName != ''">
  1291. AND tmo.org_name LIKE concat('%',my_ex.likequery(#{orgName}),'%')
  1292. </if>
  1293. <if test="supName != null and supName != ''">
  1294. AND tmp.sup_name LIKE concat('%',my_ex.likequery(#{supName}),'%')
  1295. </if>
  1296. <if test="staffName != null and staffName != ''">
  1297. AND tms.staff_name LIKE concat('%',my_ex.likequery(#{staffName}),'%')
  1298. </if>
  1299. <if test="whName != null and whName != ''">
  1300. AND tmw.wh_name LIKE concat('%',my_ex.likequery(#{whName}),'%')
  1301. </if>
  1302. <if test="staffId != null and staffId != ''">
  1303. AND tpi.staff_id = #{staffId}::uuid
  1304. </if>
  1305. <if test="supId != null and supId != ''">
  1306. AND tpi.sup_id = #{supId}::uuid
  1307. </if>
  1308. <if test="makeStaff != null and makeStaff != ''">
  1309. AND tpi.make_staff = #{makeStaff}
  1310. </if>
  1311. <if test="viewVoidedDocuments !=null and viewVoidedDocuments == false">
  1312. AND tpi.flg_valid = true
  1313. </if>
  1314. <if test="makeTime != null">
  1315. AND tpi.make_time = #{makeTime}
  1316. </if>
  1317. <if test="receivableId != null and receivableId != ''">
  1318. AND tpi.receivable_id = #{receivableId}
  1319. </if>
  1320. <if test="flgValid != null">
  1321. AND tpi.flg_valid = #{flgValid}
  1322. </if>
  1323. <if test="cpId != null">
  1324. AND tpi.cp_id = #{cpId}
  1325. </if>
  1326. <if test="intoDateStart != null and intoDateEnd != null">
  1327. AND tpi.into_date &gt;= #{intoDateStart}::timestamp with time zone
  1328. AND tpi.into_date &lt; #{intoDateEnd}::timestamp with time zone + interval '1 day'
  1329. </if>
  1330. <if test="makeTimeStart != null and makeTimeEnd != null">
  1331. AND tpi.make_time &gt;= #{makeTimeStart}::timestamp with time zone
  1332. AND tpi.make_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
  1333. </if>
  1334. <if test="intoStatusList != null and intoStatusList.size()>0">
  1335. AND tpi.into_status =
  1336. any(#{intoStatusList, typeHandler= StringListTypeHandler})
  1337. </if>
  1338. <if test="intoStatus != null and intoStatus != ''">
  1339. AND tpi.into_status LIKE concat('%',my_ex.likequery(#{intoStatus}),'%')
  1340. </if>
  1341. </where>
  1342. </select>
  1343. <!-- 查看来源单据,总单加明细 采购退货用-->
  1344. <select id="selectInboundReturnById" resultMap="BaseResultMapInboundReturnResponse">
  1345. SELECT
  1346. <include refid="Base_Column_List_Response"/>
  1347. ,tmo.org_name
  1348. ,tms.staff_name as staff_name
  1349. ,tms1.staff_name as make_staff_name
  1350. ,tmp.sup_name
  1351. ,tmw.wh_name
  1352. ,tmd.data_value as into_reason_name
  1353. ,tmp.return_address
  1354. ,tmp.contact_name
  1355. ,tmp.contact_phone
  1356. ,case when tpi.receivable_id is null then false
  1357. when tmai.amt_handle = 0 then false
  1358. else true end as "paymentFlag"
  1359. ,tpp.sum_amount AS "purSumAmount"
  1360. ,tpp.return_amt AS "purReturnAmt"
  1361. ,sys.f_get_name_i18n(tdktype.kind_name_i18n, #{i18n}) AS "intoStatusName"
  1362. FROM dkic_b.t_psi_inbound tpi
  1363. Left join dkic_b.t_mst_org tmo on tmo.org_id = tpi.org_id
  1364. Left join dkic_b.t_psi_purchase tpp on tpp.pur_id = tpi.from_id
  1365. Left join dkic_b.t_mst_supplier tmp on tmp.sup_id = tpi.sup_id
  1366. Left join dkic_b.t_mst_staff tms on tms.staff_id = tpi.staff_id
  1367. Left join dkic_b.t_mst_staff tms1 on tms1.staff_id = tpi.make_staff
  1368. Left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = tpi.wh_id
  1369. left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = tpi.into_reason
  1370. left join dkic_b.t_mac_account_item tmai on tmai.item_id = tpi.receivable_id
  1371. LEFT JOIN sys.t_data_kind tdktype ON tdktype.kind_code = tpi.into_status
  1372. WHERE tpi.into_id = #{id}::uuid AND tpi.flg_valid = true
  1373. </select>
  1374. <!-- 根据来源id查询 -->
  1375. <select id="selectByFromId" resultMap="BaseResultMapResponse">
  1376. SELECT
  1377. <include refid="Base_Column_List_Response"/>
  1378. FROM dkic_b.t_psi_inbound tpi
  1379. WHERE tpi.from_id = #{fromId}::uuid
  1380. and tpi.flg_valid
  1381. <if test="intoId != null and intoId != ''">
  1382. and tpi.into_id = #{intoId}::uuid
  1383. </if>
  1384. </select>
  1385. <!--根据来源id删除单据-->
  1386. <update id="deleteByFromId" >
  1387. update dkic_b.t_psi_inbound
  1388. <set>
  1389. flg_valid = false
  1390. </set>
  1391. WHERE from_id = #{fromId}::uuid
  1392. </update>
  1393. <!-- 查询表t_psi_inbound,(条件查询+分页)列表 -->
  1394. <select id="selectTotalDetail" resultMap="BaseResultMapItemResponse">
  1395. SELECT
  1396. <include refid="Base_Column_List_Item_Response"/>
  1397. ,(select count(DISTINCT tmgss.category_id) from dkic_b.t_psi_inbound_item ti
  1398. LEFT JOIN dkic_b.t_mst_goods_sku tmgss ON tmgss.sku_id = ti.sku_id
  1399. where ti.into_id = tpi.into_id and ti.flg_valid) as "categoryCount"
  1400. ,sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "intoStatusName"
  1401. ,tmo.org_name as "orgName"
  1402. ,tms.staff_name as "staffName"
  1403. ,tpii.item_id AS list_item_id,
  1404. tpii.item_id AS list_into_item_Id,
  1405. tpii.into_id AS list_into_id,
  1406. tpi.into_no AS list_into_no,
  1407. tpii.into_type AS list_into_type,
  1408. tpii.from_id AS list_from_id,
  1409. tpii.from_item_id AS list_from_item_id,
  1410. tpii.item_index AS list_item_index,
  1411. tpii.sku_id AS list_sku_id,
  1412. tpii.price_into AS list_price_into,
  1413. tpii.non_std_code AS list_non_std_code,
  1414. tpii.into_status AS list_into_status,
  1415. sys.f_remove_zero(tpii.intoing_qty) AS list_intoing_qty,
  1416. tpii.intoing_amt AS list_intoing_amt,
  1417. sys.f_remove_zero(tpii.into_qty) AS list_into_qty,
  1418. tpii.into_amt AS list_into_amt,
  1419. sys.f_remove_zero(tpii.return_qty) AS list_return_qty,
  1420. tpii.return_amt AS list_return_amt,
  1421. tpii.remarks AS list_remarks,
  1422. tpii.inv_id AS list_inv_id,
  1423. tpii.cost_price AS list_cost_price,
  1424. tpii.cost_amt AS list_cost_amt,
  1425. sys.f_remove_zero(tpii.out_qty) AS list_out_qty,
  1426. sys.f_remove_zero(tpii.inv_qty) AS list_inv_qty,
  1427. tpii.flg_valid AS list_flg_valids,
  1428. tpii.cp_id AS list_cp_id,
  1429. tmgs.sku_code AS list_sku_code,
  1430. tmgs.sku_name AS list_sku_name,
  1431. tmgs.sku_model AS list_sku_model,
  1432. tmgb.short_name AS list_short_name,
  1433. tmgs.price_purchase AS list_price_purchase,
  1434. tmgs.sku_images AS list_skuImages,
  1435. sys.f_remove_zero( tpii.into_qty - tpii.return_qty) AS list_reject_qty,
  1436. tmgs.price_standard AS list_price_std
  1437. ,case when tpi.into_status = '入库状态-已入库' then dkic_b.f_box_piece(tmgus.unit_name,tmgu.unit_name,tpii.into_box,tpii.into_piece)
  1438. else dkic_b.f_box_piece(tmgus.unit_name,tmgu.unit_name,tpii.intoing_box,tpii.intoing_piece) end as "list_pack_box_text"
  1439. FROM dkic_b.t_psi_inbound tpi
  1440. left join dkic_b.t_psi_inbound_item tpii on tpi.into_id = tpii.into_id and ( tpii.into_qty - tpii.return_qty) > 0
  1441. left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = tpii.wh_id
  1442. inner join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tpii.sku_id
  1443. left join dkic_b.t_mst_goods_brand tmgb on tmgb.brand_id = tmgs.brand_id
  1444. left join sys.t_data_kind tdk1 on tdk1.kind_code = tpii.into_status
  1445. Left join dkic_b.t_mst_org tmo on tpi.org_id = tmo.org_id
  1446. Left join dkic_b.t_mst_staff tms on tpi.staff_id = tms.staff_id
  1447. left join dkic_b.t_mst_unit as tmgu on tpii.unit_id = tmgu.unit_id
  1448. left join dkic_b.t_mst_unit as tmgus on tpii.sub_unit_id = tmgus.unit_id
  1449. <include refid="ConditionIsSup"/>
  1450. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  1451. limit #{end} offset #{start}
  1452. </if>
  1453. </select>
  1454. <!-- 查询表t_psi_inbound,(条件查询)个数 -->
  1455. <select id="selectTotalDetailCount" resultType="Long">
  1456. SELECT
  1457. count(1)
  1458. FROM dkic_b.t_psi_inbound tpi
  1459. left join dkic_b.t_psi_inbound_item tpii on tpi.into_id = tpii.into_id
  1460. left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = tpii.wh_id
  1461. inner join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tpii.sku_id
  1462. <include refid="ConditionIsSup"/>
  1463. </select>
  1464. </mapper>