打印数据

This commit is contained in:
2026-04-16 14:38:14 +08:00
parent 710cca65d6
commit cef7e5315a
27 changed files with 467 additions and 86 deletions

View File

@@ -1,7 +1,6 @@
package com.czg.controller.admin;
import com.czg.excel.ExcelExportUtil;
import com.czg.log.annotation.OperationLog;
import com.czg.order.entity.ShopProdStatistic;
import com.czg.order.param.SaleSummaryCountParam;
import com.czg.order.service.ShopProdStatisticService;
@@ -36,7 +35,6 @@ public class SaleSummaryController {
* 统计
*/
@GetMapping("count")
@OperationLog("统计")
//@SaAdminCheckPermission("saleSummary:count")
public CzgResult<SaleSummaryCountVo> summaryCount(SaleSummaryCountParam param) {
if (param.getShopId() == null) {
@@ -50,7 +48,6 @@ public class SaleSummaryController {
* 分页
*/
@GetMapping("page")
@OperationLog("分页")
//@SaAdminCheckPermission("saleSummary:page")
public CzgResult<List<ShopProdStatistic>> summaryPage(SaleSummaryCountParam param) {
if (param.getShopId() == null) {
@@ -60,6 +57,9 @@ public class SaleSummaryController {
return CzgResult.success(list);
}
/**
* 商品报表导出
*/
@GetMapping("/export")
public void summaryExport(SaleSummaryCountParam param, HttpServletResponse response) {
if (param.getShopId() == null) {
@@ -68,4 +68,15 @@ public class SaleSummaryController {
ExcelExportUtil.exportToResponse(prodStatisticService.getArchiveTradeData(param), ShopProdStatistic.class, "销售统计明细", response);
}
/**
* 商品报表打印
*/
@GetMapping("/print")
public void summaryPrint(SaleSummaryCountParam param) {
if (param.getShopId() == null) {
param.setShopId(StpKit.USER.getShopId());
}
prodStatisticService.summaryPrint(param);
}
}

View File

@@ -0,0 +1,36 @@
package com.czg.controller.admin;
import com.czg.order.entity.SysPrintData;
import com.czg.order.service.SysPrintDataService;
import com.czg.resp.CzgResult;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* 打印数据
*
* @author ww
*/
@RestController
@RequestMapping("/admin/printData")
public class SysPrintDataController {
@Resource
private SysPrintDataService sysPrintDataService;
/**
* 获取打印数据
*/
@GetMapping
public CzgResult<SysPrintData> getWareCount(@RequestParam Long shopId, @RequestParam Long dataId, @RequestParam String type) {
return CzgResult.success(sysPrintDataService.getOne(new QueryWrapper()
.eq(SysPrintData::getType, type)
.eq(SysPrintData::getShopId, shopId)
.eq(SysPrintData::getId, dataId)));
}
}

View File

@@ -3,9 +3,12 @@ package com.czg.mq;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson2.JSONObject;
import com.czg.config.RabbitConstants;
import com.czg.config.RabbitPublisher;
import com.czg.config.RedisCst;
import com.czg.order.entity.MqLog;
import com.czg.order.entity.SysPrintData;
import com.czg.order.service.MqLogService;
import com.czg.order.service.SysPrintDataService;
import com.czg.service.RedisService;
import com.czg.service.order.print.PrintConfig;
import com.czg.service.order.print.PrinterHandler;
@@ -30,6 +33,10 @@ public class PrintMqListener {
private RedisService redisService;
@Resource
private PrintConfig printConfig;
@Resource
private RabbitPublisher rabbitPublisher;
@Resource
protected SysPrintDataService printDataService;
private <T> void invokeFun(String queue, String type, String plat, T data, Consumer<T> consumer) {
long startTime = DateUtil.date().getTime();
@@ -74,6 +81,11 @@ public class PrintMqListener {
@RabbitListener(queues = {"${spring.profiles.active}-" + RabbitConstants.Queue.OTHER_PRINT_QUEUE})
public void otherPrint(Long shopId, Object o, String printTypeEnum) {
PrinterHandler.PrintTypeEnum typeEnum = PrinterHandler.PrintTypeEnum.valueOf(printTypeEnum);
SysPrintData sysPrintData = new SysPrintData();
sysPrintData.setShopId(shopId);
sysPrintData.setData(JSONObject.toJSONString(o));
printDataService.save(sysPrintData);
rabbitPublisher.sendOtherPrintLocalMsg(shopId, printTypeEnum, sysPrintData.getId());
printConfig.otherHandler(shopId, o, typeEnum);
}
}

View File

@@ -82,6 +82,16 @@ public class RabbitConfig {
return BindingBuilder.bind(otherPrintQueue).to(exchange).with(activeProfile + "-" + RabbitConstants.Queue.OTHER_PRINT_QUEUE);
}
@Bean
public Queue otherPrintLocalQueue() {
return new Queue(activeProfile + "-" + RabbitConstants.Queue.OTHER_PRINT_LOCAL_QUEUE, true, false, false);
}
@Bean
public Binding bindingOtherPrintLocalExchange(Queue otherPrintLocalQueue, DirectExchange exchange) {
return BindingBuilder.bind(otherPrintLocalQueue).to(exchange).with(activeProfile + "-" + RabbitConstants.Queue.OTHER_PRINT_LOCAL_QUEUE);
}
//------------------------------------------------------订单取消
@Bean
public Queue orderCancelQueue() {
@@ -115,6 +125,7 @@ public class RabbitConfig {
public Binding bindingProductInfoChange(Queue productInfoChangeQueue, DirectExchange exchange) {
return BindingBuilder.bind(productInfoChangeQueue).to(exchange).with(activeProfile + "-" + RabbitConstants.Queue.PRODUCT_INFO_CHANGE_QUEUE);
}
//------------------------------------------------------ 耗材信息更新
@Bean
public Queue consInfoChangeQueue() {

View File

@@ -19,6 +19,7 @@ public interface RabbitConstants {
public static final String ORDER_MACHINE_PRINT_QUEUE = "order.machine.print.queue";
public static final String OTHER_PRINT_QUEUE = "other.print.queue";
public static final String OTHER_PRINT_LOCAL_QUEUE = "other.print.local.queue";
public static final String PRODUCT_INFO_CHANGE_QUEUE = "product.info.change.queue";
public static final String CONS_INFO_CHANGE_QUEUE = "cons.info.change.queue";

View File

@@ -155,6 +155,7 @@ public class RabbitPublisher {
* STOCK_CHECK 库存盘点
* HANDOVER 交班单
* CALL 排队取号
*
* @param printType {@link com.czg.service.order.print.PrinterHandler.PrintTypeEnum}
*/
public void sendOtherPrintMsg(Long shopId, Object data, String printType) {
@@ -167,4 +168,14 @@ public class RabbitPublisher {
rabbitTemplate.convertAndSend(exchange, queueName, msg);
}
public void sendOtherPrintLocalMsg(Long shopId, String printType, Long dataId) {
String exchange = activeProfile + "-" + RabbitConstants.Exchange.CASH_EXCHANGE;
String queueName = activeProfile + "-" + RabbitConstants.Queue.OTHER_PRINT_LOCAL_QUEUE;
Map<String, Object> msg = new HashMap<>();
msg.put("shopId", shopId);
msg.put("dataId", dataId);
msg.put("printType", printType);
rabbitTemplate.convertAndSend(exchange, queueName, msg);
}
}

View File

@@ -12,6 +12,7 @@ import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
/**
@@ -32,11 +33,12 @@ public interface MkShopRechargeService extends IService<MkShopRecharge> {
/**
* 充值
*
* @param isNoJoin 是否没有执行 加入会员的方法
* 会员如果是条件开通 则 需要统计
* 会员如果是条件开通 则 需要统计
*/
void recharge(Long shopId, Long shopUserId, Long rechargeDetailId, BigDecimal amount, Long paymentId,
String payType, ShopUserFlowBizEnum bizEnum, boolean isNoJoin);
String payType, LocalDateTime payTime, ShopUserFlowBizEnum bizEnum, boolean isNoJoin, String operator);
List<RechargeListVO> getList(long loginIdAsLong);

View File

@@ -0,0 +1,35 @@
package com.czg.order.dto;
import java.io.Serializable;
import lombok.experimental.Accessors;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 数据打印表 实体类。
*
* @author ww
* @since 2026-04-16
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class SysPrintDataDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private Long id;
private Long shopId;
/**
* 打印数据 Json格式
*/
private String data;
}

View File

@@ -0,0 +1,46 @@
package com.czg.order.entity;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import java.io.Serializable;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 数据打印表 实体类。
*
* @author ww
* @since 2026-04-16
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("sys_print_data")
public class SysPrintData implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Id(keyType = KeyType.Auto)
private Long id;
private Long shopId;
/**
* 打印类型
*
*/
private String type;
/**
* 打印数据 Json格式
*/
private String data;
}

View File

@@ -56,4 +56,9 @@ public class SaleSummaryCountParam implements Serializable {
* 店铺id
*/
private Long shopId;
/**
* 操作人
*/
private String operator;
}

View File

@@ -23,22 +23,30 @@ public interface ShopProdStatisticService extends IService<ShopProdStatistic> {
*/
SaleSummaryCountVo summaryCount(SaleSummaryCountParam param);
/**
* 打印 商品交易数据
*/
void summaryPrint(SaleSummaryCountParam param);
/**
* 获取某一段时间的商品交易数据
* shopId 店铺id
* rangeType 时间范围类型
* TODAY, // 今天
* YESTERDAY, // 昨天
* LAST_7_DAYS, // 最近7天
* LAST_30_DAYS,// 最近30天
* THIS_WEEK, // 本周
* THIS_MONTH // 本月
* CUSTOM // 自定义时间范围
* start 开始时间 格式yyyy-MM-dd 今天/昨天不用传
* end 结束时间 格式yyyy-MM-dd 今天/昨天不用传
* shopId 店铺id
* rangeType 时间范围类型
* TODAY, // 今天
* YESTERDAY, // 昨天
* LAST_7_DAYS, // 最近7天
* LAST_30_DAYS,// 最近30天
* THIS_WEEK, // 本周
* THIS_MONTH // 本月
* CUSTOM // 自定义时间范围
* start 开始时间 格式yyyy-MM-dd 今天/昨天不用传
* end 结束时间 格式yyyy-MM-dd 今天/昨天不用传
*
* @return 商品数据
*/
List<ShopProdStatistic> getArchiveTradeData(SaleSummaryCountParam param);
List<ShopProdStatistic> getArchiveTradeDataBy10(Long shopId, Integer day);
//------------------------------------------------------------下列为 后台使用------------------------------------------------------------

View File

@@ -0,0 +1,14 @@
package com.czg.order.service;
import com.mybatisflex.core.service.IService;
import com.czg.order.entity.SysPrintData;
/**
* 数据打印表 服务层。
*
* @author ww
* @since 2026-04-16
*/
public interface SysPrintDataService extends IService<SysPrintData> {
}

View File

@@ -5,7 +5,6 @@ import lombok.experimental.Accessors;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
/**
* 商品报表打印实体
@@ -50,9 +49,39 @@ public class ProductReportPrintDTO {
* 商品明细列表
* 分类名称,商品集合
*/
private Map<String, List<ProductItem>> items;
private List<CategoryItem> items;
@Data
@Accessors(chain = true)
public static class CategoryItem {
/**
* 商品名称(第二列商品名称)
*/
private String categoryName;
/**
* 数量(第三列数量)
*/
private BigDecimal number;
/**
* 实收(第四列)
*/
private BigDecimal actualAmount;
/**
* 销售额(第五列)
*/
private BigDecimal salesAmount;
/**
* 商品明细列表
*/
private List<ProductItem> productItems;
}
public ProductItem createProductItem(String productName, BigDecimal number, BigDecimal actualAmount, BigDecimal salesAmount) {
ProductItem item = new ProductItem();
item.setProductName(productName);

View File

@@ -15,7 +15,7 @@ import java.time.LocalDateTime;
public class RechargePrintDTO {
//店铺名称
private String shopName;
private String userId;
private Long userId;
private String userName;
private String userPhone;
//支付时间

View File

@@ -7,6 +7,7 @@ import com.mybatisflex.core.service.IService;
import jakarta.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
* 店铺商品分类
@@ -26,15 +27,22 @@ public interface ShopProdCategoryService extends IService<ShopProdCategory> {
/**
* 获取店铺商品分类列表
*
* @param param 查询参数
* @return 店铺商品分类列表
*/
List<ShopProdCategoryDTO> getShopProdCategoryList(ShopProdCategoryDTO param);
/**
* 根据店铺id获取分类id和名称的映射
*/
Map<Long, String> getCategoryIdNameMap(Long shopId);
void exportShopProdCategory(ShopProdCategoryDTO param, HttpServletResponse response);
/**
* 获取店铺商品分类详情
*
* @param id id
* @return 店铺商品分类详情
*/

View File

@@ -9,6 +9,7 @@ import com.czg.account.entity.ShopUser;
import com.czg.account.service.ShopConfigService;
import com.czg.account.service.ShopInfoService;
import com.czg.account.service.ShopUserService;
import com.czg.config.RabbitPublisher;
import com.czg.constant.TableValueConstant;
import com.czg.enums.ShopUserFlowBizEnum;
import com.czg.exception.CzgException;
@@ -20,6 +21,7 @@ import com.czg.market.entity.ShopCoupon;
import com.czg.market.enums.PointsConstant;
import com.czg.market.service.*;
import com.czg.market.vo.*;
import com.czg.print.RechargePrintDTO;
import com.czg.utils.AssertUtil;
import com.czg.utils.FunUtils;
import com.mybatisflex.core.query.QueryWrapper;
@@ -32,6 +34,7 @@ import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
@@ -60,6 +63,8 @@ public class MkShopRechargeServiceImpl extends ServiceImpl<MkShopRechargeMapper,
private ShopInfoService shopInfoService;
@DubboReference
private ShopConfigService shopConfigService;
@Resource
private RabbitPublisher rabbitPublisher;
@Override
public MkShopRechargeVO detailApp(Long shopId) {
@@ -72,7 +77,7 @@ public class MkShopRechargeServiceImpl extends ServiceImpl<MkShopRechargeMapper,
}
@Override
public MkShopRechargeVO detail(Long shopId) throws CzgException{
public MkShopRechargeVO detail(Long shopId) throws CzgException {
shopId = shopInfoService.getMainIdByShopId(shopId);
ShopInfo shopInfo = shopInfoService.getById(shopId);
if (shopInfo.getMainId() != null) {
@@ -164,7 +169,7 @@ public class MkShopRechargeServiceImpl extends ServiceImpl<MkShopRechargeMapper,
@Override
public void recharge(Long shopId, Long shopUserId, Long rechargeDetailId, BigDecimal amount, Long paymentId,
String payType, ShopUserFlowBizEnum bizEnum, boolean isNoJoin) {
String payType, LocalDateTime payTime, ShopUserFlowBizEnum bizEnum, boolean isNoJoin, String operator) {
log.info("充值回调, 用户id: {}, 金额: {}, rechargeDetailId: {}", shopUserId, amount, rechargeDetailId);
ShopUser shopUser = shopUserService.getById(shopUserId);
ShopUserMoneyEditDTO shopUserMoneyEditDTO = new ShopUserMoneyEditDTO()
@@ -172,12 +177,17 @@ public class MkShopRechargeServiceImpl extends ServiceImpl<MkShopRechargeMapper,
.setType(1)
.setBizEnum(bizEnum)
.setRelationId(paymentId);
BigDecimal rechargeAmount = BigDecimal.ZERO;
BigDecimal giftAmount = BigDecimal.ZERO;
BigDecimal giftPoints = BigDecimal.ZERO;
Integer giftCoupon = 0;
// 标准充值
if (rechargeDetailId != null) {
MkShopRechargeDetail rechargeDetail = shopRechargeDetailService.getById(rechargeDetailId);
shopUserMoneyEditDTO.setMoney(rechargeDetail.getAmount());
FunUtils.asyncSafeRunVoid(() -> {
rechargeAmount = rechargeDetail.getAmount();
try {
// 赠送金额
ShopUserMoneyEditDTO shopUserMoneyEditRewardDTO = new ShopUserMoneyEditDTO()
.setId(shopUserId)
@@ -186,28 +196,56 @@ public class MkShopRechargeServiceImpl extends ServiceImpl<MkShopRechargeMapper,
.setRelationId(paymentId);
shopUserMoneyEditRewardDTO.setMoney(rechargeDetail.getRewardAmount());
Long editId = shopUserService.updateMoney(shopUserMoneyEditRewardDTO);
giftAmount = rechargeDetail.getRewardAmount();
// 发放积分
if (rechargeDetail.getRewardPoints() != null) {
giftPoints = BigDecimal.valueOf(rechargeDetail.getRewardPoints());
pointsUserService.alterPoints(null, shopUserId, shopUser.getMainShopId(), PointsConstant.ADD, rechargeDetail.getRewardPoints(), editId, "充值赠送");
}
// 发放优惠券
if (StrUtil.isNotBlank(rechargeDetail.getCouponInfoList())) {
JSONArray.parseArray(rechargeDetail.getCouponInfoList()).toJavaList(CouponInfoDTO.class).forEach(item -> {
List<CouponInfoDTO> list = JSONArray.parseArray(rechargeDetail.getCouponInfoList()).toJavaList(CouponInfoDTO.class);
for (CouponInfoDTO item : list) {
if (item.getId() == null) {
return;
}
giftCoupon = giftCoupon + item.getNum();
shopCouponRecordService.grant(shopId, new MkRewardCouponDTO().setCouponId(item.getId())
.setNum(item.getNum())
.setUserId(shopUser.getUserId())
.setShopId(shopId), "充值赠券");
});
}
}
});
} catch (Exception e) {
log.error("recharge充值有问题", e);
}
// 自定义金额
} else {
shopUserMoneyEditDTO.setMoney(amount);
rechargeAmount = amount;
}
shopUserService.updateMoney(shopUserMoneyEditDTO);
Long flowId = shopUserService.updateMoney(shopUserMoneyEditDTO);
BigDecimal finalRechargeAmount = rechargeAmount;
BigDecimal finalGiftAmount = giftAmount;
BigDecimal finalGiftPoints = giftPoints;
Integer finalGiftCoupon = giftCoupon;
FunUtils.asyncSafeRunVoid(() -> {
RechargePrintDTO rechargePrintDTO = new RechargePrintDTO();
rechargePrintDTO.setUserId(shopUserId);
rechargePrintDTO.setUserName(shopUser.getNickName());
rechargePrintDTO.setUserPhone(shopUser.getPhone());
rechargePrintDTO.setPayTime(payTime);
rechargePrintDTO.setRechargeAmount(finalRechargeAmount);
rechargePrintDTO.setGiftAmount(finalGiftAmount);
rechargePrintDTO.setGiftPoints(finalGiftPoints);
rechargePrintDTO.setGiftCoupon(finalGiftCoupon);
rechargePrintDTO.setPayType(bizEnum.getMsg());
rechargePrintDTO.setBalance(shopUser.getAmount().add(finalRechargeAmount).add(finalGiftAmount));
rechargePrintDTO.setRechargeId(flowId.toString());
rechargePrintDTO.setOperator(operator);
rabbitPublisher.sendOtherPrintMsg(shopId, rechargePrintDTO, "RECHARGE");
});
FunUtils.asyncSafeRunVoid(() -> {
memberConfigService.deliver(shopUser, TableValueConstant.MemberExpFlow.Type.RECHARGE, amount, null, rechargeDetailId);
});

View File

@@ -37,6 +37,7 @@ public class VipPayParamDTO {
private BigDecimal amount;
private String buyerRemark;
private String operator;
/**
* 跳转地址
*/

View File

@@ -0,0 +1,14 @@
package com.czg.service.order.mapper;
import com.mybatisflex.core.BaseMapper;
import com.czg.order.entity.SysPrintData;
/**
* 数据打印表 映射层。
*
* @author ww
* @since 2026-04-16
*/
public interface SysPrintDataMapper extends BaseMapper<SysPrintData> {
}

View File

@@ -62,26 +62,8 @@ public class PrintConfig implements ApplicationRunner {
public static final Map<String, PrinterHandler> PRINTER_MAP = new ConcurrentHashMap<>();
// @PostConstruct
// 直接使用实例变量,不需要静态
// private Map<String, PrinterHandler> printerMap;
// public void init() {
// Map<String, PrinterHandler> printers = applicationContext.getBeansOfType(PrinterHandler.class);
// printerMap = new ConcurrentHashMap<>();
//
// printers.forEach((beanName, printer) -> {
// String brand = printer.printerBrand;
// if (brand != null && !brand.trim().isEmpty()) {
// printerMap.put(brand, printer);
// }
// });
//
// log.info("已注册打印机: {}", printerMap.keySet());
// }
@Override
public void run(ApplicationArguments args) throws Exception {
// 🔥 这里是 Spring 容器完全启动成功后才执行!
// 🔥 所有 feiPrinter、yxyPrinter 都已经加载好了!
Map<String, PrinterHandler> beans = applicationContext.getBeansOfType(PrinterHandler.class);

View File

@@ -364,7 +364,7 @@ public abstract class PrinterHandler {
String codeUrl, LocalDateTime takeTime, String shopNote);
/**
* 出入库打印单
* 出入库打印单
*/
protected abstract void stockPrint(PrintMachine machine, String shopName, StockPrintDTO record);
@@ -379,12 +379,12 @@ public abstract class PrinterHandler {
protected abstract void productReportPrint(PrintMachine machine, String shopName, ProductReportPrintDTO record);
/**
* 储值单打印
* 储值单打印
*/
protected abstract void rechargePrint(PrintMachine machine, String shopName, RechargePrintDTO record);
/**
* 库存盘点打印
* 库存盘点打印
*/
protected abstract void stockCheckPrint(PrintMachine machine, String shopName, StockCheckPrintDTO record);

View File

@@ -17,7 +17,6 @@ import lombok.experimental.Accessors;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
@@ -668,37 +667,25 @@ public interface PrinterImpl {
builder.append(getFormatLabel(header, signLabelInfo.s)).append(signLabelInfo.br);
// 遍历分类+商品明细
Map<String, List<ProductReportPrintDTO.ProductItem>> itemsMap = record.getItems();
if (CollUtil.isNotEmpty(itemsMap)) {
for (Map.Entry<String, List<ProductReportPrintDTO.ProductItem>> entry : itemsMap.entrySet()) {
String categoryName = entry.getKey();
List<ProductReportPrintDTO.ProductItem> productList = entry.getValue();
// 先打印分类名称行(分类名称+该分类汇总数量/实收/销售额,和示例图一致)
// 分类汇总:遍历该分类下所有商品,求和
BigDecimal categoryTotalNum = BigDecimal.ZERO;
BigDecimal categoryTotalActual = BigDecimal.ZERO;
BigDecimal categoryTotalSales = BigDecimal.ZERO;
for (ProductReportPrintDTO.ProductItem item : productList) {
categoryTotalNum = categoryTotalNum.add(item.getNumber());
categoryTotalActual = categoryTotalActual.add(item.getActualAmount());
categoryTotalSales = categoryTotalSales.add(item.getSalesAmount());
}
List<ProductReportPrintDTO.CategoryItem> items = record.getItems();
if (CollUtil.isNotEmpty(items)) {
for (ProductReportPrintDTO.CategoryItem item : items) {
List<ProductReportPrintDTO.ProductItem> productList = item.getProductItems();
// 打印分类行缩进0和表头对齐
String categoryLine = key4(categoryName,
categoryTotalNum.stripTrailingZeros().toPlainString(),
categoryTotalActual.stripTrailingZeros().toPlainString(),
categoryTotalSales.stripTrailingZeros().toPlainString(),
String categoryLine = key4(item.getCategoryName(),
item.getNumber().stripTrailingZeros().toPlainString(),
item.getActualAmount().stripTrailingZeros().toPlainString(),
item.getSalesAmount().stripTrailingZeros().toPlainString(),
12, 8, 8);
builder.append(getFormatLabel(categoryLine, signLabelInfo.s)).append(signLabelInfo.br);
// 再打印该分类下的商品明细缩进2个空格和示例图一致
for (ProductReportPrintDTO.ProductItem item : productList) {
String numStr = item.getNumber().stripTrailingZeros().toPlainString();
String actualStr = item.getActualAmount().stripTrailingZeros().toPlainString();
String salesStr = item.getSalesAmount().stripTrailingZeros().toPlainString();
for (ProductReportPrintDTO.ProductItem pro : productList) {
String numStr = pro.getNumber().stripTrailingZeros().toPlainString();
String actualStr = pro.getActualAmount().stripTrailingZeros().toPlainString();
String salesStr = pro.getSalesAmount().stripTrailingZeros().toPlainString();
// 商品名称前加2个空格实现缩进效果
String productLine = key4(" " + item.getProductName(), numStr, actualStr, salesStr, 12, 8, 8);
String productLine = key4(" " + pro.getProductName(), numStr, actualStr, salesStr, 12, 8, 8);
builder.append(getFormatLabel(productLine, signLabelInfo.s)).append(signLabelInfo.br);
}
}
@@ -726,9 +713,15 @@ public interface PrinterImpl {
// 充值明细
builder.append(getFormatLabel("----------------------------------------")).append(signLabelInfo.br);
builder.append(getFormatLabel(leftRightAlign(" 充值金额:", record.getRechargeAmount().stripTrailingZeros().toPlainString(), 32), signLabelInfo.s)).append(signLabelInfo.br);
builder.append(getFormatLabel(leftRightAlign(" 赠送金额:", record.getGiftAmount().stripTrailingZeros().toPlainString(), 32), signLabelInfo.s)).append(signLabelInfo.br);
builder.append(getFormatLabel(leftRightAlign(" 赠送积分:", record.getGiftPoints().stripTrailingZeros().toPlainString(), 32), signLabelInfo.s)).append(signLabelInfo.br);
builder.append(getFormatLabel(leftRightAlign(" 赠送优惠券:", record.getGiftCoupon() + "", 32), signLabelInfo.s)).append(signLabelInfo.br);
if (record.getGiftAmount() != null && record.getGiftAmount().compareTo(BigDecimal.ZERO) > 0) {
builder.append(getFormatLabel(leftRightAlign(" 赠送金额:", record.getGiftAmount().stripTrailingZeros().toPlainString(), 32), signLabelInfo.s)).append(signLabelInfo.br);
}
if (record.getGiftPoints() != null && record.getGiftPoints().compareTo(BigDecimal.ZERO) > 0) {
builder.append(getFormatLabel(leftRightAlign(" 赠送积分:", record.getGiftPoints().stripTrailingZeros().toPlainString(), 32), signLabelInfo.s)).append(signLabelInfo.br);
}
if (record.getGiftCoupon() != null && record.getGiftCoupon() > 0) {
builder.append(getFormatLabel(leftRightAlign(" 赠送优惠券:", record.getGiftCoupon() + "", 32), signLabelInfo.s)).append(signLabelInfo.br);
}
builder.append(getFormatLabel(leftRightAlign(" 充值后余额:", record.getBalance().stripTrailingZeros().toPlainString(), 32), signLabelInfo.s)).append(signLabelInfo.br);
builder.append(getFormatLabel("----------------------------------------")).append(signLabelInfo.br);
// 支付信息

View File

@@ -1180,7 +1180,7 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
}
shopRechargeService.recharge(payment.getShopId(), payment.getSourceId(), payment.getRelatedId(),
BigDecimal.valueOf(notifyRespDTO.getAmount()).divide(BigDecimal.valueOf(100), 2, RoundingMode.DOWN),
payment.getId(), payment.getSourceType(), bizEnum, orderInfo == null);
payment.getId(), payment.getSourceType(), payment.getPayTime(), bizEnum, orderInfo == null, null);
}
} else if (PayTypeConstants.SourceType.MEMBER_PAY.equals(payment.getSourceType())) {
//购买会员

View File

@@ -1,15 +1,21 @@
package com.czg.service.order.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.czg.config.RabbitPublisher;
import com.czg.exception.CzgException;
import com.czg.order.entity.ShopProdStatistic;
import com.czg.order.param.SaleSummaryCountParam;
import com.czg.order.service.ShopProdStatisticService;
import com.czg.order.vo.SaleSummaryCountVo;
import com.czg.print.ProductReportPrintDTO;
import com.czg.product.service.ShopProdCategoryService;
import com.czg.service.order.mapper.ShopProdStatisticMapper;
import com.czg.utils.CzgStrUtils;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
@@ -28,6 +34,11 @@ import java.util.stream.Stream;
@Service
public class ShopProdStatisticServiceImpl extends ServiceImpl<ShopProdStatisticMapper, ShopProdStatistic> implements ShopProdStatisticService {
@Resource
private RabbitPublisher rabbitPublisher;
@DubboReference
private ShopProdCategoryService shopProdCategoryService;
@Override
public List<ShopProdStatistic> getArchiveTradeDataBy10(Long shopId, Integer day) {
LocalDate currentDate = LocalDate.now();
@@ -73,6 +84,86 @@ public class ShopProdStatisticServiceImpl extends ServiceImpl<ShopProdStatisticM
return mergeSummaryCountVo(todaySummary, dateRangeSummary);
}
@Override
public void summaryPrint(SaleSummaryCountParam param) {
// 1. 获取统计数据
SaleSummaryCountVo saleSummaryCountVo = summaryCount(param);
List<ShopProdStatistic> prodStatisticList = getArchiveTradeData(param);
LocalDate currentDate = LocalDate.now();
Map<Long, String> categoryMap = shopProdCategoryService.getCategoryIdNameMap(param.getShopId());
ProductReportPrintDTO printDTO = new ProductReportPrintDTO();
String statisticsTime = "";
if ("today".equals(param.getRangeType())) {
statisticsTime = LocalDateTimeUtil.format(currentDate, "yyyy/MM/dd");
}
if ("yesterday".equals(param.getRangeType())) {
statisticsTime = LocalDateTimeUtil.format(currentDate.minusDays(1), "yyyy/MM/dd");
}
if (param.getBeginDate().isAfter(currentDate)) {
throw new CzgException("开始时间不能晚于当前时间");
}
if (param.getBeginDate().equals(param.getEndDate())) {
statisticsTime = LocalDateTimeUtil.format(param.getBeginDate(), "yyyy/MM/dd");
}
if (param.getEndDate().isBefore(currentDate)) {
statisticsTime = LocalDateTimeUtil.format(param.getBeginDate(), "yyyy/MM/dd") + " ~ " + LocalDateTimeUtil.format(param.getEndDate(), "yyyy/MM/dd");
}
printDTO.setStatisticsTime(statisticsTime);
printDTO.setOperator(param.getOperator());
printDTO.setTotalProductCount(saleSummaryCountVo.getSaleCount());
printDTO.setTotalActualAmount(saleSummaryCountVo.getTotalAmount());
// 4. 先按分类ID分组商品
Map<Long, List<ShopProdStatistic>> groupByCategory = prodStatisticList.stream()
.collect(Collectors.groupingBy(ShopProdStatistic::getCategoryId));
// 5. 组装成新结构 List<CategoryItem>
List<ProductReportPrintDTO.CategoryItem> categoryItems = new ArrayList<>();
for (Map.Entry<Long, List<ShopProdStatistic>> entry : groupByCategory.entrySet()) {
Long categoryId = entry.getKey();
List<ShopProdStatistic> productList = entry.getValue();
// 分类名称
String categoryName = categoryMap.getOrDefault(categoryId, "未分类");
// 商品列表
List<ProductReportPrintDTO.ProductItem> productItems = new ArrayList<>();
BigDecimal categoryTotalNumber = BigDecimal.ZERO;
BigDecimal categoryTotalActual = BigDecimal.ZERO;
BigDecimal categoryTotalSales = BigDecimal.ZERO;
for (ShopProdStatistic s : productList) {
ProductReportPrintDTO.ProductItem item = new ProductReportPrintDTO.ProductItem();
item.setProductName(s.getProductName());
item.setNumber(s.getValidSaleCount());
item.setActualAmount(s.getValidSaleAmount());
item.setSalesAmount(s.getSaleAmount());
productItems.add(item);
// 分类汇总累加
categoryTotalNumber = categoryTotalNumber.add(s.getValidSaleCount());
categoryTotalActual = categoryTotalActual.add(s.getValidSaleAmount());
categoryTotalSales = categoryTotalSales.add(s.getSaleAmount());
}
// 构建分类项
ProductReportPrintDTO.CategoryItem categoryItem = new ProductReportPrintDTO.CategoryItem();
categoryItem.setCategoryName(categoryName);
categoryItem.setNumber(categoryTotalNumber); // 分类总数量
categoryItem.setActualAmount(categoryTotalActual); // 分类总实收
categoryItem.setSalesAmount(categoryTotalSales); // 分类总销售额
categoryItem.setProductItems(productItems); // 分类下商品
categoryItems.add(categoryItem);
}
printDTO.setItems(categoryItems);
rabbitPublisher.sendOtherPrintMsg(param.getShopId(), printDTO, "PRODUCT_REPORT");
}
@Override
public List<ShopProdStatistic> getArchiveTradeData(SaleSummaryCountParam param) {
LocalDate currentDate = LocalDate.now();

View File

@@ -41,6 +41,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
@@ -110,16 +111,9 @@ public class ShopUserServiceImpl implements ShopUserPayService {
return CzgResult.failure("支付密码错误");
}
}
// if (shopUser.getIsVip().equals(0)) {
// //更新会员
// ShopUser updateInfo = new ShopUser();
// updateInfo.setIsVip(1);
// updateInfo.setJoinTime(LocalDateTime.now());
// updateInfo.setId(payParam.getShopUserId());
// shopUserService.updateById(updateInfo);
// }
shopRechargeService.recharge(shopUser.getMainShopId(), shopUser.getId(), payParam.getRechargeDetailId(),
payParam.getAmount(), null, "cash", ShopUserFlowBizEnum.CASH_IN, true);
payParam.getAmount(), null, "cash", LocalDateTime.now(),
ShopUserFlowBizEnum.CASH_IN, true, payParam.getOperator());
return CzgResult.success();
}

View File

@@ -0,0 +1,18 @@
package com.czg.service.order.service.impl;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.order.entity.SysPrintData;
import com.czg.order.service.SysPrintDataService;
import com.czg.service.order.mapper.SysPrintDataMapper;
import org.springframework.stereotype.Service;
/**
* 数据打印表 服务层实现。
*
* @author ww
* @since 2026-04-16
*/
@Service
public class SysPrintDataServiceImpl extends ServiceImpl<SysPrintDataMapper, SysPrintData> implements SysPrintDataService{
}

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.SysPrintDataMapper">
</mapper>

View File

@@ -1,6 +1,7 @@
package com.czg.service.product.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.constants.SystemConstants;
import com.czg.excel.ExcelExportUtil;
@@ -22,6 +23,8 @@ import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.context.annotation.Lazy;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 店铺商品分类
@@ -64,6 +67,17 @@ public class ShopProdCategoryServiceImpl extends ServiceImpl<ShopProdCategoryMap
return super.listAs(queryWrapper, ShopProdCategoryDTO.class);
}
@Override
public Map<Long, String> getCategoryIdNameMap(Long shopId) {
QueryWrapper queryWrapper = query().select(ShopProdCategory::getId, ShopProdCategory::getName)
.eq(ShopProdCategory::getShopId, shopId).eq(ShopProdCategory::getStatus, SystemConstants.OneZero.ONE);
List<ShopProdCategory> list = list(queryWrapper);
if (CollUtil.isEmpty(list)) {
return Map.of();
}
return list.stream().collect(Collectors.toMap(ShopProdCategory::getId, ShopProdCategory::getName));
}
@Override
public void exportShopProdCategory(ShopProdCategoryDTO param, HttpServletResponse response) {
QueryWrapper queryWrapper = buildQueryWrapper(param);