添加不再提醒功能.
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
### 修改为已提示
|
||||
PUT {{baseUrl}}/infra/tips/tipped?key=x
|
||||
Authorization: {{token}}
|
||||
|
||||
|
||||
### 获取所有已提示的 key
|
||||
GET {{baseUrl}}/infra/tips/get
|
||||
Authorization: {{token}}
|
||||
|
||||
|
||||
###
|
||||
@@ -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<String> get() {
|
||||
return tipsService.getTippedKeys();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
@@ -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<String, Object> systemPreference;
|
||||
|
||||
@Schema(description = "已经提示的key")
|
||||
private List<String> tippedKeys;
|
||||
|
||||
}
|
||||
|
||||
@@ -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<String> getTippedKeys();
|
||||
|
||||
}
|
||||
@@ -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());
|
||||
// 组装数据
|
||||
|
||||
@@ -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<String> getTippedKeys() {
|
||||
return Lists.def(RedisLists.range(TipsCacheKeyDefine.TIPS.format(SecurityUtils.getLoginUserId())));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user