Browse Source

fix 导入

he2802 3 years ago
parent
commit
0d1caf539c

+ 77 - 0
zhongzheng-common/src/main/java/com/zhongzheng/common/utils/ToolsUtils.java

@@ -5,6 +5,8 @@ import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
 import com.aliyun.teaopenapi.models.Config;
 import io.micrometer.core.lang.NonNull;
 
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
 import java.util.Iterator;
 import java.util.Random;
 
@@ -43,4 +45,79 @@ public class ToolsUtils {
     public static final int emuToPx(double emu) {
         return DoubleUtils.div(emu, EMU_PER_PX).intValue();
     }
+
+    public static String getEncoding(String str) {
+        String encode = "GB2312";
+        try {
+            if (isEncoding(str, encode)) { // 判断是不是GB2312
+                return encode;
+            }
+        } catch (Exception exception) {
+        }
+        encode = "ISO-8859-1";
+        try {
+            if (isEncoding(str, encode)) { // 判断是不是ISO-8859-1
+                return encode;
+            }
+        } catch (Exception exception1) {
+        }
+        encode = "UTF-8";
+        try {
+            if (isEncoding(str, encode)) { // 判断是不是UTF-8
+                return encode;
+            }
+        } catch (Exception exception2) {
+        }
+        encode = "GBK";
+        try {
+            if (isEncoding(str, encode)) { // 判断是不是GBK
+                return encode;
+            }
+        } catch (Exception exception3) {
+        }
+        return ""; // 如果都不是,说明输入的内容不属于常见的编码格式。
+    }
+
+    public static boolean isEncoding(String str, String encode) {
+        try {
+            if (str.equals(new String(str.getBytes(), encode))) {
+                return true;
+            }
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+        return false;
+    }
+
+    /**
+     * 字符串转换UTF-8编码
+     *
+     * @param string 字符串
+     * @return java.lang.String
+     * @date 2022/4/14.
+     */
+    public static String toUtf8String(String string) {
+        StringBuilder stringBuffer = new StringBuilder();
+        for (int i = 0; i < string.length(); i++) {
+            char c = string.charAt(i);
+            if (c <= 255) {
+                stringBuffer.append(c);
+            } else {
+                byte[] b;
+                try {
+                    b = Character.toString(c).getBytes(StandardCharsets.UTF_8);
+                } catch (Exception ex) {
+                    b = new byte[0];
+                }
+                for (int value : b) {
+                    int k = value;
+                    if (k < 0) k += 256;
+                    stringBuffer.append("%").append(Integer.toHexString(k).toUpperCase());
+                }
+            }
+        }
+        return stringBuffer.toString();
+    }
+
+
 }

+ 14 - 14
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/service/impl/QuestionServiceImpl.java

@@ -58,6 +58,8 @@ import java.util.*;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
+import static com.zhongzheng.common.utils.ToolsUtils.getEncoding;
+
 /**
  * 题库题目Service业务层处理
  *
@@ -929,11 +931,6 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                 boolean hasQuestion = false;
                 for (XWPFParagraph paragraph : paragraphList) {
                     content = paragraph.getText();
-                    System.out.println(content);
-                    System.out.println("EEE");
-                    if(content.startsWith("2")){
-                        System.out.println("EEE");
-                    }
                     content = dealTxt(content);
                     List<XWPFRun> runs = paragraph.getRuns();
                     imgUrl = null;
@@ -992,7 +989,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                             QuestionAddBo addBo = new QuestionAddBo();
                             qContent = removeNo(qContent);
                             if (Validator.isEmpty(qContent)) {
-                                errorLog += "第" + index + "条题目内容空白\n";
+                                errorLog += "第" + index + "条题目内容错误\n";
                                 continue;
                             }
                             QuestionAddBo bo = new QuestionAddBo();
@@ -1055,12 +1052,15 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                     }
                     //第一个选项
                     System.out.println(content);
-                    System.out.println(content.length());
-                    System.out.println("FFF");
-                    System.out.println(content.startsWith("A."));
+                    System.out.println(ToolsUtils.getEncoding(content));
+                   /* System.out.println("FFF");
+                    System.out.println(content.startsWith("A"));
+                    System.out.println(ToolsUtils.getEncoding("A"));
+                    System.out.println(content.startsWith("А"));
+                    System.out.println(ToolsUtils.getEncoding("А"));*/
                     if(content.startsWith("A.")||(nowPart==1&&!isLineStart(content))) {
                         if (Validator.isEmpty(qContent)) {
-                            errorLog += "第" + index + "条题目内容空白\n";
+                            errorLog += "第" + index + "条题目内容错误\n";
                             continue;
                         }
                         if(nowPart!=1){
@@ -1185,7 +1185,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                     //答案和题型
                     if (content.startsWith("正确答案:")||(nowPart==7&&!isLineStart(content))) {
                         if (Validator.isEmpty(qContent)) {
-                            errorLog += "第" + index + "条题目内容空白\n";
+                            errorLog += "第" + index + "条题目内容错误\n";
                             continue;
                         }
                         if(nowPart!=7){
@@ -1367,7 +1367,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                             QuestionAddBo addBo = new QuestionAddBo();
                             qContent = removeNo(qContent);
                             if (Validator.isEmpty(qContent)) {
-                                errorLog += "第" + index + "条题目内容空白\n";
+                                errorLog += "第" + index + "条题目内容错误\n";
                                 continue;
                             }
                             QuestionAddBo bo = new QuestionAddBo();
@@ -1432,7 +1432,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                     //第一个选项
                     if(content.startsWith("A.")||(nowPart==1&&!isLineStart(content))) {
                         if (Validator.isEmpty(qContent)) {
-                            errorLog += "第" + index + "条题目内容空白\n";
+                            errorLog += "第" + index + "条题目内容错误\n";
                             continue;
                         }
                         if(nowPart!=1){
@@ -1557,7 +1557,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                     //答案和题型
                     if (content.startsWith("正确答案:")||(nowPart==7&&!isLineStart(content))) {
                         if (Validator.isEmpty(qContent)) {
-                            errorLog += "第" + index + "条题目内容空白\n";
+                            errorLog += "第" + index + "条题目内容错误\n";
                             continue;
                         }
                         if(nowPart!=7){

+ 1 - 1
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/bo/UserExamRecordAddBo.java

@@ -43,7 +43,7 @@ public class UserExamRecordAddBo {
     private Integer reportStatus;
     /** 分数 */
     @ApiModelProperty("分数")
-    private Long performance;
+    private BigDecimal performance;
 
     /** 历史做题JSON */
     @ApiModelProperty("历史做题JSON")

+ 1 - 1
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/bo/UserExamRecordEditBo.java

@@ -50,7 +50,7 @@ public class UserExamRecordEditBo {
 
     /** 分数 */
     @ApiModelProperty("分数")
-    private Long performance;
+    private BigDecimal performance;
 
     /** 历史做题JSON */
     @ApiModelProperty("历史做题JSON")

+ 1 - 1
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/domain/UserExamRecord.java

@@ -43,7 +43,7 @@ private static final long serialVersionUID=1L;
     /** 1及格 0不及格 */
     private Integer reportStatus;
     /** 分数 */
-    private Long performance;
+    private BigDecimal performance;
     /** 历史做题JSON */
     private String historyExamJson;
     /** 试卷总题数 */

+ 1 - 1
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/vo/UserExamRecordVo.java

@@ -51,7 +51,7 @@ public class UserExamRecordVo {
 	/** 分数 */
 	@Excel(name = "分数")
 	@ApiModelProperty("分数")
-	private Long performance;
+	private BigDecimal performance;
 	/** 历史做题JSON */
 	@Excel(name = "历史做题JSON")
 	@ApiModelProperty("历史做题JSON")