diff --git a/zlt-business/device-center/src/main/resources/bootstrap.yml b/zlt-business/device-center/src/main/resources/bootstrap.yml index 4db8cff8..73af4561 100644 --- a/zlt-business/device-center/src/main/resources/bootstrap.yml +++ b/zlt-business/device-center/src/main/resources/bootstrap.yml @@ -4,6 +4,10 @@ server: spring: application: name: device-center + cloud: + nacos: + discovery: + ip: 81.70.164.178 # cloud: # nacos: # discovery: diff --git a/zlt-business/file-center/src/main/java/com/central/file/controller/FileController.java b/zlt-business/file-center/src/main/java/com/central/file/controller/FileController.java index e0d09689..6c3f8c99 100644 --- a/zlt-business/file-center/src/main/java/com/central/file/controller/FileController.java +++ b/zlt-business/file-center/src/main/java/com/central/file/controller/FileController.java @@ -58,4 +58,9 @@ public class FileController { public PageResult findFiles(@RequestParam Map params) { return fileService.findList(params); } + + @GetMapping("/files/{id}") + public String getViewUrl(@PathVariable String id) { + return fileService.getViewUrl(id); + } } diff --git a/zlt-business/file-center/src/main/java/com/central/file/service/IFileService.java b/zlt-business/file-center/src/main/java/com/central/file/service/IFileService.java index 2e44595f..361b0096 100644 --- a/zlt-business/file-center/src/main/java/com/central/file/service/IFileService.java +++ b/zlt-business/file-center/src/main/java/com/central/file/service/IFileService.java @@ -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 upload(MultipartFile file ) throws Exception; - + PageResult findList(Map params); void delete(String id); void out(String id, OutputStream os); + + String getViewUrl(String id); } diff --git a/zlt-business/file-center/src/main/java/com/central/file/service/impl/CosService.java b/zlt-business/file-center/src/main/java/com/central/file/service/impl/CosService.java index 24f80dfc..7e3e722f 100644 --- a/zlt-business/file-center/src/main/java/com/central/file/service/impl/CosService.java +++ b/zlt-business/file-center/src/main/java/com/central/file/service/impl/CosService.java @@ -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); + } } diff --git a/zlt-business/file-center/src/main/java/com/central/file/service/impl/FastdfsService.java b/zlt-business/file-center/src/main/java/com/central/file/service/impl/FastdfsService.java index a931af9a..bf2c6e4b 100644 --- a/zlt-business/file-center/src/main/java/com/central/file/service/impl/FastdfsService.java +++ b/zlt-business/file-center/src/main/java/com/central/file/service/impl/FastdfsService.java @@ -41,4 +41,9 @@ public class FastdfsService extends AbstractIFileService { @Override public void out(String id, OutputStream os) { } + + @Override + public String getViewUrl(String id) { + return ""; + } } diff --git a/zlt-business/file-center/src/main/java/com/central/file/service/impl/S3Service.java b/zlt-business/file-center/src/main/java/com/central/file/service/impl/S3Service.java index a6dd4b86..4b2e2e2a 100644 --- a/zlt-business/file-center/src/main/java/com/central/file/service/impl/S3Service.java +++ b/zlt-business/file-center/src/main/java/com/central/file/service/impl/S3Service.java @@ -53,6 +53,11 @@ public class S3Service extends AbstractIFileService { } } + @Override + public String getViewUrl(String id) { + return ""; + } + @Setter @Getter private class S3Object { diff --git a/zlt-business/file-center/src/main/resources/bootstrap.yml b/zlt-business/file-center/src/main/resources/bootstrap.yml index fd60207c..ae6f04e8 100644 --- a/zlt-business/file-center/src/main/resources/bootstrap.yml +++ b/zlt-business/file-center/src/main/resources/bootstrap.yml @@ -3,4 +3,8 @@ server: spring: application: - name: file-center \ No newline at end of file + name: file-center +# cloud: +# nacos: +# discovery: +# ip: 119.45.169.13 diff --git a/zlt-business/order-center/pom.xml b/zlt-business/order-center/pom.xml index b1cc513a..3cb07ebd 100644 --- a/zlt-business/order-center/pom.xml +++ b/zlt-business/order-center/pom.xml @@ -96,6 +96,11 @@ 0.2.15 + + com.squareup.okhttp3 + okhttp + 4.9.1 + com.github.binarywang weixin-java-miniapp diff --git a/zlt-business/order-center/src/main/java/com/central/order/controller/OrderFileController.java b/zlt-business/order-center/src/main/java/com/central/order/controller/OrderFileController.java index 5f430e85..90a06b54 100644 --- a/zlt-business/order-center/src/main/java/com/central/order/controller/OrderFileController.java +++ b/zlt-business/order-center/src/main/java/com/central/order/controller/OrderFileController.java @@ -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 createOrder(@RequestBody OrderFile orderFile) { + public Result 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> getOrderFiles(@PathVariable("orderNo") String orderNo) { + List 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); + } + } diff --git a/zlt-business/order-center/src/main/java/com/central/order/controller/WeChatMessageController.java b/zlt-business/order-center/src/main/java/com/central/order/controller/WeChatMessageController.java new file mode 100644 index 00000000..6a92f8fc --- /dev/null +++ b/zlt-business/order-center/src/main/java/com/central/order/controller/WeChatMessageController.java @@ -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(); +// } +//} diff --git a/zlt-business/order-center/src/main/java/com/central/order/controller/WxPayController.java b/zlt-business/order-center/src/main/java/com/central/order/controller/WxPayController.java index 168f5096..addb8bd4 100644 --- a/zlt-business/order-center/src/main/java/com/central/order/controller/WxPayController.java +++ b/zlt-business/order-center/src/main/java/com/central/order/controller/WxPayController.java @@ -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 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); } diff --git a/zlt-business/order-center/src/main/java/com/central/order/controller/WxSubscribeMessageController.java b/zlt-business/order-center/src/main/java/com/central/order/controller/WxSubscribeMessageController.java deleted file mode 100644 index 72100cae..00000000 --- a/zlt-business/order-center/src/main/java/com/central/order/controller/WxSubscribeMessageController.java +++ /dev/null @@ -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 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 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; -// } -// } -//} diff --git a/zlt-business/order-center/src/main/java/com/central/order/controller/WxTemplateMessageController.java b/zlt-business/order-center/src/main/java/com/central/order/controller/WxTemplateMessageController.java deleted file mode 100644 index 23fb0c8c..00000000 --- a/zlt-business/order-center/src/main/java/com/central/order/controller/WxTemplateMessageController.java +++ /dev/null @@ -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 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 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; -// } -// } -//} diff --git a/zlt-business/order-center/src/main/java/com/central/order/feign/FileCenterService.java b/zlt-business/order-center/src/main/java/com/central/order/feign/FileCenterService.java new file mode 100644 index 00000000..bb9e40ca --- /dev/null +++ b/zlt-business/order-center/src/main/java/com/central/order/feign/FileCenterService.java @@ -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); +} diff --git a/zlt-business/order-center/src/main/java/com/central/order/feign/fallback/FileCenterServiceFallbackFactory.java b/zlt-business/order-center/src/main/java/com/central/order/feign/fallback/FileCenterServiceFallbackFactory.java new file mode 100644 index 00000000..c319d49d --- /dev/null +++ b/zlt-business/order-center/src/main/java/com/central/order/feign/fallback/FileCenterServiceFallbackFactory.java @@ -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 { + + @Override + public FileCenterService create(Throwable cause) { + return new FileCenterService() { + + @Override + public String getViewUrl(String id) { + return ""; + } + }; + } +} diff --git a/zlt-business/order-center/src/main/java/com/central/order/model/OrderFile.java b/zlt-business/order-center/src/main/java/com/central/order/model/OrderFile.java index ad2c6bcc..39a237a2 100644 --- a/zlt-business/order-center/src/main/java/com/central/order/model/OrderFile.java +++ b/zlt-business/order-center/src/main/java/com/central/order/model/OrderFile.java @@ -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; diff --git a/zlt-business/order-center/src/main/resources/bootstrap.yml b/zlt-business/order-center/src/main/resources/bootstrap.yml index 76ca792e..9f81053a 100644 --- a/zlt-business/order-center/src/main/resources/bootstrap.yml +++ b/zlt-business/order-center/src/main/resources/bootstrap.yml @@ -7,5 +7,9 @@ spring: # cloud: # nacos: # discovery: +# ip: 119.45.169.13 +# cloud: +# nacos: +# discovery: # metadata: # version: zlt diff --git a/zlt-business/order-center/src/main/resources/mapper/OrderFileMapper.xml b/zlt-business/order-center/src/main/resources/mapper/OrderFileMapper.xml index 17812de3..1c92fb9e 100644 --- a/zlt-business/order-center/src/main/resources/mapper/OrderFileMapper.xml +++ b/zlt-business/order-center/src/main/resources/mapper/OrderFileMapper.xml @@ -16,7 +16,7 @@