CacheUtils.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. package cn.cslg.pas.common.utils;
  2. import cn.cslg.pas.common.core.base.RedisConf;
  3. import cn.cslg.pas.common.model.cronModel.PersonnelVO;
  4. import cn.cslg.pas.common.vo.business.AllCustomFieldVO;
  5. import cn.dev33.satoken.exception.NotLoginException;
  6. import cn.hutool.core.lang.tree.Tree;
  7. import cn.hutool.core.util.IdUtil;
  8. import cn.hutool.crypto.SecureUtil;
  9. import com.alibaba.fastjson.JSON;
  10. import jakarta.annotation.Resource;
  11. import org.springframework.stereotype.Component;
  12. import java.util.ArrayList;
  13. import java.util.List;
  14. import java.util.Map;
  15. import java.util.concurrent.TimeUnit;
  16. @Component
  17. public class CacheUtils {
  18. @Resource
  19. private RedisUtil redisUtil;
  20. public PersonnelVO getLoginUser(Object userId) {
  21. String json = redisUtil.get(RedisConf.LOGIN_USER + RedisConf.SYMBOL_COLON + userId);
  22. if (StringUtils.isEmpty(json)) {
  23. throw new NotLoginException("无数据", "user", "");
  24. } else {
  25. return com.alibaba.fastjson2.JSONObject.parseObject(json, PersonnelVO.class);
  26. }
  27. }
  28. public PersonnelVO getLoginUserPersonnel(Object userId) {
  29. String json = redisUtil.get(RedisConf.LOGIN_USER + RedisConf.SYMBOL_COLON + userId);
  30. if (StringUtils.isEmpty(json)) {
  31. throw new NotLoginException("无数据", "user", "");
  32. } else {
  33. return com.alibaba.fastjson2.JSONObject.parseObject(json, PersonnelVO.class);
  34. }
  35. }
  36. public String getSelectPatentIds(String patentKey) {
  37. return redisUtil.get(RedisConf.SELECT_PATENT + RedisConf.SYMBOL_COLON + patentKey);
  38. }
  39. public Integer getSelectPatentNum(String patentKey) {
  40. String ids = getSelectPatentIds(patentKey);
  41. if (StringUtils.isEmpty(ids)) {
  42. return 0;
  43. }
  44. return StringUtils.changeStringToInteger(ids, ",").size();
  45. }
  46. public void setAnalysisCountV2(String patentKey, Integer field, Integer expand, String value, String ids) {
  47. String md5 = SecureUtil.md5(field + RedisConf.SYMBOL_COLON + expand + RedisConf.SYMBOL_COLON + patentKey);
  48. String key = RedisConf.ANALYSIS_COUNT + RedisConf.SYMBOL_COLON + md5;
  49. if (StringUtils.isNotEmpty(value) && StringUtils.isNotEmpty(ids)) {
  50. redisUtil.hPut(key, value, ids);
  51. redisUtil.expire(key, 7200, TimeUnit.SECONDS);
  52. }
  53. }
  54. public Object getAnalysisCountIdsV2(String patentKey, Integer field, Integer expand, String name) {
  55. String md5 = SecureUtil.md5(field + RedisConf.SYMBOL_COLON + expand + RedisConf.SYMBOL_COLON + patentKey);
  56. String key = RedisConf.ANALYSIS_COUNT + RedisConf.SYMBOL_COLON + md5;
  57. return redisUtil.hGet(key, name);
  58. }
  59. public List<Tree> setAreaTreeList(List<Tree<Integer>> treeList) {
  60. redisUtil.set(RedisConf.COMMON_DATA + RedisConf.SYMBOL_COLON + RedisConf.AREA_LIST, JsonUtils.objectToJson(treeList));
  61. return this.getAreaTreeList();
  62. }
  63. public List<Tree> getAreaTreeList() {
  64. String json = redisUtil.get(RedisConf.COMMON_DATA + RedisConf.SYMBOL_COLON + RedisConf.AREA_LIST);
  65. if (StringUtils.isNotEmpty(json)) {
  66. return JsonUtils.jsonToList(json, Tree.class);
  67. }
  68. return null;
  69. }
  70. public String setSelectPatentIds(List<Integer> patentIds) {
  71. String uuid = IdUtil.simpleUUID();
  72. redisUtil.setEx(RedisConf.SELECT_PATENT + RedisConf.SYMBOL_COLON + uuid, StringUtils.join(patentIds, ","), 43200, TimeUnit.SECONDS);
  73. return uuid;
  74. }
  75. public void deleteUserSystemFieldSetting(Integer projectId, String type, String view, Integer userId, Integer createId) {
  76. String key = SecureUtil.md5(projectId + RedisConf.SYMBOL_COLON + type + RedisConf.SYMBOL_COLON + view + RedisConf.SYMBOL_COLON + userId + createId);
  77. redisUtil.delete(RedisConf.USER_FIELD + RedisConf.SYMBOL_COLON + key);
  78. }
  79. public void setUserImportId(Integer userId, Integer importId) {
  80. redisUtil.set(RedisConf.USER_IMPORT + RedisConf.SYMBOL_COLON + userId, String.valueOf(importId));
  81. }
  82. public String getUserImportId(Integer userId) {
  83. return redisUtil.get(RedisConf.USER_IMPORT + RedisConf.SYMBOL_COLON + userId);
  84. }
  85. public void deleteUserImport(Integer userId) {
  86. redisUtil.delete(RedisConf.USER_IMPORT + RedisConf.SYMBOL_COLON + userId);
  87. }
  88. //添加自定义栏位顺序
  89. public void addPatentCustomField(Integer projectId, List<AllCustomFieldVO> allCustomFieldVOS) {
  90. redisUtil.set(RedisConf.PROJECT_FIELD_ORDER + projectId, JsonUtils.objectToJson(allCustomFieldVOS));
  91. }
  92. public List<AllCustomFieldVO> getPatentCustomField(Integer projectId) {
  93. String json = redisUtil.get(RedisConf.PROJECT_FIELD_ORDER + projectId);
  94. if (StringUtils.isEmpty(json)) {
  95. return null;
  96. } else {
  97. return JSON.parseArray(json,AllCustomFieldVO.class);
  98. }
  99. }
  100. //添加自定义栏位顺序
  101. public void addTaskCustomField(Integer taskId, List<AllCustomFieldVO> allCustomFieldVOS) {
  102. redisUtil.set(RedisConf.TASK_FIELD_ORDER + taskId, JsonUtils.objectToJson(allCustomFieldVOS));
  103. }
  104. public List<AllCustomFieldVO> getTaskCustomField(Integer taskId) {
  105. String json = redisUtil.get(RedisConf.TASK_FIELD_ORDER + taskId);
  106. if (StringUtils.isEmpty(json)) {
  107. return null;
  108. } else {
  109. return JSON.parseArray(json,AllCustomFieldVO.class);
  110. }
  111. }
  112. }