mirror of
https://gitee.com/gz-yami/mall4j.git
synced 2025-12-25 23:56:20 +08:00
代码规范优化
This commit is contained in:
parent
d3fcf3f948
commit
207187376b
@ -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;
|
||||
@ -53,9 +54,9 @@ public class FileController {
|
||||
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);
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
@ -21,6 +21,7 @@ import com.qiniu.storage.BucketManager;
|
||||
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;
|
||||
@ -83,9 +84,9 @@ public class AttachFileServiceImpl extends ServiceImpl<AttachFileMapper, AttachF
|
||||
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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user