package com.mes.job.opccallback;
|
|
import cn.hutool.core.collection.CollectionUtil;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
|
import com.mes.common.config.Const;
|
import com.mes.edgstoragecage.entity.EdgStorageCage;
|
import com.mes.edgstoragecage.entity.EdgStorageCageDetails;
|
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.service.EdgStorageDeviceTaskHistoryService;
|
import com.mes.opctask.service.EdgStorageDeviceTaskService;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.util.List;
|
|
/**
|
* @Author : zhoush
|
* @Date: 2024/10/10 14:13
|
* @Description:
|
*/
|
@Service
|
@Slf4j
|
public class CacheGlassFinishCallback implements SubscriptionCallback {
|
|
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";
|
|
@Value("${mes.glassGap}")
|
private int glassGap;
|
@Value("${mes.cellLength}")
|
private int cellLength;
|
|
@Resource
|
EdgStorageDeviceTaskService edgStorageDeviceTaskService;
|
@Resource
|
EdgStorageCageDetailsService edgStorageCageDetailsService;
|
@Resource
|
EdgStorageCageService edgStorageCageService;
|
@Resource
|
EdgStorageDeviceTaskHistoryService edgStorageDeviceTaskHistoryService;
|
|
@Override
|
public void onSubscribe(String identifier, Object value) {
|
String tableName = identifier.contains("01") ? EDG_STORAGE_DEVICE_ONE_TASK : EDG_STORAGE_DEVICE_TWO_TASK;
|
EdgStorageDeviceTask task = edgStorageDeviceTaskService.queryTaskMessage(tableName);
|
if (task == null) {
|
log.info("任务表基础数据录入失败,请检查数据是否录入成功");
|
return;
|
}
|
if (task.getTaskState() <= 4) {
|
log.info("不存在未完成的任务");
|
return;
|
}
|
Integer cell = task.getStartCell();
|
Integer state = task.getTaskState();
|
task.setTaskRunning(Const.GLASS_CACHE_TYPE_EMPTY);
|
task.setTaskState(Const.GLASS_CACHE_TYPE_EMPTY);
|
task.setStartCell(0);
|
edgStorageDeviceTaskService.updateTaskMessage(tableName, task);
|
edgStorageDeviceTaskHistoryService.update(new LambdaUpdateWrapper<EdgStorageDeviceTaskHistory>()
|
.eq(EdgStorageDeviceTaskHistory::getTaskState, Const.RAW_GLASS_TASK_NEW)
|
.set(EdgStorageDeviceTaskHistory::getTaskState,
|
Const.GLASS_CACHE_TYPE_FINISH.equals(state) ? Const.RAW_GLASS_TASK_SUCCESS : Const.RAW_GLASS_TASK_FAILURE)
|
);
|
updateCellRemainWidth(cell);
|
}
|
|
private boolean updateCellRemainWidth(int slot) {
|
List<EdgStorageCageDetails> list = edgStorageCageDetailsService.list(new LambdaQueryWrapper<EdgStorageCageDetails>().eq(EdgStorageCageDetails::getSlot, slot)
|
.eq(EdgStorageCageDetails::getState, Const.GLASS_STATE_IN));
|
if (CollectionUtil.isEmpty(list)) {
|
log.info("格子{}内无玻璃,无法更新", slot);
|
return Boolean.FALSE;
|
}
|
int widthTotal = (int) list.stream().map(e -> e.getWidth() + glassGap).mapToDouble(Double::intValue).sum();
|
int remainWidth = cellLength - widthTotal >= 0 ? cellLength - widthTotal : 0;
|
edgStorageCageService.update(new LambdaUpdateWrapper<EdgStorageCage>().
|
set(EdgStorageCage::getRemainWidth, remainWidth).eq(EdgStorageCage::getSlot, slot));
|
return Boolean.FALSE;
|
}
|
}
|