Browse Source

灯带策略

zhj 2 years ago
parent
commit
ef846b616b

+ 394 - 0
src/main/java/com/welampiot/controller/LightStripPolicyController.java

@@ -0,0 +1,394 @@
+package com.welampiot.controller;
+
+import com.welampiot.common.BaseResult;
+import com.welampiot.common.InterfaceResultEnum;
+import com.welampiot.dto.*;
+import com.welampiot.service.LightStripGroupService;
+import com.welampiot.service.LightStripPolicyCmdService;
+import com.welampiot.service.LightStripPolicyService;
+import com.welampiot.service.UserService;
+import com.welampiot.utils.ToolUtils;
+import com.welampiot.vo.LightStripPolicyVO;
+import com.welampiot.vo.PolicyVO;
+import org.json.JSONArray;
+import org.json.JSONObject;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import java.lang.reflect.Field;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * ClassName: LightStripPolicyController
+ * Package: com.welampiot.controller
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/8/3 - 18:48
+ * @Version: v1.0
+ */
+@RestController
+@CrossOrigin
+@RequestMapping("/lightStripPolicy")
+public class LightStripPolicyController {
+    @Autowired
+    private ToolUtils toolUtils;
+
+    @Autowired
+    private LightStripPolicyService lightStripPolicyService;
+
+    @Autowired
+    private LightStripPolicyCmdService policyCmdService;
+
+    @Autowired
+    private UserService userService;
+
+    @Autowired
+    private LightStripGroupService lightStripGroupService;
+
+    /**
+     * 策略列表
+     * @param request 设备id
+     * @return 策略列表
+     */
+    @RequestMapping(value = "/getList", method = RequestMethod.POST)
+    public BaseResult<?> getList(HttpServletRequest request) throws NoSuchFieldException, IllegalAccessException {
+        Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
+        Integer page = (Integer) toolUtils.getRequestContent(request,"page",1);
+        Integer count = (Integer) toolUtils.getRequestContent(request,"count",1);
+        String keyword = (String) toolUtils.getRequestContent(request,"keyword",2);
+        String username = (String) toolUtils.getRequestContent(request,"username",2);
+        if (username.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
+        if (page == 0) page = 1;
+        if (count == 0) count = 16;
+        UserDTO userDTO = userService.queryUserIdByUsername(username);
+        if (userDTO == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version);
+        LightStripPolicyVO lightStripPolicyVO = new LightStripPolicyVO();
+        lightStripPolicyVO.setPage(count * (page - 1));
+        lightStripPolicyVO.setCount(count);
+        lightStripPolicyVO.setKeyword(keyword);
+        lightStripPolicyVO.setUserid(userDTO.getId());
+        List<LightStripPolicyDTO> list;
+        List<String> ids = new ArrayList<>();
+        if (userDTO.getRole() == 1) {
+            list = lightStripPolicyService.getAllLightStripPolicyList(lightStripPolicyVO);
+        } else {
+            list = lightStripPolicyService.getLightStripPolicyList(lightStripPolicyVO);
+            if (list.isEmpty()) {
+                LightStripPolicyVO vo = new LightStripPolicyVO();
+                vo.setList(list);
+                return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,vo);
+            }
+        }
+        list.forEach(dto -> ids.add(String.valueOf(dto.getId())));
+        List<LightStripPolicyCmdDTO> cmdList = policyCmdService.getLightStripPolicyCmdList(ids);
+        for (LightStripPolicyDTO dto : list) {
+            List<StripPolicyContentDTO> contentList = new ArrayList<>();
+            for (LightStripPolicyCmdDTO l : cmdList) {
+                StripPolicyContentDTO contentDTO = new StripPolicyContentDTO();
+                List<StripPolicyValueDTO> timeList = new ArrayList<>();
+                if (l.getStripPolicyId().equals(dto.getId())) {
+                    contentDTO.setValue(l.getValue());
+                    for (int i = 1; i <= 12; i ++) {
+                        StripPolicyValueDTO valueDTO = new StripPolicyValueDTO();
+                        Field fieldType = l.getClass().getDeclaredField("policyType" + i);
+                        fieldType.setAccessible(true);
+                        String type = (String) fieldType.get(l);
+                        if (type != null && !type.equals("")) {
+                            Field fieldTime = l.getClass().getDeclaredField("startTime" + i);
+                            fieldTime.setAccessible(true);
+                            String time = (String) fieldTime.get(l);
+                            Field fieldCmd = l.getClass().getDeclaredField("typeCmd" + i);
+                            fieldCmd.setAccessible(true);
+                            String cmd = (String) fieldCmd.get(l);
+                            valueDTO.setPolicyType(type);
+                            valueDTO.setStartTime(time);
+                            valueDTO.setTypeCmd(cmd);
+                            timeList.add(valueDTO);
+                        } else {
+                            break;
+                        }
+                    }
+                    contentDTO.setTimeList(timeList);
+                    contentList.add(contentDTO);
+                }
+            }
+            dto.setContentList(contentList);
+        }
+        LightStripPolicyVO vo = new LightStripPolicyVO();
+        vo.setList(list);
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,vo);
+    }
+
+    /**
+     * 添加编辑策略
+     * @param request 策略属性
+     * @return 添加编辑策略
+     */
+    @PostMapping("/save")
+    private BaseResult<?> save(HttpServletRequest request) throws IllegalAccessException, NoSuchFieldException {
+        Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
+        Integer id = (Integer) toolUtils.getRequestContent(request,"id",1);
+        String username = (String) toolUtils.getRequestContent(request,"username",2);
+        Integer type = (Integer) toolUtils.getRequestContent(request,"type",1);
+        String name = (String) toolUtils.getRequestContent(request,"name",2);
+        String dataList = (String) toolUtils.getRequestContent(request,"dataList",2);
+        if (username.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
+        if (name.length() == 0 || dataList.length() == 0)
+            return toolUtils.response(InterfaceResultEnum.LACK_NEED_PARAM,version);
+        JSONArray jsonArray = new JSONArray(dataList);
+        LightStripPolicyDTO policyDTO = new LightStripPolicyDTO();
+        policyDTO.setType(type);
+        policyDTO.setName(name);
+        PolicyVO policyVO = new PolicyVO();
+        if (id == 0) { // 添加
+            UserDTO userDTO = userService.queryUserIdByUsername(username);
+            policyDTO.setUserId(userDTO.getId());
+            long l = System.currentTimeMillis();
+            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            String format = simpleDateFormat.format(l);
+            policyDTO.setCreateTime(format);
+            lightStripPolicyService.addLightStripPolicyData(policyDTO);
+            Integer policyId = policyDTO.getId();
+            policyVO.setId(policyId);
+            for (int i = 0; i < jsonArray.length(); i ++) {
+                JSONObject dataObject = jsonArray.getJSONObject(i);
+                String value = dataObject.getString("value");
+                JSONArray contentArray = dataObject.getJSONArray("contentList");
+                LightStripPolicyCmdDTO cmdDTO = new LightStripPolicyCmdDTO();
+                cmdDTO.setValue(value);
+                cmdDTO.setStripPolicyId(policyId);
+                cmdDTO.setType(type);
+                for (int j = 0; j < contentArray.length(); j ++) {
+                    JSONObject jsonObject = contentArray.getJSONObject(j);
+                    String policyType = jsonObject.getString("policyType");
+                    String time = jsonObject.getString("time");
+                    String typeCmd = jsonObject.getString("typeCmd");
+                    String typeName = "policyType" + (j + 1);
+                    String timeName = "startTime" + (j + 1);
+                    String cmdName = "typeCmd" + (j + 1);
+                    Field fieldType = cmdDTO.getClass().getDeclaredField(typeName);
+                    Field fieldTime = cmdDTO.getClass().getDeclaredField(timeName);
+                    Field fieldCmd = cmdDTO.getClass().getDeclaredField(cmdName);
+                    fieldType.setAccessible(true);
+                    fieldTime.setAccessible(true);
+                    fieldCmd.setAccessible(true);
+                    fieldType.set(cmdDTO,policyType);
+                    fieldTime.set(cmdDTO,time);
+                    fieldCmd.set(cmdDTO,typeCmd);
+                }
+                policyCmdService.addLightStripPolicyCmdData(cmdDTO);
+            }
+        } else { // 编辑
+            policyVO.setId(id);
+            policyDTO.setId(id);
+            lightStripPolicyService.updateLightStripPolicyData(policyDTO);
+            // 删除之前绑定的策略内容
+            policyCmdService.deleteLightStripPolicyCmdByPolicyId(id);
+            for (int i = 0; i < jsonArray.length(); i ++) {
+                JSONObject dataObject = jsonArray.getJSONObject(i);
+                String value = dataObject.getString("value");
+                JSONArray contentArray = dataObject.getJSONArray("contentList");
+                LightStripPolicyCmdDTO cmdDTO = new LightStripPolicyCmdDTO();
+                cmdDTO.setValue(value);
+                cmdDTO.setStripPolicyId(id);
+                cmdDTO.setType(type);
+                for (int j = 0; j < contentArray.length(); j ++) {
+                    JSONObject jsonObject = contentArray.getJSONObject(j);
+                    String policyType = jsonObject.getString("policyType");
+                    String time = jsonObject.getString("time");
+                    String typeCmd = jsonObject.getString("typeCmd");
+                    String typeName = "policyType" + (j + 1);
+                    String timeName = "startTime" + (j + 1);
+                    String cmdName = "typeCmd" + (j + 1);
+                    Field fieldType = cmdDTO.getClass().getDeclaredField(typeName);
+                    Field fieldTime = cmdDTO.getClass().getDeclaredField(timeName);
+                    Field fieldCmd = cmdDTO.getClass().getDeclaredField(cmdName);
+                    fieldType.setAccessible(true);
+                    fieldTime.setAccessible(true);
+                    fieldCmd.setAccessible(true);
+                    fieldType.set(cmdDTO,policyType);
+                    fieldTime.set(cmdDTO,time);
+                    fieldCmd.set(cmdDTO,typeCmd);
+                }
+                policyCmdService.addLightStripPolicyCmdData(cmdDTO);
+            }
+        }
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,policyVO);
+    }
+
+    /**
+     * 策略详情
+     * @param request 设备id
+     * @return 策略详情
+     */
+    @RequestMapping(value = "/details", method = RequestMethod.POST)
+    public BaseResult<?> details(HttpServletRequest request) throws NoSuchFieldException, IllegalAccessException {
+        Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
+        Integer policyId = (Integer) toolUtils.getRequestContent(request,"policyId",1);
+        if (policyId == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
+        LightStripPolicyDTO policyDTO = lightStripPolicyService.getLightStripPolicyDTOById(policyId);
+        if (policyDTO == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version);
+        List<LightStripPolicyCmdDTO> cmdList = policyCmdService.getStripPolicyCmdByPolicyId(policyId);
+        List<StripPolicyContentDTO> contentList = new ArrayList<>();
+        for (LightStripPolicyCmdDTO l : cmdList) {
+            StripPolicyContentDTO contentDTO = new StripPolicyContentDTO();
+            contentDTO.setValue(l.getValue());
+            List<StripPolicyValueDTO> timeList = new ArrayList<>();
+            for (int i = 1; i <= 12; i ++) {
+                StripPolicyValueDTO valueDTO = new StripPolicyValueDTO();
+                Field fieldType = l.getClass().getDeclaredField("policyType" + i);
+                fieldType.setAccessible(true);
+                String policyType = (String) fieldType.get(l);
+                if (policyType == null || policyType.equals("")) break;
+                Field fieldTime = l.getClass().getDeclaredField("startTime" + i);
+                fieldTime.setAccessible(true);
+                String startTime = (String) fieldTime.get(l);
+                Field fieldCmd = l.getClass().getDeclaredField("typeCmd" + i);
+                fieldCmd.setAccessible(true);
+                String cmd = (String) fieldCmd.get(l);
+                valueDTO.setPolicyType(policyType);
+                valueDTO.setStartTime(startTime);
+                valueDTO.setTypeCmd(cmd);
+                String content = ToolUtils.getLightStripContent(policyType, cmd);
+                valueDTO.setContent(content);
+                timeList.add(valueDTO);
+            }
+            contentDTO.setTimeList(timeList);
+            contentList.add(contentDTO);
+        }
+        policyDTO.setContentList(contentList);
+        LightStripPolicyVO lightStripPolicyVO = new LightStripPolicyVO();
+        BeanUtils.copyProperties(policyDTO,lightStripPolicyVO);
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lightStripPolicyVO);
+    }
+
+    /**
+     * 设置策略获取列表
+     * @param request username,分组id
+     * @return list
+     */
+    @RequestMapping(value = "/stripSetList", method = RequestMethod.POST)
+    public BaseResult<?> stripSetList(HttpServletRequest request) throws NoSuchFieldException, IllegalAccessException {
+        Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
+        Integer groupId = (Integer) toolUtils.getRequestContent(request,"groupId",1);
+        String username = (String) toolUtils.getRequestContent(request,"username",2);
+        if (groupId == 0 || username.length() == 0)
+            return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
+        UserDTO userDTO = userService.queryUserIdByUsername(username);
+        LightStripGroupDTO groupDTO = lightStripGroupService.getLightStripGroupById(groupId);
+        if (userDTO == null || groupDTO == null)
+            return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version);
+        LightStripPolicyVO lightStripPolicyVO = new LightStripPolicyVO();
+        lightStripPolicyVO.setUserid(userDTO.getId());
+        List<LightStripPolicyDTO> list;
+        List<String> ids = new ArrayList<>();
+        if (userDTO.getRole() == 1) {
+            list = lightStripPolicyService.getAllLightStripPolicyList(lightStripPolicyVO);
+        } else {
+            list = lightStripPolicyService.getLightStripPolicyList(lightStripPolicyVO);
+            if (list.isEmpty()) {
+                LightStripPolicyVO vo = new LightStripPolicyVO();
+                vo.setList(list);
+                return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,vo);
+            }
+        }
+        list.forEach(dto -> ids.add(String.valueOf(dto.getId())));
+        List<LightStripPolicyCmdDTO> cmdList = policyCmdService.getLightStripPolicyCmdList(ids);
+        for (LightStripPolicyDTO dto : list) {
+            if (groupDTO.getType() == 1) {
+                if (groupDTO.getValue().equals(dto.getId())) {
+                    dto.setSelect(1);
+                } else {
+                    dto.setSelect(0);
+                }
+            } else {
+                dto.setSelect(0);
+            }
+            List<StripPolicyContentDTO> contentList = new ArrayList<>();
+            for (LightStripPolicyCmdDTO cmdDTO : cmdList) {
+                if (cmdDTO.getStripPolicyId().equals(dto.getId())) {
+                    StripPolicyContentDTO contentDTO = new StripPolicyContentDTO();
+                    contentDTO.setValue(cmdDTO.getValue());
+                    List<String> value = new ArrayList<>();
+                    for (int i = 1; i <= 12; i++) {
+                        // 策略类型1
+                        Field fieldType = cmdDTO.getClass().getDeclaredField("policyType" + i);
+                        if (i < 12) {
+                            // 策略类型2
+                            Field fieldType1 = cmdDTO.getClass().getDeclaredField("policyType" + (i + 1));
+                            fieldType.setAccessible(true);
+                            fieldType1.setAccessible(true);
+                            String type = (String) fieldType.get(cmdDTO);
+                            String type1 = (String) fieldType1.get(cmdDTO);
+                            if (type != null && !type.equals("") && type1 != null && !type1.equals("")) {
+                                // 策略时间1
+                                Field fieldTime = cmdDTO.getClass().getDeclaredField("startTime" + i);
+                                fieldTime.setAccessible(true);
+                                String time = (String) fieldTime.get(cmdDTO);
+                                // 策略时间2
+                                Field fieldTime1 = cmdDTO.getClass().getDeclaredField("startTime" + (i + 1));
+                                fieldTime1.setAccessible(true);
+                                String time1 = (String) fieldTime1.get(cmdDTO);
+                                // 策略指令1
+                                Field fieldCmd = cmdDTO.getClass().getDeclaredField("typeCmd" + i);
+                                fieldCmd.setAccessible(true);
+                                String cmd = (String) fieldCmd.get(cmdDTO);
+                                // 获取策略描述
+                                String content = ToolUtils.getLightStripContent(type, cmd);
+                                String newString = time + " - " + time1 + " " + content;
+                                value.add(newString);
+                            } else if (type != null && !type.equals("")) {
+                                // 策略时间1
+                                Field fieldTime = cmdDTO.getClass().getDeclaredField("startTime" + i);
+                                fieldTime.setAccessible(true);
+                                String time = (String) fieldTime.get(cmdDTO);
+                                // 策略指令1
+                                Field fieldCmd = cmdDTO.getClass().getDeclaredField("typeCmd" + i);
+                                fieldCmd.setAccessible(true);
+                                String cmd = (String) fieldCmd.get(cmdDTO);
+                                // 获取策略描述
+                                String content = ToolUtils.getLightStripContent(type, cmd);
+                                String newString = time + " -  " + content;
+                                value.add(newString);
+                                break;
+                            } else {
+                                break;
+                            }
+                        } else {
+                            fieldType.setAccessible(true);
+                            String type = (String) fieldType.get(cmdDTO);
+                            if (type != null && !type.equals("")) {
+                                // 策略时间1
+                                Field fieldTime = cmdDTO.getClass().getDeclaredField("startTime" + i);
+                                fieldTime.setAccessible(true);
+                                String time = (String) fieldTime.get(cmdDTO);
+                                // 策略指令1
+                                Field fieldCmd = cmdDTO.getClass().getDeclaredField("typeCmd" + i);
+                                fieldCmd.setAccessible(true);
+                                String cmd = (String) fieldCmd.get(cmdDTO);
+                                // 获取策略描述
+                                String content = ToolUtils.getLightStripContent(type, cmd);
+                                String newString = time + " -  " + content;
+                                value.add(newString);
+                                break;
+                            } else {
+                                break;
+                            }
+                        }
+                    }
+                    contentDTO.setPolicy(value);
+                    contentList.add(contentDTO);
+                }
+            }
+            dto.setContentList(contentList);
+        }
+        LightStripPolicyVO policyVO = new LightStripPolicyVO();
+        policyVO.setList(list);
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,policyVO);
+    }
+}

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

@@ -23,4 +23,6 @@ public interface LightStripGroupDao {
     LightStripGroupDTO getLightStripGroupDetailsById(@Param("id") Integer id, @Param("version") Integer version);
 
     String getLightStripPolicyName(@Param("policyId") Integer policyId);
+
+    LightStripGroupDTO getLightStripGroupById(@Param("id") Integer id);
 }

+ 25 - 0
src/main/java/com/welampiot/dao/LightStripPolicyCmdDao.java

@@ -0,0 +1,25 @@
+package com.welampiot.dao;
+
+import com.welampiot.dto.LightStripPolicyCmdDTO;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * ClassName: LightStripPolicyCmdDao
+ * Package: com.welampiot.dao
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/8/4 - 10:10
+ * @Version: v1.0
+ */
+public interface LightStripPolicyCmdDao {
+    List<LightStripPolicyCmdDTO> getLightStripPolicyCmdList(@Param("ids") List<String> ids);
+
+    void addLightStripPolicyCmdData(LightStripPolicyCmdDTO dto);
+
+    void deleteLightStripPolicyCmdByPolicyId(@Param("policyId") Integer policyId);
+
+    List<LightStripPolicyCmdDTO> getStripPolicyCmdByPolicyId(@Param("policyId") Integer policyId);
+}

+ 28 - 0
src/main/java/com/welampiot/dao/LightStripPolicyDao.java

@@ -0,0 +1,28 @@
+package com.welampiot.dao;
+
+import com.welampiot.dto.LightStripPolicyDTO;
+import com.welampiot.vo.LightStripPolicyVO;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * ClassName: LightStripPolicyDao
+ * Package: com.welampiot.dao
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/8/3 - 18:42
+ * @Version: v1.0
+ */
+public interface LightStripPolicyDao {
+    List<LightStripPolicyDTO> getAllLightStripPolicyList(LightStripPolicyVO vo);
+
+    List<LightStripPolicyDTO> getLightStripPolicyList(LightStripPolicyVO vo);
+
+    void addLightStripPolicyData(LightStripPolicyDTO dto);
+
+    void updateLightStripPolicyData(LightStripPolicyDTO dto);
+
+    LightStripPolicyDTO getLightStripPolicyDTOById(@Param("id") Integer id);
+}

+ 105 - 0
src/main/java/com/welampiot/dto/LightStripPolicyCmdDTO.java

@@ -0,0 +1,105 @@
+package com.welampiot.dto;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * ClassName: LightStripPolicyCmdDTO
+ * Package: com.welampiot.dto
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/8/3 - 18:11
+ * @Version: v1.0
+ */
+@Data
+public class LightStripPolicyCmdDTO implements Serializable {
+    private Integer id;
+
+    private Integer stripPolicyId; // 灯带策略id
+
+    private String allCmd; //
+
+    private Integer type; // 类型(0:日期,1:星期)
+
+    private String value; // 类型对应的值
+
+    private String policyType1;
+
+    private String startTime1;
+
+    private String typeCmd1;
+
+    private String policyType2;
+
+    private String startTime2;
+
+    private String typeCmd2;
+
+    private String policyType3;
+
+    private String startTime3;
+
+    private String typeCmd3;
+
+    private String policyType4;
+
+    private String startTime4;
+
+    private String typeCmd4;
+
+    private String policyType5;
+
+    private String startTime5;
+
+    private String typeCmd5;
+
+    private String policyType6;
+
+    private String startTime6;
+
+    private String typeCmd6;
+
+    private String policyType7;
+
+    private String startTime7;
+
+    private String typeCmd7;
+
+    private String policyType8;
+
+    private String startTime8;
+
+    private String typeCmd8;
+
+    private String policyType9;
+
+    private String startTime9;
+
+    private String typeCmd9;
+
+    private String policyType10;
+
+    private String startTime10;
+
+    private String typeCmd10;
+
+    private String policyType11;
+
+    private String startTime11;
+
+    private String typeCmd11;
+
+    private String policyType12;
+
+    private String startTime12;
+
+    private String typeCmd12;
+
+    private String createTime;
+
+    private String updateTime;
+
+    private static final long serialVersionUID = 1L;
+}

+ 5 - 0
src/main/java/com/welampiot/dto/LightStripPolicyDTO.java

@@ -3,6 +3,7 @@ package com.welampiot.dto;
 import lombok.Data;
 
 import java.io.Serializable;
+import java.util.List;
 
 /**
  * ClassName: LightStripPolicyDTO
@@ -30,5 +31,9 @@ public class LightStripPolicyDTO implements Serializable {
     /** 创建时间 **/
     private String createTime;
 
+    private Integer select;
+
+    private List<StripPolicyContentDTO> contentList;
+
     private static final long serialVersionUID = 1L;
 }

+ 22 - 0
src/main/java/com/welampiot/dto/StripPolicyContentDTO.java

@@ -0,0 +1,22 @@
+package com.welampiot.dto;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * ClassName: StripPolicyContentDTO
+ * Package: com.welampiot.dto
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/8/4 - 11:44
+ * @Version: v1.0
+ */
+@Data
+public class StripPolicyContentDTO implements Serializable {
+    private String value;
+    private List<String> policy;
+    private List<StripPolicyValueDTO> timeList;
+}

+ 22 - 0
src/main/java/com/welampiot/dto/StripPolicyValueDTO.java

@@ -0,0 +1,22 @@
+package com.welampiot.dto;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * ClassName: StripPolicyValueDTO
+ * Package: com.welampiot.dto
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/8/4 - 11:03
+ * @Version: v1.0
+ */
+@Data
+public class StripPolicyValueDTO implements Serializable {
+    private String policyType;
+    private String startTime;
+    private String typeCmd;
+    private String content;
+}

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

@@ -17,4 +17,6 @@ public interface LightStripGroupService {
     LightStripGroupVO getLightStripGroupByDTO(LightStripGroupDTO dto);
 
     LightStripGroupDetailVO getLightStripGroupDetailsById(Integer id, Integer version);
+
+    LightStripGroupDTO getLightStripGroupById(Integer id);
 }

+ 24 - 0
src/main/java/com/welampiot/service/LightStripPolicyCmdService.java

@@ -0,0 +1,24 @@
+package com.welampiot.service;
+
+import com.welampiot.dto.LightStripPolicyCmdDTO;
+
+import java.util.List;
+
+/**
+ * ClassName: LightStripPolicyCmdService
+ * Package: com.welampiot.service
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/8/4 - 10:12
+ * @Version: v1.0
+ */
+public interface LightStripPolicyCmdService {
+    List<LightStripPolicyCmdDTO> getLightStripPolicyCmdList(List<String> ids);
+
+    void addLightStripPolicyCmdData(LightStripPolicyCmdDTO dto);
+
+    void deleteLightStripPolicyCmdByPolicyId(Integer policyId);
+
+    List<LightStripPolicyCmdDTO> getStripPolicyCmdByPolicyId(Integer policyId);
+}

+ 27 - 0
src/main/java/com/welampiot/service/LightStripPolicyService.java

@@ -0,0 +1,27 @@
+package com.welampiot.service;
+
+import com.welampiot.dto.LightStripPolicyDTO;
+import com.welampiot.vo.LightStripPolicyVO;
+
+import java.util.List;
+
+/**
+ * ClassName: LightStripPolicyService
+ * Package: com.welampiot.service
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/8/3 - 18:45
+ * @Version: v1.0
+ */
+public interface LightStripPolicyService {
+    List<LightStripPolicyDTO> getAllLightStripPolicyList(LightStripPolicyVO vo);
+
+    List<LightStripPolicyDTO> getLightStripPolicyList(LightStripPolicyVO vo);
+
+    void addLightStripPolicyData(LightStripPolicyDTO dto);
+
+    void updateLightStripPolicyData(LightStripPolicyDTO dto);
+
+    LightStripPolicyDTO getLightStripPolicyDTOById(Integer id);
+}

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

@@ -90,4 +90,9 @@ public class LightStripGroupServiceImpl implements LightStripGroupService {
         }
         return vo;
     }
+
+    @Override
+    public LightStripGroupDTO getLightStripGroupById(Integer id) {
+        return lightStripGroupDao.getLightStripGroupById(id);
+    }
 }

+ 44 - 0
src/main/java/com/welampiot/service/impl/LightStripPolicyCmdServiceImpl.java

@@ -0,0 +1,44 @@
+package com.welampiot.service.impl;
+
+import com.welampiot.dao.LightStripPolicyCmdDao;
+import com.welampiot.dto.LightStripPolicyCmdDTO;
+import com.welampiot.service.LightStripPolicyCmdService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * ClassName: LightStripPolicyCmdServiceImpl
+ * Package: com.welampiot.service.impl
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/8/4 - 10:12
+ * @Version: v1.0
+ */
+@Service
+public class LightStripPolicyCmdServiceImpl implements LightStripPolicyCmdService {
+    @Autowired
+    private LightStripPolicyCmdDao lightStripPolicyCmdDao;
+
+    @Override
+    public List<LightStripPolicyCmdDTO> getLightStripPolicyCmdList(List<String> ids) {
+        return lightStripPolicyCmdDao.getLightStripPolicyCmdList(ids);
+    }
+
+    @Override
+    public void addLightStripPolicyCmdData(LightStripPolicyCmdDTO dto) {
+        lightStripPolicyCmdDao.addLightStripPolicyCmdData(dto);
+    }
+
+    @Override
+    public void deleteLightStripPolicyCmdByPolicyId(Integer policyId) {
+        lightStripPolicyCmdDao.deleteLightStripPolicyCmdByPolicyId(policyId);
+    }
+
+    @Override
+    public List<LightStripPolicyCmdDTO> getStripPolicyCmdByPolicyId(Integer policyId) {
+        return lightStripPolicyCmdDao.getStripPolicyCmdByPolicyId(policyId);
+    }
+}

+ 50 - 0
src/main/java/com/welampiot/service/impl/LightStripPolicyServiceImpl.java

@@ -0,0 +1,50 @@
+package com.welampiot.service.impl;
+
+import com.welampiot.dao.LightStripPolicyDao;
+import com.welampiot.dto.LightStripPolicyDTO;
+import com.welampiot.service.LightStripPolicyService;
+import com.welampiot.vo.LightStripPolicyVO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * ClassName: LightStripPolicyServiceImpl
+ * Package: com.welampiot.service.impl
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/8/3 - 18:46
+ * @Version: v1.0
+ */
+@Service
+public class LightStripPolicyServiceImpl implements LightStripPolicyService {
+    @Autowired
+    private LightStripPolicyDao lightStripPolicyDao;
+
+    @Override
+    public List<LightStripPolicyDTO> getAllLightStripPolicyList(LightStripPolicyVO vo) {
+        return lightStripPolicyDao.getAllLightStripPolicyList(vo);
+    }
+
+    @Override
+    public List<LightStripPolicyDTO> getLightStripPolicyList(LightStripPolicyVO vo) {
+        return lightStripPolicyDao.getLightStripPolicyList(vo);
+    }
+
+    @Override
+    public void addLightStripPolicyData(LightStripPolicyDTO dto) {
+        lightStripPolicyDao.addLightStripPolicyData(dto);
+    }
+
+    @Override
+    public void updateLightStripPolicyData(LightStripPolicyDTO dto) {
+        lightStripPolicyDao.updateLightStripPolicyData(dto);
+    }
+
+    @Override
+    public LightStripPolicyDTO getLightStripPolicyDTOById(Integer id) {
+        return lightStripPolicyDao.getLightStripPolicyDTOById(id);
+    }
+}

+ 103 - 0
src/main/java/com/welampiot/utils/ToolUtils.java

@@ -623,4 +623,107 @@ public class ToolUtils {
         lampPoleDTO.setDevType(newDevType);
         lampPoleService.updateLampPoleDevType(lampPoleDTO);
     }
+
+    /**
+     * 获取策略内容描述
+     * @param policyType 策略类型
+     * @param cmd 指令内容
+     * @return 策略内容描述
+     */
+    public static String getLightStripContent(String policyType, String cmd) {
+        String content;
+        switch (policyType) {
+            case "0":
+                content = ("常亮(颜色:" + cmd + ")");
+                break;
+            case "1":
+                switch (cmd) {
+                    case "1":
+                        content = ("红灯呼吸");
+                        break;
+                    case "2":
+                        content = ("绿灯呼吸");
+                        break;
+                    case "3":
+                        content = ("蓝灯呼吸");
+                        break;
+                    case "4":
+                        content = ("RGB呼吸");
+                        break;
+                    case "5":
+                        content = ("黄灯呼吸");
+                        break;
+                    case "6":
+                        content = ("紫灯呼吸");
+                        break;
+                    default:
+                        content = "";
+                        break;
+                }
+                break;
+            case "2":
+                switch (cmd) {
+                    case "1":
+                        content = ("红灯爆闪");
+                        break;
+                    case "2":
+                        content = ("绿灯爆闪");
+                        break;
+                    case "3":
+                        content = ("蓝灯爆闪");
+                        break;
+                    case "4":
+                        content = ("白色爆闪");
+                        break;
+                    case "5":
+                        content = ("7色爆闪");
+                        break;
+                    case "6":
+                        content = ("黄灯爆闪");
+                        break;
+                    case "7":
+                        content = ("紫灯爆闪");
+                        break;
+                    default:
+                        content = "";
+                        break;
+                }
+                break;
+            case "3":
+                content = ("关灯");
+                break;
+            case "4":
+                switch (cmd) {
+                    case "1":
+                        content = ("红灯闪烁");
+                        break;
+                    case "2":
+                        content = ("绿灯闪烁");
+                        break;
+                    case "3":
+                        content = ("蓝灯闪烁");
+                        break;
+                    case "4":
+                        content = ("白色闪烁");
+                        break;
+                    case "5":
+                        content = ("7色闪烁");
+                        break;
+                    case "6":
+                        content = ("黄灯闪烁");
+                        break;
+                    case "7":
+                        content = ("紫灯闪烁");
+                        break;
+                    default:
+                        content = "";
+                        break;
+                }
+                break;
+            default:
+                content = "";
+                break;
+        }
+        return content;
+    }
 }

+ 38 - 0
src/main/java/com/welampiot/vo/LightStripPolicyVO.java

@@ -0,0 +1,38 @@
+package com.welampiot.vo;
+
+import com.welampiot.dto.LightStripPolicyDTO;
+import com.welampiot.dto.StripPolicyContentDTO;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * ClassName: LightStripPolicyVO
+ * Package: com.welampiot.vo
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/8/3 - 18:43
+ * @Version: v1.0
+ */
+@Data
+public class LightStripPolicyVO implements Serializable {
+    private Integer page;
+
+    private Integer count;
+
+    private String keyword;
+
+    private Integer userid;
+
+    private Integer id;
+
+    private Integer type;
+
+    private String name;
+
+    private List<StripPolicyContentDTO> contentList;
+
+    private List<LightStripPolicyDTO> list;
+}

+ 6 - 0
src/main/resources/mapper/LightStripGroupMapper.xml

@@ -74,4 +74,10 @@
         where l.id = #{policyId}
     </select>
 
+    <select id="getLightStripGroupById" resultType="LightStripGroupDTO">
+        select l.id,l.type,l.value
+        from light_strip_group l
+        where l.id = #{id}
+    </select>
+
 </mapper>

+ 132 - 0
src/main/resources/mapper/LightStripPolicyCmdMapper.xml

@@ -0,0 +1,132 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.welampiot.dao.LightStripPolicyCmdDao">
+    
+    <select id="getLightStripPolicyCmdList" resultType="LightStripPolicyCmdDTO">
+        select
+            l.id,l.value,l.type,l.strip_policy_id as stripPolicyId,
+            l.policy_type1 policyType1,l.starttime1 as startTime1,l.type_cmd1 as typeCmd1,
+            l.policy_type2 policyType2,l.starttime2 as startTime2,l.type_cmd2 as typeCmd2,
+            l.policy_type3 policyType3,l.starttime3 as startTime3,l.type_cmd3 as typeCmd3,
+            l.policy_type4 policyType4,l.starttime4 as startTime4,l.type_cmd4 as typeCmd4,
+            l.policy_type5 policyType5,l.starttime5 as startTime5,l.type_cmd5 as typeCmd5,
+            l.policy_type6 policyType6,l.starttime6 as startTime6,l.type_cmd6 as typeCmd6,
+            l.policy_type7 policyType7,l.starttime7 as startTime7,l.type_cmd7 as typeCmd7,
+            l.policy_type8 policyType8,l.starttime8 as startTime8,l.type_cmd8 as typeCmd8,
+            l.policy_type9 policyType9,l.starttime9 as startTime9,l.type_cmd9 as typeCmd9,
+            l.policy_type10 policyType10,l.starttime10 as startTime10,l.type_cmd10 as typeCmd10,
+            l.policy_type11 policyType11,l.starttime11 as startTime11,l.type_cmd11 as typeCmd11,
+            l.policy_type12 policyType12,l.starttime12 as startTime12,l.type_cmd12 as typeCmd12
+        from light_strip_policy_cmd l
+        where l.strip_policy_id in
+        <foreach collection="ids" item="item" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+    </select>
+
+    <insert id="addLightStripPolicyCmdData" parameterType="LightStripPolicyCmdDTO" useGeneratedKeys="true" keyProperty="id">
+        insert into light_strip_policy_cmd(strip_policy_id,type,`value`,
+        <if test="policyType1 != null and policyType1 != ''">
+            policy_type1, starttime1, type_cmd1,
+        </if>
+        <if test="policyType2 != null and policyType2 != ''">
+            policy_type2, starttime2, type_cmd2,
+        </if>
+        <if test="policyType3 != null and policyType3 != ''">
+            policy_type3, starttime3, type_cmd3,
+        </if>
+        <if test="policyType4 != null and policyType4 != ''">
+            policy_type4, starttime4, type_cmd4,
+        </if>
+        <if test="policyType5 != null and policyType5 != ''">
+            policy_type5, starttime5, type_cmd5,
+        </if>
+        <if test="policyType6 != null and policyType6 != ''">
+            policy_type6, starttime6, type_cmd6,
+        </if>
+        <if test="policyType7 != null and policyType7 != ''">
+            policy_type7, starttime7, type_cmd7,
+        </if>
+        <if test="policyType8 != null and policyType8 != ''">
+            policy_type8, starttime8, type_cmd8,
+        </if>
+        <if test="policyType9 != null and policyType9 != ''">
+            policy_type9, starttime9, type_cmd9,
+        </if>
+        <if test="policyType10 != null and policyType10 != ''">
+            policy_type10, starttime10, type_cmd10,
+        </if>
+        <if test="policyType11 != null and policyType11 != ''">
+            policy_type11, starttime11, type_cmd11,
+        </if>
+        <if test="policyType12 != null and policyType12 != ''">
+            policy_type12, starttime12, type_cmd12,
+        </if>
+        createtime, updatetime)
+        values (#{stripPolicyId},#{type},#{value},
+        <if test="policyType1 != null and policyType1 != ''">
+            #{policyType1},#{startTime1},#{typeCmd1},
+        </if>
+        <if test="policyType2 != null and policyType2 != ''">
+            #{policyType2},#{startTime2},#{typeCmd2},
+        </if>
+        <if test="policyType3 != null and policyType3 != ''">
+            #{policyType3},#{startTime3},#{typeCmd3},
+        </if>
+        <if test="policyType4 != null and policyType4 != ''">
+            #{policyType4},#{startTime4},#{typeCmd4},
+        </if>
+        <if test="policyType5 != null and policyType5 != ''">
+            #{policyType5},#{startTime5},#{typeCmd5},
+        </if>
+        <if test="policyType6 != null and policyType6 != ''">
+            #{policyType6},#{startTime6},#{typeCmd6},
+        </if>
+        <if test="policyType7 != null and policyType7 != ''">
+            #{policyType7},#{startTime7},#{typeCmd7},
+        </if>
+        <if test="policyType8 != null and policyType8 != ''">
+            #{policyType8},#{startTime8},#{typeCmd8},
+        </if>
+        <if test="policyType9 != null and policyType9 != ''">
+            #{policyType9},#{startTime9},#{typeCmd9},
+        </if>
+        <if test="policyType10 != null and policyType10 != ''">
+            #{policyType10},#{startTime10},#{typeCmd10},
+        </if>
+        <if test="policyType11 != null and policyType11 != ''">
+            #{policyType11},#{startTime11},#{typeCmd11},
+        </if>
+        <if test="policyType12 != null and policyType12 != ''">
+            #{policyType12},#{startTime12},#{typeCmd12},
+        </if>
+        #{createTime},#{updateTime}
+        )
+    </insert>
+
+    <delete id="deleteLightStripPolicyCmdByPolicyId">
+        delete
+        from light_strip_policy_cmd
+        where strip_policy_id = #{policyId};
+    </delete>
+
+    <select id="getStripPolicyCmdByPolicyId" resultType="LightStripPolicyCmdDTO">
+        select
+            l.id,l.value,l.type,l.strip_policy_id as stripPolicyId,
+            l.policy_type1 policyType1,l.starttime1 as startTime1,l.type_cmd1 as typeCmd1,
+            l.policy_type2 policyType2,l.starttime2 as startTime2,l.type_cmd2 as typeCmd2,
+            l.policy_type3 policyType3,l.starttime3 as startTime3,l.type_cmd3 as typeCmd3,
+            l.policy_type4 policyType4,l.starttime4 as startTime4,l.type_cmd4 as typeCmd4,
+            l.policy_type5 policyType5,l.starttime5 as startTime5,l.type_cmd5 as typeCmd5,
+            l.policy_type6 policyType6,l.starttime6 as startTime6,l.type_cmd6 as typeCmd6,
+            l.policy_type7 policyType7,l.starttime7 as startTime7,l.type_cmd7 as typeCmd7,
+            l.policy_type8 policyType8,l.starttime8 as startTime8,l.type_cmd8 as typeCmd8,
+            l.policy_type9 policyType9,l.starttime9 as startTime9,l.type_cmd9 as typeCmd9,
+            l.policy_type10 policyType10,l.starttime10 as startTime10,l.type_cmd10 as typeCmd10,
+            l.policy_type11 policyType11,l.starttime11 as startTime11,l.type_cmd11 as typeCmd11,
+            l.policy_type12 policyType12,l.starttime12 as startTime12,l.type_cmd12 as typeCmd12
+        from light_strip_policy_cmd l
+        where l.strip_policy_id = #{policyId}
+    </select>
+
+</mapper>

+ 54 - 0
src/main/resources/mapper/LightStripPolicyMapper.xml

@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.welampiot.dao.LightStripPolicyDao">
+    
+    <select id="getAllLightStripPolicyList" resultType="LightStripPolicyDTO">
+        select
+            l.id,
+            l.name
+        from light_strip_policy l
+        where 1=1
+        <if test="keyword != null and keyword != ''">
+            and l.name like '%${keyword}%'
+        </if>
+        <if test="page >= 0 and count > 0">
+            limit #{page},#{count}
+        </if>
+    </select>
+
+    <select id="getLightStripPolicyList" resultType="LightStripPolicyDTO">
+        select
+        l.id,
+        l.name
+        from light_strip_policy l
+        where l.userid = #{userid}
+        <if test="keyword != null and keyword != ''">
+            and l.name like '%${keyword}%'
+        </if>
+        <if test="page >= 0 and count > 0">
+            limit #{page},#{count}
+        </if>
+    </select>
+
+    <insert id="addLightStripPolicyData" parameterType="LightStripPolicyDTO" keyProperty="id" useGeneratedKeys="true">
+        insert into light_strip_policy(name, userid, type, createtime)
+        values (#{name},#{userid},#{type},#{createTime})
+    </insert>
+
+    <update id="updateLightStripPolicyData" parameterType="LightStripPolicyDTO">
+        update
+            light_strip_policy l
+        set
+            l.name = #{name},
+            l.type = #{type}
+        where
+            l.id = #{id}
+    </update>
+
+    <select id="getLightStripPolicyDTOById" resultType="LightStripPolicyDTO">
+        select l.id,l.name,l.type
+        from light_strip_policy l
+        where l.id = #{id}
+    </select>
+
+</mapper>