您的位置:首页 > 新闻 > 资讯 > 商城网站设计目标_学院网站设计案例_seo外包服务公司_网站排名优化专业定制

商城网站设计目标_学院网站设计案例_seo外包服务公司_网站排名优化专业定制

2025/4/21 19:53:39 来源:https://blog.csdn.net/weixin_66907051/article/details/147269917  浏览:    关键词:商城网站设计目标_学院网站设计案例_seo外包服务公司_网站排名优化专业定制
商城网站设计目标_学院网站设计案例_seo外包服务公司_网站排名优化专业定制
背景

因邮件数据过多,因此采用了分表的方式来进行存储, 支持按照天、周、月来分表以下为设计的方法

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList;
import java.util.List;public class IndexSuffixCalculator {// 按天格式化日期的模式private static final DateTimeFormatter DAY_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");// 按周格式化日期的模式private static final DateTimeFormatter WEEK_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");// 按月格式化日期的模式private static final DateTimeFormatter MONTH_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM");/*** 根据时间范围和配置计算索引后缀** @param startDate 开始日期* @param endDate   结束日期* @param mode      配置模式:day, week 或 month* @return 索引后缀列表*/public List<String> calculateIndexSuffixes(LocalDate startDate, LocalDate endDate, String mode) {if ("day".equalsIgnoreCase(mode)) {return calculateDailySuffixes(startDate, endDate);} else if ("week".equalsIgnoreCase(mode)) {return calculateWeeklySuffixes(startDate, endDate);} else if ("month".equalsIgnoreCase(mode)) {return calculateMonthlySuffixes(startDate, endDate);} else {throw new IllegalArgumentException("Unsupported mode: " + mode);}}/*** 按天计算索引后缀** @param startDate 开始日期* @param endDate   结束日期* @return 按天的索引后缀列表*/private List<String> calculateDailySuffixes(LocalDate startDate, LocalDate endDate) {List<String> suffixes = new ArrayList<>();LocalDate currentDate = startDate;while (!currentDate.isAfter(endDate)) {suffixes.add(currentDate.format(DAY_FORMATTER));currentDate = currentDate.plusDays(1); // 移动到下一天}return suffixes;}/*** 按周计算索引后缀** @param startDate 开始日期* @param endDate   结束日期* @return 按周的索引后缀列表*/private List<String> calculateWeeklySuffixes(LocalDate startDate, LocalDate endDate) {List<String> suffixes = new ArrayList<>();LocalDate currentDate = startDate.with(TemporalAdjusters.previousOrSame(java.time.DayOfWeek.MONDAY));while (!currentDate.isAfter(endDate)) {suffixes.add(currentDate.format(WEEK_FORMATTER));currentDate = currentDate.plusWeeks(1); // 移动到下一周的周一}return suffixes;}/*** 按月计算索引后缀** @param startDate 开始日期* @param endDate   结束日期* @return 按月的索引后缀列表*/private List<String> calculateMonthlySuffixes(LocalDate startDate, LocalDate endDate) {List<String> suffixes = new ArrayList<>();LocalDate currentDate = startDate.with(TemporalAdjusters.firstDayOfMonth());while (!currentDate.isAfter(endDate)) {suffixes.add(currentDate.format(MONTH_FORMATTER));currentDate = currentDate.plusMonths(1); // 移动到下一个月的第一天}return suffixes;}public static void main(String[] args) {// 测试用例LocalDate startDate = LocalDate.of(2025, 4, 1);LocalDate endDate = LocalDate.of(2025, 6, 30);IndexSuffixCalculator calculator = new IndexSuffixCalculator();// 按天计算List<String> dailySuffixes = calculator.calculateIndexSuffixes(startDate, endDate, "day");System.out.println("Daily Suffixes: " + dailySuffixes);// 按周计算List<String> weeklySuffixes = calculator.calculateIndexSuffixes(startDate, endDate, "week");System.out.println("Weekly Suffixes: " + weeklySuffixes);// 按月计算List<String> monthlySuffixes = calculator.calculateIndexSuffixes(startDate, endDate, "month");System.out.println("Monthly Suffixes: " + monthlySuffixes);}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com