feat(printer): 支持上传裁剪参数并更新照片裁剪信息

- 在 AppPrinterController 中新增 crop 参数用于接收裁剪数据
- 修改 PrinterMapper 和 PrinterService 接口及实现,支持保存 crop 字段
- 更新 MemberPrintResp 模型以包含 crop 属性
-优化 Mapper XML 查询语句,统一使用 SELECT p.* 提高可读性
- 数据库更新语句中添加 crop 字段的赋值操作
This commit is contained in:
2025-10-27 16:59:31 +08:00
parent 2a662ae86d
commit f07d808f3d
6 changed files with 17 additions and 20 deletions

View File

@@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@@ -65,12 +66,15 @@ public class AppPrinterController {
Integer id = printerService.addUserPhoto(JwtTokenUtil.getWorker().getUserId(), scenicId, url); Integer id = printerService.addUserPhoto(JwtTokenUtil.getWorker().getUserId(), scenicId, url);
return ApiResponse.success(id); return ApiResponse.success(id);
} }
@PostMapping("/uploadTo/{scenicId}/cropped/{id}") @PostMapping(value = "/uploadTo/{scenicId}/cropped/{id}", consumes = "multipart/form-data")
public ApiResponse<?> uploadReplace(@PathVariable("scenicId") Long scenicId, @PathVariable("id") Long id, @RequestParam(value = "file") MultipartFile file) throws IOException { 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 {
String[] split = file.getOriginalFilename().split("\\."); String[] split = file.getOriginalFilename().split("\\.");
String ext = split[split.length - 1]; String ext = split[split.length - 1];
String url = StorageFactory.use().uploadFile(file, "printer", UUID.randomUUID() + "." + ext); String url = StorageFactory.use().uploadFile(file, "printer", UUID.randomUUID() + "." + ext);
printerService.setPhotoCropped(JwtTokenUtil.getWorker().getUserId(), scenicId, id, url); printerService.setPhotoCropped(JwtTokenUtil.getWorker().getUserId(), scenicId, id, url, crop);
return ApiResponse.success(url); return ApiResponse.success(url);
} }
@PostMapping("/uploadTo/{scenicId}/formSource") @PostMapping("/uploadTo/{scenicId}/formSource")

View File

@@ -44,7 +44,7 @@ public interface PrinterMapper {
MemberPrintResp getUserPhoto(Long memberId, Long scenicId, Long id); MemberPrintResp getUserPhoto(Long memberId, Long scenicId, Long id);
int setPhotoCropped(Long memberId, Long scenicId, Long id, String url); int setPhotoCropped(Long memberId, Long scenicId, Long id, String url, String crop);
int setPhotoQuantity(Long memberId, Long scenicId, Long id, Integer quantity); int setPhotoQuantity(Long memberId, Long scenicId, Long id, Integer quantity);

View File

@@ -17,4 +17,5 @@ public class MemberPrintResp {
private Long orderId; private Long orderId;
private Integer status; private Integer status;
private Date createTime; private Date createTime;
private String crop;
} }

View File

@@ -42,7 +42,7 @@ public interface PrinterService {
MemberPrintResp getUserPhoto(Long memberId, Long scenicId, Long id); MemberPrintResp getUserPhoto(Long memberId, Long scenicId, Long id);
int setPhotoCropped(Long memberId, Long scenicId, Long id, String url); int setPhotoCropped(Long memberId, Long scenicId, Long id, String url, String crop);
int setPhotoQuantity(Long memberId, Long scenicId, Long id, Integer quantity); int setPhotoQuantity(Long memberId, Long scenicId, Long id, Integer quantity);

View File

@@ -243,8 +243,8 @@ public class PrinterServiceImpl implements PrinterService {
} }
@Override @Override
public int setPhotoCropped(Long memberId, Long scenicId, Long id, String url) { public int setPhotoCropped(Long memberId, Long scenicId, Long id, String url, String crop) {
return printerMapper.setPhotoCropped(memberId, scenicId, id, url); return printerMapper.setPhotoCropped(memberId, scenicId, id, url, crop);
} }
@Override @Override

View File

@@ -38,23 +38,17 @@
WHERE p.scenic_id = #{scenicId} and p.status = 1 WHERE p.scenic_id = #{scenicId} and p.status = 1
</select> </select>
<select id="listRelation" resultType="com.ycwl.basic.model.pc.printer.resp.MemberPrintResp"> <select id="listRelation" resultType="com.ycwl.basic.model.pc.printer.resp.MemberPrintResp">
SELECT p.id, p.scenic_id as scenicId, p.member_id as memberId, SELECT p.*
p.orig_url as origUrl, p.crop_url as cropUrl, p.order_id as orderId, p.quantity,
p.status, p.create_time as createTime, p.printer_id
FROM member_print p FROM member_print p
WHERE p.member_id = #{memberId} AND p.scenic_id = #{scenicId} AND p.status = 0 WHERE p.member_id = #{memberId} AND p.scenic_id = #{scenicId} AND p.status = 0
</select> </select>
<select id="getUserPhoto" resultType="com.ycwl.basic.model.pc.printer.resp.MemberPrintResp"> <select id="getUserPhoto" resultType="com.ycwl.basic.model.pc.printer.resp.MemberPrintResp">
SELECT p.id, p.scenic_id, p.member_id as memberId, SELECT p.*
p.member_id, p.orig_url as origUrl, p.crop_url as cropUrl, p.order_id as orderId, p.quantity,
p.status, p.create_time as createTime, p.printer_id
FROM member_print p FROM member_print p
WHERE p.id = #{id} AND p.member_id = #{memberId} AND p.scenic_id = #{scenicId} WHERE p.id = #{id} AND p.member_id = #{memberId} AND p.scenic_id = #{scenicId}
</select> </select>
<select id="getUserPhotoByIds" resultType="com.ycwl.basic.model.pc.printer.resp.MemberPrintResp"> <select id="getUserPhotoByIds" resultType="com.ycwl.basic.model.pc.printer.resp.MemberPrintResp">
SELECT p.id, p.scenic_id, p.member_id as memberId, SELECT p.*
p.orig_url as origUrl, p.crop_url as cropUrl, p.order_id as orderId, p.quantity,
p.status, p.create_time as createTime, p.printer_id
FROM member_print p FROM member_print p
WHERE p.id IN WHERE p.id IN
<foreach collection="ids" item="id" open="(" separator="," close=")"> <foreach collection="ids" item="id" open="(" separator="," close=")">
@@ -62,9 +56,7 @@
</foreach> </foreach>
</select> </select>
<select id="listRelationByOrderId" resultType="com.ycwl.basic.model.pc.printer.resp.MemberPrintResp"> <select id="listRelationByOrderId" resultType="com.ycwl.basic.model.pc.printer.resp.MemberPrintResp">
SELECT p.id, p.scenic_id as scenicId, p.member_id as memberId, SELECT p.*
p.orig_url as origUrl, p.crop_url as cropUrl, p.order_id as orderId, p.quantity,
p.status, p.create_time as createTime, p.printer_id
FROM member_print p FROM member_print p
WHERE p.id in (select order_item.goods_id from order_item where order_item.order_id = #{orderId} and order_item.goods_type = 3) WHERE p.id in (select order_item.goods_id from order_item where order_item.order_id = #{orderId} and order_item.goods_type = 3)
</select> </select>
@@ -166,7 +158,7 @@
WHERE id = #{id} AND status = #{expectStatus} WHERE id = #{id} AND status = #{expectStatus}
</update> </update>
<update id="setPhotoCropped"> <update id="setPhotoCropped">
UPDATE member_print SET crop_url = #{url}, update_time = NOW(), print_url = null WHERE id = #{id} UPDATE member_print SET crop_url = #{url}, crop = #{crop}, update_time = NOW(), print_url = null WHERE id = #{id}
</update> </update>
<update id="setPhotoQuantity"> <update id="setPhotoQuantity">
UPDATE member_print SET quantity = #{quantity}, update_time = NOW() WHERE id = #{id} UPDATE member_print SET quantity = #{quantity}, update_time = NOW() WHERE id = #{id}