|
@@ -1,8 +1,16 @@
|
|
|
package cn.com.ty.lift.system.utils;
|
|
|
|
|
|
+import cn.com.ty.lift.system.constants.CommonConstants;
|
|
|
+import cn.com.ty.lift.system.homepage.dao.dto.request.PlatformCalendarRequest;
|
|
|
+
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.time.Duration;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.time.temporal.TemporalAdjusters;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* @author huangyuan
|
|
@@ -39,17 +47,82 @@ public class CommonUtil {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @description 判断时间A和B差值的绝对值是否在指定的之间差值内
|
|
|
- * @date 2019-12-18 14:10
|
|
|
- * @param timeA 时间A
|
|
|
- * @param timeB 时间B
|
|
|
+ * @param timeA 时间A
|
|
|
+ * @param timeB 时间B
|
|
|
* @param dValue 差值
|
|
|
* @return true:差值在指定范围内 false:差值不在指定范围内
|
|
|
+ * @description 判断时间A和B差值的绝对值是否在指定的之间差值内
|
|
|
+ * @date 2019-12-18 14:10
|
|
|
*/
|
|
|
- public static boolean durationJudge(LocalDateTime timeA, LocalDateTime timeB, Long dValue){
|
|
|
+ public static boolean durationJudge(LocalDateTime timeA, LocalDateTime timeB, Long dValue) {
|
|
|
Duration duration = Duration.between(timeA, timeB);
|
|
|
long diffDay = duration.toDays();
|
|
|
return diffDay < dValue;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param transTimeStr 给定时间
|
|
|
+ * @param origFormat 给定时间格式
|
|
|
+ * @param monthFormat 转化为的月份时间格式
|
|
|
+ * @return Map 类型对应时间格式 monthBegin:表示月初时间 monthEnd:表示月末时间
|
|
|
+ * @description
|
|
|
+ */
|
|
|
+ public static Map<String, String> getMonthDate(String transTimeStr, String origFormat, String monthFormat) {
|
|
|
+ Map<String, String> dateTypeToDateValue = new HashMap<>();
|
|
|
+ //将传递时间字符串转化为localDate类型时间
|
|
|
+ LocalDate transDate = LocalDate.parse(transTimeStr, DateTimeFormatter.ofPattern(origFormat));
|
|
|
+ //设置月初时间
|
|
|
+ LocalDate monthBeginDate = transDate.with(TemporalAdjusters.firstDayOfMonth());
|
|
|
+ dateTypeToDateValue.put(CommonConstants.PlatformCalendarConstants.MONTH_BEGIN_DATE,
|
|
|
+ monthBeginDate.format(DateTimeFormatter.ofPattern(monthFormat)));
|
|
|
+ //设置月末时间
|
|
|
+ LocalDate monthEndDate = transDate.with(TemporalAdjusters.lastDayOfMonth());
|
|
|
+ dateTypeToDateValue.put(CommonConstants.PlatformCalendarConstants.MONTH_END_DATE,
|
|
|
+ monthEndDate.format(DateTimeFormatter.ofPattern(monthFormat)));
|
|
|
+
|
|
|
+ return dateTypeToDateValue;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param platformCalendarRequest 转化时间
|
|
|
+ * @return
|
|
|
+ * @description 设置月初月末时间
|
|
|
+ */
|
|
|
+ public static void setMonthDate(PlatformCalendarRequest platformCalendarRequest) {
|
|
|
+ Map<String, String> dateTypeToDateValue = CommonUtil.getMonthDate(platformCalendarRequest.getRequestDateStr(),
|
|
|
+ CommonConstants.PlatformCalendarConstants.REQUEST_DATE_FORMAT,
|
|
|
+ CommonConstants.PlatformCalendarConstants.TRANS_DATE_FORMAT);
|
|
|
+ //设置月初时间
|
|
|
+ platformCalendarRequest.setMonthBeginStr(dateTypeToDateValue.get(
|
|
|
+ CommonConstants.PlatformCalendarConstants.MONTH_BEGIN_DATE));
|
|
|
+ //设置当期时间
|
|
|
+ platformCalendarRequest.setNowStr(LocalDate.now().format(DateTimeFormatter.ofPattern(
|
|
|
+ CommonConstants.PlatformCalendarConstants.TRANS_DATE_FORMAT)));
|
|
|
+ //设置月末时间
|
|
|
+ platformCalendarRequest.setMonthEndStr(dateTypeToDateValue.get(
|
|
|
+ CommonConstants.PlatformCalendarConstants.MONTH_END_DATE));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param timeDateStr 传递时间
|
|
|
+ * @param timeFormat 时间格式
|
|
|
+ * @return
|
|
|
+ * @description 初始化日列数据
|
|
|
+ */
|
|
|
+ public static Map<Integer, Map<Integer, Long>> initCalendarMapData(String timeDateStr, String timeFormat) {
|
|
|
+ //将传递时间字符串转化为localDate类型时间
|
|
|
+ LocalDate transDate = LocalDate.parse(timeDateStr, DateTimeFormatter.ofPattern(timeFormat));
|
|
|
+ Map<Integer, Map<Integer, Long>> dayToLiftStatusToNum = new HashMap<>();
|
|
|
+ if (transDate != null) {
|
|
|
+ for (int monthDay = 1; monthDay <= transDate.getMonthValue(); monthDay++) {
|
|
|
+ Map<Integer, Long> liftStatusToNum = new HashMap<>();
|
|
|
+ for (int liftStatus : CommonConstants.PlatformCalendarConstants.LIFT_STATUS_ARRAY) {
|
|
|
+ liftStatusToNum.put(liftStatus, 0L);
|
|
|
+ }
|
|
|
+ dayToLiftStatusToNum.put(monthDay, liftStatusToNum);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return dayToLiftStatusToNum;
|
|
|
+ }
|
|
|
+
|
|
|
}
|