优化代码

This commit is contained in:
Jack 2024-11-02 17:39:32 +08:00
parent 7ed20a467b
commit f125a2206a
8 changed files with 96 additions and 72 deletions

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

@ -45,6 +45,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) {

View File

@ -218,42 +218,39 @@ public class FeieUtil {
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 amount = productList.get(i).getAmount();
for (ProductSimpleInfo product : productList) {
String productSn = product.getProduct_sn();
String title = product.getTitle();
String num = product.getNum() > 1 ? "x" + product.getNum() : product.getNum().toString();
num = addSpace(num, numLen);
amount = addSpace(amount, amountLen);
String otherStr = "<L><BOLD>" + num + "</BOLD></L>" + "<L>" + amount + "</L>";
String amount = addSpace(product.getAmount(), amountLen);
String otherStr = "<L><BOLD>" + num + "</BOLD></L><L>" + amount + "</L>";
int tl = asciiByteLen(title);
int spaceNum = (tl / titleLen + 1) * titleLen - tl;
if (tl < titleLen) {
int titleLength = asciiByteLen(title);
int spaceNum = (titleLength / titleLen + 1) * titleLen - titleLength;
if (titleLength < titleLen) {
for (int k = 0; k < spaceNum; k++) {
title += " ";
}
title += otherStr;
} else if (tl == titleLen) {
} else if (titleLength == titleLen) {
title += otherStr;
} else {
List<String> list = null;
List<String> titleStrList;
if (isEn(title)) {
// 英文
list = getStrList(title, titleLen);
titleStrList = getStrList(title, titleLen);
} else {
// 中文
list = getStrList(title, titleLen / 2);
titleStrList = getStrList(title, titleLen / 2);
}
String s0 = titleAddSpace(list.get(0), titleLen);
title = s0 + otherStr + "<BR>";// 添加 单价 数量 总额
String s0 = titleAddSpace(titleStrList.get(0), titleLen);
title = s0 + otherStr + "<BR>";
String s = "";
for (int k = 1; k < list.size(); k++) {
s += list.get(k);
for (int k = 1; k < titleStrList.size(); k++) {
s += titleStrList.get(k);
}
try {
@ -261,10 +258,12 @@ public class FeieUtil {
} catch (Exception e) {
e.printStackTrace();
}
title += "<L>" + s + "</L> ";
title += "<L>" + s + "</L>";
}
resultStr += "<L>" + title + "</L> " + "<BR>";
resultStr += "<BOLD>" + product_sn + "</BOLD><BR>";
resultStr += "<L>" + title + "</L>" + "<BR>";
resultStr += "<BOLD>" + productSn + "</BOLD><BR>";
}
return resultStr;
@ -297,27 +296,21 @@ public class FeieUtil {
if (len >= size) {
return str;
}
int cz = size - len;
if (cz % 2 == 0) {
// 偶数
for (int i = 1; i <= cz; i++) {
if (i % 2 == 0) {
str = " " + str;
} else {
str = str + " ";
}
}
} else {
// 奇数
for (int i = 1; i <= cz; i++) {
if (i % 2 == 0) {
str = str + " ";
} else {
str = " " + str;
}
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < cz / 2; i++) {
sb.append(" ");
}
return str;
sb.append(str);
for (int i = 0; i < cz / 2; i++) {
sb.append(" ");
}
return sb.toString();
}
/**
@ -338,7 +331,6 @@ public class FeieUtil {
}
/**
* 判断字符串是否为英文
*
@ -392,17 +384,17 @@ public class FeieUtil {
* 截取字符串
*
* @param str
* @param f
* @param t
* @param start
* @param end
* @return
*/
public String subString(String str, int f, int t) {
if (f > str.length())
public String subString(String str, int start, int end) {
if (start > str.length())
return "";
if (t > str.length()) {
return str.substring(f);
if (end > str.length()) {
return str.substring(start);
} else {
return str.substring(f, t);
return str.substring(start, end);
}
}

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

@ -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>