| | |
| | | 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.ContractFirstDto; |
| | | import me.zhengjie.modules.contract.service.dto.ContractQueryCriteria; |
| | | import me.zhengjie.modules.contract.service.dto.ContractSecondDto; |
| | | import me.zhengjie.modules.contract.service.dto.*; |
| | | import me.zhengjie.modules.contract.service.mapstruct.ContractMapper; |
| | | import me.zhengjie.modules.system.domain.Dict; |
| | | import me.zhengjie.modules.system.domain.DictDetail; |
| | |
| | | @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)); |
| | | |
| | | for (ContractDto contract : all) { |
| | | String firstName = contractFirstName(contractMapper.toEntity(contract)); |
| | | String secondName = contractSecondName(contractMapper.toEntity(contract)); |
| | | String contractType = contract.getContractType() != null ? dictDetailRepository.findByDictNameAndValue(Constant.CONTRACT_DICT_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.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("合同状态", contractStatusMap.containsKey(contract.getContractStatus()) ? contractStatusMap.get(contract.getContractStatus()) : ""); |
| | | map.put("备注信息", contract.getRemarks()); |
| | | map.put("创建者", contract.getCreateBy()); |
| | | map.put("创建日期", contract.getCreateTime()); |
| | |
| | | FileUtil.downloadExcel(list, response); |
| | | } |
| | | |
| | | @Override |
| | | public void download(ContractQueryCriteria criteria, HttpServletResponse response) throws IOException { |
| | | // 查询合同列表 |
| | | List<Contract> contractList = contractRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | 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)); |
| | | |
| | | 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)); |
| | | for (ContractInvoicePayment invoicePayment : invoicePaymentList) { |
| | | ContractInvoice invoice = contractInvoiceRepository.getById(invoicePayment.getInvoiceId()); |
| | | invoiceList.add(invoice); |
| | | } |
| | | } 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("创建者", contract.getCreateBy()); |
| | | map.put("创建日期", contract.getCreateTime()); |
| | | list.add(map); |
| | | } |
| | | } |
| | | } |
| | | |
| | | FileUtil.downloadExcel(list, response); |
| | | } |
| | | |
| | | /** |
| | | * 合同甲方姓名 |
| | | * @param resources |