From ef30e3f2eebad385c8b26bd0ff931c028d46f3ce Mon Sep 17 00:00:00 2001
From: luofl <1442745593@qq.com>
Date: 星期一, 21 四月 2025 10:39:00 +0800
Subject: [PATCH] 修改bug

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TContractController.java |  156 +++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 113 insertions(+), 43 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TContractController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TContractController.java
index 86c69c2..6987379 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TContractController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TContractController.java
@@ -46,6 +46,7 @@
 import com.ruoyi.system.vo.CheckAcceptRecordVO;
 import com.ruoyi.system.vo.TContractVO;
 import com.ruoyi.web.controller.tool.NumberToChineseUtils;
+import com.ruoyi.web.controller.tool.TencentCosUtil;
 import com.ruoyi.web.controller.tool.WordUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -62,6 +63,7 @@
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.annotation.Resource;
 import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
@@ -358,6 +360,8 @@
     }
     @Autowired
     private WordUtil wordUtil;
+    @Autowired
+    private TencentCosUtil tencentCosUtil;
     @ApiOperation(value = "生成合同附件")
     @PostMapping("/set")
     @Log(title = "生成合同附件", businessType = BusinessType.EXPORT)
@@ -366,7 +370,7 @@
         List<TContract> list = contractService.lambdaQuery().in(TContract::getId, dto.getIds()).list();
         List<String> res = new ArrayList<>();
         for (TContract contract : list) {
-            String url = generateContract(contract);
+            String url = generateContract(contract,new TContractDTO());
             res.add(url);
         }
 
@@ -385,7 +389,7 @@
 
     }
 
-    private String generateContract(TContract contract) {
+    private String generateContract(TContract contract,TContractDTO dto) {
         String templateFileName = "1_yzj_租赁合同_个人.docx";
         String contractId = contract.getId();
         TBill firstBill = null;
@@ -427,10 +431,10 @@
             fill(templateParam, "email", tenant.getEmail());
 
             // 企业、政府机构、国有企业
-            if (Objects.nonNull(tenant.getTenantType())
-                    && (tenant.getTenantType().equals("2")
-                    || tenant.getTenantType().equals("5")
-                    || tenant.getTenantType().equals("7"))) {
+            if (Objects.nonNull(tenant.getTenantAttributes())
+                    && (tenant.getTenantAttributes().equals("2")
+                    || tenant.getTenantAttributes().equals("5")
+                    || tenant.getTenantAttributes().equals("7"))) {
                 fill(templateParam, "creditCode", tenant.getCreditCode());
                 fill(templateParam, "legalPerson", tenant.getLegalPerson());
                 templateFileName = "1_yzj_租赁合同_企业.docx";
@@ -446,7 +450,7 @@
 
         // 日期相关参数处理
         fill(templateParam, "remark", contract.getRemark());
-        fill(templateParam, "houseUseScope", contract.getHouseUseScope());
+        fill(templateParam, "houseUseScope", StringUtils.isNotEmpty(contract.getHouseUseScope()) ? contract.getHouseUseScope() : "————");
         fill(templateParam, "days", ChronoUnit.DAYS.between(
                 contract.getStartTime(), contract.getEndTime()));
 
@@ -485,39 +489,30 @@
                 : contract.getPayType().equals("2") ? "季"
                 : "年";
         fill(templateParam, "payType", payType);
-        BigDecimal extracted = extracted(contract);
-        // 首期租金处理
-        if (firstBill != null) {
-            double firstRent = (contract.getPayType().equals("1")
-                    ? contract.getMonthRent()
-                    : contract.getPayType().equals("2")
-                    ? contract.getMonthRent().multiply(new BigDecimal("3"))
-                    : contract.getMonthRent().multiply(new BigDecimal("12")))
-                    .setScale(2, RoundingMode.DOWN).doubleValue();
-            fill(templateParam, "firstRent", "¥" + extracted + "元");
-            // 其他财务字段
-            fill(templateParam, "firstRentString", "人民币" + NumberToChineseUtils.numberToChinese(extracted.doubleValue()));
-        } else {
-//            fill(templateParam, "firstRent", "");
-        }
-
-        fill(templateParam, "firstRent",
-                "¥"+(contract.getPayType().equals("1")
-                        ? contract.getMonthRent()
-                        :contract.getPayType().equals("2")
-                        ?contract.getMonthRent().multiply(new BigDecimal("3"))
-                        :contract.getMonthRent().multiply(new BigDecimal("12"))
-                        .setScale(2, RoundingMode.DOWN)).doubleValue()+"元");
+        BigDecimal extracted = extracted(contract,dto);
+        System.out.println("金额========================="+extracted);
+        fill(templateParam, "firstRent", "¥" + extracted + "元");
+        // 其他财务字段
+        fill(templateParam, "firstRentString", "人民币" + NumberToChineseUtils.numberToChinese(extracted.doubleValue()));
 
 
-        fill(templateParam, "firstRentString",
-                "人民币"+NumberToChineseUtils.numberToChinese(
-                        (contract.getPayType().equals("1")
-                                ? contract.getMonthRent()
-                                :contract.getPayType().equals("2")
-                                ?contract.getMonthRent().multiply(new BigDecimal("3"))
-                                :contract.getMonthRent().multiply(new BigDecimal("12"))
-                                .setScale(2, RoundingMode.DOWN)).doubleValue()));
+//        fill(templateParam, "firstRent",
+//                "¥"+(contract.getPayType().equals("1")
+//                        ? contract.getMonthRent()
+//                        :contract.getPayType().equals("2")
+//                        ?contract.getMonthRent().multiply(new BigDecimal("3"))
+//                        :contract.getMonthRent().multiply(new BigDecimal("12"))
+//                        .setScale(2, RoundingMode.DOWN)).doubleValue()+"元");
+//
+//
+//        fill(templateParam, "firstRentString",
+//                "人民币"+NumberToChineseUtils.numberToChinese(
+//                        (contract.getPayType().equals("1")
+//                                ? contract.getMonthRent()
+//                                :contract.getPayType().equals("2")
+//                                ?contract.getMonthRent().multiply(new BigDecimal("3"))
+//                                :contract.getMonthRent().multiply(new BigDecimal("12"))
+//                                .setScale(2, RoundingMode.DOWN)).doubleValue()));
 
 
 
@@ -541,17 +536,31 @@
             fill(templateParam, "checkTime", "");
         }
 
+        String url = "";
+        if (StringUtils.isNotEmpty(contract.getSignature())){
+            url = tencentCosUtil.downLoadFileImg(contract.getSignature());
+        }
+
+
         return wordUtil.generatePdf(
                 "/usr/local/project/file/",
                 templateFileName,
                 templateParam,
                 "租赁合同",
-                "/usr/local/project/file/");
+                "/usr/local/project/file/",url);
     }
 
-    private BigDecimal extracted(TContract contract) {
-        List<TContractRentType> contractRentTypes = contractRentTypeService.list();
-        TContractRentType tContractRentType = contractRentTypes.stream().filter(e -> e.getContractId().equals(contract.getId())).findFirst().orElse(null);
+    private BigDecimal extracted(TContract contract,TContractDTO dto) {
+        TContractRentType tContractRentType = null;
+        if (contract.getIsIncreasing()){
+            tContractRentType = new TContractRentType();
+            tContractRentType.setContractId(contract.getId());
+            tContractRentType.setIncreasingDecreasing(dto.getIncreasingDecreasing());
+            tContractRentType.setIncreasingDecreasingType(dto.getIncreasingDecreasingType());
+            tContractRentType.setNumericalValue(dto.getNumericalValue());
+            tContractRentType.setChangeTime(dto.getChangeTime());
+            tContractRentType.setCycleTime(dto.getCycleTime());
+        }
         // 生成第一笔账单
         // 第一次应缴费日期
 
@@ -790,9 +799,70 @@
     @PostMapping("/generateContractPreview")
     public R<String> generateContractPreview(@RequestBody TContractDTO dto)
     {
+        String contractName = dto.getContractName();
+        if (StringUtils.isEmpty(contractName)){
+            return R.fail("合同名称不能为空");
+        }
+        LocalDateTime startTime = dto.getStartTime();
+        if (startTime == null){
+            return R.fail("合同生效日期不能为空");
+        }
+        LocalDateTime endTime = dto.getEndTime();
+        if (endTime == null){
+            return R.fail("合同生效日期不能为空");
+        }
+
+        BigDecimal monthRent = dto.getMonthRent();
+        if (monthRent == null){
+            return R.fail("月租金不能为空");
+        }
+
+        BigDecimal deposit = dto.getDeposit();
+        if (deposit == null){
+            return R.fail("押金不能为空");
+        }
+
+        String payType = dto.getPayType();
+        if (StringUtils.isEmpty(payType)){
+            return R.fail("租金支付方式不能为空");
+        }
+
+        LocalDateTime startPayTime = dto.getStartPayTime();
+        if (startPayTime == null){
+            return R.fail("开始计费日期不能为空");
+        }
+
+        String partyOneName = dto.getPartyOneName();
+        if (StringUtils.isEmpty(partyOneName)){
+            return R.fail("甲方名称不能为空");
+        }
+
+        String partyOnePerson = dto.getPartyOnePerson();
+        if (StringUtils.isEmpty(partyOnePerson)){
+            return R.fail("甲方联系人不能为空");
+        }
+
+        String partyOnePhone = dto.getPartyOnePhone();
+        if (StringUtils.isEmpty(partyOnePhone)){
+            return R.fail("甲方联系电话不能为空");
+        }
+
+        String partyTwoName = dto.getPartyTwoName();
+        if (StringUtils.isEmpty(partyTwoName)){
+            return R.fail("乙方名称不能为空");
+        }
+        String partyTwoPerson = dto.getPartyTwoPerson();
+        if (StringUtils.isEmpty(partyTwoPerson)){
+            return R.fail("乙方联系人不能为空");
+        }
+        String partyTwoPhone = dto.getPartyTwoPhone();
+        if (StringUtils.isEmpty(partyTwoPhone)){
+            return R.fail("乙方联系电话不能为空");
+        }
+
         TContract contract = new TContract();
         BeanUtil.copyProperties(dto,contract);
-        return R.ok(generateContract(contract));
+        return R.ok(generateContract(contract,dto));
     }
 
     /**

--
Gitblit v1.7.1