|
|
@ -2,6 +2,7 @@ package org.nl.wms.sch.task_manage.task.tasks.gtx; |
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import lombok.SneakyThrows; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.nl.common.exception.BadRequestException; |
|
|
|
import org.nl.system.service.notice.ISysNoticeService; |
|
|
@ -20,12 +21,16 @@ import org.nl.wms.sch.task_manage.task.core.TaskStatus; |
|
|
|
import org.nl.wms.sch.task_manage.task.tasks.gtx.mapper.HCSSXMapper; |
|
|
|
import org.nl.wms.util.PointUtils; |
|
|
|
import org.nl.wms.util.TaskUtils; |
|
|
|
import org.redisson.api.RLock; |
|
|
|
import org.redisson.api.RedissonClient; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
import java.util.function.Consumer; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
@ -50,39 +55,55 @@ public class HCSSXMLTask extends AbstractTask { |
|
|
|
private HCSSXMapper hcssxMapper; |
|
|
|
@Autowired |
|
|
|
private ISysNoticeService noticeService; |
|
|
|
@Autowired |
|
|
|
private RedissonClient redissonClient; |
|
|
|
|
|
|
|
@SneakyThrows |
|
|
|
@Override |
|
|
|
public void create() throws BadRequestException { |
|
|
|
// 需要找压制、双层输送线的半条任务。
|
|
|
|
// 获取任务
|
|
|
|
List<SchBaseTask> tasks = taskService.findApplyTasksByTaskStatus(TASK_CONFIG_CODE, YZ_TASK_CONFIG_CODE); |
|
|
|
// 配置信息
|
|
|
|
SchBaseTaskconfig taskConfig = taskConfigService.getOne(new LambdaQueryWrapper<SchBaseTaskconfig>() |
|
|
|
.eq(SchBaseTaskconfig::getConfig_code, TASK_CONFIG_CODE)); |
|
|
|
for (SchBaseTask task : tasks) { |
|
|
|
TaskUtils.setUpdateByAcs(task); |
|
|
|
List<String> nextRegionStr = Arrays.stream(taskConfig.getNext_region_str().split(",")) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
// 找终点
|
|
|
|
SchBasePoint point = findNextPoint(nextRegionStr); |
|
|
|
if (ObjectUtil.isEmpty(point)) { |
|
|
|
task.setRemark("入窑口未找到所需点位!"); |
|
|
|
taskService.updateById(task); |
|
|
|
// 消息通知
|
|
|
|
noticeService.createNotice(task.getRemark(), task.getConfig_code() + task.getTask_code(), |
|
|
|
NoticeTypeEnum.WARN.getCode()); |
|
|
|
continue; |
|
|
|
} |
|
|
|
// 设置终点并修改创建成功状态
|
|
|
|
task.setPoint_code2(point.getPoint_code()); |
|
|
|
task.setTask_status(TaskStatus.CREATED.getCode()); |
|
|
|
task.setRemark(""); |
|
|
|
TaskUtils.setUpdateByAcs(task); |
|
|
|
taskService.updateById(task); |
|
|
|
// hint: 防止定时任务与http请求并发问题
|
|
|
|
RLock lock = redissonClient.getLock(TASK_CONFIG_CODE); |
|
|
|
boolean tryLock = lock.tryLock(0, TimeUnit.SECONDS); |
|
|
|
try { |
|
|
|
if (tryLock) { |
|
|
|
// 需要找压制、双层输送线的半条任务。
|
|
|
|
// 获取任务
|
|
|
|
List<SchBaseTask> tasks = taskService.findApplyTasksByTaskStatus(TASK_CONFIG_CODE, YZ_TASK_CONFIG_CODE); |
|
|
|
// 配置信息
|
|
|
|
SchBaseTaskconfig taskConfig = taskConfigService.getOne(new LambdaQueryWrapper<SchBaseTaskconfig>() |
|
|
|
.eq(SchBaseTaskconfig::getConfig_code, TASK_CONFIG_CODE)); |
|
|
|
for (SchBaseTask task : tasks) { |
|
|
|
TaskUtils.setUpdateByAcs(task); |
|
|
|
List<String> nextRegionStr = Arrays.stream(taskConfig.getNext_region_str().split(",")) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
// 找终点
|
|
|
|
SchBasePoint point = findNextPoint(nextRegionStr); |
|
|
|
if (ObjectUtil.isEmpty(point)) { |
|
|
|
task.setRemark("入窑口未找到所需点位!"); |
|
|
|
taskService.updateById(task); |
|
|
|
// 消息通知
|
|
|
|
noticeService.createNotice(task.getRemark(), task.getConfig_code() + task.getTask_code(), |
|
|
|
NoticeTypeEnum.WARN.getCode()); |
|
|
|
return; |
|
|
|
} |
|
|
|
// 设置终点并修改创建成功状态
|
|
|
|
task.setPoint_code2(point.getPoint_code()); |
|
|
|
task.setTask_status(TaskStatus.CREATED.getCode()); |
|
|
|
task.setRemark(""); |
|
|
|
TaskUtils.setUpdateByAcs(task); |
|
|
|
taskService.updateById(task); |
|
|
|
|
|
|
|
point.setIng_task_code(task.getTask_code()); |
|
|
|
PointUtils.setUpdateByAcs(point); |
|
|
|
pointService.updateById(point); |
|
|
|
point.setIng_task_code(task.getTask_code()); |
|
|
|
PointUtils.setUpdateByAcs(point); |
|
|
|
pointService.updateById(point); |
|
|
|
} |
|
|
|
} else { |
|
|
|
throw new BadRequestException("其他设备占用锁,等待结束!"); |
|
|
|
} |
|
|
|
} finally { |
|
|
|
if (tryLock) { |
|
|
|
lock.unlock(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|