Pārlūkot izejas kodu

新增小程序预览接口

wangliang 1 gadu atpakaļ
vecāks
revīzija
9d0f9c1998

+ 13 - 3
sop-api/src/main/java/com/qmth/sop/server/api/SysController.java

@@ -161,10 +161,11 @@ public class SysController {
     @Transactional
     @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = AttachmentResult.class)})
     public Result fileUpload(@ApiParam(value = "上传文件", required = true) @RequestParam MultipartFile file,
-                             @ApiParam(value = "上传文件类型", required = true) @RequestParam UploadFileEnum type) throws Exception {
+                             @ApiParam(value = "上传文件类型", required = true) @RequestParam UploadFileEnum type,
+                             @ApiParam(value = "小程序签名key") @RequestParam(required = false) String key) throws Exception {
         BasicAttachment basicAttachment = null;
         try {
-            basicAttachment = basicAttachmentService.saveAttachment(file, type);
+            basicAttachment = basicAttachmentService.saveAttachment(file, type, key);
         } catch (Exception e) {
             log.error(SystemConstant.LOG_ERROR, e);
             basicAttachmentService.deleteAttachment(basicAttachment);
@@ -176,7 +177,7 @@ public class SysController {
         }
         JSONObject jsonObject = JSONObject.parseObject(basicAttachment.getPath());
         String filePath = (String) jsonObject.get(SystemConstant.PATH);
-        return ResultUtil.ok(new AttachmentResult(basicAttachment.getId(), basicAttachmentService.filePreview(basicAttachment.getPath()), filePath));
+        return ResultUtil.ok(new AttachmentResult(basicAttachment.getId(), basicAttachmentService.filePreview(basicAttachment.getPath()), filePath, key));
     }
 
     @ApiOperation(value = "下载导入模板")
@@ -217,6 +218,15 @@ public class SysController {
         return ResultUtil.ok(new EditResult(basicAttachmentService.filePreview(path)));
     }
 
+    @ApiOperation(value = "小程序签名预览接口")
+    @RequestMapping(value = "/file/preview/app", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = EditResult.class)})
+    public Result filePreview(@ApiParam(value = "小程序签名key", required = true) @RequestParam String key) throws Exception {
+        BasicAttachment basicAttachment = basicAttachmentService.filePreviewApp(key);
+        Optional.ofNullable(basicAttachment).orElseThrow(() -> ExceptionResultEnum.ATTACHMENT_NO_DATA.exception());
+        return ResultUtil.ok(new EditResult(basicAttachment.getId(), basicAttachmentService.filePreview(basicAttachment.getPath())), key);
+    }
+
     @ApiOperation(value = "文件预览接口")
     @RequestMapping(value = "/file/preview", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = EditResult.class)})

+ 13 - 1
sop-business/src/main/java/com/qmth/sop/business/bean/result/AttachmentResult.java

@@ -25,14 +25,26 @@ public class AttachmentResult implements Serializable {
     @ApiModelProperty(value = "预览url")
     String previewUrl;
 
+    @ApiModelProperty(value = "小程序签名key")
+    String key;
+
     public AttachmentResult() {
 
     }
 
-    public AttachmentResult(Long id, String previewUrl, String url) {
+    public AttachmentResult(Long id, String previewUrl, String url,String key) {
         this.id = id;
         this.previewUrl = previewUrl;
         this.url = url;
+        this.key = key;
+    }
+
+    public String getKey() {
+        return key;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
     }
 
     public String getPreviewUrl() {

+ 17 - 0
sop-business/src/main/java/com/qmth/sop/business/bean/result/EditResult.java

@@ -29,6 +29,17 @@ public class EditResult implements Serializable {
     @ApiModelProperty(value = "附件url")
     String url;
 
+    @ApiModelProperty(value = "小程序签名key")
+    String key;
+
+    public String getKey() {
+        return key;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+
     public String getUrl() {
         return url;
     }
@@ -79,6 +90,12 @@ public class EditResult implements Serializable {
         this.url = url;
     }
 
+    public EditResult(Long id, String url, String key) {
+        this.id = id;
+        this.url = url;
+        this.key = key;
+    }
+
     public EditResult(String url) {
         this.url = url;
     }

+ 13 - 1
sop-business/src/main/java/com/qmth/sop/business/entity/BasicAttachment.java

@@ -47,11 +47,14 @@ public class BasicAttachment extends BaseEntity implements Serializable {
     @JsonSerialize(using = ToStringSerializer.class)
     private Long objId;
 
+    @ApiModelProperty(value = "备注")
+    private String remark;
+
     public BasicAttachment() {
 
     }
 
-    public BasicAttachment(String path, AttachmentInfoDto attachmentInfoDto, Long createId) {
+    public BasicAttachment(String path, AttachmentInfoDto attachmentInfoDto, Long createId, String key) {
         setId(SystemConstant.getDbUuid());
         this.path = path;
         this.name = attachmentInfoDto.getFileName();
@@ -60,6 +63,15 @@ public class BasicAttachment extends BaseEntity implements Serializable {
         this.md5 = attachmentInfoDto.getMd5();
         setCreateTime(System.currentTimeMillis());
         setCreateId(createId);
+        this.remark = key;
+    }
+
+    public String getRemark() {
+        return remark;
+    }
+
+    public void setRemark(String remark) {
+        this.remark = remark;
     }
 
     public Long getOrgId() {

+ 10 - 1
sop-business/src/main/java/com/qmth/sop/business/service/BasicAttachmentService.java

@@ -52,10 +52,11 @@ public interface BasicAttachmentService extends IService<BasicAttachment> {
      *
      * @param file
      * @param type
+     * @param key
      * @return
      * @throws IOException
      */
-    public BasicAttachment saveAttachment(MultipartFile file, UploadFileEnum type) throws Exception;
+    public BasicAttachment saveAttachment(MultipartFile file, UploadFileEnum type, String key) throws Exception;
 
     /**
      * 删除附件
@@ -72,6 +73,14 @@ public interface BasicAttachmentService extends IService<BasicAttachment> {
      */
     public String filePreview(String path) throws Exception;
 
+    /**
+     * 文件预览
+     *
+     * @param key
+     * @return
+     */
+    public BasicAttachment filePreviewApp(String key) throws Exception;
+
     /**
      * 文件预览
      *

+ 17 - 3
sop-business/src/main/java/com/qmth/sop/business/service/impl/BasicAttachmentServiceImpl.java

@@ -1,6 +1,7 @@
 package com.qmth.sop.business.service.impl;
 
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.sop.business.bean.dto.AttachmentInfoDto;
 import com.qmth.sop.business.cache.CommonCacheService;
@@ -157,7 +158,7 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
             jsonObject.put(SystemConstant.UPLOAD_TYPE, type);
             jsonObject.put(SystemConstant.PATH, path);
             attachmentInfoDto.setFileName(fileName);
-            basicAttachment = new BasicAttachment(jsonObject.toJSONString(), attachmentInfoDto, null);
+            basicAttachment = new BasicAttachment(jsonObject.toJSONString(), attachmentInfoDto, null, null);
             this.save(basicAttachment);
         }
         Optional.ofNullable(basicAttachment).orElseThrow(() -> ExceptionResultEnum.ATTACHMENT_ERROR.exception());
@@ -169,12 +170,13 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
      *
      * @param file
      * @param type
+     * @param key
      * @return
      * @throws IOException
      */
     @Override
     @Transactional
-    public BasicAttachment saveAttachment(MultipartFile file, UploadFileEnum type) throws Exception {
+    public BasicAttachment saveAttachment(MultipartFile file, UploadFileEnum type, String key) throws Exception {
         BasicAttachment basicAttachment = null;
         AttachmentInfoDto attachmentInfoDto = this.validateAttachment(file);
         if (Objects.nonNull(attachmentInfoDto)) {
@@ -186,7 +188,7 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
             SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
             jsonObject.put(SystemConstant.UPLOAD_TYPE, type);
             jsonObject.put(SystemConstant.PATH, path);
-            basicAttachment = new BasicAttachment(jsonObject.toJSONString(), attachmentInfoDto, sysUser.getId());
+            basicAttachment = new BasicAttachment(jsonObject.toJSONString(), attachmentInfoDto, sysUser.getId(), key);
             this.save(basicAttachment);
         }
         Optional.ofNullable(basicAttachment).orElseThrow(() -> ExceptionResultEnum.ATTACHMENT_ERROR.exception());
@@ -231,6 +233,18 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
         return url;
     }
 
+    /**
+     * 文件预览
+     *
+     * @param key
+     * @return
+     * @throws Exception
+     */
+    @Override
+    public BasicAttachment filePreviewApp(String key) throws Exception {
+        return this.getOne(new QueryWrapper<BasicAttachment>().lambda().eq(BasicAttachment::getRemark, key));
+    }
+
     /**
      * 文件预览
      *

+ 1 - 1
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBTaskServiceImpl.java

@@ -53,7 +53,7 @@ public class TBTaskServiceImpl extends ServiceImpl<TBTaskMapper, TBTask> impleme
         BasicAttachment basicAttachment = null;
         Map<String, Object> map = new HashMap<>();
         try {
-            basicAttachment = basicAttachmentService.saveAttachment(file, UploadFileEnum.FILE);
+            basicAttachment = basicAttachmentService.saveAttachment(file, UploadFileEnum.FILE, null);
             SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
             TBTask tbTask = new TBTask(taskTypeEnum,
                     TaskStatusEnum.INIT,

+ 6 - 1
sop-business/src/main/resources/db/log/wangliang_update_log.sql

@@ -1874,4 +1874,9 @@ SET code='DATE', `type`='FORM', form_id='device_out_time', form_name='device_out
 WHERE id=145;
 UPDATE t_d_form_widget
 SET code='DATE', `type`='FORM', form_id='device_in_time', form_name='device_in_time', title='设备入库时间', input_type='STRING', required=1, readable=0, writable=1, visable=1, `scale`=NULL, `length`=NULL, binding=NULL, data_grid=NULL, tips=NULL, format='yyyy-MM-dd', span=6, sub_title=NULL, `options`=NULL, flow_type='CLOUD_MARK_SOP_FLOW', form_setup=11, handle=0, form_group=NULL, role_type=NULL, create_id=1, create_time=1
-WHERE id=186;
+WHERE id=186;
+
+ALTER TABLE basic_attachment ADD remark varchar(500) NULL;
+INSERT INTO sys_privilege
+(id, name, url, `type`, parent_id, `sequence`, property, related, enable, default_auth, front_display)
+VALUES(3051, '小程序签名预览', '/api/admin/common/file/preview/app', 'URL', 64, 6, 'SYS', NULL, 1, 1, 0);