feat(settlement): 添加分餐表空数据Excel生成功能
- 引入ZoneId用于获取今日起始时间戳- 过滤订单列表,仅保留今日及以后且支付状态为成功或取消的订单 - 在订单列表或详情为空时,返回空的分餐表Excel文件 - 新增createEmptyExcelBySeparateMeal方法用于生成空数据Excel - 使用SeparateMealDataDto构建空数据并写入Excel输出流
Showing
1 changed file
with
34 additions
and
3 deletions
| ... | @@ -61,6 +61,7 @@ import java.math.BigDecimal; | ... | @@ -61,6 +61,7 @@ import java.math.BigDecimal; |
| 61 | import java.math.RoundingMode; | 61 | import java.math.RoundingMode; |
| 62 | import java.time.LocalDate; | 62 | import java.time.LocalDate; |
| 63 | import java.time.LocalDateTime; | 63 | import java.time.LocalDateTime; |
| 64 | +import java.time.ZoneId; | ||
| 64 | import java.time.temporal.ChronoUnit; | 65 | import java.time.temporal.ChronoUnit; |
| 65 | import java.util.ArrayList; | 66 | import java.util.ArrayList; |
| 66 | import java.util.Collections; | 67 | import java.util.Collections; |
| ... | @@ -1124,10 +1125,25 @@ public class SettlementServiceImpl implements SettlementService { | ... | @@ -1124,10 +1125,25 @@ public class SettlementServiceImpl implements SettlementService { |
| 1124 | 1125 | ||
| 1125 | // 查询订单列表 | 1126 | // 查询订单列表 |
| 1126 | final var queryClientCustomerOrdersByConditionRpcResponse = orderServiceRpcClient.queryClientCustomerOrdersByCondition(queryOrderDto); | 1127 | final var queryClientCustomerOrdersByConditionRpcResponse = orderServiceRpcClient.queryClientCustomerOrdersByCondition(queryOrderDto); |
| 1127 | - final var orderList = queryClientCustomerOrdersByConditionRpcResponse.getResponsesList(); | 1128 | + |
| 1129 | + // 今天开始时间的时间戳(毫秒) | ||
| 1130 | + final long todayStartTimestamp = LocalDate.now().atStartOfDay() | ||
| 1131 | + .atZone(ZoneId.systemDefault()) | ||
| 1132 | + .toInstant() | ||
| 1133 | + .toEpochMilli(); | ||
| 1134 | + | ||
| 1135 | + final var orderList = queryClientCustomerOrdersByConditionRpcResponse.getResponsesList() | ||
| 1136 | + .stream() | ||
| 1137 | + .filter(e -> { | ||
| 1138 | + boolean payStatusMatch = e.getPayStatus() == PayStatusEnum.SUCCEED|| e.getPayStatus() == PayStatusEnum.PAY_CANCELED; | ||
| 1139 | + // 过滤时间:只查询今天和以后的订单 | ||
| 1140 | + boolean timeMatch = e.getMealTime() >= todayStartTimestamp; | ||
| 1141 | + return payStatusMatch && timeMatch; | ||
| 1142 | + }) | ||
| 1143 | + .toList(); | ||
| 1128 | if (orderList.isEmpty()) { | 1144 | if (orderList.isEmpty()) { |
| 1129 | log.warn("未查询到订单数据,enterpriseId: {}", enterpriseId); | 1145 | log.warn("未查询到订单数据,enterpriseId: {}", enterpriseId); |
| 1130 | - return null; | 1146 | + return createEmptyExcelBySeparateMeal(); |
| 1131 | } | 1147 | } |
| 1132 | 1148 | ||
| 1133 | // 获取订单IDs | 1149 | // 获取订单IDs |
| ... | @@ -1145,7 +1161,7 @@ public class SettlementServiceImpl implements SettlementService { | ... | @@ -1145,7 +1161,7 @@ public class SettlementServiceImpl implements SettlementService { |
| 1145 | final var orderDetailList = orderServiceRpcClient.getOrderDetailsByOrderIds(orderIds); | 1161 | final var orderDetailList = orderServiceRpcClient.getOrderDetailsByOrderIds(orderIds); |
| 1146 | if (orderDetailList == null || orderDetailList.isEmpty()) { | 1162 | if (orderDetailList == null || orderDetailList.isEmpty()) { |
| 1147 | log.warn("未查询到订单详情数据,orderIds: {}", orderIds); | 1163 | log.warn("未查询到订单详情数据,orderIds: {}", orderIds); |
| 1148 | - return null; | 1164 | + return createEmptyExcelBySeparateMeal(); |
| 1149 | } | 1165 | } |
| 1150 | 1166 | ||
| 1151 | // 订单详情按订单ID分组 | 1167 | // 订单详情按订单ID分组 |
| ... | @@ -1443,4 +1459,19 @@ public class SettlementServiceImpl implements SettlementService { | ... | @@ -1443,4 +1459,19 @@ public class SettlementServiceImpl implements SettlementService { |
| 1443 | return outputStream; | 1459 | return outputStream; |
| 1444 | } | 1460 | } |
| 1445 | 1461 | ||
| 1462 | + /** | ||
| 1463 | + * 创建空的分餐表Excel(无数据) | ||
| 1464 | + */ | ||
| 1465 | + private static ByteArrayOutputStream createEmptyExcelBySeparateMeal() { | ||
| 1466 | + try { | ||
| 1467 | + SeparateMealDataDto emptyData = SeparateMealDataDto.builder() | ||
| 1468 | + .mealDetails(new ArrayList<>()) | ||
| 1469 | + .build(); | ||
| 1470 | + return writeToExcelBySeparateMeal(emptyData); | ||
| 1471 | + } catch (IOException e) { | ||
| 1472 | + log.error("创建空分餐表Excel失败", e); | ||
| 1473 | + throw BusinessException.build(ErrorCodeEnum.GENERATE_EXCEL_ERROR); | ||
| 1474 | + } | ||
| 1475 | + } | ||
| 1476 | + | ||
| 1446 | } | 1477 | } | ... | ... |
-
Please register or login to post a comment