shiyunteng
2026-05-25 633a003d232e37c79b7135ccda35eda1c69952c6
feat:统计数据测试调整
13个文件已修改
638 ■■■■■ 已修改文件
platformx-business-finance-api/src/main/java/com/by4cloud/platformx/business/entity/ContractPaymentSchedule.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
platformx-business-finance-api/src/main/java/com/by4cloud/platformx/business/vo/ContractIncomeAnalysisVo.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
platformx-business-finance-api/src/main/java/com/by4cloud/platformx/business/vo/ContractPaymentScheduleVo.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/controller/StatisticController.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/mapper/ContractMapper.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/StatisticService.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractPaymentScheduleProcessServiceImpl.java 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractServiceImpl.java 266 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/OutBoundServiceImpl.java 44 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/PaymentConfirmServiceImpl.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/PaymentOffsetServiceImpl.java 19 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/StatisticServiceImpl.java 66 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
platformx-business-finance-biz/src/main/resources/mapper/ContractMapper.xml 154 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
platformx-business-finance-api/src/main/java/com/by4cloud/platformx/business/entity/ContractPaymentSchedule.java
@@ -102,10 +102,10 @@
    @Column(columnDefinition = "datetime comment '收款日期'")
    private Date paymentDate;
    @Schema(description = "收款阶段生效日期(隐性要素 - 履约时间起点,即该节点实际达成的日期)")
    @Schema(description = "收款阶段生效日期(作废 以截止日期为准)")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm")
    @Column(columnDefinition = "date comment '收款阶段生效日期(履约节点实际达成日期)'")
    @Column(columnDefinition = "date comment '收款阶段生效日期(履约节点实际达成日期) 作废 以截止日期为准'")
    private Date effectiveDate;
    @Schema(description = "收款阶段截止日期")
platformx-business-finance-api/src/main/java/com/by4cloud/platformx/business/vo/ContractIncomeAnalysisVo.java
@@ -5,6 +5,8 @@
@Data
public class ContractIncomeAnalysisVo {
    private String compId;
    private String compName;
    private String srMonth1;
platformx-business-finance-api/src/main/java/com/by4cloud/platformx/business/vo/ContractPaymentScheduleVo.java
@@ -2,13 +2,11 @@
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.Column;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
@Data
public class ContractPaymentScheduleVo {
@@ -18,6 +16,9 @@
    @Schema(description = "收款阶段名称(显性要素,如:合同签订预付、发货前付款、货到签收付款、调试完成付款、质保金)")
    private String stageName;
    @Schema(description = "收款比例(%,如30表示30%)(显性要素)")
    private BigDecimal paymentRatio;
    @Schema(description = "计划收款金额(根据合同总金额*比例自动计算)")
    private BigDecimal plannedAmount;
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/controller/StatisticController.java
@@ -111,4 +111,13 @@
    public R contractAmountAnalysisByExportBus(@RequestBody AnalysisCommonDTO commonDTO) {
        return statisticService.contractAmountAnalysisByExportBus(commonDTO);
    }
    /**
     * 分销售模式合同金额统计
     * @return R
     */
    @PostMapping("/contractAmountAnalysisBySaleModel")
    public R contractAmountAnalysisBySaleModel(@RequestBody AnalysisCommonDTO commonDTO) {
        return statisticService.contractAmountAnalysisBySaleModel(commonDTO);
    }
}
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/mapper/ContractMapper.java
@@ -54,4 +54,9 @@
                                                                         @Param("tfCompId") Long tfgs,@Param("ymjCompId") Long ymj);
    List<ContractAmountAnalysisCompVo> contractAmountAnalysisByComp(@Param("queryDTO")AnalysisCommonDTO commonDTO,@Param("compId") Long compId);
    List<ContractIncomeAnalysisAreaVo> contractAmountAnalysisBySaleModel(@Param("queryDTO")AnalysisCommonDTO commonDTO
            ,@Param("compIds")List<Long> compIds,@Param("smjCompId") Long smj,
                                                                         @Param("sgbCompId")Long sgb, @Param("jxcCompId")Long jxc,
                                                                         @Param("tfCompId") Long tfgs,@Param("ymjCompId") Long ymj);
}
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/StatisticService.java
@@ -21,4 +21,6 @@
    R contractAmountAnalysisByExportBus(AnalysisCommonDTO commonDTO);
    R contractAmountAnalysisByComp(AnalysisCommonDTO commonDTO);
    R contractAmountAnalysisBySaleModel(AnalysisCommonDTO commonDTO);
}
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractPaymentScheduleProcessServiceImpl.java
@@ -81,17 +81,17 @@
        //更新当前阶段
        if (ObjUtil.isNull(schedule.getEffectiveDate()) && ObjUtil.isNull(schedule.getEffectiveEndDate())) {
            schedule.setEffectiveDate(DateUtil.offsetDay(addDTO.getProcessDate(), schedule.getAgreedDays()));
            schedule.setEffectiveEndDate(DateUtil.offsetDay(addDTO.getProcessDate(), schedule.getAgreedDays()));
            contractPaymentScheduleMapper.updateById(schedule);
        }
        //查询是否有之前阶段
        ContractPaymentSchedule beforeSchedule = contractPaymentScheduleMapper.selectOne(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, schedule.getContractId())
                .lt(ContractPaymentSchedule::getStageOrder, schedule.getStageOrder()).orderByDesc(ContractPaymentSchedule::getCreateTime).last("limit 1"));
        if (ObjUtil.isNotNull(beforeSchedule) && ObjUtil.isNull(beforeSchedule.getEffectiveEndDate())) {
            beforeSchedule.setEffectiveEndDate(schedule.getEffectiveDate());
            contractPaymentScheduleMapper.updateById(beforeSchedule);
        }
//        //查询是否有之前阶段
//        ContractPaymentSchedule beforeSchedule = contractPaymentScheduleMapper.selectOne(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, schedule.getContractId())
//                .lt(ContractPaymentSchedule::getStageOrder, schedule.getStageOrder()).orderByDesc(ContractPaymentSchedule::getCreateTime).last("limit 1"));
//        if (ObjUtil.isNotNull(beforeSchedule) && ObjUtil.isNull(beforeSchedule.getEffectiveEndDate())) {
//            beforeSchedule.setEffectiveEndDate(schedule.getEffectiveDate());
//            contractPaymentScheduleMapper.updateById(beforeSchedule);
//        }
        List<ContractOutBound> contractOutBoundList = contractOutBoundMapper.selectList(Wrappers.<ContractOutBound>lambdaQuery().eq(ContractOutBound::getContractId, contract.getId())
                .isNotNull(ContractOutBound::getArrivalTime));
@@ -186,13 +186,11 @@
                        //最后阶段生效时间
                        ContractPaymentSchedule endSchedule = afterSchedule.get(0);
                        if (StrUtil.equals(endSchedule.getStageName(), "质保金")) {
                            endSchedule.setEffectiveDate(DateUtil.offsetDay(addDTO.getProcessDate(), endSchedule.getAgreedDays()));
                            endSchedule.setEffectiveEndDate(contract.getExpirationDate());
                            endSchedule.setEffectiveEndDate(DateUtil.offsetDay(addDTO.getProcessDate(), endSchedule.getAgreedDays()));
                            contractPaymentScheduleMapper.updateById(endSchedule);
                            //当前阶段生效时间
                            schedule.setEffectiveDate(DateUtil.offsetDay(addDTO.getProcessDate(), schedule.getAgreedDays()));
                            schedule.setEffectiveEndDate(endSchedule.getEffectiveDate());
                            contractPaymentScheduleMapper.updateById(schedule);
//                            schedule.setEffectiveEndDate(DateUtil.offsetDay(addDTO.getProcessDate(), schedule.getAgreedDays()));
//                            contractPaymentScheduleMapper.updateById(schedule);
                            //最后阶段应收
                            PaymentConfirm newConfim = new PaymentConfirm();
                            newConfim.setBusinessType(endSchedule.getStageName() + "应收");
@@ -228,8 +226,8 @@
                        contractMapper.updateById(contract);
                    }
                    if (ArrayUtil.isEmpty(afterSchedule.toArray())) {
                        schedule.setEffectiveEndDate(contract.getExpirationDate());
                        contractPaymentScheduleMapper.updateById(schedule);
//                        schedule.setEffectiveEndDate(contract.getExpirationDate());
//                        contractPaymentScheduleMapper.updateById(schedule);
                        //更新合同下个阶段
                        contract.setNextScheduleName("无");
                        contractMapper.updateById(contract);
@@ -277,12 +275,10 @@
                //最后阶段生效时间
                ContractPaymentSchedule endSchedule = afterSchedule.get(0);
                if (StrUtil.equals(endSchedule.getStageName(), "质保金")) {
                    endSchedule.setEffectiveDate(DateUtil.offsetDay(addDTO.getProcessDate(), endSchedule.getAgreedDays()));
                    endSchedule.setEffectiveEndDate(contract.getExpirationDate());
                    endSchedule.setEffectiveEndDate(DateUtil.offsetDay(addDTO.getProcessDate(), endSchedule.getAgreedDays()));
                    contractPaymentScheduleMapper.updateById(endSchedule);
                    //当前阶段生效时间
                    schedule.setEffectiveDate(DateUtil.offsetDay(addDTO.getProcessDate(), schedule.getAgreedDays()));
                    schedule.setEffectiveEndDate(endSchedule.getEffectiveDate());
                    schedule.setEffectiveEndDate(DateUtil.offsetDay(addDTO.getProcessDate(), schedule.getAgreedDays()));
                    contractPaymentScheduleMapper.updateById(schedule);
                    //最后阶段应收
                    PaymentConfirm newConfim = new PaymentConfirm();
@@ -319,8 +315,8 @@
                contractMapper.updateById(contract);
            }
            if (ArrayUtil.isEmpty(afterSchedule.toArray())) {
                schedule.setEffectiveEndDate(contract.getExpirationDate());
                contractPaymentScheduleMapper.updateById(schedule);
//                schedule.setEffectiveEndDate(contract.getExpirationDate());
//                contractPaymentScheduleMapper.updateById(schedule);
                //更新合同下个阶段
                contract.setNextScheduleName("无");
                contractMapper.updateById(contract);
@@ -396,7 +392,7 @@
                        ContractPaymentSchedule::getPlannedAmount, ContractPaymentSchedule::getPlannedAmount,
                        ContractPaymentSchedule::getEffectiveEndDate, ContractPaymentSchedule::getPaymentDate,
                        ContractPaymentSchedule::getPaymentStatus, ContractPaymentSchedule::getActualAmount,
                        ContractPaymentSchedule::getAgreedDays)
                        ContractPaymentSchedule::getAgreedDays,ContractPaymentSchedule::getPaymentRatio)
                .select(ContractPaymentScheduleProcess::getProcessDate)
                .leftJoin(ContractPaymentScheduleProcess.class, ContractPaymentScheduleProcess::getScheduleId, ContractPaymentSchedule::getId)
                .eq(ContractPaymentSchedule::getContractId, id)
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractServiceImpl.java
@@ -64,7 +64,7 @@
    @Override
    public R add(ContractAddDTO addDTO) {
        Contract contract = BeanUtil.copyProperties(addDTO,Contract.class);
        Contract contract = BeanUtil.copyProperties(addDTO, Contract.class);
        contract.setPartyBId(SecurityUtils.getUser().getCompId());
        contract.setPartyB(SecurityUtils.getUser().getCompName());
        contract.setContractNo(ContractNumberGenerator.generateContractNumber());
@@ -72,14 +72,14 @@
        contract.setBillingStatus("0");
        contract.setErpPushFlag("0");
        List<Contract> contracts;
        contracts = baseMapper.selectList(Wrappers.<Contract>lambdaQuery().eq(Contract::getContractNo,contract.getContractNo()));
        while (ArrayUtil.isNotEmpty(contracts.toArray())){
        contracts = baseMapper.selectList(Wrappers.<Contract>lambdaQuery().eq(Contract::getContractNo, contract.getContractNo()));
        while (ArrayUtil.isNotEmpty(contracts.toArray())) {
            contract.setContractNo(ContractNumberGenerator.generateContractNumber());
            contracts = baseMapper.selectList(Wrappers.<Contract>lambdaQuery().eq(Contract::getContractNo,contract.getContractNo()));
            contracts = baseMapper.selectList(Wrappers.<Contract>lambdaQuery().eq(Contract::getContractNo, contract.getContractNo()));
        }
        baseMapper.insert(contract);
        if (ArrayUtil.isNotEmpty(addDTO.getContractSubjectMatter())){
        if (ArrayUtil.isNotEmpty(addDTO.getContractSubjectMatter())) {
            addDTO.getContractSubjectMatter().stream().forEach(contractSubjectMatterAddDTO -> {
                ContractSubjectMatter subjectMatter = BeanUtil.copyProperties(contractSubjectMatterAddDTO, ContractSubjectMatter.class);
                subjectMatter.setContractId(contract.getId());
@@ -91,13 +91,13 @@
            });
        }
        if (ArrayUtil.isNotEmpty(addDTO.getContractPaymentSchedule())){
        if (ArrayUtil.isNotEmpty(addDTO.getContractPaymentSchedule())) {
            AtomicInteger index = new AtomicInteger(1);
            addDTO.getContractPaymentSchedule().stream().forEach(contractPaymentScheduleAddDTO -> {
                int currentIndex = index.getAndIncrement();
                ContractPaymentSchedule schedule = BeanUtil.copyProperties(contractPaymentScheduleAddDTO, ContractPaymentSchedule.class);
                if (contractPaymentScheduleAddDTO.getStageName().equals("合同签订")){
                    schedule.setEffectiveDate(DateUtil.offsetDay(contract.getSignDate(),contractPaymentScheduleAddDTO.getAgreedDays()));
                if (contractPaymentScheduleAddDTO.getStageName().equals("合同签订")) {
                    schedule.setEffectiveEndDate(DateUtil.offsetDay(contract.getSignDate(), contractPaymentScheduleAddDTO.getAgreedDays()));
                }
                if (ObjUtil.isNotNull(schedule.getEffectiveDate())) {
                    if (schedule.getEffectiveDate().before(DateUtil.date())) {
@@ -106,17 +106,21 @@
                        schedule.setFulfillmentStatus(0);
                    }
                }
                schedule.setPaymentStatus(0);
                if (contractPaymentScheduleAddDTO.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) {
                    schedule.setPaymentStatus(0);
                }else {
                    schedule.setPaymentStatus(3);
                }
                schedule.setContractId(contract.getId());
                schedule.setContractName(contract.getContractName());
                schedule.setPlannedAmount(contract.getAmount().multiply(schedule.getPaymentRatio().divide(new BigDecimal("100"))));
                schedule.setStageOrder(currentIndex);
                contractPaymentScheduleMapper.insert(schedule);
                if (contractPaymentScheduleAddDTO.getStageName().equals("货到签收")){
                if (contractPaymentScheduleAddDTO.getStageName().equals("货到签收")) {
                    contract.setArrivalScheduleId(schedule.getId());
                    baseMapper.updateById(contract);
                }
                if (contractPaymentScheduleAddDTO.getStageName().equals("调试完成或验收")){
                if (contractPaymentScheduleAddDTO.getStageName().equals("调试完成或验收")) {
                    contract.setAcceptScheduleId(schedule.getId());
                    baseMapper.updateById(contract);
                }
@@ -125,31 +129,30 @@
        }
        return R.ok();
    }
    @Override
    public R edit(ContractUpdateDTO updateDTO) {
        Contract entity = baseMapper.selectById(updateDTO.getId());
        if (!StrUtil.equals(entity.getContractStatus()+"","0")){
        if (!StrUtil.equals(entity.getContractStatus() + "", "0")) {
            return R.failed("当前状态无法修改合同");
        }
        Contract contract = BeanUtil.copyProperties(updateDTO,Contract.class);
        Contract contract = BeanUtil.copyProperties(updateDTO, Contract.class);
        contract.setContractNo(ContractNumberGenerator.generateContractNumber());
        contract.setBillingStatus("0");
        contract.setErpPushFlag("0");
        contract.setPaidAmount(new BigDecimal("0"));
        List<Contract> contracts;
        contracts = baseMapper.selectList(Wrappers.<Contract>lambdaQuery().eq(Contract::getContractNo,contract.getContractNo()));
        while (ArrayUtil.isNotEmpty(contracts.toArray())){
        contracts = baseMapper.selectList(Wrappers.<Contract>lambdaQuery().eq(Contract::getContractNo, contract.getContractNo()));
        while (ArrayUtil.isNotEmpty(contracts.toArray())) {
            contract.setContractNo(ContractNumberGenerator.generateContractNumber());
            contracts = baseMapper.selectList(Wrappers.<Contract>lambdaQuery().eq(Contract::getContractNo,contract.getContractNo()));
            contracts = baseMapper.selectList(Wrappers.<Contract>lambdaQuery().eq(Contract::getContractNo, contract.getContractNo()));
        }
        baseMapper.updateById(contract);
        if (ArrayUtil.isNotEmpty(updateDTO.getContractSubjectMatter())){
            contractSubjectMatterMapper.delete(Wrappers.<ContractSubjectMatter>lambdaQuery().eq(ContractSubjectMatter::getContractId,contract.getId()));
        if (ArrayUtil.isNotEmpty(updateDTO.getContractSubjectMatter())) {
            contractSubjectMatterMapper.delete(Wrappers.<ContractSubjectMatter>lambdaQuery().eq(ContractSubjectMatter::getContractId, contract.getId()));
            updateDTO.getContractSubjectMatter().stream().forEach(contractSubjectMatterAddDTO -> {
                ContractSubjectMatter subjectMatter = BeanUtil.copyProperties(contractSubjectMatterAddDTO, ContractSubjectMatter.class);
@@ -161,8 +164,8 @@
            });
        }
        if (ArrayUtil.isNotEmpty(updateDTO.getContractPaymentSchedule())){
            contractPaymentScheduleMapper.delete(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId,contract.getId()));
        if (ArrayUtil.isNotEmpty(updateDTO.getContractPaymentSchedule())) {
            contractPaymentScheduleMapper.delete(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, contract.getId()));
            AtomicInteger index = new AtomicInteger(1);
            updateDTO.getContractPaymentSchedule().stream().forEach(contractPaymentScheduleAddDTO -> {
@@ -172,12 +175,17 @@
                schedule.setContractName(contract.getContractName());
                schedule.setPlannedAmount(contract.getAmount().multiply(schedule.getPaymentRatio().divide(new BigDecimal("100"))));
                schedule.setStageOrder(currentIndex);
                if (contractPaymentScheduleAddDTO.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) {
                    schedule.setPaymentStatus(0);
                }else {
                    schedule.setPaymentStatus(3);
                }
                contractPaymentScheduleMapper.insert(schedule);
                if (contractPaymentScheduleAddDTO.getStageName().equals("货到签收")){
                if (contractPaymentScheduleAddDTO.getStageName().equals("货到签收")) {
                    contract.setArrivalScheduleId(schedule.getId());
                    baseMapper.updateById(contract);
                }
                if (contractPaymentScheduleAddDTO.getStageName().equals("调试完成或验收")){
                if (contractPaymentScheduleAddDTO.getStageName().equals("调试完成或验收")) {
                    contract.setAcceptScheduleId(schedule.getId());
                    baseMapper.updateById(contract);
                }
@@ -191,10 +199,10 @@
    @Override
    public ContractDetailVo detail(Long id) {
        Contract contract = baseMapper.selectById(id);
        ContractDetailVo detailVo = BeanUtil.copyProperties(contract,ContractDetailVo.class);
        List<ContractSubjectMatter> subjectMatterList = contractSubjectMatterMapper.selectList(Wrappers.<ContractSubjectMatter>lambdaQuery().eq(ContractSubjectMatter::getContractId,id));
        ContractDetailVo detailVo = BeanUtil.copyProperties(contract, ContractDetailVo.class);
        List<ContractSubjectMatter> subjectMatterList = contractSubjectMatterMapper.selectList(Wrappers.<ContractSubjectMatter>lambdaQuery().eq(ContractSubjectMatter::getContractId, id));
        detailVo.setContractSubjectMatter(subjectMatterList);
        List<ContractPaymentSchedule> paymentScheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId,contract.getId()));
        List<ContractPaymentSchedule> paymentScheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, contract.getId()));
        detailVo.setContractPaymentSchedule(paymentScheduleList);
        return detailVo;
    }
@@ -220,11 +228,11 @@
        Contract contract = baseMapper.selectById(id);
        contract.setContractStatus(2);
        baseMapper.updateById(contract);
        ContractPaymentSchedule fitstSchedule = contractPaymentScheduleMapper.selectOne(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId,contract.getId())
        ContractPaymentSchedule fitstSchedule = contractPaymentScheduleMapper.selectOne(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, contract.getId())
                .orderByAsc(ContractPaymentSchedule::getCreateTime).last("limit 1"));
        if (fitstSchedule.getStageName().equals("合同签订")){
        if (fitstSchedule.getStageName().equals("合同签订")) {
            //新增应收
            savePaymentConfirm(contract,fitstSchedule);
            savePaymentConfirm(contract, fitstSchedule);
            //新增合同履约记录
            ContractPaymentScheduleProcess process = new ContractPaymentScheduleProcess();
@@ -242,42 +250,36 @@
//                contract.setContractStatus(3);
//                baseMapper.updateById(contract);
//            }
        }else if (fitstSchedule.getStageName().equals("发货前")) {
        } else if (fitstSchedule.getStageName().equals("发货前")) {
            //更新合同下个阶段
            contract.setNextScheduleName("无");
            baseMapper.updateById(contract);
        }else if (fitstSchedule.getStageName().equals("货到签收")) {
        } else if (fitstSchedule.getStageName().equals("货到签收")) {
            //更新合同下个阶段
            contract.setNextScheduleName("货到签收");
            baseMapper.updateById(contract);
        }else if (fitstSchedule.getStageName().equals("调试完成或验收")) {
        } else if (fitstSchedule.getStageName().equals("调试完成或验收")) {
            //更新合同下个阶段
            contract.setNextScheduleName("调试完成或验收");
            baseMapper.updateById(contract);
        }else {
        } else {
            //新增应收
            savePaymentConfirm(contract,fitstSchedule);
            savePaymentConfirm(contract, fitstSchedule);
        }
        //查询是否有后续阶段
        List<ContractPaymentSchedule> afterSchedule = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery()
                .eq(ContractPaymentSchedule::getContractId, fitstSchedule.getContractId())
                .gt(ContractPaymentSchedule::getStageOrder, fitstSchedule.getStageOrder())
                .orderByAsc(ContractPaymentSchedule::getCreateTime));
        if (ArrayUtil.isNotEmpty(afterSchedule.toArray())&&afterSchedule.size()==1){
        if (ArrayUtil.isNotEmpty(afterSchedule.toArray()) && afterSchedule.size() == 1) {
            //最后阶段生效时间
            ContractPaymentSchedule endSchedule = afterSchedule.get(0);
            if (StrUtil.equals(endSchedule.getStageName(),"质保金")){
                endSchedule.setEffectiveDate(DateUtil.offsetDay(new Date(),endSchedule.getAgreedDays()));
                endSchedule.setEffectiveEndDate(contract.getExpirationDate());
                contractPaymentScheduleMapper.updateById(endSchedule);
                //第一阶段生效时间
                fitstSchedule.setEffectiveDate(DateUtil.offsetDay(contract.getSignDate(),fitstSchedule.getAgreedDays()));
                fitstSchedule.setEffectiveEndDate(endSchedule.getEffectiveDate());
                contractPaymentScheduleMapper.updateById(fitstSchedule);
            if (StrUtil.equals(endSchedule.getStageName(), "质保金")) {
//                endSchedule.setEffectiveEndDate(DateUtil.offsetDay(new Date(),endSchedule.getAgreedDays()));
//                contractPaymentScheduleMapper.updateById(endSchedule);
                //最后阶段应收
                PaymentConfirm newConfim = new PaymentConfirm();
                newConfim.setBusinessType(endSchedule.getStageName()+"应收");
                newConfim.setBusinessType(endSchedule.getStageName() + "应收");
                newConfim.setBusGuestId(contract.getPartyAId());
                newConfim.setBusGuestName(contract.getPartyA());
                newConfim.setContractId(contract.getId());
@@ -288,14 +290,14 @@
                newConfim.setConfirmTime(new Date());
                newConfim.setTransationAmount(endSchedule.getPlannedAmount());
                newConfim.setReceivableAmount(endSchedule.getPlannedAmount());
                PaymentConfirm lastNewConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId,contract.getId())
                PaymentConfirm lastNewConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, contract.getId())
                        .orderByDesc(PaymentConfirm::getCreateTime).last("limit 1"));
                BigDecimal lastNewTotal = new BigDecimal("0");
                if(ObjUtil.isNotNull(lastNewConfirm)){
                if (ObjUtil.isNotNull(lastNewConfirm)) {
                    lastNewTotal = lastNewConfirm.getTotalAmount();
                }
                newConfim.setTotalAmount(lastNewTotal.subtract(newConfim.getReceivableAmount()));
                if (endSchedule.getPaymentRatio().compareTo(new BigDecimal("0"))>0) {
                if (endSchedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) {
                    paymentConfirmMapper.insert(newConfim);
                }
            }
@@ -303,25 +305,24 @@
            contract.setNextScheduleName(endSchedule.getStageName());
            baseMapper.updateById(contract);
        }
        if(ArrayUtil.isNotEmpty(afterSchedule.toArray())&&afterSchedule.size()>1){
        if (ArrayUtil.isNotEmpty(afterSchedule.toArray()) && afterSchedule.size() > 1) {
            //第一阶段生效时间
            fitstSchedule.setEffectiveDate(DateUtil.offsetDay(contract.getSignDate(),fitstSchedule.getAgreedDays()));
            contractPaymentScheduleMapper.updateById(fitstSchedule);
//            fitstSchedule.setEffectiveEndDate(DateUtil.offsetDay(contract.getSignDate(),fitstSchedule.getAgreedDays()));
//            contractPaymentScheduleMapper.updateById(fitstSchedule);
            //更新合同下个阶段
            contract.setNextScheduleName(afterSchedule.get(0).getStageName());
            baseMapper.updateById(contract);
        }
        //只有当前合同签字阶段
        if(ArrayUtil.isEmpty(afterSchedule.toArray())){
            fitstSchedule.setEffectiveDate(DateUtil.offsetDay(contract.getSignDate(),fitstSchedule.getAgreedDays()));
            fitstSchedule.setEffectiveEndDate(contract.getExpirationDate());
            contractPaymentScheduleMapper.updateById(fitstSchedule);
        }
//        if(ArrayUtil.isEmpty(afterSchedule.toArray())){
//            fitstSchedule.setEffectiveEndDate(DateUtil.offsetDay(contract.getSignDate(),fitstSchedule.getAgreedDays()));
//            contractPaymentScheduleMapper.updateById(fitstSchedule);
//        }
    }
    private void savePaymentConfirm(Contract contract, ContractPaymentSchedule schedule) {
        PaymentConfirm paymentConfirm = new PaymentConfirm();
        paymentConfirm.setBusinessType(schedule.getStageName()+"应收");
        paymentConfirm.setBusinessType(schedule.getStageName() + "应收");
        paymentConfirm.setBusGuestId(contract.getPartyAId());
        paymentConfirm.setBusGuestName(contract.getPartyA());
        paymentConfirm.setContractId(contract.getId());
@@ -333,30 +334,30 @@
        paymentConfirm.setTransationAmount(schedule.getPlannedAmount());
        paymentConfirm.setReceivableAmount(schedule.getPlannedAmount());
        paymentConfirm.setTotalAmount(schedule.getPlannedAmount().multiply(new BigDecimal("-1")));
        PaymentConfirm lastNewConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId,contract.getId())
        PaymentConfirm lastNewConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, contract.getId())
                .orderByDesc(PaymentConfirm::getCreateTime).last("limit 1"));
        BigDecimal lastNewTotal = new BigDecimal("0");
        if(ObjUtil.isNotNull(lastNewConfirm)){
        if (ObjUtil.isNotNull(lastNewConfirm)) {
            lastNewTotal = lastNewConfirm.getTotalAmount();
        }
        paymentConfirm.setTotalAmount(lastNewTotal.subtract(paymentConfirm.getReceivableAmount()));
        if (schedule.getPaymentRatio().compareTo(new BigDecimal("0"))>0){
        if (schedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) {
            paymentConfirmMapper.insert(paymentConfirm);
        }
        //客户付款完成合同
        List<Contract> customerCompleteContractList = baseMapper.selectList(Wrappers.<Contract>lambdaQuery().eq(Contract::getPartyAId, contract.getPartyAId())
                .eq(Contract::getPartyBId,SecurityUtils.getUser().getCompId()).apply(" amount = paid_amount"));
        if (ArrayUtil.isNotEmpty(customerCompleteContractList)){
                .eq(Contract::getPartyBId, SecurityUtils.getUser().getCompId()).apply(" amount = paid_amount"));
        if (ArrayUtil.isNotEmpty(customerCompleteContractList)) {
            List<BigDecimal> outAmountList = new ArrayList<>();
            for (Contract completeContract:customerCompleteContractList
                 ) {
                PaymentConfirm contractLastConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId,completeContract.getId())
            for (Contract completeContract : customerCompleteContractList
            ) {
                PaymentConfirm contractLastConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, completeContract.getId())
                        .orderByDesc(PaymentConfirm::getCreateTime).last("limit 1"));
                //查询客户付款完成合同中最后明细金额 有预收转入当前合同
                if (contractLastConfirm.getTotalAmount().compareTo(new BigDecimal("0"))>0){
                if (contractLastConfirm.getTotalAmount().compareTo(new BigDecimal("0")) > 0) {
                    //新增完成付款合同 资金转出
                    PaymentConfirm outConfirm = BeanUtil.copyProperties(contractLastConfirm,PaymentConfirm.class,"id","transationAmount",
                            "advanceAmount","receivableAmount","overdueAmount","totalAmount");
                    PaymentConfirm outConfirm = BeanUtil.copyProperties(contractLastConfirm, PaymentConfirm.class, "id", "transationAmount",
                            "advanceAmount", "receivableAmount", "overdueAmount", "totalAmount");
                    outConfirm.setBusinessType("资金转出");
                    outConfirm.setConfirmTime(new Date());
                    outConfirm.setTransationAmount(contractLastConfirm.getTotalAmount());
@@ -365,21 +366,21 @@
                    outAmountList.add(outConfirm.getTransationAmount());
                }
            }
            if (ArrayUtil.isNotEmpty(outAmountList.toArray())){
            if (ArrayUtil.isNotEmpty(outAmountList.toArray())) {
                BigDecimal currentSum = new BigDecimal("0");
                for (BigDecimal currentAmount:outAmountList
                     ) {
                    currentSum=currentSum.add(currentAmount);
                for (BigDecimal currentAmount : outAmountList
                ) {
                    currentSum = currentSum.add(currentAmount);
                    //新增当前合同 资金转入
                    PaymentConfirm inConfirm = BeanUtil.copyProperties(paymentConfirm,PaymentConfirm.class,"id","transationAmount",
                            "advanceAmount","receivableAmount","overdueAmount","totalAmount");
                    PaymentConfirm inConfirm = BeanUtil.copyProperties(paymentConfirm, PaymentConfirm.class, "id", "transationAmount",
                            "advanceAmount", "receivableAmount", "overdueAmount", "totalAmount");
                    inConfirm.setBusinessType("资金转入");
                    inConfirm.setConfirmTime(new Date());
                    inConfirm.setTransationAmount(currentSum.subtract(currentAmount));
                    inConfirm.setTotalAmount(paymentConfirm.getTotalAmount().add(currentSum));
                    if (inConfirm.getTotalAmount().compareTo(new BigDecimal("0"))>0){
                    if (inConfirm.getTotalAmount().compareTo(new BigDecimal("0")) > 0) {
                        inConfirm.setAdvanceAmount(inConfirm.getTotalAmount());
                    }else if (inConfirm.getTotalAmount().compareTo(new BigDecimal("0"))<0){
                    } else if (inConfirm.getTotalAmount().compareTo(new BigDecimal("0")) < 0) {
                        inConfirm.setReceivableAmount(inConfirm.getTotalAmount().multiply(new BigDecimal("-1")));
                    }
                    paymentConfirmMapper.insert(inConfirm);
@@ -393,8 +394,9 @@
    public R genCurrentOverdue() {
        List<ContractPaymentSchedule> scheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery()
                .lt(ContractPaymentSchedule::getEffectiveEndDate, DateUtil.today())
                .ne(ContractPaymentSchedule::getPaymentStatus,"2"));
        if (ArrayUtil.isNotEmpty(scheduleList.toArray())){
                .ne(ContractPaymentSchedule::getPaymentStatus, "2")
                .ne(ContractPaymentSchedule::getPaymentStatus,3));
        if (ArrayUtil.isNotEmpty(scheduleList.toArray())) {
            scheduleList.stream().forEach(contractPaymentSchedule -> {
                Contract contract = baseMapper.selectById(contractPaymentSchedule.getContractId());
                //应收超期
@@ -408,10 +410,10 @@
                overdueConfirm.setConfirmTime(new Date());
                overdueConfirm.setScheduleId(contractPaymentSchedule.getId());
                overdueConfirm.setScheduleName(contractPaymentSchedule.getStageName());
                PaymentConfirm newLastConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId,contract.getId())
                PaymentConfirm newLastConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, contract.getId())
                        .orderByDesc(PaymentConfirm::getCreateTime).last("limit 1"));
                overdueConfirm.setTransationAmount(StrUtil.equals(contractPaymentSchedule.getPaymentStatus()+"","0")?
                        contractPaymentSchedule.getPlannedAmount():
                overdueConfirm.setTransationAmount(StrUtil.equals(contractPaymentSchedule.getPaymentStatus() + "", "0") ?
                        contractPaymentSchedule.getPlannedAmount() :
                        contractPaymentSchedule.getPlannedAmount().subtract(contractPaymentSchedule.getActualAmount()));
                overdueConfirm.setReceivableAmount(newLastConfirm.getTotalAmount().multiply(new BigDecimal("-1")));
                overdueConfirm.setOverdueAmount(overdueConfirm.getTransationAmount());
@@ -420,7 +422,7 @@
                //判断当前阶段是否已生成上阶段应收超期
                PaymentConfirm oiverdueConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getScheduleId, contractPaymentSchedule.getId())
                        .eq(PaymentConfirm::getBusinessType, "应收超期"));
                if (ObjUtil.isNull(oiverdueConfirm)&&overdueConfirm.getTransationAmount().compareTo(new BigDecimal("0"))>0) {
                if (ObjUtil.isNull(oiverdueConfirm) && overdueConfirm.getTransationAmount().compareTo(new BigDecimal("0")) > 0) {
                    overdueConfirm.setCompId(contractPaymentSchedule.getCompId());
                    paymentConfirmMapper.insert(overdueConfirm);
                }
@@ -434,18 +436,18 @@
                currentOverdue.setScheduleName(contractPaymentSchedule.getStageName());
                currentOverdue.setCompId(contract.getCompId());
                currentOverdue.setContractExpirTime(contractPaymentSchedule.getEffectiveEndDate());
                currentOverdue.setReceivableAmount(StrUtil.equals(contractPaymentSchedule.getPaymentStatus()+"","0")?
                        contractPaymentSchedule.getPlannedAmount():contractPaymentSchedule.getPlannedAmount().subtract(contractPaymentSchedule.getActualAmount()));
                currentOverdue.setOverdueDuration(BigDecimal.valueOf(DateUtil.betweenDay(contractPaymentSchedule.getEffectiveEndDate(),new Date(),true)));
                CurrentOverdue overdue = currentOverdueMapper.selectOne(Wrappers.<CurrentOverdue>lambdaQuery().eq(CurrentOverdue::getContractId,currentOverdue.getContractId())
                        .eq(CurrentOverdue::getScheduleId,currentOverdue.getScheduleId()).last("limit 1"));
                if (ObjUtil.isNull(overdue)){
                currentOverdue.setReceivableAmount(StrUtil.equals(contractPaymentSchedule.getPaymentStatus() + "", "0") ?
                        contractPaymentSchedule.getPlannedAmount() : contractPaymentSchedule.getPlannedAmount().subtract(contractPaymentSchedule.getActualAmount()));
                currentOverdue.setOverdueDuration(BigDecimal.valueOf(DateUtil.betweenDay(contractPaymentSchedule.getEffectiveEndDate(), new Date(), true)));
                CurrentOverdue overdue = currentOverdueMapper.selectOne(Wrappers.<CurrentOverdue>lambdaQuery().eq(CurrentOverdue::getContractId, currentOverdue.getContractId())
                        .eq(CurrentOverdue::getScheduleId, currentOverdue.getScheduleId()).last("limit 1"));
                if (ObjUtil.isNull(overdue)) {
                    currentOverdue.setCompId(contractPaymentSchedule.getCompId());
                    if (currentOverdue.getReceivableAmount().compareTo(new BigDecimal("0"))>0){
                    if (currentOverdue.getReceivableAmount().compareTo(new BigDecimal("0")) > 0) {
                        currentOverdueMapper.insert(currentOverdue);
                    }
                }else {
                    overdue.setOverdueDuration(BigDecimal.valueOf(DateUtil.betweenDay(contractPaymentSchedule.getEffectiveEndDate(),new Date(),true)));
                } else {
                    overdue.setOverdueDuration(BigDecimal.valueOf(DateUtil.betweenDay(contractPaymentSchedule.getEffectiveEndDate(), new Date(), true)));
                    currentOverdueMapper.updateById(overdue);
                }
            });
@@ -464,31 +466,31 @@
    @Override
    public R copyNewContract(Long id) {
        Contract oldContract = baseMapper.selectById(id);
        Contract newContract = BeanUtil.copyProperties(oldContract,Contract.class,"id","createTime");
        Contract newContract = BeanUtil.copyProperties(oldContract, Contract.class, "id", "createTime");
        newContract.setContractNo(ContractNumberGenerator.generateContractNumber());
        newContract.setPaidAmount(new BigDecimal("0"));
        newContract.setBillingStatus("0");
        newContract.setErpPushFlag("0");
        newContract.setContractStatus(0);
        List<Contract> contracts;
        contracts = baseMapper.selectList(Wrappers.<Contract>lambdaQuery().eq(Contract::getContractNo,newContract.getContractNo()));
        while (ArrayUtil.isNotEmpty(contracts.toArray())){
        contracts = baseMapper.selectList(Wrappers.<Contract>lambdaQuery().eq(Contract::getContractNo, newContract.getContractNo()));
        while (ArrayUtil.isNotEmpty(contracts.toArray())) {
            newContract.setContractNo(ContractNumberGenerator.generateContractNumber());
            contracts = baseMapper.selectList(Wrappers.<Contract>lambdaQuery().eq(Contract::getContractNo,newContract.getContractNo()));
            contracts = baseMapper.selectList(Wrappers.<Contract>lambdaQuery().eq(Contract::getContractNo, newContract.getContractNo()));
        }
        baseMapper.insert(newContract);
        List<ContractSubjectMatter> subjectMatterList = contractSubjectMatterMapper.selectList(Wrappers.<ContractSubjectMatter>lambdaQuery().eq(ContractSubjectMatter::getContractId,id));
        List<ContractSubjectMatter> subjectMatterList = contractSubjectMatterMapper.selectList(Wrappers.<ContractSubjectMatter>lambdaQuery().eq(ContractSubjectMatter::getContractId, id));
        subjectMatterList.stream().forEach(contractSubjectMatter -> {
            ContractSubjectMatter subjectMatter = BeanUtil.copyProperties(contractSubjectMatter,ContractSubjectMatter.class,"id","createTime");
            ContractSubjectMatter subjectMatter = BeanUtil.copyProperties(contractSubjectMatter, ContractSubjectMatter.class, "id", "createTime");
            subjectMatter.setContractId(newContract.getId());
            subjectMatter.setDeliveryStatus(0);
            subjectMatter.setDeliveredQuantity(new BigDecimal("0"));
            subjectMatter.setRemainingQuantity(new BigDecimal("0"));
            contractSubjectMatterMapper.insert(subjectMatter);
        });
        List<ContractPaymentSchedule> scheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId,id));
        List<ContractPaymentSchedule> scheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, id));
        scheduleList.stream().forEach(contractPaymentSchedule -> {
            ContractPaymentSchedule schedule = BeanUtil.copyProperties(contractPaymentSchedule,ContractPaymentSchedule.class,"id","createTime");
            ContractPaymentSchedule schedule = BeanUtil.copyProperties(contractPaymentSchedule, ContractPaymentSchedule.class, "id", "createTime");
            schedule.setContractId(newContract.getId());
            schedule.setPaymentStatus(0);
            schedule.setActualAmount(new BigDecimal("0"));
@@ -503,53 +505,53 @@
    public void exportContractYMJJGCLWord(Long id, HttpServletResponse response) {
        Contract contract = baseMapper.selectById(id);
        List<ContractSubjectMatter> subjectMatterList = contractSubjectMatterMapper.selectList(Wrappers.<ContractSubjectMatter>lambdaQuery()
                .eq(ContractSubjectMatter::getContractId,id).orderByAsc(ContractSubjectMatter::getCreateTime));
        Map<String,Object> map = new HashMap<>();
                .eq(ContractSubjectMatter::getContractId, id).orderByAsc(ContractSubjectMatter::getCreateTime));
        Map<String, Object> map = new HashMap<>();
        //合同基本信息
        map.put("partyA",contract.getPartyA());
        map.put("partyB",contract.getPartyB());
        map.put("contractNo",contract.getContractNo());
        map.put("signPlace",contract.getSignPlace());
        map.put("signDate",DateUtil.formatDate(contract.getSignDate()));
        map.put("signDateYMD",DateUtil.format(contract.getSignDate(), DatePattern.CHINESE_DATE_PATTERN));
        map.put("partyA", contract.getPartyA());
        map.put("partyB", contract.getPartyB());
        map.put("contractNo", contract.getContractNo());
        map.put("signPlace", contract.getSignPlace());
        map.put("signDate", DateUtil.formatDate(contract.getSignDate()));
        map.put("signDateYMD", DateUtil.format(contract.getSignDate(), DatePattern.CHINESE_DATE_PATTERN));
        map.put("total", contract.getAmount());
        map.put("amountWords", Convert.digitToChinese(contract.getAmount()));
        //标的物
        List<Map<String,Object>> items = new ArrayList<>();
        List<Map<String, Object>> items = new ArrayList<>();
        List<RowRenderData> dataList = new ArrayList<>();
        AtomicReference<Integer> no = new AtomicReference<>(0);
        subjectMatterList.stream().forEach(contractSubjectMatter -> {
            Map<String,Object> item = new HashMap<>();
            item.put("no",no);
            item.put("materialName",contractSubjectMatter.getMaterialName());
            item.put("guige","");
            item.put("unit","");
            item.put("quantity",contractSubjectMatter.getQuantity());
            item.put("danzhong","");
            item.put("zongzhong","");
            item.put("unitPrice",contractSubjectMatter.getUnitPrice());
            item.put("price",contractSubjectMatter.getTotalAmount());
            Map<String, Object> item = new HashMap<>();
            item.put("no", no);
            item.put("materialName", contractSubjectMatter.getMaterialName());
            item.put("guige", "");
            item.put("unit", "");
            item.put("quantity", contractSubjectMatter.getQuantity());
            item.put("danzhong", "");
            item.put("zongzhong", "");
            item.put("unitPrice", contractSubjectMatter.getUnitPrice());
            item.put("price", contractSubjectMatter.getTotalAmount());
            items.add(item);
            no.updateAndGet(v -> v + 1);
        });
        map.put("items",items);
        map.put("items", items);
        //定制方
        BusinessCustomer customer = businessCustomerMapper.selectById(contract.getPartyAId());
        map.put("companyName",customer.getCompanyName());
        map.put("legalPerson",customer.getLegalPerson());
        map.put("contactPhone",customer.getContactPhone());
        map.put("bankName",customer.getBankName());
        map.put("bankAccount",customer.getBankAccount());
        map.put("companyName", customer.getCompanyName());
        map.put("legalPerson", customer.getLegalPerson());
        map.put("contactPhone", customer.getContactPhone());
        map.put("bankName", customer.getBankName());
        map.put("bankAccount", customer.getBankAccount());
        //承揽方
        R<SysDept> r = remoteDeptService.getById(contract.getPartyBId());
        SysDept dept = r.getData();
        map.put("companyName",dept.getOrgName());
        map.put("legalPerson1",StrUtil.isNotEmpty(dept.getLegalPerson())?dept.getLegalPerson():"");
        map.put("entrustedAgent",StrUtil.isNotEmpty(dept.getLegalPerson())?"":dept.getEntrustedAgent());
        map.put("orgContact",dept.getOrgContact());
        map.put("orgBank",dept.getOrgBank());
        map.put("orgBankAccount",dept.getOrgBankAccount());
        map.put("companyName", dept.getOrgName());
        map.put("legalPerson1", StrUtil.isNotEmpty(dept.getLegalPerson()) ? dept.getLegalPerson() : "");
        map.put("entrustedAgent", StrUtil.isNotEmpty(dept.getLegalPerson()) ? "" : dept.getEntrustedAgent());
        map.put("orgContact", dept.getOrgContact());
        map.put("orgBank", dept.getOrgBank());
        map.put("orgBankAccount", dept.getOrgBankAccount());
        //生成文件名
        Long time = new Date().getTime();
@@ -567,7 +569,7 @@
                    .bind("items", new LoopRowTableRenderPolicy()) // 将 items 绑定到行循环策略
                    .build();
            // 2. 编译并渲染数据
            XWPFTemplate xwpfTemplate = XWPFTemplate.compile(resource.getInputStream(),config).render(map);
            XWPFTemplate xwpfTemplate = XWPFTemplate.compile(resource.getInputStream(), config).render(map);
            // 3. 设置响应头
            response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
@@ -580,7 +582,7 @@
            out.flush();
            out.close();
            xwpfTemplate.close(); // 重要:关闭模版释放资源
        }catch (IOException e) {
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/OutBoundServiceImpl.java
@@ -269,21 +269,21 @@
                    //更新发货前收款生效时间
                    if (ObjUtil.isNull(schedule.getEffectiveDate())) {
                        schedule.setEffectiveDate(DateUtil.offsetDay(addDTO.getOutBoundTime(), schedule.getAgreedDays()));
                        schedule.setEffectiveEndDate(DateUtil.offsetDay(addDTO.getOutBoundTime(), schedule.getAgreedDays()));
                        //查询是否有后续阶段
                        List<ContractPaymentSchedule> afterSchedule = scheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, contractId)
                                .gt(ContractPaymentSchedule::getStageOrder, schedule.getStageOrder()));
                        if (ArrayUtil.isEmpty(afterSchedule.toArray())) {
                            schedule.setEffectiveEndDate(contract.getExpirationDate());
                        }
//                        List<ContractPaymentSchedule> afterSchedule = scheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, contractId)
//                                .gt(ContractPaymentSchedule::getStageOrder, schedule.getStageOrder()));
//                        if (ArrayUtil.isEmpty(afterSchedule.toArray())) {
//                            schedule.setEffectiveEndDate(contract.getExpirationDate());
//                        }
                        scheduleMapper.updateById(schedule);
                        //查询是否有之前阶段
                        ContractPaymentSchedule beforeSchedule = scheduleMapper.selectOne(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, schedule.getContractId())
                                .lt(ContractPaymentSchedule::getStageOrder, schedule.getStageOrder()).orderByDesc(ContractPaymentSchedule::getCreateTime).last("limit 1"));
                        if (ObjUtil.isNotNull(beforeSchedule)) {
                            beforeSchedule.setEffectiveEndDate(schedule.getEffectiveDate());
                            scheduleMapper.updateById(beforeSchedule);
                        }
//                        ContractPaymentSchedule beforeSchedule = scheduleMapper.selectOne(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, schedule.getContractId())
//                                .lt(ContractPaymentSchedule::getStageOrder, schedule.getStageOrder()).orderByDesc(ContractPaymentSchedule::getCreateTime).last("limit 1"));
//                        if (ObjUtil.isNotNull(beforeSchedule)) {
//                            beforeSchedule.setEffectiveEndDate(schedule.getEffectiveDate());
//                            scheduleMapper.updateById(beforeSchedule);
//                        }
                        //更新履约
                        ContractPaymentScheduleProcess contractPaymentScheduleProcess = new ContractPaymentScheduleProcess();
                        contractPaymentScheduleProcess.setContractId(schedule.getContractId());
@@ -291,7 +291,11 @@
                        contractPaymentScheduleProcess.setScheduleId(schedule.getId());
                        contractPaymentScheduleProcess.setScheduleName(schedule.getStageName());
                        contractPaymentScheduleProcess.setProcessDate(addDTO.getOutBoundTime());
                        scheduleProcessMapper.insert(contractPaymentScheduleProcess);
                        ContractPaymentScheduleProcess lastProcess = scheduleProcessMapper.selectOne(Wrappers.<ContractPaymentScheduleProcess>lambdaQuery().eq(ContractPaymentScheduleProcess::getContractId, schedule.getContractId())
                                .eq(ContractPaymentScheduleProcess::getScheduleId, schedule.getId()).last("limit 1"));
                        if (ObjUtil.isNull(lastProcess)) {
                            scheduleProcessMapper.insert(contractPaymentScheduleProcess);
                        }
                    }
                    //查询是否有后续阶段
@@ -303,13 +307,11 @@
                        //最后阶段生效时间
                        ContractPaymentSchedule endSchedule = afterSchedule.get(0);
                        if (StrUtil.equals(endSchedule.getStageName(), "质保金")) {
                            endSchedule.setEffectiveDate(DateUtil.offsetDay(addDTO.getOutBoundTime(), endSchedule.getAgreedDays()));
                            endSchedule.setEffectiveEndDate(contract.getExpirationDate());
                            scheduleMapper.updateById(endSchedule);
//                            endSchedule.setEffectiveEndDate(DateUtil.offsetDay(addDTO.getOutBoundTime(), endSchedule.getAgreedDays()));
//                            scheduleMapper.updateById(endSchedule);
                            //当前阶段生效时间
                            schedule.setEffectiveDate(DateUtil.offsetDay(addDTO.getOutBoundTime(), schedule.getAgreedDays()));
                            schedule.setEffectiveEndDate(endSchedule.getEffectiveDate());
                            scheduleMapper.updateById(schedule);
//                            schedule.setEffectiveEndDate(DateUtil.offsetDay(addDTO.getOutBoundTime(), schedule.getAgreedDays()));
//                            scheduleMapper.updateById(schedule);
                            //最后阶段应收
                            PaymentConfirm newConfim = new PaymentConfirm();
                            newConfim.setBusinessType(endSchedule.getStageName() + "应收");
@@ -344,8 +346,8 @@
                        contractMapper.updateById(contract);
                    }
                    if (ArrayUtil.isEmpty(afterSchedule.toArray())) {
                        schedule.setEffectiveEndDate(contract.getExpirationDate());
                        scheduleMapper.updateById(schedule);
//                        schedule.setEffectiveEndDate(contract.getExpirationDate());
//                        scheduleMapper.updateById(schedule);
                        //更新合同下个阶段
                        contract.setNextScheduleName("无");
                        contractMapper.updateById(contract);
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/PaymentConfirmServiceImpl.java
@@ -120,7 +120,7 @@
                }
                //更新付款阶段付款
                List<ContractPaymentSchedule> scheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery()
                        .eq(ContractPaymentSchedule::getContractId, contract.getId()).ne(ContractPaymentSchedule::getPaymentStatus, 2)
                        .eq(ContractPaymentSchedule::getContractId, contract.getId()).ne(ContractPaymentSchedule::getPaymentStatus, 2).ne(ContractPaymentSchedule::getPaymentStatus, 3)
                        .orderByAsc(ContractPaymentSchedule::getCreateTime));
                if (ArrayUtil.isNotEmpty(scheduleList.toArray())) {
                    BigDecimal remain = addDTO.getTransationAmount();
@@ -295,7 +295,8 @@
                    break;
                } else {
                    entity.setTransationAmount(transtionRemainAmount.subtract(lastTotal));
                    entity.setTotalAmount(transtionAmount);
                    entity.setReceivableAmount(transtionRemainAmount.multiply(new BigDecimal("-1")));
                    entity.setTotalAmount(transtionRemainAmount);
                    entity.setConfirmTime(payDate);
                    baseMapper.insert(entity);
                    payContractList.add(contract);
@@ -307,6 +308,7 @@
                //更新付款阶段付款
                List<ContractPaymentSchedule> scheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery()
                        .eq(ContractPaymentSchedule::getContractId, contract.getId()).ne(ContractPaymentSchedule::getPaymentStatus, 2)
                        .ne(ContractPaymentSchedule::getPaymentStatus, 3)
                        .orderByAsc(ContractPaymentSchedule::getCreateTime));
                if (ArrayUtil.isNotEmpty(scheduleList.toArray())) {
                    BigDecimal remain = transtionAmount;
@@ -361,16 +363,18 @@
                //合同所有付款阶段
                List<ContractPaymentSchedule> payComScheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery()
                        .eq(ContractPaymentSchedule::getContractId, contract.getId()).ne(ContractPaymentSchedule::getPaymentStatus, 0)
                        );
                        .ne(ContractPaymentSchedule::getPaymentStatus, 3));
                if (ArrayUtil.isNotEmpty(payComScheduleList.toArray())){
                    BigDecimal payTotal = payComScheduleList.stream().map(item->StrUtil.equals(item.getPaymentStatus() + "", "0") ? item.getPlannedAmount() :
                    BigDecimal payTotal = payComScheduleList.stream().map(item->StrUtil.equals(item.getPaymentStatus() + "", "2") ? item.getPlannedAmount() :
                            item.getActualAmount()).reduce(BigDecimal.ZERO,BigDecimal::add);
                    contract.setPaidAmount(payTotal);
                    if (payComScheduleList.stream().allMatch(item -> Objects.equals(item.getPaymentStatus(), 2))) {
                        contract.setContractStatus(3);
                    }
//                    if (payComScheduleList.stream().allMatch(item -> Objects.equals(item.getPaymentStatus(), 2))) {
//                        contract.setContractStatus(3);
//                    }
                    contractService.updateById(contract);
                    if (contract.getAmount().compareTo(contract.getPaidAmount()) == 0) {
                        contract.setBillingStatus("2");
                        contract.setContractStatus(3);
                        payCompleteContractList.add(contract);
                    }
                    //付款 且 付款未全付
@@ -619,7 +623,7 @@
        payContractList.stream().forEach(contract -> {
            //更新付款阶段付款
            List<ContractPaymentSchedule> scheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery()
                    .eq(ContractPaymentSchedule::getContractId, contract.getId()).ne(ContractPaymentSchedule::getPaymentStatus, 2)
                    .eq(ContractPaymentSchedule::getContractId, contract.getId()).ne(ContractPaymentSchedule::getPaymentStatus, 2).ne(ContractPaymentSchedule::getPaymentStatus, 3)
                    .orderByAsc(ContractPaymentSchedule::getCreateTime));
            if (ArrayUtil.isNotEmpty(scheduleList.toArray())) {
                BigDecimal remain = transtionAmount;
@@ -673,7 +677,7 @@
            }
            //合同所有付款阶段
            List<ContractPaymentSchedule> payComScheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery()
                    .eq(ContractPaymentSchedule::getContractId, contract.getId()).ne(ContractPaymentSchedule::getPaymentStatus, 0)
                    .eq(ContractPaymentSchedule::getContractId, contract.getId()).ne(ContractPaymentSchedule::getPaymentStatus, 0).ne(ContractPaymentSchedule::getPaymentStatus,3)
            );
            if (ArrayUtil.isNotEmpty(payComScheduleList.toArray())){
                BigDecimal payTotal = payComScheduleList.stream().map(item->StrUtil.equals(item.getPaymentStatus() + "", "0") ? item.getPlannedAmount() :
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/PaymentOffsetServiceImpl.java
@@ -77,7 +77,7 @@
        //更新付款阶段付款
        List<ContractPaymentSchedule> scheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery()
                .eq(ContractPaymentSchedule::getContractId,contract.getId()).ne(ContractPaymentSchedule::getPaymentStatus,2)
                .orderByAsc(ContractPaymentSchedule::getCreateTime));
                .ne(ContractPaymentSchedule::getPaymentStatus,3).orderByAsc(ContractPaymentSchedule::getCreateTime));
        if (ArrayUtil.isNotEmpty(scheduleList.toArray())){
            BigDecimal remain = paymentOffset.getOffsetAmount();
            for (ContractPaymentSchedule schedule:scheduleList) {
@@ -135,17 +135,18 @@
        }
        paid = paid.add(paymentOffset.getOffsetAmount());
        contract.setPaidAmount(paid);
        if (paid.compareTo(contract.getAmount())>0){
            contract.setPaidAmount(contract.getAmount());
        if (paid.compareTo(contract.getAmount())==0){
            contract.setBillingStatus("2");
            contract.setContractStatus(3);
        }
        contractService.updateById(contract);
        // 查询所有付款阶段是否都付款完成
        if (ArrayUtil.isNotEmpty(scheduleList.toArray())){
            if (scheduleList.stream().allMatch(item -> Objects.equals(item.getPaymentStatus(), 2))){
                contract.setContractStatus(3);
                contractService.updateById(contract);
            };
        }
//        if (ArrayUtil.isNotEmpty(scheduleList.toArray())){
//            if (scheduleList.stream().allMatch(item -> Objects.equals(item.getPaymentStatus(), 2))){
//                contract.setContractStatus(3);
//                contractService.updateById(contract);
//            };
//        }
        return R.ok();
    }
}
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/StatisticServiceImpl.java
@@ -1,9 +1,7 @@
package com.by4cloud.platformx.business.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import com.by4cloud.platformx.admin.api.entity.SysDept;
import com.by4cloud.platformx.admin.api.entity.SysDictItem;
import com.by4cloud.platformx.admin.api.feign.RemoteDeptService;
import com.by4cloud.platformx.admin.api.feign.RemoteDictService;
@@ -14,16 +12,12 @@
import com.by4cloud.platformx.common.core.util.R;
import com.by4cloud.platformx.common.security.util.SecurityUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Service
@RequiredArgsConstructor
@@ -75,6 +69,25 @@
        compIds.add(Long.valueOf(ymj));
        compIds.add(Long.valueOf(jxc));
        List<ContractIncomeAnalysisVo> contractIncomeAnalysisVoList = contractMapper.contractIncomeAnalysis(commonDTO,compIds);
        if (ArrayUtil.isNotEmpty(contractIncomeAnalysisVoList.toArray())){
            contractIncomeAnalysisVoList.stream().forEach(contractIncomeAnalysisVo -> {
                if(StrUtil.equals(contractIncomeAnalysisVo.getCompId(),sgb)){
                    contractIncomeAnalysisVo.setCompName("石工泵");
                }
                if(StrUtil.equals(contractIncomeAnalysisVo.getCompId(),smj)){
                    contractIncomeAnalysisVo.setCompName("石煤机");
                }
                if(StrUtil.equals(contractIncomeAnalysisVo.getCompId(),ymj)){
                    contractIncomeAnalysisVo.setCompName("一煤机");
                }
                if(StrUtil.equals(contractIncomeAnalysisVo.getCompId(),tfgs)){
                    contractIncomeAnalysisVo.setCompName("通方公司");
                }
                if(StrUtil.equals(contractIncomeAnalysisVo.getCompId(),jxc)){
                    contractIncomeAnalysisVo.setCompName("机械厂");
                }
            });
        }
        return R.ok(contractIncomeAnalysisVoList);
    }
@@ -284,4 +297,45 @@
        return R.ok(contractIncomeAnalysisVoList);
    }
    @Override
    public R contractAmountAnalysisBySaleModel(AnalysisCommonDTO commonDTO) {
        R<List<SysDictItem>> r = remoteDictService.getDictByType("sales_model");
        List<SysDictItem> items = r.getData();
        if (ArrayUtil.isEmpty(items.toArray())){
            return R.failed("区域字段获取异常");
        }
        List<Long> compIds = new ArrayList<>();
        compIds.add(Long.valueOf(sgb));
        compIds.add(Long.valueOf(smj));
        compIds.add(Long.valueOf(tfgs));
        compIds.add(Long.valueOf(ymj));
        compIds.add(Long.valueOf(jxc));
        List<ContractIncomeAnalysisAreaVo> contractIncomeAnalysisVoList = items.stream().map(item -> {
            ContractIncomeAnalysisAreaVo analysisAreaVo = new ContractIncomeAnalysisAreaVo();
            analysisAreaVo.setAreaId(item.getItemValue());
            analysisAreaVo.setAreaName(item.getLabel());
            return analysisAreaVo;
        }).collect(Collectors.toList());
        contractMapper.setSession();
        List<ContractIncomeAnalysisAreaVo> statisticList = contractMapper.contractAmountAnalysisBySaleModel(commonDTO
                ,compIds,Long.valueOf(smj),Long.valueOf(sgb),Long.valueOf(jxc),Long.valueOf(tfgs),Long.valueOf(ymj));
        contractIncomeAnalysisVoList.stream().forEach(vo1->{
            statisticList.stream().forEach(vo2->{
                if (StrUtil.equals(vo1.getAreaId(),vo2.getAreaId())){
                    vo1.setJxczb(vo2.getJxczb());
                    vo1.setJxcze(vo2.getJxcze());
                    vo1.setSgbzb(vo2.getSgbzb());
                    vo1.setSgbze(vo2.getSgbze());
                    vo1.setSmjzb(vo2.getSmjzb());
                    vo1.setSmjze(vo2.getSmjze());
                    vo1.setTfzb(vo2.getTfzb());
                    vo1.setTfze(vo2.getTfze());
                    vo1.setYmjzb(vo2.getYmjzb());
                    vo1.setYmjze(vo2.getYmjze());
                }
            });
        });
        return R.ok(contractIncomeAnalysisVoList);
    }
}
platformx-business-finance-biz/src/main/resources/mapper/ContractMapper.xml
@@ -184,7 +184,7 @@
    <select id="contractIncomeAnalysis"
            resultType="com.by4cloud.platformx.business.vo.ContractIncomeAnalysisVo">
        SELECT
            compName,
            compId,
            SUM(CASE WHEN month_num = 1 THEN total_amount ELSE 0 END) AS 'srMonth1',
                SUM(CASE WHEN month_num = 1 AND pay_type = 1 THEN total_amount ELSE 0 END) AS 'xhMonth1',
                SUM(CASE WHEN month_num = 1 AND pay_type = 2 THEN total_amount ELSE 0 END) AS 'cdMonth1',
@@ -202,9 +202,9 @@
                SUM(CASE WHEN month_num = 4 AND pay_type = 2 THEN total_amount ELSE 0 END) AS 'cdMonth4',
                SUM(CASE WHEN month_num = 4 AND pay_type = 3 THEN total_amount ELSE 0 END) AS 'qtMonth4',
                SUM(CASE WHEN month_num = 5 THEN total_amount ELSE 0 END) AS 'srMonth5',
                SUM(CASE WHEN month_num = 5 AND pay_type = 0 THEN total_amount ELSE 0 END) AS 'xhMonth5',
                SUM(CASE WHEN month_num = 5 AND pay_type = 1 THEN total_amount ELSE 0 END) AS 'cdMonth5',
                SUM(CASE WHEN month_num = 5 AND pay_type = 2 THEN total_amount ELSE 0 END) AS 'qtMonth5',
                SUM(CASE WHEN month_num = 5 AND pay_type = 1 THEN total_amount ELSE 0 END) AS 'xhMonth5',
                SUM(CASE WHEN month_num = 5 AND pay_type = 2 THEN total_amount ELSE 0 END) AS 'cdMonth5',
                SUM(CASE WHEN month_num = 5 AND pay_type = 3 THEN total_amount ELSE 0 END) AS 'qtMonth5',
                SUM(CASE WHEN month_num = 6 THEN total_amount ELSE 0 END) AS 'srMonth6',
                SUM(CASE WHEN month_num = 6 AND pay_type = 1 THEN total_amount ELSE 0 END) AS 'xhMonth6',
                SUM(CASE WHEN month_num = 6 AND pay_type = 2 THEN total_amount ELSE 0 END) AS 'cdMonth6',
@@ -235,7 +235,7 @@
                SUM(CASE WHEN month_num = 12 AND pay_type = 3 THEN total_amount ELSE 0 END) AS 'qtMonth12'
        FROM (
        SELECT
        COALESCE(pc.payee_comp_id, '未知单位') AS compName,
        COALESCE(pc.payee_comp_id, '未知单位') AS compId,
        MONTH(payment_time) AS month_num,
        pay_type,
        COALESCE(payment_amount, 0) AS total_amount
@@ -250,7 +250,7 @@
            #{id}
        </foreach>
             ) AS source_data
        GROUP BY compName
        GROUP BY compId
    </select>
    <select id="contractIncomeAnalysisByComp"
@@ -746,9 +746,11 @@
        SELECT
        SUM( amount )
        FROM
        contract
        contract ct
        WHERE
        party_b_id IN
              ct.del_flag = '0'
        and  ct.supply_attribute = c.supply_attribute
        and ct.party_b_id IN
        <foreach collection="compIds" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
@@ -761,9 +763,11 @@
        SELECT
        SUM( amount )
        FROM
        contract
        contract ct
        WHERE
        party_b_id IN
        ct.del_flag = '0'
        and  ct.supply_attribute = c.supply_attribute
        and ct.party_b_id IN
        <foreach collection="compIds" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
@@ -776,9 +780,11 @@
        SELECT
        SUM( amount )
        FROM
        contract
        contract ct
        WHERE
        party_b_id IN
        ct.del_flag = '0'
        and  ct.supply_attribute = c.supply_attribute
        and ct.party_b_id IN
        <foreach collection="compIds" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
@@ -791,9 +797,11 @@
        SELECT
        SUM( amount )
        FROM
        contract
        contract ct
        WHERE
        party_b_id IN
        ct.del_flag = '0'
        and  ct.supply_attribute = c.supply_attribute
        and ct.party_b_id IN
        <foreach collection="compIds" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
@@ -806,9 +814,11 @@
        SELECT
        SUM( amount )
        FROM
        contract
        contract ct
        WHERE
        party_b_id IN
        ct.del_flag = '0'
        and  ct.supply_attribute = c.supply_attribute
        and ct.party_b_id IN
        <foreach collection="compIds" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
@@ -818,7 +828,8 @@
        FROM
        contract c
        WHERE
        c.supply_attribute IS NOT NULL
            c.del_flag = '0'
        and c.supply_attribute IS NOT NULL
        AND YEAR ( sign_date ) = #{queryDTO.year}
        GROUP BY
        c.supply_attribute
@@ -888,4 +899,113 @@
        ORDER BY m.month_num
    </select>
    <select id="contractAmountAnalysisBySaleModel"
            resultType="com.by4cloud.platformx.business.vo.ContractIncomeAnalysisAreaVo">
        SELECT
        b.sales_model area_id,
        SUM( CASE WHEN c.party_b_id = #{sgbCompId} THEN c.amount ELSE 0 END ) AS sgbze,
        ROUND(
        SUM( CASE WHEN c.party_b_id = #{sgbCompId} THEN c.amount ELSE 0 END ) / (
        SELECT
        SUM( amount )
        FROM
        contract c, business_customer bc
        WHERE
        bc.id = c.party_a_id
        and c.del_flag = '0'
        and bc.del_flag = '0'
        and bc.sales_model = b.sales_model
        and party_b_id IN
        <foreach collection="compIds" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
        ) * 100,
        2
        ) AS sgbzb,
        SUM( CASE WHEN c.party_b_id = #{jxcCompId} THEN c.amount ELSE 0 END ) AS jxcze,
        ROUND(
        SUM( CASE WHEN c.party_b_id = #{jxcCompId} THEN c.amount ELSE 0 END ) / (
        SELECT
        SUM( amount )
        FROM
        contract c, business_customer bc
        WHERE
        bc.id = c.party_a_id
        and c.del_flag = '0'
        and bc.del_flag = '0'
        and bc.sales_model = b.sales_model
        and party_b_id IN
        <foreach collection="compIds" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
        ) * 100,
        2
        ) AS jxczb ,
        SUM( CASE WHEN c.party_b_id = #{smjCompId} THEN c.amount ELSE 0 END ) AS smjze,
        ROUND(
        SUM( CASE WHEN c.party_b_id = #{smjCompId} THEN c.amount ELSE 0 END ) / (
        SELECT
        SUM( amount )
        FROM
        contract c, business_customer bc
        WHERE
        bc.id = c.party_a_id
        and c.del_flag = '0'
        and bc.del_flag = '0'
        and bc.sales_model = b.sales_model
        and party_b_id IN
        <foreach collection="compIds" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
        ) * 100,
        2
        ) AS smjzb ,
        SUM( CASE WHEN c.party_b_id = #{ymjCompId} THEN c.amount ELSE 0 END ) AS ymjze,
        ROUND(
        SUM( CASE WHEN c.party_b_id = #{ymjCompId} THEN c.amount ELSE 0 END ) / (
        SELECT
        SUM( amount )
        FROM
        contract c, business_customer bc
        WHERE
        bc.id = c.party_a_id
        and c.del_flag = '0'
        and bc.del_flag = '0'
        and bc.sales_model = b.sales_model
        and party_b_id IN
        <foreach collection="compIds" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
        ) * 100,
        2
        ) AS ymjzb ,
        SUM( CASE WHEN c.party_b_id = #{tfCompId} THEN c.amount ELSE 0 END ) AS tfze,
        ROUND(
        SUM( CASE WHEN c.party_b_id = #{tfCompId} THEN c.amount ELSE 0 END ) / (
        SELECT
        SUM( amount )
        FROM
        contract c, business_customer bc
        WHERE
        bc.id = c.party_a_id
        and c.del_flag = '0'
        and bc.del_flag = '0'
        and bc.sales_model = b.sales_model
        and party_b_id IN
        <foreach collection="compIds" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
        ) * 100,
        2
        ) AS tfzb
        FROM
        contract c
        JOIN business_customer b ON c.party_a_id = b.id
        WHERE
        b.sales_model IS NOT NULL
        AND YEAR ( sign_date ) = #{queryDTO.year}
        GROUP BY
        b.sales_model
    </select>
</mapper>