From c2fb54cf6794f250b1746c3f37e8403b516c1549 Mon Sep 17 00:00:00 2001
From: fuliqi <fuliqi@qq.com>
Date: 星期日, 08 十二月 2024 22:30:26 +0800
Subject: [PATCH] 导入规则
---
ycl-server/src/main/resources/mapper/zgyw/TContractMapper.xml | 2
ycl-server/src/main/java/com/ycl/platform/service/impl/TContractServiceImpl.java | 59 +++++++++++++++++++++++++++--
ycl-server/src/main/java/com/ycl/platform/service/ITContractService.java | 8 ++++
ycl-server/src/main/java/com/ycl/platform/controller/ContractController.java | 12 ++++++
ycl-pojo/src/main/java/com/ycl/platform/domain/entity/TContract.java | 2 -
5 files changed, 76 insertions(+), 7 deletions(-)
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 26f4ee1..eb47cd8 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
@@ -87,10 +87,8 @@
private Integer deleted;
@TableField(exist = false)
- @NotBlank
private String ruleList;
@TableField(exist = false)
- @NotNull
private MultipartFile file;
}
diff --git a/ycl-server/src/main/java/com/ycl/platform/controller/ContractController.java b/ycl-server/src/main/java/com/ycl/platform/controller/ContractController.java
index 4ebc0d6..fdc0114 100644
--- a/ycl-server/src/main/java/com/ycl/platform/controller/ContractController.java
+++ b/ycl-server/src/main/java/com/ycl/platform/controller/ContractController.java
@@ -22,6 +22,7 @@
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
+import java.io.IOException;
import java.util.List;
/**
@@ -79,6 +80,17 @@
}
/**
+ * 鍚堝悓瀵煎叆瑙勫垯
+ *
+ * @return 瀵煎叆缁撴灉
+ */
+ @Log(title = "鍚堝悓瀵煎叆", businessType = BusinessType.IMPORT)
+ @PreAuthorize("@ss.hasPermi('system:user:import')")
+ @PostMapping("/updateRule")
+ public AjaxResult importRule(TContract tContract) throws IOException {
+ return tContractService.importRule(tContract.getFile(), tContract);
+ }
+ /**
* 鑾峰彇銆愯濉啓鍔熻兘鍚嶇О銆戣缁嗕俊鎭�
*/
@PreAuthorize("@ss.hasPermi('system:contract:query')")
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 b1b8e6f..7e62bf5 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
@@ -9,6 +9,7 @@
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.multipart.MultipartFile;
+import java.io.IOException;
import java.util.List;
/**
@@ -34,6 +35,13 @@
AjaxResult importData(MultipartFile file, TContract tContract);
/**
+ * 瀵煎叆鍚堝悓瑙勫垯
+ * @param file 鏂囦欢
+ * @param tContract 鍚堝悓淇℃伅
+ * @return 瀵煎叆缁撴灉
+ */
+ AjaxResult importRule(MultipartFile file, TContract tContract) throws IOException;
+ /**
* 鍒嗛〉鏌ヨ
*
* @param query
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 f01b16e..7bd7178 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
@@ -4,6 +4,7 @@
import com.alibaba.excel.read.listener.PageReadListener;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.alibaba.fastjson2.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -33,14 +34,13 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
+import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
+import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
import java.util.stream.Collectors;
/**
@@ -159,6 +159,57 @@
}
@Override
+ public AjaxResult importRule(MultipartFile file, TContract tContract) throws IOException {
+
+ // 鑾峰彇鍚堝悓Excel瑙勫垯
+ List<CalculateRule> list = new ArrayList<>();
+ if(file!=null) {
+ EasyExcel.read(file.getInputStream(), CalculateRule.class, new PageReadListener<CalculateRule>(list::addAll)).sheet().doRead();
+
+ // 閬嶅巻鐖跺瓙鍏崇郴
+ List<CalculateRule> calculateRulesToSave = new ArrayList<>();
+ for (CalculateRule calculateRule : list) {
+ // 鍒ゆ柇鏁版嵁瀹屾暣鎬�
+ if (ObjectUtils.isEmpty(calculateRule.getDeductCategory())) {
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+ return AjaxResult.warn("璇烽�夋嫨" + calculateRule.getRuleName() + calculateRule.getRuleCondition() + "鎵e垎鏂瑰紡");
+ }
+ if (RuleDeductCategoryEnum.MULTIPLY_POINTS_AFTER_DIVIDING_QUANTITY.equals(calculateRule.getDeductCategory()) && ObjectUtils.isEmpty(calculateRule.getCalcUnit())) {
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+ return AjaxResult.warn("璇峰~鍐�" + calculateRule.getRuleName() + calculateRule.getRuleCondition() + "闄や互鏁伴噺");
+ }
+ if (ObjectUtils.isEmpty(calculateRule.getCalcFraction())) {
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+ return AjaxResult.warn("璇峰~鍐�" + calculateRule.getRuleName() + calculateRule.getRuleCondition() + "鎵e垎鏁板��");
+ }
+ // 淇濆瓨瑙勫垯
+ if (StringUtils.isNotBlank(calculateRule.getRuleName())) {
+ calculateRule.setContractId(tContract.getId().intValue());
+ calculateRule.setCreateTime(DateUtils.getNowDate());
+ calculateRule.setUpdateTime(DateUtils.getNowDate());
+ calculateRulesToSave.add(calculateRule);
+ }
+ }
+ if (!CollectionUtils.isEmpty(calculateRulesToSave)) {
+ //鍒犻櫎鍘熻鍒�
+ calculateRuleService.remove(new QueryWrapper<CalculateRule>().eq("contract_id", tContract.getId()));
+ // 鎵归噺淇濆瓨瑙勫垯
+ calculateRuleService.saveBatch(calculateRulesToSave);
+ }
+ }
+ List<CalculateMoneyRule> moneyRule = JSON.parseArray(tContract.getRuleList(), CalculateMoneyRule.class).stream().peek(
+ calculateMoneyRule -> calculateMoneyRule.setContractId(tContract.getId().intValue())
+ ).collect(Collectors.toList());
+ if (!CollectionUtils.isEmpty(moneyRule)) {
+ //鍒犻櫎鍘熻鍒�
+ calculateMoneyRuleService.remove(new QueryWrapper<CalculateMoneyRule>().eq("contract_id",tContract.getId()));
+ //鎵归噺淇濆瓨鑰冩牳缁撴灉搴旂敤瑙勫垯
+ calculateMoneyRuleService.saveBatch(moneyRule);
+ }
+ return AjaxResult.success("鎿嶄綔鎴愬姛");
+ }
+
+ @Override
public Result selectAll(ContractQuery query) {
IPage<ContractVO> page = PageUtil.getPage(query, ContractVO.class);
query.setUnitId(SecurityUtils.getUnitId());
diff --git a/ycl-server/src/main/resources/mapper/zgyw/TContractMapper.xml b/ycl-server/src/main/resources/mapper/zgyw/TContractMapper.xml
index 1620c03..91e239e 100644
--- a/ycl-server/src/main/resources/mapper/zgyw/TContractMapper.xml
+++ b/ycl-server/src/main/resources/mapper/zgyw/TContractMapper.xml
@@ -42,7 +42,7 @@
<select id="getCalculateRule" resultType="com.ycl.platform.domain.vo.CalculateRuleVO">
select tc.unit_id ,tcr.*
from t_contract tc
- left join t_calculate_rule tcr on tc.id = tcr.contract_id
+ left join t_calculate_rule tcr on tc.id = tcr.contract_id and tcr.deleted =0
<where>
tc.deleted =0 and #{date} between tc.start_time and tc.end_time
</where>
--
Gitblit v1.8.0