|
@@ -0,0 +1,79 @@
|
|
|
+package com.welampiot.controller;
|
|
|
+
|
|
|
+import com.welampiot.common.BaseResult;
|
|
|
+import com.welampiot.common.InterfaceResultEnum;
|
|
|
+import com.welampiot.dto.LampInfoDTO;
|
|
|
+import com.welampiot.service.LampService;
|
|
|
+import com.welampiot.utils.ToolUtils;
|
|
|
+import com.welampiot.vo.LampInfoVO;
|
|
|
+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 javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+/**
|
|
|
+ * ClassName: MpToolController
|
|
|
+ * Package: com.welampiot.controller
|
|
|
+ * Description:
|
|
|
+ *
|
|
|
+ * @Author: zhj_Start
|
|
|
+ * @Create: 2023/9/14 - 11:17
|
|
|
+ * @Version: v1.0
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@CrossOrigin
|
|
|
+@RequestMapping("/mpTool")
|
|
|
+public class MpToolController {
|
|
|
+ @Autowired
|
|
|
+ private ToolUtils toolUtils;
|
|
|
+ @Autowired
|
|
|
+ private LampService lampService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查找设备
|
|
|
+ * @param request 灯控设备地址
|
|
|
+ * @return 灯控设备
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/scanDevice", method = RequestMethod.POST)
|
|
|
+ public BaseResult<?> scanDevice(HttpServletRequest request) {
|
|
|
+ Integer version = (Integer) toolUtils.getRequestContent(request, "version", 1);
|
|
|
+ String sn = (String) toolUtils.getRequestContent(request, "sn", 2);
|
|
|
+ if (sn.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
|
|
|
+
|
|
|
+ LampInfoVO lampInfoVO = new LampInfoVO();
|
|
|
+ List<LampInfoDTO> lampDevList = lampService.findLampDeviceBySn(sn,version);
|
|
|
+ if (lampDevList.isEmpty()) { // 没有查询到设备
|
|
|
+ lampInfoVO.setHasDev(0);
|
|
|
+ } else { // 查询到设备
|
|
|
+ lampInfoVO.setHasDev(1);
|
|
|
+ LampInfoDTO dev1 = lampDevList.get(0);
|
|
|
+ if (dev1.getSection() == null) dev1.setSection("");
|
|
|
+ if (dev1.getArea() == null) dev1.setArea("");
|
|
|
+ if (dev1.getCity() == null) dev1.setCity("");
|
|
|
+ if (dev1.getProvince() == null) dev1.setProvince("");
|
|
|
+ lampInfoVO.setSectionName(dev1.getProvince() + dev1.getCity() + dev1.getArea() + dev1.getSection());
|
|
|
+ int protocolType = dev1.getProtocolType();
|
|
|
+ int controlType = dev1.getControlType();
|
|
|
+ lampInfoVO.setProtocolType(protocolType);
|
|
|
+ lampInfoVO.setControlType(controlType);
|
|
|
+ Set<Integer> controlTypeSet = new HashSet<>(Arrays.asList(5,8,9,22,25,27,29,34));
|
|
|
+ if (controlTypeSet.contains(controlType)) { // 双灯控制器
|
|
|
+ LampInfoDTO dev2 = lampDevList.get(1);
|
|
|
+ lampInfoVO.setIsDb(1);
|
|
|
+ lampInfoVO.setDev1(dev1);
|
|
|
+ lampInfoVO.setDev2(dev2);
|
|
|
+ } else { // 单灯控制器
|
|
|
+ lampInfoVO.setIsDb(0);
|
|
|
+ lampInfoVO.setDev1(dev1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampInfoVO);
|
|
|
+ }
|
|
|
+}
|