Merge remote-tracking branch 'origin/test' into test

This commit is contained in:
SongZhang 2024-10-22 15:25:04 +08:00
commit f5cef10c40
8 changed files with 192 additions and 56 deletions

View File

@ -255,7 +255,7 @@ public class PrintMechineConsumer {
String data = PrinterUtils.getCashPrintData(detailPO, printType, orderInfo.getOrderType());
String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
PrinterUtils.printTickets(voiceJson, 3, 1, tbPrintMachineWithBLOBs.getAddress(), data);
PrinterUtils.printTickets(voiceJson, 3, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
}
}
}
@ -630,7 +630,7 @@ public class PrintMechineConsumer {
}
log.error("打印数据2>>>>>>>>>>>>>>>>>>>>>>>>: {}", JSON.toJSONString(detailPO));
FeieyunPrintUtil.getCashPrintData(detailPO, tbPrintMachineWithBLOBs.getAddress(), printType, printType);
FeieyunPrintUtil.getCashPrintData(detailPO, tbPrintMachineWithBLOBs.getAddress(), printType, printType, printerNum);
}
}

View File

@ -1,12 +1,17 @@
package com.chaozhanggui.system.cashierservice.rabbit.print;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.chaozhanggui.system.cashierservice.dao.TbProductMapper;
import com.chaozhanggui.system.cashierservice.dao.TbProductSkuMapper;
import com.chaozhanggui.system.cashierservice.dao.TbShopUserMapper;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.dto.CallNumPrintDTO;
import com.chaozhanggui.system.cashierservice.entity.po.CallNumPrintPO;
import com.chaozhanggui.system.cashierservice.mapper.TbCallQueueMapper;
import com.chaozhanggui.system.cashierservice.mapper.TbCallTableMapper;
import com.chaozhanggui.system.cashierservice.model.OrderDetailPO;
import com.chaozhanggui.system.cashierservice.mybatis.MPOrderDetailMapper;
import com.chaozhanggui.system.cashierservice.mybatis.MPOrderInfoMapper;
@ -15,6 +20,7 @@ import com.chaozhanggui.system.cashierservice.service.ShopPrintLogService;
import com.chaozhanggui.system.cashierservice.util.DateUtils;
import com.chaozhanggui.system.cashierservice.util.FeieyunPrintUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@ -25,6 +31,14 @@ import java.util.List;
@Slf4j
public class FeiPrinter extends PrinterHandler {
@Resource
private TbCallQueueMapper tbCallQueueMapper;
@Resource
private TbCallTableMapper tbCallTableMapper;
@Value("${wx.mini.page.call}")
private String callPageUrl;
private final MPOrderInfoMapper mPOrderInfoMapper;
private final MpShopInfoMapper mpShopInfoMapper;
private final MPOrderDetailMapper mPOrderDetailMapper;
@ -71,7 +85,12 @@ public class FeiPrinter extends PrinterHandler {
"0", detailList, orderInfo.getRemark(), orderInfo.getDiscountAmount() == null ? null : orderInfo.getDiscountAmount().toPlainString(), orderInfo.getDiscountRatio() == null ? null : orderInfo.getDiscountRatio().toPlainString());
String printType = "退款单";
log.error("打印数据3>>>>>>>>>>>>>>>>>>>>>>>>: {}", JSON.toJSONString(detailPO));
String[] resp = FeieyunPrintUtil.getCashPrintData(detailPO, machine.getAddress(), printType, printType);
String printerNum = "1";
if (StrUtil.isNotBlank(machine.getPrintQty())) {
printerNum = machine.getPrintQty().split("\\^")[1];
}
StrUtil.blankToDefault(machine.getPrintQty(), "");
String[] resp = FeieyunPrintUtil.getCashPrintData(detailPO, machine.getAddress(), printType, printType, printerNum);
shopPrintLogService.save(machine, "退款单", resp[0], resp[1]);
}
@ -86,13 +105,41 @@ public class FeiPrinter extends PrinterHandler {
"0", detailList, orderInfo.getRemark(), orderInfo.getDiscountAmount() == null ? null : orderInfo.getDiscountAmount().toPlainString(), orderInfo.getDiscountRatio() == null ? null : orderInfo.getDiscountRatio().toPlainString());
String printType = "结算单";
log.error("打印数据1>>>>>>>>>>>>>>>>>>>>>>>>: {}", JSON.toJSONString(detailPO));
String[] resp = FeieyunPrintUtil.getCashPrintData(detailPO, machine.getAddress(), printType, printType);
String printerNum = "1";
if (StrUtil.isNotBlank(machine.getPrintQty())) {
printerNum = machine.getPrintQty().split("\\^")[1];
}
String[] resp = FeieyunPrintUtil.getCashPrintData(detailPO, machine.getAddress(), printType, printType, printerNum);
shopPrintLogService.save(machine, "结算单", resp[0], resp[1]);
}
@Override
protected void callNumPrint(TbPrintMachine machine, CallNumPrintDTO printDTO) {
log.error("未实现打印方法");
TbCallQueue queue = tbCallQueueMapper.selectById(printDTO.getCallQueueId());
if (queue == null) {
log.warn("叫号记录不存在");
return;
}
TbCallTable tbCallTable = tbCallTableMapper.selectById(queue.getCallTableId());
TbShopInfo shopInfo = mpShopInfoMapper.selectById(queue.getShopId());
CallNumPrintPO po = new CallNumPrintPO();
po.setCallNum(queue.getCallNum());
po.setShopName(shopInfo.getShopName());
po.setTableName(tbCallTable.getName());
po.setTableNote(tbCallTable.getNote());
po.setPreNum(tbCallQueueMapper.selectCount(new LambdaQueryWrapper<TbCallQueue>()
.eq(TbCallQueue::getShopId, queue.getShopId())
.eq(TbCallQueue::getCallTableId, queue.getCallTableId())
.lt(TbCallQueue::getId, queue.getId())
.in(TbCallQueue::getState, 0, 1)).toString());
po.setCallNum(queue.getCallNum());
po.setCodeUrl(StrUtil.format(callPageUrl, queue.getShopId(), queue.getId()));
po.setTakeTime(queue.getCreateTime());
po.setShopNote(StrUtil.format("过号顺延{}桌 {}桌后需重新排号 谢谢理解!", tbCallTable.getPostponeNum(), tbCallTable.getPostponeNum()));
String data = FeieyunPrintUtil.getCallNumPrintData(po);
String resp = FeieyunPrintUtil.print(data, machine.getAddress(), "1");
shopPrintLogService.save(machine, "叫号单", data, resp);
}
}

View File

@ -41,22 +41,24 @@ public abstract class PrinterHandler {
protected void print(TbPrintMachine machine, boolean isReturn, TbOrderInfo orderInfo, List<TbOrderDetail> tbOrderDetailList, CallNumPrintDTO printDTO) {
String printMethod = machine.getPrintMethod();
if (StrUtil.isBlank(printMethod)) {
if (StrUtil.isBlank(printMethod) && StrUtil.isBlank(machine.getPrintType())) {
throw new MsgException("打印机配置为空");
}
List<CategoryInfo> categoryInfos = JSONUtil.parseJSONStr2TList(StrUtil.emptyToDefault(machine.getCategoryList(), "[]"), CategoryInfo.class);
//仅打印后厨-一菜一品
if ("one".equals(printMethod)) {
onlyKitchen(machine, orderInfo, tbOrderDetailList, categoryInfos, isReturn);
} else if ("normal".equals(printMethod)) {
//仅打印前台
onlyFrontDesk(machine, orderInfo, tbOrderDetailList, isReturn);
} else if ("all".equals(printMethod)) {
//全部打印 前台+后厨
onlyFrontDesk(machine, orderInfo, tbOrderDetailList, isReturn);
onlyKitchen(machine, orderInfo, tbOrderDetailList, categoryInfos, isReturn);
} else {
log.warn("未知打印类型: {}", printMethod);
if (StrUtil.isNotBlank(printMethod)) {
List<CategoryInfo> categoryInfos = JSONUtil.parseJSONStr2TList(StrUtil.emptyToDefault(machine.getCategoryList(), "[]"), CategoryInfo.class);
//仅打印后厨-一菜一品
if ("one".equals(printMethod)) {
onlyKitchen(machine, orderInfo, tbOrderDetailList, categoryInfos, isReturn);
} else if ("normal".equals(printMethod)) {
//仅打印前台
onlyFrontDesk(machine, orderInfo, tbOrderDetailList, isReturn);
} else if ("all".equals(printMethod)) {
//全部打印 前台+后厨
onlyFrontDesk(machine, orderInfo, tbOrderDetailList, isReturn);
onlyKitchen(machine, orderInfo, tbOrderDetailList, categoryInfos, isReturn);
} else {
log.warn("未知打印类型: {}", printMethod);
}
}
if (StrUtil.isBlank(machine.getPrintType())) {
return;
@ -70,10 +72,10 @@ public abstract class PrinterHandler {
if (!CollUtil.contains(optionList, "queue")) {
return;
}
callNumPrint(machine, printDTO);
if (StrUtil.isBlank(printMethod)) {
throw new MsgException("打印机配置为空");
if (printDTO == null) {
return;
}
callNumPrint(machine, printDTO);
}
/**
@ -93,7 +95,10 @@ public abstract class PrinterHandler {
log.error("商品不存在, id: {}", item.getProductSkuId());
return;
}
if (StrUtil.isEmpty(machine.getClassifyPrint())) {
log.error("分类打印是空, classifyPrint: {}", machine.getClassifyPrint());
return;
}
long count = categoryInfos.stream().filter(c ->
c.getId().toString().equals(categoryId)
).count();

View File

@ -116,7 +116,11 @@ public class YxyPrinter extends PrinterHandler {
String data = PrinterUtils.getCashPrintData(detailPO, printType, orderInfo.getOrderType());
// String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
String voiceJson = "{\"bizType\":\"2\",\"content\":\"\"}";
String resp = PrinterUtils.printTickets(voiceJson, 3, 1, machine.getAddress(), data);
String printerNum = "1";
if (StrUtil.isNotBlank(machine.getPrintQty())) {
printerNum = machine.getPrintQty().split("\\^")[1];
}
String resp = PrinterUtils.printTickets(voiceJson, 3, Integer.valueOf(printerNum), machine.getAddress(), data);
shopPrintLogService.save(machine, printType, data, resp);
}

View File

@ -281,7 +281,7 @@ public class CloudPrinterService {
ObjectUtil.isEmpty(orderInfo.getMasterId()) || ObjectUtil.isNull(orderInfo.getMasterId()) ? orderInfo.getTableName() : orderInfo.getMasterId(),
orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())),
"【POS-1】001", orderInfo.getOrderAmount().toPlainString(), balance, orderInfo.getPayType(), "0",
detailList, orderInfo.getRemark(), orderInfo.getDiscountAmount()==null?null:orderInfo.getDiscountAmount().toPlainString(), orderInfo.getDiscountRatio()==null?null:orderInfo.getDiscountRatio().toPlainString());
detailList, orderInfo.getRemark(), orderInfo.getDiscountAmount() == null ? null : orderInfo.getDiscountAmount().toPlainString(), orderInfo.getDiscountRatio() == null ? null : orderInfo.getDiscountRatio().toPlainString());
detailPO.setOutNumber(orderInfo.getOutNumber());
String printType = "退款单";
@ -373,7 +373,7 @@ public class CloudPrinterService {
/**
* 仅打印结算单前台
*/
private Result onlyFrontDeskForFe(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs, String model, TbOrderInfo orderInfo, TbShopInfo shopInfo, String printerNum, List<CategoryInfo> categoryInfos, String type, Boolean ispre,String orderId) {
private Result onlyFrontDeskForFe(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs, String model, TbOrderInfo orderInfo, TbShopInfo shopInfo, String printerNum, List<CategoryInfo> categoryInfos, String type, Boolean ispre, String orderId) {
if (!"normal".equals(type)) {
return Result.fail("非小票打印");
}
@ -473,7 +473,7 @@ public class CloudPrinterService {
orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())),
"【POS-1】001", orderInfo.getOrderAmount().toPlainString(),
balance, (ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType()),
"0", detailList, orderInfo.getRemark(), orderInfo.getDiscountAmount()==null?null:orderInfo.getDiscountAmount().toPlainString(), orderInfo.getDiscountRatio()==null?null:orderInfo.getDiscountRatio().toPlainString());
"0", detailList, orderInfo.getRemark(), orderInfo.getDiscountAmount() == null ? null : orderInfo.getDiscountAmount().toPlainString(), orderInfo.getDiscountRatio() == null ? null : orderInfo.getDiscountRatio().toPlainString());
String printType = "结算单";
if (ispre) {
printType = "预结算单";
@ -484,7 +484,7 @@ public class CloudPrinterService {
}
log.error("打印数据4>>>>>>>>>>>>>>>>>>>>>>>>: {}", JSON.toJSONString(detailPO));
FeieyunPrintUtil.getCashPrintData(detailPO, tbPrintMachineWithBLOBs.getAddress(), printType, printType);
FeieyunPrintUtil.getCashPrintData(detailPO, tbPrintMachineWithBLOBs.getAddress(), printType, printType, printerNum);
}
}

View File

@ -274,7 +274,7 @@ public class DataService {
String model = it.getPrintMethod();
if(!"normal".equals(model)){
if(!"normal".equals(model) && !"all".equals(model)){
log.error("打印机类型错误");
return;
}

View File

@ -7,18 +7,13 @@ import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.model.CategoryInfo;
import com.chaozhanggui.system.cashierservice.model.OrderDetailPO;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result;
import com.chaozhanggui.system.cashierservice.util.*;
import com.chaozhanggui.system.cashierservice.util.DateUtils;
import com.chaozhanggui.system.cashierservice.util.RedisUtils;
import com.chaozhanggui.system.cashierservice.util.TokenUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import redis.clients.jedis.Jedis;
import java.math.BigDecimal;
import java.util.*;
@ -55,6 +50,8 @@ public class DutyService {
public void exect(String message) {
try {
System.out.println("数据落地开始:" + message);
log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>数据落地开始: {}", message);
log.error(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>数据落地开始: {}", message);
JSONObject jsonObject = JSON.parseObject(message);
String token = jsonObject.getString("token");
@ -71,7 +68,7 @@ public class DutyService {
String loginName = tokenJson.getString("loginName");
TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(shopId);
ShopUserDuty shopUserDuty = shopUserDutyMapper.selectByShopIdAndStatus(shopId, "0");
if(Objects.isNull(shopUserDuty)){
if (Objects.isNull(shopUserDuty)) {
shopUserDuty = new ShopUserDuty(userId, tbToken.getCreateTime(), 0, BigDecimal.ZERO, shopInfo.getShopName(), "0",
BigDecimal.ZERO, shopId, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, "");
shopUserDuty.setTokenId(tokenId);
@ -79,12 +76,12 @@ public class DutyService {
shopUserDuty.setTradeDay(DateUtils.getDay());
shopUserDuty.setQuickAmount(amount);
shopUserDutyMapper.insert(shopUserDuty);
}else {
shopUserDuty.setQuickAmount(ObjectUtil.isNull(shopUserDuty.getQuickAmount())?amount:shopUserDuty.getQuickAmount().add(amount));
} else {
shopUserDuty.setQuickAmount(ObjectUtil.isNull(shopUserDuty.getQuickAmount()) ? amount : shopUserDuty.getQuickAmount().add(amount));
shopUserDutyMapper.updateByPrimaryKey(shopUserDuty);
}
} else if("memberIn".equals(type)){
} else if ("memberIn".equals(type)) {
Integer tokenId = tbToken.getId();
BigDecimal amount = new BigDecimal(jsonObject.getString("amount"));
@ -95,7 +92,7 @@ public class DutyService {
String loginName = tokenJson.getString("loginName");
TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(shopId);
ShopUserDuty shopUserDuty = shopUserDutyMapper.selectByShopIdAndStatus(shopId, "0");
if(Objects.isNull(shopUserDuty)){
if (Objects.isNull(shopUserDuty)) {
shopUserDuty = new ShopUserDuty(userId, tbToken.getCreateTime(), 0, BigDecimal.ZERO, shopInfo.getShopName(), "0",
BigDecimal.ZERO, shopId, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, "");
shopUserDuty.setTokenId(tokenId);
@ -103,21 +100,21 @@ public class DutyService {
shopUserDuty.setTradeDay(DateUtils.getDay());
shopUserDuty.setMemberInAmount(amount);
shopUserDutyMapper.insert(shopUserDuty);
}else {
shopUserDuty.setMemberInAmount(ObjectUtil.isNull(shopUserDuty.getMemberInAmount())?amount:shopUserDuty.getMemberInAmount().add(amount));
} else {
shopUserDuty.setMemberInAmount(ObjectUtil.isNull(shopUserDuty.getMemberInAmount()) ? amount : shopUserDuty.getMemberInAmount().add(amount));
shopUserDutyMapper.updateByPrimaryKey(shopUserDuty);
}
}else if("wxMemberIn".equals(type)){
String shopId=jsonObject.getString("shopId");
} else if ("wxMemberIn".equals(type)) {
String shopId = jsonObject.getString("shopId");
BigDecimal amount=new BigDecimal(jsonObject.getString("amount"));
BigDecimal amount = new BigDecimal(jsonObject.getString("amount"));
ShopUserDuty shopUserDuty = shopUserDutyMapper.selectByShopIdAndStatus(Integer.valueOf(shopId), "0");
TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId));
if(Objects.isNull(shopUserDuty)){
if (Objects.isNull(shopUserDuty)) {
shopUserDuty = new ShopUserDuty(Integer.valueOf(shopId), tbToken.getCreateTime(), 0, BigDecimal.ZERO, shopInfo.getShopName(), "0",
BigDecimal.ZERO, Integer.valueOf(shopId), BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, "");
@ -128,11 +125,11 @@ public class DutyService {
}
shopUserDuty.setTradeDay(DateUtils.getDay());
shopUserDuty.setReturnAmount(BigDecimal.ZERO);
shopUserDuty.setMemberInAmount(ObjectUtil.isNull(shopUserDuty.getMemberInAmount())?amount:shopUserDuty.getMemberInAmount().add(amount));
shopUserDuty.setMemberInAmount(ObjectUtil.isNull(shopUserDuty.getMemberInAmount()) ? amount : shopUserDuty.getMemberInAmount().add(amount));
shopUserDutyMapper.insert(shopUserDuty);
}else {
shopUserDuty.setMemberInAmount(ObjectUtil.isNull(shopUserDuty.getMemberInAmount())?amount:shopUserDuty.getMemberInAmount().add(amount));
} else {
shopUserDuty.setMemberInAmount(ObjectUtil.isNull(shopUserDuty.getMemberInAmount()) ? amount : shopUserDuty.getMemberInAmount().add(amount));
shopUserDutyMapper.updateByPrimaryKey(shopUserDuty);
}
@ -167,7 +164,7 @@ public class DutyService {
shopUserDuty = new ShopUserDuty(userId, tbToken.getCreateTime(), 1, orderInfo.getOrderAmount(), shopInfo.getShopName(), "0",
orderInfo.getOrderAmount(), shopId, BigDecimal.ZERO, cashAmount, BigDecimal.ZERO, "");
shopUserDuty.setTokenId(tokenId);
shopUserDuty.setMemberOutAmount("deposit".equals(orderInfo.getPayType())?orderInfo.getOrderAmount():BigDecimal.ZERO);
shopUserDuty.setMemberOutAmount("deposit".equals(orderInfo.getPayType()) ? orderInfo.getOrderAmount() : BigDecimal.ZERO);
shopUserDuty.setReturnAmount(BigDecimal.ZERO);
shopUserDuty.setTradeDay(DateUtils.getDay());
shopUserDutyMapper.insert(shopUserDuty);
@ -192,7 +189,7 @@ public class DutyService {
shopUserDuty.setAmount(shopUserDuty.getAmount().add(orderInfo.getPayAmount()));
shopUserDuty.setCashAmount(shopUserDuty.getCashAmount().add(cashAmount));
shopUserDuty.setIncomeAmount(shopUserDuty.getIncomeAmount().add(orderInfo.getPayAmount()));
shopUserDuty.setMemberOutAmount("deposit".equals(orderInfo.getPayType())?ObjectUtil.isNull(shopUserDuty.getMemberOutAmount())?orderInfo.getOrderAmount():shopUserDuty.getMemberOutAmount().add(orderInfo.getOrderAmount()):shopUserDuty.getMemberOutAmount());
shopUserDuty.setMemberOutAmount("deposit".equals(orderInfo.getPayType()) ? ObjectUtil.isNull(shopUserDuty.getMemberOutAmount()) ? orderInfo.getOrderAmount() : shopUserDuty.getMemberOutAmount().add(orderInfo.getOrderAmount()) : shopUserDuty.getMemberOutAmount());
shopUserDuty.setOrderNum(shopUserDuty.getOrderNum() + 1);
shopUserDutyMapper.updateByPrimaryKeySelective(shopUserDuty);
List<Integer> skuIds = new ArrayList<>();
@ -364,20 +361,23 @@ public class DutyService {
ShopUserDuty shopUserDuty = shopUserDutyMapper.selectByShopIdAndStatus(shopId, "0");
// cloudPrinterService.handoverprintData(token, shopUserDuty.getId(), "",true);
// shopUserDutyMapper.updateStatusByTokenId(day, shopId, staffId);
if(Objects.nonNull(shopUserDuty)){
if (Objects.nonNull(shopUserDuty)) {
shopUserDutyMapper.updateStatusById(shopUserDuty.getId(), staffId);
}
}
}
}
}catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
}
}
private void subInventory(Integer shopId, Integer skuId, Integer num) {
TbProductSku tbProductSku = productSkuMapper.selectByPrimaryKey(skuId);
if (tbProductSku == null) {
return;
}
TbProductWithBLOBs product = productMapper.selectByPrimaryKey(Integer.valueOf(tbProductSku.getProductId()));

View File

@ -8,6 +8,7 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.chaozhanggui.system.cashierservice.entity.po.CallNumPrintPO;
import com.chaozhanggui.system.cashierservice.model.OrderDetailPO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
@ -254,7 +255,7 @@ public class FeieyunPrintUtil {
return data.toString();
}
public static String[] getCashPrintData(OrderDetailPO detailPO, String sn, String type, String orderType) {
public static String[] getCashPrintData(OrderDetailPO detailPO, String sn, String type, String orderType, String printerNum) {
String content = buildPrintContent(detailPO, type, orderType);
//通过POST请求发送打印信息到服务器
@ -276,7 +277,7 @@ public class FeieyunPrintUtil {
nvps.add(new BasicNameValuePair("apiname", "Open_printMsg"));//固定值,不需要修改
nvps.add(new BasicNameValuePair("sn", sn));
nvps.add(new BasicNameValuePair("content", content));
nvps.add(new BasicNameValuePair("times", "1"));//打印联数
nvps.add(new BasicNameValuePair("times", printerNum));//打印联数
CloseableHttpResponse response = null;
String result = null;
@ -316,6 +317,46 @@ public class FeieyunPrintUtil {
}
public static String print(String content, String sn, String printerNum) {
// 通过POST请求发送打印信息到服务器
RequestConfig requestConfig = RequestConfig.custom()
.setSocketTimeout(30000)// 读取超时
.setConnectTimeout(30000)// 连接超时
.build();
CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(requestConfig).build();
HttpPost post = new HttpPost(URL);
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("user", USER));
String STIME = String.valueOf(System.currentTimeMillis() / 1000);
nvps.add(new BasicNameValuePair("stime", STIME));
nvps.add(new BasicNameValuePair("sig", signature(USER, UKEY, STIME)));
nvps.add(new BasicNameValuePair("apiname", "Open_printMsg"));// 固定值,不需要修改
nvps.add(new BasicNameValuePair("sn", sn));
nvps.add(new BasicNameValuePair("content", content));
nvps.add(new BasicNameValuePair("times", printerNum));// 打印联数
CloseableHttpResponse response = null;
String result = null;
try {
post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
response = httpClient.execute(post);
int statecode = response.getStatusLine().getStatusCode();
if (statecode == 200) {
HttpEntity httpentity = response.getEntity();
if (httpentity != null) {
// 服务器返回的JSON字符串建议要当做日志记录起来
result = EntityUtils.toString(httpentity);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
close(response, post, httpClient);
}
return result;
}
public static int getProducrName(String str) {
int count = 0;
@ -337,6 +378,43 @@ public class FeieyunPrintUtil {
return s;
}
public static void close(CloseableHttpResponse response, HttpPost post, CloseableHttpClient httpClient) {
try {
if (response != null) {
response.close();
}
} catch (IOException e) {
e.printStackTrace();
}
try {
post.abort();
} catch (Exception e) {
e.printStackTrace();
}
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static String getCallNumPrintData(CallNumPrintPO po) {
StringBuilder sb = new StringBuilder();
sb.append(StrUtil.format("<CB>{}</CB><BR>", po.getShopName()));
sb.append("--------------------------------<BR>");
sb.append(StrUtil.format("<CB>{} {}</CB><BR>", po.getTableName(), po.getCallNum()));
sb.append(StrUtil.format("<C>前面有{}桌</C><BR>", po.getPreNum()));
sb.append(StrUtil.format("<C><QR>{}</QR></C><BR>", po.getCodeUrl()));
sb.append("<CB>怕过号扫一扫</CB><BR>");
sb.append("--------------------------------<BR>");
sb.append(po.getShopNote() + "<BR>");
sb.append("--------------------------------<BR>");
sb.append(StrUtil.format("取号时间:{}<BR>", DateUtils.getTime(po.getTakeTime())));
sb.append(StrUtil.format("打印时间:{}<BR>", DateUtils.getTime(new Date())));
sb.append("<CUT>");
return sb.toString();
}
/**
* 检查飞鹅打印机是否在线
*
@ -457,4 +535,6 @@ public class FeieyunPrintUtil {
//失败 {"msg":"ok","ret":0,"data":false,"serverExecutedTime":4}
System.out.println(UnicodeUtil.toString(resp));
}
}