package com.mes.hollow.service.impl; import cn.hutool.core.collection.CollectionUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.mes.common.config.Const; import com.mes.glassinfo.entity.GlassInfo; import com.mes.glassinfo.service.GlassInfoService; import com.mes.hollow.entity.HollowBigStorageCageDetails; import com.mes.hollow.entity.HollowGlassOutRelationInfo; import com.mes.hollow.entity.request.HollowTaskRequest; import com.mes.hollow.mapper.HollowGlassOutRelationInfoMapper; import com.mes.hollow.service.HollowBigStorageCageDetailsService; import com.mes.hollow.service.HollowGlassOutRelationInfoService; import com.mes.hollowqueue.entity.HollowGlassQueueInfo; import com.mes.hollowqueue.service.HollowGlassQueueInfoService; import com.mes.utils.RedisUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.stream.Collectors; /** * (HollowGlassOutRelationInfo)表服务实现类 * * @author makejava * @since 2024-11-30 13:57:29 */ @Service @Slf4j public class HollowGlassOutRelationInfoServiceImpl extends ServiceImpl implements HollowGlassOutRelationInfoService { @Resource GlassInfoService glassInfoService; @Resource HollowBigStorageCageDetailsService hollowBigStorageCageDetailsService; @Resource HollowGlassQueueInfoService hollowGlassQueueInfoService; @Resource RedisUtil redisUtil; @Override public HollowGlassOutRelationInfo receiveTask(HollowTaskRequest request) { return childrenTask(request, 0); } @Override public HollowGlassOutRelationInfo forceOutGlass(HollowTaskRequest request) { return childrenTask(request, 1); } @Override public Boolean dispatchHollowSwitch(Boolean flag) { redisUtil.setCacheObject("dispatchHollowSwitch", flag); return redisUtil.getCacheObject("dispatchHollowSwitch"); } @Override public List hollowTaskList(int cell) { //查询任务表中本条线所有未完成的任务信息 List list = this.list(new LambdaQueryWrapper() .in(HollowGlassOutRelationInfo::getState, Const.HOLLOW_FLOW_CARD_NEW, Const.HOLLOW_FLOW_CARD_START, Const.HOLLOW_FLOW_CARD_PAUSE) .eq(HollowGlassOutRelationInfo::getCell, cell)); if (CollectionUtil.isNotEmpty(list)) { return list.stream().map(HollowGlassOutRelationInfo::getFlowCardId).collect(Collectors.toList()); } return new ArrayList(); } @Override public List appointHollowTaskDetails(String flowCardId, int cell) { //按照流程卡及路线,查找对应的任务信息 HollowGlassOutRelationInfo hollowGlassOutRelationInfo = this.getOne(new LambdaQueryWrapper() .in(HollowGlassOutRelationInfo::getState, Const.HOLLOW_FLOW_CARD_NEW, Const.HOLLOW_FLOW_CARD_START, Const.HOLLOW_FLOW_CARD_PAUSE) .eq(HollowGlassOutRelationInfo::getFlowCardId, flowCardId) .eq(HollowGlassOutRelationInfo::getCell, cell).last("limit 1")); if (null == hollowGlassOutRelationInfo) { return new ArrayList(); } //按照任务id查询对列表中的队列信息 return hollowGlassQueueInfoService.list(new LambdaQueryWrapper() .eq(HollowGlassQueueInfo::getRelationId, hollowGlassOutRelationInfo.getId())); } @Override public Boolean startTask(String flowCardId, int cell) { //更新任务状态为开始 return this.update(new LambdaUpdateWrapper() .set(HollowGlassOutRelationInfo::getState, Const.HOLLOW_FLOW_CARD_START) .eq(HollowGlassOutRelationInfo::getFlowCardId, flowCardId) .eq(HollowGlassOutRelationInfo::getCell, cell)); } @Override public Boolean pauseTask(String flowCardId, int cell) { // 更新任务状态为暂停 return this.update(new LambdaUpdateWrapper() .set(HollowGlassOutRelationInfo::getState, Const.HOLLOW_FLOW_CARD_PAUSE) .eq(HollowGlassOutRelationInfo::getFlowCardId, flowCardId) .eq(HollowGlassOutRelationInfo::getCell, cell)); } @Override public Boolean finishTask(String flowCardId, int cell) { //清空队列表中未完成的玻璃信息 hollowGlassQueueInfoService.remove(new LambdaQueryWrapper() .in(HollowGlassQueueInfo::getState, Const.TEMPERING_NEW) .eq(HollowGlassQueueInfo::getFlowCardId, flowCardId) .eq(HollowGlassQueueInfo::getCell, cell)); //更新任务状态未已完成 return this.update(new LambdaUpdateWrapper() .set(HollowGlassOutRelationInfo::getState, Const.HOLLOW_FLOW_CARD_SUCCESS) .eq(HollowGlassOutRelationInfo::getFlowCardId, flowCardId) .eq(HollowGlassOutRelationInfo::getCell, cell)); } @Override public Boolean deleteHollowTaskDetails(String flowCardId, int cell) { //按照流程卡及路线,查找对应的任务信息 this.remove(new LambdaQueryWrapper() .in(HollowGlassOutRelationInfo::getState, Const.HOLLOW_FLOW_CARD_NEW, Const.HOLLOW_FLOW_CARD_START, Const.HOLLOW_FLOW_CARD_PAUSE) .eq(HollowGlassOutRelationInfo::getFlowCardId, flowCardId) .eq(HollowGlassOutRelationInfo::getCell, cell)); hollowGlassQueueInfoService.remove(new LambdaQueryWrapper() .in(HollowGlassQueueInfo::getState, Const.TEMPERING_NEW) .eq(HollowGlassQueueInfo::getFlowCardId, flowCardId) .eq(HollowGlassQueueInfo::getCell, cell)); return Boolean.TRUE; } private HollowGlassOutRelationInfo childrenTask(HollowTaskRequest request, int isForce) { GlassInfo glassInfo = glassInfoService.getOne(new LambdaQueryWrapper().eq(GlassInfo::getFlowCardId, request.getFlowCardId()).last("limit 1")); HollowGlassOutRelationInfo info = new HollowGlassOutRelationInfo(); if (null == glassInfo) { log.info("该流程卡信息系统未找到"); return info; } List outRelationInfos = this.list(new LambdaQueryWrapper() .eq(HollowGlassOutRelationInfo::getCell, request.getCell()) .eq(HollowGlassOutRelationInfo::getFlowCardId, request.getFlowCardId()) .in(HollowGlassOutRelationInfo::getState, Const.HOLLOW_FLOW_CARD_NEW, Const.HOLLOW_FLOW_CARD_START, Const.HOLLOW_FLOW_CARD_PAUSE)); if (CollectionUtil.isNotEmpty(outRelationInfos)) { log.info("当前流程卡在本条线有未完成的任务"); return null; } //保存任务关系主表 info.setFlowCardId(request.getFlowCardId()); info.setCell(request.getCell()); info.setIsForce(isForce); info.setTotalLayer(glassInfo.getTotalLayer()); info.setState(Const.HOLLOW_FLOW_CARD_NEW); info.setTotalPairQuantity(request.getTotalPairQuantity()); info.setFormulaId(request.getFormulaId()); this.save(info); // 查询出需要出玻璃的队列 List hollowBigStorageCageDetailsList = hollowBigStorageCageDetailsService .queryOutGlassList(request.getFlowCardId(), request.getCell()); int isPairCount = glassInfo.getTotalLayer() * request.getTotalPairQuantity(); List hollowQueues = new ArrayList<>(); loop: for (HollowBigStorageCageDetails queue : hollowBigStorageCageDetailsList) { HollowGlassQueueInfo queueInfo = new HollowGlassQueueInfo(); BeanUtils.copyProperties(queue, queueInfo); queueInfo.setRelationId(info.getId()); queueInfo.setState(Const.TEMPERING_NEW); queueInfo.setCell(request.getCell()); queueInfo.setCreateTime(new Date()); queueInfo.setUpdateTime(new Date()); hollowQueues.add(queueInfo); if (queue.getIsPair() == 1) { isPairCount -= 1; if (isPairCount == 0) { break loop; } } } hollowGlassQueueInfoService.saveBatch(hollowQueues); return info; } }