From d8853d8d178a1cbb0dc6dbcda75fbcae71c09e41 Mon Sep 17 00:00:00 2001 From: aike <17730485278@139.com> Date: Thu, 12 Feb 2026 11:12:38 +0800 Subject: [PATCH] =?UTF-8?q?demand:=20=20=20=E6=9C=88=E7=BB=93=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E8=BE=BE=E6=A0=87=E7=BB=9F=E8=AE=A1=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E6=AE=B5=E6=A0=BC=E5=BC=8F=E6=94=B9=E4=B8=BAyyyy-MM?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/EmisCustomerUserServiceImpl.java | 24 ++++++++++--------- .../mapper/EmisCustomerUserMapper.xml | 8 +++---- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisCustomerUserServiceImpl.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisCustomerUserServiceImpl.java index 11e5b71ba..c2d6bfc72 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisCustomerUserServiceImpl.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisCustomerUserServiceImpl.java @@ -11,7 +11,7 @@ package com.xdadan.erp.emis.service.impl; import java.util.*; -import java.time.LocalDate; +import java.time.YearMonth; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; import java.util.stream.Collectors; @@ -188,10 +188,10 @@ public class EmisCustomerUserServiceImpl extends EmisBaseService implements IEmi // 校验:当complianceStatType=3/4/5/6时,寄件时间段需大于等于3个月 checkDateForComplianceStat(emisWaybill); if(Objects.isNull(emisWaybill.getParams().get("beginSendDate"))){ - emisWaybill.getParams().put("beginSendDate","2024-01-01 00:00:00"); + emisWaybill.getParams().put("beginSendDate","2024-01"); } if(Objects.isNull(emisWaybill.getParams().get("endSendDate"))){ - emisWaybill.getParams().put("endSendDate", DateUtils.getDate("yyyy-MM-dd HH:mm:ss")); + emisWaybill.getParams().put("endSendDate", DateUtils.getDate("yyyy-MM")); } Object complianceStatTypeObj = emisWaybill.getParams().get("complianceStatType"); @@ -273,14 +273,16 @@ public class EmisCustomerUserServiceImpl extends EmisBaseService implements IEmi String beginSendDate = String.valueOf(beginSendObj).trim(); String endSendDate = String.valueOf(endSendObj).trim(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - LocalDate beginDate = LocalDate.parse(beginSendDate, formatter); - LocalDate endDate = LocalDate.parse(endSendDate, formatter); + DateTimeFormatter monthFormatter = DateTimeFormatter.ofPattern("yyyy-MM"); + // 验证格式是否为 yyyy-MM + monthFormatter.parse(beginSendDate); + monthFormatter.parse(endSendDate); + // 解析为 YearMonth 来计算月份差 + YearMonth beginMonth = YearMonth.parse(beginSendDate, monthFormatter); + YearMonth endMonth = YearMonth.parse(endSendDate, monthFormatter); - long monthsBetween = ChronoUnit.MONTHS.between( - beginDate.withDayOfMonth(1), - endDate.withDayOfMonth(1) - ) + 1L; + // 计算月份差,应大于等于3个月 + long monthsBetween = ChronoUnit.MONTHS.between(beginMonth, endMonth) + 1L; if (monthsBetween < 3) { throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, @@ -290,7 +292,7 @@ public class EmisCustomerUserServiceImpl extends EmisBaseService implements IEmi if (e instanceof EmisBizError) { throw e; } - throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "日期格式错误,请使用yyyy-MM-dd HH:mm:ss格式"); + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "日期格式错误,请使用yyyy-MM格式"); } } } diff --git a/emis-biz/src/main/resources/mapper/EmisCustomerUserMapper.xml b/emis-biz/src/main/resources/mapper/EmisCustomerUserMapper.xml index 318b3fe1d..8b2622b7d 100644 --- a/emis-biz/src/main/resources/mapper/EmisCustomerUserMapper.xml +++ b/emis-biz/src/main/resources/mapper/EmisCustomerUserMapper.xml @@ -732,8 +732,8 @@ FROM emis_customer_user cu JOIN ( SELECT - DATE_FORMAT(DATE_ADD(STR_TO_DATE(#{params.beginSendDate}, '%Y-%m-%d %H:%i:%s'), INTERVAL n.n MONTH), '%Y-%m') AS sendMonth, - DATE_FORMAT(DATE_ADD(STR_TO_DATE(#{params.beginSendDate}, '%Y-%m-%d %H:%i:%s'), INTERVAL n.n MONTH), '%Y-%m-01') AS monthStart + DATE_FORMAT(DATE_ADD(STR_TO_DATE(CONCAT(#{params.beginSendDate}, '-01'), '%Y-%m-%d'), INTERVAL n.n MONTH), '%Y-%m') AS sendMonth, + DATE_FORMAT(DATE_ADD(STR_TO_DATE(CONCAT(#{params.beginSendDate}, '-01'), '%Y-%m-%d'), INTERVAL n.n MONTH), '%Y-%m-01') AS monthStart FROM ( SELECT 0 AS n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL SELECT 10 UNION ALL SELECT 11 UNION ALL @@ -743,8 +743,8 @@ SELECT 30 UNION ALL SELECT 31 UNION ALL SELECT 32 UNION ALL SELECT 33 UNION ALL SELECT 34 UNION ALL SELECT 35 UNION ALL SELECT 36 ) n - WHERE DATE_ADD(STR_TO_DATE(#{params.beginSendDate}, '%Y-%m-%d %H:%i:%s'), INTERVAL n.n MONTH) - STR_TO_DATE(#{params.endSendDate}, '%Y-%m-%d %H:%i:%s') + WHERE DATE_ADD(STR_TO_DATE(CONCAT(#{params.beginSendDate}, '-01'), '%Y-%m-%d'), INTERVAL n.n MONTH) + STR_TO_DATE(CONCAT(#{params.endSendDate}, '-01'), '%Y-%m-%d') ) m LEFT JOIN emis_waybill a ON cu.monthly_pay_code = a.cust_no