Commit 191a8018cfea466624f86907b0df5ce41fb96082

Authored by 陶汉栋
1 parent 3009e2ac
Exists in master

无感考勤

Showing 21 changed files with 564 additions and 102 deletions   Show diff stats
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 }
... ...
cloud/dahua/src/main/java/com/example/dahua/Test.java
... ... @@ -16,8 +16,13 @@ public class Test {
16 16  
17 17 public static void main(String[] args) {
18 18  
  19 + String url = "E:\\wwwhtdocs\\SmartCampus\\face17e5\\School112\\Student\\saa.png";
19 20  
20   - Test test = new Test();
  21 + url = url.substring(url.indexOf("School")+6,url.indexOf("\\Student"));
  22 +
  23 + System.out.println("url:"+url);
  24 +
  25 + /*Test test = new Test();
21 26  
22 27 File file = new File("C:\\Users\\Administrator\\Documents\\专业.txt");
23 28  
... ... @@ -37,7 +42,7 @@ public class Test {
37 42 e.printStackTrace();
38 43 } catch (IOException e) {
39 44 e.printStackTrace();
40   - }
  45 + }*/
41 46  
42 47  
43 48 }
... ...
cloud/dahua/src/main/java/com/example/dahua/control/UserControl.java
... ... @@ -62,7 +62,7 @@ public class UserControl {
62 62 @RequestMapping(value = "sendPermission", method = RequestMethod.POST)
63 63 @ApiOperation(value = "设置权限")
64 64 public boolean sendPermission(@RequestBody PermissionBean permissionBean) {
65   - return HttpUtils.sendPermission(permissionBean);
  65 + return HttpUtils.sendPermission(permissionBean);
66 66 }
67 67  
68 68 @RequestMapping(value = "imgsSend", method = RequestMethod.GET)
... ... @@ -116,7 +116,29 @@ public class UserControl {
116 116 @ApiOperation("在线活体检测")
117 117 public boolean checkFace(@RequestParam("url") String httpurl) {
118 118  
119   - return BaiduUtils.getBaiduUtils().checkImg(httpurl);
  119 + boolean check = BaiduUtils.getBaiduUtils().checkImg(httpurl);
  120 +
  121 + if (check) {
  122 + File file = new File(httpurl);
  123 +
  124 + String userCode = file.getName().split("\\.")[0];
  125 +
  126 + String schoolId = "";
  127 +
  128 + if (httpurl.contains("Student")) {
  129 + schoolId = httpurl.substring(httpurl.indexOf("School") + 6, httpurl.indexOf("\\Student"));
  130 + } else if (httpurl.contains("Teacher")) {
  131 + schoolId = httpurl.substring(httpurl.indexOf("School") + 6, httpurl.indexOf("\\Teacher"));
  132 + }
  133 + System.out.println("choolId:" + schoolId + "userCode:" + userCode);
  134 + if (!StringUtils.isEmpty(schoolId) && !StringUtils.isEmpty(userCode)) {
  135 + String userId = userService.getUserId(userCode, schoolId);
  136 + BaiduUtils.getBaiduUtils().addFace(new File(httpurl), schoolId, userId, userId);
  137 + FileUtils.getInstance().writeLogs("人脸添加成功:" + userId, "人脸添加成功.txt");
  138 + }
  139 + }
  140 +
  141 + return check;
120 142  
121 143 }
122 144  
... ...
cloud/dahua/src/main/java/com/example/dahua/dao/UserDao.java
... ... @@ -133,4 +133,8 @@ public interface UserDao {
133 133  
134 134 @Select("select * from SZ_V_School_Teacher where user_id = #{userId}")
135 135 List<TeacherBean> getTeaWithUserId(@Param("userId")String userId);
  136 +
  137 + @Select("select Top(1) user_id from SZ_V_School_Student where studentcode = #{studentcode}")
  138 + String getStuWithCode(@Param("studentcode") String code);
  139 +
136 140 }
... ...
cloud/dahua/src/main/java/com/example/dahua/service/UserService.java
... ... @@ -3,10 +3,7 @@ package com.example.dahua.service;
3 3 import com.example.dahua.bean.AttendanceBean;
4 4 import com.example.dahua.bean.PermissionBean;
5 5 import com.example.dahua.bean.UserInfoBean;
6   -import org.springframework.scheduling.annotation.Async;
7   -import org.springframework.web.multipart.MultipartFile;
8 6  
9   -import java.io.File;
10 7 import java.util.List;
11 8  
12 9 public interface UserService {
... ... @@ -57,4 +54,7 @@ public interface UserService {
57 54 */
58 55 boolean sendPermission(PermissionBean permissionBean);
59 56  
  57 + String getUserId(String code,String schoolId);
  58 +
  59 +
60 60 }
... ...
cloud/dahua/src/main/java/com/example/dahua/service/imp/UserServiceImp.java
... ... @@ -117,4 +117,23 @@ public class UserServiceImp implements UserService {
117 117 return false;
118 118 }
119 119  
  120 + @Override
  121 + public String getUserId(String code,String schoolId) {
  122 +
  123 + String userId = "";
  124 +
  125 +
  126 + userId = userDao.getStuWithCode(code);
  127 +
  128 + if (StringUtils.isEmpty(userId)){
  129 +
  130 + TeacherBean teacherBean = userDao.getTeacher(schoolId,code);
  131 + userId = teacherBean.getUser_id();
  132 +
  133 + }
  134 +
  135 + return userId;
  136 + }
  137 +
  138 +
120 139 }
... ...
cloud/dahua/src/main/java/com/example/dahua/utils/BaiduUtils.java
1 1 package com.example.dahua.utils;
2 2  
  3 +import com.alibaba.fastjson.JSON;
3 4 import com.example.dahua.async.ImageUtils;
4 5 import com.example.dahua.lib.CompressPic;
5 6 import org.json.JSONArray;
... ... @@ -9,10 +10,7 @@ import javax.imageio.stream.FileImageInputStream;
9 10 import java.io.*;
10 11 import java.net.HttpURLConnection;
11 12 import java.net.URL;
12   -import java.util.ArrayList;
13   -import java.util.HashMap;
14   -import java.util.List;
15   -import java.util.Map;
  13 +import java.util.*;
16 14  
17 15 public class BaiduUtils {
18 16  
... ... @@ -107,6 +105,21 @@ public class BaiduUtils {
107 105 return true;
108 106 }
109 107  
  108 + /**
  109 + * 注册人脸到百度
  110 + * @param file
  111 + */
  112 + private void addToBaidu(File file) {
  113 +
  114 + //学籍号或者教职工编号
  115 + String userCode = file.getName().split("\\.")[0];
  116 +
  117 +
  118 +
  119 +// BaiduUtils.getBaiduUtils().addFace(file,)
  120 +
  121 + }
  122 +
110 123 //图片到byte数组
111 124 public byte[] image2byte(String path) {
112 125 byte[] data = null;
... ... @@ -208,4 +221,71 @@ public class BaiduUtils {
208 221 return null;
209 222 }
210 223  
  224 +
  225 + //注册人脸
  226 + public String addFace(File img, String group_id, String user_id, String userInfo) {
  227 +
  228 + String url = "https://aip.baidubce.com/rest/2.0/face/v3/faceset/user/add";
  229 +
  230 +
  231 + try {
  232 + Map<String, Object> map = new HashMap<>();
  233 + map.put("image", Base64Util.encode(InputStream2ByteArray(img.getAbsolutePath())));
  234 + map.put("group_id", group_id);
  235 + map.put("user_id", user_id);
  236 + map.put("user_info", userInfo);
  237 +// map.put("liveness_control", "NORMAL");
  238 + map.put("image_type", "BASE64");
  239 + map.put("quality_control", "NORMAL");
  240 +
  241 + String param = GsonUtils.toJson(map);
  242 +
  243 + // 注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。
  244 +
  245 + String result = HttpUtil.post(url, getAuth(), "application/json", param);
  246 + System.out.println(result);
  247 + com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(result);
  248 + String error_msg = jsonObject.getString("error_msg");
  249 + if (error_msg.equals("SUCCESS")) {
  250 +
  251 +// com.alibaba.fastjson.JSONObject faceResult = jsonObject.getJSONObject("result");
  252 +
  253 +// FacerecordBean facerecordBean = new FacerecordBean();
  254 +//
  255 +// facerecordBean.setFace_token(faceResult.getString("face_token"));
  256 +// facerecordBean.setGroup_id(group_id);
  257 +// facerecordBean.setIntime(simpleDateFormat.format(new Date()));
  258 +// facerecordBean.setUser_id(user_id);
  259 +//
  260 +// facerecordService.addFacerecord(facerecordBean);
  261 + return "注册成功";
  262 + } else {
  263 + return error_msg;
  264 + }
  265 +
  266 + } catch (Exception e) {
  267 + e.printStackTrace();
  268 + }
  269 + return "";
  270 + }
  271 +
  272 + private byte[] InputStream2ByteArray(String filePath) throws IOException {
  273 +
  274 + InputStream in = new FileInputStream(filePath);
  275 + byte[] data = toByteArray(in);
  276 + in.close();
  277 +
  278 + return data;
  279 + }
  280 +
  281 + private byte[] toByteArray(InputStream in) throws IOException {
  282 +
  283 + ByteArrayOutputStream out = new ByteArrayOutputStream();
  284 + byte[] buffer = new byte[1024 * 4];
  285 + int n = 0;
  286 + while ((n = in.read(buffer)) != -1) {
  287 + out.write(buffer, 0, n);
  288 + }
  289 + return out.toByteArray();
  290 + }
211 291 }
... ...
cloud/dahua/src/main/resources/mapper/usermapper.xml
... ... @@ -18,5 +18,6 @@
18 18  
19 19 </select>
20 20  
21   -
  21 +
  22 +
22 23 </mapper>
23 24 \ No newline at end of file
... ...
cloud/haikang/src/main/java/com/sincere/haikang/SchduleTask.java
... ... @@ -2,6 +2,7 @@ package com.sincere.haikang;
2 2  
3 3 import com.sincere.haikang.async.SendUserAsync;
4 4 import com.sincere.haikang.bean.AttendanceBean;
  5 +import com.sincere.haikang.bean.SIngleCardBean;
5 6 import com.sincere.haikang.bean.StudentBean;
6 7 import com.sincere.haikang.dao.DeviceDao;
7 8 import com.sincere.haikang.dao.UserDao;
... ... @@ -22,7 +23,9 @@ import org.springframework.util.StringUtils;
22 23 import org.springframework.web.client.RestTemplate;
23 24  
24 25 import java.io.*;
  26 +import java.text.SimpleDateFormat;
25 27 import java.util.ArrayList;
  28 +import java.util.Date;
26 29 import java.util.List;
27 30  
28 31 @Component
... ... @@ -129,10 +132,13 @@ public class SchduleTask {
129 132 String clientIds = "";
130 133 for (int i = 0; i < attendanceBeans.size(); i++) {
131 134 if (i < attendanceBeans.size() - 1) {
132   - if (attendanceBeans.get(i).getClint_type().equals("22")) {
  135 + AttendanceBean attendanceBean = attendanceBeans.get(i);
  136 + System.out.println("attendanceBean:"+attendanceBean.toString());
  137 + String clint_type = attendanceBean.getClint_type();
  138 + if (null!=clint_type&&clint_type.equals("22")) {
133 139 type = 22;
134 140 clientIds += attendanceBeans.get(i).getClint_id() + ",";
135   - } else if (attendanceBeans.get(i).getClint_type().equals("18")) {
  141 + } else if (null!=clint_type&&clint_type.equals("18")) {
136 142 type = 18;
137 143 clientIds += attendanceBeans.get(i).getClint_id();
138 144 }
... ... @@ -167,13 +173,46 @@ public class SchduleTask {
167 173 int SchoolId = studentBean.getSchoolId();
168 174 String card = TextUtils.isEmpty(studentBean.getCard()) ? studentBean.getOldCard() : studentBean.getCard();
169 175 if (!TextUtils.isEmpty(card)) {
170   - RestTemplate restTemplate = new RestTemplate();
171   - HttpHeaders headers = new HttpHeaders();
172   - headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
173   - String url = "http://campus.myjxt.com/api/OneCard/SendSingle?SchoolId=" + SchoolId + "&Card=" + card + "&ClassId=" + studentBean.getClassId();
174   - System.out.println("下发卡号url:" + url);
175   - ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class);
176   - System.out.println("下发卡号:" + responseEntity.getBody());
  176 +
  177 + List<AttendanceBean> attendanceBeans = deviceDao.getAttendancesWithSchoolId(SchoolId);
  178 +
  179 + for (int i = 0; i < attendanceBeans.size(); i++) {
  180 +
  181 + AttendanceBean attendanceBean = attendanceBeans.get(i);
  182 +
  183 + String clint_type = attendanceBean.getClint_type();
  184 +
  185 + if (null!=clint_type&&clint_type.equals("6")){
  186 +
  187 + SIngleCardBean sIngleCardBean = new SIngleCardBean();
  188 +
  189 + sIngleCardBean.setCardNo(card);
  190 + sIngleCardBean.setEndTime("2050-09-04T00:52:22.510Z");
  191 + sIngleCardBean.setId("5");
  192 + sIngleCardBean.setShiduan("2");
  193 + sIngleCardBean.setSn(attendanceBean.getClint_id());
  194 + sIngleCardBean.setStartTime(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(new Date()));
  195 + sIngleCardBean.setType("1");
  196 +
  197 + RestTemplate restTemplate = new RestTemplate();
  198 + HttpHeaders headers = new HttpHeaders();
  199 + MediaType mediaType = MediaType.parseMediaType(MediaType.APPLICATION_JSON_UTF8_VALUE);
  200 + headers.setContentType(mediaType);
  201 +// String url = "http://campus.myjxt.com/api/OneCard/SendSingle?SchoolId=" + SchoolId + "&Card=" + card + "&ClassId=" + studentBean.getClassId();
  202 +// System.out.println("下发卡号url:" + url);
  203 +// ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class);
  204 +// System.out.println("下发卡号:" + responseEntity.getBody());
  205 + System.out.println("sIngleCardBean:"+sIngleCardBean.toString());
  206 + String url = "http://121.40.109.21:9000/setSignalCardInfo";
  207 + HttpEntity<SIngleCardBean> httpEntity = new HttpEntity<>(sIngleCardBean,headers);
  208 + ResponseEntity<String> responseEntity = restTemplate.postForEntity(url,httpEntity,String.class);
  209 + System.out.println("下发卡号:" + responseEntity.getBody());
  210 +
  211 +
  212 + }
  213 +
  214 + }
  215 +
177 216 }
178 217  
179 218  
... ...
cloud/haikang/src/main/java/com/sincere/haikang/Test.java 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +package com.sincere.haikang;
  2 +
  3 +import java.text.SimpleDateFormat;
  4 +import java.util.Date;
  5 +
  6 +public class Test {
  7 + static int i ;
  8 +
  9 + public static void main(String[] args) {
  10 +
  11 + int num = 2147483647 ;
  12 + long temp = num + 2L ;
  13 + System.out.println(num) ;
  14 +
  15 + }
  16 +
  17 +}
... ...
cloud/haikang/src/main/java/com/sincere/haikang/bean/SIngleCardBean.java 0 → 100644
... ... @@ -0,0 +1,89 @@
  1 +package com.sincere.haikang.bean;
  2 +
  3 +import java.io.Serializable;
  4 +
  5 +public class SIngleCardBean implements Serializable {
  6 +
  7 + private String cardNo;
  8 +
  9 + private String endTime;
  10 +
  11 + private String id;
  12 +
  13 + private String shiduan;
  14 +
  15 + private String sn;
  16 +
  17 + private String startTime;
  18 +
  19 + private String type;
  20 +
  21 + public String getCardNo() {
  22 + return cardNo;
  23 + }
  24 +
  25 + public void setCardNo(String cardNo) {
  26 + this.cardNo = cardNo;
  27 + }
  28 +
  29 + public String getEndTime() {
  30 + return endTime;
  31 + }
  32 +
  33 + public void setEndTime(String endTime) {
  34 + this.endTime = endTime;
  35 + }
  36 +
  37 + public String getId() {
  38 + return id;
  39 + }
  40 +
  41 + public void setId(String id) {
  42 + this.id = id;
  43 + }
  44 +
  45 + public String getShiduan() {
  46 + return shiduan;
  47 + }
  48 +
  49 + public void setShiduan(String shiduan) {
  50 + this.shiduan = shiduan;
  51 + }
  52 +
  53 + public String getSn() {
  54 + return sn;
  55 + }
  56 +
  57 + public void setSn(String sn) {
  58 + this.sn = sn;
  59 + }
  60 +
  61 + public String getStartTime() {
  62 + return startTime;
  63 + }
  64 +
  65 + public void setStartTime(String startTime) {
  66 + this.startTime = startTime;
  67 + }
  68 +
  69 + public String getType() {
  70 + return type;
  71 + }
  72 +
  73 + public void setType(String type) {
  74 + this.type = type;
  75 + }
  76 +
  77 + @Override
  78 + public String toString() {
  79 + return "SIngleCardBean{" +
  80 + "cardNo='" + cardNo + '\'' +
  81 + ", endTime='" + endTime + '\'' +
  82 + ", id='" + id + '\'' +
  83 + ", shiduan='" + shiduan + '\'' +
  84 + ", sn='" + sn + '\'' +
  85 + ", startTime='" + startTime + '\'' +
  86 + ", type='" + type + '\'' +
  87 + '}';
  88 + }
  89 +}
... ...
cloud/haikangface/src/main/java/com/sincere/haikangface/CMSServer.java
... ... @@ -57,20 +57,24 @@ public class CMSServer implements ApplicationRunner {
57 57 @Autowired
58 58 UserDao userDao;
59 59  
60   -
61 60 @Autowired
62 61 SendRecordDao sendRecordDao;
63 62  
64 63 //114.55.30.100
65 64 //120.26.116.253
66   -// private String ip_cloud = "120.26.116.253";
67   -// private String ip_cloud = "192.168.71.242";
68   - private String ip_cloud = "114.55.30.100";
  65 + private String ip_cloud = "120.26.116.253";
  66 +// private String ip_cloud = "172.16.2.43";
  67 +// private String ip_cloudQJ = "120.27.221.31";//枪机的图片和报警监听地址
  68 +// private String ip_cloud = "114.55.30.100";
  69 +// private String ip_cloud = "120.27.221.31";
  70 +// private String ip_cloud = "121.40.109.21";
  71 +
69 72 private String ip;
70 73  
71 74 {
72 75 try {
73 76 ip = InetAddress.getLocalHost().getHostAddress();
  77 +// ip=ip_cloud;
74 78 // ip_cloud = ip;
75 79 } catch (UnknownHostException e) {
76 80 e.printStackTrace();
... ... @@ -91,6 +95,15 @@ public class CMSServer implements ApplicationRunner {
91 95 //初始化报警监听
92 96 initAlarm();
93 97  
  98 + /* String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
  99 + BaiduFaceRecorder baiduFaceRecorder = new BaiduFaceRecorder();
  100 + baiduFaceRecorder.setName("name");
  101 + baiduFaceRecorder.setScore("11");
  102 + baiduFaceRecorder.setTime(time);
  103 + baiduFaceRecorder.setUserImgUrl("22");
  104 + baiduFaceRecorder.setUploadImgUrl("22");
  105 + userDao.insertBaiduFaceRecorder(baiduFaceRecorder);*/
  106 +
94 107 }
95 108  
96 109 static HCEHomeCMS hCEhomeCMS = HCEHomeCMS.INSTANCE;
... ... @@ -112,8 +125,8 @@ public class CMSServer implements ApplicationRunner {
112 125 fRegisterCallBack = new FRegisterCallBack();
113 126 }
114 127 hCEhomeCMS.NET_ECMS_SetLogToFile(3, "C:/Ehomejavademo/EHomeSDKLog", false);
115   -
116 128 struCMSListenPara.struAddress.szIP = ip.getBytes();
  129 +// System.out.println("ip--------------------------------------------:"+ip);
117 130 struCMSListenPara.struAddress.wPort = 7660;
118 131 struCMSListenPara.fnCB = fRegisterCallBack;
119 132  
... ... @@ -182,6 +195,9 @@ public class CMSServer implements ApplicationRunner {
182 195  
183 196 // byte[] byIP = ip.getBytes();
184 197 byte[] byIP = ip_cloud.getBytes();
  198 +
  199 +// if (deviceId.startsWith("qj")) byIP = ip_cloudQJ.getBytes();
  200 +
185 201 System.arraycopy(byIP, 0, pInBuffer.struUDPAlarmSever.szIP, 0, byIP.length);
186 202 // TODO: 2020/8/27 人脸机类型为0
187 203 pInBuffer.dwAlarmServerType = 0; //报警服务器类型:0- 只支持UDP协议上报,1- 支持UDP、TCP两种协议上报
... ... @@ -302,9 +318,10 @@ public class CMSServer implements ApplicationRunner {
302 318 public class PSS_Storage_Callback implements HCEHomeSS.EHomeSSStorageCallBack {
303 319  
304 320 public boolean invoke(NativeLong iHandle, String pFileName, Pointer pFileBuf, int dwFileLen, Pointer pFilePath, Pointer pUser) {
305   - log.error("图片进来:{}" , pFileName);
  321 +// log.error("图片进来:{}", pFileName);
306 322 String strPath = "C://EhomePicServer/";
307 323 // System.out.println("pFileName:" + pFileName);
  324 + FileUtils.getInstance().writeLogs("文件名:" + pFileName, FileUtils.fileName);
308 325 pFileName = pFileName.replace("_", "");
309 326 boolean isZhuaPai = false;
310 327 if (pFileName.contains("-")) {//人脸抓拍机抓拍到的图片
... ... @@ -315,7 +332,6 @@ public class CMSServer implements ApplicationRunner {
315 332 }
316 333  
317 334 String strFilePath = strPath + pFileName;
318   - FileUtils.getInstance().writeLogs("文件名:" + pFileName, FileUtils.fileName);
319 335 //保存抓拍到的人脸图片,比对通过后的图片资源
320 336  
321 337 // System.out.println("文件保存回调函数:" + strFilePath);
... ... @@ -348,6 +364,7 @@ public class CMSServer implements ApplicationRunner {
348 364 fout.write(bytes);
349 365 fout.close();
350 366  
  367 +// if (ip_cloud.equals(ip_cloudQJ))
351 368 sendToKB(strFilePathFile);
352 369  
353 370 } catch (FileNotFoundException e) {
... ... @@ -369,6 +386,8 @@ public class CMSServer implements ApplicationRunner {
369 386 }
370 387 }
371 388  
  389 + Map<String, Long> userMap = new HashMap<>();
  390 +
372 391 /**
373 392 * 发送人脸到看板
374 393 *
... ... @@ -377,69 +396,109 @@ public class CMSServer implements ApplicationRunner {
377 396 public void sendToKB(File strFilePathFile) {
378 397 try {
379 398  
380   - log.error("开始识别.....");
381   - String url = "http://120.26.116.253:9214/baiduapi/search/16";
382   -
383   - RestTemplate restTemplate = new RestTemplate();
384   -
385   - HttpHeaders headers = new HttpHeaders();
386   - MediaType mediaType = MediaType.parseMediaType(MediaType.MULTIPART_FORM_DATA_VALUE);
387   - headers.setContentType(mediaType);
388   - MultiValueMap<String, Object> multiValueMap = new LinkedMultiValueMap<>();
389   - FileSystemResource fileSystemResource = new FileSystemResource(strFilePathFile);
390   -
391   - multiValueMap.add("file ", fileSystemResource);
392   - HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(multiValueMap, headers);
393   -
394   - ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, httpEntity, String.class);
395   - log.error("识别结果:{}" , responseEntity.getBody());
396   - JSONObject jsonObject = JSON.parseObject(responseEntity.getBody());
397   -
398   - String face = jsonObject.getString("data");
399   - if (face.startsWith("face"))return;
400   -
401   - JSONObject data = jsonObject.getJSONObject("data");
402   - String error_msg = data.getString("error_msg");
403   -
404   - if (error_msg.equals("SUCCESS")) {//识别成功
405   - JSONObject result = data.getJSONObject("result");
406   - JSONArray user_list = result.getJSONArray("user_list");
407   -
408   - if (user_list != null && user_list.size() > 0) {
409   -
410   - for (int i = 0; i < user_list.size(); i++) {
411   - JSONObject user = user_list.getJSONObject(i);
412   -
413   - String user_id = user.getString("user_id");
414   - String score = user.getString("score");
415   - double sc = Double.valueOf(score.split("\\.")[0]);
416   - if (sc >= 60) {
417   - System.out.println("user_id:" + user_id);
418   - TeacherBean teacherBean = userDao.getTeacherWithUserId1(user_id);
419   - if (null != teacherBean) {
420   - if (TextUtils.isEmpty(teacherBean.getTeacer_num()))teacherBean.setTeacer_num(user_id);
421   - MqtUtils.getInstance().sendMsg("09EA8EB5142F2964", 1, teacherBean.toString());
  399 + log.error("开始识别.....");
  400 + String url = "http://120.26.116.253:9214/baiduapi/search/16";
  401 +
  402 + RestTemplate restTemplate = new RestTemplate();
  403 +
  404 + HttpHeaders headers = new HttpHeaders();
  405 + MediaType mediaType = MediaType.parseMediaType(MediaType.MULTIPART_FORM_DATA_VALUE);
  406 + headers.setContentType(mediaType);
  407 + MultiValueMap<String, Object> multiValueMap = new LinkedMultiValueMap<>();
  408 + FileSystemResource fileSystemResource = new FileSystemResource(strFilePathFile);
  409 +
  410 + multiValueMap.add("file ", fileSystemResource);
  411 + HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(multiValueMap, headers);
  412 +
  413 + ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, httpEntity, String.class);
  414 +// log.error("识别结果:{}", responseEntity.getBody());
  415 + JSONObject jsonObject = JSON.parseObject(responseEntity.getBody());
  416 +
  417 + String face = jsonObject.getString("data");
  418 + if (face.startsWith("face")||face.startsWith("pic")) return;
  419 +
  420 + JSONObject data = jsonObject.getJSONObject("data");
  421 + String error_msg = data.getString("error_msg");
  422 +
  423 + if (error_msg.equals("SUCCESS")) {//识别成功
  424 + JSONObject result = data.getJSONObject("result");
  425 + JSONArray user_list = result.getJSONArray("user_list");
  426 +
  427 + if (user_list != null && user_list.size() > 0) {
  428 +
  429 + for (int i = 0; i < user_list.size(); i++) {
  430 + JSONObject user = user_list.getJSONObject(i);
  431 +
  432 + String user_id = user.getString("user_id");
  433 + String score = user.getString("score");
  434 + double sc = Double.valueOf(score.split("\\.")[0]);
  435 + if (sc >= 60) {
  436 + System.out.println("user_id:" + user_id);
  437 + TeacherBean teacherBean = userDao.getTeacherWithUserId1(user_id);
  438 +
  439 + if (null != teacherBean) {
  440 + String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
  441 + String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
  442 + BaiduFaceRecorder baiduFaceRecorder = new BaiduFaceRecorder();
  443 + baiduFaceRecorder.setName(teacherBean.getName());
  444 + baiduFaceRecorder.setScore(sc+"");
  445 + baiduFaceRecorder.setTime(time);
  446 + 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());
  449 + baiduFaceRecorder.setUserId(user_id);
  450 + userDao.insertBaiduFaceRecorder(baiduFaceRecorder);
  451 +
  452 + if (TextUtils.isEmpty(teacherBean.getTeacer_num())) teacherBean.setTeacer_num(user_id);
  453 + teacherBean.setTime(time);
  454 +
  455 + if (userMap.containsKey(user_id)) {
  456 +
  457 + long value = userMap.get(user_id);
  458 + if ((System.currentTimeMillis() - value) / 1000 > 6) {
  459 + userMap.put(user_id, System.currentTimeMillis());
  460 + MqtUtils.getInstance().sendMsg("09EA8EB5142F2964", 1, teacherBean.toString());
  461 + log.error("发送成功.....");
  462 + }
  463 +
  464 + } else {
  465 + userMap.put(user_id, System.currentTimeMillis());
  466 + MqtUtils.getInstance().sendMsg("09EA8EB5142F2964", 1, teacherBean.toString());
  467 + log.error("发送成功.....");
  468 + }
  469 +
  470 +// strFilePathFile.deleteOnExit();
  471 + } else {
  472 + System.out.println("用户身份信息不存在");
  473 + sendNoPersonImg(strFilePathFile);
  474 + }
422 475 } else {
423   - System.out.println("用户身份信息不存在");
  476 + System.out.println("用户身份信息不存在" + score);
  477 + sendNoPersonImg(strFilePathFile);
424 478 }
425   - }else {
426   - System.out.println("用户身份信息不存在"+score);
  479 +
427 480 }
428 481  
429 482 }
430   -
  483 + } else {
  484 + System.out.println("识别失败:" + error_msg);
431 485 }
432   - } else {
433   - System.out.println("识别失败:" + error_msg);
434   - }
435   - log.error("发送成功.....");
436 486 // System.out.println("responseEntity:"+responseEntity.getBody());
437   - }catch (Exception e){
  487 + } catch (Exception e) {
438 488 e.printStackTrace();
439 489 }
440 490  
441 491 }
442 492  
  493 + private void sendNoPersonImg(File strFilePathFile) {
  494 + String imgName = strFilePathFile.getName();
  495 + String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
  496 + if (imgName.contains(date)) {
  497 + 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);
  499 + }
  500 + }
  501 +
443 502 HCEHomeAlarm.NET_EHOME_ALARM_LISTEN_PARAM net_ehome_alarm_listen_param = new HCEHomeAlarm.NET_EHOME_ALARM_LISTEN_PARAM();
444 503 EHomeMsgCallBack cbEHomeMsgCallBack;
445 504 ;//报警监听回调函数实现
... ... @@ -507,9 +566,9 @@ public class CMSServer implements ApplicationRunner {
507 566  
508 567 String strXML = new String(strXMLData.byValue);
509 568 // System.out.println(strXML);
510   -// log.error("报警监听:{}",strXML);
  569 +// log.error("报警监听:{}", strXML);
511 570 if (null == alarmUtils) {
512   - alarmUtils = new AlarmUtils(deviceDao);
  571 + alarmUtils = new AlarmUtils(deviceDao,userDao);
513 572 alarmUtils.setCallBack(new AlarmUtils.AlarmCallBack() {
514 573 @Override
515 574 public void callBack(String minorType, String deviceID, String cardNo, String time, String picDataUrlId, String currTemperature) {
... ... @@ -563,7 +622,7 @@ public class CMSServer implements ApplicationRunner {
563 622 cardNo = sendRecoderUtils.getCard(card);
564 623  
565 624 StudentBean studentBean = userDao.getStudentWithCard(cardNo);
566   - log.error("studentBean:{}",studentBean);
  625 + log.error("studentBean:{}", studentBean);
567 626 if (null != studentBean) {
568 627 FileUtils.getInstance().writeLogs(studentBean.getName() + " " + cardNo, FileUtils.facerecoder);
569 628  
... ... @@ -589,9 +648,9 @@ public class CMSServer implements ApplicationRunner {
589 648 isTeacher(cardNo, deviceID);
590 649 }
591 650  
592   - if (deviceID.startsWith("qj")) {//枪击 用来抓拍人脸考勤用
593   - initQJ(deviceID, cardNo, studentBean == null);
594   - }
  651 +// if (deviceID.startsWith("qj")) {//枪击 用来抓拍人脸考勤用
  652 +// initQJ(deviceID, cardNo, studentBean == null);
  653 +// }
595 654  
596 655 }
597 656  
... ... @@ -614,12 +673,12 @@ public class CMSServer implements ApplicationRunner {
614 673 public void isTeacher(String cardNo, String deviceID) {
615 674  
616 675 List<String> devLists = userDao.getDeviceRoomRelation(deviceID);
617   - log.error("cardNo:{},devLists{}",cardNo,devLists);
  676 + log.error("cardNo:{},devLists{}", cardNo, devLists);
618 677  
619 678 if (null != devLists && devLists.size() > 0) {
620 679  
621 680 StudentBean teacher = userDao.getTeacherWithCard(cardNo);
622   - FileUtils.getInstance().writeLogs("teacher:" + teacher+"----"+cardNo, "教师点名.txt");
  681 + FileUtils.getInstance().writeLogs("teacher:" + teacher + "----" + cardNo, "教师点名.txt");
623 682 if (null != teacher) {
624 683 String url = String.format("http://campus.myjxt.com/api/RollCall/AddRollCallPersonnelRecord?userId=%s&deviceId=%s", teacher.getUser_id(), deviceID);
625 684  
... ...
cloud/haikangface/src/main/java/com/sincere/haikangface/QieTuClass.java
1 1 package com.sincere.haikangface;
2 2  
  3 +import com.sincere.haikangface.mqtt.MqtUtils;
3 4 import com.sincere.haikangface.utils.ApiUtil;
4 5 import com.sun.imageio.plugins.common.ImageUtil;
5 6 import org.json.JSONArray;
... ... @@ -11,13 +12,21 @@ import java.awt.image.FilteredImageSource;
11 12 import java.awt.image.ImageFilter;
12 13 import java.io.File;
13 14 import java.io.IOException;
  15 +import java.text.SimpleDateFormat;
  16 +import java.util.Date;
14 17  
15 18 public class QieTuClass extends JFrame {
16 19  
17 20  
18 21 public static void main(String[] args) {
  22 + String imgName = "43539917634D4EED364DEC87D8DEC2462020-09-01.jpg";
  23 + String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
  24 + if (imgName.contains(date)) {
  25 + String imgId = imgName.substring(0, imgName.indexOf(date));
  26 + System.out.println("imgId:"+imgId);
  27 + }
19 28  
20   - new QieTuClass();
  29 +// new QieTuClass();
21 30  
22 31 }
23 32  
... ...
cloud/haikangface/src/main/java/com/sincere/haikangface/async/SendUserAsync.java
... ... @@ -48,6 +48,7 @@ public class SendUserAsync {
48 48 if (check) {//合格
49 49 //根据设备是5603 还是新设备
50 50 String employeeNo = "";
  51 + boolean result = cmsServer.createImgPath(srcFile, picUrl, card, startTime, endTime, validTimeEnabled, name, deviceId, userType, employeeNo);
51 52 if (deviceId.contains("ymzx") || deviceId.contains("5607") || deviceId.contains("5671") || deviceId.contains("5604")) {
52 53 long lon = Long.parseLong(card);
53 54 //十六进制卡号
... ... @@ -67,15 +68,14 @@ public class SendUserAsync {
67 68 } else
68 69 employeeNo = studentBean.getStudent_id();
69 70 }
70   -// cmsServer.SetCardWeekPlan(deviceId, card, userType, HKXmlUtils.getInstance().SetCardTemplate(), "设置卡权限计划模板");
71   -// cmsServer.SetCardWeekPlan(deviceId, card, userType, HKXmlUtils.getInstance().SetCardWeekPlan(), "卡权限周计划");
72   -// for (int i = 0; i < 7; i++) {
73   -// cmsServer.SetCardWeekPlan(deviceId, card, userType, HKXmlUtils.getInstance().SetCardWeekPlanTime(HKXmlUtils.getInstance().SetCardWeekPlanTimes("00:00:00", "23:00:00"), "" + i), "设置卡权限周计划时间");
74   -// }
75   -// cmsServer.SetCardWeekPlan(deviceId, card, userType, HKXmlUtils.getInstance().SetCardRightCfg(card), "设置卡权限");
  71 + cmsServer.SetCardWeekPlan(deviceId, card, userType, HKXmlUtils.getInstance().SetCardTemplate(), "设置卡权限计划模板");
  72 + cmsServer.SetCardWeekPlan(deviceId, card, userType, HKXmlUtils.getInstance().SetCardWeekPlan(), "卡权限周计划");
  73 + for (int i = 0; i < 7; i++) {
  74 + cmsServer.SetCardWeekPlan(deviceId, card, userType, HKXmlUtils.getInstance().SetCardWeekPlanTime(HKXmlUtils.getInstance().SetCardWeekPlanTimes("00:00:00", "23:00:00"), "" + i), "设置卡权限周计划时间");
  75 + }
  76 + cmsServer.SetCardWeekPlan(deviceId, card, userType, HKXmlUtils.getInstance().SetCardRightCfg(card), "设置卡权限");
76 77 }
77 78  
78   - boolean result = cmsServer.createImgPath(srcFile, picUrl, card, startTime, endTime, validTimeEnabled, name, deviceId, userType, employeeNo);
79 79 } else {//不合格
80 80 sendRecoderUtils.sendFail(sendRecordDao, card, srcFile, deviceId, userDao, "人脸照片不合格", userType);
81 81 }
... ...
cloud/haikangface/src/main/java/com/sincere/haikangface/bean/BaiduFaceRecorder.java 0 → 100644
... ... @@ -0,0 +1,78 @@
  1 +package com.sincere.haikangface.bean;
  2 +
  3 +import java.io.Serializable;
  4 +
  5 +public class BaiduFaceRecorder implements Serializable {
  6 +
  7 + private String name;
  8 +
  9 + private String userId;
  10 +
  11 + private String score;
  12 +
  13 + private String time;
  14 +
  15 + private String uploadImgUrl;
  16 +
  17 + private String userImgUrl;
  18 +
  19 + public String getName() {
  20 + return name;
  21 + }
  22 +
  23 + public void setName(String name) {
  24 + this.name = name;
  25 + }
  26 +
  27 + public String getUserId() {
  28 + return userId;
  29 + }
  30 +
  31 + public void setUserId(String userId) {
  32 + this.userId = userId;
  33 + }
  34 +
  35 + public String getScore() {
  36 + return score;
  37 + }
  38 +
  39 + public void setScore(String score) {
  40 + this.score = score;
  41 + }
  42 +
  43 + public String getTime() {
  44 + return time;
  45 + }
  46 +
  47 + public void setTime(String time) {
  48 + this.time = time;
  49 + }
  50 +
  51 + public String getUploadImgUrl() {
  52 + return uploadImgUrl;
  53 + }
  54 +
  55 + public void setUploadImgUrl(String uploadImgUrl) {
  56 + this.uploadImgUrl = uploadImgUrl;
  57 + }
  58 +
  59 + public String getUserImgUrl() {
  60 + return userImgUrl;
  61 + }
  62 +
  63 + public void setUserImgUrl(String userImgUrl) {
  64 + this.userImgUrl = userImgUrl;
  65 + }
  66 +
  67 + @Override
  68 + public String toString() {
  69 + return "BaiduFaceRecorder{" +
  70 + "name='" + name + '\'' +
  71 + ", userId='" + userId + '\'' +
  72 + ", score='" + score + '\'' +
  73 + ", time='" + time + '\'' +
  74 + ", uploadImgUrl='" + uploadImgUrl + '\'' +
  75 + ", userImgUrl='" + userImgUrl + '\'' +
  76 + '}';
  77 + }
  78 +}
... ...
cloud/haikangface/src/main/java/com/sincere/haikangface/bean/TeacherBean.java
... ... @@ -12,6 +12,16 @@ public class TeacherBean implements Serializable {
12 12  
13 13 private String face;
14 14  
  15 + private String time;
  16 +
  17 + public String getTime() {
  18 + return time;
  19 + }
  20 +
  21 + public void setTime(String time) {
  22 + this.time = time;
  23 + }
  24 +
15 25 public String getTeacher_num() {
16 26 return teacher_num;
17 27 }
... ... @@ -57,6 +67,7 @@ public class TeacherBean implements Serializable {
57 67 return "{\"name\":\"" + name + '\"' +
58 68 ", \"teacher_num\":\"" + teacher_num + '\"' +
59 69 ", \"num\":\"" + num + '\"' +
  70 + ",\"time\":\""+time+'\"'+
60 71 ", \"face\":\"" + face + '\"' +"}";
61 72 }
62 73 }
... ...
cloud/haikangface/src/main/java/com/sincere/haikangface/control/UserControl.java
... ... @@ -348,9 +348,8 @@ public class UserControl {
348 348 @RequestMapping(value = "getCard", method = RequestMethod.GET)
349 349 @ApiOperation("获取设备人脸是否存在")
350 350 public boolean getCard(@RequestParam("deviceId") String deviceId, @RequestParam("card") String card) {
351   - cmsServer.getFace(deviceId, Long.parseLong(getCard(card), 16) + "");
352 351 // HttpUtil.getCard(deviceId,card);
353   - return true;
  352 + return cmsServer.getFace(deviceId, Long.parseLong(getCard(card), 16) + "");
354 353 }
355 354  
356 355 @RequestMapping(value = "IsDeviceOnline", method = RequestMethod.GET)
... ...
cloud/haikangface/src/main/java/com/sincere/haikangface/dao/UserDao.java
... ... @@ -248,5 +248,6 @@ public interface UserDao {
248 248  
249 249 List<String> getDeviceRoomRelation(@Param("clint_id") String clint_id);
250 250  
  251 + void insertBaiduFaceRecorder(BaiduFaceRecorder baiduFaceRecorder);
251 252  
252 253 }
... ...
cloud/haikangface/src/main/java/com/sincere/haikangface/mqtt/MqttManager.java
... ... @@ -3,6 +3,7 @@ package com.sincere.haikangface.mqtt;
3 3 import org.eclipse.paho.client.mqttv3.*;
4 4 import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
5 5  
  6 +import java.io.UnsupportedEncodingException;
6 7 import java.security.InvalidKeyException;
7 8 import java.security.NoSuchAlgorithmException;
8 9  
... ... @@ -112,7 +113,12 @@ public class MqttManager {
112 113 String recvClientId = groupId + "@@@" + deviceId;
113 114 final String p2pSendTopic = topic + "/p2p/" + recvClientId;
114 115 String content = "{\"cmd\":\"" + cmd + "\",\"clientId\":\"\",\"data\": " + msg + "}";
115   - MqttMessage message = new MqttMessage(content.getBytes());
  116 + MqttMessage message = null;
  117 + try {
  118 + message = new MqttMessage(content.getBytes("GB2312"));
  119 + } catch (UnsupportedEncodingException e) {
  120 + e.printStackTrace();
  121 + }
116 122 message.setQos(qosLevel);
117 123 System.out.println("发送内容:" + p2pSendTopic + " msg:---------" + msg);
118 124 if (null != mqttClient) {
... ...
cloud/haikangface/src/main/java/com/sincere/haikangface/utils/AlarmUtils.java
1 1 package com.sincere.haikangface.utils;
2 2  
  3 +import com.sincere.haikangface.bean.BaiduFaceRecorder;
3 4 import com.sincere.haikangface.bean.FaceWaterRecoder;
4 5 import com.sincere.haikangface.dao.DeviceDao;
  6 +import com.sincere.haikangface.dao.UserDao;
5 7 import org.springframework.stereotype.Component;
6 8 import org.springframework.util.StringUtils;
7 9  
... ... @@ -17,6 +19,8 @@ public class AlarmUtils {
17 19  
18 20 private DeviceDao deviceDao;
19 21  
  22 + private UserDao userDao;
  23 +
20 24 private AlarmCallBack alarmCallBack;
21 25  
22 26 // public static AlarmUtils getInstance(DeviceDao deviceDao) {
... ... @@ -28,8 +32,9 @@ public class AlarmUtils {
28 32 // return alarmUtils;
29 33 // }
30 34  
31   - public AlarmUtils(DeviceDao deviceDao) {
  35 + public AlarmUtils(DeviceDao deviceDao, UserDao userDao) {
32 36 this.deviceDao = deviceDao;
  37 + this.userDao = userDao;
33 38 }
34 39  
35 40 public void setCallBack(AlarmCallBack alarmCallBack) {
... ... @@ -41,9 +46,22 @@ public class AlarmUtils {
41 46 }
42 47  
43 48 public void deleAlarm(String strXML) {
44   -
  49 + System.out.println("人脸抓拍机:" + strXML);
45 50 if (strXML.contains("FACESNAPREPORT")) {//人脸抓拍机器
46 51  
  52 +// System.out.println("人脸抓拍机:" + strXML);
  53 + BaiduFaceRecorder baiduFaceRecorder = new BaiduFaceRecorder();
  54 + baiduFaceRecorder.setUploadImgUrl(strXML);
  55 + baiduFaceRecorder.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
  56 + userDao.insertBaiduFaceRecorder(baiduFaceRecorder);
  57 +
  58 + String deviceId = strXML.substring(strXML.indexOf("DeviceID"),strXML.lastIndexOf("DeviceID")).trim();
  59 + deviceId = deviceId.replace("DeviceID>","");
  60 + deviceId = deviceId.replace("</","");
  61 +
  62 +// if (null != alarmCallBack)
  63 +// alarmCallBack.callBack(minorType, deviceID, cardNo, time, picDataUrlId, currTemperature);
  64 +
47 65 } else {//人脸识别
48 66  
49 67 //主类型
... ...
cloud/haikangface/src/main/resources/mapper/usermapper.xml
... ... @@ -22,4 +22,9 @@
22 22 select clint_id from SZ_DeviceRoomRelation where clint_id = #{clint_id} and state = 1;
23 23 </select>
24 24  
  25 + <insert id="insertBaiduFaceRecorder" parameterType="com.sincere.haikangface.bean.BaiduFaceRecorder">
  26 +
  27 + insert into BaiduFaceRecorder values (#{name},#{userId},#{score},#{time},#{uploadImgUrl},#{userImgUrl})
  28 +
  29 + </insert>
25 30 </mapper>
... ...