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.
 
 
 
 
 
 

1508 lines
73 KiB

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xujie.sys.modules.ecss.mapper.CoDelMapper">
<select id="searchEcssCoDelNotifyHeader" resultType="EcssCoDelNotifyHeaderData">
select a.site,a.bu_no,a.delNo,a.erp_delNo,a.ready_date,a.notifyDate,a.customer_name,a.Destination,a.shipping_mode,a.erp_flag,
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.modifyFlag,a.modify_count as modifyCount,a.overseasShipper,a.overseasAddress,a.cnative,a.localShipAddress,a.walMartOrderFlag,a.fscFlag
from ecss_CoDelNotifyHeader a
left join accessBu D on A.site=D.site and A.bu_no=d.bu_no and D.username=#{query.username}
<where>
and D.site is not null
<if test="query.buNo != null and query.buNo != ''">
AND a.bu_no = #{query.buNo}
</if>
<if test="query.delNo != null and query.delNo != ''">
AND a.delNo like #{query.delNo}
</if>
<if test="query.cmcInvoice != null and query.cmcInvoice != ''">
AND a.cmc_invoice like #{query.cmcInvoice}
</if>
<if test="query.notifyStatus != null and query.notifyStatus != ''">
AND a.notify_status = #{query.notifyStatus}
</if>
<if test="query.fscFlag == 'true'">
AND a.fscFlag = 'Y'
</if>
<if test="query.walMartOrderFlag == 'true'">
AND a.walMartOrderFlag = 'Y'
</if>
<if test = "query.startDate!= null">
AND a.ready_date>= #{query.startDate}
</if>
<if test = "query.endDate!= null">
AND #{query.endDate} >=a.ready_date
</if>
<if test="query.modifyData == 'true'">
and a.modifyFlag=1
</if>
</where>
order by a.createDate desc ,a.delNo desc
</select>
<select id="searchEcssCoDelNotifyHeaderForCK" resultType="EcssCoDelNotifyHeaderData">
select a.site,a.bu_no,a.delNo,a.erp_delNo,a.ready_date,a.notifyDate,a.customer_name,a.Destination,a.shipping_mode,a.erp_flag,
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,
a.modifyFlag,a.modify_count as modifyCount,ISNULL(a.export_flag,'N') as exportFlag,a.fscFlag
from ecss_CoDelNotifyHeader a
left join accessBu D on A.site=D.site and A.bu_no=d.bu_no and D.username=#{query.username}
<where>
and D.site is not null
<if test="query.buNo != null and query.buNo != ''">
AND a.bu_no = #{query.buNo}
</if>
<if test="query.delNo != null and query.delNo != ''">
AND a.delNo like #{query.delNo}
</if>
<if test="query.cmcInvoice != null and query.cmcInvoice != ''">
AND a.cmc_invoice like #{query.cmcInvoice}
</if>
<if test="query.notifyStatus != null and query.notifyStatus != ''">
AND a.notify_status = #{query.notifyStatus}
</if>
AND a.notify_status != '已计划'
<if test = "query.startDate!= null">
AND a.ready_date>= #{query.startDate}
</if>
<if test = "query.endDate!= null">
AND #{query.endDate} >=a.ready_date
</if>
<if test="query.modifyData == 'true'">
and a.modifyFlag=1
</if>
<if test="query.exportFlag != null and query.exportFlag != ''">
and ISNULL(a.export_flag,'N') = #{query.exportFlag}
</if>
</where>
order by a.createDate desc ,a.delNo desc
</select>
<select id="searchEcssCoDelNotifyHeaderForDanZheng" resultType="EcssCoDelNotifyHeaderData">
select a.site,a.bu_no,a.delNo,a.erp_delNo,a.ready_date,a.notifyDate,a.customer_name,a.Destination,a.shipping_mode,a.erp_flag,
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
from ecss_CoDelNotifyHeader a
left join accessBu D on A.site=D.site and A.bu_no=d.bu_no and D.username=#{query.username}
<where>
and D.site is not null
<if test="query.buNo != null and query.buNo != ''">
AND a.bu_no = #{query.buNo}
</if>
<if test="query.delNo != null and query.delNo != ''">
AND a.delNo like #{query.delNo}
</if>
<if test="query.cmcInvoice != null and query.cmcInvoice != ''">
AND a.cmc_invoice like #{query.cmcInvoice}
</if>
<if test="query.notifyStatus != null and query.notifyStatus != ''">
AND a.notify_status = #{query.notifyStatus}
</if>
AND a.notify_status = '仓库已确认'
<if test = "query.startDate!= null">
AND a.ready_date>= #{query.startDate}
</if>
<if test = "query.endDate!= null">
AND #{query.endDate} >=a.ready_date
</if>
<if test="query.walMartOrderFlag == 'true'">
AND a.walMartOrderFlag = 'Y'
</if>
<if test="query.walMartOrderFlag == null or query.walMartOrderFlag == '' or query.walMartOrderFlag == 'false'">
AND (a.walMartOrderFlag is null or a.walMartOrderFlag != 'Y')
</if>
</where>
order by a.createDate desc ,a.delNo desc
</select>
<select id="checkEcssCoDelNotifyHeaderByDelNo" resultType="EcssCoDelNotifyHeaderData">
select a.site,a.bu_no,a.delNo,a.erp_delNo,a.ready_date,a.notifyDate,a.customer_name,a.Destination,a.shipping_mode,a.erp_flag,
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.overseasShipper,a.overseasAddress,a.cnative,a.localShipAddress,a.salesArea
from ecss_CoDelNotifyHeader a
where a.site = #{site}
AND a.delNo = #{delNo}
</select>
<select id="searchEcssCoDelNotifyDetail" resultType="EcssCoDelNotifyDetailData">
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,
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,
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,
c.num_value as boxrolls,d.num_value as rollqty,w.num_value as boxweight,#{cmcInvoice} as cmcInvoice,a.modifyFlag,a.modifyQtyFlag,
b.hsCodeDesc,a.vat,a.roll,a.carton,b.packageNo,a.qty_roll as qtyRoll,a.qty_box as qtyBox
from ecss_CoDelNotifydetail a
left join part b on a.site=b.site and a.part_no=b.part_no
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
and c.record_type='ECSSPART' and c.code_no='BG001' and c.properties_item_no='BOXROLLS'
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
and d.record_type='ECSSPART' and d.code_no='BG001' and d.properties_item_no='ROLLQTY'
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
and w.record_type='ECSSPART' and w.code_no='BG001' and w.properties_item_no='BOXWEIGHT'
<where>
And a.site = #{site}
AND a.delNo = #{delNo}
</where>
order by a.item_no
</select>
<select id="getEcssCoDelNotifyDetail" resultType="EcssCoDelNotifyDetailData">
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,
a.part_no,a.part_description,a.qty,a.lt,a.cmc_comment,a.saleType,a.awb_bl,a.shipping_number,a.forwarder_info,
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,
a.modifyFlag,a.modifyQtyFlag
from ecss_CoDelNotifydetail a
<where>
And a.site = #{site}
AND a.delNo = #{delNo}
AND a.item_no = #{itemNo} and a.qty>0
</where>
</select>
<select id="getSiteByBu" resultType="String">
select top 1 site from BU where bu_no=#{buNo}
</select>
<select id="checkIfHasHeader" resultType="EcssCoDelNotifyHeaderData">
select top 1 * from ecss_CoDelNotifyHeader where cmc_invoice=#{inVoice}
</select>
<update id="updateTransNo" >
EXEC UpdateTransNo #{site}, #{transType}
</update>
<select id="getTransNo" resultType="String">
SELECT
dbo.Get_TransNo(#{site},#{transType}) as transNo
</select>
<insert id="saveEcssCoDelNotifyHeader" >
insert into ecss_CoDelNotifyHeader(site,bu_no,delNo,ready_date,customer_name,Destination,shipping_mode,erp_flag,notify_status,
remark,createDate,createBy,cmc_invoice,overseasShipper,overseasAddress,cnative,localShipAddress,salesArea)
values(#{site},#{buNo},#{delNo},#{readyDate},#{customerName,jdbcType=NVARCHAR},#{destination,jdbcType=NVARCHAR},#{shippingMode},'N',#{notifyStatus},#{remark,jdbcType=NVARCHAR},GetDate(),
#{createBy},#{cmcInvoice},#{overseasShipper,jdbcType=NVARCHAR},#{overseasAddress,jdbcType=NVARCHAR},#{cnative,jdbcType=NVARCHAR},#{localShipAddress,jdbcType=NVARCHAR}, #{salesArea,jdbcType=NVARCHAR})
</insert>
<insert id="batchSaveEcssCoDelNotifyDetail">
insert into ecss_CoDelNotifyDetail (site,bu_no,delNo,item_no,salesOrder,salesOrder_item_no,customerPO,line,version,
status,family,part_no,part_description,qty,lt,cmc_comment,saleType,
awb_bl,shipping_number,forwarder_info,currency,tp,ttl_amount,sum_price,
so,upc,remark,pn,surplus_qty,vat,roll,carton,saleslt,manufacturer_name,modifyFlag,modifyQtyFlag,category,qty_roll,qty_box)
values
<foreach collection="list" separator="," item="item">
(#{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},
#{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},
#{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},
#{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},
#{item.modifyFlag},#{item.modifyQtyFlag},#{item.category,jdbcType=NVARCHAR},#{item.qtyRoll,jdbcType=NVARCHAR},#{item.qtyBox,jdbcType=NVARCHAR})
</foreach>
</insert>
<select id="checkPart" resultType="PartData">
select site,part_no from Part where site=#{site,jdbcType=VARCHAR} and part_no=#{partNo}
</select>
<select id="getPartNo" resultType="PartData">
select top 1 site,part_no from Part where site=#{site,jdbcType=VARCHAR} and sku=#{partNo} and sourceBu=#{buNo} and
site in (select site from eam_access_site where username = #{userName})
and (site + '-' + sourceBu) in (select * from dbo.query_bu(#{userName}))
</select>
<select id="getPartInfo" resultType="PartData">
select * from Part where site=#{site,jdbcType=VARCHAR} and part_no=#{partNo}
</select>
<update id="updateEcssDelHeader" >
update ecss_CoDelNotifyHeader set ready_date=#{readyDate,jdbcType=TIMESTAMP} ,customer_name=#{customerName,jdbcType=NVARCHAR},
Destination=#{destination,jdbcType=NVARCHAR},shipping_mode=#{shippingMode},modifyFlag=#{modifyFlag},export_flag='N',
remark=#{remark,jdbcType=NVARCHAR} ,cmc_invoice=#{cmcInvoice},overseasShipper=#{overseasShipper,jdbcType=NVARCHAR} ,overseasAddress=#{overseasAddress,jdbcType=NVARCHAR}
where site=#{site} and delNo=#{delNo}
</update>
<delete id="deleteEcssDelHeader">
delete from ecss_CoDelNotifyHeader where site=#{site} and delNo=#{delNo}
</delete>
<update id="updateEcssDelHeaderForBaoGuan" >
update ecss_CoDelNotifyHeader set declaration_no=#{declarationNo} ,notify_status=#{status} where site=#{site} and delNo=#{delNo}
</update>
<update id="updateEcssDelHeaderForModify" >
update ecss_CoDelNotifyHeader
set modifyFlag=#{modifyFlag},
modify_count = CASE
WHEN #{modifyFlag} = 1 THEN ISNULL(modify_count, 0) + 1
ELSE 0
END
where site=#{site} and delNo=#{delNo}
</update>
<update id="updateEcssDelDetailForModify" >
update ecss_CoDelNotifyDetail set modifyFlag=#{modifyFlag},modifyQtyFlag=#{modifyFlag},surplus_qty=0 where site=#{site} and delNo=#{delNo}
</update>
<update id="updateEcssDelDetailSurplusQty" >
update ecss_CoDelNotifyDetail set surplus_qty=0 where site=#{site} and delNo=#{delNo}
</update>
<update id="changeEcssDelStatus">
update ecss_CoDelNotifyHeader set notify_status=#{notifyStatus},walMartOrderFlag=#{walMartOrderFlag},fscFlag=#{fscFlag} where site=#{site} and delNo=#{delNo}
</update>
<update id="updateEcssDelDetailStatus">
update ecss_CoDelNotifyDetail
set status=#{notifyStatus}
where site=#{site} and delNo=#{delNo}
</update>
<update id="recoverEcssDelDetailStatus">
update ecss_CoDelNotifyDetail
set status='正常'
where site=#{site} and delNo=#{delNo}
</update>
<select id="getEcssDelDetailItemNo" resultType="int">
select isnull(max(item_no),0)+1 as itemNo from ecss_CoDelNotifyDetail
where site =#{site} and bu_no=#{buNo} and delNo=#{delNo}
</select>
<insert id="insertEcssDelDetail" >
insert into ecss_CoDelNotifyDetail(site,bu_no,delNo,item_no,salesOrder,salesOrder_item_no,customerPO,line,version,
status,family,part_no,part_description,qty,lt,cmc_comment,saleType,
awb_bl,shipping_number,forwarder_info,currency,tp,ttl_amount,sum_price,
so,upc,remark,pn,modifyFlag,modifyQtyFlag,surplus_qty,vat,roll,carton)
values(#{site},#{buNo},#{delNo},#{itemNo,jdbcType=INTEGER},#{salesOrder},#{salesOrderItemNo},#{customerPO},#{line},#{version},
#{status},#{family},#{partNo},#{partDescription},#{qty,jdbcType=DECIMAL},#{lt,jdbcType=DECIMAL},#{cmcComment},#{saleType},
#{awbBl},#{shippingNumber},#{forwarderInfo},#{currency},#{tp,jdbcType=DECIMAL},#{ttlAmount,jdbcType=DECIMAL},#{sumPrice,jdbcType=DECIMAL},
#{so},#{upc},#{remark},#{pn},#{modifyFlag},#{modifyQtyFlag},#{qty},#{vat},#{roll},#{carton})
</insert>
<update id="updateEcssDelDetail">
update ecss_CoDelNotifyDetail
set salesOrder=#{salesOrder},customerPO=#{customerPO},line=#{line},version=#{version},
status=#{status},family=#{family},part_no=#{partNo},part_description=#{partDescription},qty=#{qty,jdbcType=DECIMAL},
lt=#{lt,jdbcType=DECIMAL},cmc_comment=#{cmcComment},saleType=#{saleType},pn=#{pn},
awb_bl=#{awbBl},shipping_number=#{shippingNumber},forwarder_info=#{forwarderInfo},currency=#{currency},
tp=#{tp,jdbcType=DECIMAL},ttl_amount=#{ttlAmount,jdbcType=DECIMAL},sum_price=#{sumPrice,jdbcType=DECIMAL},
so=#{so},upc=#{upc},remark=#{remark},modifyFlag=#{modifyFlag},modifyQtyFlag=#{modifyQtyFlag},surplus_qty=#{qty,jdbcType=DECIMAL},vat=#{vat},roll=#{roll},carton=#{carton}
where
site=#{site} and delNo=#{delNo} and item_no=#{itemNo}
</update>
<delete id="deleteEcssDelDetail">
delete from ecss_CoDelNotifyDetail where site=#{site} and delNo=#{delNo} and item_no=#{itemNo}
</delete>
<delete id="deleteAllEcssDelDetail">
delete from ecss_CoDelNotifyDetail where site=#{site} and delNo=#{delNo}
</delete>
<update id="confirmEcssDel">
update ecss_CoDelNotifyHeader set notify_status=#{notifyStatus} ,notifyDate=#{notifyDate,jdbcType=TIMESTAMP} where site=#{site} and delNo=#{delNo}
</update>
<update id="updateEcssDel">
update ecss_CoDelNotifyHeader set ready_date=#{readyDate,jdbcType=TIMESTAMP},notifyDate=#{notifyDate,jdbcType=TIMESTAMP},
modifyFlag=1,export_flag='N',updateBy=#{updateBy},updateDate=GetDate()
where site=#{site} and delNo=#{delNo}
</update>
<select id="searchHsCodeData" resultType="EcssHsCodeData">
select a.Site,a.BuNo,a.HsCode,a.Remark,a.CreateBy,a.CreateDate,a.UpdateBy,a.UpdateDate,a.codeNo
,dbo.get_bu_desc(a.site,a.BuNo) as BuDesc,a.hsCodeDesc,a.hsCodeDescEn,a.unit
from ecss_hsCode a
left join accessBu D on A.site=D.site and A.BuNo=d.bu_no and D.username=#{query.username}
<where>
and D.site is not null
<if test="query.buNo != null and query.buNo != ''">
AND a.BuNo = #{query.buNo}
</if>
<if test="query.hsCode != null and query.hsCode != ''">
AND a.HsCode like #{query.hsCode}
</if>
</where>
order by a.CreateDate ,a.HsCode
</select>
<select id="checkHsCodeDescData" resultType="EcssHsCodeData">
select a.Site,a.BuNo,a.HsCode,a.hsCodeDesc
from ecss_hsCode a where a.site=#{site} and a.buNo=#{buNo} and a.HsCodeDesc=#{hsCodeDesc}
</select>
<select id="checkPropertiesModel" resultType="com.xujie.sys.modules.attrbute.entity.PropertyModelHeader">
select site,bu_no,function_type ,code_no from plm_properties_model_header
where site=#{site} and bu_no=#{buNo} and function_type=#{functionType} and code_no=#{codeNo}
</select>
<insert id="insertHsCodeData" >
insert into ecss_hsCode (Site,BuNo,HsCode,Remark,CreateBy,CreateDate,codeNo,hsCodeDesc,hsCodeDescEn,unit)
values(#{site},#{buNo},#{hsCode},#{remark},#{createBy},GetDate(),#{codeNo},#{hsCodeDesc},#{hsCodeDescEn},#{unit})
</insert>
<update id="updateHsCodeData">
update ecss_hsCode set Remark=#{remark} ,codeNo=#{codeNo},HsCode=#{hsCode},unit=#{unit} ,UpdateDate=GetDate(),UpdateBy=#{updateBy},hsCodeDescEn=#{hsCodeDescEn}
where site=#{site} and buNo=#{buNo} and hsCodeDesc=#{hsCodeDesc}
</update>
<select id="deleteHsCode" >
delete from ecss_hsCode where site=#{site} and buNo=#{buNo} and hsCodeDesc=#{hsCodeDesc}
</select>
<select id="searchPropertiesItemList" resultType="com.xujie.sys.modules.attrbute.entity.PropertyItem">
select
id,site,bu_no,item_no,item_type,item_desc,default_value,value_type,value_type_db,value_choose_flag,min_value,max_value,
create_by,create_date,update_by,update_date
from dbo.plm_properties_item
<where>
and site = #{site} and bu_no=#{buNo}
<if test="itemNo != null and itemNo != ''">
and item_no like #{itemNo}
</if>
<if test="itemDesc != null and itemDesc != ''">
and item_desc like #{itemDesc}
</if>
<if test="itemType != null and itemType != ''">
and item_type = #{itemType}
</if>
order by item_type ,item_no
</where>
</select>
<select id="getPropertiesListByPartAndCodeNo" resultType="com.xujie.sys.modules.part.entity.PartSubPropertiesValueData">
SELECT a.part_no
, a.Site
, a.code_no
, a.sub_code_seq_no
, a.sub_code_desc
,a.bu_no
,a.item_no
, a.properties_item_no
, a.text_value
, a.num_value
, a.record_type
, b.item_desc ItemDesc
, b.value_type
, b.value_type_db
, b.value_choose_flag
FROM part_sub_properties_value a
left join plm_properties_item b
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
<where>
AND a.site = #{site}
and a.record_type = #{recordType}
and a.bu_no=#{buNo}
and a.code_no = #{codeNo}
AND a.part_no = #{partNo,jdbcType=VARCHAR}
</where>
order by a.item_no
</select>
<update id="updatePropertiesList">
update part_sub_properties_value
set text_value=#{textValue},
num_value=#{numValue,jdbcType=DOUBLE}
where Site = #{site}
and code_no = #{codeNo}
and part_no = #{partNo}
and sub_code_seq_no = #{subCodeSeqNo}
and item_no = #{itemNo}
and bu_no=#{buNo}
</update>
<insert id="saveSubPropertiesValueForAlone">
insert into part_sub_properties_value ( 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)
select
#{partNo},
#{site},
#{buNo},
#{codeNo},
1,
d.code_desc,
#{itemNo,jdbcType=DOUBLE},
c.item_no,
case when c.value_type_db = 'T' then c.default_value else null end,
case when c.value_type_db = 'N' and c.default_value != '' then c.default_value else null end,
#{recordType}
from plm_properties_item c
left join plm_properties_model_header d on c.site=d.site and d.code_no=#{codeNo} and d.function_type=c.item_Type
where c.Item_No = #{propertiesItemNo}
and c.site = #{site}
and c.bu_no=#{buNo}
and c.item_Type = #{recordType}
</insert>
<delete id="deleteSubPropertiesValueForAlone">
delete
from part_sub_properties_value
where site = #{site}
and record_type = #{recordType}
and bu_no=#{buNo}
and code_no = #{codeNo}
AND part_no = #{partNo,jdbcType=VARCHAR}
and properties_item_no = #{propertiesItemNo}
</delete>
<select id="getNewSeqNoForAlone" resultType="Double">
select isnull(Max(item_No) + 1, 1)
from part_sub_properties_value a
where a.site = #{site}
and a.record_type = #{recordType}
and a.bu_no=#{buNo}
and a.code_no = #{codeNo}
AND a.part_no = #{partNo,jdbcType=VARCHAR}
</select>
<select id="searchPropertiesUnChoose" resultType="com.xujie.sys.modules.ecss.entity.PropertyItemData">
SELECT
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,
b.min_value,b.max_value,b.create_by,b.create_date,b.update_by,b.update_date
FROM plm_properties_item b
where b.item_type = #{codeType}
and b.site = #{site} and b.bu_no=#{buNo}
<if test="list != null and list.size() != 0">
and b.item_no not in (
<foreach collection="list" item="item" separator=",">
#{item}
</foreach>
)
</if>
</select>
<insert id="saveCodelPalletHeader">
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,
create_date,pallet)
values(#{site},#{buNo},#{delNo},#{seqNo},#{palletNo},#{palletQty},#{length},#{width},#{height},#{volume},#{grossWeight,jdbcType=DECIMAL},#{netWeight,jdbcType=DECIMAL},#{palletRemark},#{createBy},
GETDATE(),#{pallet})
</insert>
<insert id="saveCodelBoxList">
insert into ecss_CoDelBoxList(site,bu_no,delNo,seq_no,item_no,gross_weight,net_weight,box_qty,rolls,create_by,create_date)
values (#{site},#{buNo},#{delNo},#{seqNo},#{itemNo},#{grossWeight,jdbcType=DECIMAL},#{netWeight,jdbcType=DECIMAL},#{boxQty},#{rolls,jdbcType=DECIMAL},#{createBy},GETDATE())
</insert>
<insert id="saveCodelPalletDetail">
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)
values (#{site},#{buNo},#{delNo},#{seqNo},#{itemNo},#{partNo},#{qty,jdbcType=DECIMAL},#{poNo},#{boxQty},#{createBy},GETDATE(),#{rolls,jdbcType=DECIMAL},#{pn},#{notifyDetailItemNo})
</insert>
<select id="searchEcssCoDelPalletHeaderData" resultType="EcssCoDelPalletHeaderData">
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,
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
from ecss_CoDelPalletHeader a
LEFT JOIN ecss_pallet p on a.pallet=p.pallet_no and a.site=p.Site and a.bu_no=p.BuNo
where a.site =#{site} and a.bu_no=#{buNo} and a.delNo=#{delNo}
</select>
<select id="searchEcssCoDelPalletDetailData" resultType="EcssCoDelPalletDetailData">
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
from ecss_CoDelPalletDetail
where site =#{site} and bu_no=#{buNo} and delNo=#{delNo}
<if test="seqNo != null and seqNo != ''">
and seq_no=#{seqNo}
</if>
</select>
<select id="getCoDelPalletHeaderSeqNo" resultType="int">
select isnull(max(seq_no),0)+1 as seqNo from ecss_CoDelPalletHeader
where site =#{site} and bu_no=#{buNo} and delNo=#{delNo}
</select>
<select id="getCoDelBoxListItemNo" resultType="int">
select isnull(max(item_no),0)+1 as seqNo from ecss_CoDelBoxList
where site =#{site} and bu_no=#{buNo} and delNo=#{delNo}
</select>
<select id="getCoDelPalletDetailItem" resultType="int">
select isnull(max(item_no),0)+1 as item_no from ecss_CoDelPalletDetail
where site =#{site} and bu_no=#{buNo} and delNo=#{delNo} and seq_no=#{seqNo}
</select>
<update id="updateCodelPalletHeader">
update ecss_CoDelPalletHeader set pallet_qty=#{palletQty,jdbcType=INTEGER},[length]=#{length,jdbcType=DECIMAL},width=#{width,jdbcType=DECIMAL},height=#{height,jdbcType=DECIMAL},
volume=#{volume,jdbcType=DECIMAL},gross_weight=#{grossWeight,jdbcType=DECIMAL},net_weight=#{netWeight,jdbcType=DECIMAL},pallet_remark=#{palletRemark},
update_by=#{updateBy},update_date=GetDate(),pallet=#{pallet}
where site =#{site} and bu_no=#{buNo} and delNo=#{delNo} and seq_no=#{seqNo}
</update>
<update id="updateCodelPalletHeader2">
update ecss_CoDelPalletHeader set gross_weight=#{grossWeight,jdbcType=DECIMAL},net_weight=#{netWeight,jdbcType=DECIMAL},
update_by=#{updateBy},update_date=GetDate()
where site =#{site} and bu_no=#{buNo} and delNo=#{delNo} and seq_no=#{seqNo}
</update>
<update id="updateCodelPalletHeaderPalletQty">
update ecss_CoDelPalletHeader set pallet_qty=#{palletQty,jdbcType=INTEGER},height=#{height,jdbcType=DECIMAL},
update_by=#{updateBy},update_date=GetDate()
where site =#{site} and bu_no=#{buNo} and delNo=#{delNo} and seq_no=#{seqNo}
</update>
<update id="updateCodelPalletDetail">
update ecss_CoDelPalletDetail set part_no=#{partNo},qty=#{qty,jdbcType=DECIMAL},po_no=#{poNo},
box_qty=#{boxQty,jdbcType=DECIMAL},update_by=#{updateBy},update_date=GetDate(),rolls=#{rolls},pn=#{pn}
where site =#{site} and bu_no=#{buNo} and delNo=#{delNo} and seq_no=#{seqNo} and item_no=#{itemNo}
</update>
<delete id="deletePalletHeader">
delete from ecss_CoDelPalletHeader where site =#{site} and bu_no=#{buNo} and delNo=#{delNo}
<if test="seqNo != null and seqNo != ''">
and seq_no=#{seqNo}
</if>
</delete>
<delete id="deleteBoxList">
delete from ecss_CoDelBoxList where site =#{site} and bu_no=#{buNo} and delNo=#{delNo}
<if test="seqNo != null and seqNo != ''">
and seq_no=#{seqNo}
</if>
</delete>
<delete id="deletePalletDetail">
delete from ecss_CoDelPalletDetail where site =#{site} and bu_no=#{buNo} and delNo=#{delNo}
<if test="seqNo != null and seqNo != ''">
and seq_no=#{seqNo}
</if>
<if test="itemNo != null and itemNo != ''">
and item_no=#{itemNo}
</if>
</delete>
<select id="getAllWeight" resultType="com.xujie.sys.modules.ecss.entity.EcssCoDelPalletHeader">
select sum(gross_weight) as gross_weight ,sum(net_weight) as net_weight from ecss_CoDelBoxList
where site =#{site} and delNo=#{delNo} and bu_no=#{buNo}
</select>
<select id="getDefaultEcssDeclarationDetailData" resultType="EcssDeclarationDetailData">
-- 修复净重计算问题:按数量比例分配箱子净重,避免重复计算
-- 一个箱子(BoxList)可能包含多个零件(PalletDetail),这些零件可能有相同的hsCode
-- 需要按每个零件的数量占该箱子总数量的比例来分配净重
WITH BoxDetail AS (
-- 计算每个箱子中每个零件的数量及其占比
SELECT
d.site,
d.bu_no,
d.delNo,
d.seq_no,
p.hsCode,
p.hsCodeDesc,
d.qty,
b.net_weight,
-- 计算该零件数量占该箱子总数量的比例
CASE
WHEN SUM(d.qty) OVER (PARTITION BY d.site, d.bu_no, d.delNo, d.seq_no) > 0
THEN d.qty * 1.0 / SUM(d.qty) OVER (PARTITION BY d.site, d.bu_no, d.delNo, d.seq_no)
ELSE 0
END as qtyRatio
FROM ecss_CoDelPalletDetail d
LEFT JOIN part p ON d.site=p.site AND d.part_no=p.part_no
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
WHERE d.site=#{site} AND d.delNo=#{delNo} AND d.bu_no=#{buNo}
)
SELECT
#{site} as site,
hsCode,
hsCodeDesc,
SUM(qty) as qty,
-- 按数量比例分配净重后汇总
CONVERT(DECIMAL(20,2), SUM(ISNULL(net_weight, 0) * qtyRatio)) as NetWeight,
'CNY' as currency,
'中国' as madeArea,
#{destination} as destination,
'南通其他' as sourceArea,
'照章征免' as levy
FROM BoxDetail
GROUP BY hsCode, hsCodeDesc
</select>
<select id="getDefaultEcssDeclarationDetailData2" resultType="EcssDeclarationDetailData">
select #{site} as site, b.hsCode,b.hsCodeDesc as hsCodeDesc,sum( a.qty) as qty ,sum(a.ttl_amount) as totalPrice,
CONVERT(DECIMAL(20, 6),sum(a.ttl_amount)/sum( a.qty)) as unitPrice,
LEFT(a.currency, 3) AS currency,'中国' as madeArea,#{destination} as destination,'南通其他' as sourceArea ,'照章征免' as levy from
ecss_CoDelNotifyDetail a left join part b on a.site=b.site and a.part_no=b.part_no
where a.site =#{site} and a.delNo=#{delNo} and a.qty>0 and a.bu_no=#{buNo}
GROUP BY b.hsCodeDesc,b.hsCode,LEFT(a.currency,3)
</select>
<insert id="saveEcssDeclarationHeader">
insert into ecss_declaration_header (site,declaration_no,customs_office_code,input_code,local_shipper,local_ship_address,ship_type,ship_date,submit_date,
filing_no,overseas_shipper,shipping_mode,shipping_data,deliver_no,sales_partner,regulatory_method,duty_status,
permit_number,cmc_invoice,sales_area,receive_area,shipping_port,exit_port,documents,remark,package_type,package_qty,
gross_weight,net_weight,payment_type,ship_price,premium,other_price,special_relationship_comfirm,price_influence_confirm,
royalty_payments_confirm,create_by,create_date,delNo,overseas_address,box_qty)
values(#{site},#{declarationNo},#{customsOfficeCode},#{inputCode},#{localShipper,jdbcType=NVARCHAR},#{localShipAddress,jdbcType=NVARCHAR},#{shipType},#{shipDate},#{submitDate},
#{filingNo},#{overseasShipper,jdbcType=NVARCHAR},#{shippingMode,jdbcType=NVARCHAR},#{shippingData},#{deliverNo},#{salesPartner,jdbcType=NVARCHAR},#{regulatoryMethod,jdbcType=NVARCHAR},#{dutyStatus,jdbcType=NVARCHAR},
#{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},
#{grossWeight,jdbcType=DECIMAL},#{netWeight,jdbcType=DECIMAL},#{paymentType,jdbcType=NVARCHAR},#{shipPrice,jdbcType=DECIMAL},#{premium,jdbcType=DECIMAL},#{otherPrice,jdbcType=DECIMAL},#{specialRelationshipComfirm,jdbcType=NVARCHAR},#{priceInfluenceConfirm,jdbcType=NVARCHAR},
#{royaltyPaymentsConfirm,jdbcType=NVARCHAR},#{createBy},GETDATE(),#{delNo},#{overseasAddress,jdbcType=NVARCHAR},#{boxQty})
</insert>
<insert id="saveEcssDeclarationDetail">
insert into ecss_declaration_detail(site,declaration_no,item_no,hs_code,hs_code_desc,qty,net_weight,unit_price,total_price,currency,made_area,destination,
source_area,levy)
values(#{site},#{declarationNo},#{itemNo,jdbcType=INTEGER},#{hsCode},#{hsCodeDesc},#{qty,jdbcType=DECIMAL},#{netWeight,jdbcType=DECIMAL},#{unitPrice,jdbcType=DECIMAL},#{totalPrice,jdbcType=DECIMAL},#{currency},#{madeArea},#{destination},
#{sourceArea},#{levy})
</insert>
<select id="searchDeclarationHeader" resultType="EcssDeclarationHeaderData">
select a.site,a.declaration_no,a.customs_office_code,a.input_code,a.local_shipper,a.local_ship_address,a.ship_type,
a.ship_date,a.submit_date,a.filing_no,a.overseas_shipper,a.shipping_mode,a.shipping_data,a.deliver_no,a.sales_partner,
a.regulatory_method,a.duty_status,a.permit_number,a.cmc_invoice,a.sales_area,a.receive_area,a.shipping_port,
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,
a.premium,a.other_price,a.special_relationship_comfirm,a.price_influence_confirm,a.royalty_payments_confirm,
a.create_by,a.create_date,a.update_by,a.update_date,a.delNo,noHeader.bu_no,
a.upc,a.so,a.origin,a.pallet_weight,a.material,a.hs_code,a.packaging,a.kgs,a.shipping_mark,
a.hsCodeDesc,a.contractFlag,a.hsCodeDescType,a.goodsLabel,a.boxChange,noHeader.customer_name as customName,
noHeader.destination
from ecss_declaration_header a
left join ecss_CoDelNotifyHeader noHeader on a.site=noHeader.site and a.delNo=noHeader.delNo
<where>
<if test="query.delNo != null and query.delNo != ''">
AND a.delNo like #{query.delNo}
</if>
<if test="query.declarationNo != null and query.declarationNo != ''">
AND a.declaration_no like #{query.declarationNo}
</if>
<if test="query.cmcInvoice != null and query.cmcInvoice != ''">
AND a.cmc_invoice like #{query.cmcInvoice}
</if>
<if test="query.site != null and query.site != ''">
AND a.site like #{query.site}
</if>
<if test = "query.startDate!= null">
AND a.ship_date>= #{query.startDate}
</if>
<if test = "query.endDate!= null">
AND #{query.endDate} >=a.ship_date
</if>
</where>
order by a.create_date desc
</select>
<select id="searchDeclarationDetail" resultType="EcssDeclarationDetailData">
select site,declaration_no,item_no,hs_code,hs_code_desc,qty,net_weight,unit_price,total_price,currency,made_area,destination,
source_area,levy
from ecss_declaration_detail
where site=#{site} and declaration_no=#{declarationNo}
</select>
<delete id="deleteDeclarationHeader">
delete from ecss_declaration_header where site=#{site} and declaration_no=#{declarationNo}
</delete>
<delete id="deleteDeclarationDetail">
delete from ecss_declaration_detail where site=#{site} and declaration_no=#{declarationNo}
</delete>
<select id="searchPalletData" resultType="EcssPalletData">
select a.id,a.Site,a.BuNo,a.pallet_type as palletType,a.Remark,a.CreateBy,a.CreateDate,a.UpdateBy,a.UpdateDate,
a.length, a.width, a.height, a.application_area as applicationArea, a.pallet_weight as palletWeight
,dbo.get_bu_desc(a.site,a.BuNo) as BuDesc,a.pallet_no as palletNo
from ecss_pallet a
left join accessBu D on A.site=D.site and A.BuNo=d.bu_no and D.username=#{query.username}
<where>
and D.site is not null
<if test="query.buNo != null and query.buNo != ''">
AND a.BuNo = #{query.buNo}
</if>
<if test="query.palletType != null and query.palletType != ''">
AND a.pallet_type = #{query.palletType}
</if>
</where>
order by a.CreateDate
</select>
<insert id="insertPalletData" >
insert into ecss_pallet (Site,BuNo,pallet_type,Remark,CreateBy,CreateDate,length,width,
height,application_area,pallet_weight,pallet_no)
values(#{site},#{buNo},#{palletType},#{remark},#{createBy},GetDate(),#{length},#{width},
#{height},#{applicationArea},#{palletWeight},#{palletNo})
</insert>
<update id="updatePalletData">
update ecss_pallet set Remark=#{remark} ,pallet_type=#{palletType} ,
length=#{length} ,width=#{width} ,
height=#{height} ,application_area=#{applicationArea} ,
pallet_weight=#{palletWeight} ,pallet_no=#{palletNo},
UpdateDate=GetDate(),UpdateBy=#{updateBy}
where site=#{site} and buNo=#{buNo} and id=#{id}
</update>
<select id="deletePallet" >
delete from ecss_pallet where site=#{site} and buNo=#{buNo} and id=#{id}
</select>
<select id="getPallet" resultType="EcssPalletData">
select * from ecss_pallet where site=#{site} and buNo=#{buNo} and pallet_no=#{palletNo}
</select>
<select id="getPackage" resultType="EcssPackageData">
select * from ecss_package where site=#{site} and buNo=#{buNo} and package_no=#{packageNo}
</select>
<insert id="insertPackageData" >
insert into ecss_package (Site,BuNo,package_type,Remark,CreateBy,CreateDate,length,width,
height,volume,weight,package_no)
values(#{site},#{buNo},#{packageType},#{remark},#{createBy},GetDate(),#{length},#{width},
#{height},#{volume},#{weight},#{packageNo})
</insert>
<update id="updatePackageData">
update ecss_package set Remark=#{remark} ,package_type=#{packageType} ,
length=#{length} ,width=#{width} ,volume=#{volume},weight=#{weight},
package_no=#{packageNo},height=#{height} ,
UpdateDate=GetDate(),UpdateBy=#{updateBy}
where site=#{site} and buNo=#{buNo} and id=#{id}
</update>
<select id="deleteEcssPackage" >
delete from ecss_package where site=#{site} and buNo=#{buNo} and id=#{id}
</select>
<select id="searchPackageData" resultType="EcssPackageData">
select a.id,a.Site,a.BuNo,a.package_type as packageType,a.Remark,a.CreateBy,a.CreateDate,a.UpdateBy,a.UpdateDate,
a.length, a.width, a.height, a.volume, a.weight,a.package_no as packageNo
,dbo.get_bu_desc(a.site,a.BuNo) as BuDesc
from ecss_package a
left join accessBu D on A.site=D.site and A.BuNo=d.bu_no and D.username=#{query.username}
<where>
and D.site is not null
<if test="query.buNo != null and query.buNo != ''">
AND a.BuNo = #{query.buNo}
</if>
<if test="query.packageType != null and query.packageType != ''">
AND a.package_type = #{query.packageType}
</if>
</where>
order by a.CreateDate
</select>
<select id="searchHsCodeList" resultType="java.util.Map">
select a.BuNo,a.HsCode,a.hsCodeDesc,a.unit,a.hsCodeDescEn
from ecss_hsCode a
<where> a.BuNo = #{buNo}
<if test="hsCode != null and hsCode != ''">
AND a.HsCode like '%'+#{hsCode}+'%'
</if>
<if test="hsCodeDesc != null and hsCodeDesc != ''">
AND a.hsCodeDesc like '%'+#{hsCodeDesc}+'%'
</if>
</where>
order by a.CreateDate ,a.HsCode
</select>
<select id="searchPalletList" resultType="java.util.Map">
select a.BuNo,a.id as palletId,a.pallet_type as palletType,a.pallet_no as palletNo,
a.application_area as applicationArea ,a.length, a.width, a.height
from ecss_pallet a
<where> a.BuNo = #{buNo}
<if test="palletType != null and palletType != ''">
AND a.pallet_type like '%'+#{palletType}+'%'
</if>
</where>
order by a.CreateDate
</select>
<select id="searchPackageList" resultType="java.util.Map">
select a.BuNo,a.id as packageId,a.package_type as packageType,a.package_no as packageNo,
a.length, a.width, a.height
from ecss_package a
<where> a.BuNo = #{buNo}
<if test="packageType != null and packageType != ''">
AND a.package_type like '%'+#{packageType}+'%'
</if>
</where>
order by a.CreateDate
</select>
<select id="getDeclarationElements" resultType="java.util.Map">
select part_no as partNo,bu_no as buNo
from ecss_CoDelNotifyDetail
where site=#{site} and delNo=#{delNo} and qty>0
GROUP BY part_no,bu_no
</select>
<select id="getHsCodeByPartNo" resultType="java.util.Map">
select p.hsCode, p.hsCodeDesc,p.part_no ,h.codeNo,h.BuNo,p.sku,h.hsCodeDescEn
from Part p
left join ecss_hsCode h on p.hsCodeDesc=h.hsCodeDesc and p.site=h.site
where p.site=#{site,jdbcType=VARCHAR} and p.part_no in
<foreach item="item" index="index" collection="partNos" open="(" separator="," close=")">
#{item}
</foreach>
</select>
<select id="getDeclarationHeader" resultType="EcssDeclarationHeaderData">
select * from ecss_declaration_header where site=#{site} and declaration_no=#{declarationNo}
</select>
<select id="getDeclarationHeaderByDelNo" resultType="EcssDeclarationHeaderData">
select * from ecss_declaration_header where site=#{site} and delNo=#{delNo}
</select>
<select id="exportDeclarationDetail" resultType="java.util.Map">
select detail.site,detail.declaration_no,detail.item_no,
CONVERT(DECIMAL(20, 0), detail.qty) as qty,isnull(h.unit,'') as qty_unit,'kg' as weight_unit,
CONVERT(DECIMAL(20, 2),detail.net_weight) as net_weight,CONVERT(DECIMAL(20, 6),detail.unit_price) as unit_price,
CONVERT(DECIMAL(20, 2),detail.total_price) as total_price,detail.currency,detail.made_area,detail.destination,
detail.source_area,detail.levy,detail.hs_code,detail.hs_code_desc,h.hsCodeDescEn
from ecss_declaration_detail detail
left join ecss_hsCode h on detail.hs_code=h.HsCode and detail.site=h.Site and detail.hs_code_desc=h.hsCodeDesc
where detail.site=#{site} and declaration_no=#{declarationNo}
</select>
<select id="getEcssCoDelNotifyHeader" resultType="EcssCoDelNotifyHeaderData">
select * from ecss_CoDelNotifyHeader where site=#{site} and delNo=#{delNo}
</select>
<select id="exportEcssCoDelNotifyDetail" resultType="java.util.Map">
select a.customerPO,a.part_no,a.part_description,a.currency,
CONVERT(DECIMAL(20, 0), a.qty) as qty,CONVERT(DECIMAL(20, 6), a.tp) as unitPrice,b.hsCode,
a.upc,a.so,a.ttl_amount,a.pn,h.hsCodeDesc,h.hsCodeDescEn
from ecss_CoDelNotifydetail a
left join part b on a.site=b.site and a.part_no=b.part_no
left join ecss_hsCode h on b.hsCode=h.HsCode and a.site=h.site and b.hsCodeDesc=h.hsCodeDesc
where a.site = #{site} AND a.delNo = #{delNo} and a.qty>0
order by a.item_no
</select>
<select id="exportCoDelPalletDetail" resultType="java.util.Map">
-- 修复净重毛重重复计算问题:按数量比例分配箱子重量
WITH BoxDetail AS (
SELECT
b.part_no,
b.qty,
b.rolls,
a.box_qty,
a.net_weight,
a.gross_weight,
b.site,
b.bu_no,
b.delNo,
b.seq_no,
-- 计算该零件数量占该箱子总数量的比例
CASE
WHEN SUM(b.qty) OVER (PARTITION BY b.site, b.bu_no, b.delNo, b.seq_no) > 0
THEN b.qty * 1.0 / SUM(b.qty) OVER (PARTITION BY b.site, b.bu_no, b.delNo, b.seq_no)
ELSE 0
END as qtyRatio
FROM ecss_CoDelBoxList a
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
WHERE a.site=#{site} AND a.bu_no=#{buNo} AND a.delNo=#{delNo} AND b.site IS NOT NULL
)
SELECT
part_no,
CONVERT(DECIMAL(20, 0), SUM(qty)) as total_qty,
CONVERT(DECIMAL(20, 0), SUM(DISTINCT box_qty)) as box_qty,
CONVERT(DECIMAL(20, 0), SUM(rolls)) as rolls,
-- 按数量比例分配净重和毛重
CONVERT(DECIMAL(20, 2), SUM(ISNULL(net_weight, 0) * qtyRatio)) as net_weight,
CONVERT(DECIMAL(20, 2), SUM(ISNULL(gross_weight, 0) * qtyRatio)) as gross_weight,
CONVERT(DECIMAL(20, 0), SUM(rolls * qty)) as qty_per_carton
FROM BoxDetail
GROUP BY part_no
</select>
<select id="getCoDelPalletDetailGroupByPn" resultType="java.util.Map">
-- 修复净重毛重重复计算问题:按数量比例分配箱子重量
WITH BoxDetail AS (
SELECT
b.pn,
b.qty,
b.rolls,
a.box_qty,
a.net_weight,
a.gross_weight,
b.site,
b.bu_no,
b.delNo,
b.seq_no,
-- 计算该零件数量占该箱子总数量的比例
CASE
WHEN SUM(b.qty) OVER (PARTITION BY b.site, b.bu_no, b.delNo, b.seq_no) > 0
THEN b.qty * 1.0 / SUM(b.qty) OVER (PARTITION BY b.site, b.bu_no, b.delNo, b.seq_no)
ELSE 0
END as qtyRatio
FROM ecss_CoDelBoxList a
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
WHERE a.site=#{site} AND a.bu_no=#{buNo} AND a.delNo=#{delNo}
)
SELECT
pn,
CONVERT(DECIMAL(20, 0), SUM(qty)) as total_qty,
CONVERT(DECIMAL(20, 0), SUM(DISTINCT box_qty)) as box_qty,
CONVERT(DECIMAL(20, 0), SUM(rolls)) as rolls,
-- 按数量比例分配净重和毛重
CONVERT(DECIMAL(20, 2), SUM(ISNULL(net_weight, 0) * qtyRatio)) as net_weight,
CONVERT(DECIMAL(20, 2), SUM(ISNULL(gross_weight, 0) * qtyRatio)) as gross_weight,
CONVERT(DECIMAL(20, 0), SUM(rolls * qty)) as qty_per_carton
FROM BoxDetail
WHERE pn IS NOT NULL
GROUP BY pn
</select>
<!-- 按发货通知单明细item_no分组获取装箱明细重量(用于Invoice) -->
<select id="exportCoDelPalletDetailGroupByItemNo" resultType="java.util.Map">
-- 按发货通知单明细行号分组,汇总该行对应的装箱重量
WITH BoxDetail AS (
SELECT
b.notify_detail_item_no,
b.part_no,
b.qty,
b.rolls,
a.box_qty,
a.net_weight,
a.gross_weight,
b.site,
b.bu_no,
b.delNo,
b.seq_no,
-- 计算该零件数量占该箱子总数量的比例
CASE
WHEN SUM(b.qty) OVER (PARTITION BY b.site, b.bu_no, b.delNo, b.seq_no) > 0
THEN b.qty * 1.0 / SUM(b.qty) OVER (PARTITION BY b.site, b.bu_no, b.delNo, b.seq_no)
ELSE 0
END as qtyRatio
FROM ecss_CoDelBoxList a
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
WHERE a.site=#{site} AND a.bu_no=#{buNo} AND a.delNo=#{delNo} AND b.notify_detail_item_no IS NOT NULL
)
SELECT
notify_detail_item_no as item_no,
part_no,
CONVERT(DECIMAL(20, 0), SUM(qty)) as total_qty,
CONVERT(DECIMAL(20, 0), SUM(DISTINCT box_qty)) as box_qty,
CONVERT(DECIMAL(20, 0), SUM(rolls)) as rolls,
-- 按数量比例分配净重和毛重
CONVERT(DECIMAL(20, 2), SUM(ISNULL(net_weight, 0) * qtyRatio)) as net_weight,
CONVERT(DECIMAL(20, 2), SUM(ISNULL(gross_weight, 0) * qtyRatio)) as gross_weight,
CONVERT(DECIMAL(20, 0), SUM(rolls * qty)) as qty_per_carton
FROM BoxDetail
GROUP BY notify_detail_item_no, part_no
</select>
<select id="exportCoDelBoxList" resultType="java.util.Map">
select CONVERT(DECIMAL(20, 0),sum(a.box_qty)) as box_qty
from ecss_CoDelBoxList a
where a.site=#{site} and a.bu_no=#{buNo} and a.delNo=#{delNo} GROUP BY a.item_no
</select>
<update id="updateEcssDeclarationHeader" >
update ecss_declaration_header set
upc=#{upc},so=#{so},origin=#{origin},pallet_weight=#{palletWeight},material=#{material},
hs_code=#{hsCode},packaging=#{packaging},kgs=#{kgs},shipping_mark=#{shippingMark},boxChange=#{boxChange},
hsCodeDesc=#{hsCodeDesc},contractFlag=#{contractFlag},hsCodeDescType=#{hsCodeDescType},goodsLabel=#{goodsLabel}
where site=#{site} and declaration_no=#{declarationNo}
</update>
<update id="updateEcssCoDelNotifyDetail" >
update ecss_CoDelNotifydetail set lossratio=#{lossratio},ehundred=#{ehundred}
where site=#{site} and delNo=#{delNo} and part_no=#{partNo}
</update>
<update id="updateEcssCoDelNotifyDetailSurplus" >
update ecss_CoDelNotifydetail set surplus_qty=#{surplusQty}
where site=#{site} and bu_no=#{buNo} and delNo=#{delNo} and part_no=#{partNo} and item_no=#{itemNo}
</update>
<select id="getNotifyPartDetail" resultType="java.util.Map">
select a.part_no as partNo,b.hsCode,a.site,a.delNo,a.lossratio,a.ehundred,b.part_desc,a.pn
from ecss_CoDelNotifydetail a
left join part b on a.site=b.site and a.part_no=b.part_no
where a.site = #{site} AND a.delNo = #{delNo} and a.qty>0
group by a.part_no,b.hsCode,a.site,a.delNo,a.lossratio,a.ehundred,b.part_desc,a.pn
</select>
<select id="getNotifyPartDetail2" resultType="EcssCoDelNotifyDetailData">
select a.part_no as partNo,b.hsCode,a.site,a.delNo,a.lossratio,a.ehundred,b.part_desc,a.pn
from ecss_CoDelNotifydetail a
left join part b on a.site=b.site and a.part_no=b.part_no
where a.site = #{site} AND a.delNo = #{delNo} and a.qty>0
group by a.part_no,b.hsCode,a.site,a.delNo,a.lossratio,a.ehundred,b.part_desc,a.pn
</select>
<select id="getNotifyDetailGroup" resultType="java.util.Map">
select b.hsCodeDesc,CONVERT(DECIMAL(20, 2),sum(a.qty)) as total_qty,
CONVERT(DECIMAL(20, 2),sum(a.ttl_amount)) as ttl_amount
from ecss_CoDelNotifydetail a
left join part b on a.site=b.site and a.part_no=b.part_no
where a.site = #{site} AND a.delNo = #{delNo} and a.qty>0
group by b.hsCodeDesc
</select>
<!-- 根据notifyDetailItemNo获取发货通知单明细 -->
<select id="getEcssCoDelNotifyDetailByItemNo" resultType="EcssCoDelNotifyDetailData">
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,
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,
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,
a.modifyFlag,a.modifyQtyFlag
from ecss_CoDelNotifydetail a
where a.site = #{site}
and a.bu_no = #{buNo}
and a.delNo = #{delNo}
and a.item_no = #{notifyDetailItemNo}
</select>
<select id="getPropertiesListByTypeAndCodeNo" resultType="com.xujie.sys.modules.part.entity.PartSubPropertiesValueData">
SELECT a.part_no , a.Site, a.code_no, a.sub_code_seq_no, a.sub_code_desc
,a.bu_no,a.item_no, a.properties_item_no, a.text_value, a.num_value, a.record_type
, b.item_desc ItemDesc, b.value_type, b.value_type_db, b.value_choose_flag
FROM part_sub_properties_value a
left join plm_properties_item b
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
<where>
AND a.site = #{site}
and a.record_type = #{recordType}
and a.bu_no=#{buNo}
and a.code_no = #{codeNo}
and a.part_no = #{pn}
</where>
order by a.item_no
</select>
<select id="getEcssContacts" resultType="java.util.Map">
select * from ecss_contacts where bu_no=#{buNo}
</select>
<select id="getCustomerList" resultType="java.util.Map">
select * from ecss_custdev_mes_cmc_customer where buse='是'
</select>
<select id="getCustomerInfo" resultType="java.util.Map">
select DISTINCT vcus.ccusname,vcusp.ccontactname,vcusp.cnative
from ecss_custdev_mes_cmc_customer vcus
LEFT JOIN ecss_custdev_mes_cmc_customer_person vcusp on vcus.ccuscode=vcusp.ccuscode
<where>
<if test="ccusname != null and ccusname != ''">
and vcus.ccusname=#{ccusname}
</if>
<if test="ccuscode != null and ccuscode != ''">
and vcus.ccuscode=#{ccuscode}
</if>
</where>
</select>
<select id="getCustomerAdd" resultType="java.util.Map">
select DISTINCT vcus.ccusname,vcusa.cDeliverAdd
from ecss_custdev_mes_cmc_customer vcus
left join ecss_custdev_mes_cmc_customer_addr vcusa on vcus.ccuscode=vcusa.ccuscode
where vcus.ccusname=#{ccusname}
</select>
<select id="getPackageNoByPartNo" resultType="java.util.Map">
select p.part_no as partNo,p.packageNo
from Part p
where p.site=#{site,jdbcType=VARCHAR} and p.part_no in
<foreach item="item" index="index" collection="partNos" open="(" separator="," close=")">
#{item}
</foreach>
</select>
<select id="getPackageNoByPn" resultType="java.util.Map">
select p.sku as pn,p.packageNo
from Part p
where p.site=#{site,jdbcType=VARCHAR} and p.sku in
<foreach item="item" index="index" collection="pns" open="(" separator="," close=")">
#{item}
</foreach>
</select>
<select id="getPackageList" resultType="EcssPackageData">
select * from ecss_package where site=#{site} and buNo=#{buNo}
and package_no in
<foreach item="item" index="index" collection="packageNos" open="(" separator="," close=")">
#{item}
</foreach>
</select>
<select id="searchEcssTemplateData" resultType="EcssTemplate">
select a.*,dbo.get_bu_desc(a.site,a.BuNo) as BuDesc
from ecss_template a
left join accessBu D on A.site=D.site and A.BuNo=d.bu_no and D.username=#{query.username}
<where>
and D.site is not null
<if test="query.buNo != null and query.buNo != ''">
AND a.buNo = #{query.buNo}
</if>
<if test="query.name != null and query.name != ''">
AND a.name like '%'+#{query.name}+'%'
</if>
<if test="query.customName != null and query.customName != ''">
AND a.customName like '%'+#{query.customName}+'%'
</if>
<if test="query.shippingMode != null and query.shippingMode != ''">
AND a.shippingMode like '%'+#{query.shippingMode}+'%'
</if>
<if test="query.type != null and query.type != ''">
AND a.type = #{query.type}
</if>
</where>
order by a.CreateDate
</select>
<insert id="insertEcssTemplateData" >
insert into ecss_template (customName,site,buNo,name,type,upc,so,origin,palletWeight,material,hsCode,packaging,itemNo,
kgs,shippingMark,boxChange,hsCodeDesc,contractFlag,hsCodeDescType,goodsLabel,hsCodeFlag,shippingMode,CreateBy,CreateDate,
salesMethod,currency,madeArea,sendPort,shipper,voyage,deliveryGoodsDate,shippingDate,fscWeight, remark,highPalletFlag,showWeight)
values(#{customName,jdbcType=NVARCHAR},#{site},#{buNo},#{name},#{type},#{upc},#{so},#{origin},#{palletWeight},#{material},#{hsCode},#{packaging},
#{itemNo},#{kgs},#{shippingMark},#{boxChange},
#{hsCodeDesc},#{contractFlag},#{hsCodeDescType},#{goodsLabel},#{hsCodeFlag},#{shippingMode},#{createBy},GetDate(),
#{salesMethod},#{currency},#{madeArea},#{sendPort},#{shipper},#{voyage},#{deliveryGoodsDate},#{shippingDate},#{fscWeight},#{remark},#{highPalletFlag},#{showWeight})
</insert>
<update id="updateEcssTemplateData">
update ecss_template set buNo=#{buNo},name=#{name},type=#{type},upc=#{upc},so=#{so},origin=#{origin},boxChange=#{boxChange},
palletWeight=#{palletWeight},material=#{material},hsCode=#{hsCode},itemNo=#{itemNo},
packaging=#{packaging},kgs=#{kgs},shippingMark=#{shippingMark},hsCodeDesc=#{hsCodeDesc},
contractFlag=#{contractFlag},hsCodeDescType=#{hsCodeDescType},goodsLabel=#{goodsLabel},hsCodeFlag=#{hsCodeFlag},
shippingMode=#{shippingMode},UpdateDate=GetDate(),UpdateBy=#{updateBy},customName=#{customName,jdbcType=NVARCHAR},salesMethod= #{salesMethod},
currency= #{currency},madeArea= #{madeArea},sendPort= #{sendPort},shipper= #{shipper},remark= #{remark},
voyage= #{voyage},deliveryGoodsDate= #{deliveryGoodsDate},shippingDate= #{shippingDate},fscWeight=#{fscWeight},highPalletFlag=#{highPalletFlag},showWeight=#{showWeight}
where buNo=#{buNo} and name=#{nameNative}
</update>
<select id="deleteEcssTemplate" >
delete from ecss_template where buNo=#{buNo} and name=#{name}
</select>
<select id="getEcssTemplateByBuAndName" resultType="EcssTemplate">
select * from ecss_template where name=#{name} and site=#{site}
</select>
<select id="searchWalMartOrderData" resultType="EcssWalMartOrder">
select a.*
from ecss_walMartOrder a
<where>
<if test="query.so != null and query.so != ''">
AND a.so like '%'+#{query.so}+'%'
</if>
<if test="query.sku != null and query.sku != ''">
AND a.sku like '%'+#{query.sku}+'%'
</if>
</where>
order by a.CreateDate
</select>
<insert id="insertWalMartOrderData" >
insert into ecss_walMartOrder (site,buNo,sku,so,qty,rolls,grossWeight,verificationSheet,CreateBy,CreateDate)
values(#{site},#{buNo},#{sku},#{so},#{qty},#{rolls},#{grossWeight},#{verificationSheet},#{createBy},GetDate())
</insert>
<insert id="batchSaveWalMartOrder">
insert into ecss_walMartOrder (site,buNo,sku,so,qty,rolls,grossWeight,verificationSheet,CreateBy,CreateDate)
values
<foreach collection="list" separator="," item="item">
(#{item.site},#{item.buNo},#{item.sku},#{item.so},#{item.qty},
#{item.rolls},#{item.grossWeight},#{item.verificationSheet},#{item.createBy},GetDate())
</foreach>
</insert>
<update id="updateWalMartOrderData">
update ecss_walMartOrder set buNo=#{buNo},sku=#{sku},so=#{so},qty=#{qty},rolls=#{rolls},grossWeight=#{grossWeight},
verificationSheet=#{verificationSheet},UpdateDate=GetDate(),UpdateBy=#{updateBy}
where buNo=#{buNo} and sku=#{sku} and so=#{so} and qty=#{qty}
</update>
<select id="deleteWalMartOrder" >
delete from ecss_walMartOrder where buNo=#{buNo} and sku=#{sku} and so=#{so} and qty=#{qty}
</select>
<!-- 查出所有类型的物料 -->
<select id="queryPartListAll" parameterType="PartInformationEntity" resultType="PartInformationEntity">
SELECT site, sourceBu as buNo, part_no, part_desc, sku
FROM part
<where> sourceBu=#{query.buNo} and
site = #{query.site} and active = 'Y'
<if test = "query.partNo != null and query.partNo != ''">
AND part_no like '%' + #{query.partNo} + '%'
</if>
<if test = "query.sku != null and query.sku != ''">
AND sku like '%' + #{query.sku} + '%'
</if>
<if test = "query.partDesc != null and query.partDesc != ''">
AND part_desc like '%' + #{query.partDesc} + '%'
</if>
</where>
</select>
<select id="queryByUserName" resultType="com.xujie.sys.modules.sys.entity.SysUserEntity">
select * from sys_user where username = #{username}
</select>
<select id="queryUsersByRoleName" resultType="com.xujie.sys.modules.sys.entity.SysUserEntity">
select u.email from sys_user u
LEFT JOIN sys_user_role ur on ur.user_id = u.user_id
LEFT JOIN sys_role r on r.role_id = ur.role_id
where r.role_name = #{roleName} and u.site = #{site}
</select>
<select id="searchCoDelPalletDataNew" resultType="EcssCoDelPalletData">
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,
c.gross_weight,c.net_weight,c.box_qty as pallet_qty,b.notify_detail_item_no as notifyDetailItemNo
from ecss_CoDelPalletDetail b
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
where b.site=#{site} and b.bu_no=#{buNo} and b.delNo=#{delNo}
<if test="seqNo != null and seqNo != ''">
and b.seq_no=#{seqNo}
</if>
</select>
<update id="updateExportFlag">
update ecss_CoDelNotifyHeader
set export_flag = #{exportFlag},
updateBy = #{updateBy},
updateDate = GetDate()
where site = #{site}
and bu_no = #{buNo}
and delNo = #{delNo}
</update>
<select id="selectBoxList" resultType="java.util.Map">
select a.*,
CONVERT(DECIMAL(20, 3),a.gross_weight) as grossWeight,
CONVERT(DECIMAL(20, 3),a.net_weight) as netWeight,
CONVERT(DECIMAL(20, 3),w.num_value) as boxWeight
from ecss_CoDelBoxList a
left join (
select b.site, b.bu_no, b.delNo, b.seq_no, b.part_no,
ROW_NUMBER() OVER (PARTITION BY b.site, b.bu_no, b.delNo, b.seq_no ORDER BY b.part_no) as rn
from ecss_CoDelPalletDetail b
where b.site = #{site} and b.bu_no = #{buNo} and b.delNo = #{delNo}
) 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
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
and w.record_type='ECSSPART' and w.code_no='BG001' and w.properties_item_no='BOXWEIGHT'
where a.site = #{site} and a.bu_no = #{buNo} and a.delNo = #{delNo}
</select>
<update id="updateBoxInfo">
update ecss_CoDelBoxList
set box_qty = #{box_qty},
gross_weight = #{grossWeight},
net_weight = #{netWeight},
rolls = #{rolls}
where site = #{site}
and bu_no = #{buNo}
and delNo = #{delNo}
and item_no = #{item_no}
</update>
<delete id="deleteBoxInfo">
delete from ecss_CoDelBoxList
where site = #{site}
and bu_no = #{buNo}
and delNo = #{delNo}
and item_no = #{item_no}
</delete>
<update id="updateDetailInfo">
update ecss_CoDelPalletDetail
set qty = #{qty},
rolls = #{rolls}
where site = #{site}
and bu_no = #{buNo}
and delNo = #{delNo}
and seq_no = #{seqNo}
and item_no = #{itemNo}
</update>
<delete id="deleteDetailInfo">
delete from ecss_CoDelPalletDetail
where site = #{site}
and bu_no = #{buNo}
and delNo = #{delNo}
and seq_no = #{seqNo}
and item_no = #{itemNo}
</delete>
<delete id="deleteEmptyBoxAfterDetailDelete">
-- 删除明细后,如果该box下没有明细了,则删除对应的box
delete from ecss_CoDelBoxList
where site = #{site}
and bu_no = #{buNo}
and delNo = #{delNo}
and item_no = #{seqNo}
and not exists (
select 1
from ecss_CoDelPalletDetail
where site = #{site}
and bu_no = #{buNo}
and delNo = #{delNo}
and seq_no = #{seqNo}
);
</delete>
<!--<select id="selectPalletDetailList" resultType="java.util.Map">
select a.*,b.part_description,b.hsCode,b.upc,b.so
from ecss_CoDelPalletDetail a left join (
select a.site,a.bu_no,a.delNo,a.part_no,a.part_description,b.hsCode,a.upc,a.so,a.customerPO
from ecss_CoDelNotifydetail a
left join part b on a.site=b.site and a.part_no=b.part_no
where a.site=#{site} and a.bu_no=#{buNo} and a.delNo=#{delNo}
GROUP BY a.site,a.bu_no,a.delNo,a.part_no,a.part_description,b.hsCode,a.upc,a.so,a.customerPO
) 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
where a.site =#{site} and a.bu_no=#{buNo} and a.delNo=#{delNo}
<if test="seqNo != null and seqNo != ''">
and a.seq_no=#{seqNo}
</if>
order by a.notify_detail_item_no
</select>-->
<select id="selectPalletDetailList" resultType="java.util.Map">
select a.*,b.part_description,c.hsCode,b.upc,b.so
from ecss_CoDelPalletDetail a
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
left join part c on a.site=c.site and a.part_no=c.part_no
where a.site =#{site} and a.bu_no=#{buNo} and a.delNo=#{delNo}
<if test="seqNo != null and seqNo != ''">
and a.seq_no=#{seqNo}
</if>
order by a.notify_detail_item_no
</select>
<!-- 获取客户模板列表 -->
<select id="getCustomerTemplateList" resultType="java.util.Map">
SELECT
template_no,
template_name,
ccuscode,
ccusname,
caddcode1,
localShipAddress,
salesArea,
caddcode2,
overseasAddress,
cnative,
overseasShipper
FROM ecss_Customer_template
<where>
<if test="templateName != null and templateName != ''">
AND template_name like '%'+#{templateName}+'%'
</if>
<if test="customerName != null and customerName != ''">
AND customer_name like '%'+#{customerName}+'%'
</if>
</where>
ORDER BY template_name
</select>
<!-- ========== 物料包装属性导入相关SQL ========== -->
<!-- 根据SKU获取物料信息(一个SKU可能对应多个part) -->
<select id="getPartListBySku" resultType="PartData">
SELECT site, sourceBu as buNo, part_no as partNo, part_desc as partDesc, sku
FROM part
WHERE site = #{site}
AND sourceBu = #{buNo}
AND sku = #{sku}
</select>
<!-- 检查物料属性是否存在 -->
<select id="checkPartPropertyExists" resultType="java.util.Map">
SELECT part_no, properties_item_no, num_value, text_value, item_no
FROM part_sub_properties_value
WHERE site = #{site}
AND bu_no = #{buNo}
AND part_no = #{partNo}
AND code_no = #{codeNo}
AND record_type = #{recordType}
AND properties_item_no = #{propertiesItemNo}
</select>
<!-- 更新物料属性数值 -->
<update id="updatePartPropertyNumValue">
UPDATE part_sub_properties_value
SET num_value = #{numValue}
WHERE site = #{site}
AND bu_no = #{buNo}
AND part_no = #{partNo}
AND code_no = #{codeNo}
AND record_type = #{recordType}
AND properties_item_no = #{propertiesItemNo}
</update>
<!-- 获取物料属性的最大item_no -->
<select id="getMaxItemNo" resultType="java.lang.Double">
SELECT MAX(item_no)
FROM part_sub_properties_value
WHERE site = #{site}
AND bu_no = #{buNo}
AND part_no = #{partNo}
AND code_no = #{codeNo}
AND record_type = #{recordType}
</select>
<!-- 获取属性定义信息 -->
<select id="getPropertiesItemInfo" resultType="java.util.Map">
SELECT item_no, item_desc, value_type, value_type_db,
(SELECT TOP 1 code_desc FROM plm_properties_model_header
WHERE site = #{site} AND bu_no = #{buNo} AND function_type = #{itemType}) as codeDesc
FROM plm_properties_item
WHERE site = #{site}
AND bu_no = #{buNo}
AND item_no = #{itemNo}
AND item_type = #{itemType}
</select>
<!-- 插入物料属性 -->
<insert id="insertPartProperty">
INSERT INTO part_sub_properties_value
(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)
VALUES
(#{partNo}, #{site}, #{buNo}, #{codeNo}, #{subCodeSeqNo}, #{subCodeDesc}, #{itemNo}, #{propertiesItemNo}, #{textValue}, #{numValue}, #{recordType})
</insert>
<!-- 检查箱类型是否存在(根据packageNo) -->
<select id="checkPackageExists" resultType="java.util.Map">
SELECT id, site, BuNo, package_no as packageNo, package_type as packageType, length, width, height
FROM ecss_package
WHERE site = #{site}
AND BuNo = #{buNo}
AND package_no = #{packageNo}
</select>
<!-- 根据packageType检查箱类型是否存在 -->
<select id="checkPackageExistsByType" resultType="java.util.Map">
SELECT id, site, BuNo, package_no as packageNo, package_type as packageType, length, width, height
FROM ecss_package
WHERE site = #{site}
AND BuNo = #{buNo}
AND package_type = #{packageType}
</select>
<!-- 获取箱类型的最大packageNo编号 -->
<select id="getMaxPackageNo" resultType="java.lang.String">
SELECT MAX(package_no)
FROM ecss_package
WHERE site = #{site}
AND BuNo = #{buNo}
</select>
<!-- 插入箱类型 -->
<insert id="insertPackage">
INSERT INTO ecss_package
(Site, BuNo, package_no, package_type, length, width, height, volume, weight, Remark, CreateBy, CreateDate)
VALUES
(#{site}, #{buNo}, #{packageNo}, #{packageType}, #{length}, #{width}, #{height}, #{volume}, #{weight}, #{remark}, #{createBy}, GETDATE())
</insert>
<!-- 更新箱类型尺寸(根据packageType更新) -->
<update id="updatePackageDimensions">
UPDATE ecss_package
SET length = #{length},
width = #{width},
height = #{height},
volume = #{volume},
UpdateBy = #{updateBy},
UpdateDate = GETDATE()
WHERE site = #{site}
AND BuNo = #{buNo}
AND package_type = #{packageType}
</update>
<!-- 更新物料的packageNo -->
<update id="updatePartPackageNo">
UPDATE part
SET packageNo = #{packageNo}
WHERE site = #{site}
AND part_no = #{partNo}
</update>
</mapper>