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

This commit is contained in:
2024-10-11 10:17:30 +08:00
10 changed files with 387 additions and 166 deletions

View File

@@ -1,15 +1,20 @@
package com.chaozhanggui.system.cashierservice.controller; package com.chaozhanggui.system.cashierservice.controller;
import cn.hutool.core.date.DateUtil;
import cn.hutool.extra.servlet.ServletUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.entity.TbOrderInfo;
import com.chaozhanggui.system.cashierservice.service.OrderService; import com.chaozhanggui.system.cashierservice.service.OrderService;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.sign.Result;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
@CrossOrigin(origins = "*") @CrossOrigin(origins = "*")
@RestController @RestController
@@ -18,20 +23,44 @@ import java.util.Map;
public class NotifyController { public class NotifyController {
private final OrderService orderService; @Resource
private OrderService orderService;
public NotifyController(OrderService orderService) {
this.orderService = orderService;
}
@RequestMapping("notifyPay") @RequestMapping("notifyPay")
public String notifyPay(@RequestBody Map<String,Object> map){ public Result notifyPay(HttpServletRequest request) {
log.info("notifyPay:{}", JSON.toJSONString(map)); String body = ServletUtil.getBody(request);
return null; log.info("notifyPay body:{}", body);
JSONObject resp = JSON.parseObject(body);
String code = resp.getString("code");
String msg = resp.getString("msg");
if (!"000000".equals(code)) {
log.error("支付失败:{}", resp.getString("msg"));
return Result.fail(msg);
}
JSONObject bizData = JSON.parseObject(resp.getString("bizData"));
String state = bizData.getString("state");
String note = bizData.getString("note");
String payOrderId = bizData.getString("payOrderId");
String payType = bizData.getString("payType");
String payTime = bizData.getString("payTime");
long paidTime = DateUtil.parseDateTime(payTime).getTime();
if (!"TRADE_SUCCESS".equals(state)) {
log.error("支付失败:{},{}", state, note);
return Result.fail(state + ":" + note);
}
TbOrderInfo entity = orderService.selectByPayOrderNo(payOrderId);
if (entity == null) {
return Result.fail("订单不存在");
}
entity.setPaidTime(paidTime);
orderService.payCallbackCloseOrder(entity, payType);
return Result.success(CodeEnum.SUCCESS);
} }
/** /**
* 支付取消 * 支付取消
*
* @return 影响数量 * @return 影响数量
*/ */
@PostMapping("cancel") @PostMapping("cancel")

View File

@@ -1,8 +1,9 @@
package com.chaozhanggui.system.cashierservice.dao; package com.chaozhanggui.system.cashierservice.dao;
import com.chaozhanggui.system.cashierservice.entity.TbOrderPayment; import com.chaozhanggui.system.cashierservice.entity.TbOrderPayment;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;
import java.util.List;
public interface TbOrderPaymentMapper { public interface TbOrderPaymentMapper {
int deleteByPrimaryKey(Integer id); int deleteByPrimaryKey(Integer id);
@@ -18,4 +19,6 @@ public interface TbOrderPaymentMapper {
int updateByPrimaryKey(TbOrderPayment record); int updateByPrimaryKey(TbOrderPayment record);
TbOrderPayment selectByOrderId(String orderId); TbOrderPayment selectByOrderId(String orderId);
List<TbOrderPayment> selectListByOrderId(@Param("orderId") String orderId);
} }

View File

@@ -49,6 +49,10 @@ public class SignInterceptor implements HandlerInterceptor {
return true; return true;
} }
if (requestUri.contains("/notify/notifyPay")) {
return true;
}
if (requestUri.contains("/notify/cancel")) { if (requestUri.contains("/notify/cancel")) {
return true; return true;
} }

View File

@@ -10,11 +10,13 @@ import com.chaozhanggui.system.cashierservice.model.OrderDetailPO;
import com.chaozhanggui.system.cashierservice.mybatis.MPOrderDetailMapper; import com.chaozhanggui.system.cashierservice.mybatis.MPOrderDetailMapper;
import com.chaozhanggui.system.cashierservice.mybatis.MPOrderInfoMapper; import com.chaozhanggui.system.cashierservice.mybatis.MPOrderInfoMapper;
import com.chaozhanggui.system.cashierservice.mybatis.MpShopInfoMapper; import com.chaozhanggui.system.cashierservice.mybatis.MpShopInfoMapper;
import com.chaozhanggui.system.cashierservice.service.ShopPrintLogService;
import com.chaozhanggui.system.cashierservice.util.DateUtils; import com.chaozhanggui.system.cashierservice.util.DateUtils;
import com.chaozhanggui.system.cashierservice.util.FeieyunPrintUtil; import com.chaozhanggui.system.cashierservice.util.FeieyunPrintUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@@ -27,6 +29,9 @@ public class FeiPrinter extends PrinterHandler{
private final MPOrderDetailMapper mPOrderDetailMapper; private final MPOrderDetailMapper mPOrderDetailMapper;
private final TbProductSkuMapper tbProductSkuMapper; private final TbProductSkuMapper tbProductSkuMapper;
@Resource
private ShopPrintLogService shopPrintLogService;
public FeiPrinter(TbProductMapper productMapper, TbProductSkuMapper tbProductSkuMapper, TbShopUserMapper tbShopUserMapper, MPOrderInfoMapper mPOrderInfoMapper, MpShopInfoMapper mpShopInfoMapper, MpShopInfoMapper mpShopInfoMapper1, MPOrderDetailMapper mPOrderDetailMapper) { public FeiPrinter(TbProductMapper productMapper, TbProductSkuMapper tbProductSkuMapper, TbShopUserMapper tbShopUserMapper, MPOrderInfoMapper mPOrderInfoMapper, MpShopInfoMapper mpShopInfoMapper, MpShopInfoMapper mpShopInfoMapper1, MPOrderDetailMapper mPOrderDetailMapper) {
super("fePrinter", productMapper, tbProductSkuMapper, tbShopUserMapper); super("fePrinter", productMapper, tbProductSkuMapper, tbShopUserMapper);
this.mPOrderInfoMapper = mPOrderInfoMapper; this.mPOrderInfoMapper = mPOrderInfoMapper;
@@ -49,9 +54,9 @@ public class FeiPrinter extends PrinterHandler{
return; return;
} }
String remark = sku.getSpecSnap(); String remark = sku.getSpecSnap();
FeieyunPrintUtil.getPrintData(machine.getAddress(), orderInfo.getMasterId(), String[] resp = FeieyunPrintUtil.getPrintData(machine.getAddress(), orderInfo.getMasterId(),
DateUtils.getTime(new Date(orderInfo.getCreatedAt())), orderDetail.getProductName(), orderDetail.getNum(), remark); DateUtils.getTime(new Date(orderInfo.getCreatedAt())), orderDetail.getProductName(), orderDetail.getNum(), remark);
shopPrintLogService.save(machine, "新订单", resp[0], resp[1]);
} }
@Override @Override
@@ -64,7 +69,8 @@ public class FeiPrinter extends PrinterHandler{
(ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType()), (ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType()),
"0", detailList, orderInfo.getRemark(), null, null); "0", detailList, orderInfo.getRemark(), null, null);
String printType = "退款单"; String printType = "退款单";
FeieyunPrintUtil.getCashPrintData(detailPO, machine.getAddress(), printType, printType); String[] resp = FeieyunPrintUtil.getCashPrintData(detailPO, machine.getAddress(), printType, printType);
shopPrintLogService.save(machine, "退款单", resp[0], resp[1]);
} }
@Override @Override
@@ -77,7 +83,8 @@ public class FeiPrinter extends PrinterHandler{
(ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType()), (ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType()),
"0", detailList, orderInfo.getRemark(), null, null); "0", detailList, orderInfo.getRemark(), null, null);
String printType = "结算单"; String printType = "结算单";
FeieyunPrintUtil.getCashPrintData(detailPO, machine.getAddress(), printType, printType); String[] resp = FeieyunPrintUtil.getCashPrintData(detailPO, machine.getAddress(), printType, printType);
shopPrintLogService.save(machine, "结算单", resp[0], resp[1]);
} }
@Override @Override

View File

@@ -1,20 +1,22 @@
package com.chaozhanggui.system.cashierservice.rabbit.print; package com.chaozhanggui.system.cashierservice.rabbit.print;
import cn.hutool.core.util.ObjectUtil;
import com.chaozhanggui.system.cashierservice.dao.TbProductMapper; import com.chaozhanggui.system.cashierservice.dao.TbProductMapper;
import com.chaozhanggui.system.cashierservice.dao.TbProductSkuMapper; import com.chaozhanggui.system.cashierservice.dao.TbProductSkuMapper;
import com.chaozhanggui.system.cashierservice.dao.TbShopUserMapper; import com.chaozhanggui.system.cashierservice.dao.TbShopUserMapper;
import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail;
import com.chaozhanggui.system.cashierservice.entity.TbOrderInfo;
import com.chaozhanggui.system.cashierservice.entity.TbPrintMachine;
import com.chaozhanggui.system.cashierservice.entity.TbProductSkuWithBLOBs;
import com.chaozhanggui.system.cashierservice.entity.dto.CallNumPrintDTO; import com.chaozhanggui.system.cashierservice.entity.dto.CallNumPrintDTO;
import com.chaozhanggui.system.cashierservice.model.OrderDetailPO; import com.chaozhanggui.system.cashierservice.model.OrderDetailPO;
import com.chaozhanggui.system.cashierservice.mybatis.MPOrderDetailMapper; import com.chaozhanggui.system.cashierservice.mybatis.MPOrderDetailMapper;
import com.chaozhanggui.system.cashierservice.mybatis.MPOrderInfoMapper; import com.chaozhanggui.system.cashierservice.service.ShopPrintLogService;
import com.chaozhanggui.system.cashierservice.mybatis.MpShopInfoMapper;
import com.chaozhanggui.system.cashierservice.util.DateUtils; import com.chaozhanggui.system.cashierservice.util.DateUtils;
import com.chaozhanggui.system.cashierservice.util.FeieyunPrintUtil; import com.chaozhanggui.system.cashierservice.util.FeieyunPrintUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@@ -24,6 +26,8 @@ public class LocalLabelPrinter extends PrinterHandler{
private final MPOrderDetailMapper mPOrderDetailMapper; private final MPOrderDetailMapper mPOrderDetailMapper;
private final TbProductSkuMapper tbProductSkuMapper; private final TbProductSkuMapper tbProductSkuMapper;
@Resource
private ShopPrintLogService shopPrintLogService;
public LocalLabelPrinter(TbProductMapper productMapper, TbProductSkuMapper tbProductSkuMapper, TbShopUserMapper tbShopUserMapper, MPOrderDetailMapper mPOrderDetailMapper) { public LocalLabelPrinter(TbProductMapper productMapper, TbProductSkuMapper tbProductSkuMapper, TbShopUserMapper tbShopUserMapper, MPOrderDetailMapper mPOrderDetailMapper) {
super("local", productMapper, tbProductSkuMapper, tbShopUserMapper); super("local", productMapper, tbProductSkuMapper, tbShopUserMapper);
@@ -44,8 +48,9 @@ public class LocalLabelPrinter extends PrinterHandler{
return; return;
} }
for (int i = 0; i < orderDetail.getNum(); i++) { for (int i = 0; i < orderDetail.getNum(); i++) {
FeieyunPrintUtil.printLabelMsg(machine.getAddress(), orderInfo.getTableName(), orderDetail.getProductName(), String[] resp = FeieyunPrintUtil.printLabelMsg(machine.getAddress(), orderInfo.getTableName(), orderDetail.getProductName(),
1, DateUtils.getTimes(new Date(orderInfo.getCreatedAt())), sku.getSalePrice().toPlainString(), sku.getSpecSnap()); 1, DateUtils.getTimes(new Date(orderInfo.getCreatedAt())), sku.getSalePrice().toPlainString(), sku.getSpecSnap());
shopPrintLogService.save(machine, "新订单", resp[0], resp[1]);
} }
} }

View File

@@ -1,5 +1,6 @@
package com.chaozhanggui.system.cashierservice.service; package com.chaozhanggui.system.cashierservice.service;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.thread.ThreadUtil; import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
@@ -18,7 +19,10 @@ import com.chaozhanggui.system.cashierservice.entity.dto.ChoseCountDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnCartDTO; import com.chaozhanggui.system.cashierservice.entity.dto.ReturnCartDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.ShopEatTypeInfoDTO; import com.chaozhanggui.system.cashierservice.entity.dto.ShopEatTypeInfoDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.UpdateVipDTO; import com.chaozhanggui.system.cashierservice.entity.dto.UpdateVipDTO;
import com.chaozhanggui.system.cashierservice.entity.po.*; import com.chaozhanggui.system.cashierservice.entity.po.CartPo;
import com.chaozhanggui.system.cashierservice.entity.po.OrderPo;
import com.chaozhanggui.system.cashierservice.entity.po.QueryCartPo;
import com.chaozhanggui.system.cashierservice.entity.po.SkuInfoPo;
import com.chaozhanggui.system.cashierservice.entity.vo.CartVo; import com.chaozhanggui.system.cashierservice.entity.vo.CartVo;
import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.exception.NotPrintException; import com.chaozhanggui.system.cashierservice.exception.NotPrintException;
@@ -39,6 +43,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@@ -117,6 +122,9 @@ public class OrderService {
@Autowired @Autowired
private RabbitMsgUtils rabbitMsgUtils; private RabbitMsgUtils rabbitMsgUtils;
@Resource
private TbOrderPaymentMapper tbOrderPaymentMapper;
public OrderService(WxAccountUtil wxAccountUtil, MPCashierCartMapper mpCashierCartMapper, public OrderService(WxAccountUtil wxAccountUtil, MPCashierCartMapper mpCashierCartMapper,
TbShopOpenIdMapper shopOpenIdMapper, MpShopTableMapper mpShopTableMapper, TbShopOpenIdMapper shopOpenIdMapper, MpShopTableMapper mpShopTableMapper,
@@ -845,7 +853,6 @@ public class OrderService {
orderDetails.add(orderDetail); orderDetails.add(orderDetail);
// 库存预警校验 // 库存预警校验
if (TableConstant.CART_SEAT_ID.equals(cashierCart.getProductId())) { if (TableConstant.CART_SEAT_ID.equals(cashierCart.getProductId())) {
CompletableFuture.runAsync(() -> checkWarnLineAndSendMsg(tbProduct, product, Integer.valueOf(cashierCart.getShopId()), cashierCart.getNumber())); CompletableFuture.runAsync(() -> checkWarnLineAndSendMsg(tbProduct, product, Integer.valueOf(cashierCart.getShopId()), cashierCart.getNumber()));
@@ -1850,4 +1857,36 @@ public class OrderService {
.eq(TbOrderInfo::getStatus, "paying") .eq(TbOrderInfo::getStatus, "paying")
.set(TbOrderInfo::getStatus, "unpaid")); .set(TbOrderInfo::getStatus, "unpaid"));
} }
public TbOrderInfo selectByPayOrderNo(String payOrderNo) {
return mPOrderInfoMapper.selectOne(new LambdaQueryWrapper<TbOrderInfo>()
.eq(TbOrderInfo::getPayOrderNo, payOrderNo));
}
@Transactional(rollbackFor = Exception.class)
public void payCallbackCloseOrder(TbOrderInfo entity, String payType) {
mPOrderInfoMapper.update(null, new LambdaUpdateWrapper<TbOrderInfo>()
.eq(TbOrderInfo::getId, entity.getId())
.eq(TbOrderInfo::getStatus, "paying")
.set(TbOrderInfo::getStatus, "closed")
.set(TbOrderInfo::getPaidTime, entity.getPaidTime())
.set(TbOrderInfo::getUpdatedAt, System.currentTimeMillis())
);
List<TbOrderPayment> list = tbOrderPaymentMapper.selectListByOrderId(Convert.toStr(entity.getId()));
for (TbOrderPayment payment : list) {
payment.setTradeNumber(entity.getPayOrderNo());
payment.setUpdatedAt(System.currentTimeMillis());
if ("WECHAT".equals(payType)) {
payment.setPayName("微信支付");
payment.setPayType("wechatPay");
} else if ("ALIPAY".equals(payType)) {
payment.setPayName("支付宝支付");
payment.setPayType("aliPay");
} else {
payment.setPayName(payType);
payment.setPayType(payType);
}
tbOrderPaymentMapper.updateByPrimaryKey(payment);
}
}
} }

View File

@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -328,12 +329,12 @@ public class PayService {
} else { } else {
String status = ObjectUtil.isNotEmpty(object.getJSONObject("data")) ? object.getJSONObject("data").getString("status") : null; String status = ObjectUtil.isNotEmpty(object.getJSONObject("data")) ? object.getJSONObject("data").getString("status") : null;
if (ObjectUtil.isNotNull(status) && "7".equals(status)) { if (ObjectUtil.isNotNull(status) && "7".equals(status)) {
payment.setTradeNumber(object.getJSONObject("data").get("orderNumber").toString());
log.info("支付中4:{}", JSON.toJSONString(payment));
orderInfo.setStatus("paying"); orderInfo.setStatus("paying");
orderInfo.setPayOrderNo(payment.getTradeNumber()); orderInfo.setPayOrderNo(payment.getTradeNumber());
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo); tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
payment.setTradeNumber(object.getJSONObject("data").get("orderNumber").toString());
payment.setUpdatedAt(System.currentTimeMillis()); payment.setUpdatedAt(System.currentTimeMillis());
tbOrderPaymentMapper.updateByPrimaryKeySelective(payment); tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
@@ -437,11 +438,13 @@ public class PayService {
return Result.success(CodeEnum.SUCCESS, mainScanResp); return Result.success(CodeEnum.SUCCESS, mainScanResp);
} else if ("TRADE_AWAIT".equals(mainScanResp.getState())) { } else if ("TRADE_AWAIT".equals(mainScanResp.getState())) {
payment.setTradeNumber(mainScanResp.getPayOrderId());
log.info("支付中2:{}", JSON.toJSONString(payment));
orderInfo.setStatus("paying"); orderInfo.setStatus("paying");
orderInfo.setPayOrderNo(payment.getTradeNumber()); orderInfo.setPayOrderNo(payment.getTradeNumber());
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo); tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
payment.setTradeNumber(mainScanResp.getPayOrderId());
payment.setUpdatedAt(System.currentTimeMillis()); payment.setUpdatedAt(System.currentTimeMillis());
tbOrderPaymentMapper.updateByPrimaryKeySelective(payment); tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
// 修改台桌状态 // 修改台桌状态
@@ -1923,11 +1926,12 @@ public class PayService {
return Result.success(CodeEnum.SUCCESS, mapper.readTree(scanpayResp.getPayInfo())); return Result.success(CodeEnum.SUCCESS, mapper.readTree(scanpayResp.getPayInfo()));
} else if ("TRADE_AWAIT".equals(scanpayResp.getState())) { } else if ("TRADE_AWAIT".equals(scanpayResp.getState())) {
payment.setTradeNumber(scanpayResp.getPayOrderId());
log.info("支付中3:{}", JSON.toJSONString(payment));
orderInfo.setStatus("paying"); orderInfo.setStatus("paying");
orderInfo.setPayOrderNo(payment.getTradeNumber()); orderInfo.setPayOrderNo(payment.getTradeNumber());
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo); tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
payment.setTradeNumber(scanpayResp.getPayOrderId());
payment.setUpdatedAt(System.currentTimeMillis()); payment.setUpdatedAt(System.currentTimeMillis());
tbOrderPaymentMapper.updateByPrimaryKeySelective(payment); tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
@@ -2067,11 +2071,12 @@ public class PayService {
return Result.success(CodeEnum.SUCCESS, mapper.readTree(scanpayResp.getPayInfo())); return Result.success(CodeEnum.SUCCESS, mapper.readTree(scanpayResp.getPayInfo()));
} else if ("TRADE_AWAIT".equals(scanpayResp.getState())) { } else if ("TRADE_AWAIT".equals(scanpayResp.getState())) {
payment.setTradeNumber(scanpayResp.getPayOrderId());
log.info("支付中1:{}", JSON.toJSONString(payment));
orderInfo.setStatus("paying"); orderInfo.setStatus("paying");
orderInfo.setPayOrderNo(payment.getTradeNumber()); orderInfo.setPayOrderNo(payment.getTradeNumber());
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo); tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
payment.setTradeNumber(scanpayResp.getPayOrderId());
payment.setUpdatedAt(System.currentTimeMillis()); payment.setUpdatedAt(System.currentTimeMillis());
tbOrderPaymentMapper.updateByPrimaryKeySelective(payment); tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);

View File

@@ -13,6 +13,7 @@ import com.chaozhanggui.system.cashierservice.entity.TbPrintMachine;
import com.chaozhanggui.system.cashierservice.entity.TbPrintMachineLog; import com.chaozhanggui.system.cashierservice.entity.TbPrintMachineLog;
import com.chaozhanggui.system.cashierservice.entity.dto.ShopPrintLogDTO; import com.chaozhanggui.system.cashierservice.entity.dto.ShopPrintLogDTO;
import com.chaozhanggui.system.cashierservice.service.ShopPrintLogService; import com.chaozhanggui.system.cashierservice.service.ShopPrintLogService;
import com.chaozhanggui.system.cashierservice.util.FeieyunPrintUtil;
import com.chaozhanggui.system.cashierservice.util.PrinterUtils; import com.chaozhanggui.system.cashierservice.util.PrinterUtils;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
@@ -94,6 +95,7 @@ public class ShopPrintLogServiceImpl extends ServiceImpl<TbPrintMachineLogMapper
int failFlag = 0; int failFlag = 0;
String respCode = "0"; String respCode = "0";
String respMsg = "打印中"; String respMsg = "打印中";
Map<Integer, String> yxxStatusMap = MapUtil.builder(0, "离线(设备上线后自动补打)").put(1, "在线").put(2, "获取失败").put(3, "未激活").put(4, "设备已禁用").build(); Map<Integer, String> yxxStatusMap = MapUtil.builder(0, "离线(设备上线后自动补打)").put(1, "在线").put(2, "获取失败").put(3, "未激活").put(4, "设备已禁用").build();
// 云想印 // 云想印
if ("yxyPrinter".equals(config.getContentType())) { if ("yxyPrinter".equals(config.getContentType())) {
@@ -112,10 +114,24 @@ public class ShopPrintLogServiceImpl extends ServiceImpl<TbPrintMachineLogMapper
respMsg = status + "_" + yxxStatusMap.get(status); respMsg = status + "_" + yxxStatusMap.get(status);
} }
if(code == 0){
String taskId = resp.getJSONObject("data").getStr("orderId"); String taskId = resp.getJSONObject("data").getStr("orderId");
entity.setTaskId(taskId); entity.setTaskId(taskId);
} else { }
// 飞鹅云打印机暂时没有适配先return不做打印记录 // 飞鹅云打印机暂时没有适配先return不做打印记录
}else if ("fePrinter".equals(config.getContentType())) {
cn.hutool.json.JSONObject resp = JSONUtil.parseObj(respJson);
int ret = resp.getInt("ret");
if (ret != 0) {
failFlag = 1;
respCode = ret + "";
respMsg = resp.getStr("msg");
}else{
String printOrderId = resp.getStr("data");
entity.setTaskId(printOrderId);
}
} else {
// 其他打印机暂时没有适配先return不做打印记录
return; return;
} }
entity.setBizType(bizType); entity.setBizType(bizType);
@@ -168,6 +184,24 @@ public class ShopPrintLogServiceImpl extends ServiceImpl<TbPrintMachineLogMapper
} }
super.updateById(entity); super.updateById(entity);
} }
// 飞鹅云打印机
}else if("fePrinter".equals(config.getContentType())){
ThreadUtil.safeSleep(1000*3);
Boolean success = FeieyunPrintUtil.checkPrintStatus(entity.getTaskId());
if(success == null){
entity.setFailFlag(1);
entity.setRespMsg("打印失败,未知错误");
}else if(success) {
entity.setFailFlag(0);
entity.setPrintTime(new Date());
entity.setRespMsg("打印成功");
}else {
String msg = FeieyunPrintUtil.checkOnline(entity.getAddress());
entity.setFailFlag(1);
entity.setPrintTime(null);
entity.setRespMsg(StrUtil.concat(true,"打印失败,", "_", msg));
}
super.updateById(entity);
} }
} }

View File

@@ -1,7 +1,11 @@
package com.chaozhanggui.system.cashierservice.util; package com.chaozhanggui.system.cashierservice.util;
import cn.hutool.core.text.UnicodeUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.chaozhanggui.system.cashierservice.model.OrderDetailPO; import com.chaozhanggui.system.cashierservice.model.OrderDetailPO;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
@@ -16,9 +20,7 @@ import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.*;
import java.util.Date;
import java.util.List;
public class FeieyunPrintUtil { public class FeieyunPrintUtil {
@@ -29,8 +31,7 @@ public class FeieyunPrintUtil {
public static final String SN = "960238952";//*必填*打印机编号必须要在管理后台里添加打印机或调用API接口添加之后才能调用API public static final String SN = "960238952";//*必填*打印机编号必须要在管理后台里添加打印机或调用API接口添加之后才能调用API
public static String[] printLabelMsg(String sn, String masterId, String productName, Integer number, String date, String money, String remark) {
public static String printLabelMsg(String sn,String masterId,String productName,Integer number,String date,String money,String remark){
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
sb.append("<DIRECTION>1</DIRECTION>"); sb.append("<DIRECTION>1</DIRECTION>");
@@ -75,8 +76,7 @@ public class FeieyunPrintUtil {
CloseableHttpResponse response = null; CloseableHttpResponse response = null;
String result = null; String result = null;
try try {
{
post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8")); post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
response = httpClient.execute(post); response = httpClient.execute(post);
int statecode = response.getStatusLine().getStatusCode(); int statecode = response.getStatusLine().getStatusCode();
@@ -87,12 +87,9 @@ public class FeieyunPrintUtil {
result = EntityUtils.toString(httpentity); result = EntityUtils.toString(httpentity);
} }
} }
} } catch (Exception e) {
catch (Exception e)
{
e.printStackTrace(); e.printStackTrace();
} } finally {
finally{
try { try {
if (response != null) { if (response != null) {
response.close(); response.close();
@@ -111,13 +108,11 @@ public class FeieyunPrintUtil {
e.printStackTrace(); e.printStackTrace();
} }
} }
return result; return new String[]{content, result};
} }
public static String buildPrintContent(String pickupNumber, String date, String productName, Integer number, String remark) {
public static String getPrintData(String sn,String pickupNumber,String date,String productName,Integer number,String remark) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("<CB>" + pickupNumber + "</CB><BR><BR>"); builder.append("<CB>" + pickupNumber + "</CB><BR><BR>");
@@ -134,8 +129,11 @@ public class FeieyunPrintUtil {
builder.append("<BR><BR><BR><BR><BR><BR>"); builder.append("<BR><BR><BR><BR><BR><BR>");
builder.append("<CUT>"); builder.append("<CUT>");
return builder.toString();
}
String content=builder.toString(); public static String[] getPrintData(String sn, String pickupNumber, String date, String productName, Integer number, String remark) {
String content = buildPrintContent(pickupNumber, date, productName, number, remark);
System.out.println("content:".concat(content)); System.out.println("content:".concat(content));
@@ -162,8 +160,7 @@ public class FeieyunPrintUtil {
CloseableHttpResponse response = null; CloseableHttpResponse response = null;
String result = null; String result = null;
try try {
{
post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8")); post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
response = httpClient.execute(post); response = httpClient.execute(post);
int statecode = response.getStatusLine().getStatusCode(); int statecode = response.getStatusLine().getStatusCode();
@@ -175,12 +172,9 @@ public class FeieyunPrintUtil {
System.out.println("result:".concat(result)); System.out.println("result:".concat(result));
} }
} }
} } catch (Exception e) {
catch (Exception e)
{
e.printStackTrace(); e.printStackTrace();
} } finally {
finally{
try { try {
if (response != null) { if (response != null) {
response.close(); response.close();
@@ -199,18 +193,12 @@ public class FeieyunPrintUtil {
e.printStackTrace(); e.printStackTrace();
} }
} }
return result; return new String[]{content, result};
} }
public static String[] getCashPrintData(OrderDetailPO detailPO, String sn, String type, String orderType) {
public static String getCashPrintData(OrderDetailPO detailPO,String sn, String type, String orderType){
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("<CB>" + detailPO.getMerchantName() + "</CB><BR><BR>"); sb.append("<CB>" + detailPO.getMerchantName() + "</CB><BR><BR>");
sb.append("<C><BOLD>" + type + "" + detailPO.getMasterId() + "】</BOLD></C><BR><BR>"); sb.append("<C><BOLD>" + type + "" + detailPO.getMasterId() + "】</BOLD></C><BR><BR>");
@@ -265,7 +253,6 @@ public class FeieyunPrintUtil {
} }
sb.append("打印时间:" + DateUtils.getTime(new Date()) + "<BR>"); sb.append("打印时间:" + DateUtils.getTime(new Date()) + "<BR>");
sb.append("<CUT>"); sb.append("<CUT>");
@@ -295,8 +282,7 @@ public class FeieyunPrintUtil {
CloseableHttpResponse response = null; CloseableHttpResponse response = null;
String result = null; String result = null;
try try {
{
post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8")); post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
response = httpClient.execute(post); response = httpClient.execute(post);
int statecode = response.getStatusLine().getStatusCode(); int statecode = response.getStatusLine().getStatusCode();
@@ -307,12 +293,9 @@ public class FeieyunPrintUtil {
result = EntityUtils.toString(httpentity); result = EntityUtils.toString(httpentity);
} }
} }
} } catch (Exception e) {
catch (Exception e)
{
e.printStackTrace(); e.printStackTrace();
} } finally {
finally{
try { try {
if (response != null) { if (response != null) {
response.close(); response.close();
@@ -331,13 +314,11 @@ public class FeieyunPrintUtil {
e.printStackTrace(); e.printStackTrace();
} }
} }
return result; return new String[]{content, result};
} }
public static int getProducrName(String str) { public static int getProducrName(String str) {
int count = 0; int count = 0;
int digitCount = 0; int digitCount = 0;
@@ -358,12 +339,122 @@ public class FeieyunPrintUtil {
return s; return s;
} }
/**
* 检查飞鹅打印机是否在线
* @param sn 设备编号
* @return 在线,工作状态正常。/离线。/未知错误
*/
public static String checkOnline(String sn){
String STIME = String.valueOf(System.currentTimeMillis() / 1000);
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("user", USER);
paramMap.put("stime", STIME);
paramMap.put("sig", signature(USER, UKEY, STIME));
paramMap.put("apiname", "Open_queryPrinterStatus");
paramMap.put("sn", sn);
String msg;
try {
String resp = HttpUtil.post(URL, paramMap, 1000 * 5);
//成功 开机 {"msg":"ok","ret":0,"data":"在线,工作状态正常。","serverExecutedTime":4}
//成功 离线 {"msg":"ok","ret":0,"data":"离线。","serverExecutedTime":7}
JSONObject json = JSONUtil.parseObj(UnicodeUtil.toString(resp));
msg = json.getStr("data");
}catch (Exception e){
msg = "未知错误";
}
return msg;
}
/**
* 检查飞鹅打印机打印任务是否已打印
* @param printOrderId 打印订单编号
* @return null-未知错误true-已打印false-未打印
*/
public static Boolean checkPrintStatus(String printOrderId){
String STIME = String.valueOf(System.currentTimeMillis() / 1000);
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("user", USER);
paramMap.put("stime", STIME);
paramMap.put("sig", signature(USER, UKEY, STIME));
paramMap.put("apiname", "Open_queryOrderState");
paramMap.put("orderid", printOrderId);
Boolean ret;
try {
String resp = HttpUtil.post(URL, paramMap, 1000 * 5);
//成功 {"msg":"ok","ret":0,"data":true,"serverExecutedTime":4}
//失败 {"msg":"ok","ret":0,"data":false,"serverExecutedTime":4}
JSONObject json = JSONUtil.parseObj(UnicodeUtil.toString(resp));
ret = json.getBool("data");
}catch (Exception e){
ret = null;
}
return ret;
}
public static void main(String[] args) { public static void main(String[] args) {
//testPrint();
// OrderDetailPO detailPO=new OrderDetailPO("牛叉闪闪",null,null,"DD20240312142156962",null,null,null,null,null,null,null,null); //testPrint2();
// getCashPrintData(detailPO,"922690786","结算单",null); testPrint3();
} }
public static void testPrint(){
String STIME = String.valueOf(System.currentTimeMillis() / 1000);
String content = buildPrintContent("123456789", "2024-10-10 18:11:11", "澳洲大龙虾", 1, "一只吃爽爽");
Map<String, Object> paramMap = new HashMap<>();
// 参考文档https://help.feieyun.com/home/doc/zh;nav=0-2
paramMap.put("user", USER);
paramMap.put("stime", STIME);
paramMap.put("sig", signature("chaozhanggui2022@163.com", "UfWkhXxSkeSSscsU", STIME));
paramMap.put("apiname", "Open_printMsg");
paramMap.put("sn", "922690786");
paramMap.put("content", content);
paramMap.put("times", 1);
//paramMap.put("debug", "1");
String resp = HttpUtil.post(URL, paramMap, 1000 * 5);
//成功 开机和关机都会响应成功,只是打印任务已正确下发,不代表打印成功
//{"msg":"ok","ret":0,"data":"922690786_20241010174146_2050070451","serverExecutedTime":4} data是打印订单id
//失败1 {"msg":"参数错误 : 该帐号未注册.","ret":-2,"data":null,"serverExecutedTime":37}
System.out.println(UnicodeUtil.toString(resp));
}
/**
* 查询打印机状态
*/
public static void testPrint2(){
String STIME = String.valueOf(System.currentTimeMillis() / 1000);
String content = buildPrintContent("123456789", "2024-10-10 18:11:11", "澳洲大龙虾", 1, "一只吃爽爽");
Map<String, Object> paramMap = new HashMap<>();
// 参考文档https://help.feieyun.com/home/doc/zh;nav=0-2
paramMap.put("user", USER);
paramMap.put("stime", STIME);
paramMap.put("sig", signature("chaozhanggui2022@163.com", "UfWkhXxSkeSSscsU", STIME));
paramMap.put("apiname", "Open_queryPrinterStatus");
paramMap.put("sn", "922690786");
//paramMap.put("debug", "1");
String resp = HttpUtil.post(URL, paramMap, 1000 * 5);
//成功 开机 {"msg":"ok","ret":0,"data":"在线,工作状态正常。","serverExecutedTime":4}
//成功 离线 {"msg":"ok","ret":0,"data":"离线。","serverExecutedTime":7}
System.out.println(UnicodeUtil.toString(resp));
}
/**
* 查询打印任务是否打印成功
*/
public static void testPrint3(){
String STIME = String.valueOf(System.currentTimeMillis() / 1000);
String content = buildPrintContent("123456789", "2024-10-10 18:11:11", "澳洲大龙虾", 1, "一只吃爽爽");
Map<String, Object> paramMap = new HashMap<>();
// 参考文档https://help.feieyun.com/home/doc/zh;nav=0-2
paramMap.put("user", USER);
paramMap.put("stime", STIME);
paramMap.put("sig", signature("chaozhanggui2022@163.com", "UfWkhXxSkeSSscsU", STIME));
paramMap.put("apiname", "Open_queryOrderState");
paramMap.put("orderid", "922690786_20241010175946_1576957351x");
//paramMap.put("debug", "1");
String resp = HttpUtil.post(URL, paramMap, 1000 * 5);
//成功 {"msg":"ok","ret":0,"data":true,"serverExecutedTime":4}
//失败 {"msg":"ok","ret":0,"data":false,"serverExecutedTime":4}
System.out.println(UnicodeUtil.toString(resp));
}
} }

View File

@@ -260,4 +260,8 @@
<select id="selectByOrderId" resultMap="BaseResultMap"> <select id="selectByOrderId" resultMap="BaseResultMap">
select * from tb_order_payment where order_id=#{orderId} select * from tb_order_payment where order_id=#{orderId}
</select> </select>
<select id="selectListByOrderId" resultType="com.chaozhanggui.system.cashierservice.entity.TbOrderPayment">
select * from tb_order_payment where order_id = #{orderId}
</select>
</mapper> </mapper>