|
@@ -0,0 +1,125 @@
|
|
|
+package com.welampiot.controller;
|
|
|
+
|
|
|
+import com.welampiot.common.BaseResult;
|
|
|
+import com.welampiot.common.InterfaceResultEnum;
|
|
|
+import com.welampiot.dto.ProjectionLightDTO;
|
|
|
+import com.welampiot.service.ProjectionLightService;
|
|
|
+import com.welampiot.utils.ToolUtils;
|
|
|
+import com.welampiot.vo.ProjectionLightVO;
|
|
|
+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 java.util.List;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@CrossOrigin
|
|
|
+@RequestMapping("/projectionLight")
|
|
|
+public class ProjectionLightController extends BaseController {
|
|
|
+ @Autowired
|
|
|
+ private ProjectionLightService projectionLightService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ToolUtils toolUtils;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取投影灯列表
|
|
|
+ * @param projectionLightVO projectionLightVO
|
|
|
+ * @return 投影灯列表
|
|
|
+ */
|
|
|
+ @PostMapping("/getList")
|
|
|
+ public BaseResult<?> getList(ProjectionLightVO projectionLightVO) {
|
|
|
+ Integer version = projectionLightVO.getVersion();
|
|
|
+ String username = projectionLightVO.getUsername();
|
|
|
+ if (username == null || username.trim().isEmpty()) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR, version);
|
|
|
+ Integer page = projectionLightVO.getPage();
|
|
|
+ Integer count = projectionLightVO.getCount();
|
|
|
+ if (page == null || page < 1) page = 1;
|
|
|
+ if (count == null || count <= 0) count = 16;
|
|
|
+ projectionLightVO.setPage(count * (page - 1));
|
|
|
+ projectionLightVO.setCount(count);
|
|
|
+ List<Integer> sectionList = getSectionList(username);
|
|
|
+ projectionLightVO.setSectionList(sectionList);
|
|
|
+ List<ProjectionLightDTO> projectionLightList = projectionLightService.getProjectionLightList(projectionLightVO);
|
|
|
+ ProjectionLightVO projectionLightVO1 = new ProjectionLightVO();
|
|
|
+ projectionLightVO1.setList(projectionLightList);
|
|
|
+ projectionLightVO1.setTotal(projectionLightList.size());
|
|
|
+ projectionLightVO1.setOnlineCount(projectionLightService.getOnlineProjectionLightCount(sectionList));
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS, version, projectionLightVO1);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取当前图片
|
|
|
+ * @param id 投影灯id
|
|
|
+ */
|
|
|
+ @PostMapping("/currentImage")
|
|
|
+ public BaseResult<?> currentImage(Integer id, Integer version) {
|
|
|
+ if (id == null || id == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR, version);
|
|
|
+ ProjectionLightDTO projectionLightDTO = projectionLightService.getProjectionLightDetailsById(id);
|
|
|
+ if (projectionLightDTO == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL, version);
|
|
|
+ ProjectionLightVO projectionLightVO = new ProjectionLightVO();
|
|
|
+ BeanUtils.copyProperties(projectionLightDTO, projectionLightVO);
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS, version, projectionLightVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 投影灯切换显示图片
|
|
|
+ * @param id 投影灯id
|
|
|
+ */
|
|
|
+ @PostMapping("/chargeImage")
|
|
|
+ public BaseResult<?> chargeImage(Integer id, Integer version, Integer imageNumber) {
|
|
|
+ if (id == null || id == 0 || imageNumber == null) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR, version);
|
|
|
+ ProjectionLightDTO projectionLightDTO = projectionLightService.getProjectionLightDetailsById(id);
|
|
|
+ if (projectionLightDTO == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL, version);
|
|
|
+
|
|
|
+ String sendTopic;
|
|
|
+ String resTopic;
|
|
|
+ if (projectionLightDTO.getWifiModel() == 3 || projectionLightDTO.getWifiModel() == 6) {
|
|
|
+ sendTopic = "/WEGW3/TransIn/";
|
|
|
+ resTopic = "/WEGW3/TransOut/";
|
|
|
+ } else if (projectionLightDTO.getWifiModel() == 1 || projectionLightDTO.getWifiModel() == 5) {
|
|
|
+ sendTopic = "/WEGW2/TransIn/";
|
|
|
+ resTopic = "/WEGW2/TransOut/";
|
|
|
+ } else {
|
|
|
+ sendTopic = "/WEGW/TransIn/";
|
|
|
+ resTopic = "/WEGW/TransOut/";
|
|
|
+ }
|
|
|
+ sendTopic += projectionLightDTO.getWifiNum();
|
|
|
+ resTopic += projectionLightDTO.getWifiNum();
|
|
|
+
|
|
|
+ // 发送的指令内容:投影灯选择图案片
|
|
|
+ String cmd;
|
|
|
+ if (imageNumber == 1) {
|
|
|
+ cmd = "E0070001010101EBEE";
|
|
|
+ } else if (imageNumber == 2) {
|
|
|
+ cmd = "E0070001010102ECEE";
|
|
|
+ } else if (imageNumber == 3) {
|
|
|
+ cmd = "E0070001010103EDEE";
|
|
|
+ } else if (imageNumber == 4) {
|
|
|
+ cmd = "E0070001010104EEEE";
|
|
|
+ } else {
|
|
|
+ return toolUtils.response(InterfaceResultEnum.IMAGE_NUMBER_ERROR, version);
|
|
|
+ }
|
|
|
+
|
|
|
+ projectionLightDTO.setSerialNum(projectionLightDTO.getSerialPort());
|
|
|
+ String cmdInfo;
|
|
|
+ if (projectionLightDTO.getWifiModel() == 3 || projectionLightDTO.getWifiModel() == 6) { // 云盒G300
|
|
|
+ cmdInfo = ToolUtils.getRandomString() + projectionLightDTO.getSerialNum() + cmd;
|
|
|
+ } else {
|
|
|
+ cmdInfo = ToolUtils.getRandomString() + cmd;
|
|
|
+ }
|
|
|
+
|
|
|
+ String backResult = toolUtils.sendMqttCmd(sendTopic, toolUtils.hexString2Bytes(cmdInfo), resTopic);
|
|
|
+ if (backResult != null && !backResult.trim().isEmpty()) {
|
|
|
+ projectionLightDTO.setUpdateTime(ToolUtils.getNowTime());
|
|
|
+ projectionLightDTO.setImageNumber(imageNumber);
|
|
|
+ projectionLightService.updateImageNumber(projectionLightDTO);
|
|
|
+ } else {
|
|
|
+ return toolUtils.response(InterfaceResultEnum.COMMAND_FAIL, version);
|
|
|
+ }
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS, version);
|
|
|
+ }
|
|
|
+}
|