Merge remote-tracking branch 'origin/master'

This commit is contained in:
Tankaikai
2025-03-12 14:18:00 +08:00
3 changed files with 50 additions and 19 deletions

View File

@@ -17,5 +17,10 @@ public class OrderInfoPrintDTO{
*/
@NotNull(message = "id不为空")
private Long id;
/**
* 0结算单 1退款单
*/
@NotNull(message = "打印类型不为空")
private Integer type;
}

View File

@@ -5,12 +5,14 @@ import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.czg.order.entity.OrderDetail;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
@@ -87,7 +89,7 @@ public interface PrinterImpl {
price = addSpace(price, b2);
num = addSpace(num, b3);
total = addSpace(total, b4);
String otherStr = " %s%s %s".formatted(price, num, total);
String otherStr = " %s%s%s".formatted(price, num, total);
int titleByteLen = StrUtil.bytes(title, CharsetUtil.CHARSET_GBK).length;
StringBuilder sb = new StringBuilder();
@@ -171,7 +173,7 @@ public interface PrinterImpl {
// data.append("<OUT:15>");
// data.append("<BR>");
// 18个空格 12
data.append(getFormatLabel("品名 数量 小计", signLabelInfo.s))
data.append(getFormatLabel("品名 数量 小计 ", signLabelInfo.s))
.append(signLabelInfo.br);
// data.append("<S>品名 数量 小计</S><BR>");
data.append(getFormatLabel("--------------------------------", signLabelInfo.s))
@@ -180,7 +182,7 @@ public interface PrinterImpl {
for (OrderDetail detail : detailList) {
String number = detail.getNum().stripTrailingZeros().toPlainString();
String row = getRow(detail.getProductName(), "", number,
toPlainStr(detail.getPayAmount().stripTrailingZeros().toPlainString()), 23, 0, 5, 4);
toPlainStr(detail.getPayAmount().stripTrailingZeros().toPlainString()), 21, 0, 5, 6);
data.append(row);
if (StrUtil.isNotBlank(detail.getSkuName())) {
data.append(getFormatLabel(StrUtil.format("规格:{}", detail.getSkuName()), signLabelInfo.s))
@@ -194,12 +196,15 @@ public interface PrinterImpl {
if (!JSONUtil.isTypeJSONArray(proGroupInfo)) {
continue;
}
JSONArray subItems = JSONUtil.parseArray(proGroupInfo);
for (int i = 0; i < subItems.size(); i++) {
String proName = subItems.getJSONObject(i).getStr("proName");
int qty = subItems.getJSONObject(i).getInt("number");
String subRow = getRow(" - " + proName, "", qty + ".00", "0.00", 20, 0, 3, 6);
data.append(subRow);
JSONArray subItems = com.alibaba.fastjson2.JSONArray.parseArray(proGroupInfo);
for (Object subItem : subItems) {
JSONObject jsonObject = (JSONObject) subItem;
jsonObject.getJSONArray("goods").forEach(item -> {
String proName = ((JSONObject) item).getString("proName");
String qty = ((JSONObject) item).getString("number");
String subRow = getRow(" - " + proName, "", qty, "0.00", 21, 0, 5, 6);
data.append(subRow);
});
}
}
if (ObjectUtil.isNotNull(printInfoDTO.getDiscountAmount())) {
@@ -319,12 +324,16 @@ public interface PrinterImpl {
// builder.append("<S><L>备注: ").append(note).append(" </L></S><BR>");
}
if (!StrUtil.isBlank(proGroupInfo) && JSONUtil.isTypeJSONArray(proGroupInfo)) {
JSONArray subItems = JSONUtil.parseArray(proGroupInfo);
for (int i = 0; i < subItems.size(); i++) {
String proName = subItems.getJSONObject(i).getStr("proName");
int qty = subItems.getJSONObject(i).getInt("number");
builder.append(StrUtil.format("({}) x {}", proName, qty))
.append(signLabelInfo.br);
JSONArray subItems = JSONArray.parseArray(proGroupInfo);
for (Object subItem : subItems) {
JSONObject jsonObject = (JSONObject) subItem;
jsonObject.getJSONArray("goods").forEach(item -> {
String proName = ((JSONObject) item).getString("proName");
String qty = ((JSONObject) item).getString("number -> 1");
builder.append(StrUtil.format("({}) x {}", proName, qty))
.append(signLabelInfo.br);
});
// builder.append("<CS:32>(").append(i + 1).append(")").append(proName).append(" x ").append(qty).append("</CS><BR>");
}
}
@@ -390,7 +399,11 @@ public interface PrinterImpl {
* @return 填充之后的字符串
*/
default String addSpace(String str, int size) {
return StrUtil.fillAfter(str, ' ', size);
int len = str.length();
if (len < size) {
str = str + " ".repeat(size - len);
}
return str;
}
/**
@@ -427,8 +440,20 @@ public interface PrinterImpl {
* @return 添加间距的字符串
*/
default String titleAddSpace(String str, int b1) {
int byteLen = StrUtil.bytes(str, CharsetUtil.CHARSET_GBK).length;
return StrUtil.fillAfter(str, ' ', b1 - byteLen);
int k = 0;
try {
k = str.getBytes("GBK").length;
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
str = str + " ".repeat(Math.max(0, b1 - k));
return str;
}
public static void main(String[] args) {
System.out.println("水煮肉片".length());
System.out.println( StrUtil.repeat(' ', 8));
System.out.println(StrUtil.fillAfter("水煮肉片", ' ', 21));
}
/**

View File

@@ -706,6 +706,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
orderInfo.setSeatAmount(shopInfo.getTableFee().multiply(new BigDecimal(param.getSeatNum())));
orderInfo.setSeatNum(param.getSeatNum());
}
orderInfo.setTableCode(param.getTableCode());
orderInfo.setPlaceNum(param.getPlaceNum());
orderInfo.setOriginAmount(param.getOriginAmount());
orderInfo.setOrderAmount(BigDecimal.ZERO);