Prechádzať zdrojové kódy

活动code后端生成

tanzhongran 3 rokov pred
rodič
commit
27bce2dc1c

+ 10 - 0
abi-cloud-qr-platform-common/src/main/java/com/abi/task/common/utils/IStringUtil.java

@@ -63,4 +63,14 @@ public class IStringUtil {
         return camelSb.substring(0,1).toLowerCase()+camelSb.substring(1);
     }
 
+    /**
+     * 字符串往前补零
+     * @param num
+     * @param length 不满多少补零
+     * @return
+     */
+    public static String zeroFill(Long num,int length){
+        return String.format("%0"+length+"d", num);
+    }
+
 }

+ 0 - 2
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/dto/req/AddActiveReq.java

@@ -20,8 +20,6 @@ import java.util.List;
 @ApiModel
 public class AddActiveReq implements Serializable {
 
-    @NotEmpty(message = "活动ID为空")
-    @Size(max = 20, message = "活动ID不能超过20字符")
     @ApiModelProperty(value = "活动code(即页面上的手输的活动id)")
     private String activeCode;
 

+ 5 - 1
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/service/impl/ActiveServiceImpl.java

@@ -29,6 +29,7 @@ import com.abi.qms.platform.infrastructure.util.PageUtil;
 import com.abi.qms.platform.infrastructure.util.UserUtil;
 import com.abi.qms.platform.service.ActiveService;
 import com.abi.task.common.api.exception.BusinessException;
+import com.abi.task.common.utils.IStringUtil;
 import com.abi.task.common.utils.PojoConverterUtils;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
@@ -83,7 +84,6 @@ public class ActiveServiceImpl implements ActiveService {
         //1-新增
         Long userId = userUtil.getUser().getId();
         BaseActive active = new BaseActive();
-        active.setActiveCode(req.getActiveCode());
         active.setActiveName(req.getActiveName());
         active.setActiveType(req.getActiveType());
         active.setAuditStatus(ActiveAuditStatusEnum.WAIT_REVIEW.getCode());
@@ -98,6 +98,10 @@ public class ActiveServiceImpl implements ActiveService {
         active.setUpdateBy(userId);
         baseActiveMapper.insert(active);
 
+        //2-用id补零作为code
+        active.setActiveCode(IStringUtil.zeroFill(active.getId(),8));
+        baseActiveMapper.updateById(active);
+
     }
 
     /**

+ 20 - 16
abi-cloud-qr-platform-server/src/test/java/com/abi/qms/platform/EncryptionTest.java

@@ -33,12 +33,6 @@ public class EncryptionTest {
     }
 
 
-    public static void main(String[] args) {
-        String a = "aLI5iXza3R/w7aJ2AsYhUT7EGS0Zqk94k1nXK9rT8AvJGMbMUJytae53f82pFphWy0bmnEGv4fWb6RcpE9m3tQ==";
-        String s = AesEncodeUtil.aesDecode(a, "EC/Z+S7c3EFJa2dtvLyekg==");
-        System.out.println(s);
-    }
-
 
 
     /**
@@ -63,35 +57,45 @@ public class EncryptionTest {
         }
     }
 
+
+    public static void main(String[] args) {
+        String key = "EC/Z+S7c3EFJa2dtvLyekg==";
+        // 单个字符串解码
+        // String content = "aLI5iXza3R/w7aJ2AsYhUT7EGS0Zqk94k1nXK9rT8AvJGMbMUJytae53f82pFphWy0bmnEGv4fWb6RcpE9m3tQ==";
+        // 文件解码
+        String content = readToString("D:\\whole.txt");
+        String decodeStr = AesEncodeUtil.aesDecode(content, key);
+        System.out.println(decodeStr);
+    }
+
+
     /**
      * 读取文件
      *
      * @param fileName
      * @return
      */
-    public static String readToString(String fileName) {
+    private static String readToString(String fileName) {
         String encoding = "UTF-8";
         File file = new File(fileName);
-        Long filelength = file.length();
-        byte[] filecontent = new byte[filelength.intValue()];
+        Long fileLength = file.length();
+        byte[] fileContent = new byte[fileLength.intValue()];
         FileInputStream in = null;
         try {
             in = new FileInputStream(file);
-            in.read(filecontent);
-        } catch (FileNotFoundException e) {
-            throw new BusinessException(404,"文件不存在");
-        } catch (IOException e) {
-            throw new BusinessException(404,"文件io不存在");
+            in.read(fileContent);
+        } catch (Exception e) {
+            System.out.println(e);
         }finally {
             try {
                 in.close();
             } catch (IOException e) {
-                throw new BusinessException(404 , "io流关闭异常");
+                System.out.println(e);
             }
         }
 
         try {
-            return new String(filecontent, encoding);
+            return new String(fileContent, encoding);
         } catch (UnsupportedEncodingException e) {
             System.err.println("The OS does not support " + encoding);
             e.printStackTrace();