feat(settlement): 增加用户资源权限控制及优化结算逻辑- 在LoginContextHolder中增加clientId字段以支持客户端标识- 更…
…新LoginInterceptor以从客户和操作员信息中提取并设置clientId - 引入ClientResourceTagServiceRpcClient用于获取用户资源权限 - 根据用户权限动态过滤档口ID,若请求未指定则使用用户拥有的档口 -优化订单筛选条件,简化在线支付与非在线支付的判断逻辑 - 移除冗余的空值检查,提升代码可读性与健壮性 - 简化字符串判空逻辑,提高代码简洁度- 安全获取订单备注、忌口、医嘱等字段,避免空指针异常 - 调整订单详情构建过程,确保字段安全访问-优化餐品名称与SKU名称的安全获取方式
Showing
3 changed files
with
39 additions
and
27 deletions
| ... | @@ -57,6 +57,8 @@ public class LoginContextHolder { | ... | @@ -57,6 +57,8 @@ public class LoginContextHolder { |
| 57 | 57 | ||
| 58 | private Integer enterpriseId; | 58 | private Integer enterpriseId; |
| 59 | 59 | ||
| 60 | + private Integer clientId; | ||
| 61 | + | ||
| 60 | private String name; | 62 | private String name; |
| 61 | 63 | ||
| 62 | @Builder.Default | 64 | @Builder.Default | ... | ... |
| ... | @@ -93,7 +93,7 @@ public class LoginInterceptor implements HandlerInterceptor { | ... | @@ -93,7 +93,7 @@ public class LoginInterceptor implements HandlerInterceptor { |
| 93 | ResponseUtil.write(response, ResponseResult.failed(ErrorCodeEnum.FORBIDDEN)); | 93 | ResponseUtil.write(response, ResponseResult.failed(ErrorCodeEnum.FORBIDDEN)); |
| 94 | return false; | 94 | return false; |
| 95 | } | 95 | } |
| 96 | - builder.id(loginId).enterpriseId(enterpriseId).name(customer.getResponse().getName()).openId(openId).loginSource(LoginSourceEnum.CUSTOMER); | 96 | + builder.id(loginId).enterpriseId(enterpriseId).clientId(customer.getResponse().getClientId()).name(customer.getResponse().getName()).openId(openId).loginSource(LoginSourceEnum.CUSTOMER); |
| 97 | return true; | 97 | return true; |
| 98 | } else if (loginSource.equals(LoginSourceEnum.OPERATOR.getValue())){ | 98 | } else if (loginSource.equals(LoginSourceEnum.OPERATOR.getValue())){ |
| 99 | final var loginId = StpUtil.getLoginIdAsInt(); | 99 | final var loginId = StpUtil.getLoginIdAsInt(); |
| ... | @@ -103,7 +103,7 @@ public class LoginInterceptor implements HandlerInterceptor { | ... | @@ -103,7 +103,7 @@ public class LoginInterceptor implements HandlerInterceptor { |
| 103 | ResponseUtil.write(response, ResponseResult.failed(ErrorCodeEnum.FORBIDDEN)); | 103 | ResponseUtil.write(response, ResponseResult.failed(ErrorCodeEnum.FORBIDDEN)); |
| 104 | return false; | 104 | return false; |
| 105 | } | 105 | } |
| 106 | - builder.id(loginId).enterpriseId(enterpriseId).name(opeartor.getName()).loginSource(LoginSourceEnum.OPERATOR); | 106 | + builder.id(loginId).enterpriseId(enterpriseId).clientId(opeartor.getClientId()).name(opeartor.getName()).loginSource(LoginSourceEnum.OPERATOR); |
| 107 | return true; | 107 | return true; |
| 108 | } else if (loginSource.equals(LoginSourceEnum.KDS.getValue())) { | 108 | } else if (loginSource.equals(LoginSourceEnum.KDS.getValue())) { |
| 109 | final var loginId = StpUtil.getLoginIdAsInt(); | 109 | final var loginId = StpUtil.getLoginIdAsInt(); | ... | ... |
| 1 | package com.infoloop.tianting.service.impl; | 1 | package com.infoloop.tianting.service.impl; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.collection.CollectionUtil; | ||
| 3 | import cn.hutool.core.date.LocalDateTimeUtil; | 4 | import cn.hutool.core.date.LocalDateTimeUtil; |
| 4 | import com.infoloop.tianting.SingleDishSkuByIdsRpcResponse; | 5 | import com.infoloop.tianting.SingleDishSkuByIdsRpcResponse; |
| 5 | import com.infoloop.tianting.clientcustomerorderservice.OnlinePayEnum; | 6 | import com.infoloop.tianting.clientcustomerorderservice.OnlinePayEnum; |
| ... | @@ -31,6 +32,7 @@ import com.infoloop.tianting.model.enums.desc.OnlinePayDescEnum; | ... | @@ -31,6 +32,7 @@ import com.infoloop.tianting.model.enums.desc.OnlinePayDescEnum; |
| 31 | import com.infoloop.tianting.service.SettlementService; | 32 | import com.infoloop.tianting.service.SettlementService; |
| 32 | import com.infoloop.tianting.service.client.ClientCustomerServiceRpcClient; | 33 | import com.infoloop.tianting.service.client.ClientCustomerServiceRpcClient; |
| 33 | import com.infoloop.tianting.service.client.ClientInventoryServiceRpcClient; | 34 | import com.infoloop.tianting.service.client.ClientInventoryServiceRpcClient; |
| 35 | +import com.infoloop.tianting.service.client.ClientResourceTagServiceRpcClient; | ||
| 34 | import com.infoloop.tianting.service.client.MealServiceRpcClient; | 36 | import com.infoloop.tianting.service.client.MealServiceRpcClient; |
| 35 | import com.infoloop.tianting.service.client.MenuServiceRpcClient; | 37 | import com.infoloop.tianting.service.client.MenuServiceRpcClient; |
| 36 | import com.infoloop.tianting.service.client.OrderServiceRpcClient; | 38 | import com.infoloop.tianting.service.client.OrderServiceRpcClient; |
| ... | @@ -82,6 +84,7 @@ public class SettlementServiceImpl implements SettlementService { | ... | @@ -82,6 +84,7 @@ public class SettlementServiceImpl implements SettlementService { |
| 82 | private final ClientInventoryServiceRpcClient clientInventoryServiceRpcClient; | 84 | private final ClientInventoryServiceRpcClient clientInventoryServiceRpcClient; |
| 83 | private final MealServiceRpcClient mealServiceRpcClient; | 85 | private final MealServiceRpcClient mealServiceRpcClient; |
| 84 | private final ClientCustomerServiceRpcClient clientCustomerServiceRpcClient; | 86 | private final ClientCustomerServiceRpcClient clientCustomerServiceRpcClient; |
| 87 | + private final ClientResourceTagServiceRpcClient clientResourceTagServiceRpcClient; | ||
| 85 | 88 | ||
| 86 | public static ByteArrayOutputStream writeToExcelBySku(SettlementDataDto settlementDataDto) | 89 | public static ByteArrayOutputStream writeToExcelBySku(SettlementDataDto settlementDataDto) |
| 87 | throws IOException { | 90 | throws IOException { |
| ... | @@ -311,6 +314,9 @@ public class SettlementServiceImpl implements SettlementService { | ... | @@ -311,6 +314,9 @@ public class SettlementServiceImpl implements SettlementService { |
| 311 | throw BusinessException.build(ErrorCodeEnum.GENERATE_EXCEL_ERROR); | 314 | throw BusinessException.build(ErrorCodeEnum.GENERATE_EXCEL_ERROR); |
| 312 | } | 315 | } |
| 313 | 316 | ||
| 317 | + final var loginInfo = LoginContextHolder.getLoginInfo(); | ||
| 318 | + final var userResources = clientResourceTagServiceRpcClient.getUserResources(loginInfo.getEnterpriseId(), loginInfo.getClientId(), loginInfo.getId()); | ||
| 319 | + | ||
| 314 | // 计算日期范围 | 320 | // 计算日期范围 |
| 315 | final var startDate = settlementRequest.getTimeStart().plusHours(8).toLocalDate().atStartOfDay(); | 321 | final var startDate = settlementRequest.getTimeStart().plusHours(8).toLocalDate().atStartOfDay(); |
| 316 | final var endDate = settlementRequest.getTimeEnd().plusHours(8).toLocalDate().plusDays(1).atStartOfDay(); | 322 | final var endDate = settlementRequest.getTimeEnd().plusHours(8).toLocalDate().plusDays(1).atStartOfDay(); |
| ... | @@ -319,6 +325,13 @@ public class SettlementServiceImpl implements SettlementService { | ... | @@ -319,6 +325,13 @@ public class SettlementServiceImpl implements SettlementService { |
| 319 | final var operatorLoginInfo = LoginContextHolder.getLoginInfo(); | 325 | final var operatorLoginInfo = LoginContextHolder.getLoginInfo(); |
| 320 | final int enterpriseId = LoginContextHolder.hasLogin() ? operatorLoginInfo.getEnterpriseId() : settlementRequest.getEnterpriseId(); | 326 | final int enterpriseId = LoginContextHolder.hasLogin() ? operatorLoginInfo.getEnterpriseId() : settlementRequest.getEnterpriseId(); |
| 321 | 327 | ||
| 328 | + final var stallIds = new ArrayList<Integer>(); | ||
| 329 | + if (CollectionUtil.isEmpty(settlementRequest.getStallIds())) { | ||
| 330 | + stallIds.addAll(userResources.getStallIdsList()); | ||
| 331 | + } else { | ||
| 332 | + stallIds.addAll(settlementRequest.getStallIds()); | ||
| 333 | + } | ||
| 334 | + | ||
| 322 | // 构建查询条件 | 335 | // 构建查询条件 |
| 323 | final var queryOrderDto = QueryOrderByConditionDto.builder() | 336 | final var queryOrderDto = QueryOrderByConditionDto.builder() |
| 324 | .enterpriseId(enterpriseId) | 337 | .enterpriseId(enterpriseId) |
| ... | @@ -326,8 +339,8 @@ public class SettlementServiceImpl implements SettlementService { | ... | @@ -326,8 +339,8 @@ public class SettlementServiceImpl implements SettlementService { |
| 326 | .mealTimeStart(startDate) | 339 | .mealTimeStart(startDate) |
| 327 | .shouldFilterMealTimeEnd(true) | 340 | .shouldFilterMealTimeEnd(true) |
| 328 | .mealTimeEnd(endDate) | 341 | .mealTimeEnd(endDate) |
| 329 | - .shouldFilterStallIds(settlementRequest.getStallIds() != null && !settlementRequest.getStallIds().isEmpty()) | 342 | + .shouldFilterStallIds(true) |
| 330 | - .stallIds(settlementRequest.getStallIds() != null ? settlementRequest.getStallIds() : Collections.emptyList()) | 343 | + .stallIds(stallIds) |
| 331 | .build(); | 344 | .build(); |
| 332 | 345 | ||
| 333 | // 查询订单列表 | 346 | // 查询订单列表 |
| ... | @@ -342,15 +355,14 @@ public class SettlementServiceImpl implements SettlementService { | ... | @@ -342,15 +355,14 @@ public class SettlementServiceImpl implements SettlementService { |
| 342 | .filter(Objects::nonNull) | 355 | .filter(Objects::nonNull) |
| 343 | .filter(o -> { | 356 | .filter(o -> { |
| 344 | // 在线支付订单需要支付成功 | 357 | // 在线支付订单需要支付成功 |
| 345 | - if (o.getOnlinePay() != null && o.getOnlinePay() == OnlinePayEnum.ONLINE) { | 358 | + if (o.getOnlinePay() == OnlinePayEnum.ONLINE) { |
| 346 | - return o.getPayStatus() != null && o.getPayStatus() == PayStatusEnum.SUCCEED; | 359 | + return o.getPayStatus() == PayStatusEnum.SUCCEED; |
| 347 | } else { | 360 | } else { |
| 348 | // 非在线支付订单需要未取消 | 361 | // 非在线支付订单需要未取消 |
| 349 | - return o.getStatus() != null && o.getStatus() != OrderStatusEnum.ORDER_CANCELED; | 362 | + return o.getStatus() != OrderStatusEnum.ORDER_CANCELED; |
| 350 | } | 363 | } |
| 351 | }) | 364 | }) |
| 352 | .map(SingleClientCustomerOrderRpcResponse::getId) | 365 | .map(SingleClientCustomerOrderRpcResponse::getId) |
| 353 | - .filter(Objects::nonNull) | ||
| 354 | .distinct() | 366 | .distinct() |
| 355 | .collect(Collectors.toList()); | 367 | .collect(Collectors.toList()); |
| 356 | 368 | ||
| ... | @@ -361,7 +373,6 @@ public class SettlementServiceImpl implements SettlementService { | ... | @@ -361,7 +373,6 @@ public class SettlementServiceImpl implements SettlementService { |
| 361 | 373 | ||
| 362 | // 构建订单映射 | 374 | // 构建订单映射 |
| 363 | final var orderMap = orderList.stream() | 375 | final var orderMap = orderList.stream() |
| 364 | - .filter(Objects::nonNull) | ||
| 365 | .filter(o -> o.getId() != 0) | 376 | .filter(o -> o.getId() != 0) |
| 366 | .collect(Collectors.toMap(SingleClientCustomerOrderRpcResponse::getId, o -> o, (o1, o2) -> o1)); | 377 | .collect(Collectors.toMap(SingleClientCustomerOrderRpcResponse::getId, o -> o, (o1, o2) -> o1)); |
| 367 | 378 | ||
| ... | @@ -375,15 +386,14 @@ public class SettlementServiceImpl implements SettlementService { | ... | @@ -375,15 +386,14 @@ public class SettlementServiceImpl implements SettlementService { |
| 375 | // 订单详情按订单ID分组 | 386 | // 订单详情按订单ID分组 |
| 376 | final var orderDetailGroupByOrderId = orderDetailList.stream() | 387 | final var orderDetailGroupByOrderId = orderDetailList.stream() |
| 377 | .filter(Objects::nonNull) | 388 | .filter(Objects::nonNull) |
| 378 | - .filter(d -> d.getServeStatus() != null && !d.getServeStatus().equals(ServeStatusEnum.SERVE_REJECT)) | 389 | + .filter(d -> !d.getServeStatus().equals(ServeStatusEnum.SERVE_REJECT)) |
| 379 | .collect(Collectors.groupingBy(SingleClientCustomerOrderDetailRpcResponse::getOrderId)); | 390 | .collect(Collectors.groupingBy(SingleClientCustomerOrderDetailRpcResponse::getOrderId)); |
| 380 | 391 | ||
| 381 | // 获取SKU数据 | 392 | // 获取SKU数据 |
| 382 | List<Integer> skuIds = orderDetailList.stream() | 393 | List<Integer> skuIds = orderDetailList.stream() |
| 383 | .filter(Objects::nonNull) | 394 | .filter(Objects::nonNull) |
| 384 | - .filter(d -> d.getServeStatus() != null && !d.getServeStatus().equals(ServeStatusEnum.SERVE_REJECT)) | 395 | + .filter(d -> !d.getServeStatus().equals(ServeStatusEnum.SERVE_REJECT)) |
| 385 | .map(SingleClientCustomerOrderDetailRpcResponse::getSkuId) | 396 | .map(SingleClientCustomerOrderDetailRpcResponse::getSkuId) |
| 386 | - .filter(Objects::nonNull) | ||
| 387 | .distinct() | 397 | .distinct() |
| 388 | .collect(Collectors.toList()); | 398 | .collect(Collectors.toList()); |
| 389 | 399 | ||
| ... | @@ -484,9 +494,12 @@ public class SettlementServiceImpl implements SettlementService { | ... | @@ -484,9 +494,12 @@ public class SettlementServiceImpl implements SettlementService { |
| 484 | String onlinePayDesc = getOnlinePayDescSafely(order); | 494 | String onlinePayDesc = getOnlinePayDescSafely(order); |
| 485 | 495 | ||
| 486 | // 构建订单详情 | 496 | // 构建订单详情 |
| 497 | + order.getOrderCode(); | ||
| 498 | + order.getRemark(); | ||
| 499 | + order.getAvoidRemark(); | ||
| 487 | SettlementDTO.SettlementOrderDetail settlementOrderDetail = SettlementDTO.SettlementOrderDetail.builder() | 500 | SettlementDTO.SettlementOrderDetail settlementOrderDetail = SettlementDTO.SettlementOrderDetail.builder() |
| 488 | .mealTime(order.getMealTime() != 0L ? LocalDateTimeUtil.of(order.getMealTime()).format(DateUtil.YYYY_MM_DD_LEFT_SYMBOL) : "") | 501 | .mealTime(order.getMealTime() != 0L ? LocalDateTimeUtil.of(order.getMealTime()).format(DateUtil.YYYY_MM_DD_LEFT_SYMBOL) : "") |
| 489 | - .code(order.getOrderCode() != null ? order.getOrderCode() : "") | 502 | + .code(order.getOrderCode()) |
| 490 | .mealName(mealName) | 503 | .mealName(mealName) |
| 491 | .roomNo(roomNo) | 504 | .roomNo(roomNo) |
| 492 | .customerName(customerName) | 505 | .customerName(customerName) |
| ... | @@ -498,8 +511,8 @@ public class SettlementServiceImpl implements SettlementService { | ... | @@ -498,8 +511,8 @@ public class SettlementServiceImpl implements SettlementService { |
| 498 | .count(orderDetail.getCount() != 0 ? orderDetail.getCount() : 0) | 511 | .count(orderDetail.getCount() != 0 ? orderDetail.getCount() : 0) |
| 499 | .price(calculatePrice(orderDetail.getPrice())) | 512 | .price(calculatePrice(orderDetail.getPrice())) |
| 500 | .totalPrice(calculateTotalPrice(orderDetail.getPrice(), orderDetail.getCount())) | 513 | .totalPrice(calculateTotalPrice(orderDetail.getPrice(), orderDetail.getCount())) |
| 501 | - .remark(order.getRemark() != null ? order.getRemark() : "") | 514 | + .remark(order.getRemark()) |
| 502 | - .avoidRemark(order.getAvoidRemark() != null ? order.getAvoidRemark() : "") | 515 | + .avoidRemark(order.getAvoidRemark()) |
| 503 | .onlinePay(onlinePayDesc) | 516 | .onlinePay(onlinePayDesc) |
| 504 | .build(); | 517 | .build(); |
| 505 | classifyOrders.add(settlementOrderDetail); | 518 | classifyOrders.add(settlementOrderDetail); |
| ... | @@ -536,7 +549,7 @@ public class SettlementServiceImpl implements SettlementService { | ... | @@ -536,7 +549,7 @@ public class SettlementServiceImpl implements SettlementService { |
| 536 | } | 549 | } |
| 537 | 550 | ||
| 538 | final var meal = mealMap.get(menuDetail.getMealId()); | 551 | final var meal = mealMap.get(menuDetail.getMealId()); |
| 539 | - return meal != null && meal.getName() != null ? meal.getName() : ""; | 552 | + return meal != null ? meal.getName() : ""; |
| 540 | } | 553 | } |
| 541 | 554 | ||
| 542 | /** | 555 | /** |
| ... | @@ -549,7 +562,7 @@ public class SettlementServiceImpl implements SettlementService { | ... | @@ -549,7 +562,7 @@ public class SettlementServiceImpl implements SettlementService { |
| 549 | } | 562 | } |
| 550 | 563 | ||
| 551 | final var sku = skuMap.get(orderDetail.getSkuId()); | 564 | final var sku = skuMap.get(orderDetail.getSkuId()); |
| 552 | - return sku != null && sku.getName() != null ? sku.getName() : ""; | 565 | + return sku != null ? sku.getName() : ""; |
| 553 | } | 566 | } |
| 554 | 567 | ||
| 555 | /** | 568 | /** |
| ... | @@ -561,43 +574,40 @@ public class SettlementServiceImpl implements SettlementService { | ... | @@ -561,43 +574,40 @@ public class SettlementServiceImpl implements SettlementService { |
| 561 | } | 574 | } |
| 562 | 575 | ||
| 563 | String syncRoomNo = order.getSyncRoomNo(); | 576 | String syncRoomNo = order.getSyncRoomNo(); |
| 564 | - if (syncRoomNo != null && !syncRoomNo.isEmpty()) { | 577 | + if (!syncRoomNo.isEmpty()) { |
| 565 | return syncRoomNo; | 578 | return syncRoomNo; |
| 566 | } | 579 | } |
| 567 | 580 | ||
| 568 | - String roomNo = order.getRoomNo(); | 581 | + return order.getRoomNo(); |
| 569 | - return roomNo != null ? roomNo : ""; | ||
| 570 | } | 582 | } |
| 571 | 583 | ||
| 572 | /** | 584 | /** |
| 573 | * 安全获取忌口列表 | 585 | * 安全获取忌口列表 |
| 574 | */ | 586 | */ |
| 575 | private List<String> getAvoidsSafely(SingleClientCustomerOrderRpcResponse order) { | 587 | private List<String> getAvoidsSafely(SingleClientCustomerOrderRpcResponse order) { |
| 576 | - if (order == null || order.getCustomerNoticeJson() == null) { | 588 | + if (order == null) { |
| 577 | return Collections.emptyList(); | 589 | return Collections.emptyList(); |
| 578 | } | 590 | } |
| 579 | 591 | ||
| 580 | - List<String> avoids = order.getCustomerNoticeJson().getAvoidsList(); | 592 | + return order.getCustomerNoticeJson().getAvoidsList(); |
| 581 | - return avoids != null ? avoids : Collections.emptyList(); | ||
| 582 | } | 593 | } |
| 583 | 594 | ||
| 584 | /** | 595 | /** |
| 585 | * 安全获取医嘱列表 | 596 | * 安全获取医嘱列表 |
| 586 | */ | 597 | */ |
| 587 | private List<String> getDoctorsSafely(SingleClientCustomerOrderRpcResponse order) { | 598 | private List<String> getDoctorsSafely(SingleClientCustomerOrderRpcResponse order) { |
| 588 | - if (order == null || order.getCustomerNoticeJson() == null) { | 599 | + if (order == null) { |
| 589 | return Collections.emptyList(); | 600 | return Collections.emptyList(); |
| 590 | } | 601 | } |
| 591 | 602 | ||
| 592 | - List<String> doctors = order.getCustomerNoticeJson().getDoctorsList(); | 603 | + return order.getCustomerNoticeJson().getDoctorsList(); |
| 593 | - return doctors != null ? doctors : Collections.emptyList(); | ||
| 594 | } | 604 | } |
| 595 | 605 | ||
| 596 | /** | 606 | /** |
| 597 | * 安全获取在线支付描述 | 607 | * 安全获取在线支付描述 |
| 598 | */ | 608 | */ |
| 599 | private String getOnlinePayDescSafely(SingleClientCustomerOrderRpcResponse order) { | 609 | private String getOnlinePayDescSafely(SingleClientCustomerOrderRpcResponse order) { |
| 600 | - if (order == null || order.getOnlinePay() == null) { | 610 | + if (order == null) { |
| 601 | return ""; | 611 | return ""; |
| 602 | } | 612 | } |
| 603 | 613 | ... | ... |
-
Please register or login to post a comment