瀏覽代碼

plc策略详情、plc分组策略

zhj 2 年之前
父節點
當前提交
bdb7fb46d3

+ 171 - 2
src/main/java/com/welampiot/controller/PlcPolicyController.java

@@ -3,11 +3,13 @@ package com.welampiot.controller;
 import com.welampiot.common.BaseResult;
 import com.welampiot.common.InterfaceResultEnum;
 import com.welampiot.dto.*;
+import com.welampiot.service.GroupService;
 import com.welampiot.service.PlcPolicyCmdService;
 import com.welampiot.service.PlcPolicyService;
 import com.welampiot.service.UserService;
 import com.welampiot.utils.ToolUtils;
 import com.welampiot.vo.PlcPolicyVO;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.CrossOrigin;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -44,6 +46,9 @@ public class PlcPolicyController {
     @Autowired
     private UserService userService;
 
+    @Autowired
+    private GroupService groupService;
+
     /**
      * plc添加/编辑策略
      * @param vo PlcPolicyVO
@@ -322,12 +327,176 @@ public class PlcPolicyController {
      */
     @RequestMapping(value = "/del", method = RequestMethod.POST)
     public BaseResult<?> del(PlcPolicyVO vo) throws NoSuchFieldException, IllegalAccessException {
-        PlcPolicyVO policyVO = PlcPolicyVO.getDefaultPlcPolicyVO(vo);
+        PlcPolicyVO policyVO = PlcPolicyVO.getPlcPolicyVO(vo);
         Integer version = policyVO.getVersion();
         Integer id = policyVO.getId();
-        if (id == null) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
+        if (id == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
         plcPolicyService.deletePlcPolicyDataById(id);
         plcPolicyCmdService.deletePlcPolicyCmdByPlcPolicyId(id);
         return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
     }
+
+    /**
+     * plc策略详情
+     * @param vo plc策略id
+     * @return plc策略详情
+     */
+    @RequestMapping(value = "/details", method = RequestMethod.POST)
+    public BaseResult<?> details(PlcPolicyVO vo) throws NoSuchFieldException, IllegalAccessException {
+        PlcPolicyVO policyVO = PlcPolicyVO.getPlcPolicyVO(vo);
+        Integer version = policyVO.getVersion();
+        Integer id = policyVO.getId();
+        if (id == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
+        PlcPolicyDTO plcPolicyDTO = plcPolicyService.getPlcPolicyDetailById(id);
+        if (plcPolicyDTO == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version);
+        List<PlcPolicyCmdDTO> plcPolicyCmdList = plcPolicyCmdService.getPlcPolicyCmdByPolicyId(id);
+        List<PlcPolicyContentDTO> dataList = new ArrayList<>();
+        for (PlcPolicyCmdDTO p : plcPolicyCmdList) {
+            plcPolicyDTO.setLighterMask(p.getLighterMask());
+            PlcPolicyContentDTO contentDTO = new PlcPolicyContentDTO();
+            contentDTO.setWeekly(p.getWeekly());
+            contentDTO.setBaseTimeType(p.getBaseTimeType());
+            List<PlcPolicyValueDTO> timeList = new ArrayList<>();
+            if (p.getBaseTimeType() == 0) { // 零点
+                for (int i = 1; i <= 6; i ++) {
+                    Field fieldTime = p.getClass().getDeclaredField("startTime" + i);
+                    fieldTime.setAccessible(true);
+                    String startTime = (String) fieldTime.get(p);
+                    if (startTime == null || startTime.isEmpty()) break;
+                    // 第一段时间亮度
+                    Field fieldBright = p.getClass().getDeclaredField("bright" + i);
+                    fieldBright.setAccessible(true);
+                    Integer bright = (Integer) fieldBright.get(p);
+                    // 第一段时间色温
+                    Field fieldColor = p.getClass().getDeclaredField("color" + i);
+                    fieldColor.setAccessible(true);
+                    Integer color = (Integer) fieldColor.get(p);
+                    PlcPolicyValueDTO valueDTO = new PlcPolicyValueDTO();
+                    valueDTO.setTime(startTime);
+                    valueDTO.setLight(bright);
+                    valueDTO.setColor(color);
+                    timeList.add(valueDTO);
+                    // 第二段时间
+                    Field fieldEndTime = p.getClass().getDeclaredField("endTime" + i);
+                    fieldEndTime.setAccessible(true);
+                    String endTime = (String) fieldEndTime.get(p);
+                    if (endTime == null || endTime.isEmpty()) break;
+                    // 第二段时间亮度
+                    Field fieldEndBright = p.getClass().getDeclaredField("endBright" + i);
+                    fieldEndBright.setAccessible(true);
+                    Integer endBright = (Integer) fieldEndBright.get(p);
+                    // 第二段时间色温
+                    Field fieldEndColor = p.getClass().getDeclaredField("endColor" + i);
+                    fieldEndColor.setAccessible(true);
+                    Integer endColor = (Integer) fieldEndColor.get(p);
+                    PlcPolicyValueDTO valueDTO1 = new PlcPolicyValueDTO();
+                    valueDTO1.setTime(endTime);
+                    valueDTO1.setLight(endBright);
+                    valueDTO1.setColor(endColor);
+                    timeList.add(valueDTO1);
+                }
+            } else { // 日出日落
+                PlcPolicyValueDTO valueDTO = new PlcPolicyValueDTO();
+                valueDTO.setBaseTime(1);
+                valueDTO.setTime(p.getStartDelayTime());
+                valueDTO.setLight(p.getStartBright());
+                valueDTO.setColor(p.getStartColor());
+                timeList.add(valueDTO);
+                valueDTO = new PlcPolicyValueDTO();
+                valueDTO.setBaseTime(2);
+                valueDTO.setTime(p.getEndDelayTime());
+                valueDTO.setLight(p.getEndBright());
+                valueDTO.setColor(p.getEndColor());
+                timeList.add(valueDTO);
+            }
+            contentDTO.setTimeList(timeList);
+            dataList.add(contentDTO);
+        }
+        plcPolicyDTO.setContent(dataList);
+        PlcPolicyVO plcPolicyVO = new PlcPolicyVO();
+        BeanUtils.copyProperties(plcPolicyDTO,plcPolicyVO);
+        plcPolicyVO.setDataList(plcPolicyDTO.getContent());
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,plcPolicyVO);
+    }
+
+    /**
+     * plc分组策略
+     * @param vo groupId
+     * @return plc分组策略
+     */
+    @RequestMapping(value = "/groupSetList", method = RequestMethod.POST)
+    public BaseResult<?> groupSetList(PlcPolicyVO vo) throws NoSuchFieldException, IllegalAccessException {
+        PlcPolicyVO policyVO = PlcPolicyVO.getPlcPolicyVO(vo);
+        Integer version = policyVO.getVersion();
+        Integer groupId = policyVO.getGroupId();
+        if (groupId == null) groupId = 0;
+        String username = policyVO.getUsername();
+        if (username == null || username.isEmpty())
+            return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
+        UserDTO userDTO = userService.queryUserIdByUsername(username);
+        if (userDTO == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version);
+        policyVO.setUserid(userDTO.getId());
+        List<PlcPolicyDTO> policyList;
+        if (userDTO.getRole() == 1) { // 超管获取全部的策略列表
+            policyList = plcPolicyService.getAllPlcPolicyList(policyVO);
+        } else {
+            policyList = plcPolicyService.getPlcPolicyList(policyVO);
+            if (policyList == null || policyList.isEmpty()) {
+                PlcPolicyVO plcPolicyVO = new PlcPolicyVO();
+                plcPolicyVO.setList(policyList);
+                return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,plcPolicyVO);
+            }
+        }
+        if (groupId == 0) {
+            policyList.forEach(dto -> dto.setSelect(0));
+        } else {
+            GroupDTO groupDTO = groupService.getGroupDTOById(groupId);
+            if (groupDTO == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version);
+            if (groupDTO.getType() != null && groupDTO.getType() == 3) {
+                for (PlcPolicyDTO p : policyList) {
+                    if (p.getId().equals(groupDTO.getValue())) {
+                        p.setSelect(1);
+                    } else {
+                        p.setSelect(0);
+                    }
+                }
+            } else  {
+                policyList.forEach(dto -> dto.setSelect(0));
+            }
+        }
+        List<String> ids = new ArrayList<>();
+        policyList.forEach(dto -> ids.add(String.valueOf(dto.getId())));
+        List<PlcPolicyCmdDTO> cmdList = plcPolicyCmdService.getPlcPolicyCmdListByPolicyId(ids);
+        for (PlcPolicyDTO dto : policyList) {
+            List<PlcPolicyContentDTO> contentList = new ArrayList<>();
+            for (PlcPolicyCmdDTO p : cmdList) {
+                if (dto.getId().equals(p.getPlcPolicyId())) {
+                    dto.setLighterMask(p.getLighterMask());
+                    Integer baseTimeType = p.getBaseTimeType();
+                    PlcPolicyContentDTO contentDTO = new PlcPolicyContentDTO();
+                    contentDTO.setBaseTimeType(baseTimeType);
+                    List<String> value;
+                    if (dto.getPolicyType() == 0) { // 日常
+                        value = ToolUtils.getPlcPolicyValue(p);
+                    } else if (dto.getPolicyType() == 1) { // 周期
+                        Integer weekly = p.getWeekly();
+                        value = ToolUtils.getPlcPolicyValue(p);
+                        contentDTO.setWeekly(weekly);
+                    } else { // 假期
+                        String holidayDate = p.getHolidayDate();
+                        Integer holidayDay = p.getHolidayDay();
+                        value = ToolUtils.getPlcPolicyValue(p);
+                        contentDTO.setHolidayDate(holidayDate);
+                        contentDTO.setHolidayDay(holidayDay);
+                    }
+                    contentDTO.setValue(value);
+                    contentList.add(contentDTO);
+                }
+            }
+            dto.setContent(contentList);
+        }
+        PlcPolicyVO plcPolicyVO = new PlcPolicyVO();
+        plcPolicyVO.setList(policyList);
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,plcPolicyVO);
+    }
 }

+ 2 - 0
src/main/java/com/welampiot/dao/PlcPolicyCmdDao.java

@@ -22,4 +22,6 @@ public interface PlcPolicyCmdDao {
     void deletePlcPolicyCmdByPlcPolicyId(@Param("plcPolicyId") Integer plcPolicyId);
 
     List<PlcPolicyCmdDTO> getPlcPolicyCmdListByPolicyId(@Param("policyIds") List<String> policyIds);
+
+    List<PlcPolicyCmdDTO> getPlcPolicyCmdByPolicyId(@Param("policyId") Integer policyId);
 }

+ 2 - 0
src/main/java/com/welampiot/dao/PlcPolicyDao.java

@@ -29,4 +29,6 @@ public interface PlcPolicyDao {
     Integer getAllPlcPolicyTotal();
 
     void deletePlcPolicyDataById(@Param("id") Integer id);
+
+    PlcPolicyDTO getPlcPolicyDetailById(@Param("id") Integer id);
 }

+ 2 - 0
src/main/java/com/welampiot/dto/PlcPolicyDTO.java

@@ -32,5 +32,7 @@ public class PlcPolicyDTO implements Serializable {
 
     private Integer baseTimeType;
 
+    private Integer select;
+
     private List<PlcPolicyContentDTO> content;
 }

+ 2 - 0
src/main/java/com/welampiot/service/PlcPolicyCmdService.java

@@ -21,4 +21,6 @@ public interface PlcPolicyCmdService {
     void deletePlcPolicyCmdByPlcPolicyId(Integer plcPolicyId);
 
     List<PlcPolicyCmdDTO> getPlcPolicyCmdListByPolicyId(List<String> policyIds);
+
+    List<PlcPolicyCmdDTO> getPlcPolicyCmdByPolicyId(Integer policyId);
 }

+ 2 - 0
src/main/java/com/welampiot/service/PlcPolicyService.java

@@ -29,4 +29,6 @@ public interface PlcPolicyService {
     Integer getAllPlcPolicyTotal();
 
     void deletePlcPolicyDataById(Integer id);
+
+    PlcPolicyDTO getPlcPolicyDetailById(Integer id);
 }

+ 5 - 0
src/main/java/com/welampiot/service/impl/PlcPolicyCmdServiceImpl.java

@@ -41,4 +41,9 @@ public class PlcPolicyCmdServiceImpl implements PlcPolicyCmdService {
     public List<PlcPolicyCmdDTO> getPlcPolicyCmdListByPolicyId(List<String> policyIds) {
         return plcPolicyCmdDao.getPlcPolicyCmdListByPolicyId(policyIds);
     }
+
+    @Override
+    public List<PlcPolicyCmdDTO> getPlcPolicyCmdByPolicyId(Integer policyId) {
+        return plcPolicyCmdDao.getPlcPolicyCmdByPolicyId(policyId);
+    }
 }

+ 5 - 0
src/main/java/com/welampiot/service/impl/PlcPolicyServiceImpl.java

@@ -57,4 +57,9 @@ public class PlcPolicyServiceImpl implements PlcPolicyService {
     public void deletePlcPolicyDataById(Integer id) {
         plcPolicyDao.deletePlcPolicyDataById(id);
     }
+
+    @Override
+    public PlcPolicyDTO getPlcPolicyDetailById(Integer id) {
+        return plcPolicyDao.getPlcPolicyDetailById(id);
+    }
 }

+ 2 - 0
src/main/java/com/welampiot/vo/PlcPolicyVO.java

@@ -24,6 +24,8 @@ public class PlcPolicyVO implements Serializable {
 
     private Integer id;
 
+    private Integer groupId;
+
     private String name;
 
     private String username;

+ 3 - 1
src/main/resources/mapper/GroupMapper.xml

@@ -187,7 +187,9 @@
             g.id,
             g.lampid as lampId,
             g.devType,
-            g.patrolinterval as patrolInterval
+            g.patrolinterval as patrolInterval,
+            g.type,
+            g.value
         from `group` g
         where g.id = #{id}
     </select>

+ 17 - 0
src/main/resources/mapper/PlcPolicyCmdMapper.xml

@@ -130,4 +130,21 @@
         </foreach>
     </select>
 
+    <select id="getPlcPolicyCmdByPolicyId" resultType="PlcPolicyCmdDTO">
+        select
+        p.id, p.plc_policy_id as plcPolicyId, p.policyType, p.base_time_type as baseTimeType,
+        p.lighter_mask as lighterMask, p.starttime1 as startTime1, p.bright1, p.color1,
+        p.endtime1 as endTime1,p.end_bright1 as endBright1, p.end_color1 as endColor1,
+        p.starttime2 as startTime2, p.bright2, p.color2, p.endtime2 as endTime2, p.end_bright2 as endBright2, p.end_color2 as endColor2,
+        p.starttime3 as startTime3, p.endtime3 as endTime3, p.bright3, p.color3, p.end_bright3 as endBright3, p.end_color3 as endColor3,
+        p.starttime4 as startTime4, p.endtime4 as endTime4, p.bright4, p.color4, p.end_bright4 as endBright4, p.end_color4 as endColor4,
+        p.starttime5 as startTime5, p.endtime5 as endTime5, p.bright5, p.color5, p.end_bright5 as endBright5, p.end_color5 as endColor5,
+        p.starttime6 as startTime6, p.endtime6 as endTime6, p.bright6, p.color6, p.end_bright6 as endBright6, p.end_color6 as endColor6,
+        p.sunrise, p.start_delay_time as startDelayTime, p.start_bright as startBright, p.start_color as startColor,
+        p.sunset, p.end_delay_time as endDelayTime, p.end_bright as endBright, p.end_color as endColor,
+        p.weekly, p.holiday_date as holidayDate, p.holiday_day as holidayDay
+        from plc_policy_cmd p
+        where p.plc_policy_id = #{policyId}
+    </select>
+
 </mapper>

+ 10 - 0
src/main/resources/mapper/PlcPolicyMapper.xml

@@ -67,4 +67,14 @@
         where id = #{id};
     </delete>
 
+    <select id="getPlcPolicyDetailById" resultType="PlcPolicyDTO">
+        select
+            p.id,
+            p.name,
+            p.operateType,
+            p.policyType
+        from plc_policy p
+        where p.id = #{id}
+    </select>
+
 </mapper>