Commit ed1eda3a60fa4fe50f1b014ce95f516a7caee36a
1 parent
369c5203
1.指令补发时线调页面指令发送状态未持久化问题修复
Showing
1 changed file
with
187 additions
and
182 deletions
src/main/java/com/bsth/data/directive/DayOfDirectives.java
| 1 | -package com.bsth.data.directive; | |
| 2 | - | |
| 3 | -import com.alibaba.fastjson.JSONObject; | |
| 4 | -import com.bsth.data.LineConfigData; | |
| 5 | -import com.bsth.entity.directive.D60; | |
| 6 | -import com.bsth.entity.directive.D64; | |
| 7 | -import com.bsth.entity.directive.Directive; | |
| 8 | -import com.bsth.entity.directive.DirectiveReponse; | |
| 9 | -import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 10 | -import com.bsth.service.directive.DirectiveService; | |
| 11 | -import com.bsth.websocket.handler.SendUtils; | |
| 12 | -import org.slf4j.Logger; | |
| 13 | -import org.slf4j.LoggerFactory; | |
| 14 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 15 | -import org.springframework.stereotype.Component; | |
| 16 | - | |
| 17 | -import java.util.*; | |
| 18 | -import java.util.concurrent.ConcurrentHashMap; | |
| 19 | -import java.util.concurrent.ConcurrentLinkedQueue; | |
| 20 | -import java.util.concurrent.ConcurrentMap; | |
| 21 | - | |
| 22 | -/** | |
| 23 | - * | |
| 24 | - * @ClassName: CurrDayDirectives | |
| 25 | - * @Description: TODO(当天指令数据) | |
| 26 | - * @author PanZhao | |
| 27 | - * @date 2016年8月14日 下午5:23:59 | |
| 28 | - * | |
| 29 | - */ | |
| 30 | -@Component | |
| 31 | -public class DayOfDirectives { | |
| 32 | - | |
| 33 | - // 当日60指令缓存 | |
| 34 | - private static ConcurrentMap<Integer, D60> d60Map; | |
| 35 | - | |
| 36 | - // 线路切换指令 64 | |
| 37 | - public static ConcurrentMap<String, D64> d64Map; | |
| 38 | - | |
| 39 | - //等待插入的指令 | |
| 40 | - public static ConcurrentLinkedQueue<Directive> pstDirectives; | |
| 41 | - //等待更新的指令 | |
| 42 | - public static ConcurrentLinkedQueue<D60> pstD60s; | |
| 43 | - | |
| 44 | - @Autowired | |
| 45 | - DirectiveService directiveService; | |
| 46 | - | |
| 47 | - @Autowired | |
| 48 | - SendUtils sendUtils; | |
| 49 | - | |
| 50 | - @Autowired | |
| 51 | - LineConfigData lineConfigData; | |
| 52 | - | |
| 53 | - static Logger logger = LoggerFactory.getLogger(DayOfDirectives.class); | |
| 54 | - | |
| 55 | - | |
| 56 | - static{ | |
| 57 | - d60Map = new ConcurrentHashMap<>(); | |
| 58 | - d64Map = new ConcurrentHashMap<>(); | |
| 59 | - pstDirectives = new ConcurrentLinkedQueue<>(); | |
| 60 | - pstD60s = new ConcurrentLinkedQueue<>(); | |
| 61 | - } | |
| 62 | - | |
| 63 | - public void put60(D60 d60) { | |
| 64 | - d60Map.put(d60.getMsgId(), d60); | |
| 65 | - //等待持久化 | |
| 66 | - pstDirectives.add(d60); | |
| 67 | - } | |
| 68 | - | |
| 69 | - public void put64(D64 d64) { | |
| 70 | - d64Map.put(d64.getKey(), d64); | |
| 71 | - //等待持久化 | |
| 72 | - pstDirectives.add(d64); | |
| 73 | - } | |
| 74 | - | |
| 75 | - /** | |
| 76 | - * | |
| 77 | - * @Title: reply @Description: TODO(指令 46,47 响应) @throws | |
| 78 | - */ | |
| 79 | - public void reply(DirectiveReponse res) { | |
| 80 | - Integer msgId = res.getMsgId(); | |
| 81 | - if (msgId == null) { | |
| 82 | - logger.error("reply error , msgId is null."); | |
| 83 | - return; | |
| 84 | - } | |
| 85 | - | |
| 86 | - D60 d60 = d60Map.get(msgId); | |
| 87 | - | |
| 88 | - if (null == d60) { | |
| 89 | - logger.error("找不到msgId: " + msgId + " 对应的指令数据"); | |
| 90 | - return; | |
| 91 | - } | |
| 92 | - | |
| 93 | - switch (res.getStatus()) { | |
| 94 | - case 0: | |
| 95 | - d60.setReply46((short) -1);// 失败 | |
| 96 | - break; | |
| 97 | - case 1: | |
| 98 | - d60.setReply46((short) 0);// 发送成功 | |
| 99 | - d60.setReply46Time(System.currentTimeMillis()); | |
| 100 | - break; | |
| 101 | - case 2: | |
| 102 | - d60.setReply47((short) 0);// 驾驶员阅读 | |
| 103 | - d60.setReply47Time(System.currentTimeMillis()); | |
| 104 | - break; | |
| 105 | - } | |
| 106 | - | |
| 107 | - //更新60数据 | |
| 108 | - pstD60s.add(d60); | |
| 109 | - | |
| 110 | - ScheduleRealInfo sch = d60.getSch(); | |
| 111 | - if (null == sch) | |
| 112 | - return; | |
| 113 | - | |
| 114 | - if (d60.isDispatch()) { | |
| 115 | - // 更新班次状态 | |
| 116 | - sch.setDirectiveState(res.getStatus() * 100); | |
| 117 | - // 通知页面 | |
| 118 | - sendUtils.sendDirectiveToPage(sch); | |
| 119 | - } | |
| 120 | - } | |
| 121 | - | |
| 122 | - /** | |
| 123 | - * | |
| 124 | - * @Title: reply64 @Description: TODO(64 协议响应) @throws | |
| 125 | - */ | |
| 126 | - public void reply64(JSONObject json) { | |
| 127 | - String key = json.getString("deviceId") + "_" + json.getString("timestamp"); | |
| 128 | - | |
| 129 | - D64 d64 = d64Map.get(key); | |
| 130 | - | |
| 131 | - if (null == d64) | |
| 132 | - logger.warn("64响应 -找不到请求源,json: " + json); | |
| 133 | - else { | |
| 134 | - JSONObject data = json.getJSONObject("data"); | |
| 135 | - | |
| 136 | - if (null == data) | |
| 137 | - logger.warn("64响应 data is null ,json: " + json); | |
| 138 | - else { | |
| 139 | - logger.info(d64.getDeviceId() + "_" + d64.getData().getLineId() + "响应:" + data.getShort("requestAck")); | |
| 140 | - /*d64.setRespAck(data.getShort("requestAck")); | |
| 141 | - // 持久化*/ | |
| 142 | - //64 响应不入库了... | |
| 143 | - } | |
| 144 | - } | |
| 145 | - } | |
| 146 | - | |
| 147 | - @Autowired | |
| 148 | - DirectivesPstThread directivesPstThread; | |
| 149 | - public void clearAll(){ | |
| 150 | - d60Map = new ConcurrentHashMap<>(); | |
| 151 | - d64Map = new ConcurrentHashMap<>(); | |
| 152 | - logger.info("清除指令数据 ,,,"); | |
| 153 | - } | |
| 154 | - | |
| 155 | - public Collection<D60> all60(){ | |
| 156 | - return d60Map.values(); | |
| 157 | - } | |
| 158 | - | |
| 159 | - public Collection<D64> all64(){ | |
| 160 | - return d64Map.values(); | |
| 161 | - } | |
| 162 | - | |
| 163 | - public D60 get(Integer msgId){ | |
| 164 | - return d60Map.get(msgId); | |
| 165 | - } | |
| 166 | - | |
| 167 | - public Collection<Directive> all(){ | |
| 168 | - List<Directive> all = new ArrayList<>(); | |
| 169 | - all.addAll(d60Map.values()); | |
| 170 | - all.addAll(d64Map.values()); | |
| 171 | - | |
| 172 | - return all; | |
| 173 | - } | |
| 174 | - | |
| 175 | - public static class DComparator implements Comparator<Directive>{ | |
| 176 | - | |
| 177 | - @Override | |
| 178 | - public int compare(Directive d1, Directive d2) { | |
| 179 | - return (int) (d2.getTimestamp() - d1.getTimestamp()); | |
| 180 | - } | |
| 181 | - } | |
| 182 | - } | |
| 1 | +package com.bsth.data.directive; | |
| 2 | + | |
| 3 | +import com.alibaba.fastjson.JSONObject; | |
| 4 | +import com.bsth.data.LineConfigData; | |
| 5 | +import com.bsth.data.schedule.DayOfSchedule; | |
| 6 | +import com.bsth.entity.directive.D60; | |
| 7 | +import com.bsth.entity.directive.D64; | |
| 8 | +import com.bsth.entity.directive.Directive; | |
| 9 | +import com.bsth.entity.directive.DirectiveReponse; | |
| 10 | +import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 11 | +import com.bsth.service.directive.DirectiveService; | |
| 12 | +import com.bsth.websocket.handler.SendUtils; | |
| 13 | +import org.slf4j.Logger; | |
| 14 | +import org.slf4j.LoggerFactory; | |
| 15 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 16 | +import org.springframework.stereotype.Component; | |
| 17 | + | |
| 18 | +import java.util.*; | |
| 19 | +import java.util.concurrent.ConcurrentHashMap; | |
| 20 | +import java.util.concurrent.ConcurrentLinkedQueue; | |
| 21 | +import java.util.concurrent.ConcurrentMap; | |
| 22 | + | |
| 23 | +/** | |
| 24 | + * | |
| 25 | + * @ClassName: CurrDayDirectives | |
| 26 | + * @Description: TODO(当天指令数据) | |
| 27 | + * @author PanZhao | |
| 28 | + * @date 2016年8月14日 下午5:23:59 | |
| 29 | + * | |
| 30 | + */ | |
| 31 | +@Component | |
| 32 | +public class DayOfDirectives { | |
| 33 | + | |
| 34 | + // 当日60指令缓存 | |
| 35 | + private static ConcurrentMap<Integer, D60> d60Map; | |
| 36 | + | |
| 37 | + // 线路切换指令 64 | |
| 38 | + public static ConcurrentMap<String, D64> d64Map; | |
| 39 | + | |
| 40 | + //等待插入的指令 | |
| 41 | + public static ConcurrentLinkedQueue<Directive> pstDirectives; | |
| 42 | + //等待更新的指令 | |
| 43 | + public static ConcurrentLinkedQueue<D60> pstD60s; | |
| 44 | + | |
| 45 | + @Autowired | |
| 46 | + DirectiveService directiveService; | |
| 47 | + | |
| 48 | + @Autowired | |
| 49 | + SendUtils sendUtils; | |
| 50 | + | |
| 51 | + @Autowired | |
| 52 | + LineConfigData lineConfigData; | |
| 53 | + | |
| 54 | + @Autowired | |
| 55 | + private DayOfSchedule dayOfSchedule; | |
| 56 | + | |
| 57 | + static Logger logger = LoggerFactory.getLogger(DayOfDirectives.class); | |
| 58 | + | |
| 59 | + | |
| 60 | + static{ | |
| 61 | + d60Map = new ConcurrentHashMap<>(); | |
| 62 | + d64Map = new ConcurrentHashMap<>(); | |
| 63 | + pstDirectives = new ConcurrentLinkedQueue<>(); | |
| 64 | + pstD60s = new ConcurrentLinkedQueue<>(); | |
| 65 | + } | |
| 66 | + | |
| 67 | + public void put60(D60 d60) { | |
| 68 | + d60Map.put(d60.getMsgId(), d60); | |
| 69 | + //等待持久化 | |
| 70 | + pstDirectives.add(d60); | |
| 71 | + } | |
| 72 | + | |
| 73 | + public void put64(D64 d64) { | |
| 74 | + d64Map.put(d64.getKey(), d64); | |
| 75 | + //等待持久化 | |
| 76 | + pstDirectives.add(d64); | |
| 77 | + } | |
| 78 | + | |
| 79 | + /** | |
| 80 | + * | |
| 81 | + * @Title: reply @Description: TODO(指令 46,47 响应) @throws | |
| 82 | + */ | |
| 83 | + public void reply(DirectiveReponse res) { | |
| 84 | + Integer msgId = res.getMsgId(); | |
| 85 | + if (msgId == null) { | |
| 86 | + logger.error("reply error , msgId is null."); | |
| 87 | + return; | |
| 88 | + } | |
| 89 | + | |
| 90 | + D60 d60 = d60Map.get(msgId); | |
| 91 | + | |
| 92 | + if (null == d60) { | |
| 93 | + logger.error("找不到msgId: " + msgId + " 对应的指令数据"); | |
| 94 | + return; | |
| 95 | + } | |
| 96 | + | |
| 97 | + switch (res.getStatus()) { | |
| 98 | + case 0: | |
| 99 | + d60.setReply46((short) -1);// 失败 | |
| 100 | + break; | |
| 101 | + case 1: | |
| 102 | + d60.setReply46((short) 0);// 发送成功 | |
| 103 | + d60.setReply46Time(System.currentTimeMillis()); | |
| 104 | + break; | |
| 105 | + case 2: | |
| 106 | + d60.setReply47((short) 0);// 驾驶员阅读 | |
| 107 | + d60.setReply47Time(System.currentTimeMillis()); | |
| 108 | + break; | |
| 109 | + } | |
| 110 | + | |
| 111 | + //更新60数据 | |
| 112 | + pstD60s.add(d60); | |
| 113 | + | |
| 114 | + ScheduleRealInfo sch = d60.getSch(); | |
| 115 | + if (null == sch) | |
| 116 | + return; | |
| 117 | + | |
| 118 | + if (d60.isDispatch()) { | |
| 119 | + // 更新班次状态 | |
| 120 | + sch.setDirectiveState(res.getStatus() * 100); | |
| 121 | + dayOfSchedule.save(sch); | |
| 122 | + // 通知页面 | |
| 123 | + sendUtils.sendDirectiveToPage(sch); | |
| 124 | + } | |
| 125 | + } | |
| 126 | + | |
| 127 | + /** | |
| 128 | + * | |
| 129 | + * @Title: reply64 @Description: TODO(64 协议响应) @throws | |
| 130 | + */ | |
| 131 | + public void reply64(JSONObject json) { | |
| 132 | + String key = json.getString("deviceId") + "_" + json.getString("timestamp"); | |
| 133 | + | |
| 134 | + D64 d64 = d64Map.get(key); | |
| 135 | + | |
| 136 | + if (null == d64) | |
| 137 | + logger.warn("64响应 -找不到请求源,json: " + json); | |
| 138 | + else { | |
| 139 | + JSONObject data = json.getJSONObject("data"); | |
| 140 | + | |
| 141 | + if (null == data) | |
| 142 | + logger.warn("64响应 data is null ,json: " + json); | |
| 143 | + else { | |
| 144 | + logger.info(d64.getDeviceId() + "_" + d64.getData().getLineId() + "响应:" + data.getShort("requestAck")); | |
| 145 | + /*d64.setRespAck(data.getShort("requestAck")); | |
| 146 | + // 持久化*/ | |
| 147 | + //64 响应不入库了... | |
| 148 | + } | |
| 149 | + } | |
| 150 | + } | |
| 151 | + | |
| 152 | + @Autowired | |
| 153 | + DirectivesPstThread directivesPstThread; | |
| 154 | + public void clearAll(){ | |
| 155 | + d60Map = new ConcurrentHashMap<>(); | |
| 156 | + d64Map = new ConcurrentHashMap<>(); | |
| 157 | + logger.info("清除指令数据 ,,,"); | |
| 158 | + } | |
| 159 | + | |
| 160 | + public Collection<D60> all60(){ | |
| 161 | + return d60Map.values(); | |
| 162 | + } | |
| 163 | + | |
| 164 | + public Collection<D64> all64(){ | |
| 165 | + return d64Map.values(); | |
| 166 | + } | |
| 167 | + | |
| 168 | + public D60 get(Integer msgId){ | |
| 169 | + return d60Map.get(msgId); | |
| 170 | + } | |
| 171 | + | |
| 172 | + public Collection<Directive> all(){ | |
| 173 | + List<Directive> all = new ArrayList<>(); | |
| 174 | + all.addAll(d60Map.values()); | |
| 175 | + all.addAll(d64Map.values()); | |
| 176 | + | |
| 177 | + return all; | |
| 178 | + } | |
| 179 | + | |
| 180 | + public static class DComparator implements Comparator<Directive>{ | |
| 181 | + | |
| 182 | + @Override | |
| 183 | + public int compare(Directive d1, Directive d2) { | |
| 184 | + return (int) (d2.getTimestamp() - d1.getTimestamp()); | |
| 185 | + } | |
| 186 | + } | |
| 187 | + } | ... | ... |