| package com.zy.asrs.common.utils; | 
|   | 
| import com.alibaba.fastjson.JSON; | 
| import com.alibaba.fastjson.serializer.SerializerFeature; | 
| import com.zy.asrs.common.wms.service.LocDirectionService; | 
| import com.zy.asrs.framework.common.Cools; | 
| import com.zy.asrs.framework.common.SpringUtils; | 
|   | 
| import java.security.SecureRandom; | 
| import java.text.DecimalFormat; | 
| import java.util.ArrayList; | 
| import java.util.Base64; | 
| import java.util.LinkedHashMap; | 
| import java.util.List; | 
|   | 
| /** | 
|  * Created by vincent on 2020/8/27 | 
|  */ | 
| public class Utils { | 
|   | 
|     private static final DecimalFormat fmt = new DecimalFormat("##0.00"); | 
|   | 
|     public static String zerofill(String msg, Integer count){ | 
|         if (msg.length() == count){ | 
|             return msg; | 
|         } else if (msg.length() > count){ | 
|             return msg.substring(0, 16); | 
|         } else { | 
|             StringBuilder msgBuilder = new StringBuilder(msg); | 
|             for (int i = 0; i<count-msg.length(); i++){ | 
|                 msgBuilder.insert(0,"0"); | 
|             } | 
|             return msgBuilder.toString(); | 
|         } | 
|     } | 
|   | 
|     /** | 
|      * 通过库位号获取 排 | 
|      */ | 
|     public static int getRow(String locNo) { | 
|         if (!Cools.isEmpty(locNo)) { | 
|             return Integer.parseInt(locNo.substring(0, 2)); | 
|         } | 
|         throw new RuntimeException("库位解析异常"); | 
|     } | 
|   | 
|     /** | 
|      * 通过库位号获取 列 | 
|      */ | 
|     public static int getBay(String locNo) { | 
|         if (!Cools.isEmpty(locNo)) { | 
|             return Integer.parseInt(locNo.substring(2, 5)); | 
|         } | 
|         throw new RuntimeException("库位解析异常"); | 
|     } | 
|   | 
|     /** | 
|      * 通过库位号获取 层 | 
|      */ | 
|     public static int getLev(String locNo) { | 
|         if (!Cools.isEmpty(locNo)) { | 
|             return Integer.parseInt(locNo.substring(5, 7)); | 
|         } | 
|         throw new RuntimeException("库位解析异常"); | 
|     } | 
|   | 
|     /** | 
|      * 生成随机字符串 | 
|      */ | 
|     public static String generateString(int length) { | 
|         String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; // 可选的字符集合 | 
|         SecureRandom random = new SecureRandom(); | 
|         StringBuilder sb = new StringBuilder(length); | 
|         for (int i = 0; i < length; i++) { | 
|             int index = random.nextInt(characters.length()); | 
|             char randomChar = characters.charAt(index); | 
|             sb.append(randomChar); | 
|         } | 
|         return sb.toString(); | 
|     } | 
|   | 
|     /** | 
|      * 获取库位组 | 
|      */ | 
|     public static List<String> getGroupLoc(String locNo, Long hostId) { | 
|         int row = getRow(locNo); | 
|         List<String> result = new ArrayList<>(); | 
|         LocDirectionService locDirectionService = SpringUtils.getBean(LocDirectionService.class); | 
|         List<ArrayList<Integer>> naturalList = locDirectionService.getNaturalList(hostId); | 
|         for (ArrayList<Integer> list : naturalList) { | 
|             if (list.contains(row)) { | 
|                 for (Integer row0 : list) { | 
|                     result.add(zerofill(String.valueOf(row0), 2) + locNo.substring(2)); | 
|                 } | 
|                 return result; | 
|             } | 
|         } | 
|   | 
|         return result; | 
|     } | 
|   | 
|     /** | 
|      * 获取外侧方向的库位组 | 
|      */ | 
|     public static List<String> getGroupOuterLoc(String locNo, Long hostId) { | 
|         int row = getRow(locNo); | 
|         List<String> result = new ArrayList<>(); | 
|         LocDirectionService locDirectionService = SpringUtils.getBean(LocDirectionService.class); | 
|         List<ArrayList<Integer>> outerList = locDirectionService.getOuterList(hostId); | 
|         for (ArrayList<Integer> list : outerList) { | 
|             if (list.contains(row)) { | 
|                 for (Integer row0 : list) { | 
|                     if (row0 == row) { | 
|                         break; | 
|                     } | 
|                     result.add(zerofill(String.valueOf(row0), 2) + locNo.substring(2)); | 
|                 } | 
|                 return result; | 
|             } | 
|         } | 
|   | 
|         return result; | 
|     } | 
|   | 
|     /** | 
|      * 获取内侧方向的库位组 | 
|      */ | 
|     public static List<String> getGroupInnerLoc(String locNo, Long hostId) { | 
|         int row = getRow(locNo); | 
|         List<String> result = new ArrayList<>(); | 
|         LocDirectionService locDirectionService = SpringUtils.getBean(LocDirectionService.class); | 
|         List<ArrayList<Integer>> innerList = locDirectionService.getInnerList(hostId); | 
|         for (ArrayList<Integer> list : innerList) { | 
|             if (list.contains(row)) { | 
|                 for (Integer row0 : list) { | 
|                     if (row0 == row) { | 
|                         break; | 
|                     } | 
|                     result.add(zerofill(String.valueOf(row0), 2) + locNo.substring(2)); | 
|                 } | 
|                 return result; | 
|             } | 
|         } | 
|   | 
|         return result; | 
|     } | 
|   | 
|     //念初ERP数据加密算法 | 
|     public static String ncErpDataEncode(LinkedHashMap<String, Object> param) { | 
|         String jsonString = JSON.toJSONString(param, SerializerFeature.DisableCircularReferenceDetect); | 
|         jsonString += "Digi"; | 
|   | 
|         String baseCode = Base64.getEncoder().encodeToString(jsonString.getBytes()); | 
|         String encode = baseCode.replace("/", "{-----------------------------}"); | 
|         return encode; | 
|     } | 
|   | 
| } |