7 changed files with 753 additions and 8 deletions
-
484xujie-common/src/main/java/com/xujie/common/utils/DateUtil.java
-
47xujie-pms/src/main/java/com/xujie/pms/controller/EamController.java
-
51xujie-pms/src/main/java/com/xujie/pms/data/EamWorkPlanInData.java
-
15xujie-pms/src/main/java/com/xujie/pms/mapper/EamMapper.java
-
33xujie-pms/src/main/java/com/xujie/pms/service/EamService.java
-
99xujie-pms/src/main/java/com/xujie/pms/service/Impl/EamServiceImpl.java
-
32xujie-pms/src/main/resources/mapper/EamMapper.xml
@ -0,0 +1,484 @@ |
|||
package com.xujie.common.utils; |
|||
|
|||
import java.text.DecimalFormat; |
|||
import java.text.ParseException; |
|||
import java.text.SimpleDateFormat; |
|||
import java.time.LocalDate; |
|||
import java.time.temporal.ChronoUnit; |
|||
import java.util.*; |
|||
import java.util.stream.Collectors; |
|||
import java.util.stream.Stream; |
|||
|
|||
public class DateUtil { |
|||
/** |
|||
* 将时间转为小数 |
|||
* |
|||
* @param date |
|||
* @return |
|||
*/ |
|||
public static double getTimeforDoule(Date date) { |
|||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); |
|||
String start = sdf.format(date); |
|||
String[] strs = start.split(":"); |
|||
int a = Integer.parseInt(strs[0]); |
|||
int b = Integer.parseInt(strs[1]); |
|||
DecimalFormat df = new DecimalFormat("0.00"); |
|||
String num = df.format((float) b / 60); |
|||
double c = Double.valueOf(num).doubleValue(); |
|||
double d = a + c; |
|||
return d; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* @author LR |
|||
* @Description: 获取当前时间的年月日时分秒 |
|||
* @UpdateUser LR |
|||
* @UpdateRemark [说明本次修改内容] |
|||
*/ |
|||
public static String getStringNow() { |
|||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|||
return sdf.format(new Date()); |
|||
} |
|||
|
|||
/** |
|||
* @param @param date |
|||
* @param @return 设定文件 |
|||
* @return String 返回类型 |
|||
* @throws |
|||
* @Title: getStringDate |
|||
* @author LR |
|||
* @Description: 返回String类型的yyyy-MM-dd的日期 |
|||
*/ |
|||
public static String getStringDate(Date date) { |
|||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
|||
return sdf.format(date); |
|||
} |
|||
|
|||
/** |
|||
* 获取日期戳 |
|||
* |
|||
* @param date |
|||
* @return |
|||
*/ |
|||
public static String getSDate(Date date) { |
|||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); |
|||
return sdf.format(date); |
|||
} |
|||
|
|||
/** |
|||
* 获取时间戳 |
|||
* |
|||
* @param date |
|||
* @return |
|||
*/ |
|||
public static String getSTime(Date date) { |
|||
SimpleDateFormat sdf = new SimpleDateFormat("HHmmss"); |
|||
return sdf.format(date); |
|||
} |
|||
|
|||
/** |
|||
* @param @param date |
|||
* @param @param parten |
|||
* @param @return 设定文件 |
|||
* @return String 返回类型 |
|||
* @throws |
|||
* @Title: getStringDate |
|||
* @author LR |
|||
* @Description: 根据模版获取相应时间的格式 |
|||
*/ |
|||
public static String getStringDate(Date date, String parten) { |
|||
SimpleDateFormat sdf = new SimpleDateFormat(parten); |
|||
return sdf.format(date); |
|||
} |
|||
|
|||
/** |
|||
* @param @return 设定文件 |
|||
* @return String 返回类型 |
|||
* @throws |
|||
* @Title: getYesterday |
|||
* @author LR |
|||
* @Description: 获取昨日的String类型的yyyy-MM-dd的日期 |
|||
*/ |
|||
public static String getStringYesterday() { |
|||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
|||
Calendar cal = Calendar.getInstance(); |
|||
cal.add(Calendar.DAY_OF_MONTH, -1); |
|||
return sdf.format(cal.getTime()); |
|||
} |
|||
|
|||
/** |
|||
* @param @return 设定文件 |
|||
* @return String 返回类型 |
|||
* @throws |
|||
* @Title: getYesterday |
|||
* @author LR |
|||
* @Description: 获取明天的String类型的yyyy-MM-dd的日期 |
|||
*/ |
|||
public static String getStringTomorrow() { |
|||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
|||
Calendar cal = Calendar.getInstance(); |
|||
cal.add(Calendar.DAY_OF_MONTH, +1); |
|||
return sdf.format(cal.getTime()); |
|||
} |
|||
|
|||
/** |
|||
* @throws ParseException |
|||
* @author LR |
|||
* @Description: String转换date |
|||
* @UpdateUser LR |
|||
* @UpdateRemark [说明本次修改内容] |
|||
*/ |
|||
public static Date getDate(String time) throws ParseException { |
|||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
|||
return sdf.parse(time); |
|||
|
|||
} |
|||
|
|||
/** |
|||
* @throws |
|||
* @author RQ |
|||
* @Description: String转换date |
|||
* @UpdateUser rq |
|||
* @UpdateRemark [说明本次修改内容] |
|||
*/ |
|||
public static Date getDate2(String time) throws ParseException { |
|||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|||
return sdf.parse(time); |
|||
|
|||
} |
|||
|
|||
/** |
|||
* @param @param date |
|||
* @param @return 设定文件 |
|||
* @return String 返回类型 |
|||
* @throws |
|||
* @Title: getLastMonth |
|||
* @author LR |
|||
* @Description: 获取上一个月的YYYY-MM |
|||
*/ |
|||
public static String getLastMonth(Date date) { |
|||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); |
|||
Calendar cal = Calendar.getInstance(); |
|||
cal.setTime(date); |
|||
cal.add(Calendar.MONTH, -1); |
|||
Date lastDate = cal.getTime(); |
|||
return sdf.format(lastDate); |
|||
} |
|||
|
|||
public static Date getDateByParten(String date, String parten) |
|||
throws ParseException { |
|||
SimpleDateFormat sdf = new SimpleDateFormat(parten); |
|||
return sdf.parse(date); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 获取两个日期之间的日期 |
|||
* |
|||
* @param start 开始日期 |
|||
* @param end 结束日期 |
|||
* @return 日期集合 |
|||
*/ |
|||
public static List<Date> getBetweenDates(Date start, Date end) { |
|||
List<Date> result = new ArrayList<Date>(); |
|||
Calendar tempStart = Calendar.getInstance(); |
|||
tempStart.setTime(start); |
|||
tempStart.add(Calendar.DAY_OF_YEAR, 1); |
|||
|
|||
Calendar tempEnd = Calendar.getInstance(); |
|||
tempEnd.setTime(end); |
|||
while (tempStart.before(tempEnd)) { |
|||
result.add(tempStart.getTime()); |
|||
tempStart.add(Calendar.DAY_OF_YEAR, 1); |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
/** |
|||
* 获取两个日期之间的日期(包含) |
|||
* |
|||
* @param start 开始日期 |
|||
* @param end 结束日期 |
|||
* @return 日期集合 |
|||
*/ |
|||
public static List<String> collectLocalDates(LocalDate start, LocalDate end) { |
|||
// 用起始时间作为流的源头,按照每次加一天的方式创建一个无限流 |
|||
return Stream.iterate(start, localDate -> localDate.plusDays(1)) |
|||
// 截断无限流,长度为起始时间和结束时间的差+1个 |
|||
.limit(ChronoUnit.DAYS.between(start, end) + 1) |
|||
// 由于最后要的是字符串,所以map转换一下 |
|||
.map(LocalDate::toString) |
|||
// 把流收集为List |
|||
.collect(Collectors.toList()); |
|||
} |
|||
|
|||
/** |
|||
* 判断当前时间是否在[startTime, endTime]区间,注意时间格式要一致 |
|||
* |
|||
* @param nowTime 当前时间 |
|||
* @param startTime 开始时间 |
|||
* @param endTime 结束时间 |
|||
*/ |
|||
public static boolean isEffectiveDate(Date nowTime, Date startTime, Date endTime) { |
|||
if (nowTime.getTime() == startTime.getTime() |
|||
|| nowTime.getTime() == endTime.getTime()) { |
|||
return true; |
|||
} |
|||
|
|||
Calendar date = Calendar.getInstance(); |
|||
date.setTime(nowTime); |
|||
|
|||
Calendar begin = Calendar.getInstance(); |
|||
begin.setTime(startTime); |
|||
|
|||
Calendar end = Calendar.getInstance(); |
|||
end.setTime(endTime); |
|||
|
|||
if (date.after(begin) && date.before(end)) { |
|||
return true; |
|||
} else { |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 判断当前时间有没有超过有效期 |
|||
* |
|||
* @param nowTime |
|||
* @param termOfValidity |
|||
* @return |
|||
*/ |
|||
public static boolean termOfValidity(Date nowTime, Date termOfValidity) { |
|||
|
|||
if (nowTime.getTime() == termOfValidity.getTime()) { |
|||
return true; |
|||
} |
|||
|
|||
Calendar date = Calendar.getInstance(); |
|||
date.setTime(nowTime); |
|||
; |
|||
|
|||
Calendar end = Calendar.getInstance(); |
|||
end.setTime(termOfValidity); |
|||
|
|||
if (date.before(end)) { |
|||
return true; |
|||
} else { |
|||
return false; |
|||
} |
|||
|
|||
} |
|||
|
|||
/** |
|||
* 判断时间 |
|||
* |
|||
* @param startTime |
|||
* @param endTime |
|||
* @return |
|||
*/ |
|||
public static boolean compareDate(Date startTime, Date endTime) { |
|||
if (startTime.getTime() > endTime.getTime()) { |
|||
return true; |
|||
} else { |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* String 转 date |
|||
* |
|||
* @param time |
|||
* @return |
|||
* @throws ParseException |
|||
*/ |
|||
public static Date getDateTime(String time) throws ParseException { |
|||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|||
return sdf.parse(time); |
|||
|
|||
} |
|||
|
|||
/** |
|||
* @param date1 |
|||
* @param date2 |
|||
* @return double |
|||
* @throws |
|||
* @Method getHour |
|||
* @Description: 根据开始时间,结束时间获取相差小时数 |
|||
* @author zuowenwen |
|||
* @Version 1.0 |
|||
* @date 2020/7/21 |
|||
*/ |
|||
public static double getHour(Date date1, Date date2) throws ParseException { |
|||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); |
|||
long startTime = date1.getTime(); |
|||
long endTime = date2.getTime(); |
|||
Long Intervals = endTime - startTime; |
|||
Double hour = (double) Intervals / 1000 / 3600; |
|||
DecimalFormat decimalFormat = new DecimalFormat(".0"); |
|||
String p = decimalFormat.format(hour); |
|||
hour = Double.parseDouble(p); |
|||
return hour; |
|||
} |
|||
|
|||
/** |
|||
* @param date |
|||
* @return java.lang.String |
|||
* @throws |
|||
* @Method getWeek |
|||
* @Description: 根据时间获取星期几 |
|||
* @author zuowenwen |
|||
* @Version 1.0 |
|||
* @date 2020/7/21 |
|||
*/ |
|||
public static String getWeek(Date date) { |
|||
SimpleDateFormat sdf = new SimpleDateFormat("EEEE"); |
|||
String week = sdf.format(date); |
|||
return week; |
|||
} |
|||
|
|||
/** |
|||
* @param date |
|||
* @return java.lang.Integer |
|||
* @throws |
|||
* @Method getWeekDay |
|||
* @Description: 根据时间获取一周的第几天 |
|||
* @author zuowenwen |
|||
* @Version 1.0 |
|||
* @date 2020/7/21 |
|||
*/ |
|||
public static Integer getWeekDay(Date date) { |
|||
Calendar calendar = Calendar.getInstance(); |
|||
calendar.setTime(date); |
|||
int weekDay = calendar.get(Calendar.DAY_OF_WEEK); |
|||
if (weekDay == 1) { |
|||
weekDay = 7; |
|||
} else { |
|||
weekDay--; |
|||
} |
|||
return weekDay; |
|||
} |
|||
|
|||
/** |
|||
* @param date |
|||
* @param num |
|||
* @return java.util.Date |
|||
* @throws |
|||
* @Method getAddDate |
|||
* @Description: 根据时间 获取num之前的时间 |
|||
* @author zuowenwen |
|||
* @Version 1.0 |
|||
* @date 2020/7/23 |
|||
*/ |
|||
public static Date getAddDate(Date date, Integer num) { |
|||
Calendar calendar = new GregorianCalendar(); |
|||
calendar.setTime(date); |
|||
calendar.add(calendar.DATE, num); //把日期往后增加一天,整数 往后推,负数往前移动 |
|||
date = calendar.getTime(); //这个时间就是日期往后推一天的结果 |
|||
return date; |
|||
} |
|||
|
|||
public static Date getDateTime(String time, String parten) throws ParseException { |
|||
SimpleDateFormat sdf = new SimpleDateFormat(parten); |
|||
return sdf.parse(time); |
|||
|
|||
} |
|||
|
|||
public String DateToStringBeginOrEnd(Date date, Boolean flag) { |
|||
String time = null; |
|||
SimpleDateFormat dateformat1 = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); |
|||
Calendar calendar1 = Calendar.getInstance(); |
|||
//获取某一天的0点0分0秒 或者 23点59分59秒 |
|||
if (flag) { |
|||
calendar1.setTime(date); |
|||
calendar1.set(calendar1.get(Calendar.YEAR), calendar1.get(Calendar.MONTH), calendar1.get(Calendar.DAY_OF_MONTH), |
|||
0, 0, 0); |
|||
Date beginOfDate = calendar1.getTime(); |
|||
time = dateformat1.format(beginOfDate); |
|||
System.out.println(time); |
|||
} else { |
|||
Calendar calendar2 = Calendar.getInstance(); |
|||
calendar2.setTime(date); |
|||
calendar1.set(calendar2.get(Calendar.YEAR), calendar2.get(Calendar.MONTH), calendar2.get(Calendar.DAY_OF_MONTH), |
|||
23, 59, 59); |
|||
Date endOfDate = calendar1.getTime(); |
|||
time = dateformat1.format(endOfDate); |
|||
System.out.println(time); |
|||
} |
|||
return time; |
|||
} |
|||
|
|||
/** |
|||
* 得到某年某周的第一天 |
|||
* |
|||
* @param year |
|||
* @param week |
|||
* @return |
|||
*/ |
|||
public static Date getFirstDayOfWeek(int year, int week) { |
|||
Calendar c = new GregorianCalendar(); |
|||
c.set(Calendar.YEAR, year); |
|||
c.set(Calendar.MONTH, Calendar.JANUARY); |
|||
c.set(Calendar.DATE, 1); |
|||
|
|||
Calendar cal = (GregorianCalendar) c.clone(); |
|||
cal.add(Calendar.DATE, week * 7); |
|||
|
|||
return getFirstDayOfWeek(cal.getTime()); |
|||
} |
|||
|
|||
/** |
|||
* 取得当前日期所在周的第一天 |
|||
* |
|||
* @param date |
|||
* @return |
|||
*/ |
|||
public static Date getFirstDayOfWeek(Date date) { |
|||
Calendar c = new GregorianCalendar(); |
|||
c.setFirstDayOfWeek(Calendar.MONDAY); |
|||
c.setTime(date); |
|||
c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek()); // Monday |
|||
return c.getTime (); |
|||
} |
|||
|
|||
|
|||
|
|||
/* |
|||
输入日期字符串比如201703,返回当月第一天的Date |
|||
*/ |
|||
public static Date getMinDateMonth(String month){ |
|||
try { |
|||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
|||
Date nowDate=sdf.parse(month); |
|||
Calendar calendar = Calendar.getInstance(); |
|||
calendar.setTime(nowDate); |
|||
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH)); |
|||
return calendar.getTime(); |
|||
} catch (ParseException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
/* |
|||
输入日期字符串,返回当月最后一天的Date |
|||
*/ |
|||
public static Date getMaxDateMonth(String month){ |
|||
try { |
|||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
|||
Date nowDate=sdf.parse(month); |
|||
Calendar calendar = Calendar.getInstance(); |
|||
calendar.setTime(nowDate); |
|||
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH)); |
|||
return calendar.getTime(); |
|||
} catch (ParseException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,51 @@ |
|||
package com.xujie.pms.data; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import org.springframework.format.annotation.DateTimeFormat; |
|||
|
|||
import java.util.Date; |
|||
|
|||
public class EamWorkPlanInData extends EamWorkPlanData{ |
|||
private String objectDesc; |
|||
@DateTimeFormat(pattern = "yyyy-MM-dd") |
|||
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") |
|||
private Date startDate; |
|||
@DateTimeFormat(pattern = "yyyy-MM-dd") |
|||
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") |
|||
private Date endDate; |
|||
|
|||
private String userId; |
|||
|
|||
|
|||
public String getObjectDesc() { |
|||
return objectDesc; |
|||
} |
|||
|
|||
public void setObjectDesc(String objectDesc) { |
|||
this.objectDesc = objectDesc; |
|||
} |
|||
|
|||
public Date getStartDate() { |
|||
return startDate; |
|||
} |
|||
|
|||
public void setStartDate(Date startDate) { |
|||
this.startDate = startDate; |
|||
} |
|||
|
|||
public Date getEndDate() { |
|||
return endDate; |
|||
} |
|||
|
|||
public void setEndDate(Date endDate) { |
|||
this.endDate = endDate; |
|||
} |
|||
|
|||
public String getUserId() { |
|||
return userId; |
|||
} |
|||
|
|||
public void setUserId(String userId) { |
|||
this.userId = userId; |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue