Browse Source

添加晋能数据权限过滤

shilin 1 year ago
parent
commit
eddbe29447

+ 6 - 0
web/runeconomy-xk/src/main/java/com/gyee/runeconomy/controller/AuthController.java

@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
 
 import javax.annotation.Resource;
+import java.util.Date;
 
 @Controller
 @RequestMapping("/auth")
@@ -32,8 +33,11 @@ public class AuthController {
         if (StringUtils.notEmp(tokenVo)) {
 
             if (!tokenService.sessionMap.containsKey(tokenVo.getToken())) {
+                tokenVo.setTime(new Date());
                 tokenService.sessionMap.put(tokenVo.getToken(), tokenVo);
             }
+
+            tokenService.judegeSession();
         }
 
         return R.data(ResultMsg.ok("ok"));
@@ -67,6 +71,8 @@ public class AuthController {
 
         }
 
+        tokenService.judegeSession();
+
         return R.data(ResultMsg.ok("ok"));
     }
 

+ 36 - 36
web/runeconomy-xk/src/main/java/com/gyee/runeconomy/init/CacheContext.java

@@ -27,53 +27,53 @@ import java.util.stream.Collectors;
 public class CacheContext implements CommandLineRunner {
     Logger logger = LoggerFactory.getLogger(CacheContext.class);
 
-    public final String QS = "0";
+    private final String QS = "0";
 
     @Resource
-    public IProBasicEquipmentService proBasicEquipmentService;
+    private IProBasicEquipmentService proBasicEquipmentService;
     @Resource
-    public IProBasicLineService proBasicLineService;
+    private IProBasicLineService proBasicLineService;
     @Resource
-    public IProBasicProjectService proBasicProjectService;
+    private IProBasicProjectService proBasicProjectService;
 
     @Resource
-    public IProBasicPowerstationService proBasicWindpowerstationService;
+    private IProBasicPowerstationService proBasicWindpowerstationService;
     @Resource
-    public IProBasicMeterPointService proBasicMeterPointService;
+    private IProBasicMeterPointService proBasicMeterPointService;
     @Resource
-    public IProEconEquipmentmodelService proEconEquipmentmodelService;
+    private IProEconEquipmentmodelService proEconEquipmentmodelService;
 
     @Resource
-    public IProBasicWindturbinePowerService proBasicWindturbinePowerService;
+    private IProBasicWindturbinePowerService proBasicWindturbinePowerService;
     @Resource
-    public RedisService redisService;
+    private RedisService redisService;
     @Resource
-    public IProBasicModelPowerService proBasicModelPowerService;
+    private IProBasicModelPowerService proBasicModelPowerService;
     @Resource
-    public IProBasicSubStationService proBasicSubStationService;
+    private IProBasicSubStationService proBasicSubStationService;
     @Resource
-    public IProBasicWeatherStationService proBasicWeatherStationService;
+    private IProBasicWeatherStationService proBasicWeatherStationService;
     @Resource
-    public IProBasicSquareService proBasicSquareService;
+    private IProBasicSquareService proBasicSquareService;
     @Resource
-    public IProBasicCompanyService proBasicCompanyService;
+    private IProBasicCompanyService proBasicCompanyService;
     @Resource
-    public IProBasicRegionService proBasicRegionService;
+    private IProBasicRegionService proBasicRegionService;
     @Resource
-    public IProBasicEnergyGroupService proBasicEnergyGroupService;
+    private IProBasicEnergyGroupService proBasicEnergyGroupService;
     @Resource
-    public IProBasicBranchService proBasicBranchService;
+    private IProBasicBranchService proBasicBranchService;
     @Resource
-    public TheoreticalPowerService theoreticalPowerService;
+    private TheoreticalPowerService theoreticalPowerService;
 
     @Resource
-    public IProBasicModelPowerRdService proBasicModelPowerRdService;
+    private IProBasicModelPowerRdService proBasicModelPowerRdService;
 
     @Resource
-    public IProBasicPowerstationPointService proBasicPowerstationPointService;
+    private IProBasicPowerstationPointService proBasicPowerstationPointService;
 
     @Resource
-    public IProBasicEquipmentPointService proBasicEquipmentPointService;
+    private IProBasicEquipmentPointService proBasicEquipmentPointService;
 
 
 
@@ -160,21 +160,21 @@ public class CacheContext implements CommandLineRunner {
         logger.info("缓存开始------------------------------------------------------------");
 
 
-//        bnls = proBasicBranchService.list();
-//        bnls.stream().forEach(bn->{
-//            String bnString = redisService.get(bn.getId());
-//            Map<String, ProBasicEquipmentPoint> stringWindturbinetestingpointnewMap = JSONObject.parseObject(bnString, new TypeReference<Map<String, ProBasicEquipmentPoint>>() {
-//            });
-//            bnAimap.put(bn.getId(),stringWindturbinetestingpointnewMap);
-//
-//            if (wtbnmap.containsKey(bn.getInteverId())){
-//                wtbnmap.get(bn.getInteverId()).add(bn);
-//            }else {
-//                List<ProBasicBranch> bns = new ArrayList<>();
-//                bns.add(bn);
-//                wtbnmap.put(bn.getInteverId(),bns);
-//            }
-//        });
+        bnls = proBasicBranchService.list();
+        bnls.stream().forEach(bn->{
+            String bnString = redisService.get(bn.getId());
+            Map<String, ProBasicEquipmentPoint> stringWindturbinetestingpointnewMap = JSONObject.parseObject(bnString, new TypeReference<Map<String, ProBasicEquipmentPoint>>() {
+            });
+            bnAimap.put(bn.getId(),stringWindturbinetestingpointnewMap);
+
+            if (wtbnmap.containsKey(bn.getInteverId())){
+                wtbnmap.get(bn.getInteverId()).add(bn);
+            }else {
+                List<ProBasicBranch> bns = new ArrayList<>();
+                bns.add(bn);
+                wtbnmap.put(bn.getInteverId(),bns);
+            }
+        });
 
         equipmentmodels = proEconEquipmentmodelService.list();
         equipmentmodels.stream().forEach(e->{

+ 3 - 0
web/runeconomy-xk/src/main/java/com/gyee/runeconomy/model/vo/TokenVo.java

@@ -4,6 +4,8 @@ import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
+import java.util.Date;
+
 @Data
 @NoArgsConstructor
 @AllArgsConstructor
@@ -11,4 +13,5 @@ public class TokenVo {
 
     private String token;
     private  String userId;
+    private Date time;
 }

+ 38 - 0
web/runeconomy-xk/src/main/java/com/gyee/runeconomy/service/TokenService.java

@@ -1,6 +1,7 @@
 package com.gyee.runeconomy.service;
 
 import com.gyee.common.model.StringUtils;
+import com.gyee.health.util.DateUtils;
 import com.gyee.runeconomy.init.CacheContext;
 import com.gyee.runeconomy.model.auto.*;
 import com.gyee.runeconomy.model.vo.TokenVo;
@@ -10,6 +11,7 @@ import org.springframework.stereotype.Service;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -26,6 +28,42 @@ public class TokenService {
     public static Map<String, List<ProBasicWeatherStation>> sessionWeMap = new ConcurrentHashMap<>();
 
     public static Map<String, TokenVo> sessionMap=  new ConcurrentHashMap<>();
+
+
+    public void  judegeSession() {
+
+
+
+        for (Map.Entry <String, TokenVo>  entry : sessionMap.entrySet()) {
+            TokenVo vo=entry.getValue();
+            
+            Date begin=vo.getTime();
+            Date end=new Date();
+
+            double value=DateUtils.hoursDiff(begin,end);
+            if(value>3)
+            {
+                sessionMap.remove(entry.getKey());
+
+                if (sessionWtMap.containsKey(entry.getKey())) {
+                    sessionWtMap.remove(entry.getKey());
+                }
+                if (sessionWpMap.containsKey(entry.getKey())) {
+                    sessionWpMap.remove(entry.getKey());
+
+                }
+                if (sessionSubMap.containsKey(entry.getKey())) {
+                    sessionSubMap.remove(entry.getKey());
+
+                }
+                if (sessionWeMap.containsKey(entry.getKey())) {
+                    sessionWeMap.remove(entry.getKey());
+
+                }
+            }
+        }
+
+    }
     public  List<ProBasicEquipment>  getWtls(HttpServletRequest request ) {
 
         String token = request.getHeader("token");