update
This commit is contained in:
@@ -21,6 +21,7 @@ import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
@@ -42,14 +43,12 @@ public class DeviceTaskService {
|
||||
@Autowired
|
||||
private WorkRecordMapper workRecordMapper;
|
||||
|
||||
|
||||
@Autowired
|
||||
private DeviceSessionManager deviceSessionManager;
|
||||
|
||||
@Autowired
|
||||
private SysSiteMapper sysSiteMapper;
|
||||
|
||||
|
||||
public int insertOrUpdate(DevicePlan devicePlan, LoginUser loginUser) {
|
||||
Long id = devicePlan.getId();
|
||||
SiteMemory siteMemory = GlobalMemory.getSiteMemory(devicePlan.getOrgId(), devicePlan.getSiteId());
|
||||
@@ -116,7 +115,8 @@ public class DeviceTaskService {
|
||||
}
|
||||
}
|
||||
|
||||
public List<DevicePlan> getSiteDevicePlan(Long siteId, LocalDate startTime, LocalDate endTime, String deviceId, DeviceTaskStaus taskStaus) {
|
||||
public List<DevicePlan> getSiteDevicePlan(Long siteId, LocalDate startTime, LocalDate endTime, String deviceId,
|
||||
DeviceTaskStaus taskStaus) {
|
||||
if (siteId != null) {
|
||||
LambdaQueryWrapper<DevicePlan> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(DevicePlan::getSiteId, siteId);
|
||||
@@ -206,10 +206,10 @@ public class DeviceTaskService {
|
||||
List<DevicePlanStatisticsDTO> list = new ArrayList<>();
|
||||
LocalDate today = LocalDate.now();
|
||||
LocalDateTime monthStart = LocalDateTime.of(
|
||||
today.getYear(), // 当前年
|
||||
today.getMonth(), // 当前月
|
||||
1, // 当月第一天
|
||||
0, 0, 0, 0 // 时:分:秒:纳秒(00:00:00.000)
|
||||
today.getYear(), // 当前年
|
||||
today.getMonth(), // 当前月
|
||||
1, // 当月第一天
|
||||
0, 0, 0, 0 // 时:分:秒:纳秒(00:00:00.000)
|
||||
);
|
||||
LocalDate lastDayOfMonth = today.withDayOfMonth(today.lengthOfMonth()); // 获取当月最后一天
|
||||
LocalDateTime monthEnd = LocalDateTime.of(
|
||||
@@ -226,7 +226,8 @@ public class DeviceTaskService {
|
||||
if (!CollectionUtils.isEmpty(devicePlans)) {
|
||||
List<LocalDate> dates = getMonthDays();
|
||||
for (LocalDate date : dates) {
|
||||
List<DevicePlan> plans = devicePlans.stream().filter(x -> x.getCreateTime().toLocalDate().equals(date)).collect(Collectors.toList());
|
||||
List<DevicePlan> plans = devicePlans.stream().filter(x -> x.getCreateTime().toLocalDate().equals(date))
|
||||
.collect(Collectors.toList());
|
||||
if (!CollectionUtils.isEmpty(plans)) {
|
||||
DevicePlanStatisticsDTO dto = new DevicePlanStatisticsDTO();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("M.d");
|
||||
@@ -260,10 +261,10 @@ public class DeviceTaskService {
|
||||
LocalDate today = LocalDate.now();
|
||||
// 2. 构造当前月份的起始时间:当月第一天 00:00:00
|
||||
LocalDateTime monthStart = LocalDateTime.of(
|
||||
today.getYear(), // 当前年
|
||||
today.getMonth(), // 当前月
|
||||
1, // 当月第一天
|
||||
0, 0, 0, 0 // 时:分:秒:纳秒(00:00:00.000)
|
||||
today.getYear(), // 当前年
|
||||
today.getMonth(), // 当前月
|
||||
1, // 当月第一天
|
||||
0, 0, 0, 0 // 时:分:秒:纳秒(00:00:00.000)
|
||||
);
|
||||
// 3. 构造当前月份的结束时间:当月最后一天 23:59:59.999
|
||||
LocalDate lastDayOfMonth = today.withDayOfMonth(today.lengthOfMonth()); // 获取当月最后一天
|
||||
@@ -277,9 +278,11 @@ public class DeviceTaskService {
|
||||
LambdaQueryWrapper<DevicePlan> query = new LambdaQueryWrapper<>();
|
||||
query.eq(DevicePlan::getUserId, userId);
|
||||
List<DevicePlan> devicePlans = transferDevicePlanData(devicePlanMapper.selectList(query));
|
||||
if (CollectionUtils.isEmpty(devicePlans)) return new ArrayList<>();
|
||||
if (CollectionUtils.isEmpty(devicePlans))
|
||||
return new ArrayList<>();
|
||||
List<Long> planIds = devicePlans.stream().map(DevicePlan::getId).collect(Collectors.toList());
|
||||
if (CollectionUtils.isEmpty(planIds)) return new ArrayList<>();
|
||||
if (CollectionUtils.isEmpty(planIds))
|
||||
return new ArrayList<>();
|
||||
|
||||
LambdaQueryWrapper<DevicePlanTask> queryWrapper = new LambdaQueryWrapper<>();
|
||||
// 核心:筛选 createTime 大于等于起始时间,且小于等于结束时间
|
||||
@@ -290,16 +293,20 @@ public class DeviceTaskService {
|
||||
if (!CollectionUtils.isEmpty(devicePlanTasks)) {
|
||||
List<LocalDate> dates = getMonthDays();
|
||||
for (LocalDate date : dates) {
|
||||
List<DevicePlanTask> planTasks = devicePlanTasks.stream().filter(x -> x.getCreateTime().toLocalDate().equals(date)).collect(Collectors.toList());
|
||||
List<DevicePlanTask> planTasks = devicePlanTasks.stream()
|
||||
.filter(x -> x.getCreateTime().toLocalDate().equals(date)).collect(Collectors.toList());
|
||||
if (!CollectionUtils.isEmpty(planTasks)) {
|
||||
DevicePlanTaskStatisticsDTO dto = new DevicePlanTaskStatisticsDTO();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("M.d");
|
||||
dto.setDate(formatter.format(date));
|
||||
long finishCount = planTasks.stream().filter(x -> DeviceTaskStaus.FINISH.equals(x.getTaskStaus())).count();
|
||||
long finishCount = planTasks.stream().filter(x -> DeviceTaskStaus.FINISH.equals(x.getTaskStaus()))
|
||||
.count();
|
||||
dto.setSuccess((int) finishCount);
|
||||
long failedCount = planTasks.stream().filter(x -> DeviceTaskStaus.FAILED.equals(x.getTaskStaus())).count();
|
||||
long failedCount = planTasks.stream().filter(x -> DeviceTaskStaus.FAILED.equals(x.getTaskStaus()))
|
||||
.count();
|
||||
dto.setFailed((int) failedCount);
|
||||
long pauseCount = planTasks.stream().filter(x -> DeviceTaskStaus.PAUSE.equals(x.getTaskStaus())).count();
|
||||
long pauseCount = planTasks.stream().filter(x -> DeviceTaskStaus.PAUSE.equals(x.getTaskStaus()))
|
||||
.count();
|
||||
dto.setPaused((int) pauseCount);
|
||||
list.add(dto);
|
||||
}
|
||||
@@ -308,7 +315,6 @@ public class DeviceTaskService {
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public WorkRecord concurrentDevicePlanTask(String deviceId) {
|
||||
LambdaQueryWrapper<DevicePlanTask> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(DevicePlanTask::getDeviceId, deviceId)
|
||||
@@ -318,9 +324,8 @@ public class DeviceTaskService {
|
||||
return routId == null ? null : workRecordMapper.selectById(routId);
|
||||
}
|
||||
|
||||
|
||||
public List<DeviceWorkStatisticsDTO> workStatistics(Long userId) {
|
||||
//todo update
|
||||
// todo update
|
||||
|
||||
List<DeviceWorkStatisticsDTO> result = new ArrayList<>();
|
||||
Random random = new Random();
|
||||
@@ -341,7 +346,6 @@ public class DeviceTaskService {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public List<DevicePlanTask> deviceTaskPool(DeviceTaskQueryDTO dto) {
|
||||
List<DevicePlanTask> list = new ArrayList<>();
|
||||
if (dto.getOrgId() == null) {
|
||||
@@ -394,9 +398,9 @@ public class DeviceTaskService {
|
||||
return transferDeviceTaskData(devicePlanTaskMapper.selectList(queryWrapper));
|
||||
}
|
||||
|
||||
|
||||
public List<DevicePlan> transferDevicePlanData(List<DevicePlan> list) {
|
||||
if (CollectionUtils.isEmpty(list)) return list;
|
||||
if (CollectionUtils.isEmpty(list))
|
||||
return list;
|
||||
list.forEach(x -> {
|
||||
DeviceTaskStaus taskStaus = x.getTaskStaus();
|
||||
x.setTaskStausTranslate(taskStaus.getDescription());
|
||||
@@ -405,11 +409,17 @@ public class DeviceTaskService {
|
||||
}
|
||||
|
||||
public List<DevicePlanTask> transferDeviceTaskData(List<DevicePlanTask> list) {
|
||||
if (CollectionUtils.isEmpty(list)) return list;
|
||||
if (CollectionUtils.isEmpty(list))
|
||||
return list;
|
||||
list.forEach(x -> {
|
||||
DeviceTaskStaus taskStaus = x.getTaskStaus();
|
||||
x.setTaskStausTranslate(taskStaus.getDescription());
|
||||
});
|
||||
list.sort(
|
||||
Comparator.comparing(DevicePlanTask::getFinishTime,
|
||||
Comparator.nullsLast(Comparator.reverseOrder()))
|
||||
.thenComparing(DevicePlanTask::getCreateTime,
|
||||
Comparator.nullsLast(Comparator.reverseOrder())));
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -443,8 +453,8 @@ public class DeviceTaskService {
|
||||
}
|
||||
} else {
|
||||
Long taskId = dto.getTaskId();
|
||||
// Long siteId = dto.getSiteId();
|
||||
// Long orgId = dto.getOrgId();
|
||||
// Long siteId = dto.getSiteId();
|
||||
// Long orgId = dto.getOrgId();
|
||||
DevicePlanTask devicePlanTask = devicePlanTaskMapper.selectById(taskId);
|
||||
if (devicePlanTask != null) {
|
||||
NettyDevice device = deviceSessionManager.getDevice(devicePlanTask.getDeviceId());
|
||||
@@ -456,7 +466,7 @@ public class DeviceTaskService {
|
||||
return false;
|
||||
}
|
||||
|
||||
//todo 完善
|
||||
// todo 完善
|
||||
public boolean pauseTask(DeviceTaskCommandDTO dto, String username) {
|
||||
if (!StringUtils.isEmpty(dto.getDeviceId())) {
|
||||
NettyDevice device = deviceSessionManager.getDevice(dto.getDeviceId());
|
||||
@@ -467,18 +477,17 @@ public class DeviceTaskService {
|
||||
Long taskId = dto.getTaskId();
|
||||
DevicePlanTask devicePlanTask = devicePlanTaskMapper.selectById(taskId);
|
||||
if (devicePlanTask != null) {
|
||||
devicePlanTask.setUpdateTime(LocalDateTime.now());
|
||||
devicePlanTask.setTaskStaus(DeviceTaskStaus.PAUSE);
|
||||
devicePlanTask.setUpdateBy(username);
|
||||
devicePlanTaskMapper.saveOrUpdate(devicePlanTask);
|
||||
NettyDevice device = deviceSessionManager.getDevice(devicePlanTask.getDeviceId());
|
||||
if (device != null) {
|
||||
return device.pauseTask();
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//todo 完善
|
||||
public boolean recoveryTask(DeviceTaskCommandDTO dto, String username) {
|
||||
// todo 完善
|
||||
public boolean recoveryTask(DeviceTaskCommandDTO dto, String username) throws InterruptedException {
|
||||
if (!StringUtils.isEmpty(dto.getDeviceId())) {
|
||||
NettyDevice device = deviceSessionManager.getDevice(dto.getDeviceId());
|
||||
if (device != null) {
|
||||
@@ -486,16 +495,12 @@ public class DeviceTaskService {
|
||||
}
|
||||
} else {
|
||||
Long taskId = dto.getTaskId();
|
||||
Long siteId = dto.getSiteId();
|
||||
Long orgId = dto.getOrgId();
|
||||
DevicePlanTask devicePlanTask = devicePlanTaskMapper.selectById(taskId);
|
||||
SiteMemory siteMemory = GlobalMemory.getSiteMemory(orgId, siteId);
|
||||
DevicePlanTask executeTask = siteMemory.getDeviceExecuteTask(devicePlanTask.getDeviceId());
|
||||
if (Objects.equals(devicePlanTask.getId(), executeTask.getId())) {
|
||||
devicePlanTask.setUpdateTime(LocalDateTime.now());
|
||||
devicePlanTask.setTaskStaus(DeviceTaskStaus.EXECUTING);
|
||||
devicePlanTask.setUpdateBy(username);
|
||||
devicePlanTaskMapper.saveOrUpdate(devicePlanTask);
|
||||
if (devicePlanTask != null) {
|
||||
NettyDevice device = deviceSessionManager.getDevice(devicePlanTask.getDeviceId());
|
||||
if (device != null) {
|
||||
return device.recoveryTask();
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user