优化代码

This commit is contained in:
Jack 2024-11-02 17:39:32 +08:00
parent 7ed20a467b
commit ac1a4cb585
14 changed files with 489 additions and 138 deletions

1
.gitignore vendored
View File

@ -25,6 +25,7 @@ hs_err_pid*
#maven忽略文件
HELP.md
target/
target
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**
!**/src/test/**

View File

@ -193,6 +193,13 @@
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-web-servlet</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-freemarker -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
</dependencies>
<!-- 指定仓库为阿里云与阿帕奇 -->
<repositories>

View File

@ -0,0 +1,120 @@
package com.suisung.mall.common.pojo.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
* 门店打票机打印的订单实体
* </p>
*
* @author panjunjie
* @since 2024-10-28
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "ShopStoreOrderPrint显示对象", description = "门店订单打印实体类")
public class ShopStoreOrderPrintVO implements Serializable {
private static final long serialVersionUID = 1L;
// 门店相关信息
@ApiModelProperty(value = "门店ID")
private Integer store_id;
@ApiModelProperty(value = "门店名称")
private String store_name;
@ApiModelProperty(value = "门店电话")
private String store_tel;
@ApiModelProperty(value = "门店地址")
private String store_address;
@ApiModelProperty(value = "收银员")
private String cashier;
@ApiModelProperty(value = "商家订单备注")
private String seller_order_remark;
@ApiModelProperty(value = "取货单号")
private String fetch_no;
// 买家相关信息
@ApiModelProperty(value = "买家订单备注")
private String buyer_order_remark;
// 订单相关信息
@ApiModelProperty(value = "订单编号")
private String order_id;
@ApiModelProperty(value = "订单来源")
private String order_source;
@ApiModelProperty(value = "支付方式")
private String pay_type;
@ApiModelProperty(value = "配送来源")
private String shipper_type;
@ApiModelProperty(value = "付款时间")
private String pay_time;
@ApiModelProperty(value = "配送时间区间")
private String delivery_time_range;
// 价格相关
@ApiModelProperty(value = "商品发布原价")
private Long order_product_amount;
@ApiModelProperty(value = "订单商品金额")
private Long order_goods_amount;
@ApiModelProperty(value = "订单折扣金额")
private Long order_discount_amount;
@ApiModelProperty(value = "订单配送费用")
private Long order_shipping_fee;
@ApiModelProperty(value = "订单优惠券金额")
private Long order_voucher_price;
@ApiModelProperty(value = "订单积分费用")
private Long order_points_fee;
@ApiModelProperty(value = "订单调整费用")
private Long order_adjust_fee;
@ApiModelProperty(value = "实际应付款")
private Long order_payment_amount;
// 订单商品详情信息
@ApiModelProperty(value = "订单商品详情信息")
private ShopStoreOrderProductPrintVO order_item;
@ApiModelProperty(value = "状态1-有效2-无效;")
private Integer status;
@ApiModelProperty(value = "新增用户ID")
private Integer created_by;
@ApiModelProperty(value = "更新用户ID")
private Integer updated_by;
@ApiModelProperty(value = "新增时间")
private Date created_at;
@ApiModelProperty(value = "修改时间")
private Date updated_at;
}

View File

@ -1,4 +1,4 @@
package com.suisung.mall.common.pojo.dto;
package com.suisung.mall.common.pojo.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
@ -9,7 +9,7 @@ import java.io.Serializable;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ProductSimpleInfo implements Serializable {
public class ShopStoreOrderProductPrintVO implements Serializable {
private String product_sn;
private String title;
private Integer num;

View File

@ -0,0 +1,53 @@
package com.suisung.mall.common.utils;
import freemarker.cache.StringTemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
import java.io.StringWriter;
import java.util.Map;
@Slf4j
public class FreeMakerUtils {
/**
* 配置 freemark configuration
*
* @return
*/
private Configuration stringTempConfiguration() {
Configuration cfg = new Configuration(Configuration.VERSION_2_3_23);
StringTemplateLoader stringLoader = new StringTemplateLoader();
stringTempConfiguration().setTemplateLoader(stringLoader);
cfg.setDefaultEncoding("UTF-8");
return cfg;
}
/**
* 解析模版
*
* @param configuration
* @param templateName
* @param templateValue
* @param binding
* @return
* @throws IOException
* @throws TemplateException
*/
public String processTemplate(Configuration configuration, String templateName, String templateValue, Map<String, Object> binding) throws IOException, TemplateException {
StringWriter stringWriter = new StringWriter();
Template template = new Template(templateName, templateValue, configuration);
template.process(binding, stringWriter);
return stringWriter.toString();
}
public String processTemplate(String templateName, String templateValue, Map<String, Object> binding) throws IOException, TemplateException {
StringWriter stringWriter = new StringWriter();
Template template = new Template(templateName, templateValue, stringTempConfiguration());
template.process(binding, stringWriter);
return stringWriter.toString();
}
}

View File

@ -45,6 +45,7 @@ public class ShopStorePrinterController {
ShopStorePrinter shopStorePrinter = new ShopStorePrinter();
shopStorePrinter.setModel_id(model_id);
shopStorePrinter.setPrinter_name(printer_name);
shopStorePrinter.setPrinter_sn(printer_sn);
shopStorePrinter.setPrinter_key(printer_key);

View File

@ -27,4 +27,6 @@ public interface ShopStorePrinterMapper extends BaseMapper<ShopStorePrinter>{
* @return
*/
IPage<Map> shopStorePrinterPageList(Page<?> page, @Param("keyword") String keyword);
IPage<ShopStorePrinterVO> shopStorePrinterPageList2(Page<?> page, @Param("keyword") String keyword);
}

View File

@ -3,6 +3,7 @@ package com.suisung.mall.shop.store.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.suisung.mall.common.api.CommonResult;
import com.suisung.mall.common.modules.store.ShopStorePrinter;
import com.suisung.mall.common.pojo.vo.ShopStorePrinterVO;
import com.suisung.mall.core.web.service.IBaseService;
import java.util.Map;
@ -19,6 +20,8 @@ public interface ShopStorePrinterService extends IBaseService<ShopStorePrinter>
*/
IPage<Map> shopStorePrinterPageList(String keyword, Integer pageNum, Integer pageSize);
IPage<ShopStorePrinterVO> shopStorePrinterPageList2(String keyword, Integer pageNum, Integer pageSize);
/**
* 门店新增一个打票机
*

View File

@ -9,10 +9,9 @@ import com.suisung.mall.common.api.CommonResult;
import com.suisung.mall.common.constant.ConstantError;
import com.suisung.mall.common.domain.UserDto;
import com.suisung.mall.common.modules.store.ShopStorePrinter;
import com.suisung.mall.common.pojo.dto.ProductSimpleInfo;
import com.suisung.mall.common.pojo.vo.ShopStoreOrderProductPrintVO;
import com.suisung.mall.common.pojo.vo.ShopStorePrinterVO;
import com.suisung.mall.common.utils.DateTimeUtils;
import com.suisung.mall.common.utils.TimeUtil;
import com.suisung.mall.core.web.service.impl.BaseServiceImpl;
import com.suisung.mall.shop.store.mapper.ShopStorePrinterMapper;
import com.suisung.mall.shop.store.service.ShopStorePrinterService;
@ -45,6 +44,13 @@ public class ShopStorePrinterServiceImpl extends BaseServiceImpl<ShopStorePrinte
return shopStorePrinterMapper.shopStorePrinterPageList(page, keyword);
}
public IPage<ShopStorePrinterVO> shopStorePrinterPageList2(String keyword, Integer pageNum, Integer pageSize) {
Page<ShopStorePrinterVO> page = new Page<ShopStorePrinterVO>();
page.setCurrent(pageNum);
page.setSize(pageSize);
return shopStorePrinterMapper.shopStorePrinterPageList2(page, keyword);
}
@Override
public CommonResult addNewShopStorePrinter(ShopStorePrinter record) {
@ -216,11 +222,11 @@ public class ShopStorePrinterServiceImpl extends BaseServiceImpl<ShopStorePrinte
String sn="922441475";
ProductSimpleInfo order1 = new ProductSimpleInfo("6970448170051","可口可乐CocaCola经典美味汽水1.25L/瓶",110, "1000.45");
ProductSimpleInfo order2 = new ProductSimpleInfo("6970448170053","排骨约350g默认砍小块",1, "150.13");
ProductSimpleInfo order3 = new ProductSimpleInfo("6970448170054","新鲜虫草花1包 约200g", 11,"687.25");
ProductSimpleInfo order4 = new ProductSimpleInfo("6970448170055","冰红茶风味饮料",1, "13.24");
List<ProductSimpleInfo> productList = new ArrayList<>();
ShopStoreOrderProductPrintVO order1 = new ShopStoreOrderProductPrintVO("6970448170051","可口可乐CocaCola经典美味汽水1.25L/瓶",110, "8100.45");
ShopStoreOrderProductPrintVO order2 = new ShopStoreOrderProductPrintVO("6970448170053","排骨约350g默认砍小块",1, "150.13");
ShopStoreOrderProductPrintVO order3 = new ShopStoreOrderProductPrintVO("6970448170054","新鲜虫草花1包约200g 韭菜1000g 鸡蛋2003克", 11,"4.01");
ShopStoreOrderProductPrintVO order4 = new ShopStoreOrderProductPrintVO("6970448170055","冰红茶风味饮料",1, "13.24");
List<ShopStoreOrderProductPrintVO> productList = new ArrayList<>();
productList.add(order1);
productList.add(order2);
productList.add(order3);
@ -234,51 +240,38 @@ public class ShopStorePrinterServiceImpl extends BaseServiceImpl<ShopStorePrinte
StringBuilder cont= new StringBuilder();
cont.append("<CB>小发同城</CB><BR>");
cont.append("--------------------------------<BR>");
cont.append("<CB>#000"+DateTimeUtils.formatDateTime(now,"ddHHmm")+"</CB><BR>");
cont.append("<L>买家备注:不用敲门,放在门口旁边的外卖箱,打个电话告知送达就行,谢谢</L><BR>");
cont.append("<BOLD>配送时间2024-10-25 14:00-14:30</BOLD><BR>");
cont.append("--------------------------------<BR>");
cont.append("订单编号ES20231026111444527685<BR>");
cont.append("订单来源:微信小程序<BR>");
cont.append("支付方式:微信支付<BR>");
cont.append("配送来源:同城配送<BR>");
cont.append("付款时间:"+currentDateTime+"<BR>");
cont.append("--------------------------------<BR>");
// cont.append("<BOLD>商品名称 数量 <RIGHT>金额</RIGHT><BOLD><BR>");
// cont.append("<BOLD>可口可乐Coca_Cola<BR>经典美味汽水1.25L/瓶</BOLD> <RIGHT><BOLD>【x1】</BOLD> <BOLD>5.54</BOLD></RIGHT><BR>");
// cont.append("<BOLD>6970448170051</BOLD><BR>");
// cont.append("<BR>");
// cont.append("<BOLD>排骨 约350g (默认砍小块)</BOLD> <RIGHT><BOLD>【x5】</BOLD> <BOLD>35.51</BOLD></RIGHT><BR>");
// cont.append("<BOLD>69704481700541</BOLD><BR>");
// cont.append("<BR>");
// cont.append("<BOLD>新鲜虫草花 1包 约200g </BOLD> <RIGHT><BOLD>【x11】</BOLD> <BOLD>687.52</BOLD></RIGHT><BR>");
// cont.append("<BOLD>69704481700512</BOLD><BR>");
// cont.append("<BR>");
// cont.append("<BOLD>冰红茶风味饮料x2<BR>五香瓜子x1</BOLD> <RIGHT><BOLD>【x2】</BOLD> <BOLD>13.26</BOLD></RIGHT><BR>");
// cont.append("<BOLD>6970448170051</BOLD><BR>");
// cont.append("<CB>#000"+DateTimeUtils.formatDateTime(now,"ddHHmm")+"</CB><BR>");
// cont.append("<L>买家备注:不用敲门,放在门口旁边的外卖箱,打个电话告知送达就行,谢谢!!!</L><BR>");
// cont.append("<BOLD>配送时间2024-10-25 14:00-14:30</BOLD><BR>");
// cont.append("--------------------------------<BR>");
// cont.append("订单编号ES20231026111444527685<BR>");
// cont.append("订单来源:微信小程序<BR>");
// cont.append("支付方式:微信支付<BR>");
// cont.append("配送来源:顺丰同城<BR>");
// cont.append("付款时间:"+currentDateTime+"<BR>");
// cont.append("--------------------------------<BR>");
// 商品列表
cont.append(productsStr);
cont.append("--------------------------------<BR>");
cont.append("商品总件数:<BOLD>3</BOLD><BR>");
cont.append("商品总额:<BOLD>¥18.7</BOLD><BR>");
cont.append("押金:<BOLD>¥500</BOLD><BR>");
cont.append("运费:<BOLD>¥5.54</BOLD><BR>");
cont.append("会员权益:<BOLD>-¥50</BOLD><BR>");
cont.append("秒杀:<BOLD>-¥100</BOLD><BR>");
cont.append("实付金额:<BOLD>¥428.9元</BOLD><BR>");
cont.append("--------------------------------<BR>");
cont.append("<BOLD>商家备注:老顾客赠送一箱牛奶;玻璃瓶包装轻拿轻放</BOLD><BR>");
cont.append("--------------------------------<BR>");
cont.append("<BOLD>收货人:张三</BOLD><BR>");
cont.append("<BOLD>收货人手机13128778765</BOLD><BR>");
cont.append("<BOLD>收货地址北京市朝阳区朝阳路朝阳人民小区1号楼1栋1101</BOLD><BR>");
cont.append("--------------------------------<BR>");
cont.append("门店:岛内价生活超市<BR>");
cont.append("门店电话:<BOLD>13665822542</BOLD><BR>");
cont.append("收银员:李小璐<BR>");
// cont.append("--------------------------------<BR>");
// cont.append("商品总件数:<BOLD>3</BOLD><BR>");
// cont.append("商品总额:<BOLD>¥18.7</BOLD><BR>");
// cont.append("押金:<BOLD>¥500</BOLD><BR>");
// cont.append("运费:<BOLD>¥5.54</BOLD><BR>");
// cont.append("会员权益:<BOLD>-¥50</BOLD><BR>");
// cont.append("秒杀:<BOLD>-¥100</BOLD><BR>");
// cont.append("实付金额:<BOLD>¥428.9元</BOLD><BR>");
// cont.append("--------------------------------<BR>");
// cont.append("<BOLD>商家备注:老顾客赠送一箱牛奶;玻璃瓶包装轻拿轻放</BOLD><BR>");
// cont.append("--------------------------------<BR>");
// cont.append("<BOLD>收货人:张三</BOLD><BR>");
// cont.append("<BOLD>收货人手机13128778765</BOLD><BR>");
// cont.append("<BOLD>收货地址北京市朝阳区朝阳路朝阳人民小区1号楼1栋1101</BOLD><BR>");
// cont.append("--------------------------------<BR>");
// cont.append("门店:岛内价生活超市<BR>");
// cont.append("门店电话:<BOLD>13665822542</BOLD><BR>");
// cont.append("收银员:李小璐<BR>");
feieUtil.printContent(sn,cont.toString());

View File

@ -2,7 +2,7 @@ package com.suisung.mall.shop.store.utis;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.suisung.mall.common.pojo.dto.ProductSimpleInfo;
import com.suisung.mall.common.pojo.vo.ShopStoreOrderProductPrintVO;
import com.suisung.mall.common.pojo.res.FeiePrinterApiDataRes;
import com.suisung.mall.common.pojo.res.FeiePrinterApiRes;
import com.suisung.mall.common.utils.JsonUtil;
@ -23,6 +23,8 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
@ -44,6 +46,38 @@ public class FeieUtil {
//=====================以下是函数实现部分================================================
// 根据Unicode编码完美的判断中文汉字和符号
private static boolean isChinese(char c) {
Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
return ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B
|| ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS
|| ub == Character.UnicodeBlock.GENERAL_PUNCTUATION;
}
// 以下是 util 方法
//飞鹅技术支持
//#########################################################################################################
//进行订单的多列排版demo实现商品超出字数的自动换下一行对齐处理同时保持各列进行对齐
//排版原理是统计字符串字节数补空格换行处理
//58mm的机器,一行打印16个汉字,32个字母;80mm的机器,一行打印24个汉字,48个字母
//#########################################################################################################
//orderList为数组 title_len =18 代表名称列占用字节 num_len =8 数量列 amount_len=6金额列-->这里的字节数可按自己需求自由改写
// 完整的判断中文汉字和符号
public static boolean isChinese(String strName) {
char[] ch = strName.toCharArray();
for (int i = 0; i < ch.length; i++) {
char c = ch[i];
if (isChinese(c)) {
return true;
}
}
return false;
}
/***
* 添加一个或多个打印机到厂家
* @param printerInfo 批量添加规则
@ -128,7 +162,6 @@ public class FeieUtil {
return false;
}
/**
* 生成签名字符串
*
@ -194,17 +227,6 @@ public class FeieUtil {
return null;
}
// 以下是 util 方法
//飞鹅技术支持
//#########################################################################################################
//进行订单的多列排版demo实现商品超出字数的自动换下一行对齐处理同时保持各列进行对齐
//排版原理是统计字符串字节数补空格换行处理
//58mm的机器,一行打印16个汉字,32个字母;80mm的机器,一行打印24个汉字,48个字母
//#########################################################################################################
//orderList为数组 title_len =18 代表名称列占用字节 num_len =8 数量列 amount_len=6金额列-->这里的字节数可按自己需求自由改写
/**
* 生成商品的打印字符串
*
@ -214,56 +236,61 @@ public class FeieUtil {
* @param amountLen 金额字节数最大8个字节
* @return
*/
public String genProductStr(List<ProductSimpleInfo> productList, int titleLen, int numLen, int amountLen) {
public String genProductStr(List<ShopStoreOrderProductPrintVO> productList, int titleLen, int numLen, int amountLen) {
String resultStr = "";
resultStr += "<L>商品名称 数量 金额</L><BR>";
resultStr += "--------------------------------<BR>";
for (int i = 0; i < productList.size(); i++) {
String product_sn = productList.get(i).getProduct_sn();
String title = productList.get(i).getTitle();
String num = productList.get(i).getNum().toString();
if (productList.get(i).getNum() > 1) {
num = "x" + num;
}
String num = productList.get(i).getNum() > 1 ? "x" + productList.get(i).getNum().toString() : productList.get(i).getNum().toString();
String amount = productList.get(i).getAmount();
num = addSpace(num, numLen);
amount = addSpace(amount, amountLen);
String otherStr = "<L><BOLD>" + num + "</BOLD></L>" + "<L>" + amount + "</L>";
String otherStr = "<L><BOLD>" + num + "</BOLD></L>" + "<L>" + amount + "</L><BR>";
int tl = asciiByteLen(title);
int spaceNum = (tl / titleLen + 1) * titleLen - tl;
if (tl < titleLen) {
// 标题小于指定的长度字节数
int spaceNum = (tl / titleLen + 1) * titleLen - tl;
for (int k = 0; k < spaceNum; k++) {
title += " ";
}
title += otherStr;
resultStr += "<L>" + title + "</L>" + otherStr;
} else if (tl == titleLen) {
title += otherStr;
// 标题刚刚等于指定的长度字节数
resultStr += "<L>" + title + "</L>" + otherStr;
} else {
List<String> list = null;
if (isEn(title)) {
// 英文
list = getStrList(title, titleLen);
} else {
// 中文
list = getStrList(title, titleLen / 2);
}
String s0 = titleAddSpace(list.get(0), titleLen);
title = s0 + otherStr + "<BR>";// 添加 单价 数量 总额
String s = "";
// List<String> list = segmentString(title, titleLen);
// int cnt = list.size();
// if (cnt <= 0) {
// resultStr += StrUtil.repeat(' ', titleLen - 1) + otherStr;
// }
//
// for (i = 0; i < cnt; i++) {
// resultStr += i == 0 ? list.get(i) + otherStr : list.get(i) + "<BR>";
// }
// 标题大于指定的长度字节数需要截断再组合
List<String> list = containEn(title) ? getStrList(title, titleLen) : getStrList(title, titleLen / 2);
// 截断的第一段
String s0 = "<L>" + titleAddSpace(list.get(0), titleLen) + "</L>";
title = s0 + otherStr;// 添加 单价 数量 总额
// 非第一段处理开始
// String s = "";
for (int k = 1; k < list.size(); k++) {
s += list.get(k);
title += "<L>" + list.get(k) + "</L><BR>";
}
try {
s = getStringByEnter(titleLen, s);
} catch (Exception e) {
e.printStackTrace();
}
title += "<L>" + s + "</L> ";
resultStr += title;
}
resultStr += "<L>" + title + "</L> " + "<BR>";
// resultStr += title;
resultStr += "<BOLD>" + product_sn + "</BOLD><BR>";
}
@ -297,6 +324,7 @@ public class FeieUtil {
if (len >= size) {
return str;
}
int cz = size - len;
if (cz % 2 == 0) {
// 偶数
@ -323,29 +351,27 @@ public class FeieUtil {
/**
* 递归函数字符串超长自动换行
*
* @param length
* @param string
* @param maxBytLen
* @return
* @throws Exception
*/
public String getStringByEnter(int length, String string) throws Exception {
public String getStringByEnter(String string, int maxBytLen) throws Exception {
for (int i = 1; i <= string.length(); i++) {
if (asciiByteLen(string.substring(0, i)) > length) {
return string.substring(0, i - 1) + "<BR>" + getStringByEnter(length, string.substring(i - 1));
if (asciiByteLen(string.substring(0, i)) > maxBytLen) {
return string.substring(0, i - 1) + "<BR>" + getStringByEnter(string.substring(i - 1), maxBytLen);
}
}
return string;
}
/**
* 判断字符串是否为英文
* 判断字符串是否包含英文
*
* @param str
* @return
*/
public Boolean isEn(String str) {
public Boolean containEn(String str) {
return asciiByteLen(str) == str.length();
}
@ -362,47 +388,65 @@ public class FeieUtil {
int byteLength = 0;
for (char c : str.toCharArray()) {
if (c > 255) {
byteLength += 2;
} else {
byteLength += 1;
}
byteLength = c > 255 ? byteLength + 2 : byteLength + 1;
}
return byteLength;
}
public List<String> getStrList(String inputString, int length) {
int size = inputString.length() / length;
if (inputString.length() % length != 0) {
size += 1;
/**
* 分析标题能分几行显示
*
* @param str
* @param wordCnt 英文数字或中文的字数
* @return
*/
public List<String> getStrList(String str, int wordCnt) {
// 分几行
int linesCnt = str.length() / wordCnt;
if (str.length() % wordCnt != 0) {
linesCnt += 1;
}
return getStrList(inputString, length, size);
return setLineToList(str, wordCnt, linesCnt);
}
public List<String> getStrList(String inputString, int length, int size) {
/**
* 把一行行标题分别放入列表里
*
* @param str
* @param wordCnt
* @param linesCnt
* @return
*/
public List<String> setLineToList(String str, int wordCnt, int linesCnt) {
List<String> list = new ArrayList<String>();
for (int index = 0; index < size; index++) {
String childStr = subString(inputString, index * length, (index + 1) * length);
for (int i = 0; i < linesCnt; i++) {
String childStr = subString(str, i * wordCnt, (i + 1) * wordCnt);
list.add(childStr);
}
return list;
}
// private static boolean isChineseChar(char c) {
// return c >= 0x4E00 && c <= 0x9FFF;
// }
/**
* 截取字符串
*
* @param str
* @param f
* @param t
* @param bidx
* @param eidx
* @return
*/
public String subString(String str, int f, int t) {
if (f > str.length())
public String subString(String str, int bidx, int eidx) {
if (bidx > str.length())
return "";
if (t > str.length()) {
return str.substring(f);
if (eidx > str.length()) {
return str.substring(bidx);
} else {
return str.substring(f, t);
return str.substring(bidx, eidx);
}
}
@ -433,5 +477,68 @@ public class FeieUtil {
}
}
/**
* 按字节截取字符串
*
* @param str 原始字符串
* @param bytLen 截取位数
* @return 截取后的字符串
* @throws UnsupportedEncodingException 使用了JAVA不支持的编码格式
*/
public List<String> segmentString(String str, int bytLen) {
if (str == null || str.isEmpty() || bytLen <= 0) {
return null;
}
List<String> segments = new ArrayList<>();
String[] twoSegments = segmentStringb(str, bytLen);
if (twoSegments != null && twoSegments.length > 0) {
if (twoSegments[0] != null && twoSegments[0].length() > 0) {
segments.add(twoSegments[0]);
}
if (twoSegments[1] != null && twoSegments[1].length() > 0) {
segmentString(twoSegments[1], bytLen);
}
}
return segments;
}
public String[] segmentStringb(String str, int bytLen) {
if (str == null || str.isEmpty() || bytLen <= 0) {
return new String[]{"", ""};
}
// 将原始字符串转换为UTF_8编码格式y
str = new String(str.getBytes(), StandardCharsets.UTF_8);
int strBytLen = str.getBytes(StandardCharsets.UTF_8).length;
if (bytLen < strBytLen) {
// 要截取的字节数<原始字符串的字节数
StringBuffer buffStart = new StringBuffer();
StringBuffer buffEnd = new StringBuffer();
char c;
for (int i = 0; i < strBytLen; i++) {
c = str.charAt(i);
buffStart.append(c);
if (isChinese(c)) {
// 中文汉字截取字节总数减
--bytLen;
}
if (i >= bytLen) {
buffEnd.append(c);
}
}
return new String[]{new String(buffStart.toString().getBytes(), StandardCharsets.UTF_8), new String(buffEnd.toString().getBytes(), StandardCharsets.UTF_8)};
} else {
// 要截取的字节数>=原始字符串的字节数
return new String[]{str, ""};
}
}
}

View File

@ -3,25 +3,25 @@
<mapper namespace="com.suisung.mall.shop.store.mapper.ShopStorePrinterMapper">
<resultMap id="ShopStorePrinterVO" type="com.suisung.mall.common.pojo.vo.ShopStorePrinterVO">
<id column="printer_id" property="printer_id" jdbcType="BIGINT" />
<result column="store_id" property="store_id" jdbcType="BIGINT" />
<result column="model_id" property="model_id" jdbcType="BIGINT" />
<result column="model_name" property="model_name" jdbcType="VARCHAR" />
<result column="printer_name" property="printer_name" jdbcType="VARCHAR" />
<result column="printer_sn" property="printer_sn" jdbcType="VARCHAR" />
<result column="printer_key" property="printer_key" jdbcType="VARCHAR" />
<result column="card_no" property="card_no" jdbcType="VARCHAR" />
<result column="website_url" property="website_url" jdbcType="VARCHAR" />
<result column="region_id" property="region_id" jdbcType="INTEGER" />
<result column="region" property="region" jdbcType="INTEGER" />
<result column="paper_with" property="paper_with" jdbcType="INTEGER" />
<result column="intro" property="intro" jdbcType="VARCHAR" />
<result column="flag" property="flag" jdbcType="INTEGER" />
<result column="status" property="status" jdbcType="INTEGER" />
<result column="created_by" property="created_by" jdbcType="INTEGER" />
<result column="updated_by" property="updated_by" jdbcType="INTEGER" />
<result column="created_at" property="created_at" jdbcType="TIMESTAMP" />
<result column="updated_at" property="updated_at" jdbcType="TIMESTAMP" />
<id column="Printer_id" property="printer_id" jdbcType="BIGINT" />
<result column="Store_id" property="store_id" jdbcType="BIGINT" />
<result column="Model_id" property="model_id" jdbcType="BIGINT" />
<result column="Model_name" property="model_name" jdbcType="VARCHAR" />
<result column="Printer_name" property="printer_name" jdbcType="VARCHAR" />
<result column="Printer_sn" property="printer_sn" jdbcType="VARCHAR" />
<result column="Printer_key" property="printer_key" jdbcType="VARCHAR" />
<result column="Card_no" property="card_no" jdbcType="VARCHAR" />
<result column="Website_url" property="website_url" jdbcType="VARCHAR" />
<result column="Region_id" property="region_id" jdbcType="INTEGER" />
<result column="Region" property="region" jdbcType="INTEGER" />
<result column="Paper_with" property="paper_with" jdbcType="INTEGER" />
<result column="Intro" property="intro" jdbcType="VARCHAR" />
<result column="Flag" property="flag" jdbcType="INTEGER" />
<result column="Status" property="status" jdbcType="INTEGER" />
<result column="Created_by" property="created_by" jdbcType="INTEGER" />
<result column="Updated_by" property="updated_by" jdbcType="INTEGER" />
<result column="Created_at" property="created_at" jdbcType="TIMESTAMP" />
<result column="Updated_at" property="updated_at" jdbcType="TIMESTAMP" />
</resultMap>
<select id="shopStorePrinterPageList" resultType="java.util.Map">
@ -37,4 +37,17 @@
order by a.printer_id asc
</select>
<select id="shopStorePrinterPageList2" resultMap="ShopStorePrinterVO">
select a.*, b.model_name as model_name, c.region as region
from shop_store_printer a
left join shop_store_printer_model b on a.model_id=b.model_id
left join shop_store_printer_region c on a.region_id=c.region_id
<where>
<if test="keyword!=null">
and a.printer_name like concat('%',#{keyword},'%')
</if>
</where>
order by a.printer_id asc
</select>
</mapper>

View File

@ -0,0 +1,45 @@
<CB>小发同城</CB><BR>
--------------------------------<BR>
<CB>#00019232</CB><BR>
<L>买家备注:不用敲门,放在门口旁边的外卖箱,打个电话告知送达就行,谢谢!!!</L><BR>
<BOLD>配送时间2024-10-25 14:00-14:30</BOLD><BR>
--------------------------------<BR>
订单编号ES20231026111444527685<BR>
订单来源:微信小程序<BR>
支付方式:微信支付<BR>
配送来源:顺丰同城<BR>
付款时间2024-10-25 14:00:23<BR>
--------------------------------<BR>
<L>商品名称 数量 金额</L><BR>
--------------------------------<BR>
<L>可口可乐CocaC</L> <L><BOLD> x110 </BOLD></L><L> 8100.45</L><BR>
<L>ola经典美味汽水1.2</L><BR>
<L>5L/瓶</L><BR>
<BOLD>6970448170051</BOLD><BR>
<L>排骨约350g默 </L><L><BOLD> 1 </BOLD></L><L> 150.13 </L><BR>
<L>认砍小块)</L><BR>
<BOLD>6970448170053</BOLD><BR>
<L>新鲜虫草花1包约2 </L><L><BOLD> x11 </BOLD></L><L> 4.01 </L><BR>
<L>00g 韭菜1000g 鸡蛋</L><BR>
<L>2003克</L><BR>
<BOLD>6970448170054</BOLD><BR>
<L>冰红茶风味饮料 <L><BOLD> 1 </BOLD></L><L> 13.24 </L></L><BR>
<BOLD>6970448170055</BOLD><BR>
--------------------------------<BR>
商品总件数:<BOLD>3</BOLD><BR>
商品总额:<BOLD>¥18.7</BOLD><BR>
押金:<BOLD>¥500</BOLD><BR>
运费:<BOLD>¥5.54</BOLD><BR>
会员权益:<BOLD>-¥50</BOLD><BR>
秒杀:<BOLD>-¥100</BOLD><BR>
实付金额:<BOLD>¥428.9元</BOLD><BR>
--------------------------------<BR>
<BOLD>商家备注:老顾客赠送一箱牛奶;玻璃瓶包装轻拿轻放!</BOLD><BR>
--------------------------------<BR>
<BOLD>收货人:张三</BOLD><BR>
<BOLD>收货人手机13128778765</BOLD><BR>
<BOLD>收货地址北京市朝阳区朝阳路朝阳人民小区1号楼1栋1101</BOLD><BR>
--------------------------------<BR>
门店:岛内价生活超市<BR>
门店电话:<BOLD>13665822542</BOLD><BR>
收银员:李小璐<BR>

View File

@ -75,6 +75,12 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>