#update
This commit is contained in:
@@ -2,6 +2,7 @@ package com.maibu.controller;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
@@ -125,14 +126,10 @@ 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 + ",无法自动任务!");
|
||||
// }
|
||||
if (!siteMemory.canReceiveAutoTask(deviceId)) {
|
||||
return AjaxResult.error("当前设备模式无法自动任务,请先切换模式!");
|
||||
}
|
||||
|
||||
return AjaxResult.success(deviceTaskService.createDeviceTask(dto, getLoginUser().getUsername()));
|
||||
}
|
||||
|
||||
@@ -158,14 +155,10 @@ 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 + ",无法自动任务!");
|
||||
// }
|
||||
|
||||
if (!siteMemory.canReceiveAutoTask(deviceId)) {
|
||||
return AjaxResult.error("当前设备模式无法自动任务,请先切换模式!");
|
||||
}
|
||||
return AjaxResult.success(deviceTaskService.createRegionDeviceTask(dto, getLoginUser().getUsername()));
|
||||
}
|
||||
|
||||
@@ -214,14 +207,9 @@ 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 + ",无法自动任务!");
|
||||
// }
|
||||
if (!siteMemory.canReceiveAutoTask(deviceId)) {
|
||||
return AjaxResult.error("当前设备模式无法自动任务,请先切换模式!");
|
||||
}
|
||||
return AjaxResult.success(deviceTaskService.backToRestPoint(dto, getLoginUser().getUsername()));
|
||||
}
|
||||
|
||||
@@ -243,14 +231,9 @@ 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 + ",无法自动任务!");
|
||||
// }
|
||||
if (!siteMemory.canReceiveAutoTask(deviceId)) {
|
||||
return AjaxResult.error("当前设备模式无法自动任务,请先切换模式!");
|
||||
}
|
||||
deviceTaskService.createConsecutiveTasks(dto, getLoginUser().getUsername());
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
@@ -124,7 +124,9 @@ public class CommandForwardHandler extends SimpleChannelInboundHandler<String> {
|
||||
data.setValid_for_ms(250); // 间隔 可调整
|
||||
deviceRemoteControlDTO.setData(data);
|
||||
deviceRemoteControlDTO
|
||||
.setCommand_id(Constant.remote_control_cmd_prefix + System.currentTimeMillis());
|
||||
.setCommand_id(
|
||||
Constant.remote_control_cmd_prefix + target.getConnectorId() + "_"
|
||||
+ System.currentTimeMillis());
|
||||
deviceRemoteControlDTO.setSn(target.getConnectorId());
|
||||
deviceRemoteControlDTO.setTimestamp(System.currentTimeMillis());
|
||||
deviceRemoteControlDTO
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.maibu.core.business.DevicePlanTask;
|
||||
import com.maibu.core.business.DeviceTaskPlanRule;
|
||||
import com.maibu.core.business.WorkRecord;
|
||||
import com.maibu.core.business.device.NettyDevice;
|
||||
import com.maibu.core.domain.AjaxResult;
|
||||
import com.maibu.core.enums.DeviceTaskPlanRepeatType;
|
||||
import com.maibu.core.enums.DeviceTaskStaus;
|
||||
import com.maibu.mapper.DevicePlanMapper;
|
||||
@@ -64,6 +65,8 @@ public class DevicePlanTaskMonitorService {
|
||||
List<SiteMemory> list = GlobalMemory.getAllSiteMemory();
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
list.forEach(siteMemory -> {
|
||||
if (siteMemory == null)
|
||||
return;
|
||||
Map<String, List<DevicePlan>> planMap = siteMemory.devicePlanMap;
|
||||
if (!CollectionUtils.isEmpty(planMap.values())) {
|
||||
Iterator<String> iterator = planMap.keySet().iterator();
|
||||
@@ -73,7 +76,13 @@ public class DevicePlanTaskMonitorService {
|
||||
if (!CollectionUtils.isEmpty(pLlist)) {
|
||||
pLlist.forEach(t -> {
|
||||
try {
|
||||
createPlanTask(t);
|
||||
if (siteMemory.hasTask(t.getDeviceId())) {
|
||||
return;
|
||||
}
|
||||
if (!siteMemory.canReceiveAutoTask(t.getDeviceId())) {
|
||||
return;
|
||||
} // 检验权限
|
||||
createPlanTask(t, siteMemory);
|
||||
} catch (Exception e) {
|
||||
log.error("执行任务生成线程错误", e);
|
||||
}
|
||||
@@ -90,7 +99,7 @@ public class DevicePlanTaskMonitorService {
|
||||
}, 0, 5000, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
private void createPlanTask(DevicePlan devicePlan) throws Exception {
|
||||
private void createPlanTask(DevicePlan devicePlan, SiteMemory siteMemory) throws Exception {
|
||||
if (devicePlan.isDayTriggerFlag())
|
||||
return; // 当天应该创建的全部创建完
|
||||
DeviceTaskPlanRule rules = devicePlan.getDeviceTaskPlanRules();
|
||||
@@ -98,13 +107,13 @@ public class DevicePlanTaskMonitorService {
|
||||
DeviceTaskPlanRepeatType type = rules.getType();
|
||||
switch (type) {
|
||||
case DAY:
|
||||
dayPlan(devicePlan);
|
||||
dayPlan(devicePlan, siteMemory);
|
||||
break;
|
||||
case WEEK:
|
||||
weekPlan(devicePlan);
|
||||
weekPlan(devicePlan, siteMemory);
|
||||
break;
|
||||
case MONTH:
|
||||
monthPlan(devicePlan);
|
||||
monthPlan(devicePlan, siteMemory);
|
||||
break;
|
||||
// case ONCE:
|
||||
// oncePlan(devicePlan);
|
||||
@@ -113,10 +122,11 @@ public class DevicePlanTaskMonitorService {
|
||||
}
|
||||
}
|
||||
|
||||
public void dayPlan(DevicePlan devicePlan) throws Exception {
|
||||
public void dayPlan(DevicePlan devicePlan, SiteMemory siteMemory) throws Exception {
|
||||
DeviceTaskPlanRule rules = devicePlan.getDeviceTaskPlanRules();
|
||||
LocalTime nowTime = LocalTime.now();
|
||||
LocalTime dayTime = LocalTime.parse(rules.getDayTime());
|
||||
|
||||
if (nowTime.isAfter(dayTime)) {
|
||||
DevicePlanTask devicePlanTask = new DevicePlanTask();
|
||||
devicePlanTask.setPlanId(devicePlan.getId());
|
||||
@@ -135,12 +145,6 @@ public class DevicePlanTaskMonitorService {
|
||||
devicePlanTask.setOrgId(devicePlan.getOrgId());
|
||||
devicePlanTask.setSiteId(devicePlan.getSiteId());
|
||||
devicePlanTaskMapper.insert(devicePlanTask);
|
||||
SiteMemory siteMemory = GlobalMemory.getSiteMemory(devicePlan.getOrgId(), devicePlan.getSiteId());
|
||||
|
||||
if (!deviceTaskService.sendAutoTaskMode(siteMemory, devicePlan.getDeviceId())) {
|
||||
log.debug("创建dayPlan切换权限失败!");
|
||||
return;
|
||||
} // 检验权限
|
||||
|
||||
siteMemory.addDevicePlanPrepare(devicePlanTask);
|
||||
// 啥时候重置?每日0点?
|
||||
@@ -159,7 +163,7 @@ public class DevicePlanTaskMonitorService {
|
||||
}
|
||||
}
|
||||
|
||||
public void weekPlan(DevicePlan devicePlan) throws Exception {
|
||||
public void weekPlan(DevicePlan devicePlan, SiteMemory siteMemory) throws Exception {
|
||||
DeviceTaskPlanRule rules = devicePlan.getDeviceTaskPlanRules();
|
||||
LocalTime nowTime = LocalTime.now();
|
||||
List<DayOfWeek> days = devicePlan.getDeviceTaskPlanRules().getDays();
|
||||
@@ -184,11 +188,7 @@ public class DevicePlanTaskMonitorService {
|
||||
devicePlanTask.setSiteId(devicePlan.getSiteId());
|
||||
devicePlanTask.setTaskType("");// 待拓展任务类型
|
||||
devicePlanTaskMapper.insert(devicePlanTask);
|
||||
SiteMemory siteMemory = GlobalMemory.getSiteMemory(devicePlan.getOrgId(), devicePlan.getSiteId());
|
||||
if (!deviceTaskService.sendAutoTaskMode(siteMemory, devicePlan.getDeviceId())) {
|
||||
log.debug("创建weekPlan切换权限失败!");
|
||||
return;
|
||||
} // 检验权限
|
||||
|
||||
siteMemory.addDevicePlanPrepare(devicePlanTask);
|
||||
// 啥时候重置?每日0点?
|
||||
devicePlan.setDayTriggerFlag(true);
|
||||
@@ -205,7 +205,7 @@ public class DevicePlanTaskMonitorService {
|
||||
}
|
||||
}
|
||||
|
||||
public void monthPlan(DevicePlan devicePlan) throws Exception {
|
||||
public void monthPlan(DevicePlan devicePlan,SiteMemory siteMemory) throws Exception {
|
||||
DeviceTaskPlanRule rules = devicePlan.getDeviceTaskPlanRules();
|
||||
List<Integer> dayOfMonthList = rules.getDayOfMonth();
|
||||
LocalDate today = LocalDate.now();
|
||||
@@ -230,12 +230,7 @@ public class DevicePlanTaskMonitorService {
|
||||
devicePlanTask.setOrgId(devicePlan.getOrgId());
|
||||
devicePlanTask.setSiteId(devicePlan.getSiteId());
|
||||
devicePlanTaskMapper.insert(devicePlanTask);
|
||||
SiteMemory siteMemory = GlobalMemory.getSiteMemory(devicePlan.getOrgId(), devicePlan.getSiteId());
|
||||
|
||||
if (!deviceTaskService.sendAutoTaskMode(siteMemory, devicePlan.getDeviceId())) {
|
||||
log.debug("创建monthPlan切换权限失败!");
|
||||
return;
|
||||
} // 检验权限
|
||||
siteMemory.addDevicePlanPrepare(devicePlanTask);
|
||||
// 啥时候重置?每日0点?
|
||||
devicePlan.setDayTriggerFlag(true);
|
||||
|
||||
@@ -529,10 +529,6 @@ public class DeviceTaskService {
|
||||
public synchronized Long createDeviceTask(DeviceTaskCommandDTO dto, String username) throws Exception {
|
||||
SiteMemory siteMemory = GlobalMemory.getSiteMemory(dto.getOrgId(), dto.getSiteId());
|
||||
|
||||
boolean b = sendAutoTaskMode(siteMemory, dto.getDeviceId()); // 检验权限
|
||||
if (!b) {
|
||||
throw new ServiceException(MessageUtils.message("当前状态无法执行自动任务!"));
|
||||
}
|
||||
DevicePlanTask task = new DevicePlanTask();
|
||||
task.setOrgId(dto.getOrgId());
|
||||
task.setSiteId(dto.getSiteId());
|
||||
@@ -575,10 +571,10 @@ public class DeviceTaskService {
|
||||
}
|
||||
|
||||
SiteMemory siteMemory = GlobalMemory.getSiteMemory(dto.getOrgId(), dto.getSiteId());
|
||||
boolean b = sendAutoTaskMode(siteMemory, dto.getDeviceId()); // 检验权限
|
||||
if (!b) {
|
||||
throw new ServiceException(MessageUtils.message("当前状态无法执行自动任务!"));
|
||||
}
|
||||
// boolean b = sendAutoTaskMode(siteMemory, dto.getDeviceId()); // 检验权限
|
||||
// if (!b) {
|
||||
// throw new ServiceException(MessageUtils.message("当前状态无法执行自动任务!"));
|
||||
// }
|
||||
if (dto.getOrgId() == null) {
|
||||
SysSite site = sysSiteMapper.selectById(dto.getSiteId());
|
||||
if (site != null) {
|
||||
@@ -621,7 +617,7 @@ public class DeviceTaskService {
|
||||
if (device != null && device.getTask() != null) {
|
||||
if (dto.isForceCancel()) {
|
||||
device.cancelingTask();
|
||||
return device.canceledTask() != null;
|
||||
return device.canceledTask("人为强制取消") != null;
|
||||
} else {
|
||||
return device.cancelingTask();
|
||||
}
|
||||
@@ -703,10 +699,10 @@ public class DeviceTaskService {
|
||||
throw new ServiceException(MessageUtils.message("当前机器未配置返回点!"));
|
||||
}
|
||||
|
||||
boolean b = sendAutoTaskMode(siteMemory, dto.getDeviceId()); // 检验权限
|
||||
if (!b) {
|
||||
throw new ServiceException(MessageUtils.message("当前状态无法执行自动任务!"));
|
||||
}
|
||||
// boolean b = sendAutoTaskMode(siteMemory, dto.getDeviceId()); // 检验权限
|
||||
// if (!b) {
|
||||
// throw new ServiceException(MessageUtils.message("当前状态无法执行自动任务!"));
|
||||
// }
|
||||
|
||||
List<RestPoint> restPoints = objectMapper.convertValue(
|
||||
siteMapInfo.getRestPoints(),
|
||||
@@ -756,10 +752,10 @@ public class DeviceTaskService {
|
||||
if (siteMemory == null) {
|
||||
throw new ServiceException(MessageUtils.message("任务下发出错!"));
|
||||
}
|
||||
boolean b = sendAutoTaskMode(siteMemory, dto.getDeviceId()); // 检验权限
|
||||
if (!b) {
|
||||
throw new ServiceException(MessageUtils.message("当前状态无法执行自动任务!"));
|
||||
}
|
||||
// boolean b = sendAutoTaskMode(siteMemory, dto.getDeviceId()); // 检验权限
|
||||
// if (!b) {
|
||||
// throw new ServiceException(MessageUtils.message("当前状态无法执行自动任务!"));
|
||||
// }
|
||||
siteMemory.saveRegionConsecutiveTask(dto.getDeviceId(), dto, username);
|
||||
|
||||
}
|
||||
|
||||
@@ -622,7 +622,10 @@ public class DeviceThreadService {
|
||||
if (isAtRestPoint(deviceId, siteMemory)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 判断是否自动模式
|
||||
if (!siteMemory.canReceiveAutoTask(deviceId)) {
|
||||
return;
|
||||
}
|
||||
DeviceTaskCommandDTO dto = new DeviceTaskCommandDTO();
|
||||
dto.setDeviceId(deviceId);
|
||||
dto.setOrgId(siteMemory.getSysSite().getOrgId());
|
||||
|
||||
Reference in New Issue
Block a user