Commit fc664e400a748b597130edc65e2a0d8d40834bbb

Authored by 潘钊
1 parent 642c9016

update...

src/main/java/com/bsth/controller/UpstreamEntrance.java
1 1 package com.bsth.controller;
2 2  
3 3 import com.alibaba.fastjson.JSON;
4   -import com.bsth.data.attendance.AttendaceDataBuffer;
5 4 import com.bsth.data.attendance.dto.RemoteAttendaceDTO;
6 5 import com.bsth.data.in_out.buffer.ElectricDataBuffer;
7 6 import com.bsth.data.in_out.entity.Electric;
... ... @@ -31,7 +30,7 @@ public class UpstreamEntrance {
31 30 */
32 31 @RequestMapping(value = "attendace", method = RequestMethod.POST)
33 32 public void attendace(@RequestBody RemoteAttendaceDTO attendace){
34   - AttendaceDataBuffer.put(attendace);
  33 + SignalAndAttConsumeQueue.put(attendace);
35 34 }
36 35  
37 36 /**
... ...
src/main/java/com/bsth/data/abnormal/MainAbnormalClient.java
... ... @@ -3,6 +3,7 @@ package com.bsth.data.abnormal;
3 3 import com.bsth.data.abnormal.entity.AbnormalEntity;
4 4 import com.bsth.data.abnormal.handler.AttendanceHandler;
5 5 import com.bsth.data.abnormal.handler.InOutHandler;
  6 +import com.bsth.data.attendance.entity.JsyAttendance;
6 7 import com.bsth.data.schedule.dto.ScheduleInOut;
7 8 import com.bsth.websocket.handler.SendUtils;
8 9 import com.google.common.collect.ArrayListMultimap;
... ... @@ -96,4 +97,12 @@ public class MainAbnormalClient {
96 97 public AbnormalEntity rfidOut(ScheduleInOut sio) {
97 98 return inOutHandler.rfidOut(sio);
98 99 }
  100 +
  101 + /**
  102 + * 签到
  103 + * @param att
  104 + */
  105 + public AbnormalEntity qiandao(ScheduleInOut sio, JsyAttendance att) {
  106 + return attendanceHandler.qiandao(sio, att);
  107 + }
99 108 }
... ...
src/main/java/com/bsth/data/abnormal/handler/AttendanceHandler.java
1 1 package com.bsth.data.abnormal.handler;
2 2  
3 3 import com.bsth.data.abnormal.entity.AbnormalEntity;
  4 +import com.bsth.data.attendance.entity.JsyAttendance;
4 5 import com.bsth.data.schedule.dto.ScheduleInOut;
5 6 import com.bsth.data.schedule.real.ScheduleDataBuffer;
6 7 import com.bsth.security.util.SecurityUtils;
  8 +import org.joda.time.format.DateTimeFormat;
  9 +import org.joda.time.format.DateTimeFormatter;
7 10 import org.springframework.stereotype.Component;
8 11  
9 12 import java.util.concurrent.ConcurrentHashMap;
... ... @@ -21,6 +24,8 @@ public class AttendanceHandler {
21 24 */
22 25 private static ConcurrentMap<Long, AbnormalEntity> schIdMap;
23 26  
  27 + private static DateTimeFormatter fmtHHmm = DateTimeFormat.forPattern("HH:mm");
  28 +
24 29 static {
25 30 schIdMap = new ConcurrentHashMap<>();
26 31 }
... ... @@ -83,4 +88,26 @@ public class AttendanceHandler {
83 88 schIdMap.remove(ae.getSchId());
84 89 return ae;
85 90 }
  91 +
  92 + /**
  93 + * 一体机签到
  94 + * @param att
  95 + * @return
  96 + */
  97 + public AbnormalEntity qiandao(ScheduleInOut sio, JsyAttendance att) {
  98 + AbnormalEntity ae = schIdMap.get(sio.getId());
  99 + if(null == ae)
  100 + return null;
  101 +
  102 + Long t = att.getAttTime().getTime();
  103 +
  104 +
  105 + ae.setHandlerTime(t);
  106 + ae.setHandlerUser("system");
  107 + ae.setHandlerDes(fmtHHmm.print(t) + " 一体机签到");
  108 +
  109 + sio.reCalcAnStatus();
  110 + schIdMap.remove(ae.getSchId());
  111 + return ae;
  112 + }
86 113 }
... ...
src/main/java/com/bsth/data/attendance/AttendaceDataBuffer.java
1 1 package com.bsth.data.attendance;
2 2  
3   -import com.bsth.data.attendance.dto.RemoteAttendaceDTO;
4   -import com.bsth.data.attendance.entity.JsyAttendance;
5   -import com.bsth.data.msg_queue.SignalAndAttConsumeQueue;
6   -
7   -import java.util.LinkedList;
8   -
9 3 /**
10 4 * 查询一体机实时考勤数据缓存
11 5 * Created by panzhao on 2017/9/4.
12   - */
  6 +
13 7 public class AttendaceDataBuffer {
14 8  
15 9  
... ... @@ -27,3 +21,4 @@ public class AttendaceDataBuffer {
27 21 SignalAndAttConsumeQueue.put(att);
28 22 }
29 23 }
  24 + */
30 25 \ No newline at end of file
... ...
src/main/java/com/bsth/data/attendance/RealAttendaceHandler.java 0 → 100644
  1 +package com.bsth.data.attendance;
  2 +
  3 +import com.bsth.data.abnormal.MainAbnormalClient;
  4 +import com.bsth.data.abnormal.entity.AbnormalEntity;
  5 +import com.bsth.data.attendance.entity.JsyAttendance;
  6 +import com.bsth.data.schedule.dto.ScheduleInOut;
  7 +import com.bsth.data.schedule.real.ScheduleDataBuffer;
  8 +import com.bsth.websocket.handler.SendUtils;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.stereotype.Component;
  11 +
  12 +/**
  13 + * 实时签到退数据管理
  14 + * Created by panzhao on 2018/3/27.
  15 + */
  16 +@Component
  17 +public class RealAttendaceHandler {
  18 +
  19 + @Autowired
  20 + SendUtils sendUtils;
  21 +
  22 + @Autowired
  23 + MainAbnormalClient mainAbnormalClient;
  24 +
  25 + /**
  26 + * 签到
  27 + */
  28 + public void attendace(JsyAttendance att){
  29 + //驾驶员的出场计划
  30 + ScheduleInOut sio = ScheduleDataBuffer.getCurrExecOut(att.getCompany(), att.getUserId(), att.getAt());
  31 +
  32 + //报到时间不覆盖
  33 + if (sio.getAttSjTime() != null)
  34 + return;
  35 +
  36 + sio.setAttSjTime(att.getAt());
  37 + //处理掉相关异常
  38 + AbnormalEntity ae = mainAbnormalClient.qiandao(sio, att);
  39 +
  40 + //通知页面
  41 + sendUtils.scheduleAttendace(sio, ae);
  42 + }
  43 +}
... ...
src/main/java/com/bsth/data/in_out/RealInoutHandler.java
... ... @@ -4,6 +4,7 @@ import com.bsth.data.abnormal.MainAbnormalClient;
4 4 import com.bsth.data.abnormal.entity.AbnormalEntity;
5 5 import com.bsth.data.in_out.carpark.RealBerthManager;
6 6 import com.bsth.data.schedule.dto.ScheduleInOut;
  7 +import com.bsth.data.schedule.real.ScheduleComparator;
7 8 import com.bsth.data.schedule.real.ScheduleDataBuffer;
8 9 import com.bsth.entity.ac.CarInOutEntity;
9 10 import com.bsth.websocket.handler.SendUtils;
... ... @@ -14,7 +15,10 @@ import org.slf4j.LoggerFactory;
14 15 import org.springframework.beans.factory.annotation.Autowired;
15 16 import org.springframework.stereotype.Component;
16 17  
  18 +import java.util.Collections;
  19 +import java.util.Comparator;
17 20 import java.util.LinkedList;
  21 +import java.util.List;
18 22  
19 23 /**
20 24 * 实时进出场数据处理程序
... ... @@ -49,21 +53,22 @@ public class RealInoutHandler {
49 53  
50 54 /**
51 55 * 进出场
  56 + *
52 57 * @param cio
53 58 */
54 59 public void inOut(CarInOutEntity cio) {
55 60 rfidSignalMaps.put(cio.getNbbm(), cio);
56 61  
57   - if(0 == cio.getCarType()){//公交车
  62 + if (0 == cio.getCarType()) {//公交车
58 63 //获取对应的计划排班
59 64 ScheduleInOut sch = ScheduleDataBuffer.get(cio);
60 65  
61 66 //rfid进出场时附加排班信息
62   - if(sch != null && cio.getSignalType()==0)
  67 + if (sch != null && cio.getSignalType() == 0)
63 68 addPlanFiled(cio, sch);
64 69  
65 70 //入库 -只存实进和实出
66   - if(cio.getType() == 2 || cio.getType() == 4)
  71 + if (cio.getType() == 2 || cio.getType() == 4)
67 72 psts.add(cio);
68 73  
69 74 if (cio.getType() == 2 || cio.getType() == 1)//待进 和 实进
... ... @@ -78,13 +83,14 @@ public class RealInoutHandler {
78 83  
79 84 /**
80 85 * 处理异常监管的班次信息
  86 + *
81 87 * @param sio
82 88 * @param cio
83 89 */
84   - public void attachRfidTime(ScheduleInOut sio, CarInOutEntity cio){
85   - if(sio.getBcType().equals("out")){//出场班次
86   - if(sio.getOutTimeRfid() == null ||
87   - (null != sio.getOutTimeRfid() && outSignalMatch(sio, cio))){
  90 + public void attachRfidTime(ScheduleInOut sio, CarInOutEntity cio) {
  91 + if (sio.getBcType().equals("out")) {//出场班次
  92 + if (sio.getOutTimeRfid() == null ||
  93 + (null != sio.getOutTimeRfid() && outSignalMatch(sio, cio))) {
88 94  
89 95 //是否是一个更合适的信号
90 96 sio.setOutTimeRfid(cio.getT());
... ... @@ -99,26 +105,27 @@ public class RealInoutHandler {
99 105  
100 106 /**
101 107 * 信号匹配,
  108 + *
102 109 * @param sio
103 110 * @param cio
104 111 * @return true : 是更合适的信号
105 112 */
106   - public boolean outSignalMatch(ScheduleInOut sio, CarInOutEntity cio){
  113 + public boolean outSignalMatch(ScheduleInOut sio, CarInOutEntity cio) {
107 114 long diff1 = sio.getOutTimeRfid() - sio.getDfsjT();
108 115 long diff2 = cio.getT() - sio.getDfsjT();
109 116  
110   - if(diff1 <= 0 && diff2 <= 0){//都在计划时间之前,用最靠近的信号
111   - return diff1<diff2;
  117 + if (diff1 <= 0 && diff2 <= 0) {//都在计划时间之前,用最靠近的信号
  118 + return diff1 < diff2;
112 119 }
113 120  
114   - if(Math.abs(diff1) > 1000 * 60 * 30
  121 + if (Math.abs(diff1) > 1000 * 60 * 30
115 122 && Math.abs(diff2) < 1000 * 60 * 5)
116 123 return true;
117 124 return false;
118 125 }
119 126  
120 127 private void addPlanFiled(CarInOutEntity cio, ScheduleInOut sch) {
121   - if(null == sch.getOutTimeRfid())
  128 + if (null == sch.getOutTimeRfid())
122 129 sch.setOutTimeRfid(cio.getT());
123 130 //计划时间
124 131 cio.setPt(sch.getDfsjT());
... ... @@ -132,10 +139,10 @@ public class RealInoutHandler {
132 139 /**
133 140 * 人车是否相符
134 141 */
135   - if(StringUtils.isNotEmpty(cio.getJsy())){
  142 + if (StringUtils.isNotEmpty(cio.getJsy())) {
136 143 String sjGh = cio.getJsy().split("/")[0];
137 144  
138   - if(sch.getjGh().equals(sjGh)){
  145 + if (sch.getjGh().equals(sjGh)) {
139 146 cio.setPcMatch(true);
140 147 }
141 148 }
... ... @@ -143,10 +150,65 @@ public class RealInoutHandler {
143 150  
144 151 /**
145 152 * 重新匹配2辆车的计划和实际信号
  153 + *
146 154 * @param oldName
147 155 * @param nbbm
148 156 */
149   - public static void reCalcOutSignal(String oldName, String nbbm) {
  157 + public void reCalcOutSignal(String name1, String nbbm2) {
  158 + //获取车辆的出场计划
  159 + List<ScheduleInOut> arrayA = ScheduleDataBuffer.getByNbbm(name1), arrayB = ScheduleDataBuffer.getByNbbm(nbbm2);
150 160  
  161 + reCalcOutSignal(arrayA);
  162 + reCalcOutSignal(arrayB);
  163 + }
  164 +
  165 + /**
  166 + * 重新为计划匹配出场信号
  167 + *
  168 + * @param arrayA
  169 + */
  170 + private void reCalcOutSignal(List<ScheduleInOut> list) {
  171 + if (null == list || list.size() == 0)
  172 + return;
  173 +
  174 + //清空班次上的时间
  175 + for (ScheduleInOut sio : list)
  176 + sio.setOutTimeRfid(null);
  177 +
  178 + List<CarInOutEntity> signals = rfidSignalMaps.get(list.get(0).getNbbm());
  179 +
  180 + if (null == signals || signals.size() == 0)
  181 + return;
  182 +
  183 + Collections.sort(list, new ScheduleComparator());
  184 + Collections.sort(signals, new CioSignalsComp());
  185 +
  186 + for (CarInOutEntity cio : signals) {
  187 +
  188 + for (ScheduleInOut sio : list)
  189 + matchJh2Sj(cio, sio);
  190 + }
  191 + }
  192 +
  193 + /**
  194 + * 匹配计划和实际
  195 + *
  196 + * @param cio
  197 + * @param sio
  198 + */
  199 + private void matchJh2Sj(CarInOutEntity cio, ScheduleInOut sio) {
  200 + if (null == sio.getOutTimeRfid()
  201 + || outSignalMatch(sio, cio))
  202 + sio.setOutTimeRfid(cio.getT());
151 203 }
152 204 }
  205 +
  206 +
  207 +class CioSignalsComp implements Comparator<CarInOutEntity> {
  208 +
  209 + @Override
  210 + public int compare(CarInOutEntity o1, CarInOutEntity o2) {
  211 + return (int) (o1.getT() - o2.getT());
  212 + }
  213 +}
  214 +
... ...
src/main/java/com/bsth/data/msg_queue/SignalAndAttConsumeQueue.java
1 1 package com.bsth.data.msg_queue;
2 2  
  3 +import com.bsth.data.attendance.RealAttendaceHandler;
3 4 import com.bsth.data.attendance.entity.JsyAttendance;
4 5 import com.bsth.data.in_out.RealInoutHandler;
5 6 import com.bsth.entity.ac.CarInOutEntity;
6   -import com.bsth.service.schedule.ScheduleService;
7 7 import org.slf4j.Logger;
8 8 import org.slf4j.LoggerFactory;
9 9 import org.springframework.beans.BeansException;
... ... @@ -24,7 +24,7 @@ public class SignalAndAttConsumeQueue implements ApplicationContextAware {
24 24  
25 25 private static List<Class> clazzs;
26 26 private static LinkedList<Object> linkedList;
27   - static ScheduleService outScheduleService;
  27 + static RealAttendaceHandler realAttendaceHandler;
28 28 static RealInoutHandler realInoutHandler;
29 29 static ConsumeThread thread;
30 30 static long t;
... ... @@ -59,7 +59,7 @@ public class SignalAndAttConsumeQueue implements ApplicationContextAware {
59 59  
60 60 @Override
61 61 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
62   - outScheduleService = applicationContext.getBean(ScheduleService.class);
  62 + realAttendaceHandler = applicationContext.getBean(RealAttendaceHandler.class);
63 63 realInoutHandler = applicationContext.getBean(RealInoutHandler.class);
64 64 }
65 65  
... ... @@ -77,11 +77,9 @@ public class SignalAndAttConsumeQueue implements ApplicationContextAware {
77 77 obj = linkedList.poll();
78 78 if (null != obj) {
79 79 sleepFlag = false;
80   - //驾驶员签到
81   - if(obj instanceof JsyAttendance)
82   - outScheduleService.jsyReport((JsyAttendance) obj);
83   - //车辆进出场
84   - else if(obj instanceof CarInOutEntity)
  80 + if(obj instanceof JsyAttendance)//驾驶员签到退
  81 + realAttendaceHandler.attendace((JsyAttendance) obj);
  82 + else if(obj instanceof CarInOutEntity)//车辆进出场
85 83 realInoutHandler.inOut((CarInOutEntity)obj);
86 84 } else {
87 85 Thread.sleep(500);
... ...
src/main/java/com/bsth/data/schedule/real/ScheduleDataBuffer.java
... ... @@ -51,6 +51,9 @@ public class ScheduleDataBuffer implements CommandLineRunner {
51 51 @Autowired
52 52 InoutSchFixedRefreshThread fixedRefreshThread;
53 53  
  54 + @Autowired
  55 + RealInoutHandler realInoutHandler;
  56 +
54 57 private final static String TYPE_OUT = "out";
55 58 private final static String TYPE_IN = "in";
56 59  
... ... @@ -96,7 +99,7 @@ public class ScheduleDataBuffer implements CommandLineRunner {
96 99 return cMultimap.get(nbbm);
97 100 }
98 101  
99   - private static void putAll(List<ScheduleInOut> list) {
  102 + private void putAll(List<ScheduleInOut> list) {
100 103 Long t = System.currentTimeMillis();
101 104 for (ScheduleInOut sio : list) {
102 105 sio.setUt(t);
... ... @@ -111,7 +114,7 @@ public class ScheduleDataBuffer implements CommandLineRunner {
111 114 p_c_mapps();
112 115 }
113 116  
114   - public static void put(ScheduleInOut sio) {
  117 + public void put(ScheduleInOut sio) {
115 118 try {
116 119 if(null == sio.getUt())
117 120 sio.setUt(System.currentTimeMillis());
... ... @@ -209,7 +212,7 @@ public class ScheduleDataBuffer implements CommandLineRunner {
209 212 cMultimap = cMultimapCopy;
210 213 }
211 214  
212   - private static void update(ScheduleInOut old, ScheduleInOut now) {
  215 + private void update(ScheduleInOut old, ScheduleInOut now) {
213 216 old.setDfsjT(now.getDfsjT());
214 217 old.setZdsjT(now.getZdsjT());
215 218 old.setAttJhTime(now.getAttJhTime());
... ... @@ -227,7 +230,7 @@ public class ScheduleDataBuffer implements CommandLineRunner {
227 230 String oldName = old.getNbbm();
228 231 old.setNbbm(now.getNbbm());
229 232 //重新匹配车辆计划和实际出场
230   - RealInoutHandler.reCalcOutSignal(oldName, now.getNbbm());
  233 + realInoutHandler.reCalcOutSignal(oldName, now.getNbbm());
231 234 }
232 235 }
233 236  
... ... @@ -335,7 +338,7 @@ public class ScheduleDataBuffer implements CommandLineRunner {
335 338 }
336 339  
337 340 logger.info("同步进出场班数量 " + listCopy.size());
338   - ScheduleDataBuffer.putAll(listCopy);
  341 + putAll(listCopy);
339 342  
340 343 } catch (Exception e) {
341 344 e.printStackTrace();
... ...
src/main/java/com/bsth/service/schedule/ScheduleService.java
... ... @@ -21,9 +21,9 @@ public interface ScheduleService {
21 21 /**
22 22 * 驾驶员报到
23 23 * @param att
24   - */
25   - void jsyReport(JsyAttendance att);
26 24  
  25 + void jsyReport(JsyAttendance att);
  26 + */
27 27 Map<String, Object> findAbnormalByLineArray(String idx);
28 28  
29 29 Map<String,Object> findSchByLpName(String lineCode, String lpName);
... ...
src/main/java/com/bsth/service/schedule/impl/ScheduleServiceImpl.java
... ... @@ -40,6 +40,9 @@ public class ScheduleServiceImpl implements ScheduleService {
40 40  
41 41 private static String dataUrl;
42 42  
  43 + @Autowired
  44 + ScheduleDataBuffer scheduleDataBuffer;
  45 +
43 46 static {
44 47 dataUrl = ConfigUtil.get("data.schedule.inout.url");
45 48 }
... ... @@ -67,7 +70,7 @@ public class ScheduleServiceImpl implements ScheduleService {
67 70 * 驾驶员报到了哦....
68 71 *
69 72 * @param att
70   - */
  73 +
71 74 @Override
72 75 public void jsyReport(JsyAttendance att) {
73 76 //驾驶员的出场计划
... ... @@ -81,7 +84,7 @@ public class ScheduleServiceImpl implements ScheduleService {
81 84 //通知页面
82 85  
83 86 }
84   -
  87 + */
85 88 @Override
86 89 public Map<String, Object> findAbnormalByLineArray(String idx) {
87 90 Map<String, Object> rs = new HashMap<>();
... ... @@ -159,7 +162,7 @@ public class ScheduleServiceImpl implements ScheduleService {
159 162  
160 163 if("SUCCESS".equals(rs.get("status"))){
161 164 ScheduleInOut sio = JSON.toJavaObject(JSON.parseObject(rs.get("t").toString()), ScheduleInOut.class);
162   - ScheduleDataBuffer.put(sio);
  165 + scheduleDataBuffer.put(sio);
163 166  
164 167 //处理相关异常
165 168 List<AbnormalEntity> aes = mainAbnormalClient.dftz(sio.getId(), "调档");
... ... @@ -193,7 +196,7 @@ public class ScheduleServiceImpl implements ScheduleService {
193 196 JSONArray array = rs.getJSONArray("list");
194 197 int size = array.size();
195 198 for(int i=0; i < size;i ++){
196   - ScheduleDataBuffer.put(JSON.toJavaObject(array.getJSONObject(i), ScheduleInOut.class));
  199 + scheduleDataBuffer.put(JSON.toJavaObject(array.getJSONObject(i), ScheduleInOut.class));
197 200 }
198 201 }
199 202  
... ...
src/main/java/com/bsth/websocket/handler/SendUtils.java
... ... @@ -90,4 +90,24 @@ public class SendUtils{
90 90 logger.error("", e);
91 91 }
92 92 }
  93 +
  94 + /**
  95 + * 驾驶员报到
  96 + * @param sio
  97 + */
  98 + public void scheduleAttendace(ScheduleInOut sio, AbnormalEntity ae) {
  99 + Map<String, Object> map = new HashMap<>();
  100 + map.put("fn", "abnormal_att");
  101 + map.put("sio", sio);
  102 + if(null != ae)
  103 + map.put("ae", ae);
  104 +
  105 + ObjectMapper mapper = new ObjectMapper();
  106 +
  107 + try {
  108 + socketHandler.sendMessage(mapper.writeValueAsString(map));
  109 + } catch (Exception e) {
  110 + logger.error("", e);
  111 + }
  112 + }
93 113 }
... ...
src/main/resources/static/js/_websocket.js
... ... @@ -51,7 +51,9 @@ var gb_websocket = (function () {
51 51 var msgHandle = {
52 52 carIn: carInFun,
53 53 carOut: carOutFun,
54   - abnormal_out: gb_o_s_ws_handler.out
  54 + abnormal_out: function (msg) {
  55 + gb_o_s_ws_handler.out(msg);
  56 + }
55 57 };
56 58  
57 59 //websocket回调
... ...
src/main/resources/static/pages/b_p_manager/b_p_main.html
... ... @@ -139,7 +139,7 @@
139 139 fixedExit = true;
140 140 clearTimeout(fixedTimer);
141 141 fixedTimer = null;
142   - gb_inout_websocket.cancelCallback(socketInoutHandler);
  142 + gb_websocket.cancelCallback(socketInoutHandler);
143 143 });
144 144  
145 145 function queryRealInfos(cb) {
... ...