You've already forked FrameTour-BE
feat(printer): 添加打印机指引图片管理功能
- 新增 PrinterGuideEntity 实体类定义数据库表结构 - 创建 PrinterGuideMapper 数据访问接口及实现方法 - 在 AppPrinterController 中添加移动端查询已启用指引图片接口 - 在 PrinterController 中添加 PC 端指引图片管理完整 CRUD 接口 - 扩展打印机服务层集成指引图片业务逻辑 - 调整订单支付完成后购买后逻辑触发机制 - 修改用户照片列表到打印机缓存时间从 60 秒延长至 24 小时
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package com.ycwl.basic.controller.mobile;
|
||||
|
||||
import com.ycwl.basic.annotation.IgnoreToken;
|
||||
import com.ycwl.basic.mapper.PrinterGuideMapper;
|
||||
import com.ycwl.basic.model.jwt.JwtInfo;
|
||||
import com.ycwl.basic.model.mobile.face.FaceRecognizeResp;
|
||||
import com.ycwl.basic.model.pc.printer.entity.PrinterGuideEntity;
|
||||
import com.ycwl.basic.model.pc.printer.resp.MemberPrintResp;
|
||||
import com.ycwl.basic.model.pc.printer.resp.PrinterResp;
|
||||
import com.ycwl.basic.model.printer.req.FromSourceReq;
|
||||
@@ -31,12 +33,21 @@ import java.util.UUID;
|
||||
public class AppPrinterController {
|
||||
@Autowired
|
||||
private PrinterService printerService;
|
||||
@Autowired
|
||||
private PrinterGuideMapper printerGuideMapper;
|
||||
@GetMapping("/listFor/{scenicId}")
|
||||
@IgnoreToken
|
||||
public ApiResponse<List<PrinterResp>> listFor(@PathVariable("scenicId") Long scenicId) {
|
||||
return ApiResponse.success(printerService.listByScenicId(scenicId));
|
||||
}
|
||||
|
||||
// 查询打印机已启用的指引图片(按排序)
|
||||
@GetMapping("/guide/{printerId}")
|
||||
@IgnoreToken
|
||||
public ApiResponse<List<PrinterGuideEntity>> guideList(@PathVariable("printerId") Integer printerId) {
|
||||
return ApiResponse.success(printerGuideMapper.listEnabledByPrinterId(printerId));
|
||||
}
|
||||
|
||||
@GetMapping("/useSample/{sampleId}")
|
||||
public ApiResponse<FaceRecognizeResp> useSample(@PathVariable("sampleId") Long sampleId) throws IOException {
|
||||
JwtInfo worker = JwtTokenUtil.getWorker();
|
||||
|
||||
@@ -3,8 +3,10 @@ package com.ycwl.basic.controller.pc;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ycwl.basic.mapper.PrintTaskMapper;
|
||||
import com.ycwl.basic.mapper.PrinterGuideMapper;
|
||||
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.entity.PrinterGuideEntity;
|
||||
import com.ycwl.basic.model.pc.printer.req.PrintTaskReqQuery;
|
||||
import com.ycwl.basic.model.pc.printer.req.ReprintRequest;
|
||||
import com.ycwl.basic.service.printer.PrinterService;
|
||||
@@ -16,6 +18,7 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
@@ -29,6 +32,9 @@ public class PrinterController {
|
||||
@Autowired
|
||||
private PrintTaskMapper printTaskMapper;
|
||||
|
||||
@Autowired
|
||||
private PrinterGuideMapper printerGuideMapper;
|
||||
|
||||
// 查询列表
|
||||
@PostMapping("/list")
|
||||
public ApiResponse<List<PrinterEntity>> list(@RequestBody PrinterEntity condition) {
|
||||
@@ -119,4 +125,41 @@ public class PrinterController {
|
||||
int count = printerService.rejectPrintTasks(taskIds);
|
||||
return ApiResponse.success(count);
|
||||
}
|
||||
|
||||
// 查询打印机所有指引图片(含禁用)
|
||||
@GetMapping("/guide/list/{printerId}")
|
||||
public ApiResponse<List<PrinterGuideEntity>> guideList(@PathVariable("printerId") Integer printerId) {
|
||||
return ApiResponse.success(printerGuideMapper.listByPrinterId(printerId));
|
||||
}
|
||||
|
||||
// 添加指引图片
|
||||
@PostMapping("/guide/add")
|
||||
public ApiResponse<Integer> guideAdd(@RequestBody PrinterGuideEntity entity) {
|
||||
if (entity.getSortOrder() == null) {
|
||||
entity.setSortOrder(0);
|
||||
}
|
||||
if (entity.getEnabled() == null) {
|
||||
entity.setEnabled(1);
|
||||
}
|
||||
printerGuideMapper.insertGuide(entity);
|
||||
return ApiResponse.success(entity.getId());
|
||||
}
|
||||
|
||||
// 删除指引图片
|
||||
@DeleteMapping("/guide/delete/{id}")
|
||||
public ApiResponse<Integer> guideDelete(@PathVariable("id") Integer id) {
|
||||
return ApiResponse.success(printerGuideMapper.deleteById(id));
|
||||
}
|
||||
|
||||
// 修改指引图片排序
|
||||
@PostMapping("/guide/updateSort/{id}")
|
||||
public ApiResponse<Integer> guideUpdateSort(@PathVariable("id") Integer id, @RequestParam("sortOrder") Integer sortOrder) {
|
||||
return ApiResponse.success(printerGuideMapper.updateSortOrder(id, sortOrder));
|
||||
}
|
||||
|
||||
// 切换指引图片启用/禁用
|
||||
@PostMapping("/guide/toggleEnabled/{id}")
|
||||
public ApiResponse<Integer> guideToggleEnabled(@PathVariable("id") Integer id) {
|
||||
return ApiResponse.success(printerGuideMapper.toggleEnabled(id));
|
||||
}
|
||||
}
|
||||
23
src/main/java/com/ycwl/basic/mapper/PrinterGuideMapper.java
Normal file
23
src/main/java/com/ycwl/basic/mapper/PrinterGuideMapper.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package com.ycwl.basic.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.ycwl.basic.model.pc.printer.entity.PrinterGuideEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface PrinterGuideMapper extends BaseMapper<PrinterGuideEntity> {
|
||||
List<PrinterGuideEntity> listByPrinterId(@Param("printerId") Integer printerId);
|
||||
|
||||
List<PrinterGuideEntity> listEnabledByPrinterId(@Param("printerId") Integer printerId);
|
||||
|
||||
int insertGuide(PrinterGuideEntity entity);
|
||||
|
||||
int deleteById(@Param("id") Integer id);
|
||||
|
||||
int updateSortOrder(@Param("id") Integer id, @Param("sortOrder") Integer sortOrder);
|
||||
|
||||
int toggleEnabled(@Param("id") Integer id);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.ycwl.basic.model.pc.printer.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@TableName("printer_guide")
|
||||
public class PrinterGuideEntity {
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
private Integer printerId;
|
||||
private String imageUrl;
|
||||
private Integer sortOrder;
|
||||
private Integer enabled;
|
||||
private Date createTime;
|
||||
private Date updateTime;
|
||||
}
|
||||
@@ -1174,7 +1174,7 @@ public class PrinterServiceImpl implements PrinterService {
|
||||
if (redisTemplate.opsForValue().get(USER_PHOTO_LIST_TO_PRINTER + memberId + ":" + orderId) != null) {
|
||||
return;
|
||||
}
|
||||
redisTemplate.opsForValue().set(USER_PHOTO_LIST_TO_PRINTER + memberId + ":" + orderId, "1", 60, TimeUnit.SECONDS);
|
||||
redisTemplate.opsForValue().set(USER_PHOTO_LIST_TO_PRINTER + memberId + ":" + orderId, "1", 24, TimeUnit.HOURS);
|
||||
OrderEntity order = orderRepository.getOrder(orderId);
|
||||
List<OrderItemEntity> orderItems = orderMapper.getOrderItems(orderId);
|
||||
orderItems.forEach(item -> {
|
||||
@@ -1890,7 +1890,6 @@ public class PrinterServiceImpl implements PrinterService {
|
||||
order.setStatus(OrderStateEnum.PAID.getState());
|
||||
order.setPayAt(new Date());
|
||||
orderMapper.updateOrder(order);
|
||||
setUserIsBuyItem(virtualMemberId, memberPrintId.longValue(), orderId, needEnhance);
|
||||
log.info("待支付订单计算后价格为0,直接完成购买: orderId={}", orderId);
|
||||
result.put("needPay", false);
|
||||
} else {
|
||||
@@ -1916,12 +1915,14 @@ public class PrinterServiceImpl implements PrinterService {
|
||||
result.put("price", order.getPayPrice());
|
||||
}
|
||||
} else {
|
||||
// 立即购买模式:触发购买后逻辑
|
||||
setUserIsBuyItem(virtualMemberId, memberPrintId.longValue(), orderId, needEnhance);
|
||||
log.info("触发购买后逻辑完成: orderId={}", orderId);
|
||||
result.put("needPay", false);
|
||||
}
|
||||
|
||||
// 无论是否需要支付,都立即触发购买后动作(打印等)
|
||||
// setUserIsBuyItem 内部通过 Redis 去重,支付回调到达时不会重复触发
|
||||
setUserIsBuyItem(virtualMemberId, memberPrintId.longValue(), orderId, needEnhance);
|
||||
log.info("触发购买后逻辑完成: orderId={}", orderId);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
38
src/main/resources/mapper/PrinterGuideMapper.xml
Normal file
38
src/main/resources/mapper/PrinterGuideMapper.xml
Normal file
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.ycwl.basic.mapper.PrinterGuideMapper">
|
||||
<select id="listByPrinterId" resultType="com.ycwl.basic.model.pc.printer.entity.PrinterGuideEntity">
|
||||
select id, printer_id, image_url, sort_order, enabled, create_time, update_time
|
||||
from printer_guide
|
||||
where printer_id = #{printerId}
|
||||
order by sort_order asc, id asc
|
||||
</select>
|
||||
|
||||
<select id="listEnabledByPrinterId" resultType="com.ycwl.basic.model.pc.printer.entity.PrinterGuideEntity">
|
||||
select id, printer_id, image_url, sort_order, enabled, create_time, update_time
|
||||
from printer_guide
|
||||
where printer_id = #{printerId} and enabled = 1
|
||||
order by sort_order asc, id asc
|
||||
</select>
|
||||
|
||||
<insert id="insertGuide" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into printer_guide(printer_id, image_url, sort_order, enabled, create_time)
|
||||
values (#{printerId}, #{imageUrl}, #{sortOrder}, #{enabled}, NOW())
|
||||
</insert>
|
||||
|
||||
<delete id="deleteById">
|
||||
delete from printer_guide where id = #{id}
|
||||
</delete>
|
||||
|
||||
<update id="updateSortOrder">
|
||||
update printer_guide
|
||||
set sort_order = #{sortOrder}, update_time = NOW()
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="toggleEnabled">
|
||||
update printer_guide
|
||||
set enabled = 1 - enabled, update_time = NOW()
|
||||
where id = #{id}
|
||||
</update>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user