You've already forked FrameTour-BE
feat(image): 引入图片来源和处理场景枚举支持
- 新增 ImageSource 枚举定义图片来源类型(IPC、相机、手机等) - 新增 PipelineScene 枚举定义管线处理场景(打印、增强等) - 在 PhotoProcessContext 中添加 scenicConfigManager、scene 和 source 字段 - 在 PrinterServiceImpl 中根据 sourceId 判断并设置图片来源 - 在 PrinterServiceImpl 中设置默认管线场景为图片打印 - 修改 prepareNormalPhotoContext 和 prepareStorageAdapter 方法签名 - 优化配置获取逻辑,统一从 context 中获取 scenicConfigManager
This commit is contained in:
@@ -2,6 +2,9 @@ package com.ycwl.basic.image.pipeline.core;
|
||||
|
||||
import com.ycwl.basic.image.watermark.entity.WatermarkInfo;
|
||||
import com.ycwl.basic.image.watermark.enums.ImageWatermarkOperatorEnum;
|
||||
import com.ycwl.basic.image.pipeline.enums.ImageSource;
|
||||
import com.ycwl.basic.image.pipeline.enums.PipelineScene;
|
||||
import com.ycwl.basic.integration.common.manager.ScenicConfigManager;
|
||||
import com.ycwl.basic.model.Crop;
|
||||
import com.ycwl.basic.model.PrinterOrderItem;
|
||||
import com.ycwl.basic.image.pipeline.util.TempFileManager;
|
||||
@@ -23,6 +26,21 @@ public class PhotoProcessContext {
|
||||
private final TempFileManager tempFileManager;
|
||||
private final Long scenicId;
|
||||
|
||||
/**
|
||||
* 景区配置管理器,用于获取景区相关配置
|
||||
*/
|
||||
private ScenicConfigManager scenicConfigManager;
|
||||
|
||||
/**
|
||||
* 管线处理场景(打印、增强等)
|
||||
*/
|
||||
private PipelineScene scene;
|
||||
|
||||
/**
|
||||
* 图片来源(IPC、相机、手机等)
|
||||
*/
|
||||
private ImageSource source;
|
||||
|
||||
private File originalFile;
|
||||
private File processedFile;
|
||||
private boolean isLandscape = true;
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.ycwl.basic.image.pipeline.enums;
|
||||
|
||||
/**
|
||||
* 图片来源枚举
|
||||
* 用于标识图片的拍摄或上传来源
|
||||
*/
|
||||
public enum ImageSource {
|
||||
|
||||
/**
|
||||
* IPC设备(IP Camera)
|
||||
* 景区固定安装的网络摄像头拍摄的照片
|
||||
*/
|
||||
IPC("ipc", "IPC设备"),
|
||||
|
||||
/**
|
||||
* 相机设备
|
||||
* 工作人员使用专业相机拍摄的照片
|
||||
*/
|
||||
CAMERA("camera", "相机设备"),
|
||||
|
||||
/**
|
||||
* 手机上传
|
||||
* 用户通过手机客户端上传的照片
|
||||
*/
|
||||
PHONE("phone", "手机上传"),
|
||||
|
||||
/**
|
||||
* 未知来源
|
||||
* 无法确定来源或其他特殊情况
|
||||
*/
|
||||
UNKNOWN("unknown", "未知来源");
|
||||
|
||||
private final String code;
|
||||
private final String description;
|
||||
|
||||
ImageSource(String code, String description) {
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据code获取枚举
|
||||
*/
|
||||
public static ImageSource fromCode(String code) {
|
||||
if (code == null) {
|
||||
return UNKNOWN;
|
||||
}
|
||||
for (ImageSource source : values()) {
|
||||
if (source.code.equalsIgnoreCase(code)) {
|
||||
return source;
|
||||
}
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.ycwl.basic.image.pipeline.enums;
|
||||
|
||||
/**
|
||||
* 管线处理场景枚举
|
||||
* 用于区分不同的图片处理业务场景
|
||||
*/
|
||||
public enum PipelineScene {
|
||||
|
||||
/**
|
||||
* 图片打印场景
|
||||
* 包括照片打印、拼图打印等
|
||||
*/
|
||||
IMAGE_PRINT("image_print", "图片打印"),
|
||||
|
||||
/**
|
||||
* 图片增强场景
|
||||
* 包括图片美化、滤镜处理等
|
||||
*/
|
||||
IMAGE_ENHANCE("image_enhance", "图片增强");
|
||||
|
||||
private final String code;
|
||||
private final String description;
|
||||
|
||||
PipelineScene(String code, String description) {
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据code获取枚举
|
||||
*/
|
||||
public static PipelineScene fromCode(String code) {
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
for (PipelineScene scene : values()) {
|
||||
if (scene.code.equals(code)) {
|
||||
return scene;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,8 @@ import com.ycwl.basic.exception.BaseException;
|
||||
import com.ycwl.basic.image.pipeline.core.PhotoProcessContext;
|
||||
import com.ycwl.basic.image.pipeline.core.Pipeline;
|
||||
import com.ycwl.basic.image.pipeline.core.PipelineBuilder;
|
||||
import com.ycwl.basic.image.pipeline.enums.ImageSource;
|
||||
import com.ycwl.basic.image.pipeline.enums.PipelineScene;
|
||||
import com.ycwl.basic.image.pipeline.stages.CleanupStage;
|
||||
import com.ycwl.basic.image.pipeline.stages.ConditionalRotateStage;
|
||||
import com.ycwl.basic.image.pipeline.stages.DownloadStage;
|
||||
@@ -778,12 +780,29 @@ public class PrinterServiceImpl implements PrinterService {
|
||||
context.setQrcodeFile(qrCodeFile);
|
||||
|
||||
try {
|
||||
// 设置景区配置管理器到context
|
||||
ScenicConfigManager scenicConfig = scenicRepository.getScenicConfigManager(scenicId);
|
||||
context.setScenicConfigManager(scenicConfig);
|
||||
|
||||
// 设置管线场景为图片打印
|
||||
context.setScene(PipelineScene.IMAGE_PRINT);
|
||||
|
||||
// 根据sourceId判断图片来源
|
||||
// sourceId > 0: IPC设备拍摄
|
||||
// sourceId == null: 手机上传
|
||||
// sourceId == 0: 拼图(暂定为UNKNOWN)
|
||||
if (item.getSourceId() != null && item.getSourceId() > 0) {
|
||||
context.setSource(ImageSource.IPC);
|
||||
} else if (item.getSourceId() == null) {
|
||||
context.setSource(ImageSource.PHONE);
|
||||
} else {
|
||||
context.setSource(ImageSource.UNKNOWN);
|
||||
}
|
||||
|
||||
if (context.isNormalPhoto()) {
|
||||
prepareNormalPhotoContext(context, scenicConfig);
|
||||
prepareNormalPhotoContext(context);
|
||||
} else if (context.isPuzzle()) {
|
||||
prepareStorageAdapter(context, scenicConfig);
|
||||
prepareStorageAdapter(context);
|
||||
}
|
||||
|
||||
Pipeline<PhotoProcessContext> pipeline = context.isPuzzle()
|
||||
@@ -813,8 +832,15 @@ public class PrinterServiceImpl implements PrinterService {
|
||||
|
||||
/**
|
||||
* 准备普通照片的Context配置
|
||||
* 从context中的scenicConfigManager获取配置
|
||||
*/
|
||||
private void prepareNormalPhotoContext(PhotoProcessContext context, ScenicConfigManager scenicConfig) {
|
||||
private void prepareNormalPhotoContext(PhotoProcessContext context) {
|
||||
ScenicConfigManager scenicConfig = context.getScenicConfigManager();
|
||||
if (scenicConfig == null) {
|
||||
log.warn("scenicConfigManager未设置,跳过配置准备");
|
||||
return;
|
||||
}
|
||||
|
||||
String printWatermarkType = scenicConfig.getString("print_watermark_type");
|
||||
if (StringUtils.isNotBlank(printWatermarkType)) {
|
||||
ImageWatermarkOperatorEnum watermarkType = ImageWatermarkOperatorEnum.getByCode(printWatermarkType);
|
||||
@@ -827,13 +853,20 @@ public class PrinterServiceImpl implements PrinterService {
|
||||
String dateFormat = scenicConfig.getString("print_watermark_dt_format", "yyyy.MM.dd");
|
||||
context.setDateFormat(dateFormat);
|
||||
|
||||
prepareStorageAdapter(context, scenicConfig);
|
||||
prepareStorageAdapter(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* 准备存储适配器
|
||||
* 从context中的scenicConfigManager获取配置
|
||||
*/
|
||||
private void prepareStorageAdapter(PhotoProcessContext context, ScenicConfigManager scenicConfig) {
|
||||
private void prepareStorageAdapter(PhotoProcessContext context) {
|
||||
ScenicConfigManager scenicConfig = context.getScenicConfigManager();
|
||||
if (scenicConfig == null) {
|
||||
log.warn("scenicConfigManager未设置,将使用默认存储");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
String storeType = scenicConfig.getString("store_type");
|
||||
if (storeType != null) {
|
||||
|
||||
Reference in New Issue
Block a user