Selaa lähdekoodia

回路策略接口

zhj 2 vuotta sitten
vanhempi
commit
9a88480421

+ 280 - 0
src/main/java/com/welampiot/controller/LoopPolicyController.java

@@ -0,0 +1,280 @@
+package com.welampiot.controller;
+
+import com.welampiot.common.BaseResult;
+import com.welampiot.common.InterfaceResultEnum;
+import com.welampiot.dto.*;
+import com.welampiot.service.LoopPolicyCmdService;
+import com.welampiot.service.LoopPolicyService;
+import com.welampiot.service.UserService;
+import com.welampiot.utils.ToolUtils;
+import com.welampiot.vo.LoopPolicyDetailVO;
+import com.welampiot.vo.LoopPolicyVO;
+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: LoopPolicyController
+ * Package: com.welampiot.controller
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/7/31 - 15:56
+ * @Version: v1.0
+ */
+@RestController
+@CrossOrigin
+@RequestMapping("/loopPolicy")
+public class LoopPolicyController {
+    @Autowired
+    private ToolUtils toolUtils;
+    @Autowired
+    private LoopPolicyService loopPolicyService;
+    @Autowired
+    private LoopPolicyCmdService loopPolicyCmdService;
+    @Autowired
+    private UserService userService;
+
+    /**
+     * 回路策略列表
+     * @param request username
+     * @return list
+     */
+    @RequestMapping(value = "/getList", method = RequestMethod.POST)
+    public BaseResult<?> getList(HttpServletRequest request) throws NoSuchFieldException, IllegalAccessException {
+        Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
+        String username = (String) toolUtils.getRequestContent(request,"username",2);
+        String keyword = (String) toolUtils.getRequestContent(request,"keyword",2);
+        int page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page"));
+        int count = request.getParameter("count") == null ? 16 : Integer.parseInt(request.getParameter("count"));
+        UserDTO userDTO = userService.queryUserIdByUsername(username);
+        if (userDTO == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version);
+        LoopPolicyVO vo = new LoopPolicyVO();
+        vo.setCount(count);
+        vo.setPage(count * (page - 1));
+        vo.setKeyword(keyword);
+        vo.setUserid(userDTO.getId());
+        List<LoopPolicyDTO> list = new ArrayList<>();
+        List<LoopPolicyDTO> policyList;
+        if (userDTO.getRole() == 1) { // 超级管理员获取所有的策略
+            policyList = loopPolicyService.getAllLoopPolicyListByDTO(vo);
+        } else {
+            policyList = loopPolicyService.getLoopPolicyListByDTO(vo);
+        }
+        for (LoopPolicyDTO dto : policyList) {
+            List<LoopPolicyCmdDTO> policyCmdList = loopPolicyCmdService.getLoopPolicyCmdListByPolicyId(dto.getId());
+            List<LoopPolicyContentDTO> contentList = new ArrayList<>();
+            for (LoopPolicyCmdDTO cmdDTO : policyCmdList) {
+                LoopPolicyContentDTO loopPolicyContentDTO = new LoopPolicyContentDTO();
+                loopPolicyContentDTO.setDate(cmdDTO.getStartTime());
+                List<String> value = new ArrayList<>();
+                for (int i = 1; i <= 10; i++) {
+                    Field timeField = cmdDTO.getClass().getDeclaredField("time" + i); // 获取time属性的值
+                    if (i < 10) {
+                        Field timeField1 = cmdDTO.getClass().getDeclaredField("time" + (i + 1));
+                        timeField.setAccessible(true); // 设置可以访问
+                        timeField1.setAccessible(true);
+                        String timeValue = (String) timeField.get(cmdDTO);
+                        String timeValue1 = (String) timeField1.get(cmdDTO);
+                        if (timeValue != null && !timeValue.equals("") && timeValue1 != null && !timeValue1.equals("")) {
+                            Field valueField = cmdDTO.getClass().getDeclaredField("value" + i); // 获取value属性的值
+                            valueField.setAccessible(true); // 设置可以访问
+                            int valueValue = (int) valueField.get(cmdDTO);
+                            String newString;
+                            if (valueValue == 1) {
+                                newString = timeValue + "-" + timeValue1 + " 分闸";
+                            } else {
+                                newString = timeValue + "-" + timeValue1 + " 合闸";
+                            }
+                            value.add(newString);
+                        } else if (timeValue != null && !timeValue.equals("")) {
+                            Field valueField = cmdDTO.getClass().getDeclaredField("value" + i);
+                            valueField.setAccessible(true); // 设置可以访问
+                            int valueValue = (int) valueField.get(cmdDTO);
+                            String newString;
+                            if (valueValue == 1) {
+                                newString = timeValue + "-" + "以后" + " 分闸";
+                            } else {
+                                newString = timeValue + "-" + "以后" + " 合闸";
+                            }
+                            value.add(newString);
+                        } else {
+                            break;
+                        }
+                    } else {
+                        timeField.setAccessible(true);
+                        String timeValue = (String) timeField.get(cmdDTO);
+                        if (timeValue != null && !timeValue.equals("")) {
+                            Field valueField = cmdDTO.getClass().getDeclaredField("value" + i);
+                            valueField.setAccessible(true);
+                            int valueValue = (int) valueField.get(cmdDTO);
+                            String newString;
+                            if (valueValue == 1) {
+                                newString = timeValue + "-" + "以后" + " 分闸";
+                            } else {
+                                newString = timeValue + "-" + "以后" + " 合闸";
+                            }
+                            value.add(newString);
+                        } else {
+                            break;
+                        }
+                    }
+                }
+                loopPolicyContentDTO.setValue(value);
+                contentList.add(loopPolicyContentDTO);
+            }
+            dto.setContent(contentList);
+            list.add(dto);
+        }
+        LoopPolicyVO loopPolicyVO = new LoopPolicyVO();
+        loopPolicyVO.setList(list);
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,loopPolicyVO);
+    }
+
+    /**
+     * 添加编辑策略
+     * @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);
+        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);
+        LoopPolicyDTO loopPolicyDTO = new LoopPolicyDTO();
+        loopPolicyDTO.setName(name);
+        LoopPolicyVO loopPolicyVO = new LoopPolicyVO();
+        if (id == 0) { // 添加
+            UserDTO userDTO = userService.queryUserIdByUsername(username);
+            loopPolicyDTO.setUserid(userDTO.getId());
+            long l = System.currentTimeMillis();
+            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            String format = simpleDateFormat.format(l);
+            loopPolicyDTO.setCreateTime(format);
+            loopPolicyService.addLoopPolicyData(loopPolicyDTO);
+            Integer policyId = loopPolicyDTO.getId();
+            loopPolicyVO.setId(policyId);
+            for (int i = 0; i < jsonArray.length(); i ++) {
+                JSONObject dataObject = jsonArray.getJSONObject(i);
+                String date = dataObject.getString("date");
+                JSONArray timeArray = dataObject.getJSONArray("timeList");
+                LoopPolicyCmdDTO cmdDTO = new LoopPolicyCmdDTO();
+                cmdDTO.setStartTime(date);
+                cmdDTO.setPolicyId(policyId);
+                for (int j = 0; j < timeArray.length(); j ++) {
+                    JSONObject jsonObject = timeArray.getJSONObject(j);
+                    String time = jsonObject.getString("time");
+                    String status = jsonObject.getString("status");
+                    String timeName = "time" + (j + 1);
+                    String statusName = "value" + (j + 1);
+                    Field fieldTime = cmdDTO.getClass().getDeclaredField(timeName);
+                    Field fieldValue = cmdDTO.getClass().getDeclaredField(statusName);
+                    fieldTime.setAccessible(true);
+                    fieldValue.setAccessible(true);
+                    fieldTime.set(cmdDTO,time);
+                    fieldValue.set(cmdDTO,Integer.valueOf(status));
+                }
+                loopPolicyCmdService.addLoopPolicyCmdData(cmdDTO);
+            }
+        } else { // 编辑
+            loopPolicyVO.setId(id);
+            loopPolicyDTO.setId(id);
+            loopPolicyService.updateLoopPolicyData(loopPolicyDTO);
+            // 删除之前绑定的策略内容
+            loopPolicyCmdService.deleteLoopPolicyDataByPolicyId(id);
+            for (int i = 0; i < jsonArray.length(); i ++) {
+                JSONObject dataObject = jsonArray.getJSONObject(i);
+                String date = dataObject.getString("date");
+                JSONArray timeArray = dataObject.getJSONArray("timeList");
+                LoopPolicyCmdDTO cmdDTO = new LoopPolicyCmdDTO();
+                cmdDTO.setStartTime(date);
+                cmdDTO.setPolicyId(id);
+                for (int j = 0; j < timeArray.length(); j ++) {
+                    JSONObject jsonObject = timeArray.getJSONObject(j);
+                    String time = jsonObject.getString("time");
+                    String status = jsonObject.getString("status");
+                    String timeName = "time" + (j + 1);
+                    String statusName = "value" + (j + 1);
+                    Field fieldTime = cmdDTO.getClass().getDeclaredField(timeName);
+                    Field fieldValue = cmdDTO.getClass().getDeclaredField(statusName);
+                    fieldTime.setAccessible(true);
+                    fieldValue.setAccessible(true);
+                    fieldTime.set(cmdDTO,time);
+                    fieldValue.set(cmdDTO,Integer.valueOf(status));
+                }
+                loopPolicyCmdService.addLoopPolicyCmdData(cmdDTO);
+            }
+        }
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,loopPolicyVO);
+    }
+
+    /**
+     * 策略详情
+     * @param request 策略id
+     * @return 策略详情
+     */
+    @PostMapping("/details")
+    private 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);
+        LoopPolicyDTO loopPolicyDTO = loopPolicyService.getLoopPolicyDetailsById(policyId);
+        if (loopPolicyDTO == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version);
+        List<LoopPolicyContentDTO> contentList = new ArrayList<>();
+        List<LoopPolicyCmdDTO> list = loopPolicyCmdService.getLoopPolicyCmdListByPolicyId(loopPolicyDTO.getId());
+        for (LoopPolicyCmdDTO l : list) {
+            LoopPolicyContentDTO contentDTO = new LoopPolicyContentDTO();
+            contentDTO.setDate(l.getStartTime());
+            List<LoopPolicyTimeValueDTO> timeList = new ArrayList<>();
+            for (int i = 1; i <= 10; i ++) {
+                Field timeField = l.getClass().getDeclaredField("time" + i);
+                timeField.setAccessible(true);
+                String time = (String) timeField.get(l);
+                if (time != null && !time.equals("")) {
+                    Field valueField = l.getClass().getDeclaredField("value" + i);
+                    valueField.setAccessible(true);
+                    int status = (int) valueField.get(l);
+                    LoopPolicyTimeValueDTO valueDTO = new LoopPolicyTimeValueDTO();
+                    valueDTO.setTime(time);
+                    valueDTO.setStatus(status);
+                    timeList.add(valueDTO);
+                }
+            }
+            contentDTO.setTimeList(timeList);
+            contentList.add(contentDTO);
+        }
+        loopPolicyDTO.setContent(contentList);
+        LoopPolicyDetailVO loopPolicyDetailVO = new LoopPolicyDetailVO();
+        BeanUtils.copyProperties(loopPolicyDTO,loopPolicyDetailVO);
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,loopPolicyDetailVO);
+    }
+
+    /**
+     * 删除策略
+     * @param request 策略id
+     * @return 删除策略
+     */
+    @PostMapping("/del")
+    private BaseResult<?> del(HttpServletRequest request) {
+        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);
+        loopPolicyService.deleteLoopPolicyDataById(policyId);
+        loopPolicyCmdService.deleteLoopPolicyDataByPolicyId(policyId);
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
+    }
+}

+ 4 - 1
src/main/java/com/welampiot/controller/PolicyController.java

@@ -180,6 +180,7 @@ public class PolicyController{
         PolicyDTO policyDTO = new PolicyDTO();
         policyDTO.setPolicyType(policyType);
         policyDTO.setName(name);
+        PolicyVO policyVO = new PolicyVO();
         if (id == 0) { // 添加
             UserDTO userDTO = userService.queryUserIdByUsername(username);
             policyDTO.setUserId(userDTO.getId());
@@ -189,6 +190,7 @@ public class PolicyController{
             policyDTO.setCreateTime(format);
             policyService.addPolicyData(policyDTO);
             Integer policyId = policyDTO.getId();
+            policyVO.setId(policyId);
             for (int i = 0; i < jsonArray.length(); i ++) {
                 JSONObject dataObject = jsonArray.getJSONObject(i);
                 String date = dataObject.getString("date");
@@ -218,6 +220,7 @@ public class PolicyController{
                 policyCmdService.addPolicyCmdData(cmdDTO);
             }
         } else { // 编辑
+            policyVO.setId(id);
             policyDTO.setId(id);
             policyService.updatePolicyData(policyDTO);
             // 删除之前绑定的策略内容
@@ -251,6 +254,6 @@ public class PolicyController{
                 policyCmdService.addPolicyCmdData(cmdDTO);
             }
         }
-        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,policyVO);
     }
 }

+ 4 - 0
src/main/java/com/welampiot/dao/LoopPolicyCmdDao.java

@@ -26,4 +26,8 @@ public interface LoopPolicyCmdDao {
     void updateAirSwitchPolicyByDTO(AirSwitchInfoDTO dto);
 
     List<LoopPolicyCmdDTO> getLoopPolicyCmdListByPolicyId(@Param("policyId") Integer policyId);
+
+    void addLoopPolicyCmdData(LoopPolicyCmdDTO dto);
+
+    void deleteLoopPolicyDataByPolicyId(@Param("policyId") Integer policyId);
 }

+ 13 - 0
src/main/java/com/welampiot/dao/LoopPolicyDao.java

@@ -1,6 +1,7 @@
 package com.welampiot.dao;
 
 import com.welampiot.dto.LoopPolicyDTO;
+import com.welampiot.vo.LoopPolicyVO;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
@@ -18,4 +19,16 @@ public interface LoopPolicyDao {
     List<LoopPolicyDTO> getLoopPolicyListByUserid(@Param("userid") Integer userid);
 
     List<LoopPolicyDTO> getAllLoopPolicyList();
+
+    List<LoopPolicyDTO> getLoopPolicyListByDTO(LoopPolicyVO vo);
+
+    List<LoopPolicyDTO> getAllLoopPolicyListByDTO(LoopPolicyVO vo);
+
+    void addLoopPolicyData(LoopPolicyDTO dto);
+
+    void updateLoopPolicyData(LoopPolicyDTO dto);
+
+    LoopPolicyDTO getLoopPolicyDetailsById(@Param("id") Integer id);
+
+    void deleteLoopPolicyDataById(@Param("id") Integer id);
 }

+ 7 - 0
src/main/java/com/welampiot/dto/LoopPolicyContentDTO.java

@@ -22,4 +22,11 @@ public class LoopPolicyContentDTO {
     private String date;
 
     private List<LoopPolicyTimeValueDTO> timeList;
+
+    private List<String> value;
+
+    public LoopPolicyContentDTO(String date, List<LoopPolicyTimeValueDTO> timeList) {
+        this.date = date;
+        this.timeList = timeList;
+    }
 }

+ 1 - 2
src/main/java/com/welampiot/dto/LoopPolicyDTO.java

@@ -3,7 +3,6 @@ package com.welampiot.dto;
 import lombok.Data;
 
 import java.io.Serializable;
-import java.util.Date;
 import java.util.List;
 
 /**
@@ -27,7 +26,7 @@ public class LoopPolicyDTO implements Serializable {
     private Integer userid;
 
     /** 创建时间 **/
-    private Date createTime;
+    private String createTime;
 
     /** 是否更新策略信息 **/
     private Integer isUpdate;

+ 4 - 0
src/main/java/com/welampiot/service/LoopPolicyCmdService.java

@@ -25,4 +25,8 @@ public interface LoopPolicyCmdService {
     void updateAirSwitchPolicyByDTO(AirSwitchInfoDTO dto);
 
     List<LoopPolicyCmdDTO> getLoopPolicyCmdListByPolicyId(Integer policyId);
+
+    void addLoopPolicyCmdData(LoopPolicyCmdDTO dto);
+
+    void deleteLoopPolicyDataByPolicyId(Integer policyId);
 }

+ 13 - 0
src/main/java/com/welampiot/service/LoopPolicyService.java

@@ -1,6 +1,7 @@
 package com.welampiot.service;
 
 import com.welampiot.dto.LoopPolicyDTO;
+import com.welampiot.vo.LoopPolicyVO;
 
 import java.util.List;
 
@@ -17,4 +18,16 @@ public interface LoopPolicyService {
     List<LoopPolicyDTO> getLoopPolicyListByUserid(Integer userid);
 
     List<LoopPolicyDTO> getAllLoopPolicyList();
+
+    List<LoopPolicyDTO> getLoopPolicyListByDTO(LoopPolicyVO vo);
+
+    List<LoopPolicyDTO> getAllLoopPolicyListByDTO(LoopPolicyVO vo);
+
+    void addLoopPolicyData(LoopPolicyDTO dto);
+
+    void updateLoopPolicyData(LoopPolicyDTO dto);
+
+    LoopPolicyDTO getLoopPolicyDetailsById(Integer id);
+
+    void deleteLoopPolicyDataById(Integer id);
 }

+ 10 - 0
src/main/java/com/welampiot/service/impl/LoopPolicyCmdServiceImpl.java

@@ -48,4 +48,14 @@ public class LoopPolicyCmdServiceImpl implements LoopPolicyCmdService {
     public List<LoopPolicyCmdDTO> getLoopPolicyCmdListByPolicyId(Integer policyId) {
         return loopPolicyCmdDao.getLoopPolicyCmdListByPolicyId(policyId);
     }
+
+    @Override
+    public void addLoopPolicyCmdData(LoopPolicyCmdDTO dto) {
+        loopPolicyCmdDao.addLoopPolicyCmdData(dto);
+    }
+
+    @Override
+    public void deleteLoopPolicyDataByPolicyId(Integer policyId) {
+        loopPolicyCmdDao.deleteLoopPolicyDataByPolicyId(policyId);
+    }
 }

+ 31 - 0
src/main/java/com/welampiot/service/impl/LoopPolicyServiceImpl.java

@@ -3,6 +3,7 @@ package com.welampiot.service.impl;
 import com.welampiot.dao.LoopPolicyDao;
 import com.welampiot.dto.LoopPolicyDTO;
 import com.welampiot.service.LoopPolicyService;
+import com.welampiot.vo.LoopPolicyVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -31,4 +32,34 @@ public class LoopPolicyServiceImpl implements LoopPolicyService {
     public List<LoopPolicyDTO> getAllLoopPolicyList() {
         return loopPolicyDao.getAllLoopPolicyList();
     }
+
+    @Override
+    public List<LoopPolicyDTO> getLoopPolicyListByDTO(LoopPolicyVO vo) {
+        return loopPolicyDao.getLoopPolicyListByDTO(vo);
+    }
+
+    @Override
+    public List<LoopPolicyDTO> getAllLoopPolicyListByDTO(LoopPolicyVO vo) {
+        return loopPolicyDao.getAllLoopPolicyListByDTO(vo);
+    }
+
+    @Override
+    public void addLoopPolicyData(LoopPolicyDTO dto) {
+        loopPolicyDao.addLoopPolicyData(dto);
+    }
+
+    @Override
+    public void updateLoopPolicyData(LoopPolicyDTO dto) {
+        loopPolicyDao.updateLoopPolicyData(dto);
+    }
+
+    @Override
+    public LoopPolicyDTO getLoopPolicyDetailsById(Integer id) {
+        return loopPolicyDao.getLoopPolicyDetailsById(id);
+    }
+
+    @Override
+    public void deleteLoopPolicyDataById(Integer id) {
+        loopPolicyDao.deleteLoopPolicyDataById(id);
+    }
 }

+ 25 - 0
src/main/java/com/welampiot/vo/LoopPolicyDetailVO.java

@@ -0,0 +1,25 @@
+package com.welampiot.vo;
+
+import com.welampiot.dto.LoopPolicyContentDTO;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * ClassName: LoopPolicyDetailVO
+ * Package: com.welampiot.vo
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/7/31 - 18:37
+ * @Version: v1.0
+ */
+@Data
+public class LoopPolicyDetailVO implements Serializable {
+    private Integer id;
+
+    private String name;
+
+    private List<LoopPolicyContentDTO> content;
+}

+ 11 - 0
src/main/java/com/welampiot/vo/LoopPolicyVO.java

@@ -16,5 +16,16 @@ import java.util.List;
  */
 @Data
 public class LoopPolicyVO {
+
+    private Integer id;
+
+    private Integer userid;
+
+    private Integer page;
+
+    private Integer count;
+
+    private String keyword;
+
     private List<LoopPolicyDTO> list;
 }

+ 1 - 0
src/main/java/com/welampiot/vo/PolicyVO.java

@@ -13,4 +13,5 @@ public class PolicyVO {
     private String keyword;
     private List<PolicyDTO> list;
     private Integer total;
+    private Integer id;
 }

+ 73 - 0
src/main/resources/mapper/LoopPolicyCmdMapper.xml

@@ -57,4 +57,77 @@
         where l.policyid = #{policyId}
     </select>
 
+    <insert id="addLoopPolicyCmdData" parameterType="LoopPolicyCmdDTO" useGeneratedKeys="true" keyProperty="id">
+        insert into loop_policy_cmd(policyid,
+        <if test="time1 != null and time1 != ''">
+            time1, value1,
+        </if>
+        <if test="time2 != null and time2 != ''">
+            time2, value2,
+        </if>
+        <if test="time3 != null and time3 != ''">
+            time3, value3,
+        </if>
+        <if test="time4 != null and time4 != ''">
+            time4, value4,
+        </if>
+        <if test="time5 != null and time5 != ''">
+            time5, value5,
+        </if>
+        <if test="time6 != null and time6 != ''">
+            time6, value6,
+        </if>
+        <if test="time7 != null and time7 != ''">
+            time7, value7,
+        </if>
+        <if test="time8 != null and time8 != ''">
+            time8, value8,
+        </if>
+        <if test="time9 != null and time9 != ''">
+            time9, value9,
+        </if>
+        <if test="time10 != null and time10 != ''">
+            time10, value10,
+        </if>
+        starttime)
+        values (#{policyId},
+        <if test="time1 != null and time1 != ''">
+            #{time1},#{value1},
+        </if>
+        <if test="time2 != null and time2 != ''">
+            #{time2},#{value2},
+        </if>
+        <if test="time3 != null and time3 != ''">
+            #{time3},#{value3},
+        </if>
+        <if test="time4 != null and time4 != ''">
+            #{time4},#{value4},
+        </if>
+        <if test="time5 != null and time5 != ''">
+            #{time5},#{value5},
+        </if>
+        <if test="time6 != null and time6 != ''">
+            #{time6},#{value6},
+        </if>
+        <if test="time7 != null and time7 != ''">
+            #{time7},#{value7},
+        </if>
+        <if test="time8 != null and time8 != ''">
+            #{time8},#{value8},
+        </if>
+        <if test="time9 != null and time9 != ''">
+            #{time9},#{value9},
+        </if>
+        <if test="time10 != null and time10 != ''">
+            #{time10},#{value10},
+        </if>
+        #{startTime})
+    </insert>
+
+    <delete id="deleteLoopPolicyDataByPolicyId">
+        delete
+        from loop_policy_cmd
+        where policyid = #{policyId};
+    </delete>
+
 </mapper>

+ 52 - 0
src/main/resources/mapper/LoopPolicyMapper.xml

@@ -13,4 +13,56 @@
         from loop_policy l
     </select>
 
+    <select id="getLoopPolicyListByDTO" resultType="com.welampiot.dto.LoopPolicyDTO">
+        select l.id,l.name
+        from loop_policy l
+        where l.userid = #{userid}
+        <if test="keyword != null and keyword != ''">
+            and l.name like '%${keyword}%'
+        </if>
+        order by l.createtime desc
+        <if test="page >= 0 and count > 0">
+            limit #{page},#{count}
+        </if>
+    </select>
+
+    <select id="getAllLoopPolicyListByDTO" resultType="com.welampiot.dto.LoopPolicyDTO">
+        select l.id,l.name
+        from loop_policy l
+        where 1=1
+        <if test="keyword != null and keyword != ''">
+            and l.name like '%${keyword}%'
+        </if>
+        order by l.createtime desc
+        <if test="page >= 0 and count > 0">
+            limit #{page},#{count}
+        </if>
+    </select>
+
+    <insert id="addLoopPolicyData" parameterType="LoopPolicyDTO" keyProperty="id" useGeneratedKeys="true">
+        insert into loop_policy(name, userid, createtime)
+        values (#{name},#{userid},#{createTime})
+    </insert>
+
+    <update id="updateLoopPolicyData" parameterType="LoopPolicyDTO">
+        update
+            loop_policy l
+        set
+            l.name = #{name}
+        where
+            l.id = #{id}
+    </update>
+
+    <select id="getLoopPolicyDetailsById" resultType="LoopPolicyDTO">
+        select l.id,l.name
+        from loop_policy l
+        where l.id = #{id}
+    </select>
+
+    <delete id="deleteLoopPolicyDataById">
+        delete
+        from loop_policy
+        where id = #{id};
+    </delete>
+
 </mapper>