You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2224 lines
104 KiB

2 years ago
3 months ago
2 years ago
2 years ago
2 years ago
10 months ago
2 years ago
9 months ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
3 months ago
9 months ago
2 years ago
1 year ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
3 months ago
2 years ago
10 months ago
2 years ago
1 year ago
2 years ago
2 years ago
3 months ago
2 years ago
2 years ago
2 years ago
2 years ago
10 months ago
2 years ago
11 months ago
2 years ago
2 years ago
2 years ago
2 years ago
11 months ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 months ago
12 months ago
2 years ago
8 months ago
2 years ago
2 years ago
10 months ago
10 months ago
11 months ago
2 years ago
9 months ago
2 years ago
1 year ago
11 months ago
11 months ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
11 months ago
2 years ago
2 years ago
2 years ago
2 years ago
3 months ago
2 years ago
2 years ago
3 months ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
4 months ago
2 years ago
2 years ago
4 months ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
10 months ago
2 years ago
2 years ago
2 years ago
2 years ago
12 months ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
10 months ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
11 months ago
2 years ago
2 years ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
1 year ago
10 months ago
11 months ago
2 years ago
3 months ago
3 months ago
1 year ago
2 years ago
1 year ago
2 years ago
3 months ago
3 months ago
2 years ago
2 years ago
12 months ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
4 months ago
1 year ago
4 months ago
12 months ago
12 months ago
1 year ago
3 months ago
1 year ago
1 year ago
1 year ago
1 year ago
11 months ago
2 months ago
4 months ago
1 year ago
1 year ago
1 year ago
12 months ago
1 year ago
1 year ago
12 months ago
1 year ago
5 months ago
4 months ago
9 months ago
9 months ago
3 months ago
11 months ago
11 months ago
6 months ago
11 months ago
1 year ago
4 months ago
1 year ago
4 months ago
1 year ago
10 months ago
4 months ago
4 months ago
10 months ago
8 months ago
2 months ago
  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.xujie.sys.modules.ecss.mapper.CoDelMapper">
  4. <select id="searchEcssCoDelNotifyHeader" resultType="EcssCoDelNotifyHeaderData">
  5. select a.site,a.bu_no,a.delNo,a.erp_delNo,a.ready_date,a.notifyDate,a.actualNotifyDate,a.customer_name,a.Destination,a.shipping_mode,a.erp_flag,
  6. a.notify_status,a.remark,a.createDate,a.createBy,a.cmc_invoice,a.updateDate,a.updateBy,dbo.get_bu_desc(a.site,a.bu_no) as buDesc,
  7. a.modifyFlag,a.modify_count as modifyCount,a.overseasShipper,a.overseasAddress,a.cnative,a.salesArea,
  8. a.localShipAddress,a.walMartOrderFlag,a.fscFlag,a.boxSizeFlag,a.templateNo
  9. from ecss_CoDelNotifyHeader a
  10. left join accessBu D on A.site=D.site and A.bu_no=d.bu_no and D.username=#{query.username}
  11. <where>
  12. and D.site is not null
  13. <if test="query.buNo != null and query.buNo != ''">
  14. AND a.bu_no = #{query.buNo}
  15. </if>
  16. <if test="query.delNo != null and query.delNo != ''">
  17. AND a.delNo like #{query.delNo}
  18. </if>
  19. <if test="query.cmcInvoice != null and query.cmcInvoice != ''">
  20. AND a.cmc_invoice like #{query.cmcInvoice}
  21. </if>
  22. <if test="query.notifyStatus != null and query.notifyStatus != ''">
  23. AND a.notify_status = #{query.notifyStatus}
  24. </if>
  25. <if test="query.fscFlag == 'true'">
  26. AND a.fscFlag = 'Y'
  27. </if>
  28. <if test="query.boxSizeFlag == 'true'">
  29. AND a.boxSizeFlag = 'Y'
  30. </if>
  31. <if test="query.walMartOrderFlag == 'true'">
  32. AND a.walMartOrderFlag = 'Y'
  33. </if>
  34. <if test = "query.startDate!= null">
  35. AND a.ready_date>= #{query.startDate}
  36. </if>
  37. <if test = "query.endDate!= null">
  38. AND #{query.endDate} >=a.ready_date
  39. </if>
  40. <if test="query.modifyData == 'true'">
  41. and a.modifyFlag=1
  42. </if>
  43. </where>
  44. order by a.createDate desc ,a.delNo desc
  45. </select>
  46. <select id="searchEcssCoDelNotifyHeaderForCK" resultType="EcssCoDelNotifyHeaderData">
  47. select a.site,a.bu_no,a.delNo,a.erp_delNo,a.ready_date,a.notifyDate,a.actualNotifyDate,a.customer_name,a.Destination,a.shipping_mode,a.erp_flag,
  48. a.notify_status,a.remark,a.createDate,a.createBy,a.cmc_invoice,a.updateDate,a.updateBy,dbo.get_bu_desc(a.site,a.bu_no) as buDesc,a.walMartOrderFlag,
  49. a.modifyFlag,a.modify_count as modifyCount,ISNULL(a.export_flag,'N') as exportFlag,a.fscFlag,a.boxSizeFlag,a.totalVolume
  50. from ecss_CoDelNotifyHeader a
  51. left join accessBu D on A.site=D.site and A.bu_no=d.bu_no and D.username=#{query.username}
  52. <where>
  53. and D.site is not null
  54. <if test="query.buNo != null and query.buNo != ''">
  55. AND a.bu_no = #{query.buNo}
  56. </if>
  57. <if test="query.delNo != null and query.delNo != ''">
  58. AND a.delNo like #{query.delNo}
  59. </if>
  60. <if test="query.cmcInvoice != null and query.cmcInvoice != ''">
  61. AND a.cmc_invoice like #{query.cmcInvoice}
  62. </if>
  63. <if test="query.notifyStatus != null and query.notifyStatus != ''">
  64. AND a.notify_status = #{query.notifyStatus}
  65. </if>
  66. AND a.notify_status != '已计划'
  67. <if test = "query.startDate!= null">
  68. AND a.ready_date>= #{query.startDate}
  69. </if>
  70. <if test = "query.endDate!= null">
  71. AND #{query.endDate} >=a.ready_date
  72. </if>
  73. <if test="query.modifyData == 'true'">
  74. and a.modifyFlag=1
  75. </if>
  76. <if test="query.fscFlag == 'true'">
  77. AND a.fscFlag = 'Y'
  78. </if>
  79. <if test="query.boxSizeFlag == 'true'">
  80. AND a.boxSizeFlag = 'Y'
  81. </if>
  82. <if test="query.walMartOrderFlag == 'true'">
  83. AND a.walMartOrderFlag = 'Y'
  84. </if>
  85. <if test="query.exportFlag != null and query.exportFlag != ''">
  86. and ISNULL(a.export_flag,'N') = #{query.exportFlag}
  87. </if>
  88. </where>
  89. order by a.createDate desc ,a.delNo desc
  90. </select>
  91. <select id="searchEcssCoDelNotifyHeaderForDanZheng" resultType="EcssCoDelNotifyHeaderData">
  92. select a.site,a.bu_no,a.delNo,a.erp_delNo,a.ready_date,a.notifyDate,a.actualNotifyDate,a.customer_name,a.Destination,a.shipping_mode,a.erp_flag,
  93. a.notify_status,a.remark,a.createDate,a.createBy,a.cmc_invoice,a.updateDate,a.updateBy,dbo.get_bu_desc(a.site,a.bu_no) as buDesc
  94. from ecss_CoDelNotifyHeader a
  95. left join accessBu D on A.site=D.site and A.bu_no=d.bu_no and D.username=#{query.username}
  96. <where>
  97. and D.site is not null
  98. <if test="query.buNo != null and query.buNo != ''">
  99. AND a.bu_no = #{query.buNo}
  100. </if>
  101. <if test="query.delNo != null and query.delNo != ''">
  102. AND a.delNo like #{query.delNo}
  103. </if>
  104. <if test="query.cmcInvoice != null and query.cmcInvoice != ''">
  105. AND a.cmc_invoice like #{query.cmcInvoice}
  106. </if>
  107. <if test="query.notifyStatus != null and query.notifyStatus != ''">
  108. AND a.notify_status = #{query.notifyStatus}
  109. </if>
  110. AND a.notify_status = '仓库已确认'
  111. <if test = "query.startDate!= null">
  112. AND a.ready_date>= #{query.startDate}
  113. </if>
  114. <if test = "query.endDate!= null">
  115. AND #{query.endDate} >=a.ready_date
  116. </if>
  117. <if test="query.walMartOrderFlag == 'true'">
  118. AND a.walMartOrderFlag = 'Y'
  119. </if>
  120. <if test="query.walMartOrderFlag == null or query.walMartOrderFlag == '' or query.walMartOrderFlag == 'false'">
  121. AND (a.walMartOrderFlag is null or a.walMartOrderFlag != 'Y')
  122. </if>
  123. </where>
  124. order by a.createDate desc ,a.delNo desc
  125. </select>
  126. <select id="checkEcssCoDelNotifyHeaderByDelNo" resultType="EcssCoDelNotifyHeaderData">
  127. select a.site,a.bu_no,a.delNo,a.erp_delNo,a.ready_date,a.notifyDate,a.actualNotifyDate,a.customer_name,a.Destination,a.shipping_mode,a.erp_flag,
  128. a.notify_status,a.remark,a.createDate,a.createBy,a.cmc_invoice,a.updateDate,a.updateBy,dbo.get_bu_desc(a.site,a.bu_no) as buDesc
  129. ,a.overseasShipper,a.overseasAddress,a.cnative,a.localShipAddress,a.salesArea,a.walMartOrderFlag,a.fscFlag,a.boxSizeFlag,a.templateNo
  130. from ecss_CoDelNotifyHeader a
  131. where a.site = #{site}
  132. AND a.delNo = #{delNo}
  133. </select>
  134. <select id="checkEcssDeclarationHeaderByDelNo" resultType="EcssCoDelNotifyHeaderData">
  135. select a.site,a.delNo
  136. from ecss_declaration_header a
  137. where a.site = #{site}
  138. AND a.delNo = #{delNo}
  139. </select>
  140. <select id="searchEcssCoDelNotifyDetail" resultType="EcssCoDelNotifyDetailData">
  141. select a.site,a.bu_no,a.delNo,a.item_no,a.salesOrder,a.salesOrder_item_no,a.customerPO,a.line,a.version,a.status,a.family,
  142. a.part_no,a.part_description,a.qty,a.lt,a.cmc_comment,a.saleType,a.awb_bl,a.shipping_number,a.forwarder_info,isnull(a.surplus_qty,0) surplusQty,
  143. a.currency,a.tp,a.ttl_amount,a.sum_price,a.so,a.upc,a.remark,a.erp_delItemNo,a.pn,CONVERT(DECIMAL(20, 0),a.nocartons) as nocartons,
  144. c.num_value as boxrolls,d.num_value as rollqty,w.num_value as boxweight,#{cmcInvoice} as cmcInvoice,a.modifyFlag,a.modifyQtyFlag,
  145. b.hsCodeDesc,a.vat,a.roll,a.carton,b.packageNo,b.cinvcname,a.qty_roll as qtyRoll,a.qty_box as qtyBox
  146. from ecss_CoDelNotifydetail a
  147. left join part b on a.site=b.site and a.part_no=b.part_no
  148. left join part_sub_properties_value c on a.part_no=c.part_no and c.site=a.site and c.bu_no=a.bu_no
  149. and c.record_type='ECSSPART' and c.code_no='BG001' and c.properties_item_no='BOXROLLS'
  150. left join part_sub_properties_value d on a.part_no=d.part_no and d.site=a.site and d.bu_no=a.bu_no
  151. and d.record_type='ECSSPART' and d.code_no='BG001' and d.properties_item_no='ROLLQTY'
  152. left join part_sub_properties_value w on a.part_no=w.part_no and w.site=a.site and w.bu_no=a.bu_no
  153. and w.record_type='ECSSPART' and w.code_no='BG001' and w.properties_item_no='BOXWEIGHT'
  154. <where>
  155. And a.site = #{site}
  156. AND a.delNo = #{delNo}
  157. </where>
  158. order by a.item_no
  159. </select>
  160. <select id="getEcssCoDelNotifyDetail" resultType="EcssCoDelNotifyDetailData">
  161. select a.site,a.bu_no,a.delNo,a.item_no,a.salesOrder,a.salesOrder_item_no,a.customerPO,a.line,a.version,a.status,a.family,
  162. a.part_no,a.part_description,a.qty,a.lt,a.cmc_comment,a.saleType,a.awb_bl,a.shipping_number,a.forwarder_info,
  163. a.currency,a.tp,a.ttl_amount,a.sum_price,a.so,a.upc,a.remark,a.erp_delItemNo,a.pn,CONVERT(DECIMAL(20, 0),a.nocartons) as nocartons,
  164. a.modifyFlag,a.modifyQtyFlag
  165. from ecss_CoDelNotifydetail a
  166. <where>
  167. And a.site = #{site}
  168. AND a.delNo = #{delNo}
  169. AND a.item_no = #{itemNo} and a.qty>0
  170. </where>
  171. </select>
  172. <select id="getSiteByBu" resultType="String">
  173. select top 1 site from BU where bu_no=#{buNo}
  174. </select>
  175. <select id="checkIfHasHeader" resultType="EcssCoDelNotifyHeaderData">
  176. select top 1 * from ecss_CoDelNotifyHeader where cmc_invoice=#{inVoice}
  177. </select>
  178. <update id="updateTransNo" >
  179. EXEC UpdateTransNo #{site}, #{transType}
  180. </update>
  181. <select id="getTransNo" resultType="String">
  182. SELECT
  183. dbo.Get_TransNo(#{site},#{transType}) as transNo
  184. </select>
  185. <insert id="saveEcssCoDelNotifyHeader" >
  186. insert into ecss_CoDelNotifyHeader(site,bu_no,delNo,ready_date,customer_name,Destination,shipping_mode,erp_flag,notify_status,
  187. remark,createDate,createBy,cmc_invoice,overseasShipper,overseasAddress,cnative,localShipAddress,salesArea,templateNo)
  188. values(#{site},#{buNo},#{delNo},#{readyDate},#{customerName,jdbcType=NVARCHAR},#{destination,jdbcType=NVARCHAR},#{shippingMode},'N',#{notifyStatus},#{remark,jdbcType=NVARCHAR},GetDate(),
  189. #{createBy},#{cmcInvoice},#{overseasShipper,jdbcType=NVARCHAR},#{overseasAddress,jdbcType=NVARCHAR},#{cnative,jdbcType=NVARCHAR},
  190. #{localShipAddress,jdbcType=NVARCHAR}, #{salesArea,jdbcType=NVARCHAR},#{templateNo,jdbcType=NVARCHAR})
  191. </insert>
  192. <insert id="batchSaveEcssCoDelNotifyDetail">
  193. insert into ecss_CoDelNotifyDetail (site,bu_no,delNo,item_no,salesOrder,salesOrder_item_no,customerPO,line,version,
  194. status,family,part_no,part_description,qty,lt,cmc_comment,saleType,
  195. awb_bl,shipping_number,forwarder_info,currency,tp,ttl_amount,sum_price,
  196. so,upc,remark,pn,surplus_qty,vat,roll,carton,saleslt,manufacturer_name,modifyFlag,modifyQtyFlag,category,qty_roll,qty_box)
  197. values
  198. <foreach collection="list" separator="," item="item">
  199. (#{item.site},#{item.buNo},#{item.delNo},#{item.itemNo,jdbcType=INTEGER},#{item.salesOrder,jdbcType=NVARCHAR},#{item.salesOrderItemNo},#{item.customerPO,jdbcType=NVARCHAR},#{item.line,jdbcType=NVARCHAR},#{item.version,jdbcType=NVARCHAR},
  200. #{item.status,jdbcType=NVARCHAR},#{item.family,jdbcType=NVARCHAR},#{item.partNo},#{item.partDescription,jdbcType=NVARCHAR},#{item.qty,jdbcType=DECIMAL},#{item.lt,jdbcType=DECIMAL},#{item.cmcComment,jdbcType=NVARCHAR},#{item.saleType,jdbcType=NVARCHAR},
  201. #{item.awbBl,jdbcType=NVARCHAR},#{item.shippingNumber,jdbcType=NVARCHAR},#{item.forwarderInfo,jdbcType=NVARCHAR},#{item.currency,jdbcType=NVARCHAR},#{item.tp,jdbcType=DECIMAL},#{item.ttlAmount,jdbcType=DECIMAL},#{item.sumPrice,jdbcType=DECIMAL},
  202. #{item.so,jdbcType=NVARCHAR},#{item.upc,jdbcType=NVARCHAR},#{item.remark,jdbcType=NVARCHAR},#{item.pn,jdbcType=NVARCHAR},#{item.qty},#{item.vat},#{item.roll},#{item.carton},#{item.saleslt,jdbcType=NVARCHAR},#{item.manufacturerName,jdbcType=NVARCHAR},
  203. #{item.modifyFlag},#{item.modifyQtyFlag},#{item.category,jdbcType=NVARCHAR},#{item.qtyRoll,jdbcType=NVARCHAR},#{item.qtyBox,jdbcType=NVARCHAR})
  204. </foreach>
  205. </insert>
  206. <select id="checkPart" resultType="PartData">
  207. select site,part_no from Part where site=#{site,jdbcType=VARCHAR} and part_no=#{partNo}
  208. </select>
  209. <select id="getPartNo" resultType="PartData">
  210. select top 1 site,part_no,hsCode,hsCodeDesc,part_desc,umid,brand from Part where site=#{site,jdbcType=VARCHAR} and sku=#{partNo} and sourceBu=#{buNo}
  211. </select>
  212. <select id="getPartInfo" resultType="PartData">
  213. select * from Part where site=#{site,jdbcType=VARCHAR} and part_no=#{partNo}
  214. </select>
  215. <update id="updateEcssDelHeader" >
  216. update ecss_CoDelNotifyHeader set notifyDate=#{notifyDate,jdbcType=TIMESTAMP} ,ready_date=#{readyDate,jdbcType=TIMESTAMP} ,customer_name=#{customerName,jdbcType=NVARCHAR},
  217. Destination=#{destination,jdbcType=NVARCHAR},shipping_mode=#{shippingMode},modifyFlag=#{modifyFlag},export_flag='N',
  218. remark=#{remark,jdbcType=NVARCHAR} ,cmc_invoice=#{cmcInvoice},overseasShipper=#{overseasShipper,jdbcType=NVARCHAR} ,overseasAddress=#{overseasAddress,jdbcType=NVARCHAR}
  219. where site=#{site} and delNo=#{delNo}
  220. </update>
  221. <update id="updateEcssDelHeaderVolume" >
  222. update ecss_CoDelNotifyHeader set totalVolume=#{totalVolume,jdbcType=DECIMAL} where site=#{site} and delNo=#{delNo}
  223. </update>
  224. <!-- 专门更新客户信息的方法 -->
  225. <update id="updateCustomerInfo">
  226. update ecss_CoDelNotifyHeader
  227. set customer_name = #{customerName,jdbcType=NVARCHAR},
  228. localShipAddress = #{localShipAddress,jdbcType=NVARCHAR},
  229. overseasShipper = #{overseasShipper,jdbcType=NVARCHAR},
  230. overseasAddress = #{overseasAddress,jdbcType=NVARCHAR},
  231. salesArea = #{salesArea,jdbcType=NVARCHAR},
  232. cnative = #{cnative,jdbcType=NVARCHAR}
  233. where site = #{site} and delNo = #{delNo}
  234. </update>
  235. <delete id="deleteEcssDelHeader">
  236. delete from ecss_CoDelNotifyHeader where site=#{site} and delNo=#{delNo}
  237. </delete>
  238. <update id="updateEcssDelHeaderForBaoGuan" >
  239. update ecss_CoDelNotifyHeader set declaration_no=#{declarationNo} ,notify_status=#{status} where site=#{site} and delNo=#{delNo}
  240. </update>
  241. <update id="updateEcssDelHeaderForModify" >
  242. update ecss_CoDelNotifyHeader
  243. set modifyFlag=#{modifyFlag},
  244. modify_count = CASE
  245. WHEN #{modifyFlag} = 1 THEN ISNULL(modify_count, 0) + 1
  246. ELSE 0
  247. END
  248. where site=#{site} and delNo=#{delNo}
  249. </update>
  250. <update id="updateEcssDelDetailForModify" >
  251. update ecss_CoDelNotifyDetail set modifyFlag=#{modifyFlag},modifyQtyFlag=#{modifyFlag},surplus_qty=0 where site=#{site} and delNo=#{delNo}
  252. </update>
  253. <update id="updateEcssDelDetailSurplusQty" >
  254. update ecss_CoDelNotifyDetail set surplus_qty=0 where site=#{site} and delNo=#{delNo}
  255. </update>
  256. <update id="restoreEcssDelDetailSurplusQty" >
  257. update ecss_CoDelNotifyDetail set surplus_qty=qty
  258. where site=#{site} and delNo=#{delNo} and status != '取消发货'
  259. </update>
  260. <update id="changeEcssDelStatus">
  261. update ecss_CoDelNotifyHeader set notify_status=#{notifyStatus},walMartOrderFlag=#{walMartOrderFlag},
  262. fscFlag=#{fscFlag},boxSizeFlag=#{boxSizeFlag} where site=#{site} and delNo=#{delNo}
  263. </update>
  264. <update id="updateEcssDelDetailStatus">
  265. update ecss_CoDelNotifyDetail
  266. set status=#{notifyStatus}
  267. where site=#{site} and delNo=#{delNo}
  268. </update>
  269. <update id="recoverEcssDelDetailStatus">
  270. update ecss_CoDelNotifyDetail
  271. set status='正常'
  272. where site=#{site} and delNo=#{delNo}
  273. </update>
  274. <select id="getEcssDelDetailItemNo" resultType="int">
  275. select isnull(max(item_no),0)+1 as itemNo from ecss_CoDelNotifyDetail
  276. where site =#{site} and bu_no=#{buNo} and delNo=#{delNo}
  277. </select>
  278. <insert id="insertEcssDelDetail" >
  279. insert into ecss_CoDelNotifyDetail(site,bu_no,delNo,item_no,salesOrder,salesOrder_item_no,customerPO,line,version,
  280. status,family,part_no,part_description,qty,lt,cmc_comment,saleType,
  281. awb_bl,shipping_number,forwarder_info,currency,tp,ttl_amount,sum_price,
  282. so,upc,remark,pn,modifyFlag,modifyQtyFlag,surplus_qty,vat,roll,carton)
  283. values(#{site},#{buNo},#{delNo},#{itemNo,jdbcType=INTEGER},#{salesOrder},#{salesOrderItemNo},#{customerPO},#{line},#{version},
  284. #{status},#{family},#{partNo},#{partDescription},#{qty,jdbcType=DECIMAL},#{lt,jdbcType=DECIMAL},#{cmcComment},#{saleType},
  285. #{awbBl},#{shippingNumber},#{forwarderInfo},#{currency},#{tp,jdbcType=DECIMAL},#{ttlAmount,jdbcType=DECIMAL},#{sumPrice,jdbcType=DECIMAL},
  286. #{so},#{upc},#{remark},#{pn},#{modifyFlag},#{modifyQtyFlag},#{qty},#{vat},#{roll},#{carton})
  287. </insert>
  288. <update id="updateEcssDelDetail">
  289. update ecss_CoDelNotifyDetail
  290. set salesOrder=#{salesOrder},customerPO=#{customerPO},line=#{line},version=#{version},
  291. status=#{status},family=#{family},part_no=#{partNo},part_description=#{partDescription},qty=#{qty,jdbcType=DECIMAL},
  292. lt=#{lt,jdbcType=DECIMAL},cmc_comment=#{cmcComment},saleType=#{saleType},pn=#{pn},
  293. awb_bl=#{awbBl},shipping_number=#{shippingNumber},forwarder_info=#{forwarderInfo},currency=#{currency},
  294. tp=#{tp,jdbcType=DECIMAL},ttl_amount=#{ttlAmount,jdbcType=DECIMAL},sum_price=#{sumPrice,jdbcType=DECIMAL},
  295. so=#{so},upc=#{upc},remark=#{remark},modifyFlag=#{modifyFlag},modifyQtyFlag=#{modifyQtyFlag},surplus_qty=#{qty,jdbcType=DECIMAL},vat=#{vat},roll=#{roll},carton=#{carton}
  296. where
  297. site=#{site} and delNo=#{delNo} and item_no=#{itemNo}
  298. </update>
  299. <delete id="deleteEcssDelDetail">
  300. delete from ecss_CoDelNotifyDetail where site=#{site} and delNo=#{delNo} and item_no=#{itemNo}
  301. </delete>
  302. <delete id="deleteAllEcssDelDetail">
  303. delete from ecss_CoDelNotifyDetail where site=#{site} and delNo=#{delNo}
  304. </delete>
  305. <update id="fixTtlAmount">
  306. update ecss_CoDelNotifyDetail
  307. set ttl_amount = sum_price
  308. where site=#{site} and delNo=#{delNo} and sum_price is not null
  309. </update>
  310. <update id="confirmEcssDel">
  311. update ecss_CoDelNotifyHeader set notify_status=#{notifyStatus} ,actualNotifyDate=#{actualNotifyDate,jdbcType=TIMESTAMP} where site=#{site} and delNo=#{delNo}
  312. </update>
  313. <update id="updateEcssDel">
  314. update ecss_CoDelNotifyHeader set ready_date=#{readyDate,jdbcType=TIMESTAMP},actualNotifyDate=#{actualNotifyDate,jdbcType=TIMESTAMP},
  315. modifyFlag=1,export_flag='N',updateBy=#{updateBy},updateDate=GetDate()
  316. where site=#{site} and delNo=#{delNo}
  317. </update>
  318. <select id="searchHsCodeData" resultType="EcssHsCodeData">
  319. select a.Site,a.BuNo,a.HsCode,a.Remark,a.CreateBy,a.CreateDate,a.UpdateBy,a.UpdateDate,a.codeNo
  320. ,dbo.get_bu_desc(a.site,a.BuNo) as BuDesc,a.hsCodeDesc,a.hsCodeDescEn,a.unit,a.brand
  321. from ecss_hsCode a
  322. left join accessBu D on A.site=D.site and A.BuNo=d.bu_no and D.username=#{query.username}
  323. <where>
  324. and D.site is not null
  325. <if test="query.buNo != null and query.buNo != ''">
  326. AND a.BuNo = #{query.buNo}
  327. </if>
  328. <if test="query.hsCode != null and query.hsCode != ''">
  329. AND a.HsCode like #{query.hsCode}
  330. </if>
  331. <if test="query.hsCodeDesc != null and query.hsCodeDesc != ''">
  332. AND a.HsCodeDesc like #{query.hsCodeDesc}
  333. </if>
  334. <if test="query.brand != null and query.brand != ''">
  335. AND ISNULL(a.brand,'无') = ISNULL(#{query.brand},'无')
  336. </if>
  337. </where>
  338. order by a.CreateDate ,a.HsCode
  339. </select>
  340. <select id="checkHsCodeDescData" resultType="EcssHsCodeData">
  341. select a.Site,a.BuNo,a.HsCode,a.hsCodeDesc,a.brand
  342. from ecss_hsCode a where a.site=#{site} and a.buNo=#{buNo} and a.HsCodeDesc=#{hsCodeDesc}
  343. <choose>
  344. <when test="oldBrand != null and oldBrand != ''">
  345. AND ISNULL(a.brand,'无') = ISNULL(#{oldBrand},'无')
  346. </when>
  347. <otherwise>
  348. AND ISNULL(a.brand,'无') = ISNULL(#{brand},'无')
  349. </otherwise>
  350. </choose>
  351. </select>
  352. <select id="checkPropertiesModel" resultType="com.xujie.sys.modules.attrbute.entity.PropertyModelHeader">
  353. select site,bu_no,function_type ,code_no from plm_properties_model_header
  354. where site=#{site} and bu_no=#{buNo} and function_type=#{functionType} and code_no=#{codeNo}
  355. </select>
  356. <insert id="insertHsCodeData" >
  357. insert into ecss_hsCode (Site,BuNo,HsCode,Remark,CreateBy,CreateDate,codeNo,hsCodeDesc,hsCodeDescEn,unit,brand)
  358. values(#{site},#{buNo},#{hsCode},#{remark},#{createBy},GetDate(),#{codeNo},#{hsCodeDesc},#{hsCodeDescEn},#{unit},#{brand})
  359. </insert>
  360. <update id="updateHsCodeData">
  361. update ecss_hsCode set Remark=#{remark} ,codeNo=#{codeNo},HsCode=#{hsCode},unit=#{unit} ,brand=#{brand},UpdateDate=GetDate(),UpdateBy=#{updateBy},hsCodeDescEn=#{hsCodeDescEn}
  362. where site=#{site} and buNo=#{buNo} and hsCodeDesc=#{hsCodeDesc}
  363. <choose>
  364. <when test="oldBrand != null and oldBrand != ''">
  365. and ISNULL(brand,'无') = ISNULL(#{oldBrand},'无')
  366. </when>
  367. <otherwise>
  368. and ISNULL(brand,'无') = ISNULL(#{brand},'无')
  369. </otherwise>
  370. </choose>
  371. </update>
  372. <select id="deleteHsCode" >
  373. delete from ecss_hsCode where site=#{site} and buNo=#{buNo} and hsCodeDesc=#{hsCodeDesc} and ISNULL(brand,'无') = ISNULL(#{brand},'无')
  374. </select>
  375. <!-- 物料绑定以 Part.hsCodeDesc+brand 为准,需与品名档案唯一键保持一致 -->
  376. <select id="listPartNosBoundByHsCode" resultType="java.lang.String">
  377. select distinct a.part_no
  378. from Part a
  379. where a.site = #{site}
  380. and a.sourceBu = #{buNo}
  381. and a.hsCodeDesc = #{hsCodeDesc}
  382. and ISNULL(a.brand, '无') = ISNULL(#{brand}, '无')
  383. order by a.part_no
  384. </select>
  385. <select id="searchPropertiesItemList" resultType="com.xujie.sys.modules.attrbute.entity.PropertyItem">
  386. select
  387. id,site,bu_no,item_no,item_type,item_desc,default_value,value_type,value_type_db,value_choose_flag,min_value,max_value,
  388. create_by,create_date,update_by,update_date
  389. from dbo.plm_properties_item
  390. <where>
  391. and site = #{site} and bu_no=#{buNo}
  392. <if test="itemNo != null and itemNo != ''">
  393. and item_no like #{itemNo}
  394. </if>
  395. <if test="itemDesc != null and itemDesc != ''">
  396. and item_desc like #{itemDesc}
  397. </if>
  398. <if test="itemType != null and itemType != ''">
  399. and item_type = #{itemType}
  400. </if>
  401. order by item_type ,item_no
  402. </where>
  403. </select>
  404. <select id="getPropertiesListByPartAndCodeNo" resultType="com.xujie.sys.modules.part.entity.PartSubPropertiesValueData">
  405. SELECT a.part_no
  406. , a.Site
  407. , a.code_no
  408. , a.brand
  409. , a.sub_code_seq_no
  410. , a.sub_code_desc
  411. ,a.bu_no
  412. ,a.item_no
  413. , a.properties_item_no
  414. , a.text_value
  415. , a.num_value
  416. , a.record_type
  417. , b.item_desc ItemDesc
  418. , b.value_type
  419. , b.value_type_db
  420. , b.value_choose_flag
  421. FROM part_sub_properties_value a
  422. left join plm_properties_item b
  423. on a.properties_item_no = b.Item_No and a.site = b.site and a.record_type = b.Item_Type and a.bu_no=b.bu_no
  424. <where>
  425. AND a.site = #{site}
  426. and a.record_type = #{recordType}
  427. and a.bu_no=#{buNo}
  428. and a.code_no = #{codeNo}
  429. AND a.part_no = #{partNo,jdbcType=VARCHAR}
  430. <if test="brand != null and brand != ''">
  431. AND ISNULL(a.brand,'无') = ISNULL(#{brand},'无')
  432. </if>
  433. </where>
  434. order by a.item_no
  435. </select>
  436. <update id="updatePropertiesList">
  437. update part_sub_properties_value
  438. set text_value=#{textValue},
  439. num_value=#{numValue,jdbcType=DOUBLE}
  440. where Site = #{site}
  441. and code_no = #{codeNo}
  442. and part_no = #{partNo}
  443. and sub_code_seq_no = #{subCodeSeqNo}
  444. and item_no = #{itemNo}
  445. and bu_no=#{buNo}
  446. <if test="brand != null and brand != ''">
  447. and ISNULL(brand,'无') = ISNULL(#{brand},'无')
  448. </if>
  449. </update>
  450. <insert id="saveSubPropertiesValueForAlone">
  451. insert into part_sub_properties_value ( part_no, site, bu_no, code_no, brand, sub_code_seq_no, sub_code_desc,
  452. item_no, properties_item_no, text_value, num_value, record_type)
  453. select
  454. #{partNo},
  455. #{site},
  456. #{buNo},
  457. #{codeNo},
  458. #{brand,jdbcType=NVARCHAR},
  459. 1,
  460. d.code_desc,
  461. #{itemNo,jdbcType=DOUBLE},
  462. c.item_no,
  463. case when c.value_type_db = 'T' then c.default_value else null end,
  464. case when c.value_type_db = 'N' and c.default_value != '' then c.default_value else null end,
  465. #{recordType}
  466. from plm_properties_item c
  467. left join plm_properties_model_header d on c.site=d.site and d.code_no=#{codeNo} and d.function_type=c.item_Type
  468. where c.Item_No = #{propertiesItemNo}
  469. and c.site = #{site}
  470. and c.bu_no=#{buNo}
  471. and c.item_Type = #{recordType}
  472. </insert>
  473. <delete id="deleteSubPropertiesValueForAlone">
  474. delete
  475. from part_sub_properties_value
  476. where site = #{site}
  477. and record_type = #{recordType}
  478. and bu_no=#{buNo}
  479. and code_no = #{codeNo}
  480. AND part_no = #{partNo,jdbcType=VARCHAR}
  481. <if test="brand != null and brand != ''">
  482. AND ISNULL(brand,'无') = ISNULL(#{brand},'无')
  483. </if>
  484. and properties_item_no = #{propertiesItemNo}
  485. </delete>
  486. <select id="getNewSeqNoForAlone" resultType="Double">
  487. select isnull(Max(item_No) + 1, 1)
  488. from part_sub_properties_value a
  489. where a.site = #{site}
  490. and a.record_type = #{recordType}
  491. and a.bu_no=#{buNo}
  492. and a.code_no = #{codeNo}
  493. AND a.part_no = #{partNo,jdbcType=VARCHAR}
  494. <if test="brand != null and brand != ''">
  495. AND ISNULL(a.brand,'无') = ISNULL(#{brand},'无')
  496. </if>
  497. </select>
  498. <select id="searchPropertiesUnChoose" resultType="com.xujie.sys.modules.ecss.entity.PropertyItemData">
  499. SELECT
  500. b.id,b.site,b.bu_no,b.item_no,b.item_type as functionType,b.item_desc,b.default_value,b.value_type,b.value_type_db,b.value_choose_flag,
  501. b.min_value,b.max_value,b.create_by,b.create_date,b.update_by,b.update_date
  502. FROM plm_properties_item b
  503. where b.item_type = #{codeType}
  504. and b.site = #{site} and b.bu_no=#{buNo}
  505. <if test="list != null and list.size() != 0">
  506. and b.item_no not in (
  507. <foreach collection="list" item="item" separator=",">
  508. #{item}
  509. </foreach>
  510. )
  511. </if>
  512. </select>
  513. <insert id="saveCodelPalletHeader">
  514. insert into ecss_CoDelPalletHeader (site,bu_no,delNo,seq_no,pallet_no,pallet_qty,[length],width,height,volume,gross_weight,net_weight,pallet_remark,create_by,
  515. create_date,pallet)
  516. values(#{site},#{buNo},#{delNo},#{seqNo},#{palletNo},#{palletQty},#{length},#{width},#{height},#{volume},#{grossWeight,jdbcType=DECIMAL},#{netWeight,jdbcType=DECIMAL},#{palletRemark},#{createBy},
  517. GETDATE(),#{pallet})
  518. </insert>
  519. <insert id="saveCodelBoxList">
  520. insert into ecss_CoDelBoxList(site,bu_no,delNo,seq_no,item_no,gross_weight,net_weight,box_qty,rolls,volume,create_by,create_date)
  521. values (#{site},#{buNo},#{delNo},#{seqNo},#{itemNo},#{grossWeight,jdbcType=DECIMAL},#{netWeight,jdbcType=DECIMAL},#{boxQty},#{rolls,jdbcType=DECIMAL},#{volume,jdbcType=DECIMAL},#{createBy},GETDATE())
  522. </insert>
  523. <insert id="saveCodelPalletDetail">
  524. insert into ecss_CoDelPalletDetail(site,bu_no,delNo,seq_no,item_no,part_no,qty,po_no,box_qty,create_by,create_date,rolls,pn,notify_detail_item_no)
  525. values (#{site},#{buNo},#{delNo},#{seqNo},#{itemNo},#{partNo},#{qty,jdbcType=DECIMAL},#{poNo},#{boxQty},#{createBy},GETDATE(),#{rolls,jdbcType=DECIMAL},#{pn},#{notifyDetailItemNo})
  526. </insert>
  527. <select id="searchEcssCoDelPalletHeaderData" resultType="EcssCoDelPalletHeaderData">
  528. select a.site,a.bu_no,a.delNo,a.seq_no,a.pallet_no,a.pallet_qty,a.length,a.width,a.height,a.volume,a.gross_weight,a.net_weight,a.pallet_remark,a.create_by,
  529. a.create_date,a.update_by,a.update_date,a.pallet,CONVERT(DECIMAL(20, 3),(isnull(p.pallet_weight,0)*a.pallet_qty)) as weight
  530. from ecss_CoDelPalletHeader a
  531. LEFT JOIN ecss_pallet p on a.pallet=p.pallet_no and a.site=p.Site and a.bu_no=p.BuNo
  532. where a.site =#{site} and a.bu_no=#{buNo} and a.delNo=#{delNo}
  533. </select>
  534. <select id="searchEcssCoDelPalletDetailData" resultType="EcssCoDelPalletDetailData">
  535. select site,bu_no,delNo,seq_no,item_no,part_no,qty,po_no,box_qty,create_by,create_date,update_by,update_date,rolls,pn,notify_detail_item_no as notifyDetailItemNo
  536. from ecss_CoDelPalletDetail
  537. where site =#{site} and bu_no=#{buNo} and delNo=#{delNo}
  538. <if test="seqNo != null and seqNo != ''">
  539. and seq_no=#{seqNo}
  540. </if>
  541. </select>
  542. <select id="getCoDelPalletHeaderSeqNo" resultType="int">
  543. select isnull(max(seq_no),0)+1 as seqNo from ecss_CoDelPalletHeader
  544. where site =#{site} and bu_no=#{buNo} and delNo=#{delNo}
  545. </select>
  546. <select id="getCoDelBoxListItemNo" resultType="int">
  547. select isnull(max(item_no),0)+1 as seqNo from ecss_CoDelBoxList
  548. where site =#{site} and bu_no=#{buNo} and delNo=#{delNo}
  549. </select>
  550. <select id="getCoDelPalletDetailItem" resultType="int">
  551. select isnull(max(item_no),0)+1 as item_no from ecss_CoDelPalletDetail
  552. where site =#{site} and bu_no=#{buNo} and delNo=#{delNo} and seq_no=#{seqNo}
  553. </select>
  554. <update id="updateCodelPalletHeader">
  555. update ecss_CoDelPalletHeader set pallet_qty=#{palletQty,jdbcType=INTEGER},[length]=#{length,jdbcType=DECIMAL},width=#{width,jdbcType=DECIMAL},height=#{height,jdbcType=DECIMAL},
  556. volume=#{volume,jdbcType=DECIMAL},gross_weight=#{grossWeight,jdbcType=DECIMAL},net_weight=#{netWeight,jdbcType=DECIMAL},pallet_remark=#{palletRemark},
  557. update_by=#{updateBy},update_date=GetDate(),pallet=#{pallet}
  558. where site =#{site} and bu_no=#{buNo} and delNo=#{delNo} and seq_no=#{seqNo}
  559. </update>
  560. <update id="updateCodelPalletHeader2">
  561. update ecss_CoDelPalletHeader set gross_weight=#{grossWeight,jdbcType=DECIMAL},net_weight=#{netWeight,jdbcType=DECIMAL},
  562. update_by=#{updateBy},update_date=GetDate()
  563. where site =#{site} and bu_no=#{buNo} and delNo=#{delNo} and seq_no=#{seqNo}
  564. </update>
  565. <update id="updateCodelPalletHeaderPalletQty">
  566. update ecss_CoDelPalletHeader set pallet_qty=#{palletQty,jdbcType=INTEGER},height=#{height,jdbcType=DECIMAL},
  567. update_by=#{updateBy},update_date=GetDate()
  568. where site =#{site} and bu_no=#{buNo} and delNo=#{delNo} and seq_no=#{seqNo}
  569. </update>
  570. <update id="updateCodelPalletDetail">
  571. update ecss_CoDelPalletDetail set part_no=#{partNo},qty=#{qty,jdbcType=DECIMAL},po_no=#{poNo},
  572. box_qty=#{boxQty,jdbcType=DECIMAL},update_by=#{updateBy},update_date=GetDate(),rolls=#{rolls},pn=#{pn}
  573. where site =#{site} and bu_no=#{buNo} and delNo=#{delNo} and seq_no=#{seqNo} and item_no=#{itemNo}
  574. </update>
  575. <delete id="deletePalletHeader">
  576. delete from ecss_CoDelPalletHeader where site =#{site} and bu_no=#{buNo} and delNo=#{delNo}
  577. <if test="seqNo != null and seqNo != ''">
  578. and seq_no=#{seqNo}
  579. </if>
  580. </delete>
  581. <delete id="deleteBoxList">
  582. delete from ecss_CoDelBoxList where site =#{site} and bu_no=#{buNo} and delNo=#{delNo}
  583. <if test="seqNo != null and seqNo != ''">
  584. and seq_no=#{seqNo}
  585. </if>
  586. </delete>
  587. <delete id="deletePalletDetail">
  588. delete from ecss_CoDelPalletDetail where site =#{site} and bu_no=#{buNo} and delNo=#{delNo}
  589. <if test="seqNo != null and seqNo != ''">
  590. and seq_no=#{seqNo}
  591. </if>
  592. <if test="itemNo != null and itemNo != ''">
  593. and item_no=#{itemNo}
  594. </if>
  595. </delete>
  596. <select id="getAllWeight" resultType="com.xujie.sys.modules.ecss.entity.EcssCoDelPalletHeader">
  597. select sum(gross_weight) as gross_weight ,sum(net_weight) as net_weight from ecss_CoDelBoxList
  598. where site =#{site} and delNo=#{delNo} and bu_no=#{buNo}
  599. </select>
  600. <select id="getDefaultEcssDeclarationDetailData" resultType="EcssDeclarationDetailData">
  601. -- 修复净重计算问题:按数量比例分配箱子净重,避免重复计算
  602. -- 一个箱子(BoxList)可能包含多个零件(PalletDetail),这些零件可能有相同的hsCode
  603. -- 需要按每个零件的数量占该箱子总数量的比例来分配净重
  604. WITH BoxDetail AS (
  605. -- 计算每个箱子中每个零件的数量及其占比
  606. SELECT
  607. d.site,
  608. d.bu_no,
  609. d.delNo,
  610. d.seq_no,
  611. p.hsCode,
  612. p.hsCodeDesc,
  613. p.brand,
  614. d.qty,
  615. b.net_weight,
  616. -- 计算该零件数量占该箱子总数量的比例
  617. CASE
  618. WHEN SUM(d.qty) OVER (PARTITION BY d.site, d.bu_no, d.delNo, d.seq_no) > 0
  619. THEN d.qty * 1.0 / SUM(d.qty) OVER (PARTITION BY d.site, d.bu_no, d.delNo, d.seq_no)
  620. ELSE 0
  621. END as qtyRatio
  622. FROM ecss_CoDelPalletDetail d
  623. LEFT JOIN part p ON d.site=p.site AND d.part_no=p.part_no
  624. LEFT JOIN ecss_CoDelBoxList b ON d.site=b.site AND d.bu_no=b.bu_no AND d.delNo=b.delNo AND d.seq_no=b.item_no
  625. WHERE d.site=#{site} AND d.delNo=#{delNo} AND d.bu_no=#{buNo}
  626. )
  627. SELECT
  628. #{site} as site,
  629. hsCode,
  630. hsCodeDesc,
  631. brand,
  632. SUM(qty) as qty,
  633. -- 按数量比例分配净重后汇总
  634. CONVERT(DECIMAL(20,2), SUM(ISNULL(net_weight, 0) * qtyRatio)) as NetWeight,
  635. 'CNY' as currency,
  636. '中国' as madeArea,
  637. #{destination} as destination,
  638. '南通其他' as sourceArea,
  639. '照章征免' as levy
  640. FROM BoxDetail
  641. GROUP BY hsCode, hsCodeDesc, brand
  642. </select>
  643. <select id="getDefaultEcssDeclarationDetailData2" resultType="EcssDeclarationDetailData">
  644. select #{site} as site, b.hsCode,b.hsCodeDesc as hsCodeDesc,b.brand as brand,sum( a.qty) as qty ,sum(a.ttl_amount) as totalPrice,
  645. CONVERT(DECIMAL(20, 6),sum(a.ttl_amount)/sum( a.qty)) as unitPrice,
  646. LEFT(a.currency, 3) AS currency,'中国' as madeArea,#{destination} as destination,'南通其他' as sourceArea ,'照章征免' as levy from
  647. ecss_CoDelNotifyDetail a left join part b on a.site=b.site and a.part_no=b.part_no
  648. where a.site =#{site} and a.delNo=#{delNo} and a.qty>0 and a.bu_no=#{buNo}
  649. GROUP BY b.hsCodeDesc,b.hsCode,b.brand,LEFT(a.currency,3)
  650. ORDER BY
  651. CASE WHEN MIN(TRY_CONVERT(BIGINT, a.item_no)) IS NULL THEN 1 ELSE 0 END,
  652. MIN(TRY_CONVERT(BIGINT, a.item_no)),
  653. MIN(a.item_no)
  654. </select>
  655. <select id="getDefaultEcssDeclarationDetailDataTX" resultType="EcssDeclarationDetailData">
  656. -- 修复净重计算问题:按数量比例分配箱子净重,避免重复计算
  657. -- 一个箱子(BoxList)可能包含多个零件(PalletDetail),这些零件可能有相同的hsCode
  658. -- 需要按每个零件的数量占该箱子总数量的比例来分配净重
  659. WITH BoxDetail AS (
  660. -- 计算每个箱子中每个零件的数量及其占比
  661. SELECT
  662. d.site,
  663. d.bu_no,
  664. d.delNo,
  665. d.seq_no,
  666. p.hsCode,
  667. p.hsCodeDesc,
  668. p.brand,
  669. p.ecss_umid as unit,
  670. d.qty,
  671. b.net_weight,
  672. -- 计算该零件数量占该箱子总数量的比例
  673. CASE
  674. WHEN SUM(d.qty) OVER (PARTITION BY d.site, d.bu_no, d.delNo, d.seq_no) > 0
  675. THEN d.qty * 1.0 / SUM(d.qty) OVER (PARTITION BY d.site, d.bu_no, d.delNo, d.seq_no)
  676. ELSE 0
  677. END as qtyRatio
  678. FROM ecss_CoDelPalletDetail d
  679. LEFT JOIN part p ON d.site=p.site AND d.part_no=p.part_no
  680. LEFT JOIN ecss_CoDelBoxList b ON d.site=b.site AND d.bu_no=b.bu_no AND d.delNo=b.delNo AND d.seq_no=b.item_no
  681. WHERE d.site=#{site} AND d.delNo=#{delNo} AND d.bu_no=#{buNo}
  682. )
  683. SELECT
  684. #{site} as site,
  685. hsCode,
  686. hsCodeDesc,
  687. brand,
  688. unit,
  689. SUM(qty) as qty,
  690. -- 按数量比例分配净重后汇总
  691. CONVERT(DECIMAL(20,2), SUM(ISNULL(net_weight, 0) * qtyRatio)) as NetWeight,
  692. 'CNY' as currency,
  693. '中国' as madeArea,
  694. #{destination} as destination,
  695. '南通其他' as sourceArea,
  696. '照章征免' as levy
  697. FROM BoxDetail
  698. GROUP BY hsCode, hsCodeDesc, brand,unit
  699. </select>
  700. <select id="getDefaultEcssDeclarationDetailData2TX" resultType="EcssDeclarationDetailData">
  701. select #{site} as site, b.hsCode,b.hsCodeDesc as hsCodeDesc,b.brand as brand,sum( a.qty) as qty ,sum(a.ttl_amount) as totalPrice,
  702. CONVERT(DECIMAL(20, 6),sum(a.ttl_amount)/sum( a.qty)) as unitPrice,b.ecss_umid as unit,
  703. LEFT(a.currency, 3) AS currency,'中国' as madeArea,#{destination} as destination,'南通其他' as sourceArea ,'照章征免' as levy from
  704. ecss_CoDelNotifyDetail a left join part b on a.site=b.site and a.part_no=b.part_no
  705. where a.site =#{site} and a.delNo=#{delNo} and a.qty>0 and a.bu_no=#{buNo}
  706. GROUP BY b.hsCodeDesc,b.hsCode,b.brand,b.ecss_umid,LEFT(a.currency,3)
  707. ORDER BY
  708. CASE WHEN MIN(TRY_CONVERT(BIGINT, a.item_no)) IS NULL THEN 1 ELSE 0 END,
  709. MIN(TRY_CONVERT(BIGINT, a.item_no)),
  710. MIN(a.item_no)
  711. </select>
  712. <insert id="saveEcssDeclarationHeader">
  713. insert into ecss_declaration_header (site,declaration_no,customs_office_code,input_code,local_shipper,local_ship_address,ship_type,ship_date,submit_date,
  714. filing_no,overseas_shipper,shipping_mode,shipping_data,deliver_no,sales_partner,regulatory_method,duty_status,
  715. permit_number,cmc_invoice,sales_area,receive_area,shipping_port,exit_port,documents,remark,package_type,package_qty,
  716. gross_weight,net_weight,payment_type,ship_price,premium,other_price,special_relationship_comfirm,price_influence_confirm,
  717. royalty_payments_confirm,create_by,create_date,delNo,overseas_address,box_qty)
  718. values(#{site},#{declarationNo},#{customsOfficeCode},#{inputCode},#{localShipper,jdbcType=NVARCHAR},#{localShipAddress,jdbcType=NVARCHAR},#{shipType},#{shipDate},#{submitDate},
  719. #{filingNo},#{overseasShipper,jdbcType=NVARCHAR},#{shippingMode,jdbcType=NVARCHAR},#{shippingData},#{deliverNo},#{salesPartner,jdbcType=NVARCHAR},#{regulatoryMethod,jdbcType=NVARCHAR},#{dutyStatus,jdbcType=NVARCHAR},
  720. #{permitNumber},#{cmcInvoice},#{salesArea,jdbcType=NVARCHAR},#{receiveArea,jdbcType=NVARCHAR},#{shippingPort,jdbcType=NVARCHAR},#{exitPort,jdbcType=NVARCHAR},#{documents,jdbcType=NVARCHAR},#{remark,jdbcType=NVARCHAR},#{packageType,jdbcType=NVARCHAR},#{packageQty,jdbcType=INTEGER},
  721. #{grossWeight,jdbcType=DECIMAL},#{netWeight,jdbcType=DECIMAL},#{paymentType,jdbcType=NVARCHAR},#{shipPrice,jdbcType=DECIMAL},#{premium,jdbcType=DECIMAL},#{otherPrice,jdbcType=DECIMAL},#{specialRelationshipComfirm,jdbcType=NVARCHAR},#{priceInfluenceConfirm,jdbcType=NVARCHAR},
  722. #{royaltyPaymentsConfirm,jdbcType=NVARCHAR},#{createBy},GETDATE(),#{delNo},#{overseasAddress,jdbcType=NVARCHAR},#{boxQty})
  723. </insert>
  724. <insert id="saveEcssDeclarationDetail">
  725. insert into ecss_declaration_detail(site,declaration_no,item_no,hs_code,hs_code_desc,brand,qty,net_weight,unit_price,total_price,currency,made_area,destination,
  726. source_area,levy,unit)
  727. values(#{site},#{declarationNo},#{itemNo,jdbcType=INTEGER},#{hsCode},#{hsCodeDesc},#{brand,jdbcType=NVARCHAR},#{qty,jdbcType=DECIMAL},#{netWeight,jdbcType=DECIMAL},#{unitPrice,jdbcType=DECIMAL},#{totalPrice,jdbcType=DECIMAL},#{currency},#{madeArea},#{destination},
  728. #{sourceArea},#{levy},#{unit})
  729. </insert>
  730. <select id="searchDeclarationHeader" resultType="EcssDeclarationHeaderData">
  731. select a.site,a.declaration_no,a.customs_office_code,a.input_code,a.local_shipper,a.local_ship_address,a.ship_type,
  732. a.ship_date,a.submit_date,a.filing_no,a.overseas_shipper,a.shipping_mode,a.shipping_data,a.deliver_no,a.sales_partner,
  733. a.regulatory_method,a.duty_status,a.permit_number,a.cmc_invoice,a.sales_area,a.receive_area,a.shipping_port,
  734. a.exit_port,a.documents,a.remark,a.package_type,a.package_qty,a.gross_weight,a.net_weight,a.payment_type,a.ship_price,
  735. a.premium,a.other_price,a.special_relationship_comfirm,a.price_influence_confirm,a.royalty_payments_confirm,
  736. a.create_by,a.create_date,a.update_by,a.update_date,a.delNo,noHeader.bu_no,
  737. a.upc,a.so,a.origin,a.pallet_weight,a.material,a.hs_code,a.packaging,a.kgs,a.shipping_mark,
  738. a.hsCodeDesc,a.contractFlag,a.hsCodeDescType,a.goodsLabel,a.boxChange,noHeader.customer_name as customName,
  739. noHeader.destination
  740. from ecss_declaration_header a
  741. left join ecss_CoDelNotifyHeader noHeader on a.site=noHeader.site and a.delNo=noHeader.delNo
  742. left join accessBu D on noHeader.site=D.site and noHeader.bu_no=d.bu_no and D.username=#{query.username}
  743. <where>
  744. and D.site is not null
  745. <if test="query.delNo != null and query.delNo != ''">
  746. AND a.delNo like #{query.delNo}
  747. </if>
  748. <if test="query.declarationNo != null and query.declarationNo != ''">
  749. AND a.declaration_no like #{query.declarationNo}
  750. </if>
  751. <if test="query.cmcInvoice != null and query.cmcInvoice != ''">
  752. AND a.cmc_invoice like #{query.cmcInvoice}
  753. </if>
  754. <if test="query.site != null and query.site != ''">
  755. AND a.site like #{query.site}
  756. </if>
  757. <if test="query.buNo != null and query.buNo != ''">
  758. AND noHeader.bu_no = #{query.buNo}
  759. </if>
  760. <if test = "query.startDate!= null">
  761. AND a.ship_date>= #{query.startDate}
  762. </if>
  763. <if test = "query.endDate!= null">
  764. AND #{query.endDate} >=a.ship_date
  765. </if>
  766. </where>
  767. order by a.create_date desc
  768. </select>
  769. <select id="searchDeclarationDetail" resultType="EcssDeclarationDetailData">
  770. select site,declaration_no,item_no,hs_code,hs_code_desc,brand,qty,net_weight,unit_price,total_price,currency,made_area,destination,
  771. source_area,levy,brand
  772. from ecss_declaration_detail
  773. where site=#{site} and declaration_no=#{declarationNo}
  774. </select>
  775. <delete id="deleteDeclarationHeader">
  776. delete from ecss_declaration_header where site=#{site} and declaration_no=#{declarationNo}
  777. </delete>
  778. <delete id="deleteDeclarationDetail">
  779. delete from ecss_declaration_detail where site=#{site} and declaration_no=#{declarationNo}
  780. </delete>
  781. <select id="searchPalletData" resultType="EcssPalletData">
  782. select a.id,a.Site,a.BuNo,a.pallet_type as palletType,a.Remark,a.CreateBy,a.CreateDate,a.UpdateBy,a.UpdateDate,
  783. a.length, a.width, a.height, a.application_area as applicationArea, a.pallet_weight as palletWeight
  784. ,dbo.get_bu_desc(a.site,a.BuNo) as BuDesc,a.pallet_no as palletNo
  785. from ecss_pallet a
  786. left join accessBu D on A.site=D.site and A.BuNo=d.bu_no and D.username=#{query.username}
  787. <where>
  788. and D.site is not null
  789. <if test="query.buNo != null and query.buNo != ''">
  790. AND a.BuNo = #{query.buNo}
  791. </if>
  792. <if test="query.palletType != null and query.palletType != ''">
  793. AND a.pallet_type = #{query.palletType}
  794. </if>
  795. </where>
  796. order by a.CreateDate
  797. </select>
  798. <insert id="insertPalletData" >
  799. insert into ecss_pallet (Site,BuNo,pallet_type,Remark,CreateBy,CreateDate,length,width,
  800. height,application_area,pallet_weight,pallet_no)
  801. values(#{site},#{buNo},#{palletType},#{remark},#{createBy},GetDate(),#{length},#{width},
  802. #{height},#{applicationArea},#{palletWeight},#{palletNo})
  803. </insert>
  804. <update id="updatePalletData">
  805. update ecss_pallet set Remark=#{remark} ,pallet_type=#{palletType} ,
  806. length=#{length} ,width=#{width} ,
  807. height=#{height} ,application_area=#{applicationArea} ,
  808. pallet_weight=#{palletWeight} ,pallet_no=#{palletNo},
  809. UpdateDate=GetDate(),UpdateBy=#{updateBy}
  810. where site=#{site} and buNo=#{buNo} and id=#{id}
  811. </update>
  812. <select id="deletePallet" >
  813. delete from ecss_pallet where site=#{site} and buNo=#{buNo} and id=#{id}
  814. </select>
  815. <select id="getPallet" resultType="EcssPalletData">
  816. select * from ecss_pallet where site=#{site} and buNo=#{buNo} and pallet_no=#{palletNo}
  817. </select>
  818. <select id="getPackage" resultType="EcssPackageData">
  819. select * from ecss_package where site=#{site} and buNo=#{buNo} and package_no=#{packageNo}
  820. </select>
  821. <insert id="insertPackageData" >
  822. insert into ecss_package (Site,BuNo,package_type,Remark,CreateBy,CreateDate,length,width,
  823. height,volume,weight,package_no)
  824. values(#{site},#{buNo},#{packageType},#{remark},#{createBy},GetDate(),#{length},#{width},
  825. #{height},#{volume},#{weight},#{packageNo})
  826. </insert>
  827. <update id="updatePackageData">
  828. update ecss_package set Remark=#{remark} ,package_type=#{packageType} ,
  829. length=#{length} ,width=#{width} ,volume=#{volume},weight=#{weight},
  830. package_no=#{packageNo},height=#{height} ,
  831. UpdateDate=GetDate(),UpdateBy=#{updateBy}
  832. where site=#{site} and buNo=#{buNo} and id=#{id}
  833. </update>
  834. <select id="deleteEcssPackage" >
  835. delete from ecss_package where site=#{site} and buNo=#{buNo} and id=#{id}
  836. </select>
  837. <select id="searchPackageData" resultType="EcssPackageData">
  838. select a.id,a.Site,a.BuNo,a.package_type as packageType,a.Remark,a.CreateBy,a.CreateDate,a.UpdateBy,a.UpdateDate,
  839. a.length, a.width, a.height, a.volume, a.weight,a.package_no as packageNo
  840. ,dbo.get_bu_desc(a.site,a.BuNo) as BuDesc
  841. from ecss_package a
  842. left join accessBu D on A.site=D.site and A.BuNo=d.bu_no and D.username=#{query.username}
  843. <where>
  844. and D.site is not null
  845. <if test="query.buNo != null and query.buNo != ''">
  846. AND a.BuNo = #{query.buNo}
  847. </if>
  848. <if test="query.packageType != null and query.packageType != ''">
  849. AND a.package_type = #{query.packageType}
  850. </if>
  851. </where>
  852. order by a.CreateDate
  853. </select>
  854. <select id="searchHsCodeList" resultType="java.util.Map">
  855. select a.BuNo,a.HsCode,a.hsCodeDesc,a.unit,a.hsCodeDescEn,a.brand
  856. from ecss_hsCode a
  857. <where> a.BuNo = #{buNo}
  858. <if test="hsCode != null and hsCode != ''">
  859. AND a.HsCode like '%'+#{hsCode}+'%'
  860. </if>
  861. <if test="hsCodeDesc != null and hsCodeDesc != ''">
  862. AND a.hsCodeDesc like '%'+#{hsCodeDesc}+'%'
  863. </if>
  864. </where>
  865. order by a.CreateDate ,a.HsCode
  866. </select>
  867. <select id="searchPalletList" resultType="java.util.Map">
  868. select a.BuNo,a.id as palletId,a.pallet_type as palletType,a.pallet_no as palletNo,
  869. a.application_area as applicationArea ,a.length, a.width, a.height
  870. from ecss_pallet a
  871. <where> a.BuNo = #{buNo}
  872. <if test="palletType != null and palletType != ''">
  873. AND a.pallet_type like '%'+#{palletType}+'%'
  874. </if>
  875. </where>
  876. order by a.CreateDate
  877. </select>
  878. <select id="searchPackageList" resultType="java.util.Map">
  879. select a.BuNo,a.id as packageId,a.package_type as packageType,a.package_no as packageNo,
  880. a.length, a.width, a.height
  881. from ecss_package a
  882. <where> a.BuNo = #{buNo}
  883. <if test="packageType != null and packageType != ''">
  884. AND a.package_type like '%'+#{packageType}+'%'
  885. </if>
  886. </where>
  887. order by a.CreateDate
  888. </select>
  889. <select id="getDeclarationElements" resultType="java.util.Map">
  890. select part_no as partNo,bu_no as buNo,MIN(item_no) as itemNo
  891. from ecss_CoDelNotifyDetail
  892. where site=#{site} and delNo=#{delNo} and qty>0
  893. GROUP BY part_no,bu_no
  894. ORDER BY
  895. CASE WHEN MIN(TRY_CONVERT(BIGINT, item_no)) IS NULL THEN 1 ELSE 0 END,
  896. MIN(TRY_CONVERT(BIGINT, item_no)),
  897. MIN(item_no)
  898. </select>
  899. <select id="getHsCodeByPartNo" resultType="java.util.Map">
  900. select p.hsCode, p.hsCodeDesc, p.brand, p.part_no ,h.codeNo,h.BuNo,p.sku,h.hsCodeDescEn
  901. from Part p
  902. left join ecss_hsCode h on p.hsCodeDesc=h.hsCodeDesc and p.site=h.site
  903. where p.site=#{site,jdbcType=VARCHAR} and p.part_no in
  904. <foreach item="item" index="index" collection="partNos" open="(" separator="," close=")">
  905. #{item}
  906. </foreach>
  907. </select>
  908. <select id="getDeclarationHeader" resultType="EcssDeclarationHeaderData">
  909. select * from ecss_declaration_header where site=#{site} and declaration_no=#{declarationNo}
  910. </select>
  911. <select id="getDeclarationHeaderByDelNo" resultType="EcssDeclarationHeaderData">
  912. select * from ecss_declaration_header where site=#{site} and delNo=#{delNo}
  913. </select>
  914. <select id="exportDeclarationDetail" resultType="java.util.Map">
  915. select detail.site,detail.declaration_no,detail.item_no,
  916. CONVERT(DECIMAL(20, 6), detail.qty) as qty,isnull(h.unit,'') as qty_unit,'kg' as weight_unit,
  917. CONVERT(DECIMAL(20, 2),detail.net_weight) as net_weight,CONVERT(DECIMAL(20, 6),detail.unit_price) as unit_price,
  918. CONVERT(DECIMAL(20, 2),detail.total_price) as total_price,detail.currency,detail.made_area,detail.destination,
  919. detail.source_area,detail.levy,detail.hs_code,detail.hs_code_desc,h.hsCodeDescEn
  920. from ecss_declaration_detail detail
  921. left join ecss_hsCode h on detail.hs_code=h.HsCode and detail.site=h.Site and detail.hs_code_desc=h.hsCodeDesc
  922. where detail.site=#{site} and declaration_no=#{declarationNo}
  923. </select>
  924. <select id="exportDeclarationDetailTX" resultType="java.util.Map">
  925. select detail.site,detail.declaration_no,detail.item_no,isnull(detail.unit,'') as ecss_umid,
  926. CONVERT(DECIMAL(20, 6), detail.qty) as qty,isnull(h.unit,'') as qty_unit,'kg' as weight_unit,
  927. CONVERT(DECIMAL(20, 2),detail.net_weight) as net_weight,CONVERT(DECIMAL(20, 6),detail.unit_price) as unit_price,
  928. CONVERT(DECIMAL(20, 2),detail.total_price) as total_price,detail.currency,detail.made_area,detail.destination,
  929. detail.source_area,detail.levy,detail.hs_code,detail.hs_code_desc,h.hsCodeDescEn
  930. from ecss_declaration_detail detail
  931. left join ecss_hsCode h on detail.hs_code=h.HsCode and detail.site=h.Site and detail.hs_code_desc=h.hsCodeDesc and detail.brand=h.brand
  932. where detail.site=#{site} and declaration_no=#{declarationNo}
  933. </select>
  934. <select id="getEcssCoDelNotifyHeader" resultType="EcssCoDelNotifyHeaderData">
  935. select * from ecss_CoDelNotifyHeader where site=#{site} and delNo=#{delNo}
  936. </select>
  937. <select id="exportEcssCoDelNotifyDetail" resultType="java.util.Map">
  938. select a.customerPO,a.part_no,a.part_description,LEFT(a.currency, 3) as currency,
  939. CONVERT(DECIMAL(20, 0), a.qty) as qty,CONVERT(DECIMAL(20, 6), a.tp) as unitPrice,b.hsCode,
  940. a.upc,a.so,a.ttl_amount,a.pn,b.hsCodeDesc,h.hsCodeDescEn,a.salesOrder,b.umid as unit,b.brand,h.unit as hsUnit,b.ecss_umid as ecssUmid
  941. from ecss_CoDelNotifydetail a
  942. left join part b on a.site=b.site and a.part_no=b.part_no
  943. left join ecss_hsCode h on b.hsCode=h.HsCode and a.site=h.site and b.hsCodeDesc=h.hsCodeDesc
  944. where a.site = #{site} AND a.delNo = #{delNo} and a.qty>0
  945. order by a.item_no
  946. </select>
  947. <select id="exportCoDelPalletDetail" resultType="java.util.Map">
  948. -- 修复净重毛重重复计算问题:按数量比例分配箱子重量
  949. WITH BoxDetail AS (
  950. SELECT
  951. b.part_no,
  952. b.qty,
  953. b.rolls,
  954. a.box_qty,
  955. a.net_weight,
  956. a.gross_weight,
  957. b.site,
  958. b.bu_no,
  959. b.delNo,
  960. b.seq_no,
  961. -- 计算该零件数量占该箱子总数量的比例
  962. CASE
  963. WHEN SUM(b.qty) OVER (PARTITION BY b.site, b.bu_no, b.delNo, b.seq_no) > 0
  964. THEN b.qty * 1.0 / SUM(b.qty) OVER (PARTITION BY b.site, b.bu_no, b.delNo, b.seq_no)
  965. ELSE 0
  966. END as qtyRatio
  967. FROM ecss_CoDelBoxList a
  968. LEFT JOIN ecss_CoDelPalletDetail b ON a.site=b.site AND a.bu_no=b.bu_no AND a.delNo=b.delNo AND a.item_no=b.seq_no
  969. WHERE a.site=#{site} AND a.bu_no=#{buNo} AND a.delNo=#{delNo} AND b.site IS NOT NULL
  970. )
  971. SELECT
  972. part_no,
  973. CONVERT(DECIMAL(20, 6), SUM(qty)) as total_qty,
  974. CONVERT(DECIMAL(20, 0), SUM(DISTINCT box_qty)) as box_qty,
  975. CONVERT(DECIMAL(20, 0), SUM(rolls)) as rolls,
  976. -- 按数量比例分配净重和毛重
  977. CONVERT(DECIMAL(20, 2), SUM(ISNULL(net_weight, 0) * qtyRatio)) as net_weight,
  978. CONVERT(DECIMAL(20, 2), SUM(ISNULL(gross_weight, 0) * qtyRatio)) as gross_weight,
  979. CONVERT(DECIMAL(20, 0), SUM(rolls * qty)) as qty_per_carton
  980. FROM BoxDetail
  981. GROUP BY part_no
  982. </select>
  983. <select id="getCoDelPalletDetailGroupByPn" resultType="java.util.Map">
  984. -- 修复净重毛重重复计算问题:按数量比例分配箱子重量
  985. WITH BoxDetail AS (
  986. SELECT
  987. b.pn,
  988. b.qty,
  989. b.rolls,
  990. a.box_qty,
  991. a.net_weight,
  992. a.gross_weight,
  993. b.site,
  994. b.bu_no,
  995. b.delNo,
  996. b.seq_no,
  997. -- 计算该零件数量占该箱子总数量的比例
  998. CASE
  999. WHEN SUM(b.qty) OVER (PARTITION BY b.site, b.bu_no, b.delNo, b.seq_no) > 0
  1000. THEN b.qty * 1.0 / SUM(b.qty) OVER (PARTITION BY b.site, b.bu_no, b.delNo, b.seq_no)
  1001. ELSE 0
  1002. END as qtyRatio
  1003. FROM ecss_CoDelBoxList a
  1004. LEFT JOIN ecss_CoDelPalletDetail b ON a.site=b.site AND a.bu_no=b.bu_no AND a.delNo=b.delNo AND a.item_no=b.seq_no
  1005. WHERE a.site=#{site} AND a.bu_no=#{buNo} AND a.delNo=#{delNo}
  1006. )
  1007. SELECT
  1008. pn,
  1009. CONVERT(DECIMAL(20, 0), SUM(qty)) as total_qty,
  1010. CONVERT(DECIMAL(20, 0), SUM(DISTINCT box_qty)) as box_qty,
  1011. CONVERT(DECIMAL(20, 0), SUM(rolls)) as rolls,
  1012. -- 按数量比例分配净重和毛重
  1013. CONVERT(DECIMAL(20, 2), SUM(ISNULL(net_weight, 0) * qtyRatio)) as net_weight,
  1014. CONVERT(DECIMAL(20, 2), SUM(ISNULL(gross_weight, 0) * qtyRatio)) as gross_weight,
  1015. CONVERT(DECIMAL(20, 0), SUM(rolls * qty)) as qty_per_carton
  1016. FROM BoxDetail
  1017. WHERE pn IS NOT NULL
  1018. GROUP BY pn
  1019. </select>
  1020. <!-- 按发货通知单明细item_no分组获取装箱明细重量(用于Invoice) -->
  1021. <select id="exportCoDelPalletDetailGroupByItemNo" resultType="java.util.Map">
  1022. -- 按发货通知单明细行号分组,汇总该行对应的装箱重量
  1023. WITH BoxDetail AS (
  1024. SELECT
  1025. b.notify_detail_item_no,
  1026. b.part_no,
  1027. b.qty,
  1028. b.rolls,
  1029. a.box_qty,
  1030. a.net_weight,
  1031. a.gross_weight,
  1032. b.site,
  1033. b.bu_no,
  1034. b.delNo,
  1035. b.seq_no,
  1036. -- 计算该零件数量占该箱子总数量的比例
  1037. CASE
  1038. WHEN SUM(b.qty) OVER (PARTITION BY b.site, b.bu_no, b.delNo, b.seq_no) > 0
  1039. THEN b.qty * 1.0 / SUM(b.qty) OVER (PARTITION BY b.site, b.bu_no, b.delNo, b.seq_no)
  1040. ELSE 0
  1041. END as qtyRatio
  1042. FROM ecss_CoDelBoxList a
  1043. LEFT JOIN ecss_CoDelPalletDetail b ON a.site=b.site AND a.bu_no=b.bu_no AND a.delNo=b.delNo AND a.item_no=b.seq_no
  1044. WHERE a.site=#{site} AND a.bu_no=#{buNo} AND a.delNo=#{delNo} AND b.notify_detail_item_no IS NOT NULL
  1045. )
  1046. SELECT
  1047. notify_detail_item_no as item_no,
  1048. part_no,
  1049. CONVERT(DECIMAL(20, 0), SUM(qty)) as total_qty,
  1050. CONVERT(DECIMAL(20, 0), SUM(DISTINCT box_qty)) as box_qty,
  1051. CONVERT(DECIMAL(20, 0), SUM(rolls)) as rolls,
  1052. -- 按数量比例分配净重和毛重
  1053. CONVERT(DECIMAL(20, 2), SUM(ISNULL(net_weight, 0) * qtyRatio)) as net_weight,
  1054. CONVERT(DECIMAL(20, 2), SUM(ISNULL(gross_weight, 0) * qtyRatio)) as gross_weight,
  1055. CONVERT(DECIMAL(20, 0), SUM(rolls * qty)) as qty_per_carton
  1056. FROM BoxDetail
  1057. GROUP BY notify_detail_item_no, part_no
  1058. </select>
  1059. <select id="exportCoDelBoxList" resultType="java.util.Map">
  1060. select CONVERT(DECIMAL(20, 0),sum(a.box_qty)) as box_qty
  1061. from ecss_CoDelBoxList a
  1062. where a.site=#{site} and a.bu_no=#{buNo} and a.delNo=#{delNo} GROUP BY a.item_no
  1063. </select>
  1064. <update id="updateEcssDeclarationHeader" >
  1065. update ecss_declaration_header set
  1066. upc=#{upc},so=#{so},origin=#{origin},pallet_weight=#{palletWeight},material=#{material},
  1067. hs_code=#{hsCode},packaging=#{packaging},kgs=#{kgs},shipping_mark=#{shippingMark},boxChange=#{boxChange},
  1068. hsCodeDesc=#{hsCodeDesc},contractFlag=#{contractFlag},hsCodeDescType=#{hsCodeDescType},goodsLabel=#{goodsLabel}
  1069. where site=#{site} and declaration_no=#{declarationNo}
  1070. </update>
  1071. <update id="updateEcssCoDelNotifyDetail" >
  1072. update ecss_CoDelNotifydetail set lossratio=#{lossratio},ehundred=#{ehundred}
  1073. where site=#{site} and delNo=#{delNo} and part_no=#{partNo}
  1074. </update>
  1075. <update id="updateEcssCoDelNotifyDetailSurplus" >
  1076. update ecss_CoDelNotifydetail set surplus_qty=#{surplusQty}
  1077. where site=#{site} and bu_no=#{buNo} and delNo=#{delNo} and part_no=#{partNo} and item_no=#{itemNo}
  1078. </update>
  1079. <select id="getNotifyPartDetail" resultType="java.util.Map">
  1080. select a.part_no as partNo,b.hsCode,a.site,a.delNo,a.lossratio,a.ehundred,b.part_desc,a.pn
  1081. from ecss_CoDelNotifydetail a
  1082. left join part b on a.site=b.site and a.part_no=b.part_no
  1083. where a.site = #{site} AND a.delNo = #{delNo} and a.qty>0
  1084. group by a.part_no,b.hsCode,a.site,a.delNo,a.lossratio,a.ehundred,b.part_desc,a.pn
  1085. </select>
  1086. <select id="getDeclarationPalletPartDetail" resultType="java.util.Map">
  1087. select pd.part_no as partNo,
  1088. p.hsCode,
  1089. pd.site,
  1090. pd.delNo,
  1091. nd.lossratio,
  1092. nd.ehundred,
  1093. p.part_desc,
  1094. pd.pn,
  1095. ISNULL(p.fsc_flag, 'N') as fscFlag,
  1096. CONVERT(DECIMAL(20, 6), pd.qty) as qty,
  1097. CONVERT(DECIMAL(20, 6), ISNULL(fsc.num_value, 0)) as fscUnitWeight
  1098. from (
  1099. select site, bu_no, delNo, part_no, pn, sum(qty) as qty
  1100. from ecss_CoDelPalletDetail
  1101. where site = #{site} and bu_no = #{buNo} and delNo = #{delNo} and qty > 0
  1102. group by site, bu_no, delNo, part_no, pn
  1103. ) pd
  1104. left join (
  1105. select site, bu_no, delNo, part_no,
  1106. max(lossratio) as lossratio,
  1107. max(ehundred) as ehundred
  1108. from ecss_CoDelNotifydetail
  1109. where site = #{site} and bu_no = #{buNo} and delNo = #{delNo}
  1110. group by site, bu_no, delNo, part_no
  1111. ) nd on pd.site = nd.site
  1112. and pd.bu_no = nd.bu_no
  1113. and pd.delNo = nd.delNo
  1114. and pd.part_no = nd.part_no
  1115. left join part p on pd.site = p.site and pd.part_no = p.part_no
  1116. left join part_sub_properties_value fsc
  1117. on pd.site = fsc.site
  1118. and pd.bu_no = fsc.bu_no
  1119. and pd.part_no = fsc.part_no
  1120. and fsc.record_type = 'ECSSPART'
  1121. and fsc.code_no = 'BG001'
  1122. and fsc.properties_item_no = 'FSC006'
  1123. order by pd.part_no
  1124. </select>
  1125. <select id="getNotifyPartDetail2" resultType="EcssCoDelNotifyDetailData">
  1126. select a.part_no as partNo,b.hsCode,a.site,a.delNo,a.lossratio,a.ehundred,b.part_desc,a.pn
  1127. from ecss_CoDelNotifydetail a
  1128. left join part b on a.site=b.site and a.part_no=b.part_no
  1129. where a.site = #{site} AND a.delNo = #{delNo} and a.qty>0
  1130. group by a.part_no,b.hsCode,a.site,a.delNo,a.lossratio,a.ehundred,b.part_desc,a.pn
  1131. </select>
  1132. <select id="getNotifyDetailGroup" resultType="java.util.Map">
  1133. select b.hsCodeDesc,CONVERT(DECIMAL(20, 2),sum(a.qty)) as total_qty,
  1134. CONVERT(DECIMAL(20, 2),sum(a.ttl_amount)) as ttl_amount
  1135. from ecss_CoDelNotifydetail a
  1136. left join part b on a.site=b.site and a.part_no=b.part_no
  1137. where a.site = #{site} AND a.delNo = #{delNo} and a.qty>0
  1138. group by b.hsCodeDesc
  1139. </select>
  1140. <select id="getNotifyDetailGroupTX" resultType="java.util.Map">
  1141. select b.hsCodeDesc,CONVERT(DECIMAL(20, 2),sum(a.qty)) as total_qty,
  1142. CONVERT(DECIMAL(20, 2),sum(a.ttl_amount)) as ttl_amount
  1143. from ecss_CoDelNotifydetail a
  1144. left join part b on a.site=b.site and a.part_no=b.part_no
  1145. where a.site = #{site} AND a.delNo = #{delNo} and a.qty>0
  1146. group by b.hsCodeDesc,b.brand
  1147. </select>
  1148. <!-- 根据notifyDetailItemNo获取发货通知单明细 -->
  1149. <select id="getEcssCoDelNotifyDetailByItemNo" resultType="EcssCoDelNotifyDetailData">
  1150. select a.site,a.bu_no,a.delNo,a.item_no,a.salesOrder,a.salesOrder_item_no,a.customerPO,a.line,a.version,a.status,a.family,
  1151. a.part_no,a.part_description,a.qty,a.lt,a.cmc_comment,a.saleType,a.awb_bl,a.shipping_number,a.forwarder_info,isnull(a.surplus_qty,0) surplusQty,
  1152. a.currency,a.tp,a.ttl_amount,a.sum_price,a.so,a.upc,a.remark,a.erp_delItemNo,a.pn,CONVERT(DECIMAL(20, 0),a.nocartons) as nocartons,
  1153. a.modifyFlag,a.modifyQtyFlag
  1154. from ecss_CoDelNotifydetail a
  1155. where a.site = #{site}
  1156. and a.bu_no = #{buNo}
  1157. and a.delNo = #{delNo}
  1158. and a.item_no = #{notifyDetailItemNo}
  1159. </select>
  1160. <!-- 根据delNo获取发货通知单明细 -->
  1161. <select id="getEcssCoDelNotifyDetailByDelNo" resultType="java.util.Map">
  1162. select a.site,a.bu_no,a.delNo,a.item_no,a.salesOrder,a.salesOrder_item_no,a.customerPO,a.line,a.version,a.status,a.family,
  1163. a.part_no,a.part_description,a.qty,a.lt,a.cmc_comment,a.saleType,a.awb_bl,a.shipping_number,a.forwarder_info,isnull(a.surplus_qty,0) surplusQty,
  1164. a.currency,a.tp,a.ttl_amount,a.sum_price,a.so,a.upc,a.remark,a.erp_delItemNo,a.pn,CONVERT(DECIMAL(20, 0),a.nocartons) as nocartons,
  1165. a.modifyFlag,a.modifyQtyFlag
  1166. from ecss_CoDelNotifydetail a
  1167. where a.site = #{site}
  1168. and a.delNo = #{delNo}
  1169. </select>
  1170. <select id="getPropertiesListByTypeAndCodeNo" resultType="com.xujie.sys.modules.part.entity.PartSubPropertiesValueData">
  1171. SELECT a.part_no , a.Site, a.code_no, a.sub_code_seq_no, a.sub_code_desc
  1172. ,a.bu_no,a.item_no, a.properties_item_no, a.text_value, a.num_value, a.record_type
  1173. , b.item_desc ItemDesc, b.value_type, b.value_type_db, b.value_choose_flag
  1174. FROM part_sub_properties_value a
  1175. left join plm_properties_item b
  1176. on a.properties_item_no = b.Item_No and a.site = b.site and a.record_type = b.Item_Type and a.bu_no=b.bu_no
  1177. <where>
  1178. AND a.site = #{site}
  1179. and a.record_type = #{recordType}
  1180. and a.bu_no=#{buNo}
  1181. and a.code_no = #{codeNo}
  1182. and a.part_no = #{pn}
  1183. </where>
  1184. order by a.item_no
  1185. </select>
  1186. <select id="getEcssContacts" resultType="java.util.Map">
  1187. select
  1188. bu_no as buNo,
  1189. [name] as [name],
  1190. phone as phone,
  1191. company as company,
  1192. [address] as [address],
  1193. landline as landline,
  1194. [defaultOption] as defaultOption
  1195. from ecss_contacts
  1196. <where>
  1197. bu_no = #{buNo}
  1198. <if test="company != null and company != ''">
  1199. and company = #{company}
  1200. </if>
  1201. <if test="address != null and address != ''">
  1202. and [address] = #{address}
  1203. </if>
  1204. </where>
  1205. order by
  1206. case when [defaultOption] = 'Y' then 0 else 1 end,
  1207. ISNULL(company, ''),
  1208. ISNULL([address], ''),
  1209. ISNULL([name], '')
  1210. </select>
  1211. <select id="getCustomerList" resultType="java.util.Map">
  1212. select * from ecss_custdev_mes_cmc_customer where buse='是'
  1213. </select>
  1214. <select id="getCustomerInfo" resultType="java.util.Map">
  1215. select DISTINCT vcus.ccusname,vcusp.ccontactname,vcusp.cnative
  1216. from ecss_custdev_mes_cmc_customer vcus
  1217. LEFT JOIN ecss_custdev_mes_cmc_customer_person vcusp on vcus.ccuscode=vcusp.ccuscode
  1218. <where>
  1219. <if test="ccusname != null and ccusname != ''">
  1220. and vcus.ccusname=#{ccusname}
  1221. </if>
  1222. <if test="ccuscode != null and ccuscode != ''">
  1223. and vcus.ccuscode=#{ccuscode}
  1224. </if>
  1225. </where>
  1226. </select>
  1227. <select id="getCustomerAdd" resultType="java.util.Map">
  1228. select DISTINCT vcus.ccusname,vcusa.cDeliverAdd
  1229. from ecss_custdev_mes_cmc_customer vcus
  1230. left join ecss_custdev_mes_cmc_customer_addr vcusa on vcus.ccuscode=vcusa.ccuscode
  1231. where vcus.ccusname=#{ccusname}
  1232. </select>
  1233. <select id="getPackageNoByPartNo" resultType="java.util.Map">
  1234. select p.part_no as partNo,p.packageNo
  1235. from Part p
  1236. where p.site=#{site,jdbcType=VARCHAR} and p.part_no in
  1237. <foreach item="item" index="index" collection="partNos" open="(" separator="," close=")">
  1238. #{item}
  1239. </foreach>
  1240. </select>
  1241. <select id="getPackageNoByPn" resultType="java.util.Map">
  1242. select p.sku as pn,p.packageNo
  1243. from Part p
  1244. where p.site=#{site,jdbcType=VARCHAR} and p.sku in
  1245. <foreach item="item" index="index" collection="pns" open="(" separator="," close=")">
  1246. #{item}
  1247. </foreach>
  1248. </select>
  1249. <select id="getPackageList" resultType="EcssPackageData">
  1250. select * from ecss_package where site=#{site} and buNo=#{buNo}
  1251. and package_no in
  1252. <foreach item="item" index="index" collection="packageNos" open="(" separator="," close=")">
  1253. #{item}
  1254. </foreach>
  1255. </select>
  1256. <select id="searchEcssTemplateData" resultType="EcssTemplate">
  1257. select a.*,dbo.get_bu_desc(a.site,a.BuNo) as BuDesc
  1258. from ecss_template a
  1259. left join accessBu D on A.site=D.site and A.BuNo=d.bu_no and D.username=#{query.username}
  1260. <where>
  1261. and D.site is not null
  1262. <if test="query.buNo != null and query.buNo != ''">
  1263. AND a.buNo = #{query.buNo}
  1264. </if>
  1265. <if test="query.name != null and query.name != ''">
  1266. AND a.name like '%'+#{query.name}+'%'
  1267. </if>
  1268. <if test="query.customName != null and query.customName != ''">
  1269. AND a.customName like '%'+#{query.customName}+'%'
  1270. </if>
  1271. <if test="query.shippingMode != null and query.shippingMode != ''">
  1272. AND a.shippingMode like '%'+#{query.shippingMode}+'%'
  1273. </if>
  1274. <if test="query.type != null and query.type != ''">
  1275. AND a.type = #{query.type}
  1276. </if>
  1277. </where>
  1278. order by a.CreateDate
  1279. </select>
  1280. <insert id="insertEcssTemplateData" >
  1281. insert into ecss_template (customName,site,buNo,name,type,upc,so,origin,palletWeight,material,hsCode,packaging,itemNo,
  1282. kgs,shippingMark,boxChange,hsCodeDesc,contractFlag,hsCodeDescType,goodsLabel,hsCodeFlag,shippingMode,CreateBy,CreateDate,
  1283. salesMethod,currency,madeArea,sendPort,shipper,voyage,deliveryGoodsDate,shippingDate,fscWeight, remark,highPalletFlag,showWeight)
  1284. values(#{customName,jdbcType=NVARCHAR},#{site},#{buNo},#{name},#{type},#{upc},#{so},#{origin},#{palletWeight},#{material},#{hsCode},#{packaging},
  1285. #{itemNo},#{kgs},#{shippingMark},#{boxChange},
  1286. #{hsCodeDesc},#{contractFlag},#{hsCodeDescType},#{goodsLabel},#{hsCodeFlag},#{shippingMode},#{createBy},GetDate(),
  1287. #{salesMethod},#{currency},#{madeArea},#{sendPort},#{shipper},#{voyage},#{deliveryGoodsDate},#{shippingDate},#{fscWeight},#{remark},#{highPalletFlag},#{showWeight})
  1288. </insert>
  1289. <update id="updateEcssTemplateData">
  1290. update ecss_template set buNo=#{buNo},name=#{name},type=#{type},upc=#{upc},so=#{so},origin=#{origin},boxChange=#{boxChange},
  1291. palletWeight=#{palletWeight},material=#{material},hsCode=#{hsCode},itemNo=#{itemNo},
  1292. packaging=#{packaging},kgs=#{kgs},shippingMark=#{shippingMark},hsCodeDesc=#{hsCodeDesc},
  1293. contractFlag=#{contractFlag},hsCodeDescType=#{hsCodeDescType},goodsLabel=#{goodsLabel},hsCodeFlag=#{hsCodeFlag},
  1294. shippingMode=#{shippingMode},UpdateDate=GetDate(),UpdateBy=#{updateBy},customName=#{customName,jdbcType=NVARCHAR},salesMethod= #{salesMethod},
  1295. currency= #{currency},madeArea= #{madeArea},sendPort= #{sendPort},shipper= #{shipper},remark= #{remark},
  1296. voyage= #{voyage},deliveryGoodsDate= #{deliveryGoodsDate},shippingDate= #{shippingDate},fscWeight=#{fscWeight},highPalletFlag=#{highPalletFlag},showWeight=#{showWeight}
  1297. where buNo=#{buNo} and name=#{nameNative}
  1298. </update>
  1299. <select id="deleteEcssTemplate" >
  1300. delete from ecss_template where buNo=#{buNo} and name=#{name}
  1301. </select>
  1302. <select id="getEcssTemplateByBuAndName" resultType="EcssTemplate">
  1303. select * from ecss_template where name=#{name} and site=#{site}
  1304. </select>
  1305. <select id="searchWalMartOrderData" resultType="EcssWalMartOrder">
  1306. select a.*
  1307. from ecss_walMartOrder a
  1308. <where>
  1309. <if test="query.so != null and query.so != ''">
  1310. AND a.so like '%'+#{query.so}+'%'
  1311. </if>
  1312. <if test="query.sku != null and query.sku != ''">
  1313. AND a.sku like '%'+#{query.sku}+'%'
  1314. </if>
  1315. </where>
  1316. order by a.CreateDate
  1317. </select>
  1318. <insert id="insertWalMartOrderData" >
  1319. insert into ecss_walMartOrder (site,buNo,sku,so,qty,rolls,grossWeight,verificationSheet,CreateBy,CreateDate)
  1320. values(#{site},#{buNo},#{sku},#{so},#{qty},#{rolls},#{grossWeight},#{verificationSheet},#{createBy},GetDate())
  1321. </insert>
  1322. <insert id="batchSaveWalMartOrder">
  1323. insert into ecss_walMartOrder (site,buNo,sku,so,qty,rolls,grossWeight,verificationSheet,CreateBy,CreateDate)
  1324. values
  1325. <foreach collection="list" separator="," item="item">
  1326. (#{item.site},#{item.buNo},#{item.sku},#{item.so},#{item.qty},
  1327. #{item.rolls},#{item.grossWeight},#{item.verificationSheet},#{item.createBy},GetDate())
  1328. </foreach>
  1329. </insert>
  1330. <update id="updateWalMartOrderData">
  1331. update ecss_walMartOrder set buNo=#{buNo},sku=#{sku},so=#{so},qty=#{qty},rolls=#{rolls},grossWeight=#{grossWeight},
  1332. verificationSheet=#{verificationSheet},UpdateDate=GetDate(),UpdateBy=#{updateBy}
  1333. where buNo=#{buNo} and sku=#{sku} and so=#{so} and qty=#{qty}
  1334. </update>
  1335. <select id="deleteWalMartOrder" >
  1336. delete from ecss_walMartOrder where buNo=#{buNo} and sku=#{sku} and so=#{so} and qty=#{qty}
  1337. </select>
  1338. <!-- 查出所有类型的物料 -->
  1339. <select id="queryPartListAll" parameterType="PartInformationEntity" resultType="PartInformationEntity">
  1340. SELECT site, sourceBu as buNo, part_no, part_desc, sku
  1341. FROM part
  1342. <where> sourceBu=#{query.buNo} and
  1343. site = #{query.site} and active = 'Y'
  1344. <if test = "query.partNo != null and query.partNo != ''">
  1345. AND part_no like '%' + #{query.partNo} + '%'
  1346. </if>
  1347. <if test = "query.sku != null and query.sku != ''">
  1348. AND sku like '%' + #{query.sku} + '%'
  1349. </if>
  1350. <if test = "query.partDesc != null and query.partDesc != ''">
  1351. AND part_desc like '%' + #{query.partDesc} + '%'
  1352. </if>
  1353. </where>
  1354. </select>
  1355. <select id="queryByUserName" resultType="com.xujie.sys.modules.sys.entity.SysUserEntity">
  1356. select * from sys_user where username = #{username}
  1357. </select>
  1358. <select id="queryUsersByRoleName" resultType="com.xujie.sys.modules.sys.entity.SysUserEntity">
  1359. select u.email from sys_user u
  1360. LEFT JOIN sys_user_role ur on ur.user_id = u.user_id
  1361. LEFT JOIN sys_role r on r.role_id = ur.role_id
  1362. where r.role_name = #{roleName} and u.site = #{site}
  1363. </select>
  1364. <select id="searchCoDelPalletDataNew" resultType="EcssCoDelPalletData">
  1365. select b.site,b.bu_no,b.delNo,b.seq_no,b.item_no,b.po_no,b.part_no,b.qty,b.box_qty,b.rolls,b.pn,
  1366. c.gross_weight,c.net_weight,c.box_qty as pallet_qty,b.notify_detail_item_no as notifyDetailItemNo
  1367. from ecss_CoDelPalletDetail b
  1368. left join ecss_CoDelBoxList c on b.site=c.site and b.bu_no=c.bu_no and b.delNo=c.delNo and b.seq_no=c.item_no
  1369. where b.site=#{site} and b.bu_no=#{buNo} and b.delNo=#{delNo}
  1370. <if test="seqNo != null and seqNo != ''">
  1371. and b.seq_no=#{seqNo}
  1372. </if>
  1373. </select>
  1374. <update id="updateExportFlag">
  1375. update ecss_CoDelNotifyHeader
  1376. set export_flag = #{exportFlag},
  1377. updateBy = #{updateBy},
  1378. updateDate = GetDate()
  1379. where site = #{site}
  1380. and bu_no = #{buNo}
  1381. and delNo = #{delNo}
  1382. </update>
  1383. <select id="selectBoxList" resultType="java.util.Map">
  1384. select a.*,
  1385. CONVERT(DECIMAL(20, 3),a.gross_weight) as grossWeight,
  1386. CONVERT(DECIMAL(20, 3),a.net_weight) as netWeight,
  1387. CONVERT(DECIMAL(20, 3),w.num_value) as boxWeight
  1388. from ecss_CoDelBoxList a
  1389. left join (
  1390. select b.site, b.bu_no, b.delNo, b.seq_no, b.part_no,
  1391. ROW_NUMBER() OVER (PARTITION BY b.site, b.bu_no, b.delNo, b.seq_no ORDER BY b.part_no) as rn
  1392. from ecss_CoDelPalletDetail b
  1393. where b.site = #{site} and b.bu_no = #{buNo} and b.delNo = #{delNo}
  1394. ) d on a.site = d.site and a.bu_no = d.bu_no and a.delNo = d.delNo and a.item_no = d.seq_no and d.rn = 1
  1395. left join part_sub_properties_value w on d.part_no = w.part_no and w.site = d.site and w.bu_no = d.bu_no
  1396. and w.record_type='ECSSPART' and w.code_no='BG001' and w.properties_item_no='BOXWEIGHT'
  1397. where a.site = #{site} and a.bu_no = #{buNo} and a.delNo = #{delNo}
  1398. </select>
  1399. <select id="selectBoxListTX" resultType="java.util.Map">
  1400. select a.*,
  1401. CONVERT(DECIMAL(20, 3),a.gross_weight) as grossWeight,
  1402. CONVERT(DECIMAL(20, 3),a.net_weight) as netWeight,
  1403. CONVERT(DECIMAL(20, 3),w.num_value) as boxWeight
  1404. from ecss_CoDelBoxList a
  1405. left join (
  1406. select b.site, b.bu_no, b.delNo, b.seq_no, b.part_no,
  1407. ROW_NUMBER() OVER (PARTITION BY b.site, b.bu_no, b.delNo, b.seq_no ORDER BY b.part_no) as rn
  1408. from ecss_CoDelPalletDetail b
  1409. where b.site = #{site} and b.bu_no = #{buNo} and b.delNo = #{delNo}
  1410. ) d on a.site = d.site and a.bu_no = d.bu_no and a.delNo = d.delNo and a.item_no = d.seq_no and d.rn = 1
  1411. left join part_sub_properties_value w on d.part_no = w.part_no and w.site = d.site and w.bu_no = d.bu_no
  1412. and w.record_type='ECSSPART' and w.code_no='BG001' and w.properties_item_no='BOXWEIGHT'
  1413. where a.site = #{site} and a.bu_no = #{buNo} and a.delNo = #{delNo}
  1414. order by
  1415. CASE
  1416. WHEN LEFT(a.item_no, CHARINDEX('~', a.item_no + '~') - 1) != ''
  1417. AND LEFT(a.item_no, CHARINDEX('~', a.item_no + '~') - 1) NOT LIKE '%[^0-9]%'
  1418. THEN CONVERT(int, LEFT(a.item_no, CHARINDEX('~', a.item_no + '~') - 1))
  1419. ELSE 2147483647
  1420. END,
  1421. CASE
  1422. WHEN SUBSTRING(a.item_no, CHARINDEX('~', a.item_no + '~') + 1, LEN(a.item_no)) != ''
  1423. AND SUBSTRING(a.item_no, CHARINDEX('~', a.item_no + '~') + 1, LEN(a.item_no)) NOT LIKE '%[^0-9]%'
  1424. THEN CONVERT(int, SUBSTRING(a.item_no, CHARINDEX('~', a.item_no + '~') + 1, LEN(a.item_no)))
  1425. WHEN LEFT(a.item_no, CHARINDEX('~', a.item_no + '~') - 1) != ''
  1426. AND LEFT(a.item_no, CHARINDEX('~', a.item_no + '~') - 1) NOT LIKE '%[^0-9]%'
  1427. THEN CONVERT(int, LEFT(a.item_no, CHARINDEX('~', a.item_no + '~') - 1))
  1428. ELSE 2147483647
  1429. END,
  1430. a.item_no
  1431. </select>
  1432. <update id="updateBoxInfo">
  1433. update ecss_CoDelBoxList
  1434. set box_qty = #{box_qty},
  1435. gross_weight = #{grossWeight},
  1436. net_weight = #{netWeight},
  1437. rolls = #{rolls},
  1438. remark = #{remark}
  1439. where site = #{site}
  1440. and bu_no = #{buNo}
  1441. and delNo = #{delNo}
  1442. and item_no = #{item_no}
  1443. </update>
  1444. <update id="updateTotalVolume">
  1445. update ecss_CoDelNotifyHeader
  1446. set totalVolume = #{totalVolume}
  1447. where site = #{site}
  1448. and bu_no = #{buNo}
  1449. and delNo = #{delNo}
  1450. </update>
  1451. <delete id="deleteBoxInfo">
  1452. delete from ecss_CoDelBoxList
  1453. where site = #{site}
  1454. and bu_no = #{buNo}
  1455. and delNo = #{delNo}
  1456. and item_no = #{item_no}
  1457. </delete>
  1458. <update id="updateDetailInfo">
  1459. update ecss_CoDelPalletDetail
  1460. set qty = #{qty},
  1461. rolls = #{rolls}
  1462. where site = #{site}
  1463. and bu_no = #{buNo}
  1464. and delNo = #{delNo}
  1465. and seq_no = #{seqNo}
  1466. and item_no = #{itemNo}
  1467. </update>
  1468. <update id="updateCodelPalletDetailFscWeight">
  1469. update ecss_CoDelPalletDetail
  1470. set fsc_weight = #{fscWeight,jdbcType=DECIMAL}
  1471. where site = #{site}
  1472. and bu_no = #{buNo}
  1473. and delNo = #{delNo}
  1474. and seq_no = #{seqNo}
  1475. and item_no = #{itemNo}
  1476. </update>
  1477. <delete id="deleteDetailInfo">
  1478. delete from ecss_CoDelPalletDetail
  1479. where site = #{site}
  1480. and bu_no = #{buNo}
  1481. and delNo = #{delNo}
  1482. and seq_no = #{seqNo}
  1483. and item_no = #{itemNo}
  1484. </delete>
  1485. <delete id="deleteEmptyBoxAfterDetailDelete">
  1486. -- 删除明细后,如果该box下没有明细了,则删除对应的box
  1487. delete from ecss_CoDelBoxList
  1488. where site = #{site}
  1489. and bu_no = #{buNo}
  1490. and delNo = #{delNo}
  1491. and item_no = #{seqNo}
  1492. and not exists (
  1493. select 1
  1494. from ecss_CoDelPalletDetail
  1495. where site = #{site}
  1496. and bu_no = #{buNo}
  1497. and delNo = #{delNo}
  1498. and seq_no = #{seqNo}
  1499. );
  1500. </delete>
  1501. <!--<select id="selectPalletDetailList" resultType="java.util.Map">
  1502. select a.*,b.part_description,b.hsCode,b.upc,b.so
  1503. from ecss_CoDelPalletDetail a left join (
  1504. select a.site,a.bu_no,a.delNo,a.part_no,a.part_description,b.hsCode,a.upc,a.so,a.customerPO
  1505. from ecss_CoDelNotifydetail a
  1506. left join part b on a.site=b.site and a.part_no=b.part_no
  1507. where a.site=#{site} and a.bu_no=#{buNo} and a.delNo=#{delNo}
  1508. GROUP BY a.site,a.bu_no,a.delNo,a.part_no,a.part_description,b.hsCode,a.upc,a.so,a.customerPO
  1509. ) b on a.site=b.site and a.bu_no=b.bu_no and a.delNo=b.delNo and a.part_no=b.part_no and b.customerPO=a.po_no
  1510. where a.site =#{site} and a.bu_no=#{buNo} and a.delNo=#{delNo}
  1511. <if test="seqNo != null and seqNo != ''">
  1512. and a.seq_no=#{seqNo}
  1513. </if>
  1514. order by a.notify_detail_item_no
  1515. </select>-->
  1516. <select id="selectPalletDetailList" resultType="java.util.Map">
  1517. select a.*,b.part_description,c.hsCode,b.upc,b.salesOrder as so,c.hsCodeDesc
  1518. from ecss_CoDelPalletDetail a
  1519. left join ecss_CoDelNotifydetail b on a.site=b.site and a.bu_no=b.bu_no and a.delNo=b.delNo and a.notify_detail_item_no=b.item_no
  1520. left join part c on a.site=c.site and a.part_no=c.part_no
  1521. where a.site =#{site} and a.bu_no=#{buNo} and a.delNo=#{delNo}
  1522. <if test="seqNo != null and seqNo != ''">
  1523. and a.seq_no=#{seqNo}
  1524. </if>
  1525. order by a.notify_detail_item_no
  1526. </select>
  1527. <!-- 获取客户模板列表 -->
  1528. <select id="getCustomerTemplateList" resultType="java.util.Map">
  1529. SELECT
  1530. template_no,
  1531. template_name,
  1532. bu_no AS buNo,
  1533. ccuscode,
  1534. ccusname,
  1535. caddcode1,
  1536. localShipAddress,
  1537. salesArea,
  1538. caddcode2,
  1539. overseasAddress,
  1540. cnative,
  1541. overseasShipper
  1542. FROM ecss_Customer_template
  1543. <where>
  1544. <if test="templateName != null and templateName != ''">
  1545. AND template_name like '%'+#{templateName}+'%'
  1546. </if>
  1547. <if test="customerName != null and customerName != ''">
  1548. AND customer_name like '%'+#{customerName}+'%'
  1549. </if>
  1550. <if test="templateBuNo != null and templateBuNo != ''">
  1551. AND EXISTS (
  1552. SELECT 1
  1553. FROM string_split(REPLACE(#{templateBuNo}, ' ', ''), ',') queryBu
  1554. WHERE queryBu.value != ''
  1555. AND CHARINDEX(',' + queryBu.value + ',', ',' + REPLACE(ISNULL(bu_no, ''), ' ', '') + ',') > 0
  1556. )
  1557. </if>
  1558. </where>
  1559. ORDER BY template_name
  1560. </select>
  1561. <update id="updateCustomerTemplate">
  1562. update ecss_Customer_template
  1563. <set>
  1564. ccusname = #{ccusname},
  1565. localShipAddress = #{localShipAddress},
  1566. overseasShipper = #{overseasShipper},
  1567. overseasAddress = #{overseasAddress},
  1568. cnative = #{cnative},
  1569. salesArea = #{salesArea},
  1570. <if test="templateBuNo != null and templateBuNo != ''">
  1571. bu_no = #{templateBuNo},
  1572. </if>
  1573. </set>
  1574. where template_no = #{templateNo}
  1575. </update>
  1576. <!-- ========== 物料包装属性导入相关SQL ========== -->
  1577. <!-- 根据SKU获取物料信息(一个SKU可能对应多个part) -->
  1578. <select id="getPartListBySku" resultType="PartData">
  1579. SELECT site, sourceBu as buNo, part_no as partNo, part_desc as partDesc, sku
  1580. FROM part
  1581. WHERE site = #{site}
  1582. AND sourceBu = #{buNo}
  1583. AND sku = #{sku}
  1584. </select>
  1585. <!-- 检查物料属性是否存在 -->
  1586. <select id="checkPartPropertyExists" resultType="java.util.Map">
  1587. SELECT part_no, properties_item_no, num_value, text_value, item_no
  1588. FROM part_sub_properties_value
  1589. WHERE site = #{site}
  1590. AND bu_no = #{buNo}
  1591. AND part_no = #{partNo}
  1592. AND code_no = #{codeNo}
  1593. AND record_type = #{recordType}
  1594. AND properties_item_no = #{propertiesItemNo}
  1595. </select>
  1596. <!-- 更新物料属性数值 -->
  1597. <update id="updatePartPropertyNumValue">
  1598. UPDATE part_sub_properties_value
  1599. SET num_value = #{numValue}
  1600. WHERE site = #{site}
  1601. AND bu_no = #{buNo}
  1602. AND part_no = #{partNo}
  1603. AND code_no = #{codeNo}
  1604. AND record_type = #{recordType}
  1605. AND properties_item_no = #{propertiesItemNo}
  1606. </update>
  1607. <!-- 获取物料属性的最大item_no -->
  1608. <select id="getMaxItemNo" resultType="java.lang.Double">
  1609. SELECT MAX(item_no)
  1610. FROM part_sub_properties_value
  1611. WHERE site = #{site}
  1612. AND bu_no = #{buNo}
  1613. AND part_no = #{partNo}
  1614. AND code_no = #{codeNo}
  1615. AND record_type = #{recordType}
  1616. </select>
  1617. <!-- 获取属性定义信息 -->
  1618. <select id="getPropertiesItemInfo" resultType="java.util.Map">
  1619. SELECT item_no, item_desc, value_type, value_type_db,
  1620. (SELECT TOP 1 code_desc FROM plm_properties_model_header
  1621. WHERE site = #{site} AND bu_no = #{buNo} AND function_type = #{itemType}) as codeDesc
  1622. FROM plm_properties_item
  1623. WHERE site = #{site}
  1624. AND bu_no = #{buNo}
  1625. AND item_no = #{itemNo}
  1626. AND item_type = #{itemType}
  1627. </select>
  1628. <!-- 插入物料属性 -->
  1629. <insert id="insertPartProperty">
  1630. INSERT INTO part_sub_properties_value
  1631. (part_no, site, bu_no, code_no, sub_code_seq_no, sub_code_desc, item_no, properties_item_no, text_value, num_value, record_type)
  1632. VALUES
  1633. (#{partNo}, #{site}, #{buNo}, #{codeNo}, #{subCodeSeqNo}, #{subCodeDesc}, #{itemNo}, #{propertiesItemNo}, #{textValue}, #{numValue}, #{recordType})
  1634. </insert>
  1635. <!-- 检查箱类型是否存在(根据packageNo) -->
  1636. <select id="checkPackageExists" resultType="java.util.Map">
  1637. SELECT id, site, BuNo, package_no as packageNo, package_type as packageType, length, width, height
  1638. FROM ecss_package
  1639. WHERE site = #{site}
  1640. AND BuNo = #{buNo}
  1641. AND package_no = #{packageNo}
  1642. </select>
  1643. <!-- 根据packageType检查箱类型是否存在 -->
  1644. <select id="checkPackageExistsByType" resultType="java.util.Map">
  1645. SELECT id, site, BuNo, package_no as packageNo, package_type as packageType, length, width, height
  1646. FROM ecss_package
  1647. WHERE site = #{site}
  1648. AND BuNo = #{buNo}
  1649. AND package_type = #{packageType}
  1650. </select>
  1651. <!-- 获取箱类型的最大packageNo编号 -->
  1652. <select id="getMaxPackageNo" resultType="java.lang.String">
  1653. SELECT MAX(package_no)
  1654. FROM ecss_package
  1655. WHERE site = #{site}
  1656. AND BuNo = #{buNo}
  1657. </select>
  1658. <!-- 插入箱类型 -->
  1659. <insert id="insertPackage">
  1660. INSERT INTO ecss_package
  1661. (Site, BuNo, package_no, package_type, length, width, height, volume, weight, Remark, CreateBy, CreateDate)
  1662. VALUES
  1663. (#{site}, #{buNo}, #{packageNo}, #{packageType}, #{length}, #{width}, #{height}, #{volume}, #{weight}, #{remark}, #{createBy}, GETDATE())
  1664. </insert>
  1665. <!-- 更新箱类型尺寸(根据packageType更新) -->
  1666. <update id="updatePackageDimensions">
  1667. UPDATE ecss_package
  1668. SET length = #{length},
  1669. width = #{width},
  1670. height = #{height},
  1671. volume = #{volume},
  1672. UpdateBy = #{updateBy},
  1673. UpdateDate = GETDATE()
  1674. WHERE site = #{site}
  1675. AND BuNo = #{buNo}
  1676. AND package_type = #{packageType}
  1677. </update>
  1678. <!-- 更新物料的packageNo -->
  1679. <update id="updatePartPackageNo">
  1680. UPDATE part
  1681. SET packageNo = #{packageNo}
  1682. WHERE site = #{site}
  1683. AND part_no = #{partNo}
  1684. </update>
  1685. <!-- ============================================= -->
  1686. <!-- UPC导入相关SQL -->
  1687. <!-- ============================================= -->
  1688. <!-- 批量插入UPC导入数据 -->
  1689. <insert id="batchInsertUpcImportData">
  1690. INSERT INTO ecss_del_upc_import (
  1691. site,
  1692. cmc_invoice,
  1693. carton_no,
  1694. so,
  1695. pn,
  1696. description,
  1697. upc,
  1698. qty,
  1699. import_batch,
  1700. import_date,
  1701. import_by,
  1702. created_by,
  1703. created_date,
  1704. is_deleted
  1705. ) VALUES
  1706. <foreach collection="list" item="item" separator=",">
  1707. (
  1708. #{item.site},
  1709. #{item.cmcInvoice},
  1710. #{item.cartonNo},
  1711. #{item.so},
  1712. #{item.pn},
  1713. #{item.description},
  1714. #{item.upc},
  1715. #{item.qty},
  1716. #{item.importBatch},
  1717. #{item.importDate},
  1718. #{item.importBy},
  1719. #{item.createdBy},
  1720. #{item.createdDate},
  1721. '0'
  1722. )
  1723. </foreach>
  1724. </insert>
  1725. <!-- 根据发票号查询UPC导入数据 -->
  1726. <select id="selectUpcImportByCmcInvoice" resultType="EcssDelUpcImport">
  1727. SELECT
  1728. site,
  1729. cmc_invoice AS cmcInvoice,
  1730. carton_no AS cartonNo,
  1731. so,
  1732. pn,
  1733. description,
  1734. upc,
  1735. qty,
  1736. import_batch AS importBatch,
  1737. import_date AS importDate,
  1738. import_by AS importBy,
  1739. created_by AS createdBy,
  1740. created_date AS createdDate,
  1741. updated_by AS updatedBy,
  1742. updated_date AS updatedDate,
  1743. is_deleted AS isDeleted,
  1744. remark
  1745. FROM ecss_del_upc_import
  1746. WHERE site = #{site}
  1747. AND cmc_invoice = #{cmcInvoice}
  1748. ORDER BY TRY_CAST(carton_no AS INT) ASC
  1749. </select>
  1750. <!-- 根据发票号删除UPC导入数据 -->
  1751. <delete id="deleteUpcImportByCmcInvoice">
  1752. delete ecss_del_upc_import
  1753. WHERE site = #{site}
  1754. AND cmc_invoice = #{cmcInvoice}
  1755. </delete>
  1756. <!-- 进出口总表导出:条件与 searchEcssCoDelNotifyHeader 一致,按开票日期排序 -->
  1757. <select id="listImportExportSummary" resultType="EcssCoDelImportExportSummaryRow">
  1758. SELECT
  1759. a.bu_no AS buNo,
  1760. a.cmc_invoice AS cmcInvoice,
  1761. a.ready_date AS readyDate,
  1762. a.shipping_mode AS shippingMode,
  1763. a.customer_name AS ordererName,
  1764. COALESCE(
  1765. NULLIF(LTRIM(RTRIM(d.overseas_shipper)), ''),
  1766. NULLIF(LTRIM(RTRIM(a.overseasShipper)), '')
  1767. ) AS consignee,
  1768. a.Destination AS destination,
  1769. d.package_qty AS packageQty,
  1770. COALESCE(
  1771. d.box_qty,
  1772. CONVERT(INT, ROUND(ISNULL(box.sum_box_qty, 0), 0))
  1773. ) AS boxQty,
  1774. COALESCE(d.net_weight, box.sum_net_weight) AS netWeight,
  1775. ISNULL(box.sum_gross_weight, 0) + ISNULL(palWgt.sum_pallet_weight, 0) AS grossWeight,
  1776. CONVERT(DECIMAL(20, 6), ISNULL(palVol.sum_pallet_volume, 0)) AS totalVolume,
  1777. det.total_qty AS totalQty,
  1778. det.currency_code AS currencyCode,
  1779. det.total_amount AS totalAmount,
  1780. '' AS blNo,
  1781. '' AS exportDate,
  1782. '' AS customsDeclarationNo
  1783. FROM ecss_CoDelNotifyHeader a
  1784. INNER JOIN accessBu acc ON a.site = acc.site AND a.bu_no = acc.bu_no AND acc.username = #{query.username}
  1785. LEFT JOIN ecss_declaration_header d ON a.site = d.site AND a.delNo = d.delNo
  1786. LEFT JOIN (
  1787. SELECT
  1788. site,
  1789. bu_no,
  1790. delNo,
  1791. CONVERT(DECIMAL(20, 0), SUM(CASE WHEN qty > 0 THEN qty ELSE 0 END)) AS total_qty,
  1792. CONVERT(DECIMAL(20, 2), SUM(CASE WHEN qty > 0 THEN ISNULL(ttl_amount, 0) ELSE 0 END)) AS total_amount,
  1793. MAX(LEFT(LTRIM(RTRIM(currency)), 3)) AS currency_code,
  1794. MAX(NULLIF(LTRIM(RTRIM(awb_bl)), '')) AS awb_bl_max,
  1795. MAX(NULLIF(LTRIM(RTRIM(shipping_number)), '')) AS shipping_number_max
  1796. FROM ecss_CoDelNotifydetail
  1797. GROUP BY site, bu_no, delNo
  1798. ) det ON det.site = a.site AND det.bu_no = a.bu_no AND det.delNo = a.delNo
  1799. LEFT JOIN (
  1800. SELECT
  1801. site,
  1802. bu_no,
  1803. delNo,
  1804. SUM(ISNULL(box_qty, 0)) AS sum_box_qty,
  1805. SUM(ISNULL(net_weight, 0)) AS sum_net_weight,
  1806. SUM(ISNULL(gross_weight, 0)) AS sum_gross_weight
  1807. FROM ecss_CoDelBoxList
  1808. GROUP BY site, bu_no, delNo
  1809. ) box ON box.site = a.site AND box.bu_no = a.bu_no AND box.delNo = a.delNo
  1810. LEFT JOIN (
  1811. SELECT
  1812. site,
  1813. bu_no,
  1814. delNo,
  1815. SUM(ISNULL(volume, 0)) AS sum_pallet_volume
  1816. FROM ecss_CoDelPalletHeader
  1817. GROUP BY site, bu_no, delNo
  1818. ) palVol ON palVol.site = a.site AND palVol.bu_no = a.bu_no AND palVol.delNo = a.delNo
  1819. LEFT JOIN (
  1820. SELECT
  1821. h.site,
  1822. h.bu_no,
  1823. h.delNo,
  1824. SUM(ISNULL(p.pallet_weight, 0) * ISNULL(h.pallet_qty, 0)) AS sum_pallet_weight
  1825. FROM ecss_CoDelPalletHeader h
  1826. LEFT JOIN (
  1827. SELECT Site, BuNo, pallet_no, MAX(pallet_weight) AS pallet_weight
  1828. FROM ecss_pallet
  1829. GROUP BY Site, BuNo, pallet_no
  1830. ) p ON h.pallet = p.pallet_no AND h.site = p.Site AND h.bu_no = p.BuNo
  1831. GROUP BY h.site, h.bu_no, h.delNo
  1832. ) palWgt ON palWgt.site = a.site AND palWgt.bu_no = a.bu_no AND palWgt.delNo = a.delNo
  1833. <where>
  1834. <if test="query.buNo != null and query.buNo != ''">
  1835. AND a.bu_no = #{query.buNo}
  1836. </if>
  1837. <if test="query.delNo != null and query.delNo != ''">
  1838. AND a.delNo LIKE #{query.delNo}
  1839. </if>
  1840. <if test="query.cmcInvoice != null and query.cmcInvoice != ''">
  1841. AND a.cmc_invoice LIKE #{query.cmcInvoice}
  1842. </if>
  1843. <if test="query.notifyStatus != null and query.notifyStatus != ''">
  1844. AND a.notify_status = #{query.notifyStatus}
  1845. </if>
  1846. <if test="query.fscFlag == 'true'">
  1847. AND a.fscFlag = 'Y'
  1848. </if>
  1849. <if test="query.boxSizeFlag == 'true'">
  1850. AND a.boxSizeFlag = 'Y'
  1851. </if>
  1852. <if test="query.walMartOrderFlag == 'true'">
  1853. AND a.walMartOrderFlag = 'Y'
  1854. </if>
  1855. <if test="query.startDate != null">
  1856. AND a.ready_date &gt;= #{query.startDate}
  1857. </if>
  1858. <if test="query.endDate != null">
  1859. AND #{query.endDate} &gt;= a.ready_date
  1860. </if>
  1861. <if test="query.modifyData == 'true'">
  1862. AND a.modifyFlag = 1
  1863. </if>
  1864. </where>
  1865. ORDER BY
  1866. CASE WHEN a.ready_date IS NULL THEN 1 ELSE 0 END,
  1867. a.ready_date ASC,
  1868. a.cmc_invoice ASC
  1869. </select>
  1870. <!-- FSC产品销售统计导出:只统计 palletDetail.fsc_weight 有值的数据,按 CMC Invoice + CustomerPO 分组 -->
  1871. <select id="listFscSalesSummary" resultType="EcssCoDelFscSalesSummaryRow">
  1872. SELECT
  1873. N'电子标签' AS productName,
  1874. CONVERT(DECIMAL(20, 2), SUM(ISNULL(p.fsc_weight_sum, 0))) AS weightKgs,
  1875. N'FSC MIX CREDIT' AS fscStatement,
  1876. CONVERT(DECIMAL(20, 0), SUM(CASE WHEN d.qty &gt; 0 THEN d.qty ELSE 0 END)) AS qtyPcs,
  1877. MAX(a.customer_name) AS customerName,
  1878. a.cmc_invoice AS cmcInvoice,
  1879. MAX(a.ready_date) AS invoiceDate,
  1880. NULLIF(LTRIM(RTRIM(d.customerPO)), '') AS customerPo
  1881. FROM ecss_CoDelNotifyHeader a
  1882. INNER JOIN ecss_CoDelNotifyDetail d ON d.site = a.site AND d.bu_no = a.bu_no AND d.delNo = a.delNo
  1883. INNER JOIN (
  1884. SELECT
  1885. site,
  1886. bu_no,
  1887. delNo,
  1888. notify_detail_item_no,
  1889. SUM(ISNULL(fsc_weight, 0)) AS fsc_weight_sum
  1890. FROM ecss_CoDelPalletDetail
  1891. WHERE fsc_weight IS NOT NULL
  1892. GROUP BY site, bu_no, delNo, notify_detail_item_no
  1893. ) p ON p.site = d.site
  1894. AND p.bu_no = d.bu_no
  1895. AND p.delNo = d.delNo
  1896. AND p.notify_detail_item_no = d.item_no
  1897. <where>
  1898. <if test="query.buNo != null and query.buNo != ''">
  1899. AND a.bu_no = #{query.buNo}
  1900. </if>
  1901. <if test="query.delNo != null and query.delNo != ''">
  1902. AND a.delNo LIKE #{query.delNo}
  1903. </if>
  1904. <if test="query.cmcInvoice != null and query.cmcInvoice != ''">
  1905. AND a.cmc_invoice LIKE #{query.cmcInvoice}
  1906. </if>
  1907. <if test="query.notifyStatus != null and query.notifyStatus != ''">
  1908. AND a.notify_status = #{query.notifyStatus}
  1909. </if>
  1910. <if test="query.fscFlag == 'true'">
  1911. AND a.fscFlag = 'Y'
  1912. </if>
  1913. <if test="query.boxSizeFlag == 'true'">
  1914. AND a.boxSizeFlag = 'Y'
  1915. </if>
  1916. <if test="query.walMartOrderFlag == 'true'">
  1917. AND a.walMartOrderFlag = 'Y'
  1918. </if>
  1919. <if test="query.startDate != null">
  1920. AND a.ready_date &gt;= #{query.startDate}
  1921. </if>
  1922. <if test="query.endDate != null">
  1923. AND #{query.endDate} &gt;= a.ready_date
  1924. </if>
  1925. <if test="query.modifyData == 'true'">
  1926. AND a.modifyFlag = 1
  1927. </if>
  1928. AND d.qty &gt; 0
  1929. </where>
  1930. GROUP BY a.cmc_invoice, NULLIF(LTRIM(RTRIM(d.customerPO)), '')
  1931. ORDER BY
  1932. CASE WHEN MAX(a.ready_date) IS NULL THEN 1 ELSE 0 END,
  1933. MAX(a.ready_date) ASC,
  1934. a.cmc_invoice ASC,
  1935. NULLIF(LTRIM(RTRIM(d.customerPO)), '') ASC
  1936. </select>
  1937. <!-- FSC年度购销平衡表导出:只统计 palletDetail.fsc_weight 有值的数据,按 part.spec 分组 -->
  1938. <select id="listFscAnnualBalance" resultType="EcssCoDelFscAnnualBalanceRow">
  1939. SELECT
  1940. ISNULL(NULLIF(LTRIM(RTRIM(pt.spec)), ''), N'未维护') AS categoryCode,
  1941. CONVERT(DECIMAL(20, 0), SUM(CASE WHEN d.qty &gt; 0 THEN d.qty ELSE 0 END)) AS qtyPcs
  1942. FROM ecss_CoDelNotifyHeader a
  1943. INNER JOIN ecss_CoDelNotifyDetail d ON d.site = a.site AND d.bu_no = a.bu_no AND d.delNo = a.delNo
  1944. LEFT JOIN part pt ON d.site = pt.site AND d.part_no = pt.part_no
  1945. INNER JOIN (
  1946. SELECT
  1947. site,
  1948. bu_no,
  1949. delNo,
  1950. notify_detail_item_no
  1951. FROM ecss_CoDelPalletDetail
  1952. WHERE fsc_weight IS NOT NULL
  1953. GROUP BY site, bu_no, delNo, notify_detail_item_no
  1954. ) p ON p.site = d.site
  1955. AND p.bu_no = d.bu_no
  1956. AND p.delNo = d.delNo
  1957. AND p.notify_detail_item_no = d.item_no
  1958. <where>
  1959. <if test="query.buNo != null and query.buNo != ''">
  1960. AND a.bu_no = #{query.buNo}
  1961. </if>
  1962. <if test="query.delNo != null and query.delNo != ''">
  1963. AND a.delNo LIKE #{query.delNo}
  1964. </if>
  1965. <if test="query.cmcInvoice != null and query.cmcInvoice != ''">
  1966. AND a.cmc_invoice LIKE #{query.cmcInvoice}
  1967. </if>
  1968. <if test="query.notifyStatus != null and query.notifyStatus != ''">
  1969. AND a.notify_status = #{query.notifyStatus}
  1970. </if>
  1971. <if test="query.fscFlag == 'true'">
  1972. AND a.fscFlag = 'Y'
  1973. </if>
  1974. <if test="query.boxSizeFlag == 'true'">
  1975. AND a.boxSizeFlag = 'Y'
  1976. </if>
  1977. <if test="query.walMartOrderFlag == 'true'">
  1978. AND a.walMartOrderFlag = 'Y'
  1979. </if>
  1980. <if test="query.startDate != null">
  1981. AND a.ready_date &gt;= #{query.startDate}
  1982. </if>
  1983. <if test="query.endDate != null">
  1984. AND #{query.endDate} &gt;= a.ready_date
  1985. </if>
  1986. <if test="query.modifyData == 'true'">
  1987. AND a.modifyFlag = 1
  1988. </if>
  1989. AND d.qty &gt; 0
  1990. </where>
  1991. GROUP BY ISNULL(NULLIF(LTRIM(RTRIM(pt.spec)), ''), N'未维护')
  1992. ORDER BY ISNULL(NULLIF(LTRIM(RTRIM(pt.spec)), ''), N'未维护')
  1993. </select>
  1994. <select id="listPartMaterialArchive" resultType="java.util.Map">
  1995. SELECT
  1996. a.site AS site,
  1997. a.sourceBu AS buNo,
  1998. dbo.get_bu_desc(a.site, a.sourceBu) AS buDesc,
  1999. a.part_no AS partNo,
  2000. a.sku AS sku,
  2001. a.spec AS spec,
  2002. a.part_desce_en AS partDesceEn,
  2003. a.cinvcname AS cinvcname,
  2004. a.qty_roll AS qtyRoll,
  2005. a.qty_box_roll AS qtyBoxRoll,
  2006. a.packageNo AS packageNo,
  2007. a.box_length AS boxLength,
  2008. a.box_width AS boxWidth,
  2009. a.box_height AS boxHeight,
  2010. a.DefaultWarehouseName AS defaultWarehouseName,
  2011. rollWeight.num_value AS rollWeight,
  2012. boxWeight.num_value AS boxWeight
  2013. FROM part a
  2014. LEFT JOIN part_sub_properties_value rollWeight
  2015. ON a.site = rollWeight.site
  2016. AND a.sourceBu = rollWeight.bu_no
  2017. AND a.part_no = rollWeight.part_no
  2018. AND rollWeight.record_type = 'ECSSPART'
  2019. AND rollWeight.code_no = 'BG001'
  2020. AND rollWeight.properties_item_no = 'ROLLWEIGHT'
  2021. LEFT JOIN part_sub_properties_value boxWeight
  2022. ON a.site = boxWeight.site
  2023. AND a.sourceBu = boxWeight.bu_no
  2024. AND a.part_no = boxWeight.part_no
  2025. AND boxWeight.record_type = 'ECSSPART'
  2026. AND boxWeight.code_no = 'BG001'
  2027. AND boxWeight.properties_item_no = 'BOXWEIGHT'
  2028. <where>
  2029. (a.site + '-' + a.sourceBu) in (select * from dbo.query_bu(#{query.userName}))
  2030. AND ISNULL(a.DefaultWarehouseName, '') like '%成品仓库%'
  2031. <if test="query.buNo != null and query.buNo != ''">
  2032. AND a.sourceBu = #{query.buNo}
  2033. AND a.DefaultWarehouseName = dbo.get_bu_desc(a.site, a.sourceBu) + '成品仓库'
  2034. </if>
  2035. <if test = "query.partNo != null and query.partNo != ''">
  2036. AND a.part_no like '%' + #{query.partNo} + '%'
  2037. </if>
  2038. <if test = "query.partDesc != null and query.partDesc != ''">
  2039. AND a.part_desc like '%' + #{query.partDesc} + '%'
  2040. </if>
  2041. <if test = "query.hsCodeDesc != null and query.hsCodeDesc != ''">
  2042. AND a.hsCodeDesc like '%' + #{query.hsCodeDesc} + '%'
  2043. </if>
  2044. <if test = "query.sku != null and query.sku != ''">
  2045. AND a.sku like '%' + #{query.sku} + '%'
  2046. </if>
  2047. <if test="query.startDate != null">
  2048. AND a.creation_date &gt;= #{query.startDate}
  2049. </if>
  2050. <if test="query.endDate != null">
  2051. AND #{query.endDate} &gt;= a.creation_date
  2052. </if>
  2053. </where>
  2054. ORDER BY dbo.get_bu_desc(a.site, a.sourceBu), a.part_no
  2055. </select>
  2056. </mapper>