feat(pc): 添加打印机管理功能- 新增 PrinterManageController 类实现打印机管理接口

- 添加打印机列表查询、详情、创建、更新、删除等功能
- 新增打印机状态、首选尺寸、当前使用设备更新接口
- 在 PrinterMapper.xml 中添加相关 SQL 语句
This commit is contained in:
2025-09-19 12:32:58 +08:00
parent 524627ea73
commit ad33b1abef
5 changed files with 208 additions and 7 deletions

View File

@@ -0,0 +1,131 @@
package com.ycwl.basic.controller.pc;
import com.ycwl.basic.model.pc.printer.entity.PrinterEntity;
import com.ycwl.basic.model.pc.printer.req.PrinterPreferredSizeUpdateReq;
import com.ycwl.basic.model.pc.printer.req.PrinterStatusUpdateReq;
import com.ycwl.basic.model.pc.printer.req.PrinterUsePrinterUpdateReq;
import com.ycwl.basic.service.printer.PrinterService;
import com.ycwl.basic.utils.ApiConst;
import com.ycwl.basic.utils.ApiResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
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;
/**
* 打印机管理接口
*/
@RestController
@RequestMapping("/api/pc/printers/v1")
@RequiredArgsConstructor
public class PrinterManageController {
private final PrinterService printerService;
/**
* 打印机列表查询
*/
@GetMapping
public ApiResponse<List<PrinterEntity>> list(@RequestParam(value = "scenicId", required = false) Long scenicId,
@RequestParam(value = "status", required = false) Integer status,
@RequestParam(value = "name", required = false) String name) {
PrinterEntity condition = new PrinterEntity();
condition.setScenicId(scenicId);
condition.setStatus(status);
condition.setName(name);
return printerService.list(condition);
}
/**
* 打印机详情
*/
@GetMapping("/{id}")
public ApiResponse<PrinterEntity> detail(@PathVariable("id") Integer id) {
ApiResponse<PrinterEntity> response = printerService.get(id);
if (response.getData() == null) {
return ApiResponse.buildResponse(ApiConst.Code.CODE_NOT_EXIST, "打印机不存在");
}
return response;
}
/**
* 新增打印机
*/
@PostMapping
public ApiResponse<Integer> create(@RequestBody PrinterEntity request) {
request.setId(null);
return printerService.add(request);
}
/**
* 更新打印机信息
*/
@PutMapping("/{id}")
public ApiResponse<Integer> update(@PathVariable("id") Integer id, @RequestBody PrinterEntity request) {
request.setId(id);
return printerService.update(request);
}
/**
* 更新打印机状态
*/
@PatchMapping("/{id}/status")
public ApiResponse<Integer> updateStatus(@PathVariable("id") Integer id,
@RequestBody PrinterStatusUpdateReq req) {
if (req == null || req.getStatus() == null) {
return ApiResponse.buildResponse(ApiConst.Code.CODE_PARAM_ERROR, "状态不能为空");
}
PrinterEntity entity = new PrinterEntity();
entity.setId(id);
entity.setStatus(req.getStatus());
return printerService.update(entity);
}
/**
* 更新打印机首选尺寸
*/
@PatchMapping("/{id}/preferred-size")
public ApiResponse<Integer> updatePreferredSize(@PathVariable("id") Integer id,
@RequestBody PrinterPreferredSizeUpdateReq req) {
if (req == null || (req.getPreferW() == null && req.getPreferH() == null)) {
return ApiResponse.buildResponse(ApiConst.Code.CODE_PARAM_ERROR, "首选尺寸不能为空");
}
PrinterEntity entity = new PrinterEntity();
entity.setId(id);
entity.setPreferW(req.getPreferW());
entity.setPreferH(req.getPreferH());
return printerService.update(entity);
}
/**
* 更新当前使用的打印机
*/
@PatchMapping("/{id}/use-printer")
public ApiResponse<Integer> updateUsePrinter(@PathVariable("id") Integer id,
@RequestBody PrinterUsePrinterUpdateReq req) {
if (req == null) {
return ApiResponse.buildResponse(ApiConst.Code.CODE_PARAM_ERROR, "请求参数不能为空");
}
PrinterEntity entity = new PrinterEntity();
entity.setId(id);
entity.setUsePrinter(req.getUsePrinter());
return printerService.update(entity);
}
/**
* 删除打印机
*/
@DeleteMapping("/{id}")
public ApiResponse<Integer> delete(@PathVariable("id") Integer id) {
return printerService.delete(id);
}
}

View File

@@ -0,0 +1,19 @@
package com.ycwl.basic.model.pc.printer.req;
import lombok.Data;
/**
* 打印机首选尺寸更新请求
*/
@Data
public class PrinterPreferredSizeUpdateReq {
/**
* 首选宽度
*/
private Integer preferW;
/**
* 首选高度
*/
private Integer preferH;
}

View File

@@ -0,0 +1,14 @@
package com.ycwl.basic.model.pc.printer.req;
import lombok.Data;
/**
* 打印机状态更新请求
*/
@Data
public class PrinterStatusUpdateReq {
/**
* 打印机状态:0-停用,1-启用
*/
private Integer status;
}

View File

@@ -0,0 +1,14 @@
package com.ycwl.basic.model.pc.printer.req;
import lombok.Data;
/**
* 打印机当前使用设备更新请求
*/
@Data
public class PrinterUsePrinterUpdateReq {
/**
* 当前使用打印机标识
*/
private String usePrinter;
}

View File

@@ -78,6 +78,8 @@
printers, printers,
use_printer, use_printer,
status, status,
prefer_w,
prefer_h,
create_time, create_time,
update_time update_time
) VALUES ( ) VALUES (
@@ -87,6 +89,8 @@
#{printers}, #{printers},
#{usePrinter}, #{usePrinter},
#{status}, #{status},
#{preferW},
#{preferH},
NOW(), NOW(),
NOW() NOW()
) )
@@ -116,14 +120,33 @@
<!-- 更新 --> <!-- 更新 -->
<update id="update"> <update id="update">
UPDATE printer UPDATE printer
SET <set>
access_key = #{accessKey}, <if test="accessKey != null">
name = #{name}, access_key = #{accessKey},
scenic_id = #{scenicId}, </if>
printers = #{printers}, <if test="name != null">
use_printer = #{usePrinter}, name = #{name},
status = #{status}, </if>
<if test="scenicId != null">
scenic_id = #{scenicId},
</if>
<if test="printers != null">
printers = #{printers},
</if>
<if test="usePrinter != null">
use_printer = #{usePrinter},
</if>
<if test="status != null">
status = #{status},
</if>
<if test="preferW != null">
prefer_w = #{preferW},
</if>
<if test="preferH != null">
prefer_h = #{preferH},
</if>
update_time = NOW() update_time = NOW()
</set>
WHERE id = #{id} WHERE id = #{id}
</update> </update>
<update id="updateTaskStatus"> <update id="updateTaskStatus">