opt:优化代码
This commit is contained in:
@@ -8,14 +8,19 @@ import lombok.SneakyThrows;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.nl.b_lms.sch.task.dao.SchBaseTask;
|
import org.nl.b_lms.sch.task.dao.SchBaseTask;
|
||||||
import org.nl.b_lms.sch.task.service.IschBaseTaskService;
|
import org.nl.b_lms.sch.task.service.IschBaseTaskService;
|
||||||
|
import org.nl.b_lms.sch.tasks.first_floor_area.auto.AutoSendToZxq;
|
||||||
import org.nl.modules.wql.WQL;
|
import org.nl.modules.wql.WQL;
|
||||||
import org.nl.wms.sch.tasks.InCoolIvtTask;
|
import org.nl.wms.sch.tasks.InCoolIvtTask;
|
||||||
import org.nl.wms.sch.tasks.InHotTask;
|
import org.nl.wms.sch.tasks.InHotTask;
|
||||||
|
import org.redisson.api.RLock;
|
||||||
|
import org.redisson.api.RedissonClient;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: lyd
|
* @Author: lyd
|
||||||
@@ -24,32 +29,48 @@ import java.util.List;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class AutoIntoHotCacheTask {
|
public class AutoIntoHotCacheTask {
|
||||||
|
private final String THIS_CLASS = AutoIntoHotCacheTask.class.getName();
|
||||||
@Autowired
|
@Autowired
|
||||||
private IschBaseTaskService taskService;
|
private IschBaseTaskService taskService;
|
||||||
|
@Autowired
|
||||||
|
private RedissonClient redissonClient;
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public void run() {
|
public void run() {
|
||||||
log.info("定时对B1入暂存....");
|
log.info("定时对B1入暂存....");
|
||||||
List<SchBaseTask> tasks = taskService.list(new LambdaQueryWrapper<SchBaseTask>()
|
RLock lock = redissonClient.getLock(THIS_CLASS);
|
||||||
.eq(SchBaseTask::getTask_type, "010206")
|
boolean tryLock = lock.tryLock(0, TimeUnit.SECONDS);
|
||||||
.eq(SchBaseTask::getIs_delete, "0")
|
try {
|
||||||
.eq(SchBaseTask::getTask_status, TaskStatusEnum.SURE_START.getCode()));
|
if (tryLock) {
|
||||||
for (SchBaseTask task : tasks) {
|
List<SchBaseTask> tasks = taskService.list(new LambdaQueryWrapper<SchBaseTask>()
|
||||||
|
.eq(SchBaseTask::getTask_type, "010206")
|
||||||
|
.eq(SchBaseTask::getIs_delete, "0")
|
||||||
|
.eq(SchBaseTask::getTask_status, TaskStatusEnum.SURE_START.getCode()));
|
||||||
|
for (SchBaseTask task : tasks) {
|
||||||
|
|
||||||
JSONObject cache_param = JSONObject.parseObject(task.getRemark());
|
JSONObject cache_param = JSONObject.parseObject(task.getRemark());
|
||||||
JSONObject cache_jo = WQL.getWO("PDA_COOLIN").addParamMap(cache_param).process().uniqueResult(0);
|
JSONObject cache_jo = WQL.getWO("PDA_COOLIN").addParamMap(cache_param).process().uniqueResult(0);
|
||||||
if (ObjectUtil.isEmpty(cache_jo) || ObjectUtil.isEmpty(cache_jo.getString("point_code"))) {
|
if (ObjectUtil.isEmpty(cache_jo) || ObjectUtil.isEmpty(cache_jo.getString("point_code"))) {
|
||||||
log.info("烘箱对接位:{} 没找到暂存位!", task.getPoint_code1());
|
log.info("烘箱对接位:{} 没找到暂存位!", task.getPoint_code1());
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
new InHotTask().immediateNotifyAcs(task.getTask_id());
|
||||||
|
|
||||||
|
task.setTask_status(TaskStatusEnum.START_AND_POINT.getCode());
|
||||||
|
task.setPoint_code2(cache_jo.getString("point_code"));
|
||||||
|
task.setRemark("-");
|
||||||
|
task.setUpdate_time(DateUtil.now());
|
||||||
|
task.setTask_type("010204");
|
||||||
|
taskService.updateById(task);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.info("定时对B1入暂存任务被锁住。");
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
|
||||||
|
lock.unlock();
|
||||||
}
|
}
|
||||||
task.setTask_status(TaskStatusEnum.START_AND_POINT.getCode());
|
|
||||||
task.setPoint_code2(cache_jo.getString("point_code"));
|
|
||||||
task.setRemark("-");
|
|
||||||
task.setUpdate_time(DateUtil.now());
|
|
||||||
task.setTask_type("010204");
|
|
||||||
taskService.updateById(task);
|
|
||||||
new InHotTask().immediateNotifyAcs(task.getTask_id());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user