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:
@@ -37,9 +37,9 @@ public class AppPrinterController {
|
||||
}
|
||||
|
||||
@GetMapping("/getListFor/{scenicId}")
|
||||
public ApiResponse<List<MemberPrintResp>> getListFor(@PathVariable("scenicId") Long scenicId) {
|
||||
public ApiResponse<List<MemberPrintResp>> getListFor(@PathVariable("scenicId") Long scenicId, @RequestParam(required = false) Long faceId) {
|
||||
JwtInfo worker = JwtTokenUtil.getWorker();
|
||||
return ApiResponse.success(printerService.getUserPhotoList(worker.getUserId(), scenicId));
|
||||
return ApiResponse.success(printerService.getUserPhotoList(worker.getUserId(), scenicId, faceId));
|
||||
}
|
||||
|
||||
@GetMapping("/getItem/{scenicId}/{id}")
|
||||
@@ -53,24 +53,26 @@ public class AppPrinterController {
|
||||
}
|
||||
|
||||
@PostMapping("/deleteFrom/{scenicId}/{id}")
|
||||
public ApiResponse<?> deleteFrom(@PathVariable("scenicId") Long scenicId, @PathVariable("id") Long id) throws IOException {
|
||||
public ApiResponse<?> deleteFrom(@PathVariable("scenicId") Long scenicId, @PathVariable("id") Long id) {
|
||||
JwtInfo worker = JwtTokenUtil.getWorker();
|
||||
printerService.deleteUserPhoto(worker.getUserId(), scenicId, id);
|
||||
return ApiResponse.success(null);
|
||||
}
|
||||
@PostMapping("/uploadTo/{scenicId}")
|
||||
public ApiResponse<?> upload(@PathVariable("scenicId") Long scenicId, @RequestParam(value = "file") MultipartFile file) throws IOException {
|
||||
public ApiResponse<?> upload(@PathVariable("scenicId") Long scenicId,
|
||||
@RequestParam(value = "file") MultipartFile file,
|
||||
@RequestParam(value = "faceId", required = false) Long faceId) {
|
||||
String[] split = file.getOriginalFilename().split("\\.");
|
||||
String ext = split[split.length - 1];
|
||||
String url = StorageFactory.use().uploadFile(file, "printer", UUID.randomUUID() + "." + ext);
|
||||
Integer id = printerService.addUserPhoto(JwtTokenUtil.getWorker().getUserId(), scenicId, url);
|
||||
Integer id = printerService.addUserPhoto(JwtTokenUtil.getWorker().getUserId(), scenicId, url, faceId);
|
||||
return ApiResponse.success(id);
|
||||
}
|
||||
@PostMapping(value = "/uploadTo/{scenicId}/cropped/{id}", consumes = "multipart/form-data")
|
||||
public ApiResponse<?> uploadReplace(@PathVariable("scenicId") Long scenicId,
|
||||
@PathVariable("id") Long id,
|
||||
@RequestPart(value = "crop", required = false) String crop,
|
||||
@RequestPart(value = "file") MultipartFile file) throws IOException {
|
||||
@RequestPart(value = "file") MultipartFile file) {
|
||||
String[] split = file.getOriginalFilename().split("\\.");
|
||||
String ext = split[split.length - 1];
|
||||
String url = StorageFactory.use().uploadFile(file, "printer", UUID.randomUUID() + "." + ext);
|
||||
@@ -78,8 +80,10 @@ public class AppPrinterController {
|
||||
return ApiResponse.success(url);
|
||||
}
|
||||
@PostMapping("/uploadTo/{scenicId}/formSource")
|
||||
public ApiResponse<?> uploadFromSource(@PathVariable("scenicId") Long scenicId, @RequestBody FromSourceReq req) throws IOException {
|
||||
List<Integer> list = printerService.addUserPhotoFromSource(JwtTokenUtil.getWorker().getUserId(), scenicId, req);
|
||||
public ApiResponse<?> uploadFromSource(@PathVariable("scenicId") Long scenicId,
|
||||
@RequestBody FromSourceReq req,
|
||||
@RequestParam(value = "faceId", required = false) Long faceId) {
|
||||
List<Integer> list = printerService.addUserPhotoFromSource(JwtTokenUtil.getWorker().getUserId(), scenicId, req, faceId);
|
||||
return ApiResponse.success(list);
|
||||
}
|
||||
|
||||
@@ -95,16 +99,20 @@ public class AppPrinterController {
|
||||
return ApiResponse.success(null);
|
||||
}
|
||||
@GetMapping("/price/{scenicId}")
|
||||
public ApiResponse<?> queryPrice(@PathVariable("scenicId") Long scenicId) {
|
||||
return ApiResponse.success(printerService.queryPrice(JwtTokenUtil.getWorker().getUserId(), scenicId));
|
||||
public ApiResponse<?> queryPrice(@PathVariable("scenicId") Long scenicId,
|
||||
@RequestParam(value = "faceId", required = false) Long faceId) {
|
||||
return ApiResponse.success(printerService.queryPrice(JwtTokenUtil.getWorker().getUserId(), scenicId, faceId));
|
||||
}
|
||||
|
||||
@PostMapping("/order/{scenicId}")
|
||||
public ApiResponse<Map<String, Object>> createOrder(@PathVariable("scenicId") Long scenicId) {
|
||||
return ApiResponse.success(printerService.createOrder(JwtTokenUtil.getWorker().getUserId(), scenicId, null));
|
||||
public ApiResponse<Map<String, Object>> createOrder(@PathVariable("scenicId") Long scenicId,
|
||||
@RequestParam(value = "faceId", required = false) Long faceId) {
|
||||
return ApiResponse.success(printerService.createOrder(JwtTokenUtil.getWorker().getUserId(), scenicId, null, faceId));
|
||||
}
|
||||
@PostMapping("/order/{scenicId}/toPrinter/{printerId}")
|
||||
public ApiResponse<Map<String, Object>> createOrderToPrinter(@PathVariable("scenicId") Long scenicId, @PathVariable("printerId") Integer printerId) {
|
||||
return ApiResponse.success(printerService.createOrder(JwtTokenUtil.getWorker().getUserId(), scenicId, printerId));
|
||||
public ApiResponse<Map<String, Object>> createOrderToPrinter(@PathVariable("scenicId") Long scenicId,
|
||||
@PathVariable("printerId") Integer printerId,
|
||||
@RequestParam(value = "faceId", required = false) Long faceId) {
|
||||
return ApiResponse.success(printerService.createOrder(JwtTokenUtil.getWorker().getUserId(), scenicId, printerId, faceId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ public interface PrinterMapper {
|
||||
List<PrinterResp> listByScenicId(@Param("scenicId") Long scenicId);
|
||||
|
||||
List<MemberPrintResp> listRelation(@Param("memberId") Long memberId, @Param("scenicId") Long scenicId);
|
||||
List<MemberPrintResp> listRelationByFaceId(Long memberId, Long scenicId, Long faceId);
|
||||
|
||||
int deleteUserPhoto(Long memberId, Long scenicId, Long relationId);
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ public class MemberPrintEntity {
|
||||
private Integer id;
|
||||
private Long scenicId;
|
||||
private Long memberId;
|
||||
private Long faceId;
|
||||
private String origUrl;
|
||||
private String cropUrl;
|
||||
private String printUrl;
|
||||
|
||||
@@ -9,6 +9,7 @@ public class MemberPrintResp {
|
||||
private Integer id;
|
||||
private Long scenicId;
|
||||
private String scenicName;
|
||||
private Long faceId;
|
||||
private Long memberId;
|
||||
private String origUrl;
|
||||
private String cropUrl;
|
||||
|
||||
@@ -1239,7 +1239,7 @@ public class FaceServiceImpl implements FaceService {
|
||||
// 10. 批量添加到打印列表
|
||||
for (SourceEntity source : sourcesToAdd) {
|
||||
try {
|
||||
printerService.addUserPhoto(memberId, scenicId, source.getUrl());
|
||||
printerService.addUserPhoto(memberId, scenicId, source.getUrl(), faceId);
|
||||
totalAdded++;
|
||||
} catch (Exception e) {
|
||||
log.warn("添加照片到打印列表失败: sourceId={}, url={}, error={}",
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -42,6 +42,11 @@
|
||||
FROM member_print p
|
||||
WHERE p.member_id = #{memberId} AND p.scenic_id = #{scenicId} AND p.status = 0
|
||||
</select>
|
||||
<select id="listRelationByFaceId" resultType="com.ycwl.basic.model.pc.printer.resp.MemberPrintResp">
|
||||
SELECT p.*
|
||||
FROM member_print p
|
||||
WHERE p.member_id = #{memberId} AND p.scenic_id = #{scenicId} AND p.face_id = #{faceId} AND p.status = 0
|
||||
</select>
|
||||
<select id="getUserPhoto" resultType="com.ycwl.basic.model.pc.printer.resp.MemberPrintResp">
|
||||
SELECT p.*
|
||||
FROM member_print p
|
||||
@@ -96,6 +101,7 @@
|
||||
INSERT INTO member_print (
|
||||
member_id,
|
||||
scenic_id,
|
||||
face_id,
|
||||
orig_url,
|
||||
crop_url,
|
||||
quantity,
|
||||
@@ -105,6 +111,7 @@
|
||||
) VALUES (
|
||||
#{memberId},
|
||||
#{scenicId},
|
||||
#{faceId},
|
||||
#{origUrl},
|
||||
#{cropUrl},
|
||||
1,
|
||||
|
||||
Reference in New Issue
Block a user