You've already forked FrameTour-BE
feat(printer): 添加打印任务分页查询和重新打印功能- 引入 PageHelper 和 PageInfo 实现分页查询
All checks were successful
ZhenTu-BE/pipeline/head This commit looks good
All checks were successful
ZhenTu-BE/pipeline/head This commit looks good
- 新增 PrintTaskMapper 接口方法 queryByCondition 和 updateStatus
- 扩展 PrintTaskEntity 实体类,新增 mpId 和 paper 字段- 在 PrinterController 中新增 /task/page 和 /task/reprint/{id} 接口- 更新 PrintTaskMapper.xml,添加查询和更新状态的 SQL语句- 优化打印任务插入逻辑,补充 mpId 和 paper 字段赋值
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
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.model.pc.printer.entity.PrintTaskEntity;
|
||||
import com.ycwl.basic.model.pc.printer.entity.PrinterEntity;
|
||||
import com.ycwl.basic.model.pc.printer.req.PrintTaskReqQuery;
|
||||
import com.ycwl.basic.service.printer.PrinterService;
|
||||
import com.ycwl.basic.utils.ApiResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -20,6 +25,9 @@ public class PrinterController {
|
||||
@Autowired
|
||||
private PrinterService printerService;
|
||||
|
||||
@Autowired
|
||||
private PrintTaskMapper printTaskMapper;
|
||||
|
||||
// 查询列表
|
||||
@PostMapping("/list")
|
||||
public ApiResponse<List<PrinterEntity>> list(@RequestBody PrinterEntity condition) {
|
||||
@@ -49,4 +57,20 @@ public class PrinterController {
|
||||
public ApiResponse<Integer> delete(@PathVariable("id") Integer id) {
|
||||
return printerService.delete(id);
|
||||
}
|
||||
|
||||
// 分页查询打印任务
|
||||
@PostMapping("/task/page")
|
||||
public ApiResponse<PageInfo<PrintTaskEntity>> taskPage(@RequestBody PrintTaskReqQuery req) {
|
||||
PageHelper.startPage(req.getPageNum(), req.getPageSize());
|
||||
List<PrintTaskEntity> list = printTaskMapper.queryByCondition(req.getPrinterId(), req.getStatus());
|
||||
PageInfo<PrintTaskEntity> pageInfo = new PageInfo<>(list);
|
||||
return ApiResponse.success(pageInfo);
|
||||
}
|
||||
|
||||
// 重新打印(将状态设置为0-未开始)
|
||||
@PostMapping("/task/reprint/{id}")
|
||||
public ApiResponse<Integer> reprint(@PathVariable("id") Integer id) {
|
||||
int result = printTaskMapper.updateStatus(id, 0);
|
||||
return ApiResponse.success(result);
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,15 @@ package com.ycwl.basic.mapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.ycwl.basic.model.pc.printer.entity.PrintTaskEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface PrintTaskMapper extends BaseMapper<PrintTaskEntity> {
|
||||
int insertTask(PrintTaskEntity entity);
|
||||
|
||||
List<PrintTaskEntity> queryByCondition(@Param("printerId") Integer printerId, @Param("status") Integer status);
|
||||
|
||||
int updateStatus(@Param("id") Integer id, @Param("status") Integer status);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ public class PrintTaskEntity {
|
||||
|
||||
@TableField("height")
|
||||
private Integer height;
|
||||
private Integer mpId;
|
||||
private String paper;
|
||||
|
||||
@TableField("create_time")
|
||||
private Date createTime;
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.ycwl.basic.model.pc.printer.req;
|
||||
|
||||
import com.ycwl.basic.model.common.BaseQueryParameterReq;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class PrintTaskReqQuery extends BaseQueryParameterReq {
|
||||
/**
|
||||
* 打印机ID
|
||||
*/
|
||||
private Integer printerId;
|
||||
|
||||
/**
|
||||
* 状态:0未开始,1已完成,2正在处理,3已失败
|
||||
*/
|
||||
private Integer status;
|
||||
}
|
||||
@@ -561,6 +561,8 @@ public class PrinterServiceImpl implements PrinterService {
|
||||
|
||||
PrintTaskEntity task = new PrintTaskEntity();
|
||||
task.setPrinterId(printer.getId());
|
||||
task.setMpId(item.getId());
|
||||
task.setPaper(printer.getPreferPaper());
|
||||
task.setStatus(0);
|
||||
task.setUrl(printUrl);
|
||||
task.setHeight(printer.getPreferH());
|
||||
|
||||
@@ -2,7 +2,26 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.ycwl.basic.mapper.PrintTaskMapper">
|
||||
<insert id="insertTask">
|
||||
insert into print_task(printer_id, status, printer_name, url, width, height, create_time)
|
||||
values (#{printerId}, 0, #{printerName}, #{url}, #{width}, #{height}, NOW())
|
||||
insert into print_task(printer_id, mp_id, paper, status, printer_name, url, width, height, create_time)
|
||||
values (#{printerId}, #{mpId}, #{paper}, 0, #{printerName}, #{url}, #{width}, #{height}, NOW())
|
||||
</insert>
|
||||
|
||||
<select id="queryByCondition" resultType="com.ycwl.basic.model.pc.printer.entity.PrintTaskEntity">
|
||||
select id, printer_id, status, printer_name, url, width, height, mp_id, paper, create_time, update_time
|
||||
from print_task
|
||||
where 1=1
|
||||
<if test="printerId != null">
|
||||
and printer_id = #{printerId}
|
||||
</if>
|
||||
<if test="status != null">
|
||||
and status = #{status}
|
||||
</if>
|
||||
order by create_time desc
|
||||
</select>
|
||||
|
||||
<update id="updateStatus">
|
||||
update print_task
|
||||
set status = #{status}, update_time = NOW()
|
||||
where id = #{id}
|
||||
</update>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user