From 67683967e7be0e899ced1d460e53080b5098859d Mon Sep 17 00:00:00 2001
From: 龚焕茏 <2842157468@qq.com>
Date: 星期二, 23 四月 2024 18:05:53 +0800
Subject: [PATCH] 合同导入、规则、展示

---
 ycl-pojo/src/main/java/com/ycl/platform/domain/entity/CalculateRule.java             |   16 ++
 ycl-server/src/main/java/com/ycl/platform/service/impl/CalculateRuleServiceImpl.java |   74 ++++++++++--
 ycl-pojo/src/main/java/com/ycl/system/domain/TreeNode.java                           |   55 +++++++++
 ycl-server/src/main/java/com/ycl/platform/service/impl/TContractServiceImpl.java     |   57 +++++++++
 ycl-server/src/main/java/com/ycl/platform/service/ICalculateRuleService.java         |   15 ++
 ycl-server/src/main/java/com/ycl/platform/service/ITContractService.java             |   13 ++
 ycl-pojo/src/main/java/com/ycl/system/domain/TreeUtils.java                          |   75 ++++++++++++
 ycl-server/src/main/java/com/ycl/platform/controller/CalculateRuleController.java    |   10 +
 ycl-server/src/main/java/com/ycl/platform/controller/TContractController.java        |   23 ++-
 ycl-pojo/src/main/java/com/ycl/platform/domain/entity/TContract.java                 |   17 ++
 10 files changed, 322 insertions(+), 33 deletions(-)

diff --git a/ycl-pojo/src/main/java/com/ycl/platform/domain/entity/CalculateRule.java b/ycl-pojo/src/main/java/com/ycl/platform/domain/entity/CalculateRule.java
index c554b6c..5b750d4 100644
--- a/ycl-pojo/src/main/java/com/ycl/platform/domain/entity/CalculateRule.java
+++ b/ycl-pojo/src/main/java/com/ycl/platform/domain/entity/CalculateRule.java
@@ -6,8 +6,12 @@
 import com.alibaba.excel.enums.poi.HorizontalAlignmentEnum;
 import com.alibaba.excel.enums.poi.VerticalAlignmentEnum;
 import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.baomidou.mybatisplus.annotation.TableName;
 import com.ycl.system.domain.TreeEntity;
+import com.ycl.system.domain.TreeNode;
 import lombok.Data;
+
+import java.util.Date;
 
 /**
  * 鍒嗘暟鏍哥畻瑙勫垯瀵硅薄 t_default_rule
@@ -18,7 +22,8 @@
 @Data
 @ExcelIgnoreUnannotated
 @ContentStyle(horizontalAlignment = HorizontalAlignmentEnum.CENTER, verticalAlignment = VerticalAlignmentEnum.CENTER)
-public class CalculateRule extends TreeEntity {
+@TableName("t_calculate_rule")
+public class CalculateRule extends TreeNode {
     private static final long serialVersionUID = 1L;
 
     /**
@@ -28,9 +33,9 @@
     private Long id;
 
     /**
-     * 鍗曚綅id
+     * 鍚堝悓id
      */
-    private Integer unitId;
+    private Integer contractId;
 
     /**
      * 瑙勫垯鍚嶇О
@@ -73,7 +78,10 @@
     @ExcelProperty("闄や互鏁伴噺")
     private Integer calcUnit;
 
+    private Date createTime;
+    private Date updateTime;
+
     @TableLogic
-    private String deleted;
+    private Integer deleted;
 
 }
diff --git a/ycl-pojo/src/main/java/com/ycl/platform/domain/entity/TContract.java b/ycl-pojo/src/main/java/com/ycl/platform/domain/entity/TContract.java
index 8cdb71e..e3498b4 100644
--- a/ycl-pojo/src/main/java/com/ycl/platform/domain/entity/TContract.java
+++ b/ycl-pojo/src/main/java/com/ycl/platform/domain/entity/TContract.java
@@ -5,9 +5,10 @@
 import com.alibaba.excel.annotation.write.style.ContentStyle;
 import com.alibaba.excel.enums.poi.HorizontalAlignmentEnum;
 import com.alibaba.excel.enums.poi.VerticalAlignmentEnum;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableLogic;
 import com.fasterxml.jackson.annotation.JsonFormat;
-import com.ycl.system.entity.BaseEntity;
 import lombok.Data;
 
 import java.util.Date;
@@ -21,19 +22,23 @@
 @Data
 @ExcelIgnoreUnannotated
 @ContentStyle(horizontalAlignment = HorizontalAlignmentEnum.CENTER, verticalAlignment = VerticalAlignmentEnum.CENTER)
-public class TContract extends BaseEntity {
+public class TContract {
     private static final long serialVersionUID = 1L;
 
     /**
      * 涓婚敭
      */
     @ExcelProperty("搴忓彿")
+    @TableId
     private Long id;
 
     /**
      * 鍗曚綅id
      */
     private Integer unitId;
+
+    @TableField(exist = false)
+    private String unitName;
 
     /**
      * 鍚堝悓鍚嶇О
@@ -43,15 +48,19 @@
     /**
      * 寮�濮嬫椂闂�
      */
-    @JsonFormat(pattern = "yyyy-MM-dd")
+    @JsonFormat(pattern = "yyyy-MM-dd hh-mm-ss")
     private Date startTime;
 
     /**
      * 缁撴潫鏃堕棿
      */
-    @JsonFormat(pattern = "yyyy-MM-dd")
+    @JsonFormat(pattern = "yyyy-MM-dd hh-mm-ss")
     private Date endTime;
 
+    private Date createTime;
+
+    private Date updateTime;
+
     @TableLogic
     private String deleted;
 
diff --git a/ycl-pojo/src/main/java/com/ycl/system/domain/TreeNode.java b/ycl-pojo/src/main/java/com/ycl/system/domain/TreeNode.java
new file mode 100644
index 0000000..8f39e5c
--- /dev/null
+++ b/ycl-pojo/src/main/java/com/ycl/system/domain/TreeNode.java
@@ -0,0 +1,55 @@
+package com.ycl.system.domain;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 鏍戣妭鐐癸紝鎵�鏈夐渶瑕佸疄鐜版爲鑺傜偣鐨勶紝閮介渶瑕佺户鎵胯绫�
+ *
+ * @author Mark sunlightcs@gmail.com
+ * @since 1.0.0
+ */
+public class TreeNode<T> implements Serializable {
+    private static final long serialVersionUID = 1L;
+    /**
+     * 涓婚敭
+     */
+    private Long id;
+    /**
+     * 涓婄骇ID
+     */
+
+    private Long parentId;
+    /**
+     * 瀛愯妭鐐瑰垪琛�
+     */
+    @TableField(exist = false)
+    private List<T> children = new ArrayList<>();
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Long getParentId() {
+        return parentId;
+    }
+
+    public void setParentId(Long pid) {
+        this.parentId = pid;
+    }
+
+    public List<T> getChildren() {
+        return children;
+    }
+
+    public void setChildren(List<T> children) {
+        this.children = children;
+    }
+}
\ No newline at end of file
diff --git a/ycl-pojo/src/main/java/com/ycl/system/domain/TreeUtils.java b/ycl-pojo/src/main/java/com/ycl/system/domain/TreeUtils.java
new file mode 100644
index 0000000..d8c27d9
--- /dev/null
+++ b/ycl-pojo/src/main/java/com/ycl/system/domain/TreeUtils.java
@@ -0,0 +1,75 @@
+package com.ycl.system.domain;
+
+
+import org.apache.commons.lang3.ObjectUtils;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 鏍戝舰缁撴瀯宸ュ叿绫伙紝濡傦細鑿滃崟銆侀儴闂ㄧ瓑
+ *
+ * @author Mark sunlightcs@gmail.com
+ * @since 1.0.0
+ */
+public class TreeUtils {
+
+    /**
+     * 鏍规嵁pid锛屾瀯寤烘爲鑺傜偣
+     */
+    public static <T extends TreeNode> List<T> build(List<T> treeNodes, Long pid) {
+        //pid涓嶈兘涓虹┖
+        if(ObjectUtils.isEmpty(pid)) {
+            return null;
+        }
+
+        List<T> treeList = new ArrayList<>();
+        for (T treeNode : treeNodes) {
+            if (pid.equals(treeNode.getParentId())) {
+                treeList.add(findChildren(treeNodes, treeNode));
+            }
+        }
+
+        return treeList;
+    }
+
+    /**
+     * 鏌ユ壘瀛愯妭鐐�
+     */
+    private static <T extends TreeNode> T findChildren(List<T> treeNodes, T rootNode) {
+        for (T treeNode : treeNodes) {
+            if (rootNode.getId().equals(treeNode.getParentId())) {
+                rootNode.getChildren().add(findChildren(treeNodes, treeNode));
+            }
+        }
+        return rootNode;
+    }
+
+    /**
+     * 鏋勫缓鏍戣妭鐐�
+     */
+    public static <T extends TreeNode> List<T> build(List<T> treeNodes) {
+        List<T> result = new ArrayList<>();
+
+        //list杞琺ap
+        Map<Long, T> nodeMap = new LinkedHashMap<>(treeNodes.size());
+        for (T treeNode : treeNodes) {
+            nodeMap.put(treeNode.getId(), treeNode);
+        }
+
+        for (T node : nodeMap.values()) {
+            T parent = nodeMap.get(node.getParentId());
+            if (parent != null && !(node.getId().equals(parent.getId()))) {
+                parent.getChildren().add(node);
+                continue;
+            }
+
+            result.add(node);
+        }
+
+        return result;
+    }
+
+}
\ No newline at end of file
diff --git a/ycl-server/src/main/java/com/ycl/platform/controller/CalculateRuleController.java b/ycl-server/src/main/java/com/ycl/platform/controller/CalculateRuleController.java
index efc2f01..e4218cd 100644
--- a/ycl-server/src/main/java/com/ycl/platform/controller/CalculateRuleController.java
+++ b/ycl-server/src/main/java/com/ycl/platform/controller/CalculateRuleController.java
@@ -39,6 +39,16 @@
     }
 
     /**
+     * 鏍规嵁鍚堝悓id鏌ヨ杩濈害瑙勫垯鍒楄〃
+     */
+    @PreAuthorize("@ss.hasPermi('system:rule:query')")
+    @GetMapping("/getRuleListByContractId")
+    public AjaxResult getRuleListByContractId(Integer contractId)
+    {
+        return success(defaultRuleService.getRuleListByContractId(contractId));
+    }
+
+    /**
      * 瀵煎嚭杩濈害瑙勫垯鍒楄〃
      */
     @PreAuthorize("@ss.hasPermi('system:rule:export')")
diff --git a/ycl-server/src/main/java/com/ycl/platform/controller/TContractController.java b/ycl-server/src/main/java/com/ycl/platform/controller/TContractController.java
index 0d463e2..aaa12f7 100644
--- a/ycl-server/src/main/java/com/ycl/platform/controller/TContractController.java
+++ b/ycl-server/src/main/java/com/ycl/platform/controller/TContractController.java
@@ -1,17 +1,25 @@
 package com.ycl.platform.controller;
 
 import annotation.Log;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ycl.platform.domain.entity.TContract;
+import com.ycl.platform.domain.entity.TMonitor;
+import com.ycl.platform.domain.query.YwUnitQuery;
+import com.ycl.platform.domain.vo.TMonitorVO;
 import com.ycl.platform.service.ITContractService;
 import com.ycl.system.AjaxResult;
+import com.ycl.system.Result;
 import com.ycl.system.controller.BaseController;
-import com.ycl.utils.poi.ExcelUtil;
+import com.ycl.system.page.TableDataInfo;
 import enumeration.BusinessType;
+import io.swagger.annotations.ApiOperation;
 import jakarta.servlet.http.HttpServletResponse;
 import lombok.AllArgsConstructor;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
+
+import java.util.List;
 
 /**
  * 銆愯濉啓鍔熻兘鍚嶇О銆慍ontroller
@@ -26,6 +34,11 @@
 
     private final ITContractService tContractService;
 
+    @PreAuthorize("@ss.hasPermi('system:contract:list')")
+    @GetMapping("/list")
+    public List<TContract> list() {
+        return tContractService.selectAll();
+    }
 
     /**
      * 鍚堝悓瀵煎叆妯℃澘
@@ -40,17 +53,13 @@
     /**
      * 鍚堝悓瀵煎叆
      *
-     * @param file      瀵煎叆鏂囦欢
-     * @param unitId    杩愮淮鍗曚綅
-     * @param startTime 寮�濮嬫椂闂�
-     * @param endTime   缁撴潫鏃堕棿
      * @return 瀵煎叆缁撴灉
      */
     @Log(title = "鍚堝悓瀵煎叆", businessType = BusinessType.IMPORT)
     @PreAuthorize("@ss.hasPermi('system:user:import')")
     @PostMapping("/importData")
-    public AjaxResult importData(MultipartFile file, String unitId, String startTime, String endTime) {
-        ExcelUtil<TContract> util = new ExcelUtil<>(TContract.class);
+    public AjaxResult importData(MultipartFile file, TContract tContract) {
+        tContractService.importData(file, tContract);
         return success();
     }
 
diff --git a/ycl-server/src/main/java/com/ycl/platform/service/ICalculateRuleService.java b/ycl-server/src/main/java/com/ycl/platform/service/ICalculateRuleService.java
index 81484a7..0f5aaab 100644
--- a/ycl-server/src/main/java/com/ycl/platform/service/ICalculateRuleService.java
+++ b/ycl-server/src/main/java/com/ycl/platform/service/ICalculateRuleService.java
@@ -1,6 +1,9 @@
 package com.ycl.platform.service;
 
+import com.baomidou.mybatisplus.extension.service.IService;
 import com.ycl.platform.domain.entity.CalculateRule;
+import com.ycl.platform.domain.entity.TContract;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.util.List;
 
@@ -10,8 +13,7 @@
  * @author ruoyi
  * @date 2024-04-01
  */
-public interface ICalculateRuleService
-{
+public interface ICalculateRuleService extends IService<CalculateRule> {
     /**
      * 鏌ヨ杩濈害瑙勫垯
      *
@@ -59,4 +61,13 @@
      * @return 缁撴灉
      */
     public int deleteDefaultRuleById(Long id);
+
+    /**
+     * 璇诲彇Excel鏁版嵁
+     *
+     * @param file      鏂囦欢
+     */
+    List<CalculateRule> readExcel(MultipartFile file);
+
+    List<CalculateRule> getRuleListByContractId(Integer contractId);
 }
diff --git a/ycl-server/src/main/java/com/ycl/platform/service/ITContractService.java b/ycl-server/src/main/java/com/ycl/platform/service/ITContractService.java
index ba9cac0..d9835a0 100644
--- a/ycl-server/src/main/java/com/ycl/platform/service/ITContractService.java
+++ b/ycl-server/src/main/java/com/ycl/platform/service/ITContractService.java
@@ -3,6 +3,9 @@
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.ycl.platform.domain.entity.TContract;
 import jakarta.servlet.http.HttpServletResponse;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.List;
 
 /**
  * 銆愯濉啓鍔熻兘鍚嶇О銆慡ervice鎺ュ彛
@@ -17,4 +20,14 @@
      * @param response 缁撴灉
      */
     void importTemplate(HttpServletResponse response);
+
+    /**
+     * 瀵煎叆鍚堝悓鏁版嵁
+     * @param file 鏂囦欢
+     * @param tContract 鍚堝悓淇℃伅
+     * @return 瀵煎叆缁撴灉
+     */
+    void importData(MultipartFile file, TContract tContract);
+
+    List<TContract> selectAll();
 }
diff --git a/ycl-server/src/main/java/com/ycl/platform/service/impl/CalculateRuleServiceImpl.java b/ycl-server/src/main/java/com/ycl/platform/service/impl/CalculateRuleServiceImpl.java
index 21935bf..39896a1 100644
--- a/ycl-server/src/main/java/com/ycl/platform/service/impl/CalculateRuleServiceImpl.java
+++ b/ycl-server/src/main/java/com/ycl/platform/service/impl/CalculateRuleServiceImpl.java
@@ -1,13 +1,26 @@
 package com.ycl.platform.service.impl;
 
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.context.AnalysisContext;
+import com.alibaba.excel.enums.CellExtraTypeEnum;
+import com.alibaba.excel.metadata.CellExtra;
+import com.alibaba.excel.read.listener.ReadListener;
+import com.alibaba.fastjson2.JSON;
+import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ycl.platform.domain.entity.CalculateRule;
+import com.ycl.platform.domain.entity.TContract;
 import com.ycl.platform.mapper.CalculateRuleMapper;
 import com.ycl.platform.service.ICalculateRuleService;
+import com.ycl.system.domain.TreeNode;
+import com.ycl.system.domain.TreeUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
 import utils.DateUtils;
 
+import java.io.IOException;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -17,8 +30,7 @@
  * @date 2024-04-01
  */
 @Service
-public class CalculateRuleServiceImpl extends ServiceImpl<CalculateRuleMapper, CalculateRule> implements ICalculateRuleService
-{
+public class CalculateRuleServiceImpl extends ServiceImpl<CalculateRuleMapper, CalculateRule> implements ICalculateRuleService {
     @Autowired
     private CalculateRuleMapper calculateRuleMapper;
 
@@ -29,8 +41,7 @@
      * @return 杩濈害瑙勫垯
      */
     @Override
-    public CalculateRule selectDefaultRuleById(Long id)
-    {
+    public CalculateRule selectDefaultRuleById(Long id) {
         return calculateRuleMapper.selectDefaultRuleById(id);
     }
 
@@ -41,8 +52,7 @@
      * @return 杩濈害瑙勫垯
      */
     @Override
-    public List<CalculateRule> selectDefaultRuleList(CalculateRule calculateRule)
-    {
+    public List<CalculateRule> selectDefaultRuleList(CalculateRule calculateRule) {
         return calculateRuleMapper.selectDefaultRuleList(calculateRule);
     }
 
@@ -53,8 +63,7 @@
      * @return 缁撴灉
      */
     @Override
-    public int insertDefaultRule(CalculateRule calculateRule)
-    {
+    public int insertDefaultRule(CalculateRule calculateRule) {
         calculateRule.setCreateTime(DateUtils.getNowDate());
         return calculateRuleMapper.insertDefaultRule(calculateRule);
     }
@@ -66,8 +75,7 @@
      * @return 缁撴灉
      */
     @Override
-    public int updateDefaultRule(CalculateRule calculateRule)
-    {
+    public int updateDefaultRule(CalculateRule calculateRule) {
         calculateRule.setUpdateTime(DateUtils.getNowDate());
         return calculateRuleMapper.updateDefaultRule(calculateRule);
     }
@@ -79,8 +87,7 @@
      * @return 缁撴灉
      */
     @Override
-    public int deleteDefaultRuleByIds(Long[] ids)
-    {
+    public int deleteDefaultRuleByIds(Long[] ids) {
         return calculateRuleMapper.deleteDefaultRuleByIds(ids);
     }
 
@@ -91,8 +98,47 @@
      * @return 缁撴灉
      */
     @Override
-    public int deleteDefaultRuleById(Long id)
-    {
+    public int deleteDefaultRuleById(Long id) {
         return calculateRuleMapper.deleteDefaultRuleById(id);
     }
+
+    /**
+     * 鑾峰彇鍚堝悓Excel瑙勫垯
+     *
+     * @param file 鍚堝悓Excel鏂囦欢
+     * @return 瑙勫垯
+     */
+
+    @Override
+    public List<CalculateRule> readExcel(MultipartFile file) {
+        List<CalculateRule> calculateRuleList = new ArrayList<>();
+        try {
+            EasyExcel.read(file.getInputStream(), CalculateRule.class, new ReadListener<CalculateRule>() {
+                        @Override
+                        public void invoke(CalculateRule calculateRule, AnalysisContext analysisContext) {
+                            calculateRule.setId(null);
+                            calculateRuleList.add(calculateRule);
+                        }
+
+                        @Override
+                        public void doAfterAllAnalysed(AnalysisContext analysisContext) {
+                        }
+
+                    })
+                    .head(CalculateRule.class)
+                    .sheet()
+                    .doRead();
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        return calculateRuleList;
+    }
+
+    @Override
+    public List<CalculateRule> getRuleListByContractId(Integer contractId) {
+        List<CalculateRule> list = new LambdaQueryChainWrapper<>(calculateRuleMapper)
+                .eq(CalculateRule::getContractId, contractId)
+                .list();
+        return TreeUtils.build(list, 0L);
+    }
 }
diff --git a/ycl-server/src/main/java/com/ycl/platform/service/impl/TContractServiceImpl.java b/ycl-server/src/main/java/com/ycl/platform/service/impl/TContractServiceImpl.java
index 988d72f..810cd7b 100644
--- a/ycl-server/src/main/java/com/ycl/platform/service/impl/TContractServiceImpl.java
+++ b/ycl-server/src/main/java/com/ycl/platform/service/impl/TContractServiceImpl.java
@@ -3,19 +3,28 @@
 import com.alibaba.excel.EasyExcel;
 import com.alibaba.excel.write.merge.LoopMergeStrategy;
 import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ycl.handler.CommentWriteHandler;
 import com.ycl.handler.CustomSheetWriteHandler;
 import com.ycl.platform.domain.entity.CalculateRule;
 import com.ycl.platform.domain.entity.TContract;
 import com.ycl.platform.mapper.TContractMapper;
+import com.ycl.platform.service.ICalculateRuleService;
 import com.ycl.platform.service.ITContractService;
+import com.ycl.utils.DateUtils;
+import com.ycl.utils.StringUtils;
 import jakarta.servlet.http.HttpServletResponse;
+import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -25,7 +34,12 @@
  * @date 2024-03-12
  */
 @Service
+@AllArgsConstructor
 public class TContractServiceImpl extends ServiceImpl<TContractMapper, TContract> implements ITContractService {
+
+    private final ICalculateRuleService calculateRuleService;
+    private final YwUnitServiceImpl ywUnitService;
+
     @Override
     public void importTemplate(HttpServletResponse response) {
         try {
@@ -87,12 +101,10 @@
         calculateRule4.setCalcFraction(0.1);
         list.add(calculateRule4);
         CalculateRule calculateRule7 = new CalculateRule();
-        calculateRule7.setRuleName("鈥︹�︹�︹��");
         calculateRule7.setRuleDesc("鈥︹�︹�︹��");
         calculateRule7.setRuleCondition("鈥︹�︹�︹��");
         list.add(calculateRule7);
         CalculateRule calculateRule6 = new CalculateRule();
-        calculateRule6.setRuleName("鈥︹�︹�︹��");
         calculateRule6.setRuleDesc("鈥︹�︹�︹��");
         calculateRule6.setRuleCondition("鈥︹�︹�︹��");
         list.add(calculateRule6);
@@ -107,4 +119,45 @@
         list.add(calculateRule5);
         return list;
     }
+
+    @Override
+    @Transactional
+    public void importData(MultipartFile file, TContract tContract) {
+        tContract.setCreateTime(DateUtils.getNowDate());
+        tContract.setDeleted("0");
+        save(tContract);
+        List<CalculateRule> list = calculateRuleService.readExcel(file);
+
+        // 閬嶅巻鐖跺瓙鍏崇郴
+        List<CalculateRule> calculateRulesToSave = new ArrayList<>();
+        CalculateRule temp = new CalculateRule();
+        for (CalculateRule calculateRule : list) {
+            // 鐖惰鍒�
+            if (StringUtils.isNotBlank(calculateRule.getRuleName())) {
+                CalculateRule fu = new CalculateRule();
+                fu.setContractId(tContract.getId().intValue());
+                fu.setRuleName(calculateRule.getRuleName());
+                fu.setCreateTime(DateUtils.getNowDate());
+                fu.setDeleted(0);
+                calculateRuleService.save(fu);
+                temp = fu;
+            }
+            calculateRule.setContractId(tContract.getId().intValue());
+            calculateRule.setCreateTime(DateUtils.getNowDate());
+            calculateRule.setDeleted(0);
+            calculateRule.setParentId(temp.getId());
+            calculateRulesToSave.add(calculateRule);
+        }
+        // 鎵归噺淇濆瓨瑙勫垯
+        calculateRuleService.saveBatch(calculateRulesToSave);
+    }
+
+    @Override
+    public List<TContract> selectAll() {
+        return list(new LambdaQueryWrapper<TContract>()
+                .orderByDesc(TContract::getCreateTime))
+                .stream().peek(
+                        tContract -> tContract.setUnitName(ywUnitService.getById(tContract.getUnitId()).getUnitName())
+                ).toList();
+    }
 }

--
Gitblit v1.8.0