fix:盖章bug,商户统计bug

This commit is contained in:
dzc committed 2026-07-11 17:31:03 +08:00
1 parent d29393692c
commit f2f719d608
6 files changed
+159 -20

No files matched your search

@@ -71,6 +71,8 @@ public interface HardOrderMapper extends PjcloudBaseMapper<HardOrderEntity> {
.in(ObjectUtil.isNotEmpty(dto.getUserIds()), HardOrderEntity::getUserId, dto.getUserIds())
.in(ObjectUtil.isNotEmpty(dto.getMchIds()), HardOrderEntity::getMerchantId, dto.getMchIds())
.in(ObjectUtil.isNotEmpty(dto.getMchTypeCodes()), HardOrderEntity::getMerchantType, dto.getMchTypeCodes())
.in(ObjectUtil.isNotEmpty(dto.getOrderStatusCodes()), HardOrderEntity::getOrderStatus, dto.getOrderStatusCodes())
.in(ObjectUtil.isNotEmpty(dto.getRefundStatusCodes()), HardOrderEntity::getRefundStatus, dto.getRefundStatusCodes())
.between(
ObjectUtil.isNotEmpty(dto.getCreateTimeList()),
HardOrderEntity::getCreateTime,
@@ -169,7 +169,7 @@ public class HardAfterSaleServiceImpl extends ServiceImpl<HardAfterSaleMapper, H
// 更改订单状态为已取消
HardAfterSaleLogEntity last = hardAfterSaleLogMapper.getFirst(afterSale.getId());
if (ObjectUtil.isNotEmpty(last) && ObjectUtil.isNotEmpty(last.getAfterStatus())) {
HardOrderEntity updateOrderObj = HardOrderEntity.builder().id(order.getId()).applyCancelTime(LocalDateTime.now()).orderStatus(last.getBeforeStatus()).build();
HardOrderEntity updateOrderObj = HardOrderEntity.builder().id(order.getId()).applyCancelTime(LocalDateTime.now()).refundStatus(HardRefundStatusEnum.NONE.getStatus()).orderStatus(last.getBeforeStatus()).build();
hardOrderService.updateById(updateOrderObj);
}
// 添加售后进度
@@ -406,6 +406,11 @@ public class HardAfterSaleServiceImpl extends ServiceImpl<HardAfterSaleMapper, H
if (!HardOrderTypeEnum.isRefund(orderTypeEnum)) {
throw new RuntimeException("该订单类型不支持退款");
}
// 超过7天不能退款
int days = 7;
if (ObjectUtil.isNotEmpty(order.getPayTime()) && order.getPayTime().plusDays(days).isBefore(LocalDateTime.now())) {
throw new RuntimeException("订单已超过" + days + "天,不能退款");
}
// 查询所有成功的退款
List<HardAfterSaleEntity> afterList = baseMapper.selectList(new LambdaQueryWrapper<HardAfterSaleEntity>()
.eq(HardAfterSaleEntity::getOrderId, order.getId())
@@ -493,7 +498,7 @@ public class HardAfterSaleServiceImpl extends ServiceImpl<HardAfterSaleMapper, H
LambdaUpdateWrapper<HardOrderEntity> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.set(HardOrderEntity::getApplyCancelTime, null)
.set(HardOrderEntity::getOrderStatus, HardOrderStatusEnum.REFUND.getType())
.set(HardOrderEntity::getRefundStatus, HardRefundStatusEnum.NONE.getStatus())
.set(HardOrderEntity::getRefundStatus, HardRefundStatusEnum.APPLY.getStatus())
.eq(HardOrderEntity::getId, order.getId());
hardOrderService.update(updateWrapper);
return saveObj;
@@ -709,4 +714,4 @@ public class HardAfterSaleServiceImpl extends ServiceImpl<HardAfterSaleMapper, H
private HardAfterSaleServiceImpl getSelf() {
return SpringUtil.getBean(getClass());
}
}
}
@@ -4,7 +4,6 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alipay.api.response.AlipayTradeOrderPayResponse;
import com.alipay.api.response.AlipayTradePayResponse;
import com.baomidou.lock.annotation.Lock4j;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -31,9 +30,7 @@ import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.data.datascope.DataScope;
import com.bsd.pjcloud.common.security.service.PjcloudUser;
import com.bsd.pjcloud.hard.api.constant.HardProductNatureEnum;
import com.bsd.pjcloud.hard.api.constant.HardThirdMiStatusEnum;
import com.bsd.pjcloud.hard.api.constant.HardTypeEnum;
import com.bsd.pjcloud.hard.api.constant.order.HardHourTypeEnum;
import com.bsd.pjcloud.hard.api.constant.order.HardOrderStatusEnum;
import com.bsd.pjcloud.hard.api.constant.order.HardOrderTypeEnum;
import com.bsd.pjcloud.hard.api.constant.order.HardPayTypeEnum;
@@ -37,6 +37,7 @@ import com.bsd.pjcloud.hard.mapper.manager.HardManagerMapper;
import com.bsd.pjcloud.hard.mapper.order.HardOrderMapper;
import com.bsd.pjcloud.hard.service.HardManagerService;
import com.bsd.pjcloud.hard.service.HardOrderTotalService;
import com.bsd.pjcloud.hard.utils.RemoteBatchQueryUtil;
import com.bsd.pjcloud.wallet.api.constant.WalletBizEnum;
import com.bsd.pjcloud.wallet.api.dto.WalletTransactionSumAndCountDto;
import com.bsd.pjcloud.wallet.api.feign.RemoteMchService;
@@ -132,7 +133,7 @@ public class HardOrderTotalServiceImpl implements HardOrderTotalService {
// 商户
List<Long> mchIds = totalList.stream().map(HardOrderSbVo::getMerchantId).distinct().toList();
if (ObjectUtil.isNotEmpty(mchIds)) {
List<MchManageVo> mchList = remoteMchService.getByIds(mchIds).getData();
List<MchManageVo> mchList = getMchListByIds(mchIds);
if (ObjectUtil.isNotEmpty(mchList)) {
WalletDataUtil.convertMchList(totalList, CollectionUtils.convertMap(mchList, MchManageVo::getId));
}
@@ -220,7 +221,7 @@ public class HardOrderTotalServiceImpl implements HardOrderTotalService {
// 商户
List<Long> mchIds = totalList.stream().map(HardOrderCsVo::getMerchantId).distinct().toList();
if (ObjectUtil.isNotEmpty(mchIds)) {
List<MchManageVo> mchList = remoteMchService.getByIds(mchIds).getData();
List<MchManageVo> mchList = getMchListByIds(mchIds);
if (ObjectUtil.isNotEmpty(mchList)) {
WalletDataUtil.convertMchList(totalList, CollectionUtils.convertMap(mchList, MchManageVo::getId));
}
@@ -228,7 +229,7 @@ public class HardOrderTotalServiceImpl implements HardOrderTotalService {
// 商户部门
List<Long> mchDeptIds = totalList.stream().map(HardOrderCsVo::getMerchantDeptId).distinct().toList();
if (ObjectUtil.isNotEmpty(mchDeptIds)) {
Map<Long, SysDept> deptMap = remoteDeptService.getDeptByDeptIds(mchDeptIds).getData();
Map<Long, SysDept> deptMap = getDeptMapByIds(mchDeptIds);
if (ObjectUtil.isNotEmpty(deptMap)) {
for (HardOrderCsVo v : totalList) {
if (ObjectUtil.isEmpty(v.getMerchantDeptId())) continue;
@@ -319,7 +320,7 @@ public class HardOrderTotalServiceImpl implements HardOrderTotalService {
// 商户
List<Long> mchIds = totalList.stream().map(HardOrderCsVo::getMerchantId).distinct().toList();
if (ObjectUtil.isNotEmpty(mchIds)) {
List<MchManageVo> mchList = remoteMchService.getByIds(mchIds).getData();
List<MchManageVo> mchList = getMchListByIds(mchIds);
if (ObjectUtil.isNotEmpty(mchList)) {
WalletDataUtil.convertMchList(totalList, CollectionUtils.convertMap(mchList, MchManageVo::getId));
}
@@ -327,7 +328,7 @@ public class HardOrderTotalServiceImpl implements HardOrderTotalService {
// 商户部门
List<Long> mchDeptIds = totalList.stream().map(HardOrderCsVo::getMerchantDeptId).distinct().toList();
if (ObjectUtil.isNotEmpty(mchDeptIds)) {
Map<Long, SysDept> deptMap = remoteDeptService.getDeptByDeptIds(mchDeptIds).getData();
Map<Long, SysDept> deptMap = getDeptMapByIds(mchDeptIds);
if (ObjectUtil.isNotEmpty(deptMap)) {
for (HardOrderCsVo v : totalList) {
if (ObjectUtil.isEmpty(v.getMerchantDeptId())) continue;
@@ -388,7 +389,7 @@ public class HardOrderTotalServiceImpl implements HardOrderTotalService {
// 商户
List<Long> mchIds = totalList.stream().map(HardOrderCsVo::getMerchantId).distinct().toList();
if (ObjectUtil.isNotEmpty(mchIds)) {
List<MchManageVo> mchList = remoteMchService.getByIds(mchIds).getData();
List<MchManageVo> mchList = getMchListByIds(mchIds);
if (ObjectUtil.isNotEmpty(mchList)) {
WalletDataUtil.convertMchList(totalList, CollectionUtils.convertMap(mchList, MchManageVo::getId));
}
@@ -816,7 +817,7 @@ public class HardOrderTotalServiceImpl implements HardOrderTotalService {
}
List<List<Long>> chuckMchIds = ListUtil.split(mchIds, 5);
List<MchManageVo> mchList = remoteMchService.getByIds(mchIds).getData();
List<MchManageVo> mchList = getMchListByIds(mchIds);
Map<String, Object> map = new HashMap<String, Object>();
@@ -962,4 +963,12 @@ public class HardOrderTotalServiceImpl implements HardOrderTotalService {
return listMap;
}
private List<MchManageVo> getMchListByIds(List<Long> mchIds) {
return RemoteBatchQueryUtil.queryByIds(mchIds, ids -> remoteMchService.getByIds(ids).getData());
}
private Map<Long, SysDept> getDeptMapByIds(List<Long> deptIds) {
return RemoteBatchQueryUtil.queryMapByIds(deptIds, ids -> remoteDeptService.getDeptByDeptIds(ids).getData());
}
}
@@ -0,0 +1,113 @@
package com.bsd.pjcloud.hard.utils;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ObjectUtil;
import lombok.experimental.UtilityClass;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
/**
* 远程批量查询工具。
* <p>
* 用于处理 ids 数量过多时,直接调用其他服务的批量查询接口可能导致请求参数过长的问题。
*/
@UtilityClass
public class RemoteBatchQueryUtil {
/**
* 默认每批查询 200 个 id。
*/
public static final int DEFAULT_BATCH_SIZE = 200;
/**
* 按默认批量大小分组查询。
*
* @param ids 查询 id 集合
* @param queryFunction 实际远程查询方法
* @param <ID> id 类型
* @param <T> 返回数据类型
* @return 合并后的查询结果
*/
public static <ID, T> List<T> queryByIds(List<ID> ids, Function<List<ID>, List<T>> queryFunction) {
return queryByIds(ids, DEFAULT_BATCH_SIZE, queryFunction);
}
/**
* 按指定批量大小分组查询,并合并每批查询结果。
*
* @param ids 查询 id 集合
* @param batchSize 每批 id 数量
* @param queryFunction 实际远程查询方法
* @param <ID> id 类型
* @param <T> 返回数据类型
* @return 合并后的查询结果
*/
public static <ID, T> List<T> queryByIds(List<ID> ids, int batchSize, Function<List<ID>, List<T>> queryFunction) {
if (ObjectUtil.isEmpty(ids)) return List.of();
if (ObjectUtil.isEmpty(queryFunction)) return List.of();
List<ID> distinctIds = ids.stream()
.filter(ObjectUtil::isNotEmpty)
.distinct()
.toList();
if (ObjectUtil.isEmpty(distinctIds)) return List.of();
List<T> resultList = new ArrayList<>();
for (List<ID> batchIds : ListUtil.split(distinctIds, batchSize)) {
List<T> batchList = queryFunction.apply(batchIds);
if (ObjectUtil.isNotEmpty(batchList)) {
resultList.addAll(batchList);
}
}
return resultList;
}
/**
* 按默认批量大小分组查询,并合并每批 Map 查询结果。
*
* @param ids 查询 id 集合
* @param queryFunction 实际远程查询方法
* @param <ID> id 类型
* @param <K> 返回 Map 的 key 类型
* @param <V> 返回 Map 的 value 类型
* @return 合并后的查询结果
*/
public static <ID, K, V> Map<K, V> queryMapByIds(List<ID> ids, Function<List<ID>, Map<K, V>> queryFunction) {
return queryMapByIds(ids, DEFAULT_BATCH_SIZE, queryFunction);
}
/**
* 按指定批量大小分组查询,并合并每批 Map 查询结果。
*
* @param ids 查询 id 集合
* @param batchSize 每批 id 数量
* @param queryFunction 实际远程查询方法
* @param <ID> id 类型
* @param <K> 返回 Map 的 key 类型
* @param <V> 返回 Map 的 value 类型
* @return 合并后的查询结果
*/
public static <ID, K, V> Map<K, V> queryMapByIds(List<ID> ids, int batchSize, Function<List<ID>, Map<K, V>> queryFunction) {
if (ObjectUtil.isEmpty(ids)) return Map.of();
if (ObjectUtil.isEmpty(queryFunction)) return Map.of();
List<ID> distinctIds = ids.stream()
.filter(ObjectUtil::isNotEmpty)
.distinct()
.toList();
if (ObjectUtil.isEmpty(distinctIds)) return Map.of();
Map<K, V> resultMap = new LinkedHashMap<>();
for (List<ID> batchIds : ListUtil.split(distinctIds, batchSize)) {
Map<K, V> batchMap = queryFunction.apply(batchIds);
if (ObjectUtil.isNotEmpty(batchMap)) {
resultMap.putAll(batchMap);
}
}
return resultMap;
}
}
@@ -86,6 +86,9 @@ import java.util.Map;
public class WalletRechargeInvoiceServiceImpl extends ServiceImpl<WalletRechargeInvoiceMapper, WalletRechargeInvoiceEntity> implements WalletRechargeInvoiceService {
static private final String TAG = "充值/扣款发票";
private static final double INVOICE_STAMP_WIDTH_RATIO = 500D / (661.5D * 3D);
private static final double INVOICE_STAMP_X_RATIO = (500D + 661.5D * 3D * 0.15D + 80D) / (661.5D * 3D);
private static final double INVOICE_STAMP_BOTTOM_MARGIN_RATIO = 50D / (359.1D * 3D);
private final FlowUtil flowUtil;
@@ -428,7 +431,6 @@ public class WalletRechargeInvoiceServiceImpl extends ServiceImpl<WalletRecharge
picUrl = imageBaseUrl + picUrl;
}
}
int stampWidth = 500, stampHeight = 500;
try {
// 读取底图
URLConnection connection = new URL(picUrl).openConnection();
@@ -442,6 +444,8 @@ public class WalletRechargeInvoiceServiceImpl extends ServiceImpl<WalletRecharge
log.error("|{}|盖章失败,底图解析失败,picUrl:|{}|invoice:|{}|", TAG, picUrl, JSONUtil.toJsonStr(invoice));
return null;
}
int baseMapWidth = baseImage.getWidth();
int baseMapHeight = baseImage.getHeight();
// 读取盖章图片
BufferedImage stampImage;
try (InputStream inputStream = ResourceUtil.getStream("image/receiptStamp.png")) {
@@ -451,6 +455,13 @@ public class WalletRechargeInvoiceServiceImpl extends ServiceImpl<WalletRecharge
log.error("|{}|盖章失败,盖章图片资源不存在,invoice:|{}|", TAG, JSONUtil.toJsonStr(invoice));
return null;
}
int stampWidth = Math.max(1, (int) Math.round(baseMapWidth * INVOICE_STAMP_WIDTH_RATIO));
int stampHeight = Math.max(1, (int) Math.round(stampWidth * (double) stampImage.getHeight() / stampImage.getWidth()));
if (stampWidth > baseMapWidth || stampHeight > baseMapHeight) {
double scale = Math.min(baseMapWidth / (double) stampWidth, baseMapHeight / (double) stampHeight);
stampWidth = Math.max(1, (int) Math.floor(stampWidth * scale));
stampHeight = Math.max(1, (int) Math.floor(stampHeight * scale));
}
BufferedImage scaledStamp = new BufferedImage(stampWidth, stampHeight, BufferedImage.TYPE_INT_ARGB);
Graphics2D stampG2d = scaledStamp.createGraphics();
stampG2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
@@ -464,12 +475,10 @@ public class WalletRechargeInvoiceServiceImpl extends ServiceImpl<WalletRecharge
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
int baseMapWidth = baseImage.getWidth();
int baseMapHeight = baseImage.getHeight();
int x = (int) (stampWidth + baseMapWidth * 0.15 + 80);
int y = baseMapHeight - stampHeight - 50;
x = Math.max(0, Math.min(x, baseMapWidth - stampWidth));
y = Math.max(0, Math.min(y, baseMapHeight - stampHeight));
int x = (int) Math.round(baseMapWidth * INVOICE_STAMP_X_RATIO);
int y = baseMapHeight - stampHeight - (int) Math.round(baseMapHeight * INVOICE_STAMP_BOTTOM_MARGIN_RATIO);
x = clamp(x, 0, baseMapWidth - stampWidth);
y = clamp(y, 0, baseMapHeight - stampHeight);
g2d.drawImage(scaledStamp, x, y, null);
g2d.dispose();
String fileName = "invoice_stamped_" + invoice.getId() + ".png";
@@ -497,6 +506,10 @@ public class WalletRechargeInvoiceServiceImpl extends ServiceImpl<WalletRecharge
}
}
private static int clamp(int value, int min, int max) {
return Math.max(min, Math.min(value, max));
}
/**
* 绑定发票
*/