小票打印bug修复

This commit is contained in:
谭凯凯
2024-11-28 17:00:17 +08:00
committed by Tankaikai
parent f1c80e6f1e
commit a6de9593a7
2 changed files with 62 additions and 36 deletions

View File

@@ -230,7 +230,7 @@ public class FeieyunPrintUtil {
for (OrderDetailPO.Detail detail : detailPO.getDetailList()) { for (OrderDetailPO.Detail detail : detailPO.getDetailList()) {
String productName = detail.getProductName(); String productName = detail.getProductName();
String number = detail.getNumber(); String number = detail.getNumber();
String amount = detail.getAmount(); String amount = toPlainStr(detail.getAmount());
//58mm的机器,一行打印16个汉字,32个字母; 80mm的机器,一行打印24个汉字,48个字母 //58mm的机器,一行打印16个汉字,32个字母; 80mm的机器,一行打印24个汉字,48个字母
//展示4列 b1代表名称列占用14个字节 b2单价列6个字节 b3数量列3个字节 b4金额列6个字节-->这里的字节数可按自己需求自由改写14+6+3+6再加上代码写的3个空格就是32了58mm打印机一行总占32字节 //展示4列 b1代表名称列占用14个字节 b2单价列6个字节 b3数量列3个字节 b4金额列6个字节-->这里的字节数可按自己需求自由改写14+6+3+6再加上代码写的3个空格就是32了58mm打印机一行总占32字节
//String row = FeieYunUtil.getRow(productName, "",number, amount, 14, 6,3, 6) //String row = FeieYunUtil.getRow(productName, "",number, amount, 14, 6,3, 6)
@@ -245,22 +245,22 @@ public class FeieyunPrintUtil {
log.error("打印数据>>>>>>>>>>>>>>>>>>>>>:{}{}", detailPO.getDiscountAmount(), detailPO.getDiscountAdio()); log.error("打印数据>>>>>>>>>>>>>>>>>>>>>:{}{}", detailPO.getDiscountAmount(), detailPO.getDiscountAdio());
if (ObjectUtil.isNotNull(detailPO.getDiscountAmount()) && ObjectUtil.isNotNull(detailPO.getDiscountAdio())) { if (ObjectUtil.isNotNull(detailPO.getDiscountAmount()) && ObjectUtil.isNotNull(detailPO.getDiscountAdio())) {
data.append("--------------------------------<BR>"); data.append("--------------------------------<BR>");
data.append(StrUtil.format("原价:{}<BR>", detailPO.getReceiptsAmount())); data.append(StrUtil.format("原价:{}<BR>", toPlainStr(detailPO.getReceiptsAmount())));
data.append(StrUtil.format("折扣:-{}<BR>", NumberUtil.null2Zero(new BigDecimal(detailPO.getDiscountAmount())).toPlainString())); data.append(StrUtil.format("折扣:-{}<BR>", toPlainStr(detailPO.getDiscountAmount())));
} }
data.append("--------------------------------<BR>"); data.append("--------------------------------<BR>");
String t = "" + (ObjectUtil.isEmpty(detailPO.getDiscountAmount()) || ObjectUtil.isNull(detailPO.getDiscountAmount()) ? detailPO.getReceiptsAmount() : new BigDecimal(detailPO.getReceiptsAmount()).subtract(new BigDecimal(detailPO.getDiscountAmount())).toPlainString()); String t = "" + (ObjectUtil.isEmpty(detailPO.getDiscountAmount()) || ObjectUtil.isNull(detailPO.getDiscountAmount()) ? toPlainStr(detailPO.getReceiptsAmount()) : NumberUtil.sub(new BigDecimal(detailPO.getReceiptsAmount()),new BigDecimal(detailPO.getDiscountAmount())).toPlainString());
if (orderType.equals("return")) { if (orderType.equals("return")) {
data.append(StrUtil.format("<B>应退:{}</B><BR>", t)); data.append(StrUtil.format("<B>应退:{}</B><BR>", t));
} else { } else {
data.append(StrUtil.format("<B>应收:{}</B><BR>", t)); data.append(StrUtil.format("<B>应收:{}</B><BR>", t));
} }
if (ObjectUtil.isNotEmpty(detailPO.getPayType()) && ObjectUtil.isNotNull(detailPO.getPayType()) && detailPO.getPayType().equals("deposit")) { if (ObjectUtil.isNotEmpty(detailPO.getPayType()) && ObjectUtil.isNotNull(detailPO.getPayType()) && detailPO.getPayType().equals("deposit")) {
data.append(StrUtil.format("储值:{}<BR>", detailPO.getReceiptsAmount())); data.append(StrUtil.format("储值:{}<BR>", toPlainStr(detailPO.getReceiptsAmount())));
data.append("--------------------------------<BR>"); data.append("--------------------------------<BR>");
data.append(StrUtil.format("积分:{}<BR>", detailPO.getIntegral())); data.append(StrUtil.format("积分:{}<BR>", detailPO.getIntegral()));
} }
data.append(StrUtil.format("余额:{}<BR>", detailPO.getBalance())); data.append(StrUtil.format("余额:{}<BR>", toPlainStr(detailPO.getBalance())));
data.append("--------------------------------<BR>"); data.append("--------------------------------<BR>");
if (ObjectUtil.isNotEmpty(detailPO.getRemark()) && ObjectUtil.isNotNull(detailPO.getRemark())) { if (ObjectUtil.isNotEmpty(detailPO.getRemark()) && ObjectUtil.isNotNull(detailPO.getRemark())) {
data.append(StrUtil.format("<L><BOLD>备注:{}</BOLD></L><BR>", detailPO.getRemark())); data.append(StrUtil.format("<L><BOLD>备注:{}</BOLD></L><BR>", detailPO.getRemark()));
@@ -270,6 +270,13 @@ public class FeieyunPrintUtil {
return data.toString(); return data.toString();
} }
private static String toPlainStr(String str) {
if(StrUtil.isBlank(str)){
return "0";
}
return new BigDecimal(str).toPlainString();
}
public static String[] getCashPrintData(OrderDetailPO detailPO, String sn, String type, String orderType, String printerNum) { public static String[] getCashPrintData(OrderDetailPO detailPO, String sn, String type, String orderType, String printerNum) {
String content = buildPrintContent(detailPO, type, orderType); String content = buildPrintContent(detailPO, type, orderType);
@@ -488,7 +495,10 @@ public class FeieyunPrintUtil {
public static void main(String[] args) { public static void main(String[] args) {
//testPrint(); //testPrint();
//testPrint2(); //testPrint2();
testPrint3(); String a = "12.0000";
String s = new BigDecimal(a).toPlainString();
System.out.println(s);
//testPrint3();
} }
public static void testPrint() { public static void testPrint() {
@@ -551,7 +561,4 @@ public class FeieyunPrintUtil {
System.out.println(UnicodeUtil.toString(resp)); System.out.println(UnicodeUtil.toString(resp));
} }
} }

View File

@@ -1,5 +1,6 @@
package com.chaozhanggui.system.cashierservice.util; package com.chaozhanggui.system.cashierservice.util;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
@@ -13,7 +14,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
@@ -130,19 +130,19 @@ public class PrinterUtils {
int count = getProducrName(detail.getProductName()); int count = getProducrName(detail.getProductName());
if (count <= 0) { if (count <= 0) {
int length = 15 - (detail.getProductName().length() - 4); int length = 15 - (detail.getProductName().length() - 4);
sb.append("<S>").append(String.format("%-" + length + "s", detail.getProductName()).replace(' ', paddingCharacter)).append(String.format("%-4s", detail.getNumber()).replace(' ', paddingCharacter)).append(String.format("%8s", detail.getAmount()).replace(' ', paddingCharacter)).append("</S><BR>"); sb.append("<S>").append(String.format("%-" + length + "s", detail.getProductName()).replace(' ', paddingCharacter)).append(String.format("%-4s", detail.getNumber()).replace(' ', paddingCharacter)).append(String.format("%8s", toPlainStr(detail.getAmount())).replace(' ', paddingCharacter)).append("</S><BR>");
} else { } else {
int length = 15 + count - (detail.getProductName().length() - 4); int length = 15 + count - (detail.getProductName().length() - 4);
sb.append("<S>").append(String.format("%-" + length + "s", detail.getProductName()).replace(' ', paddingCharacter)).append(String.format("%-4s", detail.getNumber()).replace(' ', paddingCharacter)).append(String.format("%8s", detail.getAmount()).replace(' ', paddingCharacter)).append("</S><BR>"); sb.append("<S>").append(String.format("%-" + length + "s", detail.getProductName()).replace(' ', paddingCharacter)).append(String.format("%-4s", detail.getNumber()).replace(' ', paddingCharacter)).append(String.format("%8s", toPlainStr(detail.getAmount())).replace(' ', paddingCharacter)).append("</S><BR>");
} }
} else if (detail.getProductName().length() > 10) { } else if (detail.getProductName().length() > 10) {
sb.append("<S>").append(detail.getProductName()).append("</S><BR>"); sb.append("<S>").append(detail.getProductName()).append("</S><BR>");
sb.append("<S>").append(String.format("%20s", detail.getNumber()).replace(' ', paddingCharacter)).append(String.format("%11s", detail.getAmount()).replace(' ', paddingCharacter)).append("</S><BR>"); sb.append("<S>").append(String.format("%20s", detail.getNumber()).replace(' ', paddingCharacter)).append(String.format("%11s", toPlainStr(detail.getAmount())).replace(' ', paddingCharacter)).append("</S><BR>");
} else { } else {
sb.append("<S>").append(String.format("%-15s", detail.getProductName()).replace(' ', paddingCharacter)).append(String.format("%-4s", detail.getNumber()).replace(' ', paddingCharacter)).append(String.format("%8s", detail.getAmount()).replace(' ', paddingCharacter)).append("</S><BR>"); sb.append("<S>").append(String.format("%-15s", detail.getProductName()).replace(' ', paddingCharacter)).append(String.format("%-4s", detail.getNumber()).replace(' ', paddingCharacter)).append(String.format("%8s", toPlainStr(detail.getAmount())).replace(' ', paddingCharacter)).append("</S><BR>");
} }
if (detail.getSpec() != null && ObjectUtil.isNotEmpty(detail.getSpec())) { if (detail.getSpec() != null && ObjectUtil.isNotEmpty(detail.getSpec())) {
@@ -153,13 +153,13 @@ public class PrinterUtils {
if (ObjectUtil.isNotNull(detailPO.getDiscountAmount()) && ObjectUtil.isNotNull(detailPO.getDiscountAdio())) { if (ObjectUtil.isNotNull(detailPO.getDiscountAmount()) && ObjectUtil.isNotNull(detailPO.getDiscountAdio())) {
sb.append("------------------------<BR>"); sb.append("------------------------<BR>");
sb.append("<S>原价:".concat(String.format("%15s", detailPO.getReceiptsAmount()).replace(' ', paddingCharacter)).concat("</S><BR>")); sb.append("<S>原价:".concat(String.format("%15s", toPlainStr(detailPO.getReceiptsAmount())).replace(' ', paddingCharacter)).concat("</S><BR>"));
sb.append("<S>折扣: ".concat(String.format("%15s", "-".concat(new BigDecimal(detailPO.getDiscountAmount()).toPlainString())).replace(' ', paddingCharacter)).concat("</S><BR>")); sb.append("<S>折扣: ".concat(String.format("%15s", "-".concat(toPlainStr(detailPO.getDiscountAmount()))).replace(' ', paddingCharacter)).concat("</S><BR>"));
} }
sb.append("------------------------<BR>"); sb.append("------------------------<BR>");
String t = "" + (ObjectUtil.isEmpty(detailPO.getDiscountAmount()) || ObjectUtil.isNull(detailPO.getDiscountAmount()) ? detailPO.getReceiptsAmount() : new BigDecimal(detailPO.getReceiptsAmount()).subtract(new BigDecimal(detailPO.getDiscountAmount())).toPlainString()); String t = "" + (ObjectUtil.isEmpty(detailPO.getDiscountAmount()) || ObjectUtil.isNull(detailPO.getDiscountAmount()) ? toPlainStr(detailPO.getReceiptsAmount()) : NumberUtil.sub(new BigDecimal(detailPO.getReceiptsAmount()), new BigDecimal(detailPO.getDiscountAmount())).toPlainString());
t = String.format("%11s", t).replace(' ', paddingCharacter); t = String.format("%11s", t).replace(' ', paddingCharacter);
if (orderType.equals("return")) { if (orderType.equals("return")) {
sb.append("<F>应退" + t + "</F><BR>"); sb.append("<F>应退" + t + "</F><BR>");
@@ -168,12 +168,12 @@ public class PrinterUtils {
} }
if (ObjectUtil.isNotEmpty(detailPO.getPayType()) && ObjectUtil.isNotNull(detailPO.getPayType()) && detailPO.getPayType().equals("deposit")) { if (ObjectUtil.isNotEmpty(detailPO.getPayType()) && ObjectUtil.isNotNull(detailPO.getPayType()) && detailPO.getPayType().equals("deposit")) {
sb.append("<S>储值¥" + detailPO.getReceiptsAmount() + " </S><BR>"); sb.append("<S>储值¥" + toPlainStr(detailPO.getReceiptsAmount()) + " </S><BR>");
sb.append("------------------------<BR>"); sb.append("------------------------<BR>");
sb.append("<S>积分:" + detailPO.getIntegral() + "</S><BR>"); sb.append("<S>积分:" + detailPO.getIntegral() + "</S><BR>");
} }
sb.append("<S>余额:" + detailPO.getBalance() + "</S><BR>"); sb.append("<S>余额:" + toPlainStr(detailPO.getBalance()) + "</S><BR>");
sb.append("------------------------<BR>"); sb.append("------------------------<BR>");
if (ObjectUtil.isNotEmpty(detailPO.getRemark()) && ObjectUtil.isNotNull(detailPO.getRemark())) { if (ObjectUtil.isNotEmpty(detailPO.getRemark()) && ObjectUtil.isNotNull(detailPO.getRemark())) {
@@ -194,6 +194,13 @@ public class PrinterUtils {
} }
private static String toPlainStr(String str) {
if (StrUtil.isBlank(str)) {
return "0";
}
return new BigDecimal(str).toPlainString();
}
public static String getCallNumPrintData(CallNumPrintPO po) { public static String getCallNumPrintData(CallNumPrintPO po) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@@ -367,26 +374,34 @@ public class PrinterUtils {
Map<String, String> param = getToken(time, uuid); Map<String, String> param = getToken(time, uuid);
//参数 //参数
MultiValueMap<String, Object> multiValueMap = new LinkedMultiValueMap<>(); //MultiValueMap<String, Object> multiValueMap = new LinkedMultiValueMap<>();
multiValueMap.add("token", param.get("TOKEN")); Map<String, Object> map = new HashMap<>();
multiValueMap.add("devName", devName); map.put("token", param.get("TOKEN"));
multiValueMap.add("actWay", actWay); map.put("devName", devName);
multiValueMap.add("cn", cn); map.put("money", null);
multiValueMap.add("data", data); map.put("content", "收款100元");
multiValueMap.add("voiceJson", voiceJson); map.put("broadCastType", "1");
multiValueMap.add("appId", APP_ID); //multiValueMap.put("actWay", actWay);
multiValueMap.add("timestamp", time); //multiValueMap.put("cn", cn);
multiValueMap.add("requestId", uuid); //multiValueMap.put("data", data);
multiValueMap.add("userCode", USER_CODE); //multiValueMap.put("voiceJson", voiceJson);
map.put("appId", APP_ID);
map.put("timestamp", time);
map.put("requestId", uuid);
map.put("userCode", USER_CODE);
map.put("bizType", "2");
RestTemplate restTemplate = new RestTemplate(); RestTemplate restTemplate = new RestTemplate();
HttpHeaders header = new HttpHeaders(); HttpHeaders header = new HttpHeaders();
header.setContentType(MediaType.APPLICATION_FORM_URLENCODED); header.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(multiValueMap, header); String s = HttpUtil.get("https://ioe.car900.com/v1/openApi/dev/controlDevice.json", map, 50000);
System.out.println(s);
HttpEntity<MultiValueMap<String, Object>> httpEntity = null;
String httpResponse; String httpResponse;
try { try {
httpResponse = restTemplate.postForObject(URL_STR, httpResponse = restTemplate.getForObject("https://ioe.car900.com/v1/openApi/dev/registerCloud.json",
httpEntity, String.class); String.class);
System.out.println("map" + httpResponse); System.out.println("map" + httpResponse);
return httpResponse; return httpResponse;
} catch (Exception e) { } catch (Exception e) {
@@ -418,7 +433,7 @@ public class PrinterUtils {
* 检查打印状态 * 检查打印状态
* *
* @param devName 设备名称,(唯一) 对应配置表中的address字段即IP地址/打印机编号) * @param devName 设备名称,(唯一) 对应配置表中的address字段即IP地址/打印机编号)
* @param taskId 打印任务id用于复查打印状态云想印=orderId * @param taskId 打印任务id用于复查打印状态云想印=orderId
* @return * @return
*/ */
public static String checkPrintStatus(String devName, String taskId) { public static String checkPrintStatus(String devName, String taskId) {
@@ -465,7 +480,11 @@ public class PrinterUtils {
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
String str = "{\"bizType\":\"2\",\"broadCastType\":\"1\",\"money\":\"10000000\"}";
printTickets(str, 2, 1, "BSJQG01YJ0001", null);
if (1 == 1) {
return;
}
// //
List<HandoverInfo.PayInfo> payInfos = new ArrayList<>(); List<HandoverInfo.PayInfo> payInfos = new ArrayList<>();