InboundMapper.xml 57 KB

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