|
@@ -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);
|
|
|
+ }
|
|
|
}
|