From ca41db25ab3da9ddd509b79fd783b60d2e66056f Mon Sep 17 00:00:00 2001
From: peng <peng.com>
Date: 星期二, 24 三月 2026 10:28:40 +0800
Subject: [PATCH] 调整
---
jyz-base-start/src/main/java/com/tievd/jyz/controller/ClientConfigController.java | 82 +++++++++++++++++++++++++++++++++++++++-
1 files changed, 79 insertions(+), 3 deletions(-)
diff --git a/jyz-base-start/src/main/java/com/tievd/jyz/controller/ClientConfigController.java b/jyz-base-start/src/main/java/com/tievd/jyz/controller/ClientConfigController.java
index b1e36a1..f15653e 100644
--- a/jyz-base-start/src/main/java/com/tievd/jyz/controller/ClientConfigController.java
+++ b/jyz-base-start/src/main/java/com/tievd/jyz/controller/ClientConfigController.java
@@ -5,21 +5,31 @@
import com.tievd.cube.commons.annotations.DictApi;
import com.tievd.cube.commons.base.CubeController;
import com.tievd.cube.commons.base.Result;
+import com.tievd.cube.commons.constant.CacheConst;
+import com.tievd.cube.modules.system.entity.SysDictItem;
+import com.tievd.cube.modules.system.service.ISysDictItemService;
+import com.tievd.jyz.entity.Client;
import com.tievd.jyz.entity.ClientConfig;
import com.tievd.jyz.entity.vo.ClientVo;
import com.tievd.jyz.service.IClientConfigService;
import com.tievd.jyz.service.IClientService;
+import cn.dev33.satoken.stp.StpUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
+import java.util.UUID;
/**
* ClientConfig
@@ -35,11 +45,16 @@
@Tag(name = "瀹㈡埛瑙勫垯閰嶇疆")
public class ClientConfigController extends CubeController<ClientConfig, IClientConfigService> {
+ private static final String DICT_ID = "1631109859116990466";
+
@Autowired
private IClientConfigService clientConfigService;
@Autowired
IClientService clientService;
+
+ @Autowired
+ private ISysDictItemService sysDictItemService;
/**
* 鍒嗛〉鍒楄〃鏌ヨ
@@ -54,10 +69,13 @@
@AutoLog("ClientConfig-娣诲姞")
@PostMapping("/add")
+ @Transactional(rollbackFor = Exception.class)
+ @CacheEvict(value = CacheConst.SYS_DICT_CACHE, allEntries = true)
@Operation(summary = "娣诲姞瀹㈡埛瑙勫垯")
public Result<?> add(@RequestBody ClientVo clientVo) {
clientService.save(clientVo);
clientConfigService.saveBatch(getConfig(clientVo));
+ syncDictItem(clientVo.getClientName(), clientVo.getId());
return Result.ok();
}
@@ -66,23 +84,73 @@
*/
@AutoLog("ClientConfig-缂栬緫")
@PutMapping("/edit")
+ @Transactional(rollbackFor = Exception.class)
+ @CacheEvict(value = CacheConst.SYS_DICT_CACHE, allEntries = true)
@Operation(summary = "淇敼瀹㈡埛瑙勫垯")
public Result<?> edit(@RequestBody ClientVo clientVo) {
clientService.updateById(clientVo);
clientConfigService.remove(new LambdaQueryWrapper<ClientConfig>().eq(ClientConfig::getClientId, clientVo.getId()));
clientConfigService.saveBatch(getConfig(clientVo));
+ updateDictItem(clientVo.getClientName(), clientVo.getId());
return Result.ok();
}
List<ClientConfig> getConfig(ClientVo clientVo) {
List<ClientConfig> clientConfigs = clientVo.getClientConfigs();
+ if (clientConfigs == null || clientConfigs.isEmpty()) {
+ return Collections.emptyList();
+ }
clientConfigs.forEach(c -> {
- String[] param = c.getTimeStr().split(",");
+ if (StringUtils.hasText(c.getTimeStr())) {
+ String[] param = c.getTimeStr().split(",");
+ c.setTimeValue(Integer.valueOf(param[0])).setTimeUnit(param[1]);
+ }
+ if (c.getRuleType() == null) {
+ c.setRuleType((byte) 1);
+ }
+ if (c.getRuleType() == 2) {
+ if (c.getCountType() == null) {
+ c.setCountType((byte) 2);
+ }
+ if (c.getCountRef() == null) {
+ c.setCountRef((byte) 1);
+ }
+ }
c.setClientId(clientVo.getId())
- .setClientName(clientVo.getClientName())
- .setTimeValue(Integer.valueOf(param[0])).setTimeUnit(param[1]);
+ .setClientName(clientVo.getClientName());
});
return clientConfigs;
+ }
+
+ private void syncDictItem(String clientName, Integer clientId) {
+ SysDictItem dictItem = new SysDictItem();
+ dictItem.setId(UUID.randomUUID().toString().replace("-", ""));
+ dictItem.setDictId(DICT_ID);
+ dictItem.setItemText(clientName);
+ dictItem.setItemValue(String.valueOf(clientId));
+ dictItem.setSortOrder(clientId);
+ dictItem.setStatus(1);
+ dictItem.setCreateBy(StpUtil.getLoginIdAsString());
+ dictItem.setCreateTime(new java.util.Date());
+ sysDictItemService.save(dictItem);
+ }
+
+ private void updateDictItem(String clientName, Integer clientId) {
+ LambdaQueryWrapper<SysDictItem> wrapper = new LambdaQueryWrapper<>();
+ wrapper.eq(SysDictItem::getDictId, DICT_ID).eq(SysDictItem::getItemValue, String.valueOf(clientId));
+ SysDictItem dictItem = sysDictItemService.getOne(wrapper);
+ if (dictItem != null) {
+ dictItem.setItemText(clientName);
+ sysDictItemService.updateById(dictItem);
+ } else {
+ syncDictItem(clientName, clientId);
+ }
+ }
+
+ private void deleteDictItem(String clientName) {
+ LambdaQueryWrapper<SysDictItem> wrapper = new LambdaQueryWrapper<>();
+ wrapper.eq(SysDictItem::getDictId, DICT_ID).eq(SysDictItem::getItemText, clientName);
+ sysDictItemService.remove(wrapper);
}
/**
@@ -90,10 +158,18 @@
*/
@AutoLog("ClientConfig-閫氳繃id鍒犻櫎")
@DeleteMapping("/delete")
+ @Transactional(rollbackFor = Exception.class)
+ @CacheEvict(value = CacheConst.SYS_DICT_CACHE, allEntries = true)
@Operation(summary = "鍒犻櫎瀹㈡埛瑙勫垯")
public Result<?> delete(@RequestParam String id) {
+ Client client = clientService.getById(id);
+ if (client == null) {
+ return Result.error("璁板綍涓嶅瓨鍦�");
+ }
+ String clientName = client.getClientName();
clientService.removeById(id);
clientConfigService.remove(new LambdaQueryWrapper<ClientConfig>().eq(ClientConfig::getClientId, id));
+ deleteDictItem(clientName);
return Result.ok();
}
--
Gitblit v1.8.0