|  |  |  | 
|---|
|  |  |  | import com.core.common.SpringUtils; | 
|---|
|  |  |  | import com.zy.asrs.entity.BasMap; | 
|---|
|  |  |  | import com.zy.asrs.entity.LocMast; | 
|---|
|  |  |  | import com.zy.asrs.service.BasMapService; | 
|---|
|  |  |  | import com.zy.asrs.service.LocMastService; | 
|---|
|  |  |  | import com.zy.asrs.utils.Utils; | 
|---|
|  |  |  | import com.zy.common.model.MapNode; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.zy.core.properties.SlaveProperties; | 
|---|
|  |  |  | import com.zy.core.thread.ForkLiftThread; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.core.io.ClassPathResource; | 
|---|
|  |  |  | import org.springframework.stereotype.Component; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.io.*; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SlaveProperties slaveProperties; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private BasMapService basMapService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public int[][] getData(Integer lev, Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | //            RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class); | 
|---|
|  |  |  | //            Object object = redisUtil.get(RedisKeyType.BASIC_MAP.key + lev); | 
|---|
|  |  |  | //            if (object == null) { | 
|---|
|  |  |  | //                return null; | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //            //解析json地图数据 | 
|---|
|  |  |  | //            ArrayList arrayList = JSON.parseObject(object.toString(), ArrayList.class); | 
|---|
|  |  |  | //            List<List<MapNode>> lists = filterMap(mapType, arrayList, lev, whitePoints, shuttlePoints);//过滤地图数据 | 
|---|
|  |  |  | //            int[][] map = new int[lists.size()][]; | 
|---|
|  |  |  | //            int j = 0; | 
|---|
|  |  |  | //            for (List<MapNode> list : lists) { | 
|---|
|  |  |  | //                int[] tmp = new int[list.size()]; | 
|---|
|  |  |  | //                int i = 0; | 
|---|
|  |  |  | //                for (MapNode mapNode : list) { | 
|---|
|  |  |  | //                    //将数据添加进二维数组 | 
|---|
|  |  |  | //                    tmp[i++] = mapNode.getValue(); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //                //数据添加进一维数组 | 
|---|
|  |  |  | //                map[j++] = tmp; | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //            return map; | 
|---|
|  |  |  | BasMap basMap = basMapService.selectLatestMap(lev); | 
|---|
|  |  |  | String originData = basMap.getOriginData(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String mapFilename = "map_" + lev + ".json"; | 
|---|
|  |  |  | ClassPathResource classPathResource = new ClassPathResource(mapFilename); | 
|---|
|  |  |  | InputStream inputStream = classPathResource.getInputStream(); | 
|---|
|  |  |  | byte[] buffer = new byte[inputStream.available()]; | 
|---|
|  |  |  | inputStream.read(buffer); | 
|---|
|  |  |  | File file = File.createTempFile("prefix", "suffix"); | 
|---|
|  |  |  | try (OutputStream outStream = new FileOutputStream(file)) { | 
|---|
|  |  |  | outStream.write(buffer); | 
|---|
|  |  |  | //解析json地图数据 | 
|---|
|  |  |  | ArrayList arrayList = JSON.parseObject(originData, ArrayList.class); | 
|---|
|  |  |  | List<List<MapNode>> lists = filterMap(mapType, arrayList, lev, whitePoints, shuttlePoints);//过滤地图数据 | 
|---|
|  |  |  | int[][] map = new int[lists.size()][]; | 
|---|
|  |  |  | int j = 0; | 
|---|
|  |  |  | for (List<MapNode> list : lists) { | 
|---|
|  |  |  | int[] tmp = new int[list.size()]; | 
|---|
|  |  |  | int i = 0; | 
|---|
|  |  |  | for (MapNode mapNode : list) { | 
|---|
|  |  |  | //将数据添加进二维数组 | 
|---|
|  |  |  | tmp[i++] = mapNode.getValue(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //数据添加进一维数组 | 
|---|
|  |  |  | map[j++] = tmp; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //解析json地图数据 | 
|---|
|  |  |  | ArrayList arrayList = JSON.parseObject(stringBuffer.toString(), ArrayList.class); | 
|---|
|  |  |  | List<List<MapNode>> lists = filterMap(mapType, arrayList, lev, whitePoints, shuttlePoints);//过滤地图数据 | 
|---|
|  |  |  | int[][] map = new int[lists.size()][]; | 
|---|
|  |  |  | int j = 0; | 
|---|
|  |  |  | for (List<MapNode> list : lists) { | 
|---|
|  |  |  | int[] tmp = new int[list.size()]; | 
|---|
|  |  |  | int i = 0; | 
|---|
|  |  |  | for (MapNode mapNode : list) { | 
|---|
|  |  |  | //将数据添加进二维数组 | 
|---|
|  |  |  | tmp[i++] = mapNode.getValue(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //数据添加进一维数组 | 
|---|
|  |  |  | map[j++] = tmp; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!file.delete()) { | 
|---|
|  |  |  | System.out.println("临时文件删除失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return map; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | System.out.println("文件不存在!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return map; | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | return map; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //    //获取JSON格式数据 | 
|---|
|  |  |  | //    public List<List<MapNode>> getJsonData(Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) { | 
|---|
|  |  |  | //        try { | 
|---|
|  |  |  | ////            RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class); | 
|---|
|  |  |  | ////            Object object = redisUtil.get(RedisKeyType.BASIC_MAP.key + lev); | 
|---|
|  |  |  | ////            if (object == null) { | 
|---|
|  |  |  | ////                return null; | 
|---|
|  |  |  | ////            } | 
|---|
|  |  |  | //// | 
|---|
|  |  |  | ////            //解析json地图数据 | 
|---|
|  |  |  | ////            ArrayList arrayList = JSON.parseObject(object.toString(), ArrayList.class); | 
|---|
|  |  |  | ////            List<List<MapNode>> lists = filterMap(mapType, arrayList, lev, whitePoints, shuttlePoints);//过滤地图数据 | 
|---|
|  |  |  | ////            return lists; | 
|---|
|  |  |  | // | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //            String mapFilename = "map_" + lev + ".json"; | 
|---|
|  |  |  | //            ClassPathResource classPathResource = new ClassPathResource(mapFilename); | 
|---|
|  |  |  | //            InputStream inputStream = classPathResource.getInputStream(); | 
|---|
|  |  |  | //            byte[] buffer = new byte[inputStream.available()]; | 
|---|
|  |  |  | //            inputStream.read(buffer); | 
|---|
|  |  |  | //            File file = File.createTempFile("prefix","suffix"); | 
|---|
|  |  |  | //            try (OutputStream outStream = new FileOutputStream(file)) { | 
|---|
|  |  |  | //                outStream.write(buffer); | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //            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(); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                //解析json地图数据 | 
|---|
|  |  |  | //                ArrayList arrayList = JSON.parseObject(stringBuffer.toString(), ArrayList.class); | 
|---|
|  |  |  | //                List<List<MapNode>> lists = filterMap(mapType, arrayList, lev, whitePoints, shuttlePoints);//过滤地图数据 | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                if (!file.delete()) { | 
|---|
|  |  |  | //                    System.out.println("临时文件删除失败"); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                return lists; | 
|---|
|  |  |  | //            } else { | 
|---|
|  |  |  | //                System.out.println("文件不存在!"); | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //        } catch (Exception e) { | 
|---|
|  |  |  | //            e.printStackTrace(); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        return null; | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取JSON格式数据 | 
|---|
|  |  |  | public List<List<MapNode>> getJsonData(Integer lev, Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | //            RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class); | 
|---|
|  |  |  | //            Object object = redisUtil.get(RedisKeyType.BASIC_MAP.key + lev); | 
|---|
|  |  |  | //            if (object == null) { | 
|---|
|  |  |  | //                return null; | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //            //解析json地图数据 | 
|---|
|  |  |  | //            ArrayList arrayList = JSON.parseObject(object.toString(), ArrayList.class); | 
|---|
|  |  |  | //            List<List<MapNode>> lists = filterMap(mapType, arrayList, lev, whitePoints, shuttlePoints);//过滤地图数据 | 
|---|
|  |  |  | //            return lists; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String mapFilename = "map_" + lev + ".json"; | 
|---|
|  |  |  | ClassPathResource classPathResource = new ClassPathResource(mapFilename); | 
|---|
|  |  |  | InputStream inputStream = classPathResource.getInputStream(); | 
|---|
|  |  |  | byte[] buffer = new byte[inputStream.available()]; | 
|---|
|  |  |  | inputStream.read(buffer); | 
|---|
|  |  |  | File file = File.createTempFile("prefix","suffix"); | 
|---|
|  |  |  | try (OutputStream outStream = new FileOutputStream(file)) { | 
|---|
|  |  |  | outStream.write(buffer); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //解析json地图数据 | 
|---|
|  |  |  | ArrayList arrayList = JSON.parseObject(stringBuffer.toString(), ArrayList.class); | 
|---|
|  |  |  | //重建数据格式 | 
|---|
|  |  |  | List<List<MapNode>> lists = rebuildData(arrayList); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!file.delete()) { | 
|---|
|  |  |  | System.out.println("临时文件删除失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return lists; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | System.out.println("文件不存在!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | BasMap basMap = basMapService.selectLatestMap(lev); | 
|---|
|  |  |  | String originData = basMap.getOriginData(); | 
|---|
|  |  |  | //解析json地图数据 | 
|---|
|  |  |  | ArrayList arrayList = JSON.parseObject(originData, ArrayList.class); | 
|---|
|  |  |  | //重建数据格式 | 
|---|
|  |  |  | List<List<MapNode>> lists = rebuildData(arrayList); | 
|---|
|  |  |  | return lists; | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | //加载车辆 | 
|---|
|  |  |  | lists = loadShuttle(lists, shuttlePoints); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //加载货叉提升机点位 | 
|---|
|  |  |  | lists = loadForkLift(lists, mapType, lev); | 
|---|
|  |  |  | //        //加载货叉提升机点位 | 
|---|
|  |  |  | //        lists = loadForkLift(lists, mapType, lev); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //加载白名单节点 | 
|---|
|  |  |  | lists = loadWhite(lists, lev, whitePoints); | 
|---|