|
@@ -2,10 +2,7 @@ package com.welampiot.controller;
|
|
|
|
|
|
import com.welampiot.common.BaseResult;
|
|
|
import com.welampiot.common.InterfaceResultEnum;
|
|
|
-import com.welampiot.dto.GroupDTO;
|
|
|
-import com.welampiot.dto.PolicyCmdDTO;
|
|
|
-import com.welampiot.dto.PolicyDTO;
|
|
|
-import com.welampiot.dto.UserDTO;
|
|
|
+import com.welampiot.dto.*;
|
|
|
import com.welampiot.service.GroupService;
|
|
|
import com.welampiot.service.PolicyCmdService;
|
|
|
import com.welampiot.service.PolicyService;
|
|
@@ -13,14 +10,13 @@ import com.welampiot.service.UserService;
|
|
|
import com.welampiot.utils.ToolUtils;
|
|
|
import com.welampiot.vo.GroupVO;
|
|
|
import com.welampiot.vo.ListResponseVO;
|
|
|
+import com.welampiot.vo.PolicyDetailsVO;
|
|
|
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.CrossOrigin;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.lang.reflect.Field;
|
|
@@ -256,4 +252,64 @@ public class PolicyController{
|
|
|
}
|
|
|
return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,policyVO);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 策略详情
|
|
|
+ * @param vo 策略id
|
|
|
+ * @return 策略详情
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/details", method = RequestMethod.POST)
|
|
|
+ public BaseResult<?> details(PolicyVO vo) throws NoSuchFieldException, IllegalAccessException {
|
|
|
+ PolicyVO policyVO = PolicyVO.getPolicyVO(vo);
|
|
|
+ Integer version = policyVO.getVersion();
|
|
|
+ Integer id = policyVO.getId();
|
|
|
+ if (id == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
|
|
|
+ PolicyDTO policyDTO = policyService.getPolicyDTOById(id);
|
|
|
+ List<PolicyCmdDTO> cmdList = policyCmdService.getListByPolicyId(id);
|
|
|
+ List<PolicyContentDTO> content = new ArrayList<>();
|
|
|
+ for (PolicyCmdDTO p : cmdList) {
|
|
|
+ List<PolicyTimeValueDTO> timeList = new ArrayList<>();
|
|
|
+ for (int i = 1; i <= 10; i ++) {
|
|
|
+ Field fieldTime = p.getClass().getDeclaredField("time" + i);
|
|
|
+ fieldTime.setAccessible(true);
|
|
|
+ String time = (String) fieldTime.get(p);
|
|
|
+ if (time == null || time.length() == 0) break;
|
|
|
+ Field fieldColor = p.getClass().getDeclaredField("color" + i);
|
|
|
+ fieldColor.setAccessible(true);
|
|
|
+ Integer color = (Integer) fieldColor.get(p);
|
|
|
+ Field fieldValue = p.getClass().getDeclaredField("value" + i);
|
|
|
+ fieldValue.setAccessible(true);
|
|
|
+ Integer value = (Integer) fieldValue.get(p);
|
|
|
+ PolicyTimeValueDTO valueDTO = new PolicyTimeValueDTO();
|
|
|
+ valueDTO.setTime(time);
|
|
|
+ valueDTO.setColor(color);
|
|
|
+ valueDTO.setValue(value);
|
|
|
+ timeList.add(valueDTO);
|
|
|
+ }
|
|
|
+ PolicyContentDTO contentDTO = new PolicyContentDTO();
|
|
|
+ contentDTO.setDate(p.getStartTime());
|
|
|
+ contentDTO.setTimeList(timeList);
|
|
|
+ content.add(contentDTO);
|
|
|
+ }
|
|
|
+ policyDTO.setContent(content);
|
|
|
+ PolicyDetailsVO policyDetailsVO = new PolicyDetailsVO();
|
|
|
+ BeanUtils.copyProperties(policyDTO,policyDetailsVO);
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,policyDetailsVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除策略
|
|
|
+ * @param vo 策略id
|
|
|
+ * @return 删除策略
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/del", method = RequestMethod.POST)
|
|
|
+ public BaseResult<?> del(PolicyVO vo) {
|
|
|
+ PolicyVO policyVO = PolicyVO.getPolicyVO(vo);
|
|
|
+ Integer version = policyVO.getVersion();
|
|
|
+ Integer id = policyVO.getId();
|
|
|
+ if (id == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
|
|
|
+ policyService.deletePolicyDataById(id);
|
|
|
+ policyCmdService.deletePolicyCmdDataByPolicyId(id);
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
|
|
|
+ }
|
|
|
}
|