refactor(bszx): 重构报名和支付海报生成逻辑
- 提取共用的 ImageCombiner 初始化和处理逻辑 - 优化文件路径生成和质量压缩流程- 添加 @NotNull 注解提高代码可读性 - 修改时间格式化方式,使用 LocalDateTime - 更新 Jackson 配置,支持 LocalDateTime序列化和反序列化- 添加文件服务器地址配置
This commit is contained in:
@@ -23,6 +23,7 @@ import com.gxwebsoft.common.core.utils.FileServerUtil;
|
||||
import com.gxwebsoft.common.core.utils.ImageUtil;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -113,9 +114,33 @@ public class BszxBmServiceImpl extends ServiceImpl<BszxBmMapper, BszxBm> impleme
|
||||
return "https://oss.wsdns.cn/20250908/f8b88d734aac4006a89b9aeb5c3f4f75.png";
|
||||
}
|
||||
|
||||
|
||||
// 百色中学
|
||||
// Font font = new Font("阿里巴巴普惠体", Font.PLAIN, 40);
|
||||
//合成器(指定背景图和输出格式,整个图片的宽高和相关计算依赖于背景图,所以背景图的大小是个基准)
|
||||
final ImageCombiner combiner = getImageCombiner(item, article);
|
||||
|
||||
if (!FileUtil.exist(uploadPath + "/poster/" + item.getTenantId() + "/bm")) {
|
||||
FileUtil.mkdir(uploadPath + "/poster/" + item.getTenantId() + "/bm");
|
||||
}
|
||||
String basePath = "/poster/" + item.getTenantId() + "/bm/big-" + item.getId() + ".jpg";
|
||||
String smallPath = "/poster/" + item.getTenantId() + "/bm/" + item.getId() + ".jpg";
|
||||
String filename = uploadPath + basePath;
|
||||
String smallFileName = uploadPath + smallPath;
|
||||
combiner.save(filename);
|
||||
|
||||
File input = new File(filename);
|
||||
File output = new File(smallFileName);
|
||||
ImageUtil.adjustQuality(input, output, 0.8f);
|
||||
if(input.exists()){
|
||||
input.delete();
|
||||
}
|
||||
return fileServer + smallPath + "?r=" + RandomUtil.randomNumbers(4);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static ImageCombiner getImageCombiner(BszxBm item, CmsArticle article) throws Exception {
|
||||
ImageCombiner combiner = new ImageCombiner(article.getAddress(), OutputFormat.JPG);
|
||||
//加文本元素:姓名
|
||||
// if (item.getType().equals(0)) {
|
||||
@@ -140,25 +165,7 @@ public class BszxBmServiceImpl extends ServiceImpl<BszxBmMapper, BszxBm> impleme
|
||||
// combiner.addImageElement("https://oss.wsdns.cn/20250304/6936b109b09b4919a3498ac5027e728b.png", 600, 1420);
|
||||
//执行图片合并
|
||||
combiner.combine();
|
||||
|
||||
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 smallPath = "/poster/" + item.getTenantId() + "/bm/" + item.getId() + ".jpg";
|
||||
String filename = uploadPath + "/file" + basePath;
|
||||
String smallFileName = uploadPath + "/file" + smallPath;
|
||||
combiner.save(filename);
|
||||
|
||||
File input = new File(filename);
|
||||
File output = new File(smallFileName);
|
||||
ImageUtil.adjustQuality(input, output, 0.8f);
|
||||
if(input.exists()){
|
||||
input.delete();
|
||||
}
|
||||
return fileServer + smallPath + "?r=" + RandomUtil.randomNumbers(4);
|
||||
}
|
||||
return null;
|
||||
return combiner;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -124,13 +124,14 @@ public class BszxPayServiceImpl extends ServiceImpl<BszxPayMapper, BszxPay> impl
|
||||
//执行图片合并
|
||||
combiner.combine();
|
||||
|
||||
if (!FileUtil.exist(uploadPath + "/file/poster/" + payCert.getTenantId() + "/pay")) {
|
||||
FileUtil.mkdir(uploadPath + "/file/poster/" + payCert.getTenantId() + "/pay");
|
||||
if (!FileUtil.exist(uploadPath + "/poster/" + payCert.getTenantId() + "/pay")) {
|
||||
FileUtil.mkdir(uploadPath + "/poster/" + payCert.getTenantId() + "/pay");
|
||||
}
|
||||
String basePath = "/poster/" + payCert.getTenantId() + "/pay/big-" + id + ".jpg";
|
||||
String smallPath = "/poster/" + payCert.getTenantId() + "/pay/" + id + ".jpg";
|
||||
String filename = uploadPath + "/file" + basePath;
|
||||
String smallFileName = uploadPath + "/file" + smallPath;
|
||||
String filename = uploadPath + basePath;
|
||||
String smallFileName = uploadPath + smallPath;
|
||||
System.out.println("smallFileName = " + smallFileName);
|
||||
combiner.save(filename);
|
||||
|
||||
File input = new File(filename);
|
||||
@@ -139,8 +140,9 @@ public class BszxPayServiceImpl extends ServiceImpl<BszxPayMapper, BszxPay> impl
|
||||
if (input.exists()) {
|
||||
input.delete();
|
||||
}
|
||||
return fileServer + smallPath + "?r=" + RandomUtil.randomNumbers(4);
|
||||
return fileServer + smallPath + "?v=" + RandomUtil.randomNumbers(4);
|
||||
}
|
||||
// 百色中学
|
||||
if (ObjectUtil.isNotEmpty(payCert)) {
|
||||
//合成器(指定背景图和输出格式,整个图片的宽高和相关计算依赖于背景图,所以背景图的大小是个基准)
|
||||
ImageCombiner combiner = new ImageCombiner("https://oss.wsdns.cn/20250420/811a380e8e124097aa0940a7c68a1f72.jpeg", OutputFormat.JPG);
|
||||
@@ -171,13 +173,13 @@ public class BszxPayServiceImpl extends ServiceImpl<BszxPayMapper, BszxPay> impl
|
||||
//执行图片合并
|
||||
combiner.combine();
|
||||
|
||||
if (!FileUtil.exist(uploadPath + "/file/poster/" + payCert.getTenantId() + "/pay")) {
|
||||
FileUtil.mkdir(uploadPath + "/file/poster/" + payCert.getTenantId() + "/pay");
|
||||
if (!FileUtil.exist(uploadPath + "/poster/" + payCert.getTenantId() + "/pay")) {
|
||||
FileUtil.mkdir(uploadPath + "/poster/" + payCert.getTenantId() + "/pay");
|
||||
}
|
||||
String basePath = "/poster/" + payCert.getTenantId() + "/pay/big-" + id + ".jpg";
|
||||
String smallPath = "/poster/" + payCert.getTenantId() + "/pay/" + id + ".jpg";
|
||||
String filename = uploadPath + "/file" + basePath;
|
||||
String smallFileName = uploadPath + "/file" + smallPath;
|
||||
String filename = uploadPath + basePath;
|
||||
String smallFileName = uploadPath + smallPath;
|
||||
combiner.save(filename);
|
||||
|
||||
File input = new File(filename);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.gxwebsoft.cms.param;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.gxwebsoft.common.core.annotation.QueryField;
|
||||
import com.gxwebsoft.common.core.annotation.QueryType;
|
||||
import com.gxwebsoft.common.core.web.BaseParam;
|
||||
@@ -10,6 +11,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -78,7 +80,8 @@ public class CmsWebsiteParam extends BaseParam {
|
||||
private Integer version;
|
||||
|
||||
@Schema(description = "服务到期时间")
|
||||
private String expirationTime;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime expirationTime;
|
||||
|
||||
@Schema(description = "模版ID")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
|
||||
@@ -67,9 +67,9 @@ public class CmsWebsiteServiceImplHelper {
|
||||
}
|
||||
|
||||
// 时间字段 - 格式化为字符串
|
||||
if (website.getExpirationTime() != null) {
|
||||
vo.setExpirationTime(website.getExpirationTime().format(formatter));
|
||||
}
|
||||
// if (website.getExpirationTime() != null) {
|
||||
// vo.setExpirationTime(website.getExpirationTime().format(formatter));
|
||||
// }
|
||||
|
||||
// 过期相关信息
|
||||
vo.setExpired(website.getExpired());
|
||||
|
||||
@@ -4,10 +4,15 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* Jackson配置类 - 强制配置版本
|
||||
* 确保JavaTimeModule被正确注册并覆盖Spring Boot的自动配置
|
||||
@@ -18,6 +23,11 @@ import org.springframework.context.annotation.Primary;
|
||||
@Configuration
|
||||
public class JacksonConfig {
|
||||
|
||||
/**
|
||||
* 日期时间格式
|
||||
*/
|
||||
private static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
/**
|
||||
* 强制配置ObjectMapper,确保JavaTimeModule被正确注册
|
||||
*/
|
||||
@@ -26,8 +36,16 @@ public class JacksonConfig {
|
||||
public ObjectMapper objectMapper() {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
// 创建并配置JavaTimeModule
|
||||
JavaTimeModule javaTimeModule = new JavaTimeModule();
|
||||
|
||||
// 配置LocalDateTime的序列化和反序列化格式
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_TIME_FORMAT);
|
||||
javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(formatter));
|
||||
javaTimeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(formatter));
|
||||
|
||||
// 注册JavaTimeModule - 这是关键
|
||||
mapper.registerModule(new JavaTimeModule());
|
||||
mapper.registerModule(javaTimeModule);
|
||||
|
||||
// 禁用将日期写为时间戳
|
||||
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
@@ -43,6 +61,13 @@ public class JacksonConfig {
|
||||
*/
|
||||
@Bean
|
||||
public JavaTimeModule javaTimeModule() {
|
||||
return new JavaTimeModule();
|
||||
JavaTimeModule module = new JavaTimeModule();
|
||||
|
||||
// 配置LocalDateTime的序列化和反序列化格式
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_TIME_FORMAT);
|
||||
module.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(formatter));
|
||||
module.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(formatter));
|
||||
|
||||
return module;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,8 @@ mqtt:
|
||||
|
||||
# 框架配置
|
||||
config:
|
||||
# 文件服务器
|
||||
file-server: https://file-s209.shoplnk.cn
|
||||
# 生产环境接口
|
||||
server-url: https://server.websoft.top/api
|
||||
upload-path: /www/wwwroot/file.ws/
|
||||
|
||||
@@ -26,6 +26,9 @@ spring:
|
||||
write-dates-as-timestamps: false
|
||||
deserialization:
|
||||
fail-on-unknown-properties: false
|
||||
# 启用JSR310模块支持Java 8时间类型
|
||||
modules:
|
||||
- com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
|
||||
|
||||
# 连接池配置
|
||||
datasource:
|
||||
|
||||
Reference in New Issue
Block a user