Commit 3d2b122faed2614a9b03468034b6c58e6b45a68e

Authored by 陶汉栋
1 parent 191a8018
Exists in master

人脸抓拍机实现

Showing 34 changed files with 896 additions and 320 deletions   Show diff stats
cloud/dahua/ReadMe.md 0 → 100644
... ... @@ -0,0 +1,30 @@
  1 +#**服务运行的环境**
  2 +##一、运行需要的基本环境库
  3 + 在包路径下有个libs文件,该文件下有个win64文件夹,里面存放了核心的库文件;
  4 +
  5 +##二、服务运行的核心库
  6 + 在com.example.dahua.lib下有个NetSDKLib实现类,里面封装了各种核心的方法,只需要知道调用就行;
  7 + com.example.dahua.module下的类是人脸设备方法的实现,可直接调用,基本上用的是GateModule类;
  8 +
  9 +##三、下发人员信息流程
  10 + 在mytask类中 有个设备自注册服务在autoRegister()方法中,会在ServiceCB回调接口中响应设备的注册信息,
  11 + 注册上来的设备都会存在内存中,通过deviceInfoBeans存储;
  12 + 人脸和卡号下发都是通过GateModule类中的响应方法下发;
  13 +
  14 +##四、下发人脸和权限的API接口
  15 + 由于之前图片传的是本地的绝对路径,所以在100服务器上部署了一个接口服务,对应的接口控制器为UserControl,
  16 + UserControl内部有逻辑处理,大华因为可以远程控制设备的注册ip和端口号,所以设备都注册在了21服务器上,做
  17 + 人脸下发的操作都在FileControl中;
  18 +
  19 +##五、部署到不同服务器中需要注意什么?
  20 + 大华的不用修改什么,只需要注意服务器内存就行;
  21 +
  22 +##六、UserControl的主要接口方法
  23 + sendPermission():下发权限,这个是在最新的人脸一体机和教师点名中使用方式上会用到,注册上来的人脸机设备id会以ytj开头,注意如果出现人脸和权限都下发了的情况还是提示没有权限,那就再发一遍权限,有些机型需要先发人脸再发权限;
  24 + sendToKB():人脸抓拍机会把抓到的人脸信息推送到数据看板,这个用来做测试用;
  25 + uploadImgAndUserInfo():单个下发人脸的接口
  26 + imgsSend():下发学校下所有人脸给指定设备;
  27 + checkFace():在线活体检测;
  28 +
  29 +##七、配置信息修改
  30 + application.yaml,该文件下包含了数据库配置、注册中心、数据库文件映射等信息,端口号、服务名也都是在这里修改;
0 31 \ No newline at end of file
... ...
cloud/dahua/src/main/java/com/example/dahua/MyTask.java
... ... @@ -66,9 +66,9 @@ public class MyTask implements ApplicationRunner {
66 66 public void run(ApplicationArguments args) throws Exception {
67 67 // 121.40.109.21
68 68  
69   -// LoginModule.init(disConnect, haveReConnect); // 打开工程,初始化
  69 + LoginModule.init(disConnect, haveReConnect); // 打开工程,初始化
70 70  
71   -// autoRegister();//自注册
  71 + autoRegister();//自注册
72 72  
73 73 // System.out.println(" sendRecordDao:"+sendRecordDao.getSenSuccess());
74 74 }
... ... @@ -205,7 +205,11 @@ public class MyTask implements ApplicationRunner {
205 205 lLongMap.put(deviceId, loginHandleLong);
206 206 isHasNewDevice = true;
207 207 String inTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
208   - int index = attendanceService.insert(deviceId, "22", pIp, wPort + "", inTime, "-1", "1");
  208 + if (deviceId.startsWith("ytj")){
  209 + attendanceService.insert(deviceId, "29", pIp, wPort + "", inTime, "-1", "1");
  210 + }else {
  211 + attendanceService.insert(deviceId, "22", pIp, wPort + "", inTime, "-1", "1");
  212 + }
209 213 DeviceInfoBean deviceInfoBean = new DeviceInfoBean();
210 214 deviceInfoBean.setDevcieId(deviceId);
211 215 deviceInfoBean.setDeviceIp(pIp);
... ... @@ -232,9 +236,9 @@ public class MyTask implements ApplicationRunner {
232 236 if (null != deviceInfoBeans && deviceInfoBeans.size() > 0) {
233 237 for (DeviceInfoBean dev :
234 238 deviceInfoBeans) {
235   -// FileUtils.getInstance().writeLogs(dev.getDevcieId() + "------" + lLongMap.get(dev.getDevcieId()), FileUtils.device_login);
236 239 if (lLongMap.get(dev.getDevcieId()).intValue() > 0) {
237 240 NetSDKLib.LLong lLong = GateModule.realLoadPic(0, analyzerCallback, lLongMap.get(dev.getDevcieId()));
  241 +// System.out.println("监听成功:"+dev.getDevcieId());
238 242 if (lLong.intValue() != -1) {
239 243 deviceInfoBeans.remove(dev);
240 244 }
... ... @@ -291,10 +295,10 @@ public class MyTask implements ApplicationRunner {
291 295 snapPicPath = snapPicPath.replace("FaceRecoder", "image");
292 296 if (cardBean.getType() == 0) {//老师
293 297 TeacherBean teacherBean = userDao.getTeacherWithId(cardBean.getUser_id());
294   - sendRecordDao.addFaceRecoder("", teacherBean.getUser_id(), teacherBean.getName(), snapPicPath, 1, time, card);
  298 + sendRecordDao.addFaceRecoder("", teacherBean.getUser_id(), teacherBean.getName(), snapPicPath, 1, time, card,"");
295 299 } else if (cardBean.getType() == 2) {//学生
296 300 UserInfoBean userInfoBean = userDao.getStudentWithid(cardBean.getUser_id());
297   - sendRecordDao.addFaceRecoder("", userInfoBean.getUser_id(), userInfoBean.getName(), snapPicPath, 1, time, card);
  301 + sendRecordDao.addFaceRecoder("", userInfoBean.getUser_id(), userInfoBean.getName(), snapPicPath, 1, time, card,"");
298 302 }
299 303 }
300 304  
... ...
cloud/dahua/src/main/java/com/example/dahua/async/MyScheduledTask.java
... ... @@ -63,9 +63,9 @@ public class MyScheduledTask {
63 63  
64 64 private String imgFilPath = "C:\\EhomePicServer";//抓拍图片路径
65 65  
66   - // @Scheduled(fixedRate = 5000)
  66 + @Scheduled(fixedRate = 5000)
67 67 private void sendErrorInfo() throws InterruptedException {
68   - System.out.println("---------------------------sendErrorInfo:");
  68 +// System.out.println("---------------------------sendErrorInfo:");
69 69 // System.out.println("定时任务执行中....");
70 70 deleteFaceImg();
71 71  
... ... @@ -76,13 +76,13 @@ public class MyScheduledTask {
76 76 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
77 77 int hour = Integer.parseInt(simpleDateFormat.format(new Date()));
78 78  
79   - if (hour >= 9 && hour < 11) {
  79 + /* if (hour >= 9 && hour < 11) {
80 80 dealData();
81 81 } else if (hour >= 13 && hour < 14) {
82 82 dealData();
83 83 } else if (hour >= 20 || hour < 5) {
84 84 dealData();
85   - }
  85 + }*/
86 86  
87 87 if (myTasks.isHasNewDevice) myTasks.reloadPic();
88 88  
... ...
cloud/dahua/src/main/java/com/example/dahua/async/SendUserInfoTask.java
... ... @@ -267,23 +267,21 @@ public class SendUserInfoTask {
267 267 Memory memory = null;//图片缓存
268 268 try {
269 269 String targPath = FilePath.picPathComp + userInfoBean.getStudentcode() + ".jpg";
270   -// String targPath = "C:\\Users\\taohandong\\Desktop\\comp\\"+userInfoBean.getStudentcode()+".jpg";
271 270 if (new File(picSrc).exists())
272 271 CompressPic.CompressPic(picSrc, targPath, userInfoBean.getStudentcode());//压缩后的图片
273 272 memory = ToolKits.readPictureFile(targPath);
274 273 sendRecordBean.setImgPath(picSrc);
275   -// System.out.println("下发学生信息:" + "targPath:" + new File(targPath).exists() + targPath + " userInfoBean:" + userInfoBean);
276 274 } catch (Exception e) {
277 275 e.printStackTrace();
278 276 }
279 277  
280 278 for (AttendanceBean attendanceBean :
281 279 attendanceBeans) {
282   - pushCardAndFace(attendanceBean, userInfoBean.getUser_id(), userInfoBean.getStudent_num(), userInfoBean.getName(), memory, sendRecordBean);
  280 + pushCardAndFace(attendanceBean, userInfoBean.getUser_id(), userInfoBean.getStudent_num(), userInfoBean.getName(), memory, sendRecordBean,userType);
283 281 }
284 282 }
285 283  
286   - private synchronized void pushCardAndFace(AttendanceBean attendanceBean, String user_id, String student_num, String name, Memory memory, SendRecordBean sendRecordBean) {
  284 + private synchronized void pushCardAndFace(AttendanceBean attendanceBean, String user_id, String student_num, String name, Memory memory, SendRecordBean sendRecordBean,String userType) {
287 285 sendRecordBean.setDeviceID(attendanceBean.getClint_id());
288 286 sendRecordBean.setSchoolId(Integer.parseInt(attendanceBean.getSchool_id()));
289 287 sendRecordBean.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
... ... @@ -299,7 +297,6 @@ public class SendUserInfoTask {
299 297 // System.out.println("loginHandleLong:" + loginHandleLong + MyTask.lLongMap.toString() + " 设备ID:" + attendanceBean.getClint_id());
300 298 // System.out.println("loginHandleLong:" +loginHandleLong);
301 299 if (loginHandleLong == null) {
302   -
303 300 FileUtils.getInstance().writeLogs("设备不在线:" + attendanceBean.getClint_id(), FileUtils.devices);
304 301 String deviceId = sendRecordDao.getFailIsExit(attendanceBean.getClint_id(), attendanceBean.getSchool_id());
305 302 sendRecordBean.setFailType(2);
... ... @@ -315,7 +312,7 @@ public class SendUserInfoTask {
315 312 String cardNum = cardNo(student_num);
316 313 if (bCardFlags != -1) {//修改卡信息
317 314 GateModule.modifyCard(bCardFlags, cardNum, user_id, name, "123456", Res.string().getCardStatusInt(1), Res.string().getCardTypeInt(1),
318   - 0, 0, 1, startTime, endTime, loginHandleLong);
  315 + 0, 0, 1, startTime, endTime, loginHandleLong,userType);
319 316 userDao.updateRecordNo(user_id, bCardFlags, attendanceBean.getClint_id());
320 317 bFaceFalgs = GateModule.modifyFaceInfo(user_id, memory, loginHandleLong);
321 318 //卡号添加成功,但是人脸不成功的话,就需要新增人脸
... ... @@ -326,7 +323,7 @@ public class SendUserInfoTask {
326 323  
327 324 bCardFlags = GateModule.insertCard(cardNum, user_id, name, "123456"
328 325 , Res.string().getCardStatusInt(1), Res.string().getCardTypeInt(1), 0, 1
329   - , 1, startTime, endTime, loginHandleLong);
  326 + , 1, startTime, endTime, loginHandleLong,userType);
330 327  
331 328 if (bCardFlags != -1) {
332 329 int index = userDao.saveRecordNo(user_id, bCardFlags, name, attendanceBean.getClint_id());//存储记录集编号
... ...
cloud/dahua/src/main/java/com/example/dahua/bean/StudentBean.java
... ... @@ -13,6 +13,8 @@ public class StudentBean implements Serializable {
13 13  
14 14 private int StudentType;
15 15  
  16 + private String teacher_num;
  17 +
16 18 private int UserType;
17 19  
18 20 private String Name;
... ... @@ -21,6 +23,12 @@ public class StudentBean implements Serializable {
21 23  
22 24 private String ClassName;
23 25  
  26 + private String class_id;
  27 +
  28 + private String class_name;
  29 +
  30 + private String student_type;
  31 +
24 32 private String OldCard;
25 33  
26 34 private String Card;
... ... @@ -49,6 +57,24 @@ public class StudentBean implements Serializable {
49 57  
50 58 private String studentcode;
51 59  
  60 + private String num;
  61 +
  62 + public String getNum() {
  63 + return num;
  64 + }
  65 +
  66 + public void setNum(String num) {
  67 + this.num = num;
  68 + }
  69 +
  70 + public String getTeacher_num() {
  71 + return teacher_num;
  72 + }
  73 +
  74 + public void setTeacher_num(String teacher_num) {
  75 + this.teacher_num = teacher_num;
  76 + }
  77 +
52 78 public String getUser_id() {
53 79 return user_id;
54 80 }
... ... @@ -225,6 +251,30 @@ public class StudentBean implements Serializable {
225 251 this.student_id = student_id;
226 252 }
227 253  
  254 + public String getClass_id() {
  255 + return class_id;
  256 + }
  257 +
  258 + public void setClass_id(String class_id) {
  259 + this.class_id = class_id;
  260 + }
  261 +
  262 + public String getClass_name() {
  263 + return class_name;
  264 + }
  265 +
  266 + public void setClass_name(String class_name) {
  267 + this.class_name = class_name;
  268 + }
  269 +
  270 + public String getStudent_type() {
  271 + return student_type;
  272 + }
  273 +
  274 + public void setStudent_type(String student_type) {
  275 + this.student_type = student_type;
  276 + }
  277 +
228 278 @Override
229 279 public String toString() {
230 280 return "StudentBean{" +
... ... @@ -236,6 +286,9 @@ public class StudentBean implements Serializable {
236 286 ", Name='" + Name + '\'' +
237 287 ", ClassId=" + ClassId +
238 288 ", ClassName='" + ClassName + '\'' +
  289 + ", class_id='" + class_id + '\'' +
  290 + ", class_name='" + class_name + '\'' +
  291 + ", student_type='" + student_type + '\'' +
239 292 ", OldCard='" + OldCard + '\'' +
240 293 ", Card='" + Card + '\'' +
241 294 ", SchoolId=" + SchoolId +
... ... @@ -245,7 +298,6 @@ public class StudentBean implements Serializable {
245 298 ", AddTime=" + AddTime +
246 299 ", Sex=" + Sex +
247 300 ", Face='" + Face + '\'' +
248   -// ", StudentCode='" + StudentCode + '\'' +
249 301 ", student_num='" + student_num + '\'' +
250 302 ", student_id='" + student_id + '\'' +
251 303 ", user_id='" + user_id + '\'' +
... ...
cloud/dahua/src/main/java/com/example/dahua/control/FileControl.java
... ... @@ -126,7 +126,7 @@ public class FileControl {
126 126 @ApiOperation(value = "下发卡信息")
127 127 public int addCard(@RequestParam("schoolId") String schoolId, @RequestParam("targPath") String targPath) {
128 128  
129   - File file = new File(targPath);
  129 + /*File file = new File(targPath);
130 130  
131 131 File[] files = file.listFiles();
132 132  
... ... @@ -148,7 +148,7 @@ public class FileControl {
148 148 }
149 149  
150 150  
151   - }
  151 + }*/
152 152  
153 153  
154 154 return 1;
... ...
cloud/dahua/src/main/java/com/example/dahua/control/UserControl.java
1 1 package com.example.dahua.control;
2 2  
3 3 import com.example.dahua.MyTask;
4   -import com.example.dahua.async.ImageUtils;
5 4 import com.example.dahua.async.SendUserInfoTask;
6 5 import com.example.dahua.bean.PermissionBean;
7   -import com.example.dahua.bean.UserAndPermission;
  6 +import com.example.dahua.bean.SendRecordBean;
  7 +import com.example.dahua.bean.StudentBean;
  8 +import com.example.dahua.dao.UserDao;
8 9 import com.example.dahua.lib.CompressPic;
9 10 import com.example.dahua.service.UserService;
10 11 import com.example.dahua.utils.*;
  12 +import com.example.dahua.xiananDao.SendRecordDao;
11 13 import io.swagger.annotations.Api;
12 14 import io.swagger.annotations.ApiImplicitParam;
13 15 import io.swagger.annotations.ApiImplicitParams;
14 16 import io.swagger.annotations.ApiOperation;
15   -import org.json.JSONArray;
16 17 import org.json.JSONException;
17 18 import org.json.JSONObject;
18 19 import org.springframework.beans.factory.annotation.Autowired;
19   -import org.springframework.beans.factory.annotation.Value;
20   -import org.springframework.http.HttpEntity;
21   -import org.springframework.http.HttpHeaders;
22 20 import org.springframework.http.MediaType;
23   -import org.springframework.http.ResponseEntity;
24   -import org.springframework.util.LinkedMultiValueMap;
25   -import org.springframework.util.MultiValueMap;
26 21 import org.springframework.util.StringUtils;
27 22 import org.springframework.web.bind.annotation.*;
28 23 import org.springframework.web.client.RestTemplate;
29   -import org.springframework.web.multipart.MultipartFile;
30 24  
31   -import javax.imageio.stream.FileImageInputStream;
32 25 import java.io.*;
33   -import java.net.HttpURLConnection;
34   -import java.net.URL;
35 26 import java.util.*;
36 27  
37 28 /**
... ... @@ -51,6 +42,12 @@ public class UserControl {
51 42 @Autowired
52 43 MyTask myTasks;
53 44  
  45 + @Autowired
  46 + SendRecordDao sendRecordDao;
  47 +
  48 + @Autowired
  49 + UserDao userDao;
  50 +
54 51  
55 52 @RequestMapping(value = "uploadImgAndUserInfo", method = RequestMethod.GET)
56 53 @ApiOperation(value = "上传用户信息")
... ... @@ -72,6 +69,130 @@ public class UserControl {
72 69 return true;
73 70 }
74 71  
  72 + @RequestMapping(value = "sendFaces", method = RequestMethod.GET)
  73 + @ApiOperation(value = "下发学校下所有人脸给指定设备", notes = "下发所有人脸给指定设备")
  74 + public void sendFaces(@RequestParam("deviceIds") String deviceIds, @RequestParam("schoolId") String schoolId, @RequestParam("userType") String userType) {
  75 +
  76 + String typeName = userType.equals("1") ? "Teacher" : "Student";
  77 +
  78 + String imgPath = "E:\\wwwhtdocs\\SmartCampus\\face17e5\\School" + schoolId + "\\" + typeName;
  79 +
  80 + File imgPathFile = new File(imgPath);//目录
  81 +
  82 + String[] deviceIdsStr = deviceIds.split(",");
  83 +
  84 +
  85 + if (imgPathFile.exists()) {
  86 + File[] imgfiles = imgPathFile.listFiles();
  87 + if (null != imgfiles) {
  88 +
  89 + for (int i = 0; i < imgfiles.length; i++) {
  90 + File file = imgfiles[i];//图片
  91 + String targetPath = "./picPath/comp/" + file.getName();
  92 + try {
  93 + CompressPic.CompressPic(file.getAbsolutePath(), targetPath, "");
  94 + } catch (Exception e) {
  95 + e.printStackTrace();
  96 + }
  97 + if (file.exists())
  98 + for (int j = 0; j < deviceIdsStr.length; j++) {
  99 + String deviceId = deviceIdsStr[j];
  100 +
  101 + StudentBean studentBean = null;
  102 + String card = "", name = "", studentCode = "";
  103 + if (userType.equals("1")) {
  104 + studentBean = userDao.getTeacherWithstudentcode(file.getName().split("\\.")[0], schoolId);
  105 + if (null != studentBean) {
  106 + card = studentBean.getTeacher_num();
  107 + name = studentBean.getName();
  108 + studentCode = studentBean.getNum();
  109 + }
  110 + } else if (userType.equals("2")) {
  111 + studentBean = userDao.getStudentWithstudentcode(file.getName().split("\\.")[0], schoolId);
  112 + if (null != studentBean) {
  113 + card = studentBean.getStudent_num();
  114 + name = studentBean.getName();
  115 + studentCode = studentBean.getStudentcode();
  116 + }
  117 + }
  118 +
  119 + if (!StringUtils.isEmpty(card)) {
  120 + String clint_type = userDao.getClintType(deviceId);
  121 + HttpUtils.uploadImgs(new File(targetPath), schoolId, studentCode, clint_type, Integer.parseInt(userType));
  122 + }
  123 +
  124 + }
  125 +
  126 + }
  127 +
  128 + }
  129 + }
  130 +
  131 + }
  132 +
  133 + @RequestMapping(value = "sendErrorFaces", method = RequestMethod.GET)
  134 + @ApiOperation(value = "下发失败的人脸", notes = "下发失败的人脸")
  135 + public void sendErrorFaces(@RequestParam("schoolId") String schoolId, @RequestParam("deviceid") String deviceid,@RequestParam("userType")int userType) {
  136 +
  137 + if (!StringUtils.isEmpty(deviceid)) {
  138 + senErrorFace(deviceid, schoolId, userType);
  139 + } else {
  140 + List<String> deviceIds = sendRecordDao.getDeviceIds(schoolId);
  141 +
  142 + if (null != deviceIds) {
  143 + for (int j = 0; j < deviceIds.size(); j++) {
  144 + String deviceId = deviceIds.get(j);
  145 + senErrorFace(deviceId, schoolId,userType);
  146 + }
  147 + }
  148 + }
  149 +
  150 +
  151 + }
  152 +
  153 +
  154 + private void senErrorFace(String deviceId, String schoolId, int userType) {
  155 + List<SendRecordBean> sendRecordBeans = sendRecordDao.getSendFailWithDevId(deviceId);
  156 + if (null != sendRecordBeans) {
  157 +
  158 + for (int i = 0; i < sendRecordBeans.size(); i++) {
  159 +
  160 + SendRecordBean sendRecordBean = sendRecordBeans.get(i);
  161 + String typeName = "";
  162 + if (userType==0){
  163 + typeName = sendRecordBean.getUserType() == 1 ? "Teacher" : "Student";
  164 + }else {
  165 + typeName = userType == 1 ? "Teacher" : "Student";
  166 + }
  167 + String studentCode = "";
  168 +
  169 + if (sendRecordBean.getUserType() == 1) {
  170 + studentCode = userDao.getTeaNumWithCard(sendRecordBean.getNum());
  171 + } else if (sendRecordBean.getUserType() == 2) {
  172 + studentCode = userDao.getStudentCode(sendRecordBean.getNum());
  173 + }
  174 +
  175 + String imgPath = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + sendRecordBean.getSchoolId() + "\\" + typeName + "\\" + studentCode + ".png";
  176 + File imgFile = new File(imgPath);
  177 + if (imgFile.exists()) {
  178 + String targetPath = "./picPath/comp/" + imgFile.getName();
  179 + try {
  180 + CompressPic.CompressPic(imgFile.getAbsolutePath(), targetPath, "");
  181 + } catch (Exception e) {
  182 + e.printStackTrace();
  183 + }
  184 +
  185 + String clint_type = userDao.getClintType(sendRecordBean.getDeviceID());
  186 + HttpUtils.uploadImgs(new File(targetPath), schoolId, studentCode, clint_type, sendRecordBean.getUserType());
  187 + } else {
  188 + System.out.println("文件不存在");
  189 + }
  190 + }
  191 +
  192 + }
  193 + }
  194 +
  195 +
75 196 @RequestMapping(value = "sendSingle", method = RequestMethod.GET)
76 197 @ApiOperation(value = "单张卡下发")
77 198 public String sendSIngle(@RequestParam("SchoolId") String SchoolId, @RequestParam("Card") String Card) {
... ... @@ -123,11 +244,11 @@ public class UserControl {
123 244  
124 245 String userCode = file.getName().split("\\.")[0];
125 246  
126   - String schoolId = "";
  247 + String schoolId = "864";
127 248  
128   - if (httpurl.contains("Student")) {
  249 + if (httpurl.contains("Student")&&!httpurl.startsWith("http")) {
129 250 schoolId = httpurl.substring(httpurl.indexOf("School") + 6, httpurl.indexOf("\\Student"));
130   - } else if (httpurl.contains("Teacher")) {
  251 + } else if (httpurl.contains("Teacher")&&!httpurl.startsWith("http")) {
131 252 schoolId = httpurl.substring(httpurl.indexOf("School") + 6, httpurl.indexOf("\\Teacher"));
132 253 }
133 254 System.out.println("choolId:" + schoolId + "userCode:" + userCode);
... ... @@ -143,6 +264,27 @@ public class UserControl {
143 264 }
144 265  
145 266  
  267 + @RequestMapping(value = "jpg2png", method = RequestMethod.GET)
  268 + @ApiOperation("jpg图片转png")
  269 + public boolean jpg2png(@RequestParam("path") String path) {
  270 +
  271 + File file = new File(path);
  272 + if (file.exists()) {
  273 +
  274 + File[] files = file.listFiles();
  275 +
  276 + for (int i = 0; i < files.length; i++) {
  277 + File filePath = files[i];
  278 + BaiduUtils.getBaiduUtils().checkImg(filePath.getAbsolutePath());
  279 + }
  280 +
  281 + }
  282 +
  283 + return true;
  284 +
  285 + }
  286 +
  287 +
146 288  
147 289  
148 290 /*@RequestMapping(value = "tranpic", method = RequestMethod.GET)
... ...
cloud/dahua/src/main/java/com/example/dahua/dao/UserDao.java
... ... @@ -129,12 +129,37 @@ public interface UserDao {
129 129 void getUserWidthUserId(@Param("userId") String userId);
130 130  
131 131 @Select("select * from SZ_V_School_Student where user_id = #{userId}")
132   - List<StudentBean> getStudentWithUserId(@Param("userId")String userId);
  132 + List<StudentBean> getStudentWithUserId(@Param("userId") String userId);
133 133  
134 134 @Select("select * from SZ_V_School_Teacher where user_id = #{userId}")
135   - List<TeacherBean> getTeaWithUserId(@Param("userId")String userId);
  135 + List<TeacherBean> getTeaWithUserId(@Param("userId") String userId);
136 136  
137 137 @Select("select Top(1) user_id from SZ_V_School_Student where studentcode = #{studentcode}")
138 138 String getStuWithCode(@Param("studentcode") String code);
139 139  
  140 + @Select("select top(1) num from SZ_V_School_Teacher where teacher_num=#{num}")
  141 + String getTeaNumWithCard(@Param("num") String num);
  142 +
  143 + @Select("select clint_type from SZ_Attendance where clint_id = #{clint_id}}")
  144 + String getClintType(@Param("clint_id") String deviceID);
  145 +
  146 + @Select("select v.* from SZ_Student as s inner join SZ_V_School_Student as v on s.student_id = v.student_id where s.intime>'2020-09-01' and school_id = 654 order by student_id desc ")
  147 + List<StudentBean> getStus();
  148 +
  149 + @Insert("insert into HS_StudentUpdateCard(UserId,CustomerId,StudentType,UserType,Name,ClassId,ClassName,Card,SchoolId,IsNew,UpdateType,AddTime,Sex,StudentCode,mobile) values (" +
  150 + "#{UserId},#{CustomerId},#{StudentType},#{UserType},#{Name},#{ClassId},#{ClassName},#{Card},#{SchoolId},#{IsNew},#{UpdateType},#{AddTime},#{Sex},#{StudentCode},#{mobile})")
  151 + void insertUpdateCard(@Param("UserId")String UserId,@Param("CustomerId")String CustomerId,@Param("StudentType")String StudentType,@Param("UserType")String UserType,
  152 + @Param("Name")String Name,@Param("ClassId")String ClassId,@Param("ClassName")String ClassName,@Param("Card")String Card,@Param("SchoolId")String SchoolId,
  153 + @Param("IsNew")String IsNew,@Param("UpdateType")String UpdateType,@Param("AddTime")String AddTime,@Param("Sex")String Sex,@Param("StudentCode")String StudentCode,
  154 + @Param("mobile")String mobile);
  155 +
  156 + @Select("select Top(1)*\n" +
  157 + "from SZ_V_School_Teacher\n" +
  158 + "where num = #{num} and school_id = #{schoolId}")
  159 + StudentBean getTeacherWithstudentcode(@Param("num") String num, @Param("schoolId") String schoolId);
  160 +
  161 + @Select("select Top(1)*\n" +
  162 + "from SZ_V_School_Student\n" +
  163 + "where studentcode = #{studentcode} and school_id = #{schoolId}")
  164 + StudentBean getStudentWithstudentcode(@Param("studentcode") String studentcode, @Param("schoolId") String schoolId);
140 165 }
... ...
cloud/dahua/src/main/java/com/example/dahua/module/GateModule.java
... ... @@ -165,7 +165,7 @@ public class GateModule {
165 165  
166 166 public static synchronized int insertCard(String cardNo, String userId, String cardName, String cardPwd,
167 167 int cardStatus, int cardType, int useTimes, int isFirstEnter,
168   - int isValid, String startValidTime, String endValidTime, LLong lLong) {
  168 + int isValid, String startValidTime, String endValidTime, LLong lLong,String userType) {
169 169 /**
170 170 * 门禁卡记录集信息
171 171 */
... ... @@ -192,8 +192,13 @@ public class GateModule {
192 192 accessCardInfo.sznDoors[0] = 0;
193 193 accessCardInfo.sznDoors[1] = 1;
194 194 accessCardInfo.nTimeSectionNum = 2; // 与门数对应
195   - accessCardInfo.sznTimeSectionNo[0] = 120; // 表示第一个门全天有效
196   - accessCardInfo.sznTimeSectionNo[1] = 120; // 表示第二个门全天有效
  195 + if (userType.equals("1")){
  196 + accessCardInfo.sznTimeSectionNo[0] = 255; // 表示第一个门全天有效
  197 + accessCardInfo.sznTimeSectionNo[1] = 255; // 表示第二个门全天有效
  198 + }else {
  199 + accessCardInfo.sznTimeSectionNo[0] = 120; // 表示第一个门全天有效
  200 + accessCardInfo.sznTimeSectionNo[1] = 120; // 表示第二个门全天有效
  201 + }
197 202  
198 203 // 卡状态
199 204 accessCardInfo.emStatus = cardStatus;
... ... @@ -380,17 +385,19 @@ public class GateModule {
380 385  
381 386 // 获取
382 387 if (ToolKits.GetDevConfig(lLong, nChannel, strCmd, msg)) {
383   - System.out.println("Enable:" + msg.bEnable);
384   - try {
385   - System.out.println("自定义名称:" + new String(msg.szName, "utf-8").trim());
386   - } catch (UnsupportedEncodingException e) {
387   - e.printStackTrace();
388   - }
  388 +// System.out.println("Enable:" + msg.bEnable);
  389 +// try {
  390 +// System.out.println("自定义名称:" + new String(msg.szName, "utf-8").trim());
  391 +// } catch (UnsupportedEncodingException e) {
  392 +// e.printStackTrace();
  393 +// }
389 394 for (int i = 0; i < 7; i++) {
390   - for (int j = 0; j < 4; j++) {
391   - System.out.println("dwRecordMask:" + msg.stuTimeWeekDay[i].stuTimeSection[j].dwRecordMask);
  395 + for (int j = 0; j < 3; j++) {
  396 +// System.out.println("dwRecordMask:" + msg.stuTimeWeekDay[i].stuTimeSection[j]);
392 397 System.out.println(msg.stuTimeWeekDay[i].stuTimeSection[j].startTime() + "-" +
393   - msg.stuTimeWeekDay[i].stuTimeSection[j].endTime() + "\n");
  398 + msg.stuTimeWeekDay[i].stuTimeSection[j].endTime());
  399 + System.out.println("--------------------------------------------");
  400 +
394 401 }
395 402 }
396 403 // 设置
... ... @@ -514,7 +521,7 @@ public class GateModule {
514 521  
515 522 public static boolean modifyCard(int recordNo, String cardNo, String userId, String cardName, String cardPwd,
516 523 int cardStatus, int cardType, int useTimes, int isFirstEnter,
517   - int isValid, String startValidTime, String endValidTime, LLong lLong) {
  524 + int isValid, String startValidTime, String endValidTime, LLong lLong,String userType) {
518 525 /**
519 526 * 门禁卡记录集信息
520 527 */
... ... @@ -543,8 +550,13 @@ public class GateModule {
543 550 accessCardInfo.sznDoors[0] = 0;
544 551 accessCardInfo.sznDoors[1] = 1;
545 552 accessCardInfo.nTimeSectionNum = 2; // 与门数对应
546   - accessCardInfo.sznTimeSectionNo[0] = 120; // 表示第一个门全天有效
547   - accessCardInfo.sznTimeSectionNo[1] = 120; // 表示第二个门全天有效
  553 + if (userType.equals("1")){
  554 + accessCardInfo.sznTimeSectionNo[0] = 255; // 表示第一个门全天有效
  555 + accessCardInfo.sznTimeSectionNo[1] = 255; // 表示第二个门全天有效
  556 + }else {
  557 + accessCardInfo.sznTimeSectionNo[0] = 120; // 表示第一个门全天有效
  558 + accessCardInfo.sznTimeSectionNo[1] = 120; // 表示第二个门全天有效
  559 + }
548 560  
549 561 // 卡状态
550 562 accessCardInfo.emStatus = cardStatus;
... ...
cloud/dahua/src/main/java/com/example/dahua/service/imp/PermissFaceServiceImp.java
... ... @@ -16,9 +16,7 @@ import org.springframework.stereotype.Service;
16 16 import org.springframework.util.StringUtils;
17 17 import org.springframework.web.client.RestTemplate;
18 18  
19   -import java.io.File;
20   -import java.io.FileOutputStream;
21   -import java.io.IOException;
  19 +import java.io.*;
22 20 import java.net.URI;
23 21 import java.net.URISyntaxException;
24 22 import java.util.List;
... ... @@ -187,18 +185,30 @@ public class PermissFaceServiceImp implements PermissFaceService {
187 185 for (int i = 0; i < studentBeans.size(); i++) {
188 186 StudentBean studentBean = studentBeans.get(i);
189 187 int schoolId = studentBean.getSchool_id();
  188 + String imgPath = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\Student" + "\\" + studentBean.getStudentcode() + ".png";
  189 + File stuFile = new File(imgPath);
  190 + if (!stuFile.exists())stuFile.createNewFile();
  191 +
  192 + copy(saveImgFile.getAbsolutePath(),imgPath);
  193 +
190 194 uploadImgs(saveImgFile, schoolId + "", studentBean.getStudentcode(), 2, studentBean.getCard(), studentBean.getName());
191 195 }
192 196  
193 197 } else {
194 198 List<TeacherBean> teacherBeans = userDao.getTeaWithUserId(userId);
195   -log.error("教师下发");
  199 + log.error("教师下发");
196 200 if (null != teacherBeans && teacherBeans.size() > 0) {
197 201  
198 202 for (int i = 0; i < teacherBeans.size(); i++) {
199 203 TeacherBean teacherBean = teacherBeans.get(i);
200 204  
201 205 String schoolId = teacherBean.getSchool_id();
  206 +
  207 + String imgPath = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\Teacher" + "\\" + teacherBean.getNum() + ".png";
  208 + File stuFile = new File(imgPath);
  209 + if (!stuFile.exists())stuFile.createNewFile();
  210 + copy(saveImgFile.getAbsolutePath(),imgPath);
  211 +
202 212 uploadImgs(saveImgFile, schoolId, teacherBean.getNum(), 1, teacherBean.getTeacher_num(), teacherBean.getName());
203 213  
204 214 }
... ... @@ -225,6 +235,33 @@ log.error(&quot;教师下发&quot;);
225 235 return responseBean;
226 236 }
227 237  
  238 +
  239 + private void copy(String src,String target){
  240 +
  241 + try {
  242 + FileInputStream fileInputStream = new FileInputStream(src);
  243 + FileOutputStream fileOutputStream = new FileOutputStream(target);
  244 +
  245 + byte[] bytes = new byte[1024];
  246 + int length = -1;
  247 + while ((length=fileInputStream.read(bytes))!=0){
  248 +
  249 + fileOutputStream.write(bytes,0,length);
  250 +
  251 + }
  252 +
  253 + fileInputStream.close();
  254 + fileOutputStream.close();
  255 +
  256 + } catch (FileNotFoundException e) {
  257 + e.printStackTrace();
  258 + } catch (IOException e) {
  259 + e.printStackTrace();
  260 + }
  261 +
  262 + }
  263 +
  264 +
228 265 private void uploadImgs(File saveImgFile, String schoolId, String studentcode, int userType, String card, String name) {
229 266 List<AttendanceBean> attendanceBeanList = userDao.getAllDevices(schoolId + "");
230 267 if (null != attendanceBeanList && attendanceBeanList.size() > 0)
... ... @@ -233,7 +270,7 @@ log.error(&quot;教师下发&quot;);
233 270  
234 271 String clintType = attendanceBean.getClint_type();
235 272 //根据设备类型上传人脸
236   - log.error("设备:{}",clintType);
  273 + log.error("设备:{}", clintType);
237 274 if (clintType.equals("18") || clintType.equals("28")) {
238 275 HttpUtils.uploadImg2HK(saveImgFile.getAbsolutePath(), card, name, attendanceBean.getClint_id(), String.valueOf(userType));
239 276  
... ...
cloud/dahua/src/main/java/com/example/dahua/service/imp/UserServiceImp.java
... ... @@ -29,7 +29,11 @@ public class UserServiceImp implements UserService {
29 29  
30 30 if (!StringUtils.isEmpty(devid)) return userDao.getAttendanceBeanWithId(schoolId, clint_type, devid);
31 31  
32   - return userDao.getAttendanceBeans(schoolId, clint_type);
  32 + List<AttendanceBean> attendanceBeanList = userDao.getAttendanceBeans(schoolId, clint_type);
  33 +
  34 + if (attendanceBeanList.size()==0)attendanceBeanList = userDao.getAttendanceBeans(schoolId,"29");
  35 +
  36 + return attendanceBeanList;
33 37 }
34 38  
35 39 @Override
... ... @@ -49,7 +53,9 @@ public class UserServiceImp implements UserService {
49 53 @Override
50 54 public boolean uploadImgAndUserInfo(String file, String schoolId, String studentCode, String clint_type, int userType, String devid) {
51 55 List<AttendanceBean> attendanceBeans = getAttendanceBeans(schoolId, clint_type, devid);//获取学校下的大华设备
  56 +
52 57 System.out.println("设备数量:" + attendanceBeans.size());
  58 +
53 59 UserInfoBean userInfoBean = null;
54 60 try {
55 61 if (userType == 2) {
... ...
cloud/dahua/src/main/java/com/example/dahua/utils/BaiduUtils.java
... ... @@ -101,8 +101,8 @@ public class BaiduUtils {
101 101 }
102 102 } catch (Exception e) {
103 103 e.printStackTrace();
  104 + return false;
104 105 }
105   - return true;
106 106 }
107 107  
108 108 /**
... ...
cloud/dahua/src/main/java/com/example/dahua/xiananDao/SendRecordDao.java
... ... @@ -75,14 +75,16 @@ public interface SendRecordDao {
75 75 @Select("select * from Face_SendFail where schoolId = #{schoolId} and userType = #{userType} and deviceID = #{deviceID}")
76 76 List<SendRecordBean> getFaceFails(@Param("userType") int userType, @Param("schoolId") int schoolId, @Param("deviceID") String deviceID);
77 77  
78   - @Insert("insert into Face_Recoder values(#{deviceId},#{user_id},#{name},#{imgurl},#{inOrOut},#{time},#{cardNum})")
  78 + @Insert("insert into Face_Recoder values(#{deviceId},#{user_id},#{name},#{imgurl},#{inOrOut},#{time},#{cardNum},#{temp})")
79 79 void addFaceRecoder(@Param("deviceId") String deviceId, @Param("user_id") String user_id, @Param("name") String name,
80 80 @Param("imgurl") String imgurl, @Param("inOrOut") int inOrOut, @Param("time") String time,
81   - @Param("cardNum") String cardNum);
  81 + @Param("cardNum") String cardNum,@Param("temp")String temp);
82 82  
  83 + @Select("select DISTINCT deviceID from Face_SendFail where schoolId = #{schoolId} ")
  84 + List<String> getDeviceIds(@Param("schoolId") String schoolId);
83 85  
84   - @Select("select stu.studentcode from DBLan137.smartcampus.dbo.SZ_V_School_Student as stu where stu.student_num in (select distinct NUM from Face_SendFail where schoolId = 1037 and time > '2020-04-13' and userType = 2)")
85   - List<String> getStudentCode();
  86 + @Select("select * from Face_SendFail where deviceID = #{deviceID}")
  87 + List<SendRecordBean> getSendFailWithDevId(@Param("deviceID") String deviceId);
86 88  
87 89 }
88 90  
... ...
cloud/dahua/src/test/java/com/example/dahua/DahuaApplicationTests.java
... ... @@ -479,47 +479,17 @@ public class DahuaApplicationTests {
479 479 @Test
480 480 public void test1() {
481 481  
482   -// List<StudentBean> list = userDao.getStudentUserIdsWith();
483   -//
484   -// for (int i = 0; i < list.size(); i++) {
485   -// StudentBean studentBean = list.get(i);
486   -// }
487   -//
488   -// System.out.println("list:" + list.toString());
489   -
490   -// List<AttendanceBean> attendanceBeanList = userDao.getAttendanceBeans("479","4");
491   -//
492   -// for (int i = 0; i < attendanceBeanList.size(); i++) {
493   -// AttendanceBean attendanceBean = attendanceBeanList.get(i);
494   -//
495   -//
496   -// }
497   -
498   - File file = new File("D:\\新七年级\\名字.txt");
499   -
500   - try {
501   - FileReader fileReader = new FileReader(file);
502   - BufferedReader bufferedReader = new BufferedReader(fileReader);
503   - List<UserInfoBean> userInfoBeans = userDao.getStuUserInfos();
504   - String content = null;
505   - while ((content = bufferedReader.readLine()) != null) {
506   -
507   - for (int i = 0; i < userInfoBeans.size(); i++) {
508   - UserInfoBean userInfoBean = userInfoBeans.get(i);
509   - if (content.equals(userInfoBean.getName())){
510   - System.out.println(userInfoBean.getStudentcode()+"\t");
511   - }
512   - }
  482 + List<StudentBean> studentBeans = userDao.getStus();
  483 + for (int i = 0; i < studentBeans.size(); i++) {
  484 + StudentBean studentBean = studentBeans.get(i);
  485 + System.out.println("studentBean:"+studentBean.toString());
513 486  
514   - }
  487 + userDao.insertUpdateCard(studentBean.getUser_id(),studentBean.getStudent_id(),studentBean.getStudent_type()+"","2",
  488 + studentBean.getName(),studentBean.getClass_id()+"",studentBean.getClass_name(),studentBean.getStudent_num(),studentBean.getSchool_id()+"",
  489 + "1","1","2020-09-23 11:40:00",studentBean.getSex()+"",studentBean.getStudentcode(),"");
515 490  
516   - } catch (FileNotFoundException e) {
517   - e.printStackTrace();
518   - } catch (IOException e) {
519   - e.printStackTrace();
520 491 }
521 492  
522   -
523 493 }
524 494  
525 495  
... ...
cloud/fIle-center/ReadMe.md 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +#文件管理服务
  2 +##配置信息
  3 + application.yml配置文件中配置了OSS的各种属性,如果要修改的话,可直接在这里修改;
  4 +
  5 +##实现的接口
  6 + fileUpload1:上传文件,重名的会覆盖;
  7 + fileUpload:上传文件,重名的会在后面加1;
  8 +##配置类
  9 + AliyunOSSConfig类,初始化的时候会调用配置文件中的信息;
  10 + AllowOriginFilter:做跨域处理;
  11 +
  12 +##业务处理类:
  13 + service文件下,类名后面以service结尾的就是抽象方法,以Imp结尾的就是对抽象方法的实现类,做业务处理;
0 14 \ No newline at end of file
... ...
cloud/fIle-center/src/main/java/com/sincere/file/control/FileControl.java
... ... @@ -80,7 +80,7 @@ public class FileControl {
80 80 }
81 81  
82 82  
83   - @RequestMapping(value = "getWord", method = RequestMethod.GET)
  83 + /*@RequestMapping(value = "getWord", method = RequestMethod.GET)
84 84 @ApiOperation("获取21世纪题目")
85 85 @ApiImplicitParams(
86 86 {@ApiImplicitParam(name = "url", value = "链接")}
... ... @@ -106,7 +106,7 @@ public class FileControl {
106 106 return fileService.uploadLocalFile(new File(wordPath), "test");
107 107  
108 108  
109   - }
  109 + }*/
110 110  
111 111  
112 112 }
... ...
cloud/fIle-center/src/main/java/com/sincere/file/service/impl/AliyunOssServiceImpl.java
... ... @@ -43,8 +43,8 @@ public class AliyunOssServiceImpl extends AbstractFileService {
43 43  
44 44 @Override
45 45 protected void uploadFile(MultipartFile file, FileInfo fileInfo, String filePath) throws Exception {
46   -// String fileName = UUID.randomUUID().toString()+"."+fileInfo.getName().split("\\.")[1];
47   - String fileName = fileInfo.getName();
  46 + String fileName = UUID.randomUUID().toString()+"."+fileInfo.getName().split("\\.")[1];
  47 +// String fileName = fileInfo.getName();
48 48 String keyObjectName = filePath + "/" + fileName;
49 49  
50 50 // boolean isExist = ossClient.doesObjectExist(bucketName, keyObjectName);
... ...
cloud/haikangface/ReadMe.md 0 → 100644
... ... @@ -0,0 +1,38 @@
  1 +#**服务运行的环境**
  2 +##一、运行需要的基本环境库
  3 + 在C盘放了一个lib文件夹,里面放了服务运行的基础库,每台有海康服务的服务器上都有这个文件;
  4 +
  5 +##二、服务运行的核心库
  6 + 和人脸机直接通信的服务功能全在CMSServer类里面,run方法是服务在运行的时候,会自动执行注册服务、图片服务、报警服务的初始化,
  7 + 分别对应initCMS()、initSS()、initAlarm(),里面的方法不用做修改;
  8 + CMS(注册服务):设备注册该服务的IP和端口,在FRegisterCallBack注册回调接口中接收注册信息,并响应报警服务器和图片服务器的ip和端口;
  9 + HCEHomeSS(图片服务):createImgPath()方法生成图片服务路径,生成后可以下发给人脸机使用;
  10 + initAlarm(报警服务):EHomeMsgCallBack回调方法会监听设备的各种报警信息,目前主要是对人脸识别成功做了记录,其余的方法可以参考PDF文件或者AlarmUtil类;
  11 +
  12 +##三、下发人员信息流程
  13 + CMSServer方法封装了下发的方法,只需要调用就行,xml的字段和格式不需要去改变;
  14 + 直接调用createImgPath() 方法,里面执行了人脸图片路径生成和下发对应卡号的操作;
  15 +
  16 +##四、下发人脸和权限的API接口
  17 + 由于之前图片传的是本地的绝对路径,所以在100服务器上部署了一个接口服务,对应的接口控制器为UserControl,
  18 + UserControl内部有逻辑处理,如果人脸机注册在100服务器上,就会直接对人脸机做下发人脸、报警信息处理等操作,
  19 + 如果没有注册在100服务器上,内部会调用api接口访问253上的接口,253上的服务会对注册的人脸机做响应操作,调用的
  20 + 控制器对应FileControl,这些控制器都在这同一个服务中;
  21 + 下发权限:默认会发全天的权限;
  22 +
  23 +##五、部署到不同服务器中需要注意什么?
  24 + 唯一要注意的就是修改CMSServer服务中的ip_cloud值,改成对应服务的公网ip;
  25 +
  26 +##六、UserControl的主要接口方法
  27 + sendPermiss():下发权限,这个是在最新的人脸一体机和教师点名中使用方式上会用到,注册上来的人脸机设备id会以ytj开头,注意如果出现人脸和权限都下发了的情况还是提示没有权限,那就再发一遍权限,有些机型需要先发人脸再发权限;
  28 + sendUsersAndPermiss():教师点名中用到了这个方法;
  29 + sendToKB():人脸抓拍机会把抓到的人脸信息推送到数据看板,这个用来做测试用;
  30 + sendCardAndImg1():单个下发人脸的接口
  31 + sendFaces():下发学校下所有人脸给指定设备;
  32 + sendErrorFaces():下发失败的人脸;
  33 + sendFaceNotExits():下发学校下还没有下发的人脸给指定设备;
  34 + sendFaceToDevices():下发单个用户给指定设备
  35 + deleteCard():删除人脸
  36 +
  37 +##七、配置信息修改
  38 + application.yaml,该文件下包含了数据库配置、注册中心、数据库文件映射等信息,端口号、服务名也都是在这里修改;
0 39 \ No newline at end of file
... ...
cloud/haikangface/src/main/java/com/sincere/haikangface/CMSServer.java
... ... @@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSON;
4 4 import com.alibaba.fastjson.JSONArray;
5 5 import com.alibaba.fastjson.JSONObject;
6 6 import com.sincere.haikangface.bean.*;
7   -import com.sincere.haikangface.bean.face.BaiduUserInfoBean;
8 7 import com.sincere.haikangface.bean.xiaoan.Face_Recoder;
9 8 import com.sincere.haikangface.dao.DeviceDao;
10 9 import com.sincere.haikangface.dao.UserDao;
... ... @@ -12,7 +11,6 @@ import com.sincere.haikangface.haikanglibs.HCEHomeAlarm;
12 11 import com.sincere.haikangface.haikanglibs.HCEHomeCMS;
13 12 import com.sincere.haikangface.haikanglibs.HCEHomeSS;
14 13 import com.sincere.haikangface.mqtt.MqtUtils;
15   -import com.sincere.haikangface.mqtt.MqttManager;
16 14 import com.sincere.haikangface.utils.*;
17 15 import com.sincere.haikangface.xiananDao.SendRecordDao;
18 16 import com.sun.jna.NativeLong;
... ... @@ -38,13 +36,8 @@ import java.io.*;
38 36 import java.net.InetAddress;
39 37 import java.net.UnknownHostException;
40 38 import java.nio.ByteBuffer;
41   -import java.text.DecimalFormat;
42   -import java.text.ParseException;
43 39 import java.text.SimpleDateFormat;
44   -import java.util.Date;
45   -import java.util.HashMap;
46   -import java.util.List;
47   -import java.util.Map;
  40 +import java.util.*;
48 41 import java.util.regex.Pattern;
49 42  
50 43 @Component
... ... @@ -318,23 +311,19 @@ public class CMSServer implements ApplicationRunner {
318 311 public class PSS_Storage_Callback implements HCEHomeSS.EHomeSSStorageCallBack {
319 312  
320 313 public boolean invoke(NativeLong iHandle, String pFileName, Pointer pFileBuf, int dwFileLen, Pointer pFilePath, Pointer pUser) {
321   -// log.error("图片进来:{}", pFileName);
322 314 String strPath = "C://EhomePicServer/";
323   -// System.out.println("pFileName:" + pFileName);
324 315 FileUtils.getInstance().writeLogs("文件名:" + pFileName, FileUtils.fileName);
  316 +
  317 + String isQJFileName = pFileName;//用来判断是否是枪机
  318 +
325 319 pFileName = pFileName.replace("_", "");
326   - boolean isZhuaPai = false;
327   - if (pFileName.contains("-")) {//人脸抓拍机抓拍到的图片
328   - if (!ip.contains("172.16"))
329   - strPath = "E://wwwhtdocs//SmartCampus//face17e5//School16//Student//";//测试服务器
330   - pFileName = pFileName.split("T")[0] + ".jpg";
331   - isZhuaPai = true;
332   - }
  320 +
  321 + if (pFileName.contains("T"))pFileName=pFileName.split("T")[0]+".jpg";
  322 +
  323 + FileUtils.getInstance().writeLogs("文件名pFileName:" + pFileName, FileUtils.fileName);
333 324  
334 325 String strFilePath = strPath + pFileName;
335 326 //保存抓拍到的人脸图片,比对通过后的图片资源
336   -
337   -// System.out.println("文件保存回调函数:" + strFilePath);
338 327 //若此目录不存在,则创建之
339 328 File myPath = new File(strPath);
340 329 if (!myPath.exists()) {
... ... @@ -363,9 +352,16 @@ public class CMSServer implements ApplicationRunner {
363 352 buffers.get(bytes);
364 353 fout.write(bytes);
365 354 fout.close();
  355 + if (isQJFileName.contains("T")) {//人脸抓拍机抓拍到的图片
  356 + String deviceId = "";
  357 + int start = isQJFileName.indexOf("01_") + 3;
  358 + int end = isQJFileName.lastIndexOf("_01");
  359 + if (start < end) {
  360 + deviceId = isQJFileName.substring(start, end);
  361 + }
  362 + sendToKB(strFilePathFile, deviceId);
  363 + }
366 364  
367   -// if (ip_cloud.equals(ip_cloudQJ))
368   - sendToKB(strFilePathFile);
369 365  
370 366 } catch (FileNotFoundException e) {
371 367 // TODO Auto-generated catch block
... ... @@ -378,9 +374,9 @@ public class CMSServer implements ApplicationRunner {
378 374  
379 375 pFilePath.write(0, strFilePath.getBytes(), 0, strFilePath.getBytes().length);
380 376  
381   - if (isZhuaPai) {
  377 +// if (isZhuaPai) {
382 378 // MqtUtils.getInstance().sendMsg("http://campus.myjxt.com//face17e5/School16/Student/" + pFileName);
383   - }
  379 +// }
384 380  
385 381 return true;
386 382 }
... ... @@ -393,11 +389,13 @@ public class CMSServer implements ApplicationRunner {
393 389 *
394 390 * @param strFilePathFile
395 391 */
396   - public void sendToKB(File strFilePathFile) {
  392 + public void sendToKB(File strFilePathFile, String deviceId) {
397 393 try {
398 394  
  395 + String schoolId = userDao.getSchoolIdWithDevId(deviceId);
  396 +
399 397 log.error("开始识别.....");
400   - String url = "http://120.26.116.253:9214/baiduapi/search/16";
  398 + String url = "http://120.26.116.253:9214/baiduapi/search/" + schoolId;
401 399  
402 400 RestTemplate restTemplate = new RestTemplate();
403 401  
... ... @@ -415,7 +413,7 @@ public class CMSServer implements ApplicationRunner {
415 413 JSONObject jsonObject = JSON.parseObject(responseEntity.getBody());
416 414  
417 415 String face = jsonObject.getString("data");
418   - if (face.startsWith("face")||face.startsWith("pic")) return;
  416 + if (face.startsWith("face") || face.startsWith("pic")) return;
419 417  
420 418 JSONObject data = jsonObject.getJSONObject("data");
421 419 String error_msg = data.getString("error_msg");
... ... @@ -441,11 +439,11 @@ public class CMSServer implements ApplicationRunner {
441 439 String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
442 440 BaiduFaceRecorder baiduFaceRecorder = new BaiduFaceRecorder();
443 441 baiduFaceRecorder.setName(teacherBean.getName());
444   - baiduFaceRecorder.setScore(sc+"");
  442 + baiduFaceRecorder.setScore(sc + "");
445 443 baiduFaceRecorder.setTime(time);
446 444 baiduFaceRecorder.setUserImgUrl(teacherBean.getFace());
447   - baiduFaceRecorder.setUploadImgUrl(strFilePathFile.getAbsolutePath().contains(date)?
448   - "http://" + ip_cloud + ":8081/kms/services/rest/dataInfoService/downloadFile?id="+strFilePathFile.getName().substring(0,strFilePathFile.getName().indexOf(date)):strFilePathFile.getAbsolutePath());
  445 + baiduFaceRecorder.setUploadImgUrl(strFilePathFile.getAbsolutePath().contains(date) ?
  446 + "http://" + ip_cloud + ":8081/kms/services/rest/dataInfoService/downloadFile?id=" + strFilePathFile.getName().substring(0, strFilePathFile.getName().indexOf(date)) : strFilePathFile.getAbsolutePath());
449 447 baiduFaceRecorder.setUserId(user_id);
450 448 userDao.insertBaiduFaceRecorder(baiduFaceRecorder);
451 449  
... ... @@ -455,26 +453,26 @@ public class CMSServer implements ApplicationRunner {
455 453 if (userMap.containsKey(user_id)) {
456 454  
457 455 long value = userMap.get(user_id);
458   - if ((System.currentTimeMillis() - value) / 1000 > 6) {
  456 + if ((System.currentTimeMillis() - value) / 1000 > 60) {
459 457 userMap.put(user_id, System.currentTimeMillis());
460   - MqtUtils.getInstance().sendMsg("09EA8EB5142F2964", 1, teacherBean.toString());
  458 + send2DeviceIds(schoolId, teacherBean);
461 459 log.error("发送成功.....");
462 460 }
463 461  
464 462 } else {
465 463 userMap.put(user_id, System.currentTimeMillis());
466   - MqtUtils.getInstance().sendMsg("09EA8EB5142F2964", 1, teacherBean.toString());
  464 + send2DeviceIds(schoolId, teacherBean);
467 465 log.error("发送成功.....");
468 466 }
469 467  
470 468 // strFilePathFile.deleteOnExit();
471 469 } else {
472 470 System.out.println("用户身份信息不存在");
473   - sendNoPersonImg(strFilePathFile);
  471 + sendNoPersonImg(strFilePathFile,schoolId);
474 472 }
475 473 } else {
476 474 System.out.println("用户身份信息不存在" + score);
477   - sendNoPersonImg(strFilePathFile);
  475 + sendNoPersonImg(strFilePathFile,schoolId);
478 476 }
479 477  
480 478 }
... ... @@ -490,12 +488,29 @@ public class CMSServer implements ApplicationRunner {
490 488  
491 489 }
492 490  
493   - private void sendNoPersonImg(File strFilePathFile) {
  491 + private void send2DeviceIds(String schoolId, TeacherBean teacherBean) {
  492 +
  493 + List<String> deviceIds = userDao.getKBDevices(schoolId);
  494 + if (deviceIds != null)
  495 + for (int i = 0; i < deviceIds.size(); i++) {
  496 + String deviceId = deviceIds.get(i);
  497 + if (!StringUtils.isEmpty(deviceId))
  498 + MqtUtils.getInstance().sendMsg(deviceId, 1, teacherBean.toString());
  499 + }
  500 +
  501 + }
  502 +
  503 + private void sendNoPersonImg(File strFilePathFile, String schoolId) {
  504 + List<String> deviceIds = userDao.getKBDevices(schoolId);
494 505 String imgName = strFilePathFile.getName();
495 506 String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
496 507 if (imgName.contains(date)) {
497 508 String imgId = imgName.substring(0, imgName.indexOf(date));
498   - MqtUtils.getInstance().sendMsg("09EA8EB5142F2964", 2, "http://" + ip_cloud + ":8081/kms/services/rest/dataInfoService/downloadFile?id=" + imgId);
  509 + for (int i = 0; i < deviceIds.size(); i++) {
  510 + String deviceId = deviceIds.get(i);
  511 + if (!StringUtils.isEmpty(deviceId))
  512 + MqtUtils.getInstance().sendMsg(deviceId, 2, "http://" + ip_cloud + ":8081/kms/services/rest/dataInfoService/downloadFile?id=" + imgId);
  513 + }
499 514 }
500 515 }
501 516  
... ... @@ -568,7 +583,7 @@ public class CMSServer implements ApplicationRunner {
568 583 // System.out.println(strXML);
569 584 // log.error("报警监听:{}", strXML);
570 585 if (null == alarmUtils) {
571   - alarmUtils = new AlarmUtils(deviceDao,userDao);
  586 + alarmUtils = new AlarmUtils(deviceDao, userDao);
572 587 alarmUtils.setCallBack(new AlarmUtils.AlarmCallBack() {
573 588 @Override
574 589 public void callBack(String minorType, String deviceID, String cardNo, String time, String picDataUrlId, String currTemperature) {
... ... @@ -578,7 +593,6 @@ public class CMSServer implements ApplicationRunner {
578 593 saveFaceRecoder(deviceID, cardNo, time, picDataUrlId, currTemperature);
579 594 break;
580 595 case "0x426"://人证设备在线
581   -
582 596 break;
583 597 case "0x427"://人证设备离线
584 598 map.remove(deviceID);
... ... @@ -639,10 +653,10 @@ public class CMSServer implements ApplicationRunner {
639 653 if (!TextUtils.isEmpty(currTemperature)) {//只有有温度的才存记录
640 654 userDao.addWGTem(studentBean.getUser_id(), studentBean.getStudent_id(), studentBean.getName(), studentBean.getClass_id() + "",
641 655 studentBean.getClass_name(), currTemperature, studentBean.getStudent_type() + "", studentBean.getSchool_id() + "", time);
642   -
643   - sendRecordDao.addFaceRecoder(face_recoder.getDeviceId(), face_recoder.getUser_id(), face_recoder.getName(),
644   - face_recoder.getImgurl(), face_recoder.getInOrOut(), face_recoder.getTime(), face_recoder.getCardNum(), currTemperature);
645 656 }
  657 + //记录签到成功的流水
  658 + sendRecordDao.addFaceRecoder(face_recoder.getDeviceId(), face_recoder.getUser_id(), face_recoder.getName(),
  659 + face_recoder.getImgurl(), face_recoder.getInOrOut(), face_recoder.getTime(), face_recoder.getCardNum(), currTemperature);
646 660 } else {
647 661 //教师点名
648 662 isTeacher(cardNo, deviceID);
... ... @@ -673,7 +687,7 @@ public class CMSServer implements ApplicationRunner {
673 687 public void isTeacher(String cardNo, String deviceID) {
674 688  
675 689 List<String> devLists = userDao.getDeviceRoomRelation(deviceID);
676   - log.error("cardNo:{},devLists{}", cardNo, devLists);
  690 +// log.error("cardNo:{},devLists{}", cardNo, devLists);
677 691  
678 692 if (null != devLists && devLists.size() > 0) {
679 693  
... ... @@ -813,7 +827,7 @@ public class CMSServer implements ApplicationRunner {
813 827 "</CardCfg>\r\n" +
814 828 "</ConfigXML>\r\n" +
815 829 "</Params>";
816   - System.out.println("strConfigXMLCard:" + strConfigXMLCard + name + nameAfter);
  830 +// System.out.println("strConfigXMLCard:" + strConfigXMLCard + name + nameAfter);
817 831 byte[] nameBeforBy = null;
818 832 byte[] resultBy = null;
819 833 try {
... ... @@ -861,10 +875,10 @@ public class CMSServer implements ApplicationRunner {
861 875 int iErr = hCEhomeCMS.NET_ECMS_GetLastError();
862 876 if (validTimeEnabled == 0) System.err.println("删除卡号失败,错误号:" + iErr + "card:" + card);
863 877 else System.err.println("下发卡号失败,错误号:" + iErr + "card:" + card);
864   - if (iErr == 10) map.remove(deviceId);
  878 +// if (iErr == 10) map.remove(deviceId);
865 879 } else {
866 880 if (validTimeEnabled == 0) System.out.println("删除卡号成功");
867   - else System.out.println("下发卡号成功");
  881 + else System.out.println("下发卡号成功:"+name);
868 882 }
869 883  
870 884 }
... ... @@ -1015,7 +1029,7 @@ public class CMSServer implements ApplicationRunner {
1015 1029 } else {
1016 1030 stringXMLOut.read();
1017 1031 String strOutXML = new String(stringXMLOut.byString).trim();
1018   - System.out.println(content + "成功:" + strOutXML);
  1032 + System.out.println(content + "成功:" + card);
1019 1033 }
1020 1034 }
1021 1035 return false;
... ...
cloud/haikangface/src/main/java/com/sincere/haikangface/Test.java 0 → 100644
... ... @@ -0,0 +1,48 @@
  1 +package com.sincere.haikangface;
  2 +
  3 +import java.io.File;
  4 +import java.io.IOException;
  5 +
  6 +public class Test {
  7 +
  8 + public static void main(String[] args){
  9 + String strPath = "C://EhomePicServer/";
  10 + String img = "5EA6FC3BC6C6285812F92A68CB43F4F52020-09-27T16:01:59A08:00_01_qj111111_01.jpg";
  11 + String isQJFileName = img;//用来判断是否是枪机
  12 +
  13 + img = img.split("T")[0];
  14 +// img = img.substring(img.indexOf("01_")+3,img.lastIndexOf("_01"));
  15 + String strFilePath = strPath + img;
  16 + //保存抓拍到的人脸图片,比对通过后的图片资源
  17 + //若此目录不存在,则创建之
  18 + File myPath = new File(strPath);
  19 + if (!myPath.exists()) {
  20 + myPath.mkdir();
  21 + System.out.println("创建文件夹路径为:" + strPath);
  22 + }
  23 +
  24 + File strFilePathFile = new File(strFilePath);
  25 + System.out.println("strFilePath:" + strFilePath);
  26 + if (!strFilePathFile.exists()) {
  27 + try {
  28 + strFilePathFile.createNewFile();
  29 + } catch (IOException e) {
  30 + e.printStackTrace();
  31 + }
  32 + }
  33 +
  34 + if (img.contains("T")) {//人脸抓拍机抓拍到的图片
  35 + String deviceId = "";
  36 + int start = img.indexOf("01_") + 3;
  37 + int end = img.lastIndexOf("_01");
  38 + if (start < end) {
  39 + deviceId = img.substring(start, end);
  40 + }
  41 + System.out.println("deviceId:"+deviceId+"isQJFileName:"+isQJFileName.replace("_",""));
  42 + }
  43 +
  44 +
  45 +
  46 + }
  47 +
  48 +}
... ...
cloud/haikangface/src/main/java/com/sincere/haikangface/control/FileControl.java
... ... @@ -83,15 +83,15 @@ public class FileControl {
83 83 long time = System.currentTimeMillis();
84 84 // if (filePath.contains(".jpg")) filePath = filePath.replace(".jpg", ".png");
85 85 if (new File(filePath.trim()).exists()) {
86   - String targetPath = FileUtils.picPathComp + new File(filePath).getName().replace(".png", ".jpg");
  86 + String targetPath = FileUtils.picPathComp + new File(filePath).getName();
87 87  
88 88 try {
89 89 CompressPic.CompressPic(filePath, targetPath);
90 90 } catch (Exception e) {
91 91 e.printStackTrace();
92 92 }
93   - File targetFile = new File(targetPath);
94   - System.out.println("targetPath:" + targetFile.exists() + targetFile.getAbsolutePath());
  93 +// File targetFile = new File(targetPath);
  94 +// System.out.println("targetPath:" + targetFile.exists() + targetFile.getAbsolutePath());
95 95 try {
96 96 int isPiliang = 0;//0:批量,1:单张
97 97 if (filePath.contains("face17e50")) {//批量发送
... ...
cloud/haikangface/src/main/java/com/sincere/haikangface/control/UserControl.java
... ... @@ -3,13 +3,10 @@ package com.sincere.haikangface.control;
3 3 //import com.sincere.common.dto.smartCampus.SZ_AttendanceDto;
4 4  
5 5 import com.alibaba.fastjson.JSON;
6   -import com.sincere.haikangface.bean.Images2Ddevices;
  6 +import com.sincere.haikangface.bean.*;
7 7 //import com.sincere.haikangface.utils.BaiduApiUtiols;
8 8 import com.sincere.haikangface.CMSServer;
9 9 import com.sincere.haikangface.async.SendUserAsync;
10   -import com.sincere.haikangface.bean.StudentBean;
11   -import com.sincere.haikangface.bean.StudentInfo;
12   -import com.sincere.haikangface.bean.TeacherBean;
13 10 import com.sincere.haikangface.bean.face.PermissionBean;
14 11 import com.sincere.haikangface.bean.face.UserAndPermission;
15 12 import com.sincere.haikangface.dao.UserDao;
... ... @@ -21,22 +18,17 @@ import io.swagger.annotations.ApiImplicitParam;
21 18 import io.swagger.annotations.ApiImplicitParams;
22 19 import io.swagger.annotations.ApiOperation;
23 20 import lombok.extern.slf4j.Slf4j;
24   -import org.apache.poi.util.StringUtil;
25 21 import org.slf4j.Logger;
26 22 import org.slf4j.LoggerFactory;
27 23 import org.springframework.beans.factory.annotation.Autowired;
28 24 import org.springframework.http.MediaType;
29 25 import org.springframework.util.StringUtils;
30 26 import org.springframework.web.bind.annotation.*;
31   -import org.springframework.web.client.RestTemplate;
32 27 import org.springframework.web.multipart.MultipartFile;
33 28  
34 29 import java.io.*;
35 30 import java.text.SimpleDateFormat;
36   -import java.util.ArrayList;
37   -import java.util.Calendar;
38   -import java.util.Date;
39   -import java.util.List;
  31 +import java.util.*;
40 32  
41 33 @RestController
42 34 @RequestMapping(value = "/facereco/*", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
... ... @@ -67,7 +59,7 @@ public class UserControl {
67 59 @ApiOperation("下发权限给设备")
68 60 public boolean sendPermiss(@RequestBody PermissionBean permissionBean) {
69 61 log.error("permissionBean:{}", JSON.toJSONString(permissionBean));
70   - FileUtils.getInstance().writeLogs("传入权限模板:"+JSON.toJSONString(permissionBean),"设置权限内容.txt");
  62 + FileUtils.getInstance().writeLogs("传入权限模板:" + JSON.toJSONString(permissionBean), "设置权限内容.txt");
71 63 if (!StringUtils.isEmpty(permissionBean.getDeviceIds())) {
72 64 // List<String> cardNumList = userDao.getStudentCardsWidthSchoolId(permissionBean.getSchoolId());
73 65 return sendUserAsync.sendPermiss(permissionBean, 0);
... ... @@ -100,9 +92,9 @@ public class UserControl {
100 92  
101 93 @RequestMapping(value = "sendToKB", method = RequestMethod.GET)
102 94 @ApiOperation("发送数据到看板")
103   - public void sendToKB(@RequestParam("filePath") String filePath) {
  95 + public void sendToKB(@RequestParam("filePath") String filePath, @RequestParam("deviceid") String deviceid) {
104 96 try {
105   - cmsServer.sendToKB(new File(filePath));
  97 + cmsServer.sendToKB(new File(filePath), deviceid);
106 98 } catch (Exception e) {
107 99 e.printStackTrace();
108 100 }
... ... @@ -313,6 +305,139 @@ public class UserControl {
313 305  
314 306 }
315 307  
  308 +
  309 + @RequestMapping(value = "sendErrorFaces", method = RequestMethod.GET)
  310 + @ApiOperation(value = "下发失败的人脸", notes = "下发失败的人脸")
  311 + @ApiImplicitParams({
  312 + @ApiImplicitParam(name = "deviceid", required = false),
  313 + @ApiImplicitParam(name = "userType", required = false),
  314 + @ApiImplicitParam(name = "schoolId", required = true)
  315 + })
  316 + public void sendErrorFaces(String schoolId, String deviceid, String userType) {
  317 +
  318 + System.out.println("schoolId:" + schoolId + "---deviceid:" + deviceid + "---userType:" + userType);
  319 + if (StringUtils.isEmpty(userType)) userType = "0";//不传的话就默认失败表中的类型
  320 + if (!StringUtils.isEmpty(deviceid)) {
  321 + sendFace(deviceid, Integer.parseInt(userType));
  322 + } else {
  323 + List<String> deviceIds = sendRecordDao.getDeviceIds(schoolId);
  324 +
  325 + if (null != deviceIds) {
  326 + for (int j = 0; j < deviceIds.size(); j++) {
  327 + String deviceId = deviceIds.get(j);
  328 + sendFace(deviceId, Integer.parseInt(userType));
  329 + }
  330 + }
  331 + }
  332 +
  333 +
  334 + }
  335 +
  336 +
  337 + private void sendFace(String deviceId, int userType) {
  338 +
  339 + List<SendRecordBean> sendRecordBeans = sendRecordDao.getSendFailWithDevId(deviceId);
  340 + if (null != sendRecordBeans) {
  341 +
  342 + for (int i = 0; i < sendRecordBeans.size(); i++) {
  343 +
  344 + SendRecordBean sendRecordBean = sendRecordBeans.get(i);
  345 + String typeName = "";
  346 + if (userType == 0) {
  347 + typeName = sendRecordBean.getUserType() == 1 ? "Teacher" : "Student";
  348 + } else {
  349 + typeName = userType == 1 ? "Teacher" : "Student";
  350 + }
  351 + String studentCode = "";
  352 +
  353 + if (sendRecordBean.getUserType() == 1) {
  354 + studentCode = userDao.getTeaNumWithCard(sendRecordBean.getNum());
  355 + } else if (sendRecordBean.getUserType() == 2) {
  356 + studentCode = userDao.getStudentCode(sendRecordBean.getNum());
  357 + }
  358 +
  359 + String imgPath = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + sendRecordBean.getSchoolId() + "\\" + typeName + "\\" + studentCode + ".png";
  360 + File imgFile = new File(imgPath);
  361 + if (imgFile.exists()) {
  362 + String targetPath = FileUtils.picPathComp + imgFile.getName();
  363 + try {
  364 + CompressPic.CompressPic(imgFile.getAbsolutePath(), targetPath);
  365 + } catch (Exception e) {
  366 + e.printStackTrace();
  367 + }
  368 + sendImg(imgPath, targetPath, sendRecordBean.getDeviceID(), sendRecordBean.getNum(), sendRecordBean.getName(), sendRecordBean.getUserType() + "");
  369 + } else {
  370 + System.out.println("文件不存在");
  371 + }
  372 + }
  373 +
  374 + }
  375 +
  376 + }
  377 +
  378 +
  379 + @RequestMapping(value = "sendFaceNotExits", method = RequestMethod.GET)
  380 + @ApiOperation(value = "下发学校下还没有下发的人脸给指定设备", notes = "下发学校下还没有下发的人脸给指定设备")
  381 + public void sendFaceNotExits(@RequestParam("deviceIds") String deviceIds, @RequestParam("schoolId") String schoolId, @RequestParam("userType") String userType) {
  382 +
  383 + String typeName = userType.equals("1") ? "Teacher" : "Student";
  384 +
  385 + String imgPath = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\" + typeName;
  386 +
  387 + File imgPathFile = new File(imgPath);//目录
  388 +
  389 + String[] deviceIdsStr = deviceIds.split(",");
  390 +
  391 +
  392 + if (imgPathFile.exists()) {
  393 + File[] imgfiles = imgPathFile.listFiles();
  394 + if (null != imgfiles) {
  395 +
  396 + for (int i = 0; i < imgfiles.length; i++) {
  397 + File file = imgfiles[i];//图片
  398 + String targetPath = FileUtils.picPathComp + file.getName();
  399 + try {
  400 + CompressPic.CompressPic(file.getAbsolutePath(), targetPath);
  401 + } catch (Exception e) {
  402 + e.printStackTrace();
  403 + }
  404 + if (file.exists())
  405 + for (int j = 0; j < deviceIdsStr.length; j++) {
  406 + String deviceId = deviceIdsStr[j];
  407 +
  408 + StudentBean studentBean = null;
  409 + String card = "", name = "";
  410 + if (userType.equals("1")) {
  411 + studentBean = userDao.getTeacherWithstudentcode(file.getName().split("\\.")[0], schoolId);
  412 + if (null != studentBean) {
  413 + card = studentBean.getTeacher_num();
  414 + name = studentBean.getName();
  415 + }
  416 + } else if (userType.equals("2")) {
  417 + studentBean = userDao.getStudentWithstudentcode(file.getName().split("\\.")[0], schoolId);
  418 + if (null != studentBean) {
  419 + card = studentBean.getStudent_num();
  420 + name = studentBean.getName();
  421 + }
  422 + }
  423 +
  424 + if (!StringUtils.isEmpty(card)) {
  425 + List<SendRecordBean> sendRecordBeans = sendRecordDao.getFaceSendSucess(card, deviceId);
  426 + if (sendRecordBeans == null || sendRecordBeans.size() == 0)
  427 + sendImg(file.getAbsolutePath(), targetPath, deviceId, card, name, userType);
  428 + else System.out.println("人脸已经下发");
  429 + }
  430 +
  431 + }
  432 +
  433 + }
  434 +
  435 + }
  436 + }
  437 +
  438 + }
  439 +
  440 +
316 441 @RequestMapping(value = "sendFaceToDevices", method = RequestMethod.GET)
317 442 @ApiOperation(value = "下发单个用户给指定设备", notes = "下发单个用户给指定设备")
318 443 @ApiImplicitParams({@ApiImplicitParam(name = "deviceIds", value = "设备id用逗号,拼接"),
... ...
cloud/haikangface/src/main/java/com/sincere/haikangface/dao/UserDao.java
... ... @@ -216,7 +216,7 @@ public interface UserDao {
216 216 "where num = #{num} and school_id = #{schoolId}")
217 217 StudentBean getTeacherWithstudentcode(@Param("num") String num, @Param("schoolId") String schoolId);
218 218  
219   - @Select("select school_id from SZ_Attendance where clint_id = #{devId}")
  219 + @Select("select top(1) school_id from SZ_Attendance where clint_id = #{devId}")
220 220 String getSchoolIdWithDevId(@Param("devId") String devId);
221 221  
222 222 @Insert("insert into CW_StuTemperatureReocrd values (#{UserId},#{StudentId},#{Name},#{ClassId},#{ClassName},#{Temperature},#{Type},#{SchoolId},#{Intime})")
... ... @@ -236,6 +236,9 @@ public interface UserDao {
236 236 @Select("select student_num from SZ_V_School_Student where user_id = #{userId}")
237 237 String getStudentCardWithUserId(@Param("userId") String userId);
238 238  
  239 + @Select("select Top(1) studentcode from SZ_V_School_Student where student_num = #{num}")
  240 + String getStudentCode(@Param("num") String num);
  241 +
239 242 @Select("select Top(1) * from SZ_V_School_Teacher where user_id = #{userId} and teacher_num<>''")
240 243 TeacherBean getTeacherWithUserId(@Param("userId") String userId);
241 244  
... ... @@ -250,4 +253,9 @@ public interface UserDao {
250 253  
251 254 void insertBaiduFaceRecorder(BaiduFaceRecorder baiduFaceRecorder);
252 255  
  256 + @Select("select top(1) num from SZ_V_School_Teacher where teacher_num=#{num}")
  257 + String getTeaNumWithCard(@Param("num") String num);
  258 +
  259 + @Select("select clint_id from SZ_Attendance where clint_type in(8,9,10) and school_id = #{schoolId}")
  260 + List<String> getKBDevices(@Param("schoolId") String schoolId);
253 261 }
... ...
cloud/haikangface/src/main/java/com/sincere/haikangface/utils/AlarmUtils.java
... ... @@ -46,19 +46,19 @@ public class AlarmUtils {
46 46 }
47 47  
48 48 public void deleAlarm(String strXML) {
49   - System.out.println("人脸抓拍机:" + strXML);
  49 +// System.out.println("人脸抓拍机:" + strXML);
50 50 if (strXML.contains("FACESNAPREPORT")) {//人脸抓拍机器
51 51  
52 52 // System.out.println("人脸抓拍机:" + strXML);
53 53 BaiduFaceRecorder baiduFaceRecorder = new BaiduFaceRecorder();
54 54 baiduFaceRecorder.setUploadImgUrl(strXML);
55 55 baiduFaceRecorder.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
56   - userDao.insertBaiduFaceRecorder(baiduFaceRecorder);
57 56  
58 57 String deviceId = strXML.substring(strXML.indexOf("DeviceID"),strXML.lastIndexOf("DeviceID")).trim();
59 58 deviceId = deviceId.replace("DeviceID>","");
60 59 deviceId = deviceId.replace("</","");
61 60  
  61 + userDao.insertBaiduFaceRecorder(baiduFaceRecorder);
62 62 // if (null != alarmCallBack)
63 63 // alarmCallBack.callBack(minorType, deviceID, cardNo, time, picDataUrlId, currTemperature);
64 64  
... ... @@ -245,9 +245,11 @@ public class AlarmUtils {
245 245 switch (minorType) {
246 246 case "0x3a"://网络断开
247 247 content = "网络断开";
  248 + FileUtils.getInstance().writeLogs("网络断开:"+deviceID,"设备网络.txt");
248 249 break;
249 250 case "0x400"://设备上电启动
250 251 content = "设备上电启动";
  252 + FileUtils.getInstance().writeLogs("设备上电启动:"+deviceID,"设备网络.txt");
251 253 break;
252 254 case "0x401"://设备掉电关闭
253 255 content = "设备掉电关闭";
... ... @@ -266,6 +268,8 @@ public class AlarmUtils {
266 268 break;
267 269 case "0x407"://网络恢复
268 270 content = "网络恢复";
  271 + if (null != alarmCallBack) alarmCallBack.callBack(minorType, deviceID, "", time, "", "");
  272 + FileUtils.getInstance().writeLogs("网络恢复:"+deviceID,"设备网络.txt");
269 273 break;
270 274 case "0x421"://摄像头未连接
271 275 content = "摄像头未连接";
... ... @@ -274,12 +278,14 @@ public class AlarmUtils {
274 278 content = "摄像头连接恢复";
275 279 break;
276 280 case "0x426"://人证设备在线
  281 + FileUtils.getInstance().writeLogs("人证设备在线:"+deviceID,"设备网络.txt");
277 282 content = "人证设备在线";
278 283 if (null != alarmCallBack) alarmCallBack.callBack(minorType, deviceID, "", time, "", "");
279 284 break;
280 285 case "0x427"://人证设备离线
281 286 content = "人证设备离线";
282 287 if (null != alarmCallBack) alarmCallBack.callBack(minorType, deviceID, "", time, "", "");
  288 + FileUtils.getInstance().writeLogs("人证设备离线:"+deviceID,"设备网络.txt");
283 289 break;
284 290 }
285 291 saveWater(content, minorType, deviceID, "", time, "0x02");
... ...
cloud/haikangface/src/main/java/com/sincere/haikangface/xiananDao/SendRecordDao.java
... ... @@ -115,7 +115,12 @@ public interface SendRecordDao {
115 115 void deleteARecords(@Param("customerId") String customerId, @Param("systime") String systime);
116 116  
117 117  
118   - @Select("select * from Face_SendSuccess where schoolId = 4 and time < '2020-05-06'")
119   - List<SendRecordBean> getFaceSendSucess();
  118 + @Select("select * from Face_SendSuccess where Num = #{Num} and deviceID = #{deviceID}")
  119 + List<SendRecordBean> getFaceSendSucess(@Param("Num")String Num,@Param("deviceID")String deviceID);
120 120  
  121 + @Select("select * from Face_SendFail where deviceID = #{deviceID}")
  122 + List<SendRecordBean> getSendFailWithDevId(@Param("deviceID") String deviceId);
  123 +
  124 + @Select("select DISTINCT deviceID from Face_SendFail where schoolId = #{schoolId} ")
  125 + List<String> getDeviceIds(@Param("schoolId") String schoolId);
121 126 }
... ...
cloud/mypulsar/src/main/java/com/example/mypulsar/MyRunnerableInt.java
... ... @@ -40,7 +40,7 @@ public class MyRunnerableInt implements ApplicationRunner {
40 40  
41 41 @Override
42 42 public void run(ApplicationArguments args) throws Exception {
43   -// initMqConsumer();
  43 + initMqConsumer();
44 44 }
45 45  
46 46 /**
... ...
cloud/mypulsar/src/test/java/com/example/mypulsar/MypulsarApplicationTests.java
... ... @@ -85,7 +85,7 @@ public class MypulsarApplicationTests {
85 85  
86 86 }
87 87  
88   - private String closeModel = "{\"mode\":\"0\",\"power\":\"0\",\"remote_id\":\"%s\",\"remote_index\":\"11272\",\"temp\":\"26\",\"wind\":\"0\"}";
  88 + private String closeModel = "{\"mode\":\"0\",\"power\":\"1\",\"remote_id\":\"%s\",\"remote_index\":\"11272\",\"temp\":\"26\",\"wind\":\"0\"}";
89 89  
90 90  
91 91 private void closeAllDevice() {
... ... @@ -96,11 +96,9 @@ public class MypulsarApplicationTests {
96 96 String deviceId = deviceIds.get(i).getClint_id();
97 97 String conValue = getRemoteId(deviceDao.getConBeValue(deviceId));
98 98 String devName = deviceIds.get(i).getName();
99   -// System.out.println("closeModel:" + closeModel);
100 99 String con = String.format(closeModel, conValue);
101   -// System.out.println("con:" + con);
102   -
103   - HttpUtil.addAirCode(con, deviceId, devName);
  100 +// if (deviceId.equals("22000203ecfabcace679"))
  101 + HttpUtil.addAirCode(con, deviceId, devName);
104 102 }
105 103  
106 104  
... ...
cloud/pom.xml
... ... @@ -41,7 +41,7 @@
41 41 <!-- <module>weigeng</module>-->
42 42 <!-- <module>independence</module>-->
43 43 <module>quartz</module>
44   - <!-- <module>zkAttendance</module>-->
  44 + <module>zkAttendance</module>
45 45 <module>user_search</module>
46 46 <module>fIle-center</module>
47 47 <module>RibbonConsume</module>
... ...
cloud/quartz/src/main/java/com/sincere/quartz/job/SyncJob.java
1   -//package com.sincere.quartz.job;
2   -//
3   -//import com.sincere.quartz.third.yixueyun.YXYReadService;
4   -//import com.sincere.quartz.third.yixueyun.YXYWriteService;
5   -//import org.springframework.beans.factory.annotation.Autowired;
6   -//import org.springframework.scheduling.annotation.Scheduled;
7   -//import org.springframework.stereotype.Service;
8   -//
9   -///**
10   -// * @author chen
11   -// * @version 1.0
12   -// * @date 2019/12/24 0024 10:54
13   -// */
14   -//@Service
15   -//public class SyncJob {
16   -//
17   -// @Autowired
18   -// YXYWriteService yxyWriteService ;
19   -//
20   -// @Autowired
21   -// YXYReadService yxyReadService ;
22   -//
23   -// @Scheduled(cron = "30 1 22 * * ? ")
24   -// public void Sync(){
25   -// //翼校通的同步 之后还有钉钉的同步等等
26   -// yxyReadService.sync();
27   -// yxyWriteService.sync();
28   -// }
29   -//}
  1 +package com.sincere.quartz.job;
  2 +
  3 +import com.sincere.quartz.third.yixueyun.YXYReadService;
  4 +import com.sincere.quartz.third.yixueyun.YXYWriteService;
  5 +import org.springframework.beans.factory.annotation.Autowired;
  6 +import org.springframework.scheduling.annotation.Scheduled;
  7 +import org.springframework.stereotype.Service;
  8 +
  9 +/**
  10 + * @author chen
  11 + * @version 1.0
  12 + * @date 2019/12/24 0024 10:54
  13 + */
  14 +@Service
  15 +public class SyncJob {
  16 +
  17 + @Autowired
  18 + YXYWriteService yxyWriteService ;
  19 +
  20 + @Autowired
  21 + YXYReadService yxyReadService ;
  22 +
  23 + @Scheduled(cron = "30 1 22 * * ? ")
  24 + public void Sync(){
  25 + //翼校通的同步 之后还有钉钉的同步等等
  26 + yxyReadService.sync();
  27 + yxyWriteService.sync();
  28 + }
  29 +}
... ...
cloud/zkAttendance/pom.xml
... ... @@ -37,6 +37,14 @@
37 37 <artifactId>commons-lang3</artifactId>
38 38 <version>3.3.2</version>
39 39 </dependency>
  40 + <dependency>
  41 + <groupId>org.springframework.boot</groupId>
  42 + <artifactId>spring-boot-starter-web</artifactId>
  43 + </dependency>
  44 +<!-- <dependency>-->
  45 +<!-- <groupId>org.apache.tomcat.embed</groupId>-->
  46 +<!-- <artifactId>tomcat-embed-core</artifactId>-->
  47 +<!-- </dependency>-->
40 48 </dependencies>
41 49  
42 50 <dependencyManagement>
... ... @@ -75,7 +83,7 @@
75 83 <configuration>
76 84 <archive>
77 85 <manifest>
78   - <mainClass>com.sincere.quartz.QuartzApplication</mainClass>
  86 + <mainClass>com.sincere.att.AttApplication</mainClass>
79 87 <addClasspath>true</addClasspath>
80 88 <classpathPrefix>lib/</classpathPrefix>
81 89 </manifest>
... ...
cloud/zkAttendance/src/main/java/com/sincere/att/AttApplication.java
... ... @@ -4,6 +4,7 @@ import org.springframework.boot.SpringApplication;
4 4 import org.springframework.boot.autoconfigure.SpringBootApplication;
5 5 import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
6 6 import org.springframework.cloud.openfeign.EnableFeignClients;
  7 +import org.springframework.context.annotation.Configuration;
7 8  
8 9 /**
9 10 * @author chen
... ... @@ -13,6 +14,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
13 14 @EnableFeignClients(basePackages = "com.sincere.att.feign")
14 15 @EnableEurekaClient
15 16 @SpringBootApplication
  17 +@Configuration
16 18 public class AttApplication {
17 19  
18 20 // public static void main(String[] args) {
... ...
cloud/zkAttendance/src/main/java/com/sincere/att/Swagger2.java
1 1 package com.sincere.att;
2 2  
3   -import io.swagger.annotations.ApiOperation;
4 3 import org.springframework.context.annotation.Bean;
5 4 import org.springframework.context.annotation.Configuration;
6 5 import springfox.documentation.builders.ApiInfoBuilder;
... ...
cloud/zkAttendance/src/main/java/com/sincere/att/controller/AttPushController.java
... ... @@ -40,80 +40,86 @@ public class AttPushController {
40 40 private static final Logger Log_kaoInfo = LoggerUtils.Logger(LogName.kaoInfo);
41 41  
42 42 private static Map<String, List<String>> cmdMap = new HashMap<>();
43   - private static Map<String , Integer> cmdOrderMap = new HashMap<>();
  43 + private static Map<String, Integer> cmdOrderMap = new HashMap<>();
44 44  
45   - private static String pwd = "22222222-6faf-48uh-a5a9-447ec68bfe2f" ;
46   - private static String account = "yueqingzhijiao" ;
  45 + private static String pwd = "22222222-6faf-48uh-a5a9-447ec68bfe2f";
  46 + private static String account = "yueqingzhijiao";
47 47  
48 48  
49 49 @Autowired
50 50 ScFeign scFeign;
51 51  
52 52 @Autowired
53   - XaFeign xaFeign ;
  53 + XaFeign xaFeign;
54 54  
55   - @RequestMapping(value = "sendUser" , method = RequestMethod.GET)
56   - public void sendUser(int roomId){
  55 + @RequestMapping(value = "sendUser", method = RequestMethod.GET)
  56 + public void sendUser(int roomId) {
57 57 JSONObject object = new JSONObject();
58   - object.put("pageIndex",1);
59   - object.put("roomId",roomId);
60   - object.put("pageSize",9999);
61   - JSONObject result = HttpClientUtils.httpPostJson("http://campus.myjxt.com/api/Room/GetListPageRoom",object.toJSONString());
62   - JSONArray array = (JSONArray) ((JSONObject) result.get("data")).get("roomList") ;
63   - List<String> order = new ArrayList<>();
  58 + object.put("pageIndex", 1);
  59 + object.put("roomId", roomId);
  60 + object.put("pageSize", 9999);
  61 + JSONObject result = HttpClientUtils.httpPostJson("http://campus.myjxt.com/api/Room/GetListPageRoom", object.toJSONString());
  62 + JSONArray array = (JSONArray) ((JSONObject) result.get("data")).get("roomList");
64 63 List<String> attendanceList = scFeign.selectRoomAttendance(roomId);
65   - for(String attendance : attendanceList){
66   - for(int i = 0 ; i < array.size() ; i++){
  64 + System.out.println("设备数量:" + JSONObject.toJSONString(attendanceList));
  65 + for (String attendance : attendanceList) {
  66 + List<String> order = new ArrayList<>();
  67 + for (int i = 0; i < array.size(); i++) {
67 68 JSONObject student = (JSONObject) array.get(i);
68 69 UserOrderVo vo = new UserOrderVo();
69 70 vo.setStudentId((Integer) student.get("studentid"));
70 71 vo.setStudentName((String) student.get("name"));
71   - int number = 1 ;
72   - try{
73   - number = cmdOrderMap.get(attendance) ;
74   - }catch (Exception e){
  72 + int number = 1;
  73 + try {
  74 + number = cmdOrderMap.get(attendance);
  75 + } catch (Exception e) {
75 76  
76 77 }
77 78 vo.setNumber(number);
78   - number++ ;
79   - cmdOrderMap.put(attendance,number) ;
80   - if(vo.getStudentId() != 0){
81   - order.add(vo.toString());
  79 + number++;
  80 + cmdOrderMap.put(attendance, number);
  81 + if (vo.getStudentId() != 0) {
  82 +// if (vo.getStudentId() == 72196){
  83 + //todo:测试专用
  84 + if (!order.contains(vo.toString())){
  85 + order.add(vo.toString());
  86 + }
  87 +// }
82 88 }
83 89 }
84   - cmdMap.put(attendance,order);
  90 + cmdMap.put(attendance, order);
85 91 }
86 92 }
87 93  
88   - @RequestMapping(value = "sendFinger" , method = RequestMethod.GET)
89   - public void sendFinger(int roomId){
  94 + @RequestMapping(value = "sendFinger", method = RequestMethod.GET)
  95 + public void sendFinger(int roomId) {
90 96 JSONObject object = new JSONObject();
91   - object.put("PageIndex",1);
92   - object.put("roomId",roomId);
93   - object.put("pageSize",9999);
94   - JSONObject result = HttpClientUtils.httpPostJson("http://campus.myjxt.com/api/Room/GetListPageRoom",object.toJSONString());
95   - JSONArray array = (JSONArray) ((JSONObject) result.get("data")).get("roomList") ;
96   - List<String> order = new ArrayList<>();
  97 + object.put("PageIndex", 1);
  98 + object.put("roomId", roomId);
  99 + object.put("pageSize", 9999);
  100 + JSONObject result = HttpClientUtils.httpPostJson("http://campus.myjxt.com/api/Room/GetListPageRoom", object.toJSONString());
  101 + JSONArray array = (JSONArray) ((JSONObject) result.get("data")).get("roomList");
97 102 List<String> attendanceList = scFeign.selectRoomAttendance(roomId);
98   - for(String attendance : attendanceList){
99   - for(int i = 0 ; i < array.size() ; i++){
  103 + for (String attendance : attendanceList) {
  104 + List<String> order = new ArrayList<>();
  105 + for (int i = 0; i < array.size(); i++) {
100 106 JSONObject student = (JSONObject) array.get(i);
101 107 FingerOrderVo vo = new FingerOrderVo();
102   - int number = 1 ;
103   - try{
104   - number = cmdOrderMap.get(attendance) ;
105   - }catch (Exception e){
  108 + int number = 1;
  109 + try {
  110 + number = cmdOrderMap.get(attendance);
  111 + } catch (Exception e) {
106 112  
107 113 }
108 114 vo.setNumber(number);
109   - vo.setOrder(xaFeign.selectFinger((Integer)student.get("studentid")));
110   - number++ ;
111   - cmdOrderMap.put(attendance,number) ;
112   - if(StringUtils.isNotBlank(vo.getOrder())){
  115 + vo.setOrder(xaFeign.selectFinger((Integer) student.get("studentid")));
  116 + number++;
  117 + cmdOrderMap.put(attendance, number);
  118 + if (StringUtils.isNotBlank(vo.getOrder())) {
113 119 order.add(vo.toString());
114 120 }
115 121 }
116   - cmdMap.put(attendance,order);
  122 + cmdMap.put(attendance, order);
117 123 }
118 124 }
119 125  
... ... @@ -121,29 +127,29 @@ public class AttPushController {
121 127 * 1,设备通完电以后第一个发送到后台的请求
122 128 * 格式为 /iclock/cdata?options=all&language=xxxx&pushver=xxxx
123 129 */
124   - @RequestMapping(value="/cdata",params = {"options","language","pushver"},method = RequestMethod.GET)
125   - public void init(String SN, String options, String language, String pushver, HttpServletRequest request ,
126   - @RequestParam(required = false) String PushOptionsFlag, HttpServletResponse response){
  130 + @RequestMapping(value = "/cdata", params = {"options", "language", "pushver"}, method = RequestMethod.GET)
  131 + public void init(String SN, String options, String language, String pushver, HttpServletRequest request,
  132 + @RequestParam(required = false) String PushOptionsFlag, HttpServletResponse response) {
127 133 try {
128   - if(cmdMap.get(SN) == null){
  134 + if (cmdMap.get(SN) == null) {
129 135 System.out.println("设备上线:" + SN);
130   - cmdMap.put(SN,new ArrayList<>());
131   - cmdOrderMap.put(SN,1);
  136 + cmdMap.put(SN, new ArrayList<>());
  137 + cmdOrderMap.put(SN, 1);
132 138 }
133   - if(scFeign.selectAttendaceWithId(SN) == null){
  139 + if (scFeign.selectAttendaceWithId(SN) == null) {
134 140 SZ_AttendanceDto attendanceDto = new SZ_AttendanceDto();
135 141 attendanceDto.setClint_id(SN);
136 142 attendanceDto.setClint_type("24");
137 143 attendanceDto.setIp(request.getRemoteAddr());
138 144 attendanceDto.setPort(request.getRemotePort());
139   - attendanceDto.setIntime(DateUtils.date2String(new Date(),DateUtils.format2));
  145 + attendanceDto.setIntime(DateUtils.date2String(new Date(), DateUtils.format2));
140 146 attendanceDto.setSchool_id("-1");
141 147 attendanceDto.setState(1);
142 148 scFeign.insertAttendance(attendanceDto);
143   - }else {
  149 + } else {
144 150 scFeign.updateAttendance(SN);
145 151 }
146   - String initOptions = initOptions(SN,PushOptionsFlag);
  152 + String initOptions = initOptions(SN, PushOptionsFlag);
147 153 response.getWriter().write(initOptions);//返回成功以后设备会发送心跳请求
148 154 } catch (IOException e) {
149 155 e.printStackTrace();
... ... @@ -154,19 +160,19 @@ public class AttPushController {
154 160 * 2,心跳请求,会从服务器拿到命令返回 给设备
155 161 */
156 162 @RequestMapping("/getrequest")
157   - public void heartBeat(String SN, HttpServletResponse response){
  163 + public void heartBeat(String SN, HttpServletResponse response) {
158 164 scFeign.updateAttendance(SN);
159 165 StringBuffer sb = new StringBuffer("OK");
160   - List<String> cmds = cmdMap.get(SN);
161   - if(cmds==null){//等于空说明从来没加载过,如果初始化加载过了,此时应该不为Null 只是size为0
  166 + List<String> cmds = cmdMap.get(SN);
  167 + if (cmds == null) {//等于空说明从来没加载过,如果初始化加载过了,此时应该不为Null 只是size为0
162 168 System.out.println("设备上线:" + SN);
163 169 cmds = new ArrayList<>();
164   - cmdMap.put(SN,cmds);
165   - cmdOrderMap.put(SN,1);
  170 + cmdMap.put(SN, cmds);
  171 + cmdOrderMap.put(SN, 1);
166 172 }
167   - if(cmds!=null&&cmds.size()>0){
168   - sb.setLength(0);//如果有命令就不返回OK了
169   - cmds.stream().forEach(cmd->sb.append(cmd).append("\r\n\r\n"));
  173 + if (cmds != null && cmds.size() > 0) {
  174 + sb.setLength(0);//如果有命令就不返回OK了
  175 + cmds.stream().forEach(cmd -> sb.append(cmd).append("\r\n\r\n"));
170 176  
171 177 }
172 178 try {
... ... @@ -183,8 +189,8 @@ public class AttPushController {
183 189 * 这个请求,服务器只能返回OK,不可以返回命令
184 190 */
185 191 @RequestMapping("/ping")
186   - public void ping(HttpServletResponse response){
187   - System.out.println("考勤机心跳请求大量进来了......ping"+new SimpleDateFormat("HH:mm:ss").format(new Date()));
  192 + public void ping(HttpServletResponse response) {
  193 + System.out.println("考勤机心跳请求大量进来了......ping" + new SimpleDateFormat("HH:mm:ss").format(new Date()));
188 194 try {
189 195 response.getWriter().write("OK");
190 196 } catch (IOException e) {
... ... @@ -196,20 +202,35 @@ public class AttPushController {
196 202 * 4,设备端处理完命令以后会发送该请求,告诉服务器命令的处理结果
197 203 */
198 204 @RequestMapping("/devicecmd")
199   - public void handleCmd(String SN, @RequestBody String data, HttpServletResponse response){
  205 + public void handleCmd(String SN, @RequestBody String data, HttpServletResponse response) {
200 206 //判断data 清空map
201 207 List<String> cmdList = cmdMap.get(SN);
  208 + System.out.println("----请求设备:" + SN+"ssssss:"+(cmdList==null?"false":"true"));
202 209 String[] returnList = data.split("\n");
203   - if(returnList.length > 0 && cmdList.size() > 0){
204   - for(String message : returnList){
205   - String number = message.substring(message.indexOf("=")+1,message.indexOf("&"));
206   - String result = message.substring(message.indexOf("=",message.indexOf("&"))+1,message.indexOf("&",message.indexOf("&")+1));
207   - if(result.equals("0")){
  210 + if (returnList.length > 0 && cmdList.size() > 0) {
  211 + for (String message : returnList) {
  212 + String number = message.substring(message.indexOf("=") + 1, message.indexOf("&"));
  213 + String result = message.substring(message.indexOf("=", message.indexOf("&")) + 1, message.indexOf("&", message.indexOf("&") + 1));
  214 + if (result.equals("0")) {
  215 + /*for (int i = 0; i < cmdList.size(); i++) {
  216 +
  217 + String b = cmdList.get(i);
  218 +// if (null==b)System.out.println("内容为空:"+i);
  219 +// else System.out.println("内容为:"+b+"----number:"+number);
  220 + if (b.contains("C:"+number)) {
  221 + Log_orderSuccess.info("指令成功=========="+b);
  222 + }
  223 +
  224 + }
  225 + cmdList.clear();*/
208 226 Iterator<String> it = cmdList.iterator();
209 227 while (((Iterator) it).hasNext()) {
210 228 String b = it.next();
211   - if (b.contains("C:"+number)) {
212   - Log_orderSuccess.info("指令成功=========="+b);
  229 +// if (b.contains("72196"))
  230 +// System.out.println("下发指令==========" + b + "----设备id:" + SN);
  231 + if (b.contains("C:" + number)) {
  232 + Log_orderSuccess.info("指令成功==========" + b);
  233 + System.out.println( "----设备id:" + SN+"======指令成功==========" + b);
213 234 it.remove();
214 235 }
215 236 }
... ... @@ -232,22 +253,22 @@ public class AttPushController {
232 253 request.setCharacterEncoding("gbk");
233 254 String data = "";
234 255 ByteArrayOutputStream bos = null;
235   - byte[] b= new byte[1024];
  256 + byte[] b = new byte[1024];
236 257 try {
237 258 InputStream is = request.getInputStream();
238 259 bos = new ByteArrayOutputStream();
239 260 int len = 0;
240   - while((len=is.read(b))!=-1){
241   - bos.write(b,0,len);
  261 + while ((len = is.read(b)) != -1) {
  262 + bos.write(b, 0, len);
242 263 }
243   - data = new String(bos.toByteArray(),"gbk");
  264 + data = new String(bos.toByteArray(), "gbk");
244 265 } catch (IOException e) {
245 266 e.printStackTrace();
246 267 }
247   - if("ATTLOG".equals(table)){
  268 + if ("ATTLOG".equals(table)) {
248 269 String[] list = data.split("\t");
249 270 String cardNo = scFeign.selectStudentNumByStudentId(Integer.valueOf(list[0]));
250   - if(StringUtils.isNotBlank(cardNo)){
  271 + if (StringUtils.isNotBlank(cardNo)) {
251 272 String cardNo10 = new BigInteger(cardNo, 16).toString();
252 273 //考勤日志
253 274 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
... ... @@ -262,20 +283,20 @@ public class AttPushController {
262 283 String jsonResult = JSON.toJSONString(attendanceInfoBean);
263 284 String urlHXY = "http://campus.myjxt.com/api/XiaoAnCommon/SendHXY";
264 285 JSONObject jsonObject = HttpClientUtils.httpPostJson(urlHXY, jsonResult);
265   - if ((int) jsonObject.get("status") == 1){
  286 + if ((int) jsonObject.get("status") == 1) {
266 287 Log_kaoInfo.info("出入寝签到成功:" + SN + " 卡号:" + cardNo);
267   - }else {
  288 + } else {
268 289 Log_orderFail.info("出入寝签到失败:" + SN + " 卡号:" + cardNo + " result1:" + jsonObject.toJSONString());
269 290 }
270   - }else {
  291 + } else {
271 292 System.out.println(cardNo);
272 293 }
273 294 }
274   - if("OPERLOG".equals(table)){
  295 + if ("OPERLOG".equals(table)) {
275 296 //操作日志
276   - if(data.substring(0,3).contains("FP")){
  297 + if (data.substring(0, 3).contains("FP")) {
277 298 //添加指纹
278   - String studentId = data.substring(data.indexOf("=")+1,data.indexOf("\t",data.indexOf("=")));
  299 + String studentId = data.substring(data.indexOf("=") + 1, data.indexOf("\t", data.indexOf("=")));
279 300 String order = data.substring(3);
280 301 FingerDto fingerDto = new FingerDto();
281 302 fingerDto.setOrderMsg(order);
... ... @@ -291,40 +312,54 @@ public class AttPushController {
291 312 }
292 313 }
293 314  
294   - public static void main(String[] args){
295   - String cardNo = "FF013E0F" ;
296   - String SN = "A4JS174260624" ;
297   - String cardNo10 = new BigInteger(cardNo, 16).toString();
298   - //考勤日志
299   - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
300   - String info = String.format("<AttendanceInfo submitTime=\"%s\"><Info device=\"%s\" card=\"%s\" operTime=\"%s\" direc=\"%s\"></Info></AttendanceInfo>",
301   - simpleDateFormat.format(new Date()), SN, cardNo10, DateUtils.date2String(new Date(),DateUtils.format2), "-1");
302   - AttendanceInfoBean attendanceInfoBean = new AttendanceInfoBean();
303   - attendanceInfoBean.setInfo(info);
304   - attendanceInfoBean.setIsControl(0);
305   - attendanceInfoBean.setPwd(pwd);
306   - attendanceInfoBean.setUsername(account);
  315 + public static void main(String[] args) {
  316 + /*JSONObject object = new JSONObject();
  317 + object.put("pageIndex",1);
  318 + object.put("roomId","13299");
  319 + object.put("pageSize",9999);
  320 + JSONObject result = HttpClientUtils.httpPostJson("http://campus.myjxt.com/api/Room/GetListPageRoom",object.toJSONString());
  321 + JSONObject data = result.getJSONObject("data");
  322 + JSONArray roomList = data.getJSONArray("roomList");
  323 + for (int i = 0; i < roomList.size(); i++) {
  324 + String name = roomList.getJSONObject(i).getString("name");
  325 + String studentId = roomList.getJSONObject(i).getString("studentid");
  326 + System.out.println(name+","+studentId);
  327 + }*/
307 328  
308   - String jsonResult = JSON.toJSONString(attendanceInfoBean);
309   - String urlHXY = "http://campus.myjxt.com/api/XiaoAnCommon/SendHXY";
310   - JSONObject jsonObject = HttpClientUtils.httpPostJson(urlHXY, jsonResult);
311   - if ((int) jsonObject.get("status") == 1){
312   - Log_kaoInfo.info("出入寝签到成功:" + SN + " 卡号:" + cardNo);
313   - }else {
314   - Log_orderFail.info("出入寝签到失败:" + SN + " 卡号:" + cardNo + " result1:" + jsonObject.toJSONString());
315   - }
316   - }
  329 + String cardNo = "FF013E0F";
  330 + String SN = "A4JS174260624";
  331 + String cardNo10 = new BigInteger(cardNo, 16).toString();
  332 + //考勤日志
  333 + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  334 + String info = String.format("<AttendanceInfo submitTime=\"%s\"><Info device=\"%s\" card=\"%s\" operTime=\"%s\" direc=\"%s\"></Info></AttendanceInfo>",
  335 + simpleDateFormat.format(new Date()), SN, cardNo10, DateUtils.date2String(new Date(), DateUtils.format2), "-1");
  336 + AttendanceInfoBean attendanceInfoBean = new AttendanceInfoBean();
  337 + attendanceInfoBean.setInfo(info);
  338 + attendanceInfoBean.setIsControl(0);
  339 + attendanceInfoBean.setPwd(pwd);
  340 + attendanceInfoBean.setUsername(account);
  341 +
  342 + String jsonResult = JSON.toJSONString(attendanceInfoBean);
  343 + String urlHXY = "http://campus.myjxt.com/api/XiaoAnCommon/SendHXY";
  344 + JSONObject jsonObject = HttpClientUtils.httpPostJson(urlHXY, jsonResult);
  345 + if ((int) jsonObject.get("status") == 1) {
  346 + Log_kaoInfo.info("出入寝签到成功:" + SN + " 卡号:" + cardNo);
  347 + } else {
  348 + Log_orderFail.info("出入寝签到失败:" + SN + " 卡号:" + cardNo + " result1:" + jsonObject.toJSONString());
  349 + }
  350 + }
317 351  
318 352  
319 353 /**
320 354 * 设备通电以后连接到服务器,需要返回的初始化参数
  355 + *
321 356 * @param sn
322 357 * @param PushOptionsFlag
323 358 * @return
324 359 */
325   - private String initOptions(String sn,String PushOptionsFlag) {
  360 + private String initOptions(String sn, String PushOptionsFlag) {
326 361 StringBuffer devOptions = new StringBuffer();
327   - devOptions.append("GET OPTION FROM: "+sn);
  362 + devOptions.append("GET OPTION FROM: " + sn);
328 363 // + "\nStamp=" + devInfo.devInfoJson.getString("Stamp")
329 364 devOptions.append("\nATTLOGStamp=0");
330 365 devOptions.append("\nOPERLOGStamp=0");
... ... @@ -348,9 +383,8 @@ public class AttPushController {
348 383 // 11 工作号码
349 384 // 12 比对照片
350 385 devOptions.append("\nTransFlag=111111111111");// 1-12二进制位 分别代表以上含义
351   - System.out.println("PushOptionsFlag============="+PushOptionsFlag);
352   - if (PushOptionsFlag!=null&&PushOptionsFlag.equals("1"))
353   - {
  386 + System.out.println("PushOptionsFlag=============" + PushOptionsFlag);
  387 + if (PushOptionsFlag != null && PushOptionsFlag.equals("1")) {
354 388 // 支持参数单独获取的才要把需要获取的参数回传给设备 modifeid by max 20170926
355 389 devOptions.append("\nPushOptions=RegDeviceType,FingerFunOn,FaceFunOn,FPVersion,FaceVersion,NetworkType,HardwareId3,HardwareId5,HardwareId56,LicenseStatus3,LicenseStatus5,LicenseStatus56");
356 390 }
... ...
cloud/zkAttendance/src/main/resources/application.yaml
... ... @@ -12,5 +12,6 @@ eureka:
12 12 lease-renewal-interval-in-seconds: 10
13 13 client:
14 14 service-url:
15   - defaultZone: http://localhost:8761/eureka/,http://localhost:8762/eureka/
  15 +# defaultZone: http://localhost:8761/eureka/,http://localhost:8762/eureka/
  16 + defaultZone: http://121.40.109.21:8761/eureka/,http://121.40.109.21:8762/eureka/
16 17  
... ...