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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package com.mes.hollow.service.impl;
 
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.base.entity.vo.BigStorageVO;
import com.mes.common.config.Const;
import com.mes.glassinfo.entity.GlassInfo;
import com.mes.glassinfo.service.GlassInfoService;
import com.mes.hollow.entity.HollowBigStorageCage;
import com.mes.hollow.entity.HollowBigStorageCageDetails;
import com.mes.hollow.entity.HollowGlassRelationInfo;
import com.mes.hollow.entity.dto.*;
import com.mes.hollow.entity.vo.HollowBigStorageDetailsQueryVO;
import com.mes.hollow.mapper.HollowBigStorageCageDetailsMapper;
import com.mes.hollow.service.HollowBigStorageCageDetailsService;
import com.mes.hollow.service.HollowBigStorageCageService;
import com.mes.hollow.service.HollowGlassRelationInfoService;
import com.mes.job.OpcPlcStorageCageHollowTask;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * (HollowBigStorageCageDetails)表服务实现类
 *
 * @author makejava
 * @since 2024-11-21 09:23:12
 */
@Service
@Slf4j
public class HollowBigStorageCageDetailsServiceImpl extends ServiceImpl<HollowBigStorageCageDetailsMapper, HollowBigStorageCageDetails> implements HollowBigStorageCageDetailsService {
 
    @Resource
    HollowBigStorageCageService hollowBigStorageCageService;
 
    @Resource
    HollowGlassRelationInfoService hollowGlassRelationInfoService;
    @Resource
    GlassInfoService glassInfoService;
    @Resource
    OpcPlcStorageCageHollowTask opcPlcStorageCageHollowTask;
 
    @Override
    public void updateBySlot(List<UpdateHollowBigStorageCageDTO> storageCageDTOList, Integer state) {
        baseMapper.updateBySlot(storageCageDTOList, state);
    }
 
    @Override
    public List<FlowCardGlassInfoDTO> hollowIsAll(String flow_card_id, Integer totalLayer, Boolean flag) {
        return baseMapper.hollowIsAll(flow_card_id, totalLayer, flag);
    }
 
    @Override
    public List<FlowCardVirtualSlotDTO> queryIsAllNeedDispatchVirtualSlot() {
        return baseMapper.queryIsAllNeedDispatchVirtualSlot();
    }
 
    @Override
    public List<BigStorageSequenceDTO> queryNeedDispatchSlot(FlowCardVirtualSlotDTO flowCardVirtualSlotDTO) {
        return baseMapper.queryNeedDispatchSlot(flowCardVirtualSlotDTO);
    }
 
    @Override
    public List<HollowBigStorageCageDetails> queryOutGlassList(String flowCardId, int cell) {
        return baseMapper.queryOutGlassList(flowCardId, cell);
    }
 
    @Override
    public Map<Integer, List<BigStorageVO>> queryHollowbigStorageCageDetail() {
        List<BigStorageVO> bigStorageCages = baseMapper.queryHollowbigStorageCageDetail();
        return bigStorageCages.stream().collect(Collectors.groupingBy(item -> item.getDeviceId()));
    }
 
    @Override
    public List<HollowBigStorageCageDetails> querySlotMaxSequence(String flowCardId, Integer totalLayer, Integer layer, Integer virtualSlot) {
        return baseMapper.querySlotMaxSequence(flowCardId, totalLayer, layer, virtualSlot);
    }
 
    @Override
    public List<HollowBigStorageAndDetailsDTO> insertHollowBigStorageCageDetails(HollowBigStorageCageDetails bigStorageCageDetails) {
        GlassInfo info = glassInfoService.getOne(new LambdaQueryWrapper<GlassInfo>().in(GlassInfo::getGlassId, bigStorageCageDetails.getGlassId()));
        HollowBigStorageDTO hollowBigStorageDTO = hollowGlassRelationInfoService.queryHollowTargetSlot(bigStorageCageDetails.getFlowCardId(), bigStorageCageDetails.getWidth(),
                bigStorageCageDetails.getHeight(), bigStorageCageDetails.getTotalLayer(), bigStorageCageDetails.getLayer());
        HollowBigStorageCageDetails cageDetails = new HollowBigStorageCageDetails();
        BeanUtils.copyProperties(hollowBigStorageDTO, cageDetails);
        BeanUtils.copyProperties(info, cageDetails);
        cageDetails.setState(Const.GLASS_STATE_NEW);
        cageDetails.setSequence(hollowBigStorageDTO.getSlotSequence());
        cageDetails.setGap(250);
        cageDetails.setId(null);
        this.save(cageDetails);
        hollowGlassRelationInfoService.update(new LambdaUpdateWrapper<HollowGlassRelationInfo>()
                .set(HollowGlassRelationInfo::getGlassId, cageDetails.getGlassId())
                .set(HollowGlassRelationInfo::getTemperingLayoutId, cageDetails.getTemperingLayoutId())
                .set(HollowGlassRelationInfo::getTemperingFeedSequence, cageDetails.getTemperingFeedSequence())
                .set(HollowGlassRelationInfo::getEngineerId, cageDetails.getEngineerId())
                .set(HollowGlassRelationInfo::getState, Const.HOLLOW_RELATION_OCCUPY)
                .eq(HollowGlassRelationInfo::getFlowCardId, hollowBigStorageDTO.getFlowCardId())
                .eq(HollowGlassRelationInfo::getLayer, hollowBigStorageDTO.getLayer())
                .eq(HollowGlassRelationInfo::getVirtualSlot, hollowBigStorageDTO.getVirtualSlot())
                .eq(HollowGlassRelationInfo::getSlotSequence, hollowBigStorageDTO.getSlotSequence())
                .eq(HollowGlassRelationInfo::getHollowSequence, hollowBigStorageDTO.getHollowSequence())
        );
        HollowBigStorageDetailsQueryVO query = new HollowBigStorageDetailsQueryVO();
        query.setDeviceId(bigStorageCageDetails.getDeviceId());
        return hollowBigStorageCageService.queryHollowBigStorageCageDetail(query);
    }
 
    @Override
    public List<HollowBigStorageAndDetailsDTO> deleteHollowBigStorageCageDetails(String glassId, Integer deviceId, Integer slot) {
        return hollowBigStorageCageDetailsChild(glassId, deviceId, slot, Const.GLASS_STATE_OUT);
    }
 
    @Override
    public List<HollowBigStorageAndDetailsDTO> damageHollowBigStorageCageDetails(String glassId, Integer deviceId, Integer slot, int state) {
        return hollowBigStorageCageDetailsChild(glassId, deviceId, slot, state);
    }
 
    @Override
    public void updateDeviceIdBySlot(List<Integer> slotList) {
        baseMapper.updateDeviceIdBySlot(slotList);
    }
 
    @Override
    public List<HollowBigStorageCageDetails> queryPairGlassList(String flowCardId, Integer totalLayer, Integer totalPairQuantity, Integer isOut) {
        return baseMapper.queryPairGlassList(flowCardId, totalLayer, totalPairQuantity, isOut);
    }
 
    @Override
    public Boolean updateHollowStorageCageDisabled(int slot, int enableState) {
        return hollowBigStorageCageService.update(new LambdaUpdateWrapper<HollowBigStorageCage>()
                .set(HollowBigStorageCage::getEnableState, enableState)
                .eq(HollowBigStorageCage::getSlot, slot));
    }
 
    @Override
    public List<FlowCardVirtualSlotDTO> queryFlowCardIdsAndLayer() {
        return baseMapper.queryFlowCardIdsAndLayer();
    }
 
    private List<HollowBigStorageAndDetailsDTO> hollowBigStorageCageDetailsChild(String glassId, Integer deviceId, Integer slot, int state) {
        //将对应格子号的玻璃id置为101
        this.update(new LambdaUpdateWrapper<HollowBigStorageCageDetails>()
                .set(HollowBigStorageCageDetails::getState, state)
                .eq(HollowBigStorageCageDetails::getSlot, slot)
                .eq(HollowBigStorageCageDetails::getGlassId, glassId)
        );
        //将流程卡关系表内对应的玻璃信息清除
        hollowGlassRelationInfoService.update(new LambdaUpdateWrapper<HollowGlassRelationInfo>()
                .set(HollowGlassRelationInfo::getGlassId, null)
                .set(HollowGlassRelationInfo::getTemperingLayoutId, null)
                .set(HollowGlassRelationInfo::getTemperingFeedSequence, null)
                .set(HollowGlassRelationInfo::getEngineerId, null)
                .set(HollowGlassRelationInfo::getState, Const.HOLLOW_RELATION_NEW)
                .eq(HollowGlassRelationInfo::getGlassId, glassId)
        );
        //更新对应格子的剩余尺寸
        opcPlcStorageCageHollowTask.updateSlotRemainBySlots(Arrays.asList(slot));
        //返回对应的笼子的列表信息
        HollowBigStorageDetailsQueryVO query = new HollowBigStorageDetailsQueryVO();
        query.setDeviceId(deviceId);
        return hollowBigStorageCageService.queryHollowBigStorageCageDetail(query);
    }
}