| package com.zy.asrs.wms.controller; | 
|   | 
| import com.alibaba.fastjson.JSON; | 
| import com.alibaba.fastjson.JSONObject; | 
| import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
| import com.zy.asrs.common.utils.Utils; | 
| import com.zy.asrs.common.web.BaseController; | 
| import com.zy.asrs.common.wms.entity.BasMap; | 
| import com.zy.asrs.common.wms.entity.LocDetl; | 
| import com.zy.asrs.common.wms.entity.LocMast; | 
| import com.zy.asrs.common.wms.service.BasMapService; | 
| import com.zy.asrs.common.wms.service.LocDetlService; | 
| import com.zy.asrs.common.wms.service.LocMastService; | 
| import com.zy.asrs.framework.annotations.ManagerAuth; | 
| import com.zy.asrs.framework.common.Cools; | 
| import com.zy.asrs.framework.common.R; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.web.bind.annotation.*; | 
|   | 
| import java.io.*; | 
| import java.util.ArrayList; | 
| import java.util.HashMap; | 
| import java.util.List; | 
|   | 
| @RestController | 
|   | 
| public class MapController extends BaseController { | 
|   | 
|     @Autowired | 
|     private LocMastService locMastService; | 
|     @Autowired | 
|     private LocDetlService locDetlService; | 
|     @Autowired | 
|     private BasMapService basMapService; | 
|   | 
|     private static final List<String> DISABLE_LOC_NO = new ArrayList<String>() {{ | 
| //        add("0200101"); | 
|     }}; | 
|   | 
|     @GetMapping("/map/getData/{lev}/auth") | 
|     @ManagerAuth | 
|     public String getMapData(@PathVariable("lev") Integer lev) { | 
|         BasMap basMap = basMapService.getOne(new LambdaQueryWrapper<BasMap>().eq(BasMap::getLev, lev).eq(BasMap::getHostId, getHostId())); | 
|         //解析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.list(new LambdaQueryWrapper<LocMast>().eq(LocMast::getLev1, lev).eq(LocMast::getHostId, getHostId())); | 
|         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());//库位状态 | 
|   | 
|             jsonObject.put("lockLocMast", locMast.getLocType3$()); | 
|             jsonObject.put("batch", "");//批号 | 
|             jsonObject.put("barcode", "");//条码号 | 
|             if (locMast.getLocSts().equals("F") || locMast.getLocSts().equals("R")) { | 
|                 List<LocDetl> locDetls = locDetlService.list(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getLocNo, locMast.getLocNo()).eq(LocDetl::getHostId, getHostId())); | 
|                 if (!locDetls.isEmpty()) { | 
|                     LocDetl locDetl = locDetls.get(0); | 
|                     jsonObject.put("batch", locDetl.getBatch());//批号 | 
|                     jsonObject.put("barcode", locDetl.getBarcode());//条码号 | 
|                 } | 
|             } | 
|   | 
|             //更新list | 
|             rowData.set(bay, jsonObject); | 
|             arrayLists.set(row, rowData); | 
|         } | 
|   | 
|         return JSONObject.toJSONString(arrayLists); | 
|     } | 
|   | 
|     @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 | 
|                        ) { | 
|         LambdaQueryWrapper<LocDetl> wrapper = new LambdaQueryWrapper<>(); | 
|         if (!Cools.isEmpty(orderNo)) { | 
|             wrapper.like(LocDetl::getOrderNo, orderNo); | 
|         } | 
|         if (!Cools.isEmpty(matnr)) { | 
|             wrapper.like(LocDetl::getMatnr, matnr); | 
|         } | 
|         if (!Cools.isEmpty(maktx)) { | 
|             wrapper.like(LocDetl::getMaktx, maktx); | 
|         } | 
|         if (!Cools.isEmpty(specs)) { | 
|             wrapper.like(LocDetl::getSpecs, specs); | 
|         } | 
|         List<LocDetl> locDetls = locDetlService.list(wrapper); | 
|         ArrayList<LocDetl> lists = new ArrayList<>(); | 
|         for (LocDetl locDetl : locDetls) {//过滤掉不是当前楼层的数据 | 
|             int lev1 = Utils.getLev(locDetl.getLocNo()); | 
|             if (lev1 == lev) { | 
|                 lists.add(locDetl); | 
|             } | 
|         } | 
|   | 
|         //搜索指定库位号,即使库位为空,也可以返回数据 | 
|         LocMast locMast = locMastService.getOne(new LambdaQueryWrapper<LocMast>().eq(LocMast::getLocNo, locNo).eq(LocMast::getHostId, getHostId())); | 
|         if (locMast != null) { | 
|             LocDetl locDetl = new LocDetl(); | 
|             locDetl.setLocNo(locMast.getLocNo()); | 
|             lists.add(locDetl); | 
|         } | 
|         return R.ok().add(lists); | 
|     } | 
|   | 
| } |