opt:优化代码
This commit is contained in:
@@ -8,14 +8,19 @@ import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.b_lms.sch.task.dao.SchBaseTask;
|
||||
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.wms.sch.tasks.InCoolIvtTask;
|
||||
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.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @Author: lyd
|
||||
@@ -24,32 +29,48 @@ import java.util.List;
|
||||
@Slf4j
|
||||
@Component
|
||||
public class AutoIntoHotCacheTask {
|
||||
|
||||
private final String THIS_CLASS = AutoIntoHotCacheTask.class.getName();
|
||||
@Autowired
|
||||
private IschBaseTaskService taskService;
|
||||
@Autowired
|
||||
private RedissonClient redissonClient;
|
||||
|
||||
@SneakyThrows
|
||||
public void run() {
|
||||
log.info("定时对B1入暂存....");
|
||||
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) {
|
||||
RLock lock = redissonClient.getLock(THIS_CLASS);
|
||||
boolean tryLock = lock.tryLock(0, TimeUnit.SECONDS);
|
||||
try {
|
||||
if (tryLock) {
|
||||
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_jo = WQL.getWO("PDA_COOLIN").addParamMap(cache_param).process().uniqueResult(0);
|
||||
if (ObjectUtil.isEmpty(cache_jo) || ObjectUtil.isEmpty(cache_jo.getString("point_code"))) {
|
||||
log.info("烘箱对接位:{} 没找到暂存位!", task.getPoint_code1());
|
||||
return;
|
||||
JSONObject cache_param = JSONObject.parseObject(task.getRemark());
|
||||
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"))) {
|
||||
log.info("烘箱对接位:{} 没找到暂存位!", task.getPoint_code1());
|
||||
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