#
Junjie
10 小时以前 8a1f312d9f7842bb02c97b200e017926f0af63a5
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
package com.zy.asrs.controller;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.core.annotations.ManagerAuth;
import com.core.common.BaseRes;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.common.R;
import com.core.exception.CoolException;
import com.zy.asrs.entity.BasMap;
import com.zy.asrs.entity.BasShuttleCharge;
import com.zy.asrs.entity.LocMast;
import com.zy.asrs.service.BasMapService;
import com.zy.asrs.service.BasShuttleChargeService;
import com.zy.asrs.service.LocMastService;
import com.zy.asrs.utils.Utils;
import com.zy.common.model.MapNode;
import com.zy.common.model.NavigateNode;
import com.zy.common.model.enums.NavigationMapType;
import com.zy.common.utils.NavigateMapData;
import com.zy.common.web.BaseController;
import com.zy.core.enums.LocStsType;
import com.zy.core.enums.MapNodeType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
 
import java.util.*;
 
@Slf4j
@RestController
public class LocMastController extends BaseController {
 
    @Autowired
    private NavigateMapData navigateMapData;
    @Autowired
    private LocMastService locMastService;
    @Autowired
    private BasMapService basMapService;
    @Autowired
    private BasShuttleChargeService basShuttleChargeService;
 
    @RequestMapping(value = "/locMast/{id}/auth")
    @ManagerAuth
    public R get(@PathVariable("id") String id) {
        return R.ok(locMastService.selectById(String.valueOf(id)));
    }
 
    @RequestMapping(value = "/locMast/list/auth")
    @ManagerAuth
    public R list(@RequestParam(defaultValue = "1")Integer curr,
                  @RequestParam(defaultValue = "10")Integer limit,
                  @RequestParam(required = false)String orderByField,
                  @RequestParam(required = false)String orderByType,
                  @RequestParam Map<String, Object> param){
        excludeTrash(param);
        EntityWrapper<LocMast> wrapper = new EntityWrapper<>();
        convert(param, wrapper);
        if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));}
        return R.ok(locMastService.selectPage(new Page<>(curr, limit), wrapper));
    }
 
    private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){
        for (Map.Entry<String, Object> entry : map.entrySet()){
            String val = String.valueOf(entry.getValue());
            if (val.contains(RANGE_TIME_LINK)){
                String[] dates = val.split(RANGE_TIME_LINK);
                wrapper.ge(entry.getKey(), DateUtils.convert(dates[0]));
                wrapper.le(entry.getKey(), DateUtils.convert(dates[1]));
            } else {
                wrapper.like(entry.getKey(), val);
            }
        }
    }
 
    @RequestMapping(value = "/locMast/update/auth")
    @ManagerAuth(memo = "库位修改")
    @Transactional
    public R update(LocMast locMast){
        if (Cools.isEmpty(locMast) || null==locMast.getLocNo()){
            return R.error();
        }
 
        Date now = new Date();
        locMast.setModiUser(getUserId());
        locMast.setModiTime(now);
        if(!locMastService.updateById(locMast)) {
            throw new CoolException("服务器错误,请联系管理员");
        }
        return R.ok();
    }
 
    @RequestMapping(value = "/locMast/delete/auth")
    @ManagerAuth(memo = "库位删除")
    public R delete(@RequestParam String param){
        List<LocMast> list = JSONArray.parseArray(param, LocMast.class);
        if (Cools.isEmpty(list)){
            return R.error();
        }
        for (LocMast entity : list){
            locMastService.delete(new EntityWrapper<>(entity));
        }
        return R.ok();
    }
 
    @RequestMapping(value = "/locMast/export/auth")
    @ManagerAuth(memo = "库位导出")
    public R export(@RequestBody JSONObject param){
        List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class);
        EntityWrapper<LocMast> wrapper = new EntityWrapper<>();
        Map<String, Object> map = excludeTrash(param.getJSONObject("locMast"));
        convert(map, wrapper);
        List<LocMast> list = locMastService.selectList(wrapper);
        return R.ok(exportSupport(list, fields));
    }
 
    @RequestMapping(value = "/locMastQuery/auth")
    @ManagerAuth
    public R query(String condition) {
        EntityWrapper<LocMast> wrapper = new EntityWrapper<>();
        wrapper.like("loc_no", condition);
        Page<LocMast> page = locMastService.selectPage(new Page<>(0, 10), wrapper);
        List<Map<String, Object>> result = new ArrayList<>();
        for (LocMast locMast : page.getRecords()){
            Map<String, Object> map = new HashMap<>();
            map.put("id", locMast.getLocNo());
            map.put("value", locMast.getLocNo());
            result.add(map);
        }
        return R.ok(result);
    }
 
    @RequestMapping(value = "/locMast/check/column/auth")
    @ManagerAuth
    public R query(@RequestBody JSONObject param) {
        Wrapper<LocMast> wrapper = new EntityWrapper<LocMast>().eq(humpToLine(String.valueOf(param.get("key"))), param.get("val"));
        if (null != locMastService.selectOne(wrapper)){
            return R.parse(BaseRes.REPEAT).add(getComment(LocMast.class, String.valueOf(param.get("key"))));
        }
        return R.ok();
    }
 
    @PostMapping("/locMast/init")
    @ManagerAuth(memo = "初始化库位")
    @Transactional
    public R locMastInit() {
        List<BasMap> basMaps = basMapService.selectList(new EntityWrapper<BasMap>().orderBy("lev", true));
        basShuttleChargeService.delete(new EntityWrapper<>());
        int chargeNo = 1;
        for (BasMap basMap : basMaps) {
            Integer lev = basMap.getLev();
            locMastService.delete(new EntityWrapper<>(new LocMast())
                    .eq("lev1", lev));
            List<List<MapNode>> lists = navigateMapData.getJsonData(lev, NavigationMapType.getMapTypes(NavigationMapType.NONE), null, null);//获取完整地图(包括入库出库)
            for (int row = 0; row < lists.size(); row++) {
                List<MapNode> nodeList = lists.get(row);
                for (int bay = 0; bay < nodeList.size(); bay++) {
                    MapNode mapNode = nodeList.get(bay);
 
                    if (mapNode.getValue() == MapNodeType.DISABLE.id) {
                        continue;
                    }
 
                    String locNo = Utils.getLocNo(row, bay, lev);
                    LocMast locMast = new LocMast();
                    locMast.setLocNo(locNo);
                    locMast.setRow1(row);
                    locMast.setBay1(bay);
                    locMast.setLev1(lev);
                    locMast.setStatus(1);
 
                    if (mapNode.getValue() == MapNodeType.NORMAL_PATH.id) {
                        locMast.setLocSts(LocStsType.O.toString());
                    } else if (mapNode.getValue() == MapNodeType.MAIN_PATH.id) {
                        locMast.setLocSts(LocStsType.W.toString());
                    } else if (mapNode.getValue() == MapNodeType.CHARGE.id) {
                        locMast.setLocSts(LocStsType.C.toString());
 
                        BasShuttleCharge basShuttleCharge = new BasShuttleCharge();
                        basShuttleCharge.setChargeId(chargeNo++);
                        basShuttleCharge.setLocNo(locNo);
                        basShuttleCharge.setWaitLocNo(locNo);
                        basShuttleCharge.setStatus(1);
                        basShuttleCharge.setCreateTime(new Date());
                        basShuttleCharge.setUpdateTime(new Date());
                        basShuttleChargeService.insert(basShuttleCharge);
                    } else if (mapNode.getValue() == MapNodeType.CONVEYOR.id) {
                        locMast.setLocSts(LocStsType.E.toString());
                    } else if (mapNode.getValue() == MapNodeType.LIFT.id) {
                        locMast.setLocSts(LocStsType.E.toString());
                    }
 
                    locMastService.insert(locMast);
                }
            }
 
            LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("lev1", lev).orderBy("row1", false));
            Integer rowMax = locMast.getRow1();
            LocMast locMast2 = locMastService.selectOne(new EntityWrapper<LocMast>().eq("lev1", lev).orderBy("bay1", false));
            Integer bayMax = locMast2.getBay1();
 
            Integer baseRow = basMap.getBaseRow();
            Integer baseRowCode = basMap.getBaseRowCode();
 
            if (baseRow > 0) {
                for (int i = baseRow; i <= rowMax; i++) {
                    Integer baseBayCode = basMap.getBaseBayCode();
                    if (basMap.getBaseBay() > 0) {
                        for (int j = basMap.getBaseBay(); j <= bayMax; j++) {
                            String locNo = Utils.getLocNo(i, j, lev);
 
                            LocMast locMast1 = locMastService.selectOne(new EntityWrapper<LocMast>()
                                    .eq("loc_no", locNo));
                            if (locMast1 != null) {
                                HashMap<String, Object> point = new HashMap<>();
                                point.put("y", baseRowCode);
                                point.put("x", baseBayCode);
                                point.put("z", lev);
                                locMast1.setQrCodeValue(JSON.toJSONString(point));
                                locMastService.updateById(locMast1);
                            }
                            baseBayCode += 1;
                        }
                    }else {
                        int baseBay = basMap.getBaseBay() * -1;
                        for (int j = baseBay; j > 0; j--) {
                            String locNo = Utils.getLocNo(i, j, lev);
 
                            LocMast locMast1 = locMastService.selectOne(new EntityWrapper<LocMast>()
                                    .eq("loc_no", locNo));
                            if (locMast1 != null) {
                                HashMap<String, Object> point = new HashMap<>();
                                point.put("y", baseRowCode);
                                point.put("x", baseBayCode);
                                point.put("z", lev);
                                locMast1.setQrCodeValue(JSON.toJSONString(point));
                                locMastService.updateById(locMast1);
                            }
                            baseBayCode += 1;
                        }
                    }
                    baseRowCode += 1;
                }
            }else {
                baseRow = baseRow * -1;
                for (int i = baseRow; i > 0; i--) {
                    Integer baseBayCode = basMap.getBaseBayCode();
                    if (basMap.getBaseBay() > 0) {
                        for (int j = basMap.getBaseBay(); j <= bayMax; j++) {
                            String locNo = Utils.getLocNo(i, j, lev);
 
                            LocMast locMast1 = locMastService.selectOne(new EntityWrapper<LocMast>()
                                    .eq("loc_no", locNo));
                            if (locMast1 != null) {
                                HashMap<String, Object> point = new HashMap<>();
                                point.put("y", baseRowCode);
                                point.put("x", baseBayCode);
                                point.put("z", lev);
                                locMast1.setQrCodeValue(JSON.toJSONString(point));
                                locMastService.updateById(locMast1);
                            }
                            baseBayCode += 1;
                        }
                    }else {
                        int baseBay = basMap.getBaseBay() * -1;
                        for (int j = baseBay; j > 0; j--) {
                            String locNo = Utils.getLocNo(i, j, lev);
 
                            LocMast locMast1 = locMastService.selectOne(new EntityWrapper<LocMast>()
                                    .eq("loc_no", locNo));
                            if (locMast1 != null) {
                                HashMap<String, Object> point = new HashMap<>();
                                point.put("y", baseRowCode);
                                point.put("x", baseBayCode);
                                point.put("z", lev);
                                locMast1.setQrCodeValue(JSON.toJSONString(point));
                                locMastService.updateById(locMast1);
                            }
                            baseBayCode += 1;
                        }
                    }
                    baseRowCode += 1;
                }
            }
        }
 
        return R.ok();
    }
 
}