feature: tag功能.
This commit is contained in:
@@ -28,4 +28,6 @@ public class Const implements com.orion.lang.constant.Const {
|
|||||||
|
|
||||||
public static final Integer DEFAULT_SORT = 10;
|
public static final Integer DEFAULT_SORT = 10;
|
||||||
|
|
||||||
|
public static final Long NONE_ID = -1L;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* redis 工具类
|
* redis 工具类
|
||||||
@@ -23,6 +24,7 @@ import java.util.function.Function;
|
|||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
* @since 2021/11/6 11:09
|
* @since 2021/11/6 11:09
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public class RedisUtils {
|
public class RedisUtils {
|
||||||
|
|
||||||
private static RedisTemplate<String, String> redisTemplate;
|
private static RedisTemplate<String, String> redisTemplate;
|
||||||
@@ -80,7 +82,6 @@ public class RedisUtils {
|
|||||||
* @param processor processor
|
* @param processor processor
|
||||||
* @param <T> type
|
* @param <T> type
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static <T> void processSetJson(String key, CacheKeyDefine define, Consumer<T> processor) {
|
public static <T> void processSetJson(String key, CacheKeyDefine define, Consumer<T> processor) {
|
||||||
String value = redisTemplate.opsForValue().get(key);
|
String value = redisTemplate.opsForValue().get(key);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
@@ -167,6 +168,24 @@ public class RedisUtils {
|
|||||||
return Lists.map(elements, mapper);
|
return Lists.map(elements, mapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询 list 区间
|
||||||
|
*
|
||||||
|
* @param key key
|
||||||
|
* @param define define
|
||||||
|
* @return list
|
||||||
|
*/
|
||||||
|
public static <T> List<T> listRangeJson(String key, CacheKeyDefine define) {
|
||||||
|
// 查询列表
|
||||||
|
List<String> elements = redisTemplate.opsForList().range(key, 0, -1);
|
||||||
|
if (elements == null) {
|
||||||
|
return Lists.newList();
|
||||||
|
}
|
||||||
|
return (List<T>) elements.stream()
|
||||||
|
.map(s -> JSON.parseObject(s, define.getType()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* list 添加元素
|
* list 添加元素
|
||||||
*
|
*
|
||||||
@@ -179,6 +198,66 @@ public class RedisUtils {
|
|||||||
redisTemplate.opsForList().rightPushAll(key, Lists.map(list, mapper));
|
redisTemplate.opsForList().rightPushAll(key, Lists.map(list, mapper));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* list 添加元素
|
||||||
|
*
|
||||||
|
* @param key key
|
||||||
|
* @param list list
|
||||||
|
* @param <T> T
|
||||||
|
*/
|
||||||
|
public static <T> void listPushAllJson(String key, List<T> list) {
|
||||||
|
List<String> values = list.stream()
|
||||||
|
.map(JSON::toJSONString)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
redisTemplate.opsForList().rightPushAll(key, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* list 添加元素
|
||||||
|
*
|
||||||
|
* @param key key
|
||||||
|
* @param value value
|
||||||
|
* @param mapper mapper
|
||||||
|
* @param <T> T
|
||||||
|
*/
|
||||||
|
public static <T> void listPush(String key, T value, Function<T, String> mapper) {
|
||||||
|
redisTemplate.opsForList().rightPush(key, mapper.apply(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* list 添加元素
|
||||||
|
*
|
||||||
|
* @param key key
|
||||||
|
* @param value value
|
||||||
|
* @param <T> T
|
||||||
|
*/
|
||||||
|
public static <T> void listPushJson(String key, T value) {
|
||||||
|
redisTemplate.opsForList().rightPush(key, JSON.toJSONString(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* list 删除元素
|
||||||
|
*
|
||||||
|
* @param key key
|
||||||
|
* @param value value
|
||||||
|
* @param mapper mapper
|
||||||
|
* @param <T> T
|
||||||
|
*/
|
||||||
|
public static <T> void listRemove(String key, T value, Function<T, String> mapper) {
|
||||||
|
redisTemplate.opsForList().remove(key, 1, mapper.apply(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* list 删除元素
|
||||||
|
*
|
||||||
|
* @param key key
|
||||||
|
* @param value value
|
||||||
|
* @param <T> T
|
||||||
|
*/
|
||||||
|
public static <T> void listRemoveJson(String key, T value) {
|
||||||
|
redisTemplate.opsForList().remove(key, 1, JSON.toJSONString(value));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置过期时间
|
* 设置过期时间
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public class CodeGenerator {
|
|||||||
// new GenTable("system_user", "用户", "user")
|
// new GenTable("system_user", "用户", "user")
|
||||||
// .vue("user", "user")
|
// .vue("user", "user")
|
||||||
// .enums(UserStatusEnum.class),
|
// .enums(UserStatusEnum.class),
|
||||||
new GenTable("favorite", "收藏", "favorite"),
|
new GenTable("tag", "标签枚举", "tag"),
|
||||||
};
|
};
|
||||||
// jdbc 配置 - 使用配置文件
|
// jdbc 配置 - 使用配置文件
|
||||||
File yamlFile = new File("orion-ops-launch/src/main/resources/application-dev.yaml");
|
File yamlFile = new File("orion-ops-launch/src/main/resources/application-dev.yaml");
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public class ${table.controllerName} {
|
|||||||
@PutMapping("/update")
|
@PutMapping("/update")
|
||||||
@Operation(summary = "${apiComment.updateById}")
|
@Operation(summary = "${apiComment.updateById}")
|
||||||
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:update')")
|
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:update')")
|
||||||
public Integer update${type}(@Validated @RequestBody(Id.class) ${type}UpdateRequest request) {
|
public Integer update${type}(@Validated(Id.class) @RequestBody ${type}UpdateRequest request) {
|
||||||
return ${typeLower}Service.update${type}ById(request);
|
return ${typeLower}Service.update${type}ById(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public interface ${type}Convert {
|
|||||||
|
|
||||||
${type}VO to(${type}DO domain);
|
${type}VO to(${type}DO domain);
|
||||||
|
|
||||||
${type}Export export(${type}DO domain);
|
${type}Export toExport(${type}DO domain);
|
||||||
|
|
||||||
List<${type}VO> to(List<${type}DO> list);
|
List<${type}VO> to(List<${type}DO> list);
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package ${package.Mapper};
|
package ${package.Mapper};
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import ${package.Entity}.${entity};
|
|
||||||
import ${superMapperClassPackage};
|
import ${superMapperClassPackage};
|
||||||
|
import ${package.Entity}.${entity};
|
||||||
#if(${mapperAnnotationClass})
|
#if(${mapperAnnotationClass})
|
||||||
import ${mapperAnnotationClass.name};
|
import ${mapperAnnotationClass.name};
|
||||||
#end
|
#end
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ public class ${table.serviceImplName} implements ${table.serviceName} {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long create${type}(${type}CreateRequest request) {
|
public Long create${type}(${type}CreateRequest request) {
|
||||||
|
log.info("${type}Service-create${type} record: {}", JSON.toJSONString(record));
|
||||||
// 转换
|
// 转换
|
||||||
${type}DO record = ${type}Convert.MAPPER.to(request);
|
${type}DO record = ${type}Convert.MAPPER.to(request);
|
||||||
record.setId(null);
|
record.setId(null);
|
||||||
@@ -48,12 +49,13 @@ public class ${table.serviceImplName} implements ${table.serviceName} {
|
|||||||
this.check${type}Present(record);
|
this.check${type}Present(record);
|
||||||
// 插入
|
// 插入
|
||||||
int effect = ${typeLower}DAO.insert(record);
|
int effect = ${typeLower}DAO.insert(record);
|
||||||
log.info("${type}Service-create${type} effect: {}, record: {}", effect, JSON.toJSONString(record));
|
log.info("${type}Service-create${type} effect: {}", effect);
|
||||||
return record.getId();
|
return record.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer update${type}ById(${type}UpdateRequest request) {
|
public Integer update${type}ById(${type}UpdateRequest request) {
|
||||||
|
log.info("${type}Service-update${type}ById updateRecord: {}", JSON.toJSONString(updateRecord));
|
||||||
// 查询
|
// 查询
|
||||||
Long id = Valid.notNull(request.getId(), ErrorMessage.ID_MISSING);
|
Long id = Valid.notNull(request.getId(), ErrorMessage.ID_MISSING);
|
||||||
${type}DO record = ${typeLower}DAO.selectById(id);
|
${type}DO record = ${typeLower}DAO.selectById(id);
|
||||||
@@ -64,7 +66,7 @@ public class ${table.serviceImplName} implements ${table.serviceName} {
|
|||||||
this.check${type}Present(updateRecord);
|
this.check${type}Present(updateRecord);
|
||||||
// 更新
|
// 更新
|
||||||
int effect = ${typeLower}DAO.updateById(updateRecord);
|
int effect = ${typeLower}DAO.updateById(updateRecord);
|
||||||
log.info("${type}Service-update${type}ById effect: {}, updateRecord: {}", effect, JSON.toJSONString(updateRecord));
|
log.info("${type}Service-update${type}ById effect: {}", effect);
|
||||||
return effect;
|
return effect;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,15 +134,17 @@ public class ${table.serviceImplName} implements ${table.serviceName} {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer delete${type}ById(Long id) {
|
public Integer delete${type}ById(Long id) {
|
||||||
|
log.info("${type}Service-delete${type}ById id: {}", id);
|
||||||
int effect = ${typeLower}DAO.deleteById(id);
|
int effect = ${typeLower}DAO.deleteById(id);
|
||||||
log.info("${type}Service-delete${type}ById id: {}, effect: {}", id, effect);
|
log.info("${type}Service-delete${type}ById effect: {}", effect);
|
||||||
return effect;
|
return effect;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer batchDelete${type}ByIdList(List<Long> idList) {
|
public Integer batchDelete${type}ByIdList(List<Long> idList) {
|
||||||
|
log.info("${type}Service-batchDelete${type}ByIdList idList: {}", idList);
|
||||||
int effect = ${typeLower}DAO.deleteBatchIds(idList);
|
int effect = ${typeLower}DAO.deleteBatchIds(idList);
|
||||||
log.info("${type}Service-batchDelete${type}ByIdList idList: {}, effect: {}", idList, effect);
|
log.info("${type}Service-batchDelete${type}ByIdList effect: {}", effect);
|
||||||
return effect;
|
return effect;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,12 +161,14 @@ public class ${table.serviceImplName} implements ${table.serviceName} {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void export${type}(${type}QueryRequest request, HttpServletResponse response) throws IOException {
|
public void export${type}(${type}QueryRequest request, HttpServletResponse response) throws IOException {
|
||||||
|
log.info("${type}Service.export${type} request: {}", JSON.toJSONString(request));
|
||||||
// 条件
|
// 条件
|
||||||
LambdaQueryWrapper<${type}DO> wrapper = this.buildQueryWrapper(request);
|
LambdaQueryWrapper<${type}DO> wrapper = this.buildQueryWrapper(request);
|
||||||
// 查询
|
// 查询
|
||||||
List<${type}Export> rows = ${typeLower}DAO.of()
|
List<${type}Export> rows = ${typeLower}DAO.of()
|
||||||
.wrapper(wrapper)
|
.wrapper(wrapper)
|
||||||
.list(${type}Convert.MAPPER::export);
|
.list(${type}Convert.MAPPER::toExport);
|
||||||
|
log.info("${type}Service.export${type} size: {}", rows.size());
|
||||||
// 导出
|
// 导出
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
ExcelExport.create(${type}Export.class)
|
ExcelExport.create(${type}Export.class)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package ${package.ServiceImpl};
|
package ${currentPackage};
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
@@ -126,7 +126,9 @@ public class ${type}ApiImpl implements ${type}Api {
|
|||||||
log.info("${type}Api.delete${type}ById id: {}", id);
|
log.info("${type}Api.delete${type}ById id: {}", id);
|
||||||
Valid.notNull(id, ErrorMessage.ID_MISSING);
|
Valid.notNull(id, ErrorMessage.ID_MISSING);
|
||||||
// 删除
|
// 删除
|
||||||
return ${typeLower}DAO.deleteById(id);
|
int effect = ${typeLower}DAO.deleteById(id);
|
||||||
|
log.info("${type}Api.delete${type}ById effect: {}", effect);
|
||||||
|
return effect;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -134,7 +136,9 @@ public class ${type}ApiImpl implements ${type}Api {
|
|||||||
log.info("${type}Api.batchDelete${type}ByIdList idList: {}", idList);
|
log.info("${type}Api.batchDelete${type}ByIdList idList: {}", idList);
|
||||||
Valid.notEmpty(idList, ErrorMessage.ID_MISSING);
|
Valid.notEmpty(idList, ErrorMessage.ID_MISSING);
|
||||||
// 删除
|
// 删除
|
||||||
return ${typeLower}DAO.deleteBatchIds(idList);
|
int effect = ${typeLower}DAO.deleteBatchIds(idList);
|
||||||
|
log.info("${type}Api.batchDelete${type}ByIdList effect: {}", effect);
|
||||||
|
return effect;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -144,7 +148,9 @@ public class ${type}ApiImpl implements ${type}Api {
|
|||||||
// 条件
|
// 条件
|
||||||
LambdaQueryWrapper<${type}DO> wrapper = this.buildQueryWrapper(dto);
|
LambdaQueryWrapper<${type}DO> wrapper = this.buildQueryWrapper(dto);
|
||||||
// 删除
|
// 删除
|
||||||
return ${typeLower}DAO.delete(wrapper);
|
int effect = ${typeLower}DAO.delete(wrapper);
|
||||||
|
log.info("${type}Api.delete${type} effect: {}", effect);
|
||||||
|
return effect;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package ${currentPackage};
|
package ${currentPackage};
|
||||||
|
|
||||||
import com.orion.lang.define.wrapper.DataGrid;
|
|
||||||
import com.orion.lang.utils.collect.Lists;
|
import com.orion.lang.utils.collect.Lists;
|
||||||
import com.orion.ops.framework.test.core.base.BaseUnitTest;
|
import com.orion.ops.framework.test.core.base.BaseUnitTest;
|
||||||
import com.orion.ops.framework.test.core.utils.EntityRandoms;
|
import com.orion.ops.framework.test.core.utils.EntityRandoms;
|
||||||
@@ -53,44 +52,63 @@ public class ${type}ApiImplTests extends BaseUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(3)
|
@Order(3)
|
||||||
|
public void update${type}Test() {
|
||||||
|
${type}QueryDTO query = new ${type}QueryDTO();
|
||||||
|
query.setId(lastId);
|
||||||
|
${type}UpdateDTO req = EntityRandoms.random(${type}UpdateDTO.class);
|
||||||
|
req.setId(null);
|
||||||
|
Integer effect = ${typeLower}Api.update${type}(query, req);
|
||||||
|
assertEquals(effect, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(4)
|
||||||
public void get${type}ByIdTest() {
|
public void get${type}ByIdTest() {
|
||||||
${type}DTO row = ${typeLower}Api.get${type}ById(lastId);
|
${type}DTO row = ${typeLower}Api.get${type}ById(lastId);
|
||||||
assertNotNull(row);
|
assertNotNull(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(4)
|
@Order(5)
|
||||||
public void get${type}ByIdListTest() {
|
public void get${type}ByIdListTest() {
|
||||||
List<${type}DTO> rows = ${typeLower}Api.get${type}ByIdList(Lists.of(lastId));
|
List<${type}DTO> rows = ${typeLower}Api.get${type}ByIdList(Lists.of(lastId));
|
||||||
assertFalse(rows.isEmpty());
|
assertFalse(rows.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(5)
|
@Order(6)
|
||||||
public void get${type}ListTest() {
|
public void get${type}ListTest() {
|
||||||
List<${type}DTO> rows = ${typeLower}Api.get${type}List(new ${type}QueryDTO());
|
List<${type}DTO> rows = ${typeLower}Api.get${type}List(new ${type}QueryDTO());
|
||||||
assertFalse(rows.isEmpty());
|
assertFalse(rows.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(6)
|
@Order(7)
|
||||||
public void get${type}CountTest() {
|
public void get${type}CountTest() {
|
||||||
Long count = ${typeLower}Api.get${type}Count(new ${type}QueryDTO());
|
Long count = ${typeLower}Api.get${type}Count(new ${type}QueryDTO());
|
||||||
assertEquals(count, 1L);
|
assertEquals(count, 1L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(7)
|
@Order(8)
|
||||||
public void delete${type}ByIdTest() {
|
public void delete${type}ByIdTest() {
|
||||||
Integer effect = ${typeLower}Api.delete${type}ById(lastId);
|
Integer effect = ${typeLower}Api.delete${type}ById(lastId);
|
||||||
assertEquals(effect, 1);
|
assertEquals(effect, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(8)
|
@Order(9)
|
||||||
public void batchDelete${type}ByIdListTest() {
|
public void batchDelete${type}ByIdListTest() {
|
||||||
Integer effect = ${typeLower}Api.batchDelete${type}ByIdList(Lists.of(lastId));
|
Integer effect = ${typeLower}Api.batchDelete${type}ByIdList(Lists.of(lastId));
|
||||||
assertEquals(effect, 0);
|
assertEquals(effect, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(10)
|
||||||
|
public void delete${type}Test() {
|
||||||
|
${type}QueryDTO dto = new ${type}QueryDTO();
|
||||||
|
Integer effect = ${typeLower}Api.delete${type}(dto);
|
||||||
|
assertEquals(effect, 0);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,34 +53,45 @@ public class ${type}ServiceImplTests extends BaseUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(3)
|
@Order(3)
|
||||||
|
public void update${type}Test() {
|
||||||
|
${type}QueryRequest query = new ${type}QueryRequest();
|
||||||
|
query.setId(lastId);
|
||||||
|
${type}UpdateRequest req = EntityRandoms.random(${type}UpdateRequest.class);
|
||||||
|
req.setId(null);
|
||||||
|
Integer effect = ${typeLower}Service.update${type}(query, req);
|
||||||
|
assertEquals(effect, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(4)
|
||||||
public void get${type}ByIdTest() {
|
public void get${type}ByIdTest() {
|
||||||
${type}VO row = ${typeLower}Service.get${type}ById(lastId);
|
${type}VO row = ${typeLower}Service.get${type}ById(lastId);
|
||||||
assertNotNull(row);
|
assertNotNull(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(4)
|
@Order(5)
|
||||||
public void get${type}ByIdListTest() {
|
public void get${type}ByIdListTest() {
|
||||||
List<${type}VO> rows = ${typeLower}Service.get${type}ByIdList(Lists.of(lastId));
|
List<${type}VO> rows = ${typeLower}Service.get${type}ByIdList(Lists.of(lastId));
|
||||||
assertFalse(rows.isEmpty());
|
assertFalse(rows.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(5)
|
@Order(6)
|
||||||
public void get${type}ListTest() {
|
public void get${type}ListTest() {
|
||||||
List<${type}VO> rows = ${typeLower}Service.get${type}List(new ${type}QueryRequest());
|
List<${type}VO> rows = ${typeLower}Service.get${type}List(new ${type}QueryRequest());
|
||||||
assertFalse(rows.isEmpty());
|
assertFalse(rows.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(6)
|
@Order(7)
|
||||||
public void get${type}CountTest() {
|
public void get${type}CountTest() {
|
||||||
Long count = ${typeLower}Service.get${type}Count(new ${type}QueryRequest());
|
Long count = ${typeLower}Service.get${type}Count(new ${type}QueryRequest());
|
||||||
assertEquals(count, 1L);
|
assertEquals(count, 1L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(7)
|
@Order(8)
|
||||||
public void get${type}PageTest() {
|
public void get${type}PageTest() {
|
||||||
${type}QueryRequest request = new ${type}QueryRequest();
|
${type}QueryRequest request = new ${type}QueryRequest();
|
||||||
request.setPage(1);
|
request.setPage(1);
|
||||||
@@ -90,17 +101,25 @@ public class ${type}ServiceImplTests extends BaseUnitTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(8)
|
@Order(9)
|
||||||
public void delete${type}ByIdTest() {
|
public void delete${type}ByIdTest() {
|
||||||
Integer effect = ${typeLower}Service.delete${type}ById(lastId);
|
Integer effect = ${typeLower}Service.delete${type}ById(lastId);
|
||||||
assertEquals(effect, 1);
|
assertEquals(effect, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(9)
|
@Order(10)
|
||||||
public void batchDelete${type}ByIdListTest() {
|
public void batchDelete${type}ByIdListTest() {
|
||||||
Integer effect = ${typeLower}Service.batchDelete${type}ByIdList(Lists.of(lastId));
|
Integer effect = ${typeLower}Service.batchDelete${type}ByIdList(Lists.of(lastId));
|
||||||
assertEquals(effect, 0);
|
assertEquals(effect, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(11)
|
||||||
|
public void delete${type}Test() {
|
||||||
|
${type}QueryRequest query = new ${type}QueryRequest();
|
||||||
|
Integer effect = ${typeLower}Service.delete${type}(query);
|
||||||
|
assertEquals(effect, 0);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,17 +69,17 @@ public class FavoriteApiImpl implements FavoriteApi {
|
|||||||
request.setUserId(userId);
|
request.setUserId(userId);
|
||||||
request.setType(typeName);
|
request.setType(typeName);
|
||||||
cacheRelIdList = favoriteService.getFavoriteRelIdList(request);
|
cacheRelIdList = favoriteService.getFavoriteRelIdList(request);
|
||||||
// 设置 -1 到缓存防止穿透
|
// 添加默认值 防止穿透
|
||||||
if (cacheRelIdList.isEmpty()) {
|
if (cacheRelIdList.isEmpty()) {
|
||||||
cacheRelIdList.add(Const.L_N_1);
|
cacheRelIdList.add(Const.NONE_ID);
|
||||||
}
|
}
|
||||||
// 设置缓存
|
// 设置缓存
|
||||||
RedisUtils.listPushAll(key, cacheRelIdList, String::valueOf);
|
RedisUtils.listPushAll(key, cacheRelIdList, String::valueOf);
|
||||||
// 设置过期时间
|
// 设置过期时间
|
||||||
RedisUtils.setExpire(key, FavoriteCacheKeyDefine.FAVORITE);
|
RedisUtils.setExpire(key, FavoriteCacheKeyDefine.FAVORITE);
|
||||||
}
|
}
|
||||||
// 尝试删除防止穿透的 key
|
// 删除防止穿透的 key
|
||||||
cacheRelIdList.remove(Const.L_N_1);
|
cacheRelIdList.remove(Const.NONE_ID);
|
||||||
return CompletableFuture.completedFuture(cacheRelIdList);
|
return CompletableFuture.completedFuture(cacheRelIdList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
### 创建标签枚举
|
||||||
|
POST {{baseUrl}}/infra/tag/create
|
||||||
|
Content-Type: application/json
|
||||||
|
Authorization: {{token}}
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "TAG1",
|
||||||
|
"type": "HOST"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
### 查询标签枚举
|
||||||
|
GET {{baseUrl}}/infra/tag/list?type=HOST
|
||||||
|
Content-Type: application/json
|
||||||
|
Authorization: {{token}}
|
||||||
|
|
||||||
|
|
||||||
|
### 通过 id 删除标签枚举
|
||||||
|
DELETE {{baseUrl}}/infra/tag/delete?id=2
|
||||||
|
Authorization: {{token}}
|
||||||
|
|
||||||
|
|
||||||
|
###
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package com.orion.ops.module.infra.controller;
|
||||||
|
|
||||||
|
import com.orion.ops.framework.common.annotation.IgnoreLog;
|
||||||
|
import com.orion.ops.framework.common.annotation.RestWrapper;
|
||||||
|
import com.orion.ops.framework.common.constant.IgnoreLogMode;
|
||||||
|
import com.orion.ops.module.infra.entity.request.tag.TagCreateRequest;
|
||||||
|
import com.orion.ops.module.infra.entity.vo.TagVO;
|
||||||
|
import com.orion.ops.module.infra.service.TagService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签枚举 api
|
||||||
|
*
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 2023-9-5 11:58
|
||||||
|
*/
|
||||||
|
@Tag(name = "infra - 标签枚举服务")
|
||||||
|
@Slf4j
|
||||||
|
@Validated
|
||||||
|
@RestWrapper
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/infra/tag")
|
||||||
|
@SuppressWarnings({"ELValidationInJSP", "SpringElInspection"})
|
||||||
|
public class TagController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TagService tagService;
|
||||||
|
|
||||||
|
@PostMapping("/create")
|
||||||
|
@Operation(summary = "创建标签枚举")
|
||||||
|
@PreAuthorize("@ss.hasPermission('infra:tag:create')")
|
||||||
|
public Long createTag(@Validated @RequestBody TagCreateRequest request) {
|
||||||
|
return tagService.createTag(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@IgnoreLog(IgnoreLogMode.RET)
|
||||||
|
@GetMapping("/list")
|
||||||
|
@Operation(summary = "查询标签枚举")
|
||||||
|
@Parameter(name = "type", description = "type", required = true)
|
||||||
|
@PreAuthorize("@ss.hasPermission('infra:tag:query')")
|
||||||
|
public List<TagVO> getTagListAll(@RequestParam("type") String type) {
|
||||||
|
return tagService.getTagList(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/delete")
|
||||||
|
@Operation(summary = "通过 id 删除标签枚举")
|
||||||
|
@Parameter(name = "id", description = "id", required = true)
|
||||||
|
@PreAuthorize("@ss.hasPermission('infra:tag:delete')")
|
||||||
|
public Integer deleteTag(@RequestParam("id") Long id) {
|
||||||
|
return tagService.deleteTagById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package com.orion.ops.module.infra.convert;
|
||||||
|
|
||||||
|
import com.orion.ops.module.infra.entity.domain.TagDO;
|
||||||
|
import com.orion.ops.module.infra.entity.dto.TagCacheDTO;
|
||||||
|
import com.orion.ops.module.infra.entity.request.tag.TagCreateRequest;
|
||||||
|
import com.orion.ops.module.infra.entity.request.tag.TagQueryRequest;
|
||||||
|
import com.orion.ops.module.infra.entity.vo.TagVO;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签枚举 内部对象转换器
|
||||||
|
*
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 2023-9-5 11:58
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface TagConvert {
|
||||||
|
|
||||||
|
TagConvert MAPPER = Mappers.getMapper(TagConvert.class);
|
||||||
|
|
||||||
|
TagDO to(TagCreateRequest request);
|
||||||
|
|
||||||
|
TagDO to(TagQueryRequest request);
|
||||||
|
|
||||||
|
TagVO to(TagDO domain);
|
||||||
|
|
||||||
|
TagCacheDTO toCache(TagDO domain);
|
||||||
|
|
||||||
|
List<TagVO> to(List<TagDO> list);
|
||||||
|
|
||||||
|
List<TagVO> toList(List<TagCacheDTO> cache);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.orion.ops.module.infra.dao;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.orion.ops.framework.mybatis.core.mapper.IMapper;
|
||||||
|
import com.orion.ops.module.infra.entity.domain.TagDO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签枚举 Mapper 接口
|
||||||
|
*
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 2023-9-5 11:58
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface TagDAO extends IMapper<TagDO> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取查询条件
|
||||||
|
*
|
||||||
|
* @param entity entity
|
||||||
|
* @return 查询条件
|
||||||
|
*/
|
||||||
|
default LambdaQueryWrapper<TagDO> queryCondition(TagDO entity) {
|
||||||
|
return this.wrapper()
|
||||||
|
.eq(TagDO::getId, entity.getId())
|
||||||
|
.eq(TagDO::getName, entity.getName())
|
||||||
|
.eq(TagDO::getType, entity.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.orion.ops.module.infra.define;
|
||||||
|
|
||||||
|
import com.orion.lang.define.cache.CacheKeyBuilder;
|
||||||
|
import com.orion.lang.define.cache.CacheKeyDefine;
|
||||||
|
import com.orion.ops.module.infra.entity.dto.TagCacheDTO;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tag 服务缓存 key
|
||||||
|
*
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 2023/9/5 15:36
|
||||||
|
*/
|
||||||
|
public interface TagCacheKeyDefine {
|
||||||
|
|
||||||
|
CacheKeyDefine TAG_NAME = new CacheKeyBuilder()
|
||||||
|
.key("tag:{}")
|
||||||
|
.desc("tag名称 ${type}")
|
||||||
|
.type(TagCacheDTO.class)
|
||||||
|
.timeout(3, TimeUnit.DAYS)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.orion.ops.module.infra.entity.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.orion.ops.framework.mybatis.core.domain.BaseDO;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签枚举 实体对象
|
||||||
|
*
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 2023-9-5 11:58
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@TableName(value = "tag", autoResultMap = true)
|
||||||
|
@Schema(name = "TagDO", description = "标签枚举 实体对象")
|
||||||
|
public class TagDO extends BaseDO {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Schema(description = "id")
|
||||||
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "标签名称")
|
||||||
|
@TableField("name")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Schema(description = "标签类型")
|
||||||
|
@TableField("type")
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.orion.ops.module.infra.entity.dto;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 2023/9/5 15:37
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
|
||||||
|
@Schema(name = "TagCacheDTO", description = "菜单 缓存业务对象")
|
||||||
|
public class TagCacheDTO {
|
||||||
|
|
||||||
|
@EqualsAndHashCode.Include
|
||||||
|
@Schema(description = "id")
|
||||||
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "标签名称")
|
||||||
|
@TableField("name")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package com.orion.ops.module.infra.entity.request.tag;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签枚举 创建请求对象
|
||||||
|
*
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 2023-9-5 11:58
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Schema(name = "TagCreateRequest", description = "标签枚举 创建请求对象")
|
||||||
|
public class TagCreateRequest implements Serializable {
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
@Size(max = 32)
|
||||||
|
@Schema(description = "标签名称")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
@Size(max = 12)
|
||||||
|
@Schema(description = "标签类型")
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.orion.ops.module.infra.entity.request.tag;
|
||||||
|
|
||||||
|
import com.orion.ops.framework.common.entity.PageRequest;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签枚举 查询请求对象
|
||||||
|
*
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 2023-9-5 11:58
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Schema(name = "TagQueryRequest", description = "标签枚举 查询请求对象")
|
||||||
|
public class TagQueryRequest extends PageRequest {
|
||||||
|
|
||||||
|
@Size(max = 12)
|
||||||
|
@Schema(description = "标签类型")
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package com.orion.ops.module.infra.entity.request.tag;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签枚举 更新请求对象
|
||||||
|
*
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 2023-9-5 11:58
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Schema(name = "TagUpdateRequest", description = "标签枚举 更新请求对象")
|
||||||
|
public class TagUpdateRequest implements Serializable {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Schema(description = "id")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
@Size(max = 32)
|
||||||
|
@Schema(description = "标签名称")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
@Size(max = 12)
|
||||||
|
@Schema(description = "标签类型")
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.orion.ops.module.infra.entity.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签枚举 视图响应对象
|
||||||
|
*
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 2023-9-5 11:58
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Schema(name = "TagVO", description = "标签枚举 视图响应对象")
|
||||||
|
public class TagVO implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Schema(description = "id")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "标签名称")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package com.orion.ops.module.infra.service;
|
||||||
|
|
||||||
|
import com.orion.ops.module.infra.entity.request.tag.TagCreateRequest;
|
||||||
|
import com.orion.ops.module.infra.entity.vo.TagVO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签枚举 服务类
|
||||||
|
*
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 2023-9-5 11:58
|
||||||
|
*/
|
||||||
|
public interface TagService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建标签枚举
|
||||||
|
*
|
||||||
|
* @param request request
|
||||||
|
* @return id
|
||||||
|
*/
|
||||||
|
Long createTag(TagCreateRequest request);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询标签枚举
|
||||||
|
*
|
||||||
|
* @param type type
|
||||||
|
* @return rows
|
||||||
|
*/
|
||||||
|
List<TagVO> getTagList(String type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过 id 删除标签枚举
|
||||||
|
*
|
||||||
|
* @param id id
|
||||||
|
* @return effect
|
||||||
|
*/
|
||||||
|
Integer deleteTagById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过 id 删除标签枚举
|
||||||
|
*
|
||||||
|
* @param idList idList
|
||||||
|
* @return effect
|
||||||
|
*/
|
||||||
|
Integer deleteTagByIdList(List<Long> idList);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
package com.orion.ops.module.infra.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.orion.ops.framework.common.constant.Const;
|
||||||
|
import com.orion.ops.framework.mybatis.core.query.Conditions;
|
||||||
|
import com.orion.ops.framework.redis.core.utils.RedisUtils;
|
||||||
|
import com.orion.ops.module.infra.convert.TagConvert;
|
||||||
|
import com.orion.ops.module.infra.dao.TagDAO;
|
||||||
|
import com.orion.ops.module.infra.define.TagCacheKeyDefine;
|
||||||
|
import com.orion.ops.module.infra.entity.domain.TagDO;
|
||||||
|
import com.orion.ops.module.infra.entity.dto.TagCacheDTO;
|
||||||
|
import com.orion.ops.module.infra.entity.request.tag.TagCreateRequest;
|
||||||
|
import com.orion.ops.module.infra.entity.vo.TagVO;
|
||||||
|
import com.orion.ops.module.infra.service.TagService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签枚举 服务实现类
|
||||||
|
*
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 2023-9-5 11:58
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class TagServiceImpl implements TagService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TagDAO tagDAO;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long createTag(TagCreateRequest request) {
|
||||||
|
// 转换
|
||||||
|
TagDO record = TagConvert.MAPPER.to(request);
|
||||||
|
record.setId(null);
|
||||||
|
// 查询 tag 是否存在
|
||||||
|
String type = record.getType();
|
||||||
|
LambdaQueryWrapper<TagDO> wrapper = tagDAO.wrapper()
|
||||||
|
.eq(TagDO::getName, record.getName())
|
||||||
|
.eq(TagDO::getType, type);
|
||||||
|
TagDO checkTag = tagDAO.of(wrapper)
|
||||||
|
.only()
|
||||||
|
.get();
|
||||||
|
if (checkTag != null) {
|
||||||
|
return checkTag.getId();
|
||||||
|
}
|
||||||
|
// 插入
|
||||||
|
int effect = tagDAO.insert(record);
|
||||||
|
log.info("TagService-createTag effect: {}, record: {}", effect, JSON.toJSONString(record));
|
||||||
|
// 设置缓存
|
||||||
|
String cacheKey = TagCacheKeyDefine.TAG_NAME.format(type);
|
||||||
|
TagCacheDTO cache = TagConvert.MAPPER.toCache(record);
|
||||||
|
RedisUtils.listPushJson(cacheKey, cache);
|
||||||
|
RedisUtils.setExpire(cacheKey, TagCacheKeyDefine.TAG_NAME);
|
||||||
|
return record.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TagVO> getTagList(String type) {
|
||||||
|
// 查询缓存
|
||||||
|
String cacheKey = TagCacheKeyDefine.TAG_NAME.format(type);
|
||||||
|
List<TagCacheDTO> cacheValues = RedisUtils.listRangeJson(cacheKey, TagCacheKeyDefine.TAG_NAME);
|
||||||
|
if (cacheValues.isEmpty()) {
|
||||||
|
// 为空则需要查询缓存
|
||||||
|
LambdaQueryWrapper<TagDO> wrapper = Conditions.eq(TagDO::getType, type);
|
||||||
|
cacheValues = tagDAO.of(wrapper).list(TagConvert.MAPPER::toCache);
|
||||||
|
// 添加默认值 防止穿透
|
||||||
|
if (cacheValues.isEmpty()) {
|
||||||
|
cacheValues.add(TagCacheDTO.builder().id(Const.NONE_ID).build());
|
||||||
|
}
|
||||||
|
// 设置到缓存
|
||||||
|
RedisUtils.listPushAllJson(cacheKey, cacheValues);
|
||||||
|
RedisUtils.setExpire(cacheKey, TagCacheKeyDefine.TAG_NAME);
|
||||||
|
}
|
||||||
|
// 删除防止穿透的 key
|
||||||
|
cacheValues.removeIf(s -> Const.NONE_ID.equals(s.getId()));
|
||||||
|
// 转换
|
||||||
|
return TagConvert.MAPPER.toList(cacheValues);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer deleteTagById(Long id) {
|
||||||
|
TagDO tag = tagDAO.selectById(id);
|
||||||
|
if (tag == null) {
|
||||||
|
return Const.N_0;
|
||||||
|
}
|
||||||
|
// 删除数据库
|
||||||
|
int effect = tagDAO.deleteById(id);
|
||||||
|
log.info("TagService-deleteTagById id: {}, effect: {}", id, effect);
|
||||||
|
// 删除缓存
|
||||||
|
String cacheKey = TagCacheKeyDefine.TAG_NAME.format(tag.getType());
|
||||||
|
RedisUtils.listRemoveJson(cacheKey, TagConvert.MAPPER.toCache(tag));
|
||||||
|
return effect;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer deleteTagByIdList(List<Long> idList) {
|
||||||
|
List<TagDO> tagList = tagDAO.selectBatchIds(idList);
|
||||||
|
if (tagList.isEmpty()) {
|
||||||
|
return Const.N_0;
|
||||||
|
}
|
||||||
|
// 删除数据库
|
||||||
|
int effect = tagDAO.deleteBatchIds(idList);
|
||||||
|
log.info("TagService-deleteTagByIdList idList: {}, effect: {}", idList, effect);
|
||||||
|
// 删除缓存
|
||||||
|
for (TagDO tag : tagList) {
|
||||||
|
String cacheKey = TagCacheKeyDefine.TAG_NAME.format(tag.getType());
|
||||||
|
RedisUtils.listRemoveJson(cacheKey, TagConvert.MAPPER.toCache(tag));
|
||||||
|
}
|
||||||
|
return effect;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.orion.ops.module.infra.dao.TagDAO">
|
||||||
|
|
||||||
|
<!-- 通用查询映射结果 -->
|
||||||
|
<resultMap id="BaseResultMap" type="com.orion.ops.module.infra.entity.domain.TagDO">
|
||||||
|
<id column="id" property="id"/>
|
||||||
|
<result column="create_time" property="createTime"/>
|
||||||
|
<result column="update_time" property="updateTime"/>
|
||||||
|
<result column="creator" property="creator"/>
|
||||||
|
<result column="updater" property="updater"/>
|
||||||
|
<result column="deleted" property="deleted"/>
|
||||||
|
<result column="name" property="name"/>
|
||||||
|
<result column="type" property="type"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<!-- 通用查询结果列 -->
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
id, name, type, create_time, update_time, creator, updater, deleted
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
Reference in New Issue
Block a user