demand: TMS系统 - 成本管理 - 运单利润统计 -查询增加理赔金额、折让金额、抵扣金额、其他金额、批次状态、成本状态; TMS系统 - 成本管理 - 运单利润统计 - 批量重算 - 重算利润增加理赔金额、折让金额、抵扣金额、其他金额,运单毛利润重算公式调整

This commit is contained in:
aike 2026-01-27 13:57:04 +08:00
parent 72a702735b
commit 775ffd91e4
3 changed files with 122 additions and 6 deletions

View File

@ -52,6 +52,18 @@ public class EmisTmsCostProfit extends BaseEntity
private BigDecimal costFee;
/* 运单利润 */
private BigDecimal billProfit;
/* 理赔金额 */
private BigDecimal satisfyMoney;
/* 折让金额 */
private BigDecimal allowanceMoney;
/* 抵扣金额 */
private BigDecimal deductionMoney;
/* 其他金额 */
private BigDecimal otherMoney;
/* 批次状态 1:已完成,2:未完成,3:部分完成 */
private String batchStatus;
/* 成本状态 1:已完成,2:未完成,3:部分完成 */
private String costStatus;
// 扩展参数
private EmisWaybill waybillDetail;

View File

@ -77,6 +77,12 @@ public class EmisTmsCostFeeServiceImpl extends EmisBaseService implements IEmisT
@Autowired
private EmisTmsCostQuotePriceMapper emisTmsCostQuotePriceMapper;
@Autowired
private EmisSettleSubBillMapper emisSettleSubBillMapper;
@Autowired
private EmisSettleBillMapper emisSettleBillMapper;
/**
* 查询TMS运输成本账单
* @param id TMS运输成本账单主键
@ -1260,7 +1266,36 @@ public class EmisTmsCostFeeServiceImpl extends EmisBaseService implements IEmisT
// 获取主单成本费用
double costFee=emisTmsCostFeeSplitMapper.getCostFeeByMainBillCode(mainBillCode);
updProfit.setCostFee(BigDecimal.valueOf(costFee));
updProfit.setBillProfit(emisTmsCostProfit.getBillFee().subtract(updProfit.getCostFee()));
// 根据mainBillCode查询账单表获取理赔金额、折让金额、抵扣金额、其他金额
List<EmisSettleSubBill> settleSubBillList = emisSettleSubBillMapper.selectSettleSubBillListByBillCode(mainBillCode);
if (CollectionUtils.isNotEmpty(settleSubBillList)) {
// 获取第一个子账单的settleBillNo
String settleBillNo = settleSubBillList.get(0).getSettleBillNo();
if (StringUtils.isNotBlank(settleBillNo)) {
// 查询该总账单下的所有子账单,判断是否只对应一个运单
List<EmisSettleSubBill> allSubBillList = emisSettleSubBillMapper.selectSubBillListBySettleBillNo(settleBillNo);
if (CollectionUtils.isNotEmpty(allSubBillList) && allSubBillList.size() == 1) {
// 账单只对应一个运单,查询总账单获取理赔金额、折让金额、抵扣金额、其他金额
EmisSettleBill settleBill = emisSettleBillMapper.selectSettleBillBySettleBillNo(settleBillNo);
if (settleBill != null) {
updProfit.setSatisfyMoney(settleBill.getSatisfyMoney() != null ? settleBill.getSatisfyMoney() : BigDecimal.ZERO);
updProfit.setAllowanceMoney(settleBill.getAllowanceMoney() != null ? settleBill.getAllowanceMoney() : BigDecimal.ZERO);
updProfit.setDeductionMoney(settleBill.getDeductionMoney() != null ? settleBill.getDeductionMoney() : BigDecimal.ZERO);
updProfit.setOtherMoney(settleBill.getOtherMoney() != null ? settleBill.getOtherMoney() : BigDecimal.ZERO);
}
}
}
}
// 计算运单利润:运单费用 - 运输成本 - 理赔金额 - 折让金额 - 抵扣金额 - 其他金额
BigDecimal billProfit = emisTmsCostProfit.getBillFee()
.subtract(updProfit.getCostFee())
.subtract(updProfit.getSatisfyMoney() != null ? updProfit.getSatisfyMoney() : BigDecimal.ZERO)
.subtract(updProfit.getAllowanceMoney() != null ? updProfit.getAllowanceMoney() : BigDecimal.ZERO)
.subtract(updProfit.getDeductionMoney() != null ? updProfit.getDeductionMoney() : BigDecimal.ZERO)
.subtract(updProfit.getOtherMoney() != null ? updProfit.getOtherMoney() : BigDecimal.ZERO);
updProfit.setBillProfit(billProfit);
emisTmsCostProfitMapper.updateEmisTmsCostProfit(updProfit);
}

View File

@ -12,6 +12,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<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" />
</resultMap>
<resultMap id="EmisTmsCostProfitWithSubBillResult" type="EmisTmsCostProfit" extends="EmisTmsCostProfitResult" >
@ -24,6 +30,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<sql id="selectEmisTmsCostProfitVo">
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
from emis_tms_cost_profit
@ -32,7 +39,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectEmisTmsCostProfitList" parameterType="EmisTmsCostProfit" resultMap="EmisTmsCostProfitWithSubBillResult">
select
b.id, b.bill_code,b.bill_month, b.standard_fee, b.bill_fee, b.cost_fee, b.bill_profit,
b.remark, b.del_flag, b.create_by, b.create_time, b.update_by, b.update_time, b.create_site, b.update_site
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
from emis_tms_cost_profit b,emis_waybill a
<where>
a.bill_code=b.bill_code and a.del_flag='0' and b.del_flag='0'
@ -42,6 +62,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<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>
<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>
@ -132,6 +156,39 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<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 (
NOT EXISTS (SELECT 1 FROM emis_waybill_batch_status ewbs WHERE ewbs.bill_code = a.bill_code AND ewbs.del_flag = '0')
OR (
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'))
)
)
</if>
</where>
order by b.create_time desc
</select>
@ -157,13 +214,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectEmisTmsCostProfitById" parameterType="Long" resultMap="EmisTmsCostProfitResult">
select id, bill_code,bill_month, standard_fee, bill_fee, cost_fee, bill_profit, remark, del_flag, create_by, create_time, update_by, update_time, create_site, update_site
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
from emis_tms_cost_profit a
where a.id = #{id}
</select>
<select id="selectEmisTmsCostProfitByBillCode" parameterType="String" resultMap="EmisTmsCostProfitWithSubBillResult">
select id, bill_code,bill_month, standard_fee, bill_fee, cost_fee, bill_profit, remark, del_flag, create_by, create_time, update_by, update_time, create_site, update_site
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
from emis_tms_cost_profit a
where a.bill_code = #{billCode}
</select>
@ -178,6 +235,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<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>
<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>
@ -195,6 +256,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<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>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="delFlag != null and delFlag != ''">#{delFlag},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
@ -215,6 +280,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<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>
<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>