package com.huaxu.utils; import com.huaxu.evaluation.enums.EvaluationCycleEnums; import com.huaxu.evaluation.vo.EvaluationItemVo; import com.huaxu.util.DatesUtil; import org.apache.commons.lang3.StringUtils; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.stream.Collectors; /** * @ClassName EvaluationJobUtil * @Description: TODO * @Author lihui * @Date 2021/5/10 * @Version V1.0 **/ public class EvaluationUtil { private static Calendar getCalendar(){ return Calendar.getInstance(); } public static Calendar getCalendar (String dateTime){ Calendar calendar = getCalendar(); calendar.setTime(DatesUtil.parseDate(dateTime, "yyyy-MM-dd HH:mm:ss")); return calendar; } public static Integer toInteger(Long lon) { return lon == null ? null : lon.intValue(); } public static BigDecimal divide(Integer completeCount, Integer total){ BigDecimal bigDecimalComplete = new BigDecimal(completeCount.toString()); BigDecimal bigDecimalTotal = new BigDecimal(total.toString()); return bigDecimalComplete.divide(bigDecimalTotal,2, RoundingMode.HALF_UP); } /** * @Author lihui * @Description 转换分钟 * @Date 17:11 2021/5/11 * @Param [dataLimit] * @return int **/ public static int minute(String dataLimit){ if (StringUtils.isEmpty(dataLimit)){ return 0; } return new BigDecimal(dataLimit).multiply(new BigDecimal("60")).intValue(); } /** * @Author lihui * @Description 完成状态 * @Date 17:08 2021/5/11 * @Param [status] * @return boolean **/ public static boolean completed(Integer status){ return status == 2 || status == 3 ; } /** * @Author lihui * @Description 计算是否延期完成 * @Date 11:06 2021/5/11 * @Param [finishDate :最终完成时间, planFinishDate:预计完成时间, addMinute:可延期的时间] * @return boolean **/ public static boolean isDelay(Date finishDate, Date planFinishDate, int addMinute){ if (finishDate == null || planFinishDate == null) { return false; } return finishDate.after(DatesUtil.addMinuteOfDate(planFinishDate,addMinute)); } public static Long[] toLong (List userIds){ Long [] longs = new Long[userIds.size()]; for (int i = 0 ; i < userIds.size(); i++) { longs[i] =Long.parseLong(userIds.get(i).toString()) ; } return longs; } /** * @Author lihui * @Description 是否是当天 * @Date 17:08 2021/5/11 * @Param [evaluationDay] * @return boolean **/ public static boolean isToday(int evaluationDay){ return Calendar.getInstance().get(Calendar.DAY_OF_MONTH) == evaluationDay; } /** * @Author lihui * @Description 是否是同月 * @Date 18:14 2021/5/11 * @Param [month] * @return boolean **/ public static boolean sameMonth(int month){ return Calendar.getInstance().get(Calendar.MONTH) + 1 == month; } public static boolean containsType(List itemEntityList, Integer type){ List list = itemEntityList.stream().map(EvaluationItemVo::getCycle).collect(Collectors.toList()); for (String str: list) { if (str.indexOf(type.toString()) != -1) { return true; } } return false; } public static String getStartTime(int cycle, Integer year, Integer month){ int mark = month == null ? 1 : 2; Calendar calendar = getCalendar(); year = year == null ? calendar.get(Calendar.YEAR) : year; Integer calendarMonth = calendar.get(Calendar.MONTH) + 1; Integer newMonth = month == null ? calendarMonth : month; // 月度 if (cycle == EvaluationCycleEnums.MONTH.getType()) { return year + "-" + toString(newMonth) + "-01 00:00:00"; } if (cycle == EvaluationCycleEnums.QUARTER.getType()) { Integer quMonth = null; month = month == null ? calendarMonth(calendarMonth) : month; if (month != null) { quMonth = month == 1 ? 1 : month == 2 ? 4 : month == 3 ? 7 : month == 4 ? 10 : null; year = mark == 1 && month == 4 ? year -1 : year; } if (quMonth == null) { return null; } return year + "-"+toString(quMonth)+"-01 00:00:00"; } if (cycle == EvaluationCycleEnums.YEAR.getType()) { return year + "-01-01 00:00:00"; } return null; } private static Integer calendarMonth(Integer calendarMonth){ switch (calendarMonth){ case 1 : return 4; case 4 : return 1; case 7 : return 2; case 10 : return 3; } return null; } public static String getEndTime(int cycle, Integer year, Integer month){ int mark = month == null ? 1 : 2; Calendar calendar = getCalendar(); year = year == null ? calendar.get(Calendar.YEAR) : year; Integer calendarMonth = calendar.get(Calendar.MONTH) + 1; Integer newMonth = month == null ? calendarMonth : month; Integer quMonth = null; // 月度 if (cycle == EvaluationCycleEnums.MONTH.getType()) { quMonth = newMonth; } if (cycle == EvaluationCycleEnums.QUARTER.getType()) { month = month == null ? calendarMonth(calendarMonth) : month; if (month != null) { quMonth = month == 1 ? 3 : month == 2 ? 6 : month == 3 ? 9 : month == 4 ? 12 : null; year = mark == 1 && month == 4 ? year -1 : year; } if (quMonth == null) { return null; } } if (cycle == EvaluationCycleEnums.YEAR.getType()) { quMonth = 12; } String monthStr = toString(quMonth); return year + "-" + monthStr + "-" + DatesUtil.getMouthDays( year + "-" +monthStr) + " 23:59:59"; } private static String toString (Integer var){ String result = var.toString(); return result.length() == 1 ? "0" + result : result; } }