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