Forráskód Böngészése

feat(ActionCacheBuilder):动作配置缓存更新
fix(flow):修复设备拓展页流程选择问题

HMY 10 hónapja
szülő
commit
b59ae67ea4

+ 28 - 1
admin/src/main/java/com/dcs/hnyz/cache/builder/ActionCacheBuilder.java

@@ -1,5 +1,6 @@
 package com.dcs.hnyz.cache.builder;
 
+import com.dcs.hnyz.cache.CacheCenter;
 import com.dcs.hnyz.domain.bo.CachedAction;
 import com.dcs.hnyz.domain.condition.Condition;
 import com.dcs.hnyz.domain.ActionConfig;
@@ -61,6 +62,32 @@ public class ActionCacheBuilder {
         }
     }
 
-    //TODO 提供缓存更新方法
+    //缓存更新方法
+    public void updateCache(ActionConfig config) {
+        Condition condition = null;
+        try {
+            condition = ConditionParser.fromJsonString(config.getTriggerCondition());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        CachedAction cachedAction = new CachedAction();
+        cachedAction.setActionConfig(config);
+        cachedAction.setCondition(condition);
+        cachedAction.setTrigger(false);
+        cachedActionMap.put(config.getActionId(), cachedAction);
+    }
+    //缓存删除方法
+    public void deleteCache(long actionId) {
+        cachedActionMap.remove(actionId);
+    }
+    //缓存新增方法
+    public void addCache(ActionConfig config) throws Exception {
+        Condition condition = ConditionParser.fromJsonString(config.getTriggerCondition());
+        CachedAction cachedAction = new CachedAction();
+        cachedAction.setActionConfig(config);
+        cachedAction.setCondition(condition);
+        cachedAction.setTrigger(false);
+        cachedActionMap.put(config.getActionId(), cachedAction);
+    }
 
 }

+ 4 - 3
admin/src/main/java/com/dcs/hnyz/controller/FlowController.java

@@ -33,12 +33,13 @@ public class FlowController extends BaseController
     private IFlowService flowService;
 
     /**
-     * 获取流程列表(用于下拉框)需传一个参数equipmentId
+     * 获取流程列表(用于下拉框)
      */
     @GetMapping("/getFlowList")
     @ApiOperation(value = "获取设备对应流程列表(用于下拉框)")
-    public AjaxResult getFlowListByEquipmentId(@ApiParam(name = "equipmentId" ,value="设备id") Long equipmentId){
-        return success(flowService.getFlowListByEquipmentId(equipmentId));
+    public AjaxResult getFlowList(@ApiParam(name = "equipmentId" ,value="设备id") Long equipmentId,
+    @ApiParam(name="flowType" ,value = "流程类型")String flowType){
+        return success(flowService.getFlowList(equipmentId,flowType));
     }
 
     /**

+ 6 - 0
admin/src/main/java/com/dcs/hnyz/domain/Flow.java

@@ -35,6 +35,12 @@ public class Flow extends BaseEntity {
      */
     @Excel(name = "流程顺序")
     private Integer sort;
+
+    /**
+     * 流程类型 1普通流程 2组态页面流程
+     */
+    @Excel(name = "流程类型")
+    private String flowType;
     /**
      * 启用状态(0-启用,1-禁用)
      */

+ 2 - 1
admin/src/main/java/com/dcs/hnyz/service/IFlowService.java

@@ -68,7 +68,8 @@ public interface IFlowService
     /**
      * 根据设备id获取流程列表
      * @param equipmentId
+     * @param flowType 流程类型
      * @return
      */
-    List<Flow> getFlowListByEquipmentId(Long equipmentId);
+    List<Flow> getFlowList(Long equipmentId,String flowType);
 }

+ 41 - 5
admin/src/main/java/com/dcs/hnyz/service/impl/ActionConfigServiceImpl.java

@@ -90,7 +90,16 @@ public class ActionConfigServiceImpl implements IActionConfigService {
     @Override
     public int insertActionConfig(ActionConfig actionConfig) {
         actionConfig.setCreateTime(DateUtils.getNowDate());
-        return actionConfigMapper.insert(actionConfig);
+        int i = actionConfigMapper.insert(actionConfig);
+        if (i > 0) {//更新缓存
+            System.out.println(actionConfig);
+            try {
+                actionCacheBuilder.addCache(actionConfig);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+        return i;
     }
 
     /**
@@ -102,7 +111,15 @@ public class ActionConfigServiceImpl implements IActionConfigService {
     @Override
     public int updateActionConfig(ActionConfig actionConfig) {
         actionConfig.setUpdateTime(DateUtils.getNowDate());
-        return actionConfigMapper.updateById(actionConfig);
+        int i = actionConfigMapper.updateById(actionConfig);
+        if (i > 0) {//更新缓存
+            try {
+                actionCacheBuilder.updateCache(actionConfig);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+        return i;
     }
 
     /**
@@ -113,7 +130,18 @@ public class ActionConfigServiceImpl implements IActionConfigService {
      */
     @Override
     public int deleteActionConfigByActionIds(Long[] actionIds) {
-        return actionConfigMapper.deleteBatchIds(Arrays.asList(actionIds));
+        List<Long> idList = Arrays.asList(actionIds);
+        int i = actionConfigMapper.deleteBatchIds(idList);
+        if (i > 0) {
+            for (Long id : idList) {
+                try {
+                    actionCacheBuilder.deleteCache(id);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return i;
     }
 
     /**
@@ -124,7 +152,15 @@ public class ActionConfigServiceImpl implements IActionConfigService {
      */
     @Override
     public int deleteActionConfigByActionId(Long actionId) {
-        return actionConfigMapper.deleteById(actionId);
+        int i=actionConfigMapper.deleteById(actionId);
+        if (i > 0) {//更新缓存
+            try {
+                actionCacheBuilder.deleteCache(actionId);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+        return i;
     }
 
     /**
@@ -179,7 +215,7 @@ public class ActionConfigServiceImpl implements IActionConfigService {
     @Scheduled(fixedRate = 3000) // 每 3 秒执行一次
     public void checkActions() {
 //        模拟数据
-        EquipmentParamFormVo param = new EquipmentParamFormVo();
+//        EquipmentParamFormVo param = new EquipmentParamFormVo();
 //        param.setCode("D2kxh");
 //        param.setValue(true);
 //        CacheCenter.registerNowDataMap.put("D2kxh",param);

+ 7 - 2
admin/src/main/java/com/dcs/hnyz/service/impl/FlowServiceImpl.java

@@ -1,6 +1,7 @@
 package com.dcs.hnyz.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.dcs.common.enums.GeneralStatus;
 import com.dcs.hnyz.domain.Equipment;
 import com.dcs.hnyz.domain.Flow;
 import com.dcs.hnyz.mapper.FlowMapper;
@@ -114,9 +115,13 @@ public class FlowServiceImpl implements IFlowService
      * @return
      */
     @Override
-    public List<Flow> getFlowListByEquipmentId(Long equipmentId) {
+    public List<Flow> getFlowList(Long equipmentId,String flowType) {
+        LambdaQueryWrapper<Flow> wrapper=new LambdaQueryWrapper<>();
+        if(flowType!=null){
+            wrapper.eq(Flow::getFlowType,flowType);
+        }
         if(equipmentId==null){//不传设备id时默认查全部
-            return flowMapper.selectList(null);
+            return flowMapper.selectList(wrapper);
         }
         Equipment e = equipmentService.selectEquipmentByEquipmentId(equipmentId);
         String flowIds = e.getFlowIds();//获取流程ids

+ 6 - 3
ui/src/api/hnyz/flow.js

@@ -44,11 +44,14 @@ export function delFlow(flowId) {
 }
 
 //获取流程列表(下拉框)
-export function getFlowList(equipmentId) {
+export function getFlowList({ equipmentId, flowType }) {
   return request({
     url: '/hnyz/flow/getFlowList',
     method: 'get',
-    params: equipmentId
+    params: {
+      equipmentId: equipmentId,
+      flowType: flowType
+    }
   })
 }
 
@@ -56,7 +59,7 @@ export function getFlowList(equipmentId) {
 export function changeStatus(flowId, status) {
   return request({
     url: '/hnyz/flow/changeStatus',
-    method: 'put',    
+    method: 'put',
     data: {
       flowId: flowId,
       status: status