From 60fd0445b2bc67a76d65ce9bc4d2a0a6ada43791 Mon Sep 17 00:00:00 2001 From: XuQuan <1099815072@qq.com> Date: Wed, 1 Sep 2021 14:26:50 +0800 Subject: [PATCH] 智能校卫:海康、大华人脸机代码提交 --- cloud/dahua/src/main/java/com/example/dahua/service/imp/UserOperateServiceImpl.java | 10 ---------- cloud/fIle-center/pom.xml | 6 ++++++ cloud/haikangface/src/main/java/com/sincere/haikangface/CMSServer.java | 3 ++- cloud/haikangface/src/main/java/com/sincere/haikangface/control/UserOperateController.java | 9 +++++++++ cloud/haikangface/src/main/java/com/sincere/haikangface/service/UserOperateService.java | 1 + cloud/haikangface/src/main/java/com/sincere/haikangface/service/impl/UserOperateServiceImpl.java | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 6 files changed, 113 insertions(+), 20 deletions(-) diff --git a/cloud/dahua/src/main/java/com/example/dahua/service/imp/UserOperateServiceImpl.java b/cloud/dahua/src/main/java/com/example/dahua/service/imp/UserOperateServiceImpl.java index f530b1a..d63dec2 100644 --- a/cloud/dahua/src/main/java/com/example/dahua/service/imp/UserOperateServiceImpl.java +++ b/cloud/dahua/src/main/java/com/example/dahua/service/imp/UserOperateServiceImpl.java @@ -110,16 +110,6 @@ public class UserOperateServiceImpl implements UserOperateService { } } - public static void main(String[] args) { - String photo = "http://campus.myjxt.com//f0i5l7e5/0/alluser/20210114/430f64e104ea4a7bb7f78f0e42b3fad8.jpg"; - System.out.println(photo.indexOf("f0i5l7e5")!=-1); - String path = photo.split("f0i5l7e5/")[1]; - path= path.replace("/","\\"); - System.out.println("E:\\wwwhtdocs\\SmartCampus\\f0i5l7e5\\"+path); -// System.out.println(photo.split("f0i5l7e5/")[1]); -// System.out.println(photo.split("f0i5l7e5/")[0]); - } - @Override public void test6(Integer schoolId, Integer roomId, Integer type, Integer outof, String intime, String clintId, String startTime, String endTime) { List studentIds = userDao.queryStudentIdList(schoolId,roomId); diff --git a/cloud/fIle-center/pom.xml b/cloud/fIle-center/pom.xml index 49f370f..7848d9c 100644 --- a/cloud/fIle-center/pom.xml +++ b/cloud/fIle-center/pom.xml @@ -42,6 +42,12 @@ aliyun-sdk-oss 2.8.3 + + + com.google.code.gson + gson + 2.8.6 + org.apache.poi diff --git a/cloud/haikangface/src/main/java/com/sincere/haikangface/CMSServer.java b/cloud/haikangface/src/main/java/com/sincere/haikangface/CMSServer.java index 0e2e44f..ab837bc 100644 --- a/cloud/haikangface/src/main/java/com/sincere/haikangface/CMSServer.java +++ b/cloud/haikangface/src/main/java/com/sincere/haikangface/CMSServer.java @@ -26,6 +26,7 @@ import com.sun.jna.Pointer; import lombok.extern.slf4j.Slf4j; import org.apache.http.util.TextUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.stereotype.Component; @@ -67,7 +68,7 @@ public class CMSServer implements ApplicationRunner { //114.55.30.100 //120.26.116.253 // private String ip_cloud = "114.55.30.100"; - private String ip_cloud = "120.26.116.253"; + private String ip_cloud = "114.55.30.100"; private String ip; { 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 457affe..1d77477 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 @@ -114,4 +114,13 @@ public class UserOperateController { return userOperateService.insertUpdateCard(cardNums); } + + @ApiOperation(value = "压缩包上传下发") + @RequestMapping(value = "exportFace", method = RequestMethod.POST) + public Result exportFace(@RequestParam("schoolId") Integer schoolId, + @RequestParam("userType") Integer userType, + @RequestParam("deviceIds") String deviceIds, + @RequestParam("faceSrcPath") String faceSrcPath){ + return userOperateService.exportFace(schoolId,userType,deviceIds,faceSrcPath); + } } diff --git a/cloud/haikangface/src/main/java/com/sincere/haikangface/service/UserOperateService.java b/cloud/haikangface/src/main/java/com/sincere/haikangface/service/UserOperateService.java index 2e817dd..71c14f0 100644 --- a/cloud/haikangface/src/main/java/com/sincere/haikangface/service/UserOperateService.java +++ b/cloud/haikangface/src/main/java/com/sincere/haikangface/service/UserOperateService.java @@ -104,4 +104,5 @@ public interface UserOperateService { Result insertUpdateCard(String cardNums); + Result exportFace(Integer schoolId,Integer userType,String deviceIds,String faceSrcPath); } diff --git a/cloud/haikangface/src/main/java/com/sincere/haikangface/service/impl/UserOperateServiceImpl.java b/cloud/haikangface/src/main/java/com/sincere/haikangface/service/impl/UserOperateServiceImpl.java index c93bba9..efbdd07 100644 --- a/cloud/haikangface/src/main/java/com/sincere/haikangface/service/impl/UserOperateServiceImpl.java +++ b/cloud/haikangface/src/main/java/com/sincere/haikangface/service/impl/UserOperateServiceImpl.java @@ -21,8 +21,10 @@ import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import java.io.File; +import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.nio.file.Files; import java.util.*; /** @@ -626,15 +628,6 @@ public class UserOperateServiceImpl implements UserOperateService { } } - public static void main(String[] args) { - String s = "E:\\wwwhtdocs\\SmartCampus\\face17e5\\School386\\Student\\sxzx2020467.png?v=1601037209723"; - if(s.indexOf("?v=")!=-1){ - System.out.println(1); - String fileName = s.split("\\?")[0]; - System.out.println(fileName); - } - } - @Override public Result againNoSendOneFace(MultipartFile file, Integer schoolId, String cardNum, Integer userType, String deviceIds) { if(StringUtils.isBlank(cardNum)){ @@ -740,4 +733,97 @@ public class UserOperateServiceImpl implements UserOperateService { } return new Result(); } + + @Override + public Result exportFace(Integer schoolId,Integer userType,String deviceIds,String faceSrcPath) { + File imgPathFile = new File(faceSrcPath);//目录 + File[] imgfiles = imgPathFile.listFiles(); + if(imgfiles.length==0){ + return ResultGenerator.genFailResult("未获取要下发的人脸照片。"); + } + List sendFaces = new ArrayList<>(); + for (int i = 0; i < imgfiles.length; i++) { + //人脸照片 + File file = imgfiles[i]; + if(!file.isFile()){ + continue; + } + if (file.exists()){ + //原始文件路径 + String srcPath = file.getAbsolutePath(); + //原始文件名 + String fileName = file.getName(); + StudentBean studentBean = new StudentBean(); + if (userType.intValue()==1) { + studentBean = userDao.getTeacherWithstudentcode(fileName.split("\\.")[0],String.valueOf(schoolId)); + }else { + studentBean = userDao.getStudentWithstudentcode(fileName.split("\\.")[0],String.valueOf(schoolId)); + } + String typeName = userType.intValue() ==1 ? "Teacher" : "Student"; + String targetPath = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\" + typeName; +// //目标路径 + targetPath = targetPath + "\\" + fileName; + //复制文件 + copy(srcPath,targetPath); + String savePath = "http://campus.myjxt.com//face17e50/School"+ schoolId + "/" + typeName + "/" + fileName; + if(userType.intValue() ==1){ + studentBean.setFace(savePath); + }else { + studentBean.setPhoto(savePath); + } + //savePath + userDao.updateUser(studentBean.getUser_id(),savePath); + sendFaces.add(studentBean); + } + file.delete(); + } + if(StringUtils.isBlank(deviceIds)){ + return ResultGenerator.genFailResult("未选择下发设备"); + } + String[] deviceArr = deviceIds.split(","); + List deviceList = new ArrayList<>(Arrays.asList(deviceArr)); + //异步执行下发 + asyncSendFace(sendFaces,deviceList,schoolId,userType); + int fileSize = sendFaces.size(); + int clintNum = deviceList.size(); + //下发所用时长 + int timeLength = new Double(clintNum * fileSize * 0.06).intValue(); + //下发截止时间 + String dateStr = baseService.getTime(fileSize,clintNum,timeLength); + Map map = new HashMap(); + map.put("timeLength",timeLength); + map.put("afterDate",dateStr); + map.put("fileSize",fileSize); + return ResultGenerator.genSuccessResult(objectMapper.toJson(map)); + } + + public void asyncSendFace(List sendFaces,List deviceList,Integer schoolId,Integer userType){ + log.info("总共检测到:{},张人脸照片。",sendFaces.size()); + //设备类型 + Integer clintType = userDao.getClintTypeByDeviceId(deviceList.get(0)); + if(clintType.intValue()== 18 || clintType.intValue()== 28){ + //发送海康设备:异步执行 + baseService.sendUserFaceByAsyncThread(schoolId,userType,sendFaces,deviceList); + } + } + + private static void copy(String srcPathStr, String desPathStr) { + //获取源文件的名称 + try { + FileInputStream fis = new FileInputStream(srcPathStr);//创建输入流对象 + FileOutputStream fos = new FileOutputStream(desPathStr); //创建输出流对象 + byte datas[] = new byte[1024*8];//创建搬运工具 + int len = 0;//创建长度 + while((len = fis.read(datas))!=-1)//循环读取数据 + { + fos.write(datas,0,len); + } + fis.close();//释放资源 + fis.close();//释放资源 + } + catch (Exception e) + { + e.printStackTrace(); + } + } } -- libgit2 0.21.0