Browse Source

修改:uploadPath的配置值和的file路径拼接

main
科技小王子 3 weeks ago
parent
commit
7b108828a8
  1. 8
      src/main/java/com/gxwebsoft/bszx/service/impl/BszxBmServiceImpl.java
  2. 8
      src/main/java/com/gxwebsoft/bszx/service/impl/BszxPayServiceImpl.java
  3. 6
      src/main/java/com/gxwebsoft/common/core/utils/MyQrCodeUtil.java
  4. 55
      src/main/java/com/gxwebsoft/common/core/utils/WechatPayConfigValidator.java
  5. 6
      src/main/java/com/gxwebsoft/house/service/impl/HouseInfoServiceImpl.java
  6. 2
      src/main/java/com/gxwebsoft/shop/service/OrderBusinessService.java
  7. 2
      src/main/resources/application-prod.yml

8
src/main/java/com/gxwebsoft/bszx/service/impl/BszxBmServiceImpl.java

@ -133,13 +133,13 @@ public class BszxBmServiceImpl extends ServiceImpl<BszxBmMapper, BszxBm> impleme
//执行图片合并 //执行图片合并
combiner.combine(); combiner.combine();
if (!FileUtil.exist(uploadPath + "file/poster/" + item.getTenantId() + "/bm")) {
FileUtil.mkdir(uploadPath + "file/poster/" + item.getTenantId() + "/bm");
if (!FileUtil.exist(uploadPath + "/file/poster/" + item.getTenantId() + "/bm")) {
FileUtil.mkdir(uploadPath + "/file/poster/" + item.getTenantId() + "/bm");
} }
String basePath = "/poster/" + item.getTenantId() + "/bm/big-" + item.getId() + ".jpg"; String basePath = "/poster/" + item.getTenantId() + "/bm/big-" + item.getId() + ".jpg";
String smallPath = "/poster/" + item.getTenantId() + "/bm/" + item.getId() + ".jpg"; String smallPath = "/poster/" + item.getTenantId() + "/bm/" + item.getId() + ".jpg";
String filename = uploadPath + "file" + basePath;
String smallFileName = uploadPath + "file" + smallPath;
String filename = uploadPath + "/file" + basePath;
String smallFileName = uploadPath + "/file" + smallPath;
combiner.save(filename); combiner.save(filename);
File input = new File(filename); File input = new File(filename);

8
src/main/java/com/gxwebsoft/bszx/service/impl/BszxPayServiceImpl.java

@ -123,13 +123,13 @@ public class BszxPayServiceImpl extends ServiceImpl<BszxPayMapper, BszxPay> impl
//执行图片合并 //执行图片合并
combiner.combine(); combiner.combine();
if (!FileUtil.exist(uploadPath + "file/poster/" + payCert.getTenantId() + "/pay")) {
FileUtil.mkdir(uploadPath + "file/poster/" + payCert.getTenantId() + "/pay");
if (!FileUtil.exist(uploadPath + "/file/poster/" + payCert.getTenantId() + "/pay")) {
FileUtil.mkdir(uploadPath + "/file/poster/" + payCert.getTenantId() + "/pay");
} }
String basePath = "/poster/" + payCert.getTenantId() + "/pay/big-" + id + ".jpg"; String basePath = "/poster/" + payCert.getTenantId() + "/pay/big-" + id + ".jpg";
String smallPath = "/poster/" + payCert.getTenantId() + "/pay/" + id + ".jpg"; String smallPath = "/poster/" + payCert.getTenantId() + "/pay/" + id + ".jpg";
String filename = uploadPath + "file" + basePath;
String smallFileName = uploadPath + "file" + smallPath;
String filename = uploadPath + "/file" + basePath;
String smallFileName = uploadPath + "/file" + smallPath;
combiner.save(filename); combiner.save(filename);
File input = new File(filename); File input = new File(filename);

6
src/main/java/com/gxwebsoft/common/core/utils/MyQrCodeUtil.java

@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
import cn.hutool.extra.qrcode.QrCodeUtil; import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.extra.qrcode.QrConfig; import cn.hutool.extra.qrcode.QrConfig;
import org.springframework.beans.factory.annotation.Value;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
@ -22,6 +23,9 @@ import static com.gxwebsoft.common.core.constants.QRCodeConstants.*;
*/ */
public class MyQrCodeUtil { public class MyQrCodeUtil {
@Value("${config.upload-path}")
private static String uploadPath;
private static final String logoUrl = "https://file.wsdns.cn/20230430/6fa31aca3b0d47af98a149cf2dd26a4f.jpeg"; private static final String logoUrl = "https://file.wsdns.cn/20230430/6fa31aca3b0d47af98a149cf2dd26a4f.jpeg";
/** /**
@ -60,7 +64,7 @@ public class MyQrCodeUtil {
* @return 二维码图片地址 * @return 二维码图片地址
*/ */
public static String createQrCode(String type,Integer id, String content) throws IOException { public static String createQrCode(String type,Integer id, String content) throws IOException {
String filePath = "/www/wwwroot/file.ws/file/qrcode/".concat(type).concat("/");
String filePath = uploadPath + "/file/qrcode/".concat(type).concat("/");
String qrcodeUrl = "https://file.websoft.top/qrcode/".concat(type).concat("/"); String qrcodeUrl = "https://file.websoft.top/qrcode/".concat(type).concat("/");
// 将URL转为BufferedImage // 将URL转为BufferedImage
BufferedImage bufferedImage = ImageIO.read(new URL(logoUrl)); BufferedImage bufferedImage = ImageIO.read(new URL(logoUrl));

55
src/main/java/com/gxwebsoft/common/core/utils/WechatPayConfigValidator.java

@ -3,6 +3,7 @@ package com.gxwebsoft.common.core.utils;
import com.gxwebsoft.common.core.config.CertificateProperties; import com.gxwebsoft.common.core.config.CertificateProperties;
import com.gxwebsoft.common.system.entity.Payment; import com.gxwebsoft.common.system.entity.Payment;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@ -19,6 +20,9 @@ public class WechatPayConfigValidator {
private final CertificateProperties certConfig; private final CertificateProperties certConfig;
private final CertificateLoader certificateLoader; private final CertificateLoader certificateLoader;
@Value("${spring.profiles.active}")
private String activeProfile;
public WechatPayConfigValidator(CertificateProperties certConfig, CertificateLoader certificateLoader) { public WechatPayConfigValidator(CertificateProperties certConfig, CertificateLoader certificateLoader) {
this.certConfig = certConfig; this.certConfig = certConfig;
this.certificateLoader = certificateLoader; this.certificateLoader = certificateLoader;
@ -111,19 +115,25 @@ public class WechatPayConfigValidator {
* 验证证书文件 * 验证证书文件
*/ */
private void validateCertificateFiles(Integer tenantId, ValidationResult result) { private void validateCertificateFiles(Integer tenantId, ValidationResult result) {
String tenantCertPath = "dev/wechat/" + tenantId;
String privateKeyPath = tenantCertPath + "/" + certConfig.getWechatPay().getDev().getPrivateKeyFile();
if (!certificateLoader.certificateExists(privateKeyPath)) {
result.addError("证书文件不存在: " + privateKeyPath);
return;
}
if ("dev".equals(activeProfile)) {
// 开发环境证书验证
String tenantCertPath = "dev/wechat/" + tenantId;
String privateKeyPath = tenantCertPath + "/" + certConfig.getWechatPay().getDev().getPrivateKeyFile();
if (!certificateLoader.certificateExists(privateKeyPath)) {
result.addError("证书文件不存在: " + privateKeyPath);
return;
}
try {
String privateKey = certificateLoader.loadCertificatePath(privateKeyPath);
log.info("✅ 证书文件验证通过: {}", privateKey);
} catch (Exception e) {
result.addError("证书文件加载失败: " + e.getMessage());
try {
certificateLoader.loadCertificatePath(privateKeyPath);
log.info("✅ 开发环境证书文件验证通过: {}", privateKeyPath);
} catch (Exception e) {
result.addError("证书文件加载失败: " + e.getMessage());
}
} else {
// 生产环境证书验证 - 跳过文件存在性检查,因为证书路径来自数据库
log.info("✅ 生产环境跳过证书文件存在性验证,使用数据库配置的证书路径");
} }
} }
@ -184,12 +194,21 @@ public class WechatPayConfigValidator {
} }
// 证书文件检查 // 证书文件检查
String tenantCertPath = "dev/wechat/" + tenantId;
String privateKeyPath = tenantCertPath + "/" + certConfig.getWechatPay().getDev().getPrivateKeyFile();
boolean certExists = certificateLoader.certificateExists(privateKeyPath);
report.append("证书文件路径: ").append(privateKeyPath).append("\n");
report.append("证书文件存在: ").append(certExists ? "是" : "否").append("\n");
report.append("当前环境: ").append(activeProfile).append("\n");
if ("dev".equals(activeProfile)) {
String tenantCertPath = "dev/wechat/" + tenantId;
String privateKeyPath = tenantCertPath + "/" + certConfig.getWechatPay().getDev().getPrivateKeyFile();
boolean certExists = certificateLoader.certificateExists(privateKeyPath);
report.append("开发环境证书文件路径: ").append(privateKeyPath).append("\n");
report.append("证书文件存在: ").append(certExists ? "是" : "否").append("\n");
} else {
report.append("生产环境证书路径: 从数据库配置获取\n");
if (payment != null) {
report.append("私钥文件: ").append(payment.getApiclientKey()).append("\n");
report.append("证书文件: ").append(payment.getApiclientCert()).append("\n");
}
}
ValidationResult validation = validateWechatPayConfig(payment, tenantId); ValidationResult validation = validateWechatPayConfig(payment, tenantId);
report.append("配置验证结果: ").append(validation.isValid() ? "通过" : "失败").append("\n"); report.append("配置验证结果: ").append(validation.isValid() ? "通过" : "失败").append("\n");

6
src/main/java/com/gxwebsoft/house/service/impl/HouseInfoServiceImpl.java

@ -182,7 +182,7 @@ public class HouseInfoServiceImpl extends ServiceImpl<HouseInfoMapper, HouseInfo
combiner.combine(); combiner.combine();
// 创建保存目录 // 创建保存目录
String posterDir = uploadPath + "file/poster/" + houseInfo.getTenantId() + "/house";
String posterDir = uploadPath + "/file/poster/" + houseInfo.getTenantId() + "/house";
if (!FileUtil.exist(posterDir)) { if (!FileUtil.exist(posterDir)) {
FileUtil.mkdir(posterDir); FileUtil.mkdir(posterDir);
} }
@ -190,8 +190,8 @@ public class HouseInfoServiceImpl extends ServiceImpl<HouseInfoMapper, HouseInfo
// 生成文件路径 // 生成文件路径
String basePath = "/poster/" + houseInfo.getTenantId() + "/house/big-" + houseInfo.getHouseId() + ".jpg"; String basePath = "/poster/" + houseInfo.getTenantId() + "/house/big-" + houseInfo.getHouseId() + ".jpg";
String smallPath = "/poster/" + houseInfo.getTenantId() + "/house/" + houseInfo.getHouseId() + ".jpg"; String smallPath = "/poster/" + houseInfo.getTenantId() + "/house/" + houseInfo.getHouseId() + ".jpg";
String filename = uploadPath + "file" + basePath;
String smallFileName = uploadPath + "file" + smallPath;
String filename = uploadPath + "/file" + basePath;
String smallFileName = uploadPath + "/file" + smallPath;
// 保存原图 // 保存原图
combiner.save(filename); combiner.save(filename);

2
src/main/java/com/gxwebsoft/shop/service/OrderBusinessService.java

@ -123,7 +123,7 @@ public class OrderBusinessService {
*/ */
private BigDecimal validateAndCalculateTotal(OrderCreateRequest request) { private BigDecimal validateAndCalculateTotal(OrderCreateRequest request) {
if (CollectionUtils.isEmpty(request.getGoodsItems())) { if (CollectionUtils.isEmpty(request.getGoodsItems())) {
throw new BusinessException("订单商品列表不能为空");
throw new BusinessException("订单商品列表不能为空");
} }
BigDecimal total = BigDecimal.ZERO; BigDecimal total = BigDecimal.ZERO;

2
src/main/resources/application-prod.yml

@ -45,7 +45,7 @@ mqtt:
config: config:
# 生产环境接口 # 生产环境接口
server-url: https://server.websoft.top/api server-url: https://server.websoft.top/api
upload-path: /www/wwwroot/file.ws/
upload-path: /www/wwwroot/file.ws
# 阿里云OSS云存储 # 阿里云OSS云存储
endpoint: https://oss-cn-shenzhen.aliyuncs.com endpoint: https://oss-cn-shenzhen.aliyuncs.com

Loading…
Cancel
Save