|
@@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -54,7 +55,7 @@ public class PlcPolicyController {
|
|
|
Integer version = policyVO.getVersion();
|
|
|
Integer id = policyVO.getId();
|
|
|
String name = policyVO.getName();
|
|
|
- if (name == null || name.length() == 0)
|
|
|
+ if (name.isEmpty())
|
|
|
return toolUtils.response(InterfaceResultEnum.LACK_NAME_ERROR,version);
|
|
|
Integer policyType = policyVO.getPolicyType();
|
|
|
if (policyType == null)
|
|
@@ -94,6 +95,7 @@ public class PlcPolicyController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ PlcPolicyVO plcPolicyVO = new PlcPolicyVO();
|
|
|
PlcPolicyDTO plcPolicyDTO = new PlcPolicyDTO();
|
|
|
plcPolicyDTO.setName(name);
|
|
|
plcPolicyDTO.setPolicyType(policyType);
|
|
@@ -110,6 +112,7 @@ public class PlcPolicyController {
|
|
|
plcPolicyDTO.setCreateTime(format);
|
|
|
plcPolicyService.addPlcPolicyData(plcPolicyDTO);
|
|
|
Integer id1 = plcPolicyDTO.getId();
|
|
|
+ plcPolicyVO.setId(id1);
|
|
|
// 添加策略内容
|
|
|
for (PlcPolicyContentDTO p : dataList) {
|
|
|
Integer weekly = p.getWeekly();
|
|
@@ -174,6 +177,7 @@ public class PlcPolicyController {
|
|
|
}
|
|
|
}
|
|
|
} else { // 编辑
|
|
|
+ plcPolicyVO.setId(id);
|
|
|
plcPolicyDTO.setId(id);
|
|
|
plcPolicyService.updatePlcPolicyData(plcPolicyDTO);
|
|
|
plcPolicyCmdService.deletePlcPolicyCmdByPlcPolicyId(id);
|
|
@@ -241,6 +245,89 @@ public class PlcPolicyController {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,plcPolicyVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * plc策略列表
|
|
|
+ * @param vo PlcPolicyVO
|
|
|
+ * @return plc策略列表
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/getList", method = RequestMethod.POST)
|
|
|
+ public BaseResult<?> getList(PlcPolicyVO vo) throws NoSuchFieldException, IllegalAccessException {
|
|
|
+ PlcPolicyVO policyVO = PlcPolicyVO.getDefaultPlcPolicyVO(vo);
|
|
|
+ Integer version = policyVO.getVersion();
|
|
|
+ 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;
|
|
|
+ Integer total;
|
|
|
+ if (userDTO.getRole() == 1) { // 超管获取全部的策略列表
|
|
|
+ policyList = plcPolicyService.getAllPlcPolicyList(policyVO);
|
|
|
+ total = plcPolicyService.getAllPlcPolicyTotal();
|
|
|
+ } else {
|
|
|
+ policyList = plcPolicyService.getPlcPolicyList(policyVO);
|
|
|
+ total = plcPolicyService.getPlcPolicyTotal(userDTO.getId());
|
|
|
+ if (policyList == null || policyList.isEmpty()) {
|
|
|
+ PlcPolicyVO plcPolicyVO = new PlcPolicyVO();
|
|
|
+ plcPolicyVO.setList(policyList);
|
|
|
+ plcPolicyVO.setTotal(total);
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,plcPolicyVO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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.setTotal(total);
|
|
|
+ plcPolicyVO.setList(policyList);
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,plcPolicyVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除plc策略
|
|
|
+ * @param vo plc策略id
|
|
|
+ * @return 删除plc策略
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/del", method = RequestMethod.POST)
|
|
|
+ public BaseResult<?> del(PlcPolicyVO vo) throws NoSuchFieldException, IllegalAccessException {
|
|
|
+ PlcPolicyVO policyVO = PlcPolicyVO.getDefaultPlcPolicyVO(vo);
|
|
|
+ Integer version = policyVO.getVersion();
|
|
|
+ Integer id = policyVO.getId();
|
|
|
+ if (id == null) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
|
|
|
+ plcPolicyService.deletePlcPolicyDataById(id);
|
|
|
+ plcPolicyCmdService.deletePlcPolicyCmdByPlcPolicyId(id);
|
|
|
return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
|
|
|
}
|
|
|
}
|