Commit 509213ae0ed5bf3c5ab3cf66ed839a33b1caa920
1 parent
133c631c
update...
Showing
5 changed files
with
184 additions
and
7 deletions
src/main/java/com/bsth/entity/OilInfo.java
| @@ -126,6 +126,21 @@ public class OilInfo implements Serializable { | @@ -126,6 +126,21 @@ public class OilInfo implements Serializable { | ||
| 126 | //进场顺序(根据最先出场和最后进场来关联车辆的存油量) | 126 | //进场顺序(根据最先出场和最后进场来关联车辆的存油量) |
| 127 | private int jcsx; | 127 | private int jcsx; |
| 128 | 128 | ||
| 129 | + @Override | ||
| 130 | + public int hashCode() { | ||
| 131 | + return this.toString().hashCode(); | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + @Override | ||
| 135 | + public boolean equals(Object obj) { | ||
| 136 | + return this.toString().equals(((OilInfo)obj).toString()); | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + @Override | ||
| 140 | + public String toString() { | ||
| 141 | + return "oil_" + this.id; | ||
| 142 | + } | ||
| 143 | + | ||
| 129 | public Integer getId() { | 144 | public Integer getId() { |
| 130 | return id; | 145 | return id; |
| 131 | } | 146 | } |
src/main/java/com/bsth/entity/SchedulePlanInfo.java
| @@ -102,6 +102,21 @@ public class SchedulePlanInfo implements Serializable { | @@ -102,6 +102,21 @@ public class SchedulePlanInfo implements Serializable { | ||
| 102 | /** 关联的时刻表名字 */ | 102 | /** 关联的时刻表名字 */ |
| 103 | private String ttInfoName; | 103 | private String ttInfoName; |
| 104 | 104 | ||
| 105 | + @Override | ||
| 106 | + public int hashCode() { | ||
| 107 | + return this.toString().hashCode(); | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + @Override | ||
| 111 | + public boolean equals(Object obj) { | ||
| 112 | + return this.toString().equals(((SchedulePlanInfo)obj).toString()); | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + @Override | ||
| 116 | + public String toString() { | ||
| 117 | + return "sch_plan_" + this.id; | ||
| 118 | + } | ||
| 119 | + | ||
| 105 | public Long getId() { | 120 | public Long getId() { |
| 106 | return id; | 121 | return id; |
| 107 | } | 122 | } |
src/main/java/com/bsth/redis/OilRedisService.java
| @@ -13,7 +13,6 @@ import org.slf4j.LoggerFactory; | @@ -13,7 +13,6 @@ import org.slf4j.LoggerFactory; | ||
| 13 | import org.springframework.beans.factory.annotation.Autowired; | 13 | import org.springframework.beans.factory.annotation.Autowired; |
| 14 | import org.springframework.boot.CommandLineRunner; | 14 | import org.springframework.boot.CommandLineRunner; |
| 15 | import org.springframework.core.annotation.Order; | 15 | import org.springframework.core.annotation.Order; |
| 16 | -import org.springframework.data.redis.core.ListOperations; | ||
| 17 | import org.springframework.data.redis.core.RedisTemplate; | 16 | import org.springframework.data.redis.core.RedisTemplate; |
| 18 | import org.springframework.data.redis.serializer.StringRedisSerializer; | 17 | import org.springframework.data.redis.serializer.StringRedisSerializer; |
| 19 | import org.springframework.stereotype.Component; | 18 | import org.springframework.stereotype.Component; |
| @@ -107,15 +106,15 @@ public class OilRedisService implements CommandLineRunner { | @@ -107,15 +106,15 @@ public class OilRedisService implements CommandLineRunner { | ||
| 107 | public void mergeData(String key, List<OilInfo> list) { | 106 | public void mergeData(String key, List<OilInfo> list) { |
| 108 | key = REDIS_KEY_PREFIX + key; | 107 | key = REDIS_KEY_PREFIX + key; |
| 109 | 108 | ||
| 110 | - ListOperations<String, OilInfo> ops = redisTemplate.opsForList(); | 109 | +/* ListOperations<String, OilInfo> ops = redisTemplate.opsForList(); |
| 111 | List<OilInfo> cacheList = ops.range(key, 0, -1); | 110 | List<OilInfo> cacheList = ops.range(key, 0, -1); |
| 112 | 111 | ||
| 113 | for (OilInfo oil : cacheList) { | 112 | for (OilInfo oil : cacheList) { |
| 114 | if (!list.contains(oil)) | 113 | if (!list.contains(oil)) |
| 115 | list.add(oil); | 114 | list.add(oil); |
| 116 | - } | 115 | + }*/ |
| 117 | 116 | ||
| 118 | - //更新 | 117 | + //更新 直接覆盖更新 |
| 119 | redisTemplate.execute(redisUtils.getUpdateCallback(key, list)); | 118 | redisTemplate.execute(redisUtils.getUpdateCallback(key, list)); |
| 120 | } | 119 | } |
| 121 | 120 |
src/main/java/com/bsth/redis/PlanScheduleRedisService.java
| @@ -2,6 +2,7 @@ package com.bsth.redis; | @@ -2,6 +2,7 @@ package com.bsth.redis; | ||
| 2 | 2 | ||
| 3 | import com.bsth.Application; | 3 | import com.bsth.Application; |
| 4 | import com.bsth.entity.SchedulePlanInfo; | 4 | import com.bsth.entity.SchedulePlanInfo; |
| 5 | +import com.bsth.redis.util.DateUtils; | ||
| 5 | import com.bsth.redis.util.RedisUtils; | 6 | import com.bsth.redis.util.RedisUtils; |
| 6 | import com.bsth.repository.SchedulePlanInfoRepository; | 7 | import com.bsth.repository.SchedulePlanInfoRepository; |
| 7 | import com.bsth.server_rs.base_info.line.Line; | 8 | import com.bsth.server_rs.base_info.line.Line; |
| @@ -134,8 +135,11 @@ public class PlanScheduleRedisService implements CommandLineRunner { | @@ -134,8 +135,11 @@ public class PlanScheduleRedisService implements CommandLineRunner { | ||
| 134 | //写入redis | 135 | //写入redis |
| 135 | wirte(list); | 136 | wirte(list); |
| 136 | 137 | ||
| 137 | - //24小时清理一次计划排班数据 | ||
| 138 | - Application.mainServices.scheduleWithFixedDelay(planClearThread, 24, 24, TimeUnit.HOURS); | 138 | + //定时 00:05 分清理计划,并加载当天的计划 |
| 139 | + long diff = (DateUtils.getTimestamp() + 1000 * 60 * 5) - System.currentTimeMillis(); | ||
| 140 | + if (diff < 0) | ||
| 141 | + diff += (1000 * 60 * 60 * 24); | ||
| 142 | + Application.mainServices.scheduleAtFixedRate(planClearThread, diff / 1000, 60 * 60 * 24, TimeUnit.SECONDS); | ||
| 139 | } | 143 | } |
| 140 | 144 | ||
| 141 | public List<SchedulePlanInfo> findByMultiLine(List<String> lineArray, String rq) { | 145 | public List<SchedulePlanInfo> findByMultiLine(List<String> lineArray, String rq) { |
| @@ -152,7 +156,8 @@ public class PlanScheduleRedisService implements CommandLineRunner { | @@ -152,7 +156,8 @@ public class PlanScheduleRedisService implements CommandLineRunner { | ||
| 152 | 156 | ||
| 153 | @Autowired | 157 | @Autowired |
| 154 | PlanScheduleRedisService planRedisService; | 158 | PlanScheduleRedisService planRedisService; |
| 155 | - | 159 | + @Autowired |
| 160 | + SchedulePlanInfoRepository planInfoRepository; | ||
| 156 | @Override | 161 | @Override |
| 157 | public void run() { | 162 | public void run() { |
| 158 | try { | 163 | try { |
| @@ -167,6 +172,13 @@ public class PlanScheduleRedisService implements CommandLineRunner { | @@ -167,6 +172,13 @@ public class PlanScheduleRedisService implements CommandLineRunner { | ||
| 167 | for (Line line : lines) { | 172 | for (Line line : lines) { |
| 168 | planRedisService.delete(line.getLineCode(), rq); | 173 | planRedisService.delete(line.getLineCode(), rq); |
| 169 | } | 174 | } |
| 175 | + | ||
| 176 | + //加载当天的计划 | ||
| 177 | + Date d = new Date(); | ||
| 178 | + Date s = new Date(d.getTime() - 1000 * 60 * 60 * 24); | ||
| 179 | + List<SchedulePlanInfo> list = planInfoRepository.findByDateRange(s, d); | ||
| 180 | + //写入redis | ||
| 181 | + planRedisService.wirte(list); | ||
| 170 | } catch (Exception e) { | 182 | } catch (Exception e) { |
| 171 | logger.error("", e); | 183 | logger.error("", e); |
| 172 | } | 184 | } |
src/main/java/com/bsth/redis/util/DateUtils.java
0 → 100644
| 1 | +package com.bsth.redis.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 | +} |