#区域连续作业相关
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.maibu.controller;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
@@ -14,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.maibu.core.business.DevicePlan;
|
||||
import com.maibu.core.business.dto.ConsecutiveTaskDTO;
|
||||
import com.maibu.core.business.dto.DeviceTaskCommandDTO;
|
||||
import com.maibu.core.controller.BaseController;
|
||||
import com.maibu.core.domain.AjaxResult;
|
||||
@@ -121,6 +123,14 @@ public class DeviceTaskController extends BaseController {
|
||||
if (siteMemory.hasTask(deviceId)) {
|
||||
return AjaxResult.error("当前设备存在任务!");
|
||||
}
|
||||
Integer mode = siteMemory.getDeviceControlMode(deviceId);
|
||||
if (mode == null) {
|
||||
return AjaxResult.error("当前设备模式不存在,无法自动任务!");
|
||||
}
|
||||
if (mode != 2) {
|
||||
String modeStr = switchMode(mode);
|
||||
return AjaxResult.error("当前设备模式:" + modeStr + ",无法自动任务!");
|
||||
}
|
||||
return AjaxResult.success(deviceTaskService.createDeviceTask(dto, getLoginUser().getUsername()));
|
||||
}
|
||||
|
||||
@@ -146,6 +156,14 @@ public class DeviceTaskController extends BaseController {
|
||||
if (siteMemory.hasTask(deviceId)) {
|
||||
return AjaxResult.error("当前设备存在任务!");
|
||||
}
|
||||
Integer mode = siteMemory.getDeviceControlMode(deviceId);
|
||||
if (mode == null) {
|
||||
return AjaxResult.error("当前设备模式不存在,无法自动任务!");
|
||||
}
|
||||
if (mode != 2) {
|
||||
String modeStr = switchMode(mode);
|
||||
return AjaxResult.error("当前设备模式:" + modeStr + ",无法自动任务!");
|
||||
}
|
||||
return AjaxResult.success(deviceTaskService.createRegionDeviceTask(dto, getLoginUser().getUsername()));
|
||||
}
|
||||
|
||||
@@ -194,7 +212,70 @@ public class DeviceTaskController extends BaseController {
|
||||
if (siteMemory.hasTask(deviceId)) {
|
||||
return AjaxResult.error("当前设备存在任务!");
|
||||
}
|
||||
Integer mode = siteMemory.getDeviceControlMode(deviceId);
|
||||
if (mode == null) {
|
||||
return AjaxResult.error("当前设备模式不存在,无法自动任务!");
|
||||
}
|
||||
if (mode != 2) {
|
||||
String modeStr = switchMode(mode);
|
||||
return AjaxResult.error("当前设备模式:" + modeStr + ",无法自动任务!");
|
||||
}
|
||||
return AjaxResult.success(deviceTaskService.backToRestPoint(dto, getLoginUser().getUsername()));
|
||||
}
|
||||
|
||||
@PostMapping("/createConsecutiveTasks")
|
||||
public AjaxResult createConsecutiveTasks(@RequestBody ConsecutiveTaskDTO dto) {
|
||||
String deviceId = dto.getDeviceId();
|
||||
Long siteId = dto.getSiteId();
|
||||
Long orgId = dto.getOrgId();
|
||||
if (StringUtils.isEmpty(deviceId)) {
|
||||
return AjaxResult.error("deviceId为空!");
|
||||
}
|
||||
if (siteId == null) {
|
||||
return AjaxResult.error("siteId为空!");
|
||||
}
|
||||
if (orgId == null) {
|
||||
return AjaxResult.error("orgId为空!");
|
||||
}
|
||||
SiteMemory siteMemory = GlobalMemory.getSiteMemory(orgId, siteId);
|
||||
if (siteMemory.hasTask(deviceId)) {
|
||||
return AjaxResult.error("当前设备存在任务!");
|
||||
}
|
||||
Integer mode = siteMemory.getDeviceControlMode(deviceId);
|
||||
if (mode == null) {
|
||||
return AjaxResult.error("当前设备模式不存在,无法自动任务!");
|
||||
}
|
||||
if (mode != 2) {
|
||||
String modeStr = switchMode(mode);
|
||||
return AjaxResult.error("当前设备模式:" + modeStr + ",无法自动任务!");
|
||||
}
|
||||
deviceTaskService.createConsecutiveTasks(dto, getLoginUser().getUsername());
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
public String switchMode(Integer mode) {
|
||||
String modeStr = "";
|
||||
switch (mode) {
|
||||
case 0:
|
||||
modeStr = "无控制";
|
||||
break;
|
||||
case 1:
|
||||
modeStr = "本地遥控";
|
||||
break;
|
||||
case 2:
|
||||
modeStr = "自动任务";
|
||||
break;
|
||||
case 3:
|
||||
modeStr = "远程遥控";
|
||||
break;
|
||||
}
|
||||
return modeStr;
|
||||
}
|
||||
|
||||
@PostMapping("/cancelConsecutiveTask")
|
||||
public AjaxResult cancelConsecutiveTask(@RequestBody List<String> deviceIds) throws MqttException {
|
||||
deviceTaskService.cancelConsecutiveTask(deviceIds);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user