md
This commit is contained in:
parent
28c6854731
commit
c169655291
@ -44,6 +44,7 @@ import com.xdadan.erp.emis.domain.stat.ScanStatInfoDtl;
|
|||||||
import com.xdadan.erp.emis.domain.vo.*;
|
import com.xdadan.erp.emis.domain.vo.*;
|
||||||
import com.xdadan.erp.emis.service.*;
|
import com.xdadan.erp.emis.service.*;
|
||||||
import com.xdadan.erp.emis.service.print.IXddTplPrint;
|
import com.xdadan.erp.emis.service.print.IXddTplPrint;
|
||||||
|
import com.xdadan.erp.emis.service.print.cpcl.CvtTplToCpcl;
|
||||||
import com.xdadan.erp.emis.service.print.tanex.TanexSubBillPrintImpl;
|
import com.xdadan.erp.emis.service.print.tanex.TanexSubBillPrintImpl;
|
||||||
import com.xdadan.erp.emis.service.print.tanex.TanexTplPrintImpl;
|
import com.xdadan.erp.emis.service.print.tanex.TanexTplPrintImpl;
|
||||||
import com.xdadan.erp.emis.utils.PrintUtils;
|
import com.xdadan.erp.emis.utils.PrintUtils;
|
||||||
@ -96,6 +97,9 @@ public class EmisWaybillController extends EmisBaseController
|
|||||||
@Autowired
|
@Autowired
|
||||||
private IEmisElectronicSitePagService emisElectronicSitePagService;
|
private IEmisElectronicSitePagService emisElectronicSitePagService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IEmisPrintTplService emisPrintTplService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IEmisTmsScanRecordService emisTmsScanRecordService;
|
private IEmisTmsScanRecordService emisTmsScanRecordService;
|
||||||
|
|
||||||
@ -1123,7 +1127,8 @@ public class EmisWaybillController extends EmisBaseController
|
|||||||
if(!StringUtils.isEmpty(billCode)){
|
if(!StringUtils.isEmpty(billCode)){
|
||||||
try {
|
try {
|
||||||
|
|
||||||
JSONArray jArr = new JSONArray();
|
StringBuilder sbPrintCmd = new StringBuilder();
|
||||||
|
|
||||||
String printManCode=getLoginUser().getUser().getEmpCode();
|
String printManCode=getLoginUser().getUser().getEmpCode();
|
||||||
|
|
||||||
// 确定是否打子单
|
// 确定是否打子单
|
||||||
@ -1134,13 +1139,24 @@ public class EmisWaybillController extends EmisBaseController
|
|||||||
|
|
||||||
if(tplCodeArr.length>0){
|
if(tplCodeArr.length>0){
|
||||||
for (String tpCodeItem:tplCodeArr) {
|
for (String tpCodeItem:tplCodeArr) {
|
||||||
|
EmisPrintTpl emisPrintTpl =emisPrintTplService.selectAppPrintTplByCode(tpCodeItem);
|
||||||
|
if (emisPrintTpl==null) {
|
||||||
|
log.error("缺少打印模版:{}",tpCodeItem);
|
||||||
|
return AjaxResult.error("缺少打印模版:"+tpCodeItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isEmpty(emisPrintTpl.getTplData())) {
|
||||||
|
log.error("打印模版数据为空:{}",tpCodeItem);
|
||||||
|
return AjaxResult.error("打印模版数据为空:"+tpCodeItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if("TAN-GC-130".equals(tpCodeItem)) {
|
if("TAN-GC-130".equals(tpCodeItem)) {
|
||||||
|
|
||||||
// 循环获取主单信息
|
// 循环获取主单信息
|
||||||
String billSubCodeAllStr="";
|
String billSubCodeAllStr="";
|
||||||
String[] billCodeArr = billCode.split(",");
|
String[] billCodeArr = billCode.split(",");
|
||||||
if(billCodeArr.length>0){
|
if(billCodeArr.length>0){
|
||||||
IXddTplPrint xtp = new TanexSubBillPrintImpl();
|
|
||||||
for (String billCodeItem:billCodeArr) {
|
for (String billCodeItem:billCodeArr) {
|
||||||
// 查询主单信息
|
// 查询主单信息
|
||||||
EmisWaybill emisWaybill = emisBaseService.getWaybillByBillCode(billCodeItem);
|
EmisWaybill emisWaybill = emisBaseService.getWaybillByBillCode(billCodeItem);
|
||||||
@ -1175,137 +1191,25 @@ public class EmisWaybillController extends EmisBaseController
|
|||||||
|
|
||||||
if(!StringUtils.isEmpty(item)) {
|
if(!StringUtils.isEmpty(item)) {
|
||||||
Map<String, Object> order = emisBaseService.getWaybillPrintOrder(item, subBillCodeRange, tpCodeItem, "zh", tpCodeItem, printManCode);
|
Map<String, Object> order = emisBaseService.getWaybillPrintOrder(item, subBillCodeRange, tpCodeItem, "zh", tpCodeItem, printManCode);
|
||||||
String pdfBase64Data = xtp.genPDFBase64(order);
|
String cmd=CvtTplToCpcl.getPrintCmd(emisPrintTpl.getTplData(),order);
|
||||||
JSONObject jObj = new JSONObject();
|
sbPrintCmd.append(cmd);
|
||||||
jObj.put("result", "success");
|
|
||||||
jObj.put("billCodeItem", item);
|
|
||||||
jObj.put("file", pdfBase64Data);
|
|
||||||
|
|
||||||
fileArrAll.add(jObj);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// String strArry = PrintUtils.getPdfByBillCode(billSubCodeAllStr, tpCodeItem, printManCode);
|
|
||||||
// JSONArray fileArr = JSONArray.parseArray(strArry);
|
|
||||||
// fileArrAll.addAll(fileArr);
|
|
||||||
}else{
|
}else{
|
||||||
// 直接获取
|
// 直接获取
|
||||||
String strArry = PrintUtils.getPdfByBillCode(billCode, tpCodeItem, printManCode);
|
Map<String, Object> order = emisBaseService.getWaybillPrintOrder(billCode, subBillCodeRange, tpCodeItem, "zh", tpCodeItem, printManCode);
|
||||||
JSONArray fileArr = JSONArray.parseArray(strArry);
|
String cmd=CvtTplToCpcl.getPrintCmd(emisPrintTpl.getTplData(),order);
|
||||||
fileArrAll.addAll(fileArr);
|
sbPrintCmd.append(cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// String strArry=PrintUtils.getPdfByBillCode(billCode,tplCodeStr,printManCode);
|
String printBase64Data=Base64.getEncoder().encodeToString(sbPrintCmd.toString(),"UTF-8");
|
||||||
// JSONArray fileArr = JSONArray.parseArray(strArry);
|
return AjaxResult.success("获取成功",printBase64Data);
|
||||||
for(Object objFile:fileArrAll) {
|
|
||||||
JSONObject jObjFileItem = (JSONObject) objFile;
|
|
||||||
String result = jObjFileItem.getString("result");
|
|
||||||
String billCodeItem = jObjFileItem.getString("billCodeItem");
|
|
||||||
JSONObject printItem = new JSONObject();
|
|
||||||
printItem.put("billCode", billCodeItem);
|
|
||||||
if (!"success".equals(result)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
String pdfbase64 = jObjFileItem.getString("file");
|
|
||||||
try {
|
|
||||||
String fileId = UUID.fastUUID().toString();
|
|
||||||
String fileUploadDir = PayConfig.getUploadPath() + File.separator + DateUtils.datePath();
|
|
||||||
|
|
||||||
File saveDir = new File(fileUploadDir);
|
|
||||||
if (!saveDir.exists()) {
|
|
||||||
saveDir.mkdirs();
|
|
||||||
}
|
|
||||||
|
|
||||||
String saveFileName = fileUploadDir + File.separator + fileId + ".jpg";
|
|
||||||
|
|
||||||
FileOutputStream os = new FileOutputStream(saveFileName);//输出流
|
|
||||||
IXddTplPrint tplPrint = new TanexTplPrintImpl();
|
|
||||||
PrintUtils.genImage(pdfbase64, os);
|
|
||||||
|
|
||||||
JSONObject jObjRemark = new JSONObject();
|
|
||||||
jObjRemark.put("billCode", billCodeItem);
|
|
||||||
jObjRemark.put("subBillCodeRange", subBillCodeRange);
|
|
||||||
jObjRemark.put("lang", lang);
|
|
||||||
jObjRemark.put("printType", printType);
|
|
||||||
|
|
||||||
SysFileInfo sysFileInfo = sysFileInfoService.ossUploadLocalFile(saveFileName, billCodeItem, jObjRemark.toJSONString());
|
|
||||||
String imageUrl = sysFileInfo.getFileRemoteUrl();
|
|
||||||
printItem.put("imageUrl", imageUrl);
|
|
||||||
printItem.put("result", "success");
|
|
||||||
printItem.put("message", "success");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
printItem.put("imageUrl", "");
|
|
||||||
printItem.put("result", "fail");
|
|
||||||
printItem.put("message", "生成图片异常");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
jArr.add(printItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSONArray jArr = new JSONArray();
|
|
||||||
// String[] billCodeArr = billCode.split(",");
|
|
||||||
//
|
|
||||||
// for(String billCodeItem:billCodeArr) {
|
|
||||||
// Map<String, Object> order = emisBaseService.getWaybillPrintOrder(billCodeItem, billCodeRange,tplCode,lang, printType);
|
|
||||||
// JSONObject printItem = new JSONObject();
|
|
||||||
// printItem.put("billCode",billCodeItem);
|
|
||||||
// if(order!=null) {
|
|
||||||
//
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// String fileId = UUID.fastUUID().toString();
|
|
||||||
// String fileUploadDir = PayConfig.getUploadPath()+File.separator+DateUtils.datePath();
|
|
||||||
//
|
|
||||||
// File saveDir = new File(fileUploadDir);
|
|
||||||
// if(!saveDir.exists()){
|
|
||||||
// saveDir.mkdirs();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// String saveFileName = fileUploadDir+File.separator+fileId+".png";
|
|
||||||
//
|
|
||||||
// FileOutputStream os = new FileOutputStream(saveFileName);//输出流
|
|
||||||
// IXddTplPrint tplPrint = new TanexTplPrintImpl();
|
|
||||||
// tplPrint.genPNG(order, os);
|
|
||||||
//
|
|
||||||
// JSONObject jObjRemark = new JSONObject();
|
|
||||||
// jObjRemark.put("billCode",billCodeItem);
|
|
||||||
// jObjRemark.put("billCodeRange",billCodeRange);
|
|
||||||
// jObjRemark.put("lang",lang);
|
|
||||||
// jObjRemark.put("printType",printType);
|
|
||||||
//
|
|
||||||
// SysFileInfo sysFileInfo=sysFileInfoService.ossUploadLocalFile(saveFileName,billCodeItem,jObjRemark.toJSONString());
|
|
||||||
// String imageUrl = sysFileInfo.getFileRemoteUrl();
|
|
||||||
// printItem.put("imageUrl", imageUrl);
|
|
||||||
// printItem.put("result","success");
|
|
||||||
// printItem.put("message","success");
|
|
||||||
// }
|
|
||||||
// catch (Exception e)
|
|
||||||
// {
|
|
||||||
// e.printStackTrace();
|
|
||||||
// printItem.put("imageUrl", "");
|
|
||||||
// printItem.put("result","fail");
|
|
||||||
// printItem.put("message","生成图片异常");
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// }else{
|
|
||||||
// printItem.put("result","fail");
|
|
||||||
// printItem.put("message","未获取到数据");
|
|
||||||
// }
|
|
||||||
// jArr.add(printItem);
|
|
||||||
// }
|
|
||||||
|
|
||||||
return AjaxResult.success("获取成功",jArr);
|
|
||||||
}catch (Exception ex){
|
}catch (Exception ex){
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
return AjaxResult.error("获取失败");
|
return AjaxResult.error("获取失败");
|
||||||
|
|||||||
@ -28,6 +28,13 @@ public interface EmisPrintTplMapper extends BaseMapper<EmisPrintTpl>
|
|||||||
*/
|
*/
|
||||||
public EmisPrintTpl selectEmisPrintTplById(Long id);
|
public EmisPrintTpl selectEmisPrintTplById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据code 获取APP打印模版
|
||||||
|
* @param code
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public EmisPrintTpl selectAppPrintTplByCode(String code);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询列表
|
* 查询列表
|
||||||
*
|
*
|
||||||
|
|||||||
@ -27,6 +27,9 @@ public interface IEmisPrintTplService
|
|||||||
*/
|
*/
|
||||||
public EmisPrintTpl selectEmisPrintTplById(Long id);
|
public EmisPrintTpl selectEmisPrintTplById(Long id);
|
||||||
|
|
||||||
|
public EmisPrintTpl selectAppPrintTplByCode(String code);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询快递打印模板列表
|
* 查询快递打印模板列表
|
||||||
*
|
*
|
||||||
|
|||||||
@ -41,6 +41,14 @@ public class EmisPrintTplServiceImpl implements IEmisPrintTplService
|
|||||||
return emisPrintTplMapper.selectEmisPrintTplById(id);
|
return emisPrintTplMapper.selectEmisPrintTplById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EmisPrintTpl selectAppPrintTplByCode(String code)
|
||||||
|
{
|
||||||
|
return emisPrintTplMapper.selectAppPrintTplByCode(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询快递打印模板列表
|
* 查询快递打印模板列表
|
||||||
*
|
*
|
||||||
|
|||||||
@ -11,8 +11,6 @@ import java.io.IOException;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* CPCL指令
|
* CPCL指令
|
||||||
*
|
|
||||||
* @author guoweifeng
|
|
||||||
*/
|
*/
|
||||||
public class CPCL {
|
public class CPCL {
|
||||||
public static final String QR_CODE_ECC_H = "H";
|
public static final String QR_CODE_ECC_H = "H";
|
||||||
@ -94,7 +92,11 @@ public class CPCL {
|
|||||||
* @return CPCL
|
* @return CPCL
|
||||||
*/
|
*/
|
||||||
public static byte[] text(int font, int fontSize, int x, int y, String data) {
|
public static byte[] text(int font, int fontSize, int x, int y, String data) {
|
||||||
return text(0, font, fontSize, x, y, data);
|
return text(0, font, fontSize, x, y,false, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] text(int font, int fontSize, int x, int y,boolean isBold, String data) {
|
||||||
|
return text(0, font, fontSize, x, y,isBold, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -108,7 +110,7 @@ public class CPCL {
|
|||||||
* @param data 打印内容
|
* @param data 打印内容
|
||||||
* @return CPCL
|
* @return CPCL
|
||||||
*/
|
*/
|
||||||
public static byte[] text(int degree, int font, int fontSize, int x, int y, String data) {
|
public static byte[] text(int degree, int font, int fontSize, int x, int y,boolean isBold, String data) {
|
||||||
String command;
|
String command;
|
||||||
switch (degree) {
|
switch (degree) {
|
||||||
case 90:
|
case 90:
|
||||||
@ -124,7 +126,21 @@ public class CPCL {
|
|||||||
command = "TEXT";
|
command = "TEXT";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return toBytes(command + " " + font + " " + fontSize + " " + x + " " + y + " " + data + LINE);
|
StringBuilder sb=new StringBuilder();
|
||||||
|
if(isBold){
|
||||||
|
sb.append("SETBOLD 1"+ " "+ LINE);
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append(command + " " + font + " " + fontSize + " " + x + " " + y + " " + data + LINE);
|
||||||
|
// SETBOLD 1
|
||||||
|
// TEXT 24 0 0 0 This text is in bold
|
||||||
|
// SETBOLD 0
|
||||||
|
// TEXT 24 0 252 0
|
||||||
|
if(isBold){
|
||||||
|
sb.append("SETBOLD 0"+ " "+ LINE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return toBytes(sb.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -135,6 +135,10 @@ public class CpclBuilder {
|
|||||||
return append(CPCL.text(font, fontSize, x, y, data));
|
return append(CPCL.text(font, fontSize, x, y, data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CpclBuilder text(int font, int fontSize, int x, int y,boolean isBold, String data) {
|
||||||
|
return append(CPCL.text(font, fontSize, x, y,isBold, data));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文本
|
* 文本
|
||||||
*
|
*
|
||||||
@ -147,9 +151,11 @@ public class CpclBuilder {
|
|||||||
* @return CpclBuilder
|
* @return CpclBuilder
|
||||||
*/
|
*/
|
||||||
public CpclBuilder text(int degree, int font, int fontSize, int x, int y, String data) {
|
public CpclBuilder text(int degree, int font, int fontSize, int x, int y, String data) {
|
||||||
return append(CPCL.text(degree, font, fontSize, x, y, data));
|
return append(CPCL.text(degree, font, fontSize, x, y,false, data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 绘制任何长度、宽度和角度方向的线条
|
* 绘制任何长度、宽度和角度方向的线条
|
||||||
*
|
*
|
||||||
|
|||||||
@ -0,0 +1,257 @@
|
|||||||
|
package com.xdadan.erp.emis.service.print.cpcl;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.json.JSONArray;
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import cn.hutool.json.XML;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.commons.lang3.text.StrSubstitutor;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class CvtTplToCpcl {
|
||||||
|
|
||||||
|
|
||||||
|
public static String getPrintCmd(String tplBase64, Map paramMap){
|
||||||
|
|
||||||
|
if(StringUtils.isEmpty(tplBase64)){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String strData=null;
|
||||||
|
try {
|
||||||
|
String dcdTpl = new String(Base64.getDecoder().decode(tplBase64),"UTF-8");
|
||||||
|
strData=getFormatStr(dcdTpl,paramMap);
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return strData;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模版转cpcl打印指令
|
||||||
|
* @param tplXmlStr
|
||||||
|
* @param paramMap
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String cvtTplToCpcl(String tplXmlStr, Map paramMap){
|
||||||
|
|
||||||
|
if(StringUtils.isEmpty(tplXmlStr)){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// CpclBuilder builder = CpclBuilder.newBuilder();
|
||||||
|
|
||||||
|
int dpi=200;
|
||||||
|
int scale=(int)dpi/96;
|
||||||
|
|
||||||
|
JSONObject tplJsonObj = XML.toJSONObject(tplXmlStr);
|
||||||
|
log.info("CvtTplToCpcl==>tplJsonObj:{}",tplJsonObj);
|
||||||
|
|
||||||
|
JSONObject jobjReportPage = tplJsonObj.getJSONObject("Report").getJSONObject("ReportPage");
|
||||||
|
JSONObject jobjReportTitleBand = jobjReportPage.getJSONObject("ReportTitleBand");
|
||||||
|
|
||||||
|
// 页 宽高设置
|
||||||
|
int paperWidth = jobjReportPage.getInt("PaperWidth",76*8);
|
||||||
|
int paperHeight = jobjReportPage.getInt("PaperHeight",130*8);
|
||||||
|
CpclBuilder builder =CpclBuilder.createArea(0,dpi,paperWidth*8,paperHeight*8,1);
|
||||||
|
|
||||||
|
JSONArray objLineArr = jobjReportTitleBand.getJSONArray("LineObject");
|
||||||
|
for (int i=0;i<objLineArr.size();i++){
|
||||||
|
JSONObject item=objLineArr.getJSONObject(i);
|
||||||
|
log.info("CvtTplToCpcl==>line:{}",item.toJSONString(0));
|
||||||
|
|
||||||
|
// int let
|
||||||
|
int x0=item.getInt("Left",0);
|
||||||
|
int y0=item.getInt("Top",0);
|
||||||
|
int x1=x0+item.getInt("Width",0);
|
||||||
|
int y1=y0+item.getInt("Height",0);
|
||||||
|
builder.line(x0*scale, y0*scale, x1*scale, y1*scale, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
BarcodeObject": {
|
||||||
|
"Barcode.AutoEncode": true,
|
||||||
|
"ShowText": false,
|
||||||
|
"Left": 17.01,
|
||||||
|
"AutoSize": false,
|
||||||
|
"Name": "BarCode3",
|
||||||
|
"Top": 143.62,
|
||||||
|
"Expression": "logisticNo",
|
||||||
|
"Barcode": "Code128",
|
||||||
|
"Barcode.CalcCheckSum": false,
|
||||||
|
"Height": 45.36,
|
||||||
|
"Width": 247.59
|
||||||
|
},
|
||||||
|
*/
|
||||||
|
JSONObject objBarcodeObject = jobjReportTitleBand.getJSONObject("BarcodeObject");
|
||||||
|
log.info("CvtTplToCpcl==>barcode:{}",objBarcodeObject.toJSONString(0));
|
||||||
|
int barX=objBarcodeObject.getInt("Left",0);
|
||||||
|
int barY=objBarcodeObject.getInt("Top",0);
|
||||||
|
int barWidth=objBarcodeObject.getInt("Width",0);
|
||||||
|
int barHeight=objBarcodeObject.getInt("Height",0);
|
||||||
|
String barText=objBarcodeObject.getStr("Expression","");
|
||||||
|
// barWidth*scale
|
||||||
|
builder.barCode(2, 0, barHeight*scale, barX*scale, barY*scale, getFormatStr("["+barText+"]",paramMap));
|
||||||
|
|
||||||
|
// Map<String, String> valueMap = new HashMap<>();
|
||||||
|
// valueMap.put("name", "Alice");
|
||||||
|
// valueMap.put("age", "30");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// System.out.println(resolvedString);
|
||||||
|
|
||||||
|
|
||||||
|
JSONArray objTextArr = jobjReportTitleBand.getJSONArray("TextObject");
|
||||||
|
for (int i=0;i<objTextArr.size();i++){
|
||||||
|
JSONObject item=objTextArr.getJSONObject(i);
|
||||||
|
log.info("CvtTplToCpcl==>text:{}",item.toJSONString(0));
|
||||||
|
|
||||||
|
String fontStr=item.getStr("Font");
|
||||||
|
String[] fontStrArr = fontStr.split(",");
|
||||||
|
String fontName=fontStrArr[0];
|
||||||
|
String fontSizeStr=fontStrArr[1].replaceAll("pt", "");
|
||||||
|
// String fontSizeStr=fontStrArr[1];
|
||||||
|
int fontSize=(int)Float.parseFloat(fontSizeStr.trim());
|
||||||
|
String textStr=item.getStr("Text","");
|
||||||
|
boolean isBold=false;
|
||||||
|
if(fontStrArr.length>=3) {
|
||||||
|
String styleStr = fontStrArr[2];
|
||||||
|
if ("style=Bold".equals(styleStr)) {
|
||||||
|
isBold = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 参数替换为实际的数据
|
||||||
|
|
||||||
|
int x=item.getInt("Left",0);
|
||||||
|
int y=item.getInt("Top",0);
|
||||||
|
|
||||||
|
builder.text(0, fontSize, x*scale, y*scale,isBold,getFormatStr(textStr,paramMap) );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.form();
|
||||||
|
builder.print();
|
||||||
|
|
||||||
|
return new String(builder.build(), Charset.forName("GBK"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getFormatStr(String tplStr,Map paramMap){
|
||||||
|
|
||||||
|
tplStr=tplStr.replaceAll("\\[","{");
|
||||||
|
tplStr=tplStr.replaceAll("\\]","}");
|
||||||
|
|
||||||
|
return StrUtil.format(tplStr, paramMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成打印指令模版
|
||||||
|
* @param tplFile
|
||||||
|
*/
|
||||||
|
public static String genCmdTpl(String tplFile){
|
||||||
|
String tplXmlStr= FileUtil.readString(tplFile, Charset.forName("UTF-8"));
|
||||||
|
String cmd=cvtTplToCpcl(tplXmlStr,null);
|
||||||
|
log.info("cmd:{}",cmd);
|
||||||
|
String encCmd=Base64.getEncoder().encodeToString(cmd.getBytes(Charset.forName("UTF-8")));
|
||||||
|
log.info("encCmd:{}",encCmd);
|
||||||
|
return encCmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
String tplFile="/Users/alan/Downloads/dc1.frx";
|
||||||
|
String cmd=genCmdTpl(tplFile);
|
||||||
|
|
||||||
|
Map paramMap = new HashMap();
|
||||||
|
paramMap.put("logisticNo","T70803000126050001");
|
||||||
|
paramMap.put("packageWJC","缅H");
|
||||||
|
paramMap.put("receiveCountyName","缅甸");
|
||||||
|
paramMap.put("receiveProvinceName","仰光");
|
||||||
|
paramMap.put("receiveCityName"," ");
|
||||||
|
paramMap.put("address","KYAN SITTHAR YEIKMON INDUSTRIAL NO.56&59, LAND SURVEY NO 143/1 SOUTH DAGON TOWNSHIP, YANGON, MYANMAR");
|
||||||
|
|
||||||
|
paramMap.put("consignee", "YEE YEE TUN");
|
||||||
|
paramMap.put("mobile", "09953013062");
|
||||||
|
paramMap.put("k3", "T1");
|
||||||
|
paramMap.put("company", "WOORIE MJ SHIRTS CO.LTDT1");
|
||||||
|
paramMap.put("sendDate", "2024-08-08");
|
||||||
|
paramMap.put("printDate", "2024-08-08");
|
||||||
|
paramMap.put("printMan", "李晓虎");
|
||||||
|
paramMap.put("printCount", "1");
|
||||||
|
paramMap.put("subSeqNum", "1");
|
||||||
|
paramMap.put("parcelQty", "2");
|
||||||
|
paramMap.put("billWeight", "1.2");
|
||||||
|
paramMap.put("totalVolume", "0.0023");
|
||||||
|
paramMap.put("paymentType", "现金");
|
||||||
|
paramMap.put("dispatchType", "派送");
|
||||||
|
paramMap.put("shortLogisticNo", "12321");
|
||||||
|
paramMap.put("agingFlag", "1-2天");
|
||||||
|
paramMap.put("k10", "缅甸快递");
|
||||||
|
paramMap.put("k11", "探路特快");
|
||||||
|
|
||||||
|
|
||||||
|
String printCmd=getPrintCmd(cmd,paramMap);
|
||||||
|
System.out.println(printCmd);
|
||||||
|
|
||||||
|
|
||||||
|
String str="! 0 200 200 1040 1\n" +
|
||||||
|
"PW 608\n" +
|
||||||
|
"LINE 0 0 570 0 1\n" +
|
||||||
|
"LINE 0 656 0 686 1\n" +
|
||||||
|
"LINE 0 0 0 974 1\n" +
|
||||||
|
"LINE 570 0 570 974 1\n" +
|
||||||
|
"LINE 0 426 570 426 1\n" +
|
||||||
|
"LINE 0 278 570 278 1\n" +
|
||||||
|
"LINE 0 974 570 974 1\n" +
|
||||||
|
"LINE 0 180 570 180 1\n" +
|
||||||
|
"LINE 0 646 570 646 1\n" +
|
||||||
|
"LINE 0 830 570 830 1\n" +
|
||||||
|
"LINE 366 426 366 644 1\n" +
|
||||||
|
"LINE 366 510 570 510 1\n" +
|
||||||
|
"BARCODE 128 494 1 90 34 286 T70803000126050001\n" +
|
||||||
|
"TEXT 0 28 14 834 缅H\n" +
|
||||||
|
"TEXT 0 10 30 388 T70803000126050001\n" +
|
||||||
|
"TEXT 0 9 10 756 已验视\n" +
|
||||||
|
"TEXT 0 9 10 792 已安检\n" +
|
||||||
|
"TEXT 0 8 102 652 YEE YEE TUN 09953013062\n" +
|
||||||
|
"TEXT 0 7 102 736 缅甸仰光 KYAN SITTHAR YEIKMON INDUSTRIAL NO.56&59, LAND SURVEY NO 143/1 SOUTH DAGON TOWNSHIP, YANGON, MYANMAR\n" +
|
||||||
|
"TEXT 0 17 10 192 T1\n" +
|
||||||
|
"TEXT 0 12 6 660 送达地址\n" +
|
||||||
|
"TEXT 0 8 102 698 WOORIE MJ SHIRTS CO.LTDT1\n" +
|
||||||
|
"TEXT 0 6 10 434 寄件日期:\n" +
|
||||||
|
"TEXT 0 6 10 574 打印日期/打印人/打印次数\n" +
|
||||||
|
"TEXT 0 6 98 434 2024-08-08\n" +
|
||||||
|
"TEXT 0 6 10 608 2024-08-08/李晓虎/1\n" +
|
||||||
|
"TEXT 0 11 10 468 1/2|1.2kg|0.0023方\n" +
|
||||||
|
"TEXT 0 6 370 578 【{packType}】\n" +
|
||||||
|
"TEXT 0 6 210 434 现金\n" +
|
||||||
|
"TEXT 0 6 370 528 【派送】\n" +
|
||||||
|
"TEXT 0 16 370 434 12321\n" +
|
||||||
|
"TEXT 0 20 56 48 1-2天\n" +
|
||||||
|
"TEXT 0 15 226 10 缅甸快递\n" +
|
||||||
|
"TEXT 0 15 226 90 探路特快\n" +
|
||||||
|
"FORM\n" +
|
||||||
|
"PRINT";
|
||||||
|
|
||||||
|
|
||||||
|
// System.out.println(tplXmlStr);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -11,12 +11,12 @@ public class Test {
|
|||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
byte[] cpcl = CpclBuilder.createArea(0, 203, 1680, 2374, 1) // 203DPI
|
byte[] cpcl = CpclBuilder.createArea(0, 200, 608, 1040, 1) // 203DPI
|
||||||
.text(0, 0, 500, 100, "Hello World!")
|
.text(24, 11, 0, 2*8, "test1!")
|
||||||
.text(0, 0, 520, 150, "Hello World!")
|
.text(24, 11, 0, 3*8, "test2")
|
||||||
.text(0, 0, 540, 200, "Hello World!")
|
.text(24, 11, 0, 5*8, "test3!")
|
||||||
.text(0, 0, 560, 250, "Hello World!")
|
.text(24, 11, 0, 7*8, "test4!")
|
||||||
.text(0, 0, 580, 300, "Hello World!")
|
.text(24, 11, 0, 8*8, "test5")
|
||||||
.form()
|
.form()
|
||||||
.print()
|
.print()
|
||||||
//.formPrint()
|
//.formPrint()
|
||||||
|
|||||||
@ -30,7 +30,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<where>
|
<where>
|
||||||
del_flag='0'
|
del_flag='0'
|
||||||
<if test="id != null "> and id = #{id}</if>
|
<if test="id != null "> and id = #{id}</if>
|
||||||
<if test="code != null and code != ''"> and code like concat('%', #{code}, '%')</if>
|
<if test="code != null and code != ''"> and code=#{code}</if>
|
||||||
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
|
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
|
||||||
<if test="version != null and version != ''"> and version like concat('%', #{version}, '%')</if>
|
<if test="version != null and version != ''"> and version like concat('%', #{version}, '%')</if>
|
||||||
<if test="isPublic != null "> and is_public = #{isPublic}</if>
|
<if test="isPublic != null "> and is_public = #{isPublic}</if>
|
||||||
@ -63,7 +63,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<select id="selectEmisPrintTplById" parameterType="Long" resultMap="EmisPrintTplResult">
|
<select id="selectEmisPrintTplById" parameterType="Long" resultMap="EmisPrintTplResult">
|
||||||
select id, code, name, version, is_public, merch_id, express_type, tpl_data, tpl_enc_data, tpl_pdf_data, tpl_pic_url, order_num, status, del_flag, create_by, create_time, update_by, update_time, remark, create_site, update_site
|
select id, code, name, version, is_public, merch_id, express_type, tpl_data, tpl_enc_data, tpl_pdf_data, tpl_pic_url, order_num, status, del_flag, create_by, create_time, update_by, update_time, remark, create_site, update_site
|
||||||
from emis_print_tpl a
|
from emis_print_tpl a
|
||||||
where a.id = #{id}
|
where del_flag='0' and a.id = #{id}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectAppPrintTplByCode" parameterType="String" resultMap="EmisPrintTplResult">
|
||||||
|
select id, code, name, version, is_public, merch_id, express_type, tpl_data
|
||||||
|
from emis_print_tpl a
|
||||||
|
where del_flag='0' and a.code = #{code}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<insert id="insertEmisPrintTpl" parameterType="EmisPrintTpl">
|
<insert id="insertEmisPrintTpl" parameterType="EmisPrintTpl">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user