InboundMapper.xml 57 KB

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