Răsfoiți Sursa

缓存修改

wangliang 1 an în urmă
părinte
comite
38f6171e01

+ 3 - 3
sop-api/src/main/java/com/qmth/sop/server/api/SysController.java

@@ -17,8 +17,8 @@ import com.qmth.sop.business.bean.result.*;
 import com.qmth.sop.business.cache.CommonCacheService;
 import com.qmth.sop.business.entity.*;
 import com.qmth.sop.business.service.*;
-import com.qmth.sop.business.util.CacheUtil;
 import com.qmth.sop.business.util.ImportExportUtil;
+import com.qmth.sop.business.util.SoftReferenceUtil;
 import com.qmth.sop.common.annotation.OperationLog;
 import com.qmth.sop.common.contant.SystemConstant;
 import com.qmth.sop.common.enums.*;
@@ -680,8 +680,8 @@ public class SysController {
     public Result getCache(@ApiParam(value = "业务类型") @RequestParam(required = false) String cacheName) {
         //        TBSession tbSession = (TBSession) cacheService.get(SystemConstant.SESSION, cacheName);
         //        Cache cache = cacheManager.getCache(SystemConstant.SESSION);
-        JSONArray jsonArray = CacheUtil.getAll();
-        Object o = CacheUtil.get(SystemConstant.SESSION + cacheName);
+        JSONArray jsonArray = SoftReferenceUtil.getAll();
+        Object o = SoftReferenceUtil.get(SystemConstant.SESSION + cacheName);
         TBSession tbSession = (TBSession) commonCacheService.getUserSession(cacheName);
         Map<String, Object> map = new HashMap<>();
         map.put("tbsession", tbSession);

+ 7 - 4
sop-business/src/main/java/com/qmth/sop/business/cache/impl/CommonCacheServiceImpl.java

@@ -11,7 +11,7 @@ import com.qmth.sop.business.bean.result.MenuResult;
 import com.qmth.sop.business.cache.CommonCacheService;
 import com.qmth.sop.business.entity.*;
 import com.qmth.sop.business.service.*;
-import com.qmth.sop.business.util.CacheUtil;
+import com.qmth.sop.business.util.SoftReferenceUtil;
 import com.qmth.sop.common.contant.SystemConstant;
 import com.qmth.sop.common.enums.ExceptionResultEnum;
 import com.qmth.sop.common.enums.PrivilegeEnum;
@@ -261,8 +261,9 @@ public class CommonCacheServiceImpl implements CommonCacheService {
      */
     @Override
     public void setUserSession(String sessionId, Object o) {
-        CacheUtil.set(SystemConstant.SESSION + sessionId, o, 60 * 24);
+        //        CacheUtil.set(SystemConstant.SESSION + sessionId, o, 60 * 24);
         //        cacheService.put(SystemConstant.SESSION, sessionId, o);
+        SoftReferenceUtil.set(SystemConstant.SESSION + sessionId, o);
     }
 
     /**
@@ -273,8 +274,9 @@ public class CommonCacheServiceImpl implements CommonCacheService {
      */
     @Override
     public Object getUserSession(String sessionId) {
-        return CacheUtil.get(SystemConstant.SESSION + sessionId);
+        //        return CacheUtil.get(SystemConstant.SESSION + sessionId);
         //        return cacheService.get(SystemConstant.SESSION, sessionId);
+        return SoftReferenceUtil.get(SystemConstant.SESSION + sessionId);
     }
 
     /**
@@ -284,8 +286,9 @@ public class CommonCacheServiceImpl implements CommonCacheService {
      */
     @Override
     public void deleteUserSession(String sessionId) {
-        CacheUtil.delete(SystemConstant.SESSION + sessionId);
+        //        CacheUtil.delete(SystemConstant.SESSION + sessionId);
         //        cacheService.evict(SystemConstant.SESSION, sessionId);
+        SoftReferenceUtil.remove(SystemConstant.SESSION + sessionId);
     }
 
     /**

+ 149 - 149
sop-business/src/main/java/com/qmth/sop/business/util/CacheUtil.java

@@ -1,149 +1,149 @@
-package com.qmth.sop.business.util;
-
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import com.github.benmanes.caffeine.cache.Cache;
-import com.github.benmanes.caffeine.cache.Caffeine;
-import com.github.benmanes.caffeine.cache.Expiry;
-import org.checkerframework.checker.index.qual.NonNegative;
-import org.checkerframework.checker.nullness.qual.NonNull;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Collection;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-
-import static java.util.Objects.isNull;
-
-/**
- * @Description: CAFFEINE缓存工具类
- * @Param:
- * @return:
- * @Author: wangliang
- * @Date: 2023/12/27
- */
-public class CacheUtil {
-
-    private final static Logger log = LoggerFactory.getLogger(CacheUtil.class);
-
-    /**
-     * 不设置过期时长
-     */
-    public static final long NOT_EXPIRE = Long.MAX_VALUE;
-
-    public static final Cache<String, CacheObject<?>> CAFFEINE = Caffeine.newBuilder()
-            .expireAfter(new Expiry<String, CacheObject<?>>() {
-
-                @Override
-                public long expireAfterCreate(@NonNull String key, @NonNull CacheObject<?> value, long currentTime) {
-                    return value.expire;
-                }
-
-                @Override
-                public long expireAfterUpdate(@NonNull String key, @NonNull CacheObject<?> value, long currentTime,
-                        @NonNegative long currentDuration) {
-                    return value.expire;
-                }
-
-                @Override
-                public long expireAfterRead(@NonNull String key, @NonNull CacheObject<?> value, long currentTime,
-                        @NonNegative long currentDuration) {
-                    return value.expire;
-                }
-            }).initialCapacity(100).maximumSize(1024).build();
-
-    private static class CacheObject<T> {
-
-        T data;
-
-        long expire;
-
-        public CacheObject(T data, long second) {
-            this.data = data;
-            this.expire = TimeUnit.SECONDS.toNanos(second);
-        }
-    }
-
-    public static <T> void set(String key, T value, long expire) {
-        CacheObject<T> cacheObject = new CacheObject<>(value, expire);
-        CAFFEINE.put(key, cacheObject);
-    }
-
-    public static void set(String key, Object value) {
-        set(key, value, NOT_EXPIRE);
-    }
-
-    @SuppressWarnings("unchecked")
-    public static <T> T get(String key) {
-        CacheObject<?> cacheObject = CAFFEINE.getIfPresent(key);
-        if (isNull(cacheObject)) {
-            return null;
-        }
-        return (T) cacheObject.data;
-    }
-
-    public static void delete(String key) {
-        CAFFEINE.invalidate(key);
-    }
-
-    public static void delete(Collection<String> keys) {
-        CAFFEINE.invalidateAll(keys);
-    }
-
-    public static JSONArray getAll() {
-        Map map = CAFFEINE.asMap();
-        JSONArray jsonArray = new JSONArray();
-        for (Object key : map.keySet()) {
-            CacheObject cacheObject = (CacheObject) map.get(key);
-            JSONObject jsonObject = new JSONObject();
-            jsonObject.put(key.toString(), cacheObject.data + ";" + TimeUnit.SECONDS.toMinutes(cacheObject.expire));
-            jsonArray.add(jsonObject);
-        }
-        return jsonArray;
-    }
-
-    //    public static void main(String[] args) throws InterruptedException {
-    //        CacheUtil.set("A", 1, 2 * 60);
-    //        CacheUtil.set("B", 2, 5 * 60);
-    //        CacheUtil.set("C", 3, 8 * 60);
-    //
-    //        Map map = CAFFEINE.asMap();
-    //        for (Object key : map.keySet()) {
-    //            CacheObject cacheObject = (CacheObject) map.get(key);
-    //            System.out.println(key + "," + cacheObject.data + "," + TimeUnit.SECONDS.toMinutes(cacheObject.expire));
-    //        }
-    //        Object a = CacheUtil.get("A");
-    //        Object b = CacheUtil.get("B");
-    //        Object c = CacheUtil.get("C");
-    //        System.out.println(a);
-    //        System.out.println(b);
-    //        System.out.println(c);
-    //        System.out.println("-----------------");
-    //        Thread.sleep(2000);
-    //
-    //        a = CacheUtil.get("A");
-    //        b = CacheUtil.get("B");
-    //        c = CacheUtil.get("C");
-    //        System.out.println(a);
-    //        System.out.println(b);
-    //        System.out.println(c);
-    //        System.out.println("-----------------");
-    //        Thread.sleep(5000);
-    //        a = CacheUtil.get("A");
-    //        b = CacheUtil.get("B");
-    //        c = CacheUtil.get("C");
-    //        System.out.println(a);
-    //        System.out.println(b);
-    //        System.out.println(c);
-    //        System.out.println("-----------------");
-    //        Thread.sleep(1000 * 120);
-    //        a = CacheUtil.get("A");
-    //        b = CacheUtil.get("B");
-    //        c = CacheUtil.get("C");
-    //        System.out.println(a);
-    //        System.out.println(b);
-    //        System.out.println(c);
-    //        System.out.println("-----------------");
-    //    }
-}
+//package com.qmth.sop.business.util;
+//
+//import com.alibaba.fastjson.JSONArray;
+//import com.alibaba.fastjson.JSONObject;
+//import com.github.benmanes.caffeine.cache.Cache;
+//import com.github.benmanes.caffeine.cache.Caffeine;
+//import com.github.benmanes.caffeine.cache.Expiry;
+//import org.checkerframework.checker.index.qual.NonNegative;
+//import org.checkerframework.checker.nullness.qual.NonNull;
+//import org.slf4j.Logger;
+//import org.slf4j.LoggerFactory;
+//
+//import java.util.Collection;
+//import java.util.Map;
+//import java.util.concurrent.TimeUnit;
+//
+//import static java.util.Objects.isNull;
+//
+///**
+// * @Description: CAFFEINE缓存工具类
+// * @Param:
+// * @return:
+// * @Author: wangliang
+// * @Date: 2023/12/27
+// */
+//public class CacheUtil {
+//
+//    private final static Logger log = LoggerFactory.getLogger(CacheUtil.class);
+//
+//    /**
+//     * 不设置过期时长
+//     */
+//    public static final long NOT_EXPIRE = Long.MAX_VALUE;
+//
+//    public static final Cache<String, CacheObject<?>> CAFFEINE = Caffeine.newBuilder()
+//            .expireAfter(new Expiry<String, CacheObject<?>>() {
+//
+//                @Override
+//                public long expireAfterCreate(@NonNull String key, @NonNull CacheObject<?> value, long currentTime) {
+//                    return value.expire;
+//                }
+//
+//                @Override
+//                public long expireAfterUpdate(@NonNull String key, @NonNull CacheObject<?> value, long currentTime,
+//                        @NonNegative long currentDuration) {
+//                    return value.expire;
+//                }
+//
+//                @Override
+//                public long expireAfterRead(@NonNull String key, @NonNull CacheObject<?> value, long currentTime,
+//                        @NonNegative long currentDuration) {
+//                    return value.expire;
+//                }
+//            }).initialCapacity(100).maximumSize(1024).build();
+//
+//    private static class CacheObject<T> {
+//
+//        T data;
+//
+//        long expire;
+//
+//        public CacheObject(T data, long second) {
+//            this.data = data;
+//            this.expire = TimeUnit.SECONDS.toNanos(second);
+//        }
+//    }
+//
+//    public static <T> void set(String key, T value, long expire) {
+//        CacheObject<T> cacheObject = new CacheObject<>(value, expire);
+//        CAFFEINE.put(key, cacheObject);
+//    }
+//
+//    public static void set(String key, Object value) {
+//        set(key, value, NOT_EXPIRE);
+//    }
+//
+//    @SuppressWarnings("unchecked")
+//    public static <T> T get(String key) {
+//        CacheObject<?> cacheObject = CAFFEINE.getIfPresent(key);
+//        if (isNull(cacheObject)) {
+//            return null;
+//        }
+//        return (T) cacheObject.data;
+//    }
+//
+//    public static void delete(String key) {
+//        CAFFEINE.invalidate(key);
+//    }
+//
+//    public static void delete(Collection<String> keys) {
+//        CAFFEINE.invalidateAll(keys);
+//    }
+//
+//    public static JSONArray getAll() {
+//        Map map = CAFFEINE.asMap();
+//        JSONArray jsonArray = new JSONArray();
+//        for (Object key : map.keySet()) {
+//            CacheObject cacheObject = (CacheObject) map.get(key);
+//            JSONObject jsonObject = new JSONObject();
+//            jsonObject.put(key.toString(), cacheObject.data + ";" + TimeUnit.SECONDS.toMinutes(cacheObject.expire));
+//            jsonArray.add(jsonObject);
+//        }
+//        return jsonArray;
+//    }
+//
+//    //    public static void main(String[] args) throws InterruptedException {
+//    //        CacheUtil.set("A", 1, 2 * 60);
+//    //        CacheUtil.set("B", 2, 5 * 60);
+//    //        CacheUtil.set("C", 3, 8 * 60);
+//    //
+//    //        Map map = CAFFEINE.asMap();
+//    //        for (Object key : map.keySet()) {
+//    //            CacheObject cacheObject = (CacheObject) map.get(key);
+//    //            System.out.println(key + "," + cacheObject.data + "," + TimeUnit.SECONDS.toMinutes(cacheObject.expire));
+//    //        }
+//    //        Object a = CacheUtil.get("A");
+//    //        Object b = CacheUtil.get("B");
+//    //        Object c = CacheUtil.get("C");
+//    //        System.out.println(a);
+//    //        System.out.println(b);
+//    //        System.out.println(c);
+//    //        System.out.println("-----------------");
+//    //        Thread.sleep(2000);
+//    //
+//    //        a = CacheUtil.get("A");
+//    //        b = CacheUtil.get("B");
+//    //        c = CacheUtil.get("C");
+//    //        System.out.println(a);
+//    //        System.out.println(b);
+//    //        System.out.println(c);
+//    //        System.out.println("-----------------");
+//    //        Thread.sleep(5000);
+//    //        a = CacheUtil.get("A");
+//    //        b = CacheUtil.get("B");
+//    //        c = CacheUtil.get("C");
+//    //        System.out.println(a);
+//    //        System.out.println(b);
+//    //        System.out.println(c);
+//    //        System.out.println("-----------------");
+//    //        Thread.sleep(1000 * 120);
+//    //        a = CacheUtil.get("A");
+//    //        b = CacheUtil.get("B");
+//    //        c = CacheUtil.get("C");
+//    //        System.out.println(a);
+//    //        System.out.println(b);
+//    //        System.out.println(c);
+//    //        System.out.println("-----------------");
+//    //    }
+//}

+ 59 - 0
sop-business/src/main/java/com/qmth/sop/business/util/SoftReferenceUtil.java

@@ -0,0 +1,59 @@
+package com.qmth.sop.business.util;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.qmth.sop.common.util.JacksonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.ref.SoftReference;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * @Description: 软引用缓存
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2023/12/27
+ */
+public class SoftReferenceUtil {
+
+    private final static Logger log = LoggerFactory.getLogger(SoftReferenceUtil.class);
+
+    private static ConcurrentHashMap<String, SoftReference<Object>> softReferenceMap = new ConcurrentHashMap<>();
+
+    public static void set(String key, Object o) {
+        softReferenceMap.put(key, new SoftReference<>(o));
+    }
+
+    public static Object get(String key) {
+        return Objects.nonNull(softReferenceMap.get(key)) ? softReferenceMap.get(key).get() : null;
+    }
+
+    public static void remove(String key) {
+        softReferenceMap.remove(key);
+    }
+
+    public static JSONArray getAll() {
+        JSONArray jsonArray = new JSONArray();
+        for (Object key : softReferenceMap.keySet()) {
+            Object o = softReferenceMap.get(key).get();
+            JSONObject jsonObject = new JSONObject();
+            jsonObject.put(key.toString(), JacksonUtil.parseJson(o));
+            jsonArray.add(jsonObject);
+        }
+        return jsonArray;
+    }
+
+//    public static void main(String[] args) {
+//        SoftReferenceUtil.set("A", 1);
+//        SoftReferenceUtil.set("B", 2);
+//        System.out.println(SoftReferenceUtil.get("A"));
+//        System.out.println(SoftReferenceUtil.get("B"));
+//        JSONArray jsonArray = SoftReferenceUtil.getAll();
+//        System.out.println(jsonArray.toJSONString());
+//        SoftReferenceUtil.remove("B");
+//        System.out.println(SoftReferenceUtil.get("B"));
+//    }
+}

+ 3 - 0
sop-business/src/main/resources/mapper/TBSopInfoMapper.xml

@@ -202,6 +202,8 @@
         left join t_b_crm tbc on tbc.crm_no = tbsi.crm_no
         left join sys_custom sc on sc.id = tbsi.custom_id
         left join t_b_service tbs on tbs.id = tbsi.service_id
+        left join t_f_custom_flow_entity tfcfe on tfcfe.code = tbsi.sop_no
+        left join t_f_flow_approve tffa on tffa.flow_id = tfcfe.flow_id
         <where>
             <if test="userId != null and userId != ''">
                 <choose>
@@ -217,6 +219,7 @@
                 and tbsi.service_id = #{serviceId}
             </if>
                 and tbsi.status = 'START'
+                and tffa.status not in('END')
         </where>
     </select>