diff --git a/README.md b/README.md index 607de868..ed154032 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,8 @@ new GenTable("system_role", "角色", "role") .ignoreTest() // 生成 vue 文件, 一级业务包为 user, 二级业务包为 role (前端命名只能使用脊柱命名法) .vue("user", "role") + // 前端使用抽屉表单 + .useDrawerForm() // 前端代码生成的枚举对象 可变参数 .enums(RoleStatusEnum.class); ``` diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-redis/src/main/java/com/orion/ops/framework/redis/core/utils/RedisLists.java b/orion-ops-framework/orion-ops-spring-boot-starter-redis/src/main/java/com/orion/ops/framework/redis/core/utils/RedisLists.java new file mode 100644 index 00000000..a0240987 --- /dev/null +++ b/orion-ops-framework/orion-ops-spring-boot-starter-redis/src/main/java/com/orion/ops/framework/redis/core/utils/RedisLists.java @@ -0,0 +1,156 @@ +package com.orion.ops.framework.redis.core.utils; + +import com.alibaba.fastjson.JSON; +import com.orion.lang.define.cache.CacheKeyDefine; +import com.orion.lang.utils.collect.Lists; + +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** + * redis list 工具类 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023/9/20 14:08 + */ +@SuppressWarnings("unchecked") +public class RedisLists extends RedisUtils { + + private RedisLists() { + } + + /** + * 查询 list 区间 + * + * @param key key + * @return list + */ + public static List range(String key) { + // 查询列表 + List elements = redisTemplate.opsForList().range(key, 0, -1); + if (elements == null) { + return Lists.newList(); + } + return elements; + } + + /** + * 查询 list 区间 + * + * @param key key + * @param mapper mapper + * @param T + * @return list + */ + public static List range(String key, Function mapper) { + // 查询列表 + List elements = redisTemplate.opsForList().range(key, 0, -1); + if (elements == null) { + return Lists.newList(); + } + return Lists.map(elements, mapper); + } + + /** + * 查询 list 区间 + * + * @param define define + * @return list + */ + public static List rangeJson(CacheKeyDefine define) { + return rangeJson(define.getKey(), define); + } + + /** + * 查询 list 区间 + * + * @param key key + * @param define define + * @return list + */ + public static List rangeJson(String key, CacheKeyDefine define) { + // 查询列表 + List elements = redisTemplate.opsForList().range(key, 0, -1); + if (elements == null) { + return Lists.newList(); + } + return (List) elements.stream() + .map(s -> JSON.parseObject(s, define.getType())) + .collect(Collectors.toList()); + } + + /** + * list 添加元素 + * + * @param key key + * @param list list + * @param mapper mapper + * @param T + */ + public static void pushAll(String key, List list, Function mapper) { + redisTemplate.opsForList().rightPushAll(key, Lists.map(list, mapper)); + } + + /** + * list 添加元素 + * + * @param key key + * @param list list + * @param T + */ + public static void pushAllJson(String key, List list) { + List 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 + */ + public static void push(String key, T value, Function mapper) { + redisTemplate.opsForList().rightPush(key, mapper.apply(value)); + } + + /** + * list 添加元素 + * + * @param key key + * @param value value + * @param T + */ + public static void pushJson(String key, T value) { + redisTemplate.opsForList().rightPush(key, JSON.toJSONString(value)); + } + + /** + * list 删除元素 + * + * @param key key + * @param value value + * @param mapper mapper + * @param T + */ + public static void remove(String key, T value, Function mapper) { + redisTemplate.opsForList().remove(key, 1, mapper.apply(value)); + } + + /** + * list 删除元素 + * + * @param key key + * @param value value + * @param T + */ + public static void removeJson(String key, T value) { + redisTemplate.opsForList().remove(key, 1, JSON.toJSONString(value)); + } + +} diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-redis/src/main/java/com/orion/ops/framework/redis/core/utils/RedisStrings.java b/orion-ops-framework/orion-ops-spring-boot-starter-redis/src/main/java/com/orion/ops/framework/redis/core/utils/RedisStrings.java new file mode 100644 index 00000000..12a7caf8 --- /dev/null +++ b/orion-ops-framework/orion-ops-spring-boot-starter-redis/src/main/java/com/orion/ops/framework/redis/core/utils/RedisStrings.java @@ -0,0 +1,151 @@ +package com.orion.ops.framework.redis.core.utils; + +import com.alibaba.fastjson.JSON; +import com.orion.lang.define.cache.CacheKeyDefine; +import com.orion.lang.utils.Strings; + +import java.util.List; +import java.util.function.Consumer; + +/** + * redis string 工具类 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023/9/20 14:05 + */ +@SuppressWarnings("unchecked") +public class RedisStrings extends RedisUtils { + + private RedisStrings() { + } + + /** + * 获取 json + * + * @param define define + * @param T + * @return T + */ + public static T getJson(CacheKeyDefine define) { + return getJson(define.getKey(), define); + } + + /** + * 获取 json + * + * @param key key + * @param define define + * @param T + * @return T + */ + public static T getJson(String key, CacheKeyDefine define) { + String value = redisTemplate.opsForValue().get(key); + if (value == null) { + return null; + } + return (T) JSON.parseObject(value, define.getType()); + } + + /** + * 获取 json + * + * @param define define + * @param T + * @return T + */ + public static List getJsonArray(CacheKeyDefine define) { + return getJsonArray(define.getKey(), define); + } + + /** + * 获取 json + * + * @param key key + * @param define define + * @param T + * @return T + */ + public static List getJsonArray(String key, CacheKeyDefine define) { + String value = redisTemplate.opsForValue().get(key); + if (value == null) { + return null; + } + return (List) JSON.parseArray(value, define.getType()); + } + + /** + * 设置 json + * + * @param key key + * @param define define + * @param value value + */ + public static void set(String key, CacheKeyDefine define, Object value) { + if (value == null) { + value = Strings.EMPTY; + } + if (define.getTimeout() == 0) { + // 不过期 + redisTemplate.opsForValue().set(key, value.toString()); + } else { + // 过期 + redisTemplate.opsForValue().set(key, value.toString(), + define.getTimeout(), + define.getUnit()); + } + } + + /** + * 设置 json + * + * @param key key + * @param define define + * @param value value + */ + public static void setJson(String key, CacheKeyDefine define, Object value) { + if (define.getTimeout() == 0) { + // 不过期 + redisTemplate.opsForValue().set(key, JSON.toJSONString(value)); + } else { + // 过期 + redisTemplate.opsForValue().set(key, JSON.toJSONString(value), + define.getTimeout(), + define.getUnit()); + } + } + + /** + * 获取并且设置 json + * + * @param define define + * @param processor processor + * @param params params + * @param type + */ + public static void processSetJson(CacheKeyDefine define, Consumer processor, Object... params) { + processSetJson(define.format(params), define, processor); + } + + /** + * 获取并且设置 json + * + * @param key key + * @param define define + * @param processor processor + * @param type + */ + public static void processSetJson(String key, CacheKeyDefine define, Consumer processor) { + String value = redisTemplate.opsForValue().get(key); + if (value == null) { + return; + } + // 转换 + T cache = (T) JSON.parseObject(value, define.getType()); + // 执行处理逻辑 + processor.accept(cache); + // 重新设置 + setJson(key, define, cache); + } + +} diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-redis/src/main/java/com/orion/ops/framework/redis/core/utils/RedisUtils.java b/orion-ops-framework/orion-ops-spring-boot-starter-redis/src/main/java/com/orion/ops/framework/redis/core/utils/RedisUtils.java index 8e626b9e..55a40a2d 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-redis/src/main/java/com/orion/ops/framework/redis/core/utils/RedisUtils.java +++ b/orion-ops-framework/orion-ops-spring-boot-starter-redis/src/main/java/com/orion/ops/framework/redis/core/utils/RedisUtils.java @@ -1,9 +1,6 @@ package com.orion.ops.framework.redis.core.utils; -import com.alibaba.fastjson.JSON; import com.orion.lang.define.cache.CacheKeyDefine; -import com.orion.lang.utils.Strings; -import com.orion.lang.utils.collect.Lists; import com.orion.lang.utils.io.Streams; import org.springframework.data.redis.core.Cursor; import org.springframework.data.redis.core.RedisCallback; @@ -11,11 +8,7 @@ import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.ScanOptions; import java.util.HashSet; -import java.util.List; import java.util.Set; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.stream.Collectors; /** * redis 工具类 @@ -24,12 +17,11 @@ import java.util.stream.Collectors; * @version 1.0.0 * @since 2021/11/6 11:09 */ -@SuppressWarnings("unchecked") public class RedisUtils { - private static RedisTemplate redisTemplate; + protected static RedisTemplate redisTemplate; - private RedisUtils() { + protected RedisUtils() { } /** @@ -63,199 +55,12 @@ public class RedisUtils { } /** - * 获取并且设置 json + * 设置过期时间 * - * @param define define - * @param processor processor - * @param params params - * @param type - */ - public static void processSetJson(CacheKeyDefine define, Consumer processor, Object... params) { - processSetJson(define.format(params), define, processor); - } - - /** - * 获取并且设置 json - * - * @param key key - * @param define define - * @param processor processor - * @param type - */ - public static void processSetJson(String key, CacheKeyDefine define, Consumer processor) { - String value = redisTemplate.opsForValue().get(key); - if (value == null) { - return; - } - // 转换 - T cache = (T) JSON.parseObject(value, define.getType()); - // 执行处理逻辑 - processor.accept(cache); - // 重新设置 - setJson(key, define, cache); - } - - /** - * 设置 json - * - * @param key key * @param define define - * @param value value */ - public static void set(String key, CacheKeyDefine define, Object value) { - if (value == null) { - value = Strings.EMPTY; - } - if (define.getTimeout() == 0) { - // 不过期 - redisTemplate.opsForValue().set(key, value.toString()); - } else { - // 过期 - redisTemplate.opsForValue().set(key, value.toString(), - define.getTimeout(), - define.getUnit()); - } - } - - /** - * 设置 json - * - * @param key key - * @param define define - * @param value value - */ - public static void setJson(String key, CacheKeyDefine define, Object value) { - if (define.getTimeout() == 0) { - // 不过期 - redisTemplate.opsForValue().set(key, JSON.toJSONString(value)); - } else { - // 过期 - redisTemplate.opsForValue().set(key, JSON.toJSONString(value), - define.getTimeout(), - define.getUnit()); - } - } - - /** - * 查询 list 区间 - * - * @param key key - * @return list - */ - public static List listRange(String key) { - // 查询列表 - List elements = redisTemplate.opsForList().range(key, 0, -1); - if (elements == null) { - return Lists.newList(); - } - return elements; - } - - /** - * 查询 list 区间 - * - * @param key key - * @param mapper mapper - * @param T - * @return list - */ - public static List listRange(String key, Function mapper) { - // 查询列表 - List elements = redisTemplate.opsForList().range(key, 0, -1); - if (elements == null) { - return Lists.newList(); - } - return Lists.map(elements, mapper); - } - - /** - * 查询 list 区间 - * - * @param key key - * @param define define - * @return list - */ - public static List listRangeJson(String key, CacheKeyDefine define) { - // 查询列表 - List elements = redisTemplate.opsForList().range(key, 0, -1); - if (elements == null) { - return Lists.newList(); - } - return (List) elements.stream() - .map(s -> JSON.parseObject(s, define.getType())) - .collect(Collectors.toList()); - } - - /** - * list 添加元素 - * - * @param key key - * @param list list - * @param mapper mapper - * @param T - */ - public static void listPushAll(String key, List list, Function mapper) { - redisTemplate.opsForList().rightPushAll(key, Lists.map(list, mapper)); - } - - /** - * list 添加元素 - * - * @param key key - * @param list list - * @param T - */ - public static void listPushAllJson(String key, List list) { - List 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 - */ - public static void listPush(String key, T value, Function mapper) { - redisTemplate.opsForList().rightPush(key, mapper.apply(value)); - } - - /** - * list 添加元素 - * - * @param key key - * @param value value - * @param T - */ - public static 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 - */ - public static void listRemove(String key, T value, Function mapper) { - redisTemplate.opsForList().remove(key, 1, mapper.apply(value)); - } - - /** - * list 删除元素 - * - * @param key key - * @param value value - * @param T - */ - public static void listRemoveJson(String key, T value) { - redisTemplate.opsForList().remove(key, 1, JSON.toJSONString(value)); + public static void setExpire(CacheKeyDefine define) { + setExpire(define.getKey(), define); } /** diff --git a/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/CodeGenerator.java b/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/CodeGenerator.java index d2300265..0495ee3f 100644 --- a/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/CodeGenerator.java +++ b/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/CodeGenerator.java @@ -48,9 +48,11 @@ public class CodeGenerator { // .enums(UserStatusEnum.class), new GenTable("host_key", "主机秘钥", "host") .vue("asset", "host-key") + .useDrawerForm() .ignoreTest(), new GenTable("host_identity", "主机身份", "host") .vue("asset", "host-identity") + .useDrawerForm() .ignoreTest(), }; // jdbc 配置 - 使用配置文件 @@ -345,6 +347,8 @@ public class CodeGenerator { new String[]{"/templates/orion-vue-views-index.vue.vm", "index.vue", "vue/views/${module}/${feature}"}, // form-modal.vue 文件 new String[]{"/templates/orion-vue-views-components-form-modal.vue.vm", "${feature}-form-modal.vue", "vue/views/${module}/${feature}/components"}, + // form-drawer.vue 文件 + new String[]{"/templates/orion-vue-views-components-form-drawer.vue.vm", "${feature}-form-drawer.vue", "vue/views/${module}/${feature}/components"}, // table.vue 文件 new String[]{"/templates/orion-vue-views-components-table.vue.vm", "${feature}-table.vue", "vue/views/${module}/${feature}/components"}, // enum.types.ts 文件 diff --git a/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/core/GenTable.java b/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/core/GenTable.java index 92b0770b..50a332d0 100644 --- a/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/core/GenTable.java +++ b/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/core/GenTable.java @@ -60,6 +60,11 @@ public class GenTable { */ private String feature; + /** + * 使用抽屉表单 + */ + private boolean drawerForm; + /** * 生成的枚举文件 */ @@ -108,6 +113,16 @@ public class GenTable { return this; } + /** + * 使用抽屉表单 + * + * @return this + */ + public GenTable useDrawerForm() { + this.drawerForm = true; + return this; + } + /** * 生成 vue 枚举对象 * diff --git a/orion-ops-ui/src/views/asset/host-key/components/host-key-form-modal.vue b/orion-ops-launch/src/main/resources/templates/orion-vue-views-components-form-drawer.vue.vm similarity index 57% rename from orion-ops-ui/src/views/asset/host-key/components/host-key-form-modal.vue rename to orion-ops-launch/src/main/resources/templates/orion-vue-views-components-form-drawer.vue.vm index 05388df9..d262866f 100644 --- a/orion-ops-ui/src/views/asset/host-key/components/host-key-form-modal.vue +++ b/orion-ops-launch/src/main/resources/templates/orion-vue-views-components-form-drawer.vue.vm @@ -1,49 +1,44 @@ @@ -52,10 +47,10 @@ import useLoading from '@/hooks/loading'; import useVisible from '@/hooks/visible'; import formRules from '../types/form.rules'; - import { createHostKey, updateHostKey } from '@/api/asset/host-key'; + import { create${vue.featureEntity}, update${vue.featureEntity} } from '@/api/${vue.module}/${vue.feature}'; import { Message } from '@arco-design/web-vue'; - import { } from '../types/enum.types'; - import { } from '../types/const'; + import {} from '../types/enum.types'; + import {} from '../types/const'; import { toOptions } from '@/utils/enum'; const { visible, setVisible } = useVisible(); @@ -66,11 +61,9 @@ const defaultForm = () => { return { - id: undefined, - name: undefined, - publicKey: undefined, - privateKey: undefined, - password: undefined, + #foreach($field in ${table.fields}) + ${field.propertyName}: undefined, + #end }; }; @@ -81,7 +74,7 @@ // 打开新增 const openAdd = () => { - title.value = '添加主机秘钥'; + title.value = '添加${table.comment}'; isAddHandle.value = true; renderForm({ ...defaultForm() }); setVisible(true); @@ -89,7 +82,7 @@ // 打开修改 const openUpdate = (record: any) => { - title.value = '修改主机秘钥'; + title.value = '修改${table.comment}'; isAddHandle.value = false; renderForm({ ...defaultForm(), ...record }); setVisible(true); @@ -115,12 +108,12 @@ } if (isAddHandle.value) { // 新增 - await createHostKey(formModel as any); + await create${vue.featureEntity}(formModel as any); Message.success('创建成功'); emits('added'); } else { // 修改 - await updateHostKey(formModel as any); + await update${vue.featureEntity}(formModel as any); Message.success('修改成功'); emits('updated'); } diff --git a/orion-ops-launch/src/main/resources/templates/orion-vue-views-components-form-modal.vue.vm b/orion-ops-launch/src/main/resources/templates/orion-vue-views-components-form-modal.vue.vm index 990ade05..07c6c21c 100644 --- a/orion-ops-launch/src/main/resources/templates/orion-vue-views-components-form-modal.vue.vm +++ b/orion-ops-launch/src/main/resources/templates/orion-vue-views-components-form-modal.vue.vm @@ -55,8 +55,8 @@ import formRules from '../types/form.rules'; import { create${vue.featureEntity}, update${vue.featureEntity} } from '@/api/${vue.module}/${vue.feature}'; import { Message } from '@arco-design/web-vue'; - import { } from '../types/enum.types'; - import { } from '../types/const'; + import {} from '../types/enum.types'; + import {} from '../types/const'; import { toOptions } from '@/utils/enum'; const { visible, setVisible } = useVisible(); diff --git a/orion-ops-launch/src/main/resources/templates/orion-vue-views-components-table.vue.vm b/orion-ops-launch/src/main/resources/templates/orion-vue-views-components-table.vue.vm index 04a30902..589d607c 100644 --- a/orion-ops-launch/src/main/resources/templates/orion-vue-views-components-table.vue.vm +++ b/orion-ops-launch/src/main/resources/templates/orion-vue-views-components-table.vue.vm @@ -115,8 +115,8 @@ import useLoading from '@/hooks/loading'; import columns from '../types/table.columns'; import { defaultPagination, defaultRowSelection } from '@/types/table'; - import { } from '../types/enum.types'; - import { } from '../types/const'; + import {} from '../types/enum.types'; + import {} from '../types/const'; import { toOptions } from '@/utils/enum'; const tableRenderData = ref<${vue.featureEntity}QueryResponse[]>(); diff --git a/orion-ops-launch/src/main/resources/templates/orion-vue-views-index.vue.vm b/orion-ops-launch/src/main/resources/templates/orion-vue-views-index.vue.vm index 9372fde1..a0e77e69 100644 --- a/orion-ops-launch/src/main/resources/templates/orion-vue-views-index.vue.vm +++ b/orion-ops-launch/src/main/resources/templates/orion-vue-views-index.vue.vm @@ -1,13 +1,25 @@ @@ -19,11 +31,20 @@ diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/AuthenticationServiceImpl.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/AuthenticationServiceImpl.java index 654cc9fd..7f642a47 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/AuthenticationServiceImpl.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/AuthenticationServiceImpl.java @@ -14,6 +14,7 @@ import com.orion.ops.framework.common.utils.CryptoUtils; import com.orion.ops.framework.common.utils.IpUtils; import com.orion.ops.framework.common.utils.Kits; import com.orion.ops.framework.common.utils.Valid; +import com.orion.ops.framework.redis.core.utils.RedisStrings; import com.orion.ops.framework.redis.core.utils.RedisUtils; import com.orion.ops.module.infra.convert.SystemUserConvert; import com.orion.ops.module.infra.dao.SystemUserDAO; @@ -153,10 +154,10 @@ public class AuthenticationServiceImpl implements AuthenticationService { int refreshCount = refresh.getRefreshCount() + 1; refresh.setRefreshCount(refreshCount); // 设置登陆缓存 - RedisUtils.setJson(loginKey, UserCacheKeyDefine.LOGIN_TOKEN, refresh); + RedisStrings.setJson(loginKey, UserCacheKeyDefine.LOGIN_TOKEN, refresh); if (refreshCount < maxRefreshCount) { // 小于续签最大次数 则再次设置 refreshToken - RedisUtils.setJson(refreshKey, UserCacheKeyDefine.LOGIN_REFRESH, refresh); + RedisStrings.setJson(refreshKey, UserCacheKeyDefine.LOGIN_REFRESH, refresh); } else { // 大于等于续签最大次数 则删除 redisTemplate.delete(refreshKey); @@ -239,7 +240,7 @@ public class AuthenticationServiceImpl implements AuthenticationService { // 修改缓存状态 LoginUser loginUser = JSON.parseObject(userInfoCache, LoginUser.class); loginUser.setStatus(UserStatusEnum.LOCKED.getStatus()); - RedisUtils.setJson(userInfoKey, UserCacheKeyDefine.USER_INFO, loginUser); + RedisStrings.setJson(userInfoKey, UserCacheKeyDefine.USER_INFO, loginUser); } return false; } @@ -290,7 +291,7 @@ public class AuthenticationServiceImpl implements AuthenticationService { String userInfoKey = UserCacheKeyDefine.USER_INFO.format(id); LoginUser loginUser = SystemUserConvert.MAPPER.toLoginUser(user); loginUser.setRoles(roleCodeList); - RedisUtils.setJson(userInfoKey, UserCacheKeyDefine.USER_INFO, loginUser); + RedisStrings.setJson(userInfoKey, UserCacheKeyDefine.USER_INFO, loginUser); return loginUser; } @@ -323,7 +324,7 @@ public class AuthenticationServiceImpl implements AuthenticationService { loginTokenInfo.setLoginTime(loginTime); loginTokenInfo.setIp(remoteAddr); loginTokenInfo.setLocation(location); - RedisUtils.setJson(deviceLoginKey, UserCacheKeyDefine.LOGIN_TOKEN, loginTokenInfo); + RedisStrings.setJson(deviceLoginKey, UserCacheKeyDefine.LOGIN_TOKEN, loginTokenInfo); } } // 删除续签信息 @@ -358,11 +359,11 @@ public class AuthenticationServiceImpl implements AuthenticationService { .loginTime(loginTime) .location(location) .build(); - RedisUtils.setJson(loginKey, UserCacheKeyDefine.LOGIN_TOKEN, loginValue); + RedisStrings.setJson(loginKey, UserCacheKeyDefine.LOGIN_TOKEN, loginValue); // 生成 refreshToken if (allowRefresh) { String refreshKey = UserCacheKeyDefine.LOGIN_REFRESH.format(id, loginTime); - RedisUtils.setJson(refreshKey, UserCacheKeyDefine.LOGIN_REFRESH, loginValue); + RedisStrings.setJson(refreshKey, UserCacheKeyDefine.LOGIN_REFRESH, loginValue); } // 返回token return CryptoUtils.encryptBase62(id + ":" + loginTime); diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/FavoriteServiceImpl.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/FavoriteServiceImpl.java index 55293a91..5408cfbf 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/FavoriteServiceImpl.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/FavoriteServiceImpl.java @@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.orion.lang.utils.collect.Lists; import com.orion.ops.framework.common.constant.Const; import com.orion.ops.framework.common.utils.Valid; -import com.orion.ops.framework.redis.core.utils.RedisUtils; +import com.orion.ops.framework.redis.core.utils.RedisLists; import com.orion.ops.framework.security.core.utils.SecurityUtils; import com.orion.ops.module.infra.convert.FavoriteConvert; import com.orion.ops.module.infra.dao.FavoriteDAO; @@ -53,9 +53,9 @@ public class FavoriteServiceImpl implements FavoriteService { int effect = favoriteDAO.insert(record); // 设置缓存 String key = FavoriteCacheKeyDefine.FAVORITE.format(type, userId); - RedisUtils.listPush(key, request.getRelId(), String::valueOf); + RedisLists.push(key, request.getRelId(), String::valueOf); // 设置过期时间 - RedisUtils.setExpire(key, FavoriteCacheKeyDefine.FAVORITE); + RedisLists.setExpire(key, FavoriteCacheKeyDefine.FAVORITE); return record.getId(); } @@ -86,7 +86,7 @@ public class FavoriteServiceImpl implements FavoriteService { Long userId = request.getUserId(); String cacheKey = FavoriteCacheKeyDefine.FAVORITE.format(type, userId); // 获取缓存 - List cacheRelIdList = RedisUtils.listRange(cacheKey, Long::valueOf); + List cacheRelIdList = RedisLists.range(cacheKey, Long::valueOf); if (cacheRelIdList.isEmpty()) { // 条件 LambdaQueryWrapper wrapper = this.buildQueryWrapper(request); @@ -101,9 +101,9 @@ public class FavoriteServiceImpl implements FavoriteService { cacheRelIdList.add(Const.NONE_ID); } // 设置缓存 - RedisUtils.listPushAll(cacheKey, cacheRelIdList, String::valueOf); + RedisLists.pushAll(cacheKey, cacheRelIdList, String::valueOf); // 设置过期时间 - RedisUtils.setExpire(cacheKey, FavoriteCacheKeyDefine.FAVORITE); + RedisLists.setExpire(cacheKey, FavoriteCacheKeyDefine.FAVORITE); } // 删除防止穿透的 key cacheRelIdList.remove(Const.NONE_ID); diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/SystemUserRoleServiceImpl.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/SystemUserRoleServiceImpl.java index ffc27dde..cad7fc3e 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/SystemUserRoleServiceImpl.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/SystemUserRoleServiceImpl.java @@ -4,7 +4,7 @@ import com.orion.lang.utils.collect.Lists; import com.orion.ops.framework.common.constant.ErrorMessage; import com.orion.ops.framework.common.security.LoginUser; import com.orion.ops.framework.common.utils.Valid; -import com.orion.ops.framework.redis.core.utils.RedisUtils; +import com.orion.ops.framework.redis.core.utils.RedisStrings; import com.orion.ops.module.infra.dao.SystemRoleDAO; import com.orion.ops.module.infra.dao.SystemUserDAO; import com.orion.ops.module.infra.dao.SystemUserRoleDAO; @@ -54,7 +54,7 @@ public class SystemUserRoleServiceImpl implements SystemUserRoleService { // 删除用户关联 int effect = systemUserRoleDAO.deleteByUserId(userId); // 更新缓存中的角色 - RedisUtils.processSetJson(UserCacheKeyDefine.USER_INFO, s -> { + RedisStrings.processSetJson(UserCacheKeyDefine.USER_INFO, s -> { s.setRoles(Lists.empty()); }, userId); return effect; @@ -92,7 +92,7 @@ public class SystemUserRoleServiceImpl implements SystemUserRoleService { systemUserRoleDAO.insertBatch(addUserRoles); effect += addUserRoles.size(); // 更新缓存中的角色 - RedisUtils.processSetJson(UserCacheKeyDefine.USER_INFO, s -> { + RedisStrings.processSetJson(UserCacheKeyDefine.USER_INFO, s -> { List roleCodeList = userRoles.stream() .map(SystemRoleDO::getCode) .collect(Collectors.toList()); @@ -105,7 +105,7 @@ public class SystemUserRoleServiceImpl implements SystemUserRoleService { @Async("asyncExecutor") public void asyncDeleteUserCacheRole(String roleCode, List userIdList) { for (Long userId : userIdList) { - RedisUtils.processSetJson(UserCacheKeyDefine.USER_INFO, s -> { + RedisStrings.processSetJson(UserCacheKeyDefine.USER_INFO, s -> { List roles = s.getRoles(); if (Lists.isEmpty(roles)) { return; diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/SystemUserServiceImpl.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/SystemUserServiceImpl.java index a1873813..a1db5327 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/SystemUserServiceImpl.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/SystemUserServiceImpl.java @@ -9,6 +9,7 @@ import com.orion.ops.framework.common.constant.ErrorCode; import com.orion.ops.framework.common.constant.ErrorMessage; import com.orion.ops.framework.common.security.LoginUser; import com.orion.ops.framework.common.utils.Valid; +import com.orion.ops.framework.redis.core.utils.RedisStrings; import com.orion.ops.framework.redis.core.utils.RedisUtils; import com.orion.ops.framework.security.core.utils.SecurityUtils; import com.orion.ops.module.infra.convert.SystemUserConvert; @@ -82,7 +83,7 @@ public class SystemUserServiceImpl implements SystemUserService { int effect = systemUserDAO.updateById(updateRecord); log.info("SystemUserService-updateSystemUserById effect: {}, updateRecord: {}", effect, JSON.toJSONString(updateRecord)); // 更新缓存中的花名 - RedisUtils.processSetJson(UserCacheKeyDefine.USER_INFO, s -> { + RedisStrings.processSetJson(UserCacheKeyDefine.USER_INFO, s -> { s.setNickname(request.getNickname()); }, id); return effect; @@ -112,7 +113,7 @@ public class SystemUserServiceImpl implements SystemUserService { redisTemplate.delete(UserCacheKeyDefine.LOGIN_FAILED_COUNT.format(record.getUsername())); } // 更新缓存中的status - RedisUtils.processSetJson(UserCacheKeyDefine.USER_INFO, s -> { + RedisStrings.processSetJson(UserCacheKeyDefine.USER_INFO, s -> { s.setStatus(request.getStatus()); }, id); return effect; diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/TagRelServiceImpl.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/TagRelServiceImpl.java index aaf20589..5f9b1d3b 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/TagRelServiceImpl.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/TagRelServiceImpl.java @@ -4,7 +4,7 @@ import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.orion.lang.utils.collect.Lists; import com.orion.lang.utils.collect.Maps; -import com.orion.ops.framework.redis.core.utils.RedisUtils; +import com.orion.ops.framework.redis.core.utils.RedisStrings; import com.orion.ops.module.infra.convert.TagRelConvert; import com.orion.ops.module.infra.dao.TagDAO; import com.orion.ops.module.infra.dao.TagRelDAO; @@ -63,7 +63,7 @@ public class TagRelServiceImpl implements TagRelService { tagRelDAO.insertBatch(tagRelList); // 设置缓存 String cacheKey = TagCacheKeyDefine.TAG_REL.format(type, relId); - RedisUtils.setJson(cacheKey, TagCacheKeyDefine.TAG_REL, TagRelConvert.MAPPER.toCacheList(tagRelList)); + RedisStrings.setJson(cacheKey, TagCacheKeyDefine.TAG_REL, TagRelConvert.MAPPER.toCacheList(tagRelList)); } @Override @@ -90,7 +90,7 @@ public class TagRelServiceImpl implements TagRelService { List relList = tagRelDAO.selectList(wrapper); // 设置缓存 List relCacheList = TagRelConvert.MAPPER.toCacheList(relList); - RedisUtils.setJson(cacheKey, TagCacheKeyDefine.TAG_REL, relCacheList); + RedisStrings.setJson(cacheKey, TagCacheKeyDefine.TAG_REL, relCacheList); return relCacheList; } else { // 返回缓存数据 @@ -135,7 +135,7 @@ public class TagRelServiceImpl implements TagRelService { if (cacheValue == null) { cacheValue = Lists.empty(); } - RedisUtils.setJson(cacheKey, TagCacheKeyDefine.TAG_REL, cacheValue); + RedisStrings.setJson(cacheKey, TagCacheKeyDefine.TAG_REL, cacheValue); emptyCacheMap.put(relId, cacheValue); }); // 设置返回 diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/TagServiceImpl.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/TagServiceImpl.java index f8a6ba2a..06506214 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/TagServiceImpl.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/TagServiceImpl.java @@ -4,7 +4,7 @@ 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.framework.redis.core.utils.RedisLists; import com.orion.ops.module.infra.convert.TagConvert; import com.orion.ops.module.infra.dao.TagDAO; import com.orion.ops.module.infra.define.TagCacheKeyDefine; @@ -52,8 +52,8 @@ public class TagServiceImpl implements TagService { // 设置缓存 String cacheKey = TagCacheKeyDefine.TAG_NAME.format(type); TagCacheDTO cache = TagConvert.MAPPER.toCache(record); - RedisUtils.listPushJson(cacheKey, cache); - RedisUtils.setExpire(cacheKey, TagCacheKeyDefine.TAG_NAME); + RedisLists.pushJson(cacheKey, cache); + RedisLists.setExpire(cacheKey, TagCacheKeyDefine.TAG_NAME); return record.getId(); } @@ -61,7 +61,7 @@ public class TagServiceImpl implements TagService { public List getTagList(String type) { // 查询缓存 String cacheKey = TagCacheKeyDefine.TAG_NAME.format(type); - List cacheValues = RedisUtils.listRangeJson(cacheKey, TagCacheKeyDefine.TAG_NAME); + List cacheValues = RedisLists.rangeJson(cacheKey, TagCacheKeyDefine.TAG_NAME); if (cacheValues.isEmpty()) { // 为空则需要查询缓存 LambdaQueryWrapper wrapper = Conditions.eq(TagDO::getType, type); @@ -71,8 +71,8 @@ public class TagServiceImpl implements TagService { cacheValues.add(TagCacheDTO.builder().id(Const.NONE_ID).build()); } // 设置到缓存 - RedisUtils.listPushAllJson(cacheKey, cacheValues); - RedisUtils.setExpire(cacheKey, TagCacheKeyDefine.TAG_NAME); + RedisLists.pushAllJson(cacheKey, cacheValues); + RedisLists.setExpire(cacheKey, TagCacheKeyDefine.TAG_NAME); } // 删除防止穿透的 key cacheValues.removeIf(s -> Const.NONE_ID.equals(s.getId())); @@ -91,7 +91,7 @@ public class TagServiceImpl implements TagService { log.info("TagService-deleteTagById id: {}, effect: {}", id, effect); // 删除缓存 String cacheKey = TagCacheKeyDefine.TAG_NAME.format(tag.getType()); - RedisUtils.listRemoveJson(cacheKey, TagConvert.MAPPER.toCache(tag)); + RedisLists.removeJson(cacheKey, TagConvert.MAPPER.toCache(tag)); return effect; } @@ -107,7 +107,7 @@ public class TagServiceImpl implements TagService { // 删除缓存 for (TagDO tag : tagList) { String cacheKey = TagCacheKeyDefine.TAG_NAME.format(tag.getType()); - RedisUtils.listRemoveJson(cacheKey, TagConvert.MAPPER.toCache(tag)); + RedisLists.removeJson(cacheKey, TagConvert.MAPPER.toCache(tag)); } return effect; }