InboundMapper.xml 45 KB

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