fix:采购单打印机参数配置
This commit is contained in:
@@ -1,15 +0,0 @@
|
|||||||
package org.nl.config;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@Configuration
|
|
||||||
@ConfigurationProperties("printer")
|
|
||||||
public class PrinterProperties {
|
|
||||||
|
|
||||||
private String ip = "192.168.1.100";
|
|
||||||
|
|
||||||
private int port = 9100;
|
|
||||||
}
|
|
||||||
@@ -24,11 +24,12 @@ import org.nl.wms.pm_manage.purchase.service.dto.PurchaseDto;
|
|||||||
import org.nl.wms.pm_manage.purchase.service.vo.PurchasemstListVo;
|
import org.nl.wms.pm_manage.purchase.service.vo.PurchasemstListVo;
|
||||||
import org.nl.wms.ext_manage.purchase.service.dto.EasAuditRequestDto;
|
import org.nl.wms.ext_manage.purchase.service.dto.EasAuditRequestDto;
|
||||||
import org.nl.wms.pm_manage.purchase.util.ZplUtil;
|
import org.nl.wms.pm_manage.purchase.util.ZplUtil;
|
||||||
|
import org.nl.wms.system_manage.enums.SysParamConstant;
|
||||||
|
import org.nl.wms.system_manage.service.param.ISysParamService;
|
||||||
import org.nl.wms.warehouse_manage.enums.IOSEnum;
|
import org.nl.wms.warehouse_manage.enums.IOSEnum;
|
||||||
import org.nl.wms.warehouse_manage.stockReturn.service.IPmStockReturnService;
|
import org.nl.wms.warehouse_manage.stockReturn.service.IPmStockReturnService;
|
||||||
import org.nl.wms.warehouse_manage.stockReturn.service.dao.PmStockReturn;
|
import org.nl.wms.warehouse_manage.stockReturn.service.dao.PmStockReturn;
|
||||||
import org.nl.wms.warehouse_manage.stockReturn.service.enums.StockReturnStatusEnum;
|
import org.nl.wms.warehouse_manage.stockReturn.service.enums.StockReturnStatusEnum;
|
||||||
import org.nl.config.PrinterProperties;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@@ -55,7 +56,7 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchasemstMapper, Purchase
|
|||||||
private WmsToErpService wmsToErpService;
|
private WmsToErpService wmsToErpService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PrinterProperties printerProperties;
|
private ISysParamService sysParamService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IPage<PurchasemstListVo> queryAll(Map whereJson, PageQuery page) {
|
public IPage<PurchasemstListVo> queryAll(Map whereJson, PageQuery page) {
|
||||||
@@ -194,6 +195,8 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchasemstMapper, Purchase
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void print(Set<String> ids) {
|
public void print(Set<String> ids) {
|
||||||
|
String ip = sysParamService.findByCode(SysParamConstant.PRINTER_IP).getValue();
|
||||||
|
String port = sysParamService.findByCode(SysParamConstant.PRINTER_PORT).getValue();
|
||||||
List<Purchasemst> mstList = purchasemstMapper.selectBatchIds(ids);
|
List<Purchasemst> mstList = purchasemstMapper.selectBatchIds(ids);
|
||||||
if (ObjectUtil.isEmpty(mstList)) {
|
if (ObjectUtil.isEmpty(mstList)) {
|
||||||
throw new BadRequestException("未找到选中的单据");
|
throw new BadRequestException("未找到选中的单据");
|
||||||
@@ -213,15 +216,14 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchasemstMapper, Purchase
|
|||||||
labelCount++;
|
labelCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try (Socket socket = new Socket(printerProperties.getIp(), printerProperties.getPort());
|
try (Socket socket = new Socket(ip, Integer.parseInt(port));
|
||||||
OutputStream out = socket.getOutputStream()) {
|
OutputStream out = socket.getOutputStream()) {
|
||||||
out.write(allZpl.toString().getBytes(StandardCharsets.UTF_8));
|
out.write(allZpl.toString().getBytes(StandardCharsets.UTF_8));
|
||||||
out.flush();
|
out.flush();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("打印失败, 打印机: {}:{}, 标签数: {}", printerProperties.getIp(), printerProperties.getPort(), labelCount, e);
|
log.error("打印失败, 打印机: {}:{}, 标签数: {}", ip, port, labelCount, e);
|
||||||
throw new BadRequestException("打印机连接失败: " + e.getMessage());
|
throw new BadRequestException("打印机连接失败: " + e.getMessage());
|
||||||
}
|
}
|
||||||
log.info("打印成功, 打印机: {}:{}, 标签数: {}", printerProperties.getIp(), printerProperties.getPort(), labelCount);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -30,5 +30,13 @@ public class SysParamConstant {
|
|||||||
* MES URL
|
* MES URL
|
||||||
*/
|
*/
|
||||||
public final static String MES_URL = "mes_url";
|
public final static String MES_URL = "mes_url";
|
||||||
|
/**
|
||||||
|
* 打印机ip
|
||||||
|
*/
|
||||||
|
public final static String PRINTER_IP = "printer_ip";
|
||||||
|
/**
|
||||||
|
* 打印机端口
|
||||||
|
*/
|
||||||
|
public final static String PRINTER_PORT = "printer_port";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user