yq %!s(int64=2) %!d(string=hai) anos
pai
achega
eeaa7125b5

+ 24 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/controller/web/DmpSoftwareUpgradeController.java

@@ -3,7 +3,9 @@ package com.usky.iot.controller.web;
 
 import com.usky.common.core.bean.ApiResult;
 import com.usky.common.core.bean.CommonPage;
+import com.usky.iot.domain.DmpSoftwareSubpackage;
 import com.usky.iot.domain.DmpSoftwareUpgrade;
+import com.usky.iot.service.DmpSoftwareSubpackageService;
 import com.usky.iot.service.DmpSoftwareUpgradeService;
 import com.usky.iot.service.vo.DmpSoftwareUpgradeRequest;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -47,5 +49,27 @@ public class DmpSoftwareUpgradeController {
     {
         return ApiResult.success(dmpSoftwareUpgradeService.page(dmpSoftwareUpgradeRequest));
     }
+
+    @Autowired
+    private DmpSoftwareSubpackageService dmpSoftwareSubpackageService;
+
+
+    @GetMapping("test")
+    public void test(){
+        DmpSoftwareSubpackage byId = dmpSoftwareSubpackageService.getById(15524);
+        byte[] b = byId.getApplyPackage();
+        int crc = 0;
+        for(int i=0;i<b.length;i++) {
+            String str = Integer.toHexString(b[i]&0x00ff);
+            if(str.length()==1) {
+                str = "0"+str;
+            }
+//                    System.out.print(b[i]+" ");
+//            System.out.print(str+" ");
+            crc = (crc + (b[i]&0x00ff))&0xffff;
+        }
+        System.out.println(crc);
+
+    }
 }
 

+ 26 - 37
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/DmpSoftwareUpgradeServiceImpl.java

@@ -19,10 +19,11 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
-import java.io.ByteArrayInputStream;
+import java.io.BufferedInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 /**
@@ -67,55 +68,43 @@ public class DmpSoftwareUpgradeServiceImpl extends AbstractCrudService<DmpSoftwa
         InputStream inputStream = null;
         List<DmpSoftwareSubpackage> list = new ArrayList<>();
         try {
-            byte [] byteArr=multipartFile.getBytes();
-            inputStream = new ByteArrayInputStream(byteArr);
+//            byte [] byteArr=multipartFile.getBytes();
+            inputStream = new BufferedInputStream(multipartFile.getInputStream());
             //创建规定大小的byte数组
             byte[] b = new byte[num];
             //name为以后的小文件命名做准备
             int name = 0;
             //遍历将大文件读入byte数组中,当byte数组读满后写入对应的小文件中
-
             int len,crc,cur = 0;
-            while((len = inputStream.read(b))!=-1) {
-                crc = 0;
-                for(int i=0;i<len;i++) {
-                    String str = Integer.toHexString(b[i]&0x00ff);
-                    if(str.length()==1)
-                        str = "0"+str;
-                    System.out.print(str+" ");
-                    crc = (crc + (b[i]&0x00ff))&0xffff;
+//            while((len = inputStream.read(b))!=-1) {
+//                crc = 0;
+//                for(int i=0;i<len;i++) {
+//                    crc = (crc + (b[i]&0x00ff))&0xffff;
+//                }
+//                DmpSoftwareSubpackage dmpSoftwareSubpackage = new DmpSoftwareSubpackage();
+//                dmpSoftwareSubpackage.setUpgradeId(dmpSoftwareUpgrade.getId());
+//                dmpSoftwareSubpackage.setSubpackageNumber(cur);
+//                byte[] bytes = Arrays.copyOf(b, len);
+//                dmpSoftwareSubpackage.setApplyPackage(bytes);
+//                dmpSoftwareSubpackage.setSubpackageLength(String.valueOf(len));
+//                dmpSoftwareSubpackage.setCheckCode(Integer.toHexString(crc));
+//                list.add(dmpSoftwareSubpackage);
+//                cur++;
+//            }
+            while ((len = inputStream.read(b)) != -1) {
+                int chk = 0x0000;
+                for(int i=0;i<len;i++){
+                    chk += b[i]&0x00ff;
                 }
-
                 DmpSoftwareSubpackage dmpSoftwareSubpackage = new DmpSoftwareSubpackage();
                 dmpSoftwareSubpackage.setUpgradeId(dmpSoftwareUpgrade.getId());
                 dmpSoftwareSubpackage.setSubpackageNumber(name);
-                dmpSoftwareSubpackage.setApplyPackage(b);
-                if (len < 1024){
-                    dmpSoftwareSubpackage.setApplyPackage(subBytes(b,0,len));
-                }
+                dmpSoftwareSubpackage.setApplyPackage(Arrays.copyOf(b, len));
                 dmpSoftwareSubpackage.setSubpackageLength(String.valueOf(len));
-                dmpSoftwareSubpackage.setCheckCode(Integer.toHexString(crc));
+                dmpSoftwareSubpackage.setCheckCode(String.format("%04x", chk& 0x0000ffff));
                 list.add(dmpSoftwareSubpackage);
-                System.out.println("\n"+cur+") len:"+len+"\tcrc:"+Integer.toHexString(crc));
-                cur++;
+                name++;
             }
-//            while ((len = inputStream.read(b)) != -1) {
-//                int chk = 0x0000;
-//                for(int i=0;i<len;i++){
-//                    chk += b[i]&0x00ff;
-//                }
-//                DmpSoftwareSubpackage dmpSoftwareSubpackage = new DmpSoftwareSubpackage();
-//                dmpSoftwareSubpackage.setUpgradeId(dmpSoftwareUpgrade.getId());
-//                dmpSoftwareSubpackage.setSubpackageNumber(name);
-//                dmpSoftwareSubpackage.setApplyPackage(b);
-//                if (len < 1024){
-//                    dmpSoftwareSubpackage.setApplyPackage(subBytes(b,0,len));
-//                }
-//                dmpSoftwareSubpackage.setSubpackageLength(String.valueOf(len));
-//                dmpSoftwareSubpackage.setCheckCode(String.format("%04x", chk& 0x0000ffff));
-//                list.add(dmpSoftwareSubpackage);
-//                name++;
-//            }
         } catch (Exception e) {
             e.printStackTrace();
         } finally {