fix(订单服务): 修复空订单列表导致的NPE问题

feat(数据库): 新增用户余额交易记录表

refactor(权限检查): 使用权限字符串替代路由树检查
This commit is contained in:
dzq 2025-07-04 15:06:04 +08:00
parent c33f8951d7
commit 27489e68eb
3 changed files with 44 additions and 11 deletions

View File

@ -190,12 +190,17 @@ public class PaymentController {
SystemLoginUser loginUser = new SystemLoginUser(); SystemLoginUser loginUser = new SystemLoginUser();
loginUser.setAdmin(false); loginUser.setAdmin(false);
loginUser.setUserId(sysUserEntity.getUserId()); loginUser.setUserId(sysUserEntity.getUserId());
List<RouterDTO> routerTree = menuApplicationService.getRouterTree(loginUser); List<String> permissions = menuApplicationService.getPermissions(loginUser);
log.info("getRouterTreeuserid: {}, routerTree: {}", userid, JSONUtil.toJsonStr(routerTree)); /* List<RouterDTO> routerTree = menuApplicationService.getRouterTree(loginUser);
log.info("getRouterTreeuserid: {}, routerTree: {}", userid, JSONUtil.toJsonStr(routerTree));*/
int isCabinetAdmin = 0; int isCabinetAdmin = 0;
if (routerTree != null && !routerTree.isEmpty()) { // if (routerTree != null && !routerTree.isEmpty()) {
isCabinetAdmin = isCabinetAdmin(routerTree) // isCabinetAdmin = isCabinetAdmin(routerTree)
// ? 1 : 0;
// }
if (permissions != null && !permissions.isEmpty()) {
isCabinetAdmin = permissions.contains("shop:cabinet:write")
? 1 : 0; ? 1 : 0;
} }
@ -228,12 +233,17 @@ public class PaymentController {
SystemLoginUser loginUser = new SystemLoginUser(); SystemLoginUser loginUser = new SystemLoginUser();
loginUser.setAdmin(false); loginUser.setAdmin(false);
loginUser.setUserId(sysUserEntity.getUserId()); loginUser.setUserId(sysUserEntity.getUserId());
List<RouterDTO> routerTree = menuApplicationService.getRouterTree(loginUser); List<String> permissions = menuApplicationService.getPermissions(loginUser);
log.info("getRouterTreeuserid: {}, routerTree: {}", userid, JSONUtil.toJsonStr(routerTree)); /* List<RouterDTO> routerTree = menuApplicationService.getRouterTree(loginUser);
log.info("getRouterTreeuserid: {}, routerTree: {}", userid, JSONUtil.toJsonStr(routerTree));*/
int isCabinetAdmin = 0; int isCabinetAdmin = 0;
if (routerTree != null && !routerTree.isEmpty()) { // if (routerTree != null && !routerTree.isEmpty()) {
isCabinetAdmin = isCabinetAdmin(routerTree) // isCabinetAdmin = isCabinetAdmin(routerTree)
// ? 1 : 0;
// }
if (permissions != null && !permissions.isEmpty()) {
isCabinetAdmin = permissions.contains("shop:cabinet:write")
? 1 : 0; ? 1 : 0;
} }

View File

@ -533,9 +533,12 @@ public class OrderApplicationService {
.filter(order -> orderIds.contains(order.getOrderId())) .filter(order -> orderIds.contains(order.getOrderId()))
.collect(Collectors.toList()); .collect(Collectors.toList());
QueryWrapper<ShopGoodsEntity> goodsQueryWrapper = new QueryWrapper<>(); List<ShopGoodsEntity> goods = new ArrayList<>();
goodsQueryWrapper.in("goods_id", orderGoods.stream().map(ShopOrderGoodsEntity::getGoodsId).collect(Collectors.toList())); if (!orderIds.isEmpty()) {
List<ShopGoodsEntity> goods = goodsService.list(goodsQueryWrapper); QueryWrapper<ShopGoodsEntity> goodsQueryWrapper = new QueryWrapper<>();
goodsQueryWrapper.in("goods_id", orderGoods.stream().map(ShopOrderGoodsEntity::getGoodsId).collect(Collectors.toList()));
goods = goodsService.list(goodsQueryWrapper);
}
return new GetOrdersByOpenIdDTO(orderList, orderGoods, goods); return new GetOrdersByOpenIdDTO(orderList, orderGoods, goods);
} }

20
sql/20250703.sql Normal file
View File

@ -0,0 +1,20 @@
CREATE TABLE `user_balance_record` (
`balance_record_id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`ab98_user_id` bigint NOT NULL COMMENT '汇邦云用户唯一ID',
`openid` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'openid',
`transaction_type` tinyint NOT NULL COMMENT '交易类型1充值 2消费 3退款',
`use_record_id` bigint NULL COMMENT '消费或退款时使用的充值id',
`amount` int NOT NULL COMMENT '交易金额,单位分',
`status` tinyint NOT NULL DEFAULT 0 COMMENT '交易状态0未完成 1成功 2失败',
`trade_id` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '支付网关交易id',
`biz_order_id` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '业务系统订单ID对接外部系统',
`transaction_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '交易时间',
`creator_id` bigint DEFAULT 0 COMMENT '创建者ID',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updater_id` bigint DEFAULT 0 COMMENT '更新者ID',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '删除标志0存在 1删除',
PRIMARY KEY (`balance_record_id`),
KEY `idx_ab98_user_id` (`ab98_user_id`),
KEY `idx_transaction_time` (`transaction_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户余额交易记录表';