ZengTao
2025-05-20 dbbf0c051ef05480a0becee07974b80e32b1cb8f
hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/job/OpcCacheGlassNewTask.java
@@ -8,6 +8,7 @@
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.service.MiloService;
import com.mes.common.config.Const;
import com.mes.common.config.ConstSysConfig;
import com.mes.damage.service.DamageService;
import com.mes.edgglasstask.entity.EdgGlassTaskInfo;
import com.mes.edgglasstask.service.EdgGlassTaskInfoService;
@@ -21,11 +22,11 @@
import com.mes.opctask.entity.EdgStorageDeviceTaskHistory;
import com.mes.opctask.service.EdgStorageDeviceTaskHistoryService;
import com.mes.opctask.service.EdgStorageDeviceTaskService;
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.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@@ -64,35 +65,35 @@
    EdgStorageDeviceTaskHistoryService edgStorageDeviceTaskHistoryService;
    @Resource
    DamageService damageService;
    @Resource
    SysConfigService sysConfigService;
    @Value("${mes.glassGap}")
    private int glassGap;
    @Value("${mes.threshold}")
    //    @Value("${mes.threshold}")
    private int threshold;
    @Value("${mes.cellLength}")
    //    @Value("${mes.cellLength}")
    private int cellLength;
    @Value("${mes.ratio}")
    //    @Value("${mes.ratio}")
    private int ratio;
    @Value("${mes.min.one.firstLength}")
    //    @Value("${mes.min.one.firstLength}")
    private int minOneFirstLength;
    @Value("${mes.min.one.secondLength}")
    //
//    @Value("${mes.min.one.secondLength}")
    private int minOneSecondLength;
    @Value("${mes.min.two.firstLength}")
    //
//    @Value("${mes.min.two.firstLength}")
    private int minTwoFirstLength;
    @Value("${mes.min.two.secondLength}")
    //
//    @Value("${mes.min.two.secondLength}")
    private int minTwoSecondLength;
    @Value("${mes.max.firstLength}")
    //
//    @Value("${mes.max.firstLength}")
    private int maxTwoFirstLength;
    @Value("${mes.max.secondLength}")
    //
//    @Value("${mes.max.secondLength}")
    private int maxTwoSecondLength;
    @Value("${mes.maxThickness}")
    //
//    @Value("${mes.maxThickness}")
    private int maxThickness;
    private String glassInIdOne = "";
@@ -105,10 +106,10 @@
        //获取第二条线路的卧式理片笼状态
        ReadWriteEntity twoInkageEntity = miloService.readFromOpcUa("WL2.WL2.deviceState");
        //默认只跑一台卧式理片,两条线路都可以走
        int cellFlag = 2;
        int cellFlag = 1;
        //如果两条线都启动则只能跑一条线
        if (twoInkageEntity != null && Boolean.parseBoolean(twoInkageEntity.getValue() + "")) {
            cellFlag = 1;
        if (twoInkageEntity != null && !Boolean.parseBoolean(twoInkageEntity.getValue() + "")) {
            cellFlag = 2;
        }
        startOneOpcTaskChild(EDG_STORAGE_DEVICE_ONE_TASK, 1, cellFlag);
    }
@@ -116,14 +117,25 @@
    @Scheduled(fixedDelay = 1000)
    public void startTwoOpcTask() throws Exception {
        ReadWriteEntity oneInkageEntity = miloService.readFromOpcUa("WL1.WL1.deviceState");
        int cellFlag = 2;
        if (oneInkageEntity != null && Boolean.parseBoolean(oneInkageEntity.getValue() + "")) {
            cellFlag = 1;
        int cellFlag = 1;
        if (oneInkageEntity != null && !Boolean.parseBoolean(oneInkageEntity.getValue() + "")) {
            cellFlag = 2;
        }
        startOneOpcTaskChild(EDG_STORAGE_DEVICE_TWO_TASK, 2, cellFlag);
    }
    private void startOneOpcTaskChild(String tableName, int device, int cellFlag) throws Exception {
        threshold = sysConfigService.queryConfigValue(ConstSysConfig.CACHE_THRESHOLD);
        cellLength = sysConfigService.queryConfigValue(ConstSysConfig.CACHE_CELL_LENGTH);
        ratio = sysConfigService.queryConfigValue(ConstSysConfig.CACHE_RATIO);
        minOneFirstLength = sysConfigService.queryConfigValue(ConstSysConfig.CACHE_MIN_ONE_FIRST_LENGTH);
        minOneSecondLength = sysConfigService.queryConfigValue(ConstSysConfig.CACHE_MIN_ONE_SECOND_LENGTH);
        minTwoFirstLength = sysConfigService.queryConfigValue(ConstSysConfig.CACHE_MIN_TWO_FIRST_LENGTH);
        minTwoSecondLength = sysConfigService.queryConfigValue(ConstSysConfig.CACHE_MIN_TWO_SECOND_LENGTH);
        maxTwoFirstLength = sysConfigService.queryConfigValue(ConstSysConfig.CACHE_MAX_FIRST_LENGTH);
        maxTwoSecondLength = sysConfigService.queryConfigValue(ConstSysConfig.CACHE_MAX_SECOND_LENGTH);
        maxThickness = sysConfigService.queryConfigValue(ConstSysConfig.CACHE_MAX_THICKNESS);
        EdgStorageDeviceTask task = edgStorageDeviceTaskService.queryTaskMessage(tableName);
        if (task == null) {
            log.info("任务表基础数据录入失败,请检查数据是否录入成功");
@@ -200,6 +212,7 @@
    }
    private void edgTaskChild(String glassId, int cell) throws Exception {
        ratio = sysConfigService.queryConfigValue(ConstSysConfig.CACHE_RATIO);
        GlassInfo glassInfo = glassInfoService.getOne(new LambdaQueryWrapper<GlassInfo>().eq(GlassInfo::getGlassId, glassId).last("limit 1"));
        if (glassInfo == null) {
            log.info("对列表中的玻璃id错误,请检查数据,玻璃id:{}", glassId);
@@ -210,11 +223,11 @@
//        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() * 10, glassInfo.getHeight() * 10)));
        list.add(generateReadWriteEntity("MB" + cell + ".MB" + cell + ".height", (int) Math.min(glassInfo.getWidth() * 10, glassInfo.getHeight() * 10)));
        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() * 10));
        miloService.writeToOpcWord(generateReadWriteEntity("MB" + cell + ".MB" + cell + ".thickness", (int) glassInfo.getThickness() * ratio));
        //修改磨边对列中的磨边线路及状态
        edgGlassTaskInfoService.update(new LambdaUpdateWrapper<EdgGlassTaskInfo>()
                .set(EdgGlassTaskInfo::getLine, cell)
@@ -299,7 +312,7 @@
            twoOutState = twoOutStateEntity.getValue().toString();
        }
        if ((Const.OUT_BUSY.equals(oneOutState) && Const.OUT_BUSY.equals(twoOutState)) || (Const.OUT_DISABLE.equals(oneOutState) && Const.OUT_DISABLE.equals(twoOutState))) {
        if ((cellFlag == 2 && Const.OUT_BUSY.equals(oneOutState) && Const.OUT_BUSY.equals(twoOutState)) || (Const.OUT_DISABLE.equals(oneOutState) && Const.OUT_DISABLE.equals(twoOutState))) {
            log.info("A09、A10为{},{}非自动状态,无法出片", oneOutState, oneOutState);
            return Boolean.FALSE;
        }
@@ -310,17 +323,21 @@
        if (cellFlag == 1) {
            cell = deviceId;
        } else {
            if (Const.OUT_FREE.equals(oneOutState)) {
                cell = Const.ONE_OUT_TARGET_POSITION;
            } else if (Const.OUT_FREE.equals(twoOutState)) {
            if (Const.OUT_FREE.equals(twoOutState)) {
                cell = Const.TWO_OUT_TARGET_POSITION;
            } else if (Const.OUT_FREE.equals(oneOutState)) {
                cell = Const.ONE_OUT_TARGET_POSITION;
            } else {
                return Boolean.FALSE;
            }
        }
        if (Const.OUT_FREE.equals(oneOutState) && Const.OUT_FREE.equals(twoOutState)) {
            if (!outChildTask(task, tableName, deviceId, cell, startDate)) {
                cell = cell == Const.ONE_OUT_TARGET_POSITION ? Const.TWO_OUT_TARGET_POSITION : Const.ONE_OUT_TARGET_POSITION;
            if (cellFlag == 2) {
                if (!outChildTask(task, tableName, deviceId, cell, startDate)) {
                    cell = cell == Const.ONE_OUT_TARGET_POSITION ? Const.TWO_OUT_TARGET_POSITION : Const.ONE_OUT_TARGET_POSITION;
                    return outChildTask(task, tableName, deviceId, cell, startDate);
                }
            } else {
                return outChildTask(task, tableName, deviceId, cell, startDate);
            }
        } else {
@@ -711,27 +728,6 @@
        taskHistory.setTaskState(Const.RAW_GLASS_TASK_NEW);
        taskHistory.setDeviceId(deviceId);
        edgStorageDeviceTaskHistoryService.save(taskHistory);
        return Boolean.TRUE;
    }
    public boolean updateCellRemainWidth(int slot, int device, EdgStorageDeviceTaskHistory taskHistory) {
        List<EdgStorageCageDetails> list = edgStorageCageDetailsService.list(new LambdaQueryWrapper<EdgStorageCageDetails>().eq(EdgStorageCageDetails::getSlot, slot)
                .eq(EdgStorageCageDetails::getState, Const.GLASS_STATE_IN));
        int remainWidth = cellLength;
        if (CollectionUtil.isNotEmpty(list)) {
            if (2 == taskHistory.getTaskType()) {
                remainWidth = 0;
            } else {
                for (EdgStorageCageDetails item : list) {
                    remainWidth = remainWidth - glassGap - (int) Math.max(item.getWidth(), item.getHeight());
                }
                if (remainWidth <= 0) {
                    remainWidth = 0;
                }
            }
        }
        edgStorageCageService.update(new LambdaUpdateWrapper<EdgStorageCage>().
                set(EdgStorageCage::getRemainWidth, remainWidth).eq(EdgStorageCage::getSlot, slot).eq(EdgStorageCage::getDeviceId, device));
        return Boolean.TRUE;
    }