| | |
| | | public class PurchaseAgentTools { |
| | | |
| | | private static final DateTimeFormatter DATE_FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | private static final ZoneId CHINA_ZONE_ID = ZoneId.of("Asia/Shanghai"); |
| | | private static final int DEFAULT_LIMIT = 10; |
| | | private static final int MAX_LIMIT = 30; |
| | | |
| | |
| | | .sorted(Comparator.comparing(item -> (BigDecimal) item.get("pendingAmount"), Comparator.reverseOrder())) |
| | | .limit(normalizeLimit(limit)) |
| | | .collect(Collectors.toList()); |
| | | |
| | | BigDecimal totalContractAmount = items.stream() |
| | | .map(item -> asBigDecimal(item.get("contractAmount"))) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal totalPaidAmount = items.stream() |
| | | .map(item -> asBigDecimal(item.get("paidAmount"))) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal totalPendingAmount = items.stream() |
| | | .map(item -> asBigDecimal(item.get("pendingAmount"))) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | Map<String, Object> summary = rangeSummary(range, items.size()); |
| | | summary.put("pendingOrderCount", items.size()); |
| | | summary.put("totalContractAmount", totalContractAmount); |
| | | summary.put("totalPaidAmount", totalPaidAmount); |
| | | summary.put("totalPendingAmount", totalPendingAmount); |
| | | |
| | | return jsonResponse(true, "purchase_pending_payment_list", "已返回待付款采购单。", |
| | | rangeSummary(range, items.size()), Map.of("items", items), Map.of()); |
| | | summary, Map.of("items", items), Map.of()); |
| | | } |
| | | |
| | | @Tool(name = "查询采购退货情况", value = "按时间范围查询采购退货单列表和退货金额。") |
| | |
| | | return value == null ? BigDecimal.ZERO : value; |
| | | } |
| | | |
| | | private BigDecimal asBigDecimal(Object value) { |
| | | if (value == null) { |
| | | return BigDecimal.ZERO; |
| | | } |
| | | if (value instanceof BigDecimal decimal) { |
| | | return decimal; |
| | | } |
| | | if (value instanceof Number number) { |
| | | return new BigDecimal(String.valueOf(number)); |
| | | } |
| | | return BigDecimal.ZERO; |
| | | } |
| | | |
| | | private List<PaymentRegistration> queryPayments(LoginUser loginUser, DateRange range) { |
| | | LambdaQueryWrapper<PaymentRegistration> wrapper = new LambdaQueryWrapper<>(); |
| | | applyTenantFilter(wrapper, loginUser.getTenantId(), PaymentRegistration::getTenantId); |
| | |
| | | } |
| | | |
| | | private DateRange resolveDateRange(String startDate, String endDate, String timeRange) { |
| | | LocalDate today = LocalDate.now(); |
| | | LocalDate today = LocalDate.now(CHINA_ZONE_ID); |
| | | LocalDate start = parseLocalDate(startDate); |
| | | LocalDate end = parseLocalDate(endDate); |
| | | if (start != null || end != null) { |
| | |
| | | return new DateRange(today.minusDays(29), today, "近30天"); |
| | | } |
| | | String text = timeRange.trim(); |
| | | if (text.contains("今天")) { |
| | | return new DateRange(today, today, "今天"); |
| | | } |
| | | if (text.contains("昨天")) { |
| | | LocalDate yesterday = today.minusDays(1); |
| | | return new DateRange(yesterday, yesterday, "昨天"); |
| | | } |
| | | if (text.contains("本周")) { |
| | | LocalDate startOfWeek = today.minusDays(today.getDayOfWeek().getValue() - 1L); |
| | | return new DateRange(startOfWeek, today, "本周"); |
| | | } |
| | | if (text.contains("上周")) { |
| | | LocalDate thisWeekStart = today.minusDays(today.getDayOfWeek().getValue() - 1L); |
| | | LocalDate startOfLastWeek = thisWeekStart.minusWeeks(1); |
| | | return new DateRange(startOfLastWeek, startOfLastWeek.plusDays(6), "上周"); |
| | | } |
| | | if (text.contains("今年") || text.contains("本年")) { |
| | | return new DateRange(today.withDayOfYear(1), today, "今年"); |
| | | } |
| | |
| | | if (!StringUtils.hasText(text)) { |
| | | return null; |
| | | } |
| | | return LocalDate.parse(text.trim(), DATE_FMT); |
| | | try { |
| | | return LocalDate.parse(text.trim(), DATE_FMT); |
| | | } catch (Exception ignored) { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | private Date toDate(LocalDate localDate) { |