|  |  |  | 
|---|
|  |  |  | import com.zy.asrs.entity.LocMast; | 
|---|
|  |  |  | import com.zy.asrs.service.LocDetlService; | 
|---|
|  |  |  | import com.zy.asrs.service.LocMastService; | 
|---|
|  |  |  | import com.zy.asrs.utils.LocMapConstants; | 
|---|
|  |  |  | import com.zy.asrs.utils.Utils; | 
|---|
|  |  |  | import com.zy.common.web.BaseController; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.GetMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestParam; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RestController; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.io.*; | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LocDetlService locDetlService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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/{lev}/auth") | 
|---|
|  |  |  | @GetMapping("/map/getData/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public String getMapData(@PathVariable("lev") Integer lev) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | String mapFilename = "map.json"; | 
|---|
|  |  |  | String fileName = Objects.requireNonNull(this.getClass().getClassLoader().getResource(mapFilename)).getPath();//获取文件路径 | 
|---|
|  |  |  | File file = new File(fileName); | 
|---|
|  |  |  | StringBuffer stringBuffer = new StringBuffer(); | 
|---|
|  |  |  | if (file.isFile() && file.exists()) { | 
|---|
|  |  |  | InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "GBK"); | 
|---|
|  |  |  | BufferedReader br = new BufferedReader(isr); | 
|---|
|  |  |  | String lineTxt = null; | 
|---|
|  |  |  | while ((lineTxt = br.readLine()) != null) { | 
|---|
|  |  |  | stringBuffer.append(lineTxt); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | br.close(); | 
|---|
|  |  |  | public String getMapData(@RequestParam String area, @RequestParam Integer lev) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //解析json地图数据 | 
|---|
|  |  |  | List<ArrayList> arrayLists = JSON.parseArray(stringBuffer.toString(), ArrayList.class); | 
|---|
|  |  |  | for (String locNo : DISABLE_LOC_NO) {//禁用设置库位 | 
|---|
|  |  |  | int row = Utils.getRow(locNo); | 
|---|
|  |  |  | int bay = Utils.getBay(locNo); | 
|---|
|  |  |  | if (row >= 2 && row <= 12) { | 
|---|
|  |  |  | row++; | 
|---|
|  |  |  | }else if (row == 13) { | 
|---|
|  |  |  | row += 2; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ArrayList rowData = arrayLists.get(row); | 
|---|
|  |  |  | Object o = rowData.get(bay); | 
|---|
|  |  |  | JSONObject jsonObject = JSON.parseObject(o.toString()); | 
|---|
|  |  |  | jsonObject.put("value", 10);//将禁用库位进行设置 | 
|---|
|  |  |  | //更新list | 
|---|
|  |  |  | rowData.set(bay, jsonObject); | 
|---|
|  |  |  | arrayLists.set(row, rowData); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //获取当前楼层库位数据 | 
|---|
|  |  |  | List<LocMast> locMasts = locMastService.selectNodeLocByLev(area, lev); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取当前楼层库位数据 | 
|---|
|  |  |  | List<LocMast> locMasts = locMastService.selectLocByLev(lev); | 
|---|
|  |  |  | for (LocMast locMast : locMasts) { | 
|---|
|  |  |  | Integer row = locMast.getRow1(); | 
|---|
|  |  |  | Integer bay = locMast.getBay1(); | 
|---|
|  |  |  | if (row >= 2 && row <= 12) { | 
|---|
|  |  |  | row++; | 
|---|
|  |  |  | }else if (row == 13) { | 
|---|
|  |  |  | row += 2; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ArrayList rowData = arrayLists.get(row); | 
|---|
|  |  |  | Object o = rowData.get(bay); | 
|---|
|  |  |  | JSONObject jsonObject = JSON.parseObject(o.toString()); | 
|---|
|  |  |  | jsonObject.put("locNo", locMast.getLocNo());//设置库位号 | 
|---|
|  |  |  | jsonObject.put("locSts", locMast.getLocSts());//库位状态 | 
|---|
|  |  |  | jsonObject.put("locSts$", locMast.getLocSts$());//库位状态 | 
|---|
|  |  |  | //更新list | 
|---|
|  |  |  | rowData.set(bay, jsonObject); | 
|---|
|  |  |  | arrayLists.set(row, rowData); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return JSONObject.toJSONString(arrayLists); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | System.out.println("文件不存在!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (IOException ioException) { | 
|---|
|  |  |  | ioException.printStackTrace(); | 
|---|
|  |  |  | // 加载库区对应地图数据 | 
|---|
|  |  |  | List<ArrayList> arrayLists; | 
|---|
|  |  |  | switch (area) { | 
|---|
|  |  |  | case "B": | 
|---|
|  |  |  | arrayLists = LocMapConstants.B_LOC_MAP_FINAL; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case "C": | 
|---|
|  |  |  | arrayLists = LocMapConstants.C_LOC_MAP_FINAL; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case "D": | 
|---|
|  |  |  | arrayLists = LocMapConstants.D_LOC_MAP_FINAL; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case "E": | 
|---|
|  |  |  | arrayLists = LocMapConstants.E_LOC_MAP_FINAL; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | default: | 
|---|
|  |  |  | arrayLists = LocMapConstants.A_LOC_MAP_FINAL; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 除A库区外,其他区没有层,而且把列存到了层的数据里,需要转换回来 | 
|---|
|  |  |  | if (!"A".equals(area)) { | 
|---|
|  |  |  | locMasts = locMasts.stream().peek(locMast -> locMast.setBay1(locMast.getLev1())).collect(Collectors.toList()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (LocMast locMast : locMasts) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer row = locMast.getRow1(); | 
|---|
|  |  |  | Integer bay = locMast.getBay1(); | 
|---|
|  |  |  | // CDE只有一列,所以列右移 | 
|---|
|  |  |  | if ("C".equals(area) || "D".equals(area) || "E".equals(area)) { | 
|---|
|  |  |  | ++ bay ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ArrayList rowData = arrayLists.get(row); | 
|---|
|  |  |  | Object o = rowData.get(bay); | 
|---|
|  |  |  | JSONObject jsonObject = JSON.parseObject(o.toString()); | 
|---|
|  |  |  | jsonObject.put("locNo", locMast.getLocNo());//设置库位号 | 
|---|
|  |  |  | jsonObject.put("locSts", locMast.getLocSts());//库位状态 | 
|---|
|  |  |  | //更新list | 
|---|
|  |  |  | rowData.set(bay, jsonObject); | 
|---|
|  |  |  | arrayLists.set(row, rowData); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return JSONObject.toJSONString(arrayLists); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping("/map/searchData/auth") | 
|---|
|  |  |  | 
|---|
|  |  |  | @RequestParam("specs") String specs, | 
|---|
|  |  |  | @RequestParam("matnr") String matnr, | 
|---|
|  |  |  | @RequestParam("maktx") String maktx | 
|---|
|  |  |  | ) { | 
|---|
|  |  |  | List<LocDetl> locDetls = locDetlService.searchByLike(orderNo, matnr, maktx, specs, locNo); | 
|---|
|  |  |  | ) { | 
|---|
|  |  |  | List<LocDetl> locDetls = locDetlService.searchByLike(orderNo, matnr, maktx, specs, ""); | 
|---|
|  |  |  | ArrayList<LocDetl> lists = new ArrayList<>(); | 
|---|
|  |  |  | for (LocDetl locDetl : locDetls) {//过滤掉不是当前楼层的数据 | 
|---|
|  |  |  | int lev1 = Utils.getLev(locDetl.getLocNo()); | 
|---|
|  |  |  | 
|---|
|  |  |  | lists.add(locDetl); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //搜索指定库位号,即使库位为空,也可以返回数据 | 
|---|
|  |  |  | LocMast locMast = locMastService.selectById(locNo); | 
|---|
|  |  |  | if (locMast != null) { | 
|---|
|  |  |  | LocDetl locDetl = new LocDetl(); | 
|---|
|  |  |  | locDetl.setLocNo(locMast.getLocNo()); | 
|---|
|  |  |  | lists.add(locDetl); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok().add(lists); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|