opt:大屏打印功能-新增打印机管理页面支持多打印机

This commit is contained in:
zhaoyf
2026-05-09 14:22:25 +08:00
parent 5427d7c414
commit c3b58b1d0d
15 changed files with 559 additions and 8 deletions

View File

@@ -0,0 +1,71 @@
package org.nl.system.controller.printer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.nl.common.base.TableDataInfo;
import org.nl.common.domain.query.PageQuery;
import org.nl.common.logging.annotation.Log;
import org.nl.system.service.param.dao.Param;
import org.nl.system.service.printer.ISysPrinterService;
import org.nl.system.service.printer.dao.SysPrinter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* @author zhaoyf
* @date 2026-05-07
**/
@Slf4j
@RestController
@RequestMapping("/api/printer")
@Api("打印机管理")
public class SysPrinterController {
@Autowired
private ISysPrinterService iSysPrinterService;
@GetMapping
@Log("查询所有打印机")
@ApiOperation("查询打印机")
public ResponseEntity<Object> query(@RequestParam Map whereJson, PageQuery page){
return new ResponseEntity<>(TableDataInfo.build(iSysPrinterService.queryAll(whereJson, page)), HttpStatus.OK);
}
@GetMapping("/all")
public ResponseEntity<Object> all(){
return new ResponseEntity<>(iSysPrinterService.list(),HttpStatus.OK);
}
@PostMapping
@Log("新增打印机")
@ApiOperation("新增")
public ResponseEntity<Object> create(@Validated @RequestBody SysPrinter param){
iSysPrinterService.create(param);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@PutMapping
@Log("修改打印机参数")
@ApiOperation("修改打印机参数")
public ResponseEntity<Object> update(@Validated @RequestBody SysPrinter param){
iSysPrinterService.update(param);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Log("删除打印机")
@ApiOperation("删除打印机")
@DeleteMapping
public ResponseEntity<Object> delete(@RequestBody String[] ids) {
List<String> Ids = Arrays.asList(ids);
iSysPrinterService.deleteAll(Ids);
return new ResponseEntity<>(HttpStatus.OK);
}
}

View File

@@ -0,0 +1,44 @@
package org.nl.system.service.printer;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.nl.common.domain.query.PageQuery;
import com.baomidou.mybatisplus.extension.service.IService;
import org.nl.system.service.printer.dao.SysPrinter;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @description 服务接口
* @author zhaoyf
* @date 2026-05-07
**/
public interface ISysPrinterService extends IService<SysPrinter> {
/**
* 查询数据分页
* @param whereJson 条件
* @param pageable 分页参数
* @return IPage<SysPrinter>
*/
IPage<SysPrinter> queryAll(Map whereJson, PageQuery pageable);
/**
* 创建
* @param entity /
*/
void create(SysPrinter entity);
/**
* 编辑
* @param entity /
*/
void update(SysPrinter entity);
/**
* 多选删除
* @param ids /
*/
void deleteAll(List<String> ids);
}

View File

@@ -0,0 +1,77 @@
package org.nl.system.service.printer.dao;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
/**
* @description /
* @author zhaoyf
* @date 2026-05-07
**/
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("sys_printer")
public class SysPrinter implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
private String name;
private String ip;
private Integer port;
/**
* 备注
*/
private String remark;
/**
* 是否启用
*/
private Boolean is_active;
/**
* 是否删除
*/
private Boolean is_delete;
/**
* 创建者ID
*/
private String create_id;
/**
* 创建者
*/
private String create_name;
/**
* 创建时间
*/
private String create_time;
/**
* 修改者ID
*/
private String update_id;
/**
* 修改者
*/
private String update_name;
/**
* 修改时间
*/
private String update_time;
}

View File

@@ -0,0 +1,12 @@
package org.nl.system.service.printer.dao.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.nl.system.service.printer.dao.SysPrinter;
/**
* @author zhaoyf
* @date 2026-05-07
**/
public interface SysPrinterMapper extends BaseMapper<SysPrinter> {
}

View File

@@ -0,0 +1,5 @@
<?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="org.nl.system.service.printer.dao.mapper.SysPrinterMapper">
</mapper>

View File

@@ -0,0 +1,14 @@
package org.nl.system.service.printer.dto;
import lombok.Data;
import java.io.Serializable;
/**
* @description /
* @author zhaoyf
* @date 2026-05-07
**/
@Data
public class SysPrinterDto implements Serializable {
}

View File

@@ -0,0 +1,12 @@
package org.nl.system.service.printer.dto;
import org.nl.common.domain.query.BaseQuery;
import org.nl.system.service.printer.dao.SysPrinter;
/**
* @author zhaoyf
* @date 2026-05-07
**/
public class SysPrinterQuery extends BaseQuery<SysPrinter> {
}

View File

@@ -0,0 +1,80 @@
package org.nl.system.service.printer.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.common.domain.query.PageQuery;
import org.nl.common.exception.BadRequestException;
import org.nl.common.utils.SecurityUtils;
import org.nl.system.service.printer.ISysPrinterService;
import org.nl.system.service.printer.dao.SysPrinter;
import org.nl.system.service.printer.dao.mapper.SysPrinterMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @description 服务实现
* @author zhaoyf
* @date 2026-05-07
**/
@Slf4j
@Service
public class SysPrinterServiceImpl extends ServiceImpl<SysPrinterMapper, SysPrinter> implements ISysPrinterService {
@Autowired
private SysPrinterMapper sysPrinterMapper;
@Override
public IPage<SysPrinter> queryAll(Map whereJson, PageQuery page){
LambdaQueryWrapper<SysPrinter> lam = new LambdaQueryWrapper<>();
IPage<SysPrinter> pages = new Page<>(page.getPage() + 1, page.getSize());
sysPrinterMapper.selectPage(pages, lam);
return pages;
}
@Override
public void create(SysPrinter entity) {
String currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getCurrentNickName();
String now = DateUtil.now();
entity.setCreate_id(currentUserId);
entity.setCreate_name(nickName);
entity.setCreate_time(now);
entity.setUpdate_id(currentUserId);
entity.setUpdate_name(nickName);
entity.setUpdate_time(now);
sysPrinterMapper.insert(entity);
}
@Override
public void update(SysPrinter entity) {
SysPrinter dto = sysPrinterMapper.selectById(entity.getId());
if (dto == null) throw new BadRequestException("被删除或无权限,操作失败!");
String currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getCurrentNickName();
String now = DateUtil.now();
entity.setUpdate_id(currentUserId);
entity.setUpdate_name(nickName);
entity.setUpdate_time(now);
sysPrinterMapper.updateById(entity);
}
@Override
public void deleteAll(List<String> ids) {
// 真删除
sysPrinterMapper.deleteBatchIds(ids);
}
}

View File

@@ -17,4 +17,6 @@ public class PrintEntityDto {
private String MaterialCode;
@JsonProperty("username")
private String username;
private String ip;
private Integer port;
}

View File

@@ -1724,17 +1724,15 @@ public class HandheldServiceImpl implements HandheldService {
@Override
public void print(PrintEntityDto printEntityDto) {
String ip = sysParamServiceImpl.findByCode("printerIP").getValue();
String port = sysParamServiceImpl.findByCode("printerPort").getValue();
if (ip == null || StringUtils.isBlank(ip)) {
if (printEntityDto.getIp() == null || StringUtils.isBlank(printEntityDto.getIp())) {
throw new BadRequestException("打印出错未配置打印机IP(printerIP)");
}
if (port == null || StringUtils.isBlank(port)) {
if (printEntityDto.getPort() == null) {
throw new BadRequestException("打印出错:未配置打印机端口(printerPort)");
}
try (Socket client = new Socket()) {
// 3. 设置超时时间,防止网络不通时线程卡死 (单位:毫秒)
client.connect(new InetSocketAddress(ip, Integer.parseInt(port)), 3000); // 连接超时 3秒
client.connect(new InetSocketAddress(printEntityDto.getIp(), printEntityDto.getPort()), 3000); // 连接超时 3秒
client.setSoTimeout(10000); // 读取超时 10秒
try (OutputStream outputStream = client.getOutputStream()) {