浏览代码

Lora188Parser和修改安装模板

lin 4 年之前
父节点
当前提交
e38938dd3a

+ 2 - 2
smart-city-platform/src/main/java/com/bz/smart_city/async/AsyncInstallPlanDownloadTask.java

@@ -185,7 +185,7 @@ public class AsyncInstallPlanDownloadTask {
                 }
             }
 
-            InputStream in = this.getClass().getClassLoader().getResourceAsStream("excel/installPlanTemplate20200716.xlsx");   //得到文档的路径
+            InputStream in = this.getClass().getClassLoader().getResourceAsStream("excel/installPlanTemplate20200731.xlsx");   //得到文档的路径
 
             //列表数据将存储到指定的excel文件路径
             FileOutputStream out = new FileOutputStream(filePath);
@@ -243,7 +243,7 @@ public class AsyncInstallPlanDownloadTask {
             //5、获取安装计划清单数据
 
 
-            InputStream in = this.getClass().getClassLoader().getResourceAsStream("excel/installPlanTemplate20200716.xlsx");   //得到文档的路径
+            InputStream in = this.getClass().getClassLoader().getResourceAsStream("excel/installPlanTemplate20200731.xlsx");   //得到文档的路径
 
             //列表数据将存储到指定的excel文件路径
             FileOutputStream out = new FileOutputStream(filePath);

+ 2 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dao/CustomerMapper.java

@@ -53,4 +53,6 @@ public interface CustomerMapper {
     List<Integer> findAllSubIds(@Param("customerId") Integer customerId);
 
     List<Integer> findAllIds(@Param("customerId") Integer customerId);
+
+    Customer findByName(@Param("siteId") Integer siteId, @Param("name") String name);
 }

+ 2 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/BuildingService.java

@@ -86,4 +86,6 @@ public interface BuildingService{
     List<BuildingSelectDto> abnormalAreaBuildingList(Integer sysId, Integer buildingId, Integer floor, Integer measuringId, Long deviceId, String deviceNo, String location, Integer alarmCategory, Integer handleStatus, Integer alarmTypeId, Integer equipmentId, Integer manufacturerId, Integer customerId, Integer province, Integer city, Integer region, Integer communityId, LocalDateTime startDate, LocalDateTime endDate);
 
     List<BuildingSelectDto> installAreaList(String deviceNo, Integer status, String errorType, Integer customerId, Integer province, Integer city, Integer region, Integer community, Integer buildingId, String locDesc, Integer deviceTypeId, Integer registerStatus, LocalDateTime startDate, LocalDateTime endDate);
+
+    Building findCacheByName(Integer siteId, String name);
 }

+ 2 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/CommunityService.java

@@ -49,4 +49,6 @@ public interface CommunityService {
     List<Community> getMaxCodeBySiteId(Integer siteId);
 
     Community findByNameV2(Integer siteId, Integer province, Integer city, Integer region, String communityName);
+
+    Community findCacheByName(Integer siteId, String communityName);
 }

+ 7 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/BuildingServiceImpl.java

@@ -19,6 +19,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.cache.annotation.Caching;
 import org.springframework.stereotype.Service;
 
@@ -1324,6 +1325,12 @@ public class BuildingServiceImpl implements BuildingService {
         return 0;
     }
 
+    @Override
+    @Cacheable(value = "CacheBuilding", key = "#siteId + #name")
+    public Building findCacheByName(Integer siteId, String name) {
+        return buildingMapper.findByName(siteId,name);
+    }
+
     private String getFilePath() {
         String name = Util.createUUIDId();
         String fullPath = filesPath + "/" + name + ".xlsm";

+ 7 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/CommunityServiceImpl.java

@@ -13,6 +13,7 @@ import com.bz.smart_city.entity.Area;
 import com.bz.smart_city.entity.ProgramItem;
 import com.github.pagehelper.PageHelper;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 import javax.annotation.Resource;
 import java.time.LocalDateTime;
@@ -288,4 +289,10 @@ public class CommunityServiceImpl implements CommunityService{
     public Community findByNameV2(Integer siteId, Integer province, Integer city, Integer region, String communityName) {
         return communityMapper.findByNameV2(siteId,province,city,region,communityName);
     }
+
+    @Override
+    @Cacheable(value = "CacheCommunity", key = "#siteId + #communityName")
+    public Community findCacheByName(Integer siteId, String communityName) {
+        return communityMapper.findByName(siteId,communityName);
+    }
 }

+ 59 - 57
smart-city-platform/src/main/java/com/bz/smart_city/service/importfile/AsyncTaskImportService.java

@@ -60,6 +60,8 @@ public class AsyncTaskImportService {
     @Resource
     private BuildingMapper buildingMapper;
     @Autowired
+    private BuildingService buildingService;
+    @Autowired
     private InstallManagerService installManagerService;
     @Autowired
     private DeviceTypeService deviceTypeService;
@@ -140,20 +142,27 @@ public class AsyncTaskImportService {
                     }
                     invalidTemplate = true;
                     // 1,处理表头,解析客户、户数
-                    Row customerIdRow = hssfSheet.getRow(2); // 客户Id行
-                    Cell customerIdCell =  customerIdRow.getCell(7);
-                    if(customerIdCell == null ) {
+                    Row customerRow = hssfSheet.getRow(1); // 客户Id行
+                    Cell customerNameCell =  customerRow.getCell(5);
+                    customerNameCell.setCellType(CellType.STRING);
+                    if(StringUtils.equals("", customerNameCell.getStringCellValue().trim())) {
+                        messageContent.append("导入失败,");
+                        messageContent.append(ResultStatus.CUSTOMER_IS_NOT_EXISTED.getMessage());
+                        continue;
+                    }
+                    Customer customer = customerMapper.findByName(record.getSiteId(),customerNameCell.getStringCellValue().trim());
+                    if(customer!=null){
+                        dto.setCustomerId(customer.getId());
+
+                    }else {
                         messageContent.append("导入失败,");
                         messageContent.append(ResultStatus.CUSTOMER_IS_NOT_EXISTED.getMessage());
                         continue;
                     }
-                    CellValue customerIdCellValue = evaluator.evaluate(customerIdCell);
-                    Integer customerId =   (int) customerIdCellValue.getNumberValue();
-                    dto.setCustomerId(customerId);
 
 
-                    Row numberRow = hssfSheet.getRow(3); // 安装数字,只处理指定安装户数的数据
-                    Cell numberCell = numberRow.getCell(7);
+                    Row numberRow = hssfSheet.getRow(2); // 安装数字,只处理指定安装户数的数据
+                    Cell numberCell = numberRow.getCell(5);
 
                     numberCell.setCellType(CellType.NUMERIC);
                     int number = ((Double)numberCell.getNumericCellValue()).intValue();
@@ -164,27 +173,24 @@ public class AsyncTaskImportService {
                     }
 
                     // 2,处理明细行数据
-                    for (int rowNum = 9; rowNum < 9+number ; rowNum++) {
+                    for (int rowNum = 8; rowNum < 8+number ; rowNum++) {
                         Row row = hssfSheet.getRow(rowNum);
                         if (row != null) {
 
                             Cell idCell = row.getCell(1) ; // 编号
                             Cell communityCell = row.getCell(2);
-                            Cell communityIdCell = row.getCell(3);
-                            Cell buildingCell = row.getCell(4);
-                            Cell buildingIdCell = row.getCell(5);
-                            Cell doorNoCell = row.getCell(6);
-                            Cell deviceTypeCell = row.getCell(7);
-                            Cell deviceTypeIdCell = row.getCell(8);
-                            Cell electronicNoCell = row.getCell(9);
-                            Cell deviceNoCell = row.getCell(10);
-                            Cell fileNoCell = row.getCell(11);
-                            Cell newMeterStartCell = row.getCell(12);
-                            Cell oldMeterEndCell = row.getCell(13);
-                            Cell userNameCell = row.getCell(14);
-                            Cell userPhoneCell = row.getCell(15);
-                            Cell idCardCell = row.getCell(16);
-                            Cell remarkCell = row.getCell(17);
+                            Cell buildingCell = row.getCell(3);
+                            Cell doorNoCell = row.getCell(4);
+                            Cell deviceTypeCell = row.getCell(5);
+                            Cell electronicNoCell = row.getCell(6);
+                            Cell deviceNoCell = row.getCell(7);
+                            Cell fileNoCell = row.getCell(8);
+                            Cell newMeterStartCell = row.getCell(9);
+                            Cell oldMeterEndCell = row.getCell(10);
+                            Cell userNameCell = row.getCell(11);
+                            Cell userPhoneCell = row.getCell(12);
+                            Cell idCardCell = row.getCell(13);
+                            Cell remarkCell = row.getCell(14);
 
 
                             if(idCell !=null){
@@ -193,31 +199,33 @@ public class AsyncTaskImportService {
                             }
 
                             communityCell.setCellType(CellType.STRING);
-                            if (StringUtils.equals("", communityCell.getStringCellValue())) {
+                            if (StringUtils.equals("", communityCell.getStringCellValue().trim())) {
                                 continue;
                             }
-                            if (communityIdCell != null) {
-                                CellValue communityIdCellValue = evaluator.evaluate(communityIdCell);
-                                Integer communityId =   ((Double) communityIdCellValue.getNumberValue()).intValue();
-                                if(communityId==0){
-                                    continue;
-                                }
-                                dto.setCommunityId(communityId);
+                            Community community = communityService.findCacheByName(record.getSiteId(),communityCell.getStringCellValue().trim());
+                            if (community != null) {
+                                dto.setCommunityId(community.getId());
+                            }else {
+                                failTime++ ;
+                                remarkCell.setCellValue(ResultStatus.COMMUNITY_IS_NOT_EXISTED.getMessage());
+                                continue;
                             }
 
+
                             buildingCell.setCellType(CellType.STRING);
-                            if (StringUtils.equals("", buildingCell.getStringCellValue())) {
+                            if (StringUtils.equals("", buildingCell.getStringCellValue().trim())) {
                                 continue;
                             }
-                            if (buildingIdCell != null) {
-                                CellValue buildingIdCellValue = evaluator.evaluate(buildingIdCell);
-                                Integer buildingId =   ((Double) buildingIdCellValue.getNumberValue()).intValue();
-                                if(buildingId==0){
-                                    continue;
-                                }
-                                dto.setBuildingId(buildingId);
+                            Building building = buildingService.findCacheByName(record.getSiteId(),buildingCell.getStringCellValue().trim());
+                            if (building != null) {
+                                dto.setBuildingId(building.getId());
+                            }else {
+                                failTime++ ;
+                                remarkCell.setCellValue(ResultStatus.BUILDING_IS_NOT_EXISTED.getMessage());
+                                continue;
                             }
 
+
                             doorNoCell.setCellType(CellType.STRING);
                             if (!StringUtils.equals("", doorNoCell.getStringCellValue())) {
                                 String doorNo = doorNoCell.getStringCellValue().trim();
@@ -229,24 +237,18 @@ public class AsyncTaskImportService {
 
 
                             deviceTypeCell.setCellType(CellType.STRING);
-                            if (StringUtils.equals("", deviceTypeCell.getStringCellValue())) {
+                            if (StringUtils.equals("", deviceTypeCell.getStringCellValue().trim())) {
                                 continue;
                             }
-                            if (deviceTypeIdCell != null) {
-                                CellValue deviceTypeIdCellValue = evaluator.evaluate(deviceTypeIdCell);
-                                Integer deviceTypeId =   ((Double) deviceTypeIdCellValue.getNumberValue()).intValue();
-                                if(deviceTypeId==0){
-                                    continue;
-                                }
-                                DeviceTypeDto dt = deviceTypeService.findById(deviceTypeId);
-                                if(dt == null) {
-                                    failTime++ ;
-                                    remarkCell.setCellValue(ResultStatus.DEVICE_TYPE_NOT_EXISTED.getMessage());
-                                    continue;
-                                }else {
-                                    dto.setDeviceTypeId(dt.getId());
-                                    dto.setFactoryId(dt.getManufacturerId());
-                                }
+                            String[] deviceType  = StringUtils.split(deviceTypeCell.getStringCellValue().trim(),"/");
+                            DeviceTypeDto dt = deviceTypeService.getByName(deviceType[1],deviceType[2]);
+                            if(dt != null) {
+                                dto.setDeviceTypeId(dt.getId());
+                                dto.setFactoryId(dt.getManufacturerId());
+                            }else {
+                                failTime++ ;
+                                remarkCell.setCellValue(ResultStatus.DEVICE_TYPE_NOT_EXISTED.getMessage());
+                                continue;
                             }
 
 
@@ -328,7 +330,7 @@ public class AsyncTaskImportService {
 
                     //循环为空的行上移
                     if(failTime > 0){
-                        for (int rowNum = 9+number-1; rowNum >= 9 ; rowNum--) {
+                        for (int rowNum = 8+number-1; rowNum >= 8 ; rowNum--) {
                             Row row = hssfSheet.getRow(rowNum);
                             if (row == null) {
                                 hssfSheet.shiftRows(rowNum+1, 5000, -1);

+ 579 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/udip/ConvertUtils.java

@@ -0,0 +1,579 @@
+package com.bz.smart_city.service.udip;
+
+import org.springframework.stereotype.Component;
+
+import java.math.BigInteger;
+import java.text.DecimalFormat;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+import static com.google.common.collect.Lists.newArrayList;
+
+public class ConvertUtils {
+    /**ConvertQuantity1
+     * 16进制转10进制
+     * @param hex
+     * @return
+     */
+    public BigInteger hexToDecimal(String hex) {
+        return new BigInteger(hex, 16);
+    }
+
+    /**
+     * 10进制转16进制
+     *
+     * @param i
+     * @return
+     */
+    public String demicalToHex(int i) {
+        return  Integer.toHexString(i);
+    }
+
+
+    /**
+     * 16进制转2进制字符
+     *
+     * @param hex
+     * @return
+     */
+    public String hexToByte(String hex) {
+        int i = Integer.parseInt(hex, 16);
+        String str2 = Integer.toBinaryString(i);
+        return str2;
+    }
+
+
+    /**
+     * 2进制字符转16进制
+     *
+     * @param bString
+     * @return
+     */
+    public String byteToHex(String bString) {
+        if (bString == null || bString.equals("") || bString.length() % 8 != 0)
+            return null;
+        StringBuffer tmp = new StringBuffer();
+        int iTmp = 0;
+        for (int i = 0; i < bString.length(); i += 4) {
+            iTmp = 0;
+            for (int j = 0; j < 4; j++) {
+                iTmp += Integer.parseInt(bString.substring(i + j, i + j + 1)) << (4 - j - 1);
+            }
+            tmp.append(Integer.toHexString(iTmp));
+        }
+        return tmp.toString();
+    }
+
+    /**
+     * 16进制转2进制字符串
+     *
+     * @param hexString
+     * @return
+     */
+    public String hexString2binaryString(String hexString) {
+        if (hexString == null || hexString.length() % 2 != 0)
+            return null;
+        String bString = "", tmp;
+        for (int i = 0; i < hexString.length(); i++) {
+            tmp = "0000" + Integer.toBinaryString(Integer.parseInt(hexString.substring(i, i + 1), 16));
+            bString += tmp.substring(tmp.length() - 4);
+        }
+        return bString;
+    }
+
+    /**
+     * 2进制字符转16进制
+     *
+     * @param bString
+     * @return
+     */
+    public String binaryString2hexString(String bString) {
+        if (bString == null || bString.equals("") || bString.length() % 8 != 0)
+            return null;
+        StringBuffer tmp = new StringBuffer();
+        int iTmp = 0;
+        for (int i = 0; i < bString.length(); i += 4) {
+            iTmp = 0;
+            for (int j = 0; j < 4; j++) {
+                iTmp += Integer.parseInt(bString.substring(i + j, i + j + 1)) << (4 - j - 1);
+            }
+            tmp.append(Integer.toHexString(iTmp));
+        }
+        return tmp.toString();
+    }
+
+    /**
+     * 2进制字符转10进制
+     * @param str
+     * @return
+     */
+    public int byteToDecimal(String str) {
+        int len = str.length();
+        char ch;
+        int num = 0;
+        for (int i = len - 1; i >= 0; i--) {
+            ch = str.charAt(i);
+            if (ch != '0' && ch != '1') {
+                System.out.println("input wrong!!");
+                break;
+            }
+            if (ch == '1') {
+                num = (int) (num + Math.pow(2, (len - 1) - i));
+            }
+        }
+        return num;
+    }
+
+    /**
+     * 十进制转二进制
+     *
+     * @param decNum
+     * @param digit
+     * @return
+     */
+    public  String decimalToByte(int decNum, int digit) {
+        String binStr = "";
+        for (int i = digit - 1; i >= 0; i--) {
+            binStr += (decNum >> i) & 1;
+        }
+        return binStr;
+    }
+
+    /**
+     * 16进制高低位转换
+     *
+     * @param src
+     * @return
+     */
+    public  String hexTransfer(String src) {
+        if (src.length() % 2 != 0) {
+            System.out.println("16进制数字长度错误!");
+            return "";
+        }
+        // 按照2个字节进行截取
+        List<String> tmp = new ArrayList<String>();
+        for (int i = 0; i < src.length() / 2; i++) {
+            tmp.add(src.substring(i * 2, (i + 1) * 2));
+        }
+        Collections.reverse(tmp);
+        StringBuffer sb = new StringBuffer();
+        for (String str : tmp) {
+            sb.append(str);
+        }
+        return sb.toString();
+    }
+
+    /**
+     * string转换为BYTE数组
+     *
+     * @param hexString
+     * @return
+     */
+    public static byte[] hexStringToByte(String hexString) {
+        if (hexString == null || hexString.equals("")) {
+            return null;
+        }
+        hexString = hexString.toUpperCase();
+        int length = hexString.length() / 2;
+        char[] hexChars = hexString.toCharArray();
+        byte[] d = new byte[length];
+        for (int i = 0; i < length; i++) {
+            int pos = i * 2;
+            d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1]));
+        }
+        return d;
+    }
+    private static byte charToByte(char c) {
+        return (byte) "0123456789ABCDEF".indexOf(c);
+    }
+
+    /**
+     * 将字节数组转换为16进制格式的字符串
+     *
+     * @param b
+     * @return
+     */
+    public static String ByteToHexString(byte[] b) {
+        String r = "";
+
+        for (int i = 0; i < b.length; i++) {
+            String hex = Integer.toHexString(b[i] & 0xFF);
+            if (hex.length() == 1) {
+                hex = '0' + hex;
+            }
+            r += hex.toUpperCase();
+        }
+
+        return r;
+    }
+
+
+    /**
+     * 16进制加法
+     *
+     * @param hex1
+     * @param hex2
+     * @return
+     */
+    public  String hexAddHex(String hex1, String hex2) {
+        BigInteger hi1 = hexToDecimal(hex1);
+        BigInteger hi2 = hexToDecimal(hex2);
+        return demicalToHex(hi1.add(hi2).intValue());
+    }
+
+    /**
+     * 16进制减法
+     *
+     * @param hex1
+     * @param hex2
+     * @return
+     */
+    public String hexSubHex(String hex1, String hex2) {
+        BigInteger hi1 = hexToDecimal(hex1);
+        BigInteger hi2 = hexToDecimal(hex2);
+        return demicalToHex(hi1.subtract(hi2).intValue());
+    }
+
+    /**
+     * hex1 和 hex2 按位与的补码表示
+     * @param hex1
+     * @param hex2
+     * @return
+     */
+    public String bitwiseAnd(String hex1, String hex2){
+        return demicalToHex(hexToDecimal(hex1).intValue() & hexToDecimal(hex2).intValue());
+    }
+
+    /**
+     * hex1 和 hex2 按位或的补码表示
+     * @param hex1
+     * @param hex2
+     * @return
+     */
+    public String bitwiseOr(String hex1, String hex2){
+        return demicalToHex(hexToDecimal(hex1).intValue() | hexToDecimal(hex2).intValue());
+    }
+
+    /**
+     * 十六进制补位(不足补0)
+     * @param s
+     * @param length
+     * @return
+     */
+    public String padLeft(String s, int length)
+    {
+        byte[] bs = new byte[length];
+        byte[] ss = s.getBytes();
+        Arrays.fill(bs, (byte) (48 & 0xff));
+        System.arraycopy(ss, 0, bs,length - ss.length, ss.length);
+        return new String(bs);
+    }
+
+    /**
+     * "7dd",4,'0'==>"07dd"
+     * @param input 需要补位的字符串
+     * @param size 补位后的最终长度
+     * @param symbol 按symol补充 如'0'
+     * @return
+     * N_TimeCheck中用到了
+     */
+    public String fill(String input, int size, char symbol) {
+        while (input.length() < size) {
+            input = symbol + input;
+        }
+        return input;
+    }
+
+    public String fill(String input, int size) {
+        char symbol = '0';
+        while (input.length() < size) {
+            input = symbol + input;
+        }
+        return input;
+    }
+
+    /**
+     * 保留小数
+     * @param num
+     * @param length
+     * @return
+     */
+    public  String reserveDecimal(Double num, int length) {
+        String format = "%." + length + "f";
+        return String.format(format, num);
+    }
+
+
+    // 电磁水表换算 华旭提供
+    public static int dchs(String hexString) {
+        int temp = 0;
+        for (int i = 0; i < 8; i++) {
+            temp += (Integer.parseInt(hexString.substring(i, i + 1), 16) * Math.pow(16, 7 - i));
+        }
+        return temp;
+    }
+
+    /**
+     * 按长度分离字符
+     * @param str
+     * @param length
+     * @return
+     */
+    public static List<String> split(String str, int length){
+        List<String> list = newArrayList();
+        int z = 0;
+        for(int i=0;i<str.length()/length;i++){
+            String a = str.substring(z,z+length);
+
+            list.add(a);
+            z = z+length;
+        }
+        return list;
+    }
+
+
+    /**
+     * 16进制数转换成10进制数
+     *
+     * @param hexStr
+     * @return
+     */
+    public String ConvertQuantity(String hex) {
+        if(hex.equals("EEEEEEEE"))
+            return "";
+        //DecimalFormat df = new DecimalFormat("0.00");
+        //return df.format((Utilty.bytesToInt(Utilty.hexStringToBytes(hex), 0))/ (double) 100);
+        return hexToDecimal(hex).toString();
+    }
+    /**
+     * 16进制数转换成10进制数(有符号数)
+     * @param hex
+     * @return
+     */
+    public String ConvertQuantity4(String hex) {
+        if((hex.length()==4 &&hex.equals("EEEE"))||(hex.length()==8 &&hex.equals("EEEEEEEE")))
+            return "";
+        return String.valueOf(Integer.valueOf(hex,16).shortValue());
+    }
+    /**
+     * 16进制数转换成10进制数(100)
+     *
+     * @param hexStr
+     * @return
+     */
+    public String ConvertQuantity3(String hex) {
+        if((hex.length()==4 &&hex.equals("EEEE"))||(hex.length()==8 &&hex.equals("EEEEEEEE")))
+            return "";
+        DecimalFormat df = new DecimalFormat("0.000");
+        return df.format(Integer.parseInt(hex,16)/(double)1000);
+    }
+    /**
+     * 16进制数转换成10进制数(1000)
+     *
+     * @param hexStr
+     * @return
+     */
+    public String ConvertQuantity2(String hex) {
+        if((hex.length()==4 &&hex.equals("EEEE"))||(hex.length()==8 &&hex.equals("EEEEEEEE")))
+            return "";
+        DecimalFormat df = new DecimalFormat("0.000");
+        return df.format(Integer.parseInt(hex,16)/(double)100);
+    }
+    /**
+     * 16进制数转换成10进制数(1000)
+     *
+     * @param hexStr
+     * @return
+     */
+    public String ConvertQuantity5(String hex) {
+        if((hex.length()==4 &&hex.equals("EEEE"))||(hex.length()==8 &&hex.equals("EEEEEEEE")))
+            return "";
+        DecimalFormat df = new DecimalFormat("0.00");
+        return df.format(Integer.parseInt(hex,16)/(double)100);
+    }
+    /**
+     * 16进制数转换成10进制数(1000)
+     *
+     * @param hexStr
+     * @return
+     */
+    public String ConvertQuantity1(String hex) {
+        if((hex.length()==4 &&hex.equals("EEEE"))||(hex.length()==8 &&hex.equals("EEEEEEEE")))
+            return "";
+        DecimalFormat df = new DecimalFormat("0.000");
+        return df.format(Integer.parseInt(hex,16)/(double)1000);
+    }
+
+    public String dateFormat(Date date, String format) {
+        SimpleDateFormat sdf = new SimpleDateFormat(format);
+        return sdf.format(date);
+    }
+
+    /**
+     * 返回水表编码
+     * @param
+     * @return
+     */
+    public  String AnalyzeAddress(String HexString) {
+        String Address = "";
+        Address += HexString.substring(12, 14) + HexString.substring(10, 12);
+        Address += HexString.substring(8, 10) + HexString.substring(6, 8);
+        Address += HexString.substring(4, 6) + HexString.substring(2, 4);
+        Address += HexString.substring(0, 2);
+        return Address;
+    }
+
+    public String calculateChecksum(String HexString) {
+        byte[] frameBody = hexStringToByte(HexString);
+        byte sum = 0x00;
+        byte[] reByte= new byte[1];
+        int a = frameBody.length;
+        for (int i = 0; i < frameBody.length; i++)
+            sum += frameBody[i];
+        reByte[0]=sum;
+        return ByteToHexString(reByte);
+    }
+    //16进制转换为ASCII
+    public static String convertHexToString(String hex){
+        StringBuilder sb = new StringBuilder();
+        StringBuilder temp = new StringBuilder();
+        //49204c6f7665204a617661 split into two cha racters 49, 20, 4c...
+        for( int i=0; i<hex.length()-1; i+=2 ){
+            //grab the hex in pairs
+            String output = hex.substring(i, (i + 2));
+            if(output.equals("00"))
+                continue;
+
+            //convert hex to decimal
+            int decimal = Integer.parseInt(output, 16);
+            //convert the decimal to character
+            sb.append((char)decimal);
+            temp.append(decimal);
+        }
+        return sb.toString();
+    }
+
+    public static String ChangeSort(String hex) {
+        String tempString="";
+        for(int i=0;i<hex.length()/2;i++)
+        {
+            tempString =(hex.substring(i*2,i*2+2)+tempString);
+        }
+        return tempString;
+    }
+
+    /**
+     * byte数组中转换为int数值,本方法适用于(低位在前,高位在后)的顺序。
+     *
+     * @param hexStr
+     * @return
+     */
+    public static int bytesToInt(byte[] src, int offset) {
+        int value;
+        value = (int) ((src[offset] & 0xFF) | ((src[offset + 1] & 0xFF) << 8)
+                | ((src[offset + 2] & 0xFF) << 16) | ((src[offset + 3] & 0xFF) << 24));
+        return value;
+    }
+
+    /**
+     * 16进制直接转换成为byte数组(无需Unicode解码)
+     *
+     * @param hexStr
+     * @return
+     */
+    public static byte[] hexStringToBytes(String hexString) {
+        if (hexString == null || hexString.equals("")) {
+            return null;
+        }
+        hexString = hexString.toUpperCase();
+        int length = hexString.length() / 2;
+        char[] hexChars = hexString.toCharArray();
+        byte[] d = new byte[length];
+        for (int i = 0; i < length; i++) {
+            int pos = i * 2;
+            d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1]));
+        }
+        return d;
+    }
+    /**
+     * 16进制数转换成10进制数
+     *
+     * @param hexStr
+     * @return
+     */
+    private String ConvertQuantity6(String hex) {
+        if(hex.equals("EEEEEEEE"))
+            return "";
+        DecimalFormat df = new DecimalFormat("0.00");
+        return df.format((bytesToInt(hexStringToBytes(hex), 0))/ (double) 100);
+    }
+
+    public String bytes2HexString(byte[] b) {
+        String r = "";
+
+        for (int i = 0; i < b.length; i++) {
+            String hex = Integer.toHexString(b[i] & 0xFF);
+            if (hex.length() == 1) {
+                hex = '0' + hex;
+            }
+            r += hex.toUpperCase();
+        }
+
+        return r;
+    }
+
+    private static String[] binaryArray = { "0000", "0001", "0010", "0011",
+            "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011",
+            "1100", "1101", "1110", "1111" };
+    private static String hexStr = "0123456789ABCDEF";
+
+    /**
+     *
+     * @param str
+     * @return 二进制数组转换为二进制字符串 2-2
+     */
+    public static String bytes2BinStr(byte[] bArray) {
+
+        String outStr = "";
+        int pos = 0;
+        for (byte b : bArray) {
+            // 高四位
+            pos = (b & 0xF0) >> 4;
+            outStr += binaryArray[pos];
+            // 低四位
+            pos = b & 0x0F;
+            outStr += binaryArray[pos];
+        }
+        return outStr;
+    }
+
+    /**
+     *
+     * @param hexString
+     * @return 将十六进制转换为二进制字节数组 16-2
+     */
+    public static byte[] hexStr2BinArr(String hexString) {
+        // hexString的长度对2取整,作为bytes的长度
+        int len = hexString.length() / 2;
+        byte[] bytes = new byte[len];
+        byte high = 0;// 字节高四位
+        byte low = 0;// 字节低四位
+        for (int i = 0; i < len; i++) {
+            // 右移四位得到高位
+            high = (byte) ((hexStr.indexOf(hexString.charAt(2 * i))) << 4);
+            low = (byte) hexStr.indexOf(hexString.charAt(2 * i + 1));
+            bytes[i] = (byte) (high | low);// 高地位做或运算
+        }
+        return bytes;
+    }
+
+    /**
+     *
+     * @param hexString
+     * @return 将十六进制转换为二进制字符串 16-2
+     */
+    public static String hexStr2BinStr(String hexString) {
+        return bytes2BinStr(hexStr2BinArr(hexString));
+    }
+
+}

+ 85 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/udip/Lora188Parser.java

@@ -0,0 +1,85 @@
+package com.bz.smart_city.service.udip;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class Lora188Parser {
+    ConvertUtils convertUtils = new ConvertUtils();
+
+    public Map<String,Object> protocolToRawData(Map<String,Object> jsonObj) {
+        String precursor = "FEFEFEFE"; //前导
+
+        String StartChar = "68";//起始符
+
+        String meterType = "10";//表类型 冷水表
+
+        String P_AddressField;//地址域
+
+        String P_ControlField = "04";//控制域
+
+        String P_DataLength = "04"; //帧数据域长度
+
+
+        String P_DataSymbol ="A017";//数据单元标识
+
+        String P_SER ="00";//序号SER
+
+        String P_Content="";//帧数据单元域
+
+        String P_Checksum="";//校验码
+
+        String EndChar = "16";//结束符
+
+
+
+        Map<String,Object> resultObj = new HashMap<>();
+        try {
+            if("WriteValve".equals(jsonObj.get("method"))){
+                Map<String,Object> params = (Map<String, Object>) jsonObj.get("params");
+                String meterEleno = String.valueOf(params.get("electronicNo"));//电子表号
+                String valve = String.valueOf(params.get("valveStatus"));
+
+                //转换电子表号
+                P_AddressField = convertUtils.hexTransfer(convertUtils.padLeft(meterEleno,14));
+                if (valve.equals("1"))
+                    P_Content = "55";//开阀
+                else if (valve.equals("0"))
+                    P_Content = "99";//关阀
+
+
+                String sHead = StartChar + meterType + P_AddressField;
+                String sBody = P_ControlField + P_DataLength + P_DataSymbol + P_SER  + P_Content;
+
+                P_Checksum =  convertUtils.calculateChecksum(sHead + sBody);
+
+                String data =  precursor + sHead + sBody + P_Checksum + EndChar;
+                resultObj.put("status",1);
+                resultObj.put("message","successful");
+                resultObj.put("data",data);
+                return resultObj;
+            }else {
+                resultObj.put("status",0);
+                resultObj.put("message","method mismatching");
+                return resultObj;
+            }
+        }catch(Exception e) {
+            e.fillInStackTrace();
+            resultObj.put("status",0);
+            resultObj.put("message",e.getMessage());
+            return resultObj;
+        }
+    }
+
+    public static void main(String[] args) {
+        System.out.println(1);
+        /*Lora188Parser parser = new Lora188Parser();
+        Map<String,Object> map = new HashMap<>();
+        Map<String,Object> paras = new HashMap<>();
+        //paras.put("electronicNo","00202004170001")
+        paras.put("electronicNo","00000190439135");
+        paras.put("valveStatus", "1");//阀门状态  0:关阀 1:开阀
+        map.put("params", paras);
+        map.put("method", "WriteValve");
+        System.out.println(parser.protocolToRawData(map));*/
+    }
+}

二进制
smart-city-platform/src/main/resources/excel/installPlanTemplate20200731.xlsx


+ 4 - 0
smart-city-platform/src/main/resources/mapper/CustomerMapper.xml

@@ -351,6 +351,10 @@
         ) T1
     </select>
 
+    <select id="findByName" resultMap="BaseResultMap">
+        select id,customer_name from sc_customer where status = 1 and site_id = #{siteId} and customer_name = #{name} limit 1
+    </select>
+
 
 </mapper>
 

+ 22 - 0
smart-city-platform/src/test/java/com/bz/smart_city/ProtocolParser.java

@@ -0,0 +1,22 @@
+package com.bz.smart_city;
+
+import com.bz.smart_city.service.udip.Lora188Parser;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class ProtocolParser {
+    @Test
+    public void test(){
+        Lora188Parser parser = new Lora188Parser();
+        Map<String,Object> map = new HashMap<>();
+        Map<String,Object> paras = new HashMap<>();
+        //paras.put("electronicNo","00202004170001")
+        paras.put("electronicNo","00000190439135");
+        paras.put("valveStatus", "1");//阀门状态  0:关阀 1:开阀
+        map.put("params", paras);
+        map.put("method", "WriteValve");
+        System.out.println(parser.protocolToRawData(map));
+    }
+}