优化代码

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 shopStorePrinter = new ShopStorePrinter();
shopStorePrinter.setModel_id(model_id); shopStorePrinter.setModel_id(model_id);
shopStorePrinter.setPrinter_name(printer_name); shopStorePrinter.setPrinter_name(printer_name);
shopStorePrinter.setPrinter_sn(printer_sn); shopStorePrinter.setPrinter_sn(printer_sn);
shopStorePrinter.setPrinter_key(printer_key); shopStorePrinter.setPrinter_key(printer_key);

View File

@ -27,4 +27,6 @@ public interface ShopStorePrinterMapper extends BaseMapper<ShopStorePrinter>{
* @return * @return
*/ */
IPage<Map> shopStorePrinterPageList(Page<?> page, @Param("keyword") String keyword); 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.baomidou.mybatisplus.core.metadata.IPage;
import com.suisung.mall.common.api.CommonResult; import com.suisung.mall.common.api.CommonResult;
import com.suisung.mall.common.modules.store.ShopStorePrinter; 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 com.suisung.mall.core.web.service.IBaseService;
import java.util.Map; import java.util.Map;
@ -19,6 +20,8 @@ public interface ShopStorePrinterService extends IBaseService<ShopStorePrinter>
*/ */
IPage<Map> shopStorePrinterPageList(String keyword, Integer pageNum, Integer pageSize); 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); 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 @Override
public CommonResult addNewShopStorePrinter(ShopStorePrinter record) { public CommonResult addNewShopStorePrinter(ShopStorePrinter record) {

View File

@ -218,42 +218,39 @@ public class FeieUtil {
String resultStr = ""; String resultStr = "";
resultStr += "<L>商品名称 数量 金额</L><BR>"; resultStr += "<L>商品名称 数量 金额</L><BR>";
resultStr += "--------------------------------<BR>"; resultStr += "--------------------------------<BR>";
for (int i = 0; i < productList.size(); i++) { for (ProductSimpleInfo product : productList) {
String product_sn = productList.get(i).getProduct_sn(); String productSn = product.getProduct_sn();
String title = productList.get(i).getTitle(); String title = product.getTitle();
String num = productList.get(i).getNum().toString();
if (productList.get(i).getNum() > 1) {
num = "x" + num;
}
String amount = productList.get(i).getAmount();
String num = product.getNum() > 1 ? "x" + product.getNum() : product.getNum().toString();
num = addSpace(num, numLen); num = addSpace(num, numLen);
amount = addSpace(amount, amountLen); String amount = addSpace(product.getAmount(), amountLen);
String otherStr = "<L><BOLD>" + num + "</BOLD></L>" + "<L>" + amount + "</L>"; String otherStr = "<L><BOLD>" + num + "</BOLD></L><L>" + amount + "</L>";
int tl = asciiByteLen(title); int titleLength = asciiByteLen(title);
int spaceNum = (tl / titleLen + 1) * titleLen - tl; int spaceNum = (titleLength / titleLen + 1) * titleLen - titleLength;
if (tl < titleLen) {
if (titleLength < titleLen) {
for (int k = 0; k < spaceNum; k++) { for (int k = 0; k < spaceNum; k++) {
title += " "; title += " ";
} }
title += otherStr; title += otherStr;
} else if (tl == titleLen) { } else if (titleLength == titleLen) {
title += otherStr; title += otherStr;
} else { } else {
List<String> list = null; List<String> titleStrList;
if (isEn(title)) { if (isEn(title)) {
// 英文 titleStrList = getStrList(title, titleLen);
list = getStrList(title, titleLen);
} else { } else {
// 中文 titleStrList = getStrList(title, titleLen / 2);
list = 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 = ""; String s = "";
for (int k = 1; k < list.size(); k++) { for (int k = 1; k < titleStrList.size(); k++) {
s += list.get(k); s += titleStrList.get(k);
} }
try { try {
@ -261,10 +258,12 @@ public class FeieUtil {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); 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; return resultStr;
@ -297,27 +296,21 @@ public class FeieUtil {
if (len >= size) { if (len >= size) {
return str; return str;
} }
int cz = size - len; int cz = size - len;
if (cz % 2 == 0) { StringBuilder sb = new StringBuilder();
// 偶数
for (int i = 1; i <= cz; i++) { for (int i = 0; i < cz / 2; i++) {
if (i % 2 == 0) { sb.append(" ");
str = " " + str;
} else {
str = str + " ";
}
}
} else {
// 奇数
for (int i = 1; i <= cz; i++) {
if (i % 2 == 0) {
str = str + " ";
} else {
str = " " + str;
}
}
} }
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 str
* @param f * @param start
* @param t * @param end
* @return * @return
*/ */
public String subString(String str, int f, int t) { public String subString(String str, int start, int end) {
if (f > str.length()) if (start > str.length())
return ""; return "";
if (t > str.length()) { if (end > str.length()) {
return str.substring(f); return str.substring(start);
} else { } 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"> <mapper namespace="com.suisung.mall.shop.store.mapper.ShopStorePrinterMapper">
<resultMap id="ShopStorePrinterVO" type="com.suisung.mall.common.pojo.vo.ShopStorePrinterVO"> <resultMap id="ShopStorePrinterVO" type="com.suisung.mall.common.pojo.vo.ShopStorePrinterVO">
<id column="printer_id" property="printer_id" jdbcType="BIGINT" /> <id column="Printer_id" property="printer_id" jdbcType="BIGINT" />
<result column="store_id" property="store_id" jdbcType="BIGINT" /> <result column="Store_id" property="store_id" jdbcType="BIGINT" />
<result column="model_id" property="model_id" jdbcType="BIGINT" /> <result column="Model_id" property="model_id" jdbcType="BIGINT" />
<result column="model_name" property="model_name" jdbcType="VARCHAR" /> <result column="Model_name" property="model_name" jdbcType="VARCHAR" />
<result column="printer_name" property="printer_name" jdbcType="VARCHAR" /> <result column="Printer_name" property="printer_name" jdbcType="VARCHAR" />
<result column="printer_sn" property="printer_sn" jdbcType="VARCHAR" /> <result column="Printer_sn" property="printer_sn" jdbcType="VARCHAR" />
<result column="printer_key" property="printer_key" jdbcType="VARCHAR" /> <result column="Printer_key" property="printer_key" jdbcType="VARCHAR" />
<result column="card_no" property="card_no" jdbcType="VARCHAR" /> <result column="Card_no" property="card_no" jdbcType="VARCHAR" />
<result column="website_url" property="website_url" jdbcType="VARCHAR" /> <result column="Website_url" property="website_url" jdbcType="VARCHAR" />
<result column="region_id" property="region_id" jdbcType="INTEGER" /> <result column="Region_id" property="region_id" jdbcType="INTEGER" />
<result column="region" property="region" jdbcType="INTEGER" /> <result column="Region" property="region" jdbcType="INTEGER" />
<result column="paper_with" property="paper_with" jdbcType="INTEGER" /> <result column="Paper_with" property="paper_with" jdbcType="INTEGER" />
<result column="intro" property="intro" jdbcType="VARCHAR" /> <result column="Intro" property="intro" jdbcType="VARCHAR" />
<result column="flag" property="flag" jdbcType="INTEGER" /> <result column="Flag" property="flag" jdbcType="INTEGER" />
<result column="status" property="status" jdbcType="INTEGER" /> <result column="Status" property="status" jdbcType="INTEGER" />
<result column="created_by" property="created_by" jdbcType="INTEGER" /> <result column="Created_by" property="created_by" jdbcType="INTEGER" />
<result column="updated_by" property="updated_by" jdbcType="INTEGER" /> <result column="Updated_by" property="updated_by" jdbcType="INTEGER" />
<result column="created_at" property="created_at" jdbcType="TIMESTAMP" /> <result column="Created_at" property="created_at" jdbcType="TIMESTAMP" />
<result column="updated_at" property="updated_at" jdbcType="TIMESTAMP" /> <result column="Updated_at" property="updated_at" jdbcType="TIMESTAMP" />
</resultMap> </resultMap>
<select id="shopStorePrinterPageList" resultType="java.util.Map"> <select id="shopStorePrinterPageList" resultType="java.util.Map">
@ -37,4 +37,17 @@
order by a.printer_id asc order by a.printer_id asc
</select> </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> </mapper>

View File

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