feat[文件上传和订单模块功能]:已测试通过

This commit is contained in:
2025-01-13 10:54:30 +08:00
parent 40cd308749
commit d5410d0ed6
53 changed files with 2309 additions and 131 deletions
@@ -1,21 +1,14 @@
package com.central.file.controller;
import java.util.Map;
import com.central.common.model.PageResult;
import com.central.common.model.Result;
import com.central.file.model.FileInfo;
import com.central.file.service.IFileService;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import com.central.common.model.PageResult;
import com.central.file.model.FileInfo;
import javax.annotation.Resource;
import java.util.Map;
/**
* 文件上传
@@ -40,6 +33,19 @@ public class FileController {
return fileService.upload(file);
}
/**
* 文件上传
* 根据fileType选择上传方式
*
* @param id
* @return
* @throws Exception
*/
/* @GetMapping("/files/{id}")
public Result upload(@PathVariable String id) throws Exception {
return "fileService.download(file)";
}*/
/**
* 文件删除
*
@@ -0,0 +1,74 @@
package com.central.file.service.impl;
import cn.hutool.core.util.StrUtil;
import com.central.common.constant.CommonConstant;
import com.central.file.model.FileInfo;
import com.central.oss.model.ObjectInfo;
import com.central.oss.properties.FileServerProperties;
import com.central.oss.template.CosTemplate;
import com.qcloud.cos.model.COSObject;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.OutputStream;
/**
* @author lsl
* @date 2025/1/13
* <p>
*/
@Service
@ConditionalOnProperty(prefix = FileServerProperties.PREFIX, name = "type", havingValue = FileServerProperties.TYPE_COS)
public class CosService extends AbstractIFileService {
@Resource
private CosTemplate cosTemplate;
@Override
protected String fileType() {
return FileServerProperties.TYPE_COS;
}
@Override
protected ObjectInfo uploadFile(MultipartFile file) {
return cosTemplate.upload(file);
}
@Override
protected void deleteFile(String objectPath) {
COSObject cosObject = parsePath(objectPath);
cosTemplate.delete(cosObject.getBucketName(), cosObject.getKey());
}
@Override
public void out(String id, OutputStream os) {
FileInfo fileInfo = baseMapper.selectById(id);
if (fileInfo != null) {
COSObject cosObject = parsePath(fileInfo.getPath());
cosTemplate.out(cosObject.getBucketName(), cosObject.getKey(), os);
}
}
@Setter
@Getter
private class S3Object {
private String bucketName;
private String objectName;
}
private COSObject parsePath(String path) {
COSObject cosObject = new COSObject();
if (StrUtil.isNotEmpty(path)) {
int splitIndex = path.lastIndexOf(CommonConstant.PATH_SPLIT);
if (splitIndex != -1) {
cosObject.setBucketName(path.substring(0, splitIndex));
cosObject.setKey(path.substring(splitIndex + 1));
}
}
return cosObject;
}
}
@@ -1,6 +1,6 @@
spring:
datasource:
url: jdbc:mysql://${zlt.datasource.ip}:3306/file_center?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai
url: jdbc:mysql://${zlt.datasource.ip}/file_center?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai
username: ${zlt.datasource.username}
password: ${zlt.datasource.password}
driver-class-name: com.mysql.cj.jdbc.Driver
@@ -26,7 +26,7 @@ knife4j:
zlt:
file-server:
type: s3
type: cos
#fdfs:
# web-url: ${zlt.fdfs.web-url}
s3:
@@ -34,6 +34,12 @@ zlt:
accessKeySecret: ${zlt.s3.accessKeySecret}
endpoint: ${zlt.s3.endpoint}
bucketName: ${zlt.s3.bucketName}
cos:
secretId: ${zlt.cos.secretId}
secretKey: ${zlt.cos.secretKey}
endpoint: ${zlt.cos.endpoint}
region: ${zlt.cos.region}
bucketName: ${zlt.cos.bucketName}
#多租户配置
tenant:
enable: true
@@ -42,4 +48,4 @@ zlt:
#fdfs:
# soTimeout: 1500
# connectTimeout: 600
# trackerList: ${zlt.fdfs.trackerList}
# trackerList: ${zlt.fdfs.trackerList}