feat[文件上传]:oss阿里云对象存储集成
This commit is contained in:
@@ -80,9 +80,28 @@
|
||||
<artifactId>fastdfs-client</artifactId>
|
||||
</dependency>-->
|
||||
<!-- aws s3 -->
|
||||
<dependency>
|
||||
<!-- <dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-java-sdk-s3</artifactId>
|
||||
</dependency>-->
|
||||
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
<version>2.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.activation</groupId>
|
||||
<artifactId>activation</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
<!-- no more than 2.3.3-->
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jaxb</groupId>
|
||||
<artifactId>jaxb-runtime</artifactId>
|
||||
<version>2.3.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.central.file.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.aliyun.oss.model.OSSObject;
|
||||
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.OssTemplate;
|
||||
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.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* @author lsl
|
||||
* @date 2025/1/13
|
||||
* <p>
|
||||
*/
|
||||
@Service
|
||||
@ConditionalOnProperty(prefix = FileServerProperties.PREFIX, name = "type", havingValue = FileServerProperties.TYPE_OSS)
|
||||
public class OssService extends AbstractIFileService {
|
||||
|
||||
@Resource
|
||||
private OssTemplate ossTemplate;
|
||||
|
||||
@Override
|
||||
protected String fileType() {
|
||||
return FileServerProperties.TYPE_COS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ObjectInfo uploadFile(MultipartFile file) {
|
||||
return ossTemplate.upload(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ObjectInfo uploadFile(String name, InputStream inputStream) throws IOException {
|
||||
return ossTemplate.upload(name, inputStream,inputStream.available(),"image/jpeg");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void deleteFile(String objectPath) {
|
||||
OSSObject ossObject = parsePath(objectPath);
|
||||
ossTemplate.delete(ossObject.getBucketName(), ossObject.getKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void out(String id, OutputStream os) {
|
||||
FileInfo fileInfo = baseMapper.selectById(id);
|
||||
if (fileInfo != null) {
|
||||
OSSObject ossObject = parsePath(fileInfo.getPath());
|
||||
ossTemplate.out(ossObject.getBucketName(), ossObject.getKey(), os);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getViewUrl(String fileId) {
|
||||
FileInfo fileInfo = baseMapper.selectById(fileId);
|
||||
if (fileInfo != null) {
|
||||
return ossTemplate.getViewUrl(fileInfo.getName());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileInfo getFileInfo(String id) {
|
||||
return baseMapper.selectById(id);
|
||||
}
|
||||
|
||||
private OSSObject parsePath(String path) {
|
||||
OSSObject ossObject = new OSSObject();
|
||||
if (StrUtil.isNotEmpty(path)) {
|
||||
int splitIndex = path.lastIndexOf(CommonConstant.PATH_SPLIT);
|
||||
if (splitIndex != -1) {
|
||||
ossObject.setBucketName(path.substring(0, splitIndex));
|
||||
ossObject.setKey(path.substring(splitIndex + 1));
|
||||
}
|
||||
}
|
||||
return ossObject;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,7 +26,7 @@ knife4j:
|
||||
|
||||
zlt:
|
||||
file-server:
|
||||
type: cos
|
||||
type: oss
|
||||
#fdfs:
|
||||
# web-url: ${zlt.fdfs.web-url}
|
||||
s3:
|
||||
@@ -40,6 +40,11 @@ zlt:
|
||||
endpoint: ${zlt.cos.endpoint}
|
||||
region: ${zlt.cos.region}
|
||||
bucketName: ${zlt.cos.bucketName}
|
||||
oss:
|
||||
secretId: ${zlt.oss.secretId}
|
||||
secretKey: ${zlt.oss.secretKey}
|
||||
endpoint: ${zlt.oss.endpoint}
|
||||
bucketName: ${zlt.oss.bucketName}
|
||||
#多租户配置
|
||||
tenant:
|
||||
enable: true
|
||||
|
||||
@@ -4,7 +4,7 @@ server:
|
||||
spring:
|
||||
application:
|
||||
name: file-center
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
ip: 119.45.169.13
|
||||
# cloud:
|
||||
# nacos:
|
||||
# discovery:
|
||||
# ip: 119.45.169.13
|
||||
|
||||
+3
-3
@@ -150,6 +150,9 @@ public class OrderController {
|
||||
|
||||
LoginAppUser user = LoginUserContextHolder.getUser();
|
||||
order.setUserId(user.getId());
|
||||
if (order.getCodeId() == null){
|
||||
order.setCodeId("f83be3a9-2888-4000-8cf9-e6acdb3a22cd");
|
||||
}
|
||||
QrCode qrCode = qrCodeService.getByCodeId(order.getCodeId());
|
||||
if (qrCode != null){
|
||||
order.setTourismId(qrCode.getTourismId());
|
||||
@@ -174,9 +177,6 @@ public class OrderController {
|
||||
public Result<PrepayWithRequestPaymentResponse> payOrder(@PathVariable("orderId") Long orderId) {
|
||||
|
||||
SysUser user = userCenterService.findUserById(LoginUserContextHolder.getUser().getId());
|
||||
if (user == null){
|
||||
return Result.failed("登录信息失效");
|
||||
}
|
||||
Order order = orderService.getById(orderId);
|
||||
if (order == null) {
|
||||
return Result.failed("订单数据不存在");
|
||||
|
||||
@@ -35,6 +35,7 @@ public class Order extends SuperEntity {
|
||||
private Integer orderStatus;
|
||||
|
||||
private Date payTime;
|
||||
@Transient
|
||||
private String createdTime;
|
||||
@Transient
|
||||
private String codeId;
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
|
||||
<mapper namespace="com.central.order.mapper.OrderFileMapper">
|
||||
<select id="findList" resultType="com.central.order.model.OrderFile">
|
||||
select * from order_files t
|
||||
select * from order_files t ORDER BY id DESC
|
||||
</select>
|
||||
|
||||
<!-- 动态获取参数采用备参 -->
|
||||
<select id="findListByUser" resultType="com.central.order.model.OrderFile">
|
||||
select * from order_files t WHERE t.user_id = #{param2.userId}
|
||||
select * from order_files t WHERE t.user_id = #{param2.userId} ORDER BY id DESC
|
||||
</select>
|
||||
|
||||
<insert id="insertOrderFile">
|
||||
|
||||
@@ -3,17 +3,17 @@
|
||||
|
||||
<mapper namespace="com.central.order.mapper.OrderMapper">
|
||||
<select id="findList" resultType="com.central.order.model.Order">
|
||||
select * from orders t
|
||||
select * from orders t ORDER BY id DESC
|
||||
</select>
|
||||
|
||||
<!-- 动态获取参数采用备参 -->
|
||||
<select id="findListByUser" resultType="com.central.order.model.Order">
|
||||
select id,order_no,tourism_id,device_sn,workspace_id,code_id,user_id,order_amount,order_status,create_time,update_time from orders t WHERE t.user_id = #{param2.userId}
|
||||
select id,order_no,tourism_id,device_sn,workspace_id,code_id,user_id,order_amount,order_status,create_time,update_time from orders t WHERE t.user_id = #{param2.userId} ORDER BY id DESC
|
||||
</select>
|
||||
|
||||
<!-- 根据订单状态查询订单列表 -->
|
||||
<select id="getOrdersByStatus" resultMap="OrderResultMap">
|
||||
SELECT * FROM orders WHERE order_status = #{status}
|
||||
SELECT * FROM orders WHERE order_status = #{status} ORDER BY id DESC
|
||||
</select>
|
||||
<!-- 新增订单 -->
|
||||
<insert id="insertOrder" keyProperty="order_id" useGeneratedKeys="true">
|
||||
|
||||
Reference in New Issue
Block a user