From 243056af2fa01817fb0009d075be2c0f09b35479 Mon Sep 17 00:00:00 2001 From: syruan <15555146157@163.com> Date: Wed, 10 Sep 2025 15:12:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=B7=B2=E7=BB=93=E7=AE=97?= =?UTF-8?q?=E5=8D=8F=E8=AE=AE=E7=9A=84=E7=A7=9F=E8=B5=81=E8=B4=B9=E7=94=A8?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增查询已结算协议明细的 SQL 查询方法 - 修改区间费用计算逻辑,区分已结算和未结算协议 - 优化租赁天数计算逻辑,针对已结算协议进行特殊处理 -修复跨区间租赁的费用计算问题 --- .../service/impl/IwsCostPushServiceImpl.java | 6 +- .../mapper/SltAgreementInfoMapper.java | 5 ++ .../impl/SltAgreementInfoServiceImpl.java | 21 +++--- .../settlement/SltAgreementInfoMapper.xml | 73 ++++++++++++++++++- 4 files changed, 94 insertions(+), 11 deletions(-) diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/service/impl/IwsCostPushServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/service/impl/IwsCostPushServiceImpl.java index ac884bee..ae2d3a13 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/service/impl/IwsCostPushServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/service/impl/IwsCostPushServiceImpl.java @@ -108,7 +108,7 @@ public class IwsCostPushServiceImpl implements IwsCostPushService { costDto.setMonth(month); // 清除旧的费用计算数据 - // cleanSameMonthOldRecords(record); + //cleanSameMonthOldRecords(record); // 插入新的当前月份,并生成记录id iwsCostPushMapper.insertCalcMonthRecord(costDto); @@ -195,11 +195,13 @@ public class IwsCostPushServiceImpl implements IwsCostPushService { // 获取已结算协议 ---- (工器具)本月租赁的区间费用明细 settlementEquipmentCostsDetails = sltAgreementInfoService.selectPeriodCostList(new PeriodCostQueryDto() .setAgreementIds(settlementAgreementList.stream().map(IwsCostPushBean::getAgreementId).collect(Collectors.toList())) + .setSettlementStatus("2") .setStartDate(firstDate).setEndDate(lastDate) .setSltManageType((byte) 1) ); // 把区间计算的租赁费用覆盖已结算的用作展示 for (SltAgreementInfo item : settlementEquipmentCosts) { + item.setLeaseCost(BigDecimal.ZERO); Long agreementId = item.getAgreementId(); List filterArray = settlementEquipmentCostsDetails.stream().filter(obj -> obj.getAgreementId().equals(agreementId)).collect(Collectors.toList()); if (CollectionUtils.isNotEmpty(filterArray)) { @@ -224,12 +226,14 @@ public class IwsCostPushServiceImpl implements IwsCostPushService { // 获取已结算协议 ---- (安全工器具)的本月租赁区间费用明细 settlementSafetyEquipmentCostsDetails = sltAgreementInfoService.selectPeriodCostList(new PeriodCostQueryDto() .setAgreementIds(safetySettlementAgreementList.stream().map(IwsCostPushBean::getAgreementId).collect(Collectors.toList())) + .setSettlementStatus("2") .setStartDate(firstDate) .setEndDate(lastDate) .setSltManageType((byte) 2) ); // 把区间计算的租赁费用覆盖已结算的用作展示 for (SltAgreementInfo item : settlementSafetyEquipmentCosts) { + item.setLeaseCost(BigDecimal.ZERO); Long agreementId = item.getAgreementId(); List filterArray = settlementSafetyEquipmentCostsDetails.stream().filter(obj -> obj.getAgreementId().equals(agreementId)).collect(Collectors.toList()); filterArray.removeIf(Objects::isNull); diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/mapper/SltAgreementInfoMapper.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/mapper/SltAgreementInfoMapper.java index e3098509..20167f8b 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/mapper/SltAgreementInfoMapper.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/mapper/SltAgreementInfoMapper.java @@ -282,6 +282,11 @@ public interface SltAgreementInfoMapper { */ List selectLeasePeriodCostList(PeriodCostQueryDto queryDto); + /** + * 查询区间费用计算结果 -- 已结算明细 -- 只查询租赁费用 + */ + List selectLeasePeriodCostListBySltDetails(PeriodCostQueryDto queryDto); + /** * 查询区间费用-- 冲账记录表 * @param queryDto 查询条件 diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/service/impl/SltAgreementInfoServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/service/impl/SltAgreementInfoServiceImpl.java index 64b9c003..81eb1ffc 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/service/impl/SltAgreementInfoServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/service/impl/SltAgreementInfoServiceImpl.java @@ -29,6 +29,7 @@ import com.bonus.material.settlement.domain.vo.SltInfoVo; import com.bonus.material.settlement.mapper.SltAgreementReduceMapper; import com.bonus.material.task.domain.TmTask; import com.bonus.material.task.mapper.TmTaskMapper; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -54,6 +55,7 @@ import java.util.Objects; * @author xsheng * @date 2024-10-16 */ +@Slf4j @Service public class SltAgreementInfoServiceImpl implements ISltAgreementInfoService { @@ -1155,8 +1157,14 @@ public class SltAgreementInfoServiceImpl implements ISltAgreementInfoService { queryDto.setSltManageType(settlementType); } - // 从数据库查询【基础数据】 - List rawResults = sltAgreementInfoMapper.selectLeasePeriodCostList(queryDto); + List rawResults; + if (StringUtils.isNotBlank(queryDto.getSettlementStatus()) && queryDto.getSettlementStatus().equals("2")) { + // 从数据库slt_agreement_details表查询【已结算明细】 + rawResults = sltAgreementInfoMapper.selectLeasePeriodCostListBySltDetails(queryDto); + } else { + // 从数据库slt_agreement_info表查询【基础数据】 + rawResults = sltAgreementInfoMapper.selectLeasePeriodCostList(queryDto); + } // 从数据库查询【冲账数据】,冲账查询的时候直接过滤了协议和限制具体日期,所以不需要再进行范围过滤 List markResults = sltAgreementInfoMapper.selectPeriodCostListForCharge(queryDto); @@ -1173,6 +1181,7 @@ public class SltAgreementInfoServiceImpl implements ISltAgreementInfoService { // 返回结果 return periodCostResultVos; } catch (Exception e) { + log.error("查询区间费用失败:", e); throw new ServiceException("查询区间费用失败:" + e.getMessage()); } } @@ -1313,22 +1322,16 @@ public class SltAgreementInfoServiceImpl implements ISltAgreementInfoService { // 计算租赁天数 long leaseDays = calculateDaysBetween(calcStartTime, calcEndTime); - // 计算租赁费用 BigDecimal leaseCost = BigDecimal.ZERO; if (result.getComsumable() != null && result.getComsumable() == 1) { - Date startTime =result.getStartTime(); - long startDays = calculateDaysBetween(startTime, calcEndTime); - if (result.getNum() == null) { result.setNum(BigDecimal.ZERO); } - - if(startDays >0) { + if (isDateInRange(result.getStartTime(), inputStartDate, inputEndDate)) { // 消耗性物资直接计算购置价 result.setConsumeCost(result.getNum().multiply(Optional.ofNullable(result.getBuyPrice()).orElse(BigDecimal.ZERO))); } - } if (result.getNum() != null && result.getLeasePrice() != null && leaseDays >= 1) { // 非消耗性物资按照租赁单价计算租赁费用 diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/settlement/SltAgreementInfoMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/settlement/SltAgreementInfoMapper.xml index 02b4e52e..127ffcc1 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/settlement/SltAgreementInfoMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/settlement/SltAgreementInfoMapper.xml @@ -1130,7 +1130,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" mt.type_name as model_name, mt.buy_price, mt1.type_name as type_name, sai.ma_id, sai.num, sai.lease_price, sai.start_time, sai.end_time, - bai.is_slt AS is_settled, + sai.is_slt AS is_settled, sai.slt_time AS settlement_time, sai.status, mt.unit_name as mt_unit_name, mt.comsumable, bai.remark @@ -1271,4 +1271,75 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and bai.agreement_code = #{agreementCode} + + +