refactor(puzzle): 重构元素DTO及新增元素基类

- 将ElementCreateRequest和PuzzleElementDTO中的elementType从Integer改为String
- 删除所有类型特定字段,新增config和configMap支持JSON配置
- 新增BaseElement抽象基类定义元素通用行为
- 添加ElementConfig接口和具体实现类ImageConfig、TextConfig
- 创建ElementFactory工厂类和ElementRegistrar注册器
- 新增ElementType枚举和ElementValidationException异常类
- 实现ImageElement和TextElement具体元素类
- 添加Position位置信息封装类
This commit is contained in:
2025-11-18 08:13:38 +08:00
parent 5c49a5af9e
commit 3d361200b0
28 changed files with 2988 additions and 615 deletions

View File

@@ -2,13 +2,19 @@ package com.ycwl.basic.puzzle.dto;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Map;
/**
* 创建元素请求DTO
* 创建元素请求DTO(重构版)
*
* 重构说明:
* - elementType从Integer改为String(TEXT、IMAGE等)
* - 删除所有type-specific字段
* - 新增config和configMap支持JSON配置
* - 支持两种方式:直接传JSON字符串 或 传Map对象
*
* @author Claude
* @since 2025-01-17
* @since 2025-01-18
*/
@Data
public class ElementCreateRequest {
@@ -19,123 +25,76 @@ public class ElementCreateRequest {
private Long templateId;
/**
* 元素类型:1-图片 2-文字
* 元素类型(TEXT-文字 IMAGE-图片 QRCODE-二维码等)
*/
private Integer elementType;
private String elementType;
/**
* 元素标识
* 元素标识(用于动态数据映射)
*/
private String elementKey;
/**
* 元素名称
* 元素名称(便于管理识别)
*/
private String elementName;
// ===== 位置和布局属性 =====
// ===== 位置和布局属性(所有元素通用) =====
/**
* X坐标
* X坐标(相对于画布左上角,像素)
*/
private Integer xPosition;
/**
* Y坐标
* Y坐标(相对于画布左上角,像素)
*/
private Integer yPosition;
/**
* 宽度
* 宽度(像素)
*/
private Integer width;
/**
* 高度
* 高度(像素)
*/
private Integer height;
/**
* 层级
* 层级(数值越大越靠上)
*/
private Integer zIndex;
/**
* 旋转角度
* 旋转角度(0-360度,顺时针)
*/
private Integer rotation;
/**
* 不透明度
* 不透明度(0-100,100为完全不透明)
*/
private Integer opacity;
// ===== 图片元素属性 =====
// ===== JSON配置(二选一) =====
/**
* 默认图片URL
* JSON配置字符串(直接传入JSON字符串)
*
* 示例:
* - 文字元素:"{\"defaultText\":\"用户名\", \"fontFamily\":\"微软雅黑\", \"fontSize\":14}"
* - 图片元素:"{\"defaultImageUrl\":\"https://...\", \"imageFitMode\":\"COVER\", \"borderRadius\":10}"
*/
private String defaultImageUrl;
private String config;
/**
* 图片适配模式
* JSON配置Map(传入Map对象,框架自动序列化为JSON)
*
* 示例:
* Map<String, Object> configMap = new HashMap<>();
* configMap.put("defaultText", "用户名");
* configMap.put("fontSize", 14);
* request.setConfigMap(configMap);
*/
private String imageFitMode;
/**
* 圆角半径
*/
private Integer borderRadius;
// ===== 文字元素属性 =====
/**
* 默认文本内容
*/
private String defaultText;
/**
* 字体
*/
private String fontFamily;
/**
* 字号
*/
private Integer fontSize;
/**
* 字体颜色
*/
private String fontColor;
/**
* 字重
*/
private String fontWeight;
/**
* 字体样式
*/
private String fontStyle;
/**
* 对齐方式
*/
private String textAlign;
/**
* 行高倍数
*/
private BigDecimal lineHeight;
/**
* 最大行数
*/
private Integer maxLines;
/**
* 文本装饰
*/
private String textDecoration;
private Map<String, Object> configMap;
}