Browse Source

fix: 修改箱码合一文件上传起始读取

Marko552 3 years ago
parent
commit
84e15b8760

+ 7 - 6
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/service/impl/QrBoxMappingServiceImpl.java

@@ -34,6 +34,7 @@ import org.springframework.web.multipart.MultipartFile;
 import java.io.BufferedReader;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.io.LineNumberReader;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.List;
@@ -325,7 +326,7 @@ public class QrBoxMappingServiceImpl implements QrBoxMappingService {
             throw new BusinessException("文件为空,请重新选择文件");
         }
         InputStream inputStream = null;
-        BufferedReader reader = null;
+        LineNumberReader reader = null;
         String filename = file.getName();
         String encryptCodeStr;
 
@@ -335,7 +336,7 @@ public class QrBoxMappingServiceImpl implements QrBoxMappingService {
         try {
             inputStream = file.getInputStream();
             //解决服务器上乱码
-            reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
+            reader = new LineNumberReader(new InputStreamReader(inputStream, "UTF-8"));
 
             //1-逐行读取文件的码
             while ((encryptCodeStr = reader.readLine()) != null) {
@@ -343,10 +344,10 @@ public class QrBoxMappingServiceImpl implements QrBoxMappingService {
                 if (StringUtils.isBlank(encryptCodeStr)) {
                     continue;
                 }
-                //判断有没有中文标题
-                Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
-                Matcher m = p.matcher(encryptCodeStr);
-                if (!m.find()) {
+//                //判断有没有中文标题
+//                Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
+//                Matcher m = p.matcher(encryptCodeStr);
+                if (reader.getLineNumber()>1) {
                     if (encryptCodeStr.contains(",")) {
                         throw new BusinessException("码包文件格式错误,建议每行一个码!");
                     }