demand: 月结客户达标统计时间段格式改为yyyy-MM

This commit is contained in:
aike 2026-02-12 11:12:38 +08:00
parent c3dc8ae7f2
commit d8853d8d17
2 changed files with 17 additions and 15 deletions

View File

@ -11,7 +11,7 @@
package com.xdadan.erp.emis.service.impl; package com.xdadan.erp.emis.service.impl;
import java.util.*; import java.util.*;
import java.time.LocalDate; import java.time.YearMonth;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -188,10 +188,10 @@ public class EmisCustomerUserServiceImpl extends EmisBaseService implements IEmi
// 校验:当complianceStatType=3/4/5/6时,寄件时间段需大于等于3个月 // 校验:当complianceStatType=3/4/5/6时,寄件时间段需大于等于3个月
checkDateForComplianceStat(emisWaybill); checkDateForComplianceStat(emisWaybill);
if(Objects.isNull(emisWaybill.getParams().get("beginSendDate"))){ 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"))){ 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"); Object complianceStatTypeObj = emisWaybill.getParams().get("complianceStatType");
@ -273,14 +273,16 @@ public class EmisCustomerUserServiceImpl extends EmisBaseService implements IEmi
String beginSendDate = String.valueOf(beginSendObj).trim(); String beginSendDate = String.valueOf(beginSendObj).trim();
String endSendDate = String.valueOf(endSendObj).trim(); String endSendDate = String.valueOf(endSendObj).trim();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); DateTimeFormatter monthFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
LocalDate beginDate = LocalDate.parse(beginSendDate, formatter); // 验证格式是否为 yyyy-MM
LocalDate endDate = LocalDate.parse(endSendDate, formatter); monthFormatter.parse(beginSendDate);
monthFormatter.parse(endSendDate);
// 解析为 YearMonth 来计算月份差
YearMonth beginMonth = YearMonth.parse(beginSendDate, monthFormatter);
YearMonth endMonth = YearMonth.parse(endSendDate, monthFormatter);
long monthsBetween = ChronoUnit.MONTHS.between( // 计算月份差,应大于等于3个月
beginDate.withDayOfMonth(1), long monthsBetween = ChronoUnit.MONTHS.between(beginMonth, endMonth) + 1L;
endDate.withDayOfMonth(1)
) + 1L;
if (monthsBetween < 3) { if (monthsBetween < 3) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, throw new EmisBizError(EmisBizErrorType.PARAM_ERROR,
@ -290,7 +292,7 @@ public class EmisCustomerUserServiceImpl extends EmisBaseService implements IEmi
if (e instanceof EmisBizError) { if (e instanceof EmisBizError) {
throw e; throw e;
} }
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "日期格式错误,请使用yyyy-MM-dd HH:mm:ss格式"); throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "日期格式错误,请使用yyyy-MM格式");
} }
} }
} }

View File

@ -732,8 +732,8 @@
FROM emis_customer_user cu FROM emis_customer_user cu
JOIN ( JOIN (
SELECT 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(CONCAT(#{params.beginSendDate}, '-01'), '%Y-%m-%d'), 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-01') AS monthStart
FROM ( 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 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 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 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 SELECT 36
) n ) n
WHERE DATE_ADD(STR_TO_DATE(#{params.beginSendDate}, '%Y-%m-%d %H:%i:%s'), INTERVAL n.n MONTH) WHERE DATE_ADD(STR_TO_DATE(CONCAT(#{params.beginSendDate}, '-01'), '%Y-%m-%d'), INTERVAL n.n MONTH)
<![CDATA[ <= ]]> STR_TO_DATE(#{params.endSendDate}, '%Y-%m-%d %H:%i:%s') <![CDATA[ <= ]]> STR_TO_DATE(CONCAT(#{params.endSendDate}, '-01'), '%Y-%m-%d')
) m ) m
LEFT JOIN emis_waybill a LEFT JOIN emis_waybill a
ON cu.monthly_pay_code = a.cust_no ON cu.monthly_pay_code = a.cust_no