Commit de21279e53db06924d85c41fe3c78593785e0a1a
1 parent
4b09a9a2
Exists in
master
增加获取设备指纹
Showing
1 changed file
with
171 additions
and
20 deletions
Show diff stats
cloud/zkAttendance/src/main/java/com/sincere/att/controller/AttPushController.java
@@ -8,12 +8,16 @@ import com.sincere.att.feign.XaFeign; | @@ -8,12 +8,16 @@ import com.sincere.att.feign.XaFeign; | ||
8 | import com.sincere.att.logs.LogName; | 8 | import com.sincere.att.logs.LogName; |
9 | import com.sincere.att.logs.LoggerUtils; | 9 | import com.sincere.att.logs.LoggerUtils; |
10 | import com.sincere.att.vo.AttendanceInfoBean; | 10 | import com.sincere.att.vo.AttendanceInfoBean; |
11 | +import com.sincere.att.vo.CheckOrderVo; | ||
11 | import com.sincere.att.vo.FingerOrderVo; | 12 | import com.sincere.att.vo.FingerOrderVo; |
12 | import com.sincere.att.vo.UserOrderVo; | 13 | import com.sincere.att.vo.UserOrderVo; |
13 | import com.sincere.common.dto.smartCampus.SZ_AttendanceDto; | 14 | import com.sincere.common.dto.smartCampus.SZ_AttendanceDto; |
14 | import com.sincere.common.dto.xiaoan.FingerDto; | 15 | import com.sincere.common.dto.xiaoan.FingerDto; |
15 | import com.sincere.common.util.DateUtils; | 16 | import com.sincere.common.util.DateUtils; |
16 | import com.sincere.common.util.HttpClientUtils; | 17 | import com.sincere.common.util.HttpClientUtils; |
18 | +import io.swagger.annotations.ApiImplicitParam; | ||
19 | +import io.swagger.annotations.ApiImplicitParams; | ||
20 | +import io.swagger.annotations.ApiOperation; | ||
17 | import org.apache.commons.lang3.StringUtils; | 21 | import org.apache.commons.lang3.StringUtils; |
18 | import org.slf4j.Logger; | 22 | import org.slf4j.Logger; |
19 | import org.springframework.beans.factory.annotation.Autowired; | 23 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -28,6 +32,7 @@ import java.io.UnsupportedEncodingException; | @@ -28,6 +32,7 @@ import java.io.UnsupportedEncodingException; | ||
28 | import java.math.BigInteger; | 32 | import java.math.BigInteger; |
29 | import java.text.SimpleDateFormat; | 33 | import java.text.SimpleDateFormat; |
30 | import java.util.*; | 34 | import java.util.*; |
35 | +import java.util.concurrent.atomic.AtomicReference; | ||
31 | 36 | ||
32 | /** | 37 | /** |
33 | * 所有的设备请求都会在url参数里携带SN,这是设备序列号(serial number的缩写),每个设备唯一标识 | 38 | * 所有的设备请求都会在url参数里携带SN,这是设备序列号(serial number的缩写),每个设备唯一标识 |
@@ -52,8 +57,125 @@ public class AttPushController { | @@ -52,8 +57,125 @@ public class AttPushController { | ||
52 | @Autowired | 57 | @Autowired |
53 | XaFeign xaFeign; | 58 | XaFeign xaFeign; |
54 | 59 | ||
60 | + @RequestMapping(value = "GetDeviceCmd", method = RequestMethod.GET) | ||
61 | + @ApiOperation(value = "查询待处理指令") | ||
62 | + @ApiImplicitParams({@ApiImplicitParam(name = "schoolId", value = "学校id"), | ||
63 | + @ApiImplicitParam(name = "deviceId", value = "设备id")}) | ||
64 | + public String GetDeviceCmd(@RequestParam("schoolId") String schoolId, | ||
65 | + @RequestParam("deviceId") String deviceId) { | ||
66 | + try { | ||
67 | + if(schoolId=="1221") | ||
68 | + { | ||
69 | + | ||
70 | + } | ||
71 | + if(StringUtils.isNotBlank(deviceId)){ | ||
72 | + List<String> cmds = cmdMap.get(deviceId); | ||
73 | + if (cmds != null && cmds.size() > 0) { | ||
74 | + return cmds.toString(); | ||
75 | + } | ||
76 | + return "cmd is empty"; | ||
77 | + } | ||
78 | + else{ | ||
79 | + return "device not is null"; | ||
80 | + } | ||
81 | + } catch (Exception e) { | ||
82 | + return e.getMessage(); | ||
83 | + } | ||
84 | + } | ||
85 | + | ||
86 | + //C:${CmdID}:Check 检查并传送新数据 | ||
87 | + @RequestMapping(value = "GetLatestData", method = RequestMethod.GET) | ||
88 | + @ApiOperation(value = "检查并上传新数据") | ||
89 | + @ApiImplicitParams({@ApiImplicitParam(name = "schoolId", value = "学校id"), | ||
90 | + @ApiImplicitParam(name = "deviceId", value = "设备id")}) | ||
91 | + public void GetLatestData(@RequestParam("schoolId") String schoolId, | ||
92 | + @RequestParam("deviceId") String deviceId) { | ||
93 | + | ||
94 | + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); | ||
95 | + String date=simpleDateFormat.format(new Date()); | ||
96 | + List<String> order = new ArrayList<>(); | ||
97 | + CheckOrderVo vo = new CheckOrderVo(); | ||
98 | + vo.setStudentName(deviceId+date); | ||
99 | + int number = 1; | ||
100 | + try { | ||
101 | + number = cmdOrderMap.get(deviceId); | ||
102 | + } catch (Exception e) { | ||
103 | + | ||
104 | + } | ||
105 | + number++; | ||
106 | + cmdOrderMap.put(deviceId, number); | ||
107 | + | ||
108 | + if (!order.contains(vo.toString())) { | ||
109 | + order.add(vo.toString()); | ||
110 | + } | ||
111 | + | ||
112 | + cmdMap.put(deviceId, order); | ||
113 | + | ||
114 | + } | ||
115 | + | ||
116 | + @RequestMapping(value = "sendSingleUser", method = RequestMethod.GET) | ||
117 | + @ApiOperation(value = "下发单个用户") | ||
118 | + @ApiImplicitParams({@ApiImplicitParam(name = "schoolId", value = "学校id"), | ||
119 | + @ApiImplicitParam(name = "deviceId", value = "设备id"), | ||
120 | + @ApiImplicitParam(name = "studentId", value = "学生id")}) | ||
121 | + public void sendSingleUser(@RequestParam("schoolId") String schoolId, | ||
122 | + @RequestParam("deviceId") String deviceId, | ||
123 | + @RequestParam("studentId") int studentId) { | ||
124 | +// String result1 = HttpClientUtils.httpGet2("http://campus.myjxt.com/api/EasyN/GetStudentDetail?studentid="+studentId+"&schoolId="+schoolId); | ||
125 | + JSONObject result = HttpClientUtils.httpGet("http://campus.myjxt.com/api/EasyN/GetStudentDetail?studentid="+studentId+"&schoolId="+schoolId); | ||
126 | + JSONObject array = (JSONObject) result.get("data"); | ||
127 | + List<String> order = new ArrayList<>(); | ||
128 | + UserOrderVo vo = new UserOrderVo(); | ||
129 | + vo.setStudentId((Integer) array.get("studentId")); | ||
130 | + vo.setStudentName((String) array.get("studentName")); | ||
131 | + int number = 1; | ||
132 | + try { | ||
133 | + number = cmdOrderMap.get(deviceId); | ||
134 | + } catch (Exception e) { | ||
135 | + | ||
136 | + } | ||
137 | + vo.setNumber(number); | ||
138 | + number++; | ||
139 | + cmdOrderMap.put(deviceId, number); | ||
140 | + if (vo.getStudentId() != 0) { | ||
141 | +// if (vo.getStudentId() == 72196){ | ||
142 | + //todo:测试专用 | ||
143 | + if (!order.contains(vo.toString())) { | ||
144 | + order.add(vo.toString()); | ||
145 | + } | ||
146 | +// } | ||
147 | + } | ||
148 | + cmdMap.put(deviceId, order); | ||
149 | + | ||
150 | + } | ||
151 | + | ||
152 | + @RequestMapping(value = "sendSingleFinger", method = RequestMethod.GET) | ||
153 | + public void sendSingleFinger(@RequestParam("StudentId") int StudentId,@RequestParam(value = "deviceId") String deviceId) { | ||
154 | + | ||
155 | + List<String> order = new ArrayList<>(); | ||
156 | +// for (int i = 0; i < array.size(); i++) { | ||
157 | +// JSONObject student = (JSONObject) array.get(i); | ||
158 | + FingerOrderVo vo = new FingerOrderVo(); | ||
159 | + int number = 1; | ||
160 | + try { | ||
161 | + number = cmdOrderMap.get(deviceId); | ||
162 | + } catch (Exception e) { | ||
163 | + | ||
164 | + } | ||
165 | + vo.setNumber(number); | ||
166 | + vo.setOrder(xaFeign.selectFinger((Integer) StudentId)); | ||
167 | + number++; | ||
168 | + cmdOrderMap.put(deviceId, number); | ||
169 | + if (StringUtils.isNotBlank(vo.getOrder())) { | ||
170 | + order.add(vo.toString()); | ||
171 | + } | ||
172 | + //} | ||
173 | + cmdMap.put(deviceId, order); | ||
174 | + //} | ||
175 | + } | ||
176 | + | ||
55 | @RequestMapping(value = "sendUser", method = RequestMethod.GET) | 177 | @RequestMapping(value = "sendUser", method = RequestMethod.GET) |
56 | - public void sendUser(int roomId) { | 178 | + public void sendUser(@RequestParam("roomId") int roomId) { |
57 | JSONObject object = new JSONObject(); | 179 | JSONObject object = new JSONObject(); |
58 | object.put("pageIndex", 1); | 180 | object.put("pageIndex", 1); |
59 | object.put("roomId", roomId); | 181 | object.put("roomId", roomId); |
@@ -91,7 +213,7 @@ public class AttPushController { | @@ -91,7 +213,7 @@ public class AttPushController { | ||
91 | } | 213 | } |
92 | 214 | ||
93 | @RequestMapping(value = "sendFinger", method = RequestMethod.GET) | 215 | @RequestMapping(value = "sendFinger", method = RequestMethod.GET) |
94 | - public void sendFinger(int roomId) { | 216 | + public void sendFinger(@RequestParam("roomId") int roomId,@RequestParam(value = "deviceId",required = false) String deviceId) { |
95 | JSONObject object = new JSONObject(); | 217 | JSONObject object = new JSONObject(); |
96 | object.put("PageIndex", 1); | 218 | object.put("PageIndex", 1); |
97 | object.put("roomId", roomId); | 219 | object.put("roomId", roomId); |
@@ -100,6 +222,7 @@ public class AttPushController { | @@ -100,6 +222,7 @@ public class AttPushController { | ||
100 | JSONArray array = (JSONArray) ((JSONObject) result.get("data")).get("roomList"); | 222 | JSONArray array = (JSONArray) ((JSONObject) result.get("data")).get("roomList"); |
101 | List<String> attendanceList = scFeign.selectRoomAttendance(roomId); | 223 | List<String> attendanceList = scFeign.selectRoomAttendance(roomId); |
102 | for (String attendance : attendanceList) { | 224 | for (String attendance : attendanceList) { |
225 | + if(StringUtils.isNotBlank(deviceId)&&!attendance.contains(deviceId)) continue; | ||
103 | List<String> order = new ArrayList<>(); | 226 | List<String> order = new ArrayList<>(); |
104 | for (int i = 0; i < array.size(); i++) { | 227 | for (int i = 0; i < array.size(); i++) { |
105 | JSONObject student = (JSONObject) array.get(i); | 228 | JSONObject student = (JSONObject) array.get(i); |
@@ -127,13 +250,15 @@ public class AttPushController { | @@ -127,13 +250,15 @@ public class AttPushController { | ||
127 | * 格式为 /iclock/cdata?options=all&language=xxxx&pushver=xxxx | 250 | * 格式为 /iclock/cdata?options=all&language=xxxx&pushver=xxxx |
128 | */ | 251 | */ |
129 | @RequestMapping(value = "/cdata", params = {"options", "language", "pushver"}, method = RequestMethod.GET) | 252 | @RequestMapping(value = "/cdata", params = {"options", "language", "pushver"}, method = RequestMethod.GET) |
130 | - public void init(String SN, String options, String language, String pushver, HttpServletRequest request, | ||
131 | - @RequestParam(required = false) String PushOptionsFlag, HttpServletResponse response) { | 253 | + public void init(String SN,String options,String language,String pushver,HttpServletRequest request, |
254 | + @RequestParam(required = false) String PushOptionsFlag, | ||
255 | + HttpServletResponse response) { | ||
132 | try { | 256 | try { |
257 | + System.out.println("设备上电:" + SN); | ||
133 | if (cmdMap.get(SN) == null) { | 258 | if (cmdMap.get(SN) == null) { |
134 | System.out.println("设备上线:" + SN); | 259 | System.out.println("设备上线:" + SN); |
135 | cmdMap.put(SN, new ArrayList<>()); | 260 | cmdMap.put(SN, new ArrayList<>()); |
136 | - cmdOrderMap.put(SN, 1); | 261 | + cmdOrderMap.put(SN, 10000); |
137 | } | 262 | } |
138 | if (scFeign.selectAttendaceWithId(SN) == null) { | 263 | if (scFeign.selectAttendaceWithId(SN) == null) { |
139 | SZ_AttendanceDto attendanceDto = new SZ_AttendanceDto(); | 264 | SZ_AttendanceDto attendanceDto = new SZ_AttendanceDto(); |
@@ -162,6 +287,7 @@ public class AttPushController { | @@ -162,6 +287,7 @@ public class AttPushController { | ||
162 | public void heartBeat(String SN, HttpServletResponse response) { | 287 | public void heartBeat(String SN, HttpServletResponse response) { |
163 | scFeign.updateAttendance(SN); | 288 | scFeign.updateAttendance(SN); |
164 | StringBuffer sb = new StringBuffer("OK"); | 289 | StringBuffer sb = new StringBuffer("OK"); |
290 | + //System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+"设备心跳:" + SN); | ||
165 | List<String> cmds = cmdMap.get(SN); | 291 | List<String> cmds = cmdMap.get(SN); |
166 | // if (null != cmds && cmds.size() > 10) | 292 | // if (null != cmds && cmds.size() > 10) |
167 | // cmds = cmds.subList(0, 10); | 293 | // cmds = cmds.subList(0, 10); |
@@ -169,7 +295,7 @@ public class AttPushController { | @@ -169,7 +295,7 @@ public class AttPushController { | ||
169 | System.out.println("设备上线:" + SN); | 295 | System.out.println("设备上线:" + SN); |
170 | cmds = new ArrayList<>(); | 296 | cmds = new ArrayList<>(); |
171 | cmdMap.put(SN, cmds); | 297 | cmdMap.put(SN, cmds); |
172 | - cmdOrderMap.put(SN, 1); | 298 | + cmdOrderMap.put(SN, 10000); |
173 | } | 299 | } |
174 | if (cmds != null && cmds.size() > 0) { | 300 | if (cmds != null && cmds.size() > 0) { |
175 | sb.setLength(0);//如果有命令就不返回OK了 | 301 | sb.setLength(0);//如果有命令就不返回OK了 |
@@ -205,24 +331,36 @@ public class AttPushController { | @@ -205,24 +331,36 @@ public class AttPushController { | ||
205 | @RequestMapping("/devicecmd") | 331 | @RequestMapping("/devicecmd") |
206 | public void handleCmd(String SN, @RequestBody String data, HttpServletResponse response) { | 332 | public void handleCmd(String SN, @RequestBody String data, HttpServletResponse response) { |
207 | //判断data 清空map | 333 | //判断data 清空map |
334 | + //ID=10000&Return=-10&CMD=DATA 指纹下发返回return=-10,表示指纹机没有这个用户数据 | ||
208 | List<String> cmdList = cmdMap.get(SN); | 335 | List<String> cmdList = cmdMap.get(SN); |
209 | String[] returnList = data.split("\n"); | 336 | String[] returnList = data.split("\n"); |
210 | if (returnList != null && returnList.length > 0 && cmdList != null && cmdList.size() > 0) { | 337 | if (returnList != null && returnList.length > 0 && cmdList != null && cmdList.size() > 0) { |
211 | System.out.println("----returnList:" + returnList.length); | 338 | System.out.println("----returnList:" + returnList.length); |
212 | for (String message : returnList) { | 339 | for (String message : returnList) { |
340 | + System.out.println("----returnList:"+ SN + "," + message); | ||
213 | String number = message.substring(message.indexOf("=") + 1, message.indexOf("&")); | 341 | String number = message.substring(message.indexOf("=") + 1, message.indexOf("&")); |
214 | String result = message.substring(message.indexOf("=", message.indexOf("&")) + 1, message.indexOf("&", message.indexOf("&") + 1)); | 342 | String result = message.substring(message.indexOf("=", message.indexOf("&")) + 1, message.indexOf("&", message.indexOf("&") + 1)); |
215 | - if (result.equals("0")) { | 343 | + //if (result.equals("0")) { |
216 | Iterator<String> it = cmdList.iterator(); | 344 | Iterator<String> it = cmdList.iterator(); |
217 | while (((Iterator) it).hasNext()) { | 345 | while (((Iterator) it).hasNext()) { |
218 | String b = it.next(); | 346 | String b = it.next(); |
219 | if (b.contains("C:" + number)) { | 347 | if (b.contains("C:" + number)) { |
220 | it.remove(); | 348 | it.remove(); |
221 | - System.out.println("----设备接收数据成功:" + SN + "----number:" + number); | 349 | + |
350 | + System.out.println("----设备接收数据"+(Integer.parseInt(result)==0?"成功":"--失败--")+":" + SN + "----number:" + number); | ||
222 | } | 351 | } |
223 | } | 352 | } |
224 | - } | 353 | + if(message.contains("CMD=DATA")) |
354 | + { | ||
355 | + | ||
356 | + } | ||
357 | + if(message.contains("CMD=CHECK")) | ||
358 | + { | ||
359 | + | ||
360 | + } | ||
361 | + //} | ||
225 | } | 362 | } |
363 | + | ||
226 | } | 364 | } |
227 | try { | 365 | try { |
228 | response.getWriter().write("OK"); | 366 | response.getWriter().write("OK"); |
@@ -270,26 +408,39 @@ public class AttPushController { | @@ -270,26 +408,39 @@ public class AttPushController { | ||
270 | String jsonResult = JSON.toJSONString(attendanceInfoBean); | 408 | String jsonResult = JSON.toJSONString(attendanceInfoBean); |
271 | String urlHXY = "http://campus.myjxt.com/api/XiaoAnCommon/SendHXY"; | 409 | String urlHXY = "http://campus.myjxt.com/api/XiaoAnCommon/SendHXY"; |
272 | JSONObject jsonObject = HttpClientUtils.httpPostJson(urlHXY, jsonResult); | 410 | JSONObject jsonObject = HttpClientUtils.httpPostJson(urlHXY, jsonResult); |
273 | - if ((int) jsonObject.get("status") == 1) { | 411 | + //if ((int) jsonObject.get("status") == 1) { |
412 | + if ( Integer.parseInt(jsonObject.get("data").toString()) == 0) { | ||
274 | Log_kaoInfo.info("出入寝签到成功:" + SN + " 卡号:" + cardNo); | 413 | Log_kaoInfo.info("出入寝签到成功:" + SN + " 卡号:" + cardNo); |
275 | } else { | 414 | } else { |
276 | - Log_orderFail.info("出入寝签到失败:" + SN + " 卡号:" + cardNo + " result1:" + jsonObject.toJSONString()); | 415 | + Log_kaoInfo.info("出入寝签到失败:" + SN + " 卡号:" + cardNo + " result1:" + jsonObject.toJSONString()); |
277 | } | 416 | } |
278 | } else { | 417 | } else { |
279 | - System.out.println(cardNo); | 418 | + System.out.println(list[0]+":card is "+cardNo); |
280 | } | 419 | } |
281 | } | 420 | } |
282 | if ("OPERLOG".equals(table)) { | 421 | if ("OPERLOG".equals(table)) { |
422 | + | ||
283 | //操作日志 | 423 | //操作日志 |
284 | if (data.substring(0, 3).contains("FP")) { | 424 | if (data.substring(0, 3).contains("FP")) { |
285 | - //添加指纹 | ||
286 | - String studentId = data.substring(data.indexOf("=") + 1, data.indexOf("\t", data.indexOf("="))); | ||
287 | - String order = data.substring(3); | ||
288 | - FingerDto fingerDto = new FingerDto(); | ||
289 | - fingerDto.setOrderMsg(order); | ||
290 | - fingerDto.setStudentId(Integer.valueOf(studentId)); | ||
291 | - fingerDto.setCreateTime(new Date()); | ||
292 | - xaFeign.insertFinger(fingerDto); | 425 | + String[] finger = data.split("FP "); |
426 | + for (int j = 0; j < finger.length; j++) { | ||
427 | + String fingerInfo = finger[j]; | ||
428 | + if(org.springframework.util.StringUtils.isEmpty(fingerInfo)) continue; | ||
429 | + | ||
430 | + //添加指纹 | ||
431 | + String studentId = fingerInfo .substring(fingerInfo .indexOf("=") + 1, fingerInfo .indexOf("\t", fingerInfo .indexOf("="))); | ||
432 | +// String order = data.substring(3); | ||
433 | + String ret= xaFeign.selectFinger(Integer.parseInt(studentId)); | ||
434 | + if(!org.springframework.util.StringUtils.isEmpty(ret)) continue; | ||
435 | + | ||
436 | + //String order = data; | ||
437 | + FingerDto fingerDto = new FingerDto(); | ||
438 | + fingerDto.setOrderMsg(fingerInfo); | ||
439 | + fingerDto.setStudentId(Integer.valueOf(studentId)); | ||
440 | + fingerDto.setCreateTime(new Date()); | ||
441 | + xaFeign.insertFinger(fingerDto); | ||
442 | + | ||
443 | + } | ||
293 | } | 444 | } |
294 | } | 445 | } |
295 | try { | 446 | try { |