فهرست منبع

【CHG】修改生成二维码保存位置

ZhaoMn 3 سال پیش
والد
کامیت
e35e5a8756

+ 4 - 0
railway-business/src/main/java/com/railway/business/safetool/domain/BaseSafetyTool.java

@@ -46,6 +46,10 @@ public class BaseSafetyTool extends BaseEntity{
     @Length(min = 1, max = 64, message = "【二维码编码】长度必须介于 {min} 和 {max} 之间")
     private String toolQcode;
 
+    @ApiModelProperty(value = "二维码URL")
+    @Length(max = 512, message = "【二维码URL】长度必须介于 0 和 {max} 之间")
+    private String qcodeUrl;
+
     @ApiModelProperty(value = "电压等级")
     @Length(min = 1, max = 10, message = "【电压等级】长度必须介于 {min} 和 {max} 之间")
     private String elecLevel;

+ 37 - 5
railway-business/src/main/java/com/railway/business/safetool/service/impl/BaseSafetyToolServiceImpl.java

@@ -5,7 +5,12 @@ import com.railway.business.safetool.mapper.BaseSafetyToolMapper;
 import com.railway.business.safetool.service.IBaseSafetyToolService;
 import com.railway.common.enums.QcodeEnum;
 import com.railway.common.qrcode.impl.SnowflakeClient;
+import com.railway.common.utils.QRCodeUtilEx;
 import com.railway.common.utils.SecurityUtils;
+import com.railway.common.utils.StringUtils;
+import com.railway.common.utils.file.FileUploadUtils;
+import com.railway.system.service.ISysDictDataService;
+import com.railway.system.service.ISysFileService;
 import java.util.Date;
 import java.util.List;
 import org.springframework.stereotype.Service;
@@ -23,11 +28,16 @@ public class BaseSafetyToolServiceImpl implements IBaseSafetyToolService {
 
   private final BaseSafetyToolMapper baseSafetyToolMapper;
   private final SnowflakeClient snowflakeClient;
+  private final ISysDictDataService dictDataService;
+  private final ISysFileService fileService;
 
   public BaseSafetyToolServiceImpl(BaseSafetyToolMapper baseSafetyToolMapper,
-      SnowflakeClient snowflakeClient) {
+      SnowflakeClient snowflakeClient,
+      ISysDictDataService dictDataService, ISysFileService fileService) {
     this.baseSafetyToolMapper = baseSafetyToolMapper;
     this.snowflakeClient = snowflakeClient;
+    this.dictDataService = dictDataService;
+    this.fileService = fileService;
   }
 
   /**
@@ -39,9 +49,7 @@ public class BaseSafetyToolServiceImpl implements IBaseSafetyToolService {
     baseSafetyTool.setCreateTime(new Date());
     baseSafetyTool.setCreateBy(SecurityUtils.getUsername());
     baseSafetyTool.setState("1");
-    String qcode = snowflakeClient.code(QcodeEnum.LETTER_NUMBER) + "_"
-        + baseSafetyTool.getToolType() + "_" + baseSafetyTool.getToolCode();
-    baseSafetyTool.setToolQcode(qcode);
+    setTool(baseSafetyTool);
     return baseSafetyToolMapper.insert(baseSafetyTool);
   }
 
@@ -91,7 +99,31 @@ public class BaseSafetyToolServiceImpl implements IBaseSafetyToolService {
    */
   @Override
   public List<BaseSafetyTool> getList(BaseSafetyTool baseSafetyTool) {
-    return baseSafetyToolMapper.getList(baseSafetyTool);
+    List<BaseSafetyTool> list = baseSafetyToolMapper.getList(baseSafetyTool);
+    for(BaseSafetyTool tool : list){
+      setTool(tool);
+      update(tool);
+    }
+    return list;
+  }
+
+  private void setTool(BaseSafetyTool tool){
+    String qcode = tool.getToolQcode();
+    if(StringUtils.isEmpty(qcode)) {
+      qcode = snowflakeClient.code(QcodeEnum.LETTER_NUMBER) + "_"
+          + tool.getToolType() + "_" + tool.getToolCode();
+      tool.setToolQcode(qcode);
+    }
+    String dictType = "tool_type";
+    String toolName = dictDataService.selectDictLabel(dictType, tool.getToolType());
+    tool.setToolName(toolName);
+    String filePath = FileUploadUtils.getAbsoluteFile(qcode + ".jpg");
+    try {
+      QRCodeUtilEx.encode(tool.getToolQcode(), toolName, filePath);
+      String url = fileService.getUploadFileUrl(filePath);
+      tool.setQcodeUrl(url);
+    } catch (Exception ignored) {
+    }
   }
 
   /**

+ 16 - 0
railway-business/src/main/resources/mapper/safetool/BaseSafetyToolMapper.xml

@@ -12,6 +12,7 @@
     <result column="tool_type" property="toolType"/>
     <result column="tool_code" property="toolCode"/>
     <result column="tool_qcode" property="toolQcode"/>
+    <result column="qcode_url" property="qcodeUrl"/>
     <result column="elec_level" property="elecLevel"/>
     <result column="unit" property="unit"/>
     <result column="test_cycle" property="testCycle"/>
@@ -45,6 +46,7 @@
     t.tool_type,
     t.tool_code,
     t.tool_qcode,
+    t.qcode_url,
     t.elec_level,
     dict1.remark unit,
     t.test_cycle,
@@ -88,6 +90,12 @@
       <if test='null != toolCode'>
         tool_code,
       </if>
+      <if test='null != toolQcode'>
+        tool_qcode,
+      </if>
+      <if test='null != qcodeUrl'>
+        qcode_url,
+      </if>
       <if test='null != elecLevel'>
         elec_level,
       </if>
@@ -168,6 +176,12 @@
       <if test='null != toolCode'>
         #{toolCode},
       </if>
+      <if test='null != toolQcode'>
+        #{toolQcode},
+      </if>
+      <if test='null != qcodeUrl'>
+        #{qcodeUrl},
+      </if>
       <if test='null != elecLevel'>
         #{elecLevel},
       </if>
@@ -248,6 +262,8 @@
       <if test='null != toolName'>tool_name = #{toolName},</if>
       <if test='null != toolType'>tool_type = #{toolType},</if>
       <if test='null != toolCode'>tool_code = #{toolCode},</if>
+      <if test='null != toolQcode'>tool_qcode = #{toolQcode},</if>
+      <if test='null != qcodeUrl'>qcode_url = #{qcodeUrl},</if>
       <if test='null != elecLevel'>elec_level = #{elecLevel},</if>
       <if test='null != unit'>unit = #{unit},</if>
       <if test='null != testCycle'>test_cycle = #{testCycle},</if>

+ 4 - 0
railway-common/src/main/java/com/railway/common/exception/file/FileSizeLimitExceededException.java

@@ -12,4 +12,8 @@ public class FileSizeLimitExceededException extends FileException {
   public FileSizeLimitExceededException(long defaultMaxSize) {
     super("upload.exceed.maxSize", new Object[]{defaultMaxSize});
   }
+
+  public FileSizeLimitExceededException(long defaultMinSize, String msg) {
+    super("upload.exceed.minSize", new Object[]{defaultMinSize, msg});
+  }
 }

+ 9 - 0
railway-system/src/main/java/com/railway/system/service/ISysFileService.java

@@ -20,6 +20,15 @@ public interface ISysFileService {
    */
   String uploadFile(MultipartFile file) throws Exception;
 
+  /**
+   * 文件上传接口
+   *
+   * @param localFilePath 上传的文件
+   * @return 访问地址
+   * @throws Exception 文件上传异常
+   */
+  String getUploadFileUrl(String localFilePath) throws Exception;
+
   /**
    * 本地文件上传到文件服务器
    * @param localFilePath 本地文件路径

+ 19 - 0
railway-system/src/main/java/com/railway/system/service/impl/AbstractFileService.java

@@ -2,6 +2,7 @@ package com.railway.system.service.impl;
 
 import com.railway.common.constant.Constants;
 import com.railway.common.core.domain.AjaxResult;
+import com.railway.common.exception.file.FileSizeLimitExceededException;
 import com.railway.common.utils.StringUtils;
 import com.railway.common.utils.file.FileUploadUtils;
 import com.railway.common.utils.file.FileUtils;
@@ -13,6 +14,24 @@ import java.io.File;
  */
 public abstract class AbstractFileService implements ISysFileService {
 
+  /**
+   * 文件上传接口
+   *
+   * @param localFilePath 上传的文件
+   * @return 访问地址
+   * @throws Exception 文件上传异常
+   */
+  @Override
+  public String getUploadFileUrl(String localFilePath) throws Exception {
+    if(StringUtils.isEmpty(localFilePath)){
+      throw new FileSizeLimitExceededException(0, "文件读取失败");
+    }
+    File localFile = new File(localFilePath);
+    String url = uploadFile(FileUploadUtils.upload(localFile));
+    FileUtils.deleteFile(localFilePath);
+    return url;
+  }
+
   /**
    * 本地文件上传到文件服务器
    *