1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package com.mes.hollow.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.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<HollowGlassOutRelationInfoMapper, HollowGlassOutRelationInfo> implements HollowGlassOutRelationInfoService {
 
    @Resource
    GlassInfoService glassInfoService;
    @Resource
    HollowBigStorageCageDetailsService hollowBigStorageCageDetailsService;
    @Resource
    HollowGlassQueueInfoService hollowGlassQueueInfoService;
 
    @Resource
    RedisUtil redisUtil;
 
    @Override
    public HollowGlassOutRelationInfo receiveTask(String flowCardId, int cell, int totalPairQuantity) {
        return childrenTask(flowCardId,cell,totalPairQuantity,0);
    }
 
    @Override
    public HollowGlassOutRelationInfo forceOutGlass(String flowCardId, int cell, int totalPairQuantity) {
        return childrenTask(flowCardId,cell,totalPairQuantity,1);
    }
 
    @Override
    public Boolean dispatchHollowSwitch(Boolean flag) {
        redisUtil.setCacheObject("dispatchHollowSwitch", flag);
        return  redisUtil.getCacheObject("dispatchHollowSwitch");
    }
 
 
    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"));
        HollowGlassOutRelationInfo info = new HollowGlassOutRelationInfo();
        if (null == glassInfo) {
            log.info("该流程卡信息系统未找到");
            return info;
        }
        info.setFlowCardId(flowCardId);
        info.setCell(cell);
        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;
        List<HollowGlassQueueInfo> hollowQueues = new ArrayList<>();
        loop:
        for (HollowBigStorageCageDetails queue : hollowBigStorageCageDetailsList) {
            HollowGlassQueueInfo queueInfo = new HollowGlassQueueInfo();
            BeanUtils.copyProperties(queue, queueInfo);
            queueInfo.setState(Const.TEMPERING_NEW);
            queueInfo.setCell(cell);
            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);
        this.save(info);
        return info;
    }
}