Commit 60fd0445b2bc67a76d65ce9bc4d2a0a6ada43791
1 parent
89a4775c
Exists in
master
智能校卫:海康、大华人脸机代码提交
Showing
6 changed files
with
113 additions
and
20 deletions
Show diff stats
cloud/dahua/src/main/java/com/example/dahua/service/imp/UserOperateServiceImpl.java
@@ -110,16 +110,6 @@ public class UserOperateServiceImpl implements UserOperateService { | @@ -110,16 +110,6 @@ public class UserOperateServiceImpl implements UserOperateService { | ||
110 | } | 110 | } |
111 | } | 111 | } |
112 | 112 | ||
113 | - public static void main(String[] args) { | ||
114 | - String photo = "http://campus.myjxt.com//f0i5l7e5/0/alluser/20210114/430f64e104ea4a7bb7f78f0e42b3fad8.jpg"; | ||
115 | - System.out.println(photo.indexOf("f0i5l7e5")!=-1); | ||
116 | - String path = photo.split("f0i5l7e5/")[1]; | ||
117 | - path= path.replace("/","\\"); | ||
118 | - System.out.println("E:\\wwwhtdocs\\SmartCampus\\f0i5l7e5\\"+path); | ||
119 | -// System.out.println(photo.split("f0i5l7e5/")[1]); | ||
120 | -// System.out.println(photo.split("f0i5l7e5/")[0]); | ||
121 | - } | ||
122 | - | ||
123 | @Override | 113 | @Override |
124 | public void test6(Integer schoolId, Integer roomId, Integer type, Integer outof, String intime, String clintId, String startTime, String endTime) { | 114 | public void test6(Integer schoolId, Integer roomId, Integer type, Integer outof, String intime, String clintId, String startTime, String endTime) { |
125 | List<String> studentIds = userDao.queryStudentIdList(schoolId,roomId); | 115 | List<String> studentIds = userDao.queryStudentIdList(schoolId,roomId); |
cloud/fIle-center/pom.xml
@@ -42,6 +42,12 @@ | @@ -42,6 +42,12 @@ | ||
42 | <artifactId>aliyun-sdk-oss</artifactId> | 42 | <artifactId>aliyun-sdk-oss</artifactId> |
43 | <version>2.8.3</version> | 43 | <version>2.8.3</version> |
44 | </dependency> | 44 | </dependency> |
45 | + <!-- 常用依赖库--> | ||
46 | + <dependency> | ||
47 | + <groupId>com.google.code.gson</groupId> | ||
48 | + <artifactId>gson</artifactId> | ||
49 | + <version>2.8.6</version> | ||
50 | + </dependency> | ||
45 | 51 | ||
46 | <dependency> | 52 | <dependency> |
47 | <groupId>org.apache.poi</groupId> | 53 | <groupId>org.apache.poi</groupId> |
cloud/haikangface/src/main/java/com/sincere/haikangface/CMSServer.java
@@ -26,6 +26,7 @@ import com.sun.jna.Pointer; | @@ -26,6 +26,7 @@ import com.sun.jna.Pointer; | ||
26 | import lombok.extern.slf4j.Slf4j; | 26 | import lombok.extern.slf4j.Slf4j; |
27 | import org.apache.http.util.TextUtils; | 27 | import org.apache.http.util.TextUtils; |
28 | import org.springframework.beans.factory.annotation.Autowired; | 28 | import org.springframework.beans.factory.annotation.Autowired; |
29 | +import org.springframework.beans.factory.annotation.Value; | ||
29 | import org.springframework.boot.ApplicationArguments; | 30 | import org.springframework.boot.ApplicationArguments; |
30 | import org.springframework.boot.ApplicationRunner; | 31 | import org.springframework.boot.ApplicationRunner; |
31 | import org.springframework.stereotype.Component; | 32 | import org.springframework.stereotype.Component; |
@@ -67,7 +68,7 @@ public class CMSServer implements ApplicationRunner { | @@ -67,7 +68,7 @@ public class CMSServer implements ApplicationRunner { | ||
67 | //114.55.30.100 | 68 | //114.55.30.100 |
68 | //120.26.116.253 | 69 | //120.26.116.253 |
69 | // private String ip_cloud = "114.55.30.100"; | 70 | // private String ip_cloud = "114.55.30.100"; |
70 | - private String ip_cloud = "120.26.116.253"; | 71 | + private String ip_cloud = "114.55.30.100"; |
71 | 72 | ||
72 | private String ip; | 73 | private String ip; |
73 | { | 74 | { |
cloud/haikangface/src/main/java/com/sincere/haikangface/control/UserOperateController.java
@@ -114,4 +114,13 @@ public class UserOperateController { | @@ -114,4 +114,13 @@ public class UserOperateController { | ||
114 | return userOperateService.insertUpdateCard(cardNums); | 114 | return userOperateService.insertUpdateCard(cardNums); |
115 | } | 115 | } |
116 | 116 | ||
117 | + | ||
118 | + @ApiOperation(value = "压缩包上传下发") | ||
119 | + @RequestMapping(value = "exportFace", method = RequestMethod.POST) | ||
120 | + public Result exportFace(@RequestParam("schoolId") Integer schoolId, | ||
121 | + @RequestParam("userType") Integer userType, | ||
122 | + @RequestParam("deviceIds") String deviceIds, | ||
123 | + @RequestParam("faceSrcPath") String faceSrcPath){ | ||
124 | + return userOperateService.exportFace(schoolId,userType,deviceIds,faceSrcPath); | ||
125 | + } | ||
117 | } | 126 | } |
cloud/haikangface/src/main/java/com/sincere/haikangface/service/UserOperateService.java
@@ -104,4 +104,5 @@ public interface UserOperateService { | @@ -104,4 +104,5 @@ public interface UserOperateService { | ||
104 | 104 | ||
105 | Result insertUpdateCard(String cardNums); | 105 | Result insertUpdateCard(String cardNums); |
106 | 106 | ||
107 | + Result exportFace(Integer schoolId,Integer userType,String deviceIds,String faceSrcPath); | ||
107 | } | 108 | } |
cloud/haikangface/src/main/java/com/sincere/haikangface/service/impl/UserOperateServiceImpl.java
@@ -21,8 +21,10 @@ import org.springframework.stereotype.Service; | @@ -21,8 +21,10 @@ import org.springframework.stereotype.Service; | ||
21 | import org.springframework.web.multipart.MultipartFile; | 21 | import org.springframework.web.multipart.MultipartFile; |
22 | 22 | ||
23 | import java.io.File; | 23 | import java.io.File; |
24 | +import java.io.FileInputStream; | ||
24 | import java.io.FileOutputStream; | 25 | import java.io.FileOutputStream; |
25 | import java.io.IOException; | 26 | import java.io.IOException; |
27 | +import java.nio.file.Files; | ||
26 | import java.util.*; | 28 | import java.util.*; |
27 | 29 | ||
28 | /** | 30 | /** |
@@ -626,15 +628,6 @@ public class UserOperateServiceImpl implements UserOperateService { | @@ -626,15 +628,6 @@ public class UserOperateServiceImpl implements UserOperateService { | ||
626 | } | 628 | } |
627 | } | 629 | } |
628 | 630 | ||
629 | - public static void main(String[] args) { | ||
630 | - String s = "E:\\wwwhtdocs\\SmartCampus\\face17e5\\School386\\Student\\sxzx2020467.png?v=1601037209723"; | ||
631 | - if(s.indexOf("?v=")!=-1){ | ||
632 | - System.out.println(1); | ||
633 | - String fileName = s.split("\\?")[0]; | ||
634 | - System.out.println(fileName); | ||
635 | - } | ||
636 | - } | ||
637 | - | ||
638 | @Override | 631 | @Override |
639 | public Result againNoSendOneFace(MultipartFile file, Integer schoolId, String cardNum, Integer userType, String deviceIds) { | 632 | public Result againNoSendOneFace(MultipartFile file, Integer schoolId, String cardNum, Integer userType, String deviceIds) { |
640 | if(StringUtils.isBlank(cardNum)){ | 633 | if(StringUtils.isBlank(cardNum)){ |
@@ -740,4 +733,97 @@ public class UserOperateServiceImpl implements UserOperateService { | @@ -740,4 +733,97 @@ public class UserOperateServiceImpl implements UserOperateService { | ||
740 | } | 733 | } |
741 | return new Result(); | 734 | return new Result(); |
742 | } | 735 | } |
736 | + | ||
737 | + @Override | ||
738 | + public Result exportFace(Integer schoolId,Integer userType,String deviceIds,String faceSrcPath) { | ||
739 | + File imgPathFile = new File(faceSrcPath);//目录 | ||
740 | + File[] imgfiles = imgPathFile.listFiles(); | ||
741 | + if(imgfiles.length==0){ | ||
742 | + return ResultGenerator.genFailResult("未获取要下发的人脸照片。"); | ||
743 | + } | ||
744 | + List<StudentBean> sendFaces = new ArrayList<>(); | ||
745 | + for (int i = 0; i < imgfiles.length; i++) { | ||
746 | + //人脸照片 | ||
747 | + File file = imgfiles[i]; | ||
748 | + if(!file.isFile()){ | ||
749 | + continue; | ||
750 | + } | ||
751 | + if (file.exists()){ | ||
752 | + //原始文件路径 | ||
753 | + String srcPath = file.getAbsolutePath(); | ||
754 | + //原始文件名 | ||
755 | + String fileName = file.getName(); | ||
756 | + StudentBean studentBean = new StudentBean(); | ||
757 | + if (userType.intValue()==1) { | ||
758 | + studentBean = userDao.getTeacherWithstudentcode(fileName.split("\\.")[0],String.valueOf(schoolId)); | ||
759 | + }else { | ||
760 | + studentBean = userDao.getStudentWithstudentcode(fileName.split("\\.")[0],String.valueOf(schoolId)); | ||
761 | + } | ||
762 | + String typeName = userType.intValue() ==1 ? "Teacher" : "Student"; | ||
763 | + String targetPath = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\" + typeName; | ||
764 | +// //目标路径 | ||
765 | + targetPath = targetPath + "\\" + fileName; | ||
766 | + //复制文件 | ||
767 | + copy(srcPath,targetPath); | ||
768 | + String savePath = "http://campus.myjxt.com//face17e50/School"+ schoolId + "/" + typeName + "/" + fileName; | ||
769 | + if(userType.intValue() ==1){ | ||
770 | + studentBean.setFace(savePath); | ||
771 | + }else { | ||
772 | + studentBean.setPhoto(savePath); | ||
773 | + } | ||
774 | + //savePath | ||
775 | + userDao.updateUser(studentBean.getUser_id(),savePath); | ||
776 | + sendFaces.add(studentBean); | ||
777 | + } | ||
778 | + file.delete(); | ||
779 | + } | ||
780 | + if(StringUtils.isBlank(deviceIds)){ | ||
781 | + return ResultGenerator.genFailResult("未选择下发设备"); | ||
782 | + } | ||
783 | + String[] deviceArr = deviceIds.split(","); | ||
784 | + List<String> deviceList = new ArrayList<>(Arrays.asList(deviceArr)); | ||
785 | + //异步执行下发 | ||
786 | + asyncSendFace(sendFaces,deviceList,schoolId,userType); | ||
787 | + int fileSize = sendFaces.size(); | ||
788 | + int clintNum = deviceList.size(); | ||
789 | + //下发所用时长 | ||
790 | + int timeLength = new Double(clintNum * fileSize * 0.06).intValue(); | ||
791 | + //下发截止时间 | ||
792 | + String dateStr = baseService.getTime(fileSize,clintNum,timeLength); | ||
793 | + Map map = new HashMap(); | ||
794 | + map.put("timeLength",timeLength); | ||
795 | + map.put("afterDate",dateStr); | ||
796 | + map.put("fileSize",fileSize); | ||
797 | + return ResultGenerator.genSuccessResult(objectMapper.toJson(map)); | ||
798 | + } | ||
799 | + | ||
800 | + public void asyncSendFace(List<StudentBean> sendFaces,List<String> deviceList,Integer schoolId,Integer userType){ | ||
801 | + log.info("总共检测到:{},张人脸照片。",sendFaces.size()); | ||
802 | + //设备类型 | ||
803 | + Integer clintType = userDao.getClintTypeByDeviceId(deviceList.get(0)); | ||
804 | + if(clintType.intValue()== 18 || clintType.intValue()== 28){ | ||
805 | + //发送海康设备:异步执行 | ||
806 | + baseService.sendUserFaceByAsyncThread(schoolId,userType,sendFaces,deviceList); | ||
807 | + } | ||
808 | + } | ||
809 | + | ||
810 | + private static void copy(String srcPathStr, String desPathStr) { | ||
811 | + //获取源文件的名称 | ||
812 | + try { | ||
813 | + FileInputStream fis = new FileInputStream(srcPathStr);//创建输入流对象 | ||
814 | + FileOutputStream fos = new FileOutputStream(desPathStr); //创建输出流对象 | ||
815 | + byte datas[] = new byte[1024*8];//创建搬运工具 | ||
816 | + int len = 0;//创建长度 | ||
817 | + while((len = fis.read(datas))!=-1)//循环读取数据 | ||
818 | + { | ||
819 | + fos.write(datas,0,len); | ||
820 | + } | ||
821 | + fis.close();//释放资源 | ||
822 | + fis.close();//释放资源 | ||
823 | + } | ||
824 | + catch (Exception e) | ||
825 | + { | ||
826 | + e.printStackTrace(); | ||
827 | + } | ||
828 | + } | ||
743 | } | 829 | } |