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,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">