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 index a0240987..f0e62b53 100644 --- 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 @@ -3,6 +3,7 @@ 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 com.orion.ops.framework.common.constant.Const; import java.util.List; import java.util.function.Function; @@ -107,6 +108,17 @@ public class RedisLists extends RedisUtils { redisTemplate.opsForList().rightPushAll(key, values); } + /** + * list 添加元素 + * + * @param key key + * @param value value + * @param T + */ + public static void push(String key, String value) { + redisTemplate.opsForList().rightPush(key, value); + } + /** * list 添加元素 * @@ -130,6 +142,18 @@ public class RedisLists extends RedisUtils { redisTemplate.opsForList().rightPush(key, JSON.toJSONString(value)); } + /** + * 是否包含某个值 + * + * @param key key + * @param value value + * @return 是否包含 + */ + public static boolean contains(String key, String value) { + Long index = redisTemplate.opsForList().indexOf(key, value); + return index != null && !Const.L_N_1.equals(index); + } + /** * list 删除元素 * diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/controller/TipsController.http b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/controller/TipsController.http new file mode 100644 index 00000000..11413af0 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/controller/TipsController.http @@ -0,0 +1,11 @@ +### 修改为已提示 +PUT {{baseUrl}}/infra/tips/tipped?key=x +Authorization: {{token}} + + +### 获取所有已提示的 key +GET {{baseUrl}}/infra/tips/get +Authorization: {{token}} + + +### diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/controller/TipsController.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/controller/TipsController.java new file mode 100644 index 00000000..39b59d9d --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/controller/TipsController.java @@ -0,0 +1,49 @@ +package com.orion.ops.module.infra.controller; + +import com.orion.ops.framework.common.annotation.RestWrapper; +import com.orion.ops.module.infra.service.TipsService; +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.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-10-8 17:52 + */ +@Tag(name = "infra - 提示服务") +@Slf4j +@Validated +@RestWrapper +@RestController +@RequestMapping("/infra/tips") +@SuppressWarnings({"ELValidationInJSP", "SpringElInspection"}) +public class TipsController { + + @Resource + private TipsService tipsService; + + @PutMapping("/tipped") + @Operation(summary = "修改为已提示") + @Parameter(name = "key", description = "key", required = true) + public boolean tipped(@RequestParam("key") String key) { + tipsService.tipped(key); + return true; + } + + @GetMapping("/get") + @Operation(summary = "获取所有已提示的 key") + public List get() { + return tipsService.getTippedKeys(); + } + +} + diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/define/TipsCacheKeyDefine.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/define/TipsCacheKeyDefine.java new file mode 100644 index 00000000..a1ed54db --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/define/TipsCacheKeyDefine.java @@ -0,0 +1,24 @@ +package com.orion.ops.module.infra.define; + +import com.orion.lang.define.cache.CacheKeyBuilder; +import com.orion.lang.define.cache.CacheKeyDefine; + +import java.util.concurrent.TimeUnit; + +/** + * tips 服务缓存 key + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023/10/8 17:58 + */ +public interface TipsCacheKeyDefine { + + CacheKeyDefine TIPS = new CacheKeyBuilder() + .key("user:tips:{}") + .desc("user:tips ${userId} 90天不会重复提示") + .type(String.class) + .timeout(90, TimeUnit.DAYS) + .build(); + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/vo/UserCollectInfoVO.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/vo/UserCollectInfoVO.java index bcc15762..8cc93df8 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/vo/UserCollectInfoVO.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/vo/UserCollectInfoVO.java @@ -6,6 +6,7 @@ import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; +import java.util.List; import java.util.Map; /** @@ -37,4 +38,7 @@ public class UserCollectInfoVO { @Schema(description = "系统偏好") private Map systemPreference; + @Schema(description = "已经提示的key") + private List tippedKeys; + } diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/TipsService.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/TipsService.java new file mode 100644 index 00000000..1db8c739 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/TipsService.java @@ -0,0 +1,28 @@ +package com.orion.ops.module.infra.service; + +import java.util.List; + +/** + * 提示服务 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023/10/8 17:53 + */ +public interface TipsService { + + /** + * 设置为已提示 + * + * @param tippedKey tippedKey + */ + void tipped(String tippedKey); + + /** + * 获取所有已提示的 key + * + * @return keys + */ + List getTippedKeys(); + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/PermissionServiceImpl.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/PermissionServiceImpl.java index a3a83c73..dce80378 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/PermissionServiceImpl.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/PermissionServiceImpl.java @@ -25,6 +25,7 @@ import com.orion.ops.module.infra.enums.RoleStatusEnum; import com.orion.ops.module.infra.service.PermissionService; import com.orion.ops.module.infra.service.PreferenceService; import com.orion.ops.module.infra.service.SystemMenuService; +import com.orion.ops.module.infra.service.TipsService; import lombok.Getter; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; @@ -73,6 +74,9 @@ public class PermissionServiceImpl implements PermissionService { @Resource private PreferenceService preferenceService; + @Resource + private TipsService tipsService; + @PostConstruct @Override public void initPermissionCache() { @@ -224,6 +228,8 @@ public class PermissionServiceImpl implements PermissionService { .collect(Collectors.toList()); } } + // 设置已提示的 key + user.setTippedKeys(tipsService.getTippedKeys()); // 获取异步结果 user.setSystemPreference(systemPreference.get()); // 组装数据 diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/TipsServiceImpl.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/TipsServiceImpl.java new file mode 100644 index 00000000..7a0bba0a --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/TipsServiceImpl.java @@ -0,0 +1,35 @@ +package com.orion.ops.module.infra.service.impl; + +import com.orion.lang.utils.collect.Lists; +import com.orion.ops.framework.redis.core.utils.RedisLists; +import com.orion.ops.framework.security.core.utils.SecurityUtils; +import com.orion.ops.module.infra.define.TipsCacheKeyDefine; +import com.orion.ops.module.infra.service.TipsService; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 提示 服务实现类 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023/10/8 17:57 + */ +@Service +public class TipsServiceImpl implements TipsService { + + @Override + public void tipped(String tippedKey) { + Long userId = SecurityUtils.getLoginUserId(); + String key = TipsCacheKeyDefine.TIPS.format(userId); + RedisLists.push(key, tippedKey); + RedisLists.setExpire(key, TipsCacheKeyDefine.TIPS); + } + + @Override + public List getTippedKeys() { + return Lists.def(RedisLists.range(TipsCacheKeyDefine.TIPS.format(SecurityUtils.getLoginUserId()))); + } + +} diff --git a/orion-ops-ui/src/api/user/tips.ts b/orion-ops-ui/src/api/user/tips.ts new file mode 100644 index 00000000..f5f75ee0 --- /dev/null +++ b/orion-ops-ui/src/api/user/tips.ts @@ -0,0 +1,8 @@ +import axios from 'axios'; + +/** + * 修改为已提示 + */ +export function setTipsTipped(key: string) { + return axios.put('/infra/tips/tipped', null, { params: { key } }); +} diff --git a/orion-ops-ui/src/components/navbar/const.ts b/orion-ops-ui/src/components/navbar/const.ts new file mode 100644 index 00000000..27f40dd4 --- /dev/null +++ b/orion-ops-ui/src/components/navbar/const.ts @@ -0,0 +1 @@ +export const preferenceTipsKey = 'home:preference'; diff --git a/orion-ops-ui/src/components/navbar/index.vue b/orion-ops-ui/src/components/navbar/index.vue index 0c610f61..0ad11597 100644 --- a/orion-ops-ui/src/components/navbar/index.vue +++ b/orion-ops-ui/src/components/navbar/index.vue @@ -183,7 +183,7 @@