|
@@ -0,0 +1,167 @@
|
|
|
+package com.welampiot.controller;
|
|
|
+
|
|
|
+import com.welampiot.common.BaseResult;
|
|
|
+import com.welampiot.common.InterfaceResultEnum;
|
|
|
+import com.welampiot.dto.MicrowaveInfoDTO;
|
|
|
+import com.welampiot.service.MicrowaveInfoService;
|
|
|
+import com.welampiot.utils.ToolUtils;
|
|
|
+import com.welampiot.vo.EventVO;
|
|
|
+import com.welampiot.vo.InductionConfigVO;
|
|
|
+import com.welampiot.vo.MicrowaveInfoVO;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.CrossOrigin;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@CrossOrigin
|
|
|
+@RequestMapping("/microwave")
|
|
|
+public class MicrowaveController extends BaseController {
|
|
|
+ @Autowired
|
|
|
+ private MicrowaveInfoService microwaveInfoService;
|
|
|
+ @Autowired
|
|
|
+ private ToolUtils toolUtils;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取列表
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/getList", method = RequestMethod.POST)
|
|
|
+ private BaseResult<?> getList(MicrowaveInfoVO microwaveInfoVO) {
|
|
|
+ microwaveInfoVO.setSectionList(getSectionList(microwaveInfoVO.getUsername()));
|
|
|
+ microwaveInfoVO.setPageAndCount(microwaveInfoVO.getPage(), microwaveInfoVO.getCount());
|
|
|
+ List<MicrowaveInfoDTO> microList = microwaveInfoService.getMicrowaveListByMicrowaveInfoVO(microwaveInfoVO);
|
|
|
+ Integer total = microwaveInfoService.getMicrowaveTotalByMicrowaveInfoVO(microwaveInfoVO);
|
|
|
+ Integer onlineTotal = microwaveInfoService.getMicrowaveOnlineTotalByMicrowaveInfoVO(microwaveInfoVO);
|
|
|
+ MicrowaveInfoVO microwaveInfoVO1 = new MicrowaveInfoVO();
|
|
|
+ microwaveInfoVO1.setTotal(total);
|
|
|
+ microwaveInfoVO1.setOnlineTotal(onlineTotal);
|
|
|
+ microwaveInfoVO1.setList(microList);
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS, microwaveInfoVO.getVersion(), microwaveInfoVO1);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除设备
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/del", method = RequestMethod.POST)
|
|
|
+ private BaseResult<?> del(MicrowaveInfoVO microwaveInfoVO) {
|
|
|
+ Integer version = microwaveInfoVO.getVersion();
|
|
|
+ if (microwaveInfoVO.getId() == null || microwaveInfoVO.getId() == 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR, version);
|
|
|
+ microwaveInfoService.deleteMicrowaveDataById(microwaveInfoVO.getId());
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS, version);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存设备
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/save", method = RequestMethod.POST)
|
|
|
+ private BaseResult<?> save(MicrowaveInfoVO microwaveInfoVO) {
|
|
|
+ return microwaveInfoService.saveMicrowaveDataByMicrowaveVO(microwaveInfoVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置事件配置
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/setEventConfig", method = RequestMethod.POST)
|
|
|
+ private BaseResult<?> setEventConfig(EventVO eventVO) {
|
|
|
+ Integer version = eventVO.getVersion();
|
|
|
+ Integer id = eventVO.getId();
|
|
|
+ if (id == null || id == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR, version);
|
|
|
+ MicrowaveInfoDTO microwaveInfoDTO = microwaveInfoService.getMicrowaveDetailsById(id);
|
|
|
+ if (microwaveInfoDTO == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL, version);
|
|
|
+ boolean isSuccess = toolUtils.setEventData(
|
|
|
+ microwaveInfoDTO.getGateway(),
|
|
|
+ microwaveInfoDTO.getAddress(),
|
|
|
+ eventVO.getEventType(),
|
|
|
+ eventVO.getEventID(),
|
|
|
+ eventVO.getPerTimes(),
|
|
|
+ eventVO.getAddSpeed(),
|
|
|
+ eventVO.getGroupAddr());
|
|
|
+ if (!isSuccess) return toolUtils.response(InterfaceResultEnum.COMMAND_FAIL, version);
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS, version);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取事件配置
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/getEventConfig", method = RequestMethod.POST)
|
|
|
+ private BaseResult<?> getEventConfig(EventVO eventVO) {
|
|
|
+ Integer version = eventVO.getVersion();
|
|
|
+ if (eventVO.getId() == null || eventVO.getId() == 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR, version);
|
|
|
+ MicrowaveInfoDTO microwaveDetails = microwaveInfoService.getMicrowaveDetailsById(eventVO.getId());
|
|
|
+ if (microwaveDetails == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL, version);
|
|
|
+ EventVO eventData = toolUtils.getEventData(microwaveDetails.getGateway(), microwaveDetails.getAddress());
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS, version, eventData);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取感应配置
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/getInductionConfig", method = RequestMethod.POST)
|
|
|
+ private BaseResult<?> getInductionConfig(InductionConfigVO inductionConfigVO) {
|
|
|
+ Integer version = inductionConfigVO.getVersion();
|
|
|
+ if (inductionConfigVO.getId() == null || inductionConfigVO.getId() == 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR, version);
|
|
|
+ MicrowaveInfoDTO microwaveDetails = microwaveInfoService.getMicrowaveDetailsById(inductionConfigVO.getId());
|
|
|
+ if (microwaveDetails == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL, version);
|
|
|
+ InductionConfigVO inductionConfig = toolUtils.getInductionConfig(microwaveDetails.getGateway(), microwaveDetails.getAddress());
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS, version, inductionConfig);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置感应配置
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/setInductionConfig", method = RequestMethod.POST)
|
|
|
+ private BaseResult<?> setInductionConfig(InductionConfigVO inductionConfigVO) {
|
|
|
+ Integer version = inductionConfigVO.getVersion();
|
|
|
+ Integer id = inductionConfigVO.getId();
|
|
|
+ if (id == null || id == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR, version);
|
|
|
+ MicrowaveInfoDTO microwaveInfoDTO = microwaveInfoService.getMicrowaveDetailsById(id);
|
|
|
+ if (microwaveInfoDTO == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL, version);
|
|
|
+ boolean isSuccess = toolUtils.setInductionConfig(
|
|
|
+ microwaveInfoDTO.getGateway(),
|
|
|
+ microwaveInfoDTO.getAddress(),
|
|
|
+ inductionConfigVO.getEnable(),
|
|
|
+ inductionConfigVO.getSensitivity(),
|
|
|
+ inductionConfigVO.getOnLight(),
|
|
|
+ inductionConfigVO.getOffLight());
|
|
|
+ if (!isSuccess) return toolUtils.response(InterfaceResultEnum.COMMAND_FAIL, version);
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS, version);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 刷新数据
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/getLogInfo", method = RequestMethod.POST)
|
|
|
+ private BaseResult<?> getLogInfo(MicrowaveInfoVO microwaveInfoVO) {
|
|
|
+ Integer version = microwaveInfoVO.getVersion();
|
|
|
+ Integer id = microwaveInfoVO.getId();
|
|
|
+ if (id == null || id == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR, version);
|
|
|
+ MicrowaveInfoDTO microwaveInfoDTO = microwaveInfoService.getMicrowaveDetailsById(id);
|
|
|
+ if (microwaveInfoDTO == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL, version);
|
|
|
+ boolean isSuccess = toolUtils.refreshData(microwaveInfoDTO.getGateway(), microwaveInfoDTO.getAddress());
|
|
|
+ if (!isSuccess) return toolUtils.response(InterfaceResultEnum.COMMAND_FAIL, version);
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS, version);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取光照度
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/getLight", method = RequestMethod.POST)
|
|
|
+ private BaseResult<?> getLight(MicrowaveInfoVO microwaveInfoVO) {
|
|
|
+ Integer version = microwaveInfoVO.getVersion();
|
|
|
+ Integer id = microwaveInfoVO.getId();
|
|
|
+ if (id == null || id == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR, version);
|
|
|
+ MicrowaveInfoDTO microwaveInfoDTO = microwaveInfoService.getMicrowaveDetailsById(id);
|
|
|
+ if (microwaveInfoDTO == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL, version);
|
|
|
+ Integer value = toolUtils.getIlluminanceValue(microwaveInfoDTO.getGateway(), microwaveInfoDTO.getAddress());
|
|
|
+ if (-1 == value) return toolUtils.response(InterfaceResultEnum.COMMAND_FAIL, version);
|
|
|
+ InductionConfigVO inductionConfigVO = new InductionConfigVO();
|
|
|
+ inductionConfigVO.setLight(value);
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS, version, inductionConfigVO);
|
|
|
+ }
|
|
|
+}
|