emis-service/emis-biz/src/main/resources/mapper/EmisTmsSiteBatchMissMapper.xml

447 lines
24 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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.xdadan.erp.emis.mapper.EmisTmsSiteBatchMissMapper">
<resultMap type="EmisTmsSiteBatchMiss" id="EmisTmsSiteBatchMissResult" extends="com.xdadan.erp.emis.mapper.EmisBaseMapper.EmisBaseResult">
<result property="id" column="id"/>
<result property="billCode" column="bill_code"/>
<result property="manager" column="manager"/>
<result property="transManager" column="trans_manager"/>
<result property="missReason" column="miss_reason"/>
<result property="lineCode" column="line_code"/>
<result property="productType" column="product_type"/>
<result property="startSiteCode" column="start_site_code"/>
<result property="nextSiteCode" column="next_site_code"/>
<result property="supplierCode" column="supplier_code"/>
<result property="startDate" column="start_date"/>
<result property="endDate" column="end_date"/>
<result property="lineName" column="line_name"/>
<result property="productTypeName" column="product_type_name"/>
<result property="startSiteName" column="start_site_name"/>
<result property="nextSiteName" column="next_site_name"/>
<result property="supplierName" column="supplier_name"/>
<result property="sendSiteCode" column="send_site_code"/>
<result property="sendSiteName" column="send_site_name"/>
<result property="sendCountry" column="send_country"/>
<result property="sendCountryName" column="send_country_name"/>
<result property="destinationCode" column="destination_code"/>
<result property="destinationName" column="destination_name"/>
<result property="receiveCountry" column="receive_country"/>
<result property="receiveCountryName" column="receive_country_name"/>
<result property="blIsQuestion" column="bl_is_question"/>
<result property="sendDate" column="send_date"/>
<result property="blSign" column="bl_sign"/>
<result property="signDate" column="sign_date"/>
<result property="paymentType" column="payment_type"/>
<result property="parcelQty" column="parcel_qty"/>
<result property="billWeight" column="bill_weight"/>
<result property="totalVolume" column="total_volume"/>
<result property="volumeWeight" column="volume_weight"/>
<result property="settlementWeight" column="settlement_weight"/>
<result property="freight" column="freight"/>
<result property="waybillRemark" column="waybill_remark"/>
<result property="feeRemark" column="fee_remark"/>
<result property="missType" column="miss_type"/>
<result property="virtualRemark" column="virtual_remark" />
<result property="problemType" column="problem_type" />
<result property="dispatchUnderlingSiteCode" column="dispatch_underling_site_code" />
<result property="dispatchUnderlingSiteName" column="dispatch_underling_site_name" />
<result property="manual_remark" column="manualRemark" />
<result property="bl_manual" column="blManual" />
</resultMap>
<sql id="selectEmisTmsSiteBatchMissVo">
select
m.id, m.bill_code, m.miss_reason, m.create_time, m.update_time, m.remark, m.del_flag,
m.line_code, m.product_type, m.start_site_code, m.next_site_code, m.supplier_code, m.start_date, m.end_date,m.miss_type,
w.send_site_code, s1.site_name as send_site_name,s2.site_name as start_site_name,s3.site_name as next_site_name, w.send_country, c1.name as send_country_name, w.destination_code, s4.site_name as dispatch_underling_site_name,w.bl_is_question,
l.line_name as line_name,
w.receive_country, c2.name as receive_country_name, w.send_date, w.bl_sign, w.sign_date,
w.product_type,w.problem_type,w.virtual_remark,w.dispatch_underling_site_code,
w.payment_type, w.parcel_qty, w.bill_weight, w.total_volume, w.volume_weight,
w.settlement_weight, w.freight, w.remark as waybill_remark, w.fee_remark, m.manager, k.trans_manager,
(SELECT GROUP_CONCAT(s.name)
FROM emis_supplier s
WHERE FIND_IN_SET(s.code, m.supplier_code)
AND s.del_flag = '0') as supplier_name,
(SELECT GROUP_CONCAT(p.prod_name)
FROM emis_trans_product p
WHERE FIND_IN_SET(p.prod_code, m.product_type)
AND p.del_flag = '0') as product_type_name
from emis_tms_site_batch_miss m
left join emis_waybill w on m.bill_code = w.bill_code and w.del_flag='0'
left join emis_site s1 on w.send_site_code=s1.site_code and s1.del_flag=0
left join emis_site s2 on m.start_site_code=s2.site_code and s2.del_flag=0
left join emis_site s3 on m.next_site_code=s3.site_code and s3.del_flag=0
left join emis_country c1 on w.send_country=c1.code and c1.del_flag='0'
left join emis_country c2 on w.receive_country=c2.code and c2.del_flag='0'
left join emis_site s4 on w.dispatch_underling_site_code=s4.site_code and s4.del_flag=0
left join emis_trans_line k on w.trans_line_type=k.line_code and k.del_flag='0'
left join emis_trans_plan_rule r on m.trans_plan_rule_id=r.id and r.del_flag='0'
left join emis_trans_line l on m.line_code=l.line_code and l.del_flag='0'
</sql>
<!-- <select id="selectEmisTmsSiteBatchMissList" parameterType="EmisTmsSiteBatchMiss" resultMap="EmisTmsSiteBatchMissResult">-->
<!-- <include refid="selectEmisTmsSiteBatchMissVo"/>-->
<!-- <where>-->
<!-- m.del_flag = '0'-->
<!-- <if test="billCode != null and billCode != ''">-->
<!-- AND m.bill_code = #{billCode}-->
<!-- </if>-->
<!-- <if test="missReason != null and missReason != ''">-->
<!-- AND m.miss_reason like concat('%', #{missReason}, '%')-->
<!-- </if>-->
<!-- <if test="missType != null and missType != ''">-->
<!-- AND m.miss_type=#{missType}-->
<!-- </if>-->
<!-- <if test="manager != null and manager != ''">-->
<!-- AND m.manager like concat('%', #{manager}, '%')-->
<!-- </if>-->
<!-- <if test="transManager != null and transManager != ''">-->
<!-- AND k.trans_manager like concat('%', #{transManager}, '%')-->
<!-- </if>-->
<!-- <if test="lineCode != null and lineCode != ''">-->
<!-- AND m.line_code = #{lineCode}-->
<!-- </if>-->
<!-- <if test="productType != null and productType != ''">-->
<!-- AND m.product_type = #{productType}-->
<!-- </if>-->
<!-- <if test="startSiteCode != null and startSiteCode != ''">-->
<!-- AND m.start_site_code = #{startSiteCode}-->
<!-- </if>-->
<!-- <if test="nextSiteCode != null and nextSiteCode != ''">-->
<!-- AND m.next_site_code = #{nextSiteCode}-->
<!-- </if>-->
<!-- <if test="supplierCode != null and supplierCode != ''">-->
<!-- AND m.supplier_code = #{supplierCode}-->
<!-- </if>-->
<!-- <if test="startDate != null">-->
<!-- AND m.start_date = #{startDate}-->
<!-- </if>-->
<!-- <if test="endDate != null">-->
<!-- AND m.end_date = #{endDate}-->
<!-- </if>-->
<!-- <if test="blIsQuestion != null and blIsQuestion != ''">-->
<!-- AND w.bl_is_question = #{blIsQuestion}-->
<!-- </if>-->
<!-- <if test="params.privSiteCode != null and params.privSiteCode != '88888'">-->
<!-- and (r.manager=#{params.privEmpName} or k.trans_manager=#{params.privEmpName})-->
<!-- </if>-->
<!-- </where>-->
<!-- </select>-->
<select id="selectEmisTmsSiteBatchMissList" parameterType="EmisTmsSiteBatchMiss" resultMap="EmisTmsSiteBatchMissResult">
<choose>
<when test="missCount == -4 or missCount == -7">
<!-- 当missCount=-4时,查询emis_waybill_batch_status表 -->
select
distinct w.bill_code, null as id, '已组批次成功' as miss_reason,
null as create_by, null as create_time, null as update_by, null as update_time,
null as remark, '0' as del_flag,
w.trans_line_type as line_code, w.product_type, w.start_site_code, w.next_site_code,
null as supplier_code, null as start_date, null as end_date, '0' as miss_type,
w.send_site_code, s1.site_name as send_site_name,
w.send_country, c1.name as send_country_name, w.destination_code, s2.site_name as dispatch_underling_site_name, w.bl_is_question,
l.line_name as line_name,
w.receive_country, c2.name as receive_country_name, w.send_date, w.bl_sign, w.sign_date,
w.payment_type, w.parcel_qty, w.bill_weight, w.total_volume, w.volume_weight,
w.settlement_weight, w.freight, w.remark as waybill_remark, w.fee_remark,
null as manager, null as trans_manager,
(SELECT GROUP_CONCAT(s.site_name ORDER BY FIND_IN_SET(s.site_code, w.start_site_code))
FROM emis_site s
WHERE FIND_IN_SET(s.site_code, w.start_site_code) AND s.del_flag = 0) as start_site_name,
(SELECT GROUP_CONCAT(s.site_name ORDER BY FIND_IN_SET(s.site_code, w.next_site_code))
FROM emis_site s
WHERE FIND_IN_SET(s.site_code, w.next_site_code) AND s.del_flag = 0) as next_site_name,
null as supplier_name,
(SELECT GROUP_CONCAT(p.prod_name)
FROM emis_trans_product p
WHERE FIND_IN_SET(p.prod_code, w.product_type)
AND p.del_flag = '0') as product_type_name,
b.remark as manual_remark,b.bl_manual
from emis_waybill_batch_status b
inner join emis_waybill w on b.bill_code = w.bill_code and w.del_flag='0'
left join emis_site s1 on w.send_site_code=s1.site_code and s1.del_flag=0
left join emis_country c1 on w.send_country=c1.code and c1.del_flag=0
left join emis_site s2 on w.dispatch_underling_site_code=s2.site_code and s2.del_flag=0
left join emis_trans_line l on w.trans_line_type=l.line_code and l.del_flag=0
left join emis_country c2 on w.receive_country=c2.code and c2.del_flag=0
<where>
b.site_batch_status = '1'
<if test="billCode != null and billCode != '' and ( params.billCodeSortList == null or (params.billCodeSortList != null and params.billCodeSortList.size() == 1 ) )">
and ( b.`bill_code`=#{billCode} or b.bill_code like concat('%',#{billCode}) )
</if>
<if test="missCount == -7">
AND (b.bl_manual = '2' or b.bl_manual = '3')
</if>
<if test="params.billCodeSortList != null and params.billCodeSortList.size() > 1 ">
and b.bill_code in
<foreach collection="params.billCodeSortList" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="lineCode != null and lineCode != ''">
AND w.trans_line_type = #{lineCode}
</if>
<if test="productType != null and productType != ''">
AND FIND_IN_SET(#{productType}, w.product_type)
</if>
<if test="startSiteCode != null and startSiteCode != ''">
AND (
w.start_site_code REGEXP REPLACE(#{startSiteCode}, ',', '|')
)
</if>
<if test="nextSiteCode != null and nextSiteCode != ''">
AND (
w.next_site_code REGEXP REPLACE(#{nextSiteCode}, ',', '|')
)
</if>
<if test="blIsQuestion != null and blIsQuestion != ''">
AND w.bl_is_question = #{blIsQuestion}
</if>
<if test="sendSiteCode != null and sendSiteCode != ''">
AND w.send_site_code = #{sendSiteCode}
</if>
<if test="params.beginSendDate != null and params.beginSendDate != ''">
and w.send_date <![CDATA[ >= ]]> #{params.beginSendDate}
</if>
<if test="params.endSendDate != null and params.endSendDate != ''">
and w.send_date <![CDATA[ <= ]]> #{params.endSendDate}
</if>
<if test="params.privSiteCode != null and params.privSiteCode != '88888'">
and (w.start_site_code=#{params.privSiteCode} or w.send_site_code=#{params.privSiteCode})
</if>
</where>
</when>
<otherwise>
<include refid="selectEmisTmsSiteBatchMissVo"/>
<where>
m.del_flag = '0'
<if test="missCount != null">
<choose>
<when test="missCount == -1">
AND m.miss_type = 2
</when>
<when test="missCount == -2">
AND m.miss_type = 3
</when>
<when test="missCount == -3">
AND m.miss_type = 1
</when>
<when test="missCount == -6">
AND m.miss_type = 4
</when>
<when test="missCount == -5">
AND m.bill_code IN (
SELECT bill_code
FROM emis_tms_site_batch_miss
WHERE del_flag = '0'
GROUP BY bill_code
HAVING COUNT(*) > 9
)
</when>
<when test="missCount > 0">
AND m.bill_code IN (
SELECT bill_code
FROM emis_tms_site_batch_miss
WHERE del_flag = '0'
GROUP BY bill_code
HAVING COUNT(*) = #{missCount}
)
AND m.miss_type = 0
</when>
</choose>
</if>
<if test="billCode != null and billCode != '' and ( params.billCodeSortList == null or (params.billCodeSortList != null and params.billCodeSortList.size() == 1 ) )">
and ( m.`bill_code`=#{billCode} or m.bill_code like concat('%',#{billCode}) )
</if>
<if test="params.billCodeSortList != null and params.billCodeSortList.size() > 1 ">
and m.bill_code in
<foreach collection="params.billCodeSortList" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="missReason != null and missReason != ''">
AND m.miss_reason like concat('%', #{missReason}, '%')
</if>
<if test="manager != null and manager != ''">
AND (
m.manager REGEXP REPLACE(#{manager}, ',', '|')
)
</if>
<if test="transManager != null and transManager != ''">
AND k.trans_manager like concat('%', #{transManager}, '%')
</if>
<if test="params.privSiteCode != null and params.privSiteCode != '88888'">
and (w.start_site_code=#{params.privSiteCode} or w.send_site_code=#{params.privSiteCode} or m.start_site_code=#{params.privSiteCode} or m.next_site_code=#{params.privSiteCode})
</if>
<if test="lineCode != null and lineCode != ''">
AND m.line_code = #{lineCode}
</if>
<if test="productType != null and productType != ''">
AND FIND_IN_SET(#{productType}, m.product_type)
</if>
<if test="startSiteCode != null and startSiteCode != ''">
AND (
m.start_site_code REGEXP REPLACE(#{startSiteCode}, ',', '|')
)
</if>
<if test="nextSiteCode != null and nextSiteCode != ''">
AND (
m.next_site_code REGEXP REPLACE(#{nextSiteCode}, ',', '|')
)
</if>
<if test="supplierCode != null and supplierCode != ''">
AND FIND_IN_SET(#{supplierCode}, m.supplier_code)
</if>
<if test="startDate != null">
AND m.start_date = #{startDate}
</if>
<if test="endDate != null">
AND m.end_date = #{endDate}
</if>
<if test="blIsQuestion != null and blIsQuestion != ''">
AND w.bl_is_question = #{blIsQuestion}
</if>
<if test="sendSiteCode != null and sendSiteCode != ''">
AND w.send_site_code = #{sendSiteCode}
</if>
<if test="params.beginSendDate != null and params.beginSendDate != ''">
and w.send_date <![CDATA[ >= ]]> #{params.beginSendDate}
</if>
<if test="params.endSendDate != null and params.endSendDate != ''">
and w.send_date <![CDATA[ <= ]]> #{params.endSendDate}
</if>
</where>
order by m.bill_code desc
</otherwise>
</choose>
</select>
<select id="selectEmisTmsSiteBatchMissById" parameterType="Long" resultMap="EmisTmsSiteBatchMissResult">
<include refid="selectEmisTmsSiteBatchMissVo"/>
where m.id = #{id} and m.del_flag = '0'
</select>
<insert id="insertEmisTmsSiteBatchMiss" parameterType="EmisTmsSiteBatchMiss" useGeneratedKeys="true" keyProperty="id">
insert into emis_tms_site_batch_miss
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="billCode != null">bill_code,</if>
<if test="missReason != null">miss_reason,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="remark != null">remark,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="billCode != null">#{billCode},</if>
<if test="missReason != null">#{missReason},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="remark != null">#{remark},</if>
</trim>
</insert>
<update id="updateEmisTmsSiteBatchMiss" parameterType="EmisTmsSiteBatchMiss">
update emis_tms_site_batch_miss
<trim prefix="SET" suffixOverrides=",">
<if test="billCode != null">bill_code = #{billCode},</if>
<if test="missReason != null">miss_reason = #{missReason},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="remark != null">remark = #{remark},</if>
</trim>
where id = #{id}
</update>
<update id="deleteEmisTmsSiteBatchMissById" parameterType="Long">
update emis_tms_site_batch_miss set del_flag = '1' where id = #{id}
</update>
<update id="deleteEmisTmsSiteBatchMissByIds" parameterType="String">
update emis_tms_site_batch_miss set del_flag = '1' where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</update>
<update id="deleteAll">
update emis_tms_site_batch_miss set del_flag = '1'
<if test="lineCode != null and lineCode != ''">
where line_code = #{lineCode}
</if>
</update>
<delete id="deleteReally">
delete from emis_tms_site_batch_miss
<if test="lineCode != null and lineCode != ''">
where line_code = #{lineCode}
</if>
</delete>
<update id="deleteByBillCodes">
update emis_tms_site_batch_miss set del_flag = '1'
where bill_code in
<foreach collection="billCodes" item="billCode" open="(" separator="," close=")">
#{billCode}
</foreach>
</update>
<insert id="batchInsertEmisTmsSiteBatchMiss" parameterType="java.util.List">
insert into emis_tms_site_batch_miss
(trans_plan_rule_id, bill_code, miss_reason, line_code,manager, product_type,
start_site_code, next_site_code, supplier_code, start_date, end_date,
create_by, create_time, update_by, update_time, remark,
create_site, update_site, miss_type)
values
<foreach collection="list" item="item" separator=",">
(
#{item.transPlanRuleId,jdbcType=BIGINT},
#{item.billCode,jdbcType=VARCHAR},
#{item.missReason,jdbcType=VARCHAR},
#{item.lineCode,jdbcType=VARCHAR},
#{item.manager,jdbcType=VARCHAR},
#{item.productType,jdbcType=VARCHAR},
#{item.startSiteCode,jdbcType=VARCHAR},
#{item.nextSiteCode,jdbcType=VARCHAR},
#{item.supplierCode,jdbcType=VARCHAR},
#{item.startDate,jdbcType=TIMESTAMP},
#{item.endDate,jdbcType=TIMESTAMP},
#{item.createBy,jdbcType=VARCHAR},
#{item.createTime,jdbcType=TIMESTAMP},
#{item.updateBy,jdbcType=VARCHAR},
#{item.updateTime,jdbcType=TIMESTAMP},
#{item.remark,jdbcType=VARCHAR},
#{item.createSite,jdbcType=VARCHAR},
#{item.updateSite,jdbcType=VARCHAR},
#{item.missType,jdbcType=VARCHAR}
)
</foreach>
</insert>
<select id="selectByBillCodeCount" parameterType="Integer" resultMap="EmisTmsSiteBatchMissResult">
SELECT t.*
FROM emis_tms_site_batch_miss t
WHERE t.bill_code IN (
SELECT bill_code
FROM emis_tms_site_batch_miss
GROUP BY bill_code
HAVING COUNT(*) = #{count}
)
</select>
<select id="selectByBillCodes" resultMap="com.xdadan.erp.emis.mapper.EmisWaybillMapper.EmisWaybillResult">
select a.id, a.bill_code,a.trans_line_type,
a.product_type,a.start_site_code,a.send_site_code,a.problem_type,a.virtual_remark
from emis_waybill a
where bill_code in
<foreach collection="billCodes" item="billCode" open="(" separator="," close=")">
#{billCode}
</foreach>
</select>
</mapper>