修改字典值逻辑.
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
package com.orion.ops.framework.redis.core.utils;
|
||||
|
||||
import com.orion.lang.define.cache.CacheKeyDefine;
|
||||
import com.orion.lang.utils.Arrays1;
|
||||
import com.orion.lang.utils.io.Streams;
|
||||
import org.springframework.data.redis.core.Cursor;
|
||||
import org.springframework.data.redis.core.RedisCallback;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.ScanOptions;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -73,6 +75,18 @@ public class RedisUtils {
|
||||
redisTemplate.delete(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除 key
|
||||
*
|
||||
* @param keys keys
|
||||
*/
|
||||
public static void delete(String... keys) {
|
||||
if (Arrays1.isEmpty(keys)) {
|
||||
return;
|
||||
}
|
||||
redisTemplate.delete(Arrays.asList(keys));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除 key
|
||||
*
|
||||
|
||||
@@ -114,7 +114,7 @@ public class ${table.controllerName} {
|
||||
@Parameter(name = "idList", description = "idList", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:delete')")
|
||||
public Integer batchDelete${type}(@RequestParam("idList") List<Long> idList) {
|
||||
return ${typeLower}Service.batchDelete${type}ByIdList(idList);
|
||||
return ${typeLower}Service.delete${type}ByIdList(idList);
|
||||
}
|
||||
|
||||
@OperatorLog(${type}OperatorType.EXPORT)
|
||||
|
||||
@@ -66,9 +66,9 @@ public class ${table.serviceImplName} implements ${table.serviceName} {
|
||||
|
||||
@Override
|
||||
public Integer update${type}ById(${type}UpdateRequest request) {
|
||||
log.info("${type}Service-update${type}ById id: {}, request: {}", request.getId(), JSON.toJSONString(request));
|
||||
// 查询
|
||||
Long id = Valid.notNull(request.getId(), ErrorMessage.ID_MISSING);
|
||||
log.info("${type}Service-update${type}ById id: {}, request: {}", id, JSON.toJSONString(request));
|
||||
// 查询
|
||||
${type}DO record = ${typeLower}DAO.selectById(id);
|
||||
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
||||
// 转换
|
||||
@@ -191,10 +191,10 @@ public class ${table.serviceImplName} implements ${table.serviceName} {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer batchDelete${type}ByIdList(List<Long> idList) {
|
||||
log.info("${type}Service-batchDelete${type}ByIdList idList: {}", idList);
|
||||
public Integer delete${type}ByIdList(List<Long> idList) {
|
||||
log.info("${type}Service-delete${type}ByIdList idList: {}", idList);
|
||||
int effect = ${typeLower}DAO.deleteBatchIds(idList);
|
||||
log.info("${type}Service-batchDelete${type}ByIdList effect: {}", effect);
|
||||
log.info("${type}Service-delete${type}ByIdList effect: {}", effect);
|
||||
#if($cacheMeta.enableCache)
|
||||
// 删除缓存
|
||||
RedisMaps.delete(${type}CacheKeyDefine.${typeConst}, idList);
|
||||
|
||||
@@ -106,7 +106,7 @@ public interface ${table.serviceName} {
|
||||
* @param idList idList
|
||||
* @return effect
|
||||
*/
|
||||
Integer batchDelete${type}ByIdList(List<Long> idList);
|
||||
Integer delete${type}ByIdList(List<Long> idList);
|
||||
|
||||
/**
|
||||
* ${apiComment.deleteAll}
|
||||
|
||||
@@ -137,12 +137,12 @@ public class ${type}ApiImpl implements ${type}Api {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer batchDelete${type}ByIdList(List<Long> idList) {
|
||||
log.info("${type}Api.batchDelete${type}ByIdList idList: {}", idList);
|
||||
public Integer delete${type}ByIdList(List<Long> idList) {
|
||||
log.info("${type}Api.delete${type}ByIdList idList: {}", idList);
|
||||
Valid.notEmpty(idList, ErrorMessage.ID_MISSING);
|
||||
// 删除
|
||||
Integer effect = ${typeLower}Service.batchDelete${type}ByIdList(idList);
|
||||
log.info("${type}Api.batchDelete${type}ByIdList effect: {}", effect);
|
||||
Integer effect = ${typeLower}Service.delete${type}ByIdList(idList);
|
||||
log.info("${type}Api.delete${type}ByIdList effect: {}", effect);
|
||||
return effect;
|
||||
}
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ public interface ${type}Api {
|
||||
* @param idList idList
|
||||
* @return effect
|
||||
*/
|
||||
Integer batchDelete${type}ByIdList(List<Long> idList);
|
||||
Integer delete${type}ByIdList(List<Long> idList);
|
||||
|
||||
/**
|
||||
* ${apiComment.deleteAll}
|
||||
|
||||
@@ -98,8 +98,8 @@ public class ${type}ApiImplTests extends BaseUnitTest {
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
public void batchDelete${type}ByIdListTest() {
|
||||
Integer effect = ${typeLower}Api.batchDelete${type}ByIdList(Lists.of(lastId));
|
||||
public void delete${type}ByIdListTest() {
|
||||
Integer effect = ${typeLower}Api.delete${type}ByIdList(Lists.of(lastId));
|
||||
assertEquals(effect, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -109,8 +109,8 @@ public class ${type}ServiceImplTests extends BaseUnitTest {
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
public void batchDelete${type}ByIdListTest() {
|
||||
Integer effect = ${typeLower}Service.batchDelete${type}ByIdList(Lists.of(lastId));
|
||||
public void delete${type}ByIdListTest() {
|
||||
Integer effect = ${typeLower}Service.delete${type}ByIdList(Lists.of(lastId));
|
||||
assertEquals(effect, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ public class DictKeyController {
|
||||
@Parameter(name = "idList", description = "idList", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('infra:dict-key:delete')")
|
||||
public Integer batchDeleteDictKey(@RequestParam("idList") List<Long> idList) {
|
||||
return dictKeyService.batchDeleteDictKeyByIdList(idList);
|
||||
return dictKeyService.deleteDictKeyByIdList(idList);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,32 +31,10 @@ Authorization: {{token}}
|
||||
}
|
||||
|
||||
|
||||
### 查询字典配置值
|
||||
GET {{baseUrl}}/infra/dict-value/get?id=1
|
||||
Authorization: {{token}}
|
||||
|
||||
|
||||
### 批量查询字典配置值
|
||||
GET {{baseUrl}}/infra/dict-value/batch-get?idList=1,2,3
|
||||
Authorization: {{token}}
|
||||
|
||||
|
||||
### 查询全部字典配置值
|
||||
POST {{baseUrl}}/infra/dict-value/list
|
||||
Content-Type: application/json
|
||||
POST {{baseUrl}}/infra/dict-value/list?key=
|
||||
Authorization: {{token}}
|
||||
|
||||
{
|
||||
"id": "",
|
||||
"keyId": "",
|
||||
"key": "",
|
||||
"label": "",
|
||||
"value": "",
|
||||
"desc": "",
|
||||
"extra": "",
|
||||
"sort": ""
|
||||
}
|
||||
|
||||
|
||||
### 分页查询字典配置值
|
||||
POST {{baseUrl}}/infra/dict-value/query
|
||||
@@ -66,14 +44,10 @@ Authorization: {{token}}
|
||||
{
|
||||
"page": 1,
|
||||
"limit": 10,
|
||||
"id": "",
|
||||
"keyId": "",
|
||||
"key": "",
|
||||
"label": "",
|
||||
"value": "",
|
||||
"desc": "",
|
||||
"extra": "",
|
||||
"sort": ""
|
||||
"desc": ""
|
||||
}
|
||||
|
||||
|
||||
@@ -87,21 +61,3 @@ DELETE {{baseUrl}}/infra/dict-value/batch-delete?idList=1,2,3
|
||||
Authorization: {{token}}
|
||||
|
||||
|
||||
### 导出字典配置值
|
||||
POST {{baseUrl}}/infra/dict-value/export
|
||||
Content-Type: application/json
|
||||
Authorization: {{token}}
|
||||
|
||||
{
|
||||
"id": "",
|
||||
"keyId": "",
|
||||
"key": "",
|
||||
"label": "",
|
||||
"value": "",
|
||||
"desc": "",
|
||||
"extra": "",
|
||||
"sort": ""
|
||||
}
|
||||
|
||||
|
||||
###
|
||||
|
||||
@@ -59,20 +59,10 @@ public class DictValueController {
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@GetMapping("/get")
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "查询字典配置值")
|
||||
@Parameter(name = "id", description = "id", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('infra:dict-value:query')")
|
||||
public DictValueVO getDictValue(@RequestParam("id") Long id) {
|
||||
return dictValueService.getDictValueById(id);
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@PostMapping("/list")
|
||||
@Operation(summary = "查询全部字典配置值")
|
||||
@PreAuthorize("@ss.hasPermission('infra:dict-value:query')")
|
||||
public List<DictValueVO> getDictValueList(@Validated @RequestBody DictValueQueryRequest request) {
|
||||
return dictValueService.getDictValueList(request);
|
||||
public List<DictValueVO> getDictValueList(@RequestParam("key") String key) {
|
||||
return dictValueService.getDictValueList(key);
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@@ -98,7 +88,7 @@ public class DictValueController {
|
||||
@Parameter(name = "idList", description = "idList", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('infra:dict-value:delete')")
|
||||
public Integer batchDeleteDictValue(@RequestParam("idList") List<Long> idList) {
|
||||
return dictValueService.batchDeleteDictValueByIdList(idList);
|
||||
return dictValueService.deleteDictValueByIdList(idList);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ public class DictKeyOperatorType extends InitializingOperatorTypes {
|
||||
@Override
|
||||
public OperatorType[] types() {
|
||||
return new OperatorType[]{
|
||||
// todo 添加参数
|
||||
new OperatorType(L, CREATE, "创建字典配置项"),
|
||||
new OperatorType(M, UPDATE, "更新字典配置项"),
|
||||
new OperatorType(H, DELETE, "删除字典配置项"),
|
||||
|
||||
@@ -20,11 +20,15 @@ public class DictValueOperatorType extends InitializingOperatorTypes {
|
||||
|
||||
public static final String UPDATE = "dict-value:update";
|
||||
|
||||
// todo 实现
|
||||
public static final String ROLLBACK = "dict-value:rollback";
|
||||
|
||||
public static final String DELETE = "dict-value:delete";
|
||||
|
||||
@Override
|
||||
public OperatorType[] types() {
|
||||
return new OperatorType[]{
|
||||
// todo 添加参数
|
||||
new OperatorType(L, CREATE, "创建字典配置值"),
|
||||
new OperatorType(M, UPDATE, "更新字典配置值"),
|
||||
new OperatorType(H, DELETE, "删除字典配置值"),
|
||||
|
||||
@@ -33,11 +33,6 @@ public class DictValueUpdateRequest implements Serializable {
|
||||
@Schema(description = "配置项id")
|
||||
private Long keyId;
|
||||
|
||||
@NotBlank
|
||||
@Size(max = 32)
|
||||
@Schema(description = "配置项")
|
||||
private String key;
|
||||
|
||||
@NotBlank
|
||||
@Size(max = 32)
|
||||
@Schema(description = "配置名称")
|
||||
|
||||
@@ -52,6 +52,6 @@ public interface DictKeyService {
|
||||
* @param idList idList
|
||||
* @return effect
|
||||
*/
|
||||
Integer batchDeleteDictKeyByIdList(List<Long> idList);
|
||||
Integer deleteDictKeyByIdList(List<Long> idList);
|
||||
|
||||
}
|
||||
|
||||
@@ -33,28 +33,13 @@ public interface DictValueService {
|
||||
*/
|
||||
Integer updateDictValueById(DictValueUpdateRequest request);
|
||||
|
||||
/**
|
||||
* 查询字典配置值
|
||||
*
|
||||
* @param id id
|
||||
* @return row
|
||||
*/
|
||||
DictValueVO getDictValueById(Long id);
|
||||
|
||||
/**
|
||||
* 查询全部字典配置值
|
||||
*
|
||||
* @param request request
|
||||
* @param key key
|
||||
* @return rows
|
||||
*/
|
||||
List<DictValueVO> getDictValueList(DictValueQueryRequest request);
|
||||
|
||||
/**
|
||||
* 通过缓存查询字典配置值
|
||||
*
|
||||
* @return rows
|
||||
*/
|
||||
List<DictValueVO> getDictValueListByCache();
|
||||
List<DictValueVO> getDictValueList(String key);
|
||||
|
||||
/**
|
||||
* 分页查询字典配置值
|
||||
@@ -65,7 +50,17 @@ public interface DictValueService {
|
||||
DataGrid<DictValueVO> getDictValuePage(DictValueQueryRequest request);
|
||||
|
||||
/**
|
||||
* 删除字典配置值
|
||||
* 通过 keyId 更新 keyName
|
||||
*
|
||||
* @param keyId keyId
|
||||
* @param beforeKey beforeKey
|
||||
* @param newKey newKey
|
||||
* @return effect
|
||||
*/
|
||||
Integer updateKeyNameByKeyId(Long keyId, String beforeKey, String newKey);
|
||||
|
||||
/**
|
||||
* 通过 id 删除字典配置值
|
||||
*
|
||||
* @param id id
|
||||
* @return effect
|
||||
@@ -73,11 +68,27 @@ public interface DictValueService {
|
||||
Integer deleteDictValueById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除字典配置值
|
||||
* 通过 id 批量删除字典配置值
|
||||
*
|
||||
* @param idList idList
|
||||
* @return effect
|
||||
*/
|
||||
Integer batchDeleteDictValueByIdList(List<Long> idList);
|
||||
Integer deleteDictValueByIdList(List<Long> idList);
|
||||
|
||||
/**
|
||||
* 通过 keyId 删除字典配置值
|
||||
*
|
||||
* @param keyId keyId
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteDictValueByKeyId(Long keyId);
|
||||
|
||||
/**
|
||||
* 通过 keyId 批量删除字典配置值
|
||||
*
|
||||
* @param keyIdList keyIdList
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteDictValueByKeyIdList(List<Long> keyIdList);
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.orion.ops.module.infra.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.orion.lang.utils.Objects1;
|
||||
import com.orion.ops.framework.common.constant.Const;
|
||||
import com.orion.ops.framework.common.constant.ErrorMessage;
|
||||
import com.orion.ops.framework.common.utils.Valid;
|
||||
@@ -15,8 +16,10 @@ import com.orion.ops.module.infra.entity.request.dict.DictKeyCreateRequest;
|
||||
import com.orion.ops.module.infra.entity.request.dict.DictKeyUpdateRequest;
|
||||
import com.orion.ops.module.infra.entity.vo.DictKeyVO;
|
||||
import com.orion.ops.module.infra.service.DictKeyService;
|
||||
import com.orion.ops.module.infra.service.DictValueService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Comparator;
|
||||
@@ -37,9 +40,12 @@ public class DictKeyServiceImpl implements DictKeyService {
|
||||
@Resource
|
||||
private DictKeyDAO dictKeyDAO;
|
||||
|
||||
@Resource
|
||||
private DictValueService dictValueService;
|
||||
|
||||
@Override
|
||||
public Long createDictKey(DictKeyCreateRequest request) {
|
||||
log.info("DictKeyService-createDictKey request: {}", JSON.toJSONString(request));
|
||||
log.info("DictKeyService-createDictKey request: {}" , JSON.toJSONString(request));
|
||||
// 转换
|
||||
DictKeyDO record = DictKeyConvert.MAPPER.to(request);
|
||||
// 查询数据是否冲突
|
||||
@@ -47,17 +53,18 @@ public class DictKeyServiceImpl implements DictKeyService {
|
||||
// 插入
|
||||
int effect = dictKeyDAO.insert(record);
|
||||
Long id = record.getId();
|
||||
log.info("DictKeyService-createDictKey id: {}, effect: {}", id, effect);
|
||||
log.info("DictKeyService-createDictKey id: {}, effect: {}" , id, effect);
|
||||
// 删除缓存
|
||||
RedisMaps.delete(DictCacheKeyDefine.DICT_KEY);
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Integer updateDictKeyById(DictKeyUpdateRequest request) {
|
||||
log.info("DictKeyService-updateDictKeyById id: {}, request: {}", request.getId(), JSON.toJSONString(request));
|
||||
// 查询
|
||||
Long id = Valid.notNull(request.getId(), ErrorMessage.ID_MISSING);
|
||||
log.info("DictKeyService-updateDictKeyById id: {}, request: {}" , id, JSON.toJSONString(request));
|
||||
// 查询
|
||||
DictKeyDO record = dictKeyDAO.selectById(id);
|
||||
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
||||
// 转换
|
||||
@@ -66,12 +73,13 @@ public class DictKeyServiceImpl implements DictKeyService {
|
||||
this.checkDictKeyPresent(updateRecord);
|
||||
// 更新
|
||||
int effect = dictKeyDAO.updateById(updateRecord);
|
||||
log.info("DictKeyService-updateDictKeyById effect: {}", effect);
|
||||
// 如果修改了 key 则需要修改 dictValue.key
|
||||
if (!Objects1.eq(record.getKey(), request.getKey())) {
|
||||
dictValueService.updateKeyNameByKeyId(id, record.getKey(), request.getKey());
|
||||
}
|
||||
// 删除缓存
|
||||
RedisMaps.delete(DictCacheKeyDefine.DICT_KEY);
|
||||
|
||||
// 修改 value 的 key
|
||||
|
||||
log.info("DictKeyService-updateDictKeyById effect: {}" , effect);
|
||||
return effect;
|
||||
}
|
||||
|
||||
@@ -96,29 +104,33 @@ public class DictKeyServiceImpl implements DictKeyService {
|
||||
return list.stream()
|
||||
.filter(s -> !s.getId().equals(Const.NONE_ID))
|
||||
.map(DictKeyConvert.MAPPER::to)
|
||||
.sorted(Comparator.comparing(DictKeyVO::getId).reversed())
|
||||
.sorted(Comparator.comparing(DictKeyVO::getKey))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteDictKeyById(Long id) {
|
||||
log.info("DictKeyService-deleteDictKeyById id: {}", id);
|
||||
log.info("DictKeyService-deleteDictKeyById id: {}" , id);
|
||||
// 检查数据是否存在
|
||||
DictKeyDO record = dictKeyDAO.selectById(id);
|
||||
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
||||
// 删除
|
||||
// 删除配置项
|
||||
int effect = dictKeyDAO.deleteById(id);
|
||||
log.info("DictKeyService-deleteDictKeyById id: {}, effect: {}", id, effect);
|
||||
// 删除配置值
|
||||
dictValueService.deleteDictValueByKeyId(id);
|
||||
// 删除缓存
|
||||
RedisMaps.delete(DictCacheKeyDefine.DICT_KEY, id);
|
||||
log.info("DictKeyService-deleteDictKeyById id: {}, effect: {}" , id, effect);
|
||||
return effect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer batchDeleteDictKeyByIdList(List<Long> idList) {
|
||||
log.info("DictKeyService-batchDeleteDictKeyByIdList idList: {}", idList);
|
||||
public Integer deleteDictKeyByIdList(List<Long> idList) {
|
||||
log.info("DictKeyService-deleteDictKeyByIdList idList: {}" , idList);
|
||||
int effect = dictKeyDAO.deleteBatchIds(idList);
|
||||
log.info("DictKeyService-batchDeleteDictKeyByIdList effect: {}", effect);
|
||||
// 删除配置值
|
||||
dictValueService.deleteDictValueByKeyIdList(idList);
|
||||
log.info("DictKeyService-deleteDictKeyByIdList effect: {}" , effect);
|
||||
// 删除缓存
|
||||
RedisMaps.delete(DictCacheKeyDefine.DICT_KEY, idList);
|
||||
return effect;
|
||||
|
||||
@@ -3,9 +3,11 @@ package com.orion.ops.module.infra.service.impl;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.orion.lang.define.wrapper.DataGrid;
|
||||
import com.orion.lang.utils.collect.Lists;
|
||||
import com.orion.ops.framework.common.constant.Const;
|
||||
import com.orion.ops.framework.common.constant.ErrorMessage;
|
||||
import com.orion.ops.framework.common.utils.Valid;
|
||||
import com.orion.ops.framework.mybatis.core.query.Conditions;
|
||||
import com.orion.ops.framework.redis.core.utils.RedisMaps;
|
||||
import com.orion.ops.module.infra.convert.DictValueConvert;
|
||||
import com.orion.ops.module.infra.dao.DictKeyDAO;
|
||||
@@ -17,12 +19,16 @@ import com.orion.ops.module.infra.entity.dto.DictValueCacheDTO;
|
||||
import com.orion.ops.module.infra.entity.request.dict.DictValueCreateRequest;
|
||||
import com.orion.ops.module.infra.entity.request.dict.DictValueQueryRequest;
|
||||
import com.orion.ops.module.infra.entity.request.dict.DictValueUpdateRequest;
|
||||
import com.orion.ops.module.infra.entity.request.history.HistoryValueCreateRequest;
|
||||
import com.orion.ops.module.infra.entity.vo.DictValueVO;
|
||||
import com.orion.ops.module.infra.enums.HistoryValueTypeEnum;
|
||||
import com.orion.ops.module.infra.service.DictValueService;
|
||||
import com.orion.ops.module.infra.service.HistoryValueService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -43,69 +49,77 @@ public class DictValueServiceImpl implements DictValueService {
|
||||
@Resource
|
||||
private DictValueDAO dictValueDAO;
|
||||
|
||||
@Resource
|
||||
private HistoryValueService historyValueService;
|
||||
|
||||
@Override
|
||||
public Long createDictValue(DictValueCreateRequest request) {
|
||||
log.info("DictValueService-createDictValue request: {}", JSON.toJSONString(request));
|
||||
log.info("DictValueService-createDictValue request: {}" , JSON.toJSONString(request));
|
||||
// 转换
|
||||
DictValueDO record = DictValueConvert.MAPPER.to(request);
|
||||
// 查询 key 是否存在
|
||||
DictKeyDO key = dictKeyDAO.selectById(request.getKeyId());
|
||||
Valid.notNull(key, ErrorMessage.CONFIG_ABSENT);
|
||||
String keyName = record.getKey();
|
||||
// 查询 dictKey 是否存在
|
||||
DictKeyDO dictKey = dictKeyDAO.selectById(request.getKeyId());
|
||||
String key = Valid.notNull(dictKey, ErrorMessage.CONFIG_ABSENT).getKey();
|
||||
// 查询数据是否冲突
|
||||
this.checkDictValuePresent(record);
|
||||
// 插入
|
||||
record.setKey(key);
|
||||
int effect = dictValueDAO.insert(record);
|
||||
Long id = record.getId();
|
||||
log.info("DictValueService-createDictValue id: {}, effect: {}", id, effect);
|
||||
log.info("DictValueService-createDictValue id: {}, effect: {}" , id, effect);
|
||||
// 删除缓存
|
||||
RedisMaps.delete(DictCacheKeyDefine.DICT_VALUE);
|
||||
RedisMaps.delete(DictCacheKeyDefine.DICT_VALUE.format(key));
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer updateDictValueById(DictValueUpdateRequest request) {
|
||||
log.info("DictValueService-updateDictValueById id: {}, request: {}", request.getId(), JSON.toJSONString(request));
|
||||
log.info("DictValueService-updateDictValueById id: {}, request: {}" , request.getId(), JSON.toJSONString(request));
|
||||
// 查询
|
||||
Long id = Valid.notNull(request.getId(), ErrorMessage.ID_MISSING);
|
||||
DictValueDO record = dictValueDAO.selectById(id);
|
||||
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
||||
// 查询 dictKey 是否存在
|
||||
DictKeyDO dictKey = dictKeyDAO.selectById(request.getKeyId());
|
||||
String key = Valid.notNull(dictKey, ErrorMessage.CONFIG_ABSENT).getKey();
|
||||
// 转换
|
||||
DictValueDO updateRecord = DictValueConvert.MAPPER.to(request);
|
||||
// 查询数据是否冲突
|
||||
this.checkDictValuePresent(updateRecord);
|
||||
// 更新
|
||||
updateRecord.setKey(key);
|
||||
int effect = dictValueDAO.updateById(updateRecord);
|
||||
log.info("DictValueService-updateDictValueById effect: {}", effect);
|
||||
log.info("DictValueService-updateDictValueById effect: {}" , effect);
|
||||
// 删除缓存
|
||||
RedisMaps.delete(DictCacheKeyDefine.DICT_VALUE);
|
||||
RedisMaps.delete(DictCacheKeyDefine.DICT_VALUE.format(key));
|
||||
// 检查值是否发生改变
|
||||
String beforeValue = record.getValue();
|
||||
String afterValue = request.getValue();
|
||||
if (!beforeValue.equals(afterValue)) {
|
||||
// 记录历史值
|
||||
HistoryValueCreateRequest historyRequest = new HistoryValueCreateRequest();
|
||||
historyRequest.setRelId(id);
|
||||
historyRequest.setType(HistoryValueTypeEnum.DICT.name());
|
||||
historyRequest.setBeforeValue(beforeValue);
|
||||
historyRequest.setAfterValue(afterValue);
|
||||
historyValueService.createHistoryValue(historyRequest);
|
||||
}
|
||||
return effect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DictValueVO getDictValueById(Long id) {
|
||||
// 查询
|
||||
DictValueDO record = dictValueDAO.selectById(id);
|
||||
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
||||
// 转换
|
||||
return DictValueConvert.MAPPER.to(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DictValueVO> getDictValueList(DictValueQueryRequest request) {
|
||||
// 条件
|
||||
LambdaQueryWrapper<DictValueDO> wrapper = this.buildQueryWrapper(request);
|
||||
// 查询
|
||||
return dictValueDAO.of(wrapper).list(DictValueConvert.MAPPER::to);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DictValueVO> getDictValueListByCache() {
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<DictValueVO> getDictValueList(String key) {
|
||||
// 查询缓存
|
||||
List<DictValueCacheDTO> list = RedisMaps.valuesJson(DictCacheKeyDefine.DICT_VALUE);
|
||||
String cacheKey = DictCacheKeyDefine.DICT_VALUE.format(key);
|
||||
List<DictValueCacheDTO> list = RedisMaps.valuesJson(cacheKey, (Class<DictValueCacheDTO>) DictCacheKeyDefine.DICT_VALUE.getType());
|
||||
if (list.isEmpty()) {
|
||||
// 查询数据库
|
||||
list = dictValueDAO.of().list(DictValueConvert.MAPPER::toCache);
|
||||
list = dictValueDAO.of()
|
||||
.createWrapper()
|
||||
.eq(DictValueDO::getKey, key)
|
||||
.then()
|
||||
.list(DictValueConvert.MAPPER::toCache);
|
||||
// 添加默认值 防止穿透
|
||||
if (list.isEmpty()) {
|
||||
list.add(DictValueCacheDTO.builder()
|
||||
@@ -113,13 +127,14 @@ public class DictValueServiceImpl implements DictValueService {
|
||||
.build());
|
||||
}
|
||||
// 设置缓存
|
||||
RedisMaps.putAllJson(DictCacheKeyDefine.DICT_VALUE.getKey(), s -> s.getId().toString(), list);
|
||||
RedisMaps.setExpire(DictCacheKeyDefine.DICT_VALUE);
|
||||
RedisMaps.putAllJson(cacheKey, s -> s.getId().toString(), list);
|
||||
RedisMaps.setExpire(cacheKey, DictCacheKeyDefine.DICT_VALUE);
|
||||
}
|
||||
// 删除默认值
|
||||
return list.stream()
|
||||
.filter(s -> !s.getId().equals(Const.NONE_ID))
|
||||
.map(DictValueConvert.MAPPER::to)
|
||||
.sorted(Comparator.comparing(DictValueVO::getSort))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -134,26 +149,84 @@ public class DictValueServiceImpl implements DictValueService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteDictValueById(Long id) {
|
||||
log.info("DictValueService-deleteDictValueById id: {}", id);
|
||||
// 检查数据是否存在
|
||||
DictValueDO record = dictValueDAO.selectById(id);
|
||||
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
||||
// 删除
|
||||
int effect = dictValueDAO.deleteById(id);
|
||||
log.info("DictValueService-deleteDictValueById id: {}, effect: {}", id, effect);
|
||||
public Integer updateKeyNameByKeyId(Long keyId, String beforeKey, String newKey) {
|
||||
// 修改数据库
|
||||
DictValueDO updateRecord = new DictValueDO();
|
||||
updateRecord.setKey(newKey);
|
||||
LambdaQueryWrapper<DictValueDO> wrapper = dictValueDAO.lambda()
|
||||
.eq(DictValueDO::getKeyId, beforeKey);
|
||||
int effect = dictValueDAO.update(updateRecord, wrapper);
|
||||
// 删除缓存
|
||||
RedisMaps.delete(DictCacheKeyDefine.DICT_VALUE, id);
|
||||
String beforeCacheKey = DictCacheKeyDefine.DICT_VALUE.format(beforeKey);
|
||||
String newCacheKey = DictCacheKeyDefine.DICT_VALUE.format(newKey);
|
||||
RedisMaps.delete(beforeCacheKey, newCacheKey);
|
||||
return effect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer batchDeleteDictValueByIdList(List<Long> idList) {
|
||||
log.info("DictValueService-batchDeleteDictValueByIdList idList: {}", idList);
|
||||
public Integer deleteDictValueById(Long id) {
|
||||
log.info("DictValueService-deleteDictValueById id: {}" , id);
|
||||
// 检查数据是否存在
|
||||
DictValueDO record = dictValueDAO.selectById(id);
|
||||
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
||||
// 删除
|
||||
return this.deleteDictValue(Lists.singleton(id), Lists.singleton(record));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteDictValueByIdList(List<Long> idList) {
|
||||
log.info("DictValueService-deleteDictValueByIdList idList: {}" , idList);
|
||||
// 查询数据
|
||||
List<DictValueDO> records = dictValueDAO.selectBatchIds(idList);
|
||||
// 删除
|
||||
return this.deleteDictValue(idList, records);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteDictValueByKeyId(Long keyId) {
|
||||
log.info("DictValueService-deleteDictValueByKeyId keyId: {}" , keyId);
|
||||
// 查询数据
|
||||
List<DictValueDO> records = dictValueDAO.selectList(Conditions.eq(DictValueDO::getKeyId, keyId));
|
||||
// 删除
|
||||
List<Long> idList = records.stream()
|
||||
.map(DictValueDO::getId)
|
||||
.collect(Collectors.toList());
|
||||
return this.deleteDictValue(idList, records);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteDictValueByKeyIdList(List<Long> keyIdList) {
|
||||
log.info("DictValueService-deleteDictValueByKeyIdList keyIdList: {}" , keyIdList);
|
||||
// 查询数据
|
||||
List<DictValueDO> records = dictValueDAO.selectList(Conditions.in(DictValueDO::getKeyId, keyIdList));
|
||||
// 删除
|
||||
List<Long> idList = records.stream()
|
||||
.map(DictValueDO::getId)
|
||||
.collect(Collectors.toList());
|
||||
return this.deleteDictValue(idList, records);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除字典配置项
|
||||
*
|
||||
* @param idList idList
|
||||
* @param records records
|
||||
* @return effect
|
||||
*/
|
||||
private int deleteDictValue(List<Long> idList, List<DictValueDO> records) {
|
||||
if (records.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
// 删除
|
||||
int effect = dictValueDAO.deleteBatchIds(idList);
|
||||
log.info("DictValueService-batchDeleteDictValueByIdList effect: {}", effect);
|
||||
log.info("DictValueService-deleteDictValue effect: {}" , effect);
|
||||
// 删除缓存
|
||||
RedisMaps.delete(DictCacheKeyDefine.DICT_VALUE, idList);
|
||||
List<String> keyList = records.stream()
|
||||
.map(DictValueDO::getKey)
|
||||
.distinct()
|
||||
.map(DictCacheKeyDefine.DICT_VALUE::format)
|
||||
.collect(Collectors.toList());
|
||||
RedisMaps.delete(keyList);
|
||||
return effect;
|
||||
}
|
||||
|
||||
@@ -184,9 +257,10 @@ public class DictValueServiceImpl implements DictValueService {
|
||||
private LambdaQueryWrapper<DictValueDO> buildQueryWrapper(DictValueQueryRequest request) {
|
||||
return dictValueDAO.wrapper()
|
||||
.eq(DictValueDO::getKeyId, request.getKeyId())
|
||||
.eq(DictValueDO::getLabel, request.getLabel())
|
||||
.eq(DictValueDO::getValue, request.getValue())
|
||||
.eq(DictValueDO::getDesc, request.getDesc());
|
||||
.like(DictValueDO::getLabel, request.getLabel())
|
||||
.like(DictValueDO::getValue, request.getValue())
|
||||
.like(DictValueDO::getDesc, request.getDesc())
|
||||
.orderByDesc(DictValueDO::getId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user