DESKTOP-LMJ82IJ\Eno
2025-01-07 adfce6c5a94c7aefa9b5d4f67e63db7eaac268d9
zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/timer/TaskTimer.java
@@ -1,6 +1,7 @@
package com.zy.asrs.wms.asrs.timer;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.plugins.IgnoreStrategy;
import com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper;
import com.zy.asrs.framework.exception.CoolException;
@@ -8,6 +9,7 @@
import com.zy.asrs.wms.asrs.entity.enums.LocStsType;
import com.zy.asrs.wms.asrs.entity.enums.TaskStsType;
import com.zy.asrs.wms.asrs.service.*;
import io.jsonwebtoken.lang.Collections;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
@@ -15,8 +17,11 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
@Component
@@ -58,9 +63,12 @@
    @Autowired
    private OrderDetlService orderDetlService;
    @Autowired
    private CacheSiteService cacheSiteService;
    @Scheduled(cron = "0/30 * * * * ? ")
    @Transactional
    @Scheduled(cron = "0/3 * * * * ? ")
    @Transactional(rollbackFor = Exception.class)
    public void inExecute() {
        InterceptorIgnoreHelper.handle(IgnoreStrategy.builder().tenantLine(true).build());
        try {
@@ -100,8 +108,30 @@
        }
    }
//    @Scheduled(cron = "0/3 * * * * ? ")
    @Transactional
    /**
     * 1. 定时拉取需要执行回库任务列表数据,
     * 2. 删除原始库位明细,原始库位状态置成O.空库
     * 3.
     */
    @Scheduled(cron = "0/3 * * * * ? ")
    @Transactional(rollbackFor = Exception.class)
    public void rollbackStock() {
        //获取需要执行回库的任务,更新库存信息
        List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getTaskType, 53).eq(Task::getTaskSts, TaskStsType.WCS_CONVEYOR_START.id));
        if (tasks.isEmpty()) {
            return;
        }
        tasks.forEach(task -> {
            //删除原始库位明细,状态置为O.空库
            executeTask103(task);
        });
        //todo 需添加一个任务状态或临时状态,否则会一直轮循,程序报错(库位状态不处于R.出库预约)
    }
    @Scheduled(cron = "0/10 * * * * ? ")
    @Transactional(rollbackFor = Exception.class)
    public void outExecute() {
        InterceptorIgnoreHelper.handle(IgnoreStrategy.builder().tenantLine(true).build());
        try {
@@ -113,7 +143,7 @@
            for (Task task : list) {
                //同步数据
                switch (task.getTaskType().intValue()) {
                    case 101://出库
                    case 101://出库xx
                        executeTask101(task);
                        break;
                    case 103://拣料
@@ -122,13 +152,24 @@
                    default:
                        throw new CoolException("未知任务类型");
                }
                task.setTaskSts(TaskStsType.UPDATED_OUT.id);//200.库存更新完成
                if (!taskService.updateById(task)) {
                    throw new CoolException("库存更新失败");
                } else {
                    //CacheSite 释放已被占用的通道 //fixme 播种功能完成后,需要将这里注释掉
//                    List<TaskDetl> detls = taskDetlService.list(new LambdaQueryWrapper<TaskDetl>().eq(TaskDetl::getTaskId, task.getId()));
//                    if (!Collections.isEmpty(detls)) {
//                        List<Long> waveIds = detls.stream().map(TaskDetl::getWaveId).collect(Collectors.toList());
//                        List<Order> orders = orderService.list(new LambdaQueryWrapper<Order>().in(Order::getWaveId, waveIds));
//                        List<Long> orderIds = orders.stream().map(Order::getId).collect(Collectors.toList());
//                        cacheSiteService.update(new LambdaUpdateWrapper<CacheSite>()
//                                .in(CacheSite::getOrderId, orderIds)
//                                .set(CacheSite::getSiteStatus, 0)
//                                .set(CacheSite::getOrderId, null)
//                                .set(CacheSite::getOrderNo, null));
//                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
@@ -140,10 +181,8 @@
    //入库
    private void executeTask1(Task task) {
        Long hostId = task.getHostId();
        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getTargetLoc()).eq(Loc::getHostId, hostId));
        if (loc == null) {
            log.info("库位不存在" + "=======>" + task.getTargetLoc());
            throw new CoolException("库位不存在");
        }
@@ -177,9 +216,10 @@
            if (!locDetlService.save(locDetl)) {
                throw new CoolException("插入库存明细失败");
            }
            //fixme 暂时关闭HOSTID,后续打开机构ID
            //添加库存明细扩展字段
            List<TaskDetlField> detlFields = taskDetlFieldService.list(new LambdaQueryWrapper<TaskDetlField>().eq(TaskDetlField::getDetlId, taskDetl.getId()).eq(TaskDetlField::getHostId, hostId));
//            List<TaskDetlField> detlFields = taskDetlFieldService.list(new LambdaQueryWrapper<TaskDetlField>().eq(TaskDetlField::getDetlId, taskDetl.getId()).eq(TaskDetlField::getHostId, hostId));
            List<TaskDetlField> detlFields = taskDetlFieldService.list(new LambdaQueryWrapper<TaskDetlField>().eq(TaskDetlField::getDetlId, taskDetl.getId()));
            for (TaskDetlField detlField : detlFields) {
                LocDetlField locDetlField = new LocDetlField();
                locDetlField.setDetlId(locDetl.getId());
@@ -192,15 +232,17 @@
                }
            }
        }
        //fixme 暂时关闭HOSTID,后续打开机构ID
        //组托通知档转历史档
        List<WaitPakin> waitPakins = waitPakinService.list(new LambdaQueryWrapper<WaitPakin>().eq(WaitPakin::getBarcode, task.getBarcode()).eq(WaitPakin::getHostId, hostId));
//        List<WaitPakin> waitPakins = waitPakinService.list(new LambdaQueryWrapper<WaitPakin>().eq(WaitPakin::getBarcode, task.getBarcode()).eq(WaitPakin::getHostId, hostId));
        List<WaitPakin> waitPakins = waitPakinService.list(new LambdaQueryWrapper<WaitPakin>().eq(WaitPakin::getBarcode, task.getBarcode()));
        if (waitPakins.isEmpty()) {
            throw new CoolException("组托通知档不存在");
        }
        for (WaitPakin waitPakin : waitPakins) {
            WaitPakinLog waitPakinLog = new WaitPakinLog();
            waitPakinLog.sync(waitPakin);
            waitPakinLog.setId(null);
            if (!waitPakinLogService.save(waitPakinLog)) {
                throw new CoolException("组托通知档转历史档失败");
            }
@@ -292,11 +334,16 @@
    }
    /**
     * 拣料再入库,根据任务目标库位,生成新库存信息
     * @param task
     */
    //拣料再入库
    private void executeTask53(Task task) {
        Long hostId = task.getHostId();
        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getTargetLoc()).eq(Loc::getHostId, hostId));
        //fixme 将任务当前
//        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getTargetLoc()).eq(Loc::getHostId, hostId));
        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getTargetLoc()));
        if (loc == null) {
            throw new CoolException("库位不存在");
        }
@@ -338,7 +385,9 @@
            }
            //添加库存明细扩展字段
            List<TaskDetlField> detlFields = taskDetlFieldService.list(new LambdaQueryWrapper<TaskDetlField>().eq(TaskDetlField::getDetlId, taskDetl.getId()).eq(TaskDetlField::getHostId, hostId));
            //fixme 注释
//            List<TaskDetlField> detlFields = taskDetlFieldService.list(new LambdaQueryWrapper<TaskDetlField>().eq(TaskDetlField::getDetlId, taskDetl.getId()).eq(TaskDetlField::getHostId, hostId));
            List<TaskDetlField> detlFields = taskDetlFieldService.list(new LambdaQueryWrapper<TaskDetlField>().eq(TaskDetlField::getDetlId, taskDetl.getId()));
            for (TaskDetlField detlField : detlFields) {
                LocDetlField locDetlField = new LocDetlField();
                locDetlField.setDetlId(locDetl.getId());
@@ -356,7 +405,8 @@
    //出库
    private void executeTask101(Task task) {
        Long hostId = task.getHostId();
        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getOriginLoc()).eq(Loc::getHostId, hostId));
//        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getOriginLoc()).eq(Loc::getHostId, hostId));
        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getOriginLoc()));
        if (loc == null) {
            throw new CoolException("库位不存在");
        }
@@ -391,7 +441,9 @@
    //拣料出库
    private void executeTask103(Task task) {
        Long hostId = task.getHostId();
        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getOriginLoc()).eq(Loc::getHostId, hostId));
        //FIXME 暂时注释HOSTID筛选条件
//        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getOriginLoc()).eq(Loc::getHostId, hostId));
        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, task.getOriginLoc()));
        if (loc == null) {
            throw new CoolException("库位不存在");
        }
@@ -408,6 +460,7 @@
        if (!locService.updateById(loc)) {
            throw new CoolException("库位状态更新失败");
        }
        List<LocDetl> detlList = locDetlService.list(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getLocId, loc.getId()).eq(LocDetl::getHostId, hostId));
        //删除库存明细
        for (LocDetl locDetl : detlList) {