|
@@ -2,23 +2,18 @@ package com.ruoyi.system.service.impl;
|
|
|
|
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.ruoyi.common.exception.base.BaseException;
|
|
|
-import com.ruoyi.system.domain.SiteConfig;
|
|
|
import com.ruoyi.system.domain.SiteInfo;
|
|
|
+import com.ruoyi.system.domain.TaskNotice;
|
|
|
+import com.ruoyi.system.domain.TaskResult;
|
|
|
import com.ruoyi.system.dto.ManualMeasureDTO;
|
|
|
-import com.ruoyi.system.dto.SiteConfigDTO;
|
|
|
-import com.ruoyi.system.dto.SiteInfoDTO;
|
|
|
-import com.ruoyi.system.mapper.SiteConfigMapper;
|
|
|
import com.ruoyi.system.mapper.SiteInfoMapper;
|
|
|
-import com.ruoyi.system.paramet.SiteInfoQuery;
|
|
|
+import com.ruoyi.system.mapper.TaskNoticeMapper;
|
|
|
+import com.ruoyi.system.mapper.TaskResultMapper;
|
|
|
import com.ruoyi.system.service.DirectiveService;
|
|
|
import com.ruoyi.system.service.MqttGateWayService;
|
|
|
-import com.ruoyi.system.service.SiteService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.Date;
|
|
@@ -39,6 +34,12 @@ public class DirectiveServiceImpl implements DirectiveService {
|
|
|
@Resource
|
|
|
MqttGateWayService mqttGateWayService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private TaskNoticeMapper taskNoticeMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TaskResultMapper taskResultMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public boolean manualMeasure(ManualMeasureDTO manualMeasureDTO) {
|
|
|
SiteInfo siteInfo = siteInfoMapper.queryById(manualMeasureDTO.getSiteId());
|
|
@@ -74,14 +75,51 @@ public class DirectiveServiceImpl implements DirectiveService {
|
|
|
throw new BaseException("站点不存在");
|
|
|
}
|
|
|
try {
|
|
|
- log.info("手动停止任务 SiteId:{} action:{}", siteId,action);
|
|
|
+ TaskNotice taskNotice = new TaskNotice();
|
|
|
+ taskNotice.setStartId(0L);
|
|
|
+ taskNotice.setCreateTime(new Date());
|
|
|
+ taskNotice.setId(siteInfo.getId());
|
|
|
+ taskNotice.setSiteId(siteId);
|
|
|
+ TaskResult taskResul = taskResultMapper.queryBySiteIdOne(siteId);
|
|
|
+ if (taskResul == null) {
|
|
|
+ throw new BaseException("当前站点没有任务");
|
|
|
+ }
|
|
|
+ if (action == 0) {
|
|
|
+ taskNotice.setRemark("手动停止任务");
|
|
|
+ if (taskResul.getStatus() == 0 || taskResul.getStatus() == 3) {
|
|
|
+ taskResul.setStatus(1);
|
|
|
+ } else {
|
|
|
+ throw new BaseException("当前站点任务状态不能停止任务");
|
|
|
+ }
|
|
|
+ } else if (action == 1) {
|
|
|
+ taskNotice.setRemark("手动暂停任务");
|
|
|
+ if (taskResul.getStatus() == 0) {
|
|
|
+ taskResul.setStatus(3);
|
|
|
+ } else {
|
|
|
+ throw new BaseException("当前站点任务状态不能暂停任务");
|
|
|
+ }
|
|
|
+ } else if (action == 2) {
|
|
|
+ taskNotice.setRemark("手动继续任务");
|
|
|
+ if (taskResul.getStatus() == 3) {
|
|
|
+ taskResul.setStatus(0);
|
|
|
+ } else {
|
|
|
+ throw new BaseException("当前站点任务状态不能继续任务");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new BaseException("action参数错误");
|
|
|
+ }
|
|
|
+ taskResultMapper.update(taskResul);
|
|
|
+ taskNoticeMapper.insert(taskNotice);
|
|
|
+ log.info("手动停止任务 SiteId:{} Remark:{}", siteId, taskNotice.getRemark());
|
|
|
//TODO 发送mqtt
|
|
|
HashMap<String, Object> requestMap = new HashMap<>();
|
|
|
- requestMap.put("id",siteInfo.getId());
|
|
|
- requestMap.put("action",action);
|
|
|
+ requestMap.put("id", siteInfo.getId());
|
|
|
+ requestMap.put("action", action);
|
|
|
String topic = "down/" + siteInfo.getDeviceId() + "/taskStop";
|
|
|
String data = JSONUtil.toJsonStr(requestMap);
|
|
|
mqttGateWayService.sendMessageToMqtt(data, topic);
|
|
|
+ }catch (BaseException e){
|
|
|
+ throw e;
|
|
|
} catch (Exception e){
|
|
|
log.error("手动测量下发异常", e);
|
|
|
throw new BaseException("手动测量下发异常");
|