You've already forked FrameTour-BE
feat(printer): 实现人脸照片自动添加到优先打印列表功能
- 引入DeviceConfigManager和SourceEntity依赖 - 替换TaskFaceService为FaceService并注入DeviceRepository - 新增autoAddPhotosToPreferPrint方法实现自动添加逻辑 - 根据景区和设备配置筛选并添加符合条件的照片 - 支持按设备分组处理和优先打印数量控制 - 添加详细的日志记录和异常处理机制
This commit is contained in:
@@ -12,6 +12,7 @@ import com.ycwl.basic.image.watermark.ImageWatermarkFactory;
|
||||
import com.ycwl.basic.image.watermark.entity.WatermarkInfo;
|
||||
import com.ycwl.basic.image.watermark.enums.ImageWatermarkOperatorEnum;
|
||||
import com.ycwl.basic.image.watermark.operator.IOperator;
|
||||
import com.ycwl.basic.integration.common.manager.DeviceConfigManager;
|
||||
import com.ycwl.basic.integration.common.manager.ScenicConfigManager;
|
||||
import com.ycwl.basic.mapper.FaceMapper;
|
||||
import com.ycwl.basic.mapper.FaceSampleMapper;
|
||||
@@ -29,6 +30,7 @@ import com.ycwl.basic.model.pc.member.resp.MemberRespVO;
|
||||
import com.ycwl.basic.model.pc.mp.MpConfigEntity;
|
||||
import com.ycwl.basic.model.pc.order.entity.OrderEntity;
|
||||
import com.ycwl.basic.model.pc.order.entity.OrderItemEntity;
|
||||
import com.ycwl.basic.model.pc.source.entity.SourceEntity;
|
||||
import com.ycwl.basic.pricing.dto.PriceCalculationRequest;
|
||||
import com.ycwl.basic.pricing.dto.PriceCalculationResult;
|
||||
import com.ycwl.basic.pricing.dto.ProductItem;
|
||||
@@ -46,10 +48,12 @@ import com.ycwl.basic.model.printer.req.WorkerAuthReqVo;
|
||||
import com.ycwl.basic.model.printer.resp.PrintTaskResp;
|
||||
import com.ycwl.basic.model.task.resp.SearchFaceRespVo;
|
||||
import com.ycwl.basic.model.wx.WXPayOrderReqVO;
|
||||
import com.ycwl.basic.repository.DeviceRepository;
|
||||
import com.ycwl.basic.repository.FaceRepository;
|
||||
import com.ycwl.basic.repository.OrderRepository;
|
||||
import com.ycwl.basic.repository.ScenicRepository;
|
||||
import com.ycwl.basic.service.mobile.WxPayService;
|
||||
import com.ycwl.basic.service.pc.FaceService;
|
||||
import com.ycwl.basic.service.pc.ScenicService;
|
||||
import com.ycwl.basic.service.printer.PrinterService;
|
||||
import com.ycwl.basic.service.task.TaskFaceService;
|
||||
@@ -118,10 +122,11 @@ public class PrinterServiceImpl implements PrinterService {
|
||||
private FaceMapper faceMapper;
|
||||
@Autowired
|
||||
private FaceRepository faceRepository;
|
||||
@Lazy
|
||||
@Autowired
|
||||
private ScenicService scenicService;
|
||||
private FaceService faceService;
|
||||
@Autowired
|
||||
private TaskFaceService faceService;
|
||||
private DeviceRepository deviceRepository;
|
||||
|
||||
@Override
|
||||
public List<PrinterResp> listByScenicId(Long scenicId) {
|
||||
@@ -797,10 +802,120 @@ public class PrinterServiceImpl implements PrinterService {
|
||||
resp.setUrl(faceUrl);
|
||||
resp.setFaceId(faceId);
|
||||
resp.setScenicId(scenicId);
|
||||
|
||||
faceService.matchFaceId(faceId);
|
||||
autoAddPhotosToPreferPrint(faceId);
|
||||
return resp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动将人脸关联的照片添加到优先打印列表
|
||||
* 根据景区和设备配置自动添加type=2的照片到用户打印列表
|
||||
*
|
||||
* @param faceId 人脸ID
|
||||
*/
|
||||
private void autoAddPhotosToPreferPrint(Long faceId) {
|
||||
try {
|
||||
// 1. 获取人脸信息
|
||||
FaceEntity face = faceRepository.getFace(faceId);
|
||||
if (face == null) {
|
||||
log.warn("人脸不存在,无法自动添加打印: faceId={}", faceId);
|
||||
return;
|
||||
}
|
||||
|
||||
Long scenicId = face.getScenicId();
|
||||
Long memberId = face.getMemberId();
|
||||
|
||||
// 2. 获取景区配置
|
||||
ScenicConfigManager scenicConfig = scenicRepository.getScenicConfigManager(scenicId);
|
||||
if (scenicConfig == null) {
|
||||
log.warn("景区配置不存在,跳过自动添加打印: scenicId={}", scenicId);
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. 检查景区是否启用打印功能
|
||||
Boolean printEnable = scenicConfig.getBoolean("print_enable");
|
||||
if (printEnable == null || !printEnable) {
|
||||
log.debug("景区未启用打印功能,跳过自动添加: scenicId={}", scenicId);
|
||||
return;
|
||||
}
|
||||
|
||||
// 4. 查询该faceId关联的所有type=2的照片
|
||||
List<SourceEntity> imageSources = sourceMapper.listImageSourcesByFaceId(faceId);
|
||||
if (imageSources == null || imageSources.isEmpty()) {
|
||||
log.debug("该人脸没有关联的照片,跳过自动添加: faceId={}", faceId);
|
||||
return;
|
||||
}
|
||||
|
||||
// 5. 按照deviceId分组处理
|
||||
Map<Long, List<SourceEntity>> sourcesByDevice = imageSources.stream()
|
||||
.filter(source -> source.getDeviceId() != null)
|
||||
.collect(Collectors.groupingBy(SourceEntity::getDeviceId));
|
||||
|
||||
int totalAdded = 0;
|
||||
for (Map.Entry<Long, List<SourceEntity>> entry : sourcesByDevice.entrySet()) {
|
||||
Long deviceId = entry.getKey();
|
||||
List<SourceEntity> deviceSources = entry.getValue();
|
||||
|
||||
// 6. 获取设备配置
|
||||
DeviceConfigManager deviceConfig = deviceRepository.getDeviceConfigManager(deviceId);
|
||||
if (deviceConfig == null) {
|
||||
log.debug("设备配置不存在,跳过该设备: deviceId={}", deviceId);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 7. 检查是否启用优先打印
|
||||
Boolean preferPrintEnable = deviceConfig.getBoolean("prefer_print_enable");
|
||||
if (preferPrintEnable == null || !preferPrintEnable) {
|
||||
log.debug("设备未启用优先打印,跳过: deviceId={}", deviceId);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 8. 获取优先打印数量配置
|
||||
Integer preferPrintCount = deviceConfig.getInteger("prefer_print_count");
|
||||
if (preferPrintCount == null) {
|
||||
log.debug("设备未配置优先打印数量,跳过: deviceId={}", deviceId);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 9. 根据配置添加照片到打印列表
|
||||
List<SourceEntity> sourcesToAdd;
|
||||
if (preferPrintCount > 0) {
|
||||
// 如果大于0,按照数量限制添加
|
||||
sourcesToAdd = deviceSources.stream()
|
||||
.limit(preferPrintCount)
|
||||
.collect(Collectors.toList());
|
||||
log.info("设备{}配置优先打印{}张,实际添加{}张",
|
||||
deviceId, preferPrintCount, sourcesToAdd.size());
|
||||
} else {
|
||||
// 如果小于等于0,添加该设备的所有照片
|
||||
sourcesToAdd = deviceSources;
|
||||
log.info("设备{}配置优先打印所有照片,实际添加{}张",
|
||||
deviceId, sourcesToAdd.size());
|
||||
}
|
||||
|
||||
// 10. 批量添加到打印列表
|
||||
for (SourceEntity source : sourcesToAdd) {
|
||||
try {
|
||||
addUserPhoto(memberId, scenicId, source.getUrl(), faceId);
|
||||
totalAdded++;
|
||||
} catch (Exception e) {
|
||||
log.warn("添加照片到打印列表失败: sourceId={}, url={}, error={}",
|
||||
source.getId(), source.getUrl(), e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (totalAdded > 0) {
|
||||
log.info("自动添加打印完成: faceId={}, 成功添加{}张照片", faceId, totalAdded);
|
||||
} else {
|
||||
log.debug("自动添加打印完成: faceId={}, 无符合条件的照片", faceId);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
// 出现异常则放弃,不影响主流程
|
||||
log.error("自动添加打印失败,已忽略: faceId={}", faceId, e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 获取下一个要使用的打印机名称(轮询逻辑)
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user