| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- 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<Integer> 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<EvaluationItemVo> itemEntityList, Integer type){
- List<String> 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;
- }
- }
|