更新数据同步
This commit is contained in:
41
src/main/java/com/mini/capi/Dao/DateInfo.java
Normal file
41
src/main/java/com/mini/capi/Dao/DateInfo.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package com.mini.capi.Dao;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class DateInfo implements Serializable {
|
||||
|
||||
private String queryDate; // 查询日期(yyyy-MM-dd)
|
||||
|
||||
// 农历信息字段
|
||||
private String fullChineseDate; // 完整农历(如:二零二六年正月十八)
|
||||
private Integer chineseYear; // 农历年(如:二零二六年)
|
||||
private String chineseMonth; // 农历月(如:正月)
|
||||
private String chineseDay; // 农历日(如:十八)
|
||||
private String chineseZodiac; // 生肖(如:马)
|
||||
|
||||
// 星期/周末状态字段
|
||||
private int dayOfWeekNum; // 星期数字(1=周日,7=周六)
|
||||
private String dayOfWeek; // 中文星期(如:周一)
|
||||
private boolean isWeekend; // 是否为周末
|
||||
private boolean isAdjustWorkday; // 是否为调休工作日
|
||||
|
||||
public DateInfo() {
|
||||
}
|
||||
|
||||
public DateInfo(String queryDate, String fullChineseDate, Integer chineseYear, String chineseMonth, String chineseDay, String chineseZodiac, int dayOfWeekNum, String dayOfWeek, boolean isWeekend, boolean isAdjustWorkday) {
|
||||
// 为成员变量赋值
|
||||
this.queryDate = queryDate;
|
||||
this.fullChineseDate = fullChineseDate;
|
||||
this.chineseYear = chineseYear;
|
||||
this.chineseMonth = chineseMonth;
|
||||
this.chineseDay = chineseDay;
|
||||
this.chineseZodiac = chineseZodiac;
|
||||
this.dayOfWeekNum = dayOfWeekNum;
|
||||
this.dayOfWeek = dayOfWeek;
|
||||
this.isWeekend = isWeekend;
|
||||
this.isAdjustWorkday = isAdjustWorkday;
|
||||
}
|
||||
}
|
||||
54
src/main/java/com/mini/capi/utils/DateUtils.java
Normal file
54
src/main/java/com/mini/capi/utils/DateUtils.java
Normal file
@@ -0,0 +1,54 @@
|
||||
package com.mini.capi.utils;
|
||||
|
||||
import cn.hutool.core.date.ChineseDate;
|
||||
import com.mini.capi.Dao.DateInfo;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 日期工具类 - 支持指定日期查询基础信息、农历、周末状态等
|
||||
* 输入格式:yyyy-MM-dd(如2026-01-26)
|
||||
*/
|
||||
public class DateUtils {
|
||||
|
||||
private static final SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd");
|
||||
private static final String[] CHINESE_WEEK = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static DateInfo getDateInfo(String dateStr) {
|
||||
try {
|
||||
Date targetDate = DATE_FORMATTER.parse(dateStr);
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(targetDate);
|
||||
String queryDate = DATE_FORMATTER.format(targetDate);
|
||||
ChineseDate chineseDate = new ChineseDate(targetDate);
|
||||
String fullChineseDate = chineseDate.toString();
|
||||
Integer chineseYear = chineseDate.getChineseYear();
|
||||
String chineseMonth = chineseDate.getChineseMonth();
|
||||
String chineseDay = chineseDate.getChineseDay();
|
||||
String chineseZodiac = chineseDate.getChineseZodiac();
|
||||
int dayOfWeekNum = calendar.get(Calendar.DAY_OF_WEEK);
|
||||
String dayOfWeek = CHINESE_WEEK[dayOfWeekNum - 1];
|
||||
boolean isWeekend = dayOfWeekNum == Calendar.SUNDAY || dayOfWeekNum == Calendar.SATURDAY;
|
||||
boolean isAdjustWorkday = false;
|
||||
return new DateInfo(
|
||||
queryDate, // 查询日期(yyyy-MM-dd)
|
||||
fullChineseDate, // 完整农历
|
||||
chineseYear, // 农历年
|
||||
chineseMonth, // 农历月
|
||||
chineseDay, // 农历日
|
||||
chineseZodiac, // 生肖
|
||||
dayOfWeekNum, // 星期数字(1=周日,7=周六)
|
||||
dayOfWeek, // 中文星期
|
||||
isWeekend, // 是否为周末
|
||||
isAdjustWorkday // 是否为调休工作日
|
||||
);
|
||||
} catch (Exception e) {
|
||||
return new DateInfo();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user