自动化立体仓库 - WMS系统
zyx
2023-10-04 45c2bf51fae3030c8e22fa2f2016b64a28928547
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
172
173
174
175
176
177
178
179
180
package com.zy.asrs.service.impl;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.core.common.Cools;
import com.zy.asrs.entity.AgvBasDevp;
import com.zy.asrs.entity.AgvWaitPakin;
import com.zy.asrs.entity.AgvWrkDetl;
import com.zy.asrs.entity.AgvWrkMast;
import com.zy.asrs.mapper.AgvBasDevpMapper;
import com.zy.asrs.service.AgvBasDevpService;
import com.zy.asrs.service.AgvWaitPakinService;
import com.zy.asrs.service.AgvWrkDetlService;
import com.zy.asrs.service.AgvWrkMastService;
import com.zy.common.model.AgvBasDevpDto;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.*;
import java.util.stream.Collectors;
 
@Service
@Transactional
public class AgvBasDevpServiceImpl extends ServiceImpl<AgvBasDevpMapper, AgvBasDevp> implements AgvBasDevpService {
 
    @Autowired
    AgvBasDevpMapper agvBasDevpMapper;
    @Autowired
    AgvWrkMastService agvWrkMastService;
    @Autowired
    AgvWrkDetlService agvWrkDetlService;
    @Autowired
    AgvWaitPakinService agvWaitPakinService;
 
    public void clearBasDevp(){
        agvBasDevpMapper.deleteAll();
    }
 
    public void initBasDevp(){
 
        //初始化1楼缓存货架站点 2排5列3层
        this.insertBatch(getCacheBasDevpList(1,2,1,5,1,3,1));
        //初始化3楼缓存货架站点 3排5列3层
        this.insertBatch(getCacheBasDevpList(5,7,1,5,1,3,3));
        //初始化3楼输送线工作站点 4个站点
        this.insertBatch(getLineBasDevpList());
 
    }
 
    private List<AgvBasDevp> getLineBasDevpList(){
        List<AgvBasDevp> agvBasDevpList = new ArrayList<>();
        Date now = new Date();
        for(int row=1; row<=4; row++){
            agvBasDevpList.add(getAgvBasDevp(row,1,1,3,"N",now));
        }
        return agvBasDevpList;
    }
 
    //根据排列层获取AGV缓存货架站点列表
    private List<AgvBasDevp> getCacheBasDevpList(int rowIndex, int rowMax, int bayIndex, int bayMax, int levIndex, int levMax, int floor){
        List<AgvBasDevp> agvBasDevpList = new ArrayList<>();
        Date now = new Date();
        for(int row=rowIndex; row<=rowMax; row++){
            for(int bay=bayIndex; bay<=bayMax; bay++){
                for(int lev=levIndex; lev<=levMax; lev++){
                    agvBasDevpList.add(getAgvBasDevp(row,bay,lev,floor,"Y",now));
                }
            }
        }
 
        return agvBasDevpList;
    }
 
    private AgvBasDevp getAgvBasDevp(int row, int bay, int lev, int floor, String cacheShelves, Date now){
        AgvBasDevp agvBasDevp = new AgvBasDevp();
        String devNo = "CS-" + floor + "0" + row + "-00" + bay + "-0" + lev + "@" + floor;
        String stationCode = "CS-" + floor + "0" + row;
        agvBasDevp.setDevNo(devNo);
        agvBasDevp.setStationCode(stationCode);
        agvBasDevp.setLocSts("O");
        agvBasDevp.setCacheShelves(cacheShelves);
        agvBasDevp.setFloor(floor);
        agvBasDevp.setModiTime(now);
        agvBasDevp.setAppeTime(now);
        return agvBasDevp;
    }
 
    public void updateLocStsAndBarcodeByDevNo(String devNo, String locSts, String barcode){
 
        AgvBasDevp agvBasDevp = this.selectById(devNo);
        agvBasDevp.setLocSts(locSts);
        agvBasDevp.setBarcode(barcode);
        this.updateById(agvBasDevp);
    }
 
    public Map<String, Object> getAgvBasDevpDtoByStationCode(String stationCode) {
 
        List<Map<String, Object>> body = new ArrayList<>();
        for(int i=3; i>=1; i--){
            List<AgvBasDevp> agvBasDevpList = this.selectList(new EntityWrapper<AgvBasDevp>()
                    .eq("station_code", stationCode)
                    .like("dev_no","0"+ i +"@"));
 
            Map<String, Object> map = new HashMap<>();
 
            List<AgvBasDevpDto> agvBasDevpDtoList = agvBasDevpList.stream().map(agvBasDevp -> {
                AgvBasDevpDto agvBasDevpDto = new AgvBasDevpDto();
                BeanUtils.copyProperties(agvBasDevp, agvBasDevpDto);
 
                //如果工作位状态为0.空库位,则直接返回
                if("O".equals(agvBasDevpDto.getLocSts())){
                    return agvBasDevpDto;
                }
 
                AgvWrkMast agvWrkMast = agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>()
                        .eq("loc_no", agvBasDevpDto.getDevNo())
                        .or().eq("source_loc_no",agvBasDevpDto.getDevNo()));
 
                agvBasDevpDto.setAgvWrkMast(agvWrkMast);
 
                if("F".equals(agvBasDevpDto.getLocSts()) || "R".equals(agvBasDevpDto.getLocSts())){
                    AgvWaitPakin agvWaitPakin = agvWaitPakinService.selectOne(new EntityWrapper<AgvWaitPakin>()
                            .eq("supp_code", agvBasDevpDto.getBarcode()));
 
                    agvBasDevpDto.setAgvWaitPakin(agvWaitPakin);
 
                    if(Cools.isEmpty(agvWaitPakin)){
                        AgvWrkDetl agvWrkDetl = agvWrkDetlService.selectOne(new EntityWrapper<AgvWrkDetl>().
                                eq("wrk_no",agvWrkMast.getWrkNo()));
 
                        agvBasDevpDto.setAgvWrkDetl(agvWrkDetl);
                    }
                }
 
                if(!Cools.isEmpty(agvWrkMast)){
                    setFlagForAgvBasDevpDto(agvWrkMast,agvBasDevpDto);
                }
 
                return agvBasDevpDto;
 
            }).collect(Collectors.toList());
 
            map.put("loc",agvBasDevpDtoList);
            body.add(map);
        }
 
        Map<String, Object> result = new HashMap<>();
        result.put("body", body);
 
        return result;
    }
 
    private void setFlagForAgvBasDevpDto(AgvWrkMast agvWrkMast, AgvBasDevpDto agvBasDevpDto){
        //当工作档类型为101.出库 并且 工作位状态为F.在库时,显示容器离场按钮
        if(agvWrkMast.getIoType() == 101 && "F".equals(agvBasDevpDto.getLocSts())){
            agvBasDevpDto.setContainerMoveOutFlag(true);
        }
 
        //当工作档类型为101.出库 并且 工作位状态为F.在库时,显示容器离场按钮
        if(agvWrkMast.getIoType() == 110 && "D".equals(agvBasDevpDto.getLocSts())){
            agvBasDevpDto.setContainerMoveOutFlag(true);
        }
 
        //当工作档类型为103.拣料出库 并且 工作位状态为F.在库时,显示拣料/盘点入库按钮
        if(agvWrkMast.getIoType() == 103 && "F".equals(agvBasDevpDto.getLocSts())){
            agvBasDevpDto.setPickInFlag(true);
        }
        //当工作档类型为107.盘点出库 并且 工作位状态为F.在库时,显示拣料/盘点入库按钮
        if(agvWrkMast.getIoType() == 107 && "F".equals(agvBasDevpDto.getLocSts())){
            agvBasDevpDto.setPickInFlag(true);
        }
    }
 
    public List<String> getAvailableEmptyInSite() {
        return this.baseMapper.getAvailableEmptyInSite();
    }
 
}