add:大屏新增打印功能-调整为zpl指令网络打印方式

This commit is contained in:
zhaoyf
2026-05-06 14:29:00 +08:00
parent f9bf40b415
commit 5427d7c414
7 changed files with 160 additions and 61 deletions

View File

@@ -13,6 +13,7 @@ import org.nl.common.logging.annotation.Log;
import org.nl.wms.ext.fab.service.dto.CallEmpVo;
import org.nl.wms.ext.fab.service.impl.FabServiceImpl;
import org.nl.wms.ext.handheld.dto.EmptyVehicleWarehousingDto;
import org.nl.wms.ext.handheld.dto.PrintEntityDto;
import org.nl.wms.ext.handheld.service.HandheldService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
@@ -262,4 +263,15 @@ public class HandheldController {
fabService.createAgvTask(toJSON, "cnt");
return new ResponseEntity(TableDataInfo.build(), HttpStatus.OK);
}
/**
* 大屏打印订单
* @return
*/
@Log("大屏打印订单标签")
@PostMapping("/print")
public ResponseEntity<Object> print(@RequestBody PrintEntityDto printEntityDto) {
handheldService.print(printEntityDto);
return new ResponseEntity<>(HttpStatus.OK);
}
}

View File

@@ -0,0 +1,20 @@
package org.nl.wms.ext.handheld.dto;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
@Data
public class PrintEntityDto {
@JsonProperty("order_code")
private String orderCode;
@JsonProperty("create_time")
private String createTime;
@JsonProperty("material_qty")
private String materialQty;
@JsonProperty("material_id")
private String materialId;
@JsonProperty("material_code")
private String MaterialCode;
@JsonProperty("username")
private String username;
}

View File

@@ -3,6 +3,7 @@ package org.nl.wms.ext.handheld.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.nl.wms.ext.handheld.dto.EmptyVehicleWarehousingDto;
import org.nl.wms.ext.handheld.dto.PrintEntityDto;
import org.nl.wms.sch.group_delete_log.service.dto.SD01GroupLogRespondDto;
import java.util.List;
@@ -207,4 +208,9 @@ public interface HandheldService {
*/
JSONObject queryVehicleTaskStatus(String vehicleCode);
/**
* 大屏打印订单标签
* @param printEntityDto 打印内容实体
*/
void print(PrintEntityDto printEntityDto);
}

View File

@@ -1,21 +1,16 @@
package org.nl.wms.ext.handheld.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import java.math.BigDecimal;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.Synchronized;
import nl.basjes.shaded.org.springframework.util.Assert;
import org.apache.commons.lang3.StringUtils;
import org.nl.common.enums.GoodsEnum;
@@ -24,13 +19,13 @@ import org.nl.common.enums.region.RegionEnum;
import org.nl.system.service.dict.ISysDictService;
import org.nl.system.service.dict.dao.Dict;
import org.nl.wms.ext.handheld.dto.EmptyVehicleWarehousingDto;
import org.nl.wms.ext.handheld.dto.PrintEntityDto;
import org.nl.wms.ext.handheld.dto.VehicleDto;
import org.nl.wms.sch.group_delete_log.service.dao.SchBaseVehiclematerialgroupDeleteLog;
import org.nl.wms.sch.group_delete_log.service.ISchBaseVehiclematerialgroupDeleteLogService;
import org.nl.wms.sch.group_delete_log.service.dto.LogMaterialDto;
import org.nl.wms.sch.group_delete_log.service.dto.SD01GroupLogRespondDto;
import org.nl.wms.sch.task.service.dao.SchBaseTask;
import org.nl.wms.sch.task_manage.enums.GroupBindMaterialStatusEnum;
import org.nl.common.exception.BadRequestException;
import org.nl.common.utils.RedisUtils;
import org.nl.common.utils.SecurityUtils;
@@ -59,17 +54,20 @@ import org.nl.wms.sch.task_manage.GeneralDefinition;
import org.nl.wms.sch.task_manage.task.TaskFactory;
import org.nl.wms.sch.task_manage.task.core.TaskStatus;
import org.nl.wms.sch.task_manage.task.core.TaskType;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicBoolean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
@@ -117,6 +115,9 @@ public class HandheldServiceImpl implements HandheldService {
// 线程池,用于异步执行任务
private final ExecutorService executorService = Executors.newSingleThreadExecutor();
@Autowired
private SysParamServiceImpl sysParamServiceImpl;
@Override
@@ -1720,4 +1721,52 @@ 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)) {
throw new BadRequestException("打印出错未配置打印机IP(printerIP)");
}
if (port == null || StringUtils.isBlank(port)) {
throw new BadRequestException("打印出错:未配置打印机端口(printerPort)");
}
try (Socket client = new Socket()) {
// 3. 设置超时时间,防止网络不通时线程卡死 (单位:毫秒)
client.connect(new InetSocketAddress(ip, Integer.parseInt(port)), 3000); // 连接超时 3秒
client.setSoTimeout(10000); // 读取超时 10秒
try (OutputStream outputStream = client.getOutputStream()) {
StringBuilder zplStr = new StringBuilder();
// TODO: 在此拼接 ZPL 指令
zplStr.append("^XA");//开始
zplStr.append("^CI28");// 启用UTF-8字符集支持中文显示部分老机型若乱码请改用 ^CI13
zplStr.append("^CW1,E:SIMSUN.FNT");//设置中文字体
zplStr.append("^FO50,75^A1,55,55^FD订单号^FS");
zplStr.append("^FO250,50^BC,50,50^FD"+printEntityDto.getOrderCode()+"^FS");//订单号条码
zplStr.append("^FO250,100^A1,50,50^FD"+printEntityDto.getOrderCode()+"^FS");//订单号
zplStr.append("^FO50,175^A1,55,55^FD物料号^FS");
zplStr.append("^FO250,150^BC,50,50^FD"+printEntityDto.getOrderCode()+"^FS");//物料号条码
zplStr.append("^FO250,200^A1,50,50^FD"+printEntityDto.getOrderCode()+"^FS");//物料号
zplStr.append("^FO50,275^A1,55,55^FD数量^FS");
zplStr.append("^FO250,275^A1,50,50^FD"+printEntityDto.getMaterialQty()+"^FS");//数量
zplStr.append("^FO50,350^A1,55,55^FD日期^FS");
zplStr.append("^FO250,350^A1,50,50^FD"+printEntityDto.getCreateTime()+"^FS");//日期
zplStr.append("^FO50,425^A1,55,55^FD人员^FS");
zplStr.append("^FO250,425^A1,50,50^FD"+printEntityDto.getUsername()+"^FS");//人员
zplStr.append("^XZ");//结束
// 4. 将 ZPL 指令写入输出流并发送
if (zplStr.length() > 0) {
outputStream.write(zplStr.toString().getBytes(StandardCharsets.UTF_8));
outputStream.flush(); // 必须 flush确保数据发送到打印机
}
}
} catch (IOException e) {
// 5. 异常处理:不要仅仅抛出 e.getMessage(),有时候它为空
throw new BadRequestException("打印出错,连接打印机失败: " + e.getMessage());
}
}
}