EvaluationUtil.java 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. package com.huaxu.utils;
  2. import com.huaxu.evaluation.enums.EvaluationCycleEnums;
  3. import com.huaxu.evaluation.vo.EvaluationItemVo;
  4. import com.huaxu.util.DatesUtil;
  5. import org.apache.commons.lang3.StringUtils;
  6. import java.math.BigDecimal;
  7. import java.math.RoundingMode;
  8. import java.util.Calendar;
  9. import java.util.Date;
  10. import java.util.List;
  11. import java.util.stream.Collectors;
  12. /**
  13. * @ClassName EvaluationJobUtil
  14. * @Description: TODO
  15. * @Author lihui
  16. * @Date 2021/5/10
  17. * @Version V1.0
  18. **/
  19. public class EvaluationUtil {
  20. private static Calendar getCalendar(){
  21. return Calendar.getInstance();
  22. }
  23. public static Calendar getCalendar (String dateTime){
  24. Calendar calendar = getCalendar();
  25. calendar.setTime(DatesUtil.parseDate(dateTime, "yyyy-MM-dd HH:mm:ss"));
  26. return calendar;
  27. }
  28. public static Integer toInteger(Long lon) {
  29. return lon == null ? null : lon.intValue();
  30. }
  31. public static BigDecimal divide(Integer completeCount, Integer total){
  32. BigDecimal bigDecimalComplete = new BigDecimal(completeCount.toString());
  33. BigDecimal bigDecimalTotal = new BigDecimal(total.toString());
  34. return bigDecimalComplete.divide(bigDecimalTotal,2, RoundingMode.HALF_UP);
  35. }
  36. /**
  37. * @Author lihui
  38. * @Description 转换分钟
  39. * @Date 17:11 2021/5/11
  40. * @Param [dataLimit]
  41. * @return int
  42. **/
  43. public static int minute(String dataLimit){
  44. if (StringUtils.isEmpty(dataLimit)){
  45. return 0;
  46. }
  47. return new BigDecimal(dataLimit).multiply(new BigDecimal("60")).intValue();
  48. }
  49. /**
  50. * @Author lihui
  51. * @Description 完成状态
  52. * @Date 17:08 2021/5/11
  53. * @Param [status]
  54. * @return boolean
  55. **/
  56. public static boolean completed(Integer status){
  57. return status == 2 || status == 3 ;
  58. }
  59. /**
  60. * @Author lihui
  61. * @Description 计算是否延期完成
  62. * @Date 11:06 2021/5/11
  63. * @Param [finishDate :最终完成时间, planFinishDate:预计完成时间, addMinute:可延期的时间]
  64. * @return boolean
  65. **/
  66. public static boolean isDelay(Date finishDate, Date planFinishDate, int addMinute){
  67. if (finishDate == null || planFinishDate == null) {
  68. return false;
  69. }
  70. return finishDate.after(DatesUtil.addMinuteOfDate(planFinishDate,addMinute));
  71. }
  72. public static Long[] toLong (List<Integer> userIds){
  73. Long [] longs = new Long[userIds.size()];
  74. for (int i = 0 ; i < userIds.size(); i++) {
  75. longs[i] =Long.parseLong(userIds.get(i).toString()) ;
  76. }
  77. return longs;
  78. }
  79. /**
  80. * @Author lihui
  81. * @Description 是否是当天
  82. * @Date 17:08 2021/5/11
  83. * @Param [evaluationDay]
  84. * @return boolean
  85. **/
  86. public static boolean isToday(int evaluationDay){
  87. return Calendar.getInstance().get(Calendar.DAY_OF_MONTH) == evaluationDay;
  88. }
  89. /**
  90. * @Author lihui
  91. * @Description 是否是同月
  92. * @Date 18:14 2021/5/11
  93. * @Param [month]
  94. * @return boolean
  95. **/
  96. public static boolean sameMonth(int month){
  97. return Calendar.getInstance().get(Calendar.MONTH) + 1 == month;
  98. }
  99. public static boolean containsType(List<EvaluationItemVo> itemEntityList, Integer type){
  100. List<String> list = itemEntityList.stream().map(EvaluationItemVo::getCycle).collect(Collectors.toList());
  101. for (String str: list) {
  102. if (str.indexOf(type.toString()) != -1) {
  103. return true;
  104. }
  105. }
  106. return false;
  107. }
  108. public static String getStartTime(int cycle, Integer year, Integer month){
  109. int mark = month == null ? 1 : 2;
  110. Calendar calendar = getCalendar();
  111. year = year == null ? calendar.get(Calendar.YEAR) : year;
  112. Integer calendarMonth = calendar.get(Calendar.MONTH) + 1;
  113. Integer newMonth = month == null ? calendarMonth : month;
  114. // 月度
  115. if (cycle == EvaluationCycleEnums.MONTH.getType()) {
  116. return year + "-" + toString(newMonth) + "-01 00:00:00";
  117. }
  118. if (cycle == EvaluationCycleEnums.QUARTER.getType()) {
  119. Integer quMonth = null;
  120. month = month == null ? calendarMonth(calendarMonth) : month;
  121. if (month != null) {
  122. quMonth = month == 1 ? 1 :
  123. month == 2 ? 4 :
  124. month == 3 ? 7 :
  125. month == 4 ? 10 : null;
  126. year = mark == 1 && month == 4 ? year -1 : year;
  127. }
  128. if (quMonth == null) {
  129. return null;
  130. }
  131. return year + "-"+toString(quMonth)+"-01 00:00:00";
  132. }
  133. if (cycle == EvaluationCycleEnums.YEAR.getType()) {
  134. return year + "-01-01 00:00:00";
  135. }
  136. return null;
  137. }
  138. private static Integer calendarMonth(Integer calendarMonth){
  139. switch (calendarMonth){
  140. case 1 :
  141. return 4;
  142. case 4 :
  143. return 1;
  144. case 7 :
  145. return 2;
  146. case 10 :
  147. return 3;
  148. }
  149. return null;
  150. }
  151. public static String getEndTime(int cycle, Integer year, Integer month){
  152. int mark = month == null ? 1 : 2;
  153. Calendar calendar = getCalendar();
  154. year = year == null ? calendar.get(Calendar.YEAR) : year;
  155. Integer calendarMonth = calendar.get(Calendar.MONTH) + 1;
  156. Integer newMonth = month == null ? calendarMonth : month;
  157. Integer quMonth = null;
  158. // 月度
  159. if (cycle == EvaluationCycleEnums.MONTH.getType()) {
  160. quMonth = newMonth;
  161. }
  162. if (cycle == EvaluationCycleEnums.QUARTER.getType()) {
  163. month = month == null ? calendarMonth(calendarMonth) : month;
  164. if (month != null) {
  165. quMonth = month == 1 ? 3 :
  166. month == 2 ? 6 :
  167. month == 3 ? 9 :
  168. month == 4 ? 12 : null;
  169. year = mark == 1 && month == 4 ? year -1 : year;
  170. }
  171. if (quMonth == null) {
  172. return null;
  173. }
  174. }
  175. if (cycle == EvaluationCycleEnums.YEAR.getType()) {
  176. quMonth = 12;
  177. }
  178. String monthStr = toString(quMonth);
  179. return year + "-" + monthStr + "-" + DatesUtil.getMouthDays( year + "-" +monthStr) + " 23:59:59";
  180. }
  181. private static String toString (Integer var){
  182. String result = var.toString();
  183. return result.length() == 1 ? "0" + result : result;
  184. }
  185. }