From 7c30cc34b1fae37b6cd94fcf0a5d421a8e1bdb24 Mon Sep 17 00:00:00 2001
From: baolhyhzhg <baolh@yhzhg.cn>
Date: Mon, 02 Dec 2024 07:35:25 +0000
Subject: [PATCH] 合同类型变更为两级,两级间可联动

---
 eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/service/impl/ContractServiceImpl.java |   36 +++++++++++++++++++++++++++++-------
 1 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/service/impl/ContractServiceImpl.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/service/impl/ContractServiceImpl.java
index b2df737..e5e9935 100644
--- a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/service/impl/ContractServiceImpl.java
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/service/impl/ContractServiceImpl.java
@@ -22,7 +22,10 @@
 import me.zhengjie.modules.contract.service.mapstruct.ContractProjectMapper;
 import me.zhengjie.modules.project.service.dto.ProjectDto;
 import me.zhengjie.modules.project.service.impl.ProjectServiceImpl;
+import me.zhengjie.modules.system.domain.Dict;
+import me.zhengjie.modules.system.domain.DictDetail;
 import me.zhengjie.modules.system.repository.DictDetailRepository;
+import me.zhengjie.modules.system.repository.DictRepository;
 import me.zhengjie.utils.*;
 import lombok.RequiredArgsConstructor;
 import me.zhengjie.modules.contract.service.ContractService;
@@ -58,6 +61,7 @@
     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 ContractSecondServiceImpl contractSecondServiceImpl;
@@ -220,7 +224,7 @@
         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_TYPE, contract.getContractType()).getLabel() : "";
+            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;
@@ -239,7 +243,8 @@
             map.put("起始日期", contract.getStartDate());
             map.put("截止日期", contract.getEndDate());
             map.put("合同所属地区", contract.getContractArea());
-            map.put("合同类型", contractType);
+            map.put("合同类型(一级)", contractType);
+            map.put("合同类型(二级)", contract.getContractSecondType());
             map.put("合同内容", contract.getContractContent());
             map.put("开票总金额", contract.getBillingTotalAmount());
             map.put("付款总金额", contract.getPaymentTotalAmount());
@@ -561,10 +566,28 @@
      * @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_DEVELOP_SERVICE.equals(resources.getContractSecondType())) {
             // 不处理
-        } else if (Constant.CONTRACT_SERVICE.equals(resources.getContractType())) {
+        } else if (Constant.CONTRACT_SERVICE.equals(resources.getContractSecondType())) {
             // 合同费金额
             resources.setContractAmount(null);
             // 预计付款日期
@@ -632,7 +655,7 @@
             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_SERVICE.equals(contract.getContractSecondType())) {
                 // 付款状态
                 contract.setContractPaymentState(null);
             } else if(contractAmount.compareTo(new BigDecimal(0)) == 0) {
@@ -667,7 +690,7 @@
                 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_DEVELOP.equals(contract.getContractSecondType())) {
                     // 付款状态
                     contract.setServicePaymentState(null);
                 } else if(serviceAmount.compareTo(new BigDecimal(0)) == 0) {
@@ -779,7 +802,6 @@
             Long allCompanySort = contractRepository.countAllContractSort(String.valueOf(calendar.get(Calendar.YEAR)), resources.getContractId());
             contractNumber.append(String.format("%04d", (allCompanySort == null ? 0L : allCompanySort) + 1));
 
-            System.out.println("新合同编号:" + contractNumber.toString());
             resources.setContractNumber(contractNumber.toString());
         }
 

--
Gitblit v1.9.3