BAOLH
2026-11-10 4d730af0447c686133130d0116a0fa3dd82c2dca
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/service/impl/ContractServiceImpl.java
@@ -134,8 +134,14 @@
                contractDto.setReceivePayment(receivePayment(t));
                // 开票总金额
                contractDto.setBillingTotalAmount(contractInvoiceRepository.countTotalAmountByContractId(t.getContractId()));
                // 付款收入金额
                BigDecimal paymentIncomeAmount = Optional.ofNullable(contractPaymentRepository.sumPaymentAmountByContractIdAndPaymentType(t.getContractId(), Constant.CONTRACR_REVENUE)).orElse(BigDecimal.ZERO);
                contractDto.setPaymentIncomeAmount(paymentIncomeAmount);
                // 付款支出金额
                BigDecimal paymentExpendAmount = Optional.ofNullable(contractPaymentRepository.sumPaymentAmountByContractIdAndPaymentType(t.getContractId(), Constant.CONTRACR_EXPENDITURE)).orElse(BigDecimal.ZERO);
                contractDto.setPaymentExpendAmount(paymentExpendAmount);
                // 付款总金额
                contractDto.setPaymentTotalAmount(contractPaymentRepository.countTotalAmountByContractId(t.getContractId()));
                contractDto.setPaymentTotalAmount(paymentIncomeAmount.add(paymentExpendAmount));
                // 合同款付款金额
                contractDto.setContractPaymentAmount(contractPaymentAmount(t));
                // 服务款付款金额
@@ -253,10 +259,11 @@
        Map<String, String> paymentStateMap = dictDetailRepository.findByDictName(Constant.PAYMENT_STATE).parallelStream().collect(Collectors.toMap(DictDetail::getValue, DictDetail::getLabel));
        Map<String, String> contractStatusMap = dictDetailRepository.findByDictName(Constant.CONTRACT_STATUS).parallelStream().collect(Collectors.toMap(DictDetail::getValue, DictDetail::getLabel));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat ymsdf = new SimpleDateFormat("yyyy-MM");
        for (ContractDto contract : all) {
            String firstName = contractFirstName(contractMapper.toEntity(contract));
            String secondName = contractSecondName(contractMapper.toEntity(contract));
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String servicePaymentDate = null;
            if(contract.getServicePaymentDate() != null) {
                servicePaymentDate = sdf.format(contract.getServicePaymentDate());
@@ -291,6 +298,7 @@
            map.put("合同终版文件", contract.getRelatedDocumentsFinal());
            map.put("合同状态", contractStatusMap.containsKey(contract.getContractStatus()) ? contractStatusMap.get(contract.getContractStatus()) : "");
            map.put("备注信息", contract.getRemarks());
            map.put("业绩日期", ymsdf.format(contract.getPerformanceDate()));
            map.put("创建者", contract.getCreateBy());
            map.put("创建日期", contract.getCreateTime());
            list.add(map);
@@ -309,6 +317,7 @@
        Map<String, String> contractStatusMap = dictDetailRepository.findByDictName(Constant.CONTRACT_STATUS).parallelStream().collect(Collectors.toMap(DictDetail::getValue, DictDetail::getLabel));
        Map<String, String> acceptStatusMap = dictDetailRepository.findByDictName(Constant.ACCEPT_STATUS).parallelStream().collect(Collectors.toMap(DictDetail::getValue, DictDetail::getLabel));
        SimpleDateFormat ymsdf = new SimpleDateFormat("yyyy-MM");
        for (Contract contract : contractList) {
            String firstName = contractFirstName(contract);
            String secondName = contractSecondName(contract);
@@ -384,6 +393,7 @@
                    map.put("验收状态", acceptStatusMap.get(contract.getAcceptStatus()));
                    map.put("合同附件", relatedDocumentsAttachment);
                    map.put("备注信息", contract.getRemarks());
                    map.put("业绩日期", ymsdf.format(contract.getPerformanceDate()));
                    map.put("创建者", contract.getCreateBy());
                    map.put("创建日期", contract.getCreateTime());
                    list.add(map);
@@ -949,6 +959,8 @@
            resources.setContractNumber(contractNumber.toString());
            if (companyId != null) {
                resources.setCompanyId(companyId);
            } else {
                throw new BadRequestException("未匹配到所属公司,所属公司不能为空。");
            }
        }
@@ -1305,7 +1317,9 @@
            throw new BadRequestException("上传失败");
        }
        File uploadFile = FileUtil.toFile(file);
        String suffix = FileUtil.getExtensionName(file.getOriginalFilename());
        String type = FileUtil.getFileType(suffix);
        File uploadFile = FileUtil.upload(file, properties.getPath().getPath() + type +  File.separator);
        ExcelReader reader = ExcelUtil.getReader(uploadFile);
        List<Map<String,Object>> readAll = reader.readAll();
        if (ObjectUtil.isNull(readAll)) {
@@ -2774,8 +2788,16 @@
            // 上传临时素材
            List<String> mediaIds = templateControlFieldService.uploadWecomMediaFile(Arrays.asList(imagePath));
            // 发送报告
            List<String> weComList = Arrays.asList("李恩芳", "姚增春", "佟占利", "刘国杰", "吴倩", "齐勇峰").stream().map(name -> Optional.ofNullable(userRepository.findByNickName(name)).orElseGet(User::new).getWeComId()).filter(w -> StringUtils.isNotBlank(w)).collect(Collectors.toList());
            weComService.sendNotice(weComList, "合同季度统计信息", mediaIds.get(0), Constant.WECOM_MESSAGE_TYPE_IMAGE);
            SysGoalSettingQueryCriteria goalSettingCriteria = new SysGoalSettingQueryCriteria();
            goalSettingCriteria.setTargetYear(annualStartTime.toLocalDateTime().toLocalDate().toString());
            List<SysGoalSetting> goalSettingList = sysGoalSettingRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, goalSettingCriteria, criteriaBuilder));
            List<String> weComList = goalSettingList.stream().map(gs -> Arrays.stream(gs.getLeaderName().split("[\\p{P}\\p{S}\\p{Z}]+")).map(name -> Optional.ofNullable(userRepository.findByNickName(name)).orElseGet(User::new).getWeComId()).filter(w -> StringUtils.isNotBlank(w)).collect(Collectors.toList())).reduce(new ArrayList<>(), (prev, cur) -> {
                prev.addAll(cur);
                return prev;
            }).stream().distinct().collect(Collectors.toList());
            for (String mediaId : mediaIds) {
                weComService.sendNotice(weComList, "合同季度统计信息", mediaId, Constant.WECOM_MESSAGE_TYPE_IMAGE);
            }
            outputStream.close();
            inputStream.close();
@@ -2786,10 +2808,8 @@
            Integer quarterNum = quarterlyStartTime.toLocalDateTime().get(IsoFields.QUARTER_OF_YEAR);
            for (String contractType : contractTypeList) {
                SysGoalSettingQueryCriteria goalSettingCriteria = new SysGoalSettingQueryCriteria();
                goalSettingCriteria.setTargetYear(annualStartTime.toLocalDateTime().toLocalDate().toString());
                goalSettingCriteria.setProjectDistinguish(projectDistinguishMap.get(contractTypeMap.get(contractType)));
                SysGoalSetting goalSetting = sysGoalSettingRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, goalSettingCriteria, criteriaBuilder)).stream().findFirst().orElseGet(SysGoalSetting::new);
                // 获取指定类型季度、年度目标值
                SysGoalSetting goalSetting = goalSettingList.stream().filter(gs -> gs.getProjectDistinguish().equals(projectDistinguishMap.get(contractTypeMap.get(contractType)))).findFirst().orElseGet(SysGoalSetting::new);
                BigDecimal quarterlyGoal;
                switch (quarterNum) {
                    case 1: quarterlyGoal = Optional.ofNullable(goalSetting.getFirstTargetAmount()).orElse(BigDecimal.ZERO); break;
@@ -2898,8 +2918,10 @@
                    // 上传临时素材
                    List<String> typeMediaIds = templateControlFieldService.uploadWecomMediaFile(Arrays.asList(typeImagePath));
                    // 发送报告
                    List<String> typeWeComList = Arrays.stream(goalSetting.getLeaderName().split(",")).map(name -> Optional.ofNullable(userRepository.findByNickName(name)).orElseGet(User::new).getWeComId()).filter(w -> StringUtils.isNotBlank(w)).collect(Collectors.toList());
                    weComService.sendNotice(typeWeComList, "合同季度统计信息", typeMediaIds.get(0), Constant.WECOM_MESSAGE_TYPE_IMAGE);
                    List<String> typeWeComList = Arrays.stream(goalSetting.getLeaderName().split("[\\p{P}\\p{S}\\p{Z}]+")).map(name -> Optional.ofNullable(userRepository.findByNickName(name)).orElseGet(User::new).getWeComId()).filter(w -> StringUtils.isNotBlank(w)).collect(Collectors.toList());
                    for (String typeMediaId : typeMediaIds) {
                        weComService.sendNotice(typeWeComList, "合同季度统计信息", typeMediaId, Constant.WECOM_MESSAGE_TYPE_IMAGE);
                    }
                }
                typeOutputStream.close();
                typeInputStream.close();
@@ -2910,4 +2932,56 @@
            e.printStackTrace();
        }
    }
    @Override
    public void downloadTable(List<ContractDto> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        Map<String, String> contractTypeMap = dictDetailRepository.findByDictName(Constant.CONTRACT_DICT_TYPE).parallelStream().collect(Collectors.toMap(DictDetail::getValue, DictDetail::getLabel));
        Map<String, String> paymentStateMap = dictDetailRepository.findByDictName(Constant.PAYMENT_STATE).parallelStream().collect(Collectors.toMap(DictDetail::getValue, DictDetail::getLabel));
        Map<String, String> contractStatusMap = dictDetailRepository.findByDictName(Constant.CONTRACT_STATUS).parallelStream().collect(Collectors.toMap(DictDetail::getValue, DictDetail::getLabel));
        Map<String, String> acceptStatusMap = dictDetailRepository.findByDictName(Constant.ACCEPT_STATUS).parallelStream().collect(Collectors.toMap(DictDetail::getValue, DictDetail::getLabel));
        SimpleDateFormat ymdsdf = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat ymsdf = new SimpleDateFormat("yyyy-MM");
        for (ContractDto contract : all) {
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("合同编号", contract.getContractNumber());
            map.put("合同名称", contract.getContractName());
            map.put("所属甲方", contract.getFirstName());
            map.put("所属乙方", contract.getSecondName());
            map.put("签订日期", Optional.ofNullable(contract.getSignDate()).map(ymdsdf::format).orElse(""));
            map.put("业绩日期", Optional.ofNullable(contract.getPerformanceDate()).map(ymsdf::format).orElse(""));
            map.put("开票总金额", contract.getBillingTotalAmount());
            map.put("付款总金额", contract.getPaymentTotalAmount());
            map.put("付款收入金额", contract.getPaymentIncomeAmount());
            map.put("付款支出金额", contract.getPaymentExpendAmount());
            map.put("预收款金额", Optional.ofNullable(contract.getAdvancePayment()).filter(bd -> bd.compareTo(BigDecimal.ZERO) != 0).map(String::valueOf).orElse(""));
            map.put("应收款金额", Optional.ofNullable(contract.getReceivePayment()).filter(bd -> bd.compareTo(BigDecimal.ZERO) != 0).map(String::valueOf).orElse(""));
            map.put("合同费金额", Optional.ofNullable(contract.getContractAmount()).filter(bd -> bd.compareTo(BigDecimal.ZERO) != 0).map(String::valueOf).orElse(""));
            map.put("预计付款日期(合同费)", Optional.ofNullable(contract.getContractPaymentDate()).map(ymdsdf::format).orElse(""));
            map.put("付款状态(合同费)", paymentStateMap.getOrDefault(contract.getContractPaymentState(), ""));
            map.put("延期情况(合同费)", contract.getContractPostponement());
            map.put("服务开始日期", Optional.ofNullable(contract.getServiceStartsDate()).map(ymdsdf::format).orElse(""));
            map.put("运维服务费金额", Optional.ofNullable(contract.getServiceAmount()).filter(bd -> bd.compareTo(BigDecimal.ZERO) != 0).map(String::valueOf).orElse(""));
            map.put("预计付款日期(服务费)", Optional.ofNullable(contract.getServicePaymentDate()).map(ymdsdf::format).orElse(""));
            map.put("付款状态(服务费)", paymentStateMap.getOrDefault(contract.getServicePaymentState(), ""));
            map.put("延期情况(服务费)", contract.getServicePostponement());
            map.put("起始日期", Optional.ofNullable(contract.getStartDate()).map(ymdsdf::format).orElse(""));
            map.put("截止日期", Optional.ofNullable(contract.getEndDate()).map(ymdsdf::format).orElse(""));
            map.put("所属地区", contract.getContractArea());
            map.put("合同类型", contractTypeMap.getOrDefault(contract.getContractType(), ""));
            map.put("合同类型(二级)", contract.getContractSecondType());
            map.put("合同内容", contract.getContractContent());
            map.put("分配项目数(合同费)", contract.getFundContractNum());
            map.put("分配总金额(合同费)", Optional.ofNullable(contract.getFundContractAmount()).filter(bd -> bd.compareTo(BigDecimal.ZERO) != 0).map(String::valueOf).orElse(""));
            map.put("分配项目数(服务费)", contract.getFundServiceNum());
            map.put("分配总金额(服务费)", Optional.ofNullable(contract.getFundServiceAmount()).filter(bd -> bd.compareTo(BigDecimal.ZERO) != 0).map(String::valueOf).orElse(""));
            map.put("合同附件", contract.getRelatedDocumentsAttachment());
            map.put("备注信息", contract.getRemarks());
            map.put("验收状态", acceptStatusMap.getOrDefault(contract.getAcceptStatus(), ""));
            map.put("合同状态", contractStatusMap.getOrDefault(contract.getContractStatus(), ""));
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }
}