This commit is contained in:
linfso 2024-08-23 12:43:14 +08:00
parent 1934ee19ce
commit d851eb9ca0
6 changed files with 122 additions and 16 deletions

View File

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.apache.commons:commons-text:1.10.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/commons/commons-text/1.10.0/commons-text-1.10.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/commons/commons-text/1.10.0/commons-text-1.10.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/commons/commons-text/1.10.0/commons-text-1.10.0-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -270,5 +270,6 @@
<orderEntry type="library" name="Maven: xml-apis:xml-apis-ext:1.3.04" level="project" />
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-codec:1.14" level="project" />
<orderEntry type="library" name="Maven: com.aspose:aspose-words:19.1.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.10.0" level="project" />
</component>
</module>

View File

@ -229,5 +229,6 @@
<orderEntry type="library" name="Maven: xml-apis:xml-apis-ext:1.3.04" level="project" />
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-codec:1.14" level="project" />
<orderEntry type="library" name="Maven: com.aspose:aspose-words:19.1.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.10.0" level="project" />
</component>
</module>

View File

@ -145,6 +145,13 @@
<version>19.1.0</version>
</dependency>
<!-- apache commons-text-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.10.0</version>
</dependency>
</dependencies>

View File

@ -54,6 +54,7 @@ package com.xdadan.erp.emis.service;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.WordUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -1715,6 +1716,32 @@ public class EmisBaseService {
return emisCustomerUserMapper.selectMonthCustomerByName(name);
}
private static List<String> splitTextToLines(String text, int intLenMax) {
List<String> lines = new ArrayList<>();
String currentLine = "";
int currentWidth = 0;
// 遍历原字符串的每个字符
for (int i = 0; i < text.length(); i++) {
char ch = text.charAt(i);
int charWidth = Integer.valueOf(ch) > 255 ? 2 : 1; // 判断字符宽度,中文字符宽度为2,英文字符宽度为1
// 如果当前字符加上当前行已有字符宽度超过最大字符宽度,需要另起一行
if (currentWidth + charWidth > intLenMax) {
lines.add(currentLine);
currentLine = ""; // 重置当前行
currentWidth = 0; // 重置当前字符宽度
}
currentLine += ch;
currentWidth += charWidth;
}
// 添加最后一行
lines.add(currentLine);
return lines;
}
/**
* 获取打印信息
@ -1869,6 +1896,16 @@ public class EmisBaseService {
}
order.put("address", address);
// 地址拆分为多行
String[] addrArr=WordUtils.wrap(address,48).split("\n");
for(int i=0;i<4;i++) {
try{
order.put("address"+(i+1),addrArr[i]);
}catch (Exception ex){
order.put("address"+(i+1),"");
}
}
order.put("company", company);
order.put("mobile", mobile);
order.put("consignee", consignee);
@ -1882,7 +1919,21 @@ public class EmisBaseService {
}
order.put("custName", WaybillHelper.removeUnSeeChar(custName));
order.put("sendAddress", WaybillHelper.removeUnSeeChar(waybill.getSendAddress()));
String sendAddress=WaybillHelper.removeUnSeeChar(waybill.getSendAddress());
order.put("sendAddress",sendAddress );
// 地址拆分为多行
String[] sAddrArr=WordUtils.wrap(sendAddress,48).split("\n");
for(int i=0;i<4;i++) {
try{
order.put("sendAddress"+(i+1),sAddrArr[i]);
}catch (Exception ex){
order.put("sendAddress"+(i+1),"");
}
}
// 地址拆分成4行,每行最多 48个字符
order.put("sendCompany", WaybillHelper.removeUnSeeChar(waybill.getSendCompany()));
order.put("sendMobile", WaybillHelper.removeUnSeeChar(waybill.getSendMobile()));
order.put("sendPerson", WaybillHelper.removeUnSeeChar(waybill.getSendName()));
@ -2872,22 +2923,34 @@ public class EmisBaseService {
// System.out.println(packageWJC);
// System.out.println(package3dm);
String billCode="T70803000037160001";
// String billCode="T70803000037160001";
boolean isSubBill=false;
// boolean isSubBill=false;
isSubBill = true;
// isSubBill = true;
// queryBillCode=mainBillCode.substring(0,14);
int len=billCode.length();
String subBillSuffix=billCode.substring(len-4);
String mainBillCode = billCode.substring(0,len-4);
System.out.println(mainBillCode);
System.out.println(subBillSuffix);
System.out.println(Integer.valueOf(subBillSuffix));
// int len=billCode.length();
// String subBillSuffix=billCode.substring(len-4);
// String mainBillCode = billCode.substring(0,len-4);
// System.out.println(mainBillCode);
// System.out.println(subBillSuffix);
// System.out.println(Integer.valueOf(subBillSuffix));
String txt="NO.7,Chun Hong Industrial Park, National Road No.4, Svay Chrum Village Beckchan Commune ,Angsnoul District,Kandal provinve, Cambodia.";
List mlist=splitTextToLines(txt,48);
System.out.println(JSON.toJSONString(mlist));
String s1=WordUtils.wrap(txt,48);
String[] sAddrArr=s1.split("\n");
System.out.println(JSON.toJSONString(sAddrArr));
for(int i=0;i<4;i++) {
try {
System.out.println(sAddrArr[i]);
} catch (Exception ex) {
}
}
}

File diff suppressed because one or more lines are too long