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

309 lines
19 KiB
XML
Raw Normal View History

2024-10-10 02:18:56 +00:00
<?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.EmisTmsCostProfitMapper">
2024-10-10 02:18:56 +00:00
<resultMap type="EmisTmsCostProfit" id="EmisTmsCostProfitResult">
<result property="id" column="id" />
<result property="billCode" column="bill_code" />
2025-06-30 08:32:49 +00:00
<result property="billMonth" column="bill_month" />
2024-10-10 02:18:56 +00:00
<result property="standardFee" column="standard_fee" />
<result property="billFee" column="bill_fee" />
<result property="costFee" column="cost_fee" />
<result property="billProfit" column="bill_profit" />
<result property="satisfyMoney" column="satisfy_money" />
<result property="allowanceMoney" column="allowance_money" />
<result property="deductionMoney" column="deduction_money" />
<result property="otherMoney" column="other_money" />
<result property="batchStatus" column="batch_status" />
<result property="costStatus" column="cost_status" />
2024-10-10 02:18:56 +00:00
</resultMap>
2024-10-13 12:32:26 +00:00
<resultMap id="EmisTmsCostProfitWithSubBillResult" type="EmisTmsCostProfit" extends="EmisTmsCostProfitResult" >
<association property="waybillDetail"
column="bill_code"
select="com.xdadan.erp.emis.mapper.EmisWaybillMapper.selectWaybillBaseInfoByBillCode"
fetchType="lazy"
/>
</resultMap>
2024-10-10 02:18:56 +00:00
<sql id="selectEmisTmsCostProfitVo">
2025-06-30 08:32:49 +00:00
select id, bill_code,bill_month, standard_fee, bill_fee, cost_fee, bill_profit,
satisfy_money, allowance_money, deduction_money, other_money,
2025-02-23 12:05:08 +00:00
remark, del_flag, create_by, create_time, update_by, update_time, create_site, update_site
from emis_tms_cost_profit
2024-10-10 02:18:56 +00:00
</sql>
2025-02-23 09:17:09 +00:00
<select id="selectEmisTmsCostProfitList" parameterType="EmisTmsCostProfit" resultMap="EmisTmsCostProfitWithSubBillResult">
2025-02-23 10:55:42 +00:00
select
2025-06-30 09:05:35 +00:00
b.id, b.bill_code,b.bill_month, b.standard_fee, b.bill_fee, b.cost_fee, b.bill_profit,
b.satisfy_money, b.allowance_money, b.deduction_money, b.other_money,
b.remark, b.del_flag, b.create_by, b.create_time, b.update_by, b.update_time, b.create_site, b.update_site,
CASE
WHEN EXISTS (SELECT 1 FROM emis_waybill_batch_status ewbs WHERE ewbs.bill_code = a.bill_code AND ewbs.del_flag = '0') THEN '1'
WHEN NOT EXISTS (SELECT 1 FROM emis_tms_site_batch_dtl etsbd INNER JOIN emis_tms_site_batch etsb ON etsbd.batch_no = etsb.batch_no WHERE etsbd.bill_code = a.bill_code AND etsbd.del_flag = '0' AND etsb.del_flag = '0') THEN '2'
ELSE '3'
END as batch_status,
CASE
WHEN EXISTS (SELECT 1 FROM emis_waybill_batch_status ewbs WHERE ewbs.bill_code = a.bill_code AND ewbs.del_flag = '0')
AND EXISTS (SELECT 1 FROM emis_tms_site_batch_dtl etsbd INNER JOIN emis_tms_site_batch etsb ON etsbd.batch_no = etsb.batch_no WHERE etsbd.bill_code = a.bill_code AND etsbd.del_flag = '0' AND etsb.del_flag = '0')
AND NOT EXISTS (SELECT 1 FROM emis_tms_site_batch_dtl etsbd INNER JOIN emis_tms_site_batch etsb ON etsbd.batch_no = etsb.batch_no WHERE etsbd.bill_code = a.bill_code AND etsbd.del_flag = '0' AND etsb.del_flag = '0' AND (etsb.bl_entering IS NULL OR etsb.bl_entering != '1')) THEN '1'
WHEN NOT EXISTS (SELECT 1 FROM emis_tms_site_batch_dtl etsbd INNER JOIN emis_tms_site_batch etsb ON etsbd.batch_no = etsb.batch_no WHERE etsbd.bill_code = a.bill_code AND etsbd.del_flag = '0' AND etsb.del_flag = '0' AND etsb.bl_entering = '1') THEN '2'
ELSE '3'
END as cost_status
2025-02-23 12:05:08 +00:00
from emis_tms_cost_profit b,emis_waybill a
2025-02-23 10:55:42 +00:00
<where>
a.bill_code=b.bill_code and a.del_flag='0' and b.del_flag='0'
and not EXISTS (
select 1 from emis_waybill_problem_info ewpi where a.bill_code=ewpi.bill_code and ewpi.del_flag='0' and ewpi.`problem_type` in(151)
)
2025-02-23 11:52:38 +00:00
<if test="id != null "> and b.id = #{id}</if>
2025-07-02 06:40:39 +00:00
<if test="billCode != null and billCode != ''">and ( FIND_IN_SET(b.`bill_code`,#{billCode}) )</if>
2025-02-23 11:52:38 +00:00
<if test="standardFee != null "> and b.standard_fee = #{standardFee}</if>
<if test="billFee != null "> and b.bill_fee = #{billFee}</if>
<if test="costFee != null "> and b.cost_fee = #{costFee}</if>
<if test="billProfit != null "> and b.bill_profit = #{billProfit}</if>
<if test="satisfyMoney != null "> and b.satisfy_money = #{satisfyMoney}</if>
<if test="allowanceMoney != null "> and b.allowance_money = #{allowanceMoney}</if>
<if test="deductionMoney != null "> and b.deduction_money = #{deductionMoney}</if>
<if test="otherMoney != null "> and b.other_money = #{otherMoney}</if>
2025-02-23 11:52:38 +00:00
<if test="remark != null and remark != ''"> and b.remark like concat('%', #{remark}, '%')</if>
<if test="delFlag != null and delFlag != ''"> and b.del_flag like concat('%', #{delFlag}, '%')</if>
<if test="createBy != null and createBy != ''"> and b.create_by like concat('%', #{createBy}, '%')</if>
<if test="createTime != null "> and b.create_time = #{createTime}</if>
<if test="updateBy != null and updateBy != ''"> and b.update_by like concat('%', #{updateBy}, '%')</if>
<if test="updateTime != null "> and b.update_time = #{updateTime}</if>
<if test="createSite != null and createSite != ''"> and b.create_site like concat('%', #{createSite}, '%')</if>
<if test="updateSite != null and updateSite != ''"> and b.update_site like concat('%', #{updateSite}, '%')</if>
2025-02-23 10:55:42 +00:00
<if test="params.sendSiteCode != null and params.sendSiteCode != ''">
and a.send_site_code = #{params.sendSiteCode}
</if>
<if test="params.dispatchUnderlingSiteCode != null and params.dispatchUnderlingSiteCode != ''">
and a.dispatch_underling_site_code = #{params.dispatchUnderlingSiteCode}
</if>
2025-02-23 11:01:31 +00:00
<if test="params.custNo != null and params.custNo != ''">
and a.cust_no=#{params.custNo}
</if>
2025-02-23 10:55:42 +00:00
<if test="params.receiveCompany != null and params.receiveCompany != ''">
and a.receive_company like concat('%', #{params.receiveCompany}, '%')
</if>
<if test="params.sendCompany != null and params.sendCompany != ''">
and a.send_company like concat('%', #{params.sendCompany}, '%')
</if>
<if test="params.transLineType != null and params.transLineType != ''">
and a.trans_line_type = #{params.transLineType}
</if>
<if test="params.productType != null and params.productType != ''">
and a.product_type = #{params.productType}
</if>
<if test="params.payee != null and params.payee != ''">
and a.payee = #{params.payee}
</if>
<if test="params.salesmen != null and params.salesmen != ''">
and a.salesmen = #{params.salesmen}
</if>
<if test="params.paymentType != null and params.paymentType != ''">
and a.payment_type = #{params.paymentType}
</if>
<if test="params.blSpecialQuote != null and params.blSpecialQuote != ''">
and a.bl_special_quote = #{params.blSpecialQuote}
</if>
<if test="params.calcFeeType != null and params.calcFeeType != ''">
and a.calc_fee_type = #{params.calcFeeType}
</if>
2025-07-01 23:09:20 +00:00
<!-- 组批次完整: blIsBatchOk=1 blIsBatchOk=-1 不完整 -->
<if test="params.blIsBatchOk != null and params.blIsBatchOk == 1 ">
and exists (
select 1 from emis_waybill_batch_status ewbs where a.bill_code=ewbs.bill_code
)
</if>
<if test="params.blIsBatchOk != null and params.blIsBatchOk == -1 ">
and not exists (
select 1 from emis_waybill_batch_status ewbs where a.bill_code=ewbs.bill_code
)
</if>
<!-- 费用是否录入完整: blIsCostFeeOk=1 blIsCostFeeOk=-1 不完整 -->
<if test="params.blIsCostFeeOk != null and params.blIsCostFeeOk == 1 ">
and exists (
select 1 from emis_waybill_batch_status ewbs where a.bill_code=ewbs.bill_code
)
</if>
<if test="params.blIsCostFeeOk != null and params.blIsCostFeeOk == -1 ">
and not exists (
select 1 from emis_waybill_batch_status ewbs where a.bill_code=ewbs.bill_code
)
</if>
2025-02-23 10:55:42 +00:00
<if test="params.beginSendDate != null and params.beginSendDate != ''">
and a.send_date <![CDATA[ >= ]]> #{params.beginSendDate}
</if>
<if test="params.endSendDate != null and params.endSendDate != ''">
and a.send_date <![CDATA[ <= ]]> #{params.endSendDate}
</if>
<!-- 批次状态查询: batchStatus=1 在emis_waybill_batch_status中存在, batchStatus=2 在emis_tms_site_batch中不存在, 其他为3 -->
<if test="params.batchStatus != null and params.batchStatus == 1">
and EXISTS (SELECT 1 FROM emis_waybill_batch_status ewbs WHERE ewbs.bill_code = a.bill_code AND ewbs.del_flag = '0')
</if>
<if test="params.batchStatus != null and params.batchStatus == 2">
and NOT EXISTS (SELECT 1 FROM emis_tms_site_batch_dtl etsbd INNER JOIN emis_tms_site_batch etsb ON etsbd.batch_no = etsb.batch_no WHERE etsbd.bill_code = a.bill_code AND etsbd.del_flag = '0' AND etsb.del_flag = '0')
</if>
<if test="params.batchStatus != null and params.batchStatus == 3">
and (
NOT EXISTS (SELECT 1 FROM emis_waybill_batch_status ewbs WHERE ewbs.bill_code = a.bill_code AND ewbs.del_flag = '0')
AND EXISTS (SELECT 1 FROM emis_tms_site_batch_dtl etsbd INNER JOIN emis_tms_site_batch etsb ON etsbd.batch_no = etsb.batch_no WHERE etsbd.bill_code = a.bill_code AND etsbd.del_flag = '0' AND etsb.del_flag = '0')
)
</if>
<!-- 成本状态查询: costStatus=1 在emis_waybill_batch_status中存在且所有批次bl_entering=1, costStatus=2 不存在批次bl_entering=1, 其他为3 -->
<if test="params.costStatus != null and params.costStatus == 1">
and EXISTS (SELECT 1 FROM emis_waybill_batch_status ewbs WHERE ewbs.bill_code = a.bill_code AND ewbs.del_flag = '0')
and EXISTS (SELECT 1 FROM emis_tms_site_batch_dtl etsbd INNER JOIN emis_tms_site_batch etsb ON etsbd.batch_no = etsb.batch_no WHERE etsbd.bill_code = a.bill_code AND etsbd.del_flag = '0' AND etsb.del_flag = '0')
and NOT EXISTS (SELECT 1 FROM emis_tms_site_batch_dtl etsbd INNER JOIN emis_tms_site_batch etsb ON etsbd.batch_no = etsb.batch_no WHERE etsbd.bill_code = a.bill_code AND etsbd.del_flag = '0' AND etsb.del_flag = '0' AND (etsb.bl_entering IS NULL OR etsb.bl_entering != '1'))
</if>
<if test="params.costStatus != null and params.costStatus == 2">
and NOT EXISTS (SELECT 1 FROM emis_tms_site_batch_dtl etsbd INNER JOIN emis_tms_site_batch etsb ON etsbd.batch_no = etsb.batch_no WHERE etsbd.bill_code = a.bill_code AND etsbd.del_flag = '0' AND etsb.del_flag = '0' AND etsb.bl_entering = '1')
</if>
<if test="params.costStatus != null and params.costStatus == 3">
and EXISTS (SELECT 1 FROM emis_tms_site_batch_dtl etsbd INNER JOIN emis_tms_site_batch etsb ON etsbd.batch_no = etsb.batch_no WHERE etsbd.bill_code = a.bill_code AND etsbd.del_flag = '0' AND etsb.del_flag = '0')
and EXISTS (SELECT 1 FROM emis_tms_site_batch_dtl etsbd INNER JOIN emis_tms_site_batch etsb ON etsbd.batch_no = etsb.batch_no WHERE etsbd.bill_code = a.bill_code AND etsbd.del_flag = '0' AND etsb.del_flag = '0' AND (etsb.bl_entering IS NULL OR etsb.bl_entering != '1'))
and EXISTS (SELECT 1 FROM emis_tms_site_batch_dtl etsbd INNER JOIN emis_tms_site_batch etsb ON etsbd.batch_no = etsb.batch_no WHERE etsbd.bill_code = a.bill_code AND etsbd.del_flag = '0' AND etsb.del_flag = '0' AND ( etsb.bl_entering = '1'))
</if>
2024-10-10 02:18:56 +00:00
</where>
2025-02-23 10:55:42 +00:00
order by b.create_time desc
2024-10-10 02:18:56 +00:00
</select>
<select id="checkUnique" parameterType="EmisTmsCostProfit" resultType="int">
select count(1) from emis_tms_cost_profit
where del_flag='0'
and id = #{id}
and bill_code = #{billCode}
and standard_fee = #{standardFee}
and bill_fee = #{billFee}
and cost_fee = #{costFee}
and bill_profit = #{billProfit}
and remark = #{remark}
and del_flag = #{delFlag}
and create_by = #{createBy}
and create_time = #{createTime}
and update_by = #{updateBy}
and update_time = #{updateTime}
and create_site = #{createSite}
and update_site = #{updateSite}
limit 1
</select>
2024-10-10 02:18:56 +00:00
<select id="selectEmisTmsCostProfitById" parameterType="Long" resultMap="EmisTmsCostProfitResult">
select id, bill_code,bill_month, standard_fee, bill_fee, cost_fee, bill_profit, satisfy_money, allowance_money, deduction_money, other_money, remark, del_flag, create_by, create_time, update_by, update_time, create_site, update_site
2024-10-10 02:18:56 +00:00
from emis_tms_cost_profit a
where a.id = #{id}
</select>
2024-10-13 12:32:26 +00:00
<select id="selectEmisTmsCostProfitByBillCode" parameterType="String" resultMap="EmisTmsCostProfitWithSubBillResult">
select id, bill_code,bill_month, standard_fee, bill_fee, cost_fee, bill_profit, satisfy_money, allowance_money, deduction_money, other_money, remark, del_flag, create_by, create_time, update_by, update_time, create_site, update_site
2024-10-13 12:32:26 +00:00
from emis_tms_cost_profit a
where a.bill_code = #{billCode}
</select>
2025-06-30 08:32:49 +00:00
2024-10-10 02:18:56 +00:00
<insert id="insertEmisTmsCostProfit" parameterType="EmisTmsCostProfit" useGeneratedKeys="true" keyProperty="id">
insert into emis_tms_cost_profit
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="billCode != null and billCode != ''">bill_code,</if>
2025-06-30 08:32:49 +00:00
<if test="billMonth != null and billMonth != ''">bill_month,</if>
2024-10-10 02:18:56 +00:00
<if test="standardFee != null">standard_fee,</if>
<if test="billFee != null">bill_fee,</if>
<if test="costFee != null">cost_fee,</if>
<if test="billProfit != null">bill_profit,</if>
<if test="satisfyMoney != null">satisfy_money,</if>
<if test="allowanceMoney != null">allowance_money,</if>
<if test="deductionMoney != null">deduction_money,</if>
<if test="otherMoney != null">other_money,</if>
2024-10-10 02:18:56 +00:00
<if test="remark != null and remark != ''">remark,</if>
<if test="delFlag != null and delFlag != ''">del_flag,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null and updateBy != ''">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="createSite != null and createSite != ''">create_site,</if>
<if test="updateSite != null and updateSite != ''">update_site,</if>
2025-06-30 08:32:49 +00:00
</trim>
2024-10-10 02:18:56 +00:00
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="billCode != null and billCode != ''">#{billCode},</if>
2025-06-30 08:32:49 +00:00
<if test="billMonth != null and billMonth != ''">#{billMonth},</if>
2024-10-10 02:18:56 +00:00
<if test="standardFee != null">#{standardFee},</if>
<if test="billFee != null">#{billFee},</if>
<if test="costFee != null">#{costFee},</if>
<if test="billProfit != null">#{billProfit},</if>
<if test="satisfyMoney != null">#{satisfyMoney},</if>
<if test="allowanceMoney != null">#{allowanceMoney},</if>
<if test="deductionMoney != null">#{deductionMoney},</if>
<if test="otherMoney != null">#{otherMoney},</if>
2024-10-10 02:18:56 +00:00
<if test="remark != null and remark != ''">#{remark},</if>
<if test="delFlag != null and delFlag != ''">#{delFlag},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null and updateBy != ''">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="createSite != null and createSite != ''">#{createSite},</if>
<if test="updateSite != null and updateSite != ''">#{updateSite},</if>
2025-06-30 08:32:49 +00:00
</trim>
2024-10-10 02:18:56 +00:00
</insert>
<update id="updateEmisTmsCostProfit" parameterType="EmisTmsCostProfit">
update emis_tms_cost_profit
<trim prefix="SET" suffixOverrides=",">
<if test="billCode != null and billCode != ''">bill_code = #{billCode},</if>
2025-06-30 08:32:49 +00:00
<if test="billMonth != null and billMonth != ''">bill_month = #{billMonth},</if>
2024-10-10 02:18:56 +00:00
<if test="standardFee != null">standard_fee = #{standardFee},</if>
<if test="billFee != null">bill_fee = #{billFee},</if>
<if test="costFee != null">cost_fee = #{costFee},</if>
<if test="billProfit != null">bill_profit = #{billProfit},</if>
<if test="satisfyMoney != null">satisfy_money = #{satisfyMoney},</if>
<if test="allowanceMoney != null">allowance_money = #{allowanceMoney},</if>
<if test="deductionMoney != null">deduction_money = #{deductionMoney},</if>
<if test="otherMoney != null">other_money = #{otherMoney},</if>
2024-10-10 02:18:56 +00:00
<if test="remark != null and remark != ''">remark = #{remark},</if>
<if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
<if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="createSite != null and createSite != ''">create_site = #{createSite},</if>
<if test="updateSite != null and updateSite != ''">update_site = #{updateSite},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteEmisTmsCostProfitById" parameterType="Long">
2025-07-02 05:19:51 +00:00
update emis_tms_cost_profit set del_flag='1' where id = #{id}
2024-10-10 02:18:56 +00:00
</delete>
<delete id="deleteEmisTmsCostProfitByIds" parameterType="String">
2025-07-02 05:19:51 +00:00
update emis_tms_cost_profit set del_flag='1' where id in
2024-10-10 02:18:56 +00:00
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>