This commit is contained in:
韩鹏辉
2024-03-21 10:17:54 +08:00
parent c7e46f3504
commit b96a251fd8
296 changed files with 34548 additions and 0 deletions

View File

@@ -0,0 +1,273 @@
package com.chaozhanggui.system.cashierservice.rabbit;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
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.util.DateUtils;
import com.chaozhanggui.system.cashierservice.util.TokenUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.*;
@Slf4j
@Component
@RabbitListener(queues = {RabbitConstants.CART_ORDER_COLLECT_QUEUE_PUT})
@Service
public class DutyConsumer {
@Autowired
private TbTokenMapper tbTokenMapper;
@Autowired
private TbOrderDetailMapper orderDetailMapper;
@Autowired
private TbOrderInfoMapper orderInfoMapper;
@Autowired
private ShopUserDutyDetailMapper shopUserDutyDetailMapper;
@Autowired
private ShopUserDutyMapper shopUserDutyMapper;
@Autowired
private TbShopInfoMapper shopInfoMapper;
@Autowired
private ShopUserDutyPayMapper shopUserDutyPayMapper;
@RabbitHandler
public void listener(String message) {
try {
System.out.println("数据落地开始");
JSONObject jsonObject = JSON.parseObject(message);
String token = jsonObject.getString("token");
String type = jsonObject.getString("type");
TbToken tbToken = tbTokenMapper.selectByToken(token);
if (type.equals("return") || type.equals("create")) {
if (Objects.isNull(tbToken)) {
throw new MsgException("当前用户不存在");
}
Integer tokenId = tbToken.getId();
Integer orderId = jsonObject.getInteger("orderId");
JSONObject tokenJson = TokenUtil.parseParamFromToken(tbToken.getToken());
Integer shopId = tokenJson.getInteger("shopId");
Integer userId = tokenJson.getInteger("staffId");
String loginName = tokenJson.getString("loginName");
TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId);
if (Objects.isNull(orderInfo) && orderId > 0) {
throw new MsgException("订单不存在");
}
List<TbOrderDetail> list = orderDetailMapper.selectAllByOrderId(orderId);
ShopUserDuty shopUserDuty = shopUserDutyMapper.selectByTokenId(tokenId);
BigDecimal cashAmount = BigDecimal.ZERO;
if (orderInfo.getPayType().equals("cash")) {
cashAmount = orderInfo.getPayAmount();
}
if (type.equals("create")) {
if (Objects.isNull(shopUserDuty)) {
shopUserDuty = new ShopUserDuty(userId, tbToken.getCreateTime(), 1, orderInfo.getOrderAmount(), loginName, "0",
orderInfo.getOrderAmount(), shopId, BigDecimal.ZERO, cashAmount, BigDecimal.ZERO, "");
shopUserDuty.setTokenId(tokenId);
shopUserDuty.setReturnAmount(BigDecimal.ZERO);
shopUserDuty.setTradeDay(DateUtils.getDay());
shopUserDutyMapper.insert(shopUserDuty);
List<ShopUserDutyDetail> detaiList = new ArrayList<>();
for (TbOrderDetail orderDetail : list) {
ShopUserDutyDetail shopUserDutyDetail = new ShopUserDutyDetail();
shopUserDutyDetail.setDutyId(shopUserDuty.getId());
shopUserDutyDetail.setAmount(orderDetail.getPriceAmount());
shopUserDutyDetail.setNum(orderDetail.getNum());
shopUserDutyDetail.setSkuId(orderDetail.getProductSkuId());
shopUserDutyDetail.setSkuName(orderDetail.getProductSkuName());
shopUserDutyDetail.setProductId(orderDetail.getProductId());
shopUserDutyDetail.setProductName(orderDetail.getProductName());
detaiList.add(shopUserDutyDetail);
}
if (detaiList.size() > 0) {
shopUserDutyDetailMapper.batchInsert(detaiList);
}
} else {
shopUserDuty.setAmount(shopUserDuty.getAmount().add(orderInfo.getPayAmount()));
shopUserDuty.setCashAmount(shopUserDuty.getCashAmount().add(cashAmount));
shopUserDuty.setIncomeAmount(shopUserDuty.getIncomeAmount().add(orderInfo.getPayAmount()));
shopUserDuty.setOrderNum(shopUserDuty.getOrderNum() + 1);
shopUserDutyMapper.updateByPrimaryKeySelective(shopUserDuty);
List<Integer> skuIds = new ArrayList<>();
for (TbOrderDetail orderDetail : list) {
skuIds.add(orderDetail.getProductSkuId());
}
List<ShopUserDutyDetail> details = shopUserDutyDetailMapper.selectByDuctId(shopUserDuty.getId(), skuIds);
Map<Integer, ShopUserDutyDetail> map = new HashMap<>();
for (ShopUserDutyDetail shopUserDutyDetail : details) {
map.put(shopUserDutyDetail.getSkuId(), shopUserDutyDetail);
}
List<ShopUserDutyDetail> detaiList = new ArrayList<>();
for (TbOrderDetail orderDetail : list) {
if (map.containsKey(orderDetail.getProductSkuId())) {
ShopUserDutyDetail shopUserDutyDetail = map.get(orderDetail.getProductSkuId());
shopUserDutyDetail.setNum(shopUserDutyDetail.getNum() + orderDetail.getNum());
shopUserDutyDetail.setAmount(shopUserDutyDetail.getAmount().add(orderDetail.getPriceAmount().add(orderDetail.getPackAmount())));
shopUserDutyDetailMapper.updateByPrimaryKeySelective(shopUserDutyDetail);
} else {
ShopUserDutyDetail shopUserDutyDetail = new ShopUserDutyDetail();
shopUserDutyDetail.setDutyId(shopUserDuty.getId());
shopUserDutyDetail.setAmount(orderDetail.getPriceAmount());
shopUserDutyDetail.setNum(orderDetail.getNum());
shopUserDutyDetail.setSkuId(orderDetail.getProductSkuId());
shopUserDutyDetail.setSkuName(orderDetail.getProductSkuName());
shopUserDutyDetail.setProductId(orderDetail.getProductId());
shopUserDutyDetail.setProductName(orderDetail.getProductName());
detaiList.add(shopUserDutyDetail);
}
}
if (detaiList.size() > 0) {
shopUserDutyDetailMapper.batchInsert(detaiList);
}
}
ShopUserDutyPay shopUserDutyPay = shopUserDutyPayMapper.selectByDuctIdAndType(shopUserDuty.getId(),orderInfo.getPayType());
if (Objects.nonNull(shopUserDutyPay)){
shopUserDutyPay.setAmount(orderInfo.getOrderAmount().add(shopUserDutyPay.getAmount()));
shopUserDutyPayMapper.updateByPrimaryKeySelective(shopUserDutyPay);
}else {
shopUserDutyPay=new ShopUserDutyPay();
shopUserDutyPay.setDutyId(shopUserDuty.getId());
shopUserDutyPay.setType(orderInfo.getPayType());
shopUserDutyPay.setAmount(orderInfo.getOrderAmount());
shopUserDutyPayMapper.insert(shopUserDutyPay);
}
} else if (type.equals("return")) {
BigDecimal amount = jsonObject.getBigDecimal("amount");
if (Objects.isNull(shopUserDuty)) {
shopUserDuty = new ShopUserDuty(userId, tbToken.getCreateTime(), 1, BigDecimal.ZERO, loginName, "0",
BigDecimal.ZERO, shopId, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, "");
shopUserDuty.setReturnAmount(amount);
shopUserDuty.setTokenId(tokenId);
shopUserDuty.setTradeDay(DateUtils.getDay());
shopUserDutyMapper.insert(shopUserDuty);
} else {
shopUserDuty.setReturnAmount(shopUserDuty.getReturnAmount().add(amount));
shopUserDutyMapper.updateByPrimaryKeySelective(shopUserDuty);
}
}
} else if (type.equals("wxcreate")) {
String day = DateUtils.getDay();
Integer orderId = jsonObject.getInteger("orderId");
TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId);
if (Objects.isNull(orderInfo)) {
throw new MsgException("订单不存在");
}
List<TbOrderDetail> list = orderDetailMapper.selectAllByOrderId(orderId);
BigDecimal cashAmount = BigDecimal.ZERO;
if (orderInfo.getPayType().equals("cash")) {
cashAmount = orderInfo.getPayAmount();
}
ShopUserDuty shopUserDuty = shopUserDutyMapper.selectByTokenIdAndTradeDay(0, day, orderInfo.getShopId());
TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getShopId()));
if (Objects.isNull(shopUserDuty)) {
shopUserDuty = new ShopUserDuty(Integer.valueOf(orderInfo.getShopId()), new Date(), 1, orderInfo.getOrderAmount(), "", "0",
orderInfo.getOrderAmount(), Integer.valueOf(orderInfo.getShopId()), BigDecimal.ZERO, cashAmount, BigDecimal.ZERO, "");
shopUserDuty.setTokenId(0);
shopUserDuty.setType("wx");
if (Objects.nonNull(shopInfo)) {
shopUserDuty.setUserName(shopInfo.getShopName());
}
shopUserDuty.setTradeDay(DateUtils.getDay());
shopUserDutyMapper.insert(shopUserDuty);
List<ShopUserDutyDetail> detaiList = new ArrayList<>();
for (TbOrderDetail orderDetail : list) {
ShopUserDutyDetail shopUserDutyDetail = new ShopUserDutyDetail();
shopUserDutyDetail.setDutyId(shopUserDuty.getId());
shopUserDutyDetail.setAmount(orderDetail.getPriceAmount());
shopUserDutyDetail.setNum(orderDetail.getNum());
shopUserDutyDetail.setSkuId(orderDetail.getProductSkuId());
shopUserDutyDetail.setSkuName(orderDetail.getProductSkuName());
shopUserDutyDetail.setProductId(orderDetail.getProductId());
shopUserDutyDetail.setProductName(orderDetail.getProductName());
detaiList.add(shopUserDutyDetail);
}
if (detaiList.size() > 0) {
shopUserDutyDetailMapper.batchInsert(detaiList);
}
} else {
shopUserDuty.setAmount(shopUserDuty.getAmount().add(orderInfo.getPayAmount()));
shopUserDuty.setCashAmount(shopUserDuty.getCashAmount().add(cashAmount));
shopUserDuty.setIncomeAmount(shopUserDuty.getIncomeAmount().add(orderInfo.getPayAmount()));
shopUserDuty.setOrderNum(shopUserDuty.getOrderNum() + 1);
shopUserDutyMapper.updateByPrimaryKeySelective(shopUserDuty);
List<Integer> skuIds = new ArrayList<>();
for (TbOrderDetail orderDetail : list) {
skuIds.add(orderDetail.getProductSkuId());
}
List<ShopUserDutyDetail> details = shopUserDutyDetailMapper.selectByDuctId(shopUserDuty.getId(), skuIds);
Map<Integer, ShopUserDutyDetail> map = new HashMap<>();
for (ShopUserDutyDetail shopUserDutyDetail : details) {
map.put(shopUserDutyDetail.getSkuId(), shopUserDutyDetail);
}
List<ShopUserDutyDetail> detaiList = new ArrayList<>();
for (TbOrderDetail orderDetail : list) {
if (map.containsKey(orderDetail.getProductSkuId())) {
ShopUserDutyDetail shopUserDutyDetail = map.get(orderDetail.getProductSkuId());
shopUserDutyDetail.setNum(shopUserDutyDetail.getNum() + orderDetail.getNum());
shopUserDutyDetail.setAmount(shopUserDutyDetail.getAmount().add(orderDetail.getPriceAmount().add(orderDetail.getPackAmount())));
shopUserDutyDetailMapper.updateByPrimaryKeySelective(shopUserDutyDetail);
} else {
ShopUserDutyDetail shopUserDutyDetail = new ShopUserDutyDetail();
shopUserDutyDetail.setDutyId(shopUserDuty.getId());
shopUserDutyDetail.setAmount(orderDetail.getPriceAmount());
shopUserDutyDetail.setNum(orderDetail.getNum());
shopUserDutyDetail.setSkuId(orderDetail.getProductSkuId());
shopUserDutyDetail.setSkuName(orderDetail.getProductSkuName());
shopUserDutyDetail.setProductId(orderDetail.getProductId());
shopUserDutyDetail.setProductName(orderDetail.getProductName());
detaiList.add(shopUserDutyDetail);
}
}
if (detaiList.size() > 0) {
shopUserDutyDetailMapper.batchInsert(detaiList);
}
}
ShopUserDutyPay shopUserDutyPay = shopUserDutyPayMapper.selectByDuctIdAndType(shopUserDuty.getId(),orderInfo.getPayType());
if (Objects.nonNull(shopUserDutyPay)){
shopUserDutyPay.setAmount(orderInfo.getOrderAmount().add(shopUserDutyPay.getAmount()));
shopUserDutyPayMapper.updateByPrimaryKeySelective(shopUserDutyPay);
}else {
shopUserDutyPay=new ShopUserDutyPay();
shopUserDutyPay.setDutyId(shopUserDuty.getId());
shopUserDutyPay.setType(orderInfo.getPayType());
shopUserDutyPay.setAmount(orderInfo.getOrderAmount());
shopUserDutyPayMapper.insert(shopUserDutyPay);
}
}else{
if (type.equals("close")){
shopUserDutyMapper.updateStatusByTokenId(tbToken.getId());
}
}
} catch (Exception e) {
e.getMessage();
}
}
public static void main(String[] args) {
String sss = "{\"data\":{\"orderId\":\"1\",\"payAmount\":3.60,\"returnDetails\":[{\"cetyId\":\"2\",\"id\":\"1\",\"number\":\"5\"},{\"cetyId\":\"3\",\"id\":\"2\",\"number\":\"9\"}]},\"type\":\"return\",\"token\":\"黑龙江省王大秃子屯\"}";
JSONObject jsonObject = JSON.parseObject(sss);
JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("returnDetails");
for (int i = 0;i<jsonArray.size();i++){
JSONObject object = jsonArray.getJSONObject(i);
System.out.println(object.getInteger("cetyId"));
System.out.println(object.getInteger("number"));
}
System.out.println(jsonArray);
System.out.println(jsonObject.getJSONObject("data").getBigDecimal("payAmount"));
}
}

View File

@@ -0,0 +1,332 @@
package com.chaozhanggui.system.cashierservice.rabbit;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.model.CategoryInfo;
import com.chaozhanggui.system.cashierservice.model.OrderDetailPO;
import com.chaozhanggui.system.cashierservice.util.DateUtils;
import com.chaozhanggui.system.cashierservice.util.FeieyunPrintUtil;
import com.chaozhanggui.system.cashierservice.util.JSONUtil;
import com.chaozhanggui.system.cashierservice.util.PrinterUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.annotation.RabbitListeners;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Slf4j
@Component
@RabbitListener(queues = {RabbitConstants.PRINT_MECHINE_COLLECT_QUEUE_PUT})
@Service
public class PrintMechineConsumer {
@Autowired
TbShopUserMapper tbShopUserMapper;
@Autowired
private TbOrderInfoMapper tbOrderInfoMapper;
@Autowired
private TbPrintMachineMapper tbPrintMachineMapper;
@Autowired
private TbCashierCartMapper tbCashierCartMapper;
@Autowired
private TbProductSkuMapper tbProductSkuMapper;
@Autowired
private TbShopInfoMapper tbShopInfoMapper;
@Autowired
private TbProductMapper tbProductMapper;
@Autowired
private TbOrderDetailMapper tbOrderDetailMapper;
@RabbitHandler
public void listener(String message) {
String orderId = message;
try {
Thread.sleep(1000L);
TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId));
if (ObjectUtil.isEmpty(orderInfo)) {
log.error("没有对应的订单信息");
return;
}
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getShopId()));
if (ObjectUtil.isEmpty(shopInfo)) {
log.error("店铺信息不存在");
return;
}
List<TbPrintMachineWithBLOBs> list = tbPrintMachineMapper.selectByShopId(orderInfo.getShopId());
if (ObjectUtil.isEmpty(list) || list.size() <= 0) {
log.error("此店铺没有对应的打印机设备");
return;
}
list.parallelStream().forEach(it->{
if (!"network".equals(it.getConnectionType())) {
log.error("非网络打印机:{},{}",it.getAddress(),it.getConnectionType());
return;
}
if (!"1".equals(it.getStatus().toString())) {
log.error("打印机状态异常:{},{}",it.getAddress(),it.getStatus());
return;
}
JSONObject config = JSONObject.parseObject(it.getConfig());
String model = config.getString("model");
String printerNum = config.getString("printerNum");
String feet = config.getString("feet");
String autoCut = config.getString("autoCut");
List<CategoryInfo> categoryInfos=JSONUtil.parseJSONStr2TList(config.getJSONArray("categoryList").toString(),CategoryInfo.class);
switch (it.getContentType()){
case "yxyPrinter":
yxyPrinter(it,model,orderInfo,shopInfo,printerNum,categoryInfos);
break;
case "fePrinter":
fePrinter(it,model,orderInfo,shopInfo,printerNum,categoryInfos);
break;
}
});
}catch (Exception e){
e.printStackTrace();
}
}
/**
* 博时结云打印机
* @param tbPrintMachineWithBLOBs
* @param model
* @param orderInfo
* @param shopInfo
* @param printerNum
*/
private void yxyPrinter(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs,String model,TbOrderInfo orderInfo,TbShopInfo shopInfo,String printerNum, List<CategoryInfo> categoryInfos){
String orderId=orderInfo.getId().toString();
switch (tbPrintMachineWithBLOBs.getSubType()) {
case "label": //标签打印机
break;
case "cash": //小票打印机
switch (model) {
case "normal": //普通出单
if("return".equals(orderInfo.getOrderType())){
List<TbOrderDetail> tbOrderDetails=tbOrderDetailMapper.selectAllByOrderId(Integer.valueOf(orderId));
if(ObjectUtil.isNotEmpty(tbOrderDetails)&&tbOrderDetails.size()>0){
List<OrderDetailPO.Detail> detailList = new ArrayList<>();
tbOrderDetails.parallelStream().forEach(it->{
String categoryId= tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
Long count= categoryInfos.stream().filter(c->
c.getId().toString().equals(categoryId)
).count();
log.info("获取当前类别是否未打印类别:{}",count);
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(it.getProductSkuId()));
String remark = "";
if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) {
remark = tbProductSkuWithBLOBs.getSpecSnap();
}
OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getProductName(), it.getNum().toString(), it.getPriceAmount().toPlainString(), remark);
detailList.add(detail);
});
String balance = "0";
if ("deposit".equals(orderInfo.getPayType())) {
TbShopUser user = tbShopUserMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getMemberId()));
if (ObjectUtil.isNotEmpty(user) && ObjectUtil.isNotEmpty(user.getAmount())) {
balance = user.getAmount().toPlainString();
}
}
if(ObjectUtil.isNotEmpty(detailList)&&detailList.size()>0){
OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(), "普通打印", 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());
String printType="退款单";
String data= PrinterUtils.getCashPrintData(detailPO,printType,"return");
PrinterUtils.printTickets(1, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
}
}
return;
}
List<TbCashierCart> cashierCarts = tbCashierCartMapper.selectByOrderId(orderInfo.getId().toString(),"final");
if (ObjectUtil.isNotEmpty(cashierCarts) && cashierCarts.size() > 0) {
List<OrderDetailPO.Detail> detailList = new ArrayList<>();
cashierCarts.parallelStream().forEach(it -> {
String categoryId;
if(ObjectUtil.isEmpty(it.getCategoryId())){
categoryId= tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
} else {
categoryId = it.getCategoryId();
}
Long count= categoryInfos.stream().filter(c->
c.getId().toString().equals(categoryId)
).count();
log.info("获取当前类别是否未打印类别:{}",count);
if(count>0){
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(it.getSkuId()));
String remark = "";
if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) {
remark = tbProductSkuWithBLOBs.getSpecSnap();
}
OrderDetailPO.Detail detail = new OrderDetailPO.Detail(it.getName(), it.getNumber().toString(), it.getTotalAmount().toPlainString(), remark);
detailList.add(detail);
}
});
String balance = "0";
if ("deposit".equals(orderInfo.getPayType())) {
TbShopUser user = tbShopUserMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getMemberId()));
if (ObjectUtil.isNotEmpty(user) && ObjectUtil.isNotEmpty(user.getAmount())) {
balance = user.getAmount().toPlainString();
}
}
if(ObjectUtil.isNotEmpty(detailList)&&detailList.size()>0){
OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(), "普通打印", orderInfo.getOrderType().equals("miniapp")?orderInfo.getTableName():orderInfo.getMasterId(), 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());
// OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(), "普通打印", orderInfo.getMasterId(), orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), "【POS-1】001", orderInfo.getOrderAmount().toPlainString(), balance, orderInfo.getPayType(), "0", detailList);
String printType="结算单";
String data= PrinterUtils.getCashPrintData(detailPO,printType,orderInfo.getOrderType());
PrinterUtils.printTickets(3, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
}
}
break;
case "one": //一菜一品
if("return".equals(orderInfo.getOrderType())){
log.error("退款但不打印出品小票");
return;
}
cashierCarts = tbCashierCartMapper.selectByOrderId(orderId,"final");
if (ObjectUtil.isNotEmpty(cashierCarts) && cashierCarts.size() > 0) {
cashierCarts.parallelStream().forEach(it -> {
String categoryId;
if(ObjectUtil.isEmpty(it.getCategoryId())){
categoryId= tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
} else {
categoryId = it.getCategoryId();
}
Long count= categoryInfos.stream().filter(c->
c.getId().toString().equals(categoryId)
).count();
log.info("获取当前类别是否未打印类别:{}",count);
if(count>0){
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(it.getSkuId()));
String remark = "";
if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) {
remark = tbProductSkuWithBLOBs.getSpecSnap();
}
String data = PrinterUtils.getPrintData(orderInfo.getMasterId(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getName(), it.getNumber(), remark);
PrinterUtils.printTickets(3, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
}
});
}
break;
case "category": //分类出单
break;
}
break;
case "kitchen": //出品打印机
break;
}
}
private void fePrinter(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs,String model,TbOrderInfo orderInfo,TbShopInfo shopInfo,String printerNum, List<CategoryInfo> categoryInfos){
String orderId=orderInfo.getId().toString();
switch (tbPrintMachineWithBLOBs.getSubType()) {
case "label": //标签打印机
List<TbCashierCart> cashierCarts = tbCashierCartMapper.selectByOrderId(orderInfo.getId().toString(),"final");
if (ObjectUtil.isNotEmpty(cashierCarts) && cashierCarts.size() > 0) {
cashierCarts.parallelStream().forEach(it->{
String categoryId;
if(ObjectUtil.isEmpty(it.getCategoryId())){
categoryId= tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
} else {
categoryId = it.getCategoryId();
}
Long count= categoryInfos.stream().filter(c->
c.getId().toString().equals(categoryId)
).count();
log.info("获取当前类别是否未打印类别:{}",count);
if(count>0) {
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(it.getSkuId()));
String remark = "";
if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) {
remark = tbProductSkuWithBLOBs.getSpecSnap();
}
for(int i=0;i<it.getNumber();i++){
FeieyunPrintUtil.printLabelMsg(tbPrintMachineWithBLOBs.getAddress(), orderInfo.getTableName(), it.getName(), 1, DateUtils.getTimes(new Date(orderInfo.getCreatedAt())), it.getSalePrice().toPlainString(), remark);
}
}
});
}
break;
case "cash": //小票打印机
break;
case "kitchen": //出品打印机
break;
}
}
}

View File

@@ -0,0 +1,99 @@
package com.chaozhanggui.system.cashierservice.rabbit;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
@Configuration
public class RabbitConfig {
@Value("${spring.rabbitmq.host}")
private String host;
@Value("${spring.rabbitmq.port}")
private int port;
@Value("${spring.rabbitmq.username}")
private String username;
@Value("${spring.rabbitmq.password}")
private String password;
@Bean
public ConnectionFactory connectionFactory() {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(host,port);
connectionFactory.setUsername(username);
connectionFactory.setPassword(password);
connectionFactory.setVirtualHost("/");
connectionFactory.setPublisherConfirms(true);
return connectionFactory;
}
@Bean
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
//必须是prototype类型
public RabbitTemplate rabbitTemplate() {
RabbitTemplate template = new RabbitTemplate(connectionFactory());
return template;
}
@Bean
public DirectExchange defaultExchange_Register() {
return new DirectExchange(RabbitConstants.CART_ORDER_COLLECT_PUT);
}
@Bean
public Queue queuePut_Register() {
return new Queue(RabbitConstants.CART_ORDER_COLLECT_QUEUE_PUT, true); //队列持久
}
@Bean
public Binding bindingPut_Register() {
return BindingBuilder.bind(queuePut_Register()).to(defaultExchange_Register()).with(RabbitConstants.CART_ORDER_COLLECT_ROUTINGKEY_PUT);
}
@Bean
public DirectExchange printExchange_Register() {
return new DirectExchange(RabbitConstants.PRINT_MECHINE_COLLECT_PUT);
}
@Bean
public Queue queuePrint_Register() {
return new Queue(RabbitConstants.PRINT_MECHINE_COLLECT_QUEUE_PUT, true); //队列持久
}
@Bean
public Binding bindingPrint_Register() {
return BindingBuilder.bind(queuePrint_Register()).to(printExchange_Register()).with(RabbitConstants.PRINT_MECHINE_COLLECT_ROUTINGKEY_PUT);
}
}

View File

@@ -0,0 +1,22 @@
package com.chaozhanggui.system.cashierservice.rabbit;
public interface RabbitConstants {
/**
* 购物车
*/
public static final String CART_ORDER_COLLECT_PUT = "cart_order_collect_put";
public static final String CART_ORDER_COLLECT_QUEUE_PUT = "cart_order_collect_queue_put";
public static final String CART_ORDER_COLLECT_ROUTINGKEY_PUT = "cart_order_collect_routingkey_put";
public static final String PRINT_MECHINE_COLLECT_PUT="print_mechine_collect_put";
public static final String PRINT_MECHINE_COLLECT_QUEUE_PUT = "print_mechine_collect_queue_put";
public static final String PRINT_MECHINE_COLLECT_ROUTINGKEY_PUT = "print_mechine_collect_routingkey_put";
}

View File

@@ -0,0 +1,48 @@
package com.chaozhanggui.system.cashierservice.rabbit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.UUID;
@Component
public class RabbitProducer implements RabbitTemplate.ConfirmCallback {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private RabbitTemplate rabbitTemplate;
@Autowired
public RabbitProducer(RabbitTemplate rabbitTemplate) {
this.rabbitTemplate = rabbitTemplate;
rabbitTemplate.setConfirmCallback(this); //rabbitTemplate如果为单例的话那回调就是最后设置的内容
}
public void putOrderCollect(String content) {
CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());
rabbitTemplate.convertAndSend(RabbitConstants.CART_ORDER_COLLECT_PUT, RabbitConstants.CART_ORDER_COLLECT_ROUTINGKEY_PUT, content, correlationId);
}
public void printMechine(String content){
CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());
rabbitTemplate.convertAndSend(RabbitConstants.PRINT_MECHINE_COLLECT_PUT, RabbitConstants.PRINT_MECHINE_COLLECT_ROUTINGKEY_PUT, content, correlationId);
}
@Override
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
logger.info(" 回调id:" + correlationData);
if (ack) {
logger.info("消息成功消费");
} else {
logger.info("消息消费失败:" + cause);
}
}
}