From 623099fe3b1eefc4c587adbb1038f01e833caba4 Mon Sep 17 00:00:00 2001 From: xuquan <1099815072@qq.com> Date: Mon, 14 Feb 2022 08:10:19 +0800 Subject: [PATCH] 大华设备对接艺校考勤 --- cloud/dahua/src/main/java/com/example/dahua/MyTask.java | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------ cloud/dahua/src/main/java/com/example/dahua/control/UserControl.java | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- cloud/dahua/src/main/java/com/example/dahua/control/sxyx/SxyxOaControl.java | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ cloud/dahua/src/main/java/com/example/dahua/dao/UserDao.java | 6 ++++++ cloud/dahua/src/main/java/com/example/dahua/service/UserService.java | 4 ++++ cloud/dahua/src/main/java/com/example/dahua/service/imp/UserServiceImp.java | 10 ++++++++++ cloud/haikangface/src/main/java/com/sincere/haikangface/control/UserOperateController.java | 9 +++++++++ 7 files changed, 278 insertions(+), 63 deletions(-) create mode 100644 cloud/dahua/src/main/java/com/example/dahua/control/sxyx/SxyxOaControl.java diff --git a/cloud/dahua/src/main/java/com/example/dahua/MyTask.java b/cloud/dahua/src/main/java/com/example/dahua/MyTask.java index b24a189..3a1e890 100644 --- a/cloud/dahua/src/main/java/com/example/dahua/MyTask.java +++ b/cloud/dahua/src/main/java/com/example/dahua/MyTask.java @@ -1,5 +1,7 @@ package com.example.dahua; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.example.dahua.bean.*; import com.example.dahua.dao.UserDao; import com.example.dahua.enums.EnumDeviceType; @@ -25,8 +27,15 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; +import org.springframework.web.client.RestTemplate; import javax.annotation.PostConstruct; import javax.imageio.ImageIO; @@ -38,6 +47,7 @@ import java.io.UnsupportedEncodingException; import java.text.SimpleDateFormat; import java.util.*; import java.util.concurrent.CopyOnWriteArrayList; +import java.util.stream.Collectors; @Component @Slf4j @@ -388,7 +398,6 @@ public class MyTask implements ApplicationRunner { if (lAnalyzerHandle.longValue() == 0 || pAlarmInfo == null) { return -1; } - byte[] bufferBytes = new byte[dwBufSize]; pBuffer.read(0, bufferBytes, 0, dwBufSize); File path = new File(".\\FaceRecoder"); @@ -399,14 +408,6 @@ public class MyTask implements ApplicationRunner { CDevInfo data = new CDevInfo(); ToolKits.GetPointerData(dwUser, data); String szSn = new String(data.szSN).trim(); -// if(dwAlarmType == NetSDKLib.EVENT_IVS_FACERECOGNITION){ -//// ToolKits.GetPointerData(pAlarmInfo, msg); -//// //卡号 -//// String card = new String(msg.szCardNo).trim(); -//// //开门用户 -//// String userId = new String(msg.szUID).trim(); -//// log.info("你来了。。。。"); -// } ///< 门禁事件 if (dwAlarmType == NetSDKLib.EVENT_IVS_ACCESS_CTL) { NetSDKLib.DEV_EVENT_ACCESS_CTL_INFO msg = new NetSDKLib.DEV_EVENT_ACCESS_CTL_INFO(); @@ -423,66 +424,70 @@ public class MyTask implements ApplicationRunner { saveAttendanceService(szSn,"",0,1); try { if (!StringUtils.isEmpty(card)) { - // 保存图片,获取图片缓存 - // 图片服务器路径 - String snapPicPath = path + "\\" + System.currentTimeMillis() + ".png"; + //根据卡号获取卡身份信息 + CardBean cardBean = myTaskUtil.userDao.getCards(card); + if(cardBean ==null){ + card = cardNo(card); + cardBean = myTaskUtil.userDao.getCards(card); + } + if(cardBean ==null){ + return -1; + } + + // 缓存抓拍人脸 + String fileName = StringUtils.isEmpty(userId)? card + ".png" : userId + ".png"; + String snapPicPath = path + "\\" + fileName; byte[] buffer = pBuffer.getByteArray(0, dwBufSize); ByteArrayInputStream byteArrInputGlobal = new ByteArrayInputStream(buffer); gateBufferedImage = ImageIO.read(byteArrInputGlobal); if (gateBufferedImage != null) { ImageIO.write(gateBufferedImage, "png", new File(snapPicPath)); } - int schoolId=0; - int outOrIn =0; - AttendanceBean attendanceBean = myTaskUtil.userDao.getTypeByClint_id(szSn); - if(attendanceBean !=null){ - if(org.apache.commons.lang.StringUtils.isNotBlank(attendanceBean.getSchool_id())){ - schoolId=Integer.parseInt(attendanceBean.getSchool_id()); - outOrIn= StringUtils.isEmpty(attendanceBean.getOutOrIn())?0:Integer.parseInt(attendanceBean.getOutOrIn()); - } - } - /** - * 卡号取反(大写) - * 注:若设备为一体机、且非"126上虞城东小学、393上虞实验中学"学校,卡则取反 - */ - if(szSn.startsWith("ytj")&&schoolId!=126&&schoolId!=393){ - card = card; - } else{ - card = cardNo(card); - } - //根据卡号获取卡身份信息 - CardBean cardBean = myTaskUtil.userDao.getCards(card); - String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); snapPicPath = snapPicPath.replaceFirst("\\.", "http://121.40.109.21:8991"); snapPicPath = snapPicPath.replace("FaceRecoder", "image"); - if (null != cardBean && cardBean.getType() == 0) { - //老师人脸信息,保存人脸记录表 - TeacherBean teacherBean = myTaskUtil.userDao.getTeacherWithId(cardBean.getUser_id()); - myTaskUtil.sendRecordDao.addFaceRecoder(szSn, teacherBean.getUser_id(), teacherBean.getName(), snapPicPath,outOrIn, - time, card,messageCode ==20?EnumSendFaceType.TIME_INTERVAL_ERROR.message:""); - } else if (null != cardBean && cardBean.getType() == 2) { - //学生人脸信息,保存人脸记录表 - UserInfoBean userInfoBean = myTaskUtil.userDao.getStudentWithid(cardBean.getUser_id()); - myTaskUtil.sendRecordDao.addFaceRecoder(szSn, userInfoBean.getUser_id(), userInfoBean.getName(), snapPicPath,outOrIn, - time, card,messageCode ==20?EnumSendFaceType.TIME_INTERVAL_ERROR.message:""); - } - if(szSn.startsWith("ytj")) { - //门禁进出类型:1进0出 - int eventType = EnumSzBusinessType.EnumDeviceInAndOut.INT.code; - if(StringUtils.isEmpty(attendanceBean.getOutOrIn())){ - eventType = EnumSzBusinessType.EnumDeviceInAndOut.INT.code; - } - if(Integer.parseInt(attendanceBean.getOutOrIn()) != EnumSzBusinessType.EnumDeviceInAndOut.INT.code){ - eventType = EnumSzBusinessType.EnumDeviceInAndOut.OUT.code; + //关联设备信息 + AttendanceBean attendanceBean = myTaskUtil.userDao.getTypeByClint_id(szSn); + if(attendanceBean !=null){ + if(StringUtils.isEmpty(attendanceBean.getSchool_id())){ + int schoolId = Integer.parseInt(attendanceBean.getSchool_id()); + //门禁进出类型:1进0出 + int eventType = 0; + if(StringUtils.isEmpty(attendanceBean.getOutOrIn())){ + eventType = EnumSzBusinessType.EnumDeviceInAndOut.OUT.code; + }else{ + eventType = Integer.parseInt(attendanceBean.getOutOrIn()); + } + //刷卡时间 + String eventTime = DateUtils.date2String(new Date(), DateUtils.format2); + //老师 + if (cardBean.getType() == 0) { + //老师人脸信息,保存人脸记录表 + TeacherBean teacherBean = myTaskUtil.userDao.getTeacherWithId(cardBean.getUser_id()); + myTaskUtil.sendRecordDao.addFaceRecoder(szSn, teacherBean.getUser_id(), teacherBean.getName(), snapPicPath,eventType, + eventTime, card,messageCode ==20?EnumSendFaceType.TIME_INTERVAL_ERROR.message:""); + } + UserInfoBean userInfoBean = null; + if (cardBean.getType() == 2) { + //学生人脸信息,保存人脸记录表 + userInfoBean = myTaskUtil.userDao.getStudentWithid(cardBean.getUser_id()); + myTaskUtil.sendRecordDao.addFaceRecoder(szSn, userInfoBean.getUser_id(), userInfoBean.getName(), snapPicPath,eventType, + eventTime, card,messageCode ==20?EnumSendFaceType.TIME_INTERVAL_ERROR.message:""); + } + + // TODO 考勤记录 + //刷卡结果,1表示成功, 0表示失败 + int status = msg.bStatus; + + if(szSn.startsWith("ytj")) { + //保存考勤记录 + kaoQinRecord(status, eventType, card, szSn, eventTime,lAnalyzerHandle); + // 艺校考勤 + if(schoolId ==12 && status ==1){ + int intOrOut = eventType ==1? 1 : 2; + sendRecordToSXYX(userInfoBean.getName(),userInfoBean.getUser_id(),intOrOut,eventTime); + } + } } - // TODO 考勤记录 - //刷卡结果,1表示成功, 0表示失败 - int status = msg.bStatus; - //刷卡时间 - String eventTime = DateUtils.date2String(new Date(), DateUtils.format2); - - //保存考勤记录 - kaoQinRecord(status, eventType, card, szSn, eventTime,lAnalyzerHandle); } } } catch (IOException e2) { @@ -765,6 +770,25 @@ public class MyTask implements ApplicationRunner { return true; } + public static void sendRecordToSXYX(String name,String userId,int intOrOut,String eventTime) { + try { + String api = "http://yixiao.198.hmkj.com.cn/index.php/Attend/send"; + RestTemplate restTemplate = new RestTemplate(); + MultiValueMap map = new LinkedMultiValueMap<>(); + map.add("name", name); + map.add("xuehao", userId); + map.add("time", eventTime); + map.add("state", intOrOut); + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + HttpEntity> param = new HttpEntity<>(map, headers); + ResponseEntity response = restTemplate.postForEntity(api, param, String.class); + String body = response.getBody(); + System.out.println(body); + } catch (Exception e) { + sendRecordToSXYX(name,userId,intOrOut,eventTime); + } + } } diff --git a/cloud/dahua/src/main/java/com/example/dahua/control/UserControl.java b/cloud/dahua/src/main/java/com/example/dahua/control/UserControl.java index 00ad6d7..536fbe7 100644 --- a/cloud/dahua/src/main/java/com/example/dahua/control/UserControl.java +++ b/cloud/dahua/src/main/java/com/example/dahua/control/UserControl.java @@ -2,9 +2,10 @@ package com.example.dahua.control; import com.example.dahua.MyTask; import com.example.dahua.async.SendUserInfoTask; -import com.example.dahua.bean.PermissionBean; -import com.example.dahua.bean.SendRecordBean; -import com.example.dahua.bean.StudentBean; +import com.example.dahua.bean.*; +import com.example.dahua.bean.yx.Result; +import com.example.dahua.bean.yx.ResultGenerator; +import com.example.dahua.bean.yx.StudentInfo; import com.example.dahua.dao.UserDao; import com.example.dahua.enums.EnumSzBusinessType; import com.example.dahua.lib.CompressPic; @@ -13,6 +14,7 @@ import com.example.dahua.service.UserService; import com.example.dahua.service.imp.BaseService; import com.example.dahua.utils.*; import com.example.dahua.xiananDao.SendRecordDao; +import com.google.gson.Gson; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -21,7 +23,13 @@ import lombok.extern.slf4j.Slf4j; import org.json.JSONException; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.util.CollectionUtils; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; import org.springframework.web.client.RestTemplate; @@ -455,4 +463,63 @@ public class UserControl { } } + @RequestMapping(value = "getStudent", method = RequestMethod.GET) + @ApiOperation("艺校对账查询") + @ResponseBody + public Result queryStudent(@RequestHeader("code") String code) { + if(StringUtils.isEmpty(code) || !code.equals("sxyx")){ + return ResultGenerator.genFailResult("请求标识匹配错误"); + } + List students = userService.getStudent(12); + if(CollectionUtils.isEmpty(students)){ + return ResultGenerator.genSuccessResult(); + } + StudentInfo info = new StudentInfo(); + List studentList = new ArrayList<>(); + students.stream().distinct().forEach(s->{ + StudentInfo.Student student = new StudentInfo.Student(); + student.setUserName(s.getName()); + student.setStudentCode(s.getUser_id()); + studentList.add(student); + }); + info.setTotal(students.size()); + info.setStudentList(studentList); + return ResultGenerator.genSuccessResult(new Gson().toJson(info)); + } + + @RequestMapping(value = "syncStudent", method = RequestMethod.GET) + @ApiOperation("艺校对账新增") + @ResponseBody + public Result syncStudent(@RequestParam("userId") String userId) { + if(StringUtils.isEmpty(userId)){ + return ResultGenerator.genFailResult("参数为空"); + } + UserInfoBean student = userService.getStudentByUserId(userId); + if(student ==null){ + return ResultGenerator.genFailResult("此学生不存在"); + } + sendRecordToSXYX(student.getName(),userId); + return ResultGenerator.genSuccessResult(); + } + + public static String sendRecordToSXYX(String name,String userId) { + String result = ""; + try { + String api = "http://yixiao.198.hmkj.com.cn/index.php/Attend/student"; + RestTemplate restTemplate = new RestTemplate(); + MultiValueMap map = new LinkedMultiValueMap<>(); + map.add("name", name); + map.add("xuehao", userId); + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + HttpEntity> param = new HttpEntity<>(map, headers); + ResponseEntity response = restTemplate.postForEntity(api, param, String.class); + result = response.getBody(); + System.out.println(result); + } catch (Exception e) { + sendRecordToSXYX(name,userId); + } + return result; + } + } diff --git a/cloud/dahua/src/main/java/com/example/dahua/control/sxyx/SxyxOaControl.java b/cloud/dahua/src/main/java/com/example/dahua/control/sxyx/SxyxOaControl.java new file mode 100644 index 0000000..05fe8b7 --- /dev/null +++ b/cloud/dahua/src/main/java/com/example/dahua/control/sxyx/SxyxOaControl.java @@ -0,0 +1,95 @@ +package com.example.dahua.control.sxyx; + +import com.example.dahua.bean.UserInfoBean; +import com.example.dahua.bean.yx.Result; +import com.example.dahua.bean.yx.ResultGenerator; +import com.example.dahua.bean.yx.StudentInfo; +import com.example.dahua.service.UserService; +import com.google.gson.Gson; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.util.CollectionUtils; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.RestTemplate; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@RestController +@Api(tags = "绍兴艺校对外接口") +@RequestMapping("/sxyx/student") +public class SxyxOaControl { + + @Autowired + UserService userService; + + @RequestMapping(value = "/getStudent", method = RequestMethod.GET) + @ApiOperation("艺校对账查询") + @ResponseBody + public Result queryStudent(@RequestHeader("code") String code) { + if(StringUtils.isEmpty(code) || !code.equals("sxyx")){ + return ResultGenerator.genFailResult("请求标识匹配错误"); + } + List students = userService.getStudent(12); + if(CollectionUtils.isEmpty(students)){ + return ResultGenerator.genSuccessResult(); + } + StudentInfo info = new StudentInfo(); + List studentList = new ArrayList<>(); + students.stream().distinct().forEach(s->{ + StudentInfo.Student student = new StudentInfo.Student(); + student.setUserName(s.getName()); + student.setStudentCode(s.getUser_id()); + studentList.add(student); + }); + info.setTotal(students.size()); + info.setStudentList(studentList); + return ResultGenerator.genSuccessResult(new Gson().toJson(info)); + } + + @RequestMapping(value = "/syncStudent", method = RequestMethod.GET) + @ApiOperation("艺校对账新增") + @ResponseBody + public Result syncStudent(@RequestParam("userId") String userId) { + if(StringUtils.isEmpty(userId)){ + return ResultGenerator.genFailResult("参数为空"); + } + UserInfoBean student = userService.getStudentByUserId(userId); + if(student ==null){ + return ResultGenerator.genFailResult("此学生不存在"); + } + sendRecordToSXYX(student.getName(),userId); + return ResultGenerator.genSuccessResult(); + } + + public static String sendRecordToSXYX(String name,String userId) { + String result = ""; + try { + String api = "http://yixiao.198.hmkj.com.cn/index.php/Attend/student"; + RestTemplate restTemplate = new RestTemplate(); + MultiValueMap map = new LinkedMultiValueMap<>(); + map.add("name", name); + map.add("xuehao", userId); + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + HttpEntity> param = new HttpEntity<>(map, headers); + ResponseEntity response = restTemplate.postForEntity(api, param, String.class); + result = response.getBody(); + System.out.println(result); + } catch (Exception e) { + sendRecordToSXYX(name,userId); + } + return result; + } + +} diff --git a/cloud/dahua/src/main/java/com/example/dahua/dao/UserDao.java b/cloud/dahua/src/main/java/com/example/dahua/dao/UserDao.java index 54e3cf0..ce21ad7 100644 --- a/cloud/dahua/src/main/java/com/example/dahua/dao/UserDao.java +++ b/cloud/dahua/src/main/java/com/example/dahua/dao/UserDao.java @@ -94,12 +94,18 @@ public interface UserDao { @Select(" select top 1* from SZ_V_School_Student where student_id = #{student_id}") UserInfoBean getStudentWithid(@Param("student_id") String student_id); + @Select(" select top 1* from SZ_V_School_Student where user_id = #{userId}") + UserInfoBean getStudentByUserId(@Param("userId") String userId); + @Select(" select * from SZ_V_School_Student where student_num = #{student_num} and name = #{name}") UserInfoBean getStudent(@Param("student_num") String student_num, @Param("name") String name); @Select(" select * from SZ_V_School_Student where school_id = #{school_id} and sex = #{sex} and student_type = #{student_type}") List getStudentWithSchoolId(@Param("school_id") String school_id, @Param("sex") String sex, @Param("student_type") String student_type); + @Select(" select * from SZ_V_School_Student where school_id = #{school_id}") + List getStudentBySchoolId(@Param("school_id") Integer school_id); + @Select("select * from SZ_V_School_Student where school_id = 479 and student_type = 2") List getUsers(); diff --git a/cloud/dahua/src/main/java/com/example/dahua/service/UserService.java b/cloud/dahua/src/main/java/com/example/dahua/service/UserService.java index 1083ecc..a158ba7 100644 --- a/cloud/dahua/src/main/java/com/example/dahua/service/UserService.java +++ b/cloud/dahua/src/main/java/com/example/dahua/service/UserService.java @@ -67,4 +67,8 @@ public interface UserService { * @param url */ void test(String url); + + List getStudent(Integer schoolId); + + UserInfoBean getStudentByUserId(String userId); } diff --git a/cloud/dahua/src/main/java/com/example/dahua/service/imp/UserServiceImp.java b/cloud/dahua/src/main/java/com/example/dahua/service/imp/UserServiceImp.java index 126c3a6..1107fee 100644 --- a/cloud/dahua/src/main/java/com/example/dahua/service/imp/UserServiceImp.java +++ b/cloud/dahua/src/main/java/com/example/dahua/service/imp/UserServiceImp.java @@ -182,4 +182,14 @@ public class UserServiceImp implements UserService { } } } + + @Override + public List getStudent(Integer schoolId) { + return userDao.getStudentBySchoolId(schoolId); + } + + @Override + public UserInfoBean getStudentByUserId(String userId) { + return userDao.getStudentByUserId(userId); + } } diff --git a/cloud/haikangface/src/main/java/com/sincere/haikangface/control/UserOperateController.java b/cloud/haikangface/src/main/java/com/sincere/haikangface/control/UserOperateController.java index 634030f..9f933c8 100644 --- a/cloud/haikangface/src/main/java/com/sincere/haikangface/control/UserOperateController.java +++ b/cloud/haikangface/src/main/java/com/sincere/haikangface/control/UserOperateController.java @@ -145,4 +145,13 @@ public class UserOperateController { @RequestParam(value = "deviceIds",required = false) String deviceIds){ return userOperateService.deleteFaceBySchoolId(schoolId,deviceIds); } + + + public static void main(String[] args) { + String photo = "http://campus.myjxt.com//f0i5l7e5/0/alluser/20171008/aa26754eb6f24fceb8881d50ee37cdf3.jpg"; + //以学籍号为名的文件名 + String fileName = photo.substring(photo.lastIndexOf("/") + 1,photo.length()); + System.out.println(fileName); + System.out.println(fileName.split(".")[0]); + } } -- libgit2 0.21.0