feat[订单图片模块]:缩略图生成访问url,订单图片上传等逻辑

This commit is contained in:
2025-01-17 02:14:38 +08:00
parent 7dfb4ce12a
commit 59d28e53f8
25 changed files with 272 additions and 134 deletions
@@ -4,6 +4,10 @@ server:
spring:
application:
name: device-center
cloud:
nacos:
discovery:
ip: 81.70.164.178
# cloud:
# nacos:
# discovery:
@@ -58,4 +58,9 @@ public class FileController {
public PageResult<FileInfo> findFiles(@RequestParam Map<String, Object> params) {
return fileService.findList(params);
}
@GetMapping("/files/{id}")
public String getViewUrl(@PathVariable String id) {
return fileService.getViewUrl(id);
}
}
@@ -1,13 +1,12 @@
package com.central.file.service;
import java.io.OutputStream;
import java.util.Map;
import com.baomidou.mybatisplus.extension.service.IService;
import com.central.common.model.PageResult;
import com.central.file.model.FileInfo;
import org.springframework.web.multipart.MultipartFile;
import com.central.file.model.FileInfo;
import java.io.OutputStream;
import java.util.Map;
/**
* 文件service
@@ -16,10 +15,12 @@ import com.central.file.model.FileInfo;
*/
public interface IFileService extends IService<FileInfo> {
FileInfo upload(MultipartFile file ) throws Exception;
PageResult<FileInfo> findList(Map<String, Object> params);
void delete(String id);
void out(String id, OutputStream os);
String getViewUrl(String id);
}
@@ -7,8 +7,6 @@ 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;
@@ -53,11 +51,13 @@ public class CosService extends AbstractIFileService {
}
}
@Setter
@Getter
private class S3Object {
private String bucketName;
private String objectName;
@Override
public String getViewUrl(String fileId) {
FileInfo fileInfo = baseMapper.selectById(fileId);
if (fileInfo != null) {
return cosTemplate.getViewUrl(fileInfo.getName());
}
return null;
}
private COSObject parsePath(String path) {
@@ -71,4 +71,9 @@ public class CosService extends AbstractIFileService {
}
return cosObject;
}
private String getThumbnailFile(COSObject cosObject) {
return cosTemplate.getViewUrl(cosObject.getBucketName(),cosObject.getKey(),1000);
}
}
@@ -41,4 +41,9 @@ public class FastdfsService extends AbstractIFileService {
@Override
public void out(String id, OutputStream os) {
}
@Override
public String getViewUrl(String id) {
return "";
}
}
@@ -53,6 +53,11 @@ public class S3Service extends AbstractIFileService {
}
}
@Override
public String getViewUrl(String id) {
return "";
}
@Setter
@Getter
private class S3Object {
@@ -3,4 +3,8 @@ server:
spring:
application:
name: file-center
name: file-center
# cloud:
# nacos:
# discovery:
# ip: 119.45.169.13
+5
View File
@@ -96,6 +96,11 @@
<version>0.2.15</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.9.1</version>
</dependency>
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-miniapp</artifactId>
@@ -4,6 +4,7 @@ import com.central.common.context.LoginUserContextHolder;
import com.central.common.model.LoginAppUser;
import com.central.common.model.PageResult;
import com.central.common.model.Result;
import com.central.order.feign.FileCenterService;
import com.central.order.model.OrderFile;
import com.central.order.service.IOrderFileService;
import io.swagger.v3.oas.annotations.Operation;
@@ -14,8 +15,10 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
@@ -34,6 +37,9 @@ public class OrderFileController {
@Autowired
private IOrderFileService orderFileService;
@Autowired
private FileCenterService fileCenterService;
/**
* 列表
*/
@@ -48,7 +54,7 @@ public class OrderFileController {
}
@PostMapping
public Result<OrderFile> createOrder(@RequestBody OrderFile orderFile) {
public Result<OrderFile> createOrderFile(@RequestBody OrderFile orderFile) {
LoginAppUser user = LoginUserContextHolder.getUser();
orderFile.setUserId(user.getId());
@@ -68,4 +74,18 @@ public class OrderFileController {
return Result.succeed(orderFile,"获取成功");
}
@GetMapping("/{orderNo}")
public Result<List<OrderFile>> getOrderFiles(@PathVariable("orderNo") String orderNo) {
List<OrderFile> orderFiles = orderFileService.getOrderFileByOrderNo(orderNo);
if (!CollectionUtils.isEmpty(orderFiles)) {
for (OrderFile orderFile : orderFiles) {
String viewUrl = fileCenterService.getViewUrl(orderFile.getFileId());
orderFile.setViewUrl(viewUrl);
}
}else {
return Result.failed("暂无数据");
}
return Result.succeed(orderFiles);
}
}
@@ -0,0 +1,69 @@
//package com.central.order.controller;
//
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//import org.springframework.web.util.WebUtils;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.security.MessageDigest;
//import java.security.NoSuchAlgorithmException;
//import java.util.Arrays;
//
//@RestController
//@RequestMapping("/wechat")
//public class WeChatMessageController {
//
// @Value("${wechat.token}")
// private String token;
//
// @GetMapping("/message")
// public String verify(HttpServletRequest request, HttpServletResponse response) {
// String signature = request.getParameter("signature");
// String timestamp = request.getParameter("timestamp");
// String nonce = request.getParameter("nonce");
// String echostr = request.getParameter("echostr");
// String[] arr = new String[]{token, timestamp, nonce};
// Arrays.sort(arr);
// StringBuilder content = new StringBuilder();
// for (String s : arr) {
// content.append(s);
// }
// String mySignature = null;
// try {
// mySignature = getSHA1(content.toString());
// } catch (NoSuchAlgorithmException e) {
// e.printStackTrace();
// }
// if (mySignature!= null && mySignature.equals(signature)) {
// return echostr;
// } else {
// return "";
// }
// }
//
// @PostMapping("/message")
// public void receiveMessage(HttpServletRequest request, HttpServletResponse response) {
// try {
// String xmlData = WebUtils.toString(request.getInputStream(), "UTF-8");
// // 对 xmlData 进行解析和处理,可根据业务需求添加相应逻辑
// System.out.println(xmlData);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
//
// private String getSHA1(String str) throws NoSuchAlgorithmException {
// MessageDigest md = MessageDigest.getInstance("SHA1");
// md.update(str.getBytes());
// byte[] digest = md.digest();
// StringBuilder hexStr = new StringBuilder();
// for (byte b : digest) {
// hexStr.append(String.format("%02x", b & 0xFF));
// }
// return hexStr.toString();
// }
//}
@@ -39,7 +39,7 @@ public class WxPayController {
* @return
* @throws IOException
*/
@PostMapping("/payNotify")
@PostMapping("/pay/Notify")
public String wechatPayNotify(HttpServletRequest request) throws IOException {
log.info("------收到微信支付回调通知------");
return payNotify(request);
@@ -81,7 +81,7 @@ public class WxPayController {
.build();
log.info("微信支付回调body信息:{}", requestParam.getBody());
// 初始化 NotificationParser
NotificationParser parser = new NotificationParser((NotificationConfig) notificationConfig);
NotificationParser parser = new NotificationParser(notificationConfig);
// 以支付通知回调为例,验签、解密并转换成 Transaction
log.info("验签参数:{}", JSONObject.toJSONString(requestParam));
Map<String, String> returnMap = new HashMap<>(2);
@@ -106,12 +106,19 @@ public class WxPayController {
log.info("内部订单号【{}】,微信支付订单号【{}】支付未成功", transaction.getOutTradeNo(), transaction.getTransactionId());
return JSONObject.toJSONString(returnMap);
}
// TODO 修改订单信息
Order order = orderService.getOrderByNumber(transaction.getOutTradeNo());
order.setOrderStatus(OrderStatus.PAID.getId());
orderService.updateOrder(order);
returnMap.put("code", "SUCCESS");
returnMap.put("message", "成功");
boolean res = orderService.updateOrder(order);
if (res){
returnMap.put("code", "SUCCESS");
returnMap.put("message", "成功");
}else {
returnMap.put("code", "FAIL");
returnMap.put("message","失败");
}
return JSONObject.toJSONString(returnMap);
}
@@ -1,49 +0,0 @@
//package com.central.order.controller;
//
//import cn.binarywang.wx.miniapp.api.WxMaService;
//import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
//import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Map;
//
//@RestController
//@RequestMapping("/wx/subscribe")
//public class WxSubscribeMessageController {
// private final WxMaService wxMaService = new WxMaServiceImpl();
//
// static {
// wxMaService.setWxMaConfig(new WxMaInMemoryConfig());
// wxMaService.getWxMaConfig().setAppId("YOUR_APPID");
// wxMaService.getWxMaConfig().setAppSecret("YOUR_APPSECRET");
// }
//
// // 接收前端传来的订阅消息发送请求参数,发送订阅消息
// @PostMapping("/send")
// public boolean sendSubscribeMessage(@RequestBody Map<String, Object> requestData) {
// try {
// String openId = (String) requestData.get("openId");
// String templateId = (String) requestData.get("templateId");
//
// WxMaSubscribeMessage subscribeMessage = new WxMaSubscribeMessage();
// subscribeMessage.setTemplateId(templateId);
// subscribeMessage.setToUser(openId);
//
// List<WxMaSubscribeMessage> data = new ArrayList<>();
// // 根据订阅消息模板的关键词设置对应的数据,示例如下(假设模板有两个关键词:keyword1和keyword2)
// data.add(new WxMaSubscribeTemplateData("keyword1", "具体内容1", "#FF0000"));
// data.add(new WxMaSubscribeTemplateData("keyword2", "具体内容2", "#00FF00"));
// subscribeMessage.setData(data);
//
// return wxMaService.getSubscribeMsgService().sendSubscribeMsg(subscribeMessage);
// } catch (Exception e) {
// e.printStackTrace();
// return false;
// }
// }
//}
@@ -1,51 +0,0 @@
//package com.central.order.controller;
//
//import cn.binarywang.wx.miniapp.api.WxMaService;
//import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
//import cn.binarywang.wx.miniapp.bean.WxMaTemplateData;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Map;
//
//@RestController
//@RequestMapping("/wx/template")
//public class WxTemplateMessageController {
// private final WxMaService wxMaService = new WxMaServiceImpl();
//
// static {
// wxMaService.setWxMaConfig(new WxMaInMemoryConfig());
// wxMaService.getWxMaConfig().setAppId("YOUR_APPID");
// wxMaService.getWxMaConfig().setAppSecret("YOUR_APPSECRET");
// }
//
// // 接收前端传来的模板消息发送请求参数,发送模板消息
// @PostMapping("/send")
// public boolean sendTemplateMessage(@RequestBody Map<String, Object> requestData) {
// try {
// String formId = (String) requestData.get("formId");
// String templateId = (String) requestData.get("templateId");
// String openId = (String) requestData.get("openId");
//
// WxMaTemplateMessage templateMessage = new WxMaTemplateMessage();
// templateMessage.setTemplateId(templateId);
// templateMessage.setToUser(openId);
// templateMessage.setFormId(formId);
//
// List<WxMaTemplateData> data = new ArrayList<>();
// // 根据模板的关键词设置对应的数据,示例如下(假设模板有两个关键词:keyword1和keyword2)
// data.add(new WxMaTemplateData("keyword1", "具体内容1", "#FF0000"));
// data.add(new WxMaTemplateData("keyword2", "具体内容2", "#00FF00"));
// templateMessage.setData(data);
//
// return wxMaService.getTemplateMsgService().sendTemplateMsg(templateMessage);
// } catch (Exception e) {
// e.printStackTrace();
// return false;
// }
// }
//}
@@ -0,0 +1,28 @@
package com.central.order.feign;
import com.central.common.constant.ServiceNameConstants;
import com.central.order.feign.fallback.FileCenterServiceFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
/**
* user-center模块远程调用
*
* @author lsl
* @version 1.0
* @description user-center模块远程调用
* @create 2025/1/13
**/
@FeignClient(name = ServiceNameConstants.FILE_SERVICE, fallbackFactory = FileCenterServiceFallbackFactory.class, dismiss404 = true)
public interface FileCenterService {
/**
* 通过ID查询预览地址
*
* @param id 文件ID
* @return
*/
@GetMapping("/files/{id}")
String getViewUrl(@PathVariable("id") String id);
}
@@ -0,0 +1,30 @@
package com.central.order.feign.fallback;
import com.central.order.feign.FileCenterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
/**
* 文件中心调用失败回调
*
* @author lsl
* @version 1.0
* @description 用户中心调用失败回调
* @create 2025/1/17 11:33
**/
@Slf4j
@Component
public class FileCenterServiceFallbackFactory implements FallbackFactory<FileCenterService> {
@Override
public FileCenterService create(Throwable cause) {
return new FileCenterService() {
@Override
public String getViewUrl(String id) {
return "";
}
};
}
}
@@ -7,6 +7,7 @@ import com.central.common.model.SuperEntity;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.Transient;
import java.util.Date;
@@ -27,6 +28,9 @@ public class OrderFile extends SuperEntity {
private String fileId;
private Long userId;
@Transient
private String viewUrl;
// 景区ID
private Long tourismId;
private String filePath;
@@ -7,5 +7,9 @@ spring:
# cloud:
# nacos:
# discovery:
# ip: 119.45.169.13
# cloud:
# nacos:
# discovery:
# metadata:
# version: zlt
@@ -16,7 +16,7 @@
</select>
<select id="getFileByFileId" resultType="com.central.order.model.OrderFile">
SELECT * FROM order_files WHERE file_id = #{fileId}
SELECT * FROM order_files WHERE id = #{fileId}
</select>
<select id="getOrderFilesByUserId" resultType="com.central.order.model.OrderFile">
@@ -7,5 +7,9 @@ spring:
# cloud:
# nacos:
# discovery:
# ip: 124.222.128.40
# cloud:
# nacos:
# discovery:
# metadata:
# version: zlt
@@ -20,4 +20,6 @@ public interface ServiceNameConstants {
String UAA_SERVICE = "uaa-center";
String DEVICE_SERVICE = "device-center";
String FILE_SERVICE = "file-center";
}
@@ -117,6 +117,31 @@ public class CosTemplate implements InitializingBean {
return url.toString();
}
/**
* 获取预览地址
* @param objectName 对象名
* @param expires 有效时间(分钟),最大7天有效
* @return
*/
public String getViewUrl(String objectName, int expires) {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MINUTE, expires);
URL url = cosClient.generatePresignedUrl(fileProperties.getCos().getBucketName(), objectName, cal.getTime());
return url.toString();
}
/**
* 获取预览地址
* @param objectName 对象名
* @return
*/
public String getViewUrl(String objectName) {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MINUTE, 7);
URL url = cosClient.generatePresignedUrl(fileProperties.getCos().getBucketName(), objectName, cal.getTime());
return url.toString();
}
public void out(String objectName, OutputStream os) {
out(fileProperties.getS3().getBucketName(), objectName, os);
}
@@ -31,10 +31,10 @@ zlt.s3.bucketName=gofly
zlt.s3.region=us-east-1
#### cos配置
zlt.cos.secretId=AKIDBF6whIkz2tcCZmsnW3OUN0QcZKsDKCrH
zlt.cos.secretKey=FRTJxdFgy8IKAl7F8nDoHagXCdrtiKhq
zlt.cos.endpoint=gofly-1301649813.cos.ap-nanjing.myqcloud.com
zlt.cos.bucketName=gofly-1301649813
zlt.cos.secretId=AKIDkMn6B3h7KJ5dIkyzpRr7C6mFUqFWbu1u
zlt.cos.secretKey=jDThssfEZieS4S8bqsgIiAUdbXVVYgdQ
zlt.cos.endpoint=gofly-1333114031.cos.ap-nanjing.myqcloud.com
zlt.cos.bucketName=gofly-1333114031
zlt.cos.region=ap-nanjing
##### 日志链路追踪
@@ -51,7 +51,11 @@ mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
zlt.security.tencent.appId=wx0c3cc6f1d297644d
zlt.security.tencent.appSecret=9d344e6c86b42105b6e4a018f242e233
zlt.security.tencent.token=YPbzETU8oe3XguGgwtA4g1DqlFKvw7pT
zlt.security.tencent.encodingAESKey=YPbzETU8oe3XguGgwtA4g1DqlFKvw7pTZiyHTxCiQxh
zlt.security.tencent.templateId=YOUR_TEMPLATE_ID
zlt.security.tencent.jscode2sessionUrl=https://api.weixin.qq.com/sns/jscode2session
zlt.security.tencent.accessTokenUrl=https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${zlt.security.tencent.appId}&secret=${zlt.security.tencent.appSecret}
# 微信支付商户号
zlt.wxpay.merchantId=1703796518
@@ -60,7 +64,7 @@ zlt.wxpay.merchantSerialNumber=11F4AC03C50EB582D3EDE082591D1F9A65388D51
# 微信支付申请的应用ID
zlt.wxpay.appId=wx30a3c8de94a85584
# 微信支付异步通知地址(需外网可访问且与微信支付平台配置一致)
zlt.wxpay.notifyUrl=http://your_domain/weixin/pay/notify
zlt.wxpay.notifyUrl=http://img.goflytec.com/api-order/wechat/pay/notify
# 商户API私钥路径
zlt.wxpay.privateKeyPath=D:\\wx\\WXCertUtil\\cert\\1703796518_20250114_cert\\apiclient_key.pem
# 商户APIV3密钥
@@ -32,10 +32,10 @@ zlt.s3.endpoint=http://81.70.164.178:9000
zlt.s3.bucketName=gofly
#### cos配置
zlt.cos.secretId=AKIDBF6whIkz2tcCZmsnW3OUN0QcZKsDKCrH
zlt.cos.secretKey=FRTJxdFgy8IKAl7F8nDoHagXCdrtiKhq
zlt.cos.endpoint=gofly-1301649813.cos.ap-nanjing.myqcloud.com
zlt.cos.bucketName=gofly-1301649813
zlt.cos.secretId=AKIDkMn6B3h7KJ5dIkyzpRr7C6mFUqFWbu1u
zlt.cos.secretKey=jDThssfEZieS4S8bqsgIiAUdbXVVYgdQ
zlt.cos.endpoint=gofly-1333114031.cos.ap-nanjing.myqcloud.com
zlt.cos.bucketName=gofly-1333114031
zlt.cos.region=ap-nanjing
##### 日志链路追踪
@@ -1,16 +1,19 @@
########################## bootstrap级别通用配置 ##########################
# 默认开发环境
spring.profiles.active=prod
spring.profiles.active=dev
##### nacos(注册中心和配置中心)地址
spring.cloud.nacos.server-addr=47.94.136.130:8848
#spring.cloud.nacos.server-addr=127.0.0.1:8848
#spring.cloud.nacos.server-addr=47.94.136.130:8848
spring.cloud.nacos.server-addr=127.0.0.1:8848
spring.cloud.nacos.username=nacos
spring.cloud.nacos.password=nacos
spring.cloud.nacos.config.file-extension=yml
spring.cloud.nacos.config.shared-configs[0].data-id=common.yml
spring.cloud.nacos.config.shared-configs[0].refresh=true
spring.cloud.nacos.config.server-addr=${spring.cloud.nacos.server-addr}
spring.cloud.nacos.config.namespace=application
##### spring-boot-actuator配置
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
+5 -1
View File
@@ -8,9 +8,13 @@ server:
spring:
application:
name: uaa-server
# cloud:
# nacos:
# discovery:
# ip: 124.222.128.40
encrypt:
key-store:
location: classpath:zlt.jks
secret: zlt!@#$
alias: zlt
alias: zlt