zhoushihao
2024-12-30 2e20e85173b764e43a6e4022072bc8fb0cc61330
hangzhoumesParent/moduleService/howllowGlassModule/src/main/java/com/mes/hollow/service/impl/HollowGlassOutRelationInfoServiceImpl.java
@@ -1,12 +1,15 @@
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;
@@ -19,6 +22,7 @@
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@@ -43,54 +47,142 @@
    RedisUtil redisUtil;
    @Override
    public HollowGlassOutRelationInfo receiveTask(String flowCardId, int cell, int totalPairQuantity) {
        return childrenTask(flowCardId,cell,totalPairQuantity,0);
    public HollowGlassOutRelationInfo receiveTask(HollowTaskRequest request) {
        return childrenTask(request, 0);
    }
    @Override
    public HollowGlassOutRelationInfo forceOutGlass(String flowCardId, int cell, int totalPairQuantity) {
        return childrenTask(flowCardId,cell,totalPairQuantity,1);
    public HollowGlassOutRelationInfo forceOutGlass(HollowTaskRequest request) {
        return childrenTask(request, 1);
    }
    @Override
    public Boolean dispatchHollowSwitch(Boolean flag) {
        redisUtil.setCacheObject("dispatchHollowSwitch", flag);
        return  redisUtil.getCacheObject("dispatchHollowSwitch");
        return redisUtil.getCacheObject("dispatchHollowSwitch");
    }
    @Override
    public List<String> hollowTaskList(int cell) {
        //查询任务表中本条线所有未完成的任务信息
        List<HollowGlassOutRelationInfo> list = this.list(new LambdaQueryWrapper<HollowGlassOutRelationInfo>()
                .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<String>();
    }
    @Override
    public List<HollowGlassQueueInfo> appointHollowTaskDetails(String flowCardId, int cell) {
        //按照流程卡及路线,查找对应的任务信息
        HollowGlassOutRelationInfo hollowGlassOutRelationInfo = this.getOne(new LambdaQueryWrapper<HollowGlassOutRelationInfo>()
                .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<HollowGlassQueueInfo>();
        }
        //按照任务id查询对列表中的队列信息
        return hollowGlassQueueInfoService.list(new LambdaQueryWrapper<HollowGlassQueueInfo>()
                .eq(HollowGlassQueueInfo::getRelationId, hollowGlassOutRelationInfo.getId()));
    }
    @Override
    public Boolean startTask(String flowCardId, int cell) {
        //更新任务状态为开始
        return this.update(new LambdaUpdateWrapper<HollowGlassOutRelationInfo>()
                .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<HollowGlassOutRelationInfo>()
                .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<HollowGlassQueueInfo>()
                .in(HollowGlassQueueInfo::getState, Const.TEMPERING_NEW)
                .eq(HollowGlassQueueInfo::getFlowCardId, flowCardId)
                .eq(HollowGlassQueueInfo::getCell, cell));
        //更新任务状态未已完成
        return this.update(new LambdaUpdateWrapper<HollowGlassOutRelationInfo>()
                .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<HollowGlassOutRelationInfo>()
                .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<HollowGlassQueueInfo>()
                .in(HollowGlassQueueInfo::getState, Const.TEMPERING_NEW)
                .eq(HollowGlassQueueInfo::getFlowCardId, flowCardId)
                .eq(HollowGlassQueueInfo::getCell, cell));
        return Boolean.TRUE;
    }
    private HollowGlassOutRelationInfo childrenTask(String flowCardId, int cell, int totalPairQuantity,int isForce) {
        GlassInfo glassInfo = glassInfoService.getOne(new LambdaQueryWrapper<GlassInfo>().eq(GlassInfo::getFlowCardId, flowCardId).last("limit 1"));
    private HollowGlassOutRelationInfo childrenTask(HollowTaskRequest request, int isForce) {
        GlassInfo glassInfo = glassInfoService.getOne(new LambdaQueryWrapper<GlassInfo>().eq(GlassInfo::getFlowCardId, request.getFlowCardId()).last("limit 1"));
        HollowGlassOutRelationInfo info = new HollowGlassOutRelationInfo();
        if (null == glassInfo) {
            log.info("该流程卡信息系统未找到");
            return info;
        }
        info.setFlowCardId(flowCardId);
        info.setCell(cell);
        List<HollowGlassOutRelationInfo> outRelationInfos = this.list(new LambdaQueryWrapper<HollowGlassOutRelationInfo>()
                .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_START);
        info.setTotalPairQuantity(totalPairQuantity);
        List<HollowBigStorageCageDetails> hollowBigStorageCageDetailsList = hollowBigStorageCageDetailsService.queryOutGlassList(flowCardId, cell);
        int isPairCount = glassInfo.getTotalLayer() * totalPairQuantity;
        info.setState(Const.HOLLOW_FLOW_CARD_NEW);
        info.setTotalPairQuantity(request.getTotalPairQuantity());
        info.setFormulaId(request.getFormulaId());
        this.save(info);
        // 查询出需要出玻璃的队列
        List<HollowBigStorageCageDetails> hollowBigStorageCageDetailsList = hollowBigStorageCageDetailsService
                .queryOutGlassList(request.getFlowCardId(), request.getCell());
        int isPairCount = glassInfo.getTotalLayer() * request.getTotalPairQuantity();
        List<HollowGlassQueueInfo> 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(cell);
            queueInfo.setCell(request.getCell());
            queueInfo.setCreateTime(new Date());
            queueInfo.setUpdateTime(new Date());
            hollowQueues.add(queueInfo);
            if (queue.getIsPair() == 1){
                isPairCount -=1;
                if (isPairCount == 0){
            if (queue.getIsPair() == 1) {
                isPairCount -= 1;
                if (isPairCount == 0) {
                    break loop;
                }
            }
        }
        hollowGlassQueueInfoService.saveBatch(hollowQueues);
        this.save(info);
        return info;
    }
}