123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- package cn.cslg.pas.common.utils;
- import cn.cslg.pas.common.core.base.RedisConf;
- import cn.cslg.pas.common.model.cronModel.PersonnelVO;
- import cn.cslg.pas.common.vo.business.AllCustomFieldVO;
- import cn.dev33.satoken.exception.NotLoginException;
- import cn.hutool.core.lang.tree.Tree;
- import cn.hutool.core.util.IdUtil;
- import cn.hutool.crypto.SecureUtil;
- import com.alibaba.fastjson.JSON;
- import jakarta.annotation.Resource;
- import org.springframework.stereotype.Component;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- import java.util.concurrent.TimeUnit;
- @Component
- public class CacheUtils {
- @Resource
- private RedisUtil redisUtil;
- public PersonnelVO getLoginUser(Object userId) {
- String json = redisUtil.get(RedisConf.LOGIN_USER + RedisConf.SYMBOL_COLON + userId);
- if (StringUtils.isEmpty(json)) {
- throw new NotLoginException("无数据", "user", "");
- } else {
- return com.alibaba.fastjson2.JSONObject.parseObject(json, PersonnelVO.class);
- }
- }
- public PersonnelVO getLoginUserPersonnel(Object userId) {
- String json = redisUtil.get(RedisConf.LOGIN_USER + RedisConf.SYMBOL_COLON + userId);
- if (StringUtils.isEmpty(json)) {
- throw new NotLoginException("无数据", "user", "");
- } else {
- return com.alibaba.fastjson2.JSONObject.parseObject(json, PersonnelVO.class);
- }
- }
- public String getSelectPatentIds(String patentKey) {
- return redisUtil.get(RedisConf.SELECT_PATENT + RedisConf.SYMBOL_COLON + patentKey);
- }
- public Integer getSelectPatentNum(String patentKey) {
- String ids = getSelectPatentIds(patentKey);
- if (StringUtils.isEmpty(ids)) {
- return 0;
- }
- return StringUtils.changeStringToInteger(ids, ",").size();
- }
- public void setAnalysisCountV2(String patentKey, Integer field, Integer expand, String value, String ids) {
- String md5 = SecureUtil.md5(field + RedisConf.SYMBOL_COLON + expand + RedisConf.SYMBOL_COLON + patentKey);
- String key = RedisConf.ANALYSIS_COUNT + RedisConf.SYMBOL_COLON + md5;
- if (StringUtils.isNotEmpty(value) && StringUtils.isNotEmpty(ids)) {
- redisUtil.hPut(key, value, ids);
- redisUtil.expire(key, 7200, TimeUnit.SECONDS);
- }
- }
- public Object getAnalysisCountIdsV2(String patentKey, Integer field, Integer expand, String name) {
- String md5 = SecureUtil.md5(field + RedisConf.SYMBOL_COLON + expand + RedisConf.SYMBOL_COLON + patentKey);
- String key = RedisConf.ANALYSIS_COUNT + RedisConf.SYMBOL_COLON + md5;
- return redisUtil.hGet(key, name);
- }
- public List<Tree> setAreaTreeList(List<Tree<Integer>> treeList) {
- redisUtil.set(RedisConf.COMMON_DATA + RedisConf.SYMBOL_COLON + RedisConf.AREA_LIST, JsonUtils.objectToJson(treeList));
- return this.getAreaTreeList();
- }
- public List<Tree> getAreaTreeList() {
- String json = redisUtil.get(RedisConf.COMMON_DATA + RedisConf.SYMBOL_COLON + RedisConf.AREA_LIST);
- if (StringUtils.isNotEmpty(json)) {
- return JsonUtils.jsonToList(json, Tree.class);
- }
- return null;
- }
- public String setSelectPatentIds(List<Integer> patentIds) {
- String uuid = IdUtil.simpleUUID();
- redisUtil.setEx(RedisConf.SELECT_PATENT + RedisConf.SYMBOL_COLON + uuid, StringUtils.join(patentIds, ","), 43200, TimeUnit.SECONDS);
- return uuid;
- }
- public void deleteUserSystemFieldSetting(Integer projectId, String type, String view, Integer userId, Integer createId) {
- String key = SecureUtil.md5(projectId + RedisConf.SYMBOL_COLON + type + RedisConf.SYMBOL_COLON + view + RedisConf.SYMBOL_COLON + userId + createId);
- redisUtil.delete(RedisConf.USER_FIELD + RedisConf.SYMBOL_COLON + key);
- }
- public void setUserImportId(Integer userId, Integer importId) {
- redisUtil.set(RedisConf.USER_IMPORT + RedisConf.SYMBOL_COLON + userId, String.valueOf(importId));
- }
- public String getUserImportId(Integer userId) {
- return redisUtil.get(RedisConf.USER_IMPORT + RedisConf.SYMBOL_COLON + userId);
- }
- public void deleteUserImport(Integer userId) {
- redisUtil.delete(RedisConf.USER_IMPORT + RedisConf.SYMBOL_COLON + userId);
- }
- //添加自定义栏位顺序
- public void addPatentCustomField(Integer projectId, List<AllCustomFieldVO> allCustomFieldVOS) {
- redisUtil.set(RedisConf.PROJECT_FIELD_ORDER + projectId, JsonUtils.objectToJson(allCustomFieldVOS));
- }
- public List<AllCustomFieldVO> getPatentCustomField(Integer projectId) {
- String json = redisUtil.get(RedisConf.PROJECT_FIELD_ORDER + projectId);
- if (StringUtils.isEmpty(json)) {
- return null;
- } else {
- return JSON.parseArray(json,AllCustomFieldVO.class);
- }
- }
- //添加自定义栏位顺序
- public void addTaskCustomField(Integer taskId, List<AllCustomFieldVO> allCustomFieldVOS) {
- redisUtil.set(RedisConf.TASK_FIELD_ORDER + taskId, JsonUtils.objectToJson(allCustomFieldVOS));
- }
- public List<AllCustomFieldVO> getTaskCustomField(Integer taskId) {
- String json = redisUtil.get(RedisConf.TASK_FIELD_ORDER + taskId);
- if (StringUtils.isEmpty(json)) {
- return null;
- } else {
- return JSON.parseArray(json,AllCustomFieldVO.class);
- }
- }
- }
|