|
@@ -1,68 +0,0 @@
|
|
|
-package com.welampiot.tasks;
|
|
|
-
|
|
|
-import com.welampiot.dto.ProjectionLightDTO;
|
|
|
-import com.welampiot.service.ProjectionLightService;
|
|
|
-import com.welampiot.utils.ToolUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.scheduling.annotation.EnableAsync;
|
|
|
-import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
-import org.springframework.scheduling.annotation.Scheduled;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-
|
|
|
-import javax.annotation.PreDestroy;
|
|
|
-import java.util.List;
|
|
|
-import java.util.concurrent.ExecutorService;
|
|
|
-import java.util.concurrent.Executors;
|
|
|
-
|
|
|
-@Component
|
|
|
-@EnableScheduling
|
|
|
-@EnableAsync
|
|
|
-public class Task {
|
|
|
- @Autowired
|
|
|
- private ProjectionLightService projectionLightService;
|
|
|
- @Autowired
|
|
|
- private ToolUtils toolUtils;
|
|
|
-
|
|
|
- private final ExecutorService executorService = Executors.newFixedThreadPool(2);
|
|
|
-
|
|
|
- /**
|
|
|
- * 每分钟更新投影灯在线状态
|
|
|
- */
|
|
|
- @Scheduled(fixedRate = 1000 * 60)
|
|
|
- public void updateProjectionLightOnlineStatus() {
|
|
|
- List<ProjectionLightDTO> projectionLightList = projectionLightService.getAllProjectionLightList();
|
|
|
-
|
|
|
- projectionLightList.forEach(projectionLightDTO -> executorService.submit(() -> updateLightStatus(projectionLightDTO)));
|
|
|
- }
|
|
|
-
|
|
|
- private synchronized void updateLightStatus(ProjectionLightDTO projectionLightDTO) {
|
|
|
- projectionLightDTO.setTopic(projectionLightDTO.getWifiModel(), projectionLightDTO.getWifiNum());
|
|
|
- String sendTopic = projectionLightDTO.getSendTopic();
|
|
|
- String backTopic = projectionLightDTO.getBackTopic();
|
|
|
-
|
|
|
- // 发送指令内容:设置马达速度为中速
|
|
|
- String cmd = "E0070001011201FCEE";
|
|
|
- String cmdInfo;
|
|
|
- if (projectionLightDTO.getWifiModel() == 3 || projectionLightDTO.getWifiModel() == 6) { // 云盒G300
|
|
|
- projectionLightDTO.setSerialNum(projectionLightDTO.getSerialPort());
|
|
|
- cmdInfo = ToolUtils.getRandomString() + projectionLightDTO.getSerialNum() + cmd;
|
|
|
- } else {
|
|
|
- cmdInfo = ToolUtils.getRandomString() + cmd;
|
|
|
- }
|
|
|
-
|
|
|
- String backResult = toolUtils.sendMqttCmd(sendTopic, toolUtils.hexString2Bytes(cmdInfo), backTopic);
|
|
|
- if (backResult != null && !backResult.trim().isEmpty()) {
|
|
|
- projectionLightDTO.setOnline(1);
|
|
|
- } else {
|
|
|
- projectionLightDTO.setOnline(0);
|
|
|
- }
|
|
|
- projectionLightDTO.setUpdateTime(ToolUtils.getNowTime());
|
|
|
- projectionLightService.updateProjectionLightOnline(projectionLightDTO);
|
|
|
- }
|
|
|
-
|
|
|
- @PreDestroy
|
|
|
- public void shutdown() {
|
|
|
- executorService.shutdown();
|
|
|
- }
|
|
|
-
|
|
|
-}
|