package com.mes.opctask.service.impl; 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.mes.common.config.Const; import com.mes.common.config.ConstSysConfig; import com.mes.edgstoragecage.entity.EdgStorageCage; import com.mes.edgstoragecage.entity.EdgStorageCageDetails; import com.mes.edgstoragecage.entity.vo.EdgSlotRemainVO; import com.mes.edgstoragecage.service.EdgStorageCageDetailsService; import com.mes.edgstoragecage.service.EdgStorageCageService; import com.mes.opctask.entity.EdgStorageDeviceTask; import com.mes.opctask.entity.EdgStorageDeviceTaskHistory; import com.mes.opctask.mapper.EdgStorageDeviceTaskMapper; import com.mes.opctask.service.EdgStorageDeviceTaskHistoryService; import com.mes.opctask.service.EdgStorageDeviceTaskService; import com.mes.sysconfig.service.SysConfigService; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.List; /** * @Author : zhoush * @Date: 2024/10/24 15:36 * @Description: */ @Service public class EdgStorageDeviceTaskServiceImpl implements EdgStorageDeviceTaskService { private static final String EDG_STORAGE_DEVICE_ONE_TASK = "edg_storage_device_one_task"; private static final String EDG_STORAGE_DEVICE_TWO_TASK = "edg_storage_device_two_task"; @Resource private EdgStorageDeviceTaskHistoryService edgStorageDeviceTaskHistoryService; @Resource private EdgStorageCageDetailsService edgStorageCageDetailsService; @Resource private EdgStorageCageService edgStorageCageService; @Resource EdgStorageDeviceTaskMapper edgStorageDeviceTaskMapper; @Resource SysConfigService sysConfigService; // @Value("${mes.glassGap}") // private int glassGap; // @Value("${mes.cellLength}") // private int cellLength; @Override public EdgStorageDeviceTask queryTaskMessage(String tableName) { return edgStorageDeviceTaskMapper.queryTaskMessage(tableName); } @Override public boolean updateTaskMessage(String tableName, EdgStorageDeviceTask edgStorageDeviceTask) { return edgStorageDeviceTaskMapper.updateTaskMessage(tableName, edgStorageDeviceTask); } @Override public Boolean resetTask(Integer deviceId) { String tableName = deviceId == 1 ? EDG_STORAGE_DEVICE_ONE_TASK : EDG_STORAGE_DEVICE_TWO_TASK; EdgStorageDeviceTaskHistory taskHistory = edgStorageDeviceTaskHistoryService.getOne(new LambdaQueryWrapper() .eq(EdgStorageDeviceTaskHistory::getTaskState, Const.RAW_GLASS_TASK_NEW) .eq(EdgStorageDeviceTaskHistory::getDeviceId, deviceId) .orderByDesc(EdgStorageDeviceTaskHistory::getCreateTime).last("limit 1")); if (taskHistory != null) { Integer cell = taskHistory.getStartCell(); Integer taskType = taskHistory.getTaskType(); if (Const.GLASS_CACHE_TYPE_IN_ALL.contains(taskType)) { String glassId = taskHistory.getGlassIdIn(); edgStorageCageDetailsService.remove(new LambdaQueryWrapper() .eq(EdgStorageCageDetails::getDeviceId, deviceId) .eq(EdgStorageCageDetails::getSlot, cell) .eq(EdgStorageCageDetails::getGlassId, glassId)); } else { String glassId = taskHistory.getGlassIdOut(); edgStorageCageDetailsService.update(new LambdaUpdateWrapper() .set(EdgStorageCageDetails::getState, Const.GLASS_STATE_IN) .eq(EdgStorageCageDetails::getDeviceId, deviceId) .eq(EdgStorageCageDetails::getSlot, cell) .eq(EdgStorageCageDetails::getGlassId, glassId)); } edgStorageDeviceTaskHistoryService.update(new LambdaUpdateWrapper() .eq(EdgStorageDeviceTaskHistory::getTaskState, Const.RAW_GLASS_TASK_NEW) .eq(EdgStorageDeviceTaskHistory::getDeviceId, deviceId) .set(EdgStorageDeviceTaskHistory::getTaskState, Const.RAW_GLASS_TASK_FAILURE) ); //计算每个各自的剩余尺寸信息 resetSlotRemainWidth(); } //最后更新任务,保证任务前的动作都做完 EdgStorageDeviceTask task = new EdgStorageDeviceTask(); task.setTaskRunning(Const.GLASS_CACHE_TYPE_EMPTY); task.setGlassIdOut(""); task.setStartCell(0); task.setEndCell(0); this.updateTaskMessage(tableName, task); return Boolean.TRUE; } @Override public Boolean taskSuccess(Integer deviceId) { String tableName = deviceId == 1 ? EDG_STORAGE_DEVICE_ONE_TASK : EDG_STORAGE_DEVICE_TWO_TASK; edgStorageDeviceTaskHistoryService.update(new LambdaUpdateWrapper() .set(EdgStorageDeviceTaskHistory::getTaskState, Const.RAW_GLASS_TASK_SUCCESS) .eq(EdgStorageDeviceTaskHistory::getTaskState, Const.RAW_GLASS_TASK_NEW) .eq(EdgStorageDeviceTaskHistory::getDeviceId, deviceId)); //计算每个各自的剩余尺寸信息 resetSlotRemainWidth(); //最后更新任务,保证任务前的动作都做完 EdgStorageDeviceTask task = new EdgStorageDeviceTask(); task.setTaskRunning(Const.GLASS_CACHE_TYPE_EMPTY); task.setGlassIdOut(""); task.setStartCell(0); task.setEndCell(0); this.updateTaskMessage(tableName, task); return Boolean.TRUE; } private boolean resetSlotRemainWidth() { int cellLength = sysConfigService.queryConfigValue(ConstSysConfig.CACHE_CELL_LENGTH); int glassGap = sysConfigService.queryConfigValue(ConstSysConfig.CACHE_GLASS_GAP); //将尺寸重置为原始尺寸 edgStorageCageService.update(new LambdaUpdateWrapper().set(EdgStorageCage::getRemainWidth, cellLength)); //获取笼内的详情数据 List edgSlotRemainVOS = edgStorageCageDetailsService.querySlotRemainWidth(cellLength, glassGap); //按照查询结果对笼内现有玻璃的格子尺寸进行更新 if (CollectionUtils.isNotEmpty(edgSlotRemainVOS)) { edgStorageCageService.resetSlotRemainWidth(edgSlotRemainVOS); } return Boolean.TRUE; } }