Commit 392c8059979cb33ccd8b5f6f526b298737f3de55
1 parent
9c9325d3
1.
Showing
2 changed files
with
177 additions
and
0 deletions
src/main/java/com/bsth/server_rs/schedule/ScheduleTimeService.java
0 → 100644
| 1 | +package com.bsth.server_rs.schedule; | ||
| 2 | + | ||
| 3 | +import com.bsth.entity.ScheduleExec; | ||
| 4 | +import com.bsth.entity.TimeTable; | ||
| 5 | +import com.fasterxml.jackson.core.JsonProcessingException; | ||
| 6 | +import com.fasterxml.jackson.databind.ObjectMapper; | ||
| 7 | +import org.slf4j.Logger; | ||
| 8 | +import org.slf4j.LoggerFactory; | ||
| 9 | +import org.springframework.stereotype.Component; | ||
| 10 | + | ||
| 11 | +import javax.ws.rs.POST; | ||
| 12 | +import javax.ws.rs.Path; | ||
| 13 | +import javax.ws.rs.Produces; | ||
| 14 | +import javax.ws.rs.core.MediaType; | ||
| 15 | +import java.util.HashMap; | ||
| 16 | +import java.util.List; | ||
| 17 | +import java.util.Map; | ||
| 18 | + | ||
| 19 | +/** | ||
| 20 | + * @author Hill | ||
| 21 | + */ | ||
| 22 | +@Component | ||
| 23 | +@Path("/schedule") | ||
| 24 | +@Produces({MediaType.APPLICATION_JSON}) | ||
| 25 | +public class ScheduleTimeService { | ||
| 26 | + | ||
| 27 | + private final static Logger log = LoggerFactory.getLogger(ScheduleTimeService.class); | ||
| 28 | + | ||
| 29 | + private ObjectMapper mapper = new ObjectMapper(); | ||
| 30 | + | ||
| 31 | + @POST | ||
| 32 | + @Path("") | ||
| 33 | + public Map<String, Object> destroy(List<TimeTable> timeTables) throws JsonProcessingException { | ||
| 34 | + Map<String, Object> result = new HashMap<>(); | ||
| 35 | + log.info(mapper.writeValueAsString(timeTables)); | ||
| 36 | + result.put("code", 0); | ||
| 37 | + result.put("msg", "ok"); | ||
| 38 | + | ||
| 39 | + return result; | ||
| 40 | + } | ||
| 41 | +} |
src/main/java/com/bsth/util/DateUtils.java
0 → 100644
| 1 | +package com.bsth.util; | ||
| 2 | + | ||
| 3 | +import java.text.ParseException; | ||
| 4 | +import java.text.SimpleDateFormat; | ||
| 5 | +import java.util.Calendar; | ||
| 6 | +import java.util.Date; | ||
| 7 | + | ||
| 8 | +public class DateUtils { | ||
| 9 | + | ||
| 10 | + // 获得当天0点时间 | ||
| 11 | + public static int getTimesmorning() { | ||
| 12 | + Calendar cal = Calendar.getInstance(); | ||
| 13 | + cal.set(Calendar.HOUR_OF_DAY, 0); | ||
| 14 | + cal.set(Calendar.SECOND, 0); | ||
| 15 | + cal.set(Calendar.MINUTE, 0); | ||
| 16 | + cal.set(Calendar.MILLISECOND, 0); | ||
| 17 | + return (int) (cal.getTimeInMillis() / 1000); | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + // 获得当天0点毫秒时间戳 | ||
| 21 | + public static long getTimestamp() { | ||
| 22 | + Calendar cal = Calendar.getInstance(); | ||
| 23 | + cal.set(Calendar.HOUR_OF_DAY, 0); | ||
| 24 | + cal.set(Calendar.SECOND, 0); | ||
| 25 | + cal.set(Calendar.MINUTE, 0); | ||
| 26 | + cal.set(Calendar.MILLISECOND, 0); | ||
| 27 | + return cal.getTimeInMillis(); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + public static Long getTimesmorning(Calendar cal) { | ||
| 31 | + cal.set(Calendar.HOUR_OF_DAY, 0); | ||
| 32 | + cal.set(Calendar.SECOND, 0); | ||
| 33 | + cal.set(Calendar.MINUTE, 0); | ||
| 34 | + cal.set(Calendar.MILLISECOND, 0); | ||
| 35 | + return cal.getTimeInMillis() / 1000; | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + // 获得当天24点时间 | ||
| 39 | + public static int getTimesnight() { | ||
| 40 | + Calendar cal = Calendar.getInstance(); | ||
| 41 | + cal.set(Calendar.HOUR_OF_DAY, 24); | ||
| 42 | + cal.set(Calendar.SECOND, 0); | ||
| 43 | + cal.set(Calendar.MINUTE, 0); | ||
| 44 | + cal.set(Calendar.MILLISECOND, 0); | ||
| 45 | + return (int) (cal.getTimeInMillis() / 1000); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + // 获得当天24点时间 毫秒 | ||
| 49 | + public static Long getTimesnight2() { | ||
| 50 | + Calendar cal = Calendar.getInstance(); | ||
| 51 | + cal.set(Calendar.HOUR_OF_DAY, 24); | ||
| 52 | + cal.set(Calendar.SECOND, 0); | ||
| 53 | + cal.set(Calendar.MINUTE, 0); | ||
| 54 | + cal.set(Calendar.MILLISECOND, 0); | ||
| 55 | + return cal.getTimeInMillis(); | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + public static Long getTimesnight(Calendar cal) { | ||
| 59 | + cal.set(Calendar.HOUR_OF_DAY, 24); | ||
| 60 | + cal.set(Calendar.SECOND, 0); | ||
| 61 | + cal.set(Calendar.MINUTE, 0); | ||
| 62 | + cal.set(Calendar.MILLISECOND, 0); | ||
| 63 | + return cal.getTimeInMillis(); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + // 获得本周一0点时间 | ||
| 67 | + public static int getTimesWeekmorning() { | ||
| 68 | + Calendar cal = Calendar.getInstance(); | ||
| 69 | + cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONDAY), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0); | ||
| 70 | + cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); | ||
| 71 | + return (int) (cal.getTimeInMillis() / 1000); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + // 获得本周日24点时间 | ||
| 75 | + public static int getTimesWeeknight() { | ||
| 76 | + Calendar cal = Calendar.getInstance(); | ||
| 77 | + cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONDAY), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0); | ||
| 78 | + cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); | ||
| 79 | + return (int) ((cal.getTime().getTime() + (7 * 24 * 60 * 60 * 1000)) / 1000); | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + // 获得本月第一天0点时间 | ||
| 83 | + public static int getTimesMonthmorning() { | ||
| 84 | + Calendar cal = Calendar.getInstance(); | ||
| 85 | + cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONDAY), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0); | ||
| 86 | + cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH)); | ||
| 87 | + return (int) (cal.getTimeInMillis() / 1000); | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + // 获得本月最后一天24点时间 | ||
| 91 | + public static int getTimesMonthnight() { | ||
| 92 | + Calendar cal = Calendar.getInstance(); | ||
| 93 | + cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONDAY), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0); | ||
| 94 | + cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); | ||
| 95 | + cal.set(Calendar.HOUR_OF_DAY, 24); | ||
| 96 | + return (int) (cal.getTimeInMillis() / 1000); | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + private static SimpleDateFormat sdfyyyyMMddHHmm = new SimpleDateFormat("yyyy-MM-ddHH:mm") | ||
| 100 | + ,sdfyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd") | ||
| 101 | + ,sdfHHmm = new SimpleDateFormat("HH:mm"); | ||
| 102 | + public static long getTimesByHHmm(String str) throws ParseException{ | ||
| 103 | + Date d = sdfyyyyMMddHHmm.parse(sdfyyyyMMdd.format(new Date()) + str); | ||
| 104 | + return d.getTime(); | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + public static String plusDay(String old, int day){ | ||
| 108 | + Calendar cal = null; | ||
| 109 | + try { | ||
| 110 | + Date date = sdfyyyyMMdd.parse(old); | ||
| 111 | + cal = Calendar.getInstance(); | ||
| 112 | + cal.setTime(date); | ||
| 113 | + cal.add(Calendar.DATE, day); | ||
| 114 | + } catch (ParseException e) { | ||
| 115 | + e.printStackTrace(); | ||
| 116 | + } | ||
| 117 | + return sdfyyyyMMdd.format(cal.getTime()); | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + public static String subtractDay(String old, int day){ | ||
| 121 | + Calendar cal = null; | ||
| 122 | + try { | ||
| 123 | + Date date = sdfyyyyMMdd.parse(old); | ||
| 124 | + cal = Calendar.getInstance(); | ||
| 125 | + cal.setTime(date); | ||
| 126 | + cal.set(Calendar.DATE, cal.get(Calendar.DATE) - day); | ||
| 127 | + } catch (ParseException e) { | ||
| 128 | + e.printStackTrace(); | ||
| 129 | + } | ||
| 130 | + return sdfyyyyMMdd.format(cal.getTime()); | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + public static int calcHHmmDiff(String fcsj, String zdsj) throws ParseException { | ||
| 134 | + return (int) (sdfHHmm.parse(zdsj).getTime() - sdfHHmm.parse(fcsj).getTime()); | ||
| 135 | + } | ||
| 136 | +} |