Merge remote-tracking branch 'origin/master'

This commit is contained in:
Tankaikai 2025-03-11 15:34:37 +08:00
commit cbebde520c
23 changed files with 690 additions and 22 deletions

View File

@ -1,7 +1,11 @@
package com.czg.controller.user;
import com.czg.account.service.GeoService;
import com.czg.account.vo.DistrictVo;
import com.czg.resp.CzgResult;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotEmpty;
import org.springframework.web.bind.annotation.GetMapping;
@ -9,6 +13,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* geo位置管理
* @author Administrator
@ -19,8 +25,31 @@ public class UserGeoController {
@Resource
private GeoService geoService;
/**
* 经纬度换取位置信息
* @param lat 经度
* @param lng 纬度
* @return 位置西悉尼
*/
@GetMapping("/geocode")
public CzgResult<?> getAddress(@RequestParam @NotEmpty String lat, @RequestParam @NotEmpty String lng) {
return CzgResult.success(geoService.getAddress(lat, lng));
}
/**
* 根据市换取所有下属行政区
*/
@GetMapping("/district")
public CzgResult<List<DistrictVo>> district(String keywords) throws JsonProcessingException {
String districtJson = geoService.district(keywords,null);
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(districtJson);
JsonNode districts = jsonNode.get("districts");
String text = districts.toString();
List<DistrictVo> cityInfoList = mapper.readValue(text, mapper.getTypeFactory().constructCollectionType(List.class, DistrictVo.class));
DistrictVo allCity = new DistrictVo();
allCity.setName("全城");
cityInfoList.addFirst(allCity);
return CzgResult.success(cityInfoList);
}
}

View File

@ -124,7 +124,7 @@ public class CzgControllerAdvice {
*/
@ExceptionHandler(ValidateException.class)
public CzgResult<Object> handleValidateException(ValidateException ex) {
setErrorLog(ex);
log.error(ex.getMessage());
return CzgResult.failure(CzgRespCode.PARAM_ERROR.getCode(), ex.getMessage());
}

View File

@ -1,11 +1,14 @@
package com.czg.account.dto.shopuser;
import com.czg.account.entity.ShopExtend;
import com.czg.account.entity.ShopInfo;
import com.czg.account.entity.ShopUser;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
/**
* @author Administrator
@ -30,6 +33,13 @@ public class ShopUserDetailDTO extends ShopUser {
*/
private Long shopId;
/**
* 店铺信息
*/
private ShopInfo shopInfo;
/**
* 店铺拓展参数
*/
private List<ShopExtend> shopExtendList = new ArrayList<>();
}

View File

@ -7,4 +7,6 @@ import jakarta.validation.constraints.NotEmpty;
*/
public interface GeoService {
Object getAddress(@NotEmpty String lat, @NotEmpty String lng);
String district(String keywords, String subdistrict);
}

View File

@ -0,0 +1,57 @@
package com.czg.account.vo;
import lombok.Data;
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
import java.util.List;
/**
* 行政区域返回vo
*/
@Data
public class DistrictVo {
/**
* 城市代码
*/
private Object citycode;
private String adcode;
/**
* 名称
*/
private String name;
/**
* 经纬度
*/
private String center;
/**
* 级别
*/
private String level;
/**
* 行政区信息
*/
private List<DistrictVo> districts;
public String getNameAsPY() {
return getPinYin(name);
}
public String getPinYin(String name){
HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
// 设置声调类型为WITH_TONE_MARK
format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
// 设置拼音输出的大小写格式为小写
format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
String pinyin = "";
try {
pinyin = PinyinHelper.toHanYuPinyinString(name,format , "", false);
} catch (BadHanyuPinyinOutputFormatCombination e) {
return pinyin;
}
return pinyin;
}
}

View File

@ -33,6 +33,10 @@ public class CheckOrderPay implements Serializable {
* 是否整单打包
*/
private Integer allPack;
/**
* 用户端 使用 全打包 或者 全不打包
*/
private Integer userAllPack;
/**
* 用餐人数

View File

@ -0,0 +1,153 @@
package com.czg.order.dto;
import java.io.Serializable;
import java.time.LocalDateTime;
import com.alibaba.fastjson2.annotation.JSONField;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 店铺小票打印记录 实体类
*
* @author zs
* @since 2025-03-11
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PrintMachineLogDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* id
*/
private Long id;
/**
* 打印机类型 本地打印机-local USB打印机-USB 云打印机-network
*/
private String connectionType;
/**
* 打印机品牌 云想印 = yxyPrinter飞鹅 = fePrinter 本地 = local USB = printer
*/
private String contentType;
/**
* 打印小票 标签-label 出品-kitchen 小票-cash
*/
private String subType;
/**
* 打印机名称
*/
private String name;
/**
* IP地址/打印机编号
*/
private String address;
/**
* 端口/打印机秘钥
*/
private String port;
/**
* 小票尺寸 58mm 80mm
*/
private String receiptSize;
/**
* 分类打印 0-所以 1-部分分类 2-部分商品
*/
private String classifyPrint;
/**
* 桌台打印 0-所有 1-部分
*/
private String tablePrint;
/**
* 打印数量 c1m1^2=顾客+商家[2张] m1^1=商家[1张] c1^1顾客[1张] c2m1^3=顾客2+商家1[3张]
*/
private String printQty;
/**
* 打印方式 normal-普通出单 one-一菜一品 callTicket-排队取号
*/
private String printMethod;
/**
* 打印类型 JSON数组字符串数据 1-确认退款单 2-交班单 3-排队取号[1,2,3]
*/
private String printType;
/**
* 打印票据 0-全部打印 1-仅厨房 2-仅前台
*/
private String printReceipt;
/**
* 打印内容
*/
private String printContent;
/**
* 店铺id
*/
private String shopId;
/**
* 业务类型
*/
private String bizType;
/**
* 打印人id
*/
private Long createUserId;
/**
* 打印人名称
*/
private String createUserName;
/**
* 打印任务创建时间
*/
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime createTime;
/**
* 打印任务id用于复查打印状态云想印=orderId
*/
private String taskId;
/**
* 实际打印时间
*/
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime printTime;
/**
* 失败标识 1- 0-
*/
private Integer failFlag;
/**
* 响应代码
*/
private String respCode;
/**
* 响应消息
*/
private String respMsg;
}

View File

@ -0,0 +1,160 @@
package com.czg.order.entity;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 店铺小票打印记录 实体类
*
* @author zs
* @since 2025-03-11
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_print_machine_log")
public class PrintMachineLog implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* id
*/
@Id(keyType = KeyType.Auto)
private Long id;
/**
* 打印机类型 本地打印机-local USB打印机-USB 云打印机-network
*/
private String connectionType;
/**
* 打印机品牌 云想印 = yxyPrinter飞鹅 = fePrinter 本地 = local USB = printer
*/
private String contentType;
/**
* 打印小票 标签-label 出品-kitchen 小票-cash
*/
private String subType;
/**
* 打印机名称
*/
private String name;
/**
* IP地址/打印机编号
*/
private String address;
/**
* 端口/打印机秘钥
*/
private String port;
/**
* 小票尺寸 58mm 80mm
*/
private String receiptSize;
/**
* 分类打印 0-所以 1-部分分类 2-部分商品
*/
private String classifyPrint;
/**
* 桌台打印 0-所有 1-部分
*/
private String tablePrint;
/**
* 打印数量 c1m1^2=顾客+商家[2张] m1^1=商家[1张] c1^1顾客[1张] c2m1^3=顾客2+商家1[3张]
*/
private String printQty;
/**
* 打印方式 normal-普通出单 one-一菜一品 callTicket-排队取号
*/
private String printMethod;
/**
* 打印类型 JSON数组字符串数据 1-确认退款单 2-交班单 3-排队取号[1,2,3]
*/
private String printType;
/**
* 打印票据 0-全部打印 1-仅厨房 2-仅前台
*/
private String printReceipt;
/**
* 打印内容
*/
private String printContent;
/**
* 店铺id
*/
private String shopId;
/**
* 业务类型
*/
private String bizType;
/**
* 打印人id
*/
private Long createUserId;
/**
* 打印人名称
*/
private String createUserName;
/**
* 打印任务创建时间
*/
@Column(onInsertValue = "now()")
private LocalDateTime createTime;
/**
* 打印任务id用于复查打印状态云想印=orderId
*/
private String taskId;
/**
* 实际打印时间
*/
private LocalDateTime printTime;
/**
* 失败标识 1- 0-
*/
private Integer failFlag;
/**
* 响应代码
*/
private String respCode;
/**
* 响应消息
*/
private String respMsg;
}

View File

@ -30,6 +30,7 @@ public interface OrderInfoService extends IService<OrderInfo> {
Page<OrderInfoVo> getOrderByPage(OrderInfoQueryDTO param);
CzgResult<HistoryOrderVo> getOrderDetails(Long orderId);
CzgResult<HistoryOrderPrintVo> getOrderByIdPrint(Long orderId);
HistoryOrderVo historyOrder(Long orderId, String tableCode);
@ -50,7 +51,7 @@ public interface OrderInfoService extends IService<OrderInfo> {
void processOrderDetails2(List<OrderDetail> orderDetails, Map<Long, Integer> prodCouponMap,
BigDecimalDTO prodCouponAmount, BigDecimalDTO totalAmount, BigDecimalDTO packAmount,
boolean isAllPack, boolean isVipPrice);
boolean isAllPack, Integer userAllPack, boolean isVipPrice);
Boolean printOrder(Long shopId, OrderInfoPrintDTO orderInfoPrintDTO);

View File

@ -0,0 +1,14 @@
package com.czg.order.service;
import com.mybatisflex.core.service.IService;
import com.czg.order.entity.PrintMachineLog;
/**
* 店铺小票打印记录 服务层
*
* @author zs
* @since 2025-03-11
*/
public interface PrintMachineLogService extends IService<PrintMachineLog> {
}

View File

@ -39,10 +39,16 @@
<aliyun.oss.version>2.8.3</aliyun.oss.version>
<zxing.version>3.5.3</zxing.version>
<weixin.java.miniapp.version>3.8.0</weixin.java.miniapp.version>
<pinyin.version>2.5.1</pinyin.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.belerweb</groupId>
<artifactId>pinyin4j</artifactId>
<version>${pinyin.version}</version>
</dependency>
<dependency>
<groupId>com.czg</groupId>
<artifactId>cash-common-tools</artifactId>

View File

@ -18,6 +18,10 @@
</properties>
<dependencies>
<dependency>
<groupId>com.belerweb</groupId>
<artifactId >pinyin4j</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.github.binarywang</groupId>-->
<!-- <artifactId>weixin-java-miniapp</artifactId>-->

View File

@ -1,14 +1,19 @@
package com.czg.service.account.service.impl;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONObject;
import com.czg.account.service.GeoService;
import com.czg.exception.ApiNotPrintException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.seata.common.util.HttpClientUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClient;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
/**
@ -40,6 +45,21 @@ public class GeoServiceImpl implements GeoService {
}
return jsonObject.getJSONObject("regeocode");
}
@Override
public String district(String keywords, String subdistrict) {
Map<String, Object> param = new HashMap<>();
//超掌柜生活-用户端
param.put("key", "7a7f2e4790ea222660a027352ee3af39");
param.put("keywords", keywords);
param.put("subdistrict", "1");
if (StringUtils.isNotBlank(subdistrict)) {
param.put("subdistrict", "2");
}
param.put("extensions", "base");
String s = HttpUtil.get("https://restapi.amap.com/v3/config/district", param);
return s;
}
}

View File

@ -6,10 +6,7 @@ import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.account.dto.shopuser.*;
import com.czg.account.entity.*;
import com.czg.account.service.ShopActivateCouponRecordService;
import com.czg.account.service.ShopUserFlowService;
import com.czg.account.service.ShopUserService;
import com.czg.account.service.UserInfoService;
import com.czg.account.service.*;
import com.czg.config.RedisCst;
import com.czg.exception.ApiNotPrintException;
import com.czg.resp.CzgResult;
@ -32,6 +29,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
/**
@ -55,6 +53,8 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
private ShopActivateCouponRecordService shopActivateCouponRecordService;
@Resource
private ShopInfoMapper shopInfoMapper;
@Resource
private ShopExtendService shopExtendService;
private ShopUser getUserInfo(Long shopId, Long shopUserId) {
ShopUser shopUser = queryChain().eq(ShopUser::getShopId, shopId).eq(ShopUser::getId, shopUserId).one();
@ -279,6 +279,8 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
shopUserDetailDTO.setShopName(shopInfo.getShopName());
shopUserDetailDTO.setShopId(shopInfo.getId());
shopUserDetailDTO.setShopInfo(shopInfo);
List<ShopExtend> shopExtends = shopExtendService.list(new QueryWrapper().eq(ShopExtend::getShopId, shopInfo.getId()));
shopUserDetailDTO.setShopExtendList(shopExtends);
}
return shopUserDetailDTO;
}

View File

@ -0,0 +1,14 @@
package com.czg.service.order.mapper;
import com.mybatisflex.core.BaseMapper;
import com.czg.order.entity.PrintMachineLog;
/**
* 店铺小票打印记录 映射层
*
* @author zs
* @since 2025-03-11
*/
public interface PrintMachineLogMapper extends BaseMapper<PrintMachineLog> {
}

View File

@ -48,7 +48,6 @@ public class FeiPrinter extends PrinterHandler implements PrinterImpl {
private final PrintSignLabel printSignLabel = new PrintSignLabel()
.setBr("<BR>")
.setCut("")
.setF(new String[]{"<F>", "</F>"})
.setL(new String[]{"<L>", "</L>"})
@ -68,8 +67,7 @@ public class FeiPrinter extends PrinterHandler implements PrinterImpl {
String content = buildDishPrintData(false, getPickupNum(orderInfo), orderInfo.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")),
orderDetail.getProductName(), orderDetail.getSkuName(), orderDetail.getNum(), remark, orderDetail.getProGroupInfo());
sendPrintRequest(machine.getAddress(), content, null,"1");
// shopPrintLogService.save(machine, "新订单", resp[0], resp[1]); // 可以解开注释用于日志存储
// printMachineLogService.save(machine, "新订单", , );
}
@Override

View File

@ -17,6 +17,7 @@ import com.czg.order.entity.OrderDetail;
import com.czg.order.entity.OrderInfo;
import com.czg.order.service.OrderDetailService;
import com.czg.order.service.OrderInfoService;
import com.czg.order.service.PrintMachineLogService;
import com.czg.product.entity.ProdSku;
import com.czg.product.entity.Product;
import com.czg.product.service.ProdSkuService;
@ -59,6 +60,8 @@ public abstract class PrinterHandler {
protected OrderInfoService orderInfoService;
@Resource
protected RedisService redisService;
@Resource
protected PrintMachineLogService printMachineLogService;
@DubboReference
protected SysParamsService sysParamsService;
@ -266,7 +269,7 @@ public abstract class PrinterHandler {
item.setProductName("【临】" + item.getProductName());
}
}
boolean isGift = item.getPackAmount().compareTo(BigDecimal.ZERO) == 0;
boolean isGift = item.getIsGift() != null && item.getIsGift() == 1;
if (isGift && !item.getProductName().contains("【赠】")) {
item.setProductName("【赠】" + item.getProductName());
}
@ -335,7 +338,7 @@ public abstract class PrinterHandler {
it.setProductName("【临】%s".formatted(it.getProductName()));
}
it.setPackAmount(it.getPackAmount() == null ? BigDecimal.ZERO : it.getPackAmount());
boolean isGift = it.getPackAmount().compareTo(BigDecimal.ZERO) == 0;
boolean isGift = it.getIsGift() != null && it.getIsGift() == 1;
if (isGift) {
it.setProductName("【赠】%s".formatted(it.getProductName()));
}

View File

@ -170,7 +170,8 @@ public interface PrinterImpl {
data.append(signLabelInfo.br);
// data.append("<OUT:15>");
// data.append("<BR>");
data.append(getFormatLabel("品名 数量 小计", signLabelInfo.s))
// 18个空格 12
data.append(getFormatLabel("品名 数量 小计", signLabelInfo.s))
.append(signLabelInfo.br);
// data.append("<S>品名 数量 小计</S><BR>");
data.append(getFormatLabel("--------------------------------", signLabelInfo.s))
@ -178,7 +179,8 @@ public interface PrinterImpl {
// data.append("<S>--------------------------------</S><BR>");
for (OrderDetail detail : detailList) {
String number = detail.getNum().stripTrailingZeros().toPlainString();
String row = getRow(detail.getProductName(), "", number, toPlainStr(detail.getPayAmount().stripTrailingZeros().toPlainString()), 20, 0, 3, 6);
String row = getRow(detail.getProductName(), "", number,
toPlainStr(detail.getPayAmount().stripTrailingZeros().toPlainString()), 23, 0, 5, 4);
data.append(row);
if (StrUtil.isNotBlank(detail.getSkuName())) {
data.append(getFormatLabel(StrUtil.format("规格:{}", detail.getSkuName()), signLabelInfo.s))
@ -301,10 +303,11 @@ public interface PrinterImpl {
// builder.append("<CS:32>").append(skuName).append(" </CS><BR>");
}
} else {
builder.append(getFormatLabel(StrUtil.format("{} x ", productName), signLabelInfo.bold));
builder.append(getFormatLabel(StrUtil.format("{} x {}", productName, number.stripTrailingZeros().toPlainString()), signLabelInfo.l))
.append(signLabelInfo.br);
// builder.append("<B>").append(productName).append(" x ").append(number).append("</B><BR>");
if (StrUtil.isNotBlank(skuName)) {
builder.append(getFormatLabel(skuName, signLabelInfo.bold))
builder.append(getFormatLabel(skuName, signLabelInfo.l))
.append(signLabelInfo.br);
// builder.append("<B>").append(skuName).append(" </B><BR>");
}

View File

@ -291,7 +291,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
BigDecimalDTO totalAmount = new BigDecimalDTO(BigDecimal.ZERO);
//最终打包费
BigDecimalDTO packAmount = new BigDecimalDTO(BigDecimal.ZERO);
processOrderDetails2(orderDetails, prodCouponMap, prodCouponAmount, totalAmount, packAmount, param.isAllPack(), param.isVipPrice());
processOrderDetails2(orderDetails, prodCouponMap, prodCouponAmount, totalAmount, packAmount, param.isAllPack(), param.getUserAllPack(), param.isVipPrice());
//总商品支付金额 不包含打包费 用来计算后续
log.info("支付前置,商品金额{} 商品优惠券金额{} 总金额{}", totalAmount, prodCouponAmount, totalAmount.getPrice().add(orderInfo.getPackFee()));
if (prodCouponAmount.getPrice().compareTo(param.getProductCouponDiscountAmount()) != 0) {
@ -382,7 +382,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
@Override
public void processOrderDetails2(List<OrderDetail> orderDetails, Map<Long, Integer> prodCouponMap,
BigDecimalDTO prodCouponAmount, BigDecimalDTO totalAmount, BigDecimalDTO packAmount,
boolean isAllPack, boolean isVipPrice) {
boolean isAllPack, Integer userAllPack, boolean isVipPrice) {
Map<Long, List<OrderDetail>> detailMap = new HashMap<>();
for (OrderDetail detail : orderDetails) {
detailMap.computeIfAbsent(detail.getProductId(), k -> new ArrayList<>()).add(detail);
@ -408,11 +408,17 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
orderDetail.setUnitPrice(orderDetail.getPrice());
}
}
if (isAllPack) {
if (userAllPack != null) {
if (userAllPack.equals(1)) {
orderDetail.setPackNumber(orderDetail.getNum().subtract(orderDetail.getReturnNum()));
} else {
orderDetail.setPackNumber(BigDecimal.ZERO);
}
} else if (isAllPack) {
if ("weigh".equals(orderDetail.getProductType())) {
orderDetail.setPackNumber(BigDecimal.ONE);
} else {
orderDetail.setPackNumber(orderDetail.getNum());
orderDetail.setPackNumber(orderDetail.getNum().subtract(orderDetail.getReturnNum()));
}
}
packAmount.setPrice(packAmount.getPrice().add(orderDetail.getPackAmount().multiply(orderDetail.getPackNumber()).setScale(2, RoundingMode.DOWN)));
@ -426,7 +432,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
orderDetail.setPayAmount((orderDetail.getNum().subtract(orderDetail.getReturnNum()).subtract(couponNum)).multiply(orderDetail.getUnitPrice()));
couponNum = BigDecimal.ZERO;
}
prodCouponAmount.setPrice(prodCouponAmount.getPrice().add(orderDetail.getUnitPrice().multiply(orderDetail.getCouponNum())));
prodCouponAmount.setPrice((prodCouponAmount.getPrice().add(orderDetail.getUnitPrice())).multiply(orderDetail.getCouponNum()));
} else {
orderDetail.setCouponNum(BigDecimal.ZERO);
orderDetail.setPayAmount(orderDetail.getNum().subtract(orderDetail.getReturnNum()).multiply(orderDetail.getUnitPrice()));

View File

@ -125,7 +125,7 @@ public class PayServiceImpl implements PayService {
BigDecimalDTO totalAmount = new BigDecimalDTO(BigDecimal.ZERO);
//最终打包费
BigDecimalDTO packAmount = new BigDecimalDTO(BigDecimal.ZERO);
orderInfoService.processOrderDetails2(orderDetails, null, null, totalAmount, packAmount, payParam.isAllPack(), true);
orderInfoService.processOrderDetails2(orderDetails, null, null, totalAmount, packAmount, payParam.isAllPack(), null,true);
BigDecimal payAmount = (totalAmount.getPrice().add(packAmount.getPrice())).multiply(BigDecimal.TWO);
if (payAmount.compareTo(payParam.getAmount()) != 0) {
throw new ValidateException("霸王餐支付金额不正确");

View File

@ -0,0 +1,171 @@
package com.czg.service.order.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.map.MapProxy;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.czg.account.entity.PrintMachine;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.order.entity.PrintMachineLog;
import com.czg.order.service.PrintMachineLogService;
import com.czg.service.order.mapper.PrintMachineLogMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.Map;
/**
* 店铺小票打印记录ServiceImpl
*
* @author tankaikai
* @since 2024-10-8 17:10
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class PrintMachineLogServiceImpl extends ServiceImpl<PrintMachineLogMapper, PrintMachineLog> implements PrintMachineLogService{
/**
* 保存打印记录
*
* @param config 打印机配置
* @param bizType 业务类型
* @param printContent 打印内容
* @param respJson 打印机响应结果
*/
@Async
public void save(PrintMachine config, String bizType, String printContent, String respJson) {
// if (config == null) {
// return;
// }
// PrintMachineLog entity = new PrintMachineLog();
// BeanUtil.copyProperties(config, entity);
// int failFlag = 0;
// String respCode = "0";
// String respMsg = "打印中";
//
// Map<Integer, String> yxxStatusMap = MapUtil.builder(0, "离线(设备上线后自动补打)").put(1, "在线").put(2, "获取失败").put(3, "未激活").put(4, "设备已禁用").build();
// // 云想印
// if ("yxyPrinter".equals(config.getContentType())) {
// cn.hutool.json.JSONObject resp = JSONUtil.parseObj(respJson);
// int code = resp.getInt("code");
// cn.hutool.json.JSONObject data = resp.getJSONObject("data").getJSONObject("data");
// //设备状态0: 离线, 1: 在线, 2: 获取失败, 3:未激活, 4:设备已禁用
// int status = data.getInt("status");
// if (code != 0) {
// failFlag = 1;
// respCode = code + "";
// respMsg = resp.getStr("msg");
// } else if (status != 1) {
// failFlag = 1;
// respCode = code + "";
//
// respMsg = status + "_" + yxxStatusMap.get(status);
// }
// if (code == 0) {
// String taskId = resp.getJSONObject("data").getStr("orderId");
// entity.setTaskId(taskId);
// }
// // 飞鹅云打印机暂时没有适配先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;
// }
// entity.setBizType(bizType);
//// entity.setCreateUserId(config.getCurrentUserId());
//// entity.setCreateUserName(config.getCurrentUserName());
//// if (StrUtil.isNotBlank(config.getCurrentUserNickName())) {
//// entity.setCreateUserName(StrUtil.concat(true, config.getCurrentUserNickName(), " | ", config.getCurrentUserName()));
//// }
// entity.setPrintContent(printContent);
// entity.setCreateTime(DateUtil.date().toLocalDateTime());
// if (failFlag == 0) {
// entity.setPrintTime(entity.getCreateTime());
// }
// entity.setFailFlag(failFlag);
// entity.setRespCode(respCode);
// entity.setRespMsg(respMsg);
// super.save(entity);
//
// // 云想印
// if ("yxyPrinter".equals(config.getContentType())) {
// // 延迟3ms复查打印状态 (用户可以根据设备信息查询到当前设备的在线情况该接口只能提供参考设备的离线状态是在设备离线3分钟后才会生效)
// ThreadUtil.safeSleep(1000 * 5);
// String jsonStr = PrinterUtils.checkPrintStatus(config.getAddress(), entity.getTaskId());
// cn.hutool.json.JSONObject resp = JSONUtil.parseObj(jsonStr);
// int code = resp.getInt("code");
// if (code == 0) {
// cn.hutool.json.JSONObject data = resp.getJSONObject("data");
// boolean status = data.containsKey("status");
// if (!status) {
// return;
// }
// boolean success = data.getBool("status", false);
// if (entity.getFailFlag() == 0 && success) {
// entity.setFailFlag(0);
// entity.setRespMsg("打印成功");
// entity.setPrintTime(entity.getCreateTime());
// } else if (entity.getFailFlag() == 1 && success) {
// entity.setFailFlag(0);
// entity.setPrintTime(new Date());
// entity.setRespMsg("打印成功");
// // 如果设备在线 and 休眠5秒后查询结果是未打印即视为设备已离线云端3分钟后才会同步到离线信息
// } else if (entity.getFailFlag() == 0 && !success) {
// entity.setFailFlag(1);
// entity.setPrintTime(null);
// entity.setRespMsg("0_离线(设备上线后自动补打)");
// } else {
// entity.setFailFlag(1);
// entity.setPrintTime(null);
// entity.setRespMsg(StrUtil.concat(true, "打印失败,", "_", entity.getRespMsg()));
// }
// super.updateById(entity);
// }
// // 飞鹅云打印机
// } else if ("fePrinter".equals(config.getContentType())) {
// ThreadUtil.safeSleep(1000 * 5);
// 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());
// if (msg.indexOf("在线,工作状态正常") > 0) {
// entity.setFailFlag(0);
// entity.setPrintTime(new Date());
// entity.setRespMsg("打印成功");
// } else {
// entity.setFailFlag(1);
// entity.setPrintTime(null);
// entity.setRespMsg(StrUtil.concat(true, "打印失败,", "_", msg));
// }
// }
// super.updateById(entity);
// }
}
}

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.czg.service.order.mapper.PrintMachineLogMapper">
</mapper>

View File

@ -87,7 +87,11 @@
<version>2.10.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.belerweb</groupId>
<artifactId >pinyin4j</artifactId>
<version >2.5.1</version >
</dependency>
<!-- end -->
<!-- maven下载不到的包放这里下载完成后注释掉 -->
<!-- <dependency>-->