Commit ad296f75cc57c68080616ec44e28db75436c6ea9
1 parent
631fbdf8
Exists in
master
智能校卫:海康、大华人脸机代码提交
Showing
73 changed files
with
3388 additions
and
1314 deletions
Show diff stats
cloud/dahua/src/main/java/com/example/dahua/DahuaApplication.java
cloud/dahua/src/main/java/com/example/dahua/MyTask.java
... | ... | @@ -37,6 +37,7 @@ import java.io.IOException; |
37 | 37 | import java.io.UnsupportedEncodingException; |
38 | 38 | import java.text.SimpleDateFormat; |
39 | 39 | import java.util.*; |
40 | +import java.util.concurrent.CopyOnWriteArrayList; | |
40 | 41 | |
41 | 42 | @Component |
42 | 43 | @Slf4j |
... | ... | @@ -72,7 +73,6 @@ public class MyTask implements ApplicationRunner { |
72 | 73 | //设备断线 |
73 | 74 | public static boolean isFirstAutoRegister = false; |
74 | 75 | |
75 | - public static String inTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); | |
76 | 76 | |
77 | 77 | @Override |
78 | 78 | public void run(ApplicationArguments args) throws Exception { |
... | ... | @@ -143,7 +143,9 @@ public class MyTask implements ApplicationRunner { |
143 | 143 | String deviceId = getDeviceId(pchDVRIP, nDVRPort); |
144 | 144 | log.info("DisConnect Device: {}, IP: {}, Port: {}",deviceId,pchDVRIP,nDVRPort); |
145 | 145 | if (!StringUtils.isEmpty(deviceId)) { |
146 | - myTaskUtil.attendanceService.updateConnectStateWithDevid(0,inTime,deviceId); | |
146 | + String inTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); | |
147 | + //保存设备 | |
148 | + saveAttendanceService(deviceId,pchDVRIP,nDVRPort,0); | |
147 | 149 | GateModule.stopRealLoadPic(attachLongMap.get(deviceId)); |
148 | 150 | //移除在线 |
149 | 151 | removeDevice(deviceId); |
... | ... | @@ -169,7 +171,9 @@ public class MyTask implements ApplicationRunner { |
169 | 171 | String deviceId = getDeviceId(pchDVRIP, nDVRPort); |
170 | 172 | log.info("ReConnect Device: {},IP: {},Port: {}", deviceId,pchDVRIP, nDVRPort); |
171 | 173 | if (!StringUtils.isEmpty(deviceId)) { |
172 | - myTaskUtil.attendanceService.updateConnectStateWithDevid(1,inTime,deviceId); | |
174 | + String inTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); | |
175 | + //保存设备 | |
176 | + saveAttendanceService(deviceId,pchDVRIP,nDVRPort,1); | |
173 | 177 | DeviceInfoBean deviceInfoBean = new DeviceInfoBean(); |
174 | 178 | deviceInfoBean.setDevcieId(deviceId); |
175 | 179 | deviceInfoBean.setDeviceIp(pchDVRIP); |
... | ... | @@ -226,7 +230,7 @@ public class MyTask implements ApplicationRunner { |
226 | 230 | log.info("Register Device Info Device address: {},port: {},DeviceID: {}", pIp, wPort, deviceId); |
227 | 231 | log.info("EM_LISTEN_TYPE:设备注册携带序列号"); |
228 | 232 | //保存设备 |
229 | - saveAttendanceService(deviceId,pIp,wPort); | |
233 | + saveAttendanceService(deviceId,pIp,wPort,1); | |
230 | 234 | CDevInfo dev = new CDevInfo(); |
231 | 235 | System.arraycopy(pIp.getBytes(),0,dev.address,0,pIp.getBytes().length); |
232 | 236 | dev.port=wPort; |
... | ... | @@ -391,7 +395,18 @@ public class MyTask implements ApplicationRunner { |
391 | 395 | if (!path.exists()) { |
392 | 396 | path.mkdir(); |
393 | 397 | } |
394 | - | |
398 | + //设备ID | |
399 | + CDevInfo data = new CDevInfo(); | |
400 | + ToolKits.GetPointerData(dwUser, data); | |
401 | + String szSn = new String(data.szSN).trim(); | |
402 | +// if(dwAlarmType == NetSDKLib.EVENT_IVS_FACERECOGNITION){ | |
403 | +//// ToolKits.GetPointerData(pAlarmInfo, msg); | |
404 | +//// //卡号 | |
405 | +//// String card = new String(msg.szCardNo).trim(); | |
406 | +//// //开门用户 | |
407 | +//// String userId = new String(msg.szUID).trim(); | |
408 | +//// log.info("你来了。。。。"); | |
409 | +// } | |
395 | 410 | ///< 门禁事件 |
396 | 411 | if (dwAlarmType == NetSDKLib.EVENT_IVS_ACCESS_CTL) { |
397 | 412 | NetSDKLib.DEV_EVENT_ACCESS_CTL_INFO msg = new NetSDKLib.DEV_EVENT_ACCESS_CTL_INFO(); |
... | ... | @@ -403,11 +418,9 @@ public class MyTask implements ApplicationRunner { |
403 | 418 | String userId = new String(msg.szUserID).trim(); |
404 | 419 | //开门错误码 |
405 | 420 | int messageCode = msg.nErrorCode; |
406 | - //设备ID | |
407 | - CDevInfo data = new CDevInfo(); | |
408 | - ToolKits.GetPointerData(dwUser, data); | |
409 | - String szSn = new String(data.szSN).trim(); | |
410 | 421 | log.info("设备ID: {}, 开门用户ID: {}, 开门卡号: {}",szSn,userId,card); |
422 | + //处理心跳 | |
423 | + saveAttendanceService(szSn,"",0,1); | |
411 | 424 | try { |
412 | 425 | if (!StringUtils.isEmpty(card)) { |
413 | 426 | // 保存图片,获取图片缓存 |
... | ... | @@ -428,7 +441,6 @@ public class MyTask implements ApplicationRunner { |
428 | 441 | outOrIn= StringUtils.isEmpty(attendanceBean.getOutOrIn())?0:Integer.parseInt(attendanceBean.getOutOrIn()); |
429 | 442 | } |
430 | 443 | } |
431 | - | |
432 | 444 | /** |
433 | 445 | * 卡号取反(大写) |
434 | 446 | * 注:若设备为一体机、且非"126上虞城东小学、393上虞实验中学"学校,卡则取反 |
... | ... | @@ -569,14 +581,14 @@ public class MyTask implements ApplicationRunner { |
569 | 581 | * @param ip |
570 | 582 | * @param port |
571 | 583 | */ |
572 | - private static void saveAttendanceService(String deviceId, String ip, int port){ | |
584 | + public static void saveAttendanceService(String deviceId, String ip, int port,int status){ | |
585 | + String inTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); | |
573 | 586 | String clintType = String.valueOf(EnumDeviceType.DH_FACE.deviceType); |
574 | 587 | if(deviceId.startsWith("ytj")){ |
575 | 588 | clintType = String.valueOf(EnumDeviceType.DH_FACE_YTJ.deviceType); |
576 | 589 | } |
577 | - //联网成功 | |
578 | - String status = "1"; | |
579 | - myTaskUtil.attendanceService.insert(deviceId, clintType, ip,String.valueOf(port), inTime, "-1",status); | |
590 | + | |
591 | + myTaskUtil.attendanceService.insert(deviceId,clintType, ip,String.valueOf(port), inTime, "-1",1,status); | |
580 | 592 | } |
581 | 593 | |
582 | 594 | /** |
... | ... | @@ -710,7 +722,7 @@ public class MyTask implements ApplicationRunner { |
710 | 722 | log.info("设备ID集: "+ JsonUtils.nonDefaultMapper().toJson(kanbanIds)); |
711 | 723 | for (String kanbanId : kanbanIds) { |
712 | 724 | String data = "{\"cmd\":\"" + 34 + "\",\"clientId\":\"" + kanbanId + "\",\"data\":{\"cardNum\":\"" + cardNum + "\",\"inOrOut\":\"" + inOrOut + "\"}}"; |
713 | - log.info("====== 开始推送看板======, kanbanId = {}, cardNum = {},content ={}",kanbanId,cardNum,data); | |
725 | +// log.info("====== 开始推送看板======, kanbanId = {}, cardNum = {},content ={}",kanbanId,cardNum,data); | |
714 | 726 | mqttManager.sendMqQD(kanbanId, data); |
715 | 727 | } |
716 | 728 | } else { |
... | ... | @@ -729,7 +741,7 @@ public class MyTask implements ApplicationRunner { |
729 | 741 | for (int i = 0; i < clintIds.size(); i++) { |
730 | 742 | String clintId = clintIds.get(i); |
731 | 743 | String data = "{\"cmd\":\"" + 34 + "\",\"clientId\":\"" + clintId + "\",\"data\":{\"cardNum\":\"" + cardNum + "\",\"inOrOut\":\"" + inOrOut + "\"}}"; |
732 | - log.info("====== 开始推送看板======, deviceId = {}, cardNum = {},content ={}",clintId,cardNum,data); | |
744 | +// log.info("====== 开始推送看板======, deviceId = {}, cardNum = {},content ={}",clintId,cardNum,data); | |
733 | 745 | mqttManager.sendMqQD(clintId, data); |
734 | 746 | } |
735 | 747 | } |
... | ... | @@ -743,11 +755,9 @@ public class MyTask implements ApplicationRunner { |
743 | 755 | |
744 | 756 | public static boolean openDoor(NetSDKLib.LLong lLong) { |
745 | 757 | open.nChannelID = 0; |
746 | - | |
747 | 758 | open.write(); |
748 | 759 | boolean openSuccess = LoginModule.netsdk.CLIENT_ControlDeviceEx(lLong, NetSDKLib.CtrlType.CTRLTYPE_CTRL_ACCESS_OPEN, open.getPointer(), null, 5000); |
749 | 760 | open.read(); |
750 | - | |
751 | 761 | if (!openSuccess) { |
752 | 762 | log.warn("open Door error: 0x: "+ Long.toHexString(LoginModule.netsdk.CLIENT_GetLastError())); |
753 | 763 | return false; | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/async/MyScheduledTask.java
... | ... | @@ -8,10 +8,15 @@ import com.example.dahua.bean.WGBean; |
8 | 8 | import com.example.dahua.dao.UserDao; |
9 | 9 | import com.example.dahua.lib.Utils; |
10 | 10 | import com.example.dahua.mqtt.MqttManager; |
11 | +import com.example.dahua.service.UserOperateService; | |
11 | 12 | import com.example.dahua.utils.DateFormatUtil; |
12 | 13 | import com.example.dahua.utils.DateUtils; |
13 | 14 | import com.example.dahua.utils.FileUtils; |
15 | +import com.example.dahua.xiananDao.SearchMapper; | |
14 | 16 | import com.example.dahua.xiananDao.SendRecordDao; |
17 | +import com.google.common.util.concurrent.ThreadFactoryBuilder; | |
18 | +import lombok.extern.slf4j.Slf4j; | |
19 | +import org.apache.commons.collections4.CollectionUtils; | |
15 | 20 | import org.json.JSONException; |
16 | 21 | import org.json.JSONObject; |
17 | 22 | import org.springframework.beans.factory.annotation.Autowired; |
... | ... | @@ -33,7 +38,11 @@ import java.io.*; |
33 | 38 | import java.text.ParseException; |
34 | 39 | import java.text.SimpleDateFormat; |
35 | 40 | import java.util.*; |
41 | +import java.util.concurrent.*; | |
42 | +import java.util.stream.Collectors; | |
43 | +import java.util.stream.Stream; | |
36 | 44 | |
45 | +@Slf4j | |
37 | 46 | @Component |
38 | 47 | public class MyScheduledTask { |
39 | 48 | |
... | ... | @@ -89,7 +98,7 @@ public class MyScheduledTask { |
89 | 98 | /** |
90 | 99 | * 订阅任务 20秒执行一次 |
91 | 100 | */ |
92 | - @Scheduled(fixedDelay= 5000) | |
101 | + @Scheduled(fixedDelay= 10000) | |
93 | 102 | protected synchronized void reloadPic2(){ |
94 | 103 | //登录 |
95 | 104 | if (myTasks.isHasNewDevice) { |
... | ... | @@ -100,6 +109,83 @@ public class MyScheduledTask { |
100 | 109 | } |
101 | 110 | } |
102 | 111 | |
112 | + @Autowired | |
113 | + private UserOperateService userOperateService; | |
114 | + @Autowired | |
115 | + private SearchMapper searchMapper; | |
116 | +// /** | |
117 | +// * 订阅任务 20秒执行一次 | |
118 | +// */ | |
119 | +// @Scheduled(cron = "0 51 18 * * ?") | |
120 | +// protected synchronized void task(){ | |
121 | +// log.info("开始执行----- 晚上到寝"); | |
122 | +// //男 | |
123 | +// Integer schoolId=27; | |
124 | +// Integer roomId =12226; | |
125 | +// Integer type = 7; | |
126 | +// Integer outof = 1; | |
127 | +// String clintId="253169192"; | |
128 | +// String timeIds = "2021-01-08,2021-01-11,2021-01-12,2021-01-13,2021-01-14,2021-01-15,2021-01-18,2021-01-19,2021-01-20,2021-01-21,2021-01-22"; | |
129 | +// String[] deviceArr = timeIds.split(","); | |
130 | +// List<String> deviceList= new ArrayList<>(Arrays.asList(deviceArr)); | |
131 | +// //启用多线程执行 | |
132 | +// CountDownLatch begin = new CountDownLatch(1); | |
133 | +// CountDownLatch end = new CountDownLatch(deviceList.size()); | |
134 | +// ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("thread-sendFace-runner-%d").build(); | |
135 | +// ExecutorService exe = new ThreadPoolExecutor(4,8,0L, TimeUnit.MILLISECONDS,new LinkedBlockingQueue<Runnable>(),namedThreadFactory); | |
136 | +// for(String s : deviceList){ | |
137 | +// String intime = s + " 20:26:14"; | |
138 | +// String startTime= s + " 00:00:00"; | |
139 | +// String endTime = s+" 23:59:59"; | |
140 | +// exe.execute(new SendFaceBatchTask100(userDao,sendRecordDao,searchMapper,schoolId,roomId,type,outof,intime,clintId,startTime,endTime,begin,end)); | |
141 | +// } | |
142 | +// begin.countDown(); | |
143 | +// try { | |
144 | +// end.await(); | |
145 | +// }catch (Exception e){ | |
146 | +// log.error("失败"+e); | |
147 | +// } | |
148 | +// exe.shutdown(); | |
149 | +// log.info("统计100服务器总共有"+deviceList.size()+"个设备,处理完毕"); | |
150 | +// } | |
151 | +// | |
152 | +// // @Scheduled(cron = "0 50 15 * * ?") | |
153 | +// @Scheduled(cron = "0 09 21 * * ?") | |
154 | +// protected synchronized void task2(){ | |
155 | +// log.info("开始执行----- 晚上到寝"); | |
156 | +// //男 | |
157 | +// Integer schoolId=27; | |
158 | +// Integer roomId =12226; | |
159 | +// Integer type = 4; | |
160 | +// Integer outof = 1; | |
161 | +// String clintId="253169212"; | |
162 | +// String timeIds = "2021-01-08,2021-01-11,2021-01-12,2021-01-13,2021-01-14,2021-01-15,2021-01-18,2021-01-19,2021-01-20,2021-01-21,2021-01-22"; | |
163 | +// String[] deviceArr = timeIds.split(","); | |
164 | +// List<String> deviceList= new ArrayList<>(Arrays.asList(deviceArr)); | |
165 | +// //启用多线程执行 | |
166 | +// CountDownLatch begin = new CountDownLatch(1); | |
167 | +// CountDownLatch end = new CountDownLatch(deviceList.size()); | |
168 | +// ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("thread-sendFace-runner-%d").build(); | |
169 | +// ExecutorService exe = new ThreadPoolExecutor(8,16,0L, TimeUnit.MILLISECONDS,new LinkedBlockingQueue<Runnable>(),namedThreadFactory); | |
170 | +// for(String s : deviceList){ | |
171 | +//// String intime = s + " 06:03:39"; | |
172 | +//// String startTime= s + " 00:00:00"; | |
173 | +//// String endTime = s+" 23:59:59"; | |
174 | +// String intime = s + " 17:14:39"; | |
175 | +// String startTime= s + " 00:00:00"; | |
176 | +// String endTime = s+" 23:59:59"; | |
177 | +// exe.execute(new SendFaceBatchTask2(userDao,sendRecordDao,searchMapper,schoolId,roomId,type,outof,intime,clintId,startTime,endTime,begin,end)); | |
178 | +// } | |
179 | +// begin.countDown(); | |
180 | +// try { | |
181 | +// end.await(); | |
182 | +// }catch (Exception e){ | |
183 | +// log.error("失败"+e); | |
184 | +// } | |
185 | +// exe.shutdown(); | |
186 | +// log.info("统计100服务器总共有"+deviceList.size()+"个设备,处理完毕"); | |
187 | +// } | |
188 | + | |
103 | 189 | /** |
104 | 190 | * 定期删除人脸抓拍图片 |
105 | 191 | */ |
... | ... | @@ -197,12 +283,10 @@ public class MyScheduledTask { |
197 | 283 | isSendMQ = true; |
198 | 284 | String fileName = simpleDateFormat.format(new Date()); |
199 | 285 | String filePath = "D:\\wg_log\\info\\kaoInfo\\" + fileName + ".log"; |
200 | -// String filePath = "C:\\Users\\Administrator\\Desktop\\2020-04-30 08.log"; | |
201 | 286 | if (!readLineMap.containsKey(fileName)) readLineNum = -1;//更新文件后从头开始 |
202 | 287 | File file = new File(filePath); |
203 | 288 | try { |
204 | 289 | if (!file.exists()) { |
205 | -// System.out.println("文件不存在:" + filePath); | |
206 | 290 | return; |
207 | 291 | } |
208 | 292 | FileInputStream fileInputStream = new FileInputStream(file); |
... | ... | @@ -213,16 +297,12 @@ public class MyScheduledTask { |
213 | 297 | int indexLineNum = 0;//当前文件的行 |
214 | 298 | while ((content = bufferedReader.readLine()) != null) { |
215 | 299 | indexLineNum++; |
216 | -// System.out.println("indexLineNum:"+indexLineNum+" ----------readLineNum:"+readLineNum); | |
217 | 300 | if (indexLineNum >= readLineNum) { |
218 | 301 | readLineNum++; |
219 | 302 | sendMQMess(content); |
220 | 303 | } |
221 | - | |
222 | 304 | } |
223 | - | |
224 | 305 | readLineMap.put(fileName, readLineNum); |
225 | - | |
226 | 306 | fileInputStream.close(); |
227 | 307 | bufferedReader.close(); |
228 | 308 | |
... | ... | @@ -254,32 +334,36 @@ public class MyScheduledTask { |
254 | 334 | |
255 | 335 | String qiandaoDevId = content.substring(content.indexOf("设备") + 3, content.indexOf("设备") + 12); |
256 | 336 | |
337 | + String schoolId = userDao.getSchoolIdWidthCardNum(cardNum); | |
338 | + if(StringUtils.isEmpty(schoolId)){ | |
339 | + log.info("此卡号未对应所属学校,考勤卡号:{}",cardNum); | |
340 | + return; | |
341 | + } | |
257 | 342 | //获取寝室关联的场景id |
258 | 343 | String placeId = userDao.getPlaceIdWithKaoqinDevid(qiandaoDevId); |
259 | - | |
260 | - if (null != placeId) { | |
261 | - //关联的显示看板设备 | |
262 | - List<String> kanbanIds = userDao.getKanBanIdWithPlaceId(placeId); | |
263 | - | |
264 | - for (int i = 0; i < kanbanIds.size(); i++) { | |
265 | - String kanbanId = kanbanIds.get(i); | |
266 | - String data = "{\"cmd\":\"" + 34 + "\",\"clientId\":\"" + kanbanId + "\",\"data\":{\"cardNum\":\"" + cardNum + "\",\"inOrOut\":\"" + inOrOut + "\"}}"; | |
267 | - mqttManager.sendMqQD(kanbanId, data); | |
344 | + //关联的显示看板设备 | |
345 | + List<String> kanbanIds = new ArrayList<>(); | |
346 | + if(!StringUtils.isEmpty(placeId)) { | |
347 | + log.info("关联场景ID: {},考勤设备ID:{}",placeId,qiandaoDevId); | |
348 | + kanbanIds = userDao.getKanBanIdWithPlaceId(placeId); | |
349 | + }else{ | |
350 | + List<String> kBIds = userDao.getClintIds(schoolId); | |
351 | + if(CollectionUtils.isNotEmpty(kBIds)){ | |
352 | + for(String kbId : kBIds){ | |
353 | + String roomId = userDao.getPlaceIdWithKanBanDevid(kbId); | |
354 | + if(StringUtils.isEmpty(roomId)){ | |
355 | + kanbanIds.add(kbId); | |
356 | + } | |
357 | + } | |
268 | 358 | } |
269 | - | |
270 | - } else { | |
271 | - | |
272 | - String schoolId = userDao.getSchoolIdWidthCardNum(cardNum); | |
273 | - if(StringUtils.isEmpty(schoolId)||Integer.parseInt(schoolId) <=0)return; | |
274 | - List<String> clintIds = userDao.getClintIds(schoolId); | |
275 | - for (int i = 0; i < clintIds.size(); i++) { | |
276 | - String clintId = clintIds.get(i); | |
359 | + } | |
360 | + if(CollectionUtils.isNotEmpty(kanbanIds)){ | |
361 | + for (int i = 0; i < kanbanIds.size(); i++) { | |
362 | + String clintId = kanbanIds.get(i); | |
277 | 363 | String data = "{\"cmd\":\"" + 34 + "\",\"clientId\":\"" + clintId + "\",\"data\":{\"cardNum\":\"" + cardNum + "\",\"inOrOut\":\"" + inOrOut + "\"}}"; |
278 | 364 | mqttManager.sendMqQD(clintId, data); |
365 | + log.info("发送微耕考勤消息:学校ID: {},设备ID: {},关联看板room: {},",schoolId,clintId,placeId); | |
279 | 366 | } |
280 | 367 | } |
281 | - | |
282 | 368 | } |
283 | - | |
284 | - | |
285 | 369 | } | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/async/SendFaceBatchTask100.java
0 → 100644
... | ... | @@ -0,0 +1,106 @@ |
1 | +package com.example.dahua.async; | |
2 | + | |
3 | +import com.example.dahua.bean.UserInfoBean; | |
4 | +import com.example.dahua.dao.UserDao; | |
5 | +import com.example.dahua.utils.DateFormatUtil; | |
6 | +import com.example.dahua.xiananDao.SearchMapper; | |
7 | +import com.example.dahua.xiananDao.SendRecordDao; | |
8 | +import lombok.extern.slf4j.Slf4j; | |
9 | +import org.springframework.util.CollectionUtils; | |
10 | + | |
11 | +import java.text.SimpleDateFormat; | |
12 | +import java.util.Calendar; | |
13 | +import java.util.Date; | |
14 | +import java.util.List; | |
15 | +import java.util.UUID; | |
16 | +import java.util.concurrent.CountDownLatch; | |
17 | + | |
18 | +/** | |
19 | + * 多线程执行卡下发 | |
20 | + * @author xuquan | |
21 | + * @date 2021/01/12 15:56 | |
22 | + */ | |
23 | +@Slf4j | |
24 | +public class SendFaceBatchTask100 implements Runnable { | |
25 | + | |
26 | + | |
27 | + CountDownLatch begin; | |
28 | + CountDownLatch end; | |
29 | + UserDao userDao; | |
30 | + SendRecordDao sendRecordDao; | |
31 | + SearchMapper searchMapper; | |
32 | + Integer schoolId; | |
33 | + Integer roomId; | |
34 | + Integer type; | |
35 | + Integer outof; | |
36 | + String intime; | |
37 | + String clintId; | |
38 | + String startTime; | |
39 | + String endTime; | |
40 | + | |
41 | + public SendFaceBatchTask100(UserDao userDao,SendRecordDao sendRecordDao,SearchMapper searchMapper,Integer schoolId,Integer roomId, | |
42 | + Integer type,Integer outof,String intime,String clintId,String startTime,String endTime,CountDownLatch begin, CountDownLatch end){ | |
43 | + this.begin=begin; | |
44 | + this.end=end; | |
45 | + this.userDao=userDao; | |
46 | + this.sendRecordDao=sendRecordDao; | |
47 | + this.searchMapper=searchMapper; | |
48 | + this.schoolId=schoolId; | |
49 | + this.roomId=roomId; | |
50 | + this.type= type; | |
51 | + this.outof=outof; | |
52 | + this.intime=intime; | |
53 | + this.clintId=clintId; | |
54 | + this.startTime=startTime; | |
55 | + this.endTime=endTime; | |
56 | + } | |
57 | + | |
58 | + @Override | |
59 | + public void run() { | |
60 | + try { | |
61 | + begin.await(); | |
62 | + int num= (int)Math.random()*20+30; | |
63 | + List<String> studentIds = userDao.queryStudentIdList(schoolId,roomId); | |
64 | + if(!CollectionUtils.isEmpty(studentIds)){ | |
65 | + System.out.println("总数:"+studentIds.size()); | |
66 | + int i =0; | |
67 | + for(String studentId : studentIds){ | |
68 | + if(i==num){ | |
69 | + return; | |
70 | + } | |
71 | + UserInfoBean userInfoBean = userDao.getStudentWithid(studentId); | |
72 | + if(userInfoBean!=null){ | |
73 | + String cardNum = userInfoBean.getStudent_num(); | |
74 | + String userId = userInfoBean.getUser_id(); | |
75 | + String com = userInfoBean.getStudent_id(); | |
76 | + String classId = userInfoBean.getClass_id(); | |
77 | + String className = userInfoBean.getClass_name(); | |
78 | + String name= userInfoBean.getName(); | |
79 | + String mobile= userInfoBean.getParentMobile(); | |
80 | + String sex = String.valueOf(userInfoBean.getSex()); | |
81 | + String cid= UUID.randomUUID().toString().toUpperCase(); | |
82 | + int count = sendRecordDao.getKaoQin(schoolId,cardNum,type,outof,startTime,endTime); | |
83 | + System.out.println("count: "+count); | |
84 | + if(count ==0){ | |
85 | + intime = DateFormatUtil.getDateAdd(intime); | |
86 | + searchMapper.insert(userId,String.valueOf(schoolId),com,cardNum,type,outof,intime,cid,classId,clintId,name,mobile,className,sex,intime); | |
87 | + i++; | |
88 | + } | |
89 | + } | |
90 | + } | |
91 | + } | |
92 | + }catch (Exception e){ | |
93 | + log.error("异常,信息:",e); | |
94 | + }finally { | |
95 | + end.countDown(); | |
96 | + } | |
97 | + } | |
98 | + | |
99 | + public static void main(String[] args) { | |
100 | + for(int i=1;i<20;i++){ | |
101 | + int num= (int)(Math.random()*20)+30; | |
102 | + System.out.println(num); | |
103 | + } | |
104 | + } | |
105 | + | |
106 | +} | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/async/SendFaceBatchTask2.java
0 → 100644
... | ... | @@ -0,0 +1,102 @@ |
1 | +package com.example.dahua.async; | |
2 | + | |
3 | +import com.example.dahua.bean.StudentBean; | |
4 | +import com.example.dahua.bean.UserInfoBean; | |
5 | +import com.example.dahua.dao.UserDao; | |
6 | +import com.example.dahua.utils.DateFormatUtil; | |
7 | +import com.example.dahua.xiananDao.SearchMapper; | |
8 | +import com.example.dahua.xiananDao.SendRecordDao; | |
9 | +import lombok.extern.slf4j.Slf4j; | |
10 | +import org.springframework.util.CollectionUtils; | |
11 | + | |
12 | +import java.util.List; | |
13 | +import java.util.UUID; | |
14 | +import java.util.concurrent.CountDownLatch; | |
15 | + | |
16 | +/** | |
17 | + * 多线程执行卡下发 | |
18 | + * @author xuquan | |
19 | + * @date 2021/01/12 15:56 | |
20 | + */ | |
21 | +@Slf4j | |
22 | +public class SendFaceBatchTask2 implements Runnable { | |
23 | + | |
24 | + | |
25 | + CountDownLatch begin; | |
26 | + CountDownLatch end; | |
27 | + UserDao userDao; | |
28 | + SendRecordDao sendRecordDao; | |
29 | + SearchMapper searchMapper; | |
30 | + Integer schoolId; | |
31 | + Integer roomId; | |
32 | + Integer type; | |
33 | + Integer outof; | |
34 | + String intime; | |
35 | + String clintId; | |
36 | + String startTime; | |
37 | + String endTime; | |
38 | + | |
39 | + public SendFaceBatchTask2(UserDao userDao, SendRecordDao sendRecordDao, SearchMapper searchMapper, Integer schoolId, Integer roomId, | |
40 | + Integer type, Integer outof, String intime, String clintId, String startTime, String endTime, CountDownLatch begin, CountDownLatch end){ | |
41 | + this.begin=begin; | |
42 | + this.end=end; | |
43 | + this.userDao=userDao; | |
44 | + this.sendRecordDao=sendRecordDao; | |
45 | + this.searchMapper=searchMapper; | |
46 | + this.schoolId=schoolId; | |
47 | + this.roomId=roomId; | |
48 | + this.type= type; | |
49 | + this.outof=outof; | |
50 | + this.intime=intime; | |
51 | + this.clintId=clintId; | |
52 | + this.startTime=startTime; | |
53 | + this.endTime=endTime; | |
54 | + } | |
55 | + | |
56 | + @Override | |
57 | + public void run() { | |
58 | + try { | |
59 | + begin.await(); | |
60 | + int num= (int)(Math.random()*50)+150; | |
61 | + List<StudentBean> studentIds = userDao.getStudentList(schoolId,1,null); | |
62 | + if(!CollectionUtils.isEmpty(studentIds)){ | |
63 | + System.out.println("总数:"+studentIds.size()); | |
64 | + for(int i=0;i<=studentIds.size();i++){ | |
65 | + if(i==num){ | |
66 | + return; | |
67 | + } | |
68 | + String cardNum = studentIds.get(i).getStudent_num(); | |
69 | + String userId = studentIds.get(i).getUser_id(); | |
70 | + String com = studentIds.get(i).getStudent_id(); | |
71 | + String classId = studentIds.get(i).getClass_id(); | |
72 | + String className = studentIds.get(i).getClass_name(); | |
73 | + String name= studentIds.get(i).getName(); | |
74 | + String mobile= studentIds.get(i).getParentMobile(); | |
75 | + String sex = String.valueOf(studentIds.get(i).getSex()); | |
76 | + String cid= UUID.randomUUID().toString().toUpperCase(); | |
77 | + int count = sendRecordDao.getKaoQin(schoolId,cardNum,type,outof,startTime,endTime);; | |
78 | + System.out.println("count: "+count); | |
79 | + System.out.println("cardNum "+cardNum); | |
80 | + if(count ==0){ | |
81 | + intime = DateFormatUtil.getDateAdd(intime); | |
82 | + searchMapper.insert(userId,String.valueOf(schoolId),com,cardNum,type,outof,intime,cid,classId,clintId,name,mobile,className,sex,intime); | |
83 | + i++; | |
84 | + } | |
85 | + } | |
86 | + } | |
87 | + }catch (Exception e){ | |
88 | + log.error("异常,信息:",e); | |
89 | + }finally { | |
90 | + end.countDown(); | |
91 | + } | |
92 | + } | |
93 | + | |
94 | + public static void main(String[] args) { | |
95 | + for(int i=1;i<20;i++){ | |
96 | + int num= (int)(Math.random()*50)+150; | |
97 | +// int num= (int)(Math.random()*20)+30; | |
98 | + System.out.println(num); | |
99 | + } | |
100 | + } | |
101 | + | |
102 | +} | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/async/SendUserInfoTask2.java
... | ... | @@ -247,7 +247,7 @@ public class SendUserInfoTask2 { |
247 | 247 | if (!StringUtils.isEmpty(deviceId)) { |
248 | 248 | sendRecordBean.setFailType(EnumSendFaceType.FACE_AND_CARD_FAIL.code); |
249 | 249 | sendRecordBean.setFailContent(EnumSendFaceType.NOT_ONLINE_DEVICE.message); |
250 | - baseService.sendFailRecord(sendRecordBean); | |
250 | + baseService.sendFailRecord(sendRecordBean,channel); | |
251 | 251 | } |
252 | 252 | } else { |
253 | 253 | log.info("=================开始执行下发人脸及卡号任务================="); |
... | ... | @@ -311,7 +311,7 @@ public class SendUserInfoTask2 { |
311 | 311 | FileUtils.getInstance().writeLogs("下发人脸和卡号成功:" + cardNum + " " + attendanceBean.getClint_id(), FileUtils.sendUserSucTxt); |
312 | 312 | log.info("下发人脸和卡号成功, sendRecordBean: "+ JSON.toJSONString(sendRecordBean)); |
313 | 313 | //保存成功记录 |
314 | - baseService.sendSuccessRecord(sendRecordBean); | |
314 | + baseService.sendSuccessRecord(sendRecordBean,channel); | |
315 | 315 | } |
316 | 316 | /** |
317 | 317 | * 人脸和卡都下发失败 |
... | ... | @@ -323,7 +323,7 @@ public class SendUserInfoTask2 { |
323 | 323 | String failContent = analysisErrorMsg(bUserFlags,bFaceFalgs,bCardFlags); |
324 | 324 | sendRecordBean.setFailType(EnumSendFaceType.FACE_AND_CARD_FAIL.code); |
325 | 325 | sendRecordBean.setFailContent(failContent); |
326 | - baseService.sendFailRecord(sendRecordBean); | |
326 | + baseService.sendFailRecord(sendRecordBean,channel); | |
327 | 327 | } |
328 | 328 | /** |
329 | 329 | * 下发卡号成功,下发人脸失败, |
... | ... | @@ -335,7 +335,7 @@ public class SendUserInfoTask2 { |
335 | 335 | String failContent = analysisErrorMsg(bUserFlags,bFaceFalgs,bCardFlags); |
336 | 336 | sendRecordBean.setFailType(EnumSendFaceType.FACE_FAIL_CARD_SUCCESS.code); |
337 | 337 | sendRecordBean.setFailContent(failContent); |
338 | - baseService.sendFailRecord(sendRecordBean); | |
338 | + baseService.sendFailRecord(sendRecordBean,channel); | |
339 | 339 | } |
340 | 340 | /** |
341 | 341 | * 下发卡号失败,下发人脸成功, |
... | ... | @@ -346,7 +346,7 @@ public class SendUserInfoTask2 { |
346 | 346 | String failContent = analysisErrorMsg(bUserFlags,bFaceFalgs,bCardFlags); |
347 | 347 | sendRecordBean.setFailType(EnumSendFaceType.FACE_SUCCESS_CARD_FAIl.code); |
348 | 348 | sendRecordBean.setFailContent(failContent); |
349 | - baseService.sendFailRecord(sendRecordBean); | |
349 | + baseService.sendFailRecord(sendRecordBean,channel); | |
350 | 350 | } |
351 | 351 | } |
352 | 352 | } |
... | ... | @@ -575,10 +575,10 @@ public class SendUserInfoTask2 { |
575 | 575 | String typeName =""; |
576 | 576 | if(userType ==1){ |
577 | 577 | typeName= "Teacher"; |
578 | - studentBean = userDao.getTeacherWithCard(recordBean.getNum()); | |
578 | + studentBean = userDao.getTeacherWithCard(recordBean.getNum(),schoolId); | |
579 | 579 | }else{ |
580 | 580 | typeName= "Student"; |
581 | - studentBean= userDao.getStudentWithCard(recordBean.getNum()); | |
581 | + studentBean= userDao.getStudentWithCard(recordBean.getNum(),schoolId); | |
582 | 582 | } |
583 | 583 | if(studentBean==null){ |
584 | 584 | continue; |
... | ... | @@ -629,7 +629,7 @@ public class SendUserInfoTask2 { |
629 | 629 | log.error("设备不在线"); |
630 | 630 | return false; |
631 | 631 | } |
632 | - StudentBean studentBean = userDao.getStudentWithCard(cardNum); | |
632 | + StudentBean studentBean = userDao.getStudentWithCard(cardNum,schoolId); | |
633 | 633 | if(studentBean == null){ |
634 | 634 | log.error("此卡号:{},未查询到相应学生信息。",cardNum); |
635 | 635 | return false; | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/bean/StudentBean.java
... | ... | @@ -61,6 +61,16 @@ public class StudentBean implements Serializable { |
61 | 61 | |
62 | 62 | private String num; |
63 | 63 | |
64 | + private String ParentMobile; | |
65 | + | |
66 | + public String getParentMobile() { | |
67 | + return ParentMobile; | |
68 | + } | |
69 | + | |
70 | + public void setParentMobile(String parentMobile) { | |
71 | + ParentMobile = parentMobile; | |
72 | + } | |
73 | + | |
64 | 74 | public String getNum() { |
65 | 75 | return num; |
66 | 76 | } | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/bean/UserInfoBean.java
... | ... | @@ -22,6 +22,10 @@ public class UserInfoBean implements Serializable { |
22 | 22 | |
23 | 23 | private String class_id; |
24 | 24 | |
25 | + private String sex; | |
26 | + | |
27 | + private String parentMobile; | |
28 | + | |
25 | 29 | public String getClass_id() { |
26 | 30 | return class_id; |
27 | 31 | } |
... | ... | @@ -94,6 +98,22 @@ public class UserInfoBean implements Serializable { |
94 | 98 | this.student_id = student_id; |
95 | 99 | } |
96 | 100 | |
101 | + public String getSex() { | |
102 | + return sex; | |
103 | + } | |
104 | + | |
105 | + public void setSex(String sex) { | |
106 | + this.sex = sex; | |
107 | + } | |
108 | + | |
109 | + public String getParentMobile() { | |
110 | + return parentMobile; | |
111 | + } | |
112 | + | |
113 | + public void setParentMobile(String parentMobile) { | |
114 | + this.parentMobile = parentMobile; | |
115 | + } | |
116 | + | |
97 | 117 | @Override |
98 | 118 | public String toString() { |
99 | 119 | return "UserInfoBean{" + | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/control/UserControl.java
... | ... | @@ -9,8 +9,8 @@ import com.example.dahua.dao.UserDao; |
9 | 9 | import com.example.dahua.enums.EnumSzBusinessType; |
10 | 10 | import com.example.dahua.lib.CompressPic; |
11 | 11 | import com.example.dahua.lib.FilePath; |
12 | -import com.example.dahua.service.DeleteBatchTest; | |
13 | 12 | import com.example.dahua.service.UserService; |
13 | +import com.example.dahua.service.imp.BaseService; | |
14 | 14 | import com.example.dahua.utils.*; |
15 | 15 | import com.example.dahua.xiananDao.SendRecordDao; |
16 | 16 | import io.swagger.annotations.Api; |
... | ... | @@ -54,6 +54,9 @@ public class UserControl { |
54 | 54 | @Autowired |
55 | 55 | UserDao userDao; |
56 | 56 | |
57 | + @Autowired | |
58 | + BaseService baseService; | |
59 | + | |
57 | 60 | |
58 | 61 | /** |
59 | 62 | * 权限下发至设备 |
... | ... | @@ -280,17 +283,15 @@ public class UserControl { |
280 | 283 | |
281 | 284 | boolean check = BaiduUtils.getBaiduUtils().checkImg(httpurl); |
282 | 285 | //获取文件名 |
283 | - File file1 = new File(httpurl); | |
284 | - File target = new File("./huoti/"); | |
285 | - //压缩后的文件 | |
286 | - httpurl = target.getAbsolutePath() + "/"+ file1.getName(); | |
286 | +// File file1 = new File(httpurl); | |
287 | +// File target = new File("./huoti/"); | |
288 | +// //压缩后的文件 | |
289 | +// httpurl = target.getAbsolutePath() + "/"+ file1.getName(); | |
290 | + System.out.println("人脸图片路径:"+httpurl); | |
287 | 291 | if (check) { |
288 | 292 | File file = new File(httpurl); |
289 | - | |
290 | 293 | String userCode = file.getName().split("\\.")[0]; |
291 | - | |
292 | - String schoolId = "864"; | |
293 | - | |
294 | + String schoolId = ""; | |
294 | 295 | if (httpurl.contains("Student") && !httpurl.startsWith("http")) { |
295 | 296 | schoolId = httpurl.substring(httpurl.indexOf("School") + 6, httpurl.indexOf("\\Student")); |
296 | 297 | } else if (httpurl.contains("Teacher") && !httpurl.startsWith("http")) { |
... | ... | @@ -303,11 +304,43 @@ public class UserControl { |
303 | 304 | FileUtils.getInstance().writeLogs("人脸添加成功:" + userId, "人脸添加成功.txt"); |
304 | 305 | } |
305 | 306 | } |
306 | - | |
307 | 307 | return check; |
308 | + } | |
308 | 309 | |
310 | + @RequestMapping(value = "delBaiDuFace", method = RequestMethod.GET) | |
311 | + @ApiOperation("在线活体检测") | |
312 | + public void delBaiDuFace(@RequestParam("schoolId") String schoolId,@RequestParam("userId") String userId) { | |
313 | + BaiduUtils.getBaiduUtils().delFace(schoolId,userId); | |
309 | 314 | } |
310 | 315 | |
316 | + @RequestMapping(value = "updateBaiDuFace", method = RequestMethod.GET) | |
317 | + @ApiOperation("在线活体检测") | |
318 | + public boolean updateBaiDuFace(@RequestParam("url") String httpurl) { | |
319 | + boolean check = BaiduUtils.getBaiduUtils().checkImg(httpurl); | |
320 | + //获取文件名 | |
321 | +// File file1 = new File(httpurl); | |
322 | +// File target = new File("./huoti/"); | |
323 | +// //压缩后的文件 | |
324 | +// httpurl = target.getAbsolutePath() + "/"+ file1.getName(); | |
325 | + System.out.println("人脸图片路径:"+httpurl); | |
326 | + if (check) { | |
327 | + File file = new File(httpurl); | |
328 | + String userCode = file.getName().split("\\.")[0]; | |
329 | + String schoolId = ""; | |
330 | + if (httpurl.contains("Student") && !httpurl.startsWith("http")) { | |
331 | + schoolId = httpurl.substring(httpurl.indexOf("School") + 6, httpurl.indexOf("\\Student")); | |
332 | + } else if (httpurl.contains("Teacher") && !httpurl.startsWith("http")) { | |
333 | + schoolId = httpurl.substring(httpurl.indexOf("School") + 6, httpurl.indexOf("\\Teacher")); | |
334 | + } | |
335 | + System.out.println("choolId:" + schoolId + "userCode:" + userCode); | |
336 | + if (!StringUtils.isEmpty(schoolId) && !StringUtils.isEmpty(userCode)) { | |
337 | + String userId = userService.getUserId(userCode, schoolId); | |
338 | + BaiduUtils.getBaiduUtils().updateFace(new File(httpurl), schoolId, userId, userId); | |
339 | + FileUtils.getInstance().writeLogs("人脸添加成功:" + userId, "人脸添加成功.txt"); | |
340 | + } | |
341 | + } | |
342 | + return check; | |
343 | + } | |
311 | 344 | |
312 | 345 | @RequestMapping(value = "jpg2png", method = RequestMethod.GET) |
313 | 346 | @ApiOperation("jpg图片转png") |
... | ... | @@ -336,9 +369,7 @@ public class UserControl { |
336 | 369 | } |
337 | 370 | |
338 | 371 | } |
339 | - | |
340 | 372 | return true; |
341 | - | |
342 | 373 | } |
343 | 374 | |
344 | 375 | @RequestMapping(value = "imgsSend", method = RequestMethod.GET) | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/control/UserOperateController.java
1 | 1 | package com.example.dahua.control; |
2 | 2 | |
3 | 3 | import com.example.dahua.async.SendUserInfoTask2; |
4 | -import com.example.dahua.bean.SendFaceDto; | |
4 | +import com.example.dahua.bean.StudentBean; | |
5 | 5 | import com.example.dahua.dao.UserDao; |
6 | 6 | import com.example.dahua.service.UserOperateService; |
7 | +import com.example.dahua.service.imp.BaseService; | |
8 | +import com.example.dahua.utils.HttpUtil; | |
7 | 9 | import com.example.dahua.utils.HttpUtils; |
10 | +import io.micrometer.core.instrument.util.StringUtils; | |
8 | 11 | import io.swagger.annotations.Api; |
9 | 12 | import io.swagger.annotations.ApiOperation; |
10 | 13 | import lombok.extern.slf4j.Slf4j; |
14 | +import org.apache.commons.collections4.CollectionUtils; | |
11 | 15 | import org.springframework.beans.factory.annotation.Autowired; |
12 | 16 | import org.springframework.http.MediaType; |
13 | -import org.springframework.web.bind.annotation.*; | |
17 | +import org.springframework.web.bind.annotation.RequestMapping; | |
18 | +import org.springframework.web.bind.annotation.RequestMethod; | |
19 | +import org.springframework.web.bind.annotation.RequestParam; | |
20 | +import org.springframework.web.bind.annotation.RestController; | |
21 | + | |
22 | +import java.util.List; | |
14 | 23 | |
15 | 24 | /** |
16 | 25 | * 用户信息、人脸、卡信息、权限下发控制类 |
... | ... | @@ -32,16 +41,22 @@ public class UserOperateController { |
32 | 41 | @Autowired |
33 | 42 | UserOperateService userOperateService; |
34 | 43 | |
44 | + @Autowired | |
45 | + BaseService baseService; | |
46 | + | |
35 | 47 | @RequestMapping(value = "clearAllFace", method = RequestMethod.POST) |
36 | 48 | @ApiOperation(value = "21服务器清空指定学校,指定设备下所有人脸2.0") |
37 | - public boolean clearAllFace(@RequestParam("schoolId") Integer schoolId, @RequestParam("deviceId") String deviceId) { | |
49 | + public boolean clearAllFace(@RequestParam("schoolId") Integer schoolId, @RequestParam(value = "deviceId",required = false) String deviceId) { | |
38 | 50 | return sendUserInfoTask.clearAllFace(schoolId,deviceId); |
39 | 51 | } |
40 | 52 | |
41 | - @RequestMapping(value = "sendUserFaces", method = RequestMethod.POST) | |
53 | + @RequestMapping(value = "sendUserFaces", method = RequestMethod.GET) | |
42 | 54 | @ApiOperation(value = "100服务器下发学校下所有人脸给指定设备2.0") |
43 | - public void sendUserFaces(@RequestBody SendFaceDto sendFaceDto) { | |
44 | - userOperateService.sendUserFaces(sendFaceDto); | |
55 | + public void sendUserFaces(@RequestParam("schoolId") Integer schoolId,@RequestParam("userType") Integer userType, | |
56 | + @RequestParam(value = "studentType",required = false) Integer studentType, | |
57 | + @RequestParam(value = "sex",required = false) String sex, | |
58 | + @RequestParam(value = "deviceIds",required = false) String deviceIds) { | |
59 | + userOperateService.sendUserFaces(schoolId,userType,deviceIds,studentType,sex); | |
45 | 60 | } |
46 | 61 | |
47 | 62 | @RequestMapping(value = "deleteFailFace100", method = RequestMethod.POST) |
... | ... | @@ -68,5 +83,4 @@ public class UserOperateController { |
68 | 83 | public boolean deleteFaceByCard(Integer schoolId,String cardNum,String deviceId) { |
69 | 84 | return sendUserInfoTask.deleteFaceByCard(schoolId,cardNum,deviceId); |
70 | 85 | } |
71 | - | |
72 | 86 | } | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/dao/UserDao.java
... | ... | @@ -89,7 +89,7 @@ public interface UserDao { |
89 | 89 | @Select(" select studentcode from SZ_V_School_Student where student_id = #{customerid}") |
90 | 90 | String getStudentCode(@Param("customerid") String customerid); |
91 | 91 | |
92 | - @Select(" select * from SZ_V_School_Student where student_id = #{student_id}") | |
92 | + @Select(" select top 1* from SZ_V_School_Student where student_id = #{student_id}") | |
93 | 93 | UserInfoBean getStudentWithid(@Param("student_id") String student_id); |
94 | 94 | |
95 | 95 | @Select(" select * from SZ_V_School_Student where student_num = #{student_num} and name = #{name}") |
... | ... | @@ -136,6 +136,9 @@ public interface UserDao { |
136 | 136 | @Select("select Top(1) PlaceId from XA_PlaceAttendance where KaoQinAttendance = #{qiandaoDevId}") |
137 | 137 | String getPlaceIdWithKaoqinDevid(@Param("qiandaoDevId") String qiandaoDevId); |
138 | 138 | |
139 | + @Select("select Top(1) PlaceId from XA_PlaceAttendance where KanBanAttendance = #{kanBanDevId}") | |
140 | + String getPlaceIdWithKanBanDevid(@Param("kanBanDevId") String kanBanDevId); | |
141 | + | |
139 | 142 | @Select("select KanBanAttendance from XA_PlaceAttendance where PlaceId = #{PlaceId} and (len(KanBanAttendance)>0 and KanBanAttendance is not null )") |
140 | 143 | List<String> getKanBanIdWithPlaceId(@Param("PlaceId") String placeId); |
141 | 144 | |
... | ... | @@ -251,12 +254,11 @@ public interface UserDao { |
251 | 254 | |
252 | 255 | /*************************************** 仅供测试,下发失败使用接口 end ************************************/ |
253 | 256 | |
257 | + @Select("select Top(1)* from SZ_V_School_Student where student_num = #{card} and school_id = #{schoolId}") | |
258 | + StudentBean getStudentWithCard(@Param("card") String card,@Param("schoolId") Integer schoolId); | |
254 | 259 | |
255 | - @Select("select Top(1)* from SZ_V_School_Teacher where teacher_num = #{teacher_num}") | |
256 | - StudentBean getTeacherWithCard(@Param("teacher_num") String teacher_num); | |
257 | - | |
258 | - @Select("select Top(1)* from SZ_V_School_Student where student_num = #{card}") | |
259 | - StudentBean getStudentWithCard(@Param("card") String card); | |
260 | + @Select("select Top(1)* from SZ_V_School_Teacher where teacher_num = #{teacher_num} and school_id = #{schoolId}") | |
261 | + StudentBean getTeacherWithCard(@Param("teacher_num") String teacher_num,@Param("schoolId") Integer schoolId); | |
260 | 262 | |
261 | 263 | List<StudentBean> getStudentList(@Param("schoolId") Integer schoolId,@Param("studentType")Integer studentType,@Param("sex") List<Integer> sex); |
262 | 264 | |
... | ... | @@ -266,4 +268,7 @@ public interface UserDao { |
266 | 268 | |
267 | 269 | List<AttendanceBean> queryClintList(@Param("schoolId") Integer schoolId,@Param("deviceId")String deviceId); |
268 | 270 | |
271 | + List<String> queryStudentIdList(@Param("schoolId") Integer schoolId,@Param("roomId")Integer roomId); | |
272 | + | |
273 | + | |
269 | 274 | } | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/filter/AllowOriginFilter.java
1 | -package com.example.dahua.filter; | |
2 | - | |
3 | -import org.springframework.stereotype.Component; | |
4 | - | |
5 | -import javax.servlet.*; | |
6 | -import javax.servlet.annotation.WebFilter; | |
7 | -import javax.servlet.http.HttpServletResponse; | |
8 | -import java.io.IOException; | |
9 | - | |
10 | -/** | |
11 | - * 用于解决跨域问题 | |
12 | - */ | |
13 | -@Component | |
14 | -@WebFilter(urlPatterns = "/*", filterName = "authFilter") | |
15 | -public class AllowOriginFilter implements Filter { | |
16 | - | |
17 | - @Override | |
18 | - public void init(FilterConfig filterConfig) throws ServletException { | |
19 | - } | |
20 | - | |
21 | - public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { | |
22 | - HttpServletResponse response = (HttpServletResponse) res; | |
23 | - response.setHeader("Access-Control-Allow-Origin", "*"); | |
24 | - response.setHeader("Access-Control-Allow-Methods", "*"); | |
25 | - response.setHeader("Access-Control-Allow-Credentials", "true"); | |
26 | - response.setHeader("Access-Control-Allow-Headers","*"); | |
27 | - chain.doFilter(req, res); | |
28 | - } | |
29 | - | |
30 | - @Override | |
31 | - public void destroy() { | |
32 | - } | |
33 | -} | |
1 | +//package com.example.dahua.filter; | |
2 | +// | |
3 | +//import org.springframework.stereotype.Component; | |
4 | +// | |
5 | +//import javax.servlet.*; | |
6 | +//import javax.servlet.annotation.WebFilter; | |
7 | +//import javax.servlet.http.HttpServletResponse; | |
8 | +//import java.io.IOException; | |
9 | +// | |
10 | +/////** | |
11 | +//// * 用于解决跨域问题 | |
12 | +//// */ | |
13 | +////@Component | |
14 | +////@WebFilter(urlPatterns = "/*", filterName = "authFilter") | |
15 | +////public class AllowOriginFilter implements Filter { | |
16 | +//// | |
17 | +//// @Override | |
18 | +//// public void init(FilterConfig filterConfig) throws ServletException { | |
19 | +//// } | |
20 | +//// | |
21 | +//// public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { | |
22 | +//// HttpServletResponse response = (HttpServletResponse) res; | |
23 | +//// response.setHeader("Access-Control-Allow-Origin", "*"); | |
24 | +//// response.setHeader("Access-Control-Allow-Methods", "*"); | |
25 | +//// response.setHeader("Access-Control-Allow-Credentials", "true"); | |
26 | +//// response.setHeader("Access-Control-Allow-Headers","*"); | |
27 | +//// chain.doFilter(req, res); | |
28 | +//// } | |
29 | +//// | |
30 | +//// @Override | |
31 | +//// public void destroy() { | |
32 | +//// } | |
33 | +////} | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/service/AttendanceService.java
... | ... | @@ -9,8 +9,7 @@ public interface AttendanceService { |
9 | 9 | * |
10 | 10 | * @return |
11 | 11 | */ |
12 | - public int insert(String clint_id, String clint_type, String ip, String port, String intime, String school_id, | |
13 | - String state); | |
12 | + public int insert(String clint_id, String clint_type, String ip, String port, String intime, String school_id,int state,int status); | |
14 | 13 | |
15 | 14 | /** |
16 | 15 | * 更新联网状态 | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/service/DeleteBatchTest.java
... | ... | @@ -12,7 +12,13 @@ public interface DeleteBatchTest { |
12 | 12 | void test(String schoolId); |
13 | 13 | void test2(String schoolId); |
14 | 14 | void test3(String schoolId); |
15 | - | |
16 | 15 | void test4(Integer schoolId,Integer studentType,String sex); |
17 | 16 | |
17 | + void test5(String cardNum,String intime,String sysTime,String clintId); | |
18 | + | |
19 | + void test6(Integer schoolId,Integer roomId,Integer type,Integer outof,String intime,String clintId,String startTime,String endTime); | |
20 | + | |
21 | + void test7(Integer schoolId,Integer roomId,Integer type,Integer outof,String intime,String clintId,String startTime,String endTime); | |
22 | + | |
23 | + void test8(Integer schoolId,Integer roomId,Integer type,Integer outof,String startTime,String endTime,int size); | |
18 | 24 | } | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/service/UserOperateService.java
1 | 1 | package com.example.dahua.service; |
2 | 2 | |
3 | -import com.example.dahua.bean.SendFaceDto; | |
4 | 3 | |
5 | 4 | /** |
6 | 5 | * 下发用户信息、人脸、卡、权限接口 |
... | ... | @@ -11,8 +10,8 @@ public interface UserOperateService { |
11 | 10 | |
12 | 11 | /** |
13 | 12 | * 照片下发 |
14 | - * @param sendFaceDto | |
15 | 13 | */ |
16 | - void sendUserFaces(SendFaceDto sendFaceDto); | |
14 | + void sendUserFaces(Integer schoolId,Integer userType,String deviceIds,Integer studentType,String sex); | |
17 | 15 | |
16 | + void test6(Integer schoolId,Integer roomId,Integer type,Integer outof,String intime,String clintId,String startTime,String endTime); | |
18 | 17 | } | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/service/imp/AttendanceImp.java
... | ... | @@ -16,15 +16,15 @@ public class AttendanceImp implements AttendanceService { |
16 | 16 | JdbcTemplate jdbcTemplate; |
17 | 17 | |
18 | 18 | @Override |
19 | - public int insert(String clint_id, String clint_type, String ip, String port, String intime, String school_id, String state) { | |
19 | + public int insert(String clint_id, String clint_type, String ip, String port, String intime, String school_id, int state,int status) { | |
20 | 20 | try { |
21 | 21 | String selectSql = String.format("select * from SZ_Attendance where clint_id =\'%s\'", clint_id); |
22 | 22 | List<AttendanceBean> attendanceBeans = jdbcTemplate.query(selectSql, new Object[]{}, new BeanPropertyRowMapper<AttendanceBean>(AttendanceBean.class)); |
23 | 23 | if (attendanceBeans.size() == 0) {//设备不存在 |
24 | - String insertSql = String.format("insert into SZ_Attendance(clint_id, clint_type, ip, port, intime, school_id, state,isConnection) values ('%s','%s','%s','%s','%s','%s','%s','%s')", clint_id, clint_type, ip, port, intime, school_id, state, 1); | |
24 | + String insertSql = String.format("insert into SZ_Attendance(clint_id, clint_type, ip, port, intime, school_id, state,isConnection) values ('%s','%s','%s','%s','%s','%s','%s','%s')", clint_id, clint_type, ip, port, intime, school_id, state,status); | |
25 | 25 | return jdbcTemplate.update(insertSql); |
26 | 26 | } else {//设备 已经存在,更新在线状态 |
27 | - updateConnectStateWithDevid(1,intime, clint_id); | |
27 | + updateConnectStateWithDevid(status,intime, clint_id); | |
28 | 28 | } |
29 | 29 | } catch (Exception e) { |
30 | 30 | e.printStackTrace(); |
... | ... | @@ -45,7 +45,6 @@ public class AttendanceImp implements AttendanceService { |
45 | 45 | try { |
46 | 46 | String updateSql = String.format(" update SZ_Attendance set isConnection = %d where ip = '%s' and port = '%s' ", isConnection, ip, port); |
47 | 47 | index = jdbcTemplate.update(updateSql); |
48 | -// System.out.println("updateIndex:"+index+" isConnection:"+isConnection+"updateSql:"+updateSql); | |
49 | 48 | } catch (Exception e) { |
50 | 49 | e.printStackTrace(); |
51 | 50 | } |
... | ... | @@ -59,7 +58,6 @@ public class AttendanceImp implements AttendanceService { |
59 | 58 | try { |
60 | 59 | String updateSql = String.format(" update SZ_Attendance set isConnection = %d,inTime='%s' where clint_id = '%s' ", isConnection,inTime,clint_id); |
61 | 60 | index = jdbcTemplate.update(updateSql); |
62 | -// System.out.println("updateIndex:"+index+" isConnection:"+isConnection+"updateSql:"+updateSql); | |
63 | 61 | } catch (Exception e) { |
64 | 62 | e.printStackTrace(); |
65 | 63 | } | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/service/imp/BaseService.java
... | ... | @@ -67,7 +67,7 @@ public class BaseService { |
67 | 67 | /** |
68 | 68 | * 保存成功下发记录 |
69 | 69 | */ |
70 | - public synchronized void sendSuccessRecord(SendRecordBean recordBean) { | |
70 | + public synchronized void sendSuccessRecord(SendRecordBean recordBean,String channel) { | |
71 | 71 | try{ |
72 | 72 | String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); |
73 | 73 | Integer schoolId = recordBean.getSchoolId(); |
... | ... | @@ -86,9 +86,9 @@ public class BaseService { |
86 | 86 | } |
87 | 87 | if (null == sendRecordBean) { |
88 | 88 | sendRecordDao.saveFaceRecord(userId, deviceId, resultCard, userName, time, schoolName, |
89 | - faceUrl, schoolId,null,null, userType,deviceType,1); | |
89 | + faceUrl, schoolId,null,null, userType,deviceType,1,channel); | |
90 | 90 | } else { |
91 | - sendRecordDao.updateFaceSuccessRecord(deviceId, resultCard, time, faceUrl, userName, userId); | |
91 | + sendRecordDao.updateFaceSuccessRecord(deviceId, resultCard, time, faceUrl, userName, userId,channel); | |
92 | 92 | } |
93 | 93 | }catch (Exception e){ |
94 | 94 | log.error("保存成功记录失败。"); |
... | ... | @@ -100,7 +100,7 @@ public class BaseService { |
100 | 100 | /** |
101 | 101 | * 保存下发失败记录 |
102 | 102 | */ |
103 | - public synchronized void sendFailRecord(SendRecordBean recordBean) { | |
103 | + public synchronized void sendFailRecord(SendRecordBean recordBean,String channel) { | |
104 | 104 | try{ |
105 | 105 | String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); |
106 | 106 | Integer schoolId = recordBean.getSchoolId(); |
... | ... | @@ -121,7 +121,7 @@ public class BaseService { |
121 | 121 | } |
122 | 122 | if (null == sendRecordBean) { |
123 | 123 | sendRecordDao.saveFaceRecord(userId, deviceId, resultCard, userName, time, schoolName, |
124 | - faceUrl, schoolId,failContent,failType, userType,deviceType,2); | |
124 | + faceUrl, schoolId,failContent,failType, userType,deviceType,2,channel); | |
125 | 125 | }else { |
126 | 126 | sendRecordDao.updateFaceFailRecord(deviceId,faceUrl,resultCard,time,failContent,userId); |
127 | 127 | } | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/service/imp/DeleteBatchTestImpl.java
... | ... | @@ -5,12 +5,16 @@ import com.example.dahua.bean.StudentBean; |
5 | 5 | import com.example.dahua.bean.UserInfoBean; |
6 | 6 | import com.example.dahua.dao.UserDao; |
7 | 7 | import com.example.dahua.service.DeleteBatchTest; |
8 | +import com.example.dahua.utils.DateFormatUtil; | |
9 | +import com.example.dahua.xiananDao.SearchMapper; | |
8 | 10 | import com.example.dahua.xiananDao.SendRecordDao; |
9 | 11 | import org.springframework.beans.factory.annotation.Autowired; |
10 | 12 | import org.springframework.stereotype.Repository; |
11 | 13 | import org.springframework.stereotype.Service; |
14 | +import org.springframework.util.CollectionUtils; | |
12 | 15 | import org.springframework.util.StringUtils; |
13 | 16 | |
17 | +import java.security.Provider; | |
14 | 18 | import java.util.*; |
15 | 19 | import java.util.stream.Collectors; |
16 | 20 | |
... | ... | @@ -30,6 +34,8 @@ public class DeleteBatchTestImpl implements DeleteBatchTest { |
30 | 34 | private SendRecordDao sendRecordDao; |
31 | 35 | @Autowired |
32 | 36 | private BaseService baseService; |
37 | + @Autowired | |
38 | + private SearchMapper searchMapper; | |
33 | 39 | |
34 | 40 | |
35 | 41 | @Override |
... | ... | @@ -125,4 +131,101 @@ public class DeleteBatchTestImpl implements DeleteBatchTest { |
125 | 131 | } |
126 | 132 | } |
127 | 133 | |
134 | + @Override | |
135 | + public void test5(String cardNum,String intime,String sysTime,String clintId) { | |
136 | + StudentBean studentBean = userDao.getStudentWithCard(cardNum,null); | |
137 | + String userId = studentBean.getUser_id(); | |
138 | + String com = studentBean.getStudent_id(); | |
139 | + String classId = studentBean.getClass_id(); | |
140 | + String className = studentBean.getClass_name(); | |
141 | + String name= studentBean.getName(); | |
142 | + String mobile= studentBean.getParentMobile(); | |
143 | + String sex = String.valueOf(studentBean.getSex()); | |
144 | + String cid= UUID.randomUUID().toString().toUpperCase(); | |
145 | +// searchMapper.insert(userId,"27",com,cardNum,intime,cid,classId,clintId,name,mobile,className,sex,sysTime); | |
146 | + } | |
147 | + | |
148 | + | |
149 | + @Override | |
150 | + public void test6(Integer schoolId,Integer roomId,Integer type,Integer outof,String intime,String clintId,String startTime,String endTime) { | |
151 | + List<String> studentIds = userDao.queryStudentIdList(schoolId,roomId); | |
152 | + if(!CollectionUtils.isEmpty(studentIds)){ | |
153 | + System.out.println("总数:"+studentIds.size()); | |
154 | + int i =0; | |
155 | + for(String studentId : studentIds){ | |
156 | + UserInfoBean userInfoBean = userDao.getStudentWithid(studentId); | |
157 | + if(userInfoBean!=null){ | |
158 | + if(i== 1168){ | |
159 | + return; | |
160 | + } | |
161 | + String cardNum = userInfoBean.getStudent_num(); | |
162 | + String userId = userInfoBean.getUser_id(); | |
163 | + String com = userInfoBean.getStudent_id(); | |
164 | + String classId = userInfoBean.getClass_id(); | |
165 | + String className = userInfoBean.getClass_name(); | |
166 | + String name= userInfoBean.getName(); | |
167 | + String mobile= userInfoBean.getParentMobile(); | |
168 | + String sex = String.valueOf(userInfoBean.getSex()); | |
169 | + String cid= UUID.randomUUID().toString().toUpperCase(); | |
170 | + int count = sendRecordDao.getSSKaoQin(schoolId,cardNum,type,outof,startTime,endTime); | |
171 | + System.out.println("count: "+count); | |
172 | + System.out.println(cardNum); | |
173 | + if(count ==0){ | |
174 | + intime = DateFormatUtil.getDateAdd(intime); | |
175 | + searchMapper.insertSS(userId,String.valueOf(schoolId),com,cardNum,type,outof,intime,cid,classId,clintId,name,mobile,className,sex,intime); | |
176 | + System.out.println(i); | |
177 | + i++; | |
178 | + } | |
179 | + } | |
180 | + } | |
181 | + } | |
182 | + } | |
183 | + | |
184 | + @Override | |
185 | + public void test7(Integer schoolId,Integer roomId,Integer type,Integer outof,String intime,String clintId,String startTime,String endTime) { | |
186 | + List<StudentBean> studentIds = userDao.getStudentList(schoolId,1,null); | |
187 | + int num= (int)Math.random()*40+160; | |
188 | + if(!CollectionUtils.isEmpty(studentIds)){ | |
189 | + System.out.println("总数:"+studentIds.size()); | |
190 | + for(int i=0;i<=studentIds.size();i++){ | |
191 | + if(i==num){ | |
192 | + return; | |
193 | + } | |
194 | + String cardNum = studentIds.get(i).getStudent_num(); | |
195 | + String userId = studentIds.get(i).getUser_id(); | |
196 | + String com = studentIds.get(i).getStudent_id(); | |
197 | + String classId = studentIds.get(i).getClass_id(); | |
198 | + String className = studentIds.get(i).getClass_name(); | |
199 | + String name= studentIds.get(i).getName(); | |
200 | + String mobile= studentIds.get(i).getParentMobile(); | |
201 | + String sex = String.valueOf(studentIds.get(i).getSex()); | |
202 | + String cid= UUID.randomUUID().toString().toUpperCase(); | |
203 | + int count = sendRecordDao.getKaoQin(schoolId,cardNum,type,outof,startTime,endTime); | |
204 | + System.out.println("count: "+count); | |
205 | + System.out.println(cardNum); | |
206 | + if(count ==0){ | |
207 | + intime = DateFormatUtil.getDateAdd(intime); | |
208 | + searchMapper.insert(userId,String.valueOf(schoolId),com,cardNum,type,outof,intime,cid,classId,clintId,name,mobile,className,sex,intime); | |
209 | + System.out.println(i); | |
210 | + } | |
211 | + } | |
212 | + } | |
213 | + } | |
214 | + | |
215 | + @Override | |
216 | + public void test8(Integer schoolId,Integer roomId,Integer type,Integer outof,String startTime,String endTime,int size) { | |
217 | + List<String> studentIds = userDao.queryStudentIdList(schoolId,roomId); | |
218 | + if(!CollectionUtils.isEmpty(studentIds)){ | |
219 | + for(int i=0;i<=studentIds.size();i++){ | |
220 | + UserInfoBean userInfoBean = userDao.getStudentWithid(studentIds.get(i)); | |
221 | + System.out.println(i); | |
222 | + if(userInfoBean!=null){ | |
223 | + String cardNum = userInfoBean.getStudent_num(); | |
224 | + System.out.println(i); | |
225 | + sendRecordDao.deleteSS(schoolId,cardNum,type,outof,startTime,endTime); | |
226 | + } | |
227 | + } | |
228 | + } | |
229 | + } | |
230 | + | |
128 | 231 | } | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/service/imp/UserOperateServiceImpl.java
1 | 1 | package com.example.dahua.service.imp; |
2 | 2 | |
3 | -import com.example.dahua.bean.SendFaceDto; | |
4 | 3 | import com.example.dahua.bean.StudentBean; |
4 | +import com.example.dahua.bean.UserInfoBean; | |
5 | 5 | import com.example.dahua.dao.UserDao; |
6 | 6 | import com.example.dahua.lib.CompressPic; |
7 | 7 | import com.example.dahua.lib.FilePath; |
8 | 8 | import com.example.dahua.service.UserOperateService; |
9 | +import com.example.dahua.utils.DateFormatUtil; | |
9 | 10 | import com.example.dahua.utils.HttpUtils; |
11 | +import com.example.dahua.xiananDao.SearchMapper; | |
12 | +import com.example.dahua.xiananDao.SendRecordDao; | |
10 | 13 | import lombok.extern.slf4j.Slf4j; |
11 | 14 | import org.springframework.beans.factory.annotation.Autowired; |
12 | 15 | import org.springframework.stereotype.Service; |
16 | +import org.springframework.util.CollectionUtils; | |
13 | 17 | import org.springframework.util.StringUtils; |
14 | 18 | |
15 | 19 | import java.io.File; |
16 | 20 | import java.util.ArrayList; |
17 | 21 | import java.util.Arrays; |
18 | 22 | import java.util.List; |
23 | +import java.util.UUID; | |
19 | 24 | |
20 | 25 | /** |
21 | 26 | * 下发用户信息、人脸、卡、权限接口实现类 |
... | ... | @@ -30,52 +35,55 @@ public class UserOperateServiceImpl implements UserOperateService { |
30 | 35 | private UserDao userDao; |
31 | 36 | @Autowired |
32 | 37 | private BaseService baseService; |
38 | + @Autowired | |
39 | + private SendRecordDao sendRecordDao; | |
40 | + @Autowired | |
41 | + private SearchMapper searchMapper; | |
33 | 42 | |
34 | 43 | @Override |
35 | - public void sendUserFaces(SendFaceDto sendFaceDto) { | |
36 | - Integer schoolId = sendFaceDto.getSchoolId(); | |
37 | - Integer studentType = sendFaceDto.getStudentType(); | |
38 | - Integer type = sendFaceDto.getType(); | |
39 | - String sex = sendFaceDto.getSex(); | |
44 | + public void sendUserFaces(Integer schoolId,Integer userType,String deviceIds,Integer studentType,String sex) { | |
40 | 45 | //下发设备集合 |
41 | - String[] deviceArr = sendFaceDto.getsNos().split(","); | |
46 | + String[] deviceArr = deviceIds.split(","); | |
42 | 47 | List<String> deviceList= new ArrayList<>(Arrays.asList(deviceArr)); |
43 | 48 | if(deviceList.size()<1){ |
44 | 49 | log.error("未选择下发设备"); |
45 | 50 | return; |
46 | 51 | } |
47 | - Integer userType=null; | |
48 | 52 | //根据类型获取下发用户信息、文件名目录 |
49 | 53 | String typeName=""; |
50 | 54 | List<StudentBean> studentBeanList = null; |
51 | - if(type.intValue() == 0 || type.intValue()==1){ | |
52 | - userType = 2; | |
55 | + if(userType.intValue()==2){ | |
53 | 56 | typeName= "Student"; |
54 | 57 | studentBeanList = baseService.getStudentList(schoolId,studentType,sex); |
55 | 58 | }else{ |
56 | - userType = 1; | |
57 | 59 | typeName= "Teacher"; |
58 | 60 | studentBeanList = baseService.getTeacherList(schoolId); |
59 | 61 | } |
62 | + log.info("下发用户总数:"+studentBeanList.size()); | |
60 | 63 | for(StudentBean studentBean : studentBeanList){ |
61 | 64 | try{ |
62 | - //100服务器文件目录绝对路径 | |
63 | - String path = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\" + typeName; | |
64 | 65 | String photo= userType.intValue()==1?studentBean.getFace():studentBean.getPhoto(); |
66 | + //以学籍号为名的文件名 | |
67 | + String fileName = photo.split(typeName +"/")[1]; | |
65 | 68 | //学籍号 |
66 | 69 | String studentCode=userType.intValue()==1?studentBean.getNum():studentBean.getStudentcode(); |
67 | 70 | if (StringUtils.isEmpty(photo) || StringUtils.isEmpty(studentCode)){ |
68 | 71 | continue; |
69 | 72 | } |
70 | 73 | String filePath=""; |
74 | + //100服务器人脸照绝对路径 | |
75 | + String path_1 = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\" + typeName; | |
76 | + String path_2 = "E:\\wwwhtdocs\\SmartCampus\\face17e5\\School" + schoolId + "\\" + typeName; | |
77 | + String path_3 = "E:\\wwwhtdocs\\SmartCampus\\f0i5l7e5\\"; | |
71 | 78 | if(photo.indexOf("f0i5l7e5")!=-1){ |
72 | 79 | String afterStr = photo.split("f0i5l7e5/")[1].replace("/","\\"); |
73 | - filePath="E:\\wwwhtdocs\\SmartCampus\\f0i5l7e5\\" + afterStr; | |
74 | - } else{ | |
75 | - //以学籍号为名的文件名 | |
76 | - String fileName = photo.split(typeName +"/")[1]; | |
77 | - //100服务器上人脸照绝对路径 | |
78 | - filePath = path+ "\\" + fileName; | |
80 | + filePath= path_3 + afterStr; | |
81 | + } | |
82 | + if(photo.indexOf("face17e5")!=-1){ | |
83 | + filePath = path_2 + "\\" + fileName; | |
84 | + } | |
85 | + if(photo.indexOf("face17e50")!=-1){ | |
86 | + filePath = path_1 + "\\" + fileName; | |
79 | 87 | } |
80 | 88 | log.info("学籍号:{},人脸路径:{}, ",studentCode,filePath); |
81 | 89 | //100服务人脸照图片路径 |
... | ... | @@ -112,4 +120,33 @@ public class UserOperateServiceImpl implements UserOperateService { |
112 | 120 | // System.out.println(photo.split("f0i5l7e5/")[0]); |
113 | 121 | } |
114 | 122 | |
123 | + @Override | |
124 | + public void test6(Integer schoolId, Integer roomId, Integer type, Integer outof, String intime, String clintId, String startTime, String endTime) { | |
125 | + List<String> studentIds = userDao.queryStudentIdList(schoolId,roomId); | |
126 | + if(!CollectionUtils.isEmpty(studentIds)){ | |
127 | + System.out.println("总数:"+studentIds.size()); | |
128 | + int i =0; | |
129 | + for(String studentId : studentIds){ | |
130 | + UserInfoBean userInfoBean = userDao.getStudentWithid(studentId); | |
131 | + if(userInfoBean!=null){ | |
132 | + String cardNum = userInfoBean.getStudent_num(); | |
133 | + String userId = userInfoBean.getUser_id(); | |
134 | + String com = userInfoBean.getStudent_id(); | |
135 | + String classId = userInfoBean.getClass_id(); | |
136 | + String className = userInfoBean.getClass_name(); | |
137 | + String name= userInfoBean.getName(); | |
138 | + String mobile= userInfoBean.getParentMobile(); | |
139 | + String sex = String.valueOf(userInfoBean.getSex()); | |
140 | + String cid= UUID.randomUUID().toString().toUpperCase(); | |
141 | + int count = sendRecordDao.getSSKaoQin(schoolId,cardNum,type,outof,startTime,endTime); | |
142 | + System.out.println("count: "+count); | |
143 | + if(count ==0){ | |
144 | + intime = DateFormatUtil.getDateAdd(intime); | |
145 | + searchMapper.insertSS(userId,String.valueOf(schoolId),com,cardNum,type,outof,intime,cid,classId,clintId,name,mobile,className,sex,intime); | |
146 | + i++; | |
147 | + } | |
148 | + } | |
149 | + } | |
150 | + } | |
151 | + } | |
115 | 152 | } | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/utils/BaiduUtils.java
... | ... | @@ -49,8 +49,6 @@ public class BaiduUtils { |
49 | 49 | } |
50 | 50 | map.put("image", httpurl); |
51 | 51 | map.put("image_type", image_type); |
52 | -// map.put("face_field",""); | |
53 | -// map.put("option","GATE"); | |
54 | 52 | list.add(map); |
55 | 53 | String param = GsonUtils.toJson(list); |
56 | 54 | // 注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。 |
... | ... | @@ -252,17 +250,6 @@ public class BaiduUtils { |
252 | 250 | com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(result); |
253 | 251 | String error_msg = jsonObject.getString("error_msg"); |
254 | 252 | if (error_msg.equals("SUCCESS")) { |
255 | - | |
256 | -// com.alibaba.fastjson.JSONObject faceResult = jsonObject.getJSONObject("result"); | |
257 | - | |
258 | -// FacerecordBean facerecordBean = new FacerecordBean(); | |
259 | -// | |
260 | -// facerecordBean.setFace_token(faceResult.getString("face_token")); | |
261 | -// facerecordBean.setGroup_id(group_id); | |
262 | -// facerecordBean.setIntime(simpleDateFormat.format(new Date())); | |
263 | -// facerecordBean.setUser_id(user_id); | |
264 | -// | |
265 | -// facerecordService.addFacerecord(facerecordBean); | |
266 | 253 | return "注册成功"; |
267 | 254 | } else { |
268 | 255 | log.info("注册人脸失败,文件大小,size: "+ img.length()); |
... | ... | @@ -275,6 +262,64 @@ public class BaiduUtils { |
275 | 262 | return ""; |
276 | 263 | } |
277 | 264 | |
265 | + //注册人脸 | |
266 | + public String updateFace(File img, String group_id, String user_id, String userInfo) { | |
267 | + | |
268 | + String url = "https://aip.baidubce.com/rest/2.0/face/v3/faceset/user/update"; | |
269 | + try { | |
270 | + Map<String, Object> map = new HashMap<>(); | |
271 | + map.put("image", Base64Util.encode(InputStream2ByteArray(img.getAbsolutePath()))); | |
272 | + map.put("group_id", group_id); | |
273 | + map.put("user_id", user_id); | |
274 | + map.put("user_info", userInfo); | |
275 | + map.put("image_type", "BASE64"); | |
276 | + map.put("quality_control", "NORMAL"); | |
277 | + String param = GsonUtils.toJson(map); | |
278 | + | |
279 | + // 注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。 | |
280 | + | |
281 | + String result = HttpUtil.post(url, getAuth(), "application/json", param); | |
282 | + System.out.println(result); | |
283 | + com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(result); | |
284 | + String error_msg = jsonObject.getString("error_msg"); | |
285 | + if (error_msg.equals("SUCCESS")) { | |
286 | + return "更新成功"; | |
287 | + } else { | |
288 | + log.info("更新失败,文件大小,size: "+ img.length()); | |
289 | + return error_msg; | |
290 | + } | |
291 | + } catch (Exception e) { | |
292 | + e.printStackTrace(); | |
293 | + } | |
294 | + return ""; | |
295 | + } | |
296 | + | |
297 | + //注册人脸 | |
298 | + public String delFace(String group_id, String user_id) { | |
299 | + String url = "https://aip.baidubce.com/rest/2.0/face/v3/faceset/face/delete"; | |
300 | + try { | |
301 | + Map<String, Object> map = new HashMap<>(); | |
302 | + map.put("group_id", group_id); | |
303 | + map.put("user_id", user_id); | |
304 | + String param = GsonUtils.toJson(map); | |
305 | + | |
306 | + // 注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。 | |
307 | + String result = HttpUtil.post(url, getAuth(), "application/json", param); | |
308 | + System.out.println(result); | |
309 | + com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(result); | |
310 | + String error_msg = jsonObject.getString("error_msg"); | |
311 | + if (error_msg.equals("SUCCESS")) { | |
312 | + return "注册成功"; | |
313 | + } else { | |
314 | + log.info("注册人脸失败"); | |
315 | + return error_msg; | |
316 | + } | |
317 | + } catch (Exception e) { | |
318 | + e.printStackTrace(); | |
319 | + } | |
320 | + return ""; | |
321 | + } | |
322 | + | |
278 | 323 | private byte[] InputStream2ByteArray(String filePath) throws IOException { |
279 | 324 | |
280 | 325 | InputStream in = new FileInputStream(filePath); | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/utils/DateFormatUtil.java
... | ... | @@ -43,16 +43,36 @@ public class DateFormatUtil { |
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
46 | + * 日期叠加计算,以月为单位:整数 | |
47 | + * @param date 起始时间 | |
48 | + * @return | |
49 | + */ | |
50 | + public static String getDateAdd(String date) { | |
51 | + Date date1 = stringFormatDate(date,"yyyy-MM-dd hh:mm:ss"); | |
52 | + Calendar cal = Calendar.getInstance(); | |
53 | + cal.setTime(date1);//设置起时间 | |
54 | + cal.add(Calendar.SECOND, 2); | |
55 | + String strDate = dateFormatString(cal.getTime(),"yyyy-MM-dd hh:mm:ss"); | |
56 | + return strDate; | |
57 | + } | |
58 | + | |
59 | + public static void main(String[] args) { | |
60 | + System.out.println(getDateAdd("2021-01-25 19:54:03")); | |
61 | + } | |
62 | + | |
63 | + /** | |
46 | 64 | * 日期叠加计算,以天为单位:整数 |
47 | 65 | * @param length 叠加长度 |
48 | 66 | * @param date 起始时间 |
49 | 67 | * @return |
50 | 68 | */ |
51 | - public static Date getDateByTime(int length, Date date){ | |
69 | + public static String getDateByTime(String date){ | |
70 | + Date date1 = stringFormatDate(date,"yyyy-MM-dd hh:mm:ss"); | |
52 | 71 | Calendar cal = Calendar.getInstance(); |
53 | - cal.setTime(date);//设置起时间 | |
54 | - cal.add(Calendar.DATE,length);//把日期往后增加 | |
55 | - return cal.getTime(); | |
72 | + cal.setTime(date1);//设置起时间 | |
73 | + cal.add(Calendar.DATE,1);//把日期往后增加 | |
74 | + String strDate = dateFormatString(cal.getTime(),"yyyy-MM-dd hh:mm:ss"); | |
75 | + return strDate; | |
56 | 76 | } |
57 | 77 | |
58 | 78 | /** | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/xiananDao/SearchMapper.java
... | ... | @@ -10,4 +10,10 @@ public interface SearchMapper { |
10 | 10 | */ |
11 | 11 | void checkIn(CheckIn checkIn); |
12 | 12 | |
13 | + void insert(String user_id,String school_id,String customerId,String card_num,Integer card_type,Integer outof,String intime,String cid,String class_id,String attendance_id, | |
14 | + String name,String mobile,String class_name,String sex,String systime); | |
15 | + | |
16 | + void insertSS(String user_id,String school_id,String customerId,String card_num,Integer card_type,Integer outof,String intime,String cid,String class_id,String attendance_id, | |
17 | + String name,String mobile,String class_name,String sex,String systime); | |
18 | + | |
13 | 19 | } | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/xiananDao/SendRecordDao.java
1 | 1 | package com.example.dahua.xiananDao; |
2 | 2 | |
3 | -import com.example.dahua.bean.AttendanceRecords; | |
4 | -import com.example.dahua.bean.SendRecordBean; | |
5 | -import com.example.dahua.bean.StudentBean; | |
6 | -import com.example.dahua.bean.WGBean; | |
7 | -import org.apache.ibatis.annotations.*; | |
8 | -import org.springframework.stereotype.Repository; | |
3 | + import com.example.dahua.bean.AttendanceRecords; | |
4 | + import com.example.dahua.bean.SendRecordBean; | |
5 | + import com.example.dahua.bean.StudentBean; | |
6 | + import com.example.dahua.bean.WGBean; | |
7 | + import org.apache.ibatis.annotations.*; | |
8 | + import org.springframework.stereotype.Repository; | |
9 | 9 | |
10 | -import java.util.List; | |
10 | + import java.util.List; | |
11 | 11 | |
12 | 12 | /** |
13 | 13 | * 人脸照片下发结果记录 |
... | ... | @@ -106,19 +106,30 @@ public interface SendRecordDao { |
106 | 106 | @Select("select * from Face_SendRecord where schoolId = #{schoolId} and deviceID = #{deviceID} and Num = #{Num} and userId = #{userId}") |
107 | 107 | List<SendRecordBean> getRecordIsExit(@Param("schoolId") Integer schoolId,@Param("deviceID") String deviceId, @Param("Num") String card,@Param("userId") String userId); |
108 | 108 | |
109 | - @Insert("insert into Face_SendRecord values(#{deviceID},#{userId},#{num},#{name},#{time},#{schoolName},#{imgPath},#{schoolId},#{failContent},#{failType},#{userType},#{deviceType},#{status})") | |
110 | - void saveFaceRecord(@Param("userId") String userId, @Param("deviceID") String deviceID, @Param("num") String num, @Param("name") String name, | |
111 | - @Param("time") String time, @Param("schoolName") String schoolName, @Param("imgPath") String imgPath, @Param("schoolId") Integer schoolId, @Param("failContent") String failContent, | |
112 | - @Param("failType") Integer failType, @Param("userType") Integer userType, @Param("deviceType") Integer deviceType,Integer status); | |
109 | + @Insert("insert into Face_SendRecord values(#{deviceID},#{userId},#{num},#{name},#{time},#{schoolName},#{imgPath},#{schoolId},#{failContent},#{failType},#{userType},#{deviceType},#{status},#{channel})") | |
110 | + void saveFaceRecord(@Param("userId") String userId, @Param("deviceID") String deviceID, @Param("num") String num, @Param("name") String name, @Param("time") String time, @Param("schoolName") String schoolName, | |
111 | + @Param("imgPath") String imgPath, @Param("schoolId") Integer schoolId, @Param("failContent") String failContent, @Param("failType") Integer failType, @Param("userType") Integer userType, | |
112 | + @Param("deviceType") Integer deviceType,@Param("status") Integer status,@Param("channel") String channel); | |
113 | 113 | |
114 | 114 | @Update("update Face_SendRecord set time = #{time},failContent = #{content},imgPath= #{faceUrl},status = 2 where deviceID = #{deviceID} and Num =#{Num} and userId = #{userId}") |
115 | 115 | void updateFaceFailRecord(@Param("deviceID") String deviceId, @Param("faceUrl") String faceUrl,@Param("Num") String card, @Param("time") String time, @Param("content") String content,@Param("userId") String userId); |
116 | 116 | |
117 | - @Update("update Face_SendRecord set time = #{time},imgPath= #{faceUrl},Name = #{Name},status = 1, failType=null, failContent = null where deviceID = #{deviceID} and Num = #{Num}") | |
118 | - void updateFaceSuccessRecord(@Param("deviceID") String deviceId, @Param("Num") String card, @Param("time") String time, @Param("faceUrl") String faceUrl, @Param("Name") String name, @Param("userId") String userId); | |
117 | + @Update("update Face_SendRecord set time = #{time},imgPath= #{faceUrl},Name = #{Name},status = 1,channel=#{channel},failType=null, failContent = null where deviceID = #{deviceID} and Num = #{Num}") | |
118 | + void updateFaceSuccessRecord(@Param("deviceID") String deviceId, @Param("Num") String card, @Param("time") String time, @Param("faceUrl") String faceUrl, @Param("Name") String name, @Param("userId") String userId,@Param("channel") String channel); | |
119 | 119 | |
120 | 120 | @Select("select * from Face_SendRecord where schoolId = #{schoolId} and status =2") |
121 | 121 | List<SendRecordBean> getFailRecord(@Param("schoolId") Integer schoolId); |
122 | 122 | |
123 | + @Select("select count(*) from SZ_AttendanceRecordsSS202101 where school_id = #{schoolId} and card_num = #{cardNum} and card_type = #{cardType} and outof=#{outof} and intime > #{startTime} and intime < #{endTime} ") | |
124 | + int getSSKaoQin(@Param("schoolId") Integer schoolId,@Param("cardNum") String cardNum,@Param("cardType") Integer cardType,@Param("outof") Integer outof,@Param("startTime") String startTime,@Param("endTime") String endTime); | |
125 | + | |
126 | + @Select("select count(*) from SZ_AttendanceRecords202101 where school_id = #{schoolId} and card_num = #{cardNum} and card_type = #{cardType} and outof=#{outof} and intime > #{startTime} and intime < #{endTime} ") | |
127 | + int getKaoQin(@Param("schoolId") Integer schoolId,@Param("cardNum") String cardNum,@Param("cardType") Integer cardType,@Param("outof") Integer outof,@Param("startTime") String startTime,@Param("endTime") String endTime); | |
128 | + | |
129 | + @Delete("DELETE from SZ_AttendanceRecords202101 where school_id = #{schoolId} and card_Num = #{cardNum} and card_type = #{cardType} and outof=#{outof} and intime > #{startTime} and intime < #{endTime}") | |
130 | + void delete(@Param("schoolId") Integer schoolId,@Param("cardNum") String cardNum,@Param("cardType") Integer cardType,@Param("outof") Integer outof,@Param("startTime") String startTime,@Param("endTime") String endTime); | |
131 | + | |
132 | + @Delete("DELETE from SZ_AttendanceRecordsSS202101 where school_id = #{schoolId} and card_Num = #{cardNum} and card_type = #{cardType} and outof=#{outof} and intime > #{startTime} and intime < #{endTime}") | |
133 | + void deleteSS(@Param("schoolId") Integer schoolId,@Param("cardNum") String cardNum,@Param("cardType") Integer cardType,@Param("outof") Integer outof,@Param("startTime") String startTime,@Param("endTime") String endTime); | |
123 | 134 | } |
124 | 135 | ... | ... |
cloud/dahua/src/main/resources/logback-spring.xml
... | ... | @@ -8,7 +8,7 @@ |
8 | 8 | <!--<include resource="org/springframework/boot/logging/logback/defaults.xml" />--> |
9 | 9 | |
10 | 10 | <!--日志文件存储的基础路径: ${user.home} 为当前服务器用户主目录--> |
11 | - <property name="LOG_PATH" value="D:/dahua-logs"/> | |
11 | + <property name="LOG_PATH" value="E:/dahua-logs"/> | |
12 | 12 | |
13 | 13 | <!--日志文件基础名称--> |
14 | 14 | <property name="BASE_FILE_NAME" value="dahua"/> | ... | ... |
cloud/dahua/src/main/resources/mapper/usermapper.xml
... | ... | @@ -20,7 +20,7 @@ |
20 | 20 | #{item} |
21 | 21 | </foreach> |
22 | 22 | </if> |
23 | - and (student_num is not null or student_num != '') and (photo is not null or photo !='') | |
23 | + and (student_num is not null or student_num != '') and (photo is not null or photo !='') order by newid() | |
24 | 24 | </select> |
25 | 25 | |
26 | 26 | <select id="getTeacherList" resultType="com.example.dahua.bean.StudentBean"> |
... | ... | @@ -43,4 +43,10 @@ |
43 | 43 | </if> |
44 | 44 | </select> |
45 | 45 | |
46 | + <select id="queryStudentIdList" resultType="java.lang.String"> | |
47 | + select StudentId from SS_RoomNumber where Status=1 and SchoolId=#{schoolId} | |
48 | + and Pid in (select id from SS_Room where Status=1 and SchoolId=#{schoolId} and Pid=#{roomId}) | |
49 | + and StudentId in (select student_id from SZ_V_School_Student where school_id= #{schoolId}) order by newid() | |
50 | + </select> | |
51 | + | |
46 | 52 | </mapper> |
47 | 53 | \ No newline at end of file | ... | ... |
cloud/dahua/src/main/resources/xiaoanmapper/SearchMapper.xml
... | ... | @@ -15,4 +15,62 @@ |
15 | 15 | )} |
16 | 16 | </insert> |
17 | 17 | |
18 | + <insert id="insert" > | |
19 | + INSERT INTO SZ_AttendanceRecords202101 ( | |
20 | + [user_id], | |
21 | + [school_id], | |
22 | + [customerId], | |
23 | + [usertype], | |
24 | + [card_num], | |
25 | + [card_type], | |
26 | + [outof], | |
27 | + [intime], | |
28 | + [cid], | |
29 | + [func_no], | |
30 | + [head_image], | |
31 | + [class_id], | |
32 | + [expression], | |
33 | + [attendance_id], | |
34 | + [name], | |
35 | + [mobile], | |
36 | + [class_name], | |
37 | + [sex], | |
38 | + [student_type], | |
39 | + [systime] | |
40 | + ) | |
41 | + VALUES | |
42 | + ( | |
43 | + #{user_id},#{school_id},#{customerId},2,#{card_num},#{card_type},#{outof}, #{intime}, #{cid},8,null,#{class_id},null,#{attendance_id},#{name},#{mobile}, #{class_name}, #{sex}, 2, #{systime} | |
44 | + ) | |
45 | + </insert> | |
46 | + | |
47 | + <insert id="insertSS" > | |
48 | + INSERT INTO SZ_AttendanceRecordsSS202101 ( | |
49 | + [user_id], | |
50 | + [school_id], | |
51 | + [customerId], | |
52 | + [usertype], | |
53 | + [card_num], | |
54 | + [card_type], | |
55 | + [outof], | |
56 | + [intime], | |
57 | + [cid], | |
58 | + [func_no], | |
59 | + [head_image], | |
60 | + [class_id], | |
61 | + [expression], | |
62 | + [attendance_id], | |
63 | + [name], | |
64 | + [mobile], | |
65 | + [class_name], | |
66 | + [sex], | |
67 | + [student_type], | |
68 | + [systime] | |
69 | + ) | |
70 | + VALUES | |
71 | + ( | |
72 | + #{user_id},#{school_id},#{customerId},2,#{card_num},#{card_type},#{outof}, #{intime}, #{cid},8,null,#{class_id},null,#{attendance_id},#{name},#{mobile}, #{class_name}, #{sex}, 2, #{systime} | |
73 | + ) | |
74 | + </insert> | |
75 | + | |
18 | 76 | </mapper> |
19 | 77 | \ No newline at end of file | ... | ... |
cloud/dahua/src/test/java/com/example/dahua/mapper/SearchMapperTest.java
... | ... | @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON; |
4 | 4 | import com.example.dahua.MyTask; |
5 | 5 | import com.example.dahua.Tester; |
6 | 6 | import com.example.dahua.async.MyScheduledTask; |
7 | +import com.example.dahua.async.SendFaceBatchTask2; | |
7 | 8 | import com.example.dahua.bean.*; |
8 | 9 | import com.example.dahua.dao.PermissionFaceDao; |
9 | 10 | import com.example.dahua.dao.UserDao; |
... | ... | @@ -17,11 +18,17 @@ import com.example.dahua.utils.DateUtils; |
17 | 18 | import com.example.dahua.utils.HttpUtil; |
18 | 19 | import com.example.dahua.utils.JsonUtils; |
19 | 20 | import com.example.dahua.xiananDao.SearchMapper; |
21 | +import com.example.dahua.xiananDao.SendRecordDao; | |
22 | +import com.google.common.util.concurrent.ThreadFactoryBuilder; | |
20 | 23 | import org.junit.Test; |
21 | 24 | import org.springframework.beans.factory.annotation.Autowired; |
22 | 25 | |
23 | 26 | import java.io.File; |
27 | +import java.util.ArrayList; | |
28 | +import java.util.Arrays; | |
24 | 29 | import java.util.Date; |
30 | +import java.util.List; | |
31 | +import java.util.concurrent.*; | |
25 | 32 | |
26 | 33 | /** |
27 | 34 | * TODO |
... | ... | @@ -144,10 +151,120 @@ public class SearchMapperTest extends Tester { |
144 | 151 | // deleteBatchTest.test2(schoolId); |
145 | 152 | String schoolId = "1485"; |
146 | 153 | deleteBatchTest.test3(schoolId); |
154 | + | |
147 | 155 | } |
148 | 156 | |
149 | 157 | @Test |
150 | 158 | public void test9() { |
151 | - deleteBatchTest.test4(27,2,"1"); | |
159 | + String cardNum="8733277A"; | |
160 | + String intime= "2021-01-28 20:47:14"; | |
161 | + String systime="2021-01-28 20:47:23"; | |
162 | + String clientId ="253169469"; | |
163 | + deleteBatchTest.test5(cardNum,intime,systime,clientId); | |
164 | + } | |
165 | + | |
166 | + @Test | |
167 | + public void test10() { | |
168 | + //男 | |
169 | + Integer roomId =11748; | |
170 | +// String roomId ="12226"; | |
171 | + Integer type = 12; | |
172 | + Integer outof = 0; | |
173 | + String intime = "2021-01-24 20:26:14"; | |
174 | + String clintId="253169240"; | |
175 | + String startTime= "2021-01-24 00:00:00"; | |
176 | + String endTime ="2021-01-24 23:59:59"; | |
177 | + deleteBatchTest.test6(27,roomId,type,outof,intime,clintId,startTime,endTime); | |
178 | + } | |
179 | + | |
180 | + @Test | |
181 | + public void test11() { | |
182 | + //男11748 | |
183 | + Integer roomId =11748; | |
184 | +// String roomId ="12226"; | |
185 | + Integer type = 7; | |
186 | + Integer outof = 1; | |
187 | + String intime = "2021-01-08 06:03:39"; | |
188 | + String clintId="253169240"; | |
189 | + String startTime= "2021-01-08 00:00:00"; | |
190 | + String endTime ="2021-01-08 23:59:59"; | |
191 | + deleteBatchTest.test6(27,roomId,type,outof,intime,clintId,startTime,endTime); | |
192 | + } | |
193 | + | |
194 | + @Test | |
195 | + public void test12() { | |
196 | + //男 | |
197 | + Integer roomId =11748; | |
198 | +// String roomId ="12226"; | |
199 | +// Integer type = 7; | |
200 | +// Integer outof = 1; | |
201 | + Integer type = 12; | |
202 | + Integer outof = 0; | |
203 | + String startTime= "2021-01-24 00:00:00"; | |
204 | + String endTime ="2021-01-09 23:59:59"; | |
205 | + deleteBatchTest.test8(27,roomId,type,outof,startTime,endTime,47); | |
206 | + } | |
207 | + | |
208 | + @Test | |
209 | + public void test13() { | |
210 | + //男11748 | |
211 | + Integer roomId =12226; | |
212 | +// String roomId ="12226"; | |
213 | + Integer type =1; | |
214 | + Integer outof = 0; | |
215 | + String intime = "2021-01-21 06:03:39"; | |
216 | + String clintId="253185199"; | |
217 | + String startTime= "2021-01-21 00:00:00"; | |
218 | + String endTime ="2021-01-21 23:59:59"; | |
219 | + deleteBatchTest.test7(27,roomId,type,outof,intime,clintId,startTime,endTime); | |
220 | + } | |
221 | + | |
222 | + @Test | |
223 | + public void test14() { | |
224 | + //男11748 | |
225 | + Integer roomId =12226; | |
226 | +// String roomId ="12226"; | |
227 | + Integer type =4; | |
228 | + Integer outof = 1; | |
229 | + String intime = "2021-01-20 17:14:39"; | |
230 | + String clintId="253185199"; | |
231 | + String startTime= "2021-01-20 00:00:00"; | |
232 | + String endTime ="2021-01-20 23:59:59"; | |
233 | + deleteBatchTest.test7(27,roomId,type,outof,intime,clintId,startTime,endTime); | |
234 | + } | |
235 | + | |
236 | + @Autowired | |
237 | + private SendRecordDao sendRecordDao; | |
238 | + | |
239 | + @Test | |
240 | + public void test15() { | |
241 | + //男 | |
242 | + Integer schoolId=27; | |
243 | + Integer roomId =12226; | |
244 | + Integer type = 4; | |
245 | + Integer outof = 0; | |
246 | + String clintId="253169212"; | |
247 | + String timeIds = "2021-01-08,2021-01-11,2021-01-12,2021-01-13,2021-01-14,2021-01-15,2021-01-18,2021-01-19,2021-01-20,2021-01-21,2021-01-22"; | |
248 | + String[] deviceArr = timeIds.split(","); | |
249 | + List<String> deviceList= new ArrayList<>(Arrays.asList(deviceArr)); | |
250 | + //启用多线程执行 | |
251 | + CountDownLatch begin = new CountDownLatch(1); | |
252 | + CountDownLatch end = new CountDownLatch(deviceList.size()); | |
253 | + ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("thread-sendFace-runner-%d").build(); | |
254 | + ExecutorService exe = new ThreadPoolExecutor(8,16,0L, TimeUnit.MILLISECONDS,new LinkedBlockingQueue<Runnable>(),namedThreadFactory); | |
255 | + for(String s : deviceList){ | |
256 | + String intime = s + " 06:03:39"; | |
257 | + String startTime= s + " 00:00:00"; | |
258 | + String endTime = s+" 23:59:59"; | |
259 | + exe.execute(new SendFaceBatchTask2(userDao,sendRecordDao,searchMapper,schoolId,roomId,type,outof,intime,clintId,startTime,endTime,begin,end)); | |
260 | + } | |
261 | + begin.countDown(); | |
262 | + try { | |
263 | + end.await(); | |
264 | + }catch (Exception e){ | |
265 | + e.printStackTrace(); | |
266 | + } | |
267 | + exe.shutdown(); | |
268 | + System.out.println("统计100服务器总共有"+deviceList.size()+"个设备,处理完毕"); | |
152 | 269 | } |
153 | 270 | } | ... | ... |
cloud/haikangface/src/main/java/com/sincere/haikangface/CMSServer.java
1 | 1 | package com.sincere.haikangface; |
2 | 2 | |
3 | 3 | import com.alibaba.fastjson.JSON; |
4 | +import com.alibaba.fastjson.JSONArray; | |
4 | 5 | import com.alibaba.fastjson.JSONObject; |
5 | 6 | import com.sincere.haikangface.bean.AttendanceBean; |
7 | +import com.sincere.haikangface.bean.BaiduFaceRecorder; | |
6 | 8 | import com.sincere.haikangface.bean.StudentBean; |
9 | +import com.sincere.haikangface.bean.TeacherBean; | |
7 | 10 | import com.sincere.haikangface.bean.xiaoan.Face_Recoder; |
8 | 11 | import com.sincere.haikangface.dao.DeviceDao; |
9 | 12 | import com.sincere.haikangface.dao.UserDao; |
10 | 13 | import com.sincere.haikangface.haikanglibs.HCEHomeAlarm; |
11 | 14 | import com.sincere.haikangface.haikanglibs.HCEHomeCMS; |
12 | 15 | import com.sincere.haikangface.haikanglibs.HCEHomeSS; |
16 | +import com.sincere.haikangface.mqtt.MqtUtils; | |
13 | 17 | import com.sincere.haikangface.service.impl.BaseService; |
14 | 18 | import com.sincere.haikangface.utils.AlarmUtils; |
15 | -import com.sincere.haikangface.utils.FileUtils; | |
19 | +import com.sincere.haikangface.utils.HttpUtil; | |
20 | +import com.sincere.haikangface.utils.SpringContextHolder; | |
16 | 21 | import com.sincere.haikangface.xiananDao.SendRecordDao; |
17 | 22 | import com.sun.jna.NativeLong; |
18 | 23 | import com.sun.jna.Pointer; |
19 | 24 | import lombok.extern.slf4j.Slf4j; |
20 | 25 | import org.apache.http.util.TextUtils; |
21 | 26 | import org.springframework.beans.factory.annotation.Autowired; |
22 | -import org.springframework.beans.factory.annotation.Value; | |
23 | 27 | import org.springframework.boot.ApplicationArguments; |
24 | 28 | import org.springframework.boot.ApplicationRunner; |
25 | 29 | import org.springframework.stereotype.Component; |
... | ... | @@ -50,9 +54,6 @@ public class CMSServer implements ApplicationRunner { |
50 | 54 | @Autowired |
51 | 55 | SendRecordDao sendRecordDao; |
52 | 56 | |
53 | - @Autowired | |
54 | - BaseService baseService; | |
55 | - | |
56 | 57 | public static HCEHomeCMS hCEhomeCMS = HCEHomeCMS.INSTANCE; |
57 | 58 | //注册回调函数实现 |
58 | 59 | static FRegisterCallBack fRegisterCallBack; |
... | ... | @@ -61,8 +62,6 @@ public class CMSServer implements ApplicationRunner { |
61 | 62 | // 存储设备登录句柄 |
62 | 63 | static Map<String, NativeLong> map = new HashMap<>(); |
63 | 64 | |
64 | - public static String inTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); | |
65 | - | |
66 | 65 | //114.55.30.100 |
67 | 66 | //120.26.116.253 |
68 | 67 | // private String ip_cloud = "114.55.30.100"; |
... | ... | @@ -246,23 +245,7 @@ public class CMSServer implements ApplicationRunner { |
246 | 245 | log.error("注册设备,设置设备ID异常,错误信息:{}",e); |
247 | 246 | } |
248 | 247 | pInBuffer.dwSize = pInBuffer.size(); |
249 | - AttendanceBean attendanceBean = new AttendanceBean(); | |
250 | - attendanceBean.setClint_id(deviceId); | |
251 | - | |
252 | - if (deviceId.startsWith("ytj")) | |
253 | - attendanceBean.setClint_type("28"); | |
254 | - else | |
255 | - attendanceBean.setClint_type("18"); | |
256 | - attendanceBean.setIntime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); | |
257 | - attendanceBean.setIsConnection(1); | |
258 | - attendanceBean.setSchool_id("-1"); | |
259 | - attendanceBean.setState(1); | |
260 | - if (deviceDao.selectDevice(deviceId) != null) { | |
261 | - deviceDao.updateDeviceStatu(1,inTime,deviceId); | |
262 | - } else { | |
263 | - deviceDao.addDevide(attendanceBean.getClint_id(), attendanceBean.getClint_type(), attendanceBean.getIntime(), | |
264 | - attendanceBean.getSchool_id(), attendanceBean.getState() + "", attendanceBean.getIsConnection() + ""); | |
265 | - } | |
248 | + saveAttendance(deviceId); | |
266 | 249 | /*这里加判断即可,可以通过byDeviceID、sDeviceSerial、sDevName 进行判断 |
267 | 250 | if(strDevRegInfo.dwDevType == 1) { |
268 | 251 | pInBuffer.dwAlarmServerType = 3; |
... | ... | @@ -295,7 +278,7 @@ public class CMSServer implements ApplicationRunner { |
295 | 278 | |
296 | 279 | public boolean invoke(NativeLong iHandle, int enumType, Pointer pOutBuffer, int dwOutLen, Pointer pInBuffer, |
297 | 280 | int dwInLen, Pointer pUser) { |
298 | - System.out.println("信息回调函数上报:------"); | |
281 | + log.info("信息回调函数上报:------"); | |
299 | 282 | if (1 == enumType) { |
300 | 283 | HCEHomeSS.NET_EHOME_SS_TOMCAT_MSG pTomcatMsg = new HCEHomeSS.NET_EHOME_SS_TOMCAT_MSG(); |
301 | 284 | String szDevUri = new String(pTomcatMsg.szDevUri).trim(); |
... | ... | @@ -316,19 +299,17 @@ public class CMSServer implements ApplicationRunner { |
316 | 299 | public class PSS_Storage_Callback implements HCEHomeSS.EHomeSSStorageCallBack { |
317 | 300 | public boolean invoke(NativeLong iHandle, String pFileName, Pointer pFileBuf, int dwFileLen, Pointer pFilePath, Pointer pUser) { |
318 | 301 | String strPath = "C://EhomePicServer/"; |
319 | - FileUtils.getInstance().writeLogs("文件名:" + pFileName, FileUtils.fileName); | |
302 | + //若此目录不存在,则创建之 | |
303 | + File myPath = new File(strPath); | |
304 | + if (!myPath.exists()) { | |
305 | + myPath.mkdirs(); | |
306 | + } | |
320 | 307 | String isQJFileName = pFileName;//用来判断是否是枪机 |
321 | 308 | pFileName = pFileName.replace("_", ""); |
322 | 309 | if (pFileName.contains("T"))pFileName=pFileName.split("T")[0]+".jpg"; |
323 | - FileUtils.getInstance().writeLogs("文件名pFileName:" + pFileName, FileUtils.fileName); | |
324 | 310 | String strFilePath = strPath + pFileName; |
325 | 311 | //保存抓拍到的人脸图片,比对通过后的图片资源 |
326 | - //若此目录不存在,则创建之 | |
327 | - File myPath = new File(strPath); | |
328 | - if (!myPath.exists()) { | |
329 | - myPath.mkdir(); | |
330 | - log.info("人脸抓拍文件,文件夹路径为:" + strPath); | |
331 | - } | |
312 | + log.info("人脸抓拍文件,文件夹路径为:" + strFilePath); | |
332 | 313 | File strFilePathFile = new File(strFilePath); |
333 | 314 | if (!strFilePathFile.exists()) { |
334 | 315 | try { |
... | ... | @@ -358,7 +339,7 @@ public class CMSServer implements ApplicationRunner { |
358 | 339 | deviceId = isQJFileName.substring(start, end); |
359 | 340 | } |
360 | 341 | //发送看板 |
361 | - baseService.sendUserInfoToKB(strFilePathFile, deviceId); | |
342 | + sendUserInfoToKB(strFilePathFile, deviceId); | |
362 | 343 | } |
363 | 344 | } catch (FileNotFoundException e) { |
364 | 345 | log.error("处理人脸机抓拍文件异常,错误信息:{}",e); |
... | ... | @@ -366,13 +347,7 @@ public class CMSServer implements ApplicationRunner { |
366 | 347 | log.error("处理人脸机抓拍文件异常,错误信息:{}",e); |
367 | 348 | } |
368 | 349 | } |
369 | - | |
370 | 350 | pFilePath.write(0, strFilePath.getBytes(), 0, strFilePath.getBytes().length); |
371 | - | |
372 | -// if (isZhuaPai) { | |
373 | -// MqtUtils.getInstance().sendMsg("http://campus.myjxt.com//face17e5/School16/Student/" + pFileName); | |
374 | -// } | |
375 | - | |
376 | 351 | return true; |
377 | 352 | } |
378 | 353 | } |
... | ... | @@ -397,6 +372,7 @@ public class CMSServer implements ApplicationRunner { |
397 | 372 | alarmUtils.setCallBack(new AlarmUtils.AlarmCallBack() { |
398 | 373 | @Override |
399 | 374 | public void callBack(String minorType, String deviceID, String cardNo, String time, String picDataUrlId, String currTemperature) { |
375 | + saveAttendance(deviceID); | |
400 | 376 | switch (minorType) { |
401 | 377 | case "0x4b"://人脸认证通过 |
402 | 378 | log.info("人脸验证通过,事件次类型:"+minorType); |
... | ... | @@ -407,7 +383,7 @@ public class CMSServer implements ApplicationRunner { |
407 | 383 | case "0x427"://人证设备离线 |
408 | 384 | log.info("设备掉线了,设备ID: "+deviceID); |
409 | 385 | map.remove(deviceID); |
410 | - deviceDao.updateDeviceStatu(0,inTime,deviceID); | |
386 | + deviceDao.updateDeviceStatu(0,time,deviceID); | |
411 | 387 | break; |
412 | 388 | case "0x69"://人证比对通过 |
413 | 389 | log.info("人证比对通过,事件次类型:"+minorType); |
... | ... | @@ -445,6 +421,7 @@ public class CMSServer implements ApplicationRunner { |
445 | 421 | * @param picDataUrlId |
446 | 422 | */ |
447 | 423 | private void saveFaceRecoder(String deviceID, String cardNo, String time, String picDataUrlId, String currTemperature) { |
424 | + BaseService baseService = SpringContextHolder.getBaseService(); | |
448 | 425 | try { |
449 | 426 | if (!StringUtils.isEmpty(cardNo) && isNumeric(cardNo)) { |
450 | 427 | Face_Recoder face_recoder = new Face_Recoder(); |
... | ... | @@ -452,19 +429,23 @@ public class CMSServer implements ApplicationRunner { |
452 | 429 | String card = splicingZero(Long.toHexString(Long.parseLong(cardNo)), 8).toUpperCase(); |
453 | 430 | //卡号逆转 |
454 | 431 | cardNo = baseService.getCard(card); |
455 | - StudentBean studentBean = userDao.getStudentWithCard(cardNo); | |
456 | - log.info("用户信息studentBean:{}", studentBean); | |
432 | + StudentBean studentBean = userDao.getStudentWithCard(cardNo,null); | |
433 | + AttendanceBean attendanceBean = deviceDao.selectDevice(deviceID); | |
457 | 434 | if (null != studentBean) { |
458 | - FileUtils.getInstance().writeLogs(studentBean.getName() + " " + cardNo, FileUtils.facerecoder); | |
435 | + String name = studentBean.getName(); | |
436 | + int schoolId = studentBean.getSchool_id(); | |
437 | + String className = studentBean.getClass_name(); | |
438 | + | |
459 | 439 | face_recoder.setCardNum(cardNo); |
460 | 440 | face_recoder.setDeviceId(deviceID); |
461 | 441 | face_recoder.setTime(time); |
462 | - face_recoder.setName(studentBean.getName()); | |
442 | + face_recoder.setName(name); | |
463 | 443 | face_recoder.setUser_id(studentBean.getUser_id()); |
464 | - face_recoder.setInOrOut(1); | |
465 | - String api = "/kms/services/rest/dataInfoService/downloadFile?id=" + picDataUrlId; | |
466 | - String imgUrl = "http://"+ ip_cloud +":8081"+ api; | |
444 | + face_recoder.setInOrOut(attendanceBean.getOutOrIn()); | |
445 | + String imgUrl = "http://" + ip_cloud + ":8081/kms/services/rest/dataInfoService/downloadFile?id=" + picDataUrlId; | |
467 | 446 | face_recoder.setImgurl(imgUrl); |
447 | + log.info("设备: {},人脸抓怕:学校id: {} ,班级:{} ,用户名:{} ,卡号:{} ,",deviceID,schoolId,className,name,cardNo); | |
448 | + log.info("抓拍人脸:" + imgUrl); | |
468 | 449 | if (!TextUtils.isEmpty(currTemperature)) {//只有有温度的才存记录 |
469 | 450 | userDao.addWGTem(studentBean.getUser_id(), studentBean.getStudent_id(), studentBean.getName(), studentBean.getClass_id() + "", |
470 | 451 | studentBean.getClass_name(), currTemperature, studentBean.getStudent_type() + "", studentBean.getSchool_id() + "", time); |
... | ... | @@ -474,7 +455,7 @@ public class CMSServer implements ApplicationRunner { |
474 | 455 | face_recoder.getImgurl(), face_recoder.getInOrOut(), face_recoder.getTime(), face_recoder.getCardNum(), currTemperature); |
475 | 456 | } else { |
476 | 457 | //教师点名 |
477 | - isTeacher(cardNo, deviceID); | |
458 | + isTeacher(cardNo, deviceID,null); | |
478 | 459 | } |
479 | 460 | // if (deviceID.startsWith("qj")) {//枪击 用来抓拍人脸考勤用 |
480 | 461 | // initQJ(deviceID, cardNo, studentBean == null); |
... | ... | @@ -486,18 +467,16 @@ public class CMSServer implements ApplicationRunner { |
486 | 467 | } |
487 | 468 | } |
488 | 469 | |
489 | - public void isTeacher(String cardNo, String deviceID) { | |
470 | + public void isTeacher(String cardNo, String deviceID,Integer schoolId) { | |
490 | 471 | List<String> devLists = userDao.getDeviceRoomRelation(deviceID); |
491 | 472 | if (null != devLists && devLists.size() > 0) { |
492 | - | |
493 | - StudentBean teacher = userDao.getTeacherWithCard(cardNo); | |
494 | - FileUtils.getInstance().writeLogs("teacher:" + teacher + "----" + cardNo, "教师点名.txt"); | |
473 | + StudentBean teacher = userDao.getTeacherWithCard(cardNo,schoolId); | |
474 | + log.info("teacher:" + teacher + "----" + cardNo); | |
495 | 475 | if (null != teacher) { |
496 | 476 | String url = String.format("http://campus.myjxt.com/api/RollCall/AddRollCallPersonnelRecord?userId=%s&deviceId=%s", teacher.getUser_id(), deviceID); |
497 | 477 | RestTemplate restTemplate = new RestTemplate(); |
498 | 478 | String res = restTemplate.getForObject(url, String.class); |
499 | 479 | JSONObject jsonObject = JSON.parseObject(res); |
500 | - FileUtils.getInstance().writeLogs("card:" + res, "教师点名.txt"); | |
501 | 480 | System.out.println("result:" + res + "------url:" + jsonObject.getBoolean("data")); |
502 | 481 | } |
503 | 482 | } |
... | ... | @@ -552,12 +531,8 @@ public class CMSServer implements ApplicationRunner { |
552 | 531 | */ |
553 | 532 | return sendInfo(srcFile, url, card, startTime, endTime, validTimeEnabled, name, deviceId, userType, employeeNo, schoolId,cardNum); |
554 | 533 | } |
555 | - if(schoolId !=null && (schoolId.intValue() == 4 || schoolId.intValue() == 27 || schoolId.intValue() == 864 || | |
556 | - schoolId.intValue() == 2 || schoolId.intValue() == 16)){ | |
557 | - baseService.sendFailRecord(cardNum, srcFile, deviceId,"设备不在线", userType); | |
558 | - }else{ | |
559 | - baseService.sendFail(card, srcFile, deviceId,"设备不在线", userType); | |
560 | - } | |
534 | + BaseService baseService = SpringContextHolder.getBaseService(); | |
535 | + baseService.sendFailRecord(cardNum, srcFile, deviceId,"设备不在线", userType,schoolId); | |
561 | 536 | return false; |
562 | 537 | } |
563 | 538 | |
... | ... | @@ -705,9 +680,7 @@ public class CMSServer implements ApplicationRunner { |
705 | 680 | */ |
706 | 681 | public void SetCardWeekPlan(String clint_id, String card, String userType, String strConfigXMLCard, String content,Integer schoolId,String cardNum) { |
707 | 682 | try { |
708 | - | |
709 | 683 | HCEHomeCMS.NET_EHOME_XML_CFG struXMLCard = new HCEHomeCMS.NET_EHOME_XML_CFG(); |
710 | - | |
711 | 684 | HCEHomeCMS.NET_DVR_STRING_POINTER stringRequestCard = new HCEHomeCMS.NET_DVR_STRING_POINTER(); |
712 | 685 | stringRequestCard.read(); |
713 | 686 | String strRequestCard = "SETDEVICECONFIG"; |
... | ... | @@ -742,15 +715,11 @@ public class CMSServer implements ApplicationRunner { |
742 | 715 | struXMLCard.write(); |
743 | 716 | |
744 | 717 | int i = struXMLCard.size(); |
718 | + BaseService baseService = SpringContextHolder.getBaseService(); | |
745 | 719 | if (!hCEhomeCMS.NET_ECMS_XMLConfig(map.get(clint_id), struXMLCard, struXMLCard.size())) { |
746 | 720 | int iErr = hCEhomeCMS.NET_ECMS_GetLastError(); |
747 | 721 | log.error(content + "失败:" + iErr); |
748 | - if(schoolId !=null && (schoolId.intValue() == 4 || | |
749 | - schoolId.intValue() == 27 || schoolId.intValue() == 2 || schoolId.intValue() == 16)){ | |
750 | - baseService.sendFailRecord(cardNum,"",clint_id,content + "失败:" + iErr, userType); | |
751 | - }else{ | |
752 | - baseService.sendFail(card,"",clint_id,content + "失败:" + iErr, userType); | |
753 | - } | |
722 | + baseService.sendFailRecord(cardNum,"",clint_id,content + "失败:" + iErr, userType,schoolId); | |
754 | 723 | } else { |
755 | 724 | log.info(content + "成功"); |
756 | 725 | } |
... | ... | @@ -817,27 +786,22 @@ public class CMSServer implements ApplicationRunner { |
817 | 786 | HCEHomeCMS.NET_DVR_STRING_POINTER stringXMLOut = new HCEHomeCMS.NET_DVR_STRING_POINTER(); |
818 | 787 | struISAPXML.pOutBuffer = stringXMLOut.getPointer(); |
819 | 788 | struISAPXML.dwOutSize = stringXMLOut.size(); |
789 | + BaseService baseService = SpringContextHolder.getBaseService(); | |
820 | 790 | if (type == 1) {//下发人脸 |
821 | 791 | if (!hCEhomeCMS.NET_ECMS_PostPTXMLConfig(map.get(deviceId), struISAPXML)) { |
822 | 792 | int iErr = hCEhomeCMS.NET_ECMS_GetLastError(); |
823 | 793 | log.error(content + "失败,错误号:" + iErr + "---" + strConfigXML + "\n"); |
824 | - if(schoolId !=null && (schoolId.intValue() == 4 || schoolId.intValue() == 27 || schoolId.intValue() == 864 || | |
825 | - schoolId.intValue() == 2 || schoolId.intValue() == 16)){ | |
826 | - baseService.sendFailRecord(cardNum,"",deviceId,content + "失败,错误号:" + iErr, userType); | |
827 | - }else{ | |
828 | - baseService.sendFail(card,"",deviceId,content + "失败,错误号:" + iErr, userType); | |
794 | + if(schoolId !=null){ | |
795 | + log.info("学校Id: {},失败卡号: {}",schoolId,cardNum); | |
796 | + baseService.sendFailRecord(cardNum,"",deviceId,content + "失败,错误号:" + iErr, userType,schoolId); | |
829 | 797 | } |
830 | -// sendRecoderUtils.sendFailRecord(sendRecordDao, card, srcFile, deviceId, userDao, content + "失败,错误号:" + iErr, userType); | |
831 | 798 | } else { |
832 | 799 | stringXMLOut.read(); |
833 | 800 | String strOutXML = new String(stringXMLOut.byString).trim(); |
834 | - if(schoolId !=null && (schoolId.intValue() == 4 || schoolId.intValue() == 27 || schoolId.intValue() == 864 || | |
835 | - schoolId.intValue() == 2 || schoolId.intValue() == 16)){ | |
836 | - baseService.sendSuccessRecord(cardNum,faceUrl, deviceId,userType); | |
837 | - }else{ | |
838 | - baseService.sendSuccess(card,faceUrl, deviceId,userType); | |
801 | + if(schoolId !=null){ | |
802 | + log.info("学校Id: {},成功卡号: {}",schoolId,cardNum); | |
803 | + baseService.sendSuccessRecord(cardNum,faceUrl, deviceId,userType,schoolId); | |
839 | 804 | } |
840 | - log.info(content + "成功: 下发卡号:" + card); | |
841 | 805 | } |
842 | 806 | } else if (type == 2) {//删除人脸 |
843 | 807 | if (!hCEhomeCMS.NET_ECMS_PutPTXMLConfig(map.get(deviceId), struISAPXML)) { |
... | ... | @@ -863,63 +827,148 @@ public class CMSServer implements ApplicationRunner { |
863 | 827 | return false; |
864 | 828 | } |
865 | 829 | |
866 | - @Value("${attendanceHost}") | |
867 | - private String host; | |
868 | - | |
869 | - /* private boolean sendSMS(String cardNo, String deviceID, String time) { | |
870 | - if (deviceID != null && !deviceID.isEmpty() && !StringUtils.isEmpty(cardNo)) { | |
871 | - cardNo = sendRecoderUtils.getCard(splicingZero(Long.toHexString(Long.parseLong(cardNo)), 8).toUpperCase()); | |
872 | - | |
873 | - System.out.println(String.format("设备号:%s 卡号:%s 时间:%s", deviceID, cardNo, time)); | |
874 | - PlaceAttendance placeAttendance = deviceDao.getPlaceAttendance(deviceID); | |
875 | - AttendanceBean attendanceBean = deviceDao.selectDevice(deviceID); | |
876 | - QianDaoManager qianDaoManager = deviceDao.getQianDaoMnager(attendanceBean.getSchool_id()); | |
877 | - if (null != qianDaoManager) { | |
878 | - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
879 | - String info = String.format("<AttendanceInfo submitTime=\"%s\"><Info device=\"%s\" card=\"%s\" operTime=\"%s\" direc=\"%s\"></Info></AttendanceInfo>", | |
880 | - simpleDateFormat.format(new Date()), deviceID, cardNo, time, "-1"); | |
881 | - | |
882 | - AttendanceInfoBean attendanceInfoBean = new AttendanceInfoBean(); | |
883 | - attendanceInfoBean.setInfo(info); | |
884 | - attendanceInfoBean.setIsControl(0); | |
885 | - attendanceInfoBean.setPwd(qianDaoManager.getPwd()); | |
886 | - attendanceInfoBean.setUsername(qianDaoManager.getAccount()); | |
887 | - | |
888 | - String jsonResult = JSON.toJSONString(attendanceInfoBean); | |
889 | - System.out.println(jsonResult); | |
890 | - | |
891 | - if (placeAttendance == null) {//出入校 | |
892 | - String urlXST = host + "api/XiaoAnCommon/SendXST"; | |
893 | - String result1 = ApiHelper.doPost(urlXST, new HashMap<String, String>(), jsonResult); | |
894 | - JSONObject jsonObject = JSONObject.parseObject(result1); | |
895 | - System.out.println("urlXST:" + result1);//{"status":1,"message":null,"data":"0"} | |
896 | - if ((int) jsonObject.get("status") == 1) { | |
897 | - FileUtils.getInstance().writeLogs("出入校签到成功:" + deviceID + " 卡号:" + cardNo, FileUtils.qiandaoSuccess); | |
898 | - return true; | |
899 | - } else { | |
900 | - FileUtils.getInstance().writeLogs("出入校签到失败:" + deviceID + " 卡号:" + cardNo + " result1:" + result1, FileUtils.qiandaoErr); | |
901 | - return false; | |
902 | - } | |
903 | - } else {//出入寝室 | |
904 | - String urlHXY = host + "api/XiaoAnCommon/SendHXY"; | |
905 | - String result2 = ApiHelper.doPost(urlHXY, new HashMap<String, String>(), jsonResult); | |
906 | - JSONObject jsonObject = JSONObject.parseObject(result2); | |
907 | - System.out.println("urlHXY:" + result2); | |
908 | - if ((int) jsonObject.get("status") == 1) { | |
909 | - FileUtils.getInstance().writeLogs("出入寝签到成功:" + deviceID + " 卡号:" + cardNo, FileUtils.qiandaoSuccess); | |
910 | - return true; | |
830 | + //存储抓拍人脸用户信息 | |
831 | + private static Map<String, Long> userMap = new HashMap<>(); | |
832 | + /** | |
833 | + * 人脸发送看板信息 | |
834 | + * @param file | |
835 | + * @param deviceId | |
836 | + */ | |
837 | + public void sendUserInfoToKB(File file,String deviceId){ | |
838 | + //获取学校ID | |
839 | + String schoolId = userDao.getSchoolIdWithDevId(deviceId); | |
840 | + //请求人脸识别 | |
841 | + JSONObject jsonObject = HttpUtil.sendToKB(file,schoolId); | |
842 | + if(jsonObject ==null){ | |
843 | + log.error("人脸识别失败,返回数据为空"); | |
844 | + return; | |
845 | + } | |
846 | + String face = jsonObject.getString("data"); | |
847 | + if (face.startsWith("face") || face.startsWith("pic")){ | |
848 | + log.error("人脸识别失败"); | |
849 | + return; | |
850 | + } | |
851 | + JSONObject data = jsonObject.getJSONObject("data"); | |
852 | + String errorMsg = data.getString("error_msg"); | |
853 | + //识别成功 | |
854 | + if (errorMsg.equals("SUCCESS")) { | |
855 | + JSONObject result = data.getJSONObject("result"); | |
856 | + //用户信息 | |
857 | + JSONArray userList = result.getJSONArray("user_list"); | |
858 | + if (userList != null && userList.size() > 0) { | |
859 | + for (int i = 0; i < userList.size(); i++) { | |
860 | + JSONObject user = userList.getJSONObject(i); | |
861 | + //用户ID | |
862 | + String userId = user.getString("user_id"); | |
863 | + //比对成功分数值 | |
864 | + String score = user.getString("score"); | |
865 | + double sc = Double.valueOf(score.split("\\.")[0]); | |
866 | + if (sc >= 60) { | |
867 | + TeacherBean teacherBean = userDao.getTeacherWithUserId1(userId); | |
868 | + if (null != teacherBean) { | |
869 | + String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); | |
870 | + teacherBean.setTime(time); | |
871 | + if (org.apache.commons.lang3.StringUtils.isBlank(teacherBean.getTeacer_num())){ | |
872 | + teacherBean.setTeacer_num(userId); | |
873 | + } | |
874 | + //保存百度人脸识别记录 | |
875 | + saveBaiDuFaceRecorder(teacherBean,file,sc,userId); | |
876 | + //同一用户抓拍时间在60秒内,则部不发送看板 | |
877 | + if (userMap.containsKey(userId) && userMap.get(userId)!=null) { | |
878 | + long value = userMap.get(userId); | |
879 | + if ((System.currentTimeMillis() - value) / 1000 > 60) { | |
880 | + userMap.put(userId,System.currentTimeMillis()); | |
881 | + send2DeviceIds(schoolId, teacherBean); | |
882 | + log.info("发送成功....."); | |
883 | + } | |
884 | + } else { | |
885 | + userMap.put(userId, System.currentTimeMillis()); | |
886 | + send2DeviceIds(schoolId, teacherBean); | |
887 | + log.info("发送成功....."); | |
888 | + } | |
889 | + } else { | |
890 | + log.info("用户身份信息不存在"); | |
891 | + sendNoPersonImg(file,schoolId); | |
892 | + } | |
911 | 893 | } else { |
912 | - FileUtils.getInstance().writeLogs("出入寝签到失败:" + deviceID + " 卡号:" + cardNo + " result1:" + result2, FileUtils.qiandaoErr); | |
913 | - return false; | |
894 | + log.info("用户身份信息不存在" + score); | |
895 | + sendNoPersonImg(file,schoolId); | |
914 | 896 | } |
915 | 897 | } |
898 | + } | |
899 | + } else { | |
900 | + log.error("百度人脸识别失败, 返回信息:{}" + jsonObject.toJSONString()); | |
901 | + } | |
902 | + } | |
916 | 903 | |
917 | - } else { | |
918 | - FileUtils.getInstance().writeLogs("schoolId:" + attendanceBean.getSchool_id(), FileUtils.sms); | |
904 | + /** | |
905 | + * 发送平台用户信息至看板设备 | |
906 | + * @param schoolId | |
907 | + * @param teacherBean | |
908 | + */ | |
909 | + private void send2DeviceIds(String schoolId, TeacherBean teacherBean) { | |
910 | + List<String> deviceIds = userDao.getKBDevices(schoolId); | |
911 | + if (deviceIds != null) { | |
912 | + for (int i = 0; i < deviceIds.size(); i++) { | |
913 | + String deviceId = deviceIds.get(i); | |
914 | + if (!org.apache.commons.lang3.StringUtils.isEmpty(deviceId)) { | |
915 | + String content = "{\"cmd\":\"" + 1 + "\",\"clientId\":\"\",\"data\": " + teacherBean.toString() + "}"; | |
916 | + MqtUtils.getInstance().sendMsg(deviceId, content); | |
917 | + } | |
919 | 918 | } |
920 | 919 | } |
921 | - return false; | |
922 | - }*/ | |
920 | + } | |
921 | + | |
922 | + /** | |
923 | + * 发送陌生人信息至设备看板 | |
924 | + * @param faceFile | |
925 | + * @param schoolId | |
926 | + */ | |
927 | + private void sendNoPersonImg(File faceFile, String schoolId) { | |
928 | + List<String> deviceIds = userDao.getKBDevices(schoolId); | |
929 | + String imgName = faceFile.getName(); | |
930 | + String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); | |
931 | + if (imgName.contains(date)) { | |
932 | + String imgId = imgName.substring(0, imgName.indexOf(date)); | |
933 | + String imgUrl = "http://" + ip_cloud + ":8081/kms/services/rest/dataInfoService/downloadFile?id=" + imgId; | |
934 | + log.info("文件名:" + imgUrl); | |
935 | + for (int i = 0; i < deviceIds.size(); i++) { | |
936 | + String deviceId = deviceIds.get(i); | |
937 | + if (!org.springframework.util.StringUtils.isEmpty(deviceId)){ | |
938 | + String content = "{\"cmd\":\"" + 2 + "\",\"clientId\":\"\",\"data\": \"" + imgUrl + "\"}"; | |
939 | + MqtUtils.getInstance().sendMsg(deviceId, content); | |
940 | + } | |
941 | + } | |
942 | + } | |
943 | + try { | |
944 | + Thread.sleep(2000); | |
945 | + } catch (InterruptedException e) { | |
946 | + e.printStackTrace(); | |
947 | + } | |
948 | + } | |
949 | + | |
950 | + private void saveBaiDuFaceRecorder(TeacherBean teacherBean,File faceFile,double score,String userId){ | |
951 | + String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); | |
952 | + BaiduFaceRecorder baiduFaceRecorder = new BaiduFaceRecorder(); | |
953 | + baiduFaceRecorder.setUserId(userId); | |
954 | + baiduFaceRecorder.setName(teacherBean.getName()); | |
955 | + baiduFaceRecorder.setScore(score + ""); | |
956 | + baiduFaceRecorder.setTime(teacherBean.getTime()); | |
957 | + baiduFaceRecorder.setUserImgUrl(teacherBean.getFace()); | |
958 | + String uploadImgUrl = ""; | |
959 | + if(faceFile.getAbsolutePath().contains(date)){ | |
960 | + //抓拍照片ID | |
961 | + String imgId = faceFile.getName().substring(0,faceFile.getName().indexOf(date)); | |
962 | + String api = "http://"+ ip_cloud + ":8081/kms/services/rest/dataInfoService/downloadFile?id=" +imgId; | |
963 | + uploadImgUrl = api; | |
964 | + }else { | |
965 | + uploadImgUrl = faceFile.getAbsolutePath(); | |
966 | + } | |
967 | + baiduFaceRecorder.setUploadImgUrl(uploadImgUrl); | |
968 | + | |
969 | + //插入百度人脸记录表 | |
970 | + userDao.insertBaiduFaceRecorder(baiduFaceRecorder); | |
971 | + } | |
923 | 972 | |
924 | 973 | /** |
925 | 974 | * 字符串前面补零操作 |
... | ... | @@ -948,4 +997,24 @@ public class CMSServer implements ApplicationRunner { |
948 | 997 | return pattern.matcher(str).matches(); |
949 | 998 | } |
950 | 999 | |
1000 | + public void saveAttendance(String deviceId){ | |
1001 | + String inTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); | |
1002 | + AttendanceBean attendanceBean = new AttendanceBean(); | |
1003 | + attendanceBean.setClint_id(deviceId); | |
1004 | + | |
1005 | + if (deviceId.startsWith("ytj")) | |
1006 | + attendanceBean.setClint_type("28"); | |
1007 | + else | |
1008 | + attendanceBean.setClint_type("18"); | |
1009 | + attendanceBean.setIntime(inTime); | |
1010 | + attendanceBean.setIsConnection(1); | |
1011 | + attendanceBean.setSchool_id("-1"); | |
1012 | + attendanceBean.setState(1); | |
1013 | + if (deviceDao.selectDevice(deviceId) != null) { | |
1014 | + deviceDao.updateDeviceStatu(1,inTime,deviceId); | |
1015 | + } else { | |
1016 | + deviceDao.addDevide(attendanceBean.getClint_id(), attendanceBean.getClint_type(), attendanceBean.getIntime(), | |
1017 | + attendanceBean.getSchool_id(), attendanceBean.getState() + "", attendanceBean.getIsConnection() + ""); | |
1018 | + } | |
1019 | + } | |
951 | 1020 | } | ... | ... |
cloud/haikangface/src/main/java/com/sincere/haikangface/HaikangfaceApplication.java
1 | 1 | package com.sincere.haikangface; |
2 | 2 | |
3 | 3 | import com.sincere.haikangface.utils.FileUtils; |
4 | -import org.mybatis.spring.annotation.MapperScan; | |
5 | 4 | import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration; |
6 | 5 | import org.springframework.boot.SpringApplication; |
7 | 6 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; |
... | ... | @@ -10,14 +9,13 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; |
10 | 9 | import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; |
11 | 10 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; |
12 | 11 | import org.springframework.cloud.openfeign.EnableFeignClients; |
13 | -import org.springframework.context.annotation.ComponentScan; | |
14 | 12 | import org.springframework.scheduling.annotation.EnableAsync; |
15 | 13 | |
16 | 14 | @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, MybatisAutoConfiguration.class}) |
17 | 15 | @SpringBootApplication |
18 | 16 | @EnableDiscoveryClient |
19 | 17 | @EnableFeignClients(basePackages = "com.sincere.haikangface.fegin") |
20 | -//@EnableAsync | |
18 | +@EnableAsync | |
21 | 19 | public class HaikangfaceApplication { |
22 | 20 | |
23 | 21 | public static void main(String[] args) { | ... | ... |
cloud/haikangface/src/main/java/com/sincere/haikangface/async/AsyncTask.java
0 → 100644
... | ... | @@ -0,0 +1,95 @@ |
1 | +package com.sincere.haikangface.async; | |
2 | + | |
3 | +import com.sincere.haikangface.bean.SendRecordBean; | |
4 | +import com.sincere.haikangface.bean.StudentBean; | |
5 | +import com.sincere.haikangface.dao.UserDao; | |
6 | +import com.sincere.haikangface.xiananDao.SendRecordDao; | |
7 | +import lombok.extern.slf4j.Slf4j; | |
8 | +import org.springframework.transaction.annotation.Transactional; | |
9 | +import org.springframework.util.CollectionUtils; | |
10 | + | |
11 | +import java.text.SimpleDateFormat; | |
12 | +import java.util.Date; | |
13 | +import java.util.List; | |
14 | +import java.util.concurrent.CountDownLatch; | |
15 | + | |
16 | +/** | |
17 | + * 多线程执行卡下发 | |
18 | + * @author xuquan | |
19 | + * @date 2021/01/12 15:56 | |
20 | + */ | |
21 | +@Slf4j | |
22 | +public class AsyncTask implements Runnable { | |
23 | + | |
24 | + Integer schoolId; | |
25 | + String deviceId; | |
26 | + UserDao userDao; | |
27 | + SendRecordDao sendRecordDao; | |
28 | + CountDownLatch begin; | |
29 | + CountDownLatch end; | |
30 | + | |
31 | + public AsyncTask(UserDao userDao, SendRecordDao sendRecordDao, Integer schoolId,String deviceId, CountDownLatch begin, CountDownLatch end){ | |
32 | + this.userDao=userDao; | |
33 | + this.sendRecordDao=sendRecordDao; | |
34 | + this.schoolId=schoolId; | |
35 | + this.deviceId=deviceId; | |
36 | + this.begin=begin; | |
37 | + this.end=end; | |
38 | + } | |
39 | + | |
40 | + @Override | |
41 | + public void run() { | |
42 | + try { | |
43 | + begin.await(); | |
44 | + List<SendRecordBean> successList = sendRecordDao.getSenSuccesss(deviceId,schoolId); | |
45 | + if(!CollectionUtils.isEmpty(successList)){ | |
46 | + int i =0; | |
47 | + for(SendRecordBean sendRecordBean : successList){ | |
48 | + String deviceId = sendRecordBean.getDeviceID(); | |
49 | + String cardNum = sendRecordBean.getNum(); | |
50 | + int userType = sendRecordBean.getUserType(); | |
51 | + StudentBean studentBean = null; | |
52 | + switch (userType) { | |
53 | + case 1://老师 | |
54 | + studentBean = userDao.getTeacherWithCard(cardNum,schoolId); | |
55 | + break; | |
56 | + case 2://学生 | |
57 | + studentBean = userDao.getStudentWithCard(cardNum,schoolId); | |
58 | + break; | |
59 | + } | |
60 | + if (null != studentBean) { | |
61 | + //用户ID | |
62 | + String userId = studentBean.getUser_id(); | |
63 | + //用户名称 | |
64 | + String userName = studentBean.getName(); | |
65 | + //所属学校 | |
66 | + String schoolName = sendRecordBean.getSchoolName(); | |
67 | + String faceUrl= sendRecordBean.getImgPath(); | |
68 | + String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); | |
69 | + List<SendRecordBean> sendRecordBeans = sendRecordDao.getRecordIsExit(deviceId,cardNum,userId); | |
70 | + int deviceType = 0; | |
71 | + if(deviceId.startsWith("ytj")){ | |
72 | + deviceType=28; | |
73 | + }else { | |
74 | + deviceType=18; | |
75 | + } | |
76 | + if(CollectionUtils.isEmpty(sendRecordBeans)){ | |
77 | + sendRecordDao.saveFaceRecord(userId, deviceId, cardNum, userName, time, schoolName, | |
78 | + faceUrl, schoolId,null,null, userType,deviceType,1,null); | |
79 | + }else { | |
80 | + System.out.println(i); | |
81 | + sendRecordDao.updateFaceSuccessRecord(deviceId,cardNum,time,faceUrl,userName,userId,null); | |
82 | + } | |
83 | +// sendRecordDao.deleteFaceSuccess(cardNum,deviceId); | |
84 | + i++; | |
85 | + } | |
86 | + } | |
87 | + } | |
88 | + }catch (Exception e){ | |
89 | + log.error("异常,信息:",e); | |
90 | + }finally { | |
91 | + end.countDown(); | |
92 | + } | |
93 | + } | |
94 | + | |
95 | +} | ... | ... |
cloud/haikangface/src/main/java/com/sincere/haikangface/async/DeleteTask.java
0 → 100644
... | ... | @@ -0,0 +1,76 @@ |
1 | +package com.sincere.haikangface.async; | |
2 | + | |
3 | +import com.sincere.haikangface.bean.StudentBean; | |
4 | +import com.sincere.haikangface.dao.UserDao; | |
5 | +import com.sincere.haikangface.enums.EnumSzBusinessType; | |
6 | +import com.sincere.haikangface.service.impl.BaseService; | |
7 | +import com.sincere.haikangface.utils.CompressPic; | |
8 | +import com.sincere.haikangface.utils.FileUtils; | |
9 | +import com.sincere.haikangface.xiananDao.SendRecordDao; | |
10 | +import lombok.extern.slf4j.Slf4j; | |
11 | +import org.apache.commons.lang3.StringUtils; | |
12 | +import org.springframework.util.CollectionUtils; | |
13 | + | |
14 | +import java.io.File; | |
15 | +import java.text.SimpleDateFormat; | |
16 | +import java.util.Calendar; | |
17 | +import java.util.Date; | |
18 | +import java.util.List; | |
19 | +import java.util.concurrent.CountDownLatch; | |
20 | + | |
21 | +/** | |
22 | + * 多线程执行卡下发 | |
23 | + * @author xuquan | |
24 | + * @date 2021/01/12 15:56 | |
25 | + */ | |
26 | +@Slf4j | |
27 | +public class DeleteTask implements Runnable { | |
28 | + | |
29 | + Integer schoolId; | |
30 | + Integer roomId; | |
31 | + Integer type; | |
32 | + Integer outof; | |
33 | + UserDao userDao; | |
34 | + String startTime; | |
35 | + String endTime; | |
36 | + SendRecordDao sendRecordDao; | |
37 | + CountDownLatch begin; | |
38 | + CountDownLatch end; | |
39 | + | |
40 | + public DeleteTask(UserDao userDao,SendRecordDao sendRecordDao,Integer schoolId,Integer roomId, Integer type, | |
41 | + Integer outof,String startTime,String endTime,CountDownLatch begin, CountDownLatch end){ | |
42 | + this.userDao=userDao; | |
43 | + this.sendRecordDao=sendRecordDao; | |
44 | + this.schoolId=schoolId; | |
45 | + this.roomId=roomId; | |
46 | + this.type=type; | |
47 | + this.outof=outof; | |
48 | + this.startTime=startTime; | |
49 | + this.endTime=endTime; | |
50 | + this.begin=begin; | |
51 | + this.end=end; | |
52 | + } | |
53 | + | |
54 | + @Override | |
55 | + public void run() { | |
56 | + try { | |
57 | + begin.await(); | |
58 | + List<String> studentIds = userDao.queryStudentIdList(schoolId,roomId); | |
59 | + if(!CollectionUtils.isEmpty(studentIds)){ | |
60 | + for(int i=0;i<=studentIds.size();i++){ | |
61 | + StudentBean userInfoBean = userDao.getStudentWithid(studentIds.get(i)); | |
62 | + if(userInfoBean!=null){ | |
63 | + String cardNum = userInfoBean.getStudent_num(); | |
64 | + System.out.println(i); | |
65 | + sendRecordDao.deleteSS(schoolId,cardNum,type,outof,startTime,endTime); | |
66 | + } | |
67 | + } | |
68 | + } | |
69 | + }catch (Exception e){ | |
70 | + log.error("异常,信息:"); | |
71 | + }finally { | |
72 | + end.countDown(); | |
73 | + } | |
74 | + } | |
75 | + | |
76 | +} | ... | ... |
cloud/haikangface/src/main/java/com/sincere/haikangface/async/SendFaceBatchTask253.java
... | ... | @@ -71,7 +71,7 @@ public class SendFaceBatchTask253 implements Runnable { |
71 | 71 | String filePath = path+ "\\" + fileName; |
72 | 72 | Thread.sleep(1000); |
73 | 73 | //下发253服务器 |
74 | - sendUserAsync.uploadImgs(filePath, cardNum, userName, sno, startTime, endTime, validTimeEnabled, userType); | |
74 | + sendUserAsync.uploadImgs(filePath, cardNum, userName, sno, startTime, endTime, validTimeEnabled, userType,Integer.parseInt(schoolId)); | |
75 | 75 | }catch (Exception e){ |
76 | 76 | log.error("人脸下发失败"); |
77 | 77 | e.printStackTrace(); | ... | ... |
cloud/haikangface/src/main/java/com/sincere/haikangface/async/SendUserAsync.java
... | ... | @@ -15,7 +15,7 @@ import com.sincere.haikangface.service.impl.BaseService; |
15 | 15 | import com.sincere.haikangface.utils.FileUtils; |
16 | 16 | import com.sincere.haikangface.utils.HKXmlUtils; |
17 | 17 | import com.sincere.haikangface.utils.HttpUtil; |
18 | -import com.sincere.haikangface.utils.SendRecoderUtils; | |
18 | +import com.sincere.haikangface.utils.SpringContextHolder; | |
19 | 19 | import com.sincere.haikangface.xiananDao.SendRecordDao; |
20 | 20 | import lombok.extern.slf4j.Slf4j; |
21 | 21 | import org.springframework.beans.factory.annotation.Autowired; |
... | ... | @@ -45,12 +45,6 @@ public class SendUserAsync { |
45 | 45 | @Autowired |
46 | 46 | UserDao userDao; |
47 | 47 | |
48 | - @Autowired | |
49 | - BaseService baseService; | |
50 | - | |
51 | - | |
52 | - SendRecoderUtils sendRecoderUtils; | |
53 | - | |
54 | 48 | /** |
55 | 49 | * 人脸下发至海康设备 |
56 | 50 | * @param srcFile |
... | ... | @@ -81,7 +75,7 @@ public class SendUserAsync { |
81 | 75 | //1老师;2学生 |
82 | 76 | if (Integer.parseInt(userType) ==EnumSzBusinessType.EnumUserType.TEACHER.code) { |
83 | 77 | //根据卡号获取老师信息 |
84 | - StudentBean studentBean = userDao.getTeacherWithCard(resultCard); | |
78 | + StudentBean studentBean = userDao.getTeacherWithCard(resultCard,schoolId); | |
85 | 79 | if (null == studentBean) { |
86 | 80 | employeeNo = time.substring(time.length() - 6, time.length()); |
87 | 81 | } else{ |
... | ... | @@ -90,7 +84,7 @@ public class SendUserAsync { |
90 | 84 | } |
91 | 85 | if (Integer.parseInt(userType) ==EnumSzBusinessType.EnumUserType.STUDENT.code) { |
92 | 86 | //根据卡号获取学生信息 |
93 | - StudentBean studentBean = userDao.getStudentWithCard(resultCard); | |
87 | + StudentBean studentBean = userDao.getStudentWithCard(resultCard,schoolId); | |
94 | 88 | if (null == studentBean) { |
95 | 89 | employeeNo = time.substring(time.length() - 6, time.length()); |
96 | 90 | } else{ |
... | ... | @@ -107,13 +101,8 @@ public class SendUserAsync { |
107 | 101 | cmsServer.SetCardWeekPlan(deviceId, card, userType, HKXmlUtils.getInstance().SetCardRightCfg(card), "设置卡权限",schoolId,cardNum); |
108 | 102 | } |
109 | 103 | } else {//不合格 |
110 | - if(schoolId !=null && (schoolId.intValue() == 4 || schoolId.intValue() == 27 || schoolId.intValue() == 864 || | |
111 | - schoolId.intValue() == 2 || schoolId.intValue() == 16)){ | |
112 | - baseService.sendFailRecord(cardNum, srcFile, deviceId, "人脸照片不合格", userType); | |
113 | - }else{ | |
114 | - baseService.sendFail(card, srcFile, deviceId, "人脸照片不合格", userType); | |
115 | - } | |
116 | - | |
104 | + BaseService baseService = SpringContextHolder.getBaseService(); | |
105 | + baseService.sendFailRecord(cardNum, srcFile, deviceId, "人脸照片不合格", userType,schoolId); | |
117 | 106 | } |
118 | 107 | |
119 | 108 | } |
... | ... | @@ -125,7 +114,6 @@ public class SendUserAsync { |
125 | 114 | * @param permissionBean |
126 | 115 | * @param i 1:不需要重新下发,0需要重新下发 |
127 | 116 | */ |
128 | - @Async("taskExecutor") | |
129 | 117 | public boolean sendPermiss(PermissionBean permissionBean, int i) { |
130 | 118 | try{ |
131 | 119 | //用户类型1老师2学生 |
... | ... | @@ -169,7 +157,6 @@ public class SendUserAsync { |
169 | 157 | * @param permissionBean |
170 | 158 | * @param id |
171 | 159 | */ |
172 | - @Async("taskExecutor") | |
173 | 160 | public boolean sendHKAuth(PermissionBean permissionBean, Integer id,Integer studentType) { |
174 | 161 | try{ |
175 | 162 | //用户类型1老师2学生 |
... | ... | @@ -184,7 +171,7 @@ public class SendUserAsync { |
184 | 171 | String userIds = permissionBean.getUserIds(); |
185 | 172 | |
186 | 173 | List<String> deviceIds = permissionBean.getDeviceIds(); |
187 | - | |
174 | + BaseService baseService = SpringContextHolder.getBaseService(); | |
188 | 175 | for (WeekDay weekDay : weekDays) { |
189 | 176 | List<String> cardNumList = new ArrayList<>(); |
190 | 177 | String sex = weekDay.getSex(); |
... | ... | @@ -282,10 +269,8 @@ public class SendUserAsync { |
282 | 269 | String weekPlanTimes = HKXmlUtils.getInstance().SetCardWeekPlanTimes(weekTime.getStartTime(), weekTime.getEndTime()); |
283 | 270 | stringBuffer.append(weekPlanTimes); |
284 | 271 | } |
285 | - | |
286 | 272 | String weekPlanTime = HKXmlUtils.getInstance().SetCardWeekPlanTime(stringBuffer.toString(), "" + week); |
287 | 273 | String serCardRightCfg = HKXmlUtils.getInstance().SetCardRightCfg(cardNum); |
288 | - FileUtils.getInstance().writeLogs(weekPlanTime, "设置卡权限周计划时间.txt"); | |
289 | 274 | cmsServer.SetCardWeekPlan(deviceId, cardNum, userType, weekPlanTime, "设置卡权限周计划时间",schoolId,cardNum); |
290 | 275 | cmsServer.SetCardWeekPlan(deviceId, cardNum, userType, serCardRightCfg, "设置卡权限",schoolId,cardNum); |
291 | 276 | } |
... | ... | @@ -373,16 +358,14 @@ public class SendUserAsync { |
373 | 358 | * @param validTimeEnabled |
374 | 359 | * @param userType |
375 | 360 | */ |
376 | - public void uploadImgs(String filePath, String card, String name, String deviceId, String startTime, String endTime, int validTimeEnabled, String userType) { | |
377 | - HttpUtil.uploadImgs(filePath, card, name, deviceId, startTime, endTime, validTimeEnabled, userType); | |
361 | + public void uploadImgs(String filePath, String card, String name, String deviceId, String startTime, String endTime, int validTimeEnabled, String userType,Integer schoolId) { | |
362 | + HttpUtil.uploadImgs(filePath, card, name, deviceId, startTime, endTime, validTimeEnabled, userType,schoolId); | |
378 | 363 | } |
379 | 364 | |
380 | 365 | public void deleteCard(String deviceId, String card) { |
381 | 366 | HttpUtil.deleteCard(deviceId, card); |
382 | 367 | } |
383 | 368 | |
384 | - | |
385 | - @Async("taskExecutor") | |
386 | 369 | public boolean IsDeviceOnline(String deviceId) { |
387 | 370 | return HttpUtil.IsDeviceOnline(deviceId); |
388 | 371 | } | ... | ... |
cloud/haikangface/src/main/java/com/sincere/haikangface/bean/AttendanceBean.java
... | ... | @@ -23,6 +23,8 @@ public class AttendanceBean implements Serializable { |
23 | 23 | |
24 | 24 | private int isKaoqin; |
25 | 25 | |
26 | + private int OutOrIn; | |
27 | + | |
26 | 28 | public int getIsKaoqin() { |
27 | 29 | return isKaoqin; |
28 | 30 | } |
... | ... | @@ -87,6 +89,14 @@ public class AttendanceBean implements Serializable { |
87 | 89 | this.school_id = school_id; |
88 | 90 | } |
89 | 91 | |
92 | + public int getOutOrIn() { | |
93 | + return OutOrIn; | |
94 | + } | |
95 | + | |
96 | + public void setOutOrIn(int outOrIn) { | |
97 | + OutOrIn = outOrIn; | |
98 | + } | |
99 | + | |
90 | 100 | @Override |
91 | 101 | public String toString() { |
92 | 102 | return "AttendanceBean{" + | ... | ... |
cloud/haikangface/src/main/java/com/sincere/haikangface/bean/StudentBean.java
... | ... | @@ -63,6 +63,16 @@ public class StudentBean implements Serializable { |
63 | 63 | |
64 | 64 | private String num; |
65 | 65 | |
66 | + private String ParentMobile; | |
67 | + | |
68 | + public String getParentMobile() { | |
69 | + return ParentMobile; | |
70 | + } | |
71 | + | |
72 | + public void setParentMobile(String parentMobile) { | |
73 | + ParentMobile = parentMobile; | |
74 | + } | |
75 | + | |
66 | 76 | public String getNum() { |
67 | 77 | return num; |
68 | 78 | } | ... | ... |
cloud/haikangface/src/main/java/com/sincere/haikangface/bean/UpdateCardBean.java
0 → 100644
... | ... | @@ -0,0 +1,168 @@ |
1 | +package com.sincere.haikangface.bean; | |
2 | + | |
3 | +import javax.xml.crypto.Data; | |
4 | +import java.util.Date; | |
5 | + | |
6 | +/** | |
7 | + * TODO | |
8 | + * | |
9 | + * @author Administrator | |
10 | + * @date 2021/3/4 16:10 | |
11 | + */ | |
12 | + | |
13 | +public class UpdateCardBean { | |
14 | + | |
15 | + private String userId; | |
16 | + private String customerId; | |
17 | + private String studentType; | |
18 | + private Integer userType; | |
19 | + private String name; | |
20 | + private String classId; | |
21 | + private String className; | |
22 | + private String oldCard; | |
23 | + private String card; | |
24 | + private Integer schoolId; | |
25 | + private Integer isNew; | |
26 | + private Integer updateType; | |
27 | + private Date addTime; | |
28 | + private Integer sex; | |
29 | + private String face; | |
30 | + private String studentCode; | |
31 | + private String mobile; | |
32 | + | |
33 | + public String getUserId() { | |
34 | + return userId; | |
35 | + } | |
36 | + | |
37 | + public void setUserId(String userId) { | |
38 | + this.userId = userId; | |
39 | + } | |
40 | + | |
41 | + public String getCustomerId() { | |
42 | + return customerId; | |
43 | + } | |
44 | + | |
45 | + public void setCustomerId(String customerId) { | |
46 | + this.customerId = customerId; | |
47 | + } | |
48 | + | |
49 | + public String getStudentType() { | |
50 | + return studentType; | |
51 | + } | |
52 | + | |
53 | + public void setStudentType(String studentType) { | |
54 | + this.studentType = studentType; | |
55 | + } | |
56 | + | |
57 | + public Integer getUserType() { | |
58 | + return userType; | |
59 | + } | |
60 | + | |
61 | + public void setUserType(Integer userType) { | |
62 | + this.userType = userType; | |
63 | + } | |
64 | + | |
65 | + public String getName() { | |
66 | + return name; | |
67 | + } | |
68 | + | |
69 | + public void setName(String name) { | |
70 | + this.name = name; | |
71 | + } | |
72 | + | |
73 | + public String getClassId() { | |
74 | + return classId; | |
75 | + } | |
76 | + | |
77 | + public void setClassId(String classId) { | |
78 | + this.classId = classId; | |
79 | + } | |
80 | + | |
81 | + public String getClassName() { | |
82 | + return className; | |
83 | + } | |
84 | + | |
85 | + public void setClassName(String className) { | |
86 | + this.className = className; | |
87 | + } | |
88 | + | |
89 | + public String getOldCard() { | |
90 | + return oldCard; | |
91 | + } | |
92 | + | |
93 | + public void setOldCard(String oldCard) { | |
94 | + this.oldCard = oldCard; | |
95 | + } | |
96 | + | |
97 | + public String getCard() { | |
98 | + return card; | |
99 | + } | |
100 | + | |
101 | + public void setCard(String card) { | |
102 | + this.card = card; | |
103 | + } | |
104 | + | |
105 | + public Integer getSchoolId() { | |
106 | + return schoolId; | |
107 | + } | |
108 | + | |
109 | + public void setSchoolId(Integer schoolId) { | |
110 | + this.schoolId = schoolId; | |
111 | + } | |
112 | + | |
113 | + public Integer getIsNew() { | |
114 | + return isNew; | |
115 | + } | |
116 | + | |
117 | + public void setIsNew(Integer isNew) { | |
118 | + this.isNew = isNew; | |
119 | + } | |
120 | + | |
121 | + public Integer getUpdateType() { | |
122 | + return updateType; | |
123 | + } | |
124 | + | |
125 | + public void setUpdateType(Integer updateType) { | |
126 | + this.updateType = updateType; | |
127 | + } | |
128 | + | |
129 | + public Date getAddTime() { | |
130 | + return addTime; | |
131 | + } | |
132 | + | |
133 | + public void setAddTime(Date addTime) { | |
134 | + this.addTime = addTime; | |
135 | + } | |
136 | + | |
137 | + public Integer getSex() { | |
138 | + return sex; | |
139 | + } | |
140 | + | |
141 | + public void setSex(Integer sex) { | |
142 | + this.sex = sex; | |
143 | + } | |
144 | + | |
145 | + public String getFace() { | |
146 | + return face; | |
147 | + } | |
148 | + | |
149 | + public void setFace(String face) { | |
150 | + this.face = face; | |
151 | + } | |
152 | + | |
153 | + public String getStudentCode() { | |
154 | + return studentCode; | |
155 | + } | |
156 | + | |
157 | + public void setStudentCode(String studentCode) { | |
158 | + this.studentCode = studentCode; | |
159 | + } | |
160 | + | |
161 | + public String getMobile() { | |
162 | + return mobile; | |
163 | + } | |
164 | + | |
165 | + public void setMobile(String mobile) { | |
166 | + this.mobile = mobile; | |
167 | + } | |
168 | +} | ... | ... |
cloud/haikangface/src/main/java/com/sincere/haikangface/control/FileControl.java
... | ... | @@ -53,9 +53,9 @@ public class FileControl { |
53 | 53 | } |
54 | 54 | |
55 | 55 | @RequestMapping(method = RequestMethod.POST, value = "uploadImg") |
56 | - public String uploadImg(@RequestParam("file") MultipartFile file, @RequestParam("card") String card | |
57 | - , @RequestParam("name") String name, @RequestParam("deviceId") String deviceId, @RequestParam("startTime") String startTime, | |
58 | - @RequestParam("endTime") String endTime, @RequestParam("validTimeEnabled") int validTimeEnabled, @RequestParam("userType") String userType) { | |
56 | + public String uploadImg(@RequestParam("file") MultipartFile file,@RequestParam("schoolId") Integer schoolId,@RequestParam("card") String card, | |
57 | + @RequestParam("name") String name, @RequestParam("deviceId") String deviceId, @RequestParam("userType") String userType, | |
58 | + @RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime, @RequestParam("validTimeEnabled") int validTimeEnabled) { | |
59 | 59 | try { |
60 | 60 | if (!cmsServer.getIsDeviceOnline(deviceId)) { |
61 | 61 | log.warn("设备ID: {},设备不在线",deviceId); |
... | ... | @@ -74,8 +74,12 @@ public class FileControl { |
74 | 74 | fileOutputStream.close(); |
75 | 75 | String filePath = dest.getAbsolutePath(); |
76 | 76 | long time = System.currentTimeMillis(); |
77 | - StudentBean studentBean = userDao.getStudentWithCard(card); | |
78 | - Integer schoolId = studentBean ==null ?null:studentBean.getSchool_id(); | |
77 | + StudentBean studentBean =null; | |
78 | + if(userType.equals("1")){ | |
79 | + studentBean= userDao.getTeacherWithCard(card,schoolId); | |
80 | + }else{ | |
81 | + studentBean= userDao.getStudentWithCard(card,schoolId); | |
82 | + } | |
79 | 83 | String cardNum = Long.parseLong(baseService.getCard(card),16) + ""; |
80 | 84 | if (new File(filePath.trim()).exists()) { |
81 | 85 | String targetPath = FileUtils.picPathComp + new File(filePath).getName(); |
... | ... | @@ -94,7 +98,7 @@ public class FileControl { |
94 | 98 | return "0"; |
95 | 99 | } |
96 | 100 | } else { |
97 | - baseService.sendFail(cardNum, filePath, deviceId,"文件不存在", userType); | |
101 | + baseService.sendFailRecord(cardNum, filePath, deviceId,"文件不存在", userType,schoolId); | |
98 | 102 | log.error("文件不存在:" + filePath); |
99 | 103 | } |
100 | 104 | } catch (Exception e) { |
... | ... | @@ -106,25 +110,27 @@ public class FileControl { |
106 | 110 | @RequestMapping(value = "IsDeviceOnline", method = RequestMethod.GET) |
107 | 111 | @ApiOperation("判断设备是否在线") |
108 | 112 | public String IsDeviceOnline(@RequestParam("deviceId") String deviceId) { |
109 | - return cmsServer.getIsDeviceOnline(deviceId) ? "1" : "0"; | |
113 | + if(cmsServer.getIsDeviceOnline(deviceId)){ | |
114 | + return "1"; | |
115 | + }else{ | |
116 | + return "0"; | |
117 | + } | |
110 | 118 | } |
111 | 119 | |
112 | - | |
113 | 120 | @RequestMapping(value = "DeleteCard", method = RequestMethod.GET) |
114 | - @ApiOperation("删除人脸") | |
121 | + @ApiOperation("删除设备人脸") | |
115 | 122 | public String deleteCard(@RequestParam("deviceId") String deviceId, @RequestParam("card") String card) { |
116 | - StudentBean studentBean = userDao.getStudentWithCard(card); | |
117 | - Integer schoolId = studentBean ==null ?null:studentBean.getSchool_id(); | |
118 | - cmsServer.deleteCard(deviceId, Long.parseLong(baseService.getCard(card), 16) + "",schoolId); | |
119 | - return "1"; | |
123 | + if(cmsServer.deleteCard(deviceId, Long.parseLong(baseService.getCard(card), 16) + "",null)){ | |
124 | + return "1"; | |
125 | + }else{ | |
126 | + return "0"; | |
127 | + } | |
120 | 128 | } |
121 | 129 | |
122 | 130 | @RequestMapping(value = "getCard", method = RequestMethod.GET) |
123 | 131 | @ApiOperation("获取设备人脸是否存在") |
124 | 132 | public String getCard(@RequestParam("deviceId") String deviceId, @RequestParam("card") String card) { |
125 | - StudentBean studentBean = userDao.getStudentWithCard(card); | |
126 | - Integer schoolId = studentBean ==null ?null:studentBean.getSchool_id(); | |
127 | - if (cmsServer.getFace(deviceId, Long.parseLong(baseService.getCard(card), 16) + "",schoolId)){ | |
133 | + if (cmsServer.getFace(deviceId, Long.parseLong(baseService.getCard(card), 16) + "",null)){ | |
128 | 134 | return "1"; |
129 | 135 | }else{ |
130 | 136 | return "0"; | ... | ... |
cloud/haikangface/src/main/java/com/sincere/haikangface/control/UserControl.java
1 | 1 | package com.sincere.haikangface.control; |
2 | + | |
2 | 3 | import com.alibaba.fastjson.JSON; |
3 | -import com.sincere.haikangface.bean.*; | |
4 | 4 | import com.sincere.haikangface.CMSServer; |
5 | 5 | import com.sincere.haikangface.async.SendUserAsync; |
6 | +import com.sincere.haikangface.bean.Images2Ddevices; | |
7 | +import com.sincere.haikangface.bean.SendRecordBean; | |
8 | +import com.sincere.haikangface.bean.StudentBean; | |
6 | 9 | import com.sincere.haikangface.bean.face.PermissionBean; |
7 | 10 | import com.sincere.haikangface.bean.face.UserAndPermission; |
8 | 11 | import com.sincere.haikangface.dao.UserDao; |
9 | 12 | import com.sincere.haikangface.fegin.HaikangfaceFegin; |
10 | 13 | import com.sincere.haikangface.service.impl.BaseService; |
11 | -import com.sincere.haikangface.utils.*; | |
14 | +import com.sincere.haikangface.utils.CompressPic; | |
15 | +import com.sincere.haikangface.utils.FileUtils; | |
16 | +import com.sincere.haikangface.utils.HttpUtil; | |
12 | 17 | import com.sincere.haikangface.xiananDao.SendRecordDao; |
13 | 18 | import io.swagger.annotations.Api; |
14 | -import io.swagger.annotations.ApiImplicitParam; | |
15 | -import io.swagger.annotations.ApiImplicitParams; | |
16 | 19 | import io.swagger.annotations.ApiOperation; |
17 | 20 | import lombok.extern.slf4j.Slf4j; |
18 | 21 | import org.springframework.beans.factory.annotation.Autowired; |
19 | 22 | import org.springframework.http.MediaType; |
20 | 23 | import org.springframework.util.StringUtils; |
21 | 24 | import org.springframework.web.bind.annotation.*; |
22 | -import org.springframework.web.multipart.MultipartFile; | |
23 | -import java.io.*; | |
25 | + | |
26 | +import java.io.File; | |
24 | 27 | import java.text.SimpleDateFormat; |
25 | -import java.util.*; | |
28 | +import java.util.Calendar; | |
29 | +import java.util.Date; | |
30 | +import java.util.List; | |
26 | 31 | |
27 | 32 | @RestController |
28 | 33 | @RequestMapping(value = "/facereco/*", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) |
... | ... | @@ -52,7 +57,6 @@ public class UserControl { |
52 | 57 | @ApiOperation("下发权限给设备") |
53 | 58 | public boolean sendPermiss(@RequestBody PermissionBean permissionBean) { |
54 | 59 | log.error("permissionBean:{}", JSON.toJSONString(permissionBean)); |
55 | - FileUtils.getInstance().writeLogs("传入权限模板:" + JSON.toJSONString(permissionBean), "设置权限内容.txt"); | |
56 | 60 | if (!StringUtils.isEmpty(permissionBean.getDeviceIds())) { |
57 | 61 | return sendUserAsync.sendPermiss(permissionBean, 0); |
58 | 62 | } |
... | ... | @@ -63,33 +67,22 @@ public class UserControl { |
63 | 67 | @ApiOperation("下发指定教师用户权限给设备") |
64 | 68 | public boolean sendUsersAndPermiss(@RequestBody UserAndPermission userAndPermission) { |
65 | 69 | log.info("下发指定教师权限,权限信息permission:{}", JSON.toJSONString(userAndPermission)); |
66 | - FileUtils.getInstance().writeLogs(JSON.toJSONString(userAndPermission), "下发指定教师用户权限给设备.txt"); | |
67 | 70 | PermissionBean permissionBean = new PermissionBean(); |
68 | 71 | permissionBean.setSchoolId(userAndPermission.getSchoolId()); |
69 | 72 | permissionBean.setUserType(String.valueOf(userAndPermission.getUserType())); |
70 | 73 | permissionBean.setWeekDays(userAndPermission.getWeekDays()); |
71 | 74 | return sendUserAsync.sendPermiss(permissionBean, 0); |
72 | - } | |
73 | 75 | |
74 | - @RequestMapping(value = "sendStuCardAndImg", method = RequestMethod.GET) | |
75 | - @ApiOperation("下发人脸给设备") | |
76 | - public boolean sendCardAndImg(@RequestParam("filePath") String filePath, @RequestParam("card") String card | |
77 | - , @RequestParam("name") String name, @RequestParam("deviceId") String deviceId, @RequestParam("startTime") String startTime, | |
78 | - @RequestParam("endTime") String endTime, @RequestParam("validTimeEnabled") int validTimeEnabled, @RequestParam("userType") String userType) { | |
79 | - return baseService.sendImg2Device(filePath, card, name, deviceId, userType); | |
80 | 76 | } |
81 | 77 | |
82 | - @RequestMapping(value = "sendCardAndImg1", method = RequestMethod.GET) | |
78 | + @RequestMapping(value = "sendStuCardAndImg", method = RequestMethod.GET) | |
83 | 79 | @ApiOperation("下发人脸给设备") |
84 | - public boolean sendCardAndImg1(@RequestParam("filePath") String filePath, @RequestParam("card") String card, | |
85 | - @RequestParam("name") String name, @RequestParam("deviceId") String deviceId, | |
86 | - @RequestParam("userType") String userType) { | |
87 | - log.error("sendCardAndImg1:---------------------------------"); | |
88 | - return baseService.sendImg2Device(filePath, card, name, deviceId, userType); | |
80 | + public boolean sendCardAndImg(@RequestParam("schoolId") Integer schoolId,@RequestParam("card") String card,@RequestParam("filePath") String filePath, | |
81 | + @RequestParam("name") String name, @RequestParam("deviceId") String deviceId,@RequestParam("userType") String userType) { | |
82 | + return baseService.sendImg2Device(filePath, card, name, deviceId, userType,schoolId); | |
89 | 83 | } |
90 | 84 | |
91 | 85 | @RequestMapping(value = "sendImg2Devices", method = RequestMethod.POST) |
92 | - @ApiOperation("本地下发人脸给设备") | |
93 | 86 | public boolean sendImg2Devices(@RequestBody Images2Ddevices images2Ddevices) throws Exception { |
94 | 87 | String startTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); |
95 | 88 | Calendar calendar = Calendar.getInstance(); |
... | ... | @@ -139,7 +132,7 @@ public class UserControl { |
139 | 132 | String cardNum = Long.parseLong(baseService.getCard(card), 16) + ""; |
140 | 133 | sendUserAsync.sendStuToHaiKang(filePath.getAbsolutePath(),targetPath,cardNum, startTime, endTime,1, name, devId, images2Ddevices.getUserType(), 0,card); |
141 | 134 | } else { |
142 | - sendUserAsync.uploadImgs(targetPath, card, name, devId, startTime, endTime, 1, images2Ddevices.getUserType()); | |
135 | + sendUserAsync.uploadImgs(targetPath, card, name, devId, startTime, endTime, 1, images2Ddevices.getUserType(),Integer.parseInt(schoolId)); | |
143 | 136 | } |
144 | 137 | } else { |
145 | 138 | log.error("学生对象不存在"); |
... | ... | @@ -155,7 +148,6 @@ public class UserControl { |
155 | 148 | } |
156 | 149 | |
157 | 150 | @RequestMapping(value = "sendFaces", method = RequestMethod.GET) |
158 | - @ApiOperation(value = "下发学校下所有人脸给指定设备", notes = "下发所有人脸给指定设备") | |
159 | 151 | public void sendFaces(@RequestParam("deviceIds") String deviceIds, @RequestParam("schoolId") String schoolId, @RequestParam("userType") String userType) { |
160 | 152 | String typeName = userType.equals("1") ? "Teacher" : "Student"; |
161 | 153 | String imgPath = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\" + typeName; |
... | ... | @@ -201,12 +193,6 @@ public class UserControl { |
201 | 193 | } |
202 | 194 | |
203 | 195 | @RequestMapping(value = "sendErrorFaces", method = RequestMethod.GET) |
204 | - @ApiOperation(value = "下发失败的人脸", notes = "下发失败的人脸") | |
205 | - @ApiImplicitParams({ | |
206 | - @ApiImplicitParam(name = "deviceid", required = false), | |
207 | - @ApiImplicitParam(name = "userType", required = false), | |
208 | - @ApiImplicitParam(name = "schoolId", required = true) | |
209 | - }) | |
210 | 196 | public void sendErrorFaces(String schoolId, String deviceid, String userType) { |
211 | 197 | log.info("开始下发失败人脸:schoolId:" + schoolId + "---deviceid:" + deviceid + "---userType:" + userType); |
212 | 198 | //不传的话就默认失败表中的类型 |
... | ... | @@ -225,9 +211,7 @@ public class UserControl { |
225 | 211 | } |
226 | 212 | |
227 | 213 | @RequestMapping(value = "sendFaceNotExits", method = RequestMethod.GET) |
228 | - @ApiOperation(value = "下发学校下还没有下发的人脸给指定设备", notes = "下发学校下还没有下发的人脸给指定设备") | |
229 | 214 | public void sendFaceNotExits(@RequestParam("deviceIds") String deviceIds, @RequestParam("schoolId") String schoolId, @RequestParam("userType") String userType) { |
230 | - | |
231 | 215 | String typeName = userType.equals("1") ? "Teacher" : "Student"; |
232 | 216 | |
233 | 217 | String imgPath = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\" + typeName; |
... | ... | @@ -282,52 +266,35 @@ public class UserControl { |
282 | 266 | } |
283 | 267 | |
284 | 268 | |
285 | - @RequestMapping(value = "sendFaceToDevices", method = RequestMethod.GET) | |
286 | - @ApiOperation(value = "下发单个用户给指定设备", notes = "下发单个用户给指定设备") | |
287 | - @ApiImplicitParams( | |
288 | - {@ApiImplicitParam(name = "deviceIds", value = "设备id用逗号,拼接"), | |
289 | - @ApiImplicitParam(name = "file", value = "100服务器上图片绝对路径")}) | |
290 | - public void sendFaceToDevices(@RequestParam("deviceIds") String deviceIds, @RequestParam("userType") String userType, | |
291 | - @RequestParam("file") String file, @RequestParam("card") String card, @RequestParam("name") String name) { | |
292 | - String[] deviceIdsStr = deviceIds.split(","); | |
293 | - File file1 = new File(file); | |
294 | - String targetPath = FileUtils.picPathComp + file1.getName(); | |
295 | - try { | |
296 | - CompressPic.CompressPic(file1.getAbsolutePath(), targetPath); | |
297 | - } catch (Exception e) { | |
298 | - e.printStackTrace(); | |
299 | - } | |
300 | - for (int i = 0; i < deviceIdsStr.length; i++) { | |
301 | - String deviceId = deviceIdsStr[i]; | |
302 | - StudentBean studentBean = userDao.getStudentWithCard(card); | |
303 | - Integer schoolId = studentBean ==null ?null:studentBean.getSchool_id(); | |
304 | - baseService.sendImg(file1.getAbsolutePath(), targetPath, deviceId, card, name, userType,schoolId); | |
305 | - } | |
306 | - | |
307 | - } | |
308 | - | |
309 | - | |
310 | 269 | @RequestMapping(value = "DeleteCard", method = RequestMethod.GET) |
311 | - @ApiOperation("删除人脸") | |
312 | 270 | public boolean deleteCard(@RequestParam("deviceId") String deviceId, @RequestParam("card") String card) { |
313 | - StudentBean studentBean = userDao.getStudentWithCard(card); | |
314 | - Integer schoolId = studentBean ==null ?null:studentBean.getSchool_id(); | |
271 | + StudentBean studentBean = userDao.getStudentWithCard(card,null); | |
272 | + if(studentBean ==null){ | |
273 | + log.error("此卡号未检索到对应学生"); | |
274 | + return false; | |
275 | + } | |
315 | 276 | if (cmsServer.getIsDeviceOnline(deviceId)) { |
316 | 277 | String cardNo = Long.parseLong(baseService.getCard(card), 16) + ""; |
317 | - cmsServer.deleteCard(deviceId, cardNo,schoolId); | |
278 | + return cmsServer.deleteCard(deviceId, cardNo,null); | |
318 | 279 | }else{ |
319 | - HttpUtil.deleteCard(deviceId, card); | |
280 | + return HttpUtil.deleteCard(deviceId, card); | |
320 | 281 | } |
321 | - return true; | |
322 | 282 | } |
323 | 283 | |
324 | 284 | @RequestMapping(value = "getCard", method = RequestMethod.GET) |
325 | 285 | @ApiOperation("获取设备人脸是否存在") |
326 | 286 | public boolean getCard(@RequestParam("deviceId") String deviceId,@RequestParam("card") String card) { |
327 | - StudentBean studentBean = userDao.getStudentWithCard(card); | |
328 | - Integer schoolId = studentBean ==null ?null:studentBean.getSchool_id(); | |
329 | - String cardNo = Long.parseLong(baseService.getCard(card),16)+""; | |
330 | - return cmsServer.getFace(deviceId, cardNo,schoolId); | |
287 | + StudentBean studentBean = userDao.getStudentWithCard(card,null); | |
288 | + if(studentBean ==null){ | |
289 | + log.error("此卡号未检索到对应学生"); | |
290 | + return false; | |
291 | + } | |
292 | + if (cmsServer.getIsDeviceOnline(deviceId)) { | |
293 | + String cardNo = Long.parseLong(baseService.getCard(card), 16) + ""; | |
294 | + return cmsServer.getFace(deviceId, cardNo,null); | |
295 | + }else{ | |
296 | + return HttpUtil.deleteCard(deviceId, card); | |
297 | + } | |
331 | 298 | } |
332 | 299 | |
333 | 300 | @RequestMapping(value = "IsDeviceOnline", method = RequestMethod.GET) |
... | ... | @@ -340,80 +307,10 @@ public class UserControl { |
340 | 307 | } |
341 | 308 | } |
342 | 309 | |
343 | - @RequestMapping(value = "FaceUploadFile", method = RequestMethod.POST) | |
344 | - @ApiOperation("人脸图片上传") | |
345 | - public String FaceUploadFile(@RequestParam("file") MultipartFile file) { | |
346 | - | |
347 | - String targetPath = FileUtils.picPathComp; | |
348 | - System.out.println("fileName:" + file.getOriginalFilename()); | |
349 | - return "sss"; | |
350 | - | |
351 | - } | |
352 | - | |
353 | - | |
354 | -// @RequestMapping(value = "getKaoqinTem", method = RequestMethod.GET) | |
355 | -// @ApiOperation("根据设备获取考勤模板") | |
356 | -// public String getKaoqinTem(@RequestParam("deviceId") String deviceId) { | |
357 | -// SZ_AttendanceDto attendanceBean = haikangfaceFegin.selectAttendaceWithId(deviceId); | |
358 | -// System.out.println("isKaoqin:" + attendanceBean.toString()); | |
359 | -// int isKaoqin = attendanceBean.getIsKaoqin();//获取考勤模板id | |
360 | -// List<SZ_AttendanceDto> attendanceBeans = haikangfaceFegin.getAttensWithIsKaoqin(isKaoqin);//获取同一模板下的设备 | |
361 | -// String content = ""; | |
362 | -// | |
363 | -// for (int i = 0; i < attendanceBeans.size(); i++) { | |
364 | -// String clientId = attendanceBeans.get(i).getClint_id(); | |
365 | -// if (!StringUtils.isEmpty(clientId)) content += clientId + ","; | |
366 | -// } | |
367 | -// return content.substring(0, content.lastIndexOf(",")); | |
368 | -// } | |
369 | - | |
370 | - | |
371 | -// @RequestMapping(value = "addFace", method = RequestMethod.GET) | |
372 | -// @ApiOperation("注册人脸") | |
373 | -// public String addFace(@RequestParam("imgPath") String imgPath, @RequestParam("group_id") String group_id, | |
374 | -// @RequestParam("user_id") String user_id, @RequestParam("user_info") String user_info) { | |
375 | -// | |
376 | -// return BaiduApiUtiols.getInstance().registerFace(imgPath, group_id, user_id, user_info); | |
377 | -// } | |
378 | -// | |
379 | -// @RequestMapping(value = "searchFace", method = RequestMethod.GET) | |
380 | -// @ApiOperation("搜索人脸") | |
381 | -// public String searchFace(@RequestParam("imgPath") String imgPath, @RequestParam("group_id") String group_id, | |
382 | -// @RequestParam("user_id") String user_id) { | |
383 | -// | |
384 | -// return BaiduApiUtiols.getInstance().searchFace(imgPath, group_id, user_id); | |
385 | -// } | |
386 | - | |
387 | - @RequestMapping(value = "sendFiles", method = RequestMethod.GET) | |
388 | - @ApiOperation("批量下发人脸") | |
389 | - public String sendFiles() { | |
390 | - | |
391 | - List<StudentInfo> studentBeans = userDao.getAllStus(); | |
392 | - String filePath = ""; | |
393 | - List<String> deviceId = userDao.getDeviceIdsWidthSchoolId(562); | |
394 | - | |
395 | - for (int i = 0; i < studentBeans.size(); i++) { | |
396 | - StudentInfo studentBean = studentBeans.get(i); | |
397 | - | |
398 | - filePath = "C://Student//" + studentBean.getStudentcode() + ".png"; | |
399 | - System.out.println("filePath:" + new File(filePath).exists() + " devId:" + deviceId.toString()); | |
400 | - if (!new File(filePath).exists()) | |
401 | - FileUtils.getInstance().writeLogs(studentBean.getStudentcode(), FileUtils.studentcode); | |
402 | - | |
403 | - for (int j = 0; j < deviceId.size(); j++) { | |
404 | - String devId = deviceId.get(j); | |
405 | - sendCardAndImg(filePath, studentBean.getStudent_num(), studentBean.getName(), devId, "2019-10-30 12:00:00", "2030-10-10 10:00:00", | |
406 | - 1, "2"); | |
407 | - } | |
408 | - } | |
409 | - return ""; | |
410 | - } | |
411 | - | |
412 | 310 | @RequestMapping(value = "isTeacher", method = RequestMethod.GET) |
413 | - @ApiOperation("测试教师点名") | |
414 | - public void isTeacher(@RequestParam("deviceId") String deviceId, @RequestParam("cardNo") String cardNo) { | |
311 | + public void isTeacher(@RequestParam("schoolId") Integer schoolId,@RequestParam("deviceId") String deviceId, @RequestParam("cardNo") String cardNo) { | |
415 | 312 | try { |
416 | - cmsServer.isTeacher(cardNo, deviceId); | |
313 | + cmsServer.isTeacher(cardNo, deviceId,schoolId); | |
417 | 314 | } catch (Exception e) { |
418 | 315 | e.printStackTrace(); |
419 | 316 | } |
... | ... | @@ -423,7 +320,7 @@ public class UserControl { |
423 | 320 | @ApiOperation("发送数据到看板") |
424 | 321 | public void sendToKB(@RequestParam("filePath") String filePath, @RequestParam("deviceid") String deviceid) { |
425 | 322 | try { |
426 | - baseService.sendUserInfoToKB(new File(filePath), deviceid); | |
323 | + cmsServer.sendUserInfoToKB(new File(filePath), deviceid); | |
427 | 324 | } catch (Exception e) { |
428 | 325 | e.printStackTrace(); |
429 | 326 | } | ... | ... |
cloud/haikangface/src/main/java/com/sincere/haikangface/control/UserOperateController.java
... | ... | @@ -13,6 +13,7 @@ import lombok.extern.slf4j.Slf4j; |
13 | 13 | import org.springframework.beans.factory.annotation.Autowired; |
14 | 14 | import org.springframework.http.MediaType; |
15 | 15 | import org.springframework.web.bind.annotation.*; |
16 | +import org.springframework.web.multipart.MultipartFile; | |
16 | 17 | |
17 | 18 | /** |
18 | 19 | * 用户信息、人脸、卡信息、权限下发控制类 |
... | ... | @@ -66,15 +67,9 @@ public class UserOperateController { |
66 | 67 | } |
67 | 68 | |
68 | 69 | @ApiOperation(value = "照片下发2.0") |
69 | - @RequestMapping(value = "sendFace", method = RequestMethod.GET) | |
70 | - public Result sendFace(@RequestParam("schoolId") String schoolId, @RequestParam("type") int type,@RequestParam("deviceIds") String deviceIds) { | |
71 | - return userOperateService.sendFace(schoolId,type,deviceIds); | |
72 | - } | |
73 | - | |
74 | - @ApiOperation(value = "照片下发2.1") | |
75 | 70 | @RequestMapping(value = "sendFaceByThread", method = RequestMethod.POST) |
76 | - public Result sendFaceByThread(@RequestBody SendFaceDto sendFaceDto) { | |
77 | - return userOperateService.sendUserFaceByThread(sendFaceDto); | |
71 | + public Result sendFaceByThread(@RequestBody SendFaceDto sendFaceDto,@RequestParam(value = "groupId",required = false) Integer groupId) { | |
72 | + return userOperateService.sendUserFaceByThread(sendFaceDto,groupId); | |
78 | 73 | } |
79 | 74 | |
80 | 75 | @ApiOperation(value = "删除下发失败人脸2.0") |
... | ... | @@ -91,14 +86,32 @@ public class UserOperateController { |
91 | 86 | |
92 | 87 | @ApiOperation(value = "删除指定人脸2.0") |
93 | 88 | @RequestMapping(value = "deleteFace", method = RequestMethod.POST) |
94 | - public Result deleteFace(@RequestParam("schoolId") Integer schoolId, @RequestParam("cards") String cards,@RequestParam("deviceIds") String deviceIds) { | |
89 | + public Result deleteFace(@RequestParam("schoolId") Integer schoolId, @RequestParam("cards") String cards, | |
90 | + @RequestParam(value = "deviceIds",required = false) String deviceIds) { | |
95 | 91 | return userOperateService.deleteFace(schoolId,cards,deviceIds); |
96 | 92 | } |
97 | 93 | |
98 | - @ApiOperation(value = "测试下发人脸2.0") | |
99 | - @RequestMapping(value = "deleteFaceTest", method = RequestMethod.POST) | |
100 | - public Result deleteFaceTest(@RequestParam("schoolId") Integer schoolId,@RequestParam("deviceIds") String deviceIds) { | |
101 | - return userOperateService.deleteFaceTest(schoolId,deviceIds); | |
94 | + @ApiOperation(value = "下发未下发的人脸至指定设备2.0") | |
95 | + @RequestMapping(value = "sendFaceForNoSend", method = RequestMethod.POST) | |
96 | + public Result sendFaceForNoSend(@RequestParam("schoolId") Integer schoolId,@RequestParam("userType") Integer userType, | |
97 | + @RequestParam(value = "studentType",required = false) Integer studentType, | |
98 | + @RequestParam(value = "sex",required = false) String sex, | |
99 | + @RequestParam(value = "deviceIds",required = false) String deviceIds) { | |
100 | + return userOperateService.sendFaceForNoSend(schoolId,studentType,sex,userType,deviceIds); | |
101 | + } | |
102 | + | |
103 | + @ApiOperation(value = "补发单个人脸至指定设备2.0") | |
104 | + @RequestMapping(value = "againNoSendOneFace", method = RequestMethod.POST) | |
105 | + public Result againNoSendOneFace(@RequestParam("file") MultipartFile file,@RequestParam("schoolId") Integer schoolId, | |
106 | + @RequestParam("cardNum") String cardNum,@RequestParam("userType") Integer userType,@RequestParam("deviceIds") String deviceIds) { | |
107 | + return userOperateService.againNoSendOneFace(file,schoolId,cardNum,userType,deviceIds); | |
108 | + } | |
109 | + | |
110 | + | |
111 | + @ApiOperation(value = "捷安成闸机导入") | |
112 | + @RequestMapping(value = "insertUpdateCard", method = RequestMethod.POST) | |
113 | + public Result insertUpdateCard(@RequestParam("cardNums") String cardNums){ | |
114 | + return userOperateService.insertUpdateCard(cardNums); | |
102 | 115 | } |
103 | 116 | |
104 | 117 | } | ... | ... |
cloud/haikangface/src/main/java/com/sincere/haikangface/dao/UserDao.java
... | ... | @@ -49,13 +49,6 @@ public interface UserDao { |
49 | 49 | @Select("select * from SZ_User where user_id = #{user_id}") |
50 | 50 | UserBean getUser(@Param("user_id") String user_id); |
51 | 51 | |
52 | - | |
53 | - @Select("select Top(1)* from SZ_V_School_Student where student_num = #{card}") | |
54 | - StudentBean getStudentWithCard(@Param("card") String card); | |
55 | - | |
56 | - @Select("select Top(1)* from SZ_V_School_Teacher where teacher_num = #{teacher_num}") | |
57 | - StudentBean getTeacherWithCard(@Param("teacher_num") String teacher_num); | |
58 | - | |
59 | 52 | @Select("select school_name from SZ_School where school_id = #{schoolid}") |
60 | 53 | String getSchoolName(@Param("schoolid") String schoolid); |
61 | 54 | |
... | ... | @@ -264,16 +257,31 @@ public interface UserDao { |
264 | 257 | |
265 | 258 | void updateAuthRecord(@Param("id") Integer authId, @Param("grantState") Integer grantState); |
266 | 259 | |
267 | - StudentBean getStudentCByUserId(@Param("userId") String userId); | |
268 | - | |
269 | - StudentBean getTeacherByUserId(@Param("userId") String userId); | |
270 | - | |
271 | 260 | @Select("select clint_type from SZ_Attendance where clint_id = #{deviceId}") |
272 | 261 | Integer getClintTypeByDeviceId(@Param("deviceId") String deviceId); |
273 | 262 | |
274 | 263 | List<StudentBean> getStudentList(@Param("schoolId") Integer schoolId,@Param("studentType")Integer studentType,@Param("sex") List<Integer> sex); |
275 | 264 | |
265 | + List<StudentBean> getStudentCardGroup(@Param("schoolId") Integer schoolId,@Param("studentType")Integer studentType,@Param("sex") String sex,@Param("groupId")Integer groupId); | |
266 | + | |
276 | 267 | List<StudentBean> getTeacherList(@Param("schoolId") Integer schoolId); |
277 | 268 | |
278 | 269 | List<String> getDeviceIds(@Param("schoolId") Integer schoolId,@Param("deviceId") String deviceId); |
270 | + | |
271 | + void updateUser(@Param("userId") String userId,@Param("face") String face); | |
272 | + | |
273 | + List<String> queryStudentIdList(@Param("schoolId") Integer schoolId,@Param("roomId")Integer roomId); | |
274 | + | |
275 | + @Select(" select top 1* from SZ_V_School_Student where student_id = #{student_id}") | |
276 | + StudentBean getStudentWithid(@Param("student_id") String student_id); | |
277 | + | |
278 | + StudentBean getStudentCByUserId(@Param("userId") String userId,@Param("schoolId") Integer schoolId); | |
279 | + | |
280 | + StudentBean getTeacherByUserId(@Param("userId") String userId,@Param("schoolId") Integer schoolId); | |
281 | + | |
282 | + StudentBean getStudentWithCard(@Param("card") String card,@Param("schoolId") Integer schoolId); | |
283 | + | |
284 | + StudentBean getTeacherWithCard(@Param("teacher_num") String teacher_num,@Param("schoolId") Integer schoolId); | |
285 | + | |
286 | + void insertCard(UpdateCardBean bean); | |
279 | 287 | } | ... | ... |
cloud/haikangface/src/main/java/com/sincere/haikangface/mqtt/MqtUtils.java
cloud/haikangface/src/main/java/com/sincere/haikangface/mqtt/MqttManager.java
... | ... | @@ -23,20 +23,6 @@ public class MqttManager { |
23 | 23 | |
24 | 24 | private static MqttManager mqttManager; |
25 | 25 | |
26 | -// public static MqttManager getInstance(){ | |
27 | -// | |
28 | -// if (null==mqttManager){ | |
29 | -// synchronized (MqttManager.class){ | |
30 | -// if (null==mqttManager) { | |
31 | -// mqttManager = new MqttManager(); | |
32 | -// init(); | |
33 | -// } | |
34 | -// } | |
35 | -// } | |
36 | -// return mqttManager; | |
37 | -// } | |
38 | - | |
39 | - | |
40 | 26 | public void init() { |
41 | 27 | final String brokerUrl = "tcp://post-cn-4590mq2hr03.mqtt.aliyuncs.com:1883"; |
42 | 28 | groupId = "GID_HFJSIURFHAQO110"; |
... | ... | @@ -97,15 +83,6 @@ public class MqttManager { |
97 | 83 | System.out.println("mqtt:" + e.toString()); |
98 | 84 | e.printStackTrace(); |
99 | 85 | } |
100 | - /*while (true){ | |
101 | - sendMessageTest("528C8E6CD4A3C659","zy105387",0); | |
102 | - try { | |
103 | - Thread.sleep(10000); | |
104 | - } catch (InterruptedException e) { | |
105 | - System.out.println("connect success:"+e); | |
106 | - e.printStackTrace(); | |
107 | - } | |
108 | - }*/ | |
109 | 86 | } |
110 | 87 | } |
111 | 88 | ... | ... |
cloud/haikangface/src/main/java/com/sincere/haikangface/service/UserOperateService.java
... | ... | @@ -3,9 +3,8 @@ package com.sincere.haikangface.service; |
3 | 3 | import com.sincere.haikangface.bean.Result; |
4 | 4 | import com.sincere.haikangface.bean.face.AuthRecordDto; |
5 | 5 | import com.sincere.haikangface.bean.face.DeviceAuthRecord; |
6 | -import com.sincere.haikangface.bean.face.PermissionBean; | |
7 | 6 | import com.sincere.haikangface.bean.face.SendFaceDto; |
8 | -import org.apache.ibatis.annotations.Param; | |
7 | +import org.springframework.web.multipart.MultipartFile; | |
9 | 8 | |
10 | 9 | /** |
11 | 10 | * 用户操作业务接口 |
... | ... | @@ -53,20 +52,11 @@ public interface UserOperateService { |
53 | 52 | Result againSendFace(String userId,String deviceId,Integer userType); |
54 | 53 | |
55 | 54 | /** |
56 | - * 批量照片下发 | |
57 | - * @param schoolId | |
58 | - * @param type | |
59 | - * @param deviceIds | |
60 | - * @return | |
61 | - */ | |
62 | - Result sendFace(String schoolId,Integer type,String deviceIds); | |
63 | - | |
64 | - /** | |
65 | 55 | * 多线程照片下发 |
66 | 56 | * @param sendFaceDto |
67 | 57 | * @return |
68 | 58 | */ |
69 | - Result sendUserFaceByThread(SendFaceDto sendFaceDto); | |
59 | + Result sendUserFaceByThread(SendFaceDto sendFaceDto,Integer groupId); | |
70 | 60 | |
71 | 61 | /** |
72 | 62 | * 删除失败表人脸 |
... | ... | @@ -91,6 +81,27 @@ public interface UserOperateService { |
91 | 81 | */ |
92 | 82 | Result deleteFace(Integer schoolId,String cards,String deviceIds); |
93 | 83 | |
94 | - Result deleteFaceTest(Integer schoolId,String deviceIds); | |
84 | + /** | |
85 | + * 下发未下发完的人脸,仅供测试使用 | |
86 | + * @param schoolId | |
87 | + * @param studentType | |
88 | + * @param sex | |
89 | + * @param deviceIds | |
90 | + * @return | |
91 | + */ | |
92 | + Result sendFaceForNoSend(Integer schoolId,Integer studentType,String sex,Integer userType,String deviceIds); | |
93 | + | |
94 | + /** | |
95 | + * 补发单个人脸至指定设备 | |
96 | + * @param file | |
97 | + * @param schoolId | |
98 | + * @param cardNum | |
99 | + * @param userType | |
100 | + * @param deviceIds | |
101 | + * @return | |
102 | + */ | |
103 | + Result againNoSendOneFace(MultipartFile file,Integer schoolId,String cardNum,Integer userType,String deviceIds); | |
104 | + | |
105 | + Result insertUpdateCard(String cardNums); | |
95 | 106 | |
96 | 107 | } | ... | ... |
cloud/haikangface/src/main/java/com/sincere/haikangface/service/impl/BaseService.java
1 | 1 | package com.sincere.haikangface.service.impl; |
2 | 2 | |
3 | 3 | |
4 | -import com.alibaba.fastjson.JSONArray; | |
5 | -import com.alibaba.fastjson.JSONObject; | |
6 | 4 | import com.google.common.util.concurrent.ThreadFactoryBuilder; |
7 | 5 | import com.sincere.haikangface.CMSServer; |
8 | -import com.sincere.haikangface.async.SendFaceBatchTask100; | |
9 | -import com.sincere.haikangface.async.SendFaceBatchTask253; | |
6 | +import com.sincere.haikangface.async.AsyncTask; | |
10 | 7 | import com.sincere.haikangface.async.SendUserAsync; |
11 | -import com.sincere.haikangface.bean.BaiduFaceRecorder; | |
12 | 8 | import com.sincere.haikangface.bean.SendRecordBean; |
13 | 9 | import com.sincere.haikangface.bean.StudentBean; |
14 | -import com.sincere.haikangface.bean.TeacherBean; | |
15 | 10 | import com.sincere.haikangface.dao.UserDao; |
16 | 11 | import com.sincere.haikangface.enums.EnumSzBusinessType; |
17 | -import com.sincere.haikangface.mqtt.MqtUtils; | |
18 | 12 | import com.sincere.haikangface.utils.CompressPic; |
19 | 13 | import com.sincere.haikangface.utils.DateUtils; |
20 | 14 | import com.sincere.haikangface.utils.FileUtils; |
21 | -import com.sincere.haikangface.utils.HttpUtil; | |
22 | 15 | import com.sincere.haikangface.xiananDao.SendRecordDao; |
23 | 16 | import lombok.extern.slf4j.Slf4j; |
24 | 17 | import org.apache.commons.lang3.StringUtils; |
25 | 18 | import org.springframework.beans.factory.annotation.Autowired; |
26 | -import org.springframework.beans.factory.annotation.Value; | |
27 | 19 | import org.springframework.scheduling.annotation.Async; |
28 | 20 | import org.springframework.stereotype.Service; |
29 | 21 | |
... | ... | @@ -51,10 +43,7 @@ public class BaseService { |
51 | 43 | @Autowired |
52 | 44 | SendUserAsync sendUserAsync; |
53 | 45 | |
54 | - @Value("${ipCloud}") | |
55 | - private String ipCloud; | |
56 | - | |
57 | - public boolean sendImg2Device(String filePath, String card, String name, String deviceId, String userType) { | |
46 | + public boolean sendImg2Device(String filePath, String card, String name, String deviceId, String userType,Integer schoolId) { | |
58 | 47 | try { |
59 | 48 | if (new File(filePath.trim()).exists()) { |
60 | 49 | String targetPath = FileUtils.picPathComp + new File(filePath).getName(); |
... | ... | @@ -63,12 +52,14 @@ public class BaseService { |
63 | 52 | } catch (Exception e) { |
64 | 53 | e.printStackTrace(); |
65 | 54 | } |
66 | - StudentBean studentBean = userDao.getStudentWithCard(card); | |
67 | - Integer schoolId = studentBean ==null ?null:studentBean.getSchool_id(); | |
68 | - | |
55 | + StudentBean studentBean = userDao.getStudentWithCard(card,schoolId); | |
56 | + if(studentBean ==null){ | |
57 | + log.error("此卡号未检索到对应学生"); | |
58 | + return false; | |
59 | + } | |
69 | 60 | return sendImg(filePath, targetPath, deviceId, card, name, userType,schoolId); |
70 | 61 | } else { |
71 | - sendFail(Long.parseLong(getCard(card), 16) + "", filePath, deviceId,"文件不存在", userType); | |
62 | + sendFailRecord(Long.parseLong(getCard(card), 16) + "", filePath, deviceId,"文件不存在", userType,schoolId); | |
72 | 63 | System.out.println("文件不存在:" + filePath); |
73 | 64 | } |
74 | 65 | } catch (Exception e) { |
... | ... | @@ -95,13 +86,13 @@ public class BaseService { |
95 | 86 | //下发标识:详情见枚举 EnumHkOperateType |
96 | 87 | int validTimeEnabled = EnumSzBusinessType.EnumHkOperateType.ADD.code; |
97 | 88 | try { |
98 | - FileUtils.getInstance().writeLogs("startTime:" + startTime + "---endTime:" + endTime + "---card:" + card, "下发参数"); | |
89 | + log.info("startTime:" + startTime + "---endTime:" + endTime + "---card:" + card); | |
99 | 90 | if (cmsServer.getIsDeviceOnline(deviceId)) { |
100 | 91 | String cardNo = Long.parseLong(getCard(card),16)+""; |
101 | 92 | //下发海康设备 |
102 | 93 | sendUserAsync.sendStuToHaiKang(filePath,targetPath, cardNo, startTime, endTime, validTimeEnabled, name, deviceId, userType,schoolId,card); |
103 | 94 | }else { |
104 | - sendUserAsync.uploadImgs(targetPath, card, name, deviceId, startTime, endTime, validTimeEnabled, userType); | |
95 | + sendUserAsync.uploadImgs(targetPath, card, name, deviceId, startTime, endTime, validTimeEnabled, userType,schoolId); | |
105 | 96 | } |
106 | 97 | return true; |
107 | 98 | } catch (Exception e) { |
... | ... | @@ -158,15 +149,15 @@ public class BaseService { |
158 | 149 | /** |
159 | 150 | * 保存成功下发记录 |
160 | 151 | */ |
161 | - public synchronized void sendSuccessRecord(String resultCard, String faceUrl, String deviceId,String userType) { | |
152 | + public synchronized void sendSuccessRecord(String resultCard, String faceUrl, String deviceId,String userType,Integer schoolId) { | |
162 | 153 | try{ |
163 | 154 | StudentBean studentBean = null; |
164 | 155 | switch (userType) { |
165 | 156 | case "1"://老师 |
166 | - studentBean = userDao.getTeacherWithCard(resultCard); | |
157 | + studentBean = userDao.getTeacherWithCard(resultCard,schoolId); | |
167 | 158 | break; |
168 | 159 | case "2"://学生 |
169 | - studentBean = userDao.getStudentWithCard(resultCard); | |
160 | + studentBean = userDao.getStudentWithCard(resultCard,schoolId); | |
170 | 161 | break; |
171 | 162 | case "3"://家长 |
172 | 163 | break; |
... | ... | @@ -176,8 +167,6 @@ public class BaseService { |
176 | 167 | String userId = studentBean.getUser_id(); |
177 | 168 | //用户名称 |
178 | 169 | String userName = studentBean.getName(); |
179 | - //所属学校 | |
180 | - int schoolId = studentBean.getSchool_id(); | |
181 | 170 | String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); |
182 | 171 | String schoolName = userDao.getSchoolName(studentBean.getSchool_id() + ""); |
183 | 172 | List<SendRecordBean> sendRecordBeans = sendRecordDao.getRecordIsExit(deviceId,resultCard,userId); |
... | ... | @@ -187,11 +176,10 @@ public class BaseService { |
187 | 176 | } |
188 | 177 | if (null == sendRecordBean) { |
189 | 178 | sendRecordDao.saveFaceRecord(userId, deviceId, resultCard, userName, time, schoolName, |
190 | - faceUrl, schoolId,null,null, Integer.parseInt(userType),18,1); | |
179 | + faceUrl, schoolId,null,null, Integer.parseInt(userType),18,1,null); | |
191 | 180 | } else { |
192 | - sendRecordDao.updateFaceSuccessRecord(deviceId,resultCard,time,faceUrl,userName,userId); | |
181 | + sendRecordDao.updateFaceSuccessRecord(deviceId,resultCard,time,faceUrl,userName,userId,null); | |
193 | 182 | } |
194 | - FileUtils.getInstance().writeLogs(studentBean.toString() + "\r\n" + resultCard, "下发成功记录"); | |
195 | 183 | } else { |
196 | 184 | log.error("用户不存在: 对应卡号{} ," + resultCard); |
197 | 185 | } |
... | ... | @@ -207,15 +195,16 @@ public class BaseService { |
207 | 195 | * @param content |
208 | 196 | * @param userType |
209 | 197 | */ |
210 | - public synchronized void sendFailRecord(String resultCard, String faceUrl, String deviceId,String content,String userType) { | |
198 | + public synchronized void sendFailRecord(String resultCard, String faceUrl, String deviceId,String content,String userType,Integer schoolId) { | |
199 | + log.info("保存失败记录卡号:"+resultCard); | |
211 | 200 | try{ |
212 | 201 | StudentBean studentBean = null; |
213 | 202 | switch (userType) { |
214 | 203 | case "1"://老师 |
215 | - studentBean = userDao.getTeacherWithCard(resultCard); | |
204 | + studentBean = userDao.getTeacherWithCard(resultCard,schoolId); | |
216 | 205 | break; |
217 | 206 | case "2"://学生 |
218 | - studentBean = userDao.getStudentWithCard(resultCard); | |
207 | + studentBean = userDao.getStudentWithCard(resultCard,schoolId); | |
219 | 208 | break; |
220 | 209 | case "3"://家长 |
221 | 210 | break; |
... | ... | @@ -225,8 +214,6 @@ public class BaseService { |
225 | 214 | String userId = studentBean.getUser_id(); |
226 | 215 | //用户名称 |
227 | 216 | String userName = studentBean.getName(); |
228 | - //所属学校 | |
229 | - int schoolId = studentBean.getSchool_id(); | |
230 | 217 | String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); |
231 | 218 | String schoolName = userDao.getSchoolName(studentBean.getSchool_id() + ""); |
232 | 219 | List<SendRecordBean> sendRecordBeans = sendRecordDao.getRecordIsExit(deviceId,resultCard,userId); |
... | ... | @@ -236,7 +223,7 @@ public class BaseService { |
236 | 223 | } |
237 | 224 | if (null == sendRecordBean) { |
238 | 225 | sendRecordDao.saveFaceRecord(userId, deviceId, resultCard, userName, time, schoolName, |
239 | - faceUrl, schoolId, content,9, Integer.parseInt(userType),18,2); | |
226 | + faceUrl, schoolId, content,9, Integer.parseInt(userType),18,2,null); | |
240 | 227 | }else { |
241 | 228 | sendRecordDao.updateFaceFailRecord(deviceId,faceUrl,resultCard,time,content,userId); |
242 | 229 | } |
... | ... | @@ -248,103 +235,6 @@ public class BaseService { |
248 | 235 | } |
249 | 236 | } |
250 | 237 | |
251 | - public synchronized void sendSuccess(String card,String faceUrl,String deviceId,String userType) { | |
252 | -// BigInteger bigInteger = new BigInteger(card); | |
253 | - long lon = Long.parseLong(card); | |
254 | - String resultCard = getCard(String.format("%08x", lon)).toUpperCase(); | |
255 | - StudentBean studentBean = null; | |
256 | - String customerId = ""; | |
257 | - switch (userType) { | |
258 | - case "1"://老师 | |
259 | - studentBean = userDao.getTeacherWithCard(resultCard); | |
260 | - customerId = studentBean.getTeacher_id(); | |
261 | - break; | |
262 | - case "2"://学生 | |
263 | - studentBean = userDao.getStudentWithCard(resultCard); | |
264 | - customerId = studentBean.getStudent_id(); | |
265 | - break; | |
266 | - case "3"://家长 | |
267 | - | |
268 | - break; | |
269 | - } | |
270 | - if (null != studentBean) { | |
271 | - String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); | |
272 | - String schoolName = userDao.getSchoolName(studentBean.getSchool_id() + ""); | |
273 | - List<SendRecordBean> sendRecordBeans = sendRecordDao.getSuccessIsExitStu(deviceId, resultCard); | |
274 | - SendRecordBean sendRecordBean = null; | |
275 | - //处理重复添加的数据 | |
276 | - if (null != sendRecordBeans && sendRecordBeans.size() > 1) { | |
277 | - for (int i = 0; i < sendRecordBeans.size(); i++) { | |
278 | - sendRecordDao.deleteFaceSuccess(sendRecordBeans.get(i).getNum(), sendRecordBeans.get(i).getDeviceID()); | |
279 | - } | |
280 | - } else if (null != sendRecordBeans && sendRecordBeans.size() == 1) { | |
281 | - sendRecordBean = sendRecordBeans.get(0); | |
282 | - } | |
283 | - if (null == sendRecordBean) { | |
284 | - //添加成功日志 | |
285 | - sendRecordDao.addFaceSuccess(customerId, deviceId, resultCard, studentBean.getName(), time, schoolName, | |
286 | - faceUrl, studentBean.getSchool_id(), Integer.parseInt(userType), 18); | |
287 | - } else { | |
288 | - sendRecordDao.updateFaceSuccess(deviceId, resultCard, time, faceUrl, studentBean.getName(), customerId); | |
289 | - } | |
290 | - FileUtils.getInstance().writeLogs(studentBean.toString() + "\r\n" + resultCard, "下发成功记录"); | |
291 | - //删除下发失败表中的数据 | |
292 | - sendRecordDao.deleteFaceFail(resultCard, deviceId); | |
293 | - } else { | |
294 | - log.error("用户不存在: 卡号 {}," + resultCard); | |
295 | - } | |
296 | - } | |
297 | - | |
298 | - /** | |
299 | - * 下发人脸失败 | |
300 | - * | |
301 | - * @param card | |
302 | - * @param faceUrl | |
303 | - * @param deviceId | |
304 | - */ | |
305 | - public synchronized void sendFail(String card, String faceUrl, String deviceId,String content, String userType) { | |
306 | -// BigInteger bigInteger = new BigInteger(card); | |
307 | - long lon = Long.parseLong(card); | |
308 | - String resultCard = getCard(String.format("%08x", lon)).toUpperCase(); | |
309 | - StudentBean studentBean = null; | |
310 | - String customerId = ""; | |
311 | - switch (userType) { | |
312 | - case "1"://老师 | |
313 | - studentBean = userDao.getTeacherWithCard(resultCard); | |
314 | - customerId = studentBean.getTeacher_id(); | |
315 | - break; | |
316 | - case "2"://学生 | |
317 | - studentBean = userDao.getStudentWithCard(resultCard); | |
318 | - customerId = studentBean.getStudent_id(); | |
319 | - break; | |
320 | - case "3"://家长 | |
321 | - break; | |
322 | - } | |
323 | - if (null != studentBean) { | |
324 | - String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); | |
325 | - String schoolName = userDao.getSchoolName(studentBean.getSchool_id() + ""); | |
326 | - List<SendRecordBean> sendRecordBeans = sendRecordDao.getFailIsExit(deviceId, resultCard); | |
327 | - | |
328 | - SendRecordBean sendRecordBean = null; | |
329 | - //处理重复添加的数据 | |
330 | - if (null != sendRecordBeans && sendRecordBeans.size() > 1) { | |
331 | - for (int i = 0; i < sendRecordBeans.size(); i++) { | |
332 | - sendRecordDao.deleteFaceFail(sendRecordBeans.get(i).getNum(), sendRecordBeans.get(i).getDeviceID()); | |
333 | - } | |
334 | - } else if (null != sendRecordBeans && sendRecordBeans.size() == 1) { | |
335 | - sendRecordBean = sendRecordBeans.get(0); | |
336 | - } | |
337 | - if (null == sendRecordBean) { | |
338 | - sendRecordDao.addFaceFail(customerId, deviceId, resultCard, studentBean.getName(), time, schoolName, | |
339 | - faceUrl, studentBean.getSchool_id(), content, 9, Integer.parseInt(userType), 18); | |
340 | - } else { | |
341 | - sendRecordDao.updateFaceFail(deviceId, resultCard, time, content); | |
342 | - } | |
343 | - } else { | |
344 | - log.error("用户不存在: 卡号 {}," + resultCard); | |
345 | - } | |
346 | - } | |
347 | - | |
348 | 238 | /** |
349 | 239 | * 校验卡号 |
350 | 240 | * @param card |
... | ... | @@ -379,153 +269,8 @@ public class BaseService { |
379 | 269 | return dateStr; |
380 | 270 | } |
381 | 271 | |
382 | - //存储抓拍人脸用户信息 | |
383 | - private static Map<String, Long> userMap = new HashMap<>(); | |
384 | - | |
385 | - /** | |
386 | - * 人脸发送看板信息 | |
387 | - * @param file | |
388 | - * @param deviceId | |
389 | - */ | |
390 | - public void sendUserInfoToKB(File file,String deviceId){ | |
391 | - //获取学校ID | |
392 | - String schoolId = userDao.getSchoolIdWithDevId(deviceId); | |
393 | - //请求人脸识别 | |
394 | - JSONObject jsonObject = HttpUtil.sendToKB(file,schoolId); | |
395 | - if(jsonObject ==null){ | |
396 | - log.error("人脸识别失败,返回数据为空"); | |
397 | - return; | |
398 | - } | |
399 | - String face = jsonObject.getString("data"); | |
400 | - if (face.startsWith("face") || face.startsWith("pic")){ | |
401 | - log.error("人脸识别失败"); | |
402 | - return; | |
403 | - } | |
404 | - JSONObject data = jsonObject.getJSONObject("data"); | |
405 | - String errorMsg = data.getString("error_msg"); | |
406 | - //识别成功 | |
407 | - if (errorMsg.equals("SUCCESS")) { | |
408 | - JSONObject result = data.getJSONObject("result"); | |
409 | - //用户信息 | |
410 | - JSONArray userList = result.getJSONArray("user_list"); | |
411 | - if (userList != null && userList.size() > 0) { | |
412 | - for (int i = 0; i < userList.size(); i++) { | |
413 | - JSONObject user = userList.getJSONObject(i); | |
414 | - //用户ID | |
415 | - String userId = user.getString("user_id"); | |
416 | - //比对成功分数值 | |
417 | - String score = user.getString("score"); | |
418 | - double sc = Double.valueOf(score.split("\\.")[0]); | |
419 | - if (sc >= 60) { | |
420 | - TeacherBean teacherBean = userDao.getTeacherWithUserId1(userId); | |
421 | - if (null != teacherBean) { | |
422 | - String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); | |
423 | - teacherBean.setTime(time); | |
424 | - if (StringUtils.isBlank(teacherBean.getTeacer_num())){ | |
425 | - teacherBean.setTeacer_num(userId); | |
426 | - } | |
427 | - //保存百度人脸识别记录 | |
428 | - saveBaiDuFaceRecorder(teacherBean,file,sc,userId); | |
429 | - //同一用户抓拍时间在60秒内,则部不发送看板 | |
430 | - if (userMap.containsKey(userId) && userMap.get(userId)!=null) { | |
431 | - long value = userMap.get(userId); | |
432 | - if ((System.currentTimeMillis() - value) / 1000 > 60) { | |
433 | - userMap.put(userId,System.currentTimeMillis()); | |
434 | - send2DeviceIds(schoolId, teacherBean); | |
435 | - log.info("发送成功....."); | |
436 | - } | |
437 | - } else { | |
438 | - userMap.put(userId, System.currentTimeMillis()); | |
439 | - send2DeviceIds(schoolId, teacherBean); | |
440 | - log.info("发送成功....."); | |
441 | - } | |
442 | - } else { | |
443 | - log.info("用户身份信息不存在"); | |
444 | - sendNoPersonImg(file,schoolId); | |
445 | - } | |
446 | - } else { | |
447 | - log.info("用户身份信息不存在" + score); | |
448 | - sendNoPersonImg(file,schoolId); | |
449 | - } | |
450 | - } | |
451 | - } | |
452 | - } else { | |
453 | - log.error("百度人脸识别失败, 返回信息:{}" + jsonObject.toJSONString()); | |
454 | - } | |
455 | - } | |
456 | - | |
457 | - /** | |
458 | - * 发送平台用户信息至看板设备 | |
459 | - * @param schoolId | |
460 | - * @param teacherBean | |
461 | - */ | |
462 | - private void send2DeviceIds(String schoolId, TeacherBean teacherBean) { | |
463 | - List<String> deviceIds = userDao.getKBDevices(schoolId); | |
464 | - if (deviceIds != null) { | |
465 | - for (int i = 0; i < deviceIds.size(); i++) { | |
466 | - String deviceId = deviceIds.get(i); | |
467 | - if (!StringUtils.isEmpty(deviceId)) { | |
468 | - String content = "{\"cmd\":\"" + 1 + "\",\"clientId\":\"\",\"data\": " + teacherBean.toString() + "}"; | |
469 | - MqtUtils.getInstance().sendMsg(deviceId, content); | |
470 | - } | |
471 | - } | |
472 | - } | |
473 | - } | |
474 | - | |
475 | - /** | |
476 | - * 发送陌生人信息至设备看板 | |
477 | - * @param faceFile | |
478 | - * @param schoolId | |
479 | - */ | |
480 | - private void sendNoPersonImg(File faceFile, String schoolId) { | |
481 | - List<String> deviceIds = userDao.getKBDevices(schoolId); | |
482 | - String imgName = faceFile.getName(); | |
483 | - String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); | |
484 | - if (imgName.contains(date)) { | |
485 | - String imgId = imgName.substring(0, imgName.indexOf(date)); | |
486 | - String api = "/kms/services/rest/dataInfoService/downloadFile?id=" + imgId; | |
487 | - String imgUrl = ipCloud+":8081"+ api; | |
488 | - FileUtils.getInstance().writeLogs("文件名:" + imgUrl, FileUtils.fileNoPerson); | |
489 | - for (int i = 0; i < deviceIds.size(); i++) { | |
490 | - String deviceId = deviceIds.get(i); | |
491 | - if (!org.springframework.util.StringUtils.isEmpty(deviceId)){ | |
492 | - String content = "{\"cmd\":\"" + 2 + "\",\"clientId\":\"\",\"data\": \"" + imgUrl + "\"}"; | |
493 | - MqtUtils.getInstance().sendMsg(deviceId, content); | |
494 | - } | |
495 | - } | |
496 | - } | |
497 | - try { | |
498 | - Thread.sleep(2000); | |
499 | - } catch (InterruptedException e) { | |
500 | - e.printStackTrace(); | |
501 | - } | |
502 | - } | |
503 | - | |
504 | - private void saveBaiDuFaceRecorder(TeacherBean teacherBean,File faceFile,double score,String userId){ | |
505 | - String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); | |
506 | - BaiduFaceRecorder baiduFaceRecorder = new BaiduFaceRecorder(); | |
507 | - baiduFaceRecorder.setUserId(userId); | |
508 | - baiduFaceRecorder.setName(teacherBean.getName()); | |
509 | - baiduFaceRecorder.setScore(score + ""); | |
510 | - baiduFaceRecorder.setTime(teacherBean.getTime()); | |
511 | - baiduFaceRecorder.setUserImgUrl(teacherBean.getFace()); | |
512 | - String uploadImgUrl = ""; | |
513 | - if(faceFile.getAbsolutePath().contains(date)){ | |
514 | - //抓拍照片ID | |
515 | - String imgId = faceFile.getName().substring(0,faceFile.getName().indexOf(date)); | |
516 | - String api = "/kms/services/rest/dataInfoService/downloadFile?id=" +imgId; | |
517 | - uploadImgUrl = ipCloud+ api; | |
518 | - }else { | |
519 | - uploadImgUrl = faceFile.getAbsolutePath(); | |
520 | - } | |
521 | - baiduFaceRecorder.setUploadImgUrl(uploadImgUrl); | |
522 | - | |
523 | - //插入百度人脸记录表 | |
524 | - userDao.insertBaiduFaceRecorder(baiduFaceRecorder); | |
525 | - } | |
526 | - | |
527 | 272 | @Async |
528 | - public void sendUserFaceByAsyncThread(Integer schoolId,Integer userType,Integer studentType,String sex,List<String> deviceList){ | |
273 | + public void sendUserFaceByAsyncThread(Integer schoolId,Integer userType,List<StudentBean> studentBeanList,List<String> deviceList){ | |
529 | 274 | List<String> deviceId_100 = new ArrayList<>(); |
530 | 275 | List<String> deviceId_253 = new ArrayList<>(); |
531 | 276 | //过滤设备 |
... | ... | @@ -537,46 +282,19 @@ public class BaseService { |
537 | 282 | deviceId_253.add(sno); |
538 | 283 | } |
539 | 284 | } |
540 | - //根据类型获取下发用户信息 | |
541 | - List<StudentBean> studentBeanList = null; | |
542 | - if (userType == EnumSzBusinessType.EnumUserType.TEACHER.code) { | |
543 | - studentBeanList = getTeacherList(schoolId); | |
544 | - } | |
545 | - if (userType == EnumSzBusinessType.EnumUserType.STUDENT.code) { | |
546 | - studentBeanList = getStudentList(schoolId,studentType,sex); | |
547 | - } | |
548 | - log.info("统计共有下发用户数量:"+studentBeanList.size()); | |
549 | 285 | if(deviceId_100.size()>0){ |
550 | 286 | //100服务器 |
551 | - sendFaceToDevice100(deviceId_100,studentBeanList,String.valueOf(schoolId),userType); | |
287 | + sendFaceToDevice100(deviceId_100,studentBeanList,schoolId,userType); | |
552 | 288 | } |
553 | 289 | if(deviceId_253.size()>0){ |
554 | 290 | //253服务器 |
555 | - sendFaceToDevice253(deviceId_253,studentBeanList,String.valueOf(schoolId),userType); | |
291 | + sendFaceToDevice253(deviceId_253,studentBeanList,schoolId,userType); | |
556 | 292 | } |
557 | 293 | } |
558 | 294 | |
559 | 295 | |
560 | - protected void sendFaceToDevice100(List<String> deviceIds,List<StudentBean> studentBeanList,String schoolId,Integer userType){ | |
296 | + protected void sendFaceToDevice100(List<String> deviceIds,List<StudentBean> studentBeanList,Integer schoolId,Integer userType){ | |
561 | 297 | log.info("------------------------开始执行100服务,人脸照下发---------------------"); |
562 | -// //启用多线程执行 | |
563 | -// CountDownLatch begin = new CountDownLatch(1); | |
564 | -// CountDownLatch end = new CountDownLatch(deviceIds.size()); | |
565 | -// ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("thread-sendFace-runner-%d").build(); | |
566 | -// ExecutorService exe = new ThreadPoolExecutor(4,8,0L, TimeUnit.MILLISECONDS,new LinkedBlockingQueue<Runnable>(),namedThreadFactory); | |
567 | -// for(String sno : deviceIds){ | |
568 | -// log.info("设备ID:"+ sno); | |
569 | -// exe.execute(new SendFaceBatchTask100(schoolId,userType,sno,studentBeanList,FileUtils.getInstance(),sendUserAsync,begin,end)); | |
570 | -// } | |
571 | -// begin.countDown(); | |
572 | -// try { | |
573 | -// end.await(); | |
574 | -// }catch (Exception e){ | |
575 | -// log.error("下发人脸照失败"+e); | |
576 | -// e.printStackTrace(); | |
577 | -// } | |
578 | -// exe.shutdown(); | |
579 | -// System.out.println("统计100服务器总共有"+deviceIds.size()+"个设备,处理完毕"); | |
580 | 298 | String startTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); |
581 | 299 | Calendar calendar = Calendar.getInstance(); |
582 | 300 | calendar.add(Calendar.YEAR, 10); |
... | ... | @@ -592,17 +310,26 @@ public class BaseService { |
592 | 310 | if (StringUtils.isBlank(photo) || StringUtils.isBlank(cardNum)){ |
593 | 311 | continue; |
594 | 312 | } |
595 | -// String path = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\" + typeName; | |
596 | - String path = "D:\\haikangface\\School" + schoolId + "\\" + typeName; | |
313 | + String[] fileNameStr = photo.split(typeName +"/"); | |
314 | + if(fileNameStr.length==0){ | |
315 | + continue; | |
316 | + } | |
317 | + //以学籍号为名的文件名 | |
318 | + String fileName = fileNameStr[1]; | |
319 | + //100服务器人脸照绝对路径 | |
320 | + String path_1 = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\" + typeName; | |
321 | + String path_2 = "E:\\wwwhtdocs\\SmartCampus\\face17e5\\School" + schoolId + "\\" + typeName; | |
322 | + String path_3 = "E:\\wwwhtdocs\\SmartCampus\\f0i5l7e5\\"; | |
597 | 323 | String filePath=""; |
598 | 324 | if(photo.indexOf("f0i5l7e5")!=-1){ |
599 | 325 | String afterStr = photo.split("f0i5l7e5/")[1].replace("/","\\"); |
600 | - filePath="E:\\wwwhtdocs\\SmartCampus\\f0i5l7e5\\" + afterStr; | |
601 | - } else{ | |
602 | - //以学籍号为名的文件名 | |
603 | - String fileName = photo.split(typeName +"/")[1]; | |
604 | - //100服务器上人脸照绝对路径 | |
605 | - filePath = path+ "\\" + fileName; | |
326 | + filePath= path_3 + afterStr; | |
327 | + } | |
328 | + if(photo.indexOf("face17e5")!=-1){ | |
329 | + filePath = path_2 + "\\" + fileName; | |
330 | + } | |
331 | + if(photo.indexOf("face17e50")!=-1){ | |
332 | + filePath = path_1 + "\\" + fileName; | |
606 | 333 | } |
607 | 334 | log.info("卡号:{},人脸路径:{}, ",cardNum,filePath); |
608 | 335 | File file = new File(filePath);//图片 |
... | ... | @@ -611,8 +338,7 @@ public class BaseService { |
611 | 338 | try { |
612 | 339 | CompressPic.CompressPic(file.getAbsolutePath(), targetPath); |
613 | 340 | } catch (Exception e) { |
614 | - log.error("压缩图片失败"); | |
615 | - e.printStackTrace(); | |
341 | + log.error("压缩图片失败:",e); | |
616 | 342 | continue; |
617 | 343 | } |
618 | 344 | for(String sno : deviceIds){ |
... | ... | @@ -620,42 +346,23 @@ public class BaseService { |
620 | 346 | if(!StringUtils.isBlank(cardNum)){ |
621 | 347 | String cardNumLong = Long.parseLong(getCard(cardNum),16) + ""; |
622 | 348 | //下发100海康设备 |
623 | - sendUserAsync.sendStuToHaiKang(file.getAbsolutePath(),targetPath,cardNumLong, startTime, endTime, validTimeEnabled, userName, sno, String.valueOf(userType),Integer.parseInt(schoolId),cardNum); | |
349 | + sendUserAsync.sendStuToHaiKang(file.getAbsolutePath(),targetPath,cardNumLong, startTime, endTime, validTimeEnabled, userName, sno, String.valueOf(userType),schoolId,cardNum); | |
624 | 350 | } |
625 | 351 | }else{ |
626 | 352 | log.error("100服务器,设备不在线"); |
627 | 353 | } |
628 | - | |
629 | 354 | } |
630 | 355 | } |
631 | 356 | }catch (Exception e){ |
632 | - log.error("人脸下发失败"); | |
633 | - e.printStackTrace(); | |
357 | + log.error("人脸下发失败,异常信息:",e); | |
634 | 358 | continue; |
635 | 359 | } |
636 | 360 | } |
637 | 361 | } |
638 | 362 | |
639 | - protected void sendFaceToDevice253(List<String> deviceIds,List<StudentBean> studentBeanList,String schoolId,Integer userType){ | |
363 | + protected void sendFaceToDevice253(List<String> deviceIds,List<StudentBean> studentBeanList,Integer schoolId,Integer userType){ | |
640 | 364 | log.info("------------------------开始执行253服务,人脸照下发---------------------"); |
641 | -// //启用多线程执行 | |
642 | -// CountDownLatch begin = new CountDownLatch(1); | |
643 | -// CountDownLatch end = new CountDownLatch(deviceIds.size()); | |
644 | -// ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("thread-sendFace-runner-%d").build(); | |
645 | -// ExecutorService exe = new ThreadPoolExecutor(8,8,0L, TimeUnit.MILLISECONDS,new LinkedBlockingQueue<Runnable>(),namedThreadFactory); | |
646 | -// for(String sno : deviceIds){ | |
647 | -// log.info("设备ID:"+ sno); | |
648 | -// exe.execute(new SendFaceBatchTask253(schoolId,userType,sno,studentBeanList,sendUserAsync,begin,end)); | |
649 | -// } | |
650 | -// begin.countDown(); | |
651 | -// try { | |
652 | -// end.await(); | |
653 | -// }catch (Exception e){ | |
654 | -// log.error("下发人脸照失败"+e); | |
655 | -// e.printStackTrace(); | |
656 | -// } | |
657 | -// exe.shutdown(); | |
658 | -// System.out.println("统计253服务器总共有"+deviceIds.size()+"个设备,处理完毕"); | |
365 | + | |
659 | 366 | String startTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); |
660 | 367 | Calendar calendar = Calendar.getInstance(); |
661 | 368 | calendar.add(Calendar.YEAR, 10); |
... | ... | @@ -671,21 +378,41 @@ public class BaseService { |
671 | 378 | if (StringUtils.isBlank(photo) || StringUtils.isBlank(cardNum)){ |
672 | 379 | continue; |
673 | 380 | } |
674 | - String path = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\" + typeName; | |
381 | + String[] fileNameStr = photo.split(typeName +"/"); | |
382 | + if(fileNameStr.length==0){ | |
383 | + continue; | |
384 | + } | |
385 | + //以学籍号为名的文件名 | |
386 | + String fileName = fileNameStr[1]; | |
387 | + //100服务器人脸照绝对路径 | |
388 | + String path_1 = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\" + typeName; | |
389 | + String path_2 = "E:\\wwwhtdocs\\SmartCampus\\face17e5\\School" + schoolId + "\\" + typeName; | |
390 | + String path_3 = "E:\\wwwhtdocs\\SmartCampus\\f0i5l7e5\\"; | |
675 | 391 | String filePath=""; |
676 | 392 | if(photo.indexOf("f0i5l7e5")!=-1){ |
677 | 393 | String afterStr = photo.split("f0i5l7e5/")[1].replace("/","\\"); |
678 | - filePath="E:\\wwwhtdocs\\SmartCampus\\f0i5l7e5\\" + afterStr; | |
679 | - } else{ | |
680 | - //以学籍号为名的文件名 | |
681 | - String fileName = photo.split(typeName +"/")[1]; | |
682 | - //100服务器上人脸照绝对路径 | |
683 | - filePath = path+ "\\" + fileName; | |
394 | + filePath= path_3 + afterStr; | |
395 | + } | |
396 | + if(photo.indexOf("face17e5")!=-1){ | |
397 | + filePath = path_2 + "\\" + fileName; | |
398 | + } | |
399 | + if(photo.indexOf("face17e50")!=-1){ | |
400 | + filePath = path_1 + "\\" + fileName; | |
684 | 401 | } |
685 | 402 | log.info("卡号:{},人脸路径:{}, ",cardNum,filePath); |
686 | - for(String sno : deviceIds) { | |
687 | - //下发253服务器 | |
688 | - sendUserAsync.uploadImgs(filePath, cardNum, userName, sno, startTime, endTime, validTimeEnabled, String.valueOf(userType)); | |
403 | + File file = new File(filePath);//图片 | |
404 | + if(file.exists()) { | |
405 | + String targetPath = FileUtils.picPathComp + file.getName(); | |
406 | + try { | |
407 | + CompressPic.CompressPic(file.getAbsolutePath(), targetPath); | |
408 | + } catch (Exception e) { | |
409 | + log.error("压缩图片失败:", e); | |
410 | + continue; | |
411 | + } | |
412 | + for (String sno : deviceIds) { | |
413 | + //下发253服务器 | |
414 | + sendUserAsync.uploadImgs(targetPath,cardNum, userName, sno, startTime, endTime, validTimeEnabled, String.valueOf(userType),schoolId); | |
415 | + } | |
689 | 416 | } |
690 | 417 | }catch (Exception e){ |
691 | 418 | log.error("人脸下发失败"); |
... | ... | @@ -728,6 +455,21 @@ public class BaseService { |
728 | 455 | } |
729 | 456 | |
730 | 457 | /** |
458 | + * 获取学校下学生数据 | |
459 | + * @param schoolId | |
460 | + * @param studentType | |
461 | + * @param sex | |
462 | + * @return | |
463 | + */ | |
464 | + public List<StudentBean> getStudentListByGroup(Integer schoolId, Integer studentType,String sex,Integer groupId) { | |
465 | + List<StudentBean> students = userDao.getStudentCardGroup(schoolId,studentType,sex,groupId); | |
466 | + //去重重复数据 | |
467 | + List<StudentBean> studentList = students.stream().collect(Collectors.collectingAndThen( | |
468 | + Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(StudentBean::getStudent_num))), ArrayList::new)); | |
469 | + return studentList; | |
470 | + } | |
471 | + | |
472 | + /** | |
731 | 473 | * 获取学校下老师数据 |
732 | 474 | * @param schoolId |
733 | 475 | * @return |
... | ... | @@ -739,4 +481,31 @@ public class BaseService { |
739 | 481 | Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(StudentBean::getTeacher_num))), ArrayList::new)); |
740 | 482 | return teacherist; |
741 | 483 | } |
484 | + | |
485 | + | |
486 | + public void getSuccessList(Integer schoolId,String deviceIds) { | |
487 | + //下发设备集合 | |
488 | + String[] deviceArr = deviceIds.split(","); | |
489 | + List<String> deviceList= new ArrayList<>(Arrays.asList(deviceArr)); | |
490 | + if(deviceList.size()<1){ | |
491 | + return; | |
492 | + } | |
493 | + //启用多线程执行 | |
494 | + CountDownLatch begin = new CountDownLatch(1); | |
495 | + CountDownLatch end = new CountDownLatch(deviceList.size()); | |
496 | + ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("thread-sendFace-runner-%d").build(); | |
497 | + ExecutorService exe = new ThreadPoolExecutor(8,16,0L, TimeUnit.MILLISECONDS,new LinkedBlockingQueue<Runnable>(),namedThreadFactory); | |
498 | + for(String sno : deviceList){ | |
499 | + exe.execute(new AsyncTask(userDao,sendRecordDao,schoolId,sno,begin,end)); | |
500 | + } | |
501 | + begin.countDown(); | |
502 | + try { | |
503 | + end.await(); | |
504 | + }catch (Exception e){ | |
505 | + log.error("迁移人脸照失败"+e); | |
506 | + e.printStackTrace(); | |
507 | + } | |
508 | + exe.shutdown(); | |
509 | + System.out.println("统计100服务器总共有"+deviceList.size()+"个设备,处理完毕"); | |
510 | + } | |
742 | 511 | } | ... | ... |
cloud/haikangface/src/main/java/com/sincere/haikangface/service/impl/UserOperateServiceImpl.java
... | ... | @@ -4,12 +4,8 @@ import com.alibaba.fastjson.JSON; |
4 | 4 | import com.fasterxml.jackson.databind.JavaType; |
5 | 5 | import com.sincere.haikangface.CMSServer; |
6 | 6 | import com.sincere.haikangface.async.SendUserAsync; |
7 | -import com.sincere.haikangface.bean.Result; | |
8 | -import com.sincere.haikangface.bean.ResultGenerator; | |
9 | -import com.sincere.haikangface.bean.SendRecordBean; | |
10 | -import com.sincere.haikangface.bean.StudentBean; | |
7 | +import com.sincere.haikangface.bean.*; | |
11 | 8 | import com.sincere.haikangface.bean.face.*; |
12 | -import com.sincere.haikangface.control.UserControl; | |
13 | 9 | import com.sincere.haikangface.dao.DeviceDao; |
14 | 10 | import com.sincere.haikangface.dao.UserDao; |
15 | 11 | import com.sincere.haikangface.enums.EnumSzBusinessType; |
... | ... | @@ -17,14 +13,16 @@ import com.sincere.haikangface.service.UserOperateService; |
17 | 13 | import com.sincere.haikangface.utils.*; |
18 | 14 | import com.sincere.haikangface.xiananDao.SendRecordDao; |
19 | 15 | import lombok.extern.slf4j.Slf4j; |
16 | +import org.apache.commons.collections4.CollectionUtils; | |
20 | 17 | import org.apache.commons.lang3.StringUtils; |
21 | 18 | import org.springframework.beans.factory.annotation.Autowired; |
22 | 19 | import org.springframework.scheduling.annotation.Async; |
23 | 20 | import org.springframework.stereotype.Service; |
21 | +import org.springframework.web.multipart.MultipartFile; | |
24 | 22 | |
25 | 23 | import java.io.File; |
24 | +import java.io.FileOutputStream; | |
26 | 25 | import java.io.IOException; |
27 | -import java.text.SimpleDateFormat; | |
28 | 26 | import java.util.*; |
29 | 27 | |
30 | 28 | /** |
... | ... | @@ -48,8 +46,6 @@ public class UserOperateServiceImpl implements UserOperateService { |
48 | 46 | BaseService baseService; |
49 | 47 | @Autowired |
50 | 48 | SendUserAsync sendUserAsync; |
51 | - @Autowired | |
52 | - UserControl userControl; | |
53 | 49 | |
54 | 50 | private static JsonUtils objectMapper = JsonUtils.nonEmptyMapper(); |
55 | 51 | |
... | ... | @@ -106,7 +102,7 @@ public class UserOperateServiceImpl implements UserOperateService { |
106 | 102 | if(deviceType.intValue()== 22 || deviceType.intValue()== 29){ |
107 | 103 | Integer shiduan = userDao.getAuthRecordBySchoolId(schoolId,studentType,null); |
108 | 104 | //如果是大华一体机 |
109 | - record.setShiduan(shiduan!=null?shiduan+1+"":1+""); | |
105 | + record.setShiduan(shiduan!=null?String.valueOf(shiduan+1):String.valueOf(1)); | |
110 | 106 | }else{ |
111 | 107 | //时段 |
112 | 108 | record.setShiduan(null); |
... | ... | @@ -147,20 +143,6 @@ public class UserOperateServiceImpl implements UserOperateService { |
147 | 143 | ArrayList<WeekDay> weekDayList = objectMapper.fromJson(weekDaysJson,javaType); |
148 | 144 | //设备类型 |
149 | 145 | Integer clintType = userDao.getClintTypeByDeviceId(devices.get(0)); |
150 | - if(clintType.intValue()== 22 || clintType.intValue()== 29){ | |
151 | - PermissionDHBean dhBean = new PermissionDHBean(); | |
152 | - dhBean.setWeekDays(weekDayList); | |
153 | - dhBean.setDeviceIds(devices); | |
154 | - dhBean.setChannel(record.getShiduan()); | |
155 | - dhBean.setCustomName(EnumSzBusinessType.EnumStudentType.getByCode(studentType).code+""); | |
156 | - dhBean.setStudentType(String.valueOf(studentType)); | |
157 | - //发送大华设备 | |
158 | - HttpUtil.sendDHPermission(dhBean); | |
159 | - log.info("map{}", JSON.toJSONString(dhBean)); | |
160 | - //更新计划位下发成功 | |
161 | - userDao.updateAuthRecord(record.getId(),1); | |
162 | - return ResultGenerator.genSuccessResult(); | |
163 | - } | |
164 | 146 | if(clintType.intValue()== 18 || clintType.intValue()== 28){ |
165 | 147 | PermissionBean permissionBean = new PermissionBean(); |
166 | 148 | permissionBean.setWeekDays(weekDayList); |
... | ... | @@ -175,6 +157,20 @@ public class UserOperateServiceImpl implements UserOperateService { |
175 | 157 | } |
176 | 158 | } |
177 | 159 | } |
160 | + if(clintType.intValue()== 22 || clintType.intValue()== 29){ | |
161 | + PermissionDHBean dhBean = new PermissionDHBean(); | |
162 | + dhBean.setWeekDays(weekDayList); | |
163 | + dhBean.setDeviceIds(devices); | |
164 | + dhBean.setChannel(record.getShiduan()); | |
165 | + dhBean.setCustomName(EnumSzBusinessType.EnumStudentType.getByCode(studentType).code+""); | |
166 | + dhBean.setStudentType(String.valueOf(studentType)); | |
167 | + //发送大华设备 | |
168 | + HttpUtil.sendDHPermission(dhBean); | |
169 | + log.info("权限计划详情{}", JSON.toJSONString(dhBean)); | |
170 | + //更新计划位下发成功 | |
171 | + userDao.updateAuthRecord(record.getId(),1); | |
172 | + return ResultGenerator.genSuccessResult(); | |
173 | + } | |
178 | 174 | return ResultGenerator.genSuccessResult(); |
179 | 175 | } |
180 | 176 | |
... | ... | @@ -194,13 +190,13 @@ public class UserOperateServiceImpl implements UserOperateService { |
194 | 190 | String cardNum =""; |
195 | 191 | String photo =""; |
196 | 192 | String studentCode = ""; |
197 | - if(userType.intValue() ==1 ){ | |
198 | - studentBean = userDao.getTeacherByUserId(userId); | |
193 | + if(userType.intValue() ==1){ | |
194 | + studentBean = userDao.getTeacherByUserId(userId,null); | |
199 | 195 | cardNum = studentBean.getTeacher_num(); |
200 | 196 | photo = studentBean.getFace(); |
201 | 197 | studentCode = studentBean.getNum(); |
202 | 198 | }else{ |
203 | - studentBean = userDao.getStudentCByUserId(userId); | |
199 | + studentBean = userDao.getStudentCByUserId(userId,null); | |
204 | 200 | cardNum = studentBean.getStudent_num(); |
205 | 201 | photo = studentBean.getPhoto(); |
206 | 202 | studentCode = studentBean.getStudentCode(); |
... | ... | @@ -211,21 +207,45 @@ public class UserOperateServiceImpl implements UserOperateService { |
211 | 207 | } |
212 | 208 | Integer schoolId = studentBean.getSchool_id(); |
213 | 209 | String userName = studentBean.getName(); |
214 | - //2.重新下发 | |
215 | 210 | String typeName = userType.intValue() ==1 ? "Teacher" : "Student"; |
216 | - String path = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\" + typeName; | |
211 | + String[] fileNameStr =photo.split(typeName +"/"); | |
212 | + if(fileNameStr.length==0){ | |
213 | + log.error("文件名为空,文件路径 :"+ photo); | |
214 | + return ResultGenerator.genSuccessResult("文件名为空"); | |
215 | + } | |
217 | 216 | //以学籍号为名的文件名 |
218 | - String fileName = photo.split(typeName+"/")[1]; | |
219 | - //100服务器上人脸照绝对路径 | |
220 | - String filePath = path+ "\\" + fileName; | |
217 | + String fileName = fileNameStr[1]; | |
218 | + //100服务器人脸照绝对路径 | |
219 | + String path_1 = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\" + typeName; | |
220 | + String path_2 = "E:\\wwwhtdocs\\SmartCampus\\face17e5\\School" + schoolId + "\\" + typeName; | |
221 | + String path_3 = "E:\\wwwhtdocs\\SmartCampus\\f0i5l7e5\\"; | |
222 | + String filePath=""; | |
223 | + if(photo.indexOf("f0i5l7e5")!=-1){ | |
224 | + String afterStr = photo.split("f0i5l7e5/")[1].replace("/","\\"); | |
225 | + filePath= path_3 + afterStr; | |
226 | + } | |
227 | + if(photo.indexOf("face17e5")!=-1){ | |
228 | + filePath = path_2 + "\\" + fileName; | |
229 | + } | |
230 | + if(photo.indexOf("face17e50")!=-1){ | |
231 | + filePath = path_1 + "\\" + fileName; | |
232 | + } | |
233 | + log.info("卡号:{},人脸路径:{}, ",cardNum,filePath); | |
221 | 234 | //校验100服务上是否存在此人脸 |
222 | - File file = new File(filePath.trim()); | |
235 | + File file = new File(filePath.trim());//图片 | |
223 | 236 | if (!file.exists()) { |
224 | 237 | log.error("文件不存在:" + filePath); |
225 | -// String card = Long.parseLong(baseService.getCard(cardNum), 16)+""; | |
226 | - baseService.sendFailRecord(cardNum, filePath, deviceId, "文件不存在", String.valueOf(userType)); | |
238 | + baseService.sendFailRecord(cardNum, filePath, deviceId, "文件不存在", String.valueOf(userType),schoolId); | |
227 | 239 | return ResultGenerator.genFailResult("文件不存在"); |
228 | 240 | } |
241 | + String targetPath = FileUtils.picPathComp + file.getName(); | |
242 | + if(file.exists()) { | |
243 | + try { | |
244 | + CompressPic.CompressPic(file.getAbsolutePath(), targetPath); | |
245 | + } catch (Exception e) { | |
246 | + log.error("压缩图片失败:",e); | |
247 | + } | |
248 | + } | |
229 | 249 | //设备类型 |
230 | 250 | Integer clintType = userDao.getClintTypeByDeviceId(deviceId); |
231 | 251 | if(clintType.intValue()== 18 || clintType.intValue()== 28){ |
... | ... | @@ -237,12 +257,7 @@ public class UserOperateServiceImpl implements UserOperateService { |
237 | 257 | //不在线,去253服务器上删除 |
238 | 258 | HttpUtil.deleteCard(deviceId, cardNum); |
239 | 259 | } |
240 | - String targetPath = FileUtils.picPathComp + file.getName(); | |
241 | - try { | |
242 | - CompressPic.CompressPic(file.getAbsolutePath(), targetPath); | |
243 | - } catch (Exception e) { | |
244 | - log.error("图片压缩失败"); | |
245 | - } | |
260 | + //2.重新下发 | |
246 | 261 | boolean isOk = baseService.sendImg(file.getAbsolutePath(), targetPath, deviceId, cardNum, userName, String.valueOf(userType), schoolId); |
247 | 262 | if (isOk) { |
248 | 263 | return ResultGenerator.genSuccessResult(); |
... | ... | @@ -252,6 +267,7 @@ public class UserOperateServiceImpl implements UserOperateService { |
252 | 267 | } |
253 | 268 | //下大华人脸 |
254 | 269 | if(clintType.intValue()== 22 || clintType.intValue()== 29){ |
270 | + //下发单个人脸至大华设备 | |
255 | 271 | HttpUtil.uploadDHImgForOne(filePath,schoolId,studentCode,clintType,deviceId); |
256 | 272 | return ResultGenerator.genSuccessResult(); |
257 | 273 | } |
... | ... | @@ -259,61 +275,7 @@ public class UserOperateServiceImpl implements UserOperateService { |
259 | 275 | } |
260 | 276 | |
261 | 277 | @Override |
262 | - public Result sendFace(String schoolId,Integer type,String deviceIds) { | |
263 | - try { | |
264 | - String filePathStudent = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\Student"; | |
265 | - String filePathParent = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\Parent"; | |
266 | - String filePathTeacher = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\Teacher"; | |
267 | - File filePaths = null; | |
268 | - int userType = 0; | |
269 | - if (type == 0) {//主卡下发 | |
270 | - filePaths = new File(filePathStudent); | |
271 | - userType = 2; | |
272 | - } else if (type == 1) {//副卡下发 | |
273 | - filePaths = new File(filePathParent); | |
274 | - userType = 2; | |
275 | - } else if (type == 2) {//教师卡下发 | |
276 | - filePaths = new File(filePathTeacher); | |
277 | - userType = 1; | |
278 | - } | |
279 | - File[] filesStudent = filePaths.listFiles(); | |
280 | - if (filesStudent == null) { | |
281 | - log.warn("目录:{},没有找到人脸图片,",filePaths.getAbsolutePath()); | |
282 | - return ResultGenerator.genFailResult("没有找到人脸图片"); | |
283 | - } | |
284 | - if(StringUtils.isBlank(deviceIds)){ | |
285 | - log.warn("未选择下发设备"); | |
286 | - return ResultGenerator.genFailResult("未选择下发设备"); | |
287 | - } | |
288 | - String[] deviceArr = deviceIds.split(","); | |
289 | - List<String> idLists= new ArrayList<>(Arrays.asList(deviceArr)); | |
290 | - //设备类型 | |
291 | - Integer clintType = userDao.getClintTypeByDeviceId(idLists.get(0)); | |
292 | - if(clintType.intValue()== 22 || clintType.intValue()== 29){ | |
293 | - HttpUtil.uploadDHImg(schoolId,userType,deviceIds); | |
294 | - } | |
295 | - if(clintType.intValue()== 18 || clintType.intValue()== 28){ | |
296 | - HttpUtil.uploadHkImg(schoolId,userType,deviceIds); | |
297 | - } | |
298 | - int fileSize = filesStudent.length; | |
299 | - int clintNum = deviceArr.length; | |
300 | - //下发所用时长 | |
301 | - int timeLength = new Double(clintNum * fileSize * 0.06).intValue(); | |
302 | - //下发截止时间 | |
303 | - String dateStr = baseService.getTime(fileSize,clintNum,timeLength); | |
304 | - Map map = new HashMap(); | |
305 | - map.put("timeLength",timeLength); | |
306 | - map.put("afterDate",dateStr); | |
307 | - map.put("fileSize",fileSize); | |
308 | - return ResultGenerator.genSuccessResult(objectMapper.toJson(map)); | |
309 | - } catch (Exception e) { | |
310 | - log.error("下发失败,错误信息",e); | |
311 | - return ResultGenerator.genFailResult("下发失败"); | |
312 | - } | |
313 | - } | |
314 | - | |
315 | - @Override | |
316 | - public Result sendUserFaceByThread(SendFaceDto sendFaceDto) { | |
278 | + public Result sendUserFaceByThread(SendFaceDto sendFaceDto,Integer groupId) { | |
317 | 279 | //下发设备集合 |
318 | 280 | String[] deviceArr = sendFaceDto.getsNos().split(","); |
319 | 281 | List<String> deviceList= new ArrayList<>(Arrays.asList(deviceArr)); |
... | ... | @@ -329,17 +291,39 @@ public class UserOperateServiceImpl implements UserOperateService { |
329 | 291 | }else{ |
330 | 292 | userType = 1; |
331 | 293 | } |
294 | + //根据类型获取下发用户信息 | |
295 | + List<StudentBean> studentBeanList = null; | |
296 | + if (userType == EnumSzBusinessType.EnumUserType.TEACHER.code) { | |
297 | + studentBeanList = baseService.getTeacherList(schoolId); | |
298 | + } | |
299 | + if (userType == EnumSzBusinessType.EnumUserType.STUDENT.code && groupId ==null) { | |
300 | + studentBeanList = baseService.getStudentList(schoolId,studentType,sex); | |
301 | + }else if(userType == EnumSzBusinessType.EnumUserType.STUDENT.code && groupId !=null){ | |
302 | + sex = sex.split(",")[0]; | |
303 | + studentBeanList = baseService.getStudentListByGroup(schoolId,studentType,sex,groupId); | |
304 | + } | |
305 | + log.info("统计共有下发用户数量:{}",studentBeanList.size()); | |
332 | 306 | //设备类型 |
333 | 307 | Integer clintType = userDao.getClintTypeByDeviceId(deviceList.get(0)); |
334 | 308 | if(clintType.intValue()== 22 || clintType.intValue()== 29){ |
335 | 309 | //发送大华设备 |
336 | - HttpUtil.uploadDHImg(String.valueOf(schoolId),userType,sendFaceDto.getsNos()); | |
310 | + HttpUtil.uploadDHImg(String.valueOf(schoolId),userType,sendFaceDto.getsNos(),studentType,sex); | |
337 | 311 | } |
338 | 312 | if(clintType.intValue()== 18 || clintType.intValue()== 28){ |
339 | - //发送海康设备 | |
340 | - baseService.sendUserFaceByAsyncThread(schoolId,userType,studentType,sex,deviceList); | |
313 | + //发送海康设备:异步执行 | |
314 | + baseService.sendUserFaceByAsyncThread(schoolId,userType,studentBeanList,deviceList); | |
341 | 315 | } |
342 | - return ResultGenerator.genSuccessResult(); | |
316 | + int fileSize = studentBeanList.size(); | |
317 | + int clintNum = deviceList.size(); | |
318 | + //下发所用时长 | |
319 | + int timeLength = new Double(clintNum * fileSize * 0.06).intValue(); | |
320 | + //下发截止时间 | |
321 | + String dateStr = baseService.getTime(fileSize,clintNum,timeLength); | |
322 | + Map map = new HashMap(); | |
323 | + map.put("timeLength",timeLength); | |
324 | + map.put("afterDate",dateStr); | |
325 | + map.put("fileSize",fileSize); | |
326 | + return ResultGenerator.genSuccessResult(objectMapper.toJson(map)); | |
343 | 327 | } |
344 | 328 | |
345 | 329 | @Override |
... | ... | @@ -370,6 +354,9 @@ public class UserOperateServiceImpl implements UserOperateService { |
370 | 354 | if(clintType.intValue()== 22 || clintType.intValue()== 29){ |
371 | 355 | HttpUtil.deleteDHFace(schoolId,cardNum,deviceId); |
372 | 356 | } |
357 | + //删除成功记录 | |
358 | + sendRecordDao.deleteUserFaceSuccess(schoolId,cardNum,deviceId); | |
359 | + sendRecordDao.deleteRecord(schoolId,deviceId,cardNum); | |
373 | 360 | }catch (Exception e){ |
374 | 361 | log.error("删除失败人脸失败,异常信息:{}",e); |
375 | 362 | continue; |
... | ... | @@ -398,16 +385,20 @@ public class UserOperateServiceImpl implements UserOperateService { |
398 | 385 | //2.重新下发 |
399 | 386 | StudentBean studentBean= null; |
400 | 387 | String typeName =""; |
388 | + String photo = ""; | |
401 | 389 | if(userType ==1){ |
402 | 390 | typeName= "Teacher"; |
403 | - studentBean = userDao.getTeacherWithCard(cardNum); | |
391 | + studentBean = userDao.getTeacherWithCard(cardNum,schoolId); | |
392 | + photo=studentBean.getFace(); | |
404 | 393 | }else{ |
405 | 394 | typeName= "Student"; |
406 | - studentBean= userDao.getStudentWithCard(cardNum); | |
395 | + studentBean= userDao.getStudentWithCard(cardNum,schoolId); | |
396 | + photo=studentBean.getPhoto(); | |
407 | 397 | } |
408 | - if(studentBean==null){ | |
398 | + if(studentBean==null|| StringUtils.isBlank(photo)){ | |
409 | 399 | continue; |
410 | 400 | } |
401 | + String userName= studentBean.getName(); | |
411 | 402 | String studentCode = studentBean.getStudentCode(); |
412 | 403 | String filePath=""; |
413 | 404 | //下发海康人脸 |
... | ... | @@ -420,32 +411,40 @@ public class UserOperateServiceImpl implements UserOperateService { |
420 | 411 | //不在线,去253服务器上删除 |
421 | 412 | HttpUtil.deleteCard(deviceId, cardNum); |
422 | 413 | } |
423 | - //100服务器文件目录绝对路径 | |
424 | - String path = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\" + typeName; | |
425 | - String photo= userType==1?studentBean.getFace():studentBean.getPhoto(); | |
426 | - if (StringUtils.isBlank(photo)){ | |
414 | + String[] fileNameStr = photo.split(typeName +"/"); | |
415 | + if(fileNameStr.length==0){ | |
427 | 416 | continue; |
428 | 417 | } |
418 | + //以学籍号为名的文件名 | |
419 | + String fileName = fileNameStr[1]; | |
420 | + //100服务器人脸照绝对路径 | |
421 | + String path_1 = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\" + typeName; | |
422 | + String path_2 = "E:\\wwwhtdocs\\SmartCampus\\face17e5\\School" + schoolId + "\\" + typeName; | |
423 | + String path_3 = "E:\\wwwhtdocs\\SmartCampus\\f0i5l7e5\\"; | |
429 | 424 | if(photo.indexOf("f0i5l7e5")!=-1){ |
430 | 425 | String afterStr = photo.split("f0i5l7e5/")[1].replace("/","\\"); |
431 | - filePath="E:\\wwwhtdocs\\SmartCampus\\f0i5l7e5\\" + afterStr; | |
432 | - } else{ | |
433 | - //以学籍号为名的文件名 | |
434 | - String fileName = photo.split(typeName +"/")[1]; | |
435 | - //100服务器上人脸照绝对路径 | |
436 | - filePath = path+ "\\" + fileName; | |
426 | + filePath= path_3 + afterStr; | |
427 | + } | |
428 | + if(photo.indexOf("face17e5")!=-1){ | |
429 | + filePath = path_2 + "\\" + fileName; | |
430 | + } | |
431 | + if(photo.indexOf("face17e50")!=-1){ | |
432 | + filePath = path_1 + "\\" + fileName; | |
437 | 433 | } |
438 | - log.info("卡号:{},人脸路径:{}, ",cardNum, filePath); | |
434 | + log.info("卡号:{},人脸路径:{}, ",cardNum,filePath); | |
439 | 435 | File file = new File(filePath);//图片 |
440 | - String targetPath = FileUtils.picPathComp + file.getName(); | |
441 | - try { | |
442 | - CompressPic.CompressPic(file.getAbsolutePath(), targetPath); | |
443 | - } catch (IOException e) { | |
444 | - log.error("图片压缩失败",e); | |
445 | - continue; | |
436 | + if(file.exists()){ | |
437 | + String targetPath = FileUtils.picPathComp + file.getName(); | |
438 | + try { | |
439 | + CompressPic.CompressPic(file.getAbsolutePath(), targetPath); | |
440 | + } catch (Exception e) { | |
441 | + log.error("压缩图片失败:",e); | |
442 | + continue; | |
443 | + } | |
444 | + if(!StringUtils.isBlank(cardNum)) { | |
445 | + baseService.sendImg(file.getAbsolutePath(), targetPath, deviceId, cardNum, userName, String.valueOf(userType), schoolId); | |
446 | + } | |
446 | 447 | } |
447 | - String userName= studentBean.getName(); | |
448 | - baseService.sendImg(file.getAbsolutePath(), targetPath, deviceId, cardNum, userName, String.valueOf(userType), schoolId); | |
449 | 448 | } |
450 | 449 | //下发大华人脸 |
451 | 450 | if(clintType.intValue()== 22 || clintType.intValue()== 29){ |
... | ... | @@ -463,121 +462,158 @@ public class UserOperateServiceImpl implements UserOperateService { |
463 | 462 | @Override |
464 | 463 | public Result deleteFace(Integer schoolId,String cards,String deviceIds) { |
465 | 464 | if(StringUtils.isBlank(cards)){ |
466 | - return ResultGenerator.genFailResult("删除人脸卡号"); | |
465 | + return ResultGenerator.genFailResult("删除人脸卡号为空"); | |
466 | + } | |
467 | + List<String> deviceList = new ArrayList<>(); | |
468 | + if(StringUtils.isBlank(deviceIds)){ | |
469 | + List<String> clintList = userDao.getDeviceIds(schoolId,null); | |
470 | + if(CollectionUtils.isNotEmpty(clintList)){ | |
471 | + deviceList.addAll(clintList); | |
472 | + } | |
473 | + }else{ | |
474 | + //设备集合 | |
475 | + String[] deviceArr = deviceIds.split(","); | |
476 | + deviceList= new ArrayList<>(Arrays.asList(deviceArr)); | |
467 | 477 | } |
468 | 478 | String[] cardArr = cards.split(","); |
469 | - List<String> cardList= new ArrayList<>(Arrays.asList(cardArr)); | |
479 | + List<String> cardList = new ArrayList<>(Arrays.asList(cardArr)); | |
470 | 480 | for(String card : cardList){ |
471 | - if(StringUtils.isNotBlank(deviceIds)){ | |
472 | - //设备集合 | |
473 | - String[] deviceArr = deviceIds.split(","); | |
474 | - List<String> deviceList= new ArrayList<>(Arrays.asList(deviceArr)); | |
475 | - for(String sno : deviceList){ | |
476 | - try{ | |
481 | + //未指定设备,删除学校下所有 | |
482 | + if(CollectionUtils.isNotEmpty(deviceList)) { | |
483 | + for (String sno : deviceList) { | |
484 | + try { | |
477 | 485 | //设备类型 |
478 | 486 | Integer clintType = userDao.getClintTypeByDeviceId(sno); |
479 | - if(clintType.intValue()== 18 || clintType.intValue()== 28){ | |
487 | + if (clintType.intValue() == 18 || clintType.intValue() == 28) { | |
480 | 488 | //删除海康设备人脸 |
481 | 489 | if (cmsServer.getIsDeviceOnline(sno)) { |
482 | - String cardNo = Long.parseLong(baseService.getCard(card),16) + ""; | |
483 | - cmsServer.deleteCard(sno, cardNo,schoolId); | |
484 | - }else{ | |
490 | + String cardNo = Long.parseLong(baseService.getCard(card), 16) + ""; | |
491 | + cmsServer.deleteCard(sno, cardNo, schoolId); | |
492 | + } else { | |
485 | 493 | HttpUtil.deleteCard(sno, card); |
486 | 494 | } |
487 | 495 | } |
488 | - if(clintType.intValue()== 22 || clintType.intValue()== 29){ | |
496 | + if (clintType.intValue() == 22 || clintType.intValue() == 29) { | |
489 | 497 | //删除大华设备人脸 |
490 | - HttpUtil.deleteDHFace(schoolId,card,sno); | |
498 | + HttpUtil.deleteDHFace(schoolId, card, sno); | |
491 | 499 | } |
492 | - }catch (Exception e){ | |
493 | - log.error("删除人脸失败,异常信息:{}",e); | |
500 | + //删除成功记录 | |
501 | + sendRecordDao.deleteUserFaceSuccess(schoolId,card,sno); | |
502 | + sendRecordDao.deleteRecord(schoolId,sno,card); | |
503 | + } catch (Exception e) { | |
504 | + log.error("删除人脸失败,异常信息:{}", e); | |
494 | 505 | continue; |
495 | 506 | } |
496 | 507 | } |
497 | - }else{ | |
498 | - List<String> clintIds = userDao.getDeviceIds(schoolId,null); | |
499 | - if(clintIds.size()>0){ | |
500 | - for(String sno : clintIds){ | |
501 | - try{ | |
502 | - //设备类型 | |
503 | - Integer clintType = userDao.getClintTypeByDeviceId(sno); | |
504 | - if(clintType.intValue()== 18 || clintType.intValue()== 28){ | |
505 | - //删除海康设备人脸 | |
506 | - if (cmsServer.getIsDeviceOnline(sno)) { | |
507 | - String cardNo = Long.parseLong(baseService.getCard(card),16) + ""; | |
508 | - cmsServer.deleteCard(sno, cardNo,schoolId); | |
509 | - }else{ | |
510 | - HttpUtil.deleteCard(sno, card); | |
511 | - } | |
512 | - } | |
513 | - if(clintType.intValue()== 22 || clintType.intValue()== 29){ | |
514 | - //删除大华设备人脸 | |
515 | - HttpUtil.deleteDHFace(schoolId,card,sno); | |
516 | - } | |
517 | - }catch (Exception e){ | |
518 | - log.error("删除人脸失败,异常信息:{}",e); | |
519 | - continue; | |
520 | - } | |
521 | - } | |
522 | - } | |
523 | 508 | } |
524 | 509 | } |
525 | 510 | return ResultGenerator.genSuccessResult(); |
526 | 511 | } |
527 | 512 | |
528 | 513 | @Override |
529 | - public Result deleteFaceTest(Integer schoolId, String deviceIds) { | |
530 | - List<StudentBean> list = baseService.getStudentList(schoolId,null,""); | |
514 | + public Result sendFaceForNoSend(Integer schoolId,Integer studentType,String sex,Integer userType,String deviceIds) { | |
515 | + //若未传下发,则下发该学校下所有设备 | |
516 | + //下发设备集合 | |
517 | + List<String> idLists = null; | |
531 | 518 | if(StringUtils.isBlank(deviceIds)){ |
532 | - log.warn("未选择下发设备"); | |
533 | - return ResultGenerator.genFailResult("未选择下发设备"); | |
519 | + idLists = userDao.getDeviceIds(schoolId,null); | |
520 | + }else{ | |
521 | + String[] deviceArr = deviceIds.split(","); | |
522 | + idLists= new ArrayList<>(Arrays.asList(deviceArr)); | |
534 | 523 | } |
535 | - String[] deviceArr = deviceIds.split(","); | |
536 | - List<String> idLists= new ArrayList<>(Arrays.asList(deviceArr)); | |
537 | - for(StudentBean studentBean : list){ | |
538 | - for(String sno : idLists){ | |
539 | - List<SendRecordBean> bean = sendRecordDao.getRecordIsExit(sno,studentBean.getStudent_num(),studentBean.getUser_id()); | |
540 | - if(bean.size()>0){ | |
541 | - continue; | |
542 | - } | |
524 | + //下发用户集合 | |
525 | + List<StudentBean> list = null; | |
526 | + if(userType.intValue() ==2){ | |
527 | + list = baseService.getStudentList(schoolId,studentType,sex); | |
528 | + } | |
529 | + if(userType.intValue()==1){ | |
530 | + list = baseService.getTeacherList(schoolId); | |
531 | + } | |
532 | + if(StringUtils.isBlank(deviceIds)){ | |
533 | + log.warn("该学校下未查询到下发设备"); | |
534 | + return ResultGenerator.genFailResult("该学校下未查询到下发设备"); | |
535 | + } | |
536 | + //异步执行下发 | |
537 | + sendFaceForNoSend(schoolId,userType,list,idLists); | |
538 | + int fileSize = list.size(); | |
539 | + int clintNum = idLists.size(); | |
540 | + //下发所用时长 | |
541 | + int timeLength = new Double(clintNum * fileSize * 0.06).intValue(); | |
542 | + //下发截止时间 | |
543 | + String dateStr = baseService.getTime(fileSize,clintNum,timeLength); | |
544 | + Map map = new HashMap(); | |
545 | + map.put("timeLength",timeLength); | |
546 | + map.put("afterDate",dateStr); | |
547 | + map.put("fileSize",fileSize); | |
548 | + return ResultGenerator.genSuccessResult(objectMapper.toJson(map)); | |
549 | + } | |
550 | + | |
551 | + | |
552 | + @Async | |
553 | + protected void sendFaceForNoSend(Integer schoolId,Integer userType,List<StudentBean> studentList,List<String> deviceIds){ | |
554 | + log.info("统计共有:"+studentList.size()+"张卡,"+deviceIds.size()+"台设备." ); | |
555 | + for(StudentBean studentBean : studentList){ | |
556 | + for(String sno : deviceIds){ | |
543 | 557 | try{ |
544 | - String userName= studentBean.getName(); | |
545 | - String photo = studentBean.getPhoto(); | |
546 | - String cardNum =studentBean.getStudent_num(); | |
547 | - String typeName="Student"; | |
558 | + //卡号 | |
559 | + String cardNum = userType.intValue()==1?studentBean.getTeacher_num():studentBean.getStudent_num(); | |
560 | + //人脸照 | |
561 | + String photo = userType.intValue()==1?studentBean.getFace():studentBean.getPhoto(); | |
548 | 562 | if (StringUtils.isBlank(photo) || StringUtils.isBlank(cardNum)){ |
549 | 563 | continue; |
550 | 564 | } |
551 | - String path = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\" + typeName; | |
565 | + String userName= studentBean.getName(); | |
566 | + String userId = studentBean.getUser_id(); | |
567 | + String studentCode = studentBean.getStudentCode(); | |
568 | + List<SendRecordBean> bean = sendRecordDao.getRecordIsExit(sno,cardNum,userId); | |
569 | + if(CollectionUtils.isNotEmpty(bean)){ | |
570 | + continue; | |
571 | + } | |
572 | + String typeName= userType.intValue()==1?"Teacher":"Student"; | |
573 | + String[] fileNameStr = photo.split(typeName +"/"); | |
574 | + if(fileNameStr.length==0){ | |
575 | + continue; | |
576 | + } | |
577 | + //以学籍号为名的文件名 | |
578 | + String fileName = fileNameStr[1]; | |
579 | + //100服务器人脸照绝对路径 | |
580 | + String path_1 = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\" + typeName; | |
581 | + String path_2 = "E:\\wwwhtdocs\\SmartCampus\\face17e5\\School" + schoolId + "\\" + typeName; | |
582 | + String path_3 = "E:\\wwwhtdocs\\SmartCampus\\f0i5l7e5\\"; | |
552 | 583 | String filePath=""; |
553 | 584 | if(photo.indexOf("f0i5l7e5")!=-1){ |
554 | 585 | String afterStr = photo.split("f0i5l7e5/")[1].replace("/","\\"); |
555 | - filePath="E:\\wwwhtdocs\\SmartCampus\\f0i5l7e5\\" + afterStr; | |
556 | - } else{ | |
557 | - //以学籍号为名的文件名 | |
558 | - String fileName = photo.split(typeName +"/")[1]; | |
559 | - //100服务器上人脸照绝对路径 | |
560 | - filePath = path+ "\\" + fileName; | |
586 | + filePath= path_3 + afterStr; | |
587 | + } | |
588 | + if(photo.indexOf("face17e5")!=-1){ | |
589 | + filePath = path_2 + "\\" + fileName; | |
561 | 590 | } |
562 | - log.info("卡号:{},人脸路径:{}, ",cardNum,filePath); | |
591 | + if(photo.indexOf("face17e50")!=-1){ | |
592 | + filePath = path_1 + "\\" + fileName; | |
593 | + } | |
594 | + if(filePath.indexOf("?v=")!=-1){ | |
595 | + filePath = filePath.split("\\?")[0]; | |
596 | + } | |
597 | + log.info("卡号:{},人脸路径:{}",cardNum,filePath); | |
563 | 598 | File file = new File(filePath);//图片 |
564 | 599 | if(file.exists()){ |
565 | 600 | String targetPath = FileUtils.picPathComp + file.getName(); |
566 | 601 | try { |
567 | 602 | CompressPic.CompressPic(file.getAbsolutePath(), targetPath); |
568 | 603 | } catch (Exception e) { |
569 | - log.error("压缩图片失败"); | |
570 | - e.printStackTrace(); | |
604 | + log.error("压缩图片失败:",e); | |
571 | 605 | continue; |
572 | 606 | } |
573 | - String startTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); | |
574 | - Calendar calendar = Calendar.getInstance(); | |
575 | - calendar.add(Calendar.YEAR, 10); | |
576 | - String endTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime()); | |
577 | - if(!cmsServer.getIsDeviceOnline(sno)){ | |
578 | - if(!StringUtils.isBlank(cardNum)){ | |
579 | - //下发253服务器 | |
580 | - sendUserAsync.uploadImgs(targetPath, cardNum, userName, sno, startTime, endTime, 1, "2"); | |
607 | + if(!StringUtils.isBlank(cardNum)) { | |
608 | + //设备类型 | |
609 | + Integer clintType = userDao.getClintTypeByDeviceId(sno); | |
610 | + if(clintType.intValue()== 18 || clintType.intValue()== 28){ | |
611 | + baseService.sendImg(file.getAbsolutePath(), targetPath, sno, cardNum, userName, String.valueOf(userType), schoolId); | |
612 | + } | |
613 | + //下大华人脸 | |
614 | + if(clintType.intValue()== 22 || clintType.intValue()== 29){ | |
615 | + //下发单个人脸至大华设备 | |
616 | + HttpUtil.uploadDHImgForOne(filePath,schoolId,studentCode,clintType,sno); | |
581 | 617 | } |
582 | 618 | } |
583 | 619 | } |
... | ... | @@ -588,6 +624,120 @@ public class UserOperateServiceImpl implements UserOperateService { |
588 | 624 | } |
589 | 625 | } |
590 | 626 | } |
627 | + } | |
628 | + | |
629 | + public static void main(String[] args) { | |
630 | + String s = "E:\\wwwhtdocs\\SmartCampus\\face17e5\\School386\\Student\\sxzx2020467.png?v=1601037209723"; | |
631 | + if(s.indexOf("?v=")!=-1){ | |
632 | + System.out.println(1); | |
633 | + String fileName = s.split("\\?")[0]; | |
634 | + System.out.println(fileName); | |
635 | + } | |
636 | + } | |
637 | + | |
638 | + @Override | |
639 | + public Result againNoSendOneFace(MultipartFile file, Integer schoolId, String cardNum, Integer userType, String deviceIds) { | |
640 | + if(StringUtils.isBlank(cardNum)){ | |
641 | + return ResultGenerator.genFailResult("卡号为空"); | |
642 | + } | |
643 | + if(StringUtils.isBlank(deviceIds)){ | |
644 | + return ResultGenerator.genFailResult("未指定下发设备"); | |
645 | + } | |
646 | + StudentBean studentBean=null; | |
647 | + if(userType.intValue()==2){ | |
648 | + studentBean= userDao.getStudentWithCard(cardNum,schoolId); | |
649 | + }else{ | |
650 | + studentBean= userDao.getTeacherWithCard(cardNum,schoolId); | |
651 | + } | |
652 | + if(studentBean ==null){ | |
653 | + return ResultGenerator.genFailResult("此卡号未查询到对应学生/老师信息"); | |
654 | + } | |
655 | + String userName = studentBean.getName(); | |
656 | + String studentCode = userType.intValue()==1?studentBean.getNum():studentBean.getStudentCode(); | |
657 | + String typeName = userType.intValue()==1?"Teacher":"Student"; | |
658 | + //100服务器人脸照绝对路径 | |
659 | + String path = "E:\\wwwhtdocs\\SmartCampus\\face17e5\\School" + schoolId + "\\" + typeName; | |
660 | + if(!new File(path).exists()){ | |
661 | + new File(path).mkdirs(); | |
662 | + } | |
663 | + //以学籍号为名的文件名 | |
664 | + String fileName = studentCode + ".png"; | |
665 | + //人脸文件路径 | |
666 | + String facePath = path + "\\" +fileName; | |
667 | + log.info("卡号:{}, 人脸路径:{}, ",cardNum,facePath); | |
668 | + try { | |
669 | + File absolutePath = new File(facePath); | |
670 | + FileOutputStream fileOutputStream = new FileOutputStream(absolutePath); | |
671 | + fileOutputStream.write(file.getBytes()); | |
672 | + fileOutputStream.close(); | |
673 | + }catch (IOException e){ | |
674 | + log.error("文件处理异常: ",e); | |
675 | + } | |
676 | +// //在线活体检测 | |
677 | +// String result = HttpUtil.checkFace(facePath); | |
678 | +// if(StringUtils.isBlank(result) || result.equals("false")){ | |
679 | +// log.error("人脸检测不合格!"); | |
680 | +// return ResultGenerator.genFailResult("请添加规范的人脸照片."); | |
681 | +// } | |
682 | + String targetPath = FileUtils.picPathComp + file.getName(); | |
683 | + try { | |
684 | + CompressPic.CompressPic(new File(facePath).getAbsolutePath(), targetPath); | |
685 | + } catch (Exception e) { | |
686 | + log.error("压缩图片失败: ",e); | |
687 | + } | |
688 | + String[] deviceArr = deviceIds.split(","); | |
689 | + List<String> deviceList= new ArrayList<>(Arrays.asList(deviceArr)); | |
690 | + if(CollectionUtils.isNotEmpty(deviceList)){ | |
691 | + for(String deviceId : deviceList) { | |
692 | + //获取设备类型 | |
693 | + Integer clintType = userDao.getClintTypeByDeviceId(deviceId); | |
694 | + if (clintType.intValue() == 18 || clintType.intValue() == 28) { | |
695 | + baseService.sendImg(facePath, targetPath, deviceId, cardNum, userName, String.valueOf(userType), schoolId); | |
696 | + } | |
697 | + //下发大华人脸 | |
698 | + if (clintType.intValue() == 22 || clintType.intValue() == 29) { | |
699 | + HttpUtil.uploadDHImgForOne(facePath, schoolId, studentCode, clintType, deviceId); | |
700 | + } | |
701 | + } | |
702 | + } | |
703 | + //下发完成更新表中人脸路径 | |
704 | + String savePath = "http://campus.myjxt.com//face17e5/School"+ schoolId + "/" + typeName + "/" + fileName; | |
705 | + userDao.updateUser(studentBean.getUser_id(),savePath); | |
591 | 706 | return ResultGenerator.genSuccessResult(); |
592 | 707 | } |
708 | + | |
709 | + @Override | |
710 | + public Result insertUpdateCard(String cardNums) { | |
711 | + String[] cardArr = cardNums.split(","); | |
712 | + List<String> cardList = new ArrayList<>(Arrays.asList(cardArr)); | |
713 | + if(CollectionUtils.isNotEmpty(cardList)) { | |
714 | + for (String card : cardList) { | |
715 | + StudentBean studentBean = userDao.getStudentWithCard(card,null); | |
716 | + if(studentBean ==null){ | |
717 | + log.error("慧校园中此卡号不存在"); | |
718 | + continue; | |
719 | + } | |
720 | + UpdateCardBean bean = new UpdateCardBean(); | |
721 | + bean.setAddTime(new Date()); | |
722 | + bean.setCard(studentBean.getStudent_num()); | |
723 | + bean.setClassId(studentBean.getClass_id()); | |
724 | + bean.setClassName(studentBean.getClass_name()); | |
725 | + bean.setCustomerId(studentBean.getStudent_id()); | |
726 | + bean.setFace(studentBean.getFace()); | |
727 | + bean.setIsNew(1); | |
728 | + bean.setMobile(studentBean.getParentMobile()); | |
729 | + bean.setName(studentBean.getName()); | |
730 | + bean.setSchoolId(studentBean.getSchool_id()); | |
731 | + bean.setSex(studentBean.getSex()); | |
732 | + bean.setUserType(studentBean.getUserType()); | |
733 | + bean.setUserId(studentBean.getUser_id()); | |
734 | + bean.setStudentType(studentBean.getStudent_type()); | |
735 | + bean.setStudentCode(studentBean.getStudentCode()); | |
736 | + bean.setOldCard(studentBean.getOldCard()); | |
737 | + bean.setUpdateType(1); | |
738 | + userDao.insertCard(bean); | |
739 | + } | |
740 | + } | |
741 | + return new Result(); | |
742 | + } | |
593 | 743 | } | ... | ... |
cloud/haikangface/src/main/java/com/sincere/haikangface/utils/AlarmUtils.java
1 | 1 | package com.sincere.haikangface.utils; |
2 | 2 | |
3 | +import com.sincere.haikangface.bean.AttendanceBean; | |
3 | 4 | import com.sincere.haikangface.bean.BaiduFaceRecorder; |
4 | 5 | import com.sincere.haikangface.bean.FaceWaterRecoder; |
5 | 6 | import com.sincere.haikangface.dao.DeviceDao; |
... | ... | @@ -101,6 +102,7 @@ public class AlarmUtils { |
101 | 102 | currTemperature = currTemperature.replace("currTemperature>", ""); |
102 | 103 | currTemperature = currTemperature.replace("</", ""); |
103 | 104 | } |
105 | + saveAttendance(deviceID); | |
104 | 106 | switch (majirType) { |
105 | 107 | case "0x1"://报警 |
106 | 108 | baojing(minorType, deviceID, time); |
... | ... | @@ -136,20 +138,20 @@ public class AlarmUtils { |
136 | 138 | break; |
137 | 139 | case "0x07"://无效时段 |
138 | 140 | content = "无效时段"; |
139 | - log.info("卡号:{}, {}",cardNo,content); | |
141 | + log.info("卡号:{}, {}", cardNo, content); | |
140 | 142 | break; |
141 | 143 | case "0x8"://卡号过期 |
142 | 144 | content = "卡号过期"; |
143 | - log.info("卡号:{}, {}",cardNo,content); | |
145 | + log.info("卡号:{}, {}", cardNo, content); | |
144 | 146 | break; |
145 | 147 | case "0x9"://无此卡号 |
146 | 148 | content = "无此卡号"; |
147 | - log.info("卡号:{}, {}",cardNo,content); | |
149 | + log.info("卡号:{}, {}", cardNo, content); | |
148 | 150 | break; |
149 | 151 | case "0x4b"://人脸认证通过 |
150 | 152 | if (!StringUtils.isEmpty(picDataUrl) && picDataUrl.split("id=").length > 1) { |
151 | 153 | String picDataUrlId = picDataUrl.split("id=")[1]; |
152 | - FileUtils.getInstance().writeLogs("0x4bdeviceID:" + deviceID + " cardNo:" + cardNo + " time:" + time + " picDataUrlId:" + picDataUrlId, FileUtils.faceSuccess); | |
154 | + log.info("事件类型:0x4b deviceID:" + deviceID + " cardNo:" + cardNo + " time:" + time + " picDataUrlId:" + picDataUrlId); | |
153 | 155 | content = "人脸认证通过"; |
154 | 156 | if (null != alarmCallBack) |
155 | 157 | alarmCallBack.callBack(minorType, deviceID, cardNo, time, picDataUrlId, currTemperature); |
... | ... | @@ -157,32 +159,32 @@ public class AlarmUtils { |
157 | 159 | break; |
158 | 160 | case "0x4c"://人脸认证失败 |
159 | 161 | content = "人脸认证失败"; |
160 | - log.info("卡号:{}, {}",cardNo,content); | |
162 | + log.info("卡号:{}, {}", cardNo, content); | |
161 | 163 | break; |
162 | 164 | case "0x50"://人脸不存在 |
163 | 165 | content = "人脸不存在"; |
164 | - log.info("卡号:{}, {}",cardNo,content); | |
166 | + log.info("卡号:{}, {}", cardNo, content); | |
165 | 167 | break; |
166 | 168 | case "0x68"://真人检测失败 |
167 | 169 | content = "真人检测失败"; |
168 | - log.info("卡号:{}, {}",cardNo,content); | |
170 | + log.info("卡号:{}, {}", cardNo, content); | |
169 | 171 | break; |
170 | 172 | case "0x69"://人证比对通过 |
171 | 173 | if (!StringUtils.isEmpty(picDataUrl) && picDataUrl.split("id=").length > 1) { |
172 | 174 | String picDataUrlId = picDataUrl.split("id=")[1]; |
173 | - FileUtils.getInstance().writeLogs("0x69deviceID:" + deviceID + " cardNo:" + cardNo + " time:" + time + " picDataUrlId:" + picDataUrlId, FileUtils.faceSuccess); | |
175 | + log.info("事件类型:0x69 deviceID:" + deviceID + " cardNo:" + cardNo + " time:" + time + " picDataUrlId:" + picDataUrlId); | |
174 | 176 | content = "人脸认证通过"; |
175 | 177 | if (null != alarmCallBack) |
176 | 178 | alarmCallBack.callBack(minorType, deviceID, cardNo, time, picDataUrlId, currTemperature); |
177 | 179 | } |
178 | 180 | break; |
179 | 181 | case "0x70"://认证比对失败 |
180 | - FileUtils.getInstance().writeLogs("deviceID:" + deviceID + " cardNo:" + cardNo + " time:" + time, FileUtils.faceFail); | |
182 | + log.info("deviceID:" + deviceID + " cardNo:" + cardNo + " time:" + time); | |
181 | 183 | break; |
182 | 184 | case "0x6": |
183 | 185 | if (!StringUtils.isEmpty(picDataUrl) && picDataUrl.split("id=").length > 1) { |
184 | 186 | String picDataUrlId = picDataUrl.split("id=")[1]; |
185 | - FileUtils.getInstance().writeLogs("0x69deviceID:" + deviceID + " cardNo:" + cardNo + " time:" + time + " picDataUrlId:" + picDataUrlId, FileUtils.faceSuccess); | |
187 | + log.info("事件类型: 0x6 deviceID:" + deviceID + " cardNo:" + cardNo + " time:" + time + " picDataUrlId:" + picDataUrlId); | |
186 | 188 | content = "人脸认证通过"; |
187 | 189 | if (null != alarmCallBack) |
188 | 190 | alarmCallBack.callBack(minorType, deviceID, cardNo, time, picDataUrlId, currTemperature); |
... | ... | @@ -242,11 +244,11 @@ public class AlarmUtils { |
242 | 244 | switch (minorType) { |
243 | 245 | case "0x3a"://网络断开 |
244 | 246 | content = "网络断开"; |
245 | - FileUtils.getInstance().writeLogs("网络断开:"+deviceID,"设备网络.txt"); | |
247 | + log.info("网络断开:"+deviceID); | |
246 | 248 | break; |
247 | 249 | case "0x400"://设备上电启动 |
248 | 250 | content = "设备上电启动"; |
249 | - FileUtils.getInstance().writeLogs("设备上电启动:"+deviceID,"设备网络.txt"); | |
251 | + log.info("设备上电启动:"+deviceID); | |
250 | 252 | break; |
251 | 253 | case "0x401"://设备掉电关闭 |
252 | 254 | content = "设备掉电关闭"; |
... | ... | @@ -266,7 +268,7 @@ public class AlarmUtils { |
266 | 268 | case "0x407"://网络恢复 |
267 | 269 | content = "网络恢复"; |
268 | 270 | if (null != alarmCallBack) alarmCallBack.callBack(minorType, deviceID, "", time, "", ""); |
269 | - FileUtils.getInstance().writeLogs("网络恢复:"+deviceID,"设备网络.txt"); | |
271 | + log.info("网络恢复:"+deviceID,"设备网络.txt"); | |
270 | 272 | break; |
271 | 273 | case "0x421"://摄像头未连接 |
272 | 274 | content = "摄像头未连接"; |
... | ... | @@ -275,14 +277,14 @@ public class AlarmUtils { |
275 | 277 | content = "摄像头连接恢复"; |
276 | 278 | break; |
277 | 279 | case "0x426"://人证设备在线 |
278 | - FileUtils.getInstance().writeLogs("人证设备在线:"+deviceID,"设备网络.txt"); | |
280 | + log.info("人证设备在线:"+deviceID,"设备网络.txt"); | |
279 | 281 | content = "人证设备在线"; |
280 | 282 | if (null != alarmCallBack) alarmCallBack.callBack(minorType, deviceID, "", time, "", ""); |
281 | 283 | break; |
282 | 284 | case "0x427"://人证设备离线 |
283 | 285 | content = "人证设备离线"; |
284 | 286 | if (null != alarmCallBack) alarmCallBack.callBack(minorType, deviceID, "", time, "", ""); |
285 | - FileUtils.getInstance().writeLogs("人证设备离线:"+deviceID,"设备网络.txt"); | |
287 | + log.info("人证设备离线:"+deviceID,"设备网络.txt"); | |
286 | 288 | break; |
287 | 289 | } |
288 | 290 | saveWater(content, minorType, deviceID, "", time, "0x02"); |
... | ... | @@ -334,4 +336,25 @@ public class AlarmUtils { |
334 | 336 | faceWaterRecoder.getContent(), faceWaterRecoder.getMajorType(), faceWaterRecoder.getTime(), faceWaterRecoder.getCardNo(), faceWaterRecoder.getSystime()); |
335 | 337 | } |
336 | 338 | |
339 | + | |
340 | + private void saveAttendance(String deviceId){ | |
341 | + String inTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); | |
342 | + AttendanceBean attendanceBean = new AttendanceBean(); | |
343 | + attendanceBean.setClint_id(deviceId); | |
344 | + if (deviceId.startsWith("ytj")) | |
345 | + attendanceBean.setClint_type("28"); | |
346 | + else | |
347 | + attendanceBean.setClint_type("18"); | |
348 | + attendanceBean.setIntime(inTime); | |
349 | + attendanceBean.setIsConnection(1); | |
350 | + attendanceBean.setSchool_id("-1"); | |
351 | + attendanceBean.setState(1); | |
352 | + if (deviceDao.selectDevice(deviceId) != null) { | |
353 | + deviceDao.updateDeviceStatu(1,inTime,deviceId); | |
354 | + } else { | |
355 | + deviceDao.addDevide(attendanceBean.getClint_id(), attendanceBean.getClint_type(), attendanceBean.getIntime(), | |
356 | + attendanceBean.getSchool_id(), attendanceBean.getState() + "", attendanceBean.getIsConnection() + ""); | |
357 | + } | |
358 | + } | |
359 | + | |
337 | 360 | } | ... | ... |
cloud/haikangface/src/main/java/com/sincere/haikangface/utils/HttpUtil.java
... | ... | @@ -107,13 +107,14 @@ public class HttpUtil { |
107 | 107 | * @param userType |
108 | 108 | */ |
109 | 109 | public static void uploadImgs(String filePath, String card, String name, String deviceId, String startTime, |
110 | - String endTime, int validTimeEnabled, String userType) { | |
110 | + String endTime, int validTimeEnabled, String userType,Integer schoolId) { | |
111 | 111 | if (!new File(filePath).exists()) { |
112 | 112 | log.error("图片不存在,图片路径:{}",filePath); |
113 | 113 | return; |
114 | 114 | } |
115 | 115 | try{ |
116 | 116 | String url = "http://120.26.116.253:8089/file/uploadImg"; |
117 | +// String url = "http://127.0.0.1:8089/file/uploadImg"; | |
117 | 118 | RestTemplate restTemplate = new RestTemplate(); |
118 | 119 | HttpHeaders headers = new HttpHeaders(); |
119 | 120 | MediaType mediaType = MediaType.parseMediaType(MediaType.MULTIPART_FORM_DATA_VALUE); |
... | ... | @@ -128,6 +129,7 @@ public class HttpUtil { |
128 | 129 | multivaluedMap.add("endTime", endTime); |
129 | 130 | multivaluedMap.add("validTimeEnabled", validTimeEnabled); |
130 | 131 | multivaluedMap.add("userType", userType); |
132 | + multivaluedMap.add("schoolId", schoolId); | |
131 | 133 | HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(multivaluedMap, headers); |
132 | 134 | ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, httpEntity, String.class); |
133 | 135 | log.info("发送请求,下发人脸至253服务器海康设备,请求地址:{} ,下发用户名:{},返回信息:{}",url,name,responseEntity.getBody()); |
... | ... | @@ -138,7 +140,6 @@ public class HttpUtil { |
138 | 140 | |
139 | 141 | |
140 | 142 | public static boolean IsDeviceOnline(String deviceId) { |
141 | - | |
142 | 143 | String url = "http://120.26.116.253:8089/file/IsDeviceOnline?deviceId=" + deviceId; |
143 | 144 | RestTemplate restTemplate = new RestTemplate(); |
144 | 145 | String res = restTemplate.getForObject(url, String.class); |
... | ... | @@ -248,8 +249,8 @@ public class HttpUtil { |
248 | 249 | */ |
249 | 250 | public static void sendDHPermission(PermissionDHBean permissionBean) { |
250 | 251 | try{ |
251 | -// String url = "http://121.40.109.21:8991/file/sendPermission"; | |
252 | - String url = "http://localhost:8991/file/sendPermission"; | |
252 | + String url = "http://121.40.109.21:8991/file/sendPermission"; | |
253 | +// String url = "http://127.0.0.1:8991/file/sendPermission"; | |
253 | 254 | RestTemplate restTemplate = new RestTemplate(); |
254 | 255 | HttpHeaders headers = new HttpHeaders(); |
255 | 256 | MediaType mediaType = MediaType.parseMediaType(MediaType.APPLICATION_JSON_UTF8_VALUE); |
... | ... | @@ -286,11 +287,11 @@ public class HttpUtil { |
286 | 287 | * @param userType |
287 | 288 | * @param deviceIds |
288 | 289 | */ |
289 | - public static void uploadDHImg( String schoolId,int userType,String deviceIds) { | |
290 | - String api = "http://114.55.30.100:8991/user/sendFaces"; | |
290 | + public static void uploadDHImg(String schoolId,Integer userType,String deviceIds,Integer studentType,String sex) { | |
291 | + String api = "http://114.55.30.100:8991/operate/sendUserFaces"; | |
291 | 292 | // String api = "http://127.0.0.1:8991/user/sendFaces"; |
292 | 293 | try { |
293 | - String url = String.format(api +"?schoolId=%s&userType=%s&deviceIds=%s",schoolId,userType,deviceIds); | |
294 | + String url = String.format(api +"?schoolId=%s&userType=%s&deviceIds=%s&studentType=%s&sex=%s",schoolId,userType,deviceIds,studentType,sex); | |
294 | 295 | RestTemplate restTemplate = new RestTemplate(); |
295 | 296 | ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class); |
296 | 297 | log.info("发送请求,照片下发至大华设备,请求地址:{},返回信息: {}",url,responseEntity.getBody()); |
... | ... | @@ -316,4 +317,23 @@ public class HttpUtil { |
316 | 317 | log.error("发送请求,删除大华设备人脸,异常信息:{}",e); |
317 | 318 | } |
318 | 319 | } |
320 | + | |
321 | + /** | |
322 | + * 在线活体检测 | |
323 | + * @param checkUrl | |
324 | + * @return | |
325 | + */ | |
326 | + public static String checkFace(String checkUrl) { | |
327 | + String api = "http://114.55.30.100:8991/user/checkFace"; | |
328 | + try { | |
329 | + String url = String.format(api +"?url=%s",checkUrl); | |
330 | + RestTemplate restTemplate = new RestTemplate(); | |
331 | + ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class); | |
332 | + log.info("发送请求,删除大华设备人脸,请求地址:{},返回信息: {}",url,responseEntity.getBody()); | |
333 | + return responseEntity.getBody(); | |
334 | + } catch (Exception e) { | |
335 | + log.error("发送请求,删除大华设备人脸,异常信息:{}",e); | |
336 | + } | |
337 | + return null; | |
338 | + } | |
319 | 339 | } | ... | ... |
cloud/haikangface/src/main/java/com/sincere/haikangface/utils/SpringContextHolder.java
0 → 100644
... | ... | @@ -0,0 +1,23 @@ |
1 | +package com.sincere.haikangface.utils; | |
2 | + | |
3 | +import com.sincere.haikangface.service.impl.BaseService; | |
4 | +import org.springframework.beans.BeansException; | |
5 | +import org.springframework.context.ApplicationContext; | |
6 | +import org.springframework.context.ApplicationContextAware; | |
7 | +import org.springframework.stereotype.Component; | |
8 | + | |
9 | +@Component | |
10 | +public class SpringContextHolder implements ApplicationContextAware { | |
11 | + | |
12 | + private static ApplicationContext applicationContext; | |
13 | + | |
14 | + @Override | |
15 | + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | |
16 | + SpringContextHolder.applicationContext = applicationContext; | |
17 | + } | |
18 | + | |
19 | + public static BaseService getBaseService(){ | |
20 | + return (BaseService) applicationContext.getBean("baseService"); | |
21 | + } | |
22 | + | |
23 | +} | ... | ... |
cloud/haikangface/src/main/java/com/sincere/haikangface/xiananDao/SendRecordDao.java
... | ... | @@ -27,11 +27,11 @@ public interface SendRecordDao { |
27 | 27 | @Param("userType") int userType, @Param("deviceType") int deviceType); |
28 | 28 | |
29 | 29 | |
30 | - @Select("select * from Face_SendSuccess where schoolId = 870 ") | |
30 | + @Select("select * from Face_SendSuccess where schoolId = 865 ") | |
31 | 31 | List<SendRecordBean> getSenSuccess(); |
32 | 32 | |
33 | 33 | @Select("select * from Face_SendSuccess where deviceID = #{deviceID} and schoolId = #{schoolId}") |
34 | - List<SendRecordBean> getSenSuccesss(@Param("deviceID") String clint_id, @Param("schoolId") String schoolId); | |
34 | + List<SendRecordBean> getSenSuccesss(@Param("deviceID") String deviceId, @Param("schoolId") Integer schoolId); | |
35 | 35 | |
36 | 36 | |
37 | 37 | @Insert("insert into Face_SendFail values(#{deviceID},#{customerid},#{num},#{name},#{time},#{schoolName},#{imgPath},#{schoolId},#{failContent},#{failType},#{userType},#{deviceType})") |
... | ... | @@ -127,19 +127,39 @@ public interface SendRecordDao { |
127 | 127 | /******************************************* add by xuquan **********************************************/ |
128 | 128 | |
129 | 129 | @Select("select * from Face_SendRecord where deviceID = #{deviceID} and Num = #{Num} and userId = #{userId}") |
130 | - List<SendRecordBean> getRecordIsExit(@Param("deviceID") String clint_id, @Param("Num") String card,@Param("userId") String userId); | |
130 | + List<SendRecordBean> getRecordIsExit(@Param("deviceID") String deviceId, @Param("Num") String cardNum,@Param("userId") String userId); | |
131 | 131 | |
132 | - @Insert("insert into Face_SendRecord values(#{deviceID},#{userId},#{num},#{name},#{time},#{schoolName},#{imgPath},#{schoolId},#{failContent},#{failType},#{userType},#{deviceType},#{status})") | |
132 | + @Insert("insert into Face_SendRecord values(#{deviceID},#{userId},#{num},#{name},#{time},#{schoolName},#{imgPath},#{schoolId},#{failContent},#{failType},#{userType},#{deviceType},#{status},#{channel})") | |
133 | 133 | void saveFaceRecord(@Param("userId") String userId, @Param("deviceID") String deviceID, @Param("num") String num, @Param("name") String name, |
134 | 134 | @Param("time") String time, @Param("schoolName") String schoolName, @Param("imgPath") String imgPath, @Param("schoolId") Integer schoolId, @Param("failContent") String failContent, |
135 | - @Param("failType") Integer failType, @Param("userType") Integer userType, @Param("deviceType") Integer deviceType,Integer status); | |
135 | + @Param("failType") Integer failType, @Param("userType") Integer userType, @Param("deviceType") Integer deviceType,@Param("status") Integer status,@Param("channel") Integer channel); | |
136 | 136 | |
137 | 137 | @Update("update Face_SendRecord set time = #{time},failContent = #{content},imgPath= #{faceUrl},status = 2 where deviceID = #{deviceID} and Num =#{Num} and userId = #{userId}") |
138 | 138 | void updateFaceFailRecord(@Param("deviceID") String deviceId, @Param("faceUrl") String faceUrl,@Param("Num") String card, @Param("time") String time, @Param("content") String content,@Param("userId") String userId); |
139 | 139 | |
140 | - @Update("update Face_SendRecord set time = #{time},imgPath= #{faceUrl},Name = #{Name},status = 1, failType=null, failContent = null where deviceID = #{deviceID} and Num = #{Num}") | |
141 | - void updateFaceSuccessRecord(@Param("deviceID") String deviceId, @Param("Num") String card, @Param("time") String time, @Param("faceUrl") String faceUrl, @Param("Name") String name, @Param("userId") String userId); | |
140 | + @Update("update Face_SendRecord set time = #{time},imgPath= #{faceUrl},Name = #{Name},status = 1,channel=#{channel},failType=null, failContent = null where deviceID = #{deviceID} and Num = #{Num}") | |
141 | + void updateFaceSuccessRecord(@Param("deviceID") String deviceId, @Param("Num") String card, @Param("time") String time, @Param("faceUrl") String faceUrl, @Param("Name") String name, @Param("userId") String userId,@Param("channel") Integer channel); | |
142 | 142 | |
143 | 143 | @Select("select * from Face_SendRecord where schoolId = #{schoolId} and status =2") |
144 | 144 | List<SendRecordBean> getFailRecord(@Param("schoolId") Integer schoolId); |
145 | + | |
146 | + @Delete("delete Face_SendRecord where deviceID = #{deviceID} and Num = #{Num} and schoolId = #{schoolId}") | |
147 | + void deleteRecord(@Param("schoolId") Integer schoolId,@Param("deviceID") String deviceID,@Param("Num") String Num); | |
148 | + | |
149 | + @Delete("delete Face_SendSuccess where deviceID = #{deviceID} and Num = #{Num} and schoolId = #{schoolId}") | |
150 | + void deleteUserFaceSuccess(@Param("schoolId") Integer schoolId,@Param("Num") String Num, @Param("deviceID") String deviceID); | |
151 | + | |
152 | + @Delete("delete WG_SendSuccess where deviceID = #{deviceID} and cardNum = #{cardNum} and schoolID = #{schoolID}") | |
153 | + void deleteWGSuccess(@Param("schoolID") Integer schoolId,@Param("cardNum") String cardNum, @Param("deviceID") String deviceId); | |
154 | + | |
155 | + | |
156 | + @Delete("DELETE from SZ_AttendanceRecords202101 where school_id = #{schoolId} and card_Num = #{cardNum} and card_type = #{cardType} and outof=#{outof} and intime > #{startTime} and intime < #{endTime}") | |
157 | + void delete(@Param("schoolId") Integer schoolId,@Param("cardNum") String cardNum,@Param("cardType") Integer cardType,@Param("outof") Integer outof,@Param("startTime") String startTime,@Param("endTime") String endTime); | |
158 | + | |
159 | + @Delete("DELETE from SZ_AttendanceRecordsSS202101 where school_id = #{schoolId} and card_Num = #{cardNum} and card_type = #{cardType} and outof=#{outof} and intime > #{startTime} and intime < #{endTime}") | |
160 | + void deleteSS(@Param("schoolId") Integer schoolId,@Param("cardNum") String cardNum,@Param("cardType") Integer cardType,@Param("outof") Integer outof,@Param("startTime") String startTime,@Param("endTime") String endTime); | |
161 | + | |
162 | + | |
163 | + @Select("select top 1000 * from Face_SendFail where schoolId = 865 ") | |
164 | + List<SendRecordBean> getFaceFailList(); | |
145 | 165 | } | ... | ... |
cloud/haikangface/src/main/resources/application.yaml
... | ... | @@ -3,9 +3,14 @@ server: |
3 | 3 | |
4 | 4 | spring: |
5 | 5 | profiles: |
6 | - active: dev | |
6 | + active: prod | |
7 | 7 | application: |
8 | 8 | name: haikangserver |
9 | + servlet: | |
10 | + multipart: | |
11 | + enabled: true | |
12 | + max-file-size: -1 | |
13 | + max-request-size: -1 | |
9 | 14 | datasource: |
10 | 15 | campus: |
11 | 16 | username: szjxtuser |
... | ... | @@ -57,13 +62,8 @@ mybatis: |
57 | 62 | |
58 | 63 | ip: localhost |
59 | 64 | |
60 | -attendanceHost: http://campus.myjxt.com/ | |
61 | - | |
62 | 65 | iscurl: https://60.12.93.221:443 |
63 | 66 | |
64 | -##ipCloud: http://114.55.30.100:8081 | |
65 | -ipCloud: http://172.16.2.166:8081 | |
66 | - | |
67 | 67 | #logging: |
68 | 68 | # level: |
69 | 69 | # com.sincere.haikangface.xiaoanDao: debug | ... | ... |
cloud/haikangface/src/main/resources/logback-spring.xml
... | ... | @@ -8,7 +8,7 @@ |
8 | 8 | <!--<include resource="org/springframework/boot/logging/logback/defaults.xml" />--> |
9 | 9 | |
10 | 10 | <!--日志文件存储的基础路径: ${user.home} 为当前服务器用户主目录--> |
11 | - <property name="LOG_PATH" value="D:/haikang-logs"/> | |
11 | + <property name="LOG_PATH" value="D:/haikang/haikang-logs"/> | |
12 | 12 | |
13 | 13 | <!--日志文件基础名称--> |
14 | 14 | <property name="BASE_FILE_NAME" value="haikang"/> |
... | ... | @@ -51,4 +51,11 @@ |
51 | 51 | </root> |
52 | 52 | </springProfile> |
53 | 53 | |
54 | + <!--生产环境不打印控制台输出--> | |
55 | + <springProfile name="prod"> | |
56 | + <root level="INFO"> | |
57 | + <appender-ref ref="file" /> | |
58 | + </root> | |
59 | + </springProfile> | |
60 | + | |
54 | 61 | </configuration> |
55 | 62 | \ No newline at end of file | ... | ... |
cloud/haikangface/src/main/resources/mapper/usermapper.xml
... | ... | @@ -63,14 +63,6 @@ |
63 | 63 | update AC_DeviceAuthRecord set GrantState = #{grantState} where id = #{id} |
64 | 64 | </update> |
65 | 65 | |
66 | - <select id="getStudentCByUserId" resultType="com.sincere.haikangface.bean.StudentBean" parameterType="java.lang.String"> | |
67 | - select Top(1) * from SZ_V_School_Student where user_id = #{userId} | |
68 | - </select> | |
69 | - | |
70 | - <select id="getTeacherByUserId" resultType="com.sincere.haikangface.bean.StudentBean" parameterType="java.lang.String"> | |
71 | - select Top(1) * from SZ_V_School_Teacher where user_id = #{userId} | |
72 | - </select> | |
73 | - | |
74 | 66 | <select id="getStudentList" resultType="com.sincere.haikangface.bean.StudentBean"> |
75 | 67 | select * from SZ_V_School_Student where school_id = #{schoolId} |
76 | 68 | <if test="studentType != null"> |
... | ... | @@ -82,13 +74,16 @@ |
82 | 74 | #{item} |
83 | 75 | </foreach> |
84 | 76 | </if> |
85 | - and (student_num is not null or student_num != '') and (photo is not null or photo !='') | |
77 | + and student_num != '' and photo !='' | |
78 | + </select> | |
79 | + | |
80 | + <select id="getStudentCardGroup" resultType="com.sincere.haikangface.bean.StudentBean"> | |
81 | + select * from SZ_V_School_Student where sex = #{sex} and student_type = #{studentType} and | |
82 | + class_id in(select DISTINCT ClassId from SZ_OneCardGrouping where Pid = #{groupId} and state = 1) | |
86 | 83 | </select> |
87 | 84 | |
88 | 85 | <select id="getTeacherList" resultType="com.sincere.haikangface.bean.StudentBean"> |
89 | - select * from SZ_V_School_Teacher where school_id = #{schoolId} | |
90 | - and (teacher_num is not null or teacher_num !='') | |
91 | - and (face is not null or face !='') | |
86 | + select * from SZ_V_School_Teacher where school_id = #{schoolId} and teacher_num !='' and face !='' | |
92 | 87 | </select> |
93 | 88 | |
94 | 89 | <select id="getDeviceIds" resultType="java.lang.String"> |
... | ... | @@ -98,5 +93,50 @@ |
98 | 93 | </if> |
99 | 94 | </select> |
100 | 95 | |
96 | + <update id="updateUser"> | |
97 | + update SZ_User set face = #{face} where user_id = #{userId} | |
98 | + </update> | |
99 | + | |
100 | + <select id="queryStudentIdList" resultType="java.lang.String"> | |
101 | + select StudentId from SS_RoomNumber where Status=1 and SchoolId=#{schoolId} | |
102 | + and Pid in (select id from SS_Room where Status=1 and SchoolId=#{schoolId} and Pid=#{roomId}) | |
103 | + and StudentId in (select student_id from SZ_V_School_Student where school_id= #{schoolId}) order by newid() | |
104 | + </select> | |
105 | + | |
106 | + <insert id="insertCard" parameterType="com.sincere.haikangface.bean.UpdateCardBean"> | |
107 | + insert into HS_StudentUpdateCard | |
108 | + (UserId ,CustomerId,StudentType,UserType,Name,ClassId,ClassName,OldCard ,Card,SchoolId,IsNew,UpdateType,AddTime ,Sex,Face,StudentCode,mobile) | |
109 | + values | |
110 | + (#{userId},#{customerId}, #{studentType}, #{userType}, #{name}, #{classId}, #{className}, #{oldCard}, #{card},#{schoolId},#{isNew},#{updateType}, #{addTime}, #{sex}, #{face}, #{studentCode}, #{mobile}) | |
111 | + </insert> | |
112 | + | |
113 | + | |
114 | + <select id="getStudentWithCard" resultType="com.sincere.haikangface.bean.StudentBean"> | |
115 | + select Top(1)* from SZ_V_School_Student where student_num = #{card} | |
116 | + <if test="schoolId !=null"> | |
117 | + and school_id = #{schoolId} | |
118 | + </if> | |
119 | + </select> | |
120 | + | |
121 | + <select id="getTeacherWithCard" resultType="com.sincere.haikangface.bean.StudentBean"> | |
122 | + select Top(1)* from SZ_V_School_Teacher where teacher_num = #{teacher_num} | |
123 | + <if test="schoolId !=null"> | |
124 | + and school_id = #{schoolId} | |
125 | + </if> | |
126 | + </select> | |
127 | + | |
128 | + <select id="getStudentCByUserId" resultType="com.sincere.haikangface.bean.StudentBean"> | |
129 | + select Top(1) * from SZ_V_School_Student where user_id = #{userId} | |
130 | + <if test="schoolId !=null"> | |
131 | + and school_id = #{schoolId} | |
132 | + </if> | |
133 | + </select> | |
134 | + | |
135 | + <select id="getTeacherByUserId" resultType="com.sincere.haikangface.bean.StudentBean"> | |
136 | + select Top(1) * from SZ_V_School_Teacher where user_id = #{userId} | |
137 | + <if test="schoolId !=null"> | |
138 | + and school_id = #{schoolId} | |
139 | + </if> | |
140 | + </select> | |
101 | 141 | |
102 | 142 | </mapper> | ... | ... |
cloud/haikangface/src/test/java/com/sincere/haikangface/HaikangfaceApplicationTests.java
... | ... | @@ -14,6 +14,7 @@ import com.sincere.haikangface.bean.xiaoan.CreditCardRecordsSS; |
14 | 14 | import com.sincere.haikangface.dao.DeviceDao; |
15 | 15 | import com.sincere.haikangface.dao.UserDao; |
16 | 16 | import com.sincere.haikangface.dao.ZuoYeDao; |
17 | +import com.sincere.haikangface.service.impl.BaseService; | |
17 | 18 | import com.sincere.haikangface.utils.ApiUtil; |
18 | 19 | import com.sincere.haikangface.xiananDao.SendRecordDao; |
19 | 20 | import org.bouncycastle.asn1.cms.MetaData; |
... | ... | @@ -28,6 +29,7 @@ import org.springframework.http.HttpHeaders; |
28 | 29 | import org.springframework.http.MediaType; |
29 | 30 | import org.springframework.http.ResponseEntity; |
30 | 31 | import org.springframework.test.context.junit4.SpringRunner; |
32 | +import org.springframework.util.CollectionUtils; | |
31 | 33 | import org.springframework.util.LinkedMultiValueMap; |
32 | 34 | import org.springframework.util.MultiValueMap; |
33 | 35 | import org.springframework.util.StringUtils; |
... | ... | @@ -251,6 +253,56 @@ public class HaikangfaceApplicationTests { |
251 | 253 | |
252 | 254 | } |
253 | 255 | |
256 | + @Test | |
257 | + public void delete() { | |
258 | + Integer schoolId =27; | |
259 | + Integer roomId = 11748; | |
260 | + Integer type = 7; | |
261 | + Integer outof = 1; | |
262 | + Integer size = 66; | |
263 | + String startTime= "2021-01-11 00:00:00"; | |
264 | + String endTime ="2021-01-11 23:59:59"; | |
265 | + List<String> studentIds = userDao.queryStudentIdList(schoolId,roomId); | |
266 | + if(!CollectionUtils.isEmpty(studentIds)){ | |
267 | + for(int i=0;i<=studentIds.size();i++){ | |
268 | + if(i == size){ | |
269 | + return; | |
270 | + } | |
271 | + StudentBean userInfoBean = userDao.getStudentWithid(studentIds.get(i)); | |
272 | + if(userInfoBean!=null){ | |
273 | + String cardNum = userInfoBean.getStudent_num(); | |
274 | + System.out.println(i); | |
275 | + sendRecordDao.deleteSS(schoolId,cardNum,type,outof,startTime,endTime); | |
276 | + } | |
277 | + } | |
278 | + } | |
279 | + } | |
280 | + | |
281 | + @Test | |
282 | + public void delete2() { | |
283 | + Integer schoolId =27; | |
284 | + Integer roomId = 11748; | |
285 | + Integer type = 12; | |
286 | + Integer outof = 0; | |
287 | + Integer size =62; | |
288 | + String startTime= "2021-01-22 00:00:00"; | |
289 | + String endTime ="2021-01-22 23:59:59"; | |
290 | + List<String> studentIds = userDao.queryStudentIdList(schoolId,roomId); | |
291 | + if(!CollectionUtils.isEmpty(studentIds)){ | |
292 | + for(int i=0;i<=studentIds.size();i++){ | |
293 | + if(i == size){ | |
294 | + return; | |
295 | + } | |
296 | + StudentBean userInfoBean = userDao.getStudentWithid(studentIds.get(i)); | |
297 | + if(userInfoBean!=null){ | |
298 | + String cardNum = userInfoBean.getStudent_num(); | |
299 | + System.out.println(i); | |
300 | + sendRecordDao.deleteSS(schoolId,cardNum,type,outof,startTime,endTime); | |
301 | + } | |
302 | + } | |
303 | + } | |
304 | + } | |
305 | + | |
254 | 306 | private int index(String content, List<String> list) { |
255 | 307 | for (int i = 0; i < list.size(); i++) { |
256 | 308 | if (list.get(i).trim().equals(content.trim())) return i; |
... | ... | @@ -291,6 +343,18 @@ public class HaikangfaceApplicationTests { |
291 | 343 | @Autowired |
292 | 344 | ZuoyeAdminDao zuoyeAdminDao; |
293 | 345 | |
346 | + @Autowired | |
347 | + BaseService baseService; | |
348 | + | |
349 | + @Test | |
350 | + public void test() { | |
351 | +// String deviceIds = "338652415671,694642005671,694642555671,338652515671,338653105671,338652895671,ytj687425415671,ytj694642105671,694642135671,ytj694642375671"; | |
352 | +// String deviceIds = "687425135671,ytj687425345671,ytj687425395671,ytj687425155671,687425355671,687425225671,687425265671,740456495671,687425325671,694642215671"; | |
353 | + String deviceIds = "694642215671"; | |
354 | + Integer schoolId = 865; | |
355 | + baseService.getSuccessList(schoolId,deviceIds); | |
356 | + } | |
357 | + | |
294 | 358 | @Test |
295 | 359 | public void fileRes() { |
296 | 360 | ... | ... |
cloud/mypulsar/pom.xml
... | ... | @@ -117,11 +117,21 @@ |
117 | 117 | <version>2.4.2</version> |
118 | 118 | </dependency> |
119 | 119 | |
120 | - <!--<dependency>--> | |
121 | - <!--<groupId>com.gitee.sunchenbin.mybatis.actable</groupId>--> | |
122 | - <!--<artifactId>mybatis-enhance-actable</artifactId>--> | |
123 | - <!--<version>1.0.4</version>--> | |
124 | - <!--</dependency>--> | |
120 | + <!--mqtt依赖--> | |
121 | + <dependency> | |
122 | + <groupId>org.springframework.integration</groupId> | |
123 | + <artifactId>spring-integration-stream</artifactId> | |
124 | + </dependency> | |
125 | + <dependency> | |
126 | + <groupId>org.springframework.integration</groupId> | |
127 | + <artifactId>spring-integration-mqtt</artifactId> | |
128 | + </dependency> | |
129 | + | |
130 | + <dependency> | |
131 | + <groupId>commons-codec</groupId> | |
132 | + <artifactId>commons-codec</artifactId> | |
133 | + <version>1.10</version> | |
134 | + </dependency> | |
125 | 135 | </dependencies> |
126 | 136 | |
127 | 137 | <dependencyManagement> | ... | ... |
cloud/mypulsar/src/main/java/com/example/mypulsar/MyRunnerableInt.java
... | ... | @@ -7,13 +7,14 @@ import com.example.mypulsar.message.MessageVO; |
7 | 7 | import com.example.mypulsar.mq.AESBase64Utils; |
8 | 8 | import com.example.mypulsar.mq.MessageHandlerTask; |
9 | 9 | import com.example.mypulsar.mq.MqConsumer; |
10 | +import com.example.mypulsar.mqtt.MqttConsumer; | |
10 | 11 | import com.example.mypulsar.task.SchduledTasks; |
11 | 12 | import com.example.mypulsar.utils.ControlUtils; |
13 | +import com.example.mypulsar.utils.JsonUtils; | |
12 | 14 | import com.example.mypulsar.utils.PulsarConsumerPoolFactory; |
13 | 15 | import com.example.mypulsar.utils.ThreadPoolFactory; |
14 | 16 | import lombok.extern.slf4j.Slf4j; |
15 | 17 | import org.apache.pulsar.client.api.Consumer; |
16 | -import org.apache.pulsar.client.impl.TopicMessageIdImpl; | |
17 | 18 | import org.slf4j.Logger; |
18 | 19 | import org.slf4j.LoggerFactory; |
19 | 20 | import org.springframework.beans.factory.annotation.Autowired; |
... | ... | @@ -21,8 +22,7 @@ import org.springframework.boot.ApplicationArguments; |
21 | 22 | import org.springframework.boot.ApplicationRunner; |
22 | 23 | import org.springframework.stereotype.Component; |
23 | 24 | import org.springframework.util.CollectionUtils; |
24 | -import org.springframework.web.client.RestTemplate; | |
25 | -import sun.rmi.runtime.Log; | |
25 | +import org.springframework.util.StringUtils; | |
26 | 26 | |
27 | 27 | import java.text.SimpleDateFormat; |
28 | 28 | import java.util.ArrayList; |
... | ... | @@ -64,19 +64,22 @@ public class MyRunnerableInt implements ApplicationRunner { |
64 | 64 | * 第二种方式 |
65 | 65 | */ |
66 | 66 | private void initMqConsumer() { |
67 | - MqConsumer mqConsumer = MqConsumer.build().serviceUrl(url).accessId(accessId).accessKey(accessKey) | |
68 | - .maxRedeliverCount(3).messageListener(message -> { | |
69 | - //消息内容 | |
70 | - String jsonMessage = new String(message.getData()); | |
71 | - MessageVO vo = JSON.parseObject(jsonMessage, MessageVO.class); | |
72 | - String data = AESBase64Utils.decrypt(vo.getData(), accessKey.substring(8, 24)); | |
73 | - TuYaReceiverBean tuYaReceiverBean = JSON.parseObject(data, TuYaReceiverBean.class); | |
74 | - log.info("接收消息,消息内容:"+ JSON.toJSONString(tuYaReceiverBean)); | |
75 | - //处理数据上报 | |
76 | - detealData(tuYaReceiverBean); | |
77 | - } | |
78 | - | |
79 | - ); | |
67 | + MqConsumer mqConsumer = MqConsumer.build() | |
68 | + .serviceUrl(url) | |
69 | + .accessId(accessId) | |
70 | + .accessKey(accessKey) | |
71 | + .maxRedeliverCount(3) | |
72 | + .messageListener(message -> { | |
73 | + //消息内容 | |
74 | + String jsonMessage = new String(message.getData()); | |
75 | + MessageVO vo = JSON.parseObject(jsonMessage, MessageVO.class); | |
76 | + //通过 AES (ECB 模式)对 accessKey 的中间 16 位代码进行解密 | |
77 | + String data = AESBase64Utils.decrypt(vo.getData(), accessKey.substring(8, 24)); | |
78 | + TuYaReceiverBean tuYaReceiverBean = JSON.parseObject(data, TuYaReceiverBean.class); | |
79 | + log.info("接收消息,消息内容:"+ JSON.toJSONString(tuYaReceiverBean)); | |
80 | + //处理数据上报 | |
81 | + detealData(tuYaReceiverBean); | |
82 | + }); | |
80 | 83 | try { |
81 | 84 | mqConsumer.start(); |
82 | 85 | } catch (Exception e) { |
... | ... | @@ -105,30 +108,31 @@ public class MyRunnerableInt implements ApplicationRunner { |
105 | 108 | deviceBean.setBizCode(bizCode); |
106 | 109 | deviceBean.setDevId(devId); |
107 | 110 | deviceBean.setProductKey(productKey); |
111 | + Wl_Attendace attendace = deviceDao.selectAttendance(devId); | |
112 | + String deviceName = attendace ==null?"":attendace.getName(); | |
113 | + Integer schoolId = attendace ==null?null:attendace.getSchool_id(); | |
108 | 114 | //温度、人感、湿度数据上报事件 |
109 | - if (bizCode == null) { | |
110 | - deviceBean.setBizCode(""); | |
115 | + if (StringUtils.isEmpty(bizCode)) { | |
111 | 116 | //在线状态:1在线0离线 |
112 | 117 | deviceBean.setDev_status(1); |
113 | 118 | //设备上报事件:code:时间类型; 格式:"status":[{"code":"pir","t":1612283849564,"value":"pir"}] |
114 | 119 | List<TuYaReceiverBeanStatus> status = tuYaReceiverBean.getStatus(); |
115 | 120 | for (TuYaReceiverBeanStatus statue : status) { |
116 | 121 | //事件上报处理 |
117 | - initStatue(statue, deviceBean); | |
122 | + initStatue(statue, deviceBean,schoolId); | |
118 | 123 | } |
119 | 124 | } else {//其他事件上报 |
120 | 125 | deviceBean.setTime(new SimpleDateFormat("yyyy-MM-dd HH::mm:ss").format(new Date())); |
121 | - String name = deviceDao.selectAttendance(devId); | |
122 | 126 | switch (bizCode) { |
123 | 127 | case "offline"://设备掉线 |
124 | - log.info("设备: {},已掉线",name); | |
128 | + log.info("设备: {},已掉线",deviceName); | |
125 | 129 | deviceBean.setDev_type(1); |
126 | 130 | deviceBean.setDev_status(0); |
127 | 131 | updateDevStatus(deviceBean); |
128 | 132 | updateStatus(devId, "0"); |
129 | 133 | break; |
130 | 134 | case "online"://设备上线 |
131 | - log.info("设备: {},已上线",name); | |
135 | + log.info("设备: {},已上线",deviceName); | |
132 | 136 | deviceBean.setDev_status(1); |
133 | 137 | deviceBean.setDev_type(2); |
134 | 138 | updateDevStatus(deviceBean); |
... | ... | @@ -142,6 +146,10 @@ public class MyRunnerableInt implements ApplicationRunner { |
142 | 146 | case "delete"://删除设备 |
143 | 147 | break; |
144 | 148 | } |
149 | + if(schoolId !=null && schoolId.intValue()==1){ | |
150 | + //同步数据至小程序 | |
151 | + sendMsg(deviceBean); | |
152 | + } | |
145 | 153 | } |
146 | 154 | |
147 | 155 | } |
... | ... | @@ -171,13 +179,16 @@ public class MyRunnerableInt implements ApplicationRunner { |
171 | 179 | updateStatus(deviceBean.getDevId(), "1"); |
172 | 180 | } |
173 | 181 | |
182 | + | |
183 | + private MqttConsumer mqttConsumer; | |
184 | + private String accesskey = "T6dtGFMEs35U4la176032PCis5q6em3h"; | |
174 | 185 | /** |
175 | 186 | * 数据上报事件处理 |
176 | 187 | * |
177 | 188 | * @param statue |
178 | 189 | * @param deviceBean |
179 | 190 | */ |
180 | - private void initStatue(TuYaReceiverBeanStatus statue,DeviceBean deviceBean) { | |
191 | + private void initStatue(TuYaReceiverBeanStatus statue,DeviceBean deviceBean,Integer schoolId) { | |
181 | 192 | //设备消息类型:1:掉线,2:上线,3:其他事件 |
182 | 193 | deviceBean.setDev_type(3); |
183 | 194 | //事件时间 |
... | ... | @@ -195,8 +206,6 @@ public class MyRunnerableInt implements ApplicationRunner { |
195 | 206 | switch (code) { |
196 | 207 | case "va_temperature"://温度 |
197 | 208 | deviceBean.setValue(Integer.parseInt(value) / 100 + ""); |
198 | - //计算开启或关闭设备 | |
199 | -// calOpenOrCloseDevWithtemper(deviceBean); | |
200 | 209 | log.info("温度:" + deviceBean.getValue()); |
201 | 210 | //存储 对应设备对应的温度记录 |
202 | 211 | ControlUtils.tempDevices.put(deviceBean.getDevId(),Integer.valueOf(deviceBean.getValue())); |
... | ... | @@ -205,15 +214,13 @@ public class MyRunnerableInt implements ApplicationRunner { |
205 | 214 | deviceBean.setValue(Integer.parseInt(value) / 100 + ""); |
206 | 215 | log.info("湿度:" + deviceBean.getValue()); |
207 | 216 | break; |
208 | - case "pir": | |
209 | - //人体感应 | |
217 | + case "pir"://人体感应 | |
210 | 218 | log.info("人体感应:" + value); |
211 | 219 | if(value.equals("pir")){ |
212 | 220 | deviceBean.setValue("有人"); |
213 | 221 | }else{ |
214 | 222 | deviceBean.setValue("无人"); |
215 | 223 | } |
216 | - setClintTime(deviceBean.getDevId()); | |
217 | 224 | try { |
218 | 225 | Thread.sleep(1000); |
219 | 226 | //根据场地是否有人控制空调设备 |
... | ... | @@ -222,11 +229,6 @@ public class MyRunnerableInt implements ApplicationRunner { |
222 | 229 | e.printStackTrace(); |
223 | 230 | } |
224 | 231 | break; |
225 | - case "temper_alarm"://防拆报警 | |
226 | - break; | |
227 | - case "battery_percentage"://电池电量百分比 | |
228 | - log.info("电池电量百分比:" + value); | |
229 | - break; | |
230 | 232 | case "battery_value"://电池电量值 |
231 | 233 | break; |
232 | 234 | case "battery"://门磁电池电量值 |
... | ... | @@ -244,21 +246,59 @@ public class MyRunnerableInt implements ApplicationRunner { |
244 | 246 | log("开关状态:" + (value.equals("true") ? "开门" : "关门")); |
245 | 247 | break; |
246 | 248 | case "cur_voltage"://当前电压 |
247 | -// value = Integer.parseInt(value) / 10 + "V"; | |
248 | - log(deviceBean.getDevId() + " 当前电压:" + value); | |
249 | + if(value.equals("0")){ | |
250 | + value = "0"; | |
251 | + }else{ | |
252 | + value = Integer.parseInt(value) / 10 + ""; | |
253 | + } | |
254 | + log(deviceBean.getDevId() + " 当前电压:" + value +"v"); | |
249 | 255 | break; |
250 | 256 | case "cur_power"://当前功率 |
251 | -// value = value.equals("0")?"0":Integer.parseInt(value) / 10 + "W"; | |
252 | -// log(devId + " 当前功率:" + Integer.parseInt(value) / 10 + "W"); | |
257 | + if(value.equals("0")){ | |
258 | + value = "0"; | |
259 | + }else{ | |
260 | + value = Integer.parseInt(value) / 10+""; | |
261 | + } | |
262 | + log(deviceBean.getDevId() + " 当前功率:" + value + "W"); | |
253 | 263 | break; |
254 | 264 | case "cur_current"://当前电流 |
255 | -// value = value.equals("0")?"0":Integer.parseInt(value) / 10 + "A"; | |
256 | -// log(devId + " 当前电流:" + Integer.parseInt(value) / 10 + "A"); | |
265 | + if(value.equals("0")){ | |
266 | + value = "0"; | |
267 | + }else{ | |
268 | + value = Integer.parseInt(value) / 10+""; | |
269 | + } | |
270 | + log(deviceBean.getDevId() + " 当前电流:" + value + "A"); | |
271 | + break; | |
272 | + case "smoke_sensor_state"://烟雾报警 | |
273 | + break; | |
274 | + case "temper_alarm"://防拆报警 | |
275 | + break; | |
276 | + case "battery_percentage"://电池电量百分比 | |
277 | + log.info("电池电量百分比:" + value); | |
257 | 278 | break; |
258 | 279 | case "router_mgr"://网关路由 |
259 | 280 | break; |
260 | 281 | } |
261 | 282 | updateDevStatus(deviceBean); |
283 | + if(schoolId !=null && schoolId.intValue()==16){ | |
284 | + //同步数据至小程序 | |
285 | + sendMsg(deviceBean); | |
286 | + } | |
287 | + } | |
288 | + | |
289 | + private void sendMsg(DeviceBean deviceBean){ | |
290 | + String json = JsonUtils.nonDefaultMapper().toJson(deviceBean); | |
291 | + String data =""; | |
292 | + try{ | |
293 | + data= AESBase64Utils.encrypt(json,accesskey.substring(8, 24)); | |
294 | + }catch (Exception e){ | |
295 | + log.error("加密失败: ",e); | |
296 | + } | |
297 | + if(mqttConsumer == null){ | |
298 | + mqttConsumer = new MqttConsumer(); | |
299 | + mqttConsumer.init(); | |
300 | + } | |
301 | + mqttConsumer.publish("Topic_Quene_Test",data); | |
262 | 302 | } |
263 | 303 | |
264 | 304 | /** |
... | ... | @@ -267,11 +307,6 @@ public class MyRunnerableInt implements ApplicationRunner { |
267 | 307 | * @param deviceBean |
268 | 308 | */ |
269 | 309 | private void calOpenOrCloseDevWithPir(DeviceBean deviceBean) { |
270 | -// if (deviceBean.getValue().equals("有人")){ | |
271 | -// deviceBean.setValue("1"); | |
272 | -// } else{ | |
273 | -// deviceBean.setValue("0"); | |
274 | -// } | |
275 | 310 | //获取人感设备控制 |
276 | 311 | List<CalDevContrl> calDevContrls = deviceDao.getCalDevContrlWidthDevId(deviceBean.getDevId()); |
277 | 312 | if (CollectionUtils.isEmpty(calDevContrls)) { |
... | ... | @@ -286,11 +321,12 @@ public class MyRunnerableInt implements ApplicationRunner { |
286 | 321 | * @param clintId |
287 | 322 | */ |
288 | 323 | private void setClintTime(String clintId){ |
324 | + //获取人感设备 | |
289 | 325 | List<CalDevContrl> calDevContrls = deviceDao.getCalDevContrlWidthDevId(clintId); |
290 | 326 | if(!CollectionUtils.isEmpty(calDevContrls)){ |
291 | 327 | CalDevContrl calDevContrl = calDevContrls.get(0); |
292 | 328 | String assDevice = calDevContrl.getAssDevice(); |
293 | - //红外遥控器 | |
329 | + //获取人感关联红外遥控器 | |
294 | 330 | CalDevBeContrl hwClint = getCalDevBeCon(assDevice); |
295 | 331 | if(hwClint==null) { |
296 | 332 | log.info("未查询到控制红外遥控器"); | ... | ... |
cloud/mypulsar/src/main/java/com/example/mypulsar/bean/IotDevice.java
0 → 100644
... | ... | @@ -0,0 +1,56 @@ |
1 | +package com.example.mypulsar.bean; | |
2 | + | |
3 | +/** | |
4 | + * 设备上报记录 | |
5 | + * @author xuquan | |
6 | + * @date 2021/3/14 14:06 | |
7 | + */ | |
8 | + | |
9 | +public class IotDevice { | |
10 | + | |
11 | + private String devId; | |
12 | + private String code; | |
13 | + private String value; | |
14 | + private String time; | |
15 | + private Integer dev_status; | |
16 | + | |
17 | + public String getDevId() { | |
18 | + return devId; | |
19 | + } | |
20 | + | |
21 | + public void setDevId(String devId) { | |
22 | + this.devId = devId; | |
23 | + } | |
24 | + | |
25 | + public String getCode() { | |
26 | + return code; | |
27 | + } | |
28 | + | |
29 | + public void setCode(String code) { | |
30 | + this.code = code; | |
31 | + } | |
32 | + | |
33 | + public String getValue() { | |
34 | + return value; | |
35 | + } | |
36 | + | |
37 | + public void setValue(String value) { | |
38 | + this.value = value; | |
39 | + } | |
40 | + | |
41 | + public String getTime() { | |
42 | + return time; | |
43 | + } | |
44 | + | |
45 | + public void setTime(String time) { | |
46 | + this.time = time; | |
47 | + } | |
48 | + | |
49 | + public Integer getDev_status() { | |
50 | + return dev_status; | |
51 | + } | |
52 | + | |
53 | + public void setDev_status(Integer dev_status) { | |
54 | + this.dev_status = dev_status; | |
55 | + } | |
56 | +} | ... | ... |
cloud/mypulsar/src/main/java/com/example/mypulsar/bean/TuYaReceiverBean.java
... | ... | @@ -5,17 +5,22 @@ import java.util.List; |
5 | 5 | |
6 | 6 | public class TuYaReceiverBean implements Serializable { |
7 | 7 | |
8 | - private String dataId;//全局唯一id,标志单次数据上报 | |
9 | - | |
10 | - private String devId;//设备id | |
11 | - | |
12 | - private String productKey;//开发者平台对应的产品key | |
13 | - | |
8 | + /** | |
9 | + * 全局唯一id,标志单次数据上报 | |
10 | + */ | |
11 | + private String dataId; | |
12 | + /** | |
13 | + * 设备id | |
14 | + */ | |
15 | + private String devId; | |
16 | + /** | |
17 | + * 开发者平台对应的产品key | |
18 | + */ | |
19 | + private String productKey; | |
14 | 20 | /** |
15 | 21 | * 设备数据上报事件 |
16 | 22 | */ |
17 | - private List<TuYaReceiverBeanStatus> status;//设备数据上报事件 | |
18 | - | |
23 | + private List<TuYaReceiverBeanStatus> status; | |
19 | 24 | /** |
20 | 25 | * 其他事件 |
21 | 26 | */ | ... | ... |
cloud/mypulsar/src/main/java/com/example/mypulsar/bean/Wl_Attendace.java
1 | 1 | package com.example.mypulsar.bean; |
2 | 2 | |
3 | +import afu.org.checkerframework.checker.igj.qual.I; | |
4 | + | |
3 | 5 | import java.io.Serializable; |
4 | 6 | |
5 | 7 | public class Wl_Attendace implements Serializable { |
6 | 8 | |
9 | + private Integer school_id; | |
10 | + | |
7 | 11 | private String clint_id; |
8 | 12 | |
9 | 13 | private String name; |
10 | 14 | |
15 | + public Integer getSchool_id() { | |
16 | + return school_id; | |
17 | + } | |
18 | + | |
19 | + public void setSchool_id(Integer school_id) { | |
20 | + this.school_id = school_id; | |
21 | + } | |
22 | + | |
11 | 23 | public String getClint_id() { |
12 | 24 | return clint_id; |
13 | 25 | } | ... | ... |
cloud/mypulsar/src/main/java/com/example/mypulsar/control/UserControl.java
... | ... | @@ -4,6 +4,7 @@ import com.example.mypulsar.bean.DeviceBean; |
4 | 4 | import com.example.mypulsar.bean.User; |
5 | 5 | import com.example.mypulsar.dao.DeviceDao; |
6 | 6 | import com.example.mypulsar.service.UserService; |
7 | +import com.example.mypulsar.task.SchduledTasks; | |
7 | 8 | import org.springframework.beans.factory.annotation.Autowired; |
8 | 9 | import org.springframework.web.bind.annotation.*; |
9 | 10 | |
... | ... | @@ -19,6 +20,9 @@ public class UserControl { |
19 | 20 | @Autowired |
20 | 21 | DeviceDao deviceDao; |
21 | 22 | |
23 | + @Autowired | |
24 | + SchduledTasks schduledTasks; | |
25 | + | |
22 | 26 | // @GetMapping("getUsers") |
23 | 27 | // public List<User> getUsers(){ |
24 | 28 | // return userService.select(); |
... | ... | @@ -32,5 +36,9 @@ public class UserControl { |
32 | 36 | |
33 | 37 | } |
34 | 38 | |
39 | + @RequestMapping(value = "close", method = RequestMethod.GET) | |
40 | + public void close() { | |
41 | + schduledTasks.initWlMode(); | |
42 | + } | |
35 | 43 | |
36 | 44 | } | ... | ... |
cloud/mypulsar/src/main/java/com/example/mypulsar/dao/DeviceDao.java
1 | 1 | package com.example.mypulsar.dao; |
2 | 2 | |
3 | -import com.example.mypulsar.bean.Wl_LinkModeBean; | |
4 | -import com.example.mypulsar.bean.CalDevBeContrl; | |
5 | -import com.example.mypulsar.bean.CalDevContrl; | |
6 | -import com.example.mypulsar.bean.DeviceBean; | |
7 | -import com.example.mypulsar.bean.Wl_Attendace; | |
3 | +import com.example.mypulsar.bean.*; | |
8 | 4 | import org.apache.ibatis.annotations.*; |
9 | 5 | import org.springframework.stereotype.Repository; |
10 | 6 | |
... | ... | @@ -30,8 +26,8 @@ public interface DeviceDao { |
30 | 26 | int updateStatus(@Param("clint_id") String clint_id, @Param("isConnection") String isConnection, @Param("OnlineTime") String OnlineTime); |
31 | 27 | |
32 | 28 | |
33 | - @Select("select top 1 name from WL_Attendance where clint_id = #{clint_id}") | |
34 | - String selectAttendance(@Param("clint_id") String clint_id); | |
29 | + @Select("select top 1* from WL_Attendance where clint_id = #{clint_id}") | |
30 | + Wl_Attendace selectAttendance(@Param("clint_id") String clint_id); | |
35 | 31 | |
36 | 32 | @Select("select * from Iot_Device where devId = #{devId}") |
37 | 33 | List<DeviceBean> getDevice(@Param("devId") String devId); |
... | ... | @@ -40,6 +36,8 @@ public interface DeviceDao { |
40 | 36 | @Select("select * from CalDevContrl ") |
41 | 37 | List<CalDevContrl> getCalDevContrl(); |
42 | 38 | |
39 | + @Select("select top 1 * from WL_Attendance where clint_id = #{clint_id} and isConnection =1 and clint_type =10") | |
40 | + Wl_Attendace getAttendace(@Param("clint_id") String clint_id); | |
43 | 41 | |
44 | 42 | @Select("select * from CalDevContrl where Devid = #{Devid} and ModelType =10 and Status = 1") |
45 | 43 | List<CalDevContrl> getCalDevContrlWidthDevId(@Param("Devid") String devId); |
... | ... | @@ -47,9 +45,15 @@ public interface DeviceDao { |
47 | 45 | @Select("select * from CalDevBeContrl where State = 1 and Id = #{Id}") |
48 | 46 | CalDevBeContrl getCalDevBeControl(@Param("Id") String Id); |
49 | 47 | |
48 | + @Select("select top 1 * from CalDevBeContrl where State = 1 and ConDevId = #{devId}") | |
49 | + CalDevBeContrl getHWDevControl(@Param("devId") String devId); | |
50 | + | |
50 | 51 | @Select("select * from CalDevContrl where Devid = #{Devid} and Status = 1 and ModelType = 9") |
51 | 52 | List<CalDevContrl> getTempCalWitdDevid(@Param("Devid") String devId); |
52 | 53 | |
54 | + @Select("select top 1* from CalDevContrl where DevBeId = #{beId} and Status = 1 and ModelType = 9") | |
55 | + CalDevContrl getTempDevice(@Param("beId") Integer beId); | |
56 | + | |
53 | 57 | @Select("select clint_id\n" + |
54 | 58 | "from WL_Attendance where school_id = 1085 and clint_type = 12 and state = 1") |
55 | 59 | List<String> getHWDEvices(int i); |
... | ... | @@ -78,4 +82,11 @@ public interface DeviceDao { |
78 | 82 | |
79 | 83 | List<Wl_LinkModeBean> getWL_LinkMode(@Param("SchoolId") String SchoolId); |
80 | 84 | |
85 | + IotDevice getIotDeviceRecord(@Param("devId") String devId, @Param("value") String value,@Param("openTime") String openTime); | |
86 | + | |
87 | + List<Wl_Attendace> getHWAtts(); | |
88 | + | |
89 | + | |
90 | + | |
91 | + | |
81 | 92 | } | ... | ... |
cloud/mypulsar/src/main/java/com/example/mypulsar/enums/EnumEventType.java
0 → 100644
... | ... | @@ -0,0 +1,41 @@ |
1 | +package com.example.mypulsar.enums; | |
2 | + | |
3 | +/** | |
4 | + * Created with IntelliJ IDEA. | |
5 | + * | |
6 | + * @Auther: xuquan | |
7 | + * @Date: 2021/03/31 8:55 | |
8 | + * @Description: | |
9 | + */ | |
10 | +public enum EnumEventType { | |
11 | + | |
12 | + VA_TEMPERATURE("va_temperature", "温度"), | |
13 | + VA_HUMIDITY("va_humidity", "湿度"), | |
14 | + PIR("pir", "人体运动"), | |
15 | + BATTERY("battery", "门磁电池电量值"), | |
16 | + BATTERY_VALUE("battery_value", "电池电量值"), | |
17 | + BATTERY_STATE("battery_state", "电池电量状态"), | |
18 | + BATTERY_PERCENTAGE("battery_percentage", "电池电量百分比"), | |
19 | + SMOKE_SENSOR_STATE("smoke_sensor_state", "烟雾报警"), | |
20 | + CUR_POWER("cur_power", "当前功率"), | |
21 | + CUR_CURRENT("cur_current", "当前电流"), | |
22 | + CUR_VOLTAGE("cur_voltage", "当前电压"), | |
23 | + SWITCH("switch", "门磁状态"), | |
24 | + DOOR_CONTACT_STATE("doorcontact_state", "门磁状态"); | |
25 | + | |
26 | + public final String code; | |
27 | + public final String message; | |
28 | + | |
29 | + public String getCode() { | |
30 | + return code; | |
31 | + } | |
32 | + | |
33 | + public String getMessage() { | |
34 | + return message; | |
35 | + } | |
36 | + | |
37 | + EnumEventType(String code, String message) { | |
38 | + this.code = code; | |
39 | + this.message = message; | |
40 | + } | |
41 | +} | ... | ... |
cloud/mypulsar/src/main/java/com/example/mypulsar/message/MessageVO.java
... | ... | @@ -8,11 +8,25 @@ import java.io.Serializable; |
8 | 8 | */ |
9 | 9 | public class MessageVO implements Serializable { |
10 | 10 | |
11 | - | |
11 | + /** | |
12 | + * 消息体内容 | |
13 | + */ | |
12 | 14 | private String data; |
15 | + /** | |
16 | + * 协议号 | |
17 | + */ | |
13 | 18 | private Integer protocol; |
19 | + /** | |
20 | + * 通信协议号 | |
21 | + */ | |
14 | 22 | private String pv; |
23 | + /** | |
24 | + * 签名 | |
25 | + */ | |
15 | 26 | private String sign; |
27 | + /** | |
28 | + * 时间戳 | |
29 | + */ | |
16 | 30 | private Long t; |
17 | 31 | |
18 | 32 | ... | ... |
cloud/mypulsar/src/main/java/com/example/mypulsar/mqtt/MqttConsumer.java
0 → 100644
... | ... | @@ -0,0 +1,168 @@ |
1 | +package com.example.mypulsar.mqtt; | |
2 | + | |
3 | +import lombok.extern.slf4j.Slf4j; | |
4 | +import org.eclipse.paho.client.mqttv3.*; | |
5 | +import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; | |
6 | +import org.springframework.boot.ApplicationArguments; | |
7 | +import org.springframework.boot.ApplicationRunner; | |
8 | +import org.springframework.stereotype.Component; | |
9 | + | |
10 | +import javax.annotation.PostConstruct; | |
11 | + | |
12 | +/** | |
13 | + * Created with IntelliJ IDEA. | |
14 | + * | |
15 | + * @Auther: xuquan | |
16 | + * @Date: 2021/03/31 16:13 | |
17 | + * @Description: | |
18 | + */ | |
19 | +@Slf4j | |
20 | +public class MqttConsumer{ | |
21 | + | |
22 | + private static MqttClient client; | |
23 | + | |
24 | + @PostConstruct | |
25 | + public void init() { | |
26 | + connect(); | |
27 | + } | |
28 | + | |
29 | + /*** | |
30 | + * @Description: 连接mqtt服务器 | |
31 | + * @Param: [] | |
32 | + * @return: void | |
33 | + * @Author: xuquan | |
34 | + * @Date: 2021/3/31 | |
35 | + */ | |
36 | + private void connect() { | |
37 | + log.info("初始化并启动mqtt......"); | |
38 | + try { | |
39 | + // 1 创建客户端 | |
40 | + getClient(); | |
41 | + // 2 设置配置 | |
42 | + MqttConnectOptions options = getOptions(); | |
43 | + String[] topic = MqttProperties.MQTT_TOPIC.split(","); | |
44 | + // 3 消息发布质量 | |
45 | + int[] qos = getQos(topic.length); | |
46 | + // 4 最后设置 | |
47 | + create(options, topic, qos); | |
48 | + } catch (Exception e) { | |
49 | + log.error("mqtt连接异常:" + e); | |
50 | + } | |
51 | + } | |
52 | + | |
53 | + /*** | |
54 | + * @Description: 创建客户端 | |
55 | + * @Param: [] | |
56 | + * @return: void | |
57 | + * @Author: xuquan | |
58 | + * @Date: 2021/3/31 | |
59 | + */ | |
60 | + public void getClient() { | |
61 | + try { | |
62 | + if (null == client) { | |
63 | + client = new MqttClient(MqttProperties.MQTT_HOST, MqttProperties.MQTT_CLINT_ID, new MemoryPersistence()); | |
64 | + } | |
65 | + log.info("创建mqtt客户端:"); | |
66 | + } catch (Exception e) { | |
67 | + log.error("创建mqtt客户端异常:" +e); | |
68 | + } | |
69 | + } | |
70 | + | |
71 | + /*** | |
72 | + * @Description: 生成mqtt配置对象 | |
73 | + * @Param: [] | |
74 | + * @return: org.eclipse.paho.client.mqttv3.MqttConnectOptions | |
75 | + * @Author: xuquan | |
76 | + * @Date: 2021/3/31 | |
77 | + */ | |
78 | + public MqttConnectOptions getOptions() { | |
79 | + MqttConnectOptions options = new MqttConnectOptions(); | |
80 | + options.setUserName(MqttProperties.MQTT_USER_NAME); | |
81 | + options.setPassword(MqttProperties.SIGN.toCharArray()); | |
82 | + // 设置超时时间 | |
83 | + options.setConnectionTimeout(MqttProperties.MQTT_TIMEOUT); | |
84 | + // 设置会话心跳时间 | |
85 | + options.setKeepAliveInterval(MqttProperties.MQTT_KEEP_ALIVE); | |
86 | + options.setAutomaticReconnect(true); | |
87 | + // 是否清除session | |
88 | + options.setCleanSession(false); | |
89 | + log.info("生成mqtt配置对象"); | |
90 | + return options; | |
91 | + } | |
92 | + | |
93 | + /*** | |
94 | + * @Description: 设置消息发布服务质量 | |
95 | + * @Param: [length] | |
96 | + * @return: int[] | |
97 | + * @Author: xuquan | |
98 | + * @Date: 2021/3/31 | |
99 | + */ | |
100 | + public int[] getQos(int length) { | |
101 | + int[] qos = new int[length]; | |
102 | + for (int i = 0; i < length; i++) { | |
103 | + /** | |
104 | + * MQTT协议中有三种消息发布服务质量: | |
105 | + * | |
106 | + * QOS0: “至多一次”,消息发布完全依赖底层 TCP/IP 网络。会发生消息丢失或重复。这一级别可用于如下情况,环境传感器数据, | |
107 | + * 丢失一次读记录无所谓,因为不久后还会有第二次发送。 | |
108 | + * QOS1: “至少一次”,确保消息到达,但消息重复可能会发生。 | |
109 | + * QOS2: “只有一次”,确保消息到达一次。这一级别可用于如下情况,在计费系统中,消息重复或丢失会导致不正确的结果,资源开销大 | |
110 | + */ | |
111 | + qos[i] = 1; | |
112 | + } | |
113 | + log.info("设置消息发布质量"); | |
114 | + return qos; | |
115 | + } | |
116 | + | |
117 | + /*** | |
118 | + * @Description: 装载各种实例和订阅主题 | |
119 | + * @Param: [options, topic, qos] | |
120 | + * @return: void | |
121 | + * @Author: xuquan | |
122 | + * @Date: 2021/3/31 | |
123 | + */ | |
124 | + public void create(MqttConnectOptions options, String[] topic, int[] qos) { | |
125 | + try { | |
126 | + client.setCallback(new MqttConsumerCallback(client, options, topic, qos)); | |
127 | + log.info("添加回调处理类"); | |
128 | + client.connect(options); | |
129 | + } catch (Exception e) { | |
130 | + log.error("装载实例或订阅主题异常:" + e); | |
131 | + } | |
132 | + } | |
133 | + | |
134 | + /*** | |
135 | + * @Description: 发布主题消息 | |
136 | + * @Param: [topic, msg] | |
137 | + * @return: void | |
138 | + * @Author: xuquan | |
139 | + * @Date: 2021/3/31 | |
140 | + */ | |
141 | + public static void publish(String topic, String msg) { | |
142 | + publish(1, false, topic, msg); | |
143 | + } | |
144 | + | |
145 | + public static void publish(int qos, boolean retained, String topic, String pushMessage) { | |
146 | + MqttMessage message = new MqttMessage(); | |
147 | + message.setQos(qos); | |
148 | + message.setRetained(retained); | |
149 | + message.setPayload(pushMessage.getBytes()); | |
150 | + MqttTopic mTopic = client.getTopic(topic); | |
151 | + if (null == mTopic) { | |
152 | + log.warn("topic:" + topic + " 不存在"); | |
153 | + } | |
154 | + MqttDeliveryToken token; | |
155 | + try { | |
156 | + token = mTopic.publish(message); | |
157 | + token.waitForCompletion(); | |
158 | + if (!token.isComplete()) { | |
159 | + log.info("消息发送成功"); | |
160 | + } | |
161 | + } catch (MqttPersistenceException e) { | |
162 | + e.printStackTrace(); | |
163 | + } catch (MqttException e) { | |
164 | + e.printStackTrace(); | |
165 | + } | |
166 | + } | |
167 | + | |
168 | +} | ... | ... |
cloud/mypulsar/src/main/java/com/example/mypulsar/mqtt/MqttConsumerCallback.java
0 → 100644
... | ... | @@ -0,0 +1,70 @@ |
1 | +package com.example.mypulsar.mqtt; | |
2 | + | |
3 | +import lombok.extern.slf4j.Slf4j; | |
4 | +import org.eclipse.paho.client.mqttv3.*; | |
5 | + | |
6 | +import java.util.Arrays; | |
7 | + | |
8 | +/** | |
9 | + * Created with IntelliJ IDEA. | |
10 | + * | |
11 | + * @Auther: xuquan | |
12 | + * @Date: 2021/03/31 21:51 | |
13 | + * @Description: | |
14 | + */ | |
15 | +@Slf4j | |
16 | +public class MqttConsumerCallback implements MqttCallbackExtended { | |
17 | + | |
18 | + private MqttClient client; | |
19 | + private MqttConnectOptions options; | |
20 | + private String[] topic; | |
21 | + private int[] qos; | |
22 | + | |
23 | + public MqttConsumerCallback(MqttClient client, MqttConnectOptions options, String[] topic, int[] qos) { | |
24 | + this.client = client; | |
25 | + this.options = options; | |
26 | + this.topic = topic; | |
27 | + this.qos = qos; | |
28 | + } | |
29 | + | |
30 | + /*** | |
31 | + * @Description: 断开重连机制 | |
32 | + * @Param: [cause] | |
33 | + * @return: void | |
34 | + * @Author: xuquan | |
35 | + * @Date: 2021/4/1 | |
36 | + */ | |
37 | + @Override | |
38 | + public void connectionLost(Throwable cause) { | |
39 | + log.info("MQTT连接断开,发起重连......"); | |
40 | + try { | |
41 | + if (null != client && !client.isConnected()) { | |
42 | + client.reconnect(); | |
43 | + log.info("尝试重新连接"); | |
44 | + } else { | |
45 | + client.connect(options); | |
46 | + log.info("尝试建立新连接"); | |
47 | + } | |
48 | + } catch (Exception e) { | |
49 | + e.printStackTrace(); | |
50 | + } | |
51 | + } | |
52 | + | |
53 | + /*** | |
54 | + * @Description: 接收到消息调用令牌中调用 | |
55 | + * @Param: [token] | |
56 | + * @return: void | |
57 | + * @Author: xuquan | |
58 | + * @Date: 2021/4/1 | |
59 | + */ | |
60 | + @Override | |
61 | + public void deliveryComplete(IMqttDeliveryToken token) { | |
62 | + log.info("deliveryComplete---------" + Arrays.toString(topic)); | |
63 | + } | |
64 | + | |
65 | + @Override | |
66 | + public void messageArrived(String topic, MqttMessage message) { } | |
67 | + | |
68 | + @Override | |
69 | + public void connectComplete(boolean b, String s) { } | |
70 | +} | |
0 | 71 | \ No newline at end of file | ... | ... |
cloud/mypulsar/src/main/java/com/example/mypulsar/mqtt/MqttProperties.java
0 → 100644
... | ... | @@ -0,0 +1,104 @@ |
1 | +package com.example.mypulsar.mqtt; | |
2 | + | |
3 | +import org.apache.commons.codec.binary.Base64; | |
4 | +import org.apache.logging.log4j.util.PropertiesUtil; | |
5 | + | |
6 | +import javax.crypto.Mac; | |
7 | +import javax.crypto.spec.SecretKeySpec; | |
8 | +import java.io.IOException; | |
9 | +import java.io.InputStream; | |
10 | +import java.nio.charset.Charset; | |
11 | +import java.security.InvalidKeyException; | |
12 | +import java.security.NoSuchAlgorithmException; | |
13 | +import java.util.Properties; | |
14 | + | |
15 | +/** | |
16 | + * Created with IntelliJ IDEA. | |
17 | + * | |
18 | + * @Auther: xuquan | |
19 | + * @Date: 2021/03/31 21:26 | |
20 | + * @Description: | |
21 | + */ | |
22 | +public class MqttProperties { | |
23 | + | |
24 | + public static String MQTT_HOST; | |
25 | + | |
26 | + public static String MQTT_CLINT_ID; | |
27 | + | |
28 | + public static String MQTT_USER_NAME; | |
29 | + | |
30 | + public static String MQTT_PASSWORD; | |
31 | + | |
32 | + public static String MQTT_TOPIC; | |
33 | + | |
34 | + public static Integer MQTT_TIMEOUT; | |
35 | + | |
36 | + public static Integer MQTT_KEEP_ALIVE; | |
37 | + | |
38 | + public static String MQTT_GROUP_ID; | |
39 | + | |
40 | + public static String SIGN; | |
41 | + | |
42 | + | |
43 | + /** | |
44 | + * mqtt配置 | |
45 | + */ | |
46 | + static { | |
47 | + Properties properties = loadMqttProperties(); | |
48 | + MQTT_HOST = properties.getProperty("host"); | |
49 | + MQTT_CLINT_ID = properties.getProperty("clintId"); //+ "@@@9ED96FB6D72C1698"; | |
50 | + MQTT_USER_NAME = properties.getProperty("accessKey"); | |
51 | + MQTT_PASSWORD = properties.getProperty("secretKey"); | |
52 | + MQTT_TOPIC = properties.getProperty("topic"); | |
53 | + MQTT_TIMEOUT = Integer.valueOf(properties.getProperty("timeout")); | |
54 | + MQTT_KEEP_ALIVE = Integer.valueOf(properties.getProperty("keepalive")); | |
55 | + MQTT_GROUP_ID = properties.getProperty("clintId").split("@@@")[0]; | |
56 | + try { | |
57 | + SIGN = macSignature(MQTT_GROUP_ID, MQTT_PASSWORD); | |
58 | + } catch (InvalidKeyException e) { | |
59 | + e.printStackTrace(); | |
60 | + } catch (NoSuchAlgorithmException e) { | |
61 | + e.printStackTrace(); | |
62 | + } | |
63 | + } | |
64 | + | |
65 | + /** | |
66 | + * 加载mqtt配置参数 | |
67 | + * @return | |
68 | + */ | |
69 | + private static Properties loadMqttProperties() { | |
70 | + InputStream inputstream = PropertiesUtil.class.getResourceAsStream("/application.yml"); | |
71 | + Properties properties = new Properties(); | |
72 | + try { | |
73 | + properties.load(inputstream); | |
74 | + return properties; | |
75 | + } catch (IOException e) { | |
76 | + throw new RuntimeException(e); | |
77 | + } finally { | |
78 | + try { | |
79 | + if (inputstream != null) { | |
80 | + inputstream.close(); | |
81 | + } | |
82 | + } catch (IOException e) { | |
83 | + throw new RuntimeException(e); | |
84 | + } | |
85 | + } | |
86 | + } | |
87 | + | |
88 | + /** | |
89 | + * @param text 要签名的文本 | |
90 | + * @param secretKey 阿里云MQ secretKey | |
91 | + * @return 加密后的字符串 | |
92 | + * @throws InvalidKeyException | |
93 | + * @throws NoSuchAlgorithmException | |
94 | + */ | |
95 | + public static String macSignature(String text, String secretKey) throws InvalidKeyException, NoSuchAlgorithmException { | |
96 | + Charset charset = Charset.forName("UTF-8"); | |
97 | + String algorithm = "HmacSHA1"; | |
98 | + Mac mac = Mac.getInstance(algorithm); | |
99 | + mac.init(new SecretKeySpec(secretKey.getBytes(charset), algorithm)); | |
100 | + byte[] bytes = mac.doFinal(text.getBytes(charset)); | |
101 | + return new String(Base64.encodeBase64(bytes), charset); | |
102 | + } | |
103 | + | |
104 | +} | ... | ... |
cloud/mypulsar/src/main/java/com/example/mypulsar/task/SchduledTasks.java
... | ... | @@ -2,11 +2,12 @@ package com.example.mypulsar.task; |
2 | 2 | |
3 | 3 | import com.alibaba.fastjson.JSON; |
4 | 4 | import com.alibaba.fastjson.JSONObject; |
5 | -import com.example.mypulsar.bean.Wl_Attendace; | |
6 | -import com.example.mypulsar.bean.Wl_LinkModeBean; | |
5 | +import com.example.mypulsar.bean.*; | |
7 | 6 | import com.example.mypulsar.campusDao.CampusDao; |
8 | 7 | import com.example.mypulsar.dao.DeviceDao; |
9 | 8 | import com.example.mypulsar.utils.HttpUtil; |
9 | +import com.example.mypulsar.utils.JsonUtils; | |
10 | +import lombok.Data; | |
10 | 11 | import lombok.extern.slf4j.Slf4j; |
11 | 12 | import org.dom4j.Document; |
12 | 13 | import org.dom4j.DocumentException; |
... | ... | @@ -17,6 +18,7 @@ import org.springframework.boot.configurationprocessor.json.JSONArray; |
17 | 18 | import org.springframework.boot.configurationprocessor.json.JSONException; |
18 | 19 | import org.springframework.scheduling.annotation.Scheduled; |
19 | 20 | import org.springframework.stereotype.Component; |
21 | +import org.springframework.util.CollectionUtils; | |
20 | 22 | |
21 | 23 | import java.text.ParseException; |
22 | 24 | import java.text.SimpleDateFormat; |
... | ... | @@ -36,7 +38,7 @@ public class SchduledTasks { |
36 | 38 | |
37 | 39 | public static Map<String, Date> closeDevMap = new HashMap<>(); |
38 | 40 | |
39 | - private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
41 | + private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
40 | 42 | |
41 | 43 | private String closeModel = "{\"mode\":\"0\",\"power\":\"0\",\"remote_id\":\"%s\",\"remote_index\":\"11272\",\"temp\":\"26\",\"wind\":\"0\"}"; |
42 | 44 | |
... | ... | @@ -45,35 +47,46 @@ public class SchduledTasks { |
45 | 47 | |
46 | 48 | @Scheduled(fixedRate = 60000) |
47 | 49 | public void closeAttend() { |
48 | - log.info(".......定时任务执行设备关闭.......,有在线遥控设备数量" + closeDevMap.size()); | |
49 | - Iterator<Map.Entry<String, Date>> it = closeDevMap.entrySet().iterator(); | |
50 | + log.info(".......定时任务执行设备关闭.......,有在线遥控设备数量" + conDevMap.size()); | |
51 | + Iterator<Map.Entry<String, Date>> it = conDevMap.entrySet().iterator(); | |
50 | 52 | while(it.hasNext()) { |
51 | 53 | Map.Entry<String, Date> entry = it.next(); |
52 | 54 | String conBeDeviceId = entry.getKey(); |
53 | 55 | if(conDevMap.containsKey(conBeDeviceId) && conDevMap.get(conBeDeviceId)!=null){ |
56 | + //红外设备 | |
57 | + String name = deviceDao.getWLName(conBeDeviceId); | |
58 | + //获取红外绑定的遥控器ID | |
59 | + String conValue = getRemoteId(deviceDao.getConBeValue(conBeDeviceId)); | |
54 | 60 | Date openTime = entry.getValue(); |
55 | - log.info("在线设备:" + conBeDeviceId + "---在线时间:" + simpleDateFormat.format(entry.getValue())+"当前时间:"+ simpleDateFormat.format(new Date())); | |
56 | - //大于十分钟后关闭设备 | |
57 | - if(((new Date().getTime()) - openTime.getTime()) > 5 * 60 * 1000) { | |
58 | - String conValue = getRemoteId(deviceDao.getConBeValue(conBeDeviceId)); | |
59 | - String name = deviceDao.getWLName(conBeDeviceId); | |
60 | - log.info("开始执行关闭命令, remote_id: {}",conValue); | |
61 | - String response = HttpUtil.addAirCode(String.format(closeModel, conValue), conBeDeviceId, name); | |
62 | - try{ | |
63 | - // 将字符串转为XML | |
64 | - Document doc = DocumentHelper.parseText(response); | |
65 | - // 获取根节点 | |
66 | - Element rootElt = doc.getRootElement(); | |
67 | - // 拿到head节点下的子节点title值 | |
68 | - String title = rootElt.elementTextTrim("code"); | |
69 | - log.info("请求结果:" + title); | |
70 | - if(title.equals("200")){ | |
71 | - conDevMap.remove(conBeDeviceId); | |
61 | + log.info("在线红外设备:" + name + "---在线时间:" + simpleDateFormat.format(openTime)+" 当前时间:"+ simpleDateFormat.format(new Date())); | |
62 | + //获取红外设备 | |
63 | + CalDevBeContrl hwDevice = deviceDao.getHWDevControl(conBeDeviceId); | |
64 | + if(hwDevice !=null){ | |
65 | + Integer beId = hwDevice.getId(); | |
66 | + //获取温感设备 | |
67 | + CalDevContrl calDevContrl = deviceDao.getTempDevice(beId); | |
68 | + //无人状态直接关闭 | |
69 | + boolean isOk = convertDeviceRecord(calDevContrl,openTime); | |
70 | + if(isOk){ | |
71 | + log.info("开始执行关闭命令, remote_id: {}",conValue); | |
72 | + String response = HttpUtil.addAirCode(String.format(closeModel, conValue), conBeDeviceId, name); | |
73 | + try{ | |
74 | + // 将字符串转为XML | |
75 | + Document doc = DocumentHelper.parseText(response); | |
76 | + // 获取根节点 | |
77 | + Element rootElt = doc.getRootElement(); | |
78 | + // 拿到head节点下的子节点title值 | |
79 | + String title = rootElt.elementTextTrim("code"); | |
80 | + log.info("请求结果:" + title); | |
81 | + if(title.equals("200")){ | |
82 | + log.info("关闭成功:设备 :{},遥控ID: {}",name,conValue); | |
83 | + conDevMap.remove(conBeDeviceId); | |
84 | + } | |
85 | + } catch (DocumentException e) { | |
86 | + e.printStackTrace(); | |
87 | + } catch (Exception e) { | |
88 | + e.printStackTrace(); | |
72 | 89 | } |
73 | - } catch (DocumentException e) { | |
74 | - e.printStackTrace(); | |
75 | - } catch (Exception e) { | |
76 | - e.printStackTrace(); | |
77 | 90 | } |
78 | 91 | } |
79 | 92 | } |
... | ... | @@ -81,7 +94,114 @@ public class SchduledTasks { |
81 | 94 | if (!outClose){ |
82 | 95 | initWlModeOut(); |
83 | 96 | } |
84 | - log.info("关闭成功 :" + JSON.toJSONString(conDevMap)); | |
97 | + } | |
98 | + | |
99 | + | |
100 | + /** | |
101 | + * 解析上报记录,判断空间是否是无人状态。 | |
102 | + * 条件:第一次上报无人后,五分钟内没有上报有人记录,则为无人 | |
103 | + * @param calDevContrl | |
104 | + * @param openTime | |
105 | + * @return | |
106 | + */ | |
107 | + private boolean convertDeviceRecord(CalDevContrl calDevContrl,Date openTime){ | |
108 | + if(calDevContrl != null){ | |
109 | + List<String> list = new ArrayList(); | |
110 | + Map map = new HashMap(); | |
111 | + //温感设备ID | |
112 | + String tempDevId =calDevContrl.getDevid(); | |
113 | + //空调开启时间 | |
114 | + String openTimeStr = simpleDateFormat.format(openTime); | |
115 | + //温感关联的人感设备 | |
116 | + String assDevice = calDevContrl.getAssDevice(); | |
117 | + String[] assDeviceIds = assDevice.split(","); | |
118 | + for (int i = 0; i < assDeviceIds.length; i++) { | |
119 | + String deviceId = assDeviceIds[i]; | |
120 | + //过滤温感设备ID | |
121 | + if (!deviceId.equals(tempDevId)) { | |
122 | + list.add(deviceId); | |
123 | + Wl_Attendace attendance = deviceDao.getAttendace(deviceId); | |
124 | + if(attendance==null){ | |
125 | + map.put(deviceId,"true"); | |
126 | + continue; | |
127 | + } | |
128 | + //取得空调开启时间,离最近一次上报无人记录 | |
129 | + IotDevice iotDevice = deviceDao.getIotDeviceRecord(deviceId, "无人", openTimeStr); | |
130 | + log.info("空调开启时间最近一次,无人记录,时间:{}, 设备信息:{}",openTime,JSON.toJSON(iotDevice)); | |
131 | + if(iotDevice != null){ | |
132 | + //五分钟内没有上报有人记录 | |
133 | + String afterTime5 = getDateAddMinute(iotDevice.getTime(),5); | |
134 | + iotDevice = deviceDao.getIotDeviceRecord(deviceId,"有人",afterTime5); | |
135 | + log.info("5分钟之后的有人记录,时间:{}, 设备信息:{}",afterTime5,JSON.toJSON(iotDevice)); | |
136 | + if(iotDevice ==null){ | |
137 | + map.put(deviceId,"true"); | |
138 | + }else{ | |
139 | + map.put(deviceId,"false"); | |
140 | + } | |
141 | + }else{ | |
142 | + map.put(deviceId,"false"); | |
143 | + } | |
144 | + } | |
145 | + } | |
146 | + log.info("设备信息:{}, 上报记录: {}",JSON.toJSON(list),JSON.toJSON(map)); | |
147 | + //false 无人 true 有人,当前后人感都为无人下,返回true | |
148 | + if(!CollectionUtils.isEmpty(list) && !map.isEmpty()){ | |
149 | + if(map.get(list.get(0)).equals("true")&& map.get(list.get(1)).equals("true")){ | |
150 | + return true; | |
151 | + } | |
152 | + } | |
153 | + } | |
154 | + return false; | |
155 | + } | |
156 | + | |
157 | + /** | |
158 | + * 日期叠加计算,以月为单位:整数 | |
159 | + * @param date 起始时间 | |
160 | + * @return | |
161 | + */ | |
162 | + public static String getDateAddMinute(String date,int length) { | |
163 | + Date date1 = stringFormatDate(date,"yyyy-MM-dd HH:mm:ss"); | |
164 | + Calendar cal = Calendar.getInstance(); | |
165 | + cal.setTime(date1);//设置起时间 | |
166 | + cal.add(Calendar.MINUTE,length); | |
167 | + String strDate = dateFormatString(cal.getTime(),"yyyy-MM-dd HH:mm:ss"); | |
168 | + return strDate; | |
169 | + } | |
170 | + | |
171 | + /** | |
172 | + * String 转 Date : 指定格式:pattern | |
173 | + * @param date | |
174 | + * @param pattern | |
175 | + * @return | |
176 | + */ | |
177 | + public static Date stringFormatDate(String date, String pattern) { | |
178 | + SimpleDateFormat simpleDateFormat = null; | |
179 | + if (date != null) { | |
180 | + try{ | |
181 | + simpleDateFormat = new SimpleDateFormat(pattern); | |
182 | + Date retultDate = simpleDateFormat.parse(date); | |
183 | + return retultDate; | |
184 | + }catch (ParseException e){ | |
185 | + e.printStackTrace(); | |
186 | + } | |
187 | + } | |
188 | + return null; | |
189 | + } | |
190 | + | |
191 | + /** | |
192 | + * Date转 String : 指定格式:pattern | |
193 | + * @param date | |
194 | + * @param pattern | |
195 | + * @return | |
196 | + */ | |
197 | + public static String dateFormatString(Date date,String pattern) { | |
198 | + SimpleDateFormat df = null; | |
199 | + String returnValue = null; | |
200 | + if (date != null) { | |
201 | + df = new SimpleDateFormat(pattern); | |
202 | + returnValue = df.format(date); | |
203 | + } | |
204 | + return returnValue; | |
85 | 205 | } |
86 | 206 | |
87 | 207 | |
... | ... | @@ -93,10 +213,14 @@ public class SchduledTasks { |
93 | 213 | } |
94 | 214 | } |
95 | 215 | |
216 | + public static void main(String[] args) { | |
217 | + System.out.println(Calendar.getInstance().get(Calendar.HOUR_OF_DAY)); | |
218 | + } | |
219 | + | |
96 | 220 | /** |
97 | 221 | * 根据物联模板判断是否关闭 |
98 | 222 | */ |
99 | - private void initWlModeOut() { | |
223 | + public void initWlModeOut() { | |
100 | 224 | try { |
101 | 225 | isClose = true; |
102 | 226 | //获取有效的模板 |
... | ... | @@ -122,12 +246,14 @@ public class SchduledTasks { |
122 | 246 | int week = Integer.parseInt(weeks[k]); |
123 | 247 | if (week == indexWeek) { |
124 | 248 | try { |
249 | + //截至时间 | |
125 | 250 | Date endDate = simpleDateFormat.parse(endTime); |
126 | - Date date = simpleDateFormat1.parse(new Date().getHours() + ":" + new Date().getMinutes() + ":" + new Date().getSeconds()); | |
127 | - Date endDate2 = getDateByTime(1,endDate); | |
128 | - long indexTime = date.getTime(); | |
251 | + Date endDate2 = getDateByTime(3,endDate); | |
129 | 252 | long entTime = endDate.getTime(); |
130 | 253 | long entTime2 = endDate2.getTime(); |
254 | + //当前时间 | |
255 | + Date date = simpleDateFormat1.parse(new Date().getHours() + ":" + new Date().getMinutes() + ":" + new Date().getSeconds()); | |
256 | + long indexTime = date.getTime(); | |
131 | 257 | //当前时间等于结束时间触发一次指令 |
132 | 258 | if (indexTime > entTime && indexTime < entTime2) { |
133 | 259 | //关闭所有设备 |
... | ... | @@ -149,10 +275,6 @@ public class SchduledTasks { |
149 | 275 | log.info("关闭设备异常: ",e); |
150 | 276 | } |
151 | 277 | } |
152 | - } else { | |
153 | - //获取红外遥控器 | |
154 | - List<Wl_Attendace> clintIds = deviceDao.getHWIds(); | |
155 | - closeAllDevice(clintIds); | |
156 | 278 | } |
157 | 279 | } catch (Exception e) { |
158 | 280 | log.info("关闭设备异常: ",e); |
... | ... | @@ -170,12 +292,12 @@ public class SchduledTasks { |
170 | 292 | /** |
171 | 293 | * 根据物联模板判断是否关闭 |
172 | 294 | */ |
173 | - private void initWlMode() { | |
295 | + public void initWlMode() { | |
174 | 296 | try { |
175 | 297 | isClose = true; |
176 | 298 | //获取有效的模板 |
177 | 299 | List<Wl_LinkModeBean> wl_linkModes = deviceDao.getWL_LinkMode("1085"); |
178 | - if (null != wl_linkModes) { | |
300 | + if (!CollectionUtils.isEmpty(wl_linkModes)) { | |
179 | 301 | for (int i = 0; i < wl_linkModes.size(); i++) { |
180 | 302 | |
181 | 303 | Wl_LinkModeBean wl_linkModeBean = wl_linkModes.get(i); |
... | ... | @@ -206,7 +328,6 @@ public class SchduledTasks { |
206 | 328 | |
207 | 329 | for (int k = 0; k < weeks.length; k++) { |
208 | 330 | int week = Integer.parseInt(weeks[k]); |
209 | - | |
210 | 331 | if (week == indexWeek) { |
211 | 332 | Date startDate = null; |
212 | 333 | try { |
... | ... | @@ -226,13 +347,11 @@ public class SchduledTasks { |
226 | 347 | List<Wl_Attendace> clintIds = deviceDao.getHWAttsWithRoomId(fieldId); |
227 | 348 | closeAllDevice(clintIds); |
228 | 349 | } |
229 | - | |
230 | 350 | } |
231 | 351 | } catch (ParseException e) { |
232 | 352 | log.info("关闭设备异常: ",e); |
233 | 353 | } |
234 | 354 | } |
235 | - | |
236 | 355 | } |
237 | 356 | } |
238 | 357 | } |
... | ... | @@ -264,10 +383,12 @@ public class SchduledTasks { |
264 | 383 | Element rootElt = doc.getRootElement(); |
265 | 384 | // 拿到head节点下的子节点title值 |
266 | 385 | String title = rootElt.elementTextTrim("code"); |
267 | - log.info("请求结果:" + title); | |
386 | + log.info("请求结果:" + title+" 设备ID : "+ deviceId); | |
268 | 387 | if(title.equals("200")){ |
388 | + log.info("关闭成功:设备 :{},遥控ID: {}",devName,conValue); | |
269 | 389 | conDevMap.remove(deviceId); |
270 | 390 | } |
391 | + System.out.println(i); | |
271 | 392 | } catch (DocumentException e) { |
272 | 393 | e.printStackTrace(); |
273 | 394 | } catch (Exception e) { | ... | ... |
cloud/mypulsar/src/main/java/com/example/mypulsar/utils/ControlUtils.java
... | ... | @@ -63,11 +63,11 @@ public class ControlUtils { |
63 | 63 | try { |
64 | 64 | //联动的时间范围,[{"Week":"5","StartTime":"14:02","EndTime":"14:06"}] |
65 | 65 | if(StringUtils.isEmpty(cal.getInUserTime())){ |
66 | + log.info("人感控制设备ID: {},未设置联动计划。",cal.getDevid()); | |
66 | 67 | continue; |
67 | 68 | } |
68 | 69 | String inUseTime =cal.getInUserTime(); |
69 | 70 | JSONArray jsonArray = new JSONArray(inUseTime); |
70 | - log.info("控制设备ID: {}, 联动时间计划:{}",cal.getDevid(),jsonArray.toString()); | |
71 | 71 | for (int i = 0; i < jsonArray.length(); i++) { |
72 | 72 | JSONObject jsonObject = jsonArray.getJSONObject(i); |
73 | 73 | String weekStr = jsonObject.getString("Week"); | ... | ... |
cloud/mypulsar/src/main/java/com/example/mypulsar/utils/HttpUtil.java
... | ... | @@ -141,9 +141,10 @@ public class HttpUtil { |
141 | 141 | * @param conDevName 设备名称 |
142 | 142 | * @return |
143 | 143 | */ |
144 | - public static String addAirCode(String conValue, String conDevId, String conDevName) { | |
144 | + public static String addAirCode(String conValue, String conDevId, String conDevName) { | |
145 | 145 | try { |
146 | 146 | String url = String.format("http://120.26.116.253:5555/TuYa/%s/addAirCode", conDevId); |
147 | +// String url = String.format("http://120.26.116.253:5555/TuYa/%s/airConditioners", conDevId); | |
147 | 148 | RestTemplate restTemplate = new RestTemplate(); |
148 | 149 | TuYaAirCondition tuYaAirCondition = new TuYaAirCondition(); |
149 | 150 | String power = ""; |
... | ... | @@ -160,9 +161,13 @@ public class HttpUtil { |
160 | 161 | log.info("控制失败:失败信息",e); |
161 | 162 | } |
162 | 163 | log.info("开始发送遥控命令至设备:请求地址: {},设备名称: {},设备ID: {},请求参数: {}",url,conDevName,conDevId,tuYaAirCondition.toString()); |
163 | - String response = restTemplate.postForObject(url, tuYaAirCondition, String.class); | |
164 | + //轮询2次下发指令,防止偶然性第一次没启动 | |
165 | + String response =""; | |
166 | + for(int i=0;i<2;i++){ | |
167 | + Thread.sleep(1000); | |
168 | + response = restTemplate.postForObject(url, tuYaAirCondition, String.class); | |
169 | + } | |
164 | 170 | log.info("返回结果:{}",response); |
165 | -// FileUtils.getInstance().writeLogs(String.format("%s设备%s--控制%s", power.equals("1") ? "成功" : "失败", conDevName + "-" + conDevId, response), FileUtils.addAirCode); | |
166 | 171 | return response; |
167 | 172 | }catch (Exception e){ |
168 | 173 | log.info("请求红外控制指令失败:{}",e); | ... | ... |
cloud/mypulsar/src/main/java/com/example/mypulsar/utils/JsonUtils.java
0 → 100644
... | ... | @@ -0,0 +1,149 @@ |
1 | +package com.example.mypulsar.utils; | |
2 | + | |
3 | +import com.fasterxml.jackson.annotation.JsonInclude.Include; | |
4 | +import com.fasterxml.jackson.core.type.TypeReference; | |
5 | +import com.fasterxml.jackson.databind.DeserializationFeature; | |
6 | +import com.fasterxml.jackson.databind.JavaType; | |
7 | +import com.fasterxml.jackson.databind.ObjectMapper; | |
8 | +import io.micrometer.core.instrument.util.StringUtils; | |
9 | +import org.slf4j.Logger; | |
10 | +import org.slf4j.LoggerFactory; | |
11 | + | |
12 | +import java.io.IOException; | |
13 | +import java.util.Collection; | |
14 | +import java.util.Map; | |
15 | + | |
16 | +/** | |
17 | + * Created with IntelliJ IDEA. | |
18 | + * | |
19 | + * @Auther: xuquan | |
20 | + * @Date: 2021/03/22 14:21 | |
21 | + * @Description: <p> 封装不同的输出风格, 使用不同的builder函数创建实例. </p> | |
22 | + * 简单封装Jackson,实现JSON String<->Java Object的Mapper. | |
23 | + */ | |
24 | +public class JsonUtils { | |
25 | + | |
26 | + private static final Logger LOG = LoggerFactory.getLogger(JsonUtils.class); | |
27 | + | |
28 | + private ObjectMapper mapper; | |
29 | + | |
30 | + public JsonUtils(){ | |
31 | + this(null); | |
32 | + } | |
33 | + | |
34 | + public JsonUtils(Include include) { | |
35 | + mapper = new ObjectMapper(); | |
36 | + // 设置输出时包含属性的风格 | |
37 | + if (include != null) { | |
38 | + mapper.setSerializationInclusion(include); | |
39 | + } | |
40 | + // 设置输入时忽略在JSON字符串中存在但Java对象实际没有的属性 | |
41 | + mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); | |
42 | + } | |
43 | + | |
44 | + /** | |
45 | + * 创建只输出非Null且非Empty(如List.isEmpty)的属性到Json字符串的Mapper,建议在外部接口中使用. | |
46 | + */ | |
47 | + public static JsonUtils nonEmptyMapper() { | |
48 | + return new JsonUtils(Include.NON_EMPTY); | |
49 | + } | |
50 | + | |
51 | + /** | |
52 | + * 创建只输出初始值被改变的属性到Json字符串的Mapper, 最节约的存储方式,建议在内部接口中使用。 | |
53 | + */ | |
54 | + public static JsonUtils nonDefaultMapper() { | |
55 | + return new JsonUtils(Include.NON_DEFAULT); | |
56 | + } | |
57 | + | |
58 | + /** | |
59 | + * Object可以是POJO,也可以是Collection或数组。 | |
60 | + * 如果对象为Null, 返回"null". | |
61 | + * 如果集合为空集合, 返回"[]". | |
62 | + */ | |
63 | + public String toJson(Object object) { | |
64 | + | |
65 | + try { | |
66 | + return mapper.writeValueAsString(object); | |
67 | + } catch (IOException e) { | |
68 | + LOG.warn(String.format("序列化成 JSON 字符串发生错误:%s", object), e); | |
69 | + return null; | |
70 | + } | |
71 | + } | |
72 | + | |
73 | + /** | |
74 | + * 反序列化POJO或简单Collection如List<String>. | |
75 | + * | |
76 | + * 如果JSON字符串为Null或"null"字符串, 返回Null. | |
77 | + * 如果JSON字符串为"[]", 返回空集合. | |
78 | + * | |
79 | + * 如需反序列化复杂Collection如List<MyBean>, 请使用fromJson(String, JavaType) | |
80 | + * | |
81 | + * @see #fromJson(String, JavaType) | |
82 | + */ | |
83 | + public <T> T fromJson(String jsonString, Class<T> clazz) { | |
84 | + if (StringUtils.isEmpty(jsonString)) { | |
85 | + return null; | |
86 | + } | |
87 | + | |
88 | + try { | |
89 | + return mapper.readValue(jsonString, clazz); | |
90 | + } catch (IOException e) { | |
91 | + LOG.error(String.format("解析 JSON 字符串发生错误:%s", jsonString), e); | |
92 | + return null; | |
93 | + } | |
94 | + } | |
95 | + | |
96 | + /** | |
97 | + * 反序列化泛型对象 | |
98 | + * @param <T> | |
99 | + * @param jsonString | |
100 | + * @param typeReference | |
101 | + * @return | |
102 | + */ | |
103 | + public <T> T fromJson(String jsonString, TypeReference<T> typeReference) { | |
104 | + if (StringUtils.isEmpty(jsonString)) { | |
105 | + return null; | |
106 | + } | |
107 | + | |
108 | + try { | |
109 | + return mapper.readValue(jsonString, typeReference); | |
110 | + } catch (IOException e) { | |
111 | + LOG.error(String.format("解析 JSON 字符串发生错误:%s", jsonString), e); | |
112 | + return null; | |
113 | + } | |
114 | + } | |
115 | + | |
116 | + /** | |
117 | + * 反序列化复杂Collection如List<Bean>, 先使用createCollectionType()或contructMapType()构造类型, 然后调用本函数. | |
118 | + * | |
119 | + * @see #(Class, Class...) | |
120 | + */ | |
121 | + public <T> T fromJson(String jsonString, JavaType javaType) { | |
122 | + if (StringUtils.isEmpty(jsonString)) { | |
123 | + return null; | |
124 | + } | |
125 | + | |
126 | + try { | |
127 | + return mapper.readValue(jsonString, javaType); | |
128 | + } catch (IOException e) { | |
129 | + LOG.error(String.format("解析 JSON 字符串发生错误:%s", jsonString), e); | |
130 | + return null; | |
131 | + } | |
132 | + } | |
133 | + | |
134 | + /** | |
135 | + * 构造Collection类型. | |
136 | + */ | |
137 | + public JavaType contructCollectionType(Class<? extends Collection> collectionClass, Class<?> elementClass) { | |
138 | + return mapper.getTypeFactory().constructCollectionType(collectionClass, elementClass); | |
139 | + } | |
140 | + | |
141 | + /** | |
142 | + * 构造Map类型. | |
143 | + */ | |
144 | + public JavaType contructMapType(Class<? extends Map> mapClass, Class<?> keyClass, Class<?> valueClass) { | |
145 | + return mapper.getTypeFactory().constructMapType(mapClass, keyClass, valueClass); | |
146 | + } | |
147 | + | |
148 | + | |
149 | +} | ... | ... |
cloud/mypulsar/src/main/resources/application.yaml
... | ... | @@ -1,41 +0,0 @@ |
1 | -server: | |
2 | - port: 10009 | |
3 | - | |
4 | -spring: | |
5 | - profiles: | |
6 | - active: dev | |
7 | - application: | |
8 | - name: mypulsar | |
9 | - datasource: | |
10 | - iotplat: | |
11 | - username: szjxtuser | |
12 | - password: RQminVCJota3H1u8bBYH | |
13 | - jdbc-url: jdbc:sqlserver://116.62.155.137:33419;database=IotPlatform | |
14 | - driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver | |
15 | - campus: | |
16 | - username: szjxtuser | |
17 | - password: RQminVCJota3H1u8bBYH | |
18 | - jdbc-url: jdbc:sqlserver://116.62.155.137:33419;database=SmartCampus | |
19 | - driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver | |
20 | - | |
21 | -mybatis: | |
22 | - campus: | |
23 | - type-aliases-package: com.example.mypulsar.campusDao | |
24 | - mapper-locations: classpath:mapper/*.xml | |
25 | - iotplat: | |
26 | - type-aliases-package: com.example.mypulsar.dao | |
27 | - mapper-locations: classpath:iotmapper/*.xml | |
28 | - config-location: classpath:mybatis-config.xml | |
29 | - | |
30 | - | |
31 | - | |
32 | -eureka: | |
33 | - instance: | |
34 | - hostname: localhost | |
35 | - lease-expiration-duration-in-seconds: 60 | |
36 | - lease-renewal-interval-in-seconds: 10 | |
37 | - client: | |
38 | - service-url: | |
39 | - # defaultZone: http://localhost:8761/eureka/ | |
40 | - defaultZone: http://121.40.109.21:8761/eureka/,http://121.40.109.21:8762/eureka/ | |
41 | - |
... | ... | @@ -0,0 +1,57 @@ |
1 | +server: | |
2 | + port: 10009 | |
3 | + | |
4 | +spring: | |
5 | + profiles: | |
6 | + active: dev | |
7 | + application: | |
8 | + name: mypulsar | |
9 | + datasource: | |
10 | + iotplat: | |
11 | + username: szjxtuser | |
12 | + password: RQminVCJota3H1u8bBYH | |
13 | + jdbc-url: jdbc:sqlserver://116.62.155.137:33419;database=IotPlatform | |
14 | + driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver | |
15 | + campus: | |
16 | + username: szjxtuser | |
17 | + password: RQminVCJota3H1u8bBYH | |
18 | + jdbc-url: jdbc:sqlserver://116.62.155.137:33419;database=SmartCampus | |
19 | + driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver | |
20 | + # MQTT | |
21 | + mqtt: | |
22 | + # 服务器连接地址,如果有多个,用逗号隔开 | |
23 | + host: tcp://post-cn-4590mq2hr03.mqtt.aliyuncs.com:1883 | |
24 | + # 连接服务器默认客户端ID 格式:groupId + @@@ + IOT2021 | |
25 | + clintId: GID_IOTSERVER2021@@@IOT2021 | |
26 | + # 默认的消息推送主题,如果有多个,用逗号隔开 | |
27 | + topic: Topic_Quene_Test | |
28 | + # 用户名 | |
29 | + accessKey: UimvLVp0Wj90P88u | |
30 | + # 密码 | |
31 | + secretKey: TE4rZenITG27tiQqHx9qINjx71Nws7 | |
32 | + # 连接超时 | |
33 | + timeout: 30 | |
34 | + # 心跳 | |
35 | + keepalive: 30 | |
36 | + | |
37 | +mybatis: | |
38 | + campus: | |
39 | + type-aliases-package: com.example.mypulsar.campusDao | |
40 | + mapper-locations: classpath:mapper/*.xml | |
41 | + iotplat: | |
42 | + type-aliases-package: com.example.mypulsar.dao | |
43 | + mapper-locations: classpath:iotmapper/*.xml | |
44 | + config-location: classpath:mybatis-config.xml | |
45 | + | |
46 | + | |
47 | + | |
48 | +eureka: | |
49 | + instance: | |
50 | + hostname: localhost | |
51 | + lease-expiration-duration-in-seconds: 60 | |
52 | + lease-renewal-interval-in-seconds: 10 | |
53 | + client: | |
54 | + service-url: | |
55 | + # defaultZone: http://localhost:8761/eureka/ | |
56 | + defaultZone: http://121.40.109.21:8761/eureka/,http://121.40.109.21:8762/eureka/ | |
57 | + | ... | ... |
cloud/mypulsar/src/main/resources/iotmapper/iotmapper.xml
... | ... | @@ -7,31 +7,29 @@ |
7 | 7 | </select>--> |
8 | 8 | <select id="getHWAttsWithRoomId" parameterType="java.lang.String" |
9 | 9 | resultType="com.example.mypulsar.bean.Wl_Attendace"> |
10 | - | |
11 | 10 | select clint_id from WL_Attendance where belongAreaId = ${belongAreaId} and state = 1 and clint_type = 12; |
12 | - | |
13 | 11 | </select> |
14 | 12 | |
15 | 13 | <!-- 插入遥控器数据--> |
16 | 14 | <insert id="insertCalDevBeControl" parameterType="com.example.mypulsar.bean.CalDevBeContrl" |
17 | 15 | databaseId="java.lang.Long"> |
18 | - | |
19 | 16 | insert into CalDevBeContrl values |
20 | 17 | (${ConDevId},${ConCode},${ConValue},${CreateTime},${CreateUserId},${State},${ModeId}) |
21 | - | |
22 | 18 | </insert> |
23 | 19 | |
24 | 20 | <!-- 新建联动模板--> |
25 | 21 | |
26 | 22 | <select id="getWL_LinkMode" parameterType="java.lang.String" resultType="com.example.mypulsar.bean.Wl_LinkModeBean"> |
27 | - | |
28 | 23 | select * from WL_LinkageMode where SchoolId = ${SchoolId} and State = 1; |
29 | - | |
30 | 24 | </select> |
31 | 25 | |
26 | + <select id="getIotDeviceRecord" resultType="com.example.mypulsar.bean.IotDevice"> | |
27 | + select top 1 devId,code,value,time,dev_status from Iot_Device where devId = #{devId} and [value] = #{value} | |
28 | + and dev_status = 1 and code = 'pir' and dev_type =3 and time > #{openTime} ORDER BY time asc | |
29 | + </select> | |
32 | 30 | |
33 | - <!--<select id="selectUser" resultType="com.shunzhi.mqtt2kanban.bean.User">--> | |
34 | - <!--SELECT * FROM user--> | |
35 | - <!--</select>--> | |
31 | + <select id="getHWAtts" parameterType="java.lang.String" resultType="com.example.mypulsar.bean.Wl_Attendace"> | |
32 | + select * from WL_Attendance where state = 1 and clint_type = 12 and school_id = 1085; | |
33 | + </select> | |
36 | 34 | |
37 | 35 | </mapper> |
38 | 36 | \ No newline at end of file | ... | ... |
cloud/mypulsar/src/test/java/com/example/mypulsar/MypulsarApplicationTests.java
... | ... | @@ -3,11 +3,17 @@ package com.example.mypulsar; |
3 | 3 | import com.alibaba.fastjson.JSON; |
4 | 4 | import com.alibaba.fastjson.JSONObject; |
5 | 5 | import com.example.mypulsar.bean.ClassRoom; |
6 | +import com.example.mypulsar.bean.DeviceBean; | |
6 | 7 | import com.example.mypulsar.bean.Wl_Attendace; |
7 | 8 | import com.example.mypulsar.bean.Wl_LinkModeBean; |
8 | 9 | import com.example.mypulsar.campusDao.CampusDao; |
9 | 10 | import com.example.mypulsar.dao.DeviceDao; |
11 | +import com.example.mypulsar.mq.AESBase64Utils; | |
12 | +import com.example.mypulsar.mqtt.MqttConsumer; | |
13 | +import com.example.mypulsar.task.SchduledTasks; | |
10 | 14 | import com.example.mypulsar.utils.HttpUtil; |
15 | +import com.example.mypulsar.utils.JsonUtils; | |
16 | +import com.google.gson.JsonObject; | |
11 | 17 | import org.junit.Test; |
12 | 18 | import org.junit.runner.RunWith; |
13 | 19 | import org.slf4j.Logger; |
... | ... | @@ -15,6 +21,7 @@ import org.slf4j.LoggerFactory; |
15 | 21 | import org.springframework.beans.factory.annotation.Autowired; |
16 | 22 | import org.springframework.boot.test.context.SpringBootTest; |
17 | 23 | import org.springframework.test.context.junit4.SpringRunner; |
24 | +import springfox.documentation.spring.web.json.Json; | |
18 | 25 | |
19 | 26 | import java.util.List; |
20 | 27 | |
... | ... | @@ -49,6 +56,28 @@ public class MypulsarApplicationTests { |
49 | 56 | |
50 | 57 | } |
51 | 58 | |
59 | + private MqttConsumer mqttConsumer; | |
60 | + private String accesskey = "T6dtGFMEs35U4la176032PCis5q6em3h"; | |
61 | + | |
62 | + @Test | |
63 | + public void test() throws Exception { | |
64 | + DeviceBean deviceBean = new DeviceBean(); | |
65 | + deviceBean.setDataId(""); | |
66 | + deviceBean.setBizCode(""); | |
67 | + deviceBean.setDevId("6c81dd58689d0b0e53rrwz"); | |
68 | + deviceBean.setValue("19"); | |
69 | + deviceBean.setDev_status(1); | |
70 | + deviceBean.setCode("battery_percentage"); | |
71 | + deviceBean.setDev_type(2); | |
72 | + deviceBean.setTime("2021-04-08"); | |
73 | + String json = JsonUtils.nonDefaultMapper().toJson(deviceBean); | |
74 | + String data = AESBase64Utils.encrypt(json,accesskey.substring(8, 24)); | |
75 | + if(mqttConsumer == null){ | |
76 | + mqttConsumer = new MqttConsumer(); | |
77 | + mqttConsumer.init(); | |
78 | + } | |
79 | + mqttConsumer.publish("Topic_Quene_Test",data); | |
80 | + } | |
52 | 81 | |
53 | 82 | @Test |
54 | 83 | public void contextLoads() { |
... | ... | @@ -105,7 +134,6 @@ public class MypulsarApplicationTests { |
105 | 134 | } |
106 | 135 | |
107 | 136 | private String getRemoteId(String conValue) { |
108 | - | |
109 | 137 | try { |
110 | 138 | JSONObject jsonObject = JSON.parseObject(conValue); |
111 | 139 | if (null == jsonObject) return ""; | ... | ... |