Skip to content

Commit

Permalink
代码规范优化
Browse files Browse the repository at this point in the history
  • Loading branch information
OURSIL committed Aug 27, 2024
1 parent d3fcf3f commit 2071873
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

package com.yami.shop.admin.controller;

import com.yami.shop.bean.enums.UploadType;
import com.yami.shop.common.bean.Qiniu;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.ImgUploadUtil;
Expand All @@ -32,14 +33,14 @@
@RestController
@RequestMapping("/admin/file")
public class FileController {

@Autowired
private AttachFileService attachFileService;
@Autowired
private Qiniu qiniu;
@Autowired
private ImgUploadUtil imgUploadUtil;

@PostMapping("/upload/element")
public ServerResponseEntity<String> uploadElementFile(@RequestParam("file") MultipartFile file) throws IOException{
if(file.isEmpty()){
Expand All @@ -48,17 +49,17 @@ public ServerResponseEntity<String> uploadElementFile(@RequestParam("file") Mult
String fileName = attachFileService.uploadFile(file);
return ServerResponseEntity.success(fileName);
}

@PostMapping("/upload/tinymceEditor")
public ServerResponseEntity<String> uploadTinymceEditorImages(@RequestParam("editorFile") MultipartFile editorFile) throws IOException{
String fileName = attachFileService.uploadFile(editorFile);
String data = "";
if (Objects.equals(imgUploadUtil.getUploadType(), 1)) {
if (Objects.equals(imgUploadUtil.getUploadType(), UploadType.LOCAL.value())) {
data = imgUploadUtil.getUploadPath() + fileName;
} else if (Objects.equals(imgUploadUtil.getUploadType(), 2)) {
} else if (Objects.equals(imgUploadUtil.getUploadType(), UploadType.QINIU.value())) {
data = qiniu.getResourcesUrl() + fileName;
}
return ServerResponseEntity.success(data);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
*
* https://www.mall4j.com/
*
* 未经允许,不可做商业用途!
*
* 版权所有,侵权必究!
*/

package com.yami.shop.bean.enums;

/**
* @author lanhai
* 文件上传方式 1.本地文件上传 2.七牛云
*/
public enum UploadType {

/**
* 本地文件上传
*/
LOCAL(1),

/**
* 七牛云
*/
QINIU(2);

private Integer num;

public Integer value() {
return num;
}

UploadType(Integer num) {
this.num = num;
}

public static UploadType instance(Integer value) {
UploadType[] enums = values();
for (UploadType statusEnum : enums) {
if (statusEnum.value().equals(value)) {
return statusEnum;
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.qiniu.storage.UploadManager;
import com.qiniu.storage.model.DefaultPutRet;
import com.qiniu.util.Auth;
import com.yami.shop.bean.enums.UploadType;
import com.yami.shop.bean.model.AttachFile;
import com.yami.shop.common.bean.Qiniu;
import com.yami.shop.common.util.ImgUploadUtil;
Expand Down Expand Up @@ -83,9 +84,9 @@ public String uploadFile(MultipartFile file) throws IOException {
public void deleteFile(String fileName){
attachFileMapper.delete(new LambdaQueryWrapper<AttachFile>().eq(AttachFile::getFilePath,fileName));
try {
if (Objects.equals(imgUploadUtil.getUploadType(), 1)) {
if (Objects.equals(imgUploadUtil.getUploadType(), UploadType.LOCAL.value())) {
imgUploadUtil.delete(fileName);
} else if (Objects.equals(imgUploadUtil.getUploadType(), 2)) {
} else if (Objects.equals(imgUploadUtil.getUploadType(), UploadType.QINIU.value())) {
bucketManager.delete(qiniu.getBucket(), fileName);
}
} catch (QiniuException e) {
Expand Down

0 comments on commit 2071873

Please sign in to comment.