feat: 添加打印机管理模块,支持局域网打印
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
package com.example.building.controller;
|
||||
|
||||
import com.example.building.common.Result;
|
||||
import com.example.building.entity.Printer;
|
||||
import com.example.building.service.PrinterService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 打印机控制器
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/printers")
|
||||
public class PrinterController {
|
||||
|
||||
@Autowired
|
||||
private PrinterService printerService;
|
||||
|
||||
/**
|
||||
* 获取打印机列表
|
||||
*/
|
||||
@GetMapping
|
||||
public Result<List<Printer>> getPrinters() {
|
||||
return Result.success(printerService.list());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取默认打印机
|
||||
*/
|
||||
@GetMapping("/default")
|
||||
public Result<Printer> getDefaultPrinter() {
|
||||
Printer printer = printerService.getDefaultPrinter();
|
||||
return Result.success(printer);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加打印机
|
||||
*/
|
||||
@PostMapping
|
||||
public Result<Printer> addPrinter(@RequestBody Printer printer) {
|
||||
printerService.save(printer);
|
||||
return Result.success(printer);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新打印机
|
||||
*/
|
||||
@PutMapping("/{id}")
|
||||
public Result<Printer> updatePrinter(@PathVariable String id, @RequestBody Printer printer) {
|
||||
printer.setPrinterId(id);
|
||||
printerService.updateById(printer);
|
||||
return Result.success(printer);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除打印机
|
||||
*/
|
||||
@DeleteMapping("/{id}")
|
||||
public Result<Void> deletePrinter(@PathVariable String id) {
|
||||
printerService.removeById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置默认打印机
|
||||
*/
|
||||
@PutMapping("/{id}/default")
|
||||
public Result<Void> setDefaultPrinter(@PathVariable String id) {
|
||||
// 先取消所有默认
|
||||
List<Printer> printers = printerService.list();
|
||||
for (Printer p : printers) {
|
||||
if (p.getIsDefault() != null && p.getIsDefault() == 1) {
|
||||
p.setIsDefault(0);
|
||||
printerService.updateById(p);
|
||||
}
|
||||
}
|
||||
// 设置新的默认
|
||||
Printer printer = printerService.getById(id);
|
||||
if (printer != null) {
|
||||
printer.setIsDefault(1);
|
||||
printerService.updateById(printer);
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印订单
|
||||
*/
|
||||
@PostMapping("/print/{orderId}")
|
||||
public Result<Void> printOrder(@PathVariable String orderId) {
|
||||
printerService.printOrder(orderId);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user