ZengTao
2025-05-20 ae07cd92f46b88bf034c7d9d0b96b3a5e83fdc98
hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/job/OpcCacheGlassNewTask.java
@@ -5,6 +5,7 @@
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.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.service.MiloService;
import com.mes.common.config.Const;
@@ -22,11 +23,15 @@
import com.mes.opctask.entity.EdgStorageDeviceTaskHistory;
import com.mes.opctask.service.EdgStorageDeviceTaskHistoryService;
import com.mes.opctask.service.EdgStorageDeviceTaskService;
import com.mes.s7.entity.S7DataMBOne;
import com.mes.s7.entity.S7DataWLOne;
import com.mes.s7.entity.S7DataWLTwo;
import com.mes.sysconfig.service.SysConfigService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@@ -68,6 +73,18 @@
    @Resource
    SysConfigService sysConfigService;
    @Autowired
    @Qualifier("s7SerializerWLOne")
    private S7Serializer s7SerializerWLOne;
    @Autowired
    @Qualifier("s7SerializerWLTwo")
    private S7Serializer s7SerializerWLTwo;
    @Autowired
    @Qualifier("s7SerializerMBOne")
    private S7Serializer s7SerializerMBOne;
    //    @Value("${mes.threshold}")
    private int threshold;
    //    @Value("${mes.cellLength}")
@@ -103,12 +120,15 @@
    @Scheduled(fixedDelay = 1000)
    public void startOneOpcTask() throws Exception {
        S7DataWLTwo s7DataWLTwo = s7SerializerWLTwo.read(S7DataWLTwo.class);
        //获取第二条线路的卧式理片笼状态
        ReadWriteEntity twoInkageEntity = miloService.readFromOpcUa("WL2.WL2.deviceState");
//        ReadWriteEntity twoInkageEntity = miloService.readFromOpcUa("WL2.WL2.deviceState");
        Boolean twoInkageEntity = s7DataWLTwo.getDeviceState();
        //默认只跑一台卧式理片,两条线路都可以走
        int cellFlag = 1;
        //如果两条线都启动则只能跑一条线
        if (twoInkageEntity != null && !Boolean.parseBoolean(twoInkageEntity.getValue() + "")) {
//        if (twoInkageEntity != null && !Boolean.parseBoolean(twoInkageEntity.getValue() + "")) {
        if (twoInkageEntity != null && !twoInkageEntity) {
            cellFlag = 2;
        }
        startOneOpcTaskChild(EDG_STORAGE_DEVICE_ONE_TASK, 1, cellFlag);
@@ -116,9 +136,12 @@
    @Scheduled(fixedDelay = 1000)
    public void startTwoOpcTask() throws Exception {
        ReadWriteEntity oneInkageEntity = miloService.readFromOpcUa("WL1.WL1.deviceState");
        S7DataWLOne s7DataWLOne = s7SerializerWLOne.read(S7DataWLOne.class);
//        ReadWriteEntity oneInkageEntity = miloService.readFromOpcUa("WL1.WL1.deviceState");
        Boolean oneInkageEntity = s7DataWLOne.getDeviceState();
        int cellFlag = 1;
        if (oneInkageEntity != null && !Boolean.parseBoolean(oneInkageEntity.getValue() + "")) {
//        if (oneInkageEntity != null && !Boolean.parseBoolean(oneInkageEntity.getValue() + "")) {
        if (oneInkageEntity != null && !oneInkageEntity) {
            cellFlag = 2;
        }
        startOneOpcTaskChild(EDG_STORAGE_DEVICE_TWO_TASK, 2, cellFlag);
@@ -219,15 +242,25 @@
            return;
        }
        String toEndingId = glassInfo.getTemperingLayoutId() + "" + glassInfo.getTemperingFeedSequence();
        List<ReadWriteEntity> list = new ArrayList<>();
//        list.add(generateReadWriteEntity("MB" + cell + ".MB" + cell + ".mesControl", true));
        list.add(generateReadWriteEntity("MB" + cell + ".MB" + cell + ".glassId", Integer.parseInt(toEndingId)));
        list.add(generateReadWriteEntity("MB" + cell + ".MB" + cell + ".toEdingId", Integer.parseInt(toEndingId)));
        list.add(generateReadWriteEntity("MB" + cell + ".MB" + cell + ".width", (int) Math.max(glassInfo.getWidth() * ratio, glassInfo.getHeight() * ratio)));
        list.add(generateReadWriteEntity("MB" + cell + ".MB" + cell + ".height", (int) Math.min(glassInfo.getWidth() * ratio, glassInfo.getHeight() * ratio)));
//        List<ReadWriteEntity> list = new ArrayList<>();
////        list.add(generateReadWriteEntity("MB" + cell + ".MB" + cell + ".mesControl", true));
//        list.add(generateReadWriteEntity("MB" + cell + ".MB" + cell + ".glassId", Integer.parseInt(toEndingId)));
//        list.add(generateReadWriteEntity("MB" + cell + ".MB" + cell + ".toEdingId", Integer.parseInt(toEndingId)));
//        list.add(generateReadWriteEntity("MB" + cell + ".MB" + cell + ".width", (int) Math.max(glassInfo.getWidth() * ratio, glassInfo.getHeight() * ratio)));
//        list.add(generateReadWriteEntity("MB" + cell + ".MB" + cell + ".height", (int) Math.min(glassInfo.getWidth() * ratio, glassInfo.getHeight() * ratio)));
//
//        miloService.writeToOpcUa(list);
//        miloService.writeToOpcWord(generateReadWriteEntity("MB" + cell + ".MB" + cell + ".thickness", (int) glassInfo.getThickness() * ratio));
        S7DataMBOne s7DataMBOne =new S7DataMBOne();
        s7DataMBOne.setToEdingId(Integer.parseInt(toEndingId));
        s7DataMBOne.setGlassId(Integer.parseInt(toEndingId));
        s7DataMBOne.setWidth((int) Math.max(glassInfo.getWidth() * ratio, glassInfo.getHeight() * ratio));
        s7DataMBOne.setHeight((int) Math.min(glassInfo.getWidth() * ratio, glassInfo.getHeight() * ratio));
        s7SerializerMBOne.write(s7DataMBOne);
        miloService.writeToOpcUa(list);
        miloService.writeToOpcWord(generateReadWriteEntity("MB" + cell + ".MB" + cell + ".thickness", (int) glassInfo.getThickness() * ratio));
        s7DataMBOne =new S7DataMBOne();
        s7DataMBOne.setThickness((short) (glassInfo.getThickness() * ratio));
        s7SerializerMBOne.write(s7DataMBOne);
        //修改磨边对列中的磨边线路及状态
        edgGlassTaskInfoService.update(new LambdaUpdateWrapper<EdgGlassTaskInfo>()
                .set(EdgGlassTaskInfo::getLine, cell)
@@ -300,26 +333,40 @@
    private boolean outTask(EdgStorageDeviceTask task, String tableName, int deviceId, int cellFlag) throws Exception {
        Date startDate = new Date();
        //获取对应的设备状态信息
        ReadWriteEntity oneOutStateEntity = miloService.readFromOpcUa("WL1.WL1.slotState");
        ReadWriteEntity twoOutStateEntity = miloService.readFromOpcUa("WL2.WL2.slotState");
        ReadWriteEntity d06OutStateEntity = miloService.readFromOpcUa("WL2.WL2.d06SlotState");
//        ReadWriteEntity oneOutStateEntity = miloService.readFromOpcUa("WL1.WL1.slotState");
//        ReadWriteEntity twoOutStateEntity = miloService.readFromOpcUa("WL2.WL2.slotState");
//        ReadWriteEntity d06OutStateEntity = miloService.readFromOpcUa("WL2.WL2.d06SlotState");
        S7DataWLOne s7DataWLOne = s7SerializerWLOne.read(S7DataWLOne.class);
        S7DataWLTwo s7DataWLTwo = s7SerializerWLTwo.read(S7DataWLTwo.class);
        Short oneOutStateEntity = s7DataWLOne.getSlotState();
        Short twoOutStateEntity = s7DataWLTwo.getSlotState();
        Short d06OutStateEntity = s7DataWLTwo.getD06SlotState();
        //状态有3中情况:0空闲 1忙碌 2禁用
        String oneOutState = Const.OUT_DISABLE;
        String twoOutState = Const.OUT_DISABLE;
        String d06OutState = Const.OUT_DISABLE;
        if (null != oneOutStateEntity && null != oneOutStateEntity.getValue()) {
            oneOutState = oneOutStateEntity.getValue().toString();
//        if (null != oneOutStateEntity && null != oneOutStateEntity.getValue()) {
//            oneOutState = oneOutStateEntity.getValue().toString();
//        }
        if (null != oneOutStateEntity ) {
            oneOutState = oneOutStateEntity.toString();
        }
        if (null != twoOutStateEntity && null != twoOutStateEntity.getValue()) {
            twoOutState = twoOutStateEntity.getValue().toString();
//        if (null != twoOutStateEntity && null != twoOutStateEntity.getValue()) {
//            twoOutState = twoOutStateEntity.getValue().toString();
//        }
        if (null != twoOutStateEntity ) {
            twoOutState = twoOutStateEntity.toString();
        }
        //两条线都为禁用则不出玻璃
        if (Const.OUT_DISABLE.equals(oneOutState) && Const.OUT_DISABLE.equals(twoOutState)) {
            log.info("A09、A10为{},{}非自动状态,无法出片", oneOutState, oneOutState);
            return Boolean.FALSE;
        }
        if (null != d06OutStateEntity && null != d06OutStateEntity.getValue()) {
            d06OutState = d06OutStateEntity.getValue().toString();
//        if (null != d06OutStateEntity && null != d06OutStateEntity.getValue()) {
//            d06OutState = d06OutStateEntity.getValue().toString();
//        }
        if (null != d06OutStateEntity ) {
            d06OutState = d06OutStateEntity.toString();
        }
        //获取d06片台状态
        // 1:一对一的情况下不需要判断d06状态