package com.zy.asrs.controller;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONObject;
|
import com.core.annotations.ManagerAuth;
|
import com.core.common.R;
|
import com.zy.asrs.entity.AgvLocDetl;
|
import com.zy.asrs.entity.AgvLocMast;
|
import com.zy.asrs.entity.BasMap;
|
import com.zy.asrs.service.AgvBasMapService;
|
import com.zy.asrs.service.AgvLocDetlService;
|
import com.zy.asrs.service.AgvLocMastService;
|
import com.zy.asrs.utils.Utils;
|
import com.zy.common.utils.RedisUtil;
|
import com.zy.common.web.BaseController;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
@RestController
|
@RequestMapping("/agv")
|
public class AgvMapController extends BaseController {
|
|
@Autowired
|
private AgvLocMastService agvLocMastService;
|
@Autowired
|
private AgvLocDetlService agvLocDetlService;
|
@Autowired
|
private AgvBasMapService agvBasMapService;
|
@Autowired
|
private RedisUtil redisUtil;
|
|
private static final List<String> DISABLE_LOC_NO = new ArrayList<String>() {{
|
// add("0200101");
|
// add("0300101");
|
// add("0400101");
|
// add("0500101");
|
// add("0600101");
|
// add("0700101");
|
// add("0800101");
|
// add("0900101");
|
// add("1000101");
|
// add("1100101");
|
// add("1200101");
|
}};
|
|
@GetMapping("/map/getData/{floor}/{lev}/auth")
|
@ManagerAuth
|
public String getMapData(@PathVariable("floor") Integer floor, @PathVariable("lev") Integer lev) {
|
BasMap basMap = agvBasMapService.selectLatestMap(1,floor);
|
//解析json地图数据
|
List<ArrayList> arrayLists = JSON.parseArray(basMap.getData(), ArrayList.class);
|
|
|
//获取当前楼层库位数据
|
List<AgvLocMast> locMasts = agvLocMastService.selectLocByLevAndFloor(lev,floor);
|
for (AgvLocMast locMast : locMasts) {
|
Integer row = locMast.getRow1();
|
Integer bay = 34 - locMast.getBay1();
|
|
|
int x = bay;
|
int y = row;
|
////1楼
|
//if(floor == 1){
|
// x = generateMap1Row(row);
|
// y = generateMap1Bay(bay);
|
//}
|
////3楼
|
//if(floor == 3){
|
// y = generateMap3Row(row);
|
// x = generateMap3Bay(bay);
|
//}
|
|
ArrayList rowData = arrayLists.get(x);
|
Object o = rowData.get(y);
|
|
JSONObject jsonObject = JSON.parseObject(o.toString());
|
jsonObject.put("value","0");
|
|
jsonObject.put("locNo", locMast.getLocNo());//设置库位号
|
jsonObject.put("locSts", locMast.getLocSts());//库位状态
|
//更新list
|
rowData.set(y, jsonObject);
|
arrayLists.set(x, rowData);
|
}
|
|
return JSONObject.toJSONString(arrayLists);
|
}
|
|
private Integer generateMap1Row(int row){
|
int x = 21-row;
|
if(row > 1){
|
x --;
|
}
|
if(row > 3){
|
x --;
|
}
|
if(row > 5){
|
x --;
|
}
|
if(row > 7){
|
x --;
|
}
|
if(row > 9){
|
x --;
|
}
|
if(row > 10){
|
x --;
|
}
|
if(row > 12){
|
x --;
|
}
|
return x;
|
|
}
|
|
private Integer generateMap1Bay(int bay){
|
int y = bay;
|
if(y > 28){
|
y ++;
|
}
|
if(y > 57){
|
y ++;
|
}
|
return y;
|
}
|
|
private Integer generateMap3Row(int row){
|
int x = row;
|
Integer[] rowAdd = {2,4,6,7,8,10,12,13,15,17,19,21,23,24,26,28,30,32};
|
for(int i=0; i<rowAdd.length; i++){
|
if(row >= rowAdd[i]){
|
x ++;
|
}
|
}
|
return x;
|
}
|
|
private Integer generateMap3Bay(int bay){
|
int y = 76-bay;
|
if(bay >= 18) y --;
|
if(bay >= 26) y --;
|
if(bay >= 50) y --;
|
return y;
|
}
|
|
@RequestMapping("/map/searchData/auth")
|
@ManagerAuth
|
public R searchLoc(@RequestParam("lev") Integer lev,
|
@RequestParam("locNo") String locNo,
|
@RequestParam("orderNo") String orderNo,
|
@RequestParam("specs") String specs,
|
@RequestParam("matnr") String matnr,
|
@RequestParam("maktx") String maktx
|
) {
|
|
List<AgvLocDetl> locDetls = agvLocDetlService.searchByLike(orderNo, matnr, maktx, specs, locNo);
|
ArrayList<AgvLocDetl> lists = new ArrayList<>();
|
for (AgvLocDetl locDetl : locDetls) {//过滤掉不是当前楼层的数据
|
int lev1 = Utils.getAgvLev(locDetl.getLocNo());
|
if (lev1 == lev) {
|
lists.add(locDetl);
|
}
|
}
|
|
//搜索指定库位号,即使库位为空,也可以返回数据
|
AgvLocMast locMast = agvLocMastService.selectById(locNo);
|
if (locMast != null) {
|
AgvLocDetl locDetl = new AgvLocDetl();
|
locDetl.setLocNo(locMast.getLocNo());
|
lists.add(locDetl);
|
}
|
return R.ok().add(lists);
|
}
|
|
/*
|
@GetMapping("/map/realtime/getData/{lev}/auth")
|
@ManagerAuth
|
public String getRealtimeMapData(@PathVariable("lev") Integer lev) {
|
BasMap basMap = basMapService.selectLatestMap(lev);
|
//解析json地图数据
|
List<ArrayList> arrayLists = JSON.parseArray(basMap.getData(), ArrayList.class);
|
// ArrayList<HashMap<String, Integer>> lineRows = new ArrayList<>();
|
// int dataRow = 0;
|
// int dataRowCount = 0;
|
// for (int i = 1; i < arrayLists.size(); i++) {
|
// boolean flag = true;
|
// ArrayList rows = arrayLists.get(i);
|
// for (int j = 1; j < rows.size() - 1; j++) {
|
// Object o = rows.get(j);
|
// JSONObject jsonObject = JSON.parseObject(o.toString());
|
// int value = Integer.parseInt(jsonObject.get("value").toString());
|
// if (value >= 0 && value != 3) {
|
// //只有该行中的任一一列有数据,则不需要创建空白行
|
// flag = false;
|
// }
|
// }
|
//
|
// if (flag) {
|
// //空白行需要跳过
|
// HashMap<String, Integer> map = new HashMap<>();
|
// map.put("start", dataRow);
|
// int end = i - 1 - dataRowCount;
|
// map.put("end", end);
|
// map.put("count", dataRowCount);
|
// dataRow = end;
|
// dataRowCount++;
|
// lineRows.add(map);
|
// }
|
// }
|
|
//获取当前楼层库位数据
|
List<LocMast> locMasts = locMastService.selectLocByLev(lev);
|
for (LocMast locMast : locMasts) {
|
Integer row = locMast.getRow1();
|
Integer bay = locMast.getBay1();
|
// for (HashMap<String, Integer> lineRow : lineRows) {
|
// if (row > lineRow.get("start") && row <= lineRow.get("end")) {
|
// row += lineRow.get("count");
|
// break;
|
// }
|
// }
|
|
ArrayList rowData = arrayLists.get(row);
|
Object o = rowData.get(bay);
|
JSONObject jsonObject = JSON.parseObject(o.toString());
|
if (DISABLE_LOC_NO.contains(locMast.getLocNo())) {
|
//禁止库位
|
jsonObject.put("value", 10);//将禁用库位进行设置
|
}
|
jsonObject.put("locNo", locMast.getLocNo());//设置库位号
|
jsonObject.put("locSts", locMast.getLocSts());//库位状态
|
//更新list
|
rowData.set(bay, jsonObject);
|
arrayLists.set(row, rowData);
|
}
|
|
return JSONObject.toJSONString(arrayLists);
|
} */
|
|
// @GetMapping("/map/resetMap/{lev}/auth")
|
// @ManagerAuth
|
// public R resetMap(@PathVariable("lev") Integer lev) {
|
// Object o = redisUtil.get("realtimeBasMap_" + lev);
|
// if (o == null) {
|
// return R.error();
|
// }
|
// redisUtil.del("realtimeBasMap_" + lev);
|
// basMapService.deleteByLev(lev);
|
// return R.ok();
|
// }
|
|
}
|