You've already forked FrameTour-BE
feat(printer): 添加 faceId 参数支持照片打印功能
- 在多个接口中新增 faceId 请求参数,用于关联人脸识别信息 - 修改 getUserPhotoList 方法支持按 faceId 过滤照片列表 - 更新 addUserPhoto 和 addUserPhotoFromSource 方法保存 faceId信息 - 调整 queryPrice 和 createOrder 方法支持 faceId 查询条件- 新增 listRelationByFaceId Mapper 方法实现按 faceId 查询照片 - 在 MemberPrintEntity 和 MemberPrintResp 中添加 faceId 字段- 更新数据库插入语句,添加 face_id 字段写入支持
This commit is contained in:
@@ -32,13 +32,13 @@ public interface PrinterService {
|
||||
|
||||
void taskFail(Integer taskId, WorkerAuthReqVo req);
|
||||
|
||||
List<MemberPrintResp> getUserPhotoList(Long userId, Long scenicId);
|
||||
List<MemberPrintResp> getUserPhotoList(Long userId, Long scenicId, Long faceId);
|
||||
|
||||
List<MemberPrintResp> getUserPhotoListByOrderId(Long orderId);
|
||||
|
||||
boolean deleteUserPhoto(Long memberId, Long scenicId, Long relationId);
|
||||
|
||||
Integer addUserPhoto(Long memberId, Long scenicId, String url);
|
||||
Integer addUserPhoto(Long memberId, Long scenicId, String url, Long faceId);
|
||||
|
||||
MemberPrintResp getUserPhoto(Long memberId, Long scenicId, Long id);
|
||||
|
||||
@@ -46,11 +46,11 @@ public interface PrinterService {
|
||||
|
||||
int setPhotoQuantity(Long memberId, Long scenicId, Long id, Integer quantity);
|
||||
|
||||
PriceObj queryPrice(Long memberId, Long scenicId);
|
||||
PriceObj queryPrice(Long memberId, Long scenicId, Long faceId);
|
||||
|
||||
List<Integer> addUserPhotoFromSource(Long memberId, Long scenicId, FromSourceReq req);
|
||||
List<Integer> addUserPhotoFromSource(Long memberId, Long scenicId, FromSourceReq req, Long faceId);
|
||||
|
||||
Map<String, Object> createOrder(Long memberId, Long scenicId, Integer printerId);
|
||||
Map<String, Object> createOrder(Long memberId, Long scenicId, Integer printerId, Long faceId);
|
||||
|
||||
void batchSetUserPhotoListToPrinter(Long memberId, Long scenicId, Integer printerId);
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import com.ycwl.basic.exception.BaseException;
|
||||
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.exception.ImageWatermarkException;
|
||||
import com.ycwl.basic.image.watermark.operator.IOperator;
|
||||
import com.ycwl.basic.integration.common.manager.ScenicConfigManager;
|
||||
import com.ycwl.basic.mapper.MemberMapper;
|
||||
@@ -21,7 +20,6 @@ import com.ycwl.basic.model.mobile.order.PriceObj;
|
||||
import com.ycwl.basic.model.pc.member.resp.MemberRespVO;
|
||||
import com.ycwl.basic.model.pc.order.entity.OrderEntity;
|
||||
import com.ycwl.basic.model.pc.order.entity.OrderItemEntity;
|
||||
import com.ycwl.basic.model.pc.price.entity.PriceConfigEntity;
|
||||
import com.ycwl.basic.pricing.dto.PriceCalculationRequest;
|
||||
import com.ycwl.basic.pricing.dto.PriceCalculationResult;
|
||||
import com.ycwl.basic.pricing.dto.ProductItem;
|
||||
@@ -38,7 +36,6 @@ import com.ycwl.basic.model.printer.req.PrinterSyncReq;
|
||||
import com.ycwl.basic.model.printer.req.WorkerAuthReqVo;
|
||||
import com.ycwl.basic.model.printer.resp.PrintTaskResp;
|
||||
import com.ycwl.basic.model.wx.WXPayOrderReqVO;
|
||||
import com.ycwl.basic.repository.PriceRepository;
|
||||
import com.ycwl.basic.repository.ScenicRepository;
|
||||
import com.ycwl.basic.service.mobile.WxPayService;
|
||||
import com.ycwl.basic.service.printer.PrinterService;
|
||||
@@ -216,11 +213,14 @@ public class PrinterServiceImpl implements PrinterService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MemberPrintResp> getUserPhotoList(Long userId, Long scenicId) {
|
||||
List<MemberPrintResp> list = printerMapper.listRelation(userId, scenicId);
|
||||
if (list.isEmpty()) {
|
||||
// 额外逻辑
|
||||
public List<MemberPrintResp> getUserPhotoList(Long userId, Long scenicId, Long faceId) {
|
||||
if (faceId != null) {
|
||||
List<MemberPrintResp> list = printerMapper.listRelation(userId, scenicId);
|
||||
return list.stream()
|
||||
.filter(item -> Objects.nonNull(item.getFaceId()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
List<MemberPrintResp> list = printerMapper.listRelationByFaceId(userId, scenicId, faceId);
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -236,10 +236,11 @@ public class PrinterServiceImpl implements PrinterService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer addUserPhoto(Long memberId, Long scenicId, String url) {
|
||||
public Integer addUserPhoto(Long memberId, Long scenicId, String url, Long faceId) {
|
||||
MemberPrintEntity entity = new MemberPrintEntity();
|
||||
entity.setMemberId(memberId);
|
||||
entity.setScenicId(scenicId);
|
||||
entity.setFaceId(faceId);
|
||||
entity.setOrigUrl(url);
|
||||
|
||||
// 获取打印尺寸
|
||||
@@ -314,31 +315,30 @@ public class PrinterServiceImpl implements PrinterService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PriceObj queryPrice(Long memberId, Long scenicId) {
|
||||
List<MemberPrintResp> userPhotoList = getUserPhotoList(memberId, scenicId);
|
||||
|
||||
public PriceObj queryPrice(Long memberId, Long scenicId, Long faceId) {
|
||||
List<MemberPrintResp> userPhotoList = getUserPhotoList(memberId, scenicId, faceId);
|
||||
// 计算照片总数量
|
||||
long count = userPhotoList.stream()
|
||||
.filter(item -> Objects.nonNull(item.getQuantity()))
|
||||
.mapToInt(MemberPrintResp::getQuantity)
|
||||
.sum();
|
||||
|
||||
PriceObj obj = new PriceObj();
|
||||
obj.setScenicId(scenicId);
|
||||
obj.setGoodsId(faceId);
|
||||
obj.setFaceId(faceId);
|
||||
obj.setGoodsType(3);
|
||||
|
||||
if (count == 0) {
|
||||
// 如果没有照片,返回零价格
|
||||
obj.setPrice(BigDecimal.ZERO);
|
||||
obj.setSlashPrice(BigDecimal.ZERO);
|
||||
obj.setGoodsType(3);
|
||||
obj.setFree(false);
|
||||
obj.setScenicId(scenicId);
|
||||
return obj;
|
||||
}
|
||||
|
||||
// 构建价格计算请求
|
||||
PriceCalculationRequest request = new PriceCalculationRequest();
|
||||
request.setUserId(memberId);
|
||||
request.setScenicId(scenicId);
|
||||
|
||||
|
||||
// 创建照片打印商品项
|
||||
ProductItem photoItem = new ProductItem();
|
||||
photoItem.setProductType(ProductType.PHOTO_PRINT);
|
||||
@@ -346,24 +346,22 @@ public class PrinterServiceImpl implements PrinterService {
|
||||
photoItem.setQuantity(Long.valueOf(count).intValue());
|
||||
photoItem.setPurchaseCount(1);
|
||||
photoItem.setScenicId(scenicId.toString());
|
||||
|
||||
|
||||
request.setProducts(Collections.singletonList(photoItem));
|
||||
|
||||
|
||||
// 使用统一价格计算服务
|
||||
PriceCalculationResult result = priceCalculationService.calculatePrice(request);
|
||||
|
||||
|
||||
// 转换为原有的 PriceObj 格式
|
||||
obj.setPrice(result.getFinalAmount());
|
||||
obj.setSlashPrice(result.getOriginalAmount());
|
||||
obj.setGoodsType(3);
|
||||
obj.setFree(result.getFinalAmount().compareTo(BigDecimal.ZERO) == 0);
|
||||
obj.setScenicId(scenicId);
|
||||
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> addUserPhotoFromSource(Long memberId, Long scenicId, FromSourceReq req) {
|
||||
public List<Integer> addUserPhotoFromSource(Long memberId, Long scenicId, FromSourceReq req, Long faceId) {
|
||||
List<Integer> resultIds = new ArrayList<>();
|
||||
req.getIds().forEach(id -> {
|
||||
SourceRespVO byId = sourceMapper.getById(id);
|
||||
@@ -374,10 +372,11 @@ public class PrinterServiceImpl implements PrinterService {
|
||||
MemberPrintEntity entity = new MemberPrintEntity();
|
||||
entity.setMemberId(memberId);
|
||||
entity.setScenicId(scenicId);
|
||||
entity.setFaceId(faceId);
|
||||
entity.setOrigUrl(byId.getUrl());
|
||||
entity.setCropUrl(byId.getUrl());
|
||||
entity.setStatus(0);
|
||||
|
||||
|
||||
try {
|
||||
int rows = printerMapper.addUserPhoto(entity);
|
||||
if (rows > 0 && entity.getId() != null) {
|
||||
@@ -394,7 +393,7 @@ public class PrinterServiceImpl implements PrinterService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> createOrder(Long memberId, Long scenicId, Integer printerId) {
|
||||
public Map<String, Object> createOrder(Long memberId, Long scenicId, Integer printerId, Long faceId) {
|
||||
if (printerId == null) {
|
||||
List<PrinterResp> printerList = printerMapper.listByScenicId(scenicId);
|
||||
if (printerList.size() != 1) {
|
||||
@@ -415,7 +414,7 @@ public class PrinterServiceImpl implements PrinterService {
|
||||
}
|
||||
}
|
||||
// 验证照片数量
|
||||
List<MemberPrintResp> userPhotoList = getUserPhotoList(memberId, scenicId);
|
||||
List<MemberPrintResp> userPhotoList = getUserPhotoList(memberId, scenicId, faceId);
|
||||
long count = userPhotoList.stream().filter(item -> Objects.nonNull(item.getQuantity())).mapToInt(MemberPrintResp::getQuantity).sum();
|
||||
if (count == 0) {
|
||||
throw new BaseException("没有可打印的照片");
|
||||
@@ -425,13 +424,12 @@ public class PrinterServiceImpl implements PrinterService {
|
||||
Long orderId = SnowFlakeUtil.getLongId();
|
||||
order.setId(orderId);
|
||||
order.setMemberId(memberId);
|
||||
order.setFaceId(faceId);
|
||||
MemberRespVO member = memberMapper.getById(memberId);
|
||||
order.setOpenId(member.getOpenId());
|
||||
order.setScenicId(scenicId);
|
||||
order.setType(3); // 照片打印类型
|
||||
batchSetUserPhotoListToPrinter(memberId, scenicId, printerId);
|
||||
// 重新获取照片列表(包含打印机信息)
|
||||
userPhotoList = getUserPhotoList(memberId, scenicId);
|
||||
List<OrderItemEntity> orderItems = userPhotoList.stream().map(goods -> {
|
||||
OrderItemEntity orderItem = new OrderItemEntity();
|
||||
orderItem.setOrderId(orderId);
|
||||
@@ -462,7 +460,7 @@ public class PrinterServiceImpl implements PrinterService {
|
||||
order.setPrice(priceResult.getFinalAmount());
|
||||
order.setSlashPrice(priceResult.getOriginalAmount());
|
||||
order.setPayPrice(priceResult.getFinalAmount());
|
||||
// order.setFaceId();
|
||||
order.setFaceId(faceId);
|
||||
if (order.getPayPrice().equals(BigDecimal.ZERO)) {
|
||||
order.setStatus(OrderStateEnum.PAID.getState());
|
||||
order.setPayAt(new Date());
|
||||
|
||||
Reference in New Issue
Block a user