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,6 +37,7 @@ import java.io.IOException; | ||
| 37 | import java.io.UnsupportedEncodingException; | 37 | import java.io.UnsupportedEncodingException; |
| 38 | import java.text.SimpleDateFormat; | 38 | import java.text.SimpleDateFormat; |
| 39 | import java.util.*; | 39 | import java.util.*; |
| 40 | +import java.util.concurrent.CopyOnWriteArrayList; | ||
| 40 | 41 | ||
| 41 | @Component | 42 | @Component |
| 42 | @Slf4j | 43 | @Slf4j |
| @@ -72,7 +73,6 @@ public class MyTask implements ApplicationRunner { | @@ -72,7 +73,6 @@ public class MyTask implements ApplicationRunner { | ||
| 72 | //设备断线 | 73 | //设备断线 |
| 73 | public static boolean isFirstAutoRegister = false; | 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 | @Override | 77 | @Override |
| 78 | public void run(ApplicationArguments args) throws Exception { | 78 | public void run(ApplicationArguments args) throws Exception { |
| @@ -143,7 +143,9 @@ public class MyTask implements ApplicationRunner { | @@ -143,7 +143,9 @@ public class MyTask implements ApplicationRunner { | ||
| 143 | String deviceId = getDeviceId(pchDVRIP, nDVRPort); | 143 | String deviceId = getDeviceId(pchDVRIP, nDVRPort); |
| 144 | log.info("DisConnect Device: {}, IP: {}, Port: {}",deviceId,pchDVRIP,nDVRPort); | 144 | log.info("DisConnect Device: {}, IP: {}, Port: {}",deviceId,pchDVRIP,nDVRPort); |
| 145 | if (!StringUtils.isEmpty(deviceId)) { | 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 | GateModule.stopRealLoadPic(attachLongMap.get(deviceId)); | 149 | GateModule.stopRealLoadPic(attachLongMap.get(deviceId)); |
| 148 | //移除在线 | 150 | //移除在线 |
| 149 | removeDevice(deviceId); | 151 | removeDevice(deviceId); |
| @@ -169,7 +171,9 @@ public class MyTask implements ApplicationRunner { | @@ -169,7 +171,9 @@ public class MyTask implements ApplicationRunner { | ||
| 169 | String deviceId = getDeviceId(pchDVRIP, nDVRPort); | 171 | String deviceId = getDeviceId(pchDVRIP, nDVRPort); |
| 170 | log.info("ReConnect Device: {},IP: {},Port: {}", deviceId,pchDVRIP, nDVRPort); | 172 | log.info("ReConnect Device: {},IP: {},Port: {}", deviceId,pchDVRIP, nDVRPort); |
| 171 | if (!StringUtils.isEmpty(deviceId)) { | 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 | DeviceInfoBean deviceInfoBean = new DeviceInfoBean(); | 177 | DeviceInfoBean deviceInfoBean = new DeviceInfoBean(); |
| 174 | deviceInfoBean.setDevcieId(deviceId); | 178 | deviceInfoBean.setDevcieId(deviceId); |
| 175 | deviceInfoBean.setDeviceIp(pchDVRIP); | 179 | deviceInfoBean.setDeviceIp(pchDVRIP); |
| @@ -226,7 +230,7 @@ public class MyTask implements ApplicationRunner { | @@ -226,7 +230,7 @@ public class MyTask implements ApplicationRunner { | ||
| 226 | log.info("Register Device Info Device address: {},port: {},DeviceID: {}", pIp, wPort, deviceId); | 230 | log.info("Register Device Info Device address: {},port: {},DeviceID: {}", pIp, wPort, deviceId); |
| 227 | log.info("EM_LISTEN_TYPE:设备注册携带序列号"); | 231 | log.info("EM_LISTEN_TYPE:设备注册携带序列号"); |
| 228 | //保存设备 | 232 | //保存设备 |
| 229 | - saveAttendanceService(deviceId,pIp,wPort); | 233 | + saveAttendanceService(deviceId,pIp,wPort,1); |
| 230 | CDevInfo dev = new CDevInfo(); | 234 | CDevInfo dev = new CDevInfo(); |
| 231 | System.arraycopy(pIp.getBytes(),0,dev.address,0,pIp.getBytes().length); | 235 | System.arraycopy(pIp.getBytes(),0,dev.address,0,pIp.getBytes().length); |
| 232 | dev.port=wPort; | 236 | dev.port=wPort; |
| @@ -391,7 +395,18 @@ public class MyTask implements ApplicationRunner { | @@ -391,7 +395,18 @@ public class MyTask implements ApplicationRunner { | ||
| 391 | if (!path.exists()) { | 395 | if (!path.exists()) { |
| 392 | path.mkdir(); | 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 | if (dwAlarmType == NetSDKLib.EVENT_IVS_ACCESS_CTL) { | 411 | if (dwAlarmType == NetSDKLib.EVENT_IVS_ACCESS_CTL) { |
| 397 | NetSDKLib.DEV_EVENT_ACCESS_CTL_INFO msg = new NetSDKLib.DEV_EVENT_ACCESS_CTL_INFO(); | 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,11 +418,9 @@ public class MyTask implements ApplicationRunner { | ||
| 403 | String userId = new String(msg.szUserID).trim(); | 418 | String userId = new String(msg.szUserID).trim(); |
| 404 | //开门错误码 | 419 | //开门错误码 |
| 405 | int messageCode = msg.nErrorCode; | 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 | log.info("设备ID: {}, 开门用户ID: {}, 开门卡号: {}",szSn,userId,card); | 421 | log.info("设备ID: {}, 开门用户ID: {}, 开门卡号: {}",szSn,userId,card); |
| 422 | + //处理心跳 | ||
| 423 | + saveAttendanceService(szSn,"",0,1); | ||
| 411 | try { | 424 | try { |
| 412 | if (!StringUtils.isEmpty(card)) { | 425 | if (!StringUtils.isEmpty(card)) { |
| 413 | // 保存图片,获取图片缓存 | 426 | // 保存图片,获取图片缓存 |
| @@ -428,7 +441,6 @@ public class MyTask implements ApplicationRunner { | @@ -428,7 +441,6 @@ public class MyTask implements ApplicationRunner { | ||
| 428 | outOrIn= StringUtils.isEmpty(attendanceBean.getOutOrIn())?0:Integer.parseInt(attendanceBean.getOutOrIn()); | 441 | outOrIn= StringUtils.isEmpty(attendanceBean.getOutOrIn())?0:Integer.parseInt(attendanceBean.getOutOrIn()); |
| 429 | } | 442 | } |
| 430 | } | 443 | } |
| 431 | - | ||
| 432 | /** | 444 | /** |
| 433 | * 卡号取反(大写) | 445 | * 卡号取反(大写) |
| 434 | * 注:若设备为一体机、且非"126上虞城东小学、393上虞实验中学"学校,卡则取反 | 446 | * 注:若设备为一体机、且非"126上虞城东小学、393上虞实验中学"学校,卡则取反 |
| @@ -569,14 +581,14 @@ public class MyTask implements ApplicationRunner { | @@ -569,14 +581,14 @@ public class MyTask implements ApplicationRunner { | ||
| 569 | * @param ip | 581 | * @param ip |
| 570 | * @param port | 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 | String clintType = String.valueOf(EnumDeviceType.DH_FACE.deviceType); | 586 | String clintType = String.valueOf(EnumDeviceType.DH_FACE.deviceType); |
| 574 | if(deviceId.startsWith("ytj")){ | 587 | if(deviceId.startsWith("ytj")){ |
| 575 | clintType = String.valueOf(EnumDeviceType.DH_FACE_YTJ.deviceType); | 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,7 +722,7 @@ public class MyTask implements ApplicationRunner { | ||
| 710 | log.info("设备ID集: "+ JsonUtils.nonDefaultMapper().toJson(kanbanIds)); | 722 | log.info("设备ID集: "+ JsonUtils.nonDefaultMapper().toJson(kanbanIds)); |
| 711 | for (String kanbanId : kanbanIds) { | 723 | for (String kanbanId : kanbanIds) { |
| 712 | String data = "{\"cmd\":\"" + 34 + "\",\"clientId\":\"" + kanbanId + "\",\"data\":{\"cardNum\":\"" + cardNum + "\",\"inOrOut\":\"" + inOrOut + "\"}}"; | 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 | mqttManager.sendMqQD(kanbanId, data); | 726 | mqttManager.sendMqQD(kanbanId, data); |
| 715 | } | 727 | } |
| 716 | } else { | 728 | } else { |
| @@ -729,7 +741,7 @@ public class MyTask implements ApplicationRunner { | @@ -729,7 +741,7 @@ public class MyTask implements ApplicationRunner { | ||
| 729 | for (int i = 0; i < clintIds.size(); i++) { | 741 | for (int i = 0; i < clintIds.size(); i++) { |
| 730 | String clintId = clintIds.get(i); | 742 | String clintId = clintIds.get(i); |
| 731 | String data = "{\"cmd\":\"" + 34 + "\",\"clientId\":\"" + clintId + "\",\"data\":{\"cardNum\":\"" + cardNum + "\",\"inOrOut\":\"" + inOrOut + "\"}}"; | 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 | mqttManager.sendMqQD(clintId, data); | 745 | mqttManager.sendMqQD(clintId, data); |
| 734 | } | 746 | } |
| 735 | } | 747 | } |
| @@ -743,11 +755,9 @@ public class MyTask implements ApplicationRunner { | @@ -743,11 +755,9 @@ public class MyTask implements ApplicationRunner { | ||
| 743 | 755 | ||
| 744 | public static boolean openDoor(NetSDKLib.LLong lLong) { | 756 | public static boolean openDoor(NetSDKLib.LLong lLong) { |
| 745 | open.nChannelID = 0; | 757 | open.nChannelID = 0; |
| 746 | - | ||
| 747 | open.write(); | 758 | open.write(); |
| 748 | boolean openSuccess = LoginModule.netsdk.CLIENT_ControlDeviceEx(lLong, NetSDKLib.CtrlType.CTRLTYPE_CTRL_ACCESS_OPEN, open.getPointer(), null, 5000); | 759 | boolean openSuccess = LoginModule.netsdk.CLIENT_ControlDeviceEx(lLong, NetSDKLib.CtrlType.CTRLTYPE_CTRL_ACCESS_OPEN, open.getPointer(), null, 5000); |
| 749 | open.read(); | 760 | open.read(); |
| 750 | - | ||
| 751 | if (!openSuccess) { | 761 | if (!openSuccess) { |
| 752 | log.warn("open Door error: 0x: "+ Long.toHexString(LoginModule.netsdk.CLIENT_GetLastError())); | 762 | log.warn("open Door error: 0x: "+ Long.toHexString(LoginModule.netsdk.CLIENT_GetLastError())); |
| 753 | return false; | 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,10 +8,15 @@ import com.example.dahua.bean.WGBean; | ||
| 8 | import com.example.dahua.dao.UserDao; | 8 | import com.example.dahua.dao.UserDao; |
| 9 | import com.example.dahua.lib.Utils; | 9 | import com.example.dahua.lib.Utils; |
| 10 | import com.example.dahua.mqtt.MqttManager; | 10 | import com.example.dahua.mqtt.MqttManager; |
| 11 | +import com.example.dahua.service.UserOperateService; | ||
| 11 | import com.example.dahua.utils.DateFormatUtil; | 12 | import com.example.dahua.utils.DateFormatUtil; |
| 12 | import com.example.dahua.utils.DateUtils; | 13 | import com.example.dahua.utils.DateUtils; |
| 13 | import com.example.dahua.utils.FileUtils; | 14 | import com.example.dahua.utils.FileUtils; |
| 15 | +import com.example.dahua.xiananDao.SearchMapper; | ||
| 14 | import com.example.dahua.xiananDao.SendRecordDao; | 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 | import org.json.JSONException; | 20 | import org.json.JSONException; |
| 16 | import org.json.JSONObject; | 21 | import org.json.JSONObject; |
| 17 | import org.springframework.beans.factory.annotation.Autowired; | 22 | import org.springframework.beans.factory.annotation.Autowired; |
| @@ -33,7 +38,11 @@ import java.io.*; | @@ -33,7 +38,11 @@ import java.io.*; | ||
| 33 | import java.text.ParseException; | 38 | import java.text.ParseException; |
| 34 | import java.text.SimpleDateFormat; | 39 | import java.text.SimpleDateFormat; |
| 35 | import java.util.*; | 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 | @Component | 46 | @Component |
| 38 | public class MyScheduledTask { | 47 | public class MyScheduledTask { |
| 39 | 48 | ||
| @@ -89,7 +98,7 @@ public class MyScheduledTask { | @@ -89,7 +98,7 @@ public class MyScheduledTask { | ||
| 89 | /** | 98 | /** |
| 90 | * 订阅任务 20秒执行一次 | 99 | * 订阅任务 20秒执行一次 |
| 91 | */ | 100 | */ |
| 92 | - @Scheduled(fixedDelay= 5000) | 101 | + @Scheduled(fixedDelay= 10000) |
| 93 | protected synchronized void reloadPic2(){ | 102 | protected synchronized void reloadPic2(){ |
| 94 | //登录 | 103 | //登录 |
| 95 | if (myTasks.isHasNewDevice) { | 104 | if (myTasks.isHasNewDevice) { |
| @@ -100,6 +109,83 @@ public class MyScheduledTask { | @@ -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,12 +283,10 @@ public class MyScheduledTask { | ||
| 197 | isSendMQ = true; | 283 | isSendMQ = true; |
| 198 | String fileName = simpleDateFormat.format(new Date()); | 284 | String fileName = simpleDateFormat.format(new Date()); |
| 199 | String filePath = "D:\\wg_log\\info\\kaoInfo\\" + fileName + ".log"; | 285 | String filePath = "D:\\wg_log\\info\\kaoInfo\\" + fileName + ".log"; |
| 200 | -// String filePath = "C:\\Users\\Administrator\\Desktop\\2020-04-30 08.log"; | ||
| 201 | if (!readLineMap.containsKey(fileName)) readLineNum = -1;//更新文件后从头开始 | 286 | if (!readLineMap.containsKey(fileName)) readLineNum = -1;//更新文件后从头开始 |
| 202 | File file = new File(filePath); | 287 | File file = new File(filePath); |
| 203 | try { | 288 | try { |
| 204 | if (!file.exists()) { | 289 | if (!file.exists()) { |
| 205 | -// System.out.println("文件不存在:" + filePath); | ||
| 206 | return; | 290 | return; |
| 207 | } | 291 | } |
| 208 | FileInputStream fileInputStream = new FileInputStream(file); | 292 | FileInputStream fileInputStream = new FileInputStream(file); |
| @@ -213,16 +297,12 @@ public class MyScheduledTask { | @@ -213,16 +297,12 @@ public class MyScheduledTask { | ||
| 213 | int indexLineNum = 0;//当前文件的行 | 297 | int indexLineNum = 0;//当前文件的行 |
| 214 | while ((content = bufferedReader.readLine()) != null) { | 298 | while ((content = bufferedReader.readLine()) != null) { |
| 215 | indexLineNum++; | 299 | indexLineNum++; |
| 216 | -// System.out.println("indexLineNum:"+indexLineNum+" ----------readLineNum:"+readLineNum); | ||
| 217 | if (indexLineNum >= readLineNum) { | 300 | if (indexLineNum >= readLineNum) { |
| 218 | readLineNum++; | 301 | readLineNum++; |
| 219 | sendMQMess(content); | 302 | sendMQMess(content); |
| 220 | } | 303 | } |
| 221 | - | ||
| 222 | } | 304 | } |
| 223 | - | ||
| 224 | readLineMap.put(fileName, readLineNum); | 305 | readLineMap.put(fileName, readLineNum); |
| 225 | - | ||
| 226 | fileInputStream.close(); | 306 | fileInputStream.close(); |
| 227 | bufferedReader.close(); | 307 | bufferedReader.close(); |
| 228 | 308 | ||
| @@ -254,32 +334,36 @@ public class MyScheduledTask { | @@ -254,32 +334,36 @@ public class MyScheduledTask { | ||
| 254 | 334 | ||
| 255 | String qiandaoDevId = content.substring(content.indexOf("设备") + 3, content.indexOf("设备") + 12); | 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 | //获取寝室关联的场景id | 342 | //获取寝室关联的场景id |
| 258 | String placeId = userDao.getPlaceIdWithKaoqinDevid(qiandaoDevId); | 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 | String data = "{\"cmd\":\"" + 34 + "\",\"clientId\":\"" + clintId + "\",\"data\":{\"cardNum\":\"" + cardNum + "\",\"inOrOut\":\"" + inOrOut + "\"}}"; | 363 | String data = "{\"cmd\":\"" + 34 + "\",\"clientId\":\"" + clintId + "\",\"data\":{\"cardNum\":\"" + cardNum + "\",\"inOrOut\":\"" + inOrOut + "\"}}"; |
| 278 | mqttManager.sendMqQD(clintId, data); | 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 @@ | @@ -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 @@ | @@ -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,7 +247,7 @@ public class SendUserInfoTask2 { | ||
| 247 | if (!StringUtils.isEmpty(deviceId)) { | 247 | if (!StringUtils.isEmpty(deviceId)) { |
| 248 | sendRecordBean.setFailType(EnumSendFaceType.FACE_AND_CARD_FAIL.code); | 248 | sendRecordBean.setFailType(EnumSendFaceType.FACE_AND_CARD_FAIL.code); |
| 249 | sendRecordBean.setFailContent(EnumSendFaceType.NOT_ONLINE_DEVICE.message); | 249 | sendRecordBean.setFailContent(EnumSendFaceType.NOT_ONLINE_DEVICE.message); |
| 250 | - baseService.sendFailRecord(sendRecordBean); | 250 | + baseService.sendFailRecord(sendRecordBean,channel); |
| 251 | } | 251 | } |
| 252 | } else { | 252 | } else { |
| 253 | log.info("=================开始执行下发人脸及卡号任务================="); | 253 | log.info("=================开始执行下发人脸及卡号任务================="); |
| @@ -311,7 +311,7 @@ public class SendUserInfoTask2 { | @@ -311,7 +311,7 @@ public class SendUserInfoTask2 { | ||
| 311 | FileUtils.getInstance().writeLogs("下发人脸和卡号成功:" + cardNum + " " + attendanceBean.getClint_id(), FileUtils.sendUserSucTxt); | 311 | FileUtils.getInstance().writeLogs("下发人脸和卡号成功:" + cardNum + " " + attendanceBean.getClint_id(), FileUtils.sendUserSucTxt); |
| 312 | log.info("下发人脸和卡号成功, sendRecordBean: "+ JSON.toJSONString(sendRecordBean)); | 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,7 +323,7 @@ public class SendUserInfoTask2 { | ||
| 323 | String failContent = analysisErrorMsg(bUserFlags,bFaceFalgs,bCardFlags); | 323 | String failContent = analysisErrorMsg(bUserFlags,bFaceFalgs,bCardFlags); |
| 324 | sendRecordBean.setFailType(EnumSendFaceType.FACE_AND_CARD_FAIL.code); | 324 | sendRecordBean.setFailType(EnumSendFaceType.FACE_AND_CARD_FAIL.code); |
| 325 | sendRecordBean.setFailContent(failContent); | 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,7 +335,7 @@ public class SendUserInfoTask2 { | ||
| 335 | String failContent = analysisErrorMsg(bUserFlags,bFaceFalgs,bCardFlags); | 335 | String failContent = analysisErrorMsg(bUserFlags,bFaceFalgs,bCardFlags); |
| 336 | sendRecordBean.setFailType(EnumSendFaceType.FACE_FAIL_CARD_SUCCESS.code); | 336 | sendRecordBean.setFailType(EnumSendFaceType.FACE_FAIL_CARD_SUCCESS.code); |
| 337 | sendRecordBean.setFailContent(failContent); | 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,7 +346,7 @@ public class SendUserInfoTask2 { | ||
| 346 | String failContent = analysisErrorMsg(bUserFlags,bFaceFalgs,bCardFlags); | 346 | String failContent = analysisErrorMsg(bUserFlags,bFaceFalgs,bCardFlags); |
| 347 | sendRecordBean.setFailType(EnumSendFaceType.FACE_SUCCESS_CARD_FAIl.code); | 347 | sendRecordBean.setFailType(EnumSendFaceType.FACE_SUCCESS_CARD_FAIl.code); |
| 348 | sendRecordBean.setFailContent(failContent); | 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,10 +575,10 @@ public class SendUserInfoTask2 { | ||
| 575 | String typeName =""; | 575 | String typeName =""; |
| 576 | if(userType ==1){ | 576 | if(userType ==1){ |
| 577 | typeName= "Teacher"; | 577 | typeName= "Teacher"; |
| 578 | - studentBean = userDao.getTeacherWithCard(recordBean.getNum()); | 578 | + studentBean = userDao.getTeacherWithCard(recordBean.getNum(),schoolId); |
| 579 | }else{ | 579 | }else{ |
| 580 | typeName= "Student"; | 580 | typeName= "Student"; |
| 581 | - studentBean= userDao.getStudentWithCard(recordBean.getNum()); | 581 | + studentBean= userDao.getStudentWithCard(recordBean.getNum(),schoolId); |
| 582 | } | 582 | } |
| 583 | if(studentBean==null){ | 583 | if(studentBean==null){ |
| 584 | continue; | 584 | continue; |
| @@ -629,7 +629,7 @@ public class SendUserInfoTask2 { | @@ -629,7 +629,7 @@ public class SendUserInfoTask2 { | ||
| 629 | log.error("设备不在线"); | 629 | log.error("设备不在线"); |
| 630 | return false; | 630 | return false; |
| 631 | } | 631 | } |
| 632 | - StudentBean studentBean = userDao.getStudentWithCard(cardNum); | 632 | + StudentBean studentBean = userDao.getStudentWithCard(cardNum,schoolId); |
| 633 | if(studentBean == null){ | 633 | if(studentBean == null){ |
| 634 | log.error("此卡号:{},未查询到相应学生信息。",cardNum); | 634 | log.error("此卡号:{},未查询到相应学生信息。",cardNum); |
| 635 | return false; | 635 | return false; |
cloud/dahua/src/main/java/com/example/dahua/bean/StudentBean.java
| @@ -61,6 +61,16 @@ public class StudentBean implements Serializable { | @@ -61,6 +61,16 @@ public class StudentBean implements Serializable { | ||
| 61 | 61 | ||
| 62 | private String num; | 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 | public String getNum() { | 74 | public String getNum() { |
| 65 | return num; | 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,6 +22,10 @@ public class UserInfoBean implements Serializable { | ||
| 22 | 22 | ||
| 23 | private String class_id; | 23 | private String class_id; |
| 24 | 24 | ||
| 25 | + private String sex; | ||
| 26 | + | ||
| 27 | + private String parentMobile; | ||
| 28 | + | ||
| 25 | public String getClass_id() { | 29 | public String getClass_id() { |
| 26 | return class_id; | 30 | return class_id; |
| 27 | } | 31 | } |
| @@ -94,6 +98,22 @@ public class UserInfoBean implements Serializable { | @@ -94,6 +98,22 @@ public class UserInfoBean implements Serializable { | ||
| 94 | this.student_id = student_id; | 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 | @Override | 117 | @Override |
| 98 | public String toString() { | 118 | public String toString() { |
| 99 | return "UserInfoBean{" + | 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,8 +9,8 @@ import com.example.dahua.dao.UserDao; | ||
| 9 | import com.example.dahua.enums.EnumSzBusinessType; | 9 | import com.example.dahua.enums.EnumSzBusinessType; |
| 10 | import com.example.dahua.lib.CompressPic; | 10 | import com.example.dahua.lib.CompressPic; |
| 11 | import com.example.dahua.lib.FilePath; | 11 | import com.example.dahua.lib.FilePath; |
| 12 | -import com.example.dahua.service.DeleteBatchTest; | ||
| 13 | import com.example.dahua.service.UserService; | 12 | import com.example.dahua.service.UserService; |
| 13 | +import com.example.dahua.service.imp.BaseService; | ||
| 14 | import com.example.dahua.utils.*; | 14 | import com.example.dahua.utils.*; |
| 15 | import com.example.dahua.xiananDao.SendRecordDao; | 15 | import com.example.dahua.xiananDao.SendRecordDao; |
| 16 | import io.swagger.annotations.Api; | 16 | import io.swagger.annotations.Api; |
| @@ -54,6 +54,9 @@ public class UserControl { | @@ -54,6 +54,9 @@ public class UserControl { | ||
| 54 | @Autowired | 54 | @Autowired |
| 55 | UserDao userDao; | 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,17 +283,15 @@ public class UserControl { | ||
| 280 | 283 | ||
| 281 | boolean check = BaiduUtils.getBaiduUtils().checkImg(httpurl); | 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 | if (check) { | 291 | if (check) { |
| 288 | File file = new File(httpurl); | 292 | File file = new File(httpurl); |
| 289 | - | ||
| 290 | String userCode = file.getName().split("\\.")[0]; | 293 | String userCode = file.getName().split("\\.")[0]; |
| 291 | - | ||
| 292 | - String schoolId = "864"; | ||
| 293 | - | 294 | + String schoolId = ""; |
| 294 | if (httpurl.contains("Student") && !httpurl.startsWith("http")) { | 295 | if (httpurl.contains("Student") && !httpurl.startsWith("http")) { |
| 295 | schoolId = httpurl.substring(httpurl.indexOf("School") + 6, httpurl.indexOf("\\Student")); | 296 | schoolId = httpurl.substring(httpurl.indexOf("School") + 6, httpurl.indexOf("\\Student")); |
| 296 | } else if (httpurl.contains("Teacher") && !httpurl.startsWith("http")) { | 297 | } else if (httpurl.contains("Teacher") && !httpurl.startsWith("http")) { |
| @@ -303,11 +304,43 @@ public class UserControl { | @@ -303,11 +304,43 @@ public class UserControl { | ||
| 303 | FileUtils.getInstance().writeLogs("人脸添加成功:" + userId, "人脸添加成功.txt"); | 304 | FileUtils.getInstance().writeLogs("人脸添加成功:" + userId, "人脸添加成功.txt"); |
| 304 | } | 305 | } |
| 305 | } | 306 | } |
| 306 | - | ||
| 307 | return check; | 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 | @RequestMapping(value = "jpg2png", method = RequestMethod.GET) | 345 | @RequestMapping(value = "jpg2png", method = RequestMethod.GET) |
| 313 | @ApiOperation("jpg图片转png") | 346 | @ApiOperation("jpg图片转png") |
| @@ -336,9 +369,7 @@ public class UserControl { | @@ -336,9 +369,7 @@ public class UserControl { | ||
| 336 | } | 369 | } |
| 337 | 370 | ||
| 338 | } | 371 | } |
| 339 | - | ||
| 340 | return true; | 372 | return true; |
| 341 | - | ||
| 342 | } | 373 | } |
| 343 | 374 | ||
| 344 | @RequestMapping(value = "imgsSend", method = RequestMethod.GET) | 375 | @RequestMapping(value = "imgsSend", method = RequestMethod.GET) |
cloud/dahua/src/main/java/com/example/dahua/control/UserOperateController.java
| 1 | package com.example.dahua.control; | 1 | package com.example.dahua.control; |
| 2 | 2 | ||
| 3 | import com.example.dahua.async.SendUserInfoTask2; | 3 | import com.example.dahua.async.SendUserInfoTask2; |
| 4 | -import com.example.dahua.bean.SendFaceDto; | 4 | +import com.example.dahua.bean.StudentBean; |
| 5 | import com.example.dahua.dao.UserDao; | 5 | import com.example.dahua.dao.UserDao; |
| 6 | import com.example.dahua.service.UserOperateService; | 6 | import com.example.dahua.service.UserOperateService; |
| 7 | +import com.example.dahua.service.imp.BaseService; | ||
| 8 | +import com.example.dahua.utils.HttpUtil; | ||
| 7 | import com.example.dahua.utils.HttpUtils; | 9 | import com.example.dahua.utils.HttpUtils; |
| 10 | +import io.micrometer.core.instrument.util.StringUtils; | ||
| 8 | import io.swagger.annotations.Api; | 11 | import io.swagger.annotations.Api; |
| 9 | import io.swagger.annotations.ApiOperation; | 12 | import io.swagger.annotations.ApiOperation; |
| 10 | import lombok.extern.slf4j.Slf4j; | 13 | import lombok.extern.slf4j.Slf4j; |
| 14 | +import org.apache.commons.collections4.CollectionUtils; | ||
| 11 | import org.springframework.beans.factory.annotation.Autowired; | 15 | import org.springframework.beans.factory.annotation.Autowired; |
| 12 | import org.springframework.http.MediaType; | 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,16 +41,22 @@ public class UserOperateController { | ||
| 32 | @Autowired | 41 | @Autowired |
| 33 | UserOperateService userOperateService; | 42 | UserOperateService userOperateService; |
| 34 | 43 | ||
| 44 | + @Autowired | ||
| 45 | + BaseService baseService; | ||
| 46 | + | ||
| 35 | @RequestMapping(value = "clearAllFace", method = RequestMethod.POST) | 47 | @RequestMapping(value = "clearAllFace", method = RequestMethod.POST) |
| 36 | @ApiOperation(value = "21服务器清空指定学校,指定设备下所有人脸2.0") | 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 | return sendUserInfoTask.clearAllFace(schoolId,deviceId); | 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 | @ApiOperation(value = "100服务器下发学校下所有人脸给指定设备2.0") | 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 | @RequestMapping(value = "deleteFailFace100", method = RequestMethod.POST) | 62 | @RequestMapping(value = "deleteFailFace100", method = RequestMethod.POST) |
| @@ -68,5 +83,4 @@ public class UserOperateController { | @@ -68,5 +83,4 @@ public class UserOperateController { | ||
| 68 | public boolean deleteFaceByCard(Integer schoolId,String cardNum,String deviceId) { | 83 | public boolean deleteFaceByCard(Integer schoolId,String cardNum,String deviceId) { |
| 69 | return sendUserInfoTask.deleteFaceByCard(schoolId,cardNum,deviceId); | 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,7 +89,7 @@ public interface UserDao { | ||
| 89 | @Select(" select studentcode from SZ_V_School_Student where student_id = #{customerid}") | 89 | @Select(" select studentcode from SZ_V_School_Student where student_id = #{customerid}") |
| 90 | String getStudentCode(@Param("customerid") String customerid); | 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 | UserInfoBean getStudentWithid(@Param("student_id") String student_id); | 93 | UserInfoBean getStudentWithid(@Param("student_id") String student_id); |
| 94 | 94 | ||
| 95 | @Select(" select * from SZ_V_School_Student where student_num = #{student_num} and name = #{name}") | 95 | @Select(" select * from SZ_V_School_Student where student_num = #{student_num} and name = #{name}") |
| @@ -136,6 +136,9 @@ public interface UserDao { | @@ -136,6 +136,9 @@ public interface UserDao { | ||
| 136 | @Select("select Top(1) PlaceId from XA_PlaceAttendance where KaoQinAttendance = #{qiandaoDevId}") | 136 | @Select("select Top(1) PlaceId from XA_PlaceAttendance where KaoQinAttendance = #{qiandaoDevId}") |
| 137 | String getPlaceIdWithKaoqinDevid(@Param("qiandaoDevId") String qiandaoDevId); | 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 | @Select("select KanBanAttendance from XA_PlaceAttendance where PlaceId = #{PlaceId} and (len(KanBanAttendance)>0 and KanBanAttendance is not null )") | 142 | @Select("select KanBanAttendance from XA_PlaceAttendance where PlaceId = #{PlaceId} and (len(KanBanAttendance)>0 and KanBanAttendance is not null )") |
| 140 | List<String> getKanBanIdWithPlaceId(@Param("PlaceId") String placeId); | 143 | List<String> getKanBanIdWithPlaceId(@Param("PlaceId") String placeId); |
| 141 | 144 | ||
| @@ -251,12 +254,11 @@ public interface UserDao { | @@ -251,12 +254,11 @@ public interface UserDao { | ||
| 251 | 254 | ||
| 252 | /*************************************** 仅供测试,下发失败使用接口 end ************************************/ | 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 | List<StudentBean> getStudentList(@Param("schoolId") Integer schoolId,@Param("studentType")Integer studentType,@Param("sex") List<Integer> sex); | 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,4 +268,7 @@ public interface UserDao { | ||
| 266 | 268 | ||
| 267 | List<AttendanceBean> queryClintList(@Param("schoolId") Integer schoolId,@Param("deviceId")String deviceId); | 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,8 +9,7 @@ public interface AttendanceService { | ||
| 9 | * | 9 | * |
| 10 | * @return | 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,7 +12,13 @@ public interface DeleteBatchTest { | ||
| 12 | void test(String schoolId); | 12 | void test(String schoolId); |
| 13 | void test2(String schoolId); | 13 | void test2(String schoolId); |
| 14 | void test3(String schoolId); | 14 | void test3(String schoolId); |
| 15 | - | ||
| 16 | void test4(Integer schoolId,Integer studentType,String sex); | 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 | package com.example.dahua.service; | 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,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,15 +16,15 @@ public class AttendanceImp implements AttendanceService { | ||
| 16 | JdbcTemplate jdbcTemplate; | 16 | JdbcTemplate jdbcTemplate; |
| 17 | 17 | ||
| 18 | @Override | 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 | try { | 20 | try { |
| 21 | String selectSql = String.format("select * from SZ_Attendance where clint_id =\'%s\'", clint_id); | 21 | String selectSql = String.format("select * from SZ_Attendance where clint_id =\'%s\'", clint_id); |
| 22 | List<AttendanceBean> attendanceBeans = jdbcTemplate.query(selectSql, new Object[]{}, new BeanPropertyRowMapper<AttendanceBean>(AttendanceBean.class)); | 22 | List<AttendanceBean> attendanceBeans = jdbcTemplate.query(selectSql, new Object[]{}, new BeanPropertyRowMapper<AttendanceBean>(AttendanceBean.class)); |
| 23 | if (attendanceBeans.size() == 0) {//设备不存在 | 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 | return jdbcTemplate.update(insertSql); | 25 | return jdbcTemplate.update(insertSql); |
| 26 | } else {//设备 已经存在,更新在线状态 | 26 | } else {//设备 已经存在,更新在线状态 |
| 27 | - updateConnectStateWithDevid(1,intime, clint_id); | 27 | + updateConnectStateWithDevid(status,intime, clint_id); |
| 28 | } | 28 | } |
| 29 | } catch (Exception e) { | 29 | } catch (Exception e) { |
| 30 | e.printStackTrace(); | 30 | e.printStackTrace(); |
| @@ -45,7 +45,6 @@ public class AttendanceImp implements AttendanceService { | @@ -45,7 +45,6 @@ public class AttendanceImp implements AttendanceService { | ||
| 45 | try { | 45 | try { |
| 46 | String updateSql = String.format(" update SZ_Attendance set isConnection = %d where ip = '%s' and port = '%s' ", isConnection, ip, port); | 46 | String updateSql = String.format(" update SZ_Attendance set isConnection = %d where ip = '%s' and port = '%s' ", isConnection, ip, port); |
| 47 | index = jdbcTemplate.update(updateSql); | 47 | index = jdbcTemplate.update(updateSql); |
| 48 | -// System.out.println("updateIndex:"+index+" isConnection:"+isConnection+"updateSql:"+updateSql); | ||
| 49 | } catch (Exception e) { | 48 | } catch (Exception e) { |
| 50 | e.printStackTrace(); | 49 | e.printStackTrace(); |
| 51 | } | 50 | } |
| @@ -59,7 +58,6 @@ public class AttendanceImp implements AttendanceService { | @@ -59,7 +58,6 @@ public class AttendanceImp implements AttendanceService { | ||
| 59 | try { | 58 | try { |
| 60 | String updateSql = String.format(" update SZ_Attendance set isConnection = %d,inTime='%s' where clint_id = '%s' ", isConnection,inTime,clint_id); | 59 | String updateSql = String.format(" update SZ_Attendance set isConnection = %d,inTime='%s' where clint_id = '%s' ", isConnection,inTime,clint_id); |
| 61 | index = jdbcTemplate.update(updateSql); | 60 | index = jdbcTemplate.update(updateSql); |
| 62 | -// System.out.println("updateIndex:"+index+" isConnection:"+isConnection+"updateSql:"+updateSql); | ||
| 63 | } catch (Exception e) { | 61 | } catch (Exception e) { |
| 64 | e.printStackTrace(); | 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,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 | try{ | 71 | try{ |
| 72 | String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); | 72 | String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); |
| 73 | Integer schoolId = recordBean.getSchoolId(); | 73 | Integer schoolId = recordBean.getSchoolId(); |
| @@ -86,9 +86,9 @@ public class BaseService { | @@ -86,9 +86,9 @@ public class BaseService { | ||
| 86 | } | 86 | } |
| 87 | if (null == sendRecordBean) { | 87 | if (null == sendRecordBean) { |
| 88 | sendRecordDao.saveFaceRecord(userId, deviceId, resultCard, userName, time, schoolName, | 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 | } else { | 90 | } else { |
| 91 | - sendRecordDao.updateFaceSuccessRecord(deviceId, resultCard, time, faceUrl, userName, userId); | 91 | + sendRecordDao.updateFaceSuccessRecord(deviceId, resultCard, time, faceUrl, userName, userId,channel); |
| 92 | } | 92 | } |
| 93 | }catch (Exception e){ | 93 | }catch (Exception e){ |
| 94 | log.error("保存成功记录失败。"); | 94 | log.error("保存成功记录失败。"); |
| @@ -100,7 +100,7 @@ public class BaseService { | @@ -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 | try{ | 104 | try{ |
| 105 | String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); | 105 | String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); |
| 106 | Integer schoolId = recordBean.getSchoolId(); | 106 | Integer schoolId = recordBean.getSchoolId(); |
| @@ -121,7 +121,7 @@ public class BaseService { | @@ -121,7 +121,7 @@ public class BaseService { | ||
| 121 | } | 121 | } |
| 122 | if (null == sendRecordBean) { | 122 | if (null == sendRecordBean) { |
| 123 | sendRecordDao.saveFaceRecord(userId, deviceId, resultCard, userName, time, schoolName, | 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 | }else { | 125 | }else { |
| 126 | sendRecordDao.updateFaceFailRecord(deviceId,faceUrl,resultCard,time,failContent,userId); | 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,12 +5,16 @@ import com.example.dahua.bean.StudentBean; | ||
| 5 | import com.example.dahua.bean.UserInfoBean; | 5 | import com.example.dahua.bean.UserInfoBean; |
| 6 | import com.example.dahua.dao.UserDao; | 6 | import com.example.dahua.dao.UserDao; |
| 7 | import com.example.dahua.service.DeleteBatchTest; | 7 | import com.example.dahua.service.DeleteBatchTest; |
| 8 | +import com.example.dahua.utils.DateFormatUtil; | ||
| 9 | +import com.example.dahua.xiananDao.SearchMapper; | ||
| 8 | import com.example.dahua.xiananDao.SendRecordDao; | 10 | import com.example.dahua.xiananDao.SendRecordDao; |
| 9 | import org.springframework.beans.factory.annotation.Autowired; | 11 | import org.springframework.beans.factory.annotation.Autowired; |
| 10 | import org.springframework.stereotype.Repository; | 12 | import org.springframework.stereotype.Repository; |
| 11 | import org.springframework.stereotype.Service; | 13 | import org.springframework.stereotype.Service; |
| 14 | +import org.springframework.util.CollectionUtils; | ||
| 12 | import org.springframework.util.StringUtils; | 15 | import org.springframework.util.StringUtils; |
| 13 | 16 | ||
| 17 | +import java.security.Provider; | ||
| 14 | import java.util.*; | 18 | import java.util.*; |
| 15 | import java.util.stream.Collectors; | 19 | import java.util.stream.Collectors; |
| 16 | 20 | ||
| @@ -30,6 +34,8 @@ public class DeleteBatchTestImpl implements DeleteBatchTest { | @@ -30,6 +34,8 @@ public class DeleteBatchTestImpl implements DeleteBatchTest { | ||
| 30 | private SendRecordDao sendRecordDao; | 34 | private SendRecordDao sendRecordDao; |
| 31 | @Autowired | 35 | @Autowired |
| 32 | private BaseService baseService; | 36 | private BaseService baseService; |
| 37 | + @Autowired | ||
| 38 | + private SearchMapper searchMapper; | ||
| 33 | 39 | ||
| 34 | 40 | ||
| 35 | @Override | 41 | @Override |
| @@ -125,4 +131,101 @@ public class DeleteBatchTestImpl implements DeleteBatchTest { | @@ -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 | package com.example.dahua.service.imp; | 1 | package com.example.dahua.service.imp; |
| 2 | 2 | ||
| 3 | -import com.example.dahua.bean.SendFaceDto; | ||
| 4 | import com.example.dahua.bean.StudentBean; | 3 | import com.example.dahua.bean.StudentBean; |
| 4 | +import com.example.dahua.bean.UserInfoBean; | ||
| 5 | import com.example.dahua.dao.UserDao; | 5 | import com.example.dahua.dao.UserDao; |
| 6 | import com.example.dahua.lib.CompressPic; | 6 | import com.example.dahua.lib.CompressPic; |
| 7 | import com.example.dahua.lib.FilePath; | 7 | import com.example.dahua.lib.FilePath; |
| 8 | import com.example.dahua.service.UserOperateService; | 8 | import com.example.dahua.service.UserOperateService; |
| 9 | +import com.example.dahua.utils.DateFormatUtil; | ||
| 9 | import com.example.dahua.utils.HttpUtils; | 10 | import com.example.dahua.utils.HttpUtils; |
| 11 | +import com.example.dahua.xiananDao.SearchMapper; | ||
| 12 | +import com.example.dahua.xiananDao.SendRecordDao; | ||
| 10 | import lombok.extern.slf4j.Slf4j; | 13 | import lombok.extern.slf4j.Slf4j; |
| 11 | import org.springframework.beans.factory.annotation.Autowired; | 14 | import org.springframework.beans.factory.annotation.Autowired; |
| 12 | import org.springframework.stereotype.Service; | 15 | import org.springframework.stereotype.Service; |
| 16 | +import org.springframework.util.CollectionUtils; | ||
| 13 | import org.springframework.util.StringUtils; | 17 | import org.springframework.util.StringUtils; |
| 14 | 18 | ||
| 15 | import java.io.File; | 19 | import java.io.File; |
| 16 | import java.util.ArrayList; | 20 | import java.util.ArrayList; |
| 17 | import java.util.Arrays; | 21 | import java.util.Arrays; |
| 18 | import java.util.List; | 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,52 +35,55 @@ public class UserOperateServiceImpl implements UserOperateService { | ||
| 30 | private UserDao userDao; | 35 | private UserDao userDao; |
| 31 | @Autowired | 36 | @Autowired |
| 32 | private BaseService baseService; | 37 | private BaseService baseService; |
| 38 | + @Autowired | ||
| 39 | + private SendRecordDao sendRecordDao; | ||
| 40 | + @Autowired | ||
| 41 | + private SearchMapper searchMapper; | ||
| 33 | 42 | ||
| 34 | @Override | 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 | List<String> deviceList= new ArrayList<>(Arrays.asList(deviceArr)); | 47 | List<String> deviceList= new ArrayList<>(Arrays.asList(deviceArr)); |
| 43 | if(deviceList.size()<1){ | 48 | if(deviceList.size()<1){ |
| 44 | log.error("未选择下发设备"); | 49 | log.error("未选择下发设备"); |
| 45 | return; | 50 | return; |
| 46 | } | 51 | } |
| 47 | - Integer userType=null; | ||
| 48 | //根据类型获取下发用户信息、文件名目录 | 52 | //根据类型获取下发用户信息、文件名目录 |
| 49 | String typeName=""; | 53 | String typeName=""; |
| 50 | List<StudentBean> studentBeanList = null; | 54 | List<StudentBean> studentBeanList = null; |
| 51 | - if(type.intValue() == 0 || type.intValue()==1){ | ||
| 52 | - userType = 2; | 55 | + if(userType.intValue()==2){ |
| 53 | typeName= "Student"; | 56 | typeName= "Student"; |
| 54 | studentBeanList = baseService.getStudentList(schoolId,studentType,sex); | 57 | studentBeanList = baseService.getStudentList(schoolId,studentType,sex); |
| 55 | }else{ | 58 | }else{ |
| 56 | - userType = 1; | ||
| 57 | typeName= "Teacher"; | 59 | typeName= "Teacher"; |
| 58 | studentBeanList = baseService.getTeacherList(schoolId); | 60 | studentBeanList = baseService.getTeacherList(schoolId); |
| 59 | } | 61 | } |
| 62 | + log.info("下发用户总数:"+studentBeanList.size()); | ||
| 60 | for(StudentBean studentBean : studentBeanList){ | 63 | for(StudentBean studentBean : studentBeanList){ |
| 61 | try{ | 64 | try{ |
| 62 | - //100服务器文件目录绝对路径 | ||
| 63 | - String path = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\" + typeName; | ||
| 64 | String photo= userType.intValue()==1?studentBean.getFace():studentBean.getPhoto(); | 65 | String photo= userType.intValue()==1?studentBean.getFace():studentBean.getPhoto(); |
| 66 | + //以学籍号为名的文件名 | ||
| 67 | + String fileName = photo.split(typeName +"/")[1]; | ||
| 65 | //学籍号 | 68 | //学籍号 |
| 66 | String studentCode=userType.intValue()==1?studentBean.getNum():studentBean.getStudentcode(); | 69 | String studentCode=userType.intValue()==1?studentBean.getNum():studentBean.getStudentcode(); |
| 67 | if (StringUtils.isEmpty(photo) || StringUtils.isEmpty(studentCode)){ | 70 | if (StringUtils.isEmpty(photo) || StringUtils.isEmpty(studentCode)){ |
| 68 | continue; | 71 | continue; |
| 69 | } | 72 | } |
| 70 | String filePath=""; | 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 | if(photo.indexOf("f0i5l7e5")!=-1){ | 78 | if(photo.indexOf("f0i5l7e5")!=-1){ |
| 72 | String afterStr = photo.split("f0i5l7e5/")[1].replace("/","\\"); | 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 | log.info("学籍号:{},人脸路径:{}, ",studentCode,filePath); | 88 | log.info("学籍号:{},人脸路径:{}, ",studentCode,filePath); |
| 81 | //100服务人脸照图片路径 | 89 | //100服务人脸照图片路径 |
| @@ -112,4 +120,33 @@ public class UserOperateServiceImpl implements UserOperateService { | @@ -112,4 +120,33 @@ public class UserOperateServiceImpl implements UserOperateService { | ||
| 112 | // System.out.println(photo.split("f0i5l7e5/")[0]); | 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,8 +49,6 @@ public class BaiduUtils { | ||
| 49 | } | 49 | } |
| 50 | map.put("image", httpurl); | 50 | map.put("image", httpurl); |
| 51 | map.put("image_type", image_type); | 51 | map.put("image_type", image_type); |
| 52 | -// map.put("face_field",""); | ||
| 53 | -// map.put("option","GATE"); | ||
| 54 | list.add(map); | 52 | list.add(map); |
| 55 | String param = GsonUtils.toJson(list); | 53 | String param = GsonUtils.toJson(list); |
| 56 | // 注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。 | 54 | // 注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。 |
| @@ -252,17 +250,6 @@ public class BaiduUtils { | @@ -252,17 +250,6 @@ public class BaiduUtils { | ||
| 252 | com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(result); | 250 | com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(result); |
| 253 | String error_msg = jsonObject.getString("error_msg"); | 251 | String error_msg = jsonObject.getString("error_msg"); |
| 254 | if (error_msg.equals("SUCCESS")) { | 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 | return "注册成功"; | 253 | return "注册成功"; |
| 267 | } else { | 254 | } else { |
| 268 | log.info("注册人脸失败,文件大小,size: "+ img.length()); | 255 | log.info("注册人脸失败,文件大小,size: "+ img.length()); |
| @@ -275,6 +262,64 @@ public class BaiduUtils { | @@ -275,6 +262,64 @@ public class BaiduUtils { | ||
| 275 | return ""; | 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 | private byte[] InputStream2ByteArray(String filePath) throws IOException { | 323 | private byte[] InputStream2ByteArray(String filePath) throws IOException { |
| 279 | 324 | ||
| 280 | InputStream in = new FileInputStream(filePath); | 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,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 | * @param length 叠加长度 | 65 | * @param length 叠加长度 |
| 48 | * @param date 起始时间 | 66 | * @param date 起始时间 |
| 49 | * @return | 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 | Calendar cal = Calendar.getInstance(); | 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,4 +10,10 @@ public interface SearchMapper { | ||
| 10 | */ | 10 | */ |
| 11 | void checkIn(CheckIn checkIn); | 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 | package com.example.dahua.xiananDao; | 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,19 +106,30 @@ public interface SendRecordDao { | ||
| 106 | @Select("select * from Face_SendRecord where schoolId = #{schoolId} and deviceID = #{deviceID} and Num = #{Num} and userId = #{userId}") | 106 | @Select("select * from Face_SendRecord where schoolId = #{schoolId} and deviceID = #{deviceID} and Num = #{Num} and userId = #{userId}") |
| 107 | List<SendRecordBean> getRecordIsExit(@Param("schoolId") Integer schoolId,@Param("deviceID") String deviceId, @Param("Num") String card,@Param("userId") String userId); | 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 | @Update("update Face_SendRecord set time = #{time},failContent = #{content},imgPath= #{faceUrl},status = 2 where deviceID = #{deviceID} and Num =#{Num} and userId = #{userId}") | 114 | @Update("update Face_SendRecord set time = #{time},failContent = #{content},imgPath= #{faceUrl},status = 2 where deviceID = #{deviceID} and Num =#{Num} and userId = #{userId}") |
| 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); | 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 | @Select("select * from Face_SendRecord where schoolId = #{schoolId} and status =2") | 120 | @Select("select * from Face_SendRecord where schoolId = #{schoolId} and status =2") |
| 121 | List<SendRecordBean> getFailRecord(@Param("schoolId") Integer schoolId); | 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,7 +8,7 @@ | ||
| 8 | <!--<include resource="org/springframework/boot/logging/logback/defaults.xml" />--> | 8 | <!--<include resource="org/springframework/boot/logging/logback/defaults.xml" />--> |
| 9 | 9 | ||
| 10 | <!--日志文件存储的基础路径: ${user.home} 为当前服务器用户主目录--> | 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 | <property name="BASE_FILE_NAME" value="dahua"/> | 14 | <property name="BASE_FILE_NAME" value="dahua"/> |
cloud/dahua/src/main/resources/mapper/usermapper.xml
| @@ -20,7 +20,7 @@ | @@ -20,7 +20,7 @@ | ||
| 20 | #{item} | 20 | #{item} |
| 21 | </foreach> | 21 | </foreach> |
| 22 | </if> | 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 | </select> | 24 | </select> |
| 25 | 25 | ||
| 26 | <select id="getTeacherList" resultType="com.example.dahua.bean.StudentBean"> | 26 | <select id="getTeacherList" resultType="com.example.dahua.bean.StudentBean"> |
| @@ -43,4 +43,10 @@ | @@ -43,4 +43,10 @@ | ||
| 43 | </if> | 43 | </if> |
| 44 | </select> | 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 | </mapper> | 52 | </mapper> |
| 47 | \ No newline at end of file | 53 | \ No newline at end of file |
cloud/dahua/src/main/resources/xiaoanmapper/SearchMapper.xml
| @@ -15,4 +15,62 @@ | @@ -15,4 +15,62 @@ | ||
| 15 | )} | 15 | )} |
| 16 | </insert> | 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 | </mapper> | 76 | </mapper> |
| 19 | \ No newline at end of file | 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,6 +4,7 @@ import com.alibaba.fastjson.JSON; | ||
| 4 | import com.example.dahua.MyTask; | 4 | import com.example.dahua.MyTask; |
| 5 | import com.example.dahua.Tester; | 5 | import com.example.dahua.Tester; |
| 6 | import com.example.dahua.async.MyScheduledTask; | 6 | import com.example.dahua.async.MyScheduledTask; |
| 7 | +import com.example.dahua.async.SendFaceBatchTask2; | ||
| 7 | import com.example.dahua.bean.*; | 8 | import com.example.dahua.bean.*; |
| 8 | import com.example.dahua.dao.PermissionFaceDao; | 9 | import com.example.dahua.dao.PermissionFaceDao; |
| 9 | import com.example.dahua.dao.UserDao; | 10 | import com.example.dahua.dao.UserDao; |
| @@ -17,11 +18,17 @@ import com.example.dahua.utils.DateUtils; | @@ -17,11 +18,17 @@ import com.example.dahua.utils.DateUtils; | ||
| 17 | import com.example.dahua.utils.HttpUtil; | 18 | import com.example.dahua.utils.HttpUtil; |
| 18 | import com.example.dahua.utils.JsonUtils; | 19 | import com.example.dahua.utils.JsonUtils; |
| 19 | import com.example.dahua.xiananDao.SearchMapper; | 20 | import com.example.dahua.xiananDao.SearchMapper; |
| 21 | +import com.example.dahua.xiananDao.SendRecordDao; | ||
| 22 | +import com.google.common.util.concurrent.ThreadFactoryBuilder; | ||
| 20 | import org.junit.Test; | 23 | import org.junit.Test; |
| 21 | import org.springframework.beans.factory.annotation.Autowired; | 24 | import org.springframework.beans.factory.annotation.Autowired; |
| 22 | 25 | ||
| 23 | import java.io.File; | 26 | import java.io.File; |
| 27 | +import java.util.ArrayList; | ||
| 28 | +import java.util.Arrays; | ||
| 24 | import java.util.Date; | 29 | import java.util.Date; |
| 30 | +import java.util.List; | ||
| 31 | +import java.util.concurrent.*; | ||
| 25 | 32 | ||
| 26 | /** | 33 | /** |
| 27 | * TODO | 34 | * TODO |
| @@ -144,10 +151,120 @@ public class SearchMapperTest extends Tester { | @@ -144,10 +151,120 @@ public class SearchMapperTest extends Tester { | ||
| 144 | // deleteBatchTest.test2(schoolId); | 151 | // deleteBatchTest.test2(schoolId); |
| 145 | String schoolId = "1485"; | 152 | String schoolId = "1485"; |
| 146 | deleteBatchTest.test3(schoolId); | 153 | deleteBatchTest.test3(schoolId); |
| 154 | + | ||
| 147 | } | 155 | } |
| 148 | 156 | ||
| 149 | @Test | 157 | @Test |
| 150 | public void test9() { | 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 | package com.sincere.haikangface; | 1 | package com.sincere.haikangface; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSON; | 3 | import com.alibaba.fastjson.JSON; |
| 4 | +import com.alibaba.fastjson.JSONArray; | ||
| 4 | import com.alibaba.fastjson.JSONObject; | 5 | import com.alibaba.fastjson.JSONObject; |
| 5 | import com.sincere.haikangface.bean.AttendanceBean; | 6 | import com.sincere.haikangface.bean.AttendanceBean; |
| 7 | +import com.sincere.haikangface.bean.BaiduFaceRecorder; | ||
| 6 | import com.sincere.haikangface.bean.StudentBean; | 8 | import com.sincere.haikangface.bean.StudentBean; |
| 9 | +import com.sincere.haikangface.bean.TeacherBean; | ||
| 7 | import com.sincere.haikangface.bean.xiaoan.Face_Recoder; | 10 | import com.sincere.haikangface.bean.xiaoan.Face_Recoder; |
| 8 | import com.sincere.haikangface.dao.DeviceDao; | 11 | import com.sincere.haikangface.dao.DeviceDao; |
| 9 | import com.sincere.haikangface.dao.UserDao; | 12 | import com.sincere.haikangface.dao.UserDao; |
| 10 | import com.sincere.haikangface.haikanglibs.HCEHomeAlarm; | 13 | import com.sincere.haikangface.haikanglibs.HCEHomeAlarm; |
| 11 | import com.sincere.haikangface.haikanglibs.HCEHomeCMS; | 14 | import com.sincere.haikangface.haikanglibs.HCEHomeCMS; |
| 12 | import com.sincere.haikangface.haikanglibs.HCEHomeSS; | 15 | import com.sincere.haikangface.haikanglibs.HCEHomeSS; |
| 16 | +import com.sincere.haikangface.mqtt.MqtUtils; | ||
| 13 | import com.sincere.haikangface.service.impl.BaseService; | 17 | import com.sincere.haikangface.service.impl.BaseService; |
| 14 | import com.sincere.haikangface.utils.AlarmUtils; | 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 | import com.sincere.haikangface.xiananDao.SendRecordDao; | 21 | import com.sincere.haikangface.xiananDao.SendRecordDao; |
| 17 | import com.sun.jna.NativeLong; | 22 | import com.sun.jna.NativeLong; |
| 18 | import com.sun.jna.Pointer; | 23 | import com.sun.jna.Pointer; |
| 19 | import lombok.extern.slf4j.Slf4j; | 24 | import lombok.extern.slf4j.Slf4j; |
| 20 | import org.apache.http.util.TextUtils; | 25 | import org.apache.http.util.TextUtils; |
| 21 | import org.springframework.beans.factory.annotation.Autowired; | 26 | import org.springframework.beans.factory.annotation.Autowired; |
| 22 | -import org.springframework.beans.factory.annotation.Value; | ||
| 23 | import org.springframework.boot.ApplicationArguments; | 27 | import org.springframework.boot.ApplicationArguments; |
| 24 | import org.springframework.boot.ApplicationRunner; | 28 | import org.springframework.boot.ApplicationRunner; |
| 25 | import org.springframework.stereotype.Component; | 29 | import org.springframework.stereotype.Component; |
| @@ -50,9 +54,6 @@ public class CMSServer implements ApplicationRunner { | @@ -50,9 +54,6 @@ public class CMSServer implements ApplicationRunner { | ||
| 50 | @Autowired | 54 | @Autowired |
| 51 | SendRecordDao sendRecordDao; | 55 | SendRecordDao sendRecordDao; |
| 52 | 56 | ||
| 53 | - @Autowired | ||
| 54 | - BaseService baseService; | ||
| 55 | - | ||
| 56 | public static HCEHomeCMS hCEhomeCMS = HCEHomeCMS.INSTANCE; | 57 | public static HCEHomeCMS hCEhomeCMS = HCEHomeCMS.INSTANCE; |
| 57 | //注册回调函数实现 | 58 | //注册回调函数实现 |
| 58 | static FRegisterCallBack fRegisterCallBack; | 59 | static FRegisterCallBack fRegisterCallBack; |
| @@ -61,8 +62,6 @@ public class CMSServer implements ApplicationRunner { | @@ -61,8 +62,6 @@ public class CMSServer implements ApplicationRunner { | ||
| 61 | // 存储设备登录句柄 | 62 | // 存储设备登录句柄 |
| 62 | static Map<String, NativeLong> map = new HashMap<>(); | 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 | //114.55.30.100 | 65 | //114.55.30.100 |
| 67 | //120.26.116.253 | 66 | //120.26.116.253 |
| 68 | // private String ip_cloud = "114.55.30.100"; | 67 | // private String ip_cloud = "114.55.30.100"; |
| @@ -246,23 +245,7 @@ public class CMSServer implements ApplicationRunner { | @@ -246,23 +245,7 @@ public class CMSServer implements ApplicationRunner { | ||
| 246 | log.error("注册设备,设置设备ID异常,错误信息:{}",e); | 245 | log.error("注册设备,设置设备ID异常,错误信息:{}",e); |
| 247 | } | 246 | } |
| 248 | pInBuffer.dwSize = pInBuffer.size(); | 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 | /*这里加判断即可,可以通过byDeviceID、sDeviceSerial、sDevName 进行判断 | 249 | /*这里加判断即可,可以通过byDeviceID、sDeviceSerial、sDevName 进行判断 |
| 267 | if(strDevRegInfo.dwDevType == 1) { | 250 | if(strDevRegInfo.dwDevType == 1) { |
| 268 | pInBuffer.dwAlarmServerType = 3; | 251 | pInBuffer.dwAlarmServerType = 3; |
| @@ -295,7 +278,7 @@ public class CMSServer implements ApplicationRunner { | @@ -295,7 +278,7 @@ public class CMSServer implements ApplicationRunner { | ||
| 295 | 278 | ||
| 296 | public boolean invoke(NativeLong iHandle, int enumType, Pointer pOutBuffer, int dwOutLen, Pointer pInBuffer, | 279 | public boolean invoke(NativeLong iHandle, int enumType, Pointer pOutBuffer, int dwOutLen, Pointer pInBuffer, |
| 297 | int dwInLen, Pointer pUser) { | 280 | int dwInLen, Pointer pUser) { |
| 298 | - System.out.println("信息回调函数上报:------"); | 281 | + log.info("信息回调函数上报:------"); |
| 299 | if (1 == enumType) { | 282 | if (1 == enumType) { |
| 300 | HCEHomeSS.NET_EHOME_SS_TOMCAT_MSG pTomcatMsg = new HCEHomeSS.NET_EHOME_SS_TOMCAT_MSG(); | 283 | HCEHomeSS.NET_EHOME_SS_TOMCAT_MSG pTomcatMsg = new HCEHomeSS.NET_EHOME_SS_TOMCAT_MSG(); |
| 301 | String szDevUri = new String(pTomcatMsg.szDevUri).trim(); | 284 | String szDevUri = new String(pTomcatMsg.szDevUri).trim(); |
| @@ -316,19 +299,17 @@ public class CMSServer implements ApplicationRunner { | @@ -316,19 +299,17 @@ public class CMSServer implements ApplicationRunner { | ||
| 316 | public class PSS_Storage_Callback implements HCEHomeSS.EHomeSSStorageCallBack { | 299 | public class PSS_Storage_Callback implements HCEHomeSS.EHomeSSStorageCallBack { |
| 317 | public boolean invoke(NativeLong iHandle, String pFileName, Pointer pFileBuf, int dwFileLen, Pointer pFilePath, Pointer pUser) { | 300 | public boolean invoke(NativeLong iHandle, String pFileName, Pointer pFileBuf, int dwFileLen, Pointer pFilePath, Pointer pUser) { |
| 318 | String strPath = "C://EhomePicServer/"; | 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 | String isQJFileName = pFileName;//用来判断是否是枪机 | 307 | String isQJFileName = pFileName;//用来判断是否是枪机 |
| 321 | pFileName = pFileName.replace("_", ""); | 308 | pFileName = pFileName.replace("_", ""); |
| 322 | if (pFileName.contains("T"))pFileName=pFileName.split("T")[0]+".jpg"; | 309 | if (pFileName.contains("T"))pFileName=pFileName.split("T")[0]+".jpg"; |
| 323 | - FileUtils.getInstance().writeLogs("文件名pFileName:" + pFileName, FileUtils.fileName); | ||
| 324 | String strFilePath = strPath + pFileName; | 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 | File strFilePathFile = new File(strFilePath); | 313 | File strFilePathFile = new File(strFilePath); |
| 333 | if (!strFilePathFile.exists()) { | 314 | if (!strFilePathFile.exists()) { |
| 334 | try { | 315 | try { |
| @@ -358,7 +339,7 @@ public class CMSServer implements ApplicationRunner { | @@ -358,7 +339,7 @@ public class CMSServer implements ApplicationRunner { | ||
| 358 | deviceId = isQJFileName.substring(start, end); | 339 | deviceId = isQJFileName.substring(start, end); |
| 359 | } | 340 | } |
| 360 | //发送看板 | 341 | //发送看板 |
| 361 | - baseService.sendUserInfoToKB(strFilePathFile, deviceId); | 342 | + sendUserInfoToKB(strFilePathFile, deviceId); |
| 362 | } | 343 | } |
| 363 | } catch (FileNotFoundException e) { | 344 | } catch (FileNotFoundException e) { |
| 364 | log.error("处理人脸机抓拍文件异常,错误信息:{}",e); | 345 | log.error("处理人脸机抓拍文件异常,错误信息:{}",e); |
| @@ -366,13 +347,7 @@ public class CMSServer implements ApplicationRunner { | @@ -366,13 +347,7 @@ public class CMSServer implements ApplicationRunner { | ||
| 366 | log.error("处理人脸机抓拍文件异常,错误信息:{}",e); | 347 | log.error("处理人脸机抓拍文件异常,错误信息:{}",e); |
| 367 | } | 348 | } |
| 368 | } | 349 | } |
| 369 | - | ||
| 370 | pFilePath.write(0, strFilePath.getBytes(), 0, strFilePath.getBytes().length); | 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 | return true; | 351 | return true; |
| 377 | } | 352 | } |
| 378 | } | 353 | } |
| @@ -397,6 +372,7 @@ public class CMSServer implements ApplicationRunner { | @@ -397,6 +372,7 @@ public class CMSServer implements ApplicationRunner { | ||
| 397 | alarmUtils.setCallBack(new AlarmUtils.AlarmCallBack() { | 372 | alarmUtils.setCallBack(new AlarmUtils.AlarmCallBack() { |
| 398 | @Override | 373 | @Override |
| 399 | public void callBack(String minorType, String deviceID, String cardNo, String time, String picDataUrlId, String currTemperature) { | 374 | public void callBack(String minorType, String deviceID, String cardNo, String time, String picDataUrlId, String currTemperature) { |
| 375 | + saveAttendance(deviceID); | ||
| 400 | switch (minorType) { | 376 | switch (minorType) { |
| 401 | case "0x4b"://人脸认证通过 | 377 | case "0x4b"://人脸认证通过 |
| 402 | log.info("人脸验证通过,事件次类型:"+minorType); | 378 | log.info("人脸验证通过,事件次类型:"+minorType); |
| @@ -407,7 +383,7 @@ public class CMSServer implements ApplicationRunner { | @@ -407,7 +383,7 @@ public class CMSServer implements ApplicationRunner { | ||
| 407 | case "0x427"://人证设备离线 | 383 | case "0x427"://人证设备离线 |
| 408 | log.info("设备掉线了,设备ID: "+deviceID); | 384 | log.info("设备掉线了,设备ID: "+deviceID); |
| 409 | map.remove(deviceID); | 385 | map.remove(deviceID); |
| 410 | - deviceDao.updateDeviceStatu(0,inTime,deviceID); | 386 | + deviceDao.updateDeviceStatu(0,time,deviceID); |
| 411 | break; | 387 | break; |
| 412 | case "0x69"://人证比对通过 | 388 | case "0x69"://人证比对通过 |
| 413 | log.info("人证比对通过,事件次类型:"+minorType); | 389 | log.info("人证比对通过,事件次类型:"+minorType); |
| @@ -445,6 +421,7 @@ public class CMSServer implements ApplicationRunner { | @@ -445,6 +421,7 @@ public class CMSServer implements ApplicationRunner { | ||
| 445 | * @param picDataUrlId | 421 | * @param picDataUrlId |
| 446 | */ | 422 | */ |
| 447 | private void saveFaceRecoder(String deviceID, String cardNo, String time, String picDataUrlId, String currTemperature) { | 423 | private void saveFaceRecoder(String deviceID, String cardNo, String time, String picDataUrlId, String currTemperature) { |
| 424 | + BaseService baseService = SpringContextHolder.getBaseService(); | ||
| 448 | try { | 425 | try { |
| 449 | if (!StringUtils.isEmpty(cardNo) && isNumeric(cardNo)) { | 426 | if (!StringUtils.isEmpty(cardNo) && isNumeric(cardNo)) { |
| 450 | Face_Recoder face_recoder = new Face_Recoder(); | 427 | Face_Recoder face_recoder = new Face_Recoder(); |
| @@ -452,19 +429,23 @@ public class CMSServer implements ApplicationRunner { | @@ -452,19 +429,23 @@ public class CMSServer implements ApplicationRunner { | ||
| 452 | String card = splicingZero(Long.toHexString(Long.parseLong(cardNo)), 8).toUpperCase(); | 429 | String card = splicingZero(Long.toHexString(Long.parseLong(cardNo)), 8).toUpperCase(); |
| 453 | //卡号逆转 | 430 | //卡号逆转 |
| 454 | cardNo = baseService.getCard(card); | 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 | if (null != studentBean) { | 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 | face_recoder.setCardNum(cardNo); | 439 | face_recoder.setCardNum(cardNo); |
| 460 | face_recoder.setDeviceId(deviceID); | 440 | face_recoder.setDeviceId(deviceID); |
| 461 | face_recoder.setTime(time); | 441 | face_recoder.setTime(time); |
| 462 | - face_recoder.setName(studentBean.getName()); | 442 | + face_recoder.setName(name); |
| 463 | face_recoder.setUser_id(studentBean.getUser_id()); | 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 | face_recoder.setImgurl(imgUrl); | 446 | face_recoder.setImgurl(imgUrl); |
| 447 | + log.info("设备: {},人脸抓怕:学校id: {} ,班级:{} ,用户名:{} ,卡号:{} ,",deviceID,schoolId,className,name,cardNo); | ||
| 448 | + log.info("抓拍人脸:" + imgUrl); | ||
| 468 | if (!TextUtils.isEmpty(currTemperature)) {//只有有温度的才存记录 | 449 | if (!TextUtils.isEmpty(currTemperature)) {//只有有温度的才存记录 |
| 469 | userDao.addWGTem(studentBean.getUser_id(), studentBean.getStudent_id(), studentBean.getName(), studentBean.getClass_id() + "", | 450 | userDao.addWGTem(studentBean.getUser_id(), studentBean.getStudent_id(), studentBean.getName(), studentBean.getClass_id() + "", |
| 470 | studentBean.getClass_name(), currTemperature, studentBean.getStudent_type() + "", studentBean.getSchool_id() + "", time); | 451 | studentBean.getClass_name(), currTemperature, studentBean.getStudent_type() + "", studentBean.getSchool_id() + "", time); |
| @@ -474,7 +455,7 @@ public class CMSServer implements ApplicationRunner { | @@ -474,7 +455,7 @@ public class CMSServer implements ApplicationRunner { | ||
| 474 | face_recoder.getImgurl(), face_recoder.getInOrOut(), face_recoder.getTime(), face_recoder.getCardNum(), currTemperature); | 455 | face_recoder.getImgurl(), face_recoder.getInOrOut(), face_recoder.getTime(), face_recoder.getCardNum(), currTemperature); |
| 475 | } else { | 456 | } else { |
| 476 | //教师点名 | 457 | //教师点名 |
| 477 | - isTeacher(cardNo, deviceID); | 458 | + isTeacher(cardNo, deviceID,null); |
| 478 | } | 459 | } |
| 479 | // if (deviceID.startsWith("qj")) {//枪击 用来抓拍人脸考勤用 | 460 | // if (deviceID.startsWith("qj")) {//枪击 用来抓拍人脸考勤用 |
| 480 | // initQJ(deviceID, cardNo, studentBean == null); | 461 | // initQJ(deviceID, cardNo, studentBean == null); |
| @@ -486,18 +467,16 @@ public class CMSServer implements ApplicationRunner { | @@ -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 | List<String> devLists = userDao.getDeviceRoomRelation(deviceID); | 471 | List<String> devLists = userDao.getDeviceRoomRelation(deviceID); |
| 491 | if (null != devLists && devLists.size() > 0) { | 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 | if (null != teacher) { | 475 | if (null != teacher) { |
| 496 | String url = String.format("http://campus.myjxt.com/api/RollCall/AddRollCallPersonnelRecord?userId=%s&deviceId=%s", teacher.getUser_id(), deviceID); | 476 | String url = String.format("http://campus.myjxt.com/api/RollCall/AddRollCallPersonnelRecord?userId=%s&deviceId=%s", teacher.getUser_id(), deviceID); |
| 497 | RestTemplate restTemplate = new RestTemplate(); | 477 | RestTemplate restTemplate = new RestTemplate(); |
| 498 | String res = restTemplate.getForObject(url, String.class); | 478 | String res = restTemplate.getForObject(url, String.class); |
| 499 | JSONObject jsonObject = JSON.parseObject(res); | 479 | JSONObject jsonObject = JSON.parseObject(res); |
| 500 | - FileUtils.getInstance().writeLogs("card:" + res, "教师点名.txt"); | ||
| 501 | System.out.println("result:" + res + "------url:" + jsonObject.getBoolean("data")); | 480 | System.out.println("result:" + res + "------url:" + jsonObject.getBoolean("data")); |
| 502 | } | 481 | } |
| 503 | } | 482 | } |
| @@ -552,12 +531,8 @@ public class CMSServer implements ApplicationRunner { | @@ -552,12 +531,8 @@ public class CMSServer implements ApplicationRunner { | ||
| 552 | */ | 531 | */ |
| 553 | return sendInfo(srcFile, url, card, startTime, endTime, validTimeEnabled, name, deviceId, userType, employeeNo, schoolId,cardNum); | 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 | return false; | 536 | return false; |
| 562 | } | 537 | } |
| 563 | 538 | ||
| @@ -705,9 +680,7 @@ public class CMSServer implements ApplicationRunner { | @@ -705,9 +680,7 @@ public class CMSServer implements ApplicationRunner { | ||
| 705 | */ | 680 | */ |
| 706 | public void SetCardWeekPlan(String clint_id, String card, String userType, String strConfigXMLCard, String content,Integer schoolId,String cardNum) { | 681 | public void SetCardWeekPlan(String clint_id, String card, String userType, String strConfigXMLCard, String content,Integer schoolId,String cardNum) { |
| 707 | try { | 682 | try { |
| 708 | - | ||
| 709 | HCEHomeCMS.NET_EHOME_XML_CFG struXMLCard = new HCEHomeCMS.NET_EHOME_XML_CFG(); | 683 | HCEHomeCMS.NET_EHOME_XML_CFG struXMLCard = new HCEHomeCMS.NET_EHOME_XML_CFG(); |
| 710 | - | ||
| 711 | HCEHomeCMS.NET_DVR_STRING_POINTER stringRequestCard = new HCEHomeCMS.NET_DVR_STRING_POINTER(); | 684 | HCEHomeCMS.NET_DVR_STRING_POINTER stringRequestCard = new HCEHomeCMS.NET_DVR_STRING_POINTER(); |
| 712 | stringRequestCard.read(); | 685 | stringRequestCard.read(); |
| 713 | String strRequestCard = "SETDEVICECONFIG"; | 686 | String strRequestCard = "SETDEVICECONFIG"; |
| @@ -742,15 +715,11 @@ public class CMSServer implements ApplicationRunner { | @@ -742,15 +715,11 @@ public class CMSServer implements ApplicationRunner { | ||
| 742 | struXMLCard.write(); | 715 | struXMLCard.write(); |
| 743 | 716 | ||
| 744 | int i = struXMLCard.size(); | 717 | int i = struXMLCard.size(); |
| 718 | + BaseService baseService = SpringContextHolder.getBaseService(); | ||
| 745 | if (!hCEhomeCMS.NET_ECMS_XMLConfig(map.get(clint_id), struXMLCard, struXMLCard.size())) { | 719 | if (!hCEhomeCMS.NET_ECMS_XMLConfig(map.get(clint_id), struXMLCard, struXMLCard.size())) { |
| 746 | int iErr = hCEhomeCMS.NET_ECMS_GetLastError(); | 720 | int iErr = hCEhomeCMS.NET_ECMS_GetLastError(); |
| 747 | log.error(content + "失败:" + iErr); | 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 | } else { | 723 | } else { |
| 755 | log.info(content + "成功"); | 724 | log.info(content + "成功"); |
| 756 | } | 725 | } |
| @@ -817,27 +786,22 @@ public class CMSServer implements ApplicationRunner { | @@ -817,27 +786,22 @@ public class CMSServer implements ApplicationRunner { | ||
| 817 | HCEHomeCMS.NET_DVR_STRING_POINTER stringXMLOut = new HCEHomeCMS.NET_DVR_STRING_POINTER(); | 786 | HCEHomeCMS.NET_DVR_STRING_POINTER stringXMLOut = new HCEHomeCMS.NET_DVR_STRING_POINTER(); |
| 818 | struISAPXML.pOutBuffer = stringXMLOut.getPointer(); | 787 | struISAPXML.pOutBuffer = stringXMLOut.getPointer(); |
| 819 | struISAPXML.dwOutSize = stringXMLOut.size(); | 788 | struISAPXML.dwOutSize = stringXMLOut.size(); |
| 789 | + BaseService baseService = SpringContextHolder.getBaseService(); | ||
| 820 | if (type == 1) {//下发人脸 | 790 | if (type == 1) {//下发人脸 |
| 821 | if (!hCEhomeCMS.NET_ECMS_PostPTXMLConfig(map.get(deviceId), struISAPXML)) { | 791 | if (!hCEhomeCMS.NET_ECMS_PostPTXMLConfig(map.get(deviceId), struISAPXML)) { |
| 822 | int iErr = hCEhomeCMS.NET_ECMS_GetLastError(); | 792 | int iErr = hCEhomeCMS.NET_ECMS_GetLastError(); |
| 823 | log.error(content + "失败,错误号:" + iErr + "---" + strConfigXML + "\n"); | 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 | } else { | 798 | } else { |
| 832 | stringXMLOut.read(); | 799 | stringXMLOut.read(); |
| 833 | String strOutXML = new String(stringXMLOut.byString).trim(); | 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 | } else if (type == 2) {//删除人脸 | 806 | } else if (type == 2) {//删除人脸 |
| 843 | if (!hCEhomeCMS.NET_ECMS_PutPTXMLConfig(map.get(deviceId), struISAPXML)) { | 807 | if (!hCEhomeCMS.NET_ECMS_PutPTXMLConfig(map.get(deviceId), struISAPXML)) { |
| @@ -863,63 +827,148 @@ public class CMSServer implements ApplicationRunner { | @@ -863,63 +827,148 @@ public class CMSServer implements ApplicationRunner { | ||
| 863 | return false; | 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 | } else { | 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,4 +997,24 @@ public class CMSServer implements ApplicationRunner { | ||
| 948 | return pattern.matcher(str).matches(); | 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 | package com.sincere.haikangface; | 1 | package com.sincere.haikangface; |
| 2 | 2 | ||
| 3 | import com.sincere.haikangface.utils.FileUtils; | 3 | import com.sincere.haikangface.utils.FileUtils; |
| 4 | -import org.mybatis.spring.annotation.MapperScan; | ||
| 5 | import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration; | 4 | import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration; |
| 6 | import org.springframework.boot.SpringApplication; | 5 | import org.springframework.boot.SpringApplication; |
| 7 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | 6 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; |
| @@ -10,14 +9,13 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | @@ -10,14 +9,13 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | ||
| 10 | import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; | 9 | import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; |
| 11 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; | 10 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; |
| 12 | import org.springframework.cloud.openfeign.EnableFeignClients; | 11 | import org.springframework.cloud.openfeign.EnableFeignClients; |
| 13 | -import org.springframework.context.annotation.ComponentScan; | ||
| 14 | import org.springframework.scheduling.annotation.EnableAsync; | 12 | import org.springframework.scheduling.annotation.EnableAsync; |
| 15 | 13 | ||
| 16 | @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, MybatisAutoConfiguration.class}) | 14 | @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, MybatisAutoConfiguration.class}) |
| 17 | @SpringBootApplication | 15 | @SpringBootApplication |
| 18 | @EnableDiscoveryClient | 16 | @EnableDiscoveryClient |
| 19 | @EnableFeignClients(basePackages = "com.sincere.haikangface.fegin") | 17 | @EnableFeignClients(basePackages = "com.sincere.haikangface.fegin") |
| 20 | -//@EnableAsync | 18 | +@EnableAsync |
| 21 | public class HaikangfaceApplication { | 19 | public class HaikangfaceApplication { |
| 22 | 20 | ||
| 23 | public static void main(String[] args) { | 21 | public static void main(String[] args) { |
cloud/haikangface/src/main/java/com/sincere/haikangface/async/AsyncTask.java
0 → 100644
| @@ -0,0 +1,95 @@ | @@ -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 @@ | @@ -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,7 +71,7 @@ public class SendFaceBatchTask253 implements Runnable { | ||
| 71 | String filePath = path+ "\\" + fileName; | 71 | String filePath = path+ "\\" + fileName; |
| 72 | Thread.sleep(1000); | 72 | Thread.sleep(1000); |
| 73 | //下发253服务器 | 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 | }catch (Exception e){ | 75 | }catch (Exception e){ |
| 76 | log.error("人脸下发失败"); | 76 | log.error("人脸下发失败"); |
| 77 | e.printStackTrace(); | 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,7 +15,7 @@ import com.sincere.haikangface.service.impl.BaseService; | ||
| 15 | import com.sincere.haikangface.utils.FileUtils; | 15 | import com.sincere.haikangface.utils.FileUtils; |
| 16 | import com.sincere.haikangface.utils.HKXmlUtils; | 16 | import com.sincere.haikangface.utils.HKXmlUtils; |
| 17 | import com.sincere.haikangface.utils.HttpUtil; | 17 | import com.sincere.haikangface.utils.HttpUtil; |
| 18 | -import com.sincere.haikangface.utils.SendRecoderUtils; | 18 | +import com.sincere.haikangface.utils.SpringContextHolder; |
| 19 | import com.sincere.haikangface.xiananDao.SendRecordDao; | 19 | import com.sincere.haikangface.xiananDao.SendRecordDao; |
| 20 | import lombok.extern.slf4j.Slf4j; | 20 | import lombok.extern.slf4j.Slf4j; |
| 21 | import org.springframework.beans.factory.annotation.Autowired; | 21 | import org.springframework.beans.factory.annotation.Autowired; |
| @@ -45,12 +45,6 @@ public class SendUserAsync { | @@ -45,12 +45,6 @@ public class SendUserAsync { | ||
| 45 | @Autowired | 45 | @Autowired |
| 46 | UserDao userDao; | 46 | UserDao userDao; |
| 47 | 47 | ||
| 48 | - @Autowired | ||
| 49 | - BaseService baseService; | ||
| 50 | - | ||
| 51 | - | ||
| 52 | - SendRecoderUtils sendRecoderUtils; | ||
| 53 | - | ||
| 54 | /** | 48 | /** |
| 55 | * 人脸下发至海康设备 | 49 | * 人脸下发至海康设备 |
| 56 | * @param srcFile | 50 | * @param srcFile |
| @@ -81,7 +75,7 @@ public class SendUserAsync { | @@ -81,7 +75,7 @@ public class SendUserAsync { | ||
| 81 | //1老师;2学生 | 75 | //1老师;2学生 |
| 82 | if (Integer.parseInt(userType) ==EnumSzBusinessType.EnumUserType.TEACHER.code) { | 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 | if (null == studentBean) { | 79 | if (null == studentBean) { |
| 86 | employeeNo = time.substring(time.length() - 6, time.length()); | 80 | employeeNo = time.substring(time.length() - 6, time.length()); |
| 87 | } else{ | 81 | } else{ |
| @@ -90,7 +84,7 @@ public class SendUserAsync { | @@ -90,7 +84,7 @@ public class SendUserAsync { | ||
| 90 | } | 84 | } |
| 91 | if (Integer.parseInt(userType) ==EnumSzBusinessType.EnumUserType.STUDENT.code) { | 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 | if (null == studentBean) { | 88 | if (null == studentBean) { |
| 95 | employeeNo = time.substring(time.length() - 6, time.length()); | 89 | employeeNo = time.substring(time.length() - 6, time.length()); |
| 96 | } else{ | 90 | } else{ |
| @@ -107,13 +101,8 @@ public class SendUserAsync { | @@ -107,13 +101,8 @@ public class SendUserAsync { | ||
| 107 | cmsServer.SetCardWeekPlan(deviceId, card, userType, HKXmlUtils.getInstance().SetCardRightCfg(card), "设置卡权限",schoolId,cardNum); | 101 | cmsServer.SetCardWeekPlan(deviceId, card, userType, HKXmlUtils.getInstance().SetCardRightCfg(card), "设置卡权限",schoolId,cardNum); |
| 108 | } | 102 | } |
| 109 | } else {//不合格 | 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,7 +114,6 @@ public class SendUserAsync { | ||
| 125 | * @param permissionBean | 114 | * @param permissionBean |
| 126 | * @param i 1:不需要重新下发,0需要重新下发 | 115 | * @param i 1:不需要重新下发,0需要重新下发 |
| 127 | */ | 116 | */ |
| 128 | - @Async("taskExecutor") | ||
| 129 | public boolean sendPermiss(PermissionBean permissionBean, int i) { | 117 | public boolean sendPermiss(PermissionBean permissionBean, int i) { |
| 130 | try{ | 118 | try{ |
| 131 | //用户类型1老师2学生 | 119 | //用户类型1老师2学生 |
| @@ -169,7 +157,6 @@ public class SendUserAsync { | @@ -169,7 +157,6 @@ public class SendUserAsync { | ||
| 169 | * @param permissionBean | 157 | * @param permissionBean |
| 170 | * @param id | 158 | * @param id |
| 171 | */ | 159 | */ |
| 172 | - @Async("taskExecutor") | ||
| 173 | public boolean sendHKAuth(PermissionBean permissionBean, Integer id,Integer studentType) { | 160 | public boolean sendHKAuth(PermissionBean permissionBean, Integer id,Integer studentType) { |
| 174 | try{ | 161 | try{ |
| 175 | //用户类型1老师2学生 | 162 | //用户类型1老师2学生 |
| @@ -184,7 +171,7 @@ public class SendUserAsync { | @@ -184,7 +171,7 @@ public class SendUserAsync { | ||
| 184 | String userIds = permissionBean.getUserIds(); | 171 | String userIds = permissionBean.getUserIds(); |
| 185 | 172 | ||
| 186 | List<String> deviceIds = permissionBean.getDeviceIds(); | 173 | List<String> deviceIds = permissionBean.getDeviceIds(); |
| 187 | - | 174 | + BaseService baseService = SpringContextHolder.getBaseService(); |
| 188 | for (WeekDay weekDay : weekDays) { | 175 | for (WeekDay weekDay : weekDays) { |
| 189 | List<String> cardNumList = new ArrayList<>(); | 176 | List<String> cardNumList = new ArrayList<>(); |
| 190 | String sex = weekDay.getSex(); | 177 | String sex = weekDay.getSex(); |
| @@ -282,10 +269,8 @@ public class SendUserAsync { | @@ -282,10 +269,8 @@ public class SendUserAsync { | ||
| 282 | String weekPlanTimes = HKXmlUtils.getInstance().SetCardWeekPlanTimes(weekTime.getStartTime(), weekTime.getEndTime()); | 269 | String weekPlanTimes = HKXmlUtils.getInstance().SetCardWeekPlanTimes(weekTime.getStartTime(), weekTime.getEndTime()); |
| 283 | stringBuffer.append(weekPlanTimes); | 270 | stringBuffer.append(weekPlanTimes); |
| 284 | } | 271 | } |
| 285 | - | ||
| 286 | String weekPlanTime = HKXmlUtils.getInstance().SetCardWeekPlanTime(stringBuffer.toString(), "" + week); | 272 | String weekPlanTime = HKXmlUtils.getInstance().SetCardWeekPlanTime(stringBuffer.toString(), "" + week); |
| 287 | String serCardRightCfg = HKXmlUtils.getInstance().SetCardRightCfg(cardNum); | 273 | String serCardRightCfg = HKXmlUtils.getInstance().SetCardRightCfg(cardNum); |
| 288 | - FileUtils.getInstance().writeLogs(weekPlanTime, "设置卡权限周计划时间.txt"); | ||
| 289 | cmsServer.SetCardWeekPlan(deviceId, cardNum, userType, weekPlanTime, "设置卡权限周计划时间",schoolId,cardNum); | 274 | cmsServer.SetCardWeekPlan(deviceId, cardNum, userType, weekPlanTime, "设置卡权限周计划时间",schoolId,cardNum); |
| 290 | cmsServer.SetCardWeekPlan(deviceId, cardNum, userType, serCardRightCfg, "设置卡权限",schoolId,cardNum); | 275 | cmsServer.SetCardWeekPlan(deviceId, cardNum, userType, serCardRightCfg, "设置卡权限",schoolId,cardNum); |
| 291 | } | 276 | } |
| @@ -373,16 +358,14 @@ public class SendUserAsync { | @@ -373,16 +358,14 @@ public class SendUserAsync { | ||
| 373 | * @param validTimeEnabled | 358 | * @param validTimeEnabled |
| 374 | * @param userType | 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 | public void deleteCard(String deviceId, String card) { | 365 | public void deleteCard(String deviceId, String card) { |
| 381 | HttpUtil.deleteCard(deviceId, card); | 366 | HttpUtil.deleteCard(deviceId, card); |
| 382 | } | 367 | } |
| 383 | 368 | ||
| 384 | - | ||
| 385 | - @Async("taskExecutor") | ||
| 386 | public boolean IsDeviceOnline(String deviceId) { | 369 | public boolean IsDeviceOnline(String deviceId) { |
| 387 | return HttpUtil.IsDeviceOnline(deviceId); | 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,6 +23,8 @@ public class AttendanceBean implements Serializable { | ||
| 23 | 23 | ||
| 24 | private int isKaoqin; | 24 | private int isKaoqin; |
| 25 | 25 | ||
| 26 | + private int OutOrIn; | ||
| 27 | + | ||
| 26 | public int getIsKaoqin() { | 28 | public int getIsKaoqin() { |
| 27 | return isKaoqin; | 29 | return isKaoqin; |
| 28 | } | 30 | } |
| @@ -87,6 +89,14 @@ public class AttendanceBean implements Serializable { | @@ -87,6 +89,14 @@ public class AttendanceBean implements Serializable { | ||
| 87 | this.school_id = school_id; | 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 | @Override | 100 | @Override |
| 91 | public String toString() { | 101 | public String toString() { |
| 92 | return "AttendanceBean{" + | 102 | return "AttendanceBean{" + |
cloud/haikangface/src/main/java/com/sincere/haikangface/bean/StudentBean.java
| @@ -63,6 +63,16 @@ public class StudentBean implements Serializable { | @@ -63,6 +63,16 @@ public class StudentBean implements Serializable { | ||
| 63 | 63 | ||
| 64 | private String num; | 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 | public String getNum() { | 76 | public String getNum() { |
| 67 | return num; | 77 | return num; |
| 68 | } | 78 | } |
cloud/haikangface/src/main/java/com/sincere/haikangface/bean/UpdateCardBean.java
0 → 100644
| @@ -0,0 +1,168 @@ | @@ -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,9 +53,9 @@ public class FileControl { | ||
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | @RequestMapping(method = RequestMethod.POST, value = "uploadImg") | 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 | try { | 59 | try { |
| 60 | if (!cmsServer.getIsDeviceOnline(deviceId)) { | 60 | if (!cmsServer.getIsDeviceOnline(deviceId)) { |
| 61 | log.warn("设备ID: {},设备不在线",deviceId); | 61 | log.warn("设备ID: {},设备不在线",deviceId); |
| @@ -74,8 +74,12 @@ public class FileControl { | @@ -74,8 +74,12 @@ public class FileControl { | ||
| 74 | fileOutputStream.close(); | 74 | fileOutputStream.close(); |
| 75 | String filePath = dest.getAbsolutePath(); | 75 | String filePath = dest.getAbsolutePath(); |
| 76 | long time = System.currentTimeMillis(); | 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 | String cardNum = Long.parseLong(baseService.getCard(card),16) + ""; | 83 | String cardNum = Long.parseLong(baseService.getCard(card),16) + ""; |
| 80 | if (new File(filePath.trim()).exists()) { | 84 | if (new File(filePath.trim()).exists()) { |
| 81 | String targetPath = FileUtils.picPathComp + new File(filePath).getName(); | 85 | String targetPath = FileUtils.picPathComp + new File(filePath).getName(); |
| @@ -94,7 +98,7 @@ public class FileControl { | @@ -94,7 +98,7 @@ public class FileControl { | ||
| 94 | return "0"; | 98 | return "0"; |
| 95 | } | 99 | } |
| 96 | } else { | 100 | } else { |
| 97 | - baseService.sendFail(cardNum, filePath, deviceId,"文件不存在", userType); | 101 | + baseService.sendFailRecord(cardNum, filePath, deviceId,"文件不存在", userType,schoolId); |
| 98 | log.error("文件不存在:" + filePath); | 102 | log.error("文件不存在:" + filePath); |
| 99 | } | 103 | } |
| 100 | } catch (Exception e) { | 104 | } catch (Exception e) { |
| @@ -106,25 +110,27 @@ public class FileControl { | @@ -106,25 +110,27 @@ public class FileControl { | ||
| 106 | @RequestMapping(value = "IsDeviceOnline", method = RequestMethod.GET) | 110 | @RequestMapping(value = "IsDeviceOnline", method = RequestMethod.GET) |
| 107 | @ApiOperation("判断设备是否在线") | 111 | @ApiOperation("判断设备是否在线") |
| 108 | public String IsDeviceOnline(@RequestParam("deviceId") String deviceId) { | 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 | @RequestMapping(value = "DeleteCard", method = RequestMethod.GET) | 120 | @RequestMapping(value = "DeleteCard", method = RequestMethod.GET) |
| 114 | - @ApiOperation("删除人脸") | 121 | + @ApiOperation("删除设备人脸") |
| 115 | public String deleteCard(@RequestParam("deviceId") String deviceId, @RequestParam("card") String card) { | 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 | @RequestMapping(value = "getCard", method = RequestMethod.GET) | 130 | @RequestMapping(value = "getCard", method = RequestMethod.GET) |
| 123 | @ApiOperation("获取设备人脸是否存在") | 131 | @ApiOperation("获取设备人脸是否存在") |
| 124 | public String getCard(@RequestParam("deviceId") String deviceId, @RequestParam("card") String card) { | 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 | return "1"; | 134 | return "1"; |
| 129 | }else{ | 135 | }else{ |
| 130 | return "0"; | 136 | return "0"; |
cloud/haikangface/src/main/java/com/sincere/haikangface/control/UserControl.java
| 1 | package com.sincere.haikangface.control; | 1 | package com.sincere.haikangface.control; |
| 2 | + | ||
| 2 | import com.alibaba.fastjson.JSON; | 3 | import com.alibaba.fastjson.JSON; |
| 3 | -import com.sincere.haikangface.bean.*; | ||
| 4 | import com.sincere.haikangface.CMSServer; | 4 | import com.sincere.haikangface.CMSServer; |
| 5 | import com.sincere.haikangface.async.SendUserAsync; | 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 | import com.sincere.haikangface.bean.face.PermissionBean; | 9 | import com.sincere.haikangface.bean.face.PermissionBean; |
| 7 | import com.sincere.haikangface.bean.face.UserAndPermission; | 10 | import com.sincere.haikangface.bean.face.UserAndPermission; |
| 8 | import com.sincere.haikangface.dao.UserDao; | 11 | import com.sincere.haikangface.dao.UserDao; |
| 9 | import com.sincere.haikangface.fegin.HaikangfaceFegin; | 12 | import com.sincere.haikangface.fegin.HaikangfaceFegin; |
| 10 | import com.sincere.haikangface.service.impl.BaseService; | 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 | import com.sincere.haikangface.xiananDao.SendRecordDao; | 17 | import com.sincere.haikangface.xiananDao.SendRecordDao; |
| 13 | import io.swagger.annotations.Api; | 18 | import io.swagger.annotations.Api; |
| 14 | -import io.swagger.annotations.ApiImplicitParam; | ||
| 15 | -import io.swagger.annotations.ApiImplicitParams; | ||
| 16 | import io.swagger.annotations.ApiOperation; | 19 | import io.swagger.annotations.ApiOperation; |
| 17 | import lombok.extern.slf4j.Slf4j; | 20 | import lombok.extern.slf4j.Slf4j; |
| 18 | import org.springframework.beans.factory.annotation.Autowired; | 21 | import org.springframework.beans.factory.annotation.Autowired; |
| 19 | import org.springframework.http.MediaType; | 22 | import org.springframework.http.MediaType; |
| 20 | import org.springframework.util.StringUtils; | 23 | import org.springframework.util.StringUtils; |
| 21 | import org.springframework.web.bind.annotation.*; | 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 | import java.text.SimpleDateFormat; | 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 | @RestController | 32 | @RestController |
| 28 | @RequestMapping(value = "/facereco/*", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) | 33 | @RequestMapping(value = "/facereco/*", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) |
| @@ -52,7 +57,6 @@ public class UserControl { | @@ -52,7 +57,6 @@ public class UserControl { | ||
| 52 | @ApiOperation("下发权限给设备") | 57 | @ApiOperation("下发权限给设备") |
| 53 | public boolean sendPermiss(@RequestBody PermissionBean permissionBean) { | 58 | public boolean sendPermiss(@RequestBody PermissionBean permissionBean) { |
| 54 | log.error("permissionBean:{}", JSON.toJSONString(permissionBean)); | 59 | log.error("permissionBean:{}", JSON.toJSONString(permissionBean)); |
| 55 | - FileUtils.getInstance().writeLogs("传入权限模板:" + JSON.toJSONString(permissionBean), "设置权限内容.txt"); | ||
| 56 | if (!StringUtils.isEmpty(permissionBean.getDeviceIds())) { | 60 | if (!StringUtils.isEmpty(permissionBean.getDeviceIds())) { |
| 57 | return sendUserAsync.sendPermiss(permissionBean, 0); | 61 | return sendUserAsync.sendPermiss(permissionBean, 0); |
| 58 | } | 62 | } |
| @@ -63,33 +67,22 @@ public class UserControl { | @@ -63,33 +67,22 @@ public class UserControl { | ||
| 63 | @ApiOperation("下发指定教师用户权限给设备") | 67 | @ApiOperation("下发指定教师用户权限给设备") |
| 64 | public boolean sendUsersAndPermiss(@RequestBody UserAndPermission userAndPermission) { | 68 | public boolean sendUsersAndPermiss(@RequestBody UserAndPermission userAndPermission) { |
| 65 | log.info("下发指定教师权限,权限信息permission:{}", JSON.toJSONString(userAndPermission)); | 69 | log.info("下发指定教师权限,权限信息permission:{}", JSON.toJSONString(userAndPermission)); |
| 66 | - FileUtils.getInstance().writeLogs(JSON.toJSONString(userAndPermission), "下发指定教师用户权限给设备.txt"); | ||
| 67 | PermissionBean permissionBean = new PermissionBean(); | 70 | PermissionBean permissionBean = new PermissionBean(); |
| 68 | permissionBean.setSchoolId(userAndPermission.getSchoolId()); | 71 | permissionBean.setSchoolId(userAndPermission.getSchoolId()); |
| 69 | permissionBean.setUserType(String.valueOf(userAndPermission.getUserType())); | 72 | permissionBean.setUserType(String.valueOf(userAndPermission.getUserType())); |
| 70 | permissionBean.setWeekDays(userAndPermission.getWeekDays()); | 73 | permissionBean.setWeekDays(userAndPermission.getWeekDays()); |
| 71 | return sendUserAsync.sendPermiss(permissionBean, 0); | 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 | @ApiOperation("下发人脸给设备") | 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 | @RequestMapping(value = "sendImg2Devices", method = RequestMethod.POST) | 85 | @RequestMapping(value = "sendImg2Devices", method = RequestMethod.POST) |
| 92 | - @ApiOperation("本地下发人脸给设备") | ||
| 93 | public boolean sendImg2Devices(@RequestBody Images2Ddevices images2Ddevices) throws Exception { | 86 | public boolean sendImg2Devices(@RequestBody Images2Ddevices images2Ddevices) throws Exception { |
| 94 | String startTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); | 87 | String startTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); |
| 95 | Calendar calendar = Calendar.getInstance(); | 88 | Calendar calendar = Calendar.getInstance(); |
| @@ -139,7 +132,7 @@ public class UserControl { | @@ -139,7 +132,7 @@ public class UserControl { | ||
| 139 | String cardNum = Long.parseLong(baseService.getCard(card), 16) + ""; | 132 | String cardNum = Long.parseLong(baseService.getCard(card), 16) + ""; |
| 140 | sendUserAsync.sendStuToHaiKang(filePath.getAbsolutePath(),targetPath,cardNum, startTime, endTime,1, name, devId, images2Ddevices.getUserType(), 0,card); | 133 | sendUserAsync.sendStuToHaiKang(filePath.getAbsolutePath(),targetPath,cardNum, startTime, endTime,1, name, devId, images2Ddevices.getUserType(), 0,card); |
| 141 | } else { | 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 | } else { | 137 | } else { |
| 145 | log.error("学生对象不存在"); | 138 | log.error("学生对象不存在"); |
| @@ -155,7 +148,6 @@ public class UserControl { | @@ -155,7 +148,6 @@ public class UserControl { | ||
| 155 | } | 148 | } |
| 156 | 149 | ||
| 157 | @RequestMapping(value = "sendFaces", method = RequestMethod.GET) | 150 | @RequestMapping(value = "sendFaces", method = RequestMethod.GET) |
| 158 | - @ApiOperation(value = "下发学校下所有人脸给指定设备", notes = "下发所有人脸给指定设备") | ||
| 159 | public void sendFaces(@RequestParam("deviceIds") String deviceIds, @RequestParam("schoolId") String schoolId, @RequestParam("userType") String userType) { | 151 | public void sendFaces(@RequestParam("deviceIds") String deviceIds, @RequestParam("schoolId") String schoolId, @RequestParam("userType") String userType) { |
| 160 | String typeName = userType.equals("1") ? "Teacher" : "Student"; | 152 | String typeName = userType.equals("1") ? "Teacher" : "Student"; |
| 161 | String imgPath = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\" + typeName; | 153 | String imgPath = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\" + typeName; |
| @@ -201,12 +193,6 @@ public class UserControl { | @@ -201,12 +193,6 @@ public class UserControl { | ||
| 201 | } | 193 | } |
| 202 | 194 | ||
| 203 | @RequestMapping(value = "sendErrorFaces", method = RequestMethod.GET) | 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 | public void sendErrorFaces(String schoolId, String deviceid, String userType) { | 196 | public void sendErrorFaces(String schoolId, String deviceid, String userType) { |
| 211 | log.info("开始下发失败人脸:schoolId:" + schoolId + "---deviceid:" + deviceid + "---userType:" + userType); | 197 | log.info("开始下发失败人脸:schoolId:" + schoolId + "---deviceid:" + deviceid + "---userType:" + userType); |
| 212 | //不传的话就默认失败表中的类型 | 198 | //不传的话就默认失败表中的类型 |
| @@ -225,9 +211,7 @@ public class UserControl { | @@ -225,9 +211,7 @@ public class UserControl { | ||
| 225 | } | 211 | } |
| 226 | 212 | ||
| 227 | @RequestMapping(value = "sendFaceNotExits", method = RequestMethod.GET) | 213 | @RequestMapping(value = "sendFaceNotExits", method = RequestMethod.GET) |
| 228 | - @ApiOperation(value = "下发学校下还没有下发的人脸给指定设备", notes = "下发学校下还没有下发的人脸给指定设备") | ||
| 229 | public void sendFaceNotExits(@RequestParam("deviceIds") String deviceIds, @RequestParam("schoolId") String schoolId, @RequestParam("userType") String userType) { | 214 | public void sendFaceNotExits(@RequestParam("deviceIds") String deviceIds, @RequestParam("schoolId") String schoolId, @RequestParam("userType") String userType) { |
| 230 | - | ||
| 231 | String typeName = userType.equals("1") ? "Teacher" : "Student"; | 215 | String typeName = userType.equals("1") ? "Teacher" : "Student"; |
| 232 | 216 | ||
| 233 | String imgPath = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\" + typeName; | 217 | String imgPath = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\" + typeName; |
| @@ -282,52 +266,35 @@ public class UserControl { | @@ -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 | @RequestMapping(value = "DeleteCard", method = RequestMethod.GET) | 269 | @RequestMapping(value = "DeleteCard", method = RequestMethod.GET) |
| 311 | - @ApiOperation("删除人脸") | ||
| 312 | public boolean deleteCard(@RequestParam("deviceId") String deviceId, @RequestParam("card") String card) { | 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 | if (cmsServer.getIsDeviceOnline(deviceId)) { | 276 | if (cmsServer.getIsDeviceOnline(deviceId)) { |
| 316 | String cardNo = Long.parseLong(baseService.getCard(card), 16) + ""; | 277 | String cardNo = Long.parseLong(baseService.getCard(card), 16) + ""; |
| 317 | - cmsServer.deleteCard(deviceId, cardNo,schoolId); | 278 | + return cmsServer.deleteCard(deviceId, cardNo,null); |
| 318 | }else{ | 279 | }else{ |
| 319 | - HttpUtil.deleteCard(deviceId, card); | 280 | + return HttpUtil.deleteCard(deviceId, card); |
| 320 | } | 281 | } |
| 321 | - return true; | ||
| 322 | } | 282 | } |
| 323 | 283 | ||
| 324 | @RequestMapping(value = "getCard", method = RequestMethod.GET) | 284 | @RequestMapping(value = "getCard", method = RequestMethod.GET) |
| 325 | @ApiOperation("获取设备人脸是否存在") | 285 | @ApiOperation("获取设备人脸是否存在") |
| 326 | public boolean getCard(@RequestParam("deviceId") String deviceId,@RequestParam("card") String card) { | 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 | @RequestMapping(value = "IsDeviceOnline", method = RequestMethod.GET) | 300 | @RequestMapping(value = "IsDeviceOnline", method = RequestMethod.GET) |
| @@ -340,80 +307,10 @@ public class UserControl { | @@ -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 | @RequestMapping(value = "isTeacher", method = RequestMethod.GET) | 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 | try { | 312 | try { |
| 416 | - cmsServer.isTeacher(cardNo, deviceId); | 313 | + cmsServer.isTeacher(cardNo, deviceId,schoolId); |
| 417 | } catch (Exception e) { | 314 | } catch (Exception e) { |
| 418 | e.printStackTrace(); | 315 | e.printStackTrace(); |
| 419 | } | 316 | } |
| @@ -423,7 +320,7 @@ public class UserControl { | @@ -423,7 +320,7 @@ public class UserControl { | ||
| 423 | @ApiOperation("发送数据到看板") | 320 | @ApiOperation("发送数据到看板") |
| 424 | public void sendToKB(@RequestParam("filePath") String filePath, @RequestParam("deviceid") String deviceid) { | 321 | public void sendToKB(@RequestParam("filePath") String filePath, @RequestParam("deviceid") String deviceid) { |
| 425 | try { | 322 | try { |
| 426 | - baseService.sendUserInfoToKB(new File(filePath), deviceid); | 323 | + cmsServer.sendUserInfoToKB(new File(filePath), deviceid); |
| 427 | } catch (Exception e) { | 324 | } catch (Exception e) { |
| 428 | e.printStackTrace(); | 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,6 +13,7 @@ import lombok.extern.slf4j.Slf4j; | ||
| 13 | import org.springframework.beans.factory.annotation.Autowired; | 13 | import org.springframework.beans.factory.annotation.Autowired; |
| 14 | import org.springframework.http.MediaType; | 14 | import org.springframework.http.MediaType; |
| 15 | import org.springframework.web.bind.annotation.*; | 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,15 +67,9 @@ public class UserOperateController { | ||
| 66 | } | 67 | } |
| 67 | 68 | ||
| 68 | @ApiOperation(value = "照片下发2.0") | 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 | @RequestMapping(value = "sendFaceByThread", method = RequestMethod.POST) | 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 | @ApiOperation(value = "删除下发失败人脸2.0") | 75 | @ApiOperation(value = "删除下发失败人脸2.0") |
| @@ -91,14 +86,32 @@ public class UserOperateController { | @@ -91,14 +86,32 @@ public class UserOperateController { | ||
| 91 | 86 | ||
| 92 | @ApiOperation(value = "删除指定人脸2.0") | 87 | @ApiOperation(value = "删除指定人脸2.0") |
| 93 | @RequestMapping(value = "deleteFace", method = RequestMethod.POST) | 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 | return userOperateService.deleteFace(schoolId,cards,deviceIds); | 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,13 +49,6 @@ public interface UserDao { | ||
| 49 | @Select("select * from SZ_User where user_id = #{user_id}") | 49 | @Select("select * from SZ_User where user_id = #{user_id}") |
| 50 | UserBean getUser(@Param("user_id") String user_id); | 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 | @Select("select school_name from SZ_School where school_id = #{schoolid}") | 52 | @Select("select school_name from SZ_School where school_id = #{schoolid}") |
| 60 | String getSchoolName(@Param("schoolid") String schoolid); | 53 | String getSchoolName(@Param("schoolid") String schoolid); |
| 61 | 54 | ||
| @@ -264,16 +257,31 @@ public interface UserDao { | @@ -264,16 +257,31 @@ public interface UserDao { | ||
| 264 | 257 | ||
| 265 | void updateAuthRecord(@Param("id") Integer authId, @Param("grantState") Integer grantState); | 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 | @Select("select clint_type from SZ_Attendance where clint_id = #{deviceId}") | 260 | @Select("select clint_type from SZ_Attendance where clint_id = #{deviceId}") |
| 272 | Integer getClintTypeByDeviceId(@Param("deviceId") String deviceId); | 261 | Integer getClintTypeByDeviceId(@Param("deviceId") String deviceId); |
| 273 | 262 | ||
| 274 | List<StudentBean> getStudentList(@Param("schoolId") Integer schoolId,@Param("studentType")Integer studentType,@Param("sex") List<Integer> sex); | 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 | List<StudentBean> getTeacherList(@Param("schoolId") Integer schoolId); | 267 | List<StudentBean> getTeacherList(@Param("schoolId") Integer schoolId); |
| 277 | 268 | ||
| 278 | List<String> getDeviceIds(@Param("schoolId") Integer schoolId,@Param("deviceId") String deviceId); | 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
| @@ -21,7 +21,6 @@ public class MqtUtils { | @@ -21,7 +21,6 @@ public class MqtUtils { | ||
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | public void sendMsg(String deviceId, String content) { | 23 | public void sendMsg(String deviceId, String content) { |
| 24 | - | ||
| 25 | mqttManager.sendMq(deviceId, content); | 24 | mqttManager.sendMq(deviceId, content); |
| 26 | } | 25 | } |
| 27 | 26 |
cloud/haikangface/src/main/java/com/sincere/haikangface/mqtt/MqttManager.java
| @@ -23,20 +23,6 @@ public class MqttManager { | @@ -23,20 +23,6 @@ public class MqttManager { | ||
| 23 | 23 | ||
| 24 | private static MqttManager mqttManager; | 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 | public void init() { | 26 | public void init() { |
| 41 | final String brokerUrl = "tcp://post-cn-4590mq2hr03.mqtt.aliyuncs.com:1883"; | 27 | final String brokerUrl = "tcp://post-cn-4590mq2hr03.mqtt.aliyuncs.com:1883"; |
| 42 | groupId = "GID_HFJSIURFHAQO110"; | 28 | groupId = "GID_HFJSIURFHAQO110"; |
| @@ -97,15 +83,6 @@ public class MqttManager { | @@ -97,15 +83,6 @@ public class MqttManager { | ||
| 97 | System.out.println("mqtt:" + e.toString()); | 83 | System.out.println("mqtt:" + e.toString()); |
| 98 | e.printStackTrace(); | 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,9 +3,8 @@ package com.sincere.haikangface.service; | ||
| 3 | import com.sincere.haikangface.bean.Result; | 3 | import com.sincere.haikangface.bean.Result; |
| 4 | import com.sincere.haikangface.bean.face.AuthRecordDto; | 4 | import com.sincere.haikangface.bean.face.AuthRecordDto; |
| 5 | import com.sincere.haikangface.bean.face.DeviceAuthRecord; | 5 | import com.sincere.haikangface.bean.face.DeviceAuthRecord; |
| 6 | -import com.sincere.haikangface.bean.face.PermissionBean; | ||
| 7 | import com.sincere.haikangface.bean.face.SendFaceDto; | 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,20 +52,11 @@ public interface UserOperateService { | ||
| 53 | Result againSendFace(String userId,String deviceId,Integer userType); | 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 | * @param sendFaceDto | 56 | * @param sendFaceDto |
| 67 | * @return | 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,6 +81,27 @@ public interface UserOperateService { | ||
| 91 | */ | 81 | */ |
| 92 | Result deleteFace(Integer schoolId,String cards,String deviceIds); | 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 | package com.sincere.haikangface.service.impl; | 1 | package com.sincere.haikangface.service.impl; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | -import com.alibaba.fastjson.JSONArray; | ||
| 5 | -import com.alibaba.fastjson.JSONObject; | ||
| 6 | import com.google.common.util.concurrent.ThreadFactoryBuilder; | 4 | import com.google.common.util.concurrent.ThreadFactoryBuilder; |
| 7 | import com.sincere.haikangface.CMSServer; | 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 | import com.sincere.haikangface.async.SendUserAsync; | 7 | import com.sincere.haikangface.async.SendUserAsync; |
| 11 | -import com.sincere.haikangface.bean.BaiduFaceRecorder; | ||
| 12 | import com.sincere.haikangface.bean.SendRecordBean; | 8 | import com.sincere.haikangface.bean.SendRecordBean; |
| 13 | import com.sincere.haikangface.bean.StudentBean; | 9 | import com.sincere.haikangface.bean.StudentBean; |
| 14 | -import com.sincere.haikangface.bean.TeacherBean; | ||
| 15 | import com.sincere.haikangface.dao.UserDao; | 10 | import com.sincere.haikangface.dao.UserDao; |
| 16 | import com.sincere.haikangface.enums.EnumSzBusinessType; | 11 | import com.sincere.haikangface.enums.EnumSzBusinessType; |
| 17 | -import com.sincere.haikangface.mqtt.MqtUtils; | ||
| 18 | import com.sincere.haikangface.utils.CompressPic; | 12 | import com.sincere.haikangface.utils.CompressPic; |
| 19 | import com.sincere.haikangface.utils.DateUtils; | 13 | import com.sincere.haikangface.utils.DateUtils; |
| 20 | import com.sincere.haikangface.utils.FileUtils; | 14 | import com.sincere.haikangface.utils.FileUtils; |
| 21 | -import com.sincere.haikangface.utils.HttpUtil; | ||
| 22 | import com.sincere.haikangface.xiananDao.SendRecordDao; | 15 | import com.sincere.haikangface.xiananDao.SendRecordDao; |
| 23 | import lombok.extern.slf4j.Slf4j; | 16 | import lombok.extern.slf4j.Slf4j; |
| 24 | import org.apache.commons.lang3.StringUtils; | 17 | import org.apache.commons.lang3.StringUtils; |
| 25 | import org.springframework.beans.factory.annotation.Autowired; | 18 | import org.springframework.beans.factory.annotation.Autowired; |
| 26 | -import org.springframework.beans.factory.annotation.Value; | ||
| 27 | import org.springframework.scheduling.annotation.Async; | 19 | import org.springframework.scheduling.annotation.Async; |
| 28 | import org.springframework.stereotype.Service; | 20 | import org.springframework.stereotype.Service; |
| 29 | 21 | ||
| @@ -51,10 +43,7 @@ public class BaseService { | @@ -51,10 +43,7 @@ public class BaseService { | ||
| 51 | @Autowired | 43 | @Autowired |
| 52 | SendUserAsync sendUserAsync; | 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 | try { | 47 | try { |
| 59 | if (new File(filePath.trim()).exists()) { | 48 | if (new File(filePath.trim()).exists()) { |
| 60 | String targetPath = FileUtils.picPathComp + new File(filePath).getName(); | 49 | String targetPath = FileUtils.picPathComp + new File(filePath).getName(); |
| @@ -63,12 +52,14 @@ public class BaseService { | @@ -63,12 +52,14 @@ public class BaseService { | ||
| 63 | } catch (Exception e) { | 52 | } catch (Exception e) { |
| 64 | e.printStackTrace(); | 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 | return sendImg(filePath, targetPath, deviceId, card, name, userType,schoolId); | 60 | return sendImg(filePath, targetPath, deviceId, card, name, userType,schoolId); |
| 70 | } else { | 61 | } else { |
| 71 | - sendFail(Long.parseLong(getCard(card), 16) + "", filePath, deviceId,"文件不存在", userType); | 62 | + sendFailRecord(Long.parseLong(getCard(card), 16) + "", filePath, deviceId,"文件不存在", userType,schoolId); |
| 72 | System.out.println("文件不存在:" + filePath); | 63 | System.out.println("文件不存在:" + filePath); |
| 73 | } | 64 | } |
| 74 | } catch (Exception e) { | 65 | } catch (Exception e) { |
| @@ -95,13 +86,13 @@ public class BaseService { | @@ -95,13 +86,13 @@ public class BaseService { | ||
| 95 | //下发标识:详情见枚举 EnumHkOperateType | 86 | //下发标识:详情见枚举 EnumHkOperateType |
| 96 | int validTimeEnabled = EnumSzBusinessType.EnumHkOperateType.ADD.code; | 87 | int validTimeEnabled = EnumSzBusinessType.EnumHkOperateType.ADD.code; |
| 97 | try { | 88 | try { |
| 98 | - FileUtils.getInstance().writeLogs("startTime:" + startTime + "---endTime:" + endTime + "---card:" + card, "下发参数"); | 89 | + log.info("startTime:" + startTime + "---endTime:" + endTime + "---card:" + card); |
| 99 | if (cmsServer.getIsDeviceOnline(deviceId)) { | 90 | if (cmsServer.getIsDeviceOnline(deviceId)) { |
| 100 | String cardNo = Long.parseLong(getCard(card),16)+""; | 91 | String cardNo = Long.parseLong(getCard(card),16)+""; |
| 101 | //下发海康设备 | 92 | //下发海康设备 |
| 102 | sendUserAsync.sendStuToHaiKang(filePath,targetPath, cardNo, startTime, endTime, validTimeEnabled, name, deviceId, userType,schoolId,card); | 93 | sendUserAsync.sendStuToHaiKang(filePath,targetPath, cardNo, startTime, endTime, validTimeEnabled, name, deviceId, userType,schoolId,card); |
| 103 | }else { | 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 | return true; | 97 | return true; |
| 107 | } catch (Exception e) { | 98 | } catch (Exception e) { |
| @@ -158,15 +149,15 @@ public class BaseService { | @@ -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 | try{ | 153 | try{ |
| 163 | StudentBean studentBean = null; | 154 | StudentBean studentBean = null; |
| 164 | switch (userType) { | 155 | switch (userType) { |
| 165 | case "1"://老师 | 156 | case "1"://老师 |
| 166 | - studentBean = userDao.getTeacherWithCard(resultCard); | 157 | + studentBean = userDao.getTeacherWithCard(resultCard,schoolId); |
| 167 | break; | 158 | break; |
| 168 | case "2"://学生 | 159 | case "2"://学生 |
| 169 | - studentBean = userDao.getStudentWithCard(resultCard); | 160 | + studentBean = userDao.getStudentWithCard(resultCard,schoolId); |
| 170 | break; | 161 | break; |
| 171 | case "3"://家长 | 162 | case "3"://家长 |
| 172 | break; | 163 | break; |
| @@ -176,8 +167,6 @@ public class BaseService { | @@ -176,8 +167,6 @@ public class BaseService { | ||
| 176 | String userId = studentBean.getUser_id(); | 167 | String userId = studentBean.getUser_id(); |
| 177 | //用户名称 | 168 | //用户名称 |
| 178 | String userName = studentBean.getName(); | 169 | String userName = studentBean.getName(); |
| 179 | - //所属学校 | ||
| 180 | - int schoolId = studentBean.getSchool_id(); | ||
| 181 | String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); | 170 | String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); |
| 182 | String schoolName = userDao.getSchoolName(studentBean.getSchool_id() + ""); | 171 | String schoolName = userDao.getSchoolName(studentBean.getSchool_id() + ""); |
| 183 | List<SendRecordBean> sendRecordBeans = sendRecordDao.getRecordIsExit(deviceId,resultCard,userId); | 172 | List<SendRecordBean> sendRecordBeans = sendRecordDao.getRecordIsExit(deviceId,resultCard,userId); |
| @@ -187,11 +176,10 @@ public class BaseService { | @@ -187,11 +176,10 @@ public class BaseService { | ||
| 187 | } | 176 | } |
| 188 | if (null == sendRecordBean) { | 177 | if (null == sendRecordBean) { |
| 189 | sendRecordDao.saveFaceRecord(userId, deviceId, resultCard, userName, time, schoolName, | 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 | } else { | 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 | } else { | 183 | } else { |
| 196 | log.error("用户不存在: 对应卡号{} ," + resultCard); | 184 | log.error("用户不存在: 对应卡号{} ," + resultCard); |
| 197 | } | 185 | } |
| @@ -207,15 +195,16 @@ public class BaseService { | @@ -207,15 +195,16 @@ public class BaseService { | ||
| 207 | * @param content | 195 | * @param content |
| 208 | * @param userType | 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 | try{ | 200 | try{ |
| 212 | StudentBean studentBean = null; | 201 | StudentBean studentBean = null; |
| 213 | switch (userType) { | 202 | switch (userType) { |
| 214 | case "1"://老师 | 203 | case "1"://老师 |
| 215 | - studentBean = userDao.getTeacherWithCard(resultCard); | 204 | + studentBean = userDao.getTeacherWithCard(resultCard,schoolId); |
| 216 | break; | 205 | break; |
| 217 | case "2"://学生 | 206 | case "2"://学生 |
| 218 | - studentBean = userDao.getStudentWithCard(resultCard); | 207 | + studentBean = userDao.getStudentWithCard(resultCard,schoolId); |
| 219 | break; | 208 | break; |
| 220 | case "3"://家长 | 209 | case "3"://家长 |
| 221 | break; | 210 | break; |
| @@ -225,8 +214,6 @@ public class BaseService { | @@ -225,8 +214,6 @@ public class BaseService { | ||
| 225 | String userId = studentBean.getUser_id(); | 214 | String userId = studentBean.getUser_id(); |
| 226 | //用户名称 | 215 | //用户名称 |
| 227 | String userName = studentBean.getName(); | 216 | String userName = studentBean.getName(); |
| 228 | - //所属学校 | ||
| 229 | - int schoolId = studentBean.getSchool_id(); | ||
| 230 | String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); | 217 | String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); |
| 231 | String schoolName = userDao.getSchoolName(studentBean.getSchool_id() + ""); | 218 | String schoolName = userDao.getSchoolName(studentBean.getSchool_id() + ""); |
| 232 | List<SendRecordBean> sendRecordBeans = sendRecordDao.getRecordIsExit(deviceId,resultCard,userId); | 219 | List<SendRecordBean> sendRecordBeans = sendRecordDao.getRecordIsExit(deviceId,resultCard,userId); |
| @@ -236,7 +223,7 @@ public class BaseService { | @@ -236,7 +223,7 @@ public class BaseService { | ||
| 236 | } | 223 | } |
| 237 | if (null == sendRecordBean) { | 224 | if (null == sendRecordBean) { |
| 238 | sendRecordDao.saveFaceRecord(userId, deviceId, resultCard, userName, time, schoolName, | 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 | }else { | 227 | }else { |
| 241 | sendRecordDao.updateFaceFailRecord(deviceId,faceUrl,resultCard,time,content,userId); | 228 | sendRecordDao.updateFaceFailRecord(deviceId,faceUrl,resultCard,time,content,userId); |
| 242 | } | 229 | } |
| @@ -248,103 +235,6 @@ public class BaseService { | @@ -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 | * @param card | 240 | * @param card |
| @@ -379,153 +269,8 @@ public class BaseService { | @@ -379,153 +269,8 @@ public class BaseService { | ||
| 379 | return dateStr; | 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 | @Async | 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 | List<String> deviceId_100 = new ArrayList<>(); | 274 | List<String> deviceId_100 = new ArrayList<>(); |
| 530 | List<String> deviceId_253 = new ArrayList<>(); | 275 | List<String> deviceId_253 = new ArrayList<>(); |
| 531 | //过滤设备 | 276 | //过滤设备 |
| @@ -537,46 +282,19 @@ public class BaseService { | @@ -537,46 +282,19 @@ public class BaseService { | ||
| 537 | deviceId_253.add(sno); | 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 | if(deviceId_100.size()>0){ | 285 | if(deviceId_100.size()>0){ |
| 550 | //100服务器 | 286 | //100服务器 |
| 551 | - sendFaceToDevice100(deviceId_100,studentBeanList,String.valueOf(schoolId),userType); | 287 | + sendFaceToDevice100(deviceId_100,studentBeanList,schoolId,userType); |
| 552 | } | 288 | } |
| 553 | if(deviceId_253.size()>0){ | 289 | if(deviceId_253.size()>0){ |
| 554 | //253服务器 | 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 | log.info("------------------------开始执行100服务,人脸照下发---------------------"); | 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 | String startTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); | 298 | String startTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); |
| 581 | Calendar calendar = Calendar.getInstance(); | 299 | Calendar calendar = Calendar.getInstance(); |
| 582 | calendar.add(Calendar.YEAR, 10); | 300 | calendar.add(Calendar.YEAR, 10); |
| @@ -592,17 +310,26 @@ public class BaseService { | @@ -592,17 +310,26 @@ public class BaseService { | ||
| 592 | if (StringUtils.isBlank(photo) || StringUtils.isBlank(cardNum)){ | 310 | if (StringUtils.isBlank(photo) || StringUtils.isBlank(cardNum)){ |
| 593 | continue; | 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 | String filePath=""; | 323 | String filePath=""; |
| 598 | if(photo.indexOf("f0i5l7e5")!=-1){ | 324 | if(photo.indexOf("f0i5l7e5")!=-1){ |
| 599 | String afterStr = photo.split("f0i5l7e5/")[1].replace("/","\\"); | 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 | log.info("卡号:{},人脸路径:{}, ",cardNum,filePath); | 334 | log.info("卡号:{},人脸路径:{}, ",cardNum,filePath); |
| 608 | File file = new File(filePath);//图片 | 335 | File file = new File(filePath);//图片 |
| @@ -611,8 +338,7 @@ public class BaseService { | @@ -611,8 +338,7 @@ public class BaseService { | ||
| 611 | try { | 338 | try { |
| 612 | CompressPic.CompressPic(file.getAbsolutePath(), targetPath); | 339 | CompressPic.CompressPic(file.getAbsolutePath(), targetPath); |
| 613 | } catch (Exception e) { | 340 | } catch (Exception e) { |
| 614 | - log.error("压缩图片失败"); | ||
| 615 | - e.printStackTrace(); | 341 | + log.error("压缩图片失败:",e); |
| 616 | continue; | 342 | continue; |
| 617 | } | 343 | } |
| 618 | for(String sno : deviceIds){ | 344 | for(String sno : deviceIds){ |
| @@ -620,42 +346,23 @@ public class BaseService { | @@ -620,42 +346,23 @@ public class BaseService { | ||
| 620 | if(!StringUtils.isBlank(cardNum)){ | 346 | if(!StringUtils.isBlank(cardNum)){ |
| 621 | String cardNumLong = Long.parseLong(getCard(cardNum),16) + ""; | 347 | String cardNumLong = Long.parseLong(getCard(cardNum),16) + ""; |
| 622 | //下发100海康设备 | 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 | }else{ | 351 | }else{ |
| 626 | log.error("100服务器,设备不在线"); | 352 | log.error("100服务器,设备不在线"); |
| 627 | } | 353 | } |
| 628 | - | ||
| 629 | } | 354 | } |
| 630 | } | 355 | } |
| 631 | }catch (Exception e){ | 356 | }catch (Exception e){ |
| 632 | - log.error("人脸下发失败"); | ||
| 633 | - e.printStackTrace(); | 357 | + log.error("人脸下发失败,异常信息:",e); |
| 634 | continue; | 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 | log.info("------------------------开始执行253服务,人脸照下发---------------------"); | 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 | String startTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); | 366 | String startTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); |
| 660 | Calendar calendar = Calendar.getInstance(); | 367 | Calendar calendar = Calendar.getInstance(); |
| 661 | calendar.add(Calendar.YEAR, 10); | 368 | calendar.add(Calendar.YEAR, 10); |
| @@ -671,21 +378,41 @@ public class BaseService { | @@ -671,21 +378,41 @@ public class BaseService { | ||
| 671 | if (StringUtils.isBlank(photo) || StringUtils.isBlank(cardNum)){ | 378 | if (StringUtils.isBlank(photo) || StringUtils.isBlank(cardNum)){ |
| 672 | continue; | 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 | String filePath=""; | 391 | String filePath=""; |
| 676 | if(photo.indexOf("f0i5l7e5")!=-1){ | 392 | if(photo.indexOf("f0i5l7e5")!=-1){ |
| 677 | String afterStr = photo.split("f0i5l7e5/")[1].replace("/","\\"); | 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 | log.info("卡号:{},人脸路径:{}, ",cardNum,filePath); | 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 | }catch (Exception e){ | 417 | }catch (Exception e){ |
| 691 | log.error("人脸下发失败"); | 418 | log.error("人脸下发失败"); |
| @@ -728,6 +455,21 @@ public class BaseService { | @@ -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 | * @param schoolId | 474 | * @param schoolId |
| 733 | * @return | 475 | * @return |
| @@ -739,4 +481,31 @@ public class BaseService { | @@ -739,4 +481,31 @@ public class BaseService { | ||
| 739 | Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(StudentBean::getTeacher_num))), ArrayList::new)); | 481 | Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(StudentBean::getTeacher_num))), ArrayList::new)); |
| 740 | return teacherist; | 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,12 +4,8 @@ import com.alibaba.fastjson.JSON; | ||
| 4 | import com.fasterxml.jackson.databind.JavaType; | 4 | import com.fasterxml.jackson.databind.JavaType; |
| 5 | import com.sincere.haikangface.CMSServer; | 5 | import com.sincere.haikangface.CMSServer; |
| 6 | import com.sincere.haikangface.async.SendUserAsync; | 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 | import com.sincere.haikangface.bean.face.*; | 8 | import com.sincere.haikangface.bean.face.*; |
| 12 | -import com.sincere.haikangface.control.UserControl; | ||
| 13 | import com.sincere.haikangface.dao.DeviceDao; | 9 | import com.sincere.haikangface.dao.DeviceDao; |
| 14 | import com.sincere.haikangface.dao.UserDao; | 10 | import com.sincere.haikangface.dao.UserDao; |
| 15 | import com.sincere.haikangface.enums.EnumSzBusinessType; | 11 | import com.sincere.haikangface.enums.EnumSzBusinessType; |
| @@ -17,14 +13,16 @@ import com.sincere.haikangface.service.UserOperateService; | @@ -17,14 +13,16 @@ import com.sincere.haikangface.service.UserOperateService; | ||
| 17 | import com.sincere.haikangface.utils.*; | 13 | import com.sincere.haikangface.utils.*; |
| 18 | import com.sincere.haikangface.xiananDao.SendRecordDao; | 14 | import com.sincere.haikangface.xiananDao.SendRecordDao; |
| 19 | import lombok.extern.slf4j.Slf4j; | 15 | import lombok.extern.slf4j.Slf4j; |
| 16 | +import org.apache.commons.collections4.CollectionUtils; | ||
| 20 | import org.apache.commons.lang3.StringUtils; | 17 | import org.apache.commons.lang3.StringUtils; |
| 21 | import org.springframework.beans.factory.annotation.Autowired; | 18 | import org.springframework.beans.factory.annotation.Autowired; |
| 22 | import org.springframework.scheduling.annotation.Async; | 19 | import org.springframework.scheduling.annotation.Async; |
| 23 | import org.springframework.stereotype.Service; | 20 | import org.springframework.stereotype.Service; |
| 21 | +import org.springframework.web.multipart.MultipartFile; | ||
| 24 | 22 | ||
| 25 | import java.io.File; | 23 | import java.io.File; |
| 24 | +import java.io.FileOutputStream; | ||
| 26 | import java.io.IOException; | 25 | import java.io.IOException; |
| 27 | -import java.text.SimpleDateFormat; | ||
| 28 | import java.util.*; | 26 | import java.util.*; |
| 29 | 27 | ||
| 30 | /** | 28 | /** |
| @@ -48,8 +46,6 @@ public class UserOperateServiceImpl implements UserOperateService { | @@ -48,8 +46,6 @@ public class UserOperateServiceImpl implements UserOperateService { | ||
| 48 | BaseService baseService; | 46 | BaseService baseService; |
| 49 | @Autowired | 47 | @Autowired |
| 50 | SendUserAsync sendUserAsync; | 48 | SendUserAsync sendUserAsync; |
| 51 | - @Autowired | ||
| 52 | - UserControl userControl; | ||
| 53 | 49 | ||
| 54 | private static JsonUtils objectMapper = JsonUtils.nonEmptyMapper(); | 50 | private static JsonUtils objectMapper = JsonUtils.nonEmptyMapper(); |
| 55 | 51 | ||
| @@ -106,7 +102,7 @@ public class UserOperateServiceImpl implements UserOperateService { | @@ -106,7 +102,7 @@ public class UserOperateServiceImpl implements UserOperateService { | ||
| 106 | if(deviceType.intValue()== 22 || deviceType.intValue()== 29){ | 102 | if(deviceType.intValue()== 22 || deviceType.intValue()== 29){ |
| 107 | Integer shiduan = userDao.getAuthRecordBySchoolId(schoolId,studentType,null); | 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 | }else{ | 106 | }else{ |
| 111 | //时段 | 107 | //时段 |
| 112 | record.setShiduan(null); | 108 | record.setShiduan(null); |
| @@ -147,20 +143,6 @@ public class UserOperateServiceImpl implements UserOperateService { | @@ -147,20 +143,6 @@ public class UserOperateServiceImpl implements UserOperateService { | ||
| 147 | ArrayList<WeekDay> weekDayList = objectMapper.fromJson(weekDaysJson,javaType); | 143 | ArrayList<WeekDay> weekDayList = objectMapper.fromJson(weekDaysJson,javaType); |
| 148 | //设备类型 | 144 | //设备类型 |
| 149 | Integer clintType = userDao.getClintTypeByDeviceId(devices.get(0)); | 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 | if(clintType.intValue()== 18 || clintType.intValue()== 28){ | 146 | if(clintType.intValue()== 18 || clintType.intValue()== 28){ |
| 165 | PermissionBean permissionBean = new PermissionBean(); | 147 | PermissionBean permissionBean = new PermissionBean(); |
| 166 | permissionBean.setWeekDays(weekDayList); | 148 | permissionBean.setWeekDays(weekDayList); |
| @@ -175,6 +157,20 @@ public class UserOperateServiceImpl implements UserOperateService { | @@ -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 | return ResultGenerator.genSuccessResult(); | 174 | return ResultGenerator.genSuccessResult(); |
| 179 | } | 175 | } |
| 180 | 176 | ||
| @@ -194,13 +190,13 @@ public class UserOperateServiceImpl implements UserOperateService { | @@ -194,13 +190,13 @@ public class UserOperateServiceImpl implements UserOperateService { | ||
| 194 | String cardNum =""; | 190 | String cardNum =""; |
| 195 | String photo =""; | 191 | String photo =""; |
| 196 | String studentCode = ""; | 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 | cardNum = studentBean.getTeacher_num(); | 195 | cardNum = studentBean.getTeacher_num(); |
| 200 | photo = studentBean.getFace(); | 196 | photo = studentBean.getFace(); |
| 201 | studentCode = studentBean.getNum(); | 197 | studentCode = studentBean.getNum(); |
| 202 | }else{ | 198 | }else{ |
| 203 | - studentBean = userDao.getStudentCByUserId(userId); | 199 | + studentBean = userDao.getStudentCByUserId(userId,null); |
| 204 | cardNum = studentBean.getStudent_num(); | 200 | cardNum = studentBean.getStudent_num(); |
| 205 | photo = studentBean.getPhoto(); | 201 | photo = studentBean.getPhoto(); |
| 206 | studentCode = studentBean.getStudentCode(); | 202 | studentCode = studentBean.getStudentCode(); |
| @@ -211,21 +207,45 @@ public class UserOperateServiceImpl implements UserOperateService { | @@ -211,21 +207,45 @@ public class UserOperateServiceImpl implements UserOperateService { | ||
| 211 | } | 207 | } |
| 212 | Integer schoolId = studentBean.getSchool_id(); | 208 | Integer schoolId = studentBean.getSchool_id(); |
| 213 | String userName = studentBean.getName(); | 209 | String userName = studentBean.getName(); |
| 214 | - //2.重新下发 | ||
| 215 | String typeName = userType.intValue() ==1 ? "Teacher" : "Student"; | 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 | //校验100服务上是否存在此人脸 | 234 | //校验100服务上是否存在此人脸 |
| 222 | - File file = new File(filePath.trim()); | 235 | + File file = new File(filePath.trim());//图片 |
| 223 | if (!file.exists()) { | 236 | if (!file.exists()) { |
| 224 | log.error("文件不存在:" + filePath); | 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 | return ResultGenerator.genFailResult("文件不存在"); | 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 | Integer clintType = userDao.getClintTypeByDeviceId(deviceId); | 250 | Integer clintType = userDao.getClintTypeByDeviceId(deviceId); |
| 231 | if(clintType.intValue()== 18 || clintType.intValue()== 28){ | 251 | if(clintType.intValue()== 18 || clintType.intValue()== 28){ |
| @@ -237,12 +257,7 @@ public class UserOperateServiceImpl implements UserOperateService { | @@ -237,12 +257,7 @@ public class UserOperateServiceImpl implements UserOperateService { | ||
| 237 | //不在线,去253服务器上删除 | 257 | //不在线,去253服务器上删除 |
| 238 | HttpUtil.deleteCard(deviceId, cardNum); | 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 | boolean isOk = baseService.sendImg(file.getAbsolutePath(), targetPath, deviceId, cardNum, userName, String.valueOf(userType), schoolId); | 261 | boolean isOk = baseService.sendImg(file.getAbsolutePath(), targetPath, deviceId, cardNum, userName, String.valueOf(userType), schoolId); |
| 247 | if (isOk) { | 262 | if (isOk) { |
| 248 | return ResultGenerator.genSuccessResult(); | 263 | return ResultGenerator.genSuccessResult(); |
| @@ -252,6 +267,7 @@ public class UserOperateServiceImpl implements UserOperateService { | @@ -252,6 +267,7 @@ public class UserOperateServiceImpl implements UserOperateService { | ||
| 252 | } | 267 | } |
| 253 | //下大华人脸 | 268 | //下大华人脸 |
| 254 | if(clintType.intValue()== 22 || clintType.intValue()== 29){ | 269 | if(clintType.intValue()== 22 || clintType.intValue()== 29){ |
| 270 | + //下发单个人脸至大华设备 | ||
| 255 | HttpUtil.uploadDHImgForOne(filePath,schoolId,studentCode,clintType,deviceId); | 271 | HttpUtil.uploadDHImgForOne(filePath,schoolId,studentCode,clintType,deviceId); |
| 256 | return ResultGenerator.genSuccessResult(); | 272 | return ResultGenerator.genSuccessResult(); |
| 257 | } | 273 | } |
| @@ -259,61 +275,7 @@ public class UserOperateServiceImpl implements UserOperateService { | @@ -259,61 +275,7 @@ public class UserOperateServiceImpl implements UserOperateService { | ||
| 259 | } | 275 | } |
| 260 | 276 | ||
| 261 | @Override | 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 | String[] deviceArr = sendFaceDto.getsNos().split(","); | 280 | String[] deviceArr = sendFaceDto.getsNos().split(","); |
| 319 | List<String> deviceList= new ArrayList<>(Arrays.asList(deviceArr)); | 281 | List<String> deviceList= new ArrayList<>(Arrays.asList(deviceArr)); |
| @@ -329,17 +291,39 @@ public class UserOperateServiceImpl implements UserOperateService { | @@ -329,17 +291,39 @@ public class UserOperateServiceImpl implements UserOperateService { | ||
| 329 | }else{ | 291 | }else{ |
| 330 | userType = 1; | 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 | Integer clintType = userDao.getClintTypeByDeviceId(deviceList.get(0)); | 307 | Integer clintType = userDao.getClintTypeByDeviceId(deviceList.get(0)); |
| 334 | if(clintType.intValue()== 22 || clintType.intValue()== 29){ | 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 | if(clintType.intValue()== 18 || clintType.intValue()== 28){ | 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 | @Override | 329 | @Override |
| @@ -370,6 +354,9 @@ public class UserOperateServiceImpl implements UserOperateService { | @@ -370,6 +354,9 @@ public class UserOperateServiceImpl implements UserOperateService { | ||
| 370 | if(clintType.intValue()== 22 || clintType.intValue()== 29){ | 354 | if(clintType.intValue()== 22 || clintType.intValue()== 29){ |
| 371 | HttpUtil.deleteDHFace(schoolId,cardNum,deviceId); | 355 | HttpUtil.deleteDHFace(schoolId,cardNum,deviceId); |
| 372 | } | 356 | } |
| 357 | + //删除成功记录 | ||
| 358 | + sendRecordDao.deleteUserFaceSuccess(schoolId,cardNum,deviceId); | ||
| 359 | + sendRecordDao.deleteRecord(schoolId,deviceId,cardNum); | ||
| 373 | }catch (Exception e){ | 360 | }catch (Exception e){ |
| 374 | log.error("删除失败人脸失败,异常信息:{}",e); | 361 | log.error("删除失败人脸失败,异常信息:{}",e); |
| 375 | continue; | 362 | continue; |
| @@ -398,16 +385,20 @@ public class UserOperateServiceImpl implements UserOperateService { | @@ -398,16 +385,20 @@ public class UserOperateServiceImpl implements UserOperateService { | ||
| 398 | //2.重新下发 | 385 | //2.重新下发 |
| 399 | StudentBean studentBean= null; | 386 | StudentBean studentBean= null; |
| 400 | String typeName =""; | 387 | String typeName =""; |
| 388 | + String photo = ""; | ||
| 401 | if(userType ==1){ | 389 | if(userType ==1){ |
| 402 | typeName= "Teacher"; | 390 | typeName= "Teacher"; |
| 403 | - studentBean = userDao.getTeacherWithCard(cardNum); | 391 | + studentBean = userDao.getTeacherWithCard(cardNum,schoolId); |
| 392 | + photo=studentBean.getFace(); | ||
| 404 | }else{ | 393 | }else{ |
| 405 | typeName= "Student"; | 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 | continue; | 399 | continue; |
| 410 | } | 400 | } |
| 401 | + String userName= studentBean.getName(); | ||
| 411 | String studentCode = studentBean.getStudentCode(); | 402 | String studentCode = studentBean.getStudentCode(); |
| 412 | String filePath=""; | 403 | String filePath=""; |
| 413 | //下发海康人脸 | 404 | //下发海康人脸 |
| @@ -420,32 +411,40 @@ public class UserOperateServiceImpl implements UserOperateService { | @@ -420,32 +411,40 @@ public class UserOperateServiceImpl implements UserOperateService { | ||
| 420 | //不在线,去253服务器上删除 | 411 | //不在线,去253服务器上删除 |
| 421 | HttpUtil.deleteCard(deviceId, cardNum); | 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 | continue; | 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 | if(photo.indexOf("f0i5l7e5")!=-1){ | 424 | if(photo.indexOf("f0i5l7e5")!=-1){ |
| 430 | String afterStr = photo.split("f0i5l7e5/")[1].replace("/","\\"); | 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 | File file = new File(filePath);//图片 | 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 | if(clintType.intValue()== 22 || clintType.intValue()== 29){ | 450 | if(clintType.intValue()== 22 || clintType.intValue()== 29){ |
| @@ -463,121 +462,158 @@ public class UserOperateServiceImpl implements UserOperateService { | @@ -463,121 +462,158 @@ public class UserOperateServiceImpl implements UserOperateService { | ||
| 463 | @Override | 462 | @Override |
| 464 | public Result deleteFace(Integer schoolId,String cards,String deviceIds) { | 463 | public Result deleteFace(Integer schoolId,String cards,String deviceIds) { |
| 465 | if(StringUtils.isBlank(cards)){ | 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 | String[] cardArr = cards.split(","); | 478 | String[] cardArr = cards.split(","); |
| 469 | - List<String> cardList= new ArrayList<>(Arrays.asList(cardArr)); | 479 | + List<String> cardList = new ArrayList<>(Arrays.asList(cardArr)); |
| 470 | for(String card : cardList){ | 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 | Integer clintType = userDao.getClintTypeByDeviceId(sno); | 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 | if (cmsServer.getIsDeviceOnline(sno)) { | 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 | HttpUtil.deleteCard(sno, card); | 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 | continue; | 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 | return ResultGenerator.genSuccessResult(); | 510 | return ResultGenerator.genSuccessResult(); |
| 526 | } | 511 | } |
| 527 | 512 | ||
| 528 | @Override | 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 | if(StringUtils.isBlank(deviceIds)){ | 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 | try{ | 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 | if (StringUtils.isBlank(photo) || StringUtils.isBlank(cardNum)){ | 562 | if (StringUtils.isBlank(photo) || StringUtils.isBlank(cardNum)){ |
| 549 | continue; | 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 | String filePath=""; | 583 | String filePath=""; |
| 553 | if(photo.indexOf("f0i5l7e5")!=-1){ | 584 | if(photo.indexOf("f0i5l7e5")!=-1){ |
| 554 | String afterStr = photo.split("f0i5l7e5/")[1].replace("/","\\"); | 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 | File file = new File(filePath);//图片 | 598 | File file = new File(filePath);//图片 |
| 564 | if(file.exists()){ | 599 | if(file.exists()){ |
| 565 | String targetPath = FileUtils.picPathComp + file.getName(); | 600 | String targetPath = FileUtils.picPathComp + file.getName(); |
| 566 | try { | 601 | try { |
| 567 | CompressPic.CompressPic(file.getAbsolutePath(), targetPath); | 602 | CompressPic.CompressPic(file.getAbsolutePath(), targetPath); |
| 568 | } catch (Exception e) { | 603 | } catch (Exception e) { |
| 569 | - log.error("压缩图片失败"); | ||
| 570 | - e.printStackTrace(); | 604 | + log.error("压缩图片失败:",e); |
| 571 | continue; | 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,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 | return ResultGenerator.genSuccessResult(); | 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 | package com.sincere.haikangface.utils; | 1 | package com.sincere.haikangface.utils; |
| 2 | 2 | ||
| 3 | +import com.sincere.haikangface.bean.AttendanceBean; | ||
| 3 | import com.sincere.haikangface.bean.BaiduFaceRecorder; | 4 | import com.sincere.haikangface.bean.BaiduFaceRecorder; |
| 4 | import com.sincere.haikangface.bean.FaceWaterRecoder; | 5 | import com.sincere.haikangface.bean.FaceWaterRecoder; |
| 5 | import com.sincere.haikangface.dao.DeviceDao; | 6 | import com.sincere.haikangface.dao.DeviceDao; |
| @@ -101,6 +102,7 @@ public class AlarmUtils { | @@ -101,6 +102,7 @@ public class AlarmUtils { | ||
| 101 | currTemperature = currTemperature.replace("currTemperature>", ""); | 102 | currTemperature = currTemperature.replace("currTemperature>", ""); |
| 102 | currTemperature = currTemperature.replace("</", ""); | 103 | currTemperature = currTemperature.replace("</", ""); |
| 103 | } | 104 | } |
| 105 | + saveAttendance(deviceID); | ||
| 104 | switch (majirType) { | 106 | switch (majirType) { |
| 105 | case "0x1"://报警 | 107 | case "0x1"://报警 |
| 106 | baojing(minorType, deviceID, time); | 108 | baojing(minorType, deviceID, time); |
| @@ -136,20 +138,20 @@ public class AlarmUtils { | @@ -136,20 +138,20 @@ public class AlarmUtils { | ||
| 136 | break; | 138 | break; |
| 137 | case "0x07"://无效时段 | 139 | case "0x07"://无效时段 |
| 138 | content = "无效时段"; | 140 | content = "无效时段"; |
| 139 | - log.info("卡号:{}, {}",cardNo,content); | 141 | + log.info("卡号:{}, {}", cardNo, content); |
| 140 | break; | 142 | break; |
| 141 | case "0x8"://卡号过期 | 143 | case "0x8"://卡号过期 |
| 142 | content = "卡号过期"; | 144 | content = "卡号过期"; |
| 143 | - log.info("卡号:{}, {}",cardNo,content); | 145 | + log.info("卡号:{}, {}", cardNo, content); |
| 144 | break; | 146 | break; |
| 145 | case "0x9"://无此卡号 | 147 | case "0x9"://无此卡号 |
| 146 | content = "无此卡号"; | 148 | content = "无此卡号"; |
| 147 | - log.info("卡号:{}, {}",cardNo,content); | 149 | + log.info("卡号:{}, {}", cardNo, content); |
| 148 | break; | 150 | break; |
| 149 | case "0x4b"://人脸认证通过 | 151 | case "0x4b"://人脸认证通过 |
| 150 | if (!StringUtils.isEmpty(picDataUrl) && picDataUrl.split("id=").length > 1) { | 152 | if (!StringUtils.isEmpty(picDataUrl) && picDataUrl.split("id=").length > 1) { |
| 151 | String picDataUrlId = picDataUrl.split("id=")[1]; | 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 | content = "人脸认证通过"; | 155 | content = "人脸认证通过"; |
| 154 | if (null != alarmCallBack) | 156 | if (null != alarmCallBack) |
| 155 | alarmCallBack.callBack(minorType, deviceID, cardNo, time, picDataUrlId, currTemperature); | 157 | alarmCallBack.callBack(minorType, deviceID, cardNo, time, picDataUrlId, currTemperature); |
| @@ -157,32 +159,32 @@ public class AlarmUtils { | @@ -157,32 +159,32 @@ public class AlarmUtils { | ||
| 157 | break; | 159 | break; |
| 158 | case "0x4c"://人脸认证失败 | 160 | case "0x4c"://人脸认证失败 |
| 159 | content = "人脸认证失败"; | 161 | content = "人脸认证失败"; |
| 160 | - log.info("卡号:{}, {}",cardNo,content); | 162 | + log.info("卡号:{}, {}", cardNo, content); |
| 161 | break; | 163 | break; |
| 162 | case "0x50"://人脸不存在 | 164 | case "0x50"://人脸不存在 |
| 163 | content = "人脸不存在"; | 165 | content = "人脸不存在"; |
| 164 | - log.info("卡号:{}, {}",cardNo,content); | 166 | + log.info("卡号:{}, {}", cardNo, content); |
| 165 | break; | 167 | break; |
| 166 | case "0x68"://真人检测失败 | 168 | case "0x68"://真人检测失败 |
| 167 | content = "真人检测失败"; | 169 | content = "真人检测失败"; |
| 168 | - log.info("卡号:{}, {}",cardNo,content); | 170 | + log.info("卡号:{}, {}", cardNo, content); |
| 169 | break; | 171 | break; |
| 170 | case "0x69"://人证比对通过 | 172 | case "0x69"://人证比对通过 |
| 171 | if (!StringUtils.isEmpty(picDataUrl) && picDataUrl.split("id=").length > 1) { | 173 | if (!StringUtils.isEmpty(picDataUrl) && picDataUrl.split("id=").length > 1) { |
| 172 | String picDataUrlId = picDataUrl.split("id=")[1]; | 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 | content = "人脸认证通过"; | 176 | content = "人脸认证通过"; |
| 175 | if (null != alarmCallBack) | 177 | if (null != alarmCallBack) |
| 176 | alarmCallBack.callBack(minorType, deviceID, cardNo, time, picDataUrlId, currTemperature); | 178 | alarmCallBack.callBack(minorType, deviceID, cardNo, time, picDataUrlId, currTemperature); |
| 177 | } | 179 | } |
| 178 | break; | 180 | break; |
| 179 | case "0x70"://认证比对失败 | 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 | break; | 183 | break; |
| 182 | case "0x6": | 184 | case "0x6": |
| 183 | if (!StringUtils.isEmpty(picDataUrl) && picDataUrl.split("id=").length > 1) { | 185 | if (!StringUtils.isEmpty(picDataUrl) && picDataUrl.split("id=").length > 1) { |
| 184 | String picDataUrlId = picDataUrl.split("id=")[1]; | 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 | content = "人脸认证通过"; | 188 | content = "人脸认证通过"; |
| 187 | if (null != alarmCallBack) | 189 | if (null != alarmCallBack) |
| 188 | alarmCallBack.callBack(minorType, deviceID, cardNo, time, picDataUrlId, currTemperature); | 190 | alarmCallBack.callBack(minorType, deviceID, cardNo, time, picDataUrlId, currTemperature); |
| @@ -242,11 +244,11 @@ public class AlarmUtils { | @@ -242,11 +244,11 @@ public class AlarmUtils { | ||
| 242 | switch (minorType) { | 244 | switch (minorType) { |
| 243 | case "0x3a"://网络断开 | 245 | case "0x3a"://网络断开 |
| 244 | content = "网络断开"; | 246 | content = "网络断开"; |
| 245 | - FileUtils.getInstance().writeLogs("网络断开:"+deviceID,"设备网络.txt"); | 247 | + log.info("网络断开:"+deviceID); |
| 246 | break; | 248 | break; |
| 247 | case "0x400"://设备上电启动 | 249 | case "0x400"://设备上电启动 |
| 248 | content = "设备上电启动"; | 250 | content = "设备上电启动"; |
| 249 | - FileUtils.getInstance().writeLogs("设备上电启动:"+deviceID,"设备网络.txt"); | 251 | + log.info("设备上电启动:"+deviceID); |
| 250 | break; | 252 | break; |
| 251 | case "0x401"://设备掉电关闭 | 253 | case "0x401"://设备掉电关闭 |
| 252 | content = "设备掉电关闭"; | 254 | content = "设备掉电关闭"; |
| @@ -266,7 +268,7 @@ public class AlarmUtils { | @@ -266,7 +268,7 @@ public class AlarmUtils { | ||
| 266 | case "0x407"://网络恢复 | 268 | case "0x407"://网络恢复 |
| 267 | content = "网络恢复"; | 269 | content = "网络恢复"; |
| 268 | if (null != alarmCallBack) alarmCallBack.callBack(minorType, deviceID, "", time, "", ""); | 270 | if (null != alarmCallBack) alarmCallBack.callBack(minorType, deviceID, "", time, "", ""); |
| 269 | - FileUtils.getInstance().writeLogs("网络恢复:"+deviceID,"设备网络.txt"); | 271 | + log.info("网络恢复:"+deviceID,"设备网络.txt"); |
| 270 | break; | 272 | break; |
| 271 | case "0x421"://摄像头未连接 | 273 | case "0x421"://摄像头未连接 |
| 272 | content = "摄像头未连接"; | 274 | content = "摄像头未连接"; |
| @@ -275,14 +277,14 @@ public class AlarmUtils { | @@ -275,14 +277,14 @@ public class AlarmUtils { | ||
| 275 | content = "摄像头连接恢复"; | 277 | content = "摄像头连接恢复"; |
| 276 | break; | 278 | break; |
| 277 | case "0x426"://人证设备在线 | 279 | case "0x426"://人证设备在线 |
| 278 | - FileUtils.getInstance().writeLogs("人证设备在线:"+deviceID,"设备网络.txt"); | 280 | + log.info("人证设备在线:"+deviceID,"设备网络.txt"); |
| 279 | content = "人证设备在线"; | 281 | content = "人证设备在线"; |
| 280 | if (null != alarmCallBack) alarmCallBack.callBack(minorType, deviceID, "", time, "", ""); | 282 | if (null != alarmCallBack) alarmCallBack.callBack(minorType, deviceID, "", time, "", ""); |
| 281 | break; | 283 | break; |
| 282 | case "0x427"://人证设备离线 | 284 | case "0x427"://人证设备离线 |
| 283 | content = "人证设备离线"; | 285 | content = "人证设备离线"; |
| 284 | if (null != alarmCallBack) alarmCallBack.callBack(minorType, deviceID, "", time, "", ""); | 286 | if (null != alarmCallBack) alarmCallBack.callBack(minorType, deviceID, "", time, "", ""); |
| 285 | - FileUtils.getInstance().writeLogs("人证设备离线:"+deviceID,"设备网络.txt"); | 287 | + log.info("人证设备离线:"+deviceID,"设备网络.txt"); |
| 286 | break; | 288 | break; |
| 287 | } | 289 | } |
| 288 | saveWater(content, minorType, deviceID, "", time, "0x02"); | 290 | saveWater(content, minorType, deviceID, "", time, "0x02"); |
| @@ -334,4 +336,25 @@ public class AlarmUtils { | @@ -334,4 +336,25 @@ public class AlarmUtils { | ||
| 334 | faceWaterRecoder.getContent(), faceWaterRecoder.getMajorType(), faceWaterRecoder.getTime(), faceWaterRecoder.getCardNo(), faceWaterRecoder.getSystime()); | 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,13 +107,14 @@ public class HttpUtil { | ||
| 107 | * @param userType | 107 | * @param userType |
| 108 | */ | 108 | */ |
| 109 | public static void uploadImgs(String filePath, String card, String name, String deviceId, String startTime, | 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 | if (!new File(filePath).exists()) { | 111 | if (!new File(filePath).exists()) { |
| 112 | log.error("图片不存在,图片路径:{}",filePath); | 112 | log.error("图片不存在,图片路径:{}",filePath); |
| 113 | return; | 113 | return; |
| 114 | } | 114 | } |
| 115 | try{ | 115 | try{ |
| 116 | String url = "http://120.26.116.253:8089/file/uploadImg"; | 116 | String url = "http://120.26.116.253:8089/file/uploadImg"; |
| 117 | +// String url = "http://127.0.0.1:8089/file/uploadImg"; | ||
| 117 | RestTemplate restTemplate = new RestTemplate(); | 118 | RestTemplate restTemplate = new RestTemplate(); |
| 118 | HttpHeaders headers = new HttpHeaders(); | 119 | HttpHeaders headers = new HttpHeaders(); |
| 119 | MediaType mediaType = MediaType.parseMediaType(MediaType.MULTIPART_FORM_DATA_VALUE); | 120 | MediaType mediaType = MediaType.parseMediaType(MediaType.MULTIPART_FORM_DATA_VALUE); |
| @@ -128,6 +129,7 @@ public class HttpUtil { | @@ -128,6 +129,7 @@ public class HttpUtil { | ||
| 128 | multivaluedMap.add("endTime", endTime); | 129 | multivaluedMap.add("endTime", endTime); |
| 129 | multivaluedMap.add("validTimeEnabled", validTimeEnabled); | 130 | multivaluedMap.add("validTimeEnabled", validTimeEnabled); |
| 130 | multivaluedMap.add("userType", userType); | 131 | multivaluedMap.add("userType", userType); |
| 132 | + multivaluedMap.add("schoolId", schoolId); | ||
| 131 | HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(multivaluedMap, headers); | 133 | HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(multivaluedMap, headers); |
| 132 | ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, httpEntity, String.class); | 134 | ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, httpEntity, String.class); |
| 133 | log.info("发送请求,下发人脸至253服务器海康设备,请求地址:{} ,下发用户名:{},返回信息:{}",url,name,responseEntity.getBody()); | 135 | log.info("发送请求,下发人脸至253服务器海康设备,请求地址:{} ,下发用户名:{},返回信息:{}",url,name,responseEntity.getBody()); |
| @@ -138,7 +140,6 @@ public class HttpUtil { | @@ -138,7 +140,6 @@ public class HttpUtil { | ||
| 138 | 140 | ||
| 139 | 141 | ||
| 140 | public static boolean IsDeviceOnline(String deviceId) { | 142 | public static boolean IsDeviceOnline(String deviceId) { |
| 141 | - | ||
| 142 | String url = "http://120.26.116.253:8089/file/IsDeviceOnline?deviceId=" + deviceId; | 143 | String url = "http://120.26.116.253:8089/file/IsDeviceOnline?deviceId=" + deviceId; |
| 143 | RestTemplate restTemplate = new RestTemplate(); | 144 | RestTemplate restTemplate = new RestTemplate(); |
| 144 | String res = restTemplate.getForObject(url, String.class); | 145 | String res = restTemplate.getForObject(url, String.class); |
| @@ -248,8 +249,8 @@ public class HttpUtil { | @@ -248,8 +249,8 @@ public class HttpUtil { | ||
| 248 | */ | 249 | */ |
| 249 | public static void sendDHPermission(PermissionDHBean permissionBean) { | 250 | public static void sendDHPermission(PermissionDHBean permissionBean) { |
| 250 | try{ | 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 | RestTemplate restTemplate = new RestTemplate(); | 254 | RestTemplate restTemplate = new RestTemplate(); |
| 254 | HttpHeaders headers = new HttpHeaders(); | 255 | HttpHeaders headers = new HttpHeaders(); |
| 255 | MediaType mediaType = MediaType.parseMediaType(MediaType.APPLICATION_JSON_UTF8_VALUE); | 256 | MediaType mediaType = MediaType.parseMediaType(MediaType.APPLICATION_JSON_UTF8_VALUE); |
| @@ -286,11 +287,11 @@ public class HttpUtil { | @@ -286,11 +287,11 @@ public class HttpUtil { | ||
| 286 | * @param userType | 287 | * @param userType |
| 287 | * @param deviceIds | 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 | // String api = "http://127.0.0.1:8991/user/sendFaces"; | 292 | // String api = "http://127.0.0.1:8991/user/sendFaces"; |
| 292 | try { | 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 | RestTemplate restTemplate = new RestTemplate(); | 295 | RestTemplate restTemplate = new RestTemplate(); |
| 295 | ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class); | 296 | ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class); |
| 296 | log.info("发送请求,照片下发至大华设备,请求地址:{},返回信息: {}",url,responseEntity.getBody()); | 297 | log.info("发送请求,照片下发至大华设备,请求地址:{},返回信息: {}",url,responseEntity.getBody()); |
| @@ -316,4 +317,23 @@ public class HttpUtil { | @@ -316,4 +317,23 @@ public class HttpUtil { | ||
| 316 | log.error("发送请求,删除大华设备人脸,异常信息:{}",e); | 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 @@ | @@ -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,11 +27,11 @@ public interface SendRecordDao { | ||
| 27 | @Param("userType") int userType, @Param("deviceType") int deviceType); | 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 | List<SendRecordBean> getSenSuccess(); | 31 | List<SendRecordBean> getSenSuccess(); |
| 32 | 32 | ||
| 33 | @Select("select * from Face_SendSuccess where deviceID = #{deviceID} and schoolId = #{schoolId}") | 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 | @Insert("insert into Face_SendFail values(#{deviceID},#{customerid},#{num},#{name},#{time},#{schoolName},#{imgPath},#{schoolId},#{failContent},#{failType},#{userType},#{deviceType})") | 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,19 +127,39 @@ public interface SendRecordDao { | ||
| 127 | /******************************************* add by xuquan **********************************************/ | 127 | /******************************************* add by xuquan **********************************************/ |
| 128 | 128 | ||
| 129 | @Select("select * from Face_SendRecord where deviceID = #{deviceID} and Num = #{Num} and userId = #{userId}") | 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 | void saveFaceRecord(@Param("userId") String userId, @Param("deviceID") String deviceID, @Param("num") String num, @Param("name") String name, | 133 | void saveFaceRecord(@Param("userId") String userId, @Param("deviceID") String deviceID, @Param("num") String num, @Param("name") String name, |
| 134 | @Param("time") String time, @Param("schoolName") String schoolName, @Param("imgPath") String imgPath, @Param("schoolId") Integer schoolId, @Param("failContent") String failContent, | 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 | @Update("update Face_SendRecord set time = #{time},failContent = #{content},imgPath= #{faceUrl},status = 2 where deviceID = #{deviceID} and Num =#{Num} and userId = #{userId}") | 137 | @Update("update Face_SendRecord set time = #{time},failContent = #{content},imgPath= #{faceUrl},status = 2 where deviceID = #{deviceID} and Num =#{Num} and userId = #{userId}") |
| 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); | 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 | @Select("select * from Face_SendRecord where schoolId = #{schoolId} and status =2") | 143 | @Select("select * from Face_SendRecord where schoolId = #{schoolId} and status =2") |
| 144 | List<SendRecordBean> getFailRecord(@Param("schoolId") Integer schoolId); | 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,9 +3,14 @@ server: | ||
| 3 | 3 | ||
| 4 | spring: | 4 | spring: |
| 5 | profiles: | 5 | profiles: |
| 6 | - active: dev | 6 | + active: prod |
| 7 | application: | 7 | application: |
| 8 | name: haikangserver | 8 | name: haikangserver |
| 9 | + servlet: | ||
| 10 | + multipart: | ||
| 11 | + enabled: true | ||
| 12 | + max-file-size: -1 | ||
| 13 | + max-request-size: -1 | ||
| 9 | datasource: | 14 | datasource: |
| 10 | campus: | 15 | campus: |
| 11 | username: szjxtuser | 16 | username: szjxtuser |
| @@ -57,13 +62,8 @@ mybatis: | @@ -57,13 +62,8 @@ mybatis: | ||
| 57 | 62 | ||
| 58 | ip: localhost | 63 | ip: localhost |
| 59 | 64 | ||
| 60 | -attendanceHost: http://campus.myjxt.com/ | ||
| 61 | - | ||
| 62 | iscurl: https://60.12.93.221:443 | 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 | #logging: | 67 | #logging: |
| 68 | # level: | 68 | # level: |
| 69 | # com.sincere.haikangface.xiaoanDao: debug | 69 | # com.sincere.haikangface.xiaoanDao: debug |
cloud/haikangface/src/main/resources/logback-spring.xml
| @@ -8,7 +8,7 @@ | @@ -8,7 +8,7 @@ | ||
| 8 | <!--<include resource="org/springframework/boot/logging/logback/defaults.xml" />--> | 8 | <!--<include resource="org/springframework/boot/logging/logback/defaults.xml" />--> |
| 9 | 9 | ||
| 10 | <!--日志文件存储的基础路径: ${user.home} 为当前服务器用户主目录--> | 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 | <property name="BASE_FILE_NAME" value="haikang"/> | 14 | <property name="BASE_FILE_NAME" value="haikang"/> |
| @@ -51,4 +51,11 @@ | @@ -51,4 +51,11 @@ | ||
| 51 | </root> | 51 | </root> |
| 52 | </springProfile> | 52 | </springProfile> |
| 53 | 53 | ||
| 54 | + <!--生产环境不打印控制台输出--> | ||
| 55 | + <springProfile name="prod"> | ||
| 56 | + <root level="INFO"> | ||
| 57 | + <appender-ref ref="file" /> | ||
| 58 | + </root> | ||
| 59 | + </springProfile> | ||
| 60 | + | ||
| 54 | </configuration> | 61 | </configuration> |
| 55 | \ No newline at end of file | 62 | \ No newline at end of file |
cloud/haikangface/src/main/resources/mapper/usermapper.xml
| @@ -63,14 +63,6 @@ | @@ -63,14 +63,6 @@ | ||
| 63 | update AC_DeviceAuthRecord set GrantState = #{grantState} where id = #{id} | 63 | update AC_DeviceAuthRecord set GrantState = #{grantState} where id = #{id} |
| 64 | </update> | 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 | <select id="getStudentList" resultType="com.sincere.haikangface.bean.StudentBean"> | 66 | <select id="getStudentList" resultType="com.sincere.haikangface.bean.StudentBean"> |
| 75 | select * from SZ_V_School_Student where school_id = #{schoolId} | 67 | select * from SZ_V_School_Student where school_id = #{schoolId} |
| 76 | <if test="studentType != null"> | 68 | <if test="studentType != null"> |
| @@ -82,13 +74,16 @@ | @@ -82,13 +74,16 @@ | ||
| 82 | #{item} | 74 | #{item} |
| 83 | </foreach> | 75 | </foreach> |
| 84 | </if> | 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 | </select> | 83 | </select> |
| 87 | 84 | ||
| 88 | <select id="getTeacherList" resultType="com.sincere.haikangface.bean.StudentBean"> | 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 | </select> | 87 | </select> |
| 93 | 88 | ||
| 94 | <select id="getDeviceIds" resultType="java.lang.String"> | 89 | <select id="getDeviceIds" resultType="java.lang.String"> |
| @@ -98,5 +93,50 @@ | @@ -98,5 +93,50 @@ | ||
| 98 | </if> | 93 | </if> |
| 99 | </select> | 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 | </mapper> | 142 | </mapper> |
cloud/haikangface/src/test/java/com/sincere/haikangface/HaikangfaceApplicationTests.java
| @@ -14,6 +14,7 @@ import com.sincere.haikangface.bean.xiaoan.CreditCardRecordsSS; | @@ -14,6 +14,7 @@ import com.sincere.haikangface.bean.xiaoan.CreditCardRecordsSS; | ||
| 14 | import com.sincere.haikangface.dao.DeviceDao; | 14 | import com.sincere.haikangface.dao.DeviceDao; |
| 15 | import com.sincere.haikangface.dao.UserDao; | 15 | import com.sincere.haikangface.dao.UserDao; |
| 16 | import com.sincere.haikangface.dao.ZuoYeDao; | 16 | import com.sincere.haikangface.dao.ZuoYeDao; |
| 17 | +import com.sincere.haikangface.service.impl.BaseService; | ||
| 17 | import com.sincere.haikangface.utils.ApiUtil; | 18 | import com.sincere.haikangface.utils.ApiUtil; |
| 18 | import com.sincere.haikangface.xiananDao.SendRecordDao; | 19 | import com.sincere.haikangface.xiananDao.SendRecordDao; |
| 19 | import org.bouncycastle.asn1.cms.MetaData; | 20 | import org.bouncycastle.asn1.cms.MetaData; |
| @@ -28,6 +29,7 @@ import org.springframework.http.HttpHeaders; | @@ -28,6 +29,7 @@ import org.springframework.http.HttpHeaders; | ||
| 28 | import org.springframework.http.MediaType; | 29 | import org.springframework.http.MediaType; |
| 29 | import org.springframework.http.ResponseEntity; | 30 | import org.springframework.http.ResponseEntity; |
| 30 | import org.springframework.test.context.junit4.SpringRunner; | 31 | import org.springframework.test.context.junit4.SpringRunner; |
| 32 | +import org.springframework.util.CollectionUtils; | ||
| 31 | import org.springframework.util.LinkedMultiValueMap; | 33 | import org.springframework.util.LinkedMultiValueMap; |
| 32 | import org.springframework.util.MultiValueMap; | 34 | import org.springframework.util.MultiValueMap; |
| 33 | import org.springframework.util.StringUtils; | 35 | import org.springframework.util.StringUtils; |
| @@ -251,6 +253,56 @@ public class HaikangfaceApplicationTests { | @@ -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 | private int index(String content, List<String> list) { | 306 | private int index(String content, List<String> list) { |
| 255 | for (int i = 0; i < list.size(); i++) { | 307 | for (int i = 0; i < list.size(); i++) { |
| 256 | if (list.get(i).trim().equals(content.trim())) return i; | 308 | if (list.get(i).trim().equals(content.trim())) return i; |
| @@ -291,6 +343,18 @@ public class HaikangfaceApplicationTests { | @@ -291,6 +343,18 @@ public class HaikangfaceApplicationTests { | ||
| 291 | @Autowired | 343 | @Autowired |
| 292 | ZuoyeAdminDao zuoyeAdminDao; | 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 | @Test | 358 | @Test |
| 295 | public void fileRes() { | 359 | public void fileRes() { |
| 296 | 360 |
cloud/mypulsar/pom.xml
| @@ -117,11 +117,21 @@ | @@ -117,11 +117,21 @@ | ||
| 117 | <version>2.4.2</version> | 117 | <version>2.4.2</version> |
| 118 | </dependency> | 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 | </dependencies> | 135 | </dependencies> |
| 126 | 136 | ||
| 127 | <dependencyManagement> | 137 | <dependencyManagement> |
cloud/mypulsar/src/main/java/com/example/mypulsar/MyRunnerableInt.java
| @@ -7,13 +7,14 @@ import com.example.mypulsar.message.MessageVO; | @@ -7,13 +7,14 @@ import com.example.mypulsar.message.MessageVO; | ||
| 7 | import com.example.mypulsar.mq.AESBase64Utils; | 7 | import com.example.mypulsar.mq.AESBase64Utils; |
| 8 | import com.example.mypulsar.mq.MessageHandlerTask; | 8 | import com.example.mypulsar.mq.MessageHandlerTask; |
| 9 | import com.example.mypulsar.mq.MqConsumer; | 9 | import com.example.mypulsar.mq.MqConsumer; |
| 10 | +import com.example.mypulsar.mqtt.MqttConsumer; | ||
| 10 | import com.example.mypulsar.task.SchduledTasks; | 11 | import com.example.mypulsar.task.SchduledTasks; |
| 11 | import com.example.mypulsar.utils.ControlUtils; | 12 | import com.example.mypulsar.utils.ControlUtils; |
| 13 | +import com.example.mypulsar.utils.JsonUtils; | ||
| 12 | import com.example.mypulsar.utils.PulsarConsumerPoolFactory; | 14 | import com.example.mypulsar.utils.PulsarConsumerPoolFactory; |
| 13 | import com.example.mypulsar.utils.ThreadPoolFactory; | 15 | import com.example.mypulsar.utils.ThreadPoolFactory; |
| 14 | import lombok.extern.slf4j.Slf4j; | 16 | import lombok.extern.slf4j.Slf4j; |
| 15 | import org.apache.pulsar.client.api.Consumer; | 17 | import org.apache.pulsar.client.api.Consumer; |
| 16 | -import org.apache.pulsar.client.impl.TopicMessageIdImpl; | ||
| 17 | import org.slf4j.Logger; | 18 | import org.slf4j.Logger; |
| 18 | import org.slf4j.LoggerFactory; | 19 | import org.slf4j.LoggerFactory; |
| 19 | import org.springframework.beans.factory.annotation.Autowired; | 20 | import org.springframework.beans.factory.annotation.Autowired; |
| @@ -21,8 +22,7 @@ import org.springframework.boot.ApplicationArguments; | @@ -21,8 +22,7 @@ import org.springframework.boot.ApplicationArguments; | ||
| 21 | import org.springframework.boot.ApplicationRunner; | 22 | import org.springframework.boot.ApplicationRunner; |
| 22 | import org.springframework.stereotype.Component; | 23 | import org.springframework.stereotype.Component; |
| 23 | import org.springframework.util.CollectionUtils; | 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 | import java.text.SimpleDateFormat; | 27 | import java.text.SimpleDateFormat; |
| 28 | import java.util.ArrayList; | 28 | import java.util.ArrayList; |
| @@ -64,19 +64,22 @@ public class MyRunnerableInt implements ApplicationRunner { | @@ -64,19 +64,22 @@ public class MyRunnerableInt implements ApplicationRunner { | ||
| 64 | * 第二种方式 | 64 | * 第二种方式 |
| 65 | */ | 65 | */ |
| 66 | private void initMqConsumer() { | 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 | try { | 83 | try { |
| 81 | mqConsumer.start(); | 84 | mqConsumer.start(); |
| 82 | } catch (Exception e) { | 85 | } catch (Exception e) { |
| @@ -105,30 +108,31 @@ public class MyRunnerableInt implements ApplicationRunner { | @@ -105,30 +108,31 @@ public class MyRunnerableInt implements ApplicationRunner { | ||
| 105 | deviceBean.setBizCode(bizCode); | 108 | deviceBean.setBizCode(bizCode); |
| 106 | deviceBean.setDevId(devId); | 109 | deviceBean.setDevId(devId); |
| 107 | deviceBean.setProductKey(productKey); | 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 | //在线状态:1在线0离线 | 116 | //在线状态:1在线0离线 |
| 112 | deviceBean.setDev_status(1); | 117 | deviceBean.setDev_status(1); |
| 113 | //设备上报事件:code:时间类型; 格式:"status":[{"code":"pir","t":1612283849564,"value":"pir"}] | 118 | //设备上报事件:code:时间类型; 格式:"status":[{"code":"pir","t":1612283849564,"value":"pir"}] |
| 114 | List<TuYaReceiverBeanStatus> status = tuYaReceiverBean.getStatus(); | 119 | List<TuYaReceiverBeanStatus> status = tuYaReceiverBean.getStatus(); |
| 115 | for (TuYaReceiverBeanStatus statue : status) { | 120 | for (TuYaReceiverBeanStatus statue : status) { |
| 116 | //事件上报处理 | 121 | //事件上报处理 |
| 117 | - initStatue(statue, deviceBean); | 122 | + initStatue(statue, deviceBean,schoolId); |
| 118 | } | 123 | } |
| 119 | } else {//其他事件上报 | 124 | } else {//其他事件上报 |
| 120 | deviceBean.setTime(new SimpleDateFormat("yyyy-MM-dd HH::mm:ss").format(new Date())); | 125 | deviceBean.setTime(new SimpleDateFormat("yyyy-MM-dd HH::mm:ss").format(new Date())); |
| 121 | - String name = deviceDao.selectAttendance(devId); | ||
| 122 | switch (bizCode) { | 126 | switch (bizCode) { |
| 123 | case "offline"://设备掉线 | 127 | case "offline"://设备掉线 |
| 124 | - log.info("设备: {},已掉线",name); | 128 | + log.info("设备: {},已掉线",deviceName); |
| 125 | deviceBean.setDev_type(1); | 129 | deviceBean.setDev_type(1); |
| 126 | deviceBean.setDev_status(0); | 130 | deviceBean.setDev_status(0); |
| 127 | updateDevStatus(deviceBean); | 131 | updateDevStatus(deviceBean); |
| 128 | updateStatus(devId, "0"); | 132 | updateStatus(devId, "0"); |
| 129 | break; | 133 | break; |
| 130 | case "online"://设备上线 | 134 | case "online"://设备上线 |
| 131 | - log.info("设备: {},已上线",name); | 135 | + log.info("设备: {},已上线",deviceName); |
| 132 | deviceBean.setDev_status(1); | 136 | deviceBean.setDev_status(1); |
| 133 | deviceBean.setDev_type(2); | 137 | deviceBean.setDev_type(2); |
| 134 | updateDevStatus(deviceBean); | 138 | updateDevStatus(deviceBean); |
| @@ -142,6 +146,10 @@ public class MyRunnerableInt implements ApplicationRunner { | @@ -142,6 +146,10 @@ public class MyRunnerableInt implements ApplicationRunner { | ||
| 142 | case "delete"://删除设备 | 146 | case "delete"://删除设备 |
| 143 | break; | 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,13 +179,16 @@ public class MyRunnerableInt implements ApplicationRunner { | ||
| 171 | updateStatus(deviceBean.getDevId(), "1"); | 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 | * @param statue | 188 | * @param statue |
| 178 | * @param deviceBean | 189 | * @param deviceBean |
| 179 | */ | 190 | */ |
| 180 | - private void initStatue(TuYaReceiverBeanStatus statue,DeviceBean deviceBean) { | 191 | + private void initStatue(TuYaReceiverBeanStatus statue,DeviceBean deviceBean,Integer schoolId) { |
| 181 | //设备消息类型:1:掉线,2:上线,3:其他事件 | 192 | //设备消息类型:1:掉线,2:上线,3:其他事件 |
| 182 | deviceBean.setDev_type(3); | 193 | deviceBean.setDev_type(3); |
| 183 | //事件时间 | 194 | //事件时间 |
| @@ -195,8 +206,6 @@ public class MyRunnerableInt implements ApplicationRunner { | @@ -195,8 +206,6 @@ public class MyRunnerableInt implements ApplicationRunner { | ||
| 195 | switch (code) { | 206 | switch (code) { |
| 196 | case "va_temperature"://温度 | 207 | case "va_temperature"://温度 |
| 197 | deviceBean.setValue(Integer.parseInt(value) / 100 + ""); | 208 | deviceBean.setValue(Integer.parseInt(value) / 100 + ""); |
| 198 | - //计算开启或关闭设备 | ||
| 199 | -// calOpenOrCloseDevWithtemper(deviceBean); | ||
| 200 | log.info("温度:" + deviceBean.getValue()); | 209 | log.info("温度:" + deviceBean.getValue()); |
| 201 | //存储 对应设备对应的温度记录 | 210 | //存储 对应设备对应的温度记录 |
| 202 | ControlUtils.tempDevices.put(deviceBean.getDevId(),Integer.valueOf(deviceBean.getValue())); | 211 | ControlUtils.tempDevices.put(deviceBean.getDevId(),Integer.valueOf(deviceBean.getValue())); |
| @@ -205,15 +214,13 @@ public class MyRunnerableInt implements ApplicationRunner { | @@ -205,15 +214,13 @@ public class MyRunnerableInt implements ApplicationRunner { | ||
| 205 | deviceBean.setValue(Integer.parseInt(value) / 100 + ""); | 214 | deviceBean.setValue(Integer.parseInt(value) / 100 + ""); |
| 206 | log.info("湿度:" + deviceBean.getValue()); | 215 | log.info("湿度:" + deviceBean.getValue()); |
| 207 | break; | 216 | break; |
| 208 | - case "pir": | ||
| 209 | - //人体感应 | 217 | + case "pir"://人体感应 |
| 210 | log.info("人体感应:" + value); | 218 | log.info("人体感应:" + value); |
| 211 | if(value.equals("pir")){ | 219 | if(value.equals("pir")){ |
| 212 | deviceBean.setValue("有人"); | 220 | deviceBean.setValue("有人"); |
| 213 | }else{ | 221 | }else{ |
| 214 | deviceBean.setValue("无人"); | 222 | deviceBean.setValue("无人"); |
| 215 | } | 223 | } |
| 216 | - setClintTime(deviceBean.getDevId()); | ||
| 217 | try { | 224 | try { |
| 218 | Thread.sleep(1000); | 225 | Thread.sleep(1000); |
| 219 | //根据场地是否有人控制空调设备 | 226 | //根据场地是否有人控制空调设备 |
| @@ -222,11 +229,6 @@ public class MyRunnerableInt implements ApplicationRunner { | @@ -222,11 +229,6 @@ public class MyRunnerableInt implements ApplicationRunner { | ||
| 222 | e.printStackTrace(); | 229 | e.printStackTrace(); |
| 223 | } | 230 | } |
| 224 | break; | 231 | break; |
| 225 | - case "temper_alarm"://防拆报警 | ||
| 226 | - break; | ||
| 227 | - case "battery_percentage"://电池电量百分比 | ||
| 228 | - log.info("电池电量百分比:" + value); | ||
| 229 | - break; | ||
| 230 | case "battery_value"://电池电量值 | 232 | case "battery_value"://电池电量值 |
| 231 | break; | 233 | break; |
| 232 | case "battery"://门磁电池电量值 | 234 | case "battery"://门磁电池电量值 |
| @@ -244,21 +246,59 @@ public class MyRunnerableInt implements ApplicationRunner { | @@ -244,21 +246,59 @@ public class MyRunnerableInt implements ApplicationRunner { | ||
| 244 | log("开关状态:" + (value.equals("true") ? "开门" : "关门")); | 246 | log("开关状态:" + (value.equals("true") ? "开门" : "关门")); |
| 245 | break; | 247 | break; |
| 246 | case "cur_voltage"://当前电压 | 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 | break; | 255 | break; |
| 250 | case "cur_power"://当前功率 | 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 | break; | 263 | break; |
| 254 | case "cur_current"://当前电流 | 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 | break; | 278 | break; |
| 258 | case "router_mgr"://网关路由 | 279 | case "router_mgr"://网关路由 |
| 259 | break; | 280 | break; |
| 260 | } | 281 | } |
| 261 | updateDevStatus(deviceBean); | 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,11 +307,6 @@ public class MyRunnerableInt implements ApplicationRunner { | ||
| 267 | * @param deviceBean | 307 | * @param deviceBean |
| 268 | */ | 308 | */ |
| 269 | private void calOpenOrCloseDevWithPir(DeviceBean deviceBean) { | 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 | List<CalDevContrl> calDevContrls = deviceDao.getCalDevContrlWidthDevId(deviceBean.getDevId()); | 311 | List<CalDevContrl> calDevContrls = deviceDao.getCalDevContrlWidthDevId(deviceBean.getDevId()); |
| 277 | if (CollectionUtils.isEmpty(calDevContrls)) { | 312 | if (CollectionUtils.isEmpty(calDevContrls)) { |
| @@ -286,11 +321,12 @@ public class MyRunnerableInt implements ApplicationRunner { | @@ -286,11 +321,12 @@ public class MyRunnerableInt implements ApplicationRunner { | ||
| 286 | * @param clintId | 321 | * @param clintId |
| 287 | */ | 322 | */ |
| 288 | private void setClintTime(String clintId){ | 323 | private void setClintTime(String clintId){ |
| 324 | + //获取人感设备 | ||
| 289 | List<CalDevContrl> calDevContrls = deviceDao.getCalDevContrlWidthDevId(clintId); | 325 | List<CalDevContrl> calDevContrls = deviceDao.getCalDevContrlWidthDevId(clintId); |
| 290 | if(!CollectionUtils.isEmpty(calDevContrls)){ | 326 | if(!CollectionUtils.isEmpty(calDevContrls)){ |
| 291 | CalDevContrl calDevContrl = calDevContrls.get(0); | 327 | CalDevContrl calDevContrl = calDevContrls.get(0); |
| 292 | String assDevice = calDevContrl.getAssDevice(); | 328 | String assDevice = calDevContrl.getAssDevice(); |
| 293 | - //红外遥控器 | 329 | + //获取人感关联红外遥控器 |
| 294 | CalDevBeContrl hwClint = getCalDevBeCon(assDevice); | 330 | CalDevBeContrl hwClint = getCalDevBeCon(assDevice); |
| 295 | if(hwClint==null) { | 331 | if(hwClint==null) { |
| 296 | log.info("未查询到控制红外遥控器"); | 332 | log.info("未查询到控制红外遥控器"); |
cloud/mypulsar/src/main/java/com/example/mypulsar/bean/IotDevice.java
0 → 100644
| @@ -0,0 +1,56 @@ | @@ -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,17 +5,22 @@ import java.util.List; | ||
| 5 | 5 | ||
| 6 | public class TuYaReceiverBean implements Serializable { | 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 | package com.example.mypulsar.bean; | 1 | package com.example.mypulsar.bean; |
| 2 | 2 | ||
| 3 | +import afu.org.checkerframework.checker.igj.qual.I; | ||
| 4 | + | ||
| 3 | import java.io.Serializable; | 5 | import java.io.Serializable; |
| 4 | 6 | ||
| 5 | public class Wl_Attendace implements Serializable { | 7 | public class Wl_Attendace implements Serializable { |
| 6 | 8 | ||
| 9 | + private Integer school_id; | ||
| 10 | + | ||
| 7 | private String clint_id; | 11 | private String clint_id; |
| 8 | 12 | ||
| 9 | private String name; | 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 | public String getClint_id() { | 23 | public String getClint_id() { |
| 12 | return clint_id; | 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,6 +4,7 @@ import com.example.mypulsar.bean.DeviceBean; | ||
| 4 | import com.example.mypulsar.bean.User; | 4 | import com.example.mypulsar.bean.User; |
| 5 | import com.example.mypulsar.dao.DeviceDao; | 5 | import com.example.mypulsar.dao.DeviceDao; |
| 6 | import com.example.mypulsar.service.UserService; | 6 | import com.example.mypulsar.service.UserService; |
| 7 | +import com.example.mypulsar.task.SchduledTasks; | ||
| 7 | import org.springframework.beans.factory.annotation.Autowired; | 8 | import org.springframework.beans.factory.annotation.Autowired; |
| 8 | import org.springframework.web.bind.annotation.*; | 9 | import org.springframework.web.bind.annotation.*; |
| 9 | 10 | ||
| @@ -19,6 +20,9 @@ public class UserControl { | @@ -19,6 +20,9 @@ public class UserControl { | ||
| 19 | @Autowired | 20 | @Autowired |
| 20 | DeviceDao deviceDao; | 21 | DeviceDao deviceDao; |
| 21 | 22 | ||
| 23 | + @Autowired | ||
| 24 | + SchduledTasks schduledTasks; | ||
| 25 | + | ||
| 22 | // @GetMapping("getUsers") | 26 | // @GetMapping("getUsers") |
| 23 | // public List<User> getUsers(){ | 27 | // public List<User> getUsers(){ |
| 24 | // return userService.select(); | 28 | // return userService.select(); |
| @@ -32,5 +36,9 @@ public class UserControl { | @@ -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 | package com.example.mypulsar.dao; | 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 | import org.apache.ibatis.annotations.*; | 4 | import org.apache.ibatis.annotations.*; |
| 9 | import org.springframework.stereotype.Repository; | 5 | import org.springframework.stereotype.Repository; |
| 10 | 6 | ||
| @@ -30,8 +26,8 @@ public interface DeviceDao { | @@ -30,8 +26,8 @@ public interface DeviceDao { | ||
| 30 | int updateStatus(@Param("clint_id") String clint_id, @Param("isConnection") String isConnection, @Param("OnlineTime") String OnlineTime); | 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 | @Select("select * from Iot_Device where devId = #{devId}") | 32 | @Select("select * from Iot_Device where devId = #{devId}") |
| 37 | List<DeviceBean> getDevice(@Param("devId") String devId); | 33 | List<DeviceBean> getDevice(@Param("devId") String devId); |
| @@ -40,6 +36,8 @@ public interface DeviceDao { | @@ -40,6 +36,8 @@ public interface DeviceDao { | ||
| 40 | @Select("select * from CalDevContrl ") | 36 | @Select("select * from CalDevContrl ") |
| 41 | List<CalDevContrl> getCalDevContrl(); | 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 | @Select("select * from CalDevContrl where Devid = #{Devid} and ModelType =10 and Status = 1") | 42 | @Select("select * from CalDevContrl where Devid = #{Devid} and ModelType =10 and Status = 1") |
| 45 | List<CalDevContrl> getCalDevContrlWidthDevId(@Param("Devid") String devId); | 43 | List<CalDevContrl> getCalDevContrlWidthDevId(@Param("Devid") String devId); |
| @@ -47,9 +45,15 @@ public interface DeviceDao { | @@ -47,9 +45,15 @@ public interface DeviceDao { | ||
| 47 | @Select("select * from CalDevBeContrl where State = 1 and Id = #{Id}") | 45 | @Select("select * from CalDevBeContrl where State = 1 and Id = #{Id}") |
| 48 | CalDevBeContrl getCalDevBeControl(@Param("Id") String Id); | 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 | @Select("select * from CalDevContrl where Devid = #{Devid} and Status = 1 and ModelType = 9") | 51 | @Select("select * from CalDevContrl where Devid = #{Devid} and Status = 1 and ModelType = 9") |
| 51 | List<CalDevContrl> getTempCalWitdDevid(@Param("Devid") String devId); | 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 | @Select("select clint_id\n" + | 57 | @Select("select clint_id\n" + |
| 54 | "from WL_Attendance where school_id = 1085 and clint_type = 12 and state = 1") | 58 | "from WL_Attendance where school_id = 1085 and clint_type = 12 and state = 1") |
| 55 | List<String> getHWDEvices(int i); | 59 | List<String> getHWDEvices(int i); |
| @@ -78,4 +82,11 @@ public interface DeviceDao { | @@ -78,4 +82,11 @@ public interface DeviceDao { | ||
| 78 | 82 | ||
| 79 | List<Wl_LinkModeBean> getWL_LinkMode(@Param("SchoolId") String SchoolId); | 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 @@ | @@ -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,11 +8,25 @@ import java.io.Serializable; | ||
| 8 | */ | 8 | */ |
| 9 | public class MessageVO implements Serializable { | 9 | public class MessageVO implements Serializable { |
| 10 | 10 | ||
| 11 | - | 11 | + /** |
| 12 | + * 消息体内容 | ||
| 13 | + */ | ||
| 12 | private String data; | 14 | private String data; |
| 15 | + /** | ||
| 16 | + * 协议号 | ||
| 17 | + */ | ||
| 13 | private Integer protocol; | 18 | private Integer protocol; |
| 19 | + /** | ||
| 20 | + * 通信协议号 | ||
| 21 | + */ | ||
| 14 | private String pv; | 22 | private String pv; |
| 23 | + /** | ||
| 24 | + * 签名 | ||
| 25 | + */ | ||
| 15 | private String sign; | 26 | private String sign; |
| 27 | + /** | ||
| 28 | + * 时间戳 | ||
| 29 | + */ | ||
| 16 | private Long t; | 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 @@ | @@ -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 @@ | @@ -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 | \ No newline at end of file | 71 | \ No newline at end of file |
cloud/mypulsar/src/main/java/com/example/mypulsar/mqtt/MqttProperties.java
0 → 100644
| @@ -0,0 +1,104 @@ | @@ -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,11 +2,12 @@ package com.example.mypulsar.task; | ||
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSON; | 3 | import com.alibaba.fastjson.JSON; |
| 4 | import com.alibaba.fastjson.JSONObject; | 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 | import com.example.mypulsar.campusDao.CampusDao; | 6 | import com.example.mypulsar.campusDao.CampusDao; |
| 8 | import com.example.mypulsar.dao.DeviceDao; | 7 | import com.example.mypulsar.dao.DeviceDao; |
| 9 | import com.example.mypulsar.utils.HttpUtil; | 8 | import com.example.mypulsar.utils.HttpUtil; |
| 9 | +import com.example.mypulsar.utils.JsonUtils; | ||
| 10 | +import lombok.Data; | ||
| 10 | import lombok.extern.slf4j.Slf4j; | 11 | import lombok.extern.slf4j.Slf4j; |
| 11 | import org.dom4j.Document; | 12 | import org.dom4j.Document; |
| 12 | import org.dom4j.DocumentException; | 13 | import org.dom4j.DocumentException; |
| @@ -17,6 +18,7 @@ import org.springframework.boot.configurationprocessor.json.JSONArray; | @@ -17,6 +18,7 @@ import org.springframework.boot.configurationprocessor.json.JSONArray; | ||
| 17 | import org.springframework.boot.configurationprocessor.json.JSONException; | 18 | import org.springframework.boot.configurationprocessor.json.JSONException; |
| 18 | import org.springframework.scheduling.annotation.Scheduled; | 19 | import org.springframework.scheduling.annotation.Scheduled; |
| 19 | import org.springframework.stereotype.Component; | 20 | import org.springframework.stereotype.Component; |
| 21 | +import org.springframework.util.CollectionUtils; | ||
| 20 | 22 | ||
| 21 | import java.text.ParseException; | 23 | import java.text.ParseException; |
| 22 | import java.text.SimpleDateFormat; | 24 | import java.text.SimpleDateFormat; |
| @@ -36,7 +38,7 @@ public class SchduledTasks { | @@ -36,7 +38,7 @@ public class SchduledTasks { | ||
| 36 | 38 | ||
| 37 | public static Map<String, Date> closeDevMap = new HashMap<>(); | 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 | private String closeModel = "{\"mode\":\"0\",\"power\":\"0\",\"remote_id\":\"%s\",\"remote_index\":\"11272\",\"temp\":\"26\",\"wind\":\"0\"}"; | 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,35 +47,46 @@ public class SchduledTasks { | ||
| 45 | 47 | ||
| 46 | @Scheduled(fixedRate = 60000) | 48 | @Scheduled(fixedRate = 60000) |
| 47 | public void closeAttend() { | 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 | while(it.hasNext()) { | 52 | while(it.hasNext()) { |
| 51 | Map.Entry<String, Date> entry = it.next(); | 53 | Map.Entry<String, Date> entry = it.next(); |
| 52 | String conBeDeviceId = entry.getKey(); | 54 | String conBeDeviceId = entry.getKey(); |
| 53 | if(conDevMap.containsKey(conBeDeviceId) && conDevMap.get(conBeDeviceId)!=null){ | 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 | Date openTime = entry.getValue(); | 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,7 +94,114 @@ public class SchduledTasks { | ||
| 81 | if (!outClose){ | 94 | if (!outClose){ |
| 82 | initWlModeOut(); | 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,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 | try { | 224 | try { |
| 101 | isClose = true; | 225 | isClose = true; |
| 102 | //获取有效的模板 | 226 | //获取有效的模板 |
| @@ -122,12 +246,14 @@ public class SchduledTasks { | @@ -122,12 +246,14 @@ public class SchduledTasks { | ||
| 122 | int week = Integer.parseInt(weeks[k]); | 246 | int week = Integer.parseInt(weeks[k]); |
| 123 | if (week == indexWeek) { | 247 | if (week == indexWeek) { |
| 124 | try { | 248 | try { |
| 249 | + //截至时间 | ||
| 125 | Date endDate = simpleDateFormat.parse(endTime); | 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 | long entTime = endDate.getTime(); | 252 | long entTime = endDate.getTime(); |
| 130 | long entTime2 = endDate2.getTime(); | 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 | if (indexTime > entTime && indexTime < entTime2) { | 258 | if (indexTime > entTime && indexTime < entTime2) { |
| 133 | //关闭所有设备 | 259 | //关闭所有设备 |
| @@ -149,10 +275,6 @@ public class SchduledTasks { | @@ -149,10 +275,6 @@ public class SchduledTasks { | ||
| 149 | log.info("关闭设备异常: ",e); | 275 | log.info("关闭设备异常: ",e); |
| 150 | } | 276 | } |
| 151 | } | 277 | } |
| 152 | - } else { | ||
| 153 | - //获取红外遥控器 | ||
| 154 | - List<Wl_Attendace> clintIds = deviceDao.getHWIds(); | ||
| 155 | - closeAllDevice(clintIds); | ||
| 156 | } | 278 | } |
| 157 | } catch (Exception e) { | 279 | } catch (Exception e) { |
| 158 | log.info("关闭设备异常: ",e); | 280 | log.info("关闭设备异常: ",e); |
| @@ -170,12 +292,12 @@ public class SchduledTasks { | @@ -170,12 +292,12 @@ public class SchduledTasks { | ||
| 170 | /** | 292 | /** |
| 171 | * 根据物联模板判断是否关闭 | 293 | * 根据物联模板判断是否关闭 |
| 172 | */ | 294 | */ |
| 173 | - private void initWlMode() { | 295 | + public void initWlMode() { |
| 174 | try { | 296 | try { |
| 175 | isClose = true; | 297 | isClose = true; |
| 176 | //获取有效的模板 | 298 | //获取有效的模板 |
| 177 | List<Wl_LinkModeBean> wl_linkModes = deviceDao.getWL_LinkMode("1085"); | 299 | List<Wl_LinkModeBean> wl_linkModes = deviceDao.getWL_LinkMode("1085"); |
| 178 | - if (null != wl_linkModes) { | 300 | + if (!CollectionUtils.isEmpty(wl_linkModes)) { |
| 179 | for (int i = 0; i < wl_linkModes.size(); i++) { | 301 | for (int i = 0; i < wl_linkModes.size(); i++) { |
| 180 | 302 | ||
| 181 | Wl_LinkModeBean wl_linkModeBean = wl_linkModes.get(i); | 303 | Wl_LinkModeBean wl_linkModeBean = wl_linkModes.get(i); |
| @@ -206,7 +328,6 @@ public class SchduledTasks { | @@ -206,7 +328,6 @@ public class SchduledTasks { | ||
| 206 | 328 | ||
| 207 | for (int k = 0; k < weeks.length; k++) { | 329 | for (int k = 0; k < weeks.length; k++) { |
| 208 | int week = Integer.parseInt(weeks[k]); | 330 | int week = Integer.parseInt(weeks[k]); |
| 209 | - | ||
| 210 | if (week == indexWeek) { | 331 | if (week == indexWeek) { |
| 211 | Date startDate = null; | 332 | Date startDate = null; |
| 212 | try { | 333 | try { |
| @@ -226,13 +347,11 @@ public class SchduledTasks { | @@ -226,13 +347,11 @@ public class SchduledTasks { | ||
| 226 | List<Wl_Attendace> clintIds = deviceDao.getHWAttsWithRoomId(fieldId); | 347 | List<Wl_Attendace> clintIds = deviceDao.getHWAttsWithRoomId(fieldId); |
| 227 | closeAllDevice(clintIds); | 348 | closeAllDevice(clintIds); |
| 228 | } | 349 | } |
| 229 | - | ||
| 230 | } | 350 | } |
| 231 | } catch (ParseException e) { | 351 | } catch (ParseException e) { |
| 232 | log.info("关闭设备异常: ",e); | 352 | log.info("关闭设备异常: ",e); |
| 233 | } | 353 | } |
| 234 | } | 354 | } |
| 235 | - | ||
| 236 | } | 355 | } |
| 237 | } | 356 | } |
| 238 | } | 357 | } |
| @@ -264,10 +383,12 @@ public class SchduledTasks { | @@ -264,10 +383,12 @@ public class SchduledTasks { | ||
| 264 | Element rootElt = doc.getRootElement(); | 383 | Element rootElt = doc.getRootElement(); |
| 265 | // 拿到head节点下的子节点title值 | 384 | // 拿到head节点下的子节点title值 |
| 266 | String title = rootElt.elementTextTrim("code"); | 385 | String title = rootElt.elementTextTrim("code"); |
| 267 | - log.info("请求结果:" + title); | 386 | + log.info("请求结果:" + title+" 设备ID : "+ deviceId); |
| 268 | if(title.equals("200")){ | 387 | if(title.equals("200")){ |
| 388 | + log.info("关闭成功:设备 :{},遥控ID: {}",devName,conValue); | ||
| 269 | conDevMap.remove(deviceId); | 389 | conDevMap.remove(deviceId); |
| 270 | } | 390 | } |
| 391 | + System.out.println(i); | ||
| 271 | } catch (DocumentException e) { | 392 | } catch (DocumentException e) { |
| 272 | e.printStackTrace(); | 393 | e.printStackTrace(); |
| 273 | } catch (Exception e) { | 394 | } catch (Exception e) { |
cloud/mypulsar/src/main/java/com/example/mypulsar/utils/ControlUtils.java
| @@ -63,11 +63,11 @@ public class ControlUtils { | @@ -63,11 +63,11 @@ public class ControlUtils { | ||
| 63 | try { | 63 | try { |
| 64 | //联动的时间范围,[{"Week":"5","StartTime":"14:02","EndTime":"14:06"}] | 64 | //联动的时间范围,[{"Week":"5","StartTime":"14:02","EndTime":"14:06"}] |
| 65 | if(StringUtils.isEmpty(cal.getInUserTime())){ | 65 | if(StringUtils.isEmpty(cal.getInUserTime())){ |
| 66 | + log.info("人感控制设备ID: {},未设置联动计划。",cal.getDevid()); | ||
| 66 | continue; | 67 | continue; |
| 67 | } | 68 | } |
| 68 | String inUseTime =cal.getInUserTime(); | 69 | String inUseTime =cal.getInUserTime(); |
| 69 | JSONArray jsonArray = new JSONArray(inUseTime); | 70 | JSONArray jsonArray = new JSONArray(inUseTime); |
| 70 | - log.info("控制设备ID: {}, 联动时间计划:{}",cal.getDevid(),jsonArray.toString()); | ||
| 71 | for (int i = 0; i < jsonArray.length(); i++) { | 71 | for (int i = 0; i < jsonArray.length(); i++) { |
| 72 | JSONObject jsonObject = jsonArray.getJSONObject(i); | 72 | JSONObject jsonObject = jsonArray.getJSONObject(i); |
| 73 | String weekStr = jsonObject.getString("Week"); | 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,9 +141,10 @@ public class HttpUtil { | ||
| 141 | * @param conDevName 设备名称 | 141 | * @param conDevName 设备名称 |
| 142 | * @return | 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 | try { | 145 | try { |
| 146 | String url = String.format("http://120.26.116.253:5555/TuYa/%s/addAirCode", conDevId); | 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 | RestTemplate restTemplate = new RestTemplate(); | 148 | RestTemplate restTemplate = new RestTemplate(); |
| 148 | TuYaAirCondition tuYaAirCondition = new TuYaAirCondition(); | 149 | TuYaAirCondition tuYaAirCondition = new TuYaAirCondition(); |
| 149 | String power = ""; | 150 | String power = ""; |
| @@ -160,9 +161,13 @@ public class HttpUtil { | @@ -160,9 +161,13 @@ public class HttpUtil { | ||
| 160 | log.info("控制失败:失败信息",e); | 161 | log.info("控制失败:失败信息",e); |
| 161 | } | 162 | } |
| 162 | log.info("开始发送遥控命令至设备:请求地址: {},设备名称: {},设备ID: {},请求参数: {}",url,conDevName,conDevId,tuYaAirCondition.toString()); | 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 | log.info("返回结果:{}",response); | 170 | log.info("返回结果:{}",response); |
| 165 | -// FileUtils.getInstance().writeLogs(String.format("%s设备%s--控制%s", power.equals("1") ? "成功" : "失败", conDevName + "-" + conDevId, response), FileUtils.addAirCode); | ||
| 166 | return response; | 171 | return response; |
| 167 | }catch (Exception e){ | 172 | }catch (Exception e){ |
| 168 | log.info("请求红外控制指令失败:{}",e); | 173 | log.info("请求红外控制指令失败:{}",e); |
cloud/mypulsar/src/main/java/com/example/mypulsar/utils/JsonUtils.java
0 → 100644
| @@ -0,0 +1,149 @@ | @@ -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,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 @@ | @@ -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,31 +7,29 @@ | ||
| 7 | </select>--> | 7 | </select>--> |
| 8 | <select id="getHWAttsWithRoomId" parameterType="java.lang.String" | 8 | <select id="getHWAttsWithRoomId" parameterType="java.lang.String" |
| 9 | resultType="com.example.mypulsar.bean.Wl_Attendace"> | 9 | resultType="com.example.mypulsar.bean.Wl_Attendace"> |
| 10 | - | ||
| 11 | select clint_id from WL_Attendance where belongAreaId = ${belongAreaId} and state = 1 and clint_type = 12; | 10 | select clint_id from WL_Attendance where belongAreaId = ${belongAreaId} and state = 1 and clint_type = 12; |
| 12 | - | ||
| 13 | </select> | 11 | </select> |
| 14 | 12 | ||
| 15 | <!-- 插入遥控器数据--> | 13 | <!-- 插入遥控器数据--> |
| 16 | <insert id="insertCalDevBeControl" parameterType="com.example.mypulsar.bean.CalDevBeContrl" | 14 | <insert id="insertCalDevBeControl" parameterType="com.example.mypulsar.bean.CalDevBeContrl" |
| 17 | databaseId="java.lang.Long"> | 15 | databaseId="java.lang.Long"> |
| 18 | - | ||
| 19 | insert into CalDevBeContrl values | 16 | insert into CalDevBeContrl values |
| 20 | (${ConDevId},${ConCode},${ConValue},${CreateTime},${CreateUserId},${State},${ModeId}) | 17 | (${ConDevId},${ConCode},${ConValue},${CreateTime},${CreateUserId},${State},${ModeId}) |
| 21 | - | ||
| 22 | </insert> | 18 | </insert> |
| 23 | 19 | ||
| 24 | <!-- 新建联动模板--> | 20 | <!-- 新建联动模板--> |
| 25 | 21 | ||
| 26 | <select id="getWL_LinkMode" parameterType="java.lang.String" resultType="com.example.mypulsar.bean.Wl_LinkModeBean"> | 22 | <select id="getWL_LinkMode" parameterType="java.lang.String" resultType="com.example.mypulsar.bean.Wl_LinkModeBean"> |
| 27 | - | ||
| 28 | select * from WL_LinkageMode where SchoolId = ${SchoolId} and State = 1; | 23 | select * from WL_LinkageMode where SchoolId = ${SchoolId} and State = 1; |
| 29 | - | ||
| 30 | </select> | 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 | </mapper> | 35 | </mapper> |
| 38 | \ No newline at end of file | 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,11 +3,17 @@ package com.example.mypulsar; | ||
| 3 | import com.alibaba.fastjson.JSON; | 3 | import com.alibaba.fastjson.JSON; |
| 4 | import com.alibaba.fastjson.JSONObject; | 4 | import com.alibaba.fastjson.JSONObject; |
| 5 | import com.example.mypulsar.bean.ClassRoom; | 5 | import com.example.mypulsar.bean.ClassRoom; |
| 6 | +import com.example.mypulsar.bean.DeviceBean; | ||
| 6 | import com.example.mypulsar.bean.Wl_Attendace; | 7 | import com.example.mypulsar.bean.Wl_Attendace; |
| 7 | import com.example.mypulsar.bean.Wl_LinkModeBean; | 8 | import com.example.mypulsar.bean.Wl_LinkModeBean; |
| 8 | import com.example.mypulsar.campusDao.CampusDao; | 9 | import com.example.mypulsar.campusDao.CampusDao; |
| 9 | import com.example.mypulsar.dao.DeviceDao; | 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 | import com.example.mypulsar.utils.HttpUtil; | 14 | import com.example.mypulsar.utils.HttpUtil; |
| 15 | +import com.example.mypulsar.utils.JsonUtils; | ||
| 16 | +import com.google.gson.JsonObject; | ||
| 11 | import org.junit.Test; | 17 | import org.junit.Test; |
| 12 | import org.junit.runner.RunWith; | 18 | import org.junit.runner.RunWith; |
| 13 | import org.slf4j.Logger; | 19 | import org.slf4j.Logger; |
| @@ -15,6 +21,7 @@ import org.slf4j.LoggerFactory; | @@ -15,6 +21,7 @@ import org.slf4j.LoggerFactory; | ||
| 15 | import org.springframework.beans.factory.annotation.Autowired; | 21 | import org.springframework.beans.factory.annotation.Autowired; |
| 16 | import org.springframework.boot.test.context.SpringBootTest; | 22 | import org.springframework.boot.test.context.SpringBootTest; |
| 17 | import org.springframework.test.context.junit4.SpringRunner; | 23 | import org.springframework.test.context.junit4.SpringRunner; |
| 24 | +import springfox.documentation.spring.web.json.Json; | ||
| 18 | 25 | ||
| 19 | import java.util.List; | 26 | import java.util.List; |
| 20 | 27 | ||
| @@ -49,6 +56,28 @@ public class MypulsarApplicationTests { | @@ -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 | @Test | 82 | @Test |
| 54 | public void contextLoads() { | 83 | public void contextLoads() { |
| @@ -105,7 +134,6 @@ public class MypulsarApplicationTests { | @@ -105,7 +134,6 @@ public class MypulsarApplicationTests { | ||
| 105 | } | 134 | } |
| 106 | 135 | ||
| 107 | private String getRemoteId(String conValue) { | 136 | private String getRemoteId(String conValue) { |
| 108 | - | ||
| 109 | try { | 137 | try { |
| 110 | JSONObject jsonObject = JSON.parseObject(conValue); | 138 | JSONObject jsonObject = JSON.parseObject(conValue); |
| 111 | if (null == jsonObject) return ""; | 139 | if (null == jsonObject) return ""; |