zhoushihao
2025-10-19 f9978d9309b3a75f078b32746bcb96d4afd55bcc
hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/job/OpcPlcStorageCageNewTask.java
@@ -3,11 +3,14 @@
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.github.xingshuangs.iot.protocol.s7.serializer.S7Serializer;
import com.github.yulichang.toolkit.JoinWrappers;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.service.MiloService;
import com.mes.alarm.entity.ProductAlarmInfo;
import com.mes.alarm.service.ProductAlarmInfoService;
import com.mes.base.entity.BigStorageCageBaseInfo;
import com.mes.bigstorage.entity.BigStorageCage;
import com.mes.bigstorage.entity.BigStorageCageDetails;
@@ -96,11 +99,28 @@
     */
    private static final Integer THROUGH_SLOT = 920;
    @Resource
    private ProductAlarmInfoService productAlarmInfoService;
    private static final String ALARM_MODULE = "钢化";
    private static final String ALARM_TYPE = "钢化大理片";
    private static final String ALARM_CODE_SIZE = "sizeSame";
    private static final String ALARM_CODE_ID = "idSame";
    @Resource
    private RedisUtil redisUtil;
    @Scheduled(fixedDelay = 1000)
    public void inBigStorageTask() throws Exception {
    public void inBigStorageTask() {
        List<ProductAlarmInfo> alarmInfos = productAlarmInfoService.list(new LambdaQueryWrapper<ProductAlarmInfo>()
                .eq(ProductAlarmInfo::getState, Const.LOAD_RAW_GLASS_NEW)
                .eq(ProductAlarmInfo::getAlarmModule, ALARM_MODULE)
                .eq(ProductAlarmInfo::getAlarmType, ALARM_TYPE));
        if (CollectionUtil.isNotEmpty(alarmInfos)) {
            log.info("界面报警,等待人工干预处理");
            return;
        }
        S7DataDLPOne s7DataDLPOne = s7SerializerDLPOne.read(S7DataDLPOne.class);
        log.info("进片任务开始{}", s7DataDLPOne);
        Boolean inkageEntity = s7DataDLPOne.getMesControl();
@@ -154,6 +174,13 @@
            if (entry.getValue() > 1) {
                log.info("进片玻璃{}存在相同,结束本次任务", entry.getKey());
                //向plc发送报警:同一车进片玻璃存在相同
                ProductAlarmInfo alarmInfo = new ProductAlarmInfo();
                alarmInfo.setState(Const.LOAD_RAW_GLASS_NEW);
                alarmInfo.setAlarmModule(ALARM_MODULE);
                alarmInfo.setAlarmType(ALARM_TYPE);
                alarmInfo.setAlarmCode(ALARM_CODE_ID);
                alarmInfo.setAlarmMessage(entry.getKey());
                productAlarmInfoService.save(alarmInfo);
                s7DataDLPOne = new S7DataDLPOne();
                s7DataDLPOne.setAlarmSignal(2);
                s7SerializerDLPOne.write(s7DataDLPOne);
@@ -165,6 +192,17 @@
        if (CollectionUtil.isNotEmpty(detailsList)) {
            log.info("理片笼存在相同的进片玻璃{},结束本次任务", detailsList);
            //向plc发送报警:理片笼存在相同的进片玻璃
            List<String> sameGlassIds = detailsList.stream()
                    .map(BigStorageCageDetails::getGlassId)
                    .collect(Collectors.toList());
            ProductAlarmInfo alarmInfo = new ProductAlarmInfo();
            alarmInfo.setState(Const.LOAD_RAW_GLASS_NEW);
            alarmInfo.setAlarmModule(ALARM_MODULE);
            alarmInfo.setAlarmType(ALARM_TYPE);
            alarmInfo.setAlarmCode(ALARM_CODE_ID);
            alarmInfo.setAlarmMessage(sameGlassIds.toString());
            productAlarmInfoService.save(alarmInfo);
            s7DataDLPOne = new S7DataDLPOne();
            s7DataDLPOne.setAlarmSignal(4);
            s7SerializerDLPOne.write(s7DataDLPOne);
@@ -339,49 +377,58 @@
            log.info("有正在执行的出片任务,结束本次出片任务");
            return;
        }
        //是否允许钢化
        //是否有正在钢化的玻璃:钢化小片表关联历史任务表,筛选未出笼的玻璃信息
//            获取当前钢化任务未完成出片的玻璃信息
        Integer temperingOutTargetPosition = sysConfigService.queryConfigValue(ConstSysConfig.VERTICAL_TEMPERING_OUT_TARGET_POSITION);
        List<TemperingGlassInfo> unFinishTemperingGlassInfoList = temperingGlassInfoService.list(new LambdaQueryWrapper<TemperingGlassInfo>()
                .eq(TemperingGlassInfo::getState, Const.TEMPERING_NEW).orderByAsc(TemperingGlassInfo::getTemperingLayoutId).orderByAsc(TemperingGlassInfo::getTemperingFeedSequence));
        if (CollectionUtil.isNotEmpty(unFinishTemperingGlassInfoList)) {
            log.info("有正在出片的钢化任务");
            computeOutGlassInfoByVirtualSlot(unFinishTemperingGlassInfoList, "big_storage_cage_out_one_task", temperingOutTargetPosition, Const.GLASS_STATE_OUT_ING, Const.BIG_STORAGE_BEFORE_OUT);
            Date endDate = new Date();
            log.info("大理片笼出片任务结束时间:{},共耗时:{}ms,结束扫码任务", endDate, endDate.getTime() - startDate.getTime());
            return;
        }
        BigStorageCageDetails details = bigStorageCageDetailsService.getOne(new LambdaQueryWrapper<BigStorageCageDetails>()
                .eq(BigStorageCageDetails::getSlot, THROUGH_SLOT)
                .in(BigStorageCageDetails::getState, Const.GLASS_STATE_IN_ALL).last("limit 1"));
        if (details != null) {
            TemperingGlassInfo temperingGlassInfo = new TemperingGlassInfo();
            BeanUtils.copyProperties(details, temperingGlassInfo);
            temperingGlassInfo.setState(-1);
            temperingGlassInfoService.save(temperingGlassInfo);
            computeOutGlassInfoByVirtualSlot(Arrays.asList(temperingGlassInfo), "big_storage_cage_out_one_task", temperingOutTargetPosition, Const.GLASS_STATE_OUT_ING, Const.BIG_STORAGE_BEFORE_OUT);
            return;
        }
        if (redisUtil.getCacheObject("temperingSwitch")) {
            //钢化优先:获取理片笼  玻璃小片  破损表 数量   判断笼内版图是否到齐
            List<TemperingLayoutDTO> temperingLayoutDTOList = bigStorageCageDetailsService.temperingIsAll();
            if (CollectionUtil.isNotEmpty(temperingLayoutDTOList)) {
                //玻璃到齐包括已出片的
                //到齐,将玻璃小片数据存入钢化小片表,逻辑生成出片任务  结束
                for (TemperingLayoutDTO item : temperingLayoutDTOList) {
//                    if (item.getEngineerId().equals(redisUtil.getCacheObject("temperingengineerId"))) {
            //是否允许钢化
            //是否有正在钢化的玻璃:钢化小片表关联历史任务表,筛选未出笼的玻璃信息
//            获取当前钢化任务未完成出片的玻璃信息
            List<TemperingGlassInfo> unFinishTemperingGlassInfoList = temperingGlassInfoService.list(new LambdaQueryWrapper<TemperingGlassInfo>()
                    .eq(TemperingGlassInfo::getState, Const.TEMPERING_NEW).orderByAsc(TemperingGlassInfo::getTemperingLayoutId).orderByAsc(TemperingGlassInfo::getTemperingFeedSequence));
            if (CollectionUtil.isNotEmpty(unFinishTemperingGlassInfoList)) {
                log.info("有正在出片的钢化任务");
                computeOutGlassInfoByVirtualSlot(unFinishTemperingGlassInfoList, "big_storage_cage_out_one_task", temperingOutTargetPosition, Const.GLASS_STATE_OUT_ING, Const.BIG_STORAGE_BEFORE_OUT);
                Date endDate = new Date();
                log.info("大理片笼出片任务结束时间:{},共耗时:{}ms,结束扫码任务", endDate, endDate.getTime() - startDate.getTime());
                return;
            }
            BigStorageCageDetails details = bigStorageCageDetailsService.getOne(new LambdaQueryWrapper<BigStorageCageDetails>()
                    .eq(BigStorageCageDetails::getSlot, THROUGH_SLOT)
                    .in(BigStorageCageDetails::getState, Const.GLASS_STATE_IN_ALL).last("limit 1"));
            if (details != null) {
                TemperingGlassInfo temperingGlassInfo = new TemperingGlassInfo();
                BeanUtils.copyProperties(details, temperingGlassInfo);
                temperingGlassInfo.setState(-1);
                temperingGlassInfoService.save(temperingGlassInfo);
                computeOutGlassInfoByVirtualSlot(Arrays.asList(temperingGlassInfo), "big_storage_cage_out_one_task", temperingOutTargetPosition, Const.GLASS_STATE_OUT_ING, Const.BIG_STORAGE_BEFORE_OUT);
                return;
            }
            String temperingEngineerId = redisUtil.getCacheObject("temperingEngineerId");
            if (StringUtils.isNotBlank(temperingEngineerId)) {
                TemperingGlassInfo temperingGlassInfo = temperingGlassInfoService.getOne(new QueryWrapper<TemperingGlassInfo>()
                        .select("Top 1 *")
                        .eq("engineer_id", temperingEngineerId)
                        .orderByDesc("tempering_layout_id"));
                int temperingLayoutId = 1;
                if (temperingGlassInfo != null) {
                    temperingLayoutId = temperingGlassInfo.getTemperingLayoutId() + 1;
                }
                List<GlassInfo> glassInfos = glassInfoService.list(new LambdaQueryWrapper<GlassInfo>().eq(GlassInfo::getEngineerId, temperingEngineerId).eq(GlassInfo::getTemperingLayoutId, temperingLayoutId));
                if (CollectionUtil.isEmpty(glassInfos)) {
                    //指定钢化工程执行完成,移除工程号
                    redisUtil.deleteObject("temperingEngineerId");
                    return;
                }
                List<TemperingLayoutDTO> temperingLayoutDTOS = bigStorageCageDetailsService.temperingIsAllByTemperingLayoutId(temperingEngineerId, temperingLayoutId);
                if (CollectionUtil.isNotEmpty(temperingLayoutDTOS)) {
                    List<TemperingGlassInfo> temperingGlassInfos = glassInfoService.selectJoinList(TemperingGlassInfo.class, JoinWrappers.lambda(GlassInfo.class)
                            .select("-1 as state,t.filmsid as films_id,t.glass_id,t.flow_card_id,t.glass_type,t.width,t.height" +
                                    ",t.thickness,t.ishorizontal,t.tempering_layout_id,t.tempering_feed_sequence,t.x_coordinate,t.y_coordinate," +
                                    "t.angle,t1.slot,t.engineer_id")
                            .innerJoin(BigStorageCageDetails.class, BigStorageCageDetails::getGlassId, GlassInfo::getGlassId)
                            .eq(BigStorageCageDetails::getState, Const.GLASS_STATE_IN)
                            .eq(GlassInfo::getTemperingLayoutId, item.getTemperingLayoutId())
                            .eq(GlassInfo::getEngineerId, item.getEngineerId())
                            .eq(GlassInfo::getTemperingLayoutId, temperingLayoutId)
                            .eq(GlassInfo::getEngineerId, temperingEngineerId)
                            .orderByAsc(GlassInfo::getTemperingFeedSequence));
                    if (CollectionUtil.isNotEmpty(temperingGlassInfos)) {
                        temperingGlassInfoService.saveBatch(temperingGlassInfos);
@@ -390,10 +437,11 @@
                        log.info("大理片笼出片任务结束时间:{},共耗时:{}ms,结束扫码任务", endDate, endDate.getTime() - startDate.getTime());
                        return;
                    }
//                    }
                }
            }
        }
        //是否有人工下片任务   有直接出
        Integer artificialOutTargetPosition = sysConfigService.queryConfigValue(ConstSysConfig.VERTICAL_ARTIFICIAL_OUT_TARGET_POSITION);
        Integer outCarMaxSize = sysConfigService.queryConfigValue(ConstSysConfig.VERTICAL_OUT_CAR_SIZE);
@@ -409,6 +457,18 @@
        }
        //是否存在需要内部调度的格子:执行内部调度任务
        if (redisUtil.getCacheObject("dispatchSwitch")) {
            //获取进片协议内容,在进片有请求/进片任务执行中不执行调度任务
            S7DataDLPOne s7DataDLPOne = s7SerializerDLPOne.read(S7DataDLPOne.class);
            String requestInEntity = s7DataDLPOne.getRequestMes().toString();
            if ("1".equals(requestInEntity)) {
                log.info("当前收到进片请求,结束调度任务");
                return;
            }
            String mesReplyInEntity = s7DataDLPOne.getMesReply().toString();
            if ("1".equals(mesReplyInEntity)) {
                log.info("有正在执行的进片任务,结束调度任务");
                return;
            }
            //todo:获取笼内单格已经到齐的玻璃格子信息
            List<BigStorageRelationDTO> virtualList = bigStorageCageDetailsService.queryIsAllNeedDispatchVirtualSlot();
            if (CollectionUtil.isEmpty(virtualList)) {