hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/job/OpcPlcStorageCageTask.java
@@ -3,10 +3,11 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import com.mes.bigstorage.entity.BigStorageCage;
import com.mes.bigstorage.entity.BigStorageCageDetails;
import com.mes.bigstorage.entity.BigStorageDTO;
import com.mes.bigstorage.service.BigStorageCageDetailsService;
import com.mes.bigstorage.service.BigStorageCageService;
import com.mes.bigstoragecageIntask.entity.BigStorageCageInTask;
import com.mes.bigstoragecageIntask.service.BigStorageCageInTaskService;
import com.mes.bigstoragetask.entity.BigStorageCageFeedTask;
@@ -17,20 +18,22 @@
import com.mes.common.config.Const;
import com.mes.damage.entity.Damage;
import com.mes.damage.service.DamageService;
import com.mes.glassinfo.entity.GlassInfo;
import com.mes.glassinfo.service.GlassInfoService;
import com.mes.temperingglass.entity.TemperingGlassInfo;
import com.mes.temperingglass.service.TemperingGlassInfoService;
import com.mes.tools.service.BigStorageBaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
@@ -51,28 +54,39 @@
    private DamageService damageService;
    @Resource
    private GlassInfoService glassInfoService;
    @Resource
    private BigStorageCageService bigStorageCageService;
    @Resource
    private BigStorageBaseService baseService;
    @Resource
    private BigStorageCageInTaskService bigStorageBaseInTaskService;
    @Autowired(required = false)
    MiloService miloService;
    @Value("${mes.glassGap}")
    private Integer glassGap;
    @Resource(name = "bigStorageStartCallback")
    SubscriptionCallback bigStorageStartCallback;
//    @Resource
//    private BigStorageCage bigStorageBaseInTaskService;
//    @Autowired(required = false)
//    MiloService miloService;
//
//    @Resource(name = "bigStorageStartCallback")
//    SubscriptionCallback bigStorageStartCallback;
    @Scheduled(fixedDelay = Long.MAX_VALUE)
    public void startOpcTask() throws Exception {
        //设备一二的进片请求
        miloService.subscriptionFromOpcUa(Arrays.asList("my.device01.x1", "my.device02.x1"), bigStorageStartCallback);
    }
//    @Scheduled(fixedDelay = Long.MAX_VALUE)
//    public void startOpcTask() throws Exception {
//        //设备一二的进片请求
//        miloService.subscriptionFromOpcUa(Arrays.asList("my.device01.x1", "my.device02.x1"), bigStorageStartCallback);
//    }
    @Scheduled(fixedDelay = Long.MAX_VALUE)
    public void outOpcTask() throws Exception {
        //设备1的出片请求
        miloService.subscriptionFromOpcUa(Arrays.asList("my.device03.x1"), bigStorageStartCallback);
    }
//    @Scheduled(fixedDelay = Long.MAX_VALUE)
//    public void outOpcTask() throws Exception {
//        //设备1的出片请求
//        miloService.subscriptionFromOpcUa(Arrays.asList("my.device03.x1"), bigStorageStartCallback);
//    }
    @Scheduled(fixedDelay = 200)
@@ -82,7 +96,25 @@
        if (CollectionUtils.isEmpty(inTaskList)) {
            log.info("当前大车无进片任务,结束本地定时任务");
        }
        inTaskList
        List<String> glassIdList = inTaskList.stream().map(BigStorageCageInTask::getGlassId).collect(Collectors.toList());
        Map<String, List<BigStorageCageInTask>> taskMap = inTaskList.stream().collect(Collectors.groupingBy(BigStorageCageInTask::getGlassId));
        List<GlassInfo> glassInfoList = glassInfoService.list(new LambdaQueryWrapper<GlassInfo>().in(GlassInfo::getGlassId, glassIdList));
        //todo:计算目标格子
        for (GlassInfo info : glassInfoList) {
            //获取目标格子信息
            BigStorageDTO bigStorageDTO = bigStorageCageDetailsService.queryTargetSlotByTempering(info);
//            临时更新格子的剩余尺寸:防止相邻玻璃进同一格子造成剩余尺寸不足,玻璃越界的情况,任务完成后再次更新大理片笼表剩余宽度(按照笼内玻璃数量更新大理片笼剩余尺寸)
            bigStorageCageService.update(new LambdaUpdateWrapper<BigStorageCage>()
                    .set(BigStorageCage::getRemainWidth, bigStorageDTO.getWidth() - Math.max(info.getWidth(), info.getHeight()) - glassGap)
                    .eq(BigStorageCage::getSlot, bigStorageDTO.getSlot()));
            BigStorageCageInTask task = taskMap.get(info.getGlassId()).get(0);
            task.setTargetSlot(bigStorageDTO.getSlot());
            task.setGlassId(info.getGlassId());
            task.setTaskRunning(Const.BIG_STORAGE_TASK_RUNNING);
            bigStorageBaseInTaskService.updateTaskMessage("", task);
            //todo:存放历史任务
        }
    }