feat(printer):优化用户照片添加逻辑并返回结果ID
All checks were successful
ZhenTu-BE/pipeline/head This commit looks good

- 修改 addUserPhoto 方法参数,使用 MemberPrintEntity 实体传参- 在 PrinterMapper.xml 中配置 insert 语句返回主键 ID- 更新 addUserPhotoFromSource 方法返回值为 List<Integer>
- 添加异常处理和日志记录
- 调整 AppPrinterController 接口返回照片 ID 列表
This commit is contained in:
2025-10-14 11:45:46 +08:00
parent feac2e8d93
commit 3cb12c13c2
5 changed files with 39 additions and 11 deletions

View File

@@ -75,8 +75,8 @@ public class AppPrinterController {
}
@PostMapping("/uploadTo/{scenicId}/formSource")
public ApiResponse<?> uploadFromSource(@PathVariable("scenicId") Long scenicId, @RequestBody FromSourceReq req) throws IOException {
printerService.addUserPhotoFromSource(JwtTokenUtil.getWorker().getUserId(), scenicId, req);
return ApiResponse.success(null);
List<Integer> list = printerService.addUserPhotoFromSource(JwtTokenUtil.getWorker().getUserId(), scenicId, req);
return ApiResponse.success(list);
}
@PostMapping("/setQuantity/{scenicId}/{id}")

View File

@@ -1,5 +1,6 @@
package com.ycwl.basic.mapper;
import com.ycwl.basic.model.pc.printer.entity.MemberPrintEntity;
import com.ycwl.basic.model.pc.printer.entity.PrintTaskEntity;
import com.ycwl.basic.model.pc.printer.entity.PrinterEntity;
import com.ycwl.basic.model.pc.printer.resp.MemberPrintResp;
@@ -35,7 +36,7 @@ public interface PrinterMapper {
int deleteUserPhoto(Long memberId, Long scenicId, Long relationId);
int addUserPhoto(Long memberId, Long scenicId, String url);
int addUserPhoto(MemberPrintEntity entity);
MemberPrintResp getUserPhoto(Long memberId, Long scenicId, Long id);

View File

@@ -48,7 +48,7 @@ public interface PrinterService {
PriceObj queryPrice(Long memberId, Long scenicId);
boolean addUserPhotoFromSource(Long memberId, Long scenicId, FromSourceReq req);
List<Integer> addUserPhotoFromSource(Long memberId, Long scenicId, FromSourceReq req);
Map<String, Object> createOrder(Long memberId, Long scenicId, Integer printerId);

View File

@@ -19,6 +19,7 @@ import com.ycwl.basic.pricing.dto.PriceCalculationResult;
import com.ycwl.basic.pricing.dto.ProductItem;
import com.ycwl.basic.pricing.enums.ProductType;
import com.ycwl.basic.pricing.service.IPriceCalculationService;
import com.ycwl.basic.model.pc.printer.entity.MemberPrintEntity;
import com.ycwl.basic.model.pc.printer.entity.PrintTaskEntity;
import com.ycwl.basic.model.pc.printer.entity.PrinterEntity;
import com.ycwl.basic.model.pc.printer.resp.MemberPrintResp;
@@ -44,6 +45,7 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
@@ -190,7 +192,13 @@ public class PrinterServiceImpl implements PrinterService {
@Override
public boolean addUserPhoto(Long memberId, Long scenicId, String url) {
printerMapper.addUserPhoto(memberId, scenicId, url);
MemberPrintEntity entity = new MemberPrintEntity();
entity.setMemberId(memberId);
entity.setScenicId(scenicId);
entity.setOrigUrl(url);
entity.setCropUrl(url);
entity.setStatus(0);
printerMapper.addUserPhoto(entity);
return true;
}
@@ -259,15 +267,34 @@ public class PrinterServiceImpl implements PrinterService {
}
@Override
public boolean addUserPhotoFromSource(Long memberId, Long scenicId, FromSourceReq req) {
public List<Integer> addUserPhotoFromSource(Long memberId, Long scenicId, FromSourceReq req) {
List<Integer> resultIds = new ArrayList<>();
req.getIds().forEach(id -> {
SourceRespVO byId = sourceMapper.getById(id);
if (byId == null) {
resultIds.add(null);
return;
}
printerMapper.addUserPhoto(memberId, scenicId, byId.getUrl());
MemberPrintEntity entity = new MemberPrintEntity();
entity.setMemberId(memberId);
entity.setScenicId(scenicId);
entity.setOrigUrl(byId.getUrl());
entity.setCropUrl(byId.getUrl());
entity.setStatus(0);
try {
int rows = printerMapper.addUserPhoto(entity);
if (rows > 0 && entity.getId() != null) {
resultIds.add(entity.getId());
} else {
resultIds.add(null);
}
} catch (Exception e) {
log.error("添加用户照片失败, memberId={}, scenicId={}, sourceId={}", memberId, scenicId, id, e);
resultIds.add(null);
}
});
return false;
return resultIds;
}
@Override