| | |
| | | */ |
| | | package me.zhengjie.modules.contract.service.impl; |
| | | |
| | | import me.zhengjie.modules.constant.Constant; |
| | | import me.zhengjie.modules.contract.domain.Contract; |
| | | import me.zhengjie.modules.contract.domain.ContractInvoice; |
| | | import me.zhengjie.modules.contract.domain.ContractInvoicePayment; |
| | | import me.zhengjie.modules.contract.domain.ContractPayment; |
| | | import me.zhengjie.modules.contract.repository.ContractInvoicePaymentRepository; |
| | | import me.zhengjie.modules.contract.repository.ContractInvoiceRepository; |
| | | import me.zhengjie.modules.contract.repository.ContractPaymentRepository; |
| | | import me.zhengjie.modules.contract.service.dto.ContractFirstDto; |
| | | import me.zhengjie.modules.contract.service.dto.ContractSecondDto; |
| | | import me.zhengjie.modules.project.service.dto.ProjectDto; |
| | | import me.zhengjie.modules.project.service.impl.ProjectServiceImpl; |
| | | import me.zhengjie.modules.system.repository.DictDetailRepository; |
| | | import me.zhengjie.utils.ValidationUtil; |
| | | import me.zhengjie.utils.FileUtil; |
| | | import cn.hutool.core.io.IoUtil; |
| | | import cn.hutool.core.util.IdUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.poi.excel.ExcelReader; |
| | | import cn.hutool.poi.excel.ExcelUtil; |
| | | import lombok.RequiredArgsConstructor; |
| | | import me.zhengjie.modules.contract.repository.ContractRepository; |
| | | import me.zhengjie.config.FileProperties; |
| | | import me.zhengjie.exception.BadRequestException; |
| | | import me.zhengjie.modules.approval.service.TemplateControlFieldService; |
| | | import me.zhengjie.modules.constant.ChinaArea; |
| | | import me.zhengjie.modules.constant.Constant; |
| | | import me.zhengjie.modules.contract.domain.*; |
| | | import me.zhengjie.modules.contract.repository.*; |
| | | import me.zhengjie.modules.contract.service.ContractService; |
| | | import me.zhengjie.modules.contract.service.dto.ContractDto; |
| | | import me.zhengjie.modules.contract.service.dto.ContractQueryCriteria; |
| | | import me.zhengjie.modules.contract.service.dto.*; |
| | | import me.zhengjie.modules.contract.service.mapstruct.ContractMapper; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import me.zhengjie.modules.project.repository.ProjectReimburseRepository; |
| | | import me.zhengjie.modules.project.service.ProjectCostService; |
| | | import me.zhengjie.modules.project.service.dto.ProjectReimburseQueryCriteria; |
| | | import me.zhengjie.modules.quartz.service.impl.WeComServiceImpl; |
| | | import me.zhengjie.modules.salary.repository.NewSalaryRepository; |
| | | import me.zhengjie.modules.salary.service.dto.NewSalaryQueryCriteria; |
| | | import me.zhengjie.modules.system.domain.*; |
| | | import me.zhengjie.modules.system.repository.*; |
| | | import me.zhengjie.modules.system.service.dto.SysCompanyQueryCriteria; |
| | | import me.zhengjie.modules.system.service.dto.SysGoalSettingQueryCriteria; |
| | | import me.zhengjie.modules.system.service.dto.UserQueryCriteria; |
| | | import me.zhengjie.modules.task.domain.TaskMongo; |
| | | import me.zhengjie.modules.task.domain.TaskUserMongo; |
| | | import me.zhengjie.utils.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.Pageable; |
| | | import me.zhengjie.utils.PageUtil; |
| | | import me.zhengjie.utils.QueryHelp; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.aggregation.Aggregation; |
| | | import org.springframework.data.mongodb.core.aggregation.AggregationResults; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import org.w3c.dom.Document; |
| | | import org.xhtmlrenderer.swing.Java2DRenderer; |
| | | import org.xhtmlrenderer.util.FSImageWriter; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.xml.parsers.DocumentBuilder; |
| | | import javax.xml.parsers.DocumentBuilderFactory; |
| | | import java.awt.image.BufferedImage; |
| | | import java.io.*; |
| | | import java.math.BigDecimal; |
| | | import java.sql.Timestamp; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.time.temporal.IsoFields; |
| | | import java.util.*; |
| | | import java.io.IOException; |
| | | import java.util.function.Function; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.stream.Collectors; |
| | | import java.util.zip.ZipEntry; |
| | | import java.util.zip.ZipOutputStream; |
| | | |
| | | /** |
| | | * @website https://eladmin.vip |
| | |
| | | private final ContractPaymentRepository contractPaymentRepository; |
| | | private final ContractInvoicePaymentRepository contractInvoicePaymentRepository; |
| | | private final ContractInvoiceRepository contractInvoiceRepository; |
| | | private final DictRepository dictRepository; |
| | | private final DictDetailRepository dictDetailRepository; |
| | | private final ContractFirstServiceImpl contractFirstServiceImpl; |
| | | private final ContractFirstRepository contractFirstRepository; |
| | | private final ContractSecondServiceImpl contractSecondServiceImpl; |
| | | private final ProjectServiceImpl projectServiceImpl; |
| | | private final ContractSecondRepository contractSecondRepository; |
| | | private final ContractProjectRepository contractProjectRepository; |
| | | private final SysCompanyRepository sysCompanyRepository; |
| | | private final ProjectCostService projectCostService; |
| | | private final SysGoalSettingRepository sysGoalSettingRepository; |
| | | private final NewSalaryRepository newSalaryRepository; |
| | | private final ProjectReimburseRepository projectReimburseRepository; |
| | | private final UserRepository userRepository; |
| | | private final FileProperties properties; |
| | | private final WeComServiceImpl weComService; |
| | | private final TemplateControlFieldService templateControlFieldService; |
| | | |
| | | @Autowired |
| | | private final MongoTemplate mongoTemplate; |
| | | |
| | | @Override |
| | | public Map<String,Object> queryAll(ContractQueryCriteria criteria, Pageable pageable){ |
| | | criteria.setCompanys(SecurityUtils.getCompanyIds()); |
| | | Page<Contract> page = contractRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); |
| | | // 将实体类转换为DTO(重写) |
| | | Function<Contract, ContractDto> func = new Function<Contract, ContractDto>(){ |
| | |
| | | public ContractDto apply(Contract t) { |
| | | // 将实体类转换成DTO |
| | | ContractDto contractDto = contractMapper.toDto(t); |
| | | |
| | | // 合同款延期情况 |
| | | contractDto.setContractPostponement(contractPostponement(t)); |
| | | // 服务款延期情况 |
| | |
| | | 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)); |
| | | // 服务款付款金额 |
| | |
| | | contractDto.setFirstName(contractFirstName(t)); |
| | | // 乙方姓名 |
| | | contractDto.setSecondName(contractSecondName(t)); |
| | | // 项目名称 |
| | | contractDto.setProjectName(projectName(t)); |
| | | // 合同费数量 |
| | | contractDto.setFundContractNum(contractProjectNum(t, Constant.FUND_CONTRACT)); |
| | | // 合同费金额 |
| | | contractDto.setFundContractAmount(contractProjectAmount(t, Constant.FUND_CONTRACT)); |
| | | // 服务费数量 |
| | | contractDto.setFundServiceNum(contractProjectNum(t, Constant.FUND_SERVICE)); |
| | | // 服务费金额 |
| | | contractDto.setFundServiceAmount(contractProjectAmount(t, Constant.FUND_SERVICE)); |
| | | // 返回处理好的DTO |
| | | return contractDto; |
| | | } |
| | |
| | | |
| | | @Override |
| | | public List<ContractDto> queryAll(ContractQueryCriteria criteria){ |
| | | criteria.setCompanys(SecurityUtils.getCompanyIds()); |
| | | // 合同DTO列表 |
| | | List<ContractDto> contractDtoList = new ArrayList<>(); |
| | | // 查询合同列表 |
| | |
| | | contractDto.setFirstName(contractFirstName(contractList.get(i))); |
| | | // 乙方姓名 |
| | | contractDto.setSecondName(contractSecondName(contractList.get(i))); |
| | | // 项目名称 |
| | | contractDto.setProjectName(projectName(contractList.get(i))); |
| | | // 合同费数量 |
| | | contractDto.setFundContractNum(contractProjectNum(contractList.get(i), Constant.FUND_CONTRACT)); |
| | | // 合同费金额 |
| | | contractDto.setFundContractAmount(contractProjectAmount(contractList.get(i), Constant.FUND_CONTRACT)); |
| | | // 服务费数量 |
| | | contractDto.setFundServiceNum(contractProjectNum(contractList.get(i), Constant.FUND_SERVICE)); |
| | | // 服务费金额 |
| | | contractDto.setFundServiceAmount(contractProjectAmount(contractList.get(i), Constant.FUND_SERVICE)); |
| | | // DTO新增 |
| | | contractDtoList.add(contractDto); |
| | | } |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ContractDto create(Contract resources) { |
| | | // 当前日历类 |
| | | Calendar calendar = Calendar.getInstance(); |
| | | // 当前年份 |
| | | String year = String.valueOf(calendar.get(Calendar.YEAR)); |
| | | // 当前月份 |
| | | String month = calendar.get(Calendar.MONTH) + 1 >= 10 ? "" + (calendar.get(Calendar.MONTH) + 1) : "0" + (calendar.get(Calendar.MONTH) + 1); |
| | | // 当前日份 |
| | | String date = calendar.get(Calendar.DATE) >= 10 ? "" + calendar.get(Calendar.DATE) : "0" + calendar.get(Calendar.DATE); |
| | | // 查询当天合同数据 |
| | | List<Contract> contracts = contractRepository.findLikeContractNumber(year + "-" + month + date); |
| | | // 当天合同最大编号 |
| | | int maxNumber = 0; |
| | | // 循环当天合同数据 |
| | | for(int i = 0; i < contracts.size(); i ++) { |
| | | // 当前合同编号 |
| | | int nowNumber = Integer.valueOf(contracts.get(i).getContractNumber().substring(10, 13)); |
| | | // 最大合同编号 |
| | | maxNumber = nowNumber > maxNumber ? nowNumber : maxNumber; |
| | | } |
| | | // 计算下一编号 |
| | | String nextNumber = maxNumber + 1 >= 100 ? "" + (maxNumber + 1) : maxNumber + 1 >= 10 ? "0" + (maxNumber + 1) : "00" + (maxNumber + 1); |
| | | // 合同编号 |
| | | resources.setContractNumber(year + "-" + month + date + "-" + nextNumber); |
| | | // 更新金额相关数据 |
| | | Contract contract = updateAmountData(resources); |
| | | return contractMapper.toDto(contractRepository.save(contract)); |
| | | |
| | | // 保存后再更新合同编号(获取健全信息,防止顺序编号冲突) |
| | | contract = updateContractNumber(contractRepository.save(contract)); |
| | | |
| | | return contractMapper.toDto(contract); |
| | | } |
| | | |
| | | @Override |
| | |
| | | Contract contractOne = updatePaymentStatus(contract); |
| | | // 更新金额相关数据 |
| | | Contract contractTwo = updateAmountData(contractOne); |
| | | contractRepository.save(contractTwo); |
| | | |
| | | updateContractNumber(contractRepository.save(contractTwo)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | contractRepository.deleteById(contractId); |
| | | contractInvoiceRepository.deleteByContractId(contractId); |
| | | contractPaymentRepository.deleteByContractId(contractId); |
| | | contractProjectRepository.deleteByContractId(contractId); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void download(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)); |
| | | |
| | | 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)); |
| | | String projectName = projectName(contractMapper.toEntity(contract)); |
| | | String contractType = contract.getContractType() != null ? dictDetailRepository.findByDictNameAndValue(Constant.CONTRACT_TYPE, contract.getContractType()).getLabel() : ""; |
| | | String contractPaymentState = contract.getContractPaymentState() != null ? dictDetailRepository.findByDictNameAndValue(Constant.PAYMENT_STATE, contract.getContractPaymentState()).getLabel() : ""; |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | String servicePaymentDate = null; |
| | | if(contract.getServicePaymentDate() != null) { |
| | | servicePaymentDate = sdf.format(contract.getServicePaymentDate()); |
| | | servicePaymentDate = servicePaymentDate.substring(5, 10); |
| | | } |
| | | String servicePaymentState = contract.getServicePaymentState() != null ? dictDetailRepository.findByDictNameAndValue(Constant.PAYMENT_STATE, contract.getServicePaymentState()).getLabel() : ""; |
| | | String contractStatus = contract.getContractStatus() != null ? dictDetailRepository.findByDictNameAndValue(Constant.CONTRACT_STATUS, contract.getContractStatus()).getLabel() : ""; |
| | | Map<String,Object> map = new LinkedHashMap<>(); |
| | | map.put("合同编号", contract.getContractNumber()); |
| | | map.put("合同名称", contract.getContractName()); |
| | |
| | | map.put("起始日期", contract.getStartDate()); |
| | | map.put("截止日期", contract.getEndDate()); |
| | | map.put("合同所属地区", contract.getContractArea()); |
| | | map.put("合同类型", contractType); |
| | | map.put("合同类型(一级)", contractTypeMap.containsKey(contract.getContractType()) ? contractTypeMap.get(contract.getContractType()) : ""); |
| | | map.put("合同类型(二级)", contract.getContractSecondType()); |
| | | map.put("合同内容", contract.getContractContent()); |
| | | map.put("开票总金额", contract.getBillingTotalAmount()); |
| | | map.put("付款总金额", contract.getPaymentTotalAmount()); |
| | |
| | | map.put("应收款金额", contract.getReceivePayment()); |
| | | map.put("合同费金额", contract.getContractAmount()); |
| | | map.put("合同费预计付款日期", contract.getContractPaymentDate()); |
| | | map.put("合同费付款状态", contractPaymentState); |
| | | map.put("合同费付款状态", paymentStateMap.containsKey(contract.getContractPaymentState()) ? paymentStateMap.get(contract.getContractPaymentState()) : ""); |
| | | map.put("合同费延期情况", contract.getContractPostponement()); |
| | | map.put("服务开始日期", contract.getServiceStartsDate()); |
| | | map.put("服务费金额", contract.getServiceAmount()); |
| | | map.put("服务费预计付款日期", servicePaymentDate); |
| | | map.put("服务费付款状态", servicePaymentState); |
| | | map.put("服务费付款状态", paymentStateMap.containsKey(contract.getServicePaymentState()) ? paymentStateMap.get(contract.getServicePaymentState()) : ""); |
| | | map.put("服务费延期情况", contract.getServicePostponement()); |
| | | map.put("合同初版文件", contract.getRelatedDocumentsFirst()); |
| | | map.put("合同终版文件", contract.getRelatedDocumentsFinal()); |
| | | map.put("合同状态", contractStatus); |
| | | map.put("项目名称", projectName); |
| | | 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); |
| | | } |
| | | FileUtil.downloadExcel(list, response); |
| | | } |
| | | |
| | | @Override |
| | | public void download(ContractQueryCriteria criteria, HttpServletResponse response) throws IOException { |
| | | criteria.setCompanys(SecurityUtils.getCompanyIds()); |
| | | // 查询合同列表 |
| | | List<Contract> contractList = contractRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)); |
| | | 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 ymsdf = new SimpleDateFormat("yyyy-MM"); |
| | | for (Contract contract : contractList) { |
| | | String firstName = contractFirstName(contract); |
| | | String secondName = contractSecondName(contract); |
| | | String relatedDocumentsAttachment = ""; |
| | | if (StringUtils.isNotBlank(contract.getRelatedDocumentsAttachment())) { |
| | | relatedDocumentsAttachment = Arrays.stream(contract.getRelatedDocumentsAttachment().split(",")).map(item -> Arrays.stream(item.trim().split("/")).reduce("", (f, s) -> s)).reduce("", (first, second) -> first.length() == 0 ? second : first.concat(",").concat(second)); |
| | | } |
| | | |
| | | ContractPaymentQueryCriteria paymentQueryCriteria = new ContractPaymentQueryCriteria(); |
| | | paymentQueryCriteria.setContractId(contract.getContractId()); |
| | | List<ContractPayment> paymentList = contractPaymentRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,paymentQueryCriteria,criteriaBuilder)); |
| | | if (paymentList.size() <= 0) { |
| | | // 至少一条 |
| | | paymentList.add(new ContractPayment()); |
| | | } |
| | | |
| | | for (ContractPayment payment : paymentList) { |
| | | List<ContractInvoice> invoiceList = new ArrayList<>(); |
| | | if (ObjectUtil.isNotEmpty(payment.getPaymentId())) { |
| | | ContractInvoicePaymentQueryCriteria invoicePaymentQueryCriteria = new ContractInvoicePaymentQueryCriteria(); |
| | | invoicePaymentQueryCriteria.setPaymentId(payment.getPaymentId()); |
| | | List<ContractInvoicePayment> invoicePaymentList = contractInvoicePaymentRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,invoicePaymentQueryCriteria,criteriaBuilder)); |
| | | if (invoicePaymentList.size() > 0) { |
| | | for (ContractInvoicePayment invoicePayment : invoicePaymentList) { |
| | | ContractInvoice invoice = contractInvoiceRepository.getById(invoicePayment.getInvoiceId()); |
| | | invoiceList.add(invoice); |
| | | } |
| | | } else { |
| | | invoiceList.add(new ContractInvoice()); |
| | | } |
| | | } else { |
| | | invoiceList.add(new ContractInvoice()); |
| | | } |
| | | |
| | | BigDecimal paymentAmount = ObjectUtil.isNotEmpty(payment.getPaymentAmount()) ? payment.getPaymentAmount() : new BigDecimal(0); |
| | | BigDecimal advancePayment = ObjectUtil.isNotEmpty(payment.getPaymentAmount()) ? payment.getPaymentAmount() : new BigDecimal(0); |
| | | |
| | | for (ContractInvoice invoice : invoiceList) { |
| | | BigDecimal afterTaxAmount = ObjectUtil.isNotEmpty(invoice.getAfterTaxAmount()) ? invoice.getAfterTaxAmount() : new BigDecimal(0); |
| | | BigDecimal receivePayment = afterTaxAmount.subtract(paymentAmount); |
| | | advancePayment = advancePayment.subtract(afterTaxAmount); |
| | | |
| | | Map<String,Object> map = new LinkedHashMap<>(); |
| | | map.put("合同编号", contract.getContractNumber()); |
| | | map.put("合同名称", contract.getContractName()); |
| | | map.put("甲方姓名", firstName); |
| | | map.put("乙方姓名", secondName); |
| | | map.put("签订日期", contract.getSignDate()); |
| | | map.put("起始日期", contract.getStartDate()); |
| | | map.put("截止日期", contract.getEndDate()); |
| | | map.put("合同所属地区", contract.getContractArea()); |
| | | map.put("合同类型", contractTypeMap.get(contract.getContractType())); |
| | | map.put("合同类型(二级)", contract.getContractSecondType()); |
| | | map.put("合同内容", contract.getContractContent()); |
| | | map.put("合同状态", contractStatusMap.get(contract.getContractStatus())); |
| | | map.put("开票金额", invoice.getAfterTaxAmount()); |
| | | map.put("开票日期", invoice.getBillingTime()); |
| | | map.put("付款金额", payment.getPaymentAmount()); |
| | | map.put("预收款金额", advancePayment.compareTo(new BigDecimal(0)) < 1 ? new BigDecimal(0) : advancePayment); |
| | | map.put("应收款金额", receivePayment.compareTo(new BigDecimal(0)) < 1 ? new BigDecimal(0) : receivePayment); |
| | | map.put("合同费金额", contract.getContractAmount()); |
| | | map.put("合同费预计付款日期", contract.getContractPaymentDate()); |
| | | map.put("合同费付款状态", paymentStateMap.get(contract.getContractPaymentState())); |
| | | map.put("付款时间", payment.getPaymentTime()); |
| | | map.put("合同费延期情况", contractPostponement(contract)); |
| | | map.put("服务开始日期", contract.getServiceStartsDate()); |
| | | map.put("服务费金额", contract.getServiceAmount()); |
| | | map.put("服务费预计付款日期", contract.getServicePaymentDate()); |
| | | map.put("服务费付款状态", paymentStateMap.get(contract.getServicePaymentState())); |
| | | map.put("服务费延期情况", servicePostponement(contract)); |
| | | map.put("合同初版文件", contract.getRelatedDocumentsFirst()); |
| | | map.put("合同终版文件", contract.getRelatedDocumentsFinal()); |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | |
| | | FileUtil.downloadExcel(list, response); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * 项目名称 |
| | | * 合同项目数量 |
| | | * @param resources |
| | | * @return |
| | | */ |
| | | public String projectName(Contract resources) { |
| | | // 判断项目ID是否为空 |
| | | if (resources.getProjectId() != null) { |
| | | // 查询项目数据 |
| | | ProjectDto projectDto = projectServiceImpl.findById(resources.getProjectId()); |
| | | return projectDto.getName(); |
| | | } else { |
| | | return null; |
| | | } |
| | | public Integer contractProjectNum(Contract resources, String fundType) { |
| | | // 查询合同项目数据 |
| | | return contractProjectRepository.countByContractIdAndFundType(resources.getContractId(), fundType); |
| | | } |
| | | |
| | | /** |
| | | * 合同项目金额 |
| | | * @param resources |
| | | * @return |
| | | */ |
| | | public BigDecimal contractProjectAmount(Contract resources, String fundType) { |
| | | // 查询合同项目数据 |
| | | return contractProjectRepository.sumAllocatedAmountByContractIdAndFundType(resources.getContractId(), fundType); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return |
| | | */ |
| | | public String contractPostponement(Contract resources) { |
| | | if (Constant.RECOVERY_STATUS_ABANDON.equals(resources.getRecoveryStatus())) { |
| | | return ""; |
| | | } |
| | | |
| | | // 时间格式化 |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | |
| | | * @return |
| | | */ |
| | | public String servicePostponement(Contract resources) { |
| | | if (Constant.RECOVERY_STATUS_ABANDON.equals(resources.getRecoveryStatus())) { |
| | | return ""; |
| | | } |
| | | |
| | | // 时间格式化 |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | // 服务开始年份 |
| | |
| | | * @return |
| | | */ |
| | | public Contract updateAmountData(Contract resources) { |
| | | if (StringUtils.isNotBlank(resources.getContractType()) && StringUtils.isNotBlank(resources.getContractSecondType())) { |
| | | // 判断是否是已存在的合同类型(二级) |
| | | if (ElAdminConstant.Enum.ContractTypeDict.findByDictValue(resources.getContractType()) != null) { |
| | | String secondDictName = ElAdminConstant.Enum.ContractTypeDict.findByDictValue(resources.getContractType()).getSecondDictName(); |
| | | DictDetail dictDetail = dictDetailRepository.findByDictNameAndValue(secondDictName, resources.getContractSecondType()); |
| | | if (dictDetail == null) { |
| | | // 新建合同类型(二级) |
| | | dictDetail = new DictDetail(); |
| | | Dict dict = dictRepository.findByName(secondDictName); |
| | | dictDetail.setDict(dict); |
| | | dictDetail.setLabel(resources.getContractSecondType()); |
| | | dictDetail.setValue(resources.getContractSecondType()); |
| | | dictDetail.setDictSort(10); |
| | | dictDetailRepository.save(dictDetail); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 判断合同类型 |
| | | if (Constant.CONTRACT_DEVELOP_SERVICE.equals(resources.getContractType())) { |
| | | if (Constant.CONTRACT_TECHNOLOGY.equals(resources.getContractType()) && Constant.CONTRACT_DEVELOP_SERVICE.equals(resources.getContractSecondType())) { |
| | | // 不处理 |
| | | } else if (Constant.CONTRACT_SERVICE.equals(resources.getContractType())) { |
| | | } else if (Constant.CONTRACT_TECHNOLOGY.equals(resources.getContractType()) && Constant.CONTRACT_SERVICE.equals(resources.getContractSecondType())) { |
| | | // 合同费金额 |
| | | resources.setContractAmount(null); |
| | | // 预计付款日期 |
| | |
| | | BigDecimal contractAmount = contractPaymentRepository.findByContractIdAndFundType(contract.getContractId(), Constant.FUND_CONTRACT); |
| | | contractAmount = contractAmount == null ? new BigDecimal(0) : contractAmount; |
| | | // 判断合同款项付款金额 |
| | | if(Constant.CONTRACT_SERVICE.equals(contract.getContractType())) { |
| | | if(Constant.CONTRACT_TECHNOLOGY.equals(contract.getContractType()) && Constant.CONTRACT_SERVICE.equals(contract.getContractSecondType())) { |
| | | // 付款状态 |
| | | contract.setContractPaymentState(null); |
| | | } else if(contractAmount.compareTo(new BigDecimal(0)) == 0) { |
| | |
| | | BigDecimal serviceAmount = contractPaymentRepository.findByContractIdAndFundType(contract.getContractId(), Constant.FUND_SERVICE); |
| | | serviceAmount = serviceAmount == null ? new BigDecimal(0) : serviceAmount; |
| | | // 判断服务款项付款金额 |
| | | if(Constant.CONTRACT_DEVELOP.equals(contract.getContractType())) { |
| | | if(Constant.CONTRACT_TECHNOLOGY.equals(contract.getContractType()) && Constant.CONTRACT_DEVELOP.equals(contract.getContractSecondType())) { |
| | | // 付款状态 |
| | | contract.setServicePaymentState(null); |
| | | } else if(serviceAmount.compareTo(new BigDecimal(0)) == 0) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 更新合同编号(因更新序号需求加锁执行)(本更新为先存其他后改) |
| | | * @param resources |
| | | * @return |
| | | */ |
| | | public synchronized Contract updateContractNumber(Contract resources) { |
| | | StringBuilder contractNumber = new StringBuilder(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | |
| | | if (StringUtils.isNotBlank(resources.getContractNumber())) { |
| | | // 修改编号 |
| | | calendar.setTime(resources.getSignDate()); |
| | | contractNumber.append(resources.getContractNumber().substring(0, 9)); |
| | | |
| | | // 业绩年度 |
| | | String oldSignYear = resources.getContractNumber().substring(9, 11); |
| | | String newSignYear = String.valueOf(calendar.get(Calendar.YEAR)).substring(2); |
| | | // 是否有真实合同 |
| | | String oldTrueContract = resources.getContractNumber().substring(14, 15); |
| | | String newTrueContract = resources.getContractStatus().equals(Constant.CONTRACT_STATUS_NOT_SIGN) ? Constant.CONTRACT_REAL_SIGN_N : Constant.CONTRACT_REAL_SIGN_Y; |
| | | |
| | | if (oldSignYear.equals(newSignYear)) { |
| | | contractNumber.append(resources.getContractNumber().substring(9, 14)); |
| | | } else { |
| | | // 业绩年度(以签订日期为准) |
| | | contractNumber.append(newSignYear); |
| | | // 本公司当年编号(以签订日期为准)(因先存后改故排除本身数据) |
| | | // TODO:250115业务方提出修改为以创建日期为准 |
| | | contractNumber.append(resources.getContractNumber().substring(11, 14)); |
| | | } |
| | | |
| | | if (oldTrueContract.equals(newTrueContract)) { |
| | | contractNumber.append(resources.getContractNumber().substring(14, 15)); |
| | | } else { |
| | | // 是否有真实合同 |
| | | contractNumber.append(newTrueContract); |
| | | } |
| | | // 全部公司当年编号(以签订日期为准) |
| | | // TODO:250115业务方提出修改为以创建日期为准 |
| | | contractNumber.append(resources.getContractNumber().substring(15)); |
| | | |
| | | if (resources.getContractNumber().equals(contractNumber.toString())) { |
| | | return resources; |
| | | } else { |
| | | resources.setContractNumber(contractNumber.toString()); |
| | | } |
| | | } else { |
| | | // 新建编号 |
| | | String companyCode; |
| | | String sign; |
| | | Long companyId = null; |
| | | |
| | | // 合同前缀 |
| | | String firstName = contractFirstName(resources); |
| | | String SecondName = contractSecondName(resources); |
| | | if (ElAdminConstant.Enum.CompanySuffix.findByCompanyName(firstName) != null) { |
| | | companyCode = ElAdminConstant.Enum.CompanySuffix.findByCompanyName(firstName).getCode(); |
| | | sign = Constant.CONTRACT_DEMAND_SIGN_J; |
| | | contractNumber.append(companyCode); |
| | | SysCompanyQueryCriteria criteria = new SysCompanyQueryCriteria(); |
| | | criteria.setLabel(ElAdminConstant.Enum.CompanySuffix.findByCompanyName(firstName).getCompanyName()); |
| | | List<SysCompany> companyList = sysCompanyRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)); |
| | | if (companyList.size() > 0) { |
| | | companyId = companyList.get(0).getId(); |
| | | } |
| | | } else if (ElAdminConstant.Enum.CompanySuffix.findByCompanyName(SecondName) != null) { |
| | | companyCode = ElAdminConstant.Enum.CompanySuffix.findByCompanyName(SecondName).getCode(); |
| | | sign = Constant.CONTRACT_DEMAND_SIGN_Y; |
| | | contractNumber.append(companyCode); |
| | | SysCompanyQueryCriteria criteria = new SysCompanyQueryCriteria(); |
| | | criteria.setLabel(ElAdminConstant.Enum.CompanySuffix.findByCompanyName(SecondName).getCompanyName()); |
| | | List<SysCompany> companyList = sysCompanyRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)); |
| | | if (companyList.size() > 0) { |
| | | companyId = companyList.get(0).getId(); |
| | | } |
| | | } else { |
| | | return resources; |
| | | } |
| | | // 签订年度(以创建日期为准) |
| | | calendar.setTime(resources.getCreateTime()); |
| | | contractNumber.append(String.valueOf(calendar.get(Calendar.YEAR)).substring(2)); |
| | | // 签订月份(以创建日期为准) |
| | | contractNumber.append(calendar.get(Calendar.MONTH) + 1 >= 10 ? "" + (calendar.get(Calendar.MONTH) + 1) : "0" + (calendar.get(Calendar.MONTH) + 1)); |
| | | // 甲乙标识 |
| | | contractNumber.append(sign); |
| | | // 业绩年度(以签订日期为准) |
| | | calendar.setTime(resources.getSignDate()); |
| | | contractNumber.append(String.valueOf(calendar.get(Calendar.YEAR)).substring(2)); |
| | | // 本公司当年编号(以签订日期为准)(因先存后改故排除本身数据) |
| | | // TODO:250115业务方提出修改为以创建日期为准 |
| | | calendar.setTime(resources.getCreateTime()); |
| | | Long companySort = contractRepository.countContractSort(String.valueOf(calendar.get(Calendar.YEAR)), companyCode, resources.getContractId()); |
| | | contractNumber.append(String.format("%03d", (companySort == null ? 0L : companySort) + 1)); |
| | | // 是否有真实合同 |
| | | if (resources.getContractStatus().equals(Constant.CONTRACT_STATUS_NOT_SIGN)) { |
| | | contractNumber.append(Constant.CONTRACT_REAL_SIGN_N); |
| | | } else { |
| | | contractNumber.append(Constant.CONTRACT_REAL_SIGN_Y); |
| | | } |
| | | // 全部公司当年编号(以签订日期为准)(因先存后改故排除本身数据) |
| | | // TODO:250115业务方提出修改为以创建日期为准 |
| | | Long allCompanySort = contractRepository.countAllContractSort(String.valueOf(calendar.get(Calendar.YEAR)), resources.getContractId()); |
| | | contractNumber.append(String.format("%04d", (allCompanySort == null ? 0L : allCompanySort) + 1)); |
| | | |
| | | resources.setContractNumber(contractNumber.toString()); |
| | | if (companyId != null) { |
| | | resources.setCompanyId(companyId); |
| | | } else { |
| | | throw new BadRequestException("未匹配到所属公司,所属公司不能为空。"); |
| | | } |
| | | } |
| | | |
| | | return contractRepository.save(resources); |
| | | } |
| | | |
| | | /** |
| | | * 查询合同款总金额 |
| | | * @param criteria |
| | | * @return |
| | | */ |
| | | @Override |
| | | public BigDecimal contractTotalMoney(ContractQueryCriteria criteria){ |
| | | criteria.setCompanys(SecurityUtils.getCompanyIds()); |
| | | // 搜索数据处理 |
| | | String signStartDate = criteria.getSignDate() != null ? criteria.getSignDate().get(0).toString() : null; |
| | | String signEndDate = criteria.getSignDate() != null ? criteria.getSignDate().get(1).toString() : null; |
| | | // 查询合同款总金额 |
| | | BigDecimal contractTotalMoney = contractRepository.contractTotalMoney( |
| | | criteria.getContractNumber(), criteria.getContractName(), criteria.getFirstId(), criteria.getSecondId(), signStartDate, signEndDate, criteria.getContractType(), |
| | | criteria.getContractPaymentState(), criteria.getServicePaymentState(), criteria.getContractStatus(), criteria.getContractAreaCode() |
| | | criteria.getContractPaymentState(), criteria.getServicePaymentState(), criteria.getContractStatus(), criteria.getContractAreaCode(), criteria.getCompanys() |
| | | ); |
| | | return contractTotalMoney; |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | public Integer contractDelayTotalAmount(ContractQueryCriteria criteria){ |
| | | criteria.setCompanys(SecurityUtils.getCompanyIds()); |
| | | // 合同款延期数 |
| | | Integer contractDelayTotalAmount = 0; |
| | | // 搜索数据处理 |
| | |
| | | // 查询有合同款的合同数据 |
| | | List<Contract> contractList = contractRepository.findContractAmountNotNull( |
| | | criteria.getContractNumber(), criteria.getContractName(), criteria.getFirstId(), criteria.getSecondId(), signStartDate, signEndDate, criteria.getContractType(), |
| | | criteria.getContractPaymentState(), criteria.getServicePaymentState(), criteria.getContractStatus(), criteria.getContractAreaCode() |
| | | criteria.getContractPaymentState(), criteria.getServicePaymentState(), criteria.getContractStatus(), criteria.getContractAreaCode(), criteria.getCompanys() |
| | | ); |
| | | // 循环有合同款的合同数据 |
| | | for(int i = 0; i < contractList.size(); i ++) { |
| | | if (Constant.RECOVERY_STATUS_ABANDON.equals(contractList.get(i).getRecoveryStatus())) { |
| | | continue; |
| | | } |
| | | // 查询合同各款项付款金额 |
| | | BigDecimal paymentAmount = contractPaymentRepository.findByContractIdAndFundType(contractList.get(i).getContractId(), Constant.FUND_CONTRACT); |
| | | // 判断是否超过付款时间 |
| | |
| | | */ |
| | | @Override |
| | | public BigDecimal contractDelayTotalMoney(ContractQueryCriteria criteria){ |
| | | criteria.setCompanys(SecurityUtils.getCompanyIds()); |
| | | // 合同款延期金额 |
| | | BigDecimal contractDelayTotalMoney = new BigDecimal("0.00"); |
| | | // 搜索数据处理 |
| | |
| | | // 查询有合同款的合同数据 |
| | | List<Contract> contractList = contractRepository.findContractAmountNotNull( |
| | | criteria.getContractNumber(), criteria.getContractName(), criteria.getFirstId(), criteria.getSecondId(), signStartDate, signEndDate, criteria.getContractType(), |
| | | criteria.getContractPaymentState(), criteria.getServicePaymentState(), criteria.getContractStatus(), criteria.getContractAreaCode() |
| | | criteria.getContractPaymentState(), criteria.getServicePaymentState(), criteria.getContractStatus(), criteria.getContractAreaCode(), criteria.getCompanys() |
| | | ); |
| | | // 循环有合同款的合同数据 |
| | | for(int i = 0; i < contractList.size(); i ++) { |
| | | if (Constant.RECOVERY_STATUS_ABANDON.equals(contractList.get(i).getRecoveryStatus())) { |
| | | continue; |
| | | } |
| | | // 查询合同各款项付款金额 |
| | | BigDecimal paymentAmount = contractPaymentRepository.findByContractIdAndFundType(contractList.get(i).getContractId(), Constant.FUND_CONTRACT); |
| | | // 判断是否超过付款时间 |
| | |
| | | */ |
| | | @Override |
| | | public BigDecimal advancePaymentTotalMoney(ContractQueryCriteria criteria){ |
| | | criteria.setCompanys(SecurityUtils.getCompanyIds()); |
| | | // 预收款总金额 |
| | | BigDecimal advancePaymentTotalMoney = new BigDecimal("0.00"); |
| | | // 查询所有合同信息 |
| | |
| | | */ |
| | | @Override |
| | | public BigDecimal serviceTotalMoney(ContractQueryCriteria criteria){ |
| | | criteria.setCompanys(SecurityUtils.getCompanyIds()); |
| | | // 搜索数据处理 |
| | | String signStartDate = criteria.getSignDate() != null ? criteria.getSignDate().get(0).toString() : null; |
| | | String signEndDate = criteria.getSignDate() != null ? criteria.getSignDate().get(1).toString() : null; |
| | | // 查询运维服务总金额 |
| | | BigDecimal serviceTotalMoney = contractRepository.serviceTotalMoney( |
| | | criteria.getContractNumber(), criteria.getContractName(), criteria.getFirstId(), criteria.getSecondId(), signStartDate, signEndDate, criteria.getContractType(), |
| | | criteria.getContractPaymentState(), criteria.getServicePaymentState(), criteria.getContractStatus(), criteria.getContractAreaCode() |
| | | criteria.getContractPaymentState(), criteria.getServicePaymentState(), criteria.getContractStatus(), criteria.getContractAreaCode(), criteria.getCompanys() |
| | | ); |
| | | return serviceTotalMoney; |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | public Integer serviceDelayTotalAmount(ContractQueryCriteria criteria){ |
| | | criteria.setCompanys(SecurityUtils.getCompanyIds()); |
| | | // 运维服务延期数 |
| | | Integer serviceDelayTotalAmount = 0; |
| | | // 搜索数据处理 |
| | |
| | | // 查询有运维服务的合同数据 |
| | | List<Contract> contractList = contractRepository.findServiceAmountNotNull( |
| | | criteria.getContractNumber(), criteria.getContractName(), criteria.getFirstId(), criteria.getSecondId(), signStartDate, signEndDate, criteria.getContractType(), |
| | | criteria.getContractPaymentState(), criteria.getServicePaymentState(), criteria.getContractStatus(), criteria.getContractAreaCode() |
| | | criteria.getContractPaymentState(), criteria.getServicePaymentState(), criteria.getContractStatus(), criteria.getContractAreaCode(), criteria.getCompanys() |
| | | ); |
| | | // 循环有运维服务的合同数据 |
| | | for(int i = 0; i < contractList.size(); i ++) { |
| | | if (Constant.RECOVERY_STATUS_ABANDON.equals(contractList.get(i).getRecoveryStatus())) { |
| | | continue; |
| | | } |
| | | // 时间格式化 |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | // 服务开始年份 |
| | |
| | | */ |
| | | @Override |
| | | public BigDecimal serviceDelayTotalMoney(ContractQueryCriteria criteria){ |
| | | criteria.setCompanys(SecurityUtils.getCompanyIds()); |
| | | // 运维服务延期金额 |
| | | BigDecimal serviceDelayTotalMoney = new BigDecimal("0.00"); |
| | | // 搜索数据处理 |
| | |
| | | // 查询有运维服务的合同数据 |
| | | List<Contract> contractList = contractRepository.findServiceAmountNotNull( |
| | | criteria.getContractNumber(), criteria.getContractName(), criteria.getFirstId(), criteria.getSecondId(), signStartDate, signEndDate, criteria.getContractType(), |
| | | criteria.getContractPaymentState(), criteria.getServicePaymentState(), criteria.getContractStatus(), criteria.getContractAreaCode() |
| | | criteria.getContractPaymentState(), criteria.getServicePaymentState(), criteria.getContractStatus(), criteria.getContractAreaCode(), criteria.getCompanys() |
| | | ); |
| | | // 循环有运维服务的合同数据 |
| | | for(int i = 0; i < contractList.size(); i ++) { |
| | | if (Constant.RECOVERY_STATUS_ABANDON.equals(contractList.get(i).getRecoveryStatus())) { |
| | | continue; |
| | | } |
| | | // 时间格式化 |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | // 服务开始年份 |
| | |
| | | */ |
| | | @Override |
| | | public BigDecimal receivePaymentTotalMoney(ContractQueryCriteria criteria){ |
| | | criteria.setCompanys(SecurityUtils.getCompanyIds()); |
| | | // 应收款总金额 |
| | | BigDecimal receivePaymentTotalMoney = new BigDecimal("0.00"); |
| | | // 查询所有合同信息 |
| | |
| | | } |
| | | return receivePaymentTotalMoney; |
| | | } |
| | | |
| | | /** |
| | | * 批量导入合同详情 |
| | | * @param file |
| | | * @return Map<String, Object> |
| | | */ |
| | | @Override |
| | | public Map<String, Object> batchUpload(MultipartFile file) { |
| | | FileUtil.checkSize(properties.getMaxSize(), file.getSize()); |
| | | if (ObjectUtil.isNull(file)) { |
| | | throw new BadRequestException("上传失败"); |
| | | } |
| | | |
| | | 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)) { |
| | | throw new BadRequestException("Excel解析失败"); |
| | | } |
| | | Map<String, Object> finalMap = new HashMap<>(); |
| | | finalMap.put("errCode", 0); |
| | | finalMap.put("errMsg", null); |
| | | |
| | | try { |
| | | List<Contract> contractList = new ArrayList<>(); |
| | | Map<String, List<Map<String, Object>>> supplyMap = new HashMap<>(); |
| | | Map<String, List<Integer>> errorMap = new HashMap<>(); |
| | | Map<String, Map<String, String>> chinaAreaMap = ChinaArea.getAreaData(); |
| | | Map<String, Long> firstMap = contractFirstRepository.findAll().stream().collect(Collectors.toMap(ContractFirst::getFirstName, ContractFirst::getFirstId)); |
| | | Map<String, Long> secondMap = contractSecondRepository.findAll().stream().collect(Collectors.toMap(ContractSecond::getSecondName, ContractSecond::getSecondId)); |
| | | Map<String, Long> companyMap = sysCompanyRepository.findAll().stream().collect(Collectors.toMap(SysCompany::getLabel, SysCompany::getId)); |
| | | Map<String, String> provinceMap = chinaAreaMap.get("86").entrySet().stream().collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey)); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | SimpleDateFormat useSdf = new SimpleDateFormat("yyyy-MM-dd 00:00:00"); |
| | | int rowNum = 1; |
| | | |
| | | for (Map<String,Object> row: readAll) { |
| | | Contract contract = new Contract(); |
| | | ContractInvoice invoice = new ContractInvoice(); |
| | | ContractPayment payment = new ContractPayment(); |
| | | |
| | | if (checkRequiredColumn(row, "合同编号", rowNum, errorMap)) { |
| | | contract.setContractNumber(row.get("合同编号").toString()); |
| | | } |
| | | checkRequiredColumn(row, "合同编号", rowNum, errorMap); |
| | | if (checkRequiredColumn(row, "合同名称", rowNum, errorMap)) { |
| | | contract.setContractName(row.get("合同名称").toString()); |
| | | } |
| | | if (checkRequiredColumn(row, "甲方姓名", rowNum, errorMap) && checkCompanyColumn(row, "甲方姓名", rowNum, errorMap, firstMap)) { |
| | | contract.setFirstId(firstMap.get(row.get("甲方姓名").toString())); |
| | | } |
| | | if (checkRequiredColumn(row, "乙方姓名", rowNum, errorMap) && checkCompanyColumn(row, "乙方姓名", rowNum, errorMap, secondMap)) { |
| | | contract.setSecondId(secondMap.get(row.get("乙方姓名").toString())); |
| | | // 合同付款:所属公司 |
| | | if (companyMap.containsKey(row.get("乙方姓名").toString())) { |
| | | payment.setCompanyId(companyMap.get(row.get("乙方姓名").toString())); |
| | | } |
| | | } |
| | | if (checkRequiredColumn(row, "签订日期", rowNum, errorMap)) { |
| | | contract.setSignDate(Timestamp.valueOf(row.get("签订日期").toString())); |
| | | // 业绩日期按照签订日期填充 |
| | | contract.setPerformanceDate(Timestamp.valueOf(row.get("签订日期").toString())); |
| | | } |
| | | if (checkRequiredColumn(row, "起始日期", rowNum, errorMap)) { |
| | | contract.setStartDate(Timestamp.valueOf(row.get("起始日期").toString())); |
| | | } |
| | | if (checkRequiredColumn(row, "截止日期", rowNum, errorMap)) { |
| | | contract.setEndDate(Timestamp.valueOf(row.get("截止日期").toString())); |
| | | } |
| | | if (checkRequiredColumn(row, "合同所属地区", rowNum, errorMap)) { |
| | | String contractArea = row.get("合同所属地区").toString(); |
| | | contract.setContractArea(contractArea); |
| | | // 合同所属地区编码 |
| | | int finalRowNum = rowNum; |
| | | try { |
| | | String contractAreaCode = Arrays.stream(contractArea.split("/")).filter(item -> StringUtils.isNotBlank(item)).reduce("", (concatStr, itemStr) -> { |
| | | if (concatStr.length() == 0) { |
| | | return provinceMap.get(itemStr); |
| | | } else { |
| | | if (itemStr.equals("本级")) { |
| | | return concatStr; |
| | | } else { |
| | | List<String> contractAreaCodeList = Arrays.stream(concatStr.split("/")).collect(Collectors.toList()); |
| | | String superAreaCode = contractAreaCodeList.get(contractAreaCodeList.size() - 1); |
| | | Map<String, String> superAreaMap = chinaAreaMap.get(superAreaCode).entrySet().stream().collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey)); |
| | | if (superAreaMap.containsKey(itemStr)) { |
| | | return concatStr.concat("/").concat(superAreaMap.get(itemStr)); |
| | | } else { |
| | | customizeErrorColumn("合同所属地区编码校验未通过", finalRowNum, errorMap); |
| | | return concatStr; |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | contract.setContractAreaCode(contractAreaCode); |
| | | } catch (Exception e) { |
| | | customizeErrorColumn("合同所属地区输入错误", rowNum, errorMap); |
| | | } |
| | | } |
| | | if (checkRequiredColumn(row, "合同类型", rowNum, errorMap) && checkTypeColumn(row, "合同类型", rowNum, errorMap)) { |
| | | contract.setContractType(ElAdminConstant.Enum.ContractTypeDict.findByImportValue(row.get("合同类型").toString()).getDictValue()); |
| | | } |
| | | if (checkRequiredColumn(row, "合同类型(二级)", rowNum, errorMap)) { |
| | | contract.setContractSecondType(row.get("合同类型(二级)").toString()); |
| | | } |
| | | if (ObjectUtil.isNotEmpty(row.get("合同内容"))) { |
| | | contract.setContractContent(row.get("合同内容").toString()); |
| | | } |
| | | if (checkRequiredColumn(row, "合同状态", rowNum, errorMap)) { |
| | | if (row.get("合同状态").toString().equals("未签订")) { |
| | | contract.setContractStatus(Constant.CONTRACT_STATUS_UNSIGNED); |
| | | } else if (row.get("合同状态").toString().equals("签订中")) { |
| | | contract.setContractStatus(Constant.CONTRACT_STATUS_SIGNING); |
| | | } else if (row.get("合同状态").toString().equals("已签订")) { |
| | | contract.setContractStatus(Constant.CONTRACT_STATUS_SIGNED); |
| | | } else if (row.get("合同状态").toString().equals("不签订")) { |
| | | contract.setContractStatus(Constant.CONTRACT_STATUS_NOT_SIGN); |
| | | } |
| | | } |
| | | if (ObjectUtil.isNotEmpty(row.get("开票总金额"))) { |
| | | // billingTotalAmount(计算) |
| | | invoice.setAfterTaxAmount(new BigDecimal(row.get("开票总金额").toString())); |
| | | |
| | | if (checkRequiredColumn(row, "开票日期", rowNum, errorMap)) { |
| | | // billingTime |
| | | try { |
| | | invoice.setBillingTime(Timestamp.valueOf(row.get("开票日期").toString())); |
| | | } catch (IllegalArgumentException illegalArgumentException) { |
| | | try { |
| | | // 仅日期转换问题再次尝试 |
| | | invoice.setBillingTime(Timestamp.valueOf(useSdf.format(sdf.parse(row.get("开票日期").toString())))); |
| | | } catch (Exception e) { |
| | | customizeErrorColumn("开票日期输入错误", rowNum, errorMap); |
| | | } |
| | | } catch (Exception e) { |
| | | customizeErrorColumn("开票日期输入错误", rowNum, errorMap); |
| | | } |
| | | } |
| | | if (checkRequiredColumn(row, "税前开票金额", rowNum, errorMap)) { |
| | | // beforeTaxAmount |
| | | invoice.setBeforeTaxAmount(new BigDecimal(row.get("税前开票金额").toString())); |
| | | |
| | | if (ObjectUtil.isNotEmpty(row.get("税率"))) { |
| | | // taxRate |
| | | invoice.setTaxRate(new BigDecimal(row.get("税率").toString()).multiply(new BigDecimal(100)).doubleValue()); |
| | | invoice.setTaxAmount(new BigDecimal(row.get("税前开票金额").toString()).multiply(new BigDecimal(row.get("税率").toString()))); |
| | | } |
| | | } |
| | | if (checkRequiredColumn(row, "发票类型", rowNum, errorMap) && checkTypeColumn(row, "发票类型", rowNum, errorMap)) { |
| | | // invoiceType |
| | | if (row.get("发票类型").toString().equals("增值税普通发票")) { |
| | | invoice.setInvoiceType(Constant.INVOICE_TYPE_ORDINARY); |
| | | } else if (row.get("发票类型").toString().equals("增值税专用发票")) { |
| | | invoice.setInvoiceType(Constant.INVOICE_TYPE_SPECIAL); |
| | | } |
| | | } |
| | | if (ObjectUtil.isNotEmpty(row.get("开票备注"))) { |
| | | // remarks |
| | | invoice.setRemarks(row.get("开票备注").toString()); |
| | | } |
| | | } |
| | | if (ObjectUtil.isNotEmpty(row.get("付款总金额"))) { |
| | | // paymentTotalAmount(计算) |
| | | payment.setPaymentAmount(new BigDecimal(row.get("付款总金额").toString())); |
| | | // NOTE:暂定算为合同收入,PaymentType为无处使用字段,此行代码仅为通过验证,可删除 |
| | | payment.setPaymentType(Constant.CONTRACR_REVENUE); |
| | | |
| | | if (checkRequiredColumn(row, "付款时间", rowNum, errorMap)) { |
| | | // paymentTime(合同付款信息) |
| | | try { |
| | | payment.setPaymentTime(Timestamp.valueOf(row.get("付款时间").toString())); |
| | | } catch (IllegalArgumentException illegalArgumentException) { |
| | | try { |
| | | // 仅日期转换问题再次尝试 |
| | | payment.setPaymentTime(Timestamp.valueOf(useSdf.format(sdf.parse(row.get("付款时间").toString())))); |
| | | } catch (Exception e) { |
| | | customizeErrorColumn("付款时间输入错误", rowNum, errorMap); |
| | | } |
| | | } catch (Exception e) { |
| | | customizeErrorColumn("付款时间输入错误", rowNum, errorMap); |
| | | } |
| | | } |
| | | if (checkRequiredColumn(row, "付款类型", rowNum, errorMap) && checkTypeColumn(row, "付款类型", rowNum, errorMap)) { |
| | | // fundType |
| | | if (row.get("付款类型").toString().equals("服务费")) { |
| | | payment.setFundType(Constant.FUND_SERVICE); |
| | | |
| | | if (checkRequiredColumn(row, "服务费开始时间", rowNum, errorMap)) { |
| | | // fundBelongStart |
| | | payment.setFundBelongStart(Timestamp.valueOf(row.get("服务费开始时间").toString())); |
| | | } |
| | | if (checkRequiredColumn(row, "服务费结束时间", rowNum, errorMap)) { |
| | | // fundBelongEnd |
| | | payment.setFundBelongEnd(Timestamp.valueOf(row.get("服务费结束时间").toString())); |
| | | } |
| | | } else if (row.get("付款类型").toString().equals("合同费")) { |
| | | payment.setFundType(Constant.FUND_CONTRACT); |
| | | |
| | | if (ObjectUtil.isNotEmpty(row.get("合同费所属"))) { |
| | | // fundBelong |
| | | payment.setFundBelong(row.get("合同费所属").toString()); |
| | | } |
| | | } |
| | | if (ObjectUtil.isNotEmpty(row.get("付款备注"))) { |
| | | // remarks |
| | | payment.setRemarks(row.get("付款备注").toString()); |
| | | } |
| | | } |
| | | } |
| | | // if (checkRequiredColumn(row, "预收款金额", rowNum, errorMap)) { |
| | | // // advancePayment(计算) |
| | | // } |
| | | // if (checkRequiredColumn(row, "应收款金额", rowNum, errorMap)) { |
| | | // // receivePayment(计算) |
| | | // } |
| | | if (ObjectUtil.isNotEmpty(row.get("合同类型")) && ObjectUtil.isNotEmpty(row.get("合同类型(二级)"))) { |
| | | // 合同费 |
| | | if (!(row.get("合同类型").toString().equals(Constant.CONTRACT_TECHNOLOGY) && row.get("合同类型(二级)").toString().equals(Constant.CONTRACT_SERVICE))) { |
| | | if (checkRequiredColumn(row, "合同费金额", rowNum, errorMap)) { |
| | | contract.setContractAmount(new BigDecimal(row.get("合同费金额").toString())); |
| | | } |
| | | if (checkRequiredColumn(row, "合同费预计付款日期", rowNum, errorMap)) { |
| | | contract.setContractPaymentDate(Timestamp.valueOf(row.get("合同费预计付款日期").toString())); |
| | | } |
| | | if (checkRequiredColumn(row, "合同费付款状态", rowNum, errorMap) && checkTypeColumn(row, "合同费付款状态", rowNum, errorMap)) { |
| | | if (row.get("合同费付款状态").toString().equals("未付款")) { |
| | | contract.setContractPaymentState(Constant.PAYMENT_NOT); |
| | | } else if (row.get("合同费付款状态").toString().equals("部分付款")) { |
| | | contract.setContractPaymentState(Constant.PAYMENT_PART); |
| | | } else if (row.get("合同费付款状态").toString().equals("已付款")) { |
| | | contract.setContractPaymentState(Constant.PAYMENT_ALREADY); |
| | | } |
| | | } |
| | | } |
| | | // 服务费 |
| | | if (row.get("合同类型").toString().equals(Constant.CONTRACT_TECHNOLOGY) && (row.get("合同类型(二级)").toString().equals(Constant.CONTRACT_SERVICE) || row.get("合同类型(二级)").toString().equals(Constant.CONTRACT_DEVELOP_SERVICE))) { |
| | | if (row.get("合同类型(二级)").toString().equals(Constant.CONTRACT_DEVELOP_SERVICE) && checkRequiredColumn(row, "服务开始日期", rowNum, errorMap)) { |
| | | contract.setServiceStartsDate(Timestamp.valueOf(row.get("服务开始日期").toString())); |
| | | } |
| | | if (checkRequiredColumn(row, "服务费金额", rowNum, errorMap)) { |
| | | contract.setServiceAmount(new BigDecimal(row.get("服务费金额").toString())); |
| | | } |
| | | if (checkRequiredColumn(row, "服务费预计付款日期", rowNum, errorMap)) { |
| | | contract.setServicePaymentDate(Timestamp.valueOf(row.get("服务费预计付款日期").toString())); |
| | | } |
| | | if (checkRequiredColumn(row, "服务费付款状态", rowNum, errorMap) && checkTypeColumn(row, "服务费付款状态", rowNum, errorMap)) { |
| | | if (row.get("服务费付款状态").toString().equals("未付款")) { |
| | | contract.setServicePaymentState(Constant.PAYMENT_NOT); |
| | | } else if (row.get("服务费付款状态").toString().equals("部分付款")) { |
| | | contract.setServicePaymentState(Constant.PAYMENT_PART); |
| | | } else if (row.get("服务费付款状态").toString().equals("已付款")) { |
| | | contract.setServicePaymentState(Constant.PAYMENT_ALREADY); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // if (checkRequiredColumn(row, "合同费延期情况", rowNum, errorMap)) { |
| | | // // contractPostponement |
| | | // } |
| | | // if (checkRequiredColumn(row, "服务费延期情况", rowNum, errorMap)) { |
| | | // // servicePostponement |
| | | // } |
| | | // if (checkRequiredColumn(row, "合同初版文件", rowNum, errorMap)) { |
| | | // contract.setContractName(row.get("合同初版文件").toString()); |
| | | // } |
| | | // if (checkRequiredColumn(row, "合同终版文件", rowNum, errorMap)) { |
| | | // contract.setContractName(row.get("合同终版文件").toString()); |
| | | // } |
| | | if (checkRequiredColumn(row, "验收状态", rowNum, errorMap)) { |
| | | if (row.get("验收状态").toString().equals("待制作")) { |
| | | contract.setAcceptStatus(Constant.ACCEPT_STATUS_TO_BE); |
| | | } else if (row.get("验收状态").toString().equals("验收中")) { |
| | | contract.setAcceptStatus(Constant.ACCEPT_STATUS_UNDER); |
| | | } else if (row.get("验收状态").toString().equals("部分验收")) { |
| | | contract.setAcceptStatus(Constant.ACCEPT_STATUS_PARTIAL); |
| | | } else if (row.get("验收状态").toString().equals("已验收")) { |
| | | contract.setAcceptStatus(Constant.ACCEPT_STATUS_ACCEPTED); |
| | | } else if (row.get("验收状态").toString().equals("不验收")) { |
| | | contract.setAcceptStatus(Constant.ACCEPT_STATUS_NOT); |
| | | } |
| | | } |
| | | // if (checkRequiredColumn(row, "合同附件", rowNum, errorMap)) { |
| | | // contract.setContractName(row.get("合同附件").toString()); |
| | | // } |
| | | if (ObjectUtil.isNotEmpty(row.get("备注信息"))) { |
| | | contract.setRemarks(row.get("备注信息").toString()); |
| | | } |
| | | if (ObjectUtil.isNotEmpty(row.get("创建者"))) { |
| | | contract.setCreateBy(row.get("创建者").toString()); |
| | | } |
| | | if (ObjectUtil.isNotEmpty(row.get("创建日期"))) { |
| | | contract.setCreateTime(Timestamp.valueOf(row.get("创建日期").toString())); |
| | | } |
| | | |
| | | // 暂存数据 |
| | | if (errorMap.size() <= 0) { |
| | | if (!supplyMap.containsKey(contract.getContractNumber())) { |
| | | contractList.add(contract); |
| | | } |
| | | |
| | | Map<String, Object> supplyMapData = new HashMap<>(); |
| | | if (ObjectUtil.isNotEmpty(invoice.getAfterTaxAmount())) { |
| | | supplyMapData.put("invoice", invoice); |
| | | } |
| | | if (ObjectUtil.isNotEmpty(payment.getPaymentAmount())) { |
| | | supplyMapData.put("payment", payment); |
| | | } |
| | | if (supplyMapData.size() > 0) { |
| | | List<Map<String, Object>> supplyList = supplyMap.containsKey(contract.getContractNumber()) ? supplyMap.get(contract.getContractNumber()) : new ArrayList<>(); |
| | | supplyList.add(supplyMapData); |
| | | supplyMap.put(contract.getContractNumber(), supplyList); |
| | | } |
| | | } |
| | | |
| | | rowNum += 1; |
| | | } |
| | | |
| | | // 保存数据 |
| | | if (errorMap.size() <= 0) { |
| | | for (Contract contract : contractList) { |
| | | Contract contractUpdate = new Contract(); |
| | | contractUpdate.copy(contract); |
| | | // 编号用于唯一标识但不保存(自动生成) |
| | | contractUpdate.setContractNumber(null); |
| | | // 默认参数 |
| | | contractUpdate.setRecoveryStatus(Constant.RECOVERY_STATUS_NORMAL); |
| | | |
| | | // 更新金额相关数据 |
| | | contractUpdate = contractRepository.save(updateAmountData(contractUpdate)); |
| | | // 保存后再更新合同编号(获取健全信息,防止顺序编号冲突) |
| | | if (ObjectUtil.isNotEmpty(contract.getCreateTime())) { |
| | | // 因可能导入旧数据,则合同编号签订日期取旧日期 |
| | | contractUpdate.setCreateTime(contract.getCreateTime()); |
| | | } |
| | | Contract savedContract = updateContractNumber(contractUpdate); |
| | | if (supplyMap.containsKey(contract.getContractNumber())) { |
| | | for (Map<String, Object> supplyMapData : supplyMap.get(contract.getContractNumber())) { |
| | | ContractInvoice savedInvoice = null; |
| | | ContractPayment savedPayment = null; |
| | | if (supplyMapData.containsKey("invoice")) { |
| | | savedInvoice = (ContractInvoice) supplyMapData.get("invoice"); |
| | | savedInvoice.setContractId(savedContract.getContractId()); |
| | | savedInvoice = contractInvoiceRepository.save(savedInvoice); |
| | | } |
| | | if (supplyMapData.containsKey("payment")) { |
| | | savedPayment = (ContractPayment) supplyMapData.get("payment"); |
| | | savedPayment.setContractId(savedContract.getContractId()); |
| | | savedPayment = contractPaymentRepository.save(savedPayment); |
| | | } |
| | | if (ObjectUtil.isNotEmpty(savedInvoice) && ObjectUtil.isNotEmpty(savedPayment)) { |
| | | ContractInvoicePayment invoicePayment = new ContractInvoicePayment(); |
| | | invoicePayment.setInvoiceId(savedInvoice.getInvoiceId()); |
| | | invoicePayment.setPaymentId(savedPayment.getPaymentId()); |
| | | contractInvoicePaymentRepository.save(invoicePayment); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | finalMap.put("errCode", 999); |
| | | finalMap.put("errMsg", errorMap.entrySet().stream().map(item -> item.getKey().concat(":").concat(item.getValue().stream().map(col -> col.toString()).collect(Collectors.joining("、")))).collect(Collectors.joining(" \n "))); |
| | | } |
| | | } catch (Exception e){ |
| | | e.printStackTrace(); |
| | | throw new BadRequestException("数据保存失败"); |
| | | } finally { |
| | | reader.close(); |
| | | if (uploadFile.exists()) { |
| | | uploadFile.deleteOnExit(); |
| | | } |
| | | } |
| | | |
| | | return finalMap; |
| | | } |
| | | |
| | | private Boolean checkRequiredColumn(Map<String,Object> data, String key, Integer rowNum, Map<String, List<Integer>> errorMap) { |
| | | if (ObjectUtil.isNotEmpty(data.get(key))) { |
| | | return true; |
| | | } else { |
| | | List<Integer> errorRows = errorMap.containsKey(key) ? errorMap.get(key) : new ArrayList<>(); |
| | | errorRows.add(rowNum); |
| | | errorMap.put(key, errorRows); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | private Boolean checkCompanyColumn(Map<String,Object> data, String key, Integer rowNum, Map<String, List<Integer>> errorMap, Map<String, Long> companyMap) { |
| | | if (companyMap.containsKey(data.get(key).toString())) { |
| | | return true; |
| | | } else { |
| | | String newKey = key.concat("输入错误"); |
| | | List<Integer> errorRows = errorMap.containsKey(newKey) ? errorMap.get(newKey) : new ArrayList<>(); |
| | | errorRows.add(rowNum); |
| | | errorMap.put(newKey, errorRows); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | private Boolean checkTypeColumn(Map<String,Object> data, String key, Integer rowNum, Map<String, List<Integer>> errorMap) { |
| | | if (key.equals("合同类型")) { |
| | | if (ElAdminConstant.Enum.ContractTypeDict.findByImportValue(data.get(key).toString()) != null) { |
| | | return true; |
| | | } else { |
| | | String newKey = key.concat("输入错误"); |
| | | List<Integer> errorRows = errorMap.containsKey(newKey) ? errorMap.get(newKey) : new ArrayList<>(); |
| | | errorRows.add(rowNum); |
| | | errorMap.put(newKey, errorRows); |
| | | return false; |
| | | } |
| | | } else if (key.equals("合同费付款状态") || key.equals("服务费付款状态")) { |
| | | if (data.get(key).toString().equals("未付款") || data.get(key).toString().equals("部分付款") || data.get(key).toString().equals("已付款")) { |
| | | return true; |
| | | } else { |
| | | String newKey = key.concat("输入错误"); |
| | | List<Integer> errorRows = errorMap.containsKey(newKey) ? errorMap.get(newKey) : new ArrayList<>(); |
| | | errorRows.add(rowNum); |
| | | errorMap.put(newKey, errorRows); |
| | | return false; |
| | | } |
| | | } else if (key.equals("发票类型")) { |
| | | if (data.get(key).toString().equals("增值税普通发票") || data.get(key).toString().equals("增值税专用发票")) { |
| | | return true; |
| | | } else { |
| | | String newKey = key.concat("输入错误"); |
| | | List<Integer> errorRows = errorMap.containsKey(newKey) ? errorMap.get(newKey) : new ArrayList<>(); |
| | | errorRows.add(rowNum); |
| | | errorMap.put(newKey, errorRows); |
| | | return false; |
| | | } |
| | | } else if (key.equals("付款类型")) { |
| | | if (data.get(key).toString().equals("服务费") || data.get(key).toString().equals("合同费")) { |
| | | return true; |
| | | } else { |
| | | String newKey = key.concat("输入错误"); |
| | | List<Integer> errorRows = errorMap.containsKey(newKey) ? errorMap.get(newKey) : new ArrayList<>(); |
| | | errorRows.add(rowNum); |
| | | errorMap.put(newKey, errorRows); |
| | | return false; |
| | | } |
| | | } else { |
| | | String newKey = "校验类型不存在"; |
| | | List<Integer> errorRows = errorMap.containsKey(newKey) ? errorMap.get(newKey) : new ArrayList<>(); |
| | | errorRows.add(rowNum); |
| | | errorMap.put(newKey, errorRows); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | private Boolean customizeErrorColumn(String key, Integer rowNum, Map<String, List<Integer>> errorMap) { |
| | | List<Integer> errorRows = errorMap.containsKey(key) ? errorMap.get(key) : new ArrayList<>(); |
| | | errorRows.add(rowNum); |
| | | errorMap.put(key, errorRows); |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 预警 |
| | | * |
| | | * @param ids |
| | | * @return |
| | | */ |
| | | @Override |
| | | public void addWarningStatus(Long[] ids) { |
| | | for (Long id : ids) { |
| | | Contract contract = contractRepository.findById(id).orElseGet(Contract::new); |
| | | if (contract.getWarningStatus() != null) { |
| | | if (contract.getWarningStatus() == 0) { |
| | | contract.setWarningStatus(1); |
| | | } else { |
| | | contract.setWarningStatus(0); |
| | | } |
| | | } else { |
| | | contract.setWarningStatus(1); |
| | | } |
| | | contractRepository.save(contract); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 下载合同附件 |
| | | * |
| | | * @param id |
| | | * @return Map<String, Object> |
| | | */ |
| | | @Override |
| | | public void downloadContractAttachments(Long id, HttpServletResponse response) { |
| | | ByteArrayOutputStream byteArrayOutputStream = null; |
| | | ZipOutputStream zipOutputStream = null; |
| | | FileInputStream fis = null; |
| | | BufferedInputStream bis = null; |
| | | // 合同 |
| | | Contract contract = contractRepository.findById(id).orElseGet(Contract::new); |
| | | try { |
| | | byteArrayOutputStream = new ByteArrayOutputStream(); |
| | | zipOutputStream = new ZipOutputStream(byteArrayOutputStream); |
| | | String relatedDocumentsAttachment = contract.getRelatedDocumentsAttachment(); |
| | | String[] attachments = relatedDocumentsAttachment.split(","); |
| | | for (String attachment : attachments) { |
| | | if (StringUtils.isNotBlank(attachment)) { |
| | | String fileName = attachment.substring(attachment.lastIndexOf("/") + 1); |
| | | String suffix = FileUtil.getExtensionName(fileName); |
| | | String type = FileUtil.getFileType(suffix); |
| | | File file = new File(properties.getPath().getPath() + type + File.separator + fileName); |
| | | fis = new FileInputStream(file); |
| | | bis = new BufferedInputStream(fis); |
| | | ZipEntry zipEntry = new ZipEntry(fileName); |
| | | zipOutputStream.putNextEntry(zipEntry); |
| | | byte[] buffer = new byte[1024]; |
| | | int length; |
| | | while ((length = bis.read(buffer)) > 0) { |
| | | zipOutputStream.write(buffer, 0, length); |
| | | } |
| | | zipOutputStream.flush(); |
| | | zipOutputStream.closeEntry(); |
| | | } |
| | | } |
| | | IoUtil.close(zipOutputStream); |
| | | FileUtil.downloadZip(byteArrayOutputStream, response); |
| | | } catch (Exception e) { |
| | | throw new BadRequestException(e.getMessage()); |
| | | } finally { |
| | | IoUtil.close(zipOutputStream); |
| | | IoUtil.close(byteArrayOutputStream); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 查询合同统计 |
| | | * |
| | | * @param criteria |
| | | * @return Map<String, Object> |
| | | */ |
| | | @Override |
| | | public Map<String, Object> contractStatistics(ContractQueryCriteria criteria, Integer type) { |
| | | Map<String, Object> finalData = new HashMap<>(2); |
| | | |
| | | SysCompanyQueryCriteria companyQueryCriteria = new SysCompanyQueryCriteria(); |
| | | companyQueryCriteria.setIdSet(SecurityUtils.getCompanyIds()); |
| | | Map<Long, String> companyMap = sysCompanyRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,companyQueryCriteria,criteriaBuilder)).stream().collect(Collectors.toMap(SysCompany::getId, SysCompany::getLabel)); |
| | | Map<Long, String> firstMap = contractFirstRepository.findAll().stream().collect(Collectors.toMap(ContractFirst::getFirstId, ContractFirst::getFirstName)); |
| | | Map<Long, String> secondMap = contractSecondRepository.findAll().stream().collect(Collectors.toMap(ContractSecond::getSecondId, ContractSecond::getSecondName)); |
| | | |
| | | Set<Long> companyIds = companyMap.keySet(); |
| | | if (type.equals(1)) { |
| | | // 模块1统计数据 |
| | | if (criteria.getSignDate().isEmpty()) { |
| | | throw new BadRequestException("检索时间不存在"); |
| | | } |
| | | List<Map<String, Object>> incomeDataList = new ArrayList<>(); |
| | | Integer totalSignedQuantity = 0; |
| | | Integer totalUnsignedQuantity = 0; |
| | | |
| | | for (Long companyId : companyIds) { |
| | | Map<String, Object> incomeDataMap = new HashMap<>(); |
| | | |
| | | // 获取合同信息 |
| | | ContractQueryCriteria queryCriteria = new ContractQueryCriteria(); |
| | | queryCriteria.setCompanyId(companyId); |
| | | queryCriteria.setSignDate(criteria.getSignDate()); |
| | | List<Contract> contractList = contractRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,queryCriteria,criteriaBuilder)); |
| | | // 过滤收入合同(仅乙方) |
| | | List<Contract> incomeContractList = contractList.stream().filter(item -> ElAdminConstant.Enum.CompanySuffix.findByCompanyName(firstMap.get(item.getFirstId())) == null && ElAdminConstant.Enum.CompanySuffix.findByCompanyName(secondMap.get(item.getSecondId())) != null).collect(Collectors.toList()); |
| | | // 初始化统计参数 |
| | | Integer signedQuantity = 0; |
| | | Integer unsignedQuantity = 0; |
| | | |
| | | for (Contract incomeContract : incomeContractList) { |
| | | if (incomeContract.getContractStatus().equals(Constant.CONTRACT_STATUS_SIGNED)) { |
| | | // 已签订 |
| | | signedQuantity += 1; |
| | | totalSignedQuantity += 1; |
| | | } else if (incomeContract.getContractStatus().equals(Constant.CONTRACT_STATUS_UNSIGNED)) { |
| | | // 未签订 |
| | | unsignedQuantity += 1; |
| | | totalUnsignedQuantity += 1; |
| | | } |
| | | } |
| | | |
| | | // 保存数据 |
| | | incomeDataMap.put("companyName", companyMap.get(companyId)); |
| | | incomeDataMap.put("signedQuantity", signedQuantity); |
| | | incomeDataMap.put("unsignedQuantity", unsignedQuantity); |
| | | incomeDataList.add(incomeDataMap); |
| | | } |
| | | // 总计数据 |
| | | Map<String, Object> totalIncomeDataMap = new HashMap<>(); |
| | | totalIncomeDataMap.put("companyName", "总计"); |
| | | totalIncomeDataMap.put("signedQuantity", totalSignedQuantity); |
| | | totalIncomeDataMap.put("unsignedQuantity", totalUnsignedQuantity); |
| | | |
| | | finalData.put("total", totalIncomeDataMap); |
| | | finalData.put("income", incomeDataList); |
| | | } else if (type.equals(2)) { |
| | | // 模块2统计数据 |
| | | if (criteria.getSignDate().isEmpty()) { |
| | | throw new BadRequestException("检索时间不存在"); |
| | | } |
| | | Calendar calendar = Calendar.getInstance(); |
| | | List<Map<String, Object>> incomeDataList = new ArrayList<>(); |
| | | |
| | | for (Long companyId : companyIds) { |
| | | Map<String, Object> incomeDataMap = new HashMap<>(); |
| | | |
| | | // 获取合同信息 |
| | | ContractQueryCriteria queryCriteria = new ContractQueryCriteria(); |
| | | queryCriteria.setCompanyId(companyId); |
| | | queryCriteria.setSignDate(criteria.getSignDate()); |
| | | List<Contract> contractList = contractRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,queryCriteria,criteriaBuilder)); |
| | | // 过滤收入合同(仅乙方) |
| | | List<Contract> incomeContractList = contractList.stream().filter(item -> ElAdminConstant.Enum.CompanySuffix.findByCompanyName(firstMap.get(item.getFirstId())) == null && ElAdminConstant.Enum.CompanySuffix.findByCompanyName(secondMap.get(item.getSecondId())) != null).collect(Collectors.toList()); |
| | | // 初始化统计参数 |
| | | Map<String, Map<String, Map<String, BigDecimal>>> annualData = new HashMap<>(); |
| | | calendar.setTime(criteria.getSignDate().get(0)); |
| | | Integer startYear = calendar.get(Calendar.YEAR); |
| | | calendar.setTime(criteria.getSignDate().get(1)); |
| | | Integer endYear = calendar.get(Calendar.YEAR); |
| | | for (int year = startYear; year <= endYear; year++) { |
| | | Map<String, Map<String, BigDecimal>> currentMap = new HashMap<>(5); |
| | | Map<String, BigDecimal> fullQuarterMap = new HashMap<>(4); |
| | | Map<String, BigDecimal> firstQuarterMap = new HashMap<>(4); |
| | | Map<String, BigDecimal> secondQuarterMap = new HashMap<>(4); |
| | | Map<String, BigDecimal> thirdQuarterMap = new HashMap<>(4); |
| | | Map<String, BigDecimal> fourthQuarterMap = new HashMap<>(4); |
| | | // 全年 |
| | | fullQuarterMap.put("invoiced", new BigDecimal(0)); |
| | | fullQuarterMap.put("paid", new BigDecimal(0)); |
| | | fullQuarterMap.put("uninvoice", new BigDecimal(0)); |
| | | fullQuarterMap.put("unpaid", new BigDecimal(0)); |
| | | // 第一季度 |
| | | firstQuarterMap.put("invoiced", new BigDecimal(0)); |
| | | firstQuarterMap.put("paid", new BigDecimal(0)); |
| | | firstQuarterMap.put("uninvoice", new BigDecimal(0)); |
| | | firstQuarterMap.put("unpaid", new BigDecimal(0)); |
| | | // 第二季度 |
| | | secondQuarterMap.put("invoiced", new BigDecimal(0)); |
| | | secondQuarterMap.put("paid", new BigDecimal(0)); |
| | | secondQuarterMap.put("uninvoice", new BigDecimal(0)); |
| | | secondQuarterMap.put("unpaid", new BigDecimal(0)); |
| | | // 第三季度 |
| | | thirdQuarterMap.put("invoiced", new BigDecimal(0)); |
| | | thirdQuarterMap.put("paid", new BigDecimal(0)); |
| | | thirdQuarterMap.put("uninvoice", new BigDecimal(0)); |
| | | thirdQuarterMap.put("unpaid", new BigDecimal(0)); |
| | | // 第四季度 |
| | | fourthQuarterMap.put("invoiced", new BigDecimal(0)); |
| | | fourthQuarterMap.put("paid", new BigDecimal(0)); |
| | | fourthQuarterMap.put("uninvoice", new BigDecimal(0)); |
| | | fourthQuarterMap.put("unpaid", new BigDecimal(0)); |
| | | |
| | | currentMap.put("full", fullQuarterMap); |
| | | currentMap.put("first", firstQuarterMap); |
| | | currentMap.put("second", secondQuarterMap); |
| | | currentMap.put("third", thirdQuarterMap); |
| | | currentMap.put("fourth", fourthQuarterMap); |
| | | annualData.put(String.valueOf(year), currentMap); |
| | | } |
| | | |
| | | for (Contract incomeContract : incomeContractList) { |
| | | // 支付统计(当前合同) |
| | | BigDecimal currentContractAmount = incomeContract.getContractAmount() != null ? incomeContract.getContractAmount() : new BigDecimal(0); |
| | | BigDecimal currentServiceAmount = incomeContract.getServiceAmount() != null ? incomeContract.getServiceAmount() : new BigDecimal(0); |
| | | BigDecimal invoicedAmount = contractInvoiceRepository.countTotalAmountByContractId(incomeContract.getContractId()); |
| | | invoicedAmount = invoicedAmount != null ? invoicedAmount : new BigDecimal(0); |
| | | BigDecimal paidAmount = contractPaymentRepository.countTotalAmountByContractId(incomeContract.getContractId()); |
| | | paidAmount = paidAmount != null ? paidAmount : new BigDecimal(0); |
| | | BigDecimal uninvoiceAmount = currentContractAmount.add(currentServiceAmount).subtract(invoicedAmount); |
| | | BigDecimal unpaidAmount = currentContractAmount.add(currentServiceAmount).subtract(paidAmount); |
| | | if (Constant.RECOVERY_STATUS_ABANDON.equals(incomeContract.getRecoveryStatus())) { |
| | | uninvoiceAmount = new BigDecimal(0); |
| | | unpaidAmount = new BigDecimal(0); |
| | | } |
| | | |
| | | // 年度内统计 |
| | | calendar.setTime(incomeContract.getPerformanceDate()); |
| | | Integer year = calendar.get(Calendar.YEAR); |
| | | Integer month = calendar.get(Calendar.MONTH) + 1; |
| | | |
| | | if (annualData.containsKey(year.toString())) { |
| | | Map<String, Map<String, BigDecimal>> currentMap = annualData.get(year.toString()); |
| | | Map<String, BigDecimal> fullQuarterMap = currentMap.get("full"); |
| | | fullQuarterMap.put("invoiced", fullQuarterMap.get("invoiced").add(invoicedAmount)); |
| | | fullQuarterMap.put("paid", fullQuarterMap.get("paid").add(paidAmount)); |
| | | fullQuarterMap.put("uninvoice", fullQuarterMap.get("uninvoice").add(uninvoiceAmount)); |
| | | fullQuarterMap.put("unpaid", fullQuarterMap.get("unpaid").add(unpaidAmount)); |
| | | currentMap.put("full", fullQuarterMap); |
| | | if (month >= 1 && month <= 3) { |
| | | Map<String, BigDecimal> firstQuarterMap = currentMap.get("first"); |
| | | firstQuarterMap.put("invoiced", firstQuarterMap.get("invoiced").add(invoicedAmount)); |
| | | firstQuarterMap.put("paid", firstQuarterMap.get("paid").add(paidAmount)); |
| | | firstQuarterMap.put("uninvoice", firstQuarterMap.get("uninvoice").add(uninvoiceAmount)); |
| | | firstQuarterMap.put("unpaid", firstQuarterMap.get("unpaid").add(unpaidAmount)); |
| | | currentMap.put("first", firstQuarterMap); |
| | | } else if (month >= 4 && month <= 6) { |
| | | Map<String, BigDecimal> secondQuarterMap = currentMap.get("second"); |
| | | secondQuarterMap.put("invoiced", secondQuarterMap.get("invoiced").add(invoicedAmount)); |
| | | secondQuarterMap.put("paid", secondQuarterMap.get("paid").add(paidAmount)); |
| | | secondQuarterMap.put("uninvoice", secondQuarterMap.get("uninvoice").add(uninvoiceAmount)); |
| | | secondQuarterMap.put("unpaid", secondQuarterMap.get("unpaid").add(unpaidAmount)); |
| | | currentMap.put("second", secondQuarterMap); |
| | | } else if (month >= 7 && month <= 9) { |
| | | Map<String, BigDecimal> thirdQuarterMap = currentMap.get("third"); |
| | | thirdQuarterMap.put("invoiced", thirdQuarterMap.get("invoiced").add(invoicedAmount)); |
| | | thirdQuarterMap.put("paid", thirdQuarterMap.get("paid").add(paidAmount)); |
| | | thirdQuarterMap.put("uninvoice", thirdQuarterMap.get("uninvoice").add(uninvoiceAmount)); |
| | | thirdQuarterMap.put("unpaid", thirdQuarterMap.get("unpaid").add(unpaidAmount)); |
| | | currentMap.put("third", thirdQuarterMap); |
| | | } else if (month >= 10 && month <= 12) { |
| | | Map<String, BigDecimal> fourthQuarterMap = currentMap.get("fourth"); |
| | | fourthQuarterMap.put("invoiced", fourthQuarterMap.get("invoiced").add(invoicedAmount)); |
| | | fourthQuarterMap.put("paid", fourthQuarterMap.get("paid").add(paidAmount)); |
| | | fourthQuarterMap.put("uninvoice", fourthQuarterMap.get("uninvoice").add(uninvoiceAmount)); |
| | | fourthQuarterMap.put("unpaid", fourthQuarterMap.get("unpaid").add(unpaidAmount)); |
| | | currentMap.put("fourth", fourthQuarterMap); |
| | | } |
| | | annualData.put(year.toString(), currentMap); |
| | | } else { |
| | | Map<String, Map<String, BigDecimal>> currentMap = new HashMap<>(5); |
| | | Map<String, BigDecimal> fullQuarterMap = new HashMap<>(4); |
| | | Map<String, BigDecimal> firstQuarterMap = new HashMap<>(4); |
| | | Map<String, BigDecimal> secondQuarterMap = new HashMap<>(4); |
| | | Map<String, BigDecimal> thirdQuarterMap = new HashMap<>(4); |
| | | Map<String, BigDecimal> fourthQuarterMap = new HashMap<>(4); |
| | | // 全年 |
| | | fullQuarterMap.put("invoiced", new BigDecimal(0)); |
| | | fullQuarterMap.put("paid", new BigDecimal(0)); |
| | | fullQuarterMap.put("uninvoice", new BigDecimal(0)); |
| | | fullQuarterMap.put("unpaid", new BigDecimal(0)); |
| | | // 第一季度 |
| | | firstQuarterMap.put("invoiced", new BigDecimal(0)); |
| | | firstQuarterMap.put("paid", new BigDecimal(0)); |
| | | firstQuarterMap.put("uninvoice", new BigDecimal(0)); |
| | | firstQuarterMap.put("unpaid", new BigDecimal(0)); |
| | | // 第二季度 |
| | | secondQuarterMap.put("invoiced", new BigDecimal(0)); |
| | | secondQuarterMap.put("paid", new BigDecimal(0)); |
| | | secondQuarterMap.put("uninvoice", new BigDecimal(0)); |
| | | secondQuarterMap.put("unpaid", new BigDecimal(0)); |
| | | // 第三季度 |
| | | thirdQuarterMap.put("invoiced", new BigDecimal(0)); |
| | | thirdQuarterMap.put("paid", new BigDecimal(0)); |
| | | thirdQuarterMap.put("uninvoice", new BigDecimal(0)); |
| | | thirdQuarterMap.put("unpaid", new BigDecimal(0)); |
| | | // 第四季度 |
| | | fourthQuarterMap.put("invoiced", new BigDecimal(0)); |
| | | fourthQuarterMap.put("paid", new BigDecimal(0)); |
| | | fourthQuarterMap.put("uninvoice", new BigDecimal(0)); |
| | | fourthQuarterMap.put("unpaid", new BigDecimal(0)); |
| | | |
| | | // 放入数据 |
| | | fullQuarterMap.put("invoiced", invoicedAmount); |
| | | fullQuarterMap.put("paid", paidAmount); |
| | | fullQuarterMap.put("uninvoice", uninvoiceAmount); |
| | | fullQuarterMap.put("unpaid", unpaidAmount); |
| | | if (month >= 1 && month <= 3) { |
| | | firstQuarterMap.put("invoiced", invoicedAmount); |
| | | firstQuarterMap.put("paid", paidAmount); |
| | | firstQuarterMap.put("uninvoice", uninvoiceAmount); |
| | | firstQuarterMap.put("unpaid", unpaidAmount); |
| | | } else if (month >= 4 && month <= 6) { |
| | | secondQuarterMap.put("invoiced", invoicedAmount); |
| | | secondQuarterMap.put("paid", paidAmount); |
| | | secondQuarterMap.put("uninvoice", uninvoiceAmount); |
| | | secondQuarterMap.put("unpaid", unpaidAmount); |
| | | } else if (month >= 7 && month <= 9) { |
| | | thirdQuarterMap.put("invoiced", invoicedAmount); |
| | | thirdQuarterMap.put("paid", paidAmount); |
| | | thirdQuarterMap.put("uninvoice", uninvoiceAmount); |
| | | thirdQuarterMap.put("unpaid", unpaidAmount); |
| | | } else if (month >= 10 && month <= 12) { |
| | | fourthQuarterMap.put("invoiced", invoicedAmount); |
| | | fourthQuarterMap.put("paid", paidAmount); |
| | | fourthQuarterMap.put("uninvoice", uninvoiceAmount); |
| | | fourthQuarterMap.put("unpaid", unpaidAmount); |
| | | } |
| | | currentMap.put("full", fullQuarterMap); |
| | | currentMap.put("first", firstQuarterMap); |
| | | currentMap.put("second", secondQuarterMap); |
| | | currentMap.put("third", thirdQuarterMap); |
| | | currentMap.put("fourth", fourthQuarterMap); |
| | | annualData.put(year.toString(), currentMap); |
| | | } |
| | | } |
| | | |
| | | incomeDataMap.put("companyName", companyMap.get(companyId)); |
| | | incomeDataMap.put("annualData", annualData); |
| | | incomeDataList.add(incomeDataMap); |
| | | } |
| | | |
| | | finalData.put("income", incomeDataList); |
| | | } else if (type.equals(3)) { |
| | | // 模块3统计数据 |
| | | if (criteria.getSignDate().isEmpty()) { |
| | | throw new BadRequestException("检索时间不存在"); |
| | | } |
| | | List<ContractDto> overdueContractList = new ArrayList<>(); |
| | | |
| | | for (Long companyId : companyIds) { |
| | | // 获取合同信息 |
| | | ContractQueryCriteria queryCriteria = new ContractQueryCriteria(); |
| | | queryCriteria.setCompanyId(companyId); |
| | | queryCriteria.setSignDate(criteria.getSignDate()); |
| | | queryCriteria.setRecoveryStatus(Constant.RECOVERY_STATUS_NORMAL); |
| | | List<Contract> contractList = contractRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,queryCriteria,criteriaBuilder)); |
| | | // 过滤收入合同(仅乙方) |
| | | List<Contract> incomeContractList = contractList.stream().filter(item -> ElAdminConstant.Enum.CompanySuffix.findByCompanyName(firstMap.get(item.getFirstId())) == null && ElAdminConstant.Enum.CompanySuffix.findByCompanyName(secondMap.get(item.getSecondId())) != null).collect(Collectors.toList()); |
| | | |
| | | for (Contract incomeContract : incomeContractList) { |
| | | // 时间格式化 |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | | ContractDto contractDto = contractMapper.toDto(incomeContract); |
| | | // 判断合同费逾期 |
| | | if (incomeContract.getContractPaymentDate() != null && incomeContract.getContractAmount() != null) { |
| | | // 合同预计付款日期 |
| | | String contractPaymentDate = null; |
| | | // 合同预计付款时间 |
| | | Date contractPaymentTime = null; |
| | | // 判断合同预计付款日期是否为空 |
| | | if(incomeContract.getContractPaymentDate() != null) { |
| | | // 合同预计付款日期 |
| | | contractPaymentDate = incomeContract.getContractPaymentDate().toString(); |
| | | // 合同预计付款时间 |
| | | try { |
| | | contractPaymentTime = sdf.parse(contractPaymentDate.substring(0, 10) + " 00:00:00"); |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | // 当前系统时间 |
| | | Date systemTime = new Date(); |
| | | // 合同款总金额 |
| | | BigDecimal contractTotalAmount = incomeContract.getContractAmount() == null ? new BigDecimal(0) : incomeContract.getContractAmount(); |
| | | // 查询合同款项付款金额 |
| | | BigDecimal contractAmount = contractPaymentRepository.findByContractIdAndFundType(incomeContract.getContractId(), Constant.FUND_CONTRACT); |
| | | contractAmount = contractAmount == null ? new BigDecimal(0) : contractAmount; |
| | | // 判断合同款总金额与付款金额 |
| | | if (contractTotalAmount.compareTo(contractAmount) == 1 && contractPaymentDate != null && systemTime.getTime() > contractPaymentTime.getTime()) { |
| | | // 两时间差 |
| | | ZoneId zoneId = ZoneId.systemDefault(); |
| | | LocalDateTime fromDateTime = LocalDateTime.ofInstant(contractPaymentTime.toInstant(), zoneId); |
| | | LocalDateTime toDateTime = LocalDateTime.ofInstant(systemTime.toInstant(), zoneId); |
| | | LocalDateTime tempDateTime = LocalDateTime.from(fromDateTime); |
| | | Long days = tempDateTime.until(toDateTime, ChronoUnit.DAYS); |
| | | |
| | | contractDto.setContractPostponement("延期" + days + "天"); |
| | | } |
| | | } |
| | | |
| | | if (incomeContract.getServicePaymentDate() != null && incomeContract.getServiceStartsDate() != null && incomeContract.getServiceAmount() != null) { |
| | | // 服务开始年份 |
| | | String serviceStartsYear = null; |
| | | // 判断服务开始日期是否为空 |
| | | if(incomeContract.getServiceStartsDate() != null) { |
| | | // 服务开始年份 |
| | | serviceStartsYear = incomeContract.getServiceStartsDate().toString().substring(0, 4); |
| | | } |
| | | // 服务预计付款月日 |
| | | String servicePaymentMonth = null; |
| | | // 判断服务预计付款日期是否为空 |
| | | if(incomeContract.getServicePaymentDate() != null) { |
| | | // 服务预计付款月日 |
| | | servicePaymentMonth = incomeContract.getServicePaymentDate().toString().substring(4, 10); |
| | | } |
| | | // 当前系统时间 |
| | | Date systemTime = new Date(); |
| | | // 当前系统年份 |
| | | String systemYear = sdf.format(systemTime).substring(0, 4); |
| | | // 当前年付款时间 |
| | | Date systemPaymentTime = null; |
| | | // 判断服务预计付款日期是否为空 |
| | | if (incomeContract.getServicePaymentDate() != null) { |
| | | // 当前年付款时间 |
| | | try { |
| | | systemPaymentTime = sdf.parse(systemYear + servicePaymentMonth + " 00:00:00"); |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | // 服务款总金额 |
| | | BigDecimal serviceTotalAmount = incomeContract.getServiceAmount() == null ? new BigDecimal(0) : incomeContract.getServiceAmount(); |
| | | // 判断服务开始年份是否为空 |
| | | if (serviceStartsYear != null) { |
| | | // 返回字符串 |
| | | String returnString = ""; |
| | | // 服务开始年份与当前年份差 |
| | | int years = Integer.valueOf(systemYear) - Integer.valueOf(serviceStartsYear) + 1; |
| | | // 循环年份差 |
| | | for(int i = 0; i < years; i ++) { |
| | | // 查询合同服务款项各年度付款金额 |
| | | BigDecimal serviceAmount = contractPaymentRepository.findByContractIdAndFundBelongStart(incomeContract.getContractId(), Integer.valueOf(serviceStartsYear) + i); |
| | | serviceAmount = serviceAmount == null ? new BigDecimal(0) : serviceAmount; |
| | | // 判断服务款总金额与付款金额 |
| | | if(serviceTotalAmount.compareTo(serviceAmount) == 1) { |
| | | // 判断是否是当年数据 |
| | | if(Integer.valueOf(serviceStartsYear) + i == Integer.valueOf(systemYear)) { |
| | | // 判断是否超出付款时间 |
| | | if(systemPaymentTime != null && systemTime.getTime() > systemPaymentTime.getTime()) { |
| | | // 两时间差 |
| | | ZoneId zoneId = ZoneId.systemDefault(); |
| | | LocalDateTime fromDateTime = LocalDateTime.ofInstant(systemPaymentTime.toInstant(), zoneId); |
| | | LocalDateTime toDateTime = LocalDateTime.ofInstant(systemTime.toInstant(), zoneId); |
| | | LocalDateTime tempDateTime = LocalDateTime.from(fromDateTime); |
| | | long days = tempDateTime.until(toDateTime, ChronoUnit.DAYS); |
| | | // 返回字符串 |
| | | returnString += "当前年度延期" + days + "天"; |
| | | } |
| | | } else { |
| | | // 返回字符串 |
| | | returnString += (Integer.valueOf(serviceStartsYear) + i) + "至" + (Integer.valueOf(serviceStartsYear) + (i + 1)) + "年度未结清、"; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (returnString.length() > 0) { |
| | | contractDto.setServicePostponement(returnString); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(contractDto.getContractPostponement()) || StringUtils.isNotBlank(contractDto.getServicePostponement())) { |
| | | // 查询合同甲方数据 |
| | | ContractFirstDto contractFirstDto = contractFirstServiceImpl.findById(contractDto.getFirstId()); |
| | | String firstContactInfo = ""; |
| | | if (StringUtils.isNotBlank(contractFirstDto.getFirstPerson())) { |
| | | firstContactInfo = firstContactInfo.concat("姓名:").concat(contractFirstDto.getFirstPerson()).concat(";"); |
| | | } |
| | | if (StringUtils.isNotBlank(contractFirstDto.getFirstPhone())) { |
| | | firstContactInfo = firstContactInfo.concat("电话:").concat(contractFirstDto.getFirstPhone()).concat(";"); |
| | | } |
| | | if (StringUtils.isNotBlank(contractFirstDto.getFirstEmail())) { |
| | | firstContactInfo = firstContactInfo.concat("邮箱:").concat(contractFirstDto.getFirstEmail()).concat(";"); |
| | | } |
| | | contractDto.setFirstContactInfo(firstContactInfo); |
| | | // 查询合同乙方数据 |
| | | ContractSecondDto contractSecondDto = contractSecondServiceImpl.findById(contractDto.getSecondId()); |
| | | contractDto.setSecondName(contractSecondDto.getSecondName()); |
| | | overdueContractList.add(contractDto); |
| | | } |
| | | } |
| | | } |
| | | |
| | | finalData.put("overdueContract", overdueContractList); |
| | | } else if (type.equals(4)) { |
| | | // 模块4统计数据 |
| | | if (criteria.getSignDateEqual() == null) { |
| | | throw new BadRequestException("检索时间不存在"); |
| | | } |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(criteria.getSignDateEqual()); |
| | | String targetYear = String.valueOf(calendar.get(Calendar.YEAR)); |
| | | SysGoalSettingQueryCriteria goalSettingQueryCriteria = new SysGoalSettingQueryCriteria(); |
| | | goalSettingQueryCriteria.setTargetYear(targetYear); |
| | | Map<String, BigDecimal> goalSettingMap = sysGoalSettingRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, goalSettingQueryCriteria, criteriaBuilder)).stream().filter(item -> ElAdminConstant.Enum.ContractTypeDict.findByGoalSetting(item.getProjectDistinguish()) != null).collect(Collectors.toMap(item -> ElAdminConstant.Enum.ContractTypeDict.findByGoalSetting(item.getProjectDistinguish()).getDictValue(), SysGoalSetting::getTargetAmount)); |
| | | |
| | | Map<String, Map<String, BigDecimal>> incomeDataMap = new HashMap<>(); |
| | | for (int i = 0; i < 4; i++) { |
| | | Map<String, BigDecimal> monthMap = new HashMap<>(); |
| | | monthMap.put("1", new BigDecimal(0)); |
| | | monthMap.put("2", new BigDecimal(0)); |
| | | monthMap.put("3", new BigDecimal(0)); |
| | | monthMap.put("4", new BigDecimal(0)); |
| | | monthMap.put("5", new BigDecimal(0)); |
| | | monthMap.put("6", new BigDecimal(0)); |
| | | monthMap.put("7", new BigDecimal(0)); |
| | | monthMap.put("8", new BigDecimal(0)); |
| | | monthMap.put("9", new BigDecimal(0)); |
| | | monthMap.put("10", new BigDecimal(0)); |
| | | monthMap.put("11", new BigDecimal(0)); |
| | | monthMap.put("12", new BigDecimal(0)); |
| | | |
| | | if (i == 0) { |
| | | incomeDataMap.put("contract_technology", monthMap); |
| | | } else if (i == 1) { |
| | | incomeDataMap.put("contract_consultation", monthMap); |
| | | } else if (i == 2) { |
| | | incomeDataMap.put("contract_weak_current", monthMap); |
| | | } else if (i == 3) { |
| | | incomeDataMap.put("contract_ip", monthMap); |
| | | } |
| | | } |
| | | |
| | | for (Long companyId : companyIds) { |
| | | // 获取合同信息 |
| | | calendar.setTime(criteria.getSignDateEqual()); |
| | | ContractQueryCriteria queryCriteria = new ContractQueryCriteria(); |
| | | queryCriteria.setCompanyId(companyId); |
| | | queryCriteria.setSignDateRightLike(targetYear); |
| | | List<Contract> contractList = contractRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, queryCriteria, criteriaBuilder)); |
| | | // 过滤收入合同(仅乙方) |
| | | List<Contract> incomeContractList = contractList.stream().filter(item -> ElAdminConstant.Enum.CompanySuffix.findByCompanyName(firstMap.get(item.getFirstId())) == null && ElAdminConstant.Enum.CompanySuffix.findByCompanyName(secondMap.get(item.getSecondId())) != null).collect(Collectors.toList()); |
| | | |
| | | for (Contract incomeContract : incomeContractList) { |
| | | // 支付统计(当前合同) |
| | | BigDecimal currentContractAmount = incomeContract.getContractAmount() != null ? incomeContract.getContractAmount() : new BigDecimal(0); |
| | | BigDecimal currentServiceAmount = incomeContract.getServiceAmount() != null ? incomeContract.getServiceAmount() : new BigDecimal(0); |
| | | |
| | | // 年度内统计 |
| | | calendar.setTime(incomeContract.getSignDate()); |
| | | String month = String.valueOf(calendar.get(Calendar.MONTH) + 1); |
| | | Map<String, BigDecimal> monthMap = incomeDataMap.get(incomeContract.getContractType()); |
| | | monthMap.put(month, monthMap.get(month).add(currentContractAmount.add(currentServiceAmount))); |
| | | incomeDataMap.put(incomeContract.getContractType(), monthMap); |
| | | } |
| | | } |
| | | |
| | | finalData.put("goal", goalSettingMap); |
| | | finalData.put("income", incomeDataMap); |
| | | } else if (type.equals(5)) { |
| | | // 模块5统计数据 |
| | | if (criteria.getSignDateEqual() == null) { |
| | | throw new BadRequestException("检索时间不存在"); |
| | | } |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(criteria.getSignDateEqual()); |
| | | String targetYear = String.valueOf(calendar.get(Calendar.YEAR)); |
| | | |
| | | Map<String, Map<String, Map<String, BigDecimal>>> typeDataMap = new HashMap<>(); |
| | | for (int i = 0; i < 4; i++) { |
| | | Map<String, Map<String, BigDecimal>> quarterMap = new HashMap<>(); |
| | | Map<String, BigDecimal> firstQuarterMap = new HashMap<>(); |
| | | Map<String, BigDecimal> secondQuarterMap = new HashMap<>(); |
| | | Map<String, BigDecimal> thirdQuarterMap = new HashMap<>(); |
| | | Map<String, BigDecimal> fourthQuarterMap = new HashMap<>(); |
| | | firstQuarterMap.put("income", new BigDecimal(0)); |
| | | firstQuarterMap.put("expend", new BigDecimal(0)); |
| | | secondQuarterMap.put("income", new BigDecimal(0)); |
| | | secondQuarterMap.put("expend", new BigDecimal(0)); |
| | | thirdQuarterMap.put("income", new BigDecimal(0)); |
| | | thirdQuarterMap.put("expend", new BigDecimal(0)); |
| | | fourthQuarterMap.put("income", new BigDecimal(0)); |
| | | fourthQuarterMap.put("expend", new BigDecimal(0)); |
| | | quarterMap.put("first", firstQuarterMap); |
| | | quarterMap.put("second", secondQuarterMap); |
| | | quarterMap.put("third", thirdQuarterMap); |
| | | quarterMap.put("fourth", fourthQuarterMap); |
| | | if (i == 0) { |
| | | typeDataMap.put("contract_technology", quarterMap); |
| | | } else if (i == 1) { |
| | | typeDataMap.put("contract_consultation", quarterMap); |
| | | } else if (i == 2) { |
| | | typeDataMap.put("contract_weak_current", quarterMap); |
| | | } else if (i == 3) { |
| | | typeDataMap.put("contract_ip", quarterMap); |
| | | } |
| | | } |
| | | |
| | | for (Long companyId : companyIds) { |
| | | // 获取合同信息 |
| | | ContractQueryCriteria queryCriteria = new ContractQueryCriteria(); |
| | | queryCriteria.setCompanyId(companyId); |
| | | queryCriteria.setSignDateRightLike(targetYear); |
| | | List<Contract> contractList = contractRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, queryCriteria, criteriaBuilder)); |
| | | // 过滤收入合同 |
| | | List<Contract> incomeContractList = contractList.stream().filter(item -> ElAdminConstant.Enum.CompanySuffix.findByCompanyName(firstMap.get(item.getFirstId())) == null && ElAdminConstant.Enum.CompanySuffix.findByCompanyName(secondMap.get(item.getSecondId())) != null).collect(Collectors.toList()); |
| | | // 过滤支出合同 |
| | | List<Contract> expendContractList = contractList.stream().filter(item -> ElAdminConstant.Enum.CompanySuffix.findByCompanyName(firstMap.get(item.getFirstId())) != null).collect(Collectors.toList()); |
| | | |
| | | for (Contract incomeContract : incomeContractList) { |
| | | // 支付统计(当前合同) |
| | | BigDecimal currentContractAmount = incomeContract.getContractAmount() != null ? incomeContract.getContractAmount() : new BigDecimal(0); |
| | | BigDecimal currentServiceAmount = incomeContract.getServiceAmount() != null ? incomeContract.getServiceAmount() : new BigDecimal(0); |
| | | |
| | | // 计算收入 |
| | | BigDecimal income = currentContractAmount.add(currentServiceAmount); |
| | | // 计算成本 |
| | | BigDecimal expend = new BigDecimal(0); |
| | | ContractProjectQueryCriteria contractProjectQueryCriteria = new ContractProjectQueryCriteria(); |
| | | contractProjectQueryCriteria.setContractId(incomeContract.getContractId()); |
| | | List<ContractProject> contractProjectList = contractProjectRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, contractProjectQueryCriteria, criteriaBuilder)); |
| | | for (ContractProject contractProject : contractProjectList) { |
| | | Query query = new Query(Criteria.where("projectId").is(contractProject.getProjectId())); |
| | | List<TaskMongo> taskMongoList = mongoTemplate.find(query, TaskMongo.class); |
| | | |
| | | Aggregation customerAgg = Aggregation.newAggregation( |
| | | Aggregation.match(Criteria.where("task").in(taskMongoList)), |
| | | Aggregation.project("userId", "taskHours", "costHours"), |
| | | Aggregation.group("userId").sum("taskHours").as("taskHours").sum("costHours").as("costHours") |
| | | ); |
| | | |
| | | AggregationResults<Map> aggregate = mongoTemplate.aggregate(customerAgg, TaskUserMongo.class, Map.class); |
| | | BigDecimal actualCost =aggregate.getMappedResults().stream().filter(data -> data.get("_id") != null).map(data -> { |
| | | BigDecimal moneyTotalCost = projectCostService.calcUserCostByHours(Long.parseLong(String.valueOf(data.get("_id"))), Double.valueOf(String.valueOf(data.get("costHours")))); |
| | | return moneyTotalCost; |
| | | }).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | |
| | | expend = expend.add(actualCost); |
| | | } |
| | | |
| | | Map<String, Map<String, BigDecimal>> quarterMap = typeDataMap.get(incomeContract.getContractType()); |
| | | // 年度内统计 |
| | | calendar.setTime(incomeContract.getSignDate()); |
| | | Integer month = calendar.get(Calendar.MONTH) + 1; |
| | | if (month >= 1 && month <= 3) { |
| | | Map<String, BigDecimal> firstQuarterMap = quarterMap.get("first"); |
| | | firstQuarterMap.put("income", firstQuarterMap.get("income").add(income)); |
| | | firstQuarterMap.put("expend", firstQuarterMap.get("expend").add(expend)); |
| | | quarterMap.put("first", firstQuarterMap); |
| | | } else if (month >= 4 && month <= 6) { |
| | | Map<String, BigDecimal> secondQuarterMap = quarterMap.get("second"); |
| | | secondQuarterMap.put("income", secondQuarterMap.get("income").add(income)); |
| | | secondQuarterMap.put("expend", secondQuarterMap.get("expend").add(expend)); |
| | | quarterMap.put("second", secondQuarterMap); |
| | | } else if (month >= 7 && month <= 9) { |
| | | Map<String, BigDecimal> thirdQuarterMap = quarterMap.get("third"); |
| | | thirdQuarterMap.put("income", thirdQuarterMap.get("income").add(income)); |
| | | thirdQuarterMap.put("expend", thirdQuarterMap.get("expend").add(expend)); |
| | | quarterMap.put("third", thirdQuarterMap); |
| | | } else if (month >= 10 && month <= 12) { |
| | | Map<String, BigDecimal> fourthQuarterMap = quarterMap.get("fourth"); |
| | | fourthQuarterMap.put("income", fourthQuarterMap.get("income").add(income)); |
| | | fourthQuarterMap.put("expend", fourthQuarterMap.get("expend").add(expend)); |
| | | quarterMap.put("fourth", fourthQuarterMap); |
| | | } |
| | | typeDataMap.put(incomeContract.getContractType(), quarterMap); |
| | | } |
| | | |
| | | for (Contract expendContract : expendContractList) { |
| | | // 支付统计(当前合同) |
| | | BigDecimal currentContractAmount = expendContract.getContractAmount() != null ? expendContract.getContractAmount() : new BigDecimal(0); |
| | | BigDecimal currentServiceAmount = expendContract.getServiceAmount() != null ? expendContract.getServiceAmount() : new BigDecimal(0); |
| | | |
| | | // 计算支出 |
| | | BigDecimal expend = currentContractAmount.add(currentServiceAmount); |
| | | |
| | | Map<String, Map<String, BigDecimal>> quarterMap = typeDataMap.get(expendContract.getContractType()); |
| | | // 年度内统计 |
| | | calendar.setTime(expendContract.getSignDate()); |
| | | Integer month = calendar.get(Calendar.MONTH) + 1; |
| | | if (month >= 1 && month <= 3) { |
| | | Map<String, BigDecimal> firstQuarterMap = quarterMap.get("first"); |
| | | firstQuarterMap.put("expend", firstQuarterMap.get("expend").add(expend)); |
| | | quarterMap.put("first", firstQuarterMap); |
| | | } else if (month >= 4 && month <= 6) { |
| | | Map<String, BigDecimal> secondQuarterMap = quarterMap.get("second"); |
| | | secondQuarterMap.put("expend", secondQuarterMap.get("expend").add(expend)); |
| | | quarterMap.put("second", secondQuarterMap); |
| | | } else if (month >= 7 && month <= 9) { |
| | | Map<String, BigDecimal> thirdQuarterMap = quarterMap.get("third"); |
| | | thirdQuarterMap.put("expend", thirdQuarterMap.get("expend").add(expend)); |
| | | quarterMap.put("third", thirdQuarterMap); |
| | | } else if (month >= 10 && month <= 12) { |
| | | Map<String, BigDecimal> fourthQuarterMap = quarterMap.get("fourth"); |
| | | fourthQuarterMap.put("expend", fourthQuarterMap.get("expend").add(expend)); |
| | | quarterMap.put("fourth", fourthQuarterMap); |
| | | } |
| | | typeDataMap.put(expendContract.getContractType(), quarterMap); |
| | | } |
| | | } |
| | | |
| | | finalData.put("typeData", typeDataMap); |
| | | } else if (type.equals(6)) { |
| | | // 模块6统计数据 |
| | | if (criteria.getSignDate().isEmpty()) { |
| | | throw new BadRequestException("检索时间不存在"); |
| | | } |
| | | List<Map<String, Object>> incomeDataList = new ArrayList<>(); |
| | | BigDecimal totalRecoveryFund = new BigDecimal(0); |
| | | BigDecimal totalUnRecoveryFund = new BigDecimal(0); |
| | | |
| | | for (Long companyId : companyIds) { |
| | | Map<String, Object> incomeDataMap = new HashMap<>(); |
| | | |
| | | // 获取合同信息 |
| | | ContractQueryCriteria queryCriteria = new ContractQueryCriteria(); |
| | | queryCriteria.setCompanyId(companyId); |
| | | queryCriteria.setSignDate(criteria.getSignDate()); |
| | | queryCriteria.setRecoveryStatus(Constant.RECOVERY_STATUS_ABANDON); |
| | | List<Contract> contractList = contractRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,queryCriteria,criteriaBuilder)); |
| | | // 过滤收入合同(仅乙方) |
| | | List<Contract> incomeContractList = contractList.stream().filter(item -> ElAdminConstant.Enum.CompanySuffix.findByCompanyName(firstMap.get(item.getFirstId())) == null && ElAdminConstant.Enum.CompanySuffix.findByCompanyName(secondMap.get(item.getSecondId())) != null).collect(Collectors.toList()); |
| | | // 初始化统计参数 |
| | | BigDecimal recoveryFund = new BigDecimal(0); |
| | | BigDecimal unRecoveryFund = new BigDecimal(0); |
| | | |
| | | for (Contract incomeContract : incomeContractList) { |
| | | BigDecimal currentContractAmount = incomeContract.getContractAmount() != null ? incomeContract.getContractAmount() : new BigDecimal(0); |
| | | BigDecimal currentServiceAmount = incomeContract.getServiceAmount() != null ? incomeContract.getServiceAmount() : new BigDecimal(0); |
| | | |
| | | BigDecimal paidAmount = contractPaymentRepository.countTotalAmountByContractId(incomeContract.getContractId()); |
| | | paidAmount = paidAmount != null ? paidAmount : new BigDecimal(0); |
| | | BigDecimal unpaidAmount = currentContractAmount.add(currentServiceAmount).subtract(paidAmount); |
| | | |
| | | recoveryFund = recoveryFund.add(paidAmount); |
| | | unRecoveryFund = unRecoveryFund.add(unpaidAmount); |
| | | // 总额计算 |
| | | totalRecoveryFund = totalRecoveryFund.add(paidAmount); |
| | | totalUnRecoveryFund = totalUnRecoveryFund.add(unpaidAmount); |
| | | } |
| | | |
| | | // 保存数据 |
| | | incomeDataMap.put("companyName", companyMap.get(companyId)); |
| | | incomeDataMap.put("recoveryFund", recoveryFund); |
| | | incomeDataMap.put("unRecoveryFund", unRecoveryFund); |
| | | incomeDataList.add(incomeDataMap); |
| | | } |
| | | // 总计数据 |
| | | Map<String, Object> totalIncomeDataMap = new HashMap<>(); |
| | | totalIncomeDataMap.put("companyName", "总计"); |
| | | totalIncomeDataMap.put("recoveryFund", totalRecoveryFund); |
| | | totalIncomeDataMap.put("unRecoveryFund", totalUnRecoveryFund); |
| | | |
| | | finalData.put("total", totalIncomeDataMap); |
| | | finalData.put("income", incomeDataList); |
| | | } |
| | | |
| | | return finalData; |
| | | } |
| | | |
| | | /** |
| | | * 合同季度统计推送 |
| | | */ |
| | | @Override |
| | | public void contractQuarterlyReport(String statisticsDate) { |
| | | SimpleDateFormat sdf = new SimpleDateFormat("YYMM"); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | if (StringUtils.isNotBlank(statisticsDate)) { |
| | | // 有指定时间时按照指定时间统计 |
| | | calendar.setTime(Timestamp.valueOf(statisticsDate)); |
| | | } |
| | | |
| | | // 统计时间范围获取 |
| | | int todayMonth = calendar.get(Calendar.MONTH) + 1; |
| | | int quarterlyMaxMonth = todayMonth + (3 - ((todayMonth - 1) % 3) - 1); |
| | | int quarterlyMinMonth = quarterlyMaxMonth - 2; |
| | | |
| | | // 季度统计开始时间 |
| | | calendar.set(Calendar.MONTH, quarterlyMinMonth - 1); |
| | | calendar.set(Calendar.DAY_OF_MONTH, 1); |
| | | calendar.set(Calendar.HOUR_OF_DAY, 0); |
| | | calendar.set(Calendar.MINUTE, 0); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | Timestamp quarterlyStartTime = new Timestamp(calendar.getTimeInMillis()); |
| | | // 年度统计开始时间 |
| | | calendar.set(Calendar.MONTH, 0); |
| | | calendar.set(Calendar.DAY_OF_MONTH, 1); |
| | | Timestamp annualStartTime = new Timestamp(calendar.getTimeInMillis()); |
| | | // 去年统计开始时间 |
| | | calendar.add(Calendar.YEAR, -1); |
| | | Timestamp lastYearStartTime = new Timestamp(calendar.getTimeInMillis()); |
| | | |
| | | // 重置年份 |
| | | calendar.add(Calendar.YEAR, 1); |
| | | |
| | | // 季度统计结束时间(每月天数不同,故减一天获得当月最后一天) |
| | | calendar.set(Calendar.MONTH, quarterlyMaxMonth - 1); |
| | | calendar.set(Calendar.DAY_OF_MONTH, 1); |
| | | calendar.add(Calendar.MONTH, 1); |
| | | calendar.add(Calendar.DAY_OF_MONTH, -1); |
| | | calendar.set(Calendar.HOUR_OF_DAY, 23); |
| | | calendar.set(Calendar.MINUTE, 59); |
| | | calendar.set(Calendar.SECOND, 59); |
| | | calendar.set(Calendar.MILLISECOND, 999); |
| | | Timestamp quarterlyEndTime = new Timestamp(calendar.getTimeInMillis()); |
| | | // 年度统计结束时间 |
| | | calendar.set(Calendar.MONTH, 11); |
| | | calendar.set(Calendar.DAY_OF_MONTH, 31); |
| | | Timestamp annualEndTime = new Timestamp(calendar.getTimeInMillis()); |
| | | // 去年统计结束时间 |
| | | calendar.add(Calendar.YEAR, -1); |
| | | Timestamp lastYearEndTime = new Timestamp(calendar.getTimeInMillis()); |
| | | |
| | | String quarterlyStartDate = sdf.format(quarterlyStartTime); |
| | | String quarterlyEndDate = sdf.format(quarterlyEndTime); |
| | | String annualStartDate = sdf.format(annualStartTime); |
| | | String annualEndDate = sdf.format(annualEndTime); |
| | | String lastYearStartDate = sdf.format(lastYearStartTime); |
| | | String lastYearEndDate = sdf.format(lastYearEndTime); |
| | | |
| | | try { |
| | | // 构建HTML内容(开头) |
| | | StringBuilder companyContentBuilder = new StringBuilder(); |
| | | companyContentBuilder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); |
| | | companyContentBuilder.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"); |
| | | companyContentBuilder.append("<html xmlns=\"http://www.w3.org/1999/xhtml\">"); |
| | | companyContentBuilder.append("<head>"); |
| | | companyContentBuilder.append("<style type=\"text/css\">"); |
| | | companyContentBuilder.append(".content-box { width: 1450px; background: #f6f6f7; border: 1px solid #ccc; padding: 20px; font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, Arial, sans-serif; }"); |
| | | companyContentBuilder.append(".card { width: 100%; }"); |
| | | companyContentBuilder.append(".title { width: 100%; font-size: 20px; }"); |
| | | companyContentBuilder.append(".sub-title { width: 100%; font-size: 18px; }"); |
| | | companyContentBuilder.append(".content { display: inline-block; width: 140px; font-size: 16px; }"); |
| | | companyContentBuilder.append(".content-title { display: inline-block; width: 100px; font-size: 16px; }"); |
| | | companyContentBuilder.append(".blank { display: inline-block; width: 120px; }"); |
| | | companyContentBuilder.append(".highlight { color: #fca378; }"); |
| | | companyContentBuilder.append(".gray { color: #9a989e; }"); |
| | | companyContentBuilder.append(".normal { color: #000000; }"); |
| | | companyContentBuilder.append(".font-bold { font-weight: bold }"); |
| | | companyContentBuilder.append(".mb-20 { margin: 0 0 20px 0; }"); |
| | | companyContentBuilder.append("</style>"); |
| | | companyContentBuilder.append("</head>"); |
| | | companyContentBuilder.append("<body>"); |
| | | companyContentBuilder.append("<div class=\"content-box\">"); |
| | | companyContentBuilder.append(String.format("<div class=\"normal title font-bold mb-20\">%d年%d季度合同统计</div>", quarterlyStartTime.toLocalDateTime().getYear(), quarterlyStartTime.toLocalDateTime().get(IsoFields.QUARTER_OF_YEAR))); |
| | | |
| | | Map<String, BigDecimal> contractTypeStatisticsMap = new HashMap<>(); |
| | | // 构建HTML内容(具体内容) |
| | | List<SysCompany> companyList = sysCompanyRepository.findAll(); |
| | | for (SysCompany company : companyList) { |
| | | Map<String, BigDecimal> companyStatisticsMap = new HashMap<>(); |
| | | |
| | | // 查询合同(今年) |
| | | List<Contract> contractList = contractRepository.findAllByTimeAndSignAndCompanyId(annualStartDate, annualEndDate, Constant.CONTRACT_DEMAND_SIGN_Y, company.getId()); |
| | | for (Contract contract : contractList) { |
| | | if (Constant.RECOVERY_STATUS_ABANDON.equals(contract.getRecoveryStatus())) { |
| | | // 钱款缴纳状态是已放弃的不计入统计 |
| | | continue; |
| | | } |
| | | |
| | | String createDate = contract.getContractNumber().substring(4, 8); |
| | | BigDecimal contractAmount = Optional.ofNullable(contract.getContractAmount()).orElse(BigDecimal.ZERO); |
| | | BigDecimal serviceAmount = Optional.ofNullable(contract.getServiceAmount()).orElse(BigDecimal.ZERO); |
| | | |
| | | // 季度维度 |
| | | if (createDate.compareTo(quarterlyStartDate) >= 0 && createDate.compareTo(quarterlyEndDate) <= 0) { |
| | | // 签订数量(季度) |
| | | companyStatisticsMap.merge("quarterlyCount", BigDecimal.ONE, BigDecimal::add); |
| | | // 签订金额(季度) |
| | | companyStatisticsMap.merge("quarterlyAmount", contractAmount, BigDecimal::add); |
| | | companyStatisticsMap.merge("quarterlyAmount", serviceAmount, BigDecimal::add); |
| | | } |
| | | |
| | | // 年度维度 |
| | | // 应付金额(年度) |
| | | companyStatisticsMap.merge("annualPayable", contractAmount, BigDecimal::add); |
| | | companyStatisticsMap.merge("annualPayable", serviceAmount, BigDecimal::add); |
| | | // 到账金额(年度) |
| | | BigDecimal contractTotalAmount = Optional.ofNullable(contractPaymentRepository.countTotalAmountByContractId(contract.getContractId())).orElse(BigDecimal.ZERO); |
| | | companyStatisticsMap.merge("annualPaid", contractTotalAmount, BigDecimal::add); |
| | | // 未付金额(年度) |
| | | BigDecimal unpaid = contractAmount.add(serviceAmount).subtract(contractTotalAmount).max(BigDecimal.ZERO); |
| | | companyStatisticsMap.merge("annualUnpaid", unpaid, BigDecimal::add); |
| | | |
| | | // 按照合同类型汇总统计 |
| | | if (StringUtils.isNotBlank(contract.getContractType())) { |
| | | if (createDate.compareTo(quarterlyStartDate) >= 0 && createDate.compareTo(quarterlyEndDate) <= 0) { |
| | | // 类型签订数量(季度) |
| | | contractTypeStatisticsMap.merge(String.format("quarterlyCount_%s", contract.getContractType()), BigDecimal.ONE, BigDecimal::add); |
| | | // 类型签订金额(季度) |
| | | contractTypeStatisticsMap.merge(String.format("quarterlyAmount_%s", contract.getContractType()), contractAmount, BigDecimal::add); |
| | | contractTypeStatisticsMap.merge(String.format("quarterlyAmount_%s", contract.getContractType()), serviceAmount, BigDecimal::add); |
| | | } |
| | | // 类型应付金额(年度) |
| | | contractTypeStatisticsMap.merge(String.format("annualPayable_%s", contract.getContractType()), contractAmount, BigDecimal::add); |
| | | contractTypeStatisticsMap.merge(String.format("annualPayable_%s", contract.getContractType()), serviceAmount, BigDecimal::add); |
| | | // 类型到账金额(年度) |
| | | contractTypeStatisticsMap.merge(String.format("annualPaid_%s", contract.getContractType()), contractTotalAmount, BigDecimal::add); |
| | | // 类型未付金额(年度) |
| | | contractTypeStatisticsMap.merge(String.format("annualUnpaid_%s", contract.getContractType()), unpaid, BigDecimal::add); |
| | | } |
| | | } |
| | | |
| | | // 查询合同(去年) |
| | | List<Contract> lastYearContractList = contractRepository.findAllByTimeAndSignAndCompanyId(lastYearStartDate, lastYearEndDate, Constant.CONTRACT_DEMAND_SIGN_Y, company.getId()); |
| | | // 去年未付(年度)钱款缴纳状态是已放弃的不计入统计 |
| | | Map<String, BigDecimal> lastYearQuarterlyUnpaid = lastYearContractList.stream().filter(c -> !Constant.RECOVERY_STATUS_ABANDON.equals(c.getRecoveryStatus())).collect( |
| | | Collectors.groupingBy( |
| | | Contract::getContractType, |
| | | Collectors.collectingAndThen(Collectors.toList(), list -> list.stream().map(c -> { |
| | | BigDecimal contractAmount = Optional.ofNullable(c.getContractAmount()).orElse(BigDecimal.ZERO); |
| | | BigDecimal serviceAmount = Optional.ofNullable(c.getServiceAmount()).orElse(BigDecimal.ZERO); |
| | | BigDecimal contractTotalAmount = Optional.ofNullable(contractPaymentRepository.countTotalAmountByContractId(c.getContractId())).orElse(BigDecimal.ZERO); |
| | | BigDecimal unpaid = contractAmount.add(serviceAmount).subtract(contractTotalAmount).max(BigDecimal.ZERO); |
| | | return unpaid; |
| | | }).reduce(BigDecimal.ZERO, BigDecimal::add)) |
| | | ) |
| | | ); |
| | | BigDecimal lastYearUnpaid = lastYearQuarterlyUnpaid.values().stream().reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | companyStatisticsMap.merge("lastYearUnpaid", lastYearUnpaid, BigDecimal::add); |
| | | // 科技去年未付(年度) |
| | | contractTypeStatisticsMap.merge(String.format("lastYearUnpaid_%s", Constant.CONTRACT_TECHNOLOGY), lastYearQuarterlyUnpaid.getOrDefault(Constant.CONTRACT_TECHNOLOGY, BigDecimal.ZERO), BigDecimal::add); |
| | | // 咨询去年未付(年度) |
| | | contractTypeStatisticsMap.merge(String.format("lastYearUnpaid_%s", Constant.CONTRACT_CONSULTATION), lastYearQuarterlyUnpaid.getOrDefault(Constant.CONTRACT_CONSULTATION, BigDecimal.ZERO), BigDecimal::add); |
| | | // 弱电去年未付(年度) |
| | | contractTypeStatisticsMap.merge(String.format("lastYearUnpaid_%s", Constant.CONTRACT_WEAK_CURRENT), lastYearQuarterlyUnpaid.getOrDefault(Constant.CONTRACT_WEAK_CURRENT, BigDecimal.ZERO), BigDecimal::add); |
| | | // 知识产权去年未付(年度) |
| | | contractTypeStatisticsMap.merge(String.format("lastYearUnpaid_%s", Constant.CONTRACT_IP), lastYearQuarterlyUnpaid.getOrDefault(Constant.CONTRACT_IP, BigDecimal.ZERO), BigDecimal::add); |
| | | |
| | | // 获取公司下所有用户 |
| | | UserQueryCriteria userQueryCriteria = new UserQueryCriteria(); |
| | | userQueryCriteria.setEnabled(true); |
| | | userQueryCriteria.setCompanyId(company.getId()); |
| | | List<Long> userIds = userRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, userQueryCriteria, criteriaBuilder)).stream().map(user -> user.getId()).collect(Collectors.toList()); |
| | | |
| | | // 已付工资(季度) |
| | | BigDecimal newSalaryAmount = BigDecimal.ZERO; |
| | | if (userIds.size() > 0) { |
| | | NewSalaryQueryCriteria newSalaryCriteria = new NewSalaryQueryCriteria(); |
| | | newSalaryCriteria.setUserIds(userIds); |
| | | newSalaryCriteria.setSalaryYearMonthStart(quarterlyStartTime.toLocalDateTime().toLocalDate().toString()); |
| | | newSalaryCriteria.setSalaryYearMonthEnd(quarterlyEndTime.toLocalDateTime().toLocalDate().toString()); |
| | | newSalaryAmount = newSalaryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, newSalaryCriteria, criteriaBuilder)).stream() |
| | | .map(ns -> ns.getPreTaxAmount().add(ns.getAccumulationFundCompanyAmount()).add(ns.getRetirementInsuranceCompanyAmount()).add(ns.getMedicalInsuranceCompanyAmount()) |
| | | .add(ns.getUnemploymentInsuranceCompanyAmount()).add(ns.getBirthInsuranceCompanyAmount()).add(ns.getEmploymentInsuranceCompanyAmount())).reduce(BigDecimal.ZERO, BigDecimal::add).max(BigDecimal.ZERO); |
| | | } |
| | | companyStatisticsMap.merge("quarterlySalary", newSalaryAmount, BigDecimal::add); |
| | | |
| | | // 报销金额(季度) |
| | | BigDecimal reimburseAmount = BigDecimal.ZERO; |
| | | if (userIds.size() > 0) { |
| | | ProjectReimburseQueryCriteria reimburseCriteria = new ProjectReimburseQueryCriteria(); |
| | | reimburseCriteria.setUserIds(userIds); |
| | | reimburseCriteria.setStartTimeStart(quarterlyStartTime.toLocalDateTime().toLocalDate().toString()); |
| | | reimburseCriteria.setStartTimeEnd(quarterlyEndTime.toLocalDateTime().toLocalDate().toString()); |
| | | reimburseCriteria.setApprovalStatus(Constant.REIMBURSE_APPROVE_STATUS_AGREE); |
| | | reimburseAmount = projectReimburseRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, reimburseCriteria, criteriaBuilder)).stream() |
| | | .map(pr -> pr.getExpenseAmount()).reduce(BigDecimal.ZERO, BigDecimal::add).max(BigDecimal.ZERO); |
| | | } |
| | | companyStatisticsMap.merge("quarterlyReimburse", reimburseAmount, BigDecimal::add); |
| | | |
| | | // 构建HTML内容(具体内容) |
| | | companyContentBuilder.append(String.format( |
| | | "<div class=\"card mb-20\">" + |
| | | "<div class=\"highlight sub-title font-bold\">%s</div>" + |
| | | "<div>" + |
| | | "<div class=\"gray content-title font-bold\">合同信息</div>" + |
| | | "<div class=\"normal content\">签订数量(季度)</div>" + |
| | | "<div class=\"normal content\">签订金额(季度)</div>" + |
| | | "<div class=\"normal content\">应付金额(年度)</div>" + |
| | | "<div class=\"normal content\">到账金额(年度)</div>" + |
| | | "<div class=\"normal content\">未付金额(年度)</div>" + |
| | | "<div class=\"normal content\">去年未付(年度)</div>" + |
| | | "<div class=\"blank\"></div>" + |
| | | "<div class=\"gray content-title font-bold\">资金信息</div>" + |
| | | "<div class=\"normal content\">已付工资(季度)</div>" + |
| | | "<div class=\"normal content\">报销金额(季度)</div>" + |
| | | "</div>" + |
| | | "<div>" + |
| | | "<div class=\"gray content-title font-bold\"></div>" + |
| | | "<div class=\"normal content\">%d</div>" + |
| | | "<div class=\"normal content\">%,.2f</div>" + |
| | | "<div class=\"normal content\">%,.2f</div>" + |
| | | "<div class=\"normal content\">%,.2f</div>" + |
| | | "<div class=\"normal content\">%,.2f</div>" + |
| | | "<div class=\"normal content\">%,.2f</div>" + |
| | | "<div class=\"blank\"></div>" + |
| | | "<div class=\"gray content-title font-bold\"></div>" + |
| | | "<div class=\"normal content\">%,.2f</div>" + |
| | | "<div class=\"normal content\">%,.2f</div>" + |
| | | "</div>" + |
| | | "</div>", |
| | | company.getLabel(), |
| | | companyStatisticsMap.getOrDefault("quarterlyCount", BigDecimal.ZERO).intValue(), |
| | | companyStatisticsMap.getOrDefault("quarterlyAmount", BigDecimal.ZERO).doubleValue(), |
| | | companyStatisticsMap.getOrDefault("annualPayable", BigDecimal.ZERO).doubleValue(), |
| | | companyStatisticsMap.getOrDefault("annualPaid", BigDecimal.ZERO).doubleValue(), |
| | | companyStatisticsMap.getOrDefault("annualUnpaid", BigDecimal.ZERO).doubleValue(), |
| | | companyStatisticsMap.getOrDefault("lastYearUnpaid", BigDecimal.ZERO).doubleValue(), |
| | | companyStatisticsMap.getOrDefault("quarterlySalary", BigDecimal.ZERO).doubleValue(), |
| | | companyStatisticsMap.getOrDefault("quarterlyReimburse", BigDecimal.ZERO).doubleValue() |
| | | )); |
| | | } |
| | | |
| | | // 构建HTML内容(结尾) |
| | | companyContentBuilder.append("</div>"); |
| | | companyContentBuilder.append("</body>"); |
| | | companyContentBuilder.append("</html>"); |
| | | |
| | | // 创建DocumentBuilder对象 |
| | | DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); |
| | | DocumentBuilder builder = factory.newDocumentBuilder(); |
| | | |
| | | // 将字符串转换为InputStream对象 |
| | | ByteArrayInputStream inputStream = new ByteArrayInputStream(companyContentBuilder.toString().getBytes()); |
| | | Document document = builder.parse(inputStream); |
| | | |
| | | // 使用DocumentBuilder解析XML文档 |
| | | Java2DRenderer renderer = new Java2DRenderer(document, 1510); |
| | | BufferedImage image = renderer.getImage(); |
| | | |
| | | // 生成报告图片 |
| | | FSImageWriter imageWriter = new FSImageWriter(); |
| | | String imagePath = properties.getPath().getPath() + "image" + File.separator + "contract_company_statistics_" + IdUtil.simpleUUID() + ".png"; |
| | | File file = new File(imagePath); |
| | | file.getParentFile().mkdirs(); |
| | | OutputStream outputStream = new FileOutputStream(file); |
| | | imageWriter.write(image, outputStream); |
| | | // 上传临时素材 |
| | | List<String> mediaIds = templateControlFieldService.uploadWecomMediaFile(Arrays.asList(imagePath)); |
| | | // 发送报告 |
| | | 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(); |
| | | |
| | | // 类型合同统计 |
| | | List<String> contractTypeList = Arrays.asList(Constant.CONTRACT_TECHNOLOGY, Constant.CONTRACT_CONSULTATION, Constant.CONTRACT_WEAK_CURRENT, Constant.CONTRACT_IP); |
| | | Map<String, String> contractTypeMap = dictDetailRepository.findByDictName(Constant.CONTRACT_DICT_TYPE).stream().collect(Collectors.toMap(DictDetail::getValue, DictDetail::getLabel)); |
| | | Map<String, String> projectDistinguishMap = dictDetailRepository.findByDictName(Constant.PROJECT_DISTINGUISH).stream().collect(Collectors.toMap(DictDetail::getLabel, DictDetail::getValue)); |
| | | Integer quarterNum = quarterlyStartTime.toLocalDateTime().get(IsoFields.QUARTER_OF_YEAR); |
| | | |
| | | for (String contractType : contractTypeList) { |
| | | // 获取指定类型季度、年度目标值 |
| | | 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; |
| | | case 2: quarterlyGoal = Optional.ofNullable(goalSetting.getSecondTargetAmount()).orElse(BigDecimal.ZERO); break; |
| | | case 3: quarterlyGoal = Optional.ofNullable(goalSetting.getThirdTargetAmount()).orElse(BigDecimal.ZERO); break; |
| | | case 4: quarterlyGoal = Optional.ofNullable(goalSetting.getFourthTargetAmount()).orElse(BigDecimal.ZERO); break; |
| | | default: quarterlyGoal = BigDecimal.ZERO; |
| | | } |
| | | BigDecimal annualGoal = Optional.ofNullable(goalSetting.getTargetAmount()).orElse(BigDecimal.ZERO); |
| | | |
| | | // 构建HTML内容(开头) |
| | | StringBuilder typeContentBuilder = new StringBuilder(); |
| | | typeContentBuilder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); |
| | | typeContentBuilder.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"); |
| | | typeContentBuilder.append("<html xmlns=\"http://www.w3.org/1999/xhtml\">"); |
| | | typeContentBuilder.append("<head>"); |
| | | typeContentBuilder.append("<style type=\"text/css\">"); |
| | | typeContentBuilder.append(".content-box { width: 960px; background: #f6f6f7; border: 1px solid #ccc; padding: 20px; font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, Arial, sans-serif; }"); |
| | | typeContentBuilder.append(".card { width: 100%; }"); |
| | | typeContentBuilder.append(".title { width: 100%; font-size: 20px; }"); |
| | | typeContentBuilder.append(".sub-title { width: 100%; font-size: 18px; }"); |
| | | typeContentBuilder.append(".content { display: inline-block; width: 140px; font-size: 16px; }"); |
| | | typeContentBuilder.append(".content-title { display: inline-block; width: 100px; font-size: 16px; }"); |
| | | typeContentBuilder.append(".blank { display: inline-block; width: 120px; }"); |
| | | typeContentBuilder.append(".highlight { color: #fca378; }"); |
| | | typeContentBuilder.append(".gray { color: #9a989e; }"); |
| | | typeContentBuilder.append(".normal { color: #000000; }"); |
| | | typeContentBuilder.append(".font-bold { font-weight: bold }"); |
| | | typeContentBuilder.append(".mb-20 { margin: 0 0 20px 0; }"); |
| | | typeContentBuilder.append("</style>"); |
| | | typeContentBuilder.append("</head>"); |
| | | typeContentBuilder.append("<body>"); |
| | | typeContentBuilder.append("<div class=\"content-box\">"); |
| | | typeContentBuilder.append(String.format("<div class=\"normal title font-bold mb-20\">%d年%d季度%s类型合同统计</div>", quarterlyStartTime.toLocalDateTime().getYear(), quarterNum, contractTypeMap.get(contractType))); |
| | | |
| | | // 构建HTML内容(具体内容) |
| | | typeContentBuilder.append(String.format( |
| | | "<div class=\"card mb-20\">" + |
| | | "<div class=\"highlight sub-title font-bold\">%s</div>" + |
| | | "<div>" + |
| | | "<div class=\"gray content-title font-bold\">合同信息</div>" + |
| | | "<div class=\"normal content\">签订数量(季度)</div>" + |
| | | "<div class=\"normal content\">签订金额(季度)</div>" + |
| | | "<div class=\"normal content\">应付金额(年度)</div>" + |
| | | "<div class=\"normal content\">到账金额(年度)</div>" + |
| | | "<div class=\"normal content\">未付金额(年度)</div>" + |
| | | "<div class=\"normal content\">去年未付(年度)</div>" + |
| | | "</div>" + |
| | | "<div class=\"mb-20\">" + |
| | | "<div class=\"gray content-title font-bold\"></div>" + |
| | | "<div class=\"normal content\">%d</div>" + |
| | | "<div class=\"normal content\">%,.2f</div>" + |
| | | "<div class=\"normal content\">%,.2f</div>" + |
| | | "<div class=\"normal content\">%,.2f</div>" + |
| | | "<div class=\"normal content\">%,.2f</div>" + |
| | | "<div class=\"normal content\">%,.2f</div>" + |
| | | "</div>" + |
| | | "<div>" + |
| | | "<div class=\"gray content-title font-bold\">目标信息</div>" + |
| | | "<div class=\"normal content\">季度目标</div>" + |
| | | "<div class=\"normal content\">季度差额</div>" + |
| | | "<div class=\"normal content\">年度目标</div>" + |
| | | "<div class=\"normal content\">年度差额</div>" + |
| | | "</div>" + |
| | | "<div>" + |
| | | "<div class=\"gray content-title font-bold\"></div>" + |
| | | "<div class=\"normal content\">%,.2f</div>" + |
| | | "<div class=\"normal content\">%,.2f</div>" + |
| | | "<div class=\"normal content\">%,.2f</div>" + |
| | | "<div class=\"normal content\">%,.2f</div>" + |
| | | "</div>" + |
| | | "</div>", |
| | | contractTypeMap.get(contractType), |
| | | contractTypeStatisticsMap.getOrDefault(String.format("quarterlyCount_%s", contractType), BigDecimal.ZERO).intValue(), |
| | | contractTypeStatisticsMap.getOrDefault(String.format("quarterlyAmount_%s", contractType), BigDecimal.ZERO).doubleValue(), |
| | | contractTypeStatisticsMap.getOrDefault(String.format("annualPayable_%s", contractType), BigDecimal.ZERO).doubleValue(), |
| | | contractTypeStatisticsMap.getOrDefault(String.format("annualPaid_%s", contractType), BigDecimal.ZERO).doubleValue(), |
| | | contractTypeStatisticsMap.getOrDefault(String.format("annualUnpaid_%s", contractType), BigDecimal.ZERO).doubleValue(), |
| | | contractTypeStatisticsMap.getOrDefault(String.format("lastYearUnpaid_%s", contractType), BigDecimal.ZERO).doubleValue(), |
| | | quarterlyGoal.doubleValue(), |
| | | quarterlyGoal.subtract(contractTypeStatisticsMap.getOrDefault(String.format("quarterlyAmount_%s", contractType), BigDecimal.ZERO)).max(BigDecimal.ZERO).doubleValue(), |
| | | annualGoal.doubleValue(), |
| | | annualGoal.subtract(contractTypeStatisticsMap.getOrDefault(String.format("annualPayable_%s", contractType), BigDecimal.ZERO)).max(BigDecimal.ZERO).doubleValue() |
| | | )); |
| | | |
| | | // 构建HTML内容(结尾) |
| | | typeContentBuilder.append("</div>"); |
| | | typeContentBuilder.append("</body>"); |
| | | typeContentBuilder.append("</html>"); |
| | | |
| | | // 将字符串转换为InputStream对象 |
| | | ByteArrayInputStream typeInputStream = new ByteArrayInputStream(typeContentBuilder.toString().getBytes()); |
| | | Document typeDocument = builder.parse(typeInputStream); |
| | | |
| | | // 使用DocumentBuilder解析XML文档 |
| | | Java2DRenderer typeRenderer = new Java2DRenderer(typeDocument, 1020); |
| | | BufferedImage typeImage = typeRenderer.getImage(); |
| | | |
| | | // 生成报告图片 |
| | | String typeImagePath = properties.getPath().getPath() + "image" + File.separator + "contract_type_statistics_" + IdUtil.simpleUUID() + ".png"; |
| | | File typeFile = new File(typeImagePath); |
| | | typeFile.getParentFile().mkdirs(); |
| | | OutputStream typeOutputStream = new FileOutputStream(typeFile); |
| | | imageWriter.write(typeImage, typeOutputStream); |
| | | if (StringUtils.isNotBlank(goalSetting.getLeaderName())) { |
| | | // 上传临时素材 |
| | | List<String> typeMediaIds = templateControlFieldService.uploadWecomMediaFile(Arrays.asList(typeImagePath)); |
| | | // 发送报告 |
| | | 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(); |
| | | } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } catch (Exception e) { |
| | | 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); |
| | | } |
| | | } |