diff --git a/cloud/dahua/pom.xml b/cloud/dahua/pom.xml
index 750f9df..ecb3d03 100644
--- a/cloud/dahua/pom.xml
+++ b/cloud/dahua/pom.xml
@@ -192,13 +192,13 @@
true
ZIP
-
-
-
- nothing
- nothing
-
-
+
+
+
+
+
+
+
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 6cb6e0c..4dfa78b 100644
--- a/cloud/dahua/src/main/java/com/example/dahua/MyTask.java
+++ b/cloud/dahua/src/main/java/com/example/dahua/MyTask.java
@@ -110,9 +110,9 @@ public class MyTask implements ApplicationRunner {
// 通过 CLIENT_SetAutoReconnect 设置该回调函数,当已断线的设备重连成功时,SDK会调用该函数
private class HaveReConnect implements NetSDKLib.fHaveReConnect {
public void invoke(NetSDKLib.LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) {
- System.out.printf("ReConnect Device[%s] Port[%d]\n", pchDVRIP, nDVRPort);
// 重连提示
String deviceId = getDeviceId(pchDVRIP, nDVRPort);
+ System.out.printf("ReConnect Device[%s] IP[%S] Port[%d]\n", deviceId,pchDVRIP, nDVRPort);
if (!StringUtils.isEmpty(deviceId)) {
attendanceService.updateConnectStateWithDevid(1, deviceId);
// devMap.put(deviceId,"");
@@ -228,7 +228,7 @@ public class MyTask implements ApplicationRunner {
break;
}
- return 0;
+ return 1;
}
}
@@ -240,9 +240,9 @@ public class MyTask implements ApplicationRunner {
if (lLongMap.get(dev.getDevcieId()).intValue() > 0) {
NetSDKLib.LLong lLong = GateModule.realLoadPic(0, analyzerCallback, lLongMap.get(dev.getDevcieId()));
// System.out.println("监听成功:"+dev.getDevcieId());
- if (lLong.intValue() != -1) {
- deviceInfoBeans.remove(dev);
- }
+// if (lLong.intValue() != -1) {
+// //deviceInfoBeans.remove(dev);
+// }
}
}
@@ -290,14 +290,15 @@ public class MyTask implements ApplicationRunner {
ImageIO.write(gateBufferedImage, "png", new File(snapPicPath));
}
card = cardNo(card);
+
CardBean cardBean = 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 (cardBean.getType() == 0) {//老师
+ if (null != cardBean && cardBean.getType() == 0) {//老师
TeacherBean teacherBean = userDao.getTeacherWithId(cardBean.getUser_id());
sendRecordDao.addFaceRecoder("", teacherBean.getUser_id(), teacherBean.getName(), snapPicPath, 1, time, card,"");
- } else if (cardBean.getType() == 2) {//学生
+ } else if (null != cardBean && cardBean.getType() == 2) {//学生
UserInfoBean userInfoBean = userDao.getStudentWithid(cardBean.getUser_id());
sendRecordDao.addFaceRecoder("", userInfoBean.getUser_id(), userInfoBean.getName(), snapPicPath, 1, time, card,"");
}
diff --git a/cloud/dahua/src/main/java/com/example/dahua/async/SendUserInfoTask.java b/cloud/dahua/src/main/java/com/example/dahua/async/SendUserInfoTask.java
index b0b3539..1ee73a1 100644
--- a/cloud/dahua/src/main/java/com/example/dahua/async/SendUserInfoTask.java
+++ b/cloud/dahua/src/main/java/com/example/dahua/async/SendUserInfoTask.java
@@ -1,6 +1,6 @@
package com.example.dahua.async;
-import com.example.dahua.Gate.Gate;
+//import com.example.dahua.Gate.Gate;
import com.example.dahua.MyTask;
import com.example.dahua.bean.*;
import com.example.dahua.common.Res;
@@ -154,7 +154,7 @@ public class SendUserInfoTask {
if (type == 0 || type == 1) {//学生信息或家长信息
userInfoBean = userDao.getUserInfo(schoolId, studentCode);
- HttpUtils.uploadImgs(studentFile, schoolId, studentCode, clint_type, 2);
+ HttpUtils.uploadImgs(studentFile, schoolId, studentCode, clint_type, 2,"");
} else if (type == 2) {//教师信息
TeacherBean teacher = userDao.getTeacher(schoolId, studentCode);
System.out.println("教师信息:" + teacher.toString());
@@ -166,7 +166,7 @@ public class SendUserInfoTask {
userInfoBean.setStudentcode(teacher.getNum());
userInfoBean.setStudent_id(teacher.getTeacher_id());
}
- HttpUtils.uploadImgs(studentFile, schoolId, studentCode, clint_type, 1);
+ HttpUtils.uploadImgs(studentFile, schoolId, studentCode, clint_type, 1,"");
}
//判断用户是否存在
@@ -282,6 +282,7 @@ public class SendUserInfoTask {
}
private synchronized void pushCardAndFace(AttendanceBean attendanceBean, String user_id, String student_num, String name, Memory memory, SendRecordBean sendRecordBean,String userType) {
+ try{
sendRecordBean.setDeviceID(attendanceBean.getClint_id());
sendRecordBean.setSchoolId(Integer.parseInt(attendanceBean.getSchool_id()));
sendRecordBean.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
@@ -297,6 +298,7 @@ public class SendUserInfoTask {
// System.out.println("loginHandleLong:" + loginHandleLong + MyTask.lLongMap.toString() + " 设备ID:" + attendanceBean.getClint_id());
// System.out.println("loginHandleLong:" +loginHandleLong);
if (loginHandleLong == null) {
+ System.out.println("设备不在线:" + attendanceBean.getClint_id());
FileUtils.getInstance().writeLogs("设备不在线:" + attendanceBean.getClint_id(), FileUtils.devices);
String deviceId = sendRecordDao.getFailIsExit(attendanceBean.getClint_id(), attendanceBean.getSchool_id());
sendRecordBean.setFailType(2);
@@ -310,11 +312,30 @@ public class SendUserInfoTask {
boolean bFaceFalgs = false;
String cardNum = cardNo(student_num);
+// GateModule.getFace(user_id, loginHandleLong);
+// GateModule.getUser(user_id, loginHandleLong);
+// GateModule.getCard(cardNum, loginHandleLong);
if (bCardFlags != -1) {//修改卡信息
- GateModule.modifyCard(bCardFlags, cardNum, user_id, name, "123456", Res.string().getCardStatusInt(1), Res.string().getCardTypeInt(1),
- 0, 0, 1, startTime, endTime, loginHandleLong,userType);
- userDao.updateRecordNo(user_id, bCardFlags, attendanceBean.getClint_id());
- bFaceFalgs = GateModule.modifyFaceInfo(user_id, memory, loginHandleLong);
+ int newRecordNo=0;
+ int bFaceFalgsInt=0;
+ bFaceFalgsInt = GateModule.modifyFaceInfo(user_id, memory, loginHandleLong);
+ if(bFaceFalgsInt==1) {//1照片修改成功
+ bFaceFalgs=true;
+ GateModule.modifyCard(bCardFlags, cardNum, user_id, name, "123456", Res.string().getCardStatusInt(1), Res.string().getCardTypeInt(1),
+ 0, 0, 1, startTime, endTime, loginHandleLong, userType);
+ userDao.updateRecordNo(user_id, bCardFlags, attendanceBean.getClint_id());
+ }
+ else if(bFaceFalgsInt==1029)//1029用户id不存在
+ {
+ bCardFlags = GateModule.insertCard(cardNum, user_id, name, "123456"
+ , Res.string().getCardStatusInt(1), Res.string().getCardTypeInt(1), 0, 1
+ , 1, startTime, endTime, loginHandleLong,userType);
+
+ if (bCardFlags != -1) {
+ userDao.updateRecordNo(user_id, bCardFlags, attendanceBean.getClint_id());
+ }
+ }
+ else{bFaceFalgs=false;}
//卡号添加成功,但是人脸不成功的话,就需要新增人脸
if (!bFaceFalgs)
bFaceFalgs = GateModule.addFaceInfo(user_id, memory, loginHandleLong);
@@ -389,7 +410,9 @@ public class SendUserInfoTask {
System.out.println("卡信息已存在,添加人脸成功-----------\n");
}
}
-
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
//人脸发送失败信息添加
diff --git a/cloud/dahua/src/main/java/com/example/dahua/common/FunctionList.java b/cloud/dahua/src/main/java/com/example/dahua/common/FunctionList.java
index 99a136c..0726a3d 100644
--- a/cloud/dahua/src/main/java/com/example/dahua/common/FunctionList.java
+++ b/cloud/dahua/src/main/java/com/example/dahua/common/FunctionList.java
@@ -1,10 +1,10 @@
package com.example.dahua.common;
import com.example.dahua.AutoRegister.AutoRegister;
-import com.example.dahua.DeviceControl;
-import com.example.dahua.DeviceSearchAndInit;
-import com.example.dahua.FaceRecognition.FaceRecognition;
-import com.example.dahua.Gate.Gate;
+//import com.example.dahua.DeviceControl;
+//import com.example.dahua.DeviceSearchAndInit;
+//import com.example.dahua.FaceRecognition.FaceRecognition;
+//import com.example.dahua.Gate.Gate;
import java.awt.BorderLayout;
import java.awt.GridLayout;
@@ -88,7 +88,7 @@ public class FunctionList extends JFrame {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
dispose();
- FaceRecognition.main(null);
+// FaceRecognition.main(null);
}
});
}
@@ -161,7 +161,7 @@ public class FunctionList extends JFrame {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
dispose();
- DeviceSearchAndInit.main(null);
+// DeviceSearchAndInit.main(null);
}
});
}
@@ -186,7 +186,7 @@ public class FunctionList extends JFrame {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
dispose();
- DeviceControl.main(null);
+// DeviceControl.main(null);
}
});
}
@@ -235,7 +235,7 @@ public class FunctionList extends JFrame {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
dispose();
- Gate.main(null);
+// Gate.main(null);
}
});
}
diff --git a/cloud/dahua/src/main/java/com/example/dahua/control/FileControl.java b/cloud/dahua/src/main/java/com/example/dahua/control/FileControl.java
index 60769a6..0e2d551 100644
--- a/cloud/dahua/src/main/java/com/example/dahua/control/FileControl.java
+++ b/cloud/dahua/src/main/java/com/example/dahua/control/FileControl.java
@@ -2,7 +2,7 @@ package com.example.dahua.control;
import com.example.dahua.MyTask;
import com.example.dahua.async.SendUserInfoTask;
-import com.example.dahua.attendance.Attendance;
+//import com.example.dahua.attendance.Attendance;
import com.example.dahua.bean.AttendanceBean;
import com.example.dahua.bean.PermissionBean;
import com.example.dahua.bean.TeacherBean;
@@ -17,6 +17,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
+import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@@ -42,8 +43,9 @@ public class FileControl {
UserDao userDao;
@RequestMapping(method = RequestMethod.POST, value = "uploadImg")
- public String uploadImg(@RequestParam("file") MultipartFile file, @RequestParam("schoolId") String schoolId, @RequestParam("studentCode") String studentCode,
- @RequestParam("clint_type") String clint_type, @RequestParam("userType") int userType) {
+ public String uploadImg(@RequestParam("file") MultipartFile file, @RequestParam("schoolId") String schoolId,
+ @RequestParam("studentCode") String studentCode, @RequestParam("clint_type") String clint_type,
+ @RequestParam("userType") int userType,@RequestParam(required = false) String deviceId) {
System.out.println("schoolId:" + schoolId + " studentCode:" + studentCode);
String fileName = file.getOriginalFilename();//文件名
@@ -55,7 +57,7 @@ public class FileControl {
fileOutputStream.write(file.getBytes());
fileOutputStream.close();
- userService.uploadImgAndUserInfo(dest.getAbsolutePath(), schoolId, studentCode, clint_type, userType, "");
+ userService.uploadImgAndUserInfo(dest.getAbsolutePath(), schoolId, studentCode, clint_type, userType, StringUtils.isEmpty(deviceId)?"":deviceId);
return "1";
} catch (FileNotFoundException e) {
e.printStackTrace();
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 e660007..8a8c2a3 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
@@ -53,7 +53,7 @@ public class UserControl {
@ApiOperation(value = "上传用户信息")
public boolean uploadImgAndUserInfo(@RequestParam("file") String file, @RequestParam("schoolId") String schoolId, @RequestParam("studentCode") String studentCode, @RequestParam("clint_type") String clint_type) {
// return userService.uploadImgAndUserInfo(file, schoolId, studentCode, clint_type);
- return HttpUtils.uploadImgs(new File(file), schoolId, studentCode, clint_type, file.contains("Teacher") ? 1 : 2);
+ return HttpUtils.uploadImgs(new File(file), schoolId, studentCode, clint_type, file.contains("Teacher") ? 1 : 2,"");
}
@RequestMapping(value = "sendPermission", method = RequestMethod.POST)
@@ -118,7 +118,7 @@ public class UserControl {
if (!StringUtils.isEmpty(card)) {
String clint_type = userDao.getClintType(deviceId);
- HttpUtils.uploadImgs(new File(targetPath), schoolId, studentCode, clint_type, Integer.parseInt(userType));
+ HttpUtils.uploadImgs(new File(targetPath), schoolId, studentCode, clint_type, Integer.parseInt(userType),"");
}
}
@@ -169,10 +169,10 @@ public class UserControl {
if (sendRecordBean.getUserType() == 1) {
studentCode = userDao.getTeaNumWithCard(sendRecordBean.getNum());
} else if (sendRecordBean.getUserType() == 2) {
- studentCode = userDao.getStudentCode(sendRecordBean.getNum());
+ studentCode = userDao.getStudentCode(sendRecordBean.getCustomerid());
}
- String imgPath = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + sendRecordBean.getSchoolId() + "\\" + typeName + "\\" + studentCode + ".png";
+ String imgPath = "E:\\wwwhtdocs\\SmartCampus\\face17e5\\School" + sendRecordBean.getSchoolId() + "\\" + typeName + "\\" + studentCode + ".png";
File imgFile = new File(imgPath);
if (imgFile.exists()) {
String targetPath = "./picPath/comp/" + imgFile.getName();
@@ -183,7 +183,7 @@ public class UserControl {
}
String clint_type = userDao.getClintType(sendRecordBean.getDeviceID());
- HttpUtils.uploadImgs(new File(targetPath), schoolId, studentCode, clint_type, sendRecordBean.getUserType());
+ HttpUtils.uploadImgs(new File(targetPath), schoolId, studentCode, clint_type, sendRecordBean.getUserType(),deviceId);
} else {
System.out.println("文件不存在");
}
@@ -461,7 +461,7 @@ public class UserControl {
public void add2Stuinfo(@RequestParam("schoolid") String schoolId) {
try {
- String path = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\Student";
+ String path = "E:\\wwwhtdocs\\SmartCampus\\face17e5\\School" + schoolId + "\\Student";
File filePath = new File(path);
File[] files = filePath.listFiles();
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 78e38f2..8cd70d8 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
@@ -41,7 +41,7 @@ public interface UserDao {
* @param user_id
* @return
*/
- @Select("select recordNo from SZ_Student_RecoderNo where user_id = #{user_id} and deviceId = #{deviceId}")
+ @Select("select top 1 recordNo from SZ_Student_RecoderNo where user_id = #{user_id} and deviceId = #{deviceId}")
String getRecordNo(@Param("user_id") String user_id, @Param("deviceId") String deviceId);
@Insert("insert into SZ_Student_RecoderNo values(#{user_id},#{recordNo},#{student_name},#{deviceId})")
@@ -140,7 +140,7 @@ public interface UserDao {
@Select("select top(1) num from SZ_V_School_Teacher where teacher_num=#{num}")
String getTeaNumWithCard(@Param("num") String num);
- @Select("select clint_type from SZ_Attendance where clint_id = #{clint_id}}")
+ @Select("select clint_type from SZ_Attendance where clint_id = #{clint_id}")
String getClintType(@Param("clint_id") String deviceID);
@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 ")
diff --git a/cloud/dahua/src/main/java/com/example/dahua/lib/CompressPic.java b/cloud/dahua/src/main/java/com/example/dahua/lib/CompressPic.java
index 938aea2..f7e5db3 100644
--- a/cloud/dahua/src/main/java/com/example/dahua/lib/CompressPic.java
+++ b/cloud/dahua/src/main/java/com/example/dahua/lib/CompressPic.java
@@ -24,10 +24,10 @@ public class CompressPic {
int width = bufferedImage.getWidth(null);
int height = bufferedImage.getHeight(null);
long fileLength = file.length();
- if ((fileLength / 1024) < 200) {
+ if ((fileLength / 1024) < 100) {
writeImgToFile(bufferedImage, width, height, targetPath);
} else
- while ((fileLength / 1024) >= 200) {
+ while ((fileLength / 1024) >= 100) {
width = (int) (width * (1 - cutPercent));
height = (int) (height * (1 - cutPercent));
diff --git a/cloud/dahua/src/main/java/com/example/dahua/module/GateModule.java b/cloud/dahua/src/main/java/com/example/dahua/module/GateModule.java
index df1597a..375e010 100644
--- a/cloud/dahua/src/main/java/com/example/dahua/module/GateModule.java
+++ b/cloud/dahua/src/main/java/com/example/dahua/module/GateModule.java
@@ -1,5 +1,9 @@
package com.example.dahua.module;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -15,6 +19,8 @@ import com.example.dahua.lib.ToolKits;
import com.sun.jna.Memory;
import com.sun.jna.ptr.IntByReference;
+import javax.imageio.ImageIO;
+
public class GateModule {
// 查询句柄
@@ -248,7 +254,17 @@ public class GateModule {
accessCardInfo.read();
if(!bRet) {
- System.err.println("添加卡信息失败." + ToolKits.getErrorCodePrint());
+ //System.err.println("添加卡信息失败." + ToolKits.getErrorCodePrint());
+ String ret=ToolKits.getErrorCodePrint();
+ System.err.println("添加卡信息失败." + ret);
+ String number = ret.substring(ret.indexOf("|") + 1, ret.indexOf(")"));
+ if(number.equals("21")||number.equals("146"))//146用户已存在,21对返回数据的校验出错,1162未知错误 number.equals("1162")||
+ {
+ deleteUser( userId, lLong);
+ return insertCard( cardNo, userId, cardName, cardPwd,
+ cardStatus, cardType, useTimes, isFirstEnter,
+ isValid, startValidTime, endValidTime, lLong, userType);
+ }
return -1;
} else {
System.out.println("添加卡信息成功,卡信息记录集编号 : " + insert.stuCtrlRecordSetResult.nRecNo);
@@ -387,6 +403,7 @@ public class GateModule {
WeekTime weekTime = weekTimes.get(i);
String startTime = weekTime.getStartTime();
String endTime = weekTime.getEndTime();
+ msg.stuTimeWeekDay[weekDayIndex].stuTimeSection[i].dwRecordMask=1;
msg.stuTimeWeekDay[weekDayIndex].stuTimeSection[i].nBeginHour = Integer.parseInt(startTime.split(":")[0]);
msg.stuTimeWeekDay[weekDayIndex].stuTimeSection[i].nBeginMin = Integer.parseInt(startTime.split(":")[1]);
msg.stuTimeWeekDay[weekDayIndex].stuTimeSection[i].nBeginSec = 0;
@@ -702,7 +719,16 @@ public class GateModule {
accessCardInfo.read();
if (!bRet) {
- System.err.println("修改卡信息失败." + ToolKits.getErrorCodePrint());
+ //System.err.println("修改卡信息失败." + ToolKits.getErrorCodePrint());
+ String ret=ToolKits.getErrorCodePrint();
+ System.err.println("修改卡信息失败." + ret);
+ String number = ret.substring(ret.indexOf("|") + 1, ret.indexOf(")"));
+ if(number.equals("21")||number.equals("147"))//147用户不存在,21对返回数据的校验出错
+ {
+// newRecordNo= insertCard( cardNo, userId, cardName, cardPwd,
+// cardStatus, cardType, useTimes, isFirstEnter,
+// isValid, startValidTime, endValidTime, lLong, userType);
+ }
return false;
} else {
System.out.println("修改卡信息成功 ");
@@ -784,6 +810,239 @@ public class GateModule {
return bRet;
}
+ /**
+ * 根据用户ID获取用户信息
+ */
+ public static void getUser(String userID,LLong lLong) {
+ String[] userIDs = { userID };
+
+ // 获取的用户个数
+ int nMaxNum = userIDs.length;
+
+ // /////////////////////////// 以下固定写法
+ // /////////////////////////////////////
+ // 用户操作类型
+ // 获取用户
+ int emtype = NET_EM_ACCESS_CTL_USER_SERVICE.NET_EM_ACCESS_CTL_USER_SERVICE_GET;
+
+ /**
+ * 用户信息数组
+ */
+ // 先初始化用户信息数组
+ NET_ACCESS_USER_INFO[] users = new NET_ACCESS_USER_INFO[nMaxNum];
+ // 初始化返回的失败信息数组
+ FAIL_CODE[] failCodes = new FAIL_CODE[nMaxNum];
+
+ for (int i = 0; i < nMaxNum; i++) {
+ users[i] = new NET_ACCESS_USER_INFO();
+ failCodes[i] = new FAIL_CODE();
+ }
+
+ /**
+ * 入参
+ */
+ NET_IN_ACCESS_USER_SERVICE_GET stIn = new NET_IN_ACCESS_USER_SERVICE_GET();
+ // 用户ID个数
+ stIn.nUserNum = userIDs.length;
+
+ // 用户ID
+ for (int i = 0; i < userIDs.length; i++) {
+ System.arraycopy(userIDs[i].getBytes(), 0,
+ stIn.szUserIDs[i].szUserID, 0, userIDs[i].getBytes().length);
+ }
+
+ /**
+ * 出参
+ */
+ NET_OUT_ACCESS_USER_SERVICE_GET stOut = new NET_OUT_ACCESS_USER_SERVICE_GET();
+ stOut.nMaxRetNum = nMaxNum;
+
+ stOut.pUserInfo = new Memory(users[0].size() * nMaxNum); // 申请内存
+ stOut.pUserInfo.clear(users[0].size() * nMaxNum);
+
+ stOut.pFailCode = new Memory(failCodes[0].size() * nMaxNum); // 申请内存
+ stOut.pFailCode.clear(failCodes[0].size() * nMaxNum);
+
+ ToolKits.SetStructArrToPointerData(users, stOut.pUserInfo);
+ ToolKits.SetStructArrToPointerData(failCodes, stOut.pFailCode);
+
+ stIn.write();
+ stOut.write();
+ if (LoginModule.netsdk.CLIENT_OperateAccessUserService(lLong, emtype,
+ stIn.getPointer(), stOut.getPointer(), 5000)) {
+ // 将指针转为具体的信息
+ ToolKits.GetPointerDataToStructArr(stOut.pUserInfo, users);
+ ToolKits.GetPointerDataToStructArr(stOut.pFailCode, failCodes);
+
+ /**
+ * 打印具体的信息
+ */
+ for (int i = 0; i < nMaxNum; i++) {
+ try {
+ System.out.println("[" + i + "]用户名:"
+ + new String(users[i].szName, "GBK").trim());
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ System.out.println("[" + i + "]密码:"
+ + new String(users[i].szPsw).trim());
+ System.out.println("[" + i + "]查询用户结果:"
+ + failCodes[i].nFailCode);
+ }
+ } else {
+ System.err.println("查询卡失败, " + ToolKits.getErrorCodePrint());
+ }
+
+ stIn.read();
+ stOut.read();
+ }
+
+ /**
+ * 根据卡号获取卡信息
+ */
+ public static void getCard(String userID,LLong lLong) {
+ String[] cardNOs = { userID };
+
+ // 修改的卡的最大个数
+ int nMaxCount = cardNOs.length;
+
+ // 卡片信息
+ NET_ACCESS_CARD_INFO[] cards = new NET_ACCESS_CARD_INFO[nMaxCount];
+ for (int i = 0; i < nMaxCount; i++) {
+ cards[i] = new NET_ACCESS_CARD_INFO();
+ }
+
+ //
+ FAIL_CODE[] failCodes = new FAIL_CODE[nMaxCount];
+ for (int i = 0; i < nMaxCount; i++) {
+ failCodes[i] = new FAIL_CODE();
+ }
+
+ // 卡操作类型
+ // 获取卡信息
+ int emtype = NET_EM_ACCESS_CTL_CARD_SERVICE.NET_EM_ACCESS_CTL_CARD_SERVICE_GET;
+
+ /**
+ * 入参
+ */
+ NET_IN_ACCESS_CARD_SERVICE_GET stIn = new NET_IN_ACCESS_CARD_SERVICE_GET();
+ // 卡号数量
+ stIn.nCardNum = cardNOs.length;
+
+ for (int i = 0; i < cardNOs.length; i++) {
+ // 卡号
+ System.arraycopy(cardNOs[i].getBytes(), 0,
+ stIn.szCardNos[i].szCardNo, 0, cardNOs[i].getBytes().length);
+ }
+
+ /**
+ * 出参
+ */
+ NET_OUT_ACCESS_CARD_SERVICE_GET stOut = new NET_OUT_ACCESS_CARD_SERVICE_GET();
+ stOut.nMaxRetNum = nMaxCount;
+
+ stOut.pCardInfo = new Memory(cards[0].size() * nMaxCount);
+ stOut.pCardInfo.clear(cards[0].size() * nMaxCount);
+
+ stOut.pFailCode = new Memory(failCodes[0].size() * nMaxCount);
+ stOut.pFailCode.clear(failCodes[0].size() * nMaxCount);
+
+ ToolKits.SetStructArrToPointerData(cards, stOut.pCardInfo);
+ ToolKits.SetStructArrToPointerData(failCodes, stOut.pFailCode);
+
+ stIn.write();
+ stOut.write();
+ if (LoginModule.netsdk.CLIENT_OperateAccessCardService(lLong, emtype,
+ stIn.getPointer(), stOut.getPointer(), 5000)) {
+ // 将获取到的结果信息转成具体的结构体
+ ToolKits.GetPointerDataToStructArr(stOut.pCardInfo, cards);
+ ToolKits.GetPointerDataToStructArr(stOut.pFailCode, failCodes);
+
+ // 打印具体信息
+ for (int i = 0; i < nMaxCount; i++) {
+ System.out.println("[" + i + "]用户ID : "
+ + new String(cards[i].szUserID).trim());
+ System.out.println("[" + i + "]卡号 : "
+ + new String(cards[i].szCardNo).trim());
+ System.out.println("[" + i + "]卡类型 : " + cards[i].emType);
+ System.out.println("[" + i + "]查询卡结果 : "
+ + failCodes[i].nFailCode + "\n");
+ }
+ } else {
+ System.err.println("查询卡失败, " + ToolKits.getErrorCodePrint());
+ }
+ stIn.read();
+ stOut.read();
+ }
+
+ /**
+ * 删除指定用户ID的用户
+ */
+ public static void deleteUser(String userID,LLong lLong) {
+ String[] userIDs = { userID };
+
+ // 删除的用户个数
+ int nMaxNum = userIDs.length;
+
+ // /////////////////////////// 以下固定写法
+ // /////////////////////////////////////
+ // 用户操作类型
+ // 删除用户
+ int emtype = NET_EM_ACCESS_CTL_USER_SERVICE.NET_EM_ACCESS_CTL_USER_SERVICE_REMOVE;
+
+ // 初始化返回的失败信息数组
+ FAIL_CODE[] failCodes = new FAIL_CODE[nMaxNum];
+ for (int i = 0; i < nMaxNum; i++) {
+ failCodes[i] = new FAIL_CODE();
+ }
+
+ /**
+ * 入参
+ */
+ NET_IN_ACCESS_USER_SERVICE_REMOVE stIn = new NET_IN_ACCESS_USER_SERVICE_REMOVE();
+ // 用户ID个数
+ stIn.nUserNum = userIDs.length;
+
+ // 用户ID
+ for (int i = 0; i < userIDs.length; i++) {
+ System.arraycopy(userIDs[i].getBytes(), 0,
+ stIn.szUserIDs[i].szUserID, 0, userIDs[i].getBytes().length);
+ }
+
+ /**
+ * 出参
+ */
+ NET_OUT_ACCESS_USER_SERVICE_REMOVE stOut = new NET_OUT_ACCESS_USER_SERVICE_REMOVE();
+ stOut.nMaxRetNum = nMaxNum;
+
+ stOut.pFailCode = new Memory(failCodes[0].size() * nMaxNum); // 申请内存
+ stOut.pFailCode.clear(failCodes[0].size() * nMaxNum);
+
+ ToolKits.SetStructArrToPointerData(failCodes, stOut.pFailCode);
+
+ stIn.write();
+ stOut.write();
+ if (LoginModule.netsdk.CLIENT_OperateAccessUserService(lLong, emtype,
+ stIn.getPointer(), stOut.getPointer(), 5000)) {
+ // 将指针转为具体的信息
+ ToolKits.GetPointerDataToStructArr(stOut.pFailCode, failCodes);
+
+ /**
+ * 打印具体的信息
+ */
+ for (int i = 0; i < nMaxNum; i++) {
+ System.out.println("[" + i + "]删除用户结果:"
+ + failCodes[i].nFailCode);
+ }
+ } else {
+ //System.err.println("删除用户失败, " + getErrorCode());
+ System.err.println("删除用户失败, " + ToolKits.getErrorCodePrint());
+ }
+
+ stIn.read();
+ stOut.read();
+ }
+
///////////////////////////////// 人脸的增、删、改、清空 ///////////////////////////////////////
@@ -867,7 +1126,18 @@ public class GateModule {
if (bRet) {
System.out.println("添加人脸成功!");
} else {
- System.err.println("添加人脸失败!" + ToolKits.getErrorCodePrint());
+// System.err.println("添加人脸失败!" + ToolKits.getErrorCodePrint());
+ String ret=ToolKits.getErrorCodePrint();
+ System.err.println("添加人脸失败!" + ret);
+ String number = ret.substring(ret.indexOf("|") + 1, ret.indexOf(")"));
+ if(number.equals("1031"))//照片已存在
+ {
+ return modifyFaceInfo( userId, memory, lLong)==1?true:false;
+ }
+ if(number.equals("1029"))//照片已存在
+ {
+ return addFaceInfo( userId, memory, lLong);
+ }
return false;
}
@@ -914,7 +1184,10 @@ public class GateModule {
if (bRet) {
System.out.println("修改人脸成功!");
} else {
- System.err.println("修改人脸失败!" + ToolKits.getErrorCodePrint());
+// System.err.println("修改人脸失败!" + ToolKits.getErrorCodePrint());
+ String ret=ToolKits.getErrorCodePrint();
+ System.err.println("修改人脸成功!" + ret);
+ String number = ret.substring(ret.indexOf("|") + 1, ret.indexOf(")"));
return false;
}
@@ -922,7 +1195,7 @@ public class GateModule {
}
- public static boolean modifyFaceInfo(String userId, Memory memory, LLong lLong) {
+ public static int modifyFaceInfo(String userId, Memory memory, LLong lLong) {
int emType = EM_FACEINFO_OPREATE_TYPE.EM_FACEINFO_OPREATE_UPDATE; // 修改
/**
@@ -955,13 +1228,139 @@ public class GateModule {
if (bRet) {
System.out.println("修改人脸成功!");
} else {
+// System.err.println("修改人脸失败!" + ToolKits.getErrorCodePrint());
+ String ret=ToolKits.getErrorCodePrint();
+ System.err.println("修改人脸失败!" + ret);
+ String number = ret.substring(ret.indexOf("|") + 1, ret.indexOf(")"));
+ if(number.equals("1029"))//1029用户ID不存在
+ {
+ //return addFaceInfo(userId, memory, lLong);
+ return Integer.parseInt(number);
+ }
+ return 0;
+ }
+
+ return 1;
+ }
+
+ /**
+ * 获取人脸信息
+ */
+ public static void getFace(String userId,LLong lLong) {
+ String[] userIDs = { userId };
+
+ // 获取人脸的用户最大个数
+ int nMaxCount = userIDs.length;
+
+ // ////////////////////// 每个用户的人脸信息初始化 ////////////////////////
+ NET_ACCESS_FACE_INFO[] faces = new NET_ACCESS_FACE_INFO[nMaxCount];
+ for (int i = 0; i < faces.length; i++) {
+ faces[i] = new NET_ACCESS_FACE_INFO();
+
+ // 根据每个用户的人脸图片的实际个数申请内存,最多5张照片
+
+ faces[i].nFacePhoto = 1; // 每个用户图片个数
+
+ // 对每张照片申请内存
+ faces[i].nInFacePhotoLen[0] = 200 * 1024;
+ faces[i].pFacePhotos[0].pFacePhoto = new Memory(200 * 1024); // 人脸照片数据,大小不超过200K
+ faces[i].pFacePhotos[0].pFacePhoto.clear(200 * 1024);
+ }
+
+ // 初始化
+ FAIL_CODE[] failCodes = new FAIL_CODE[nMaxCount];
+ for (int i = 0; i < failCodes.length; i++) {
+ failCodes[i] = new FAIL_CODE();
+ }
+
+ // 人脸操作类型
+ // 获取人脸信息
+ int emtype = NET_EM_ACCESS_CTL_FACE_SERVICE.NET_EM_ACCESS_CTL_FACE_SERVICE_GET;
+
+ /**
+ * 入参
+ */
+ NET_IN_ACCESS_FACE_SERVICE_GET stIn = new NET_IN_ACCESS_FACE_SERVICE_GET();
+ stIn.nUserNum = nMaxCount;
+ for (int i = 0; i < nMaxCount; i++) {
+ System.arraycopy(userIDs[i].getBytes(), 0,
+ stIn.szUserIDs[i].szUserID, 0, userIDs[i].getBytes().length);
+ }
+
+ /**
+ * 出参
+ */
+ NET_OUT_ACCESS_FACE_SERVICE_GET stOut = new NET_OUT_ACCESS_FACE_SERVICE_GET();
+ stOut.nMaxRetNum = nMaxCount;
+
+ stOut.pFaceInfo = new Memory(faces[0].size() * nMaxCount);
+ stOut.pFaceInfo.clear(faces[0].size() * nMaxCount);
+
+ stOut.pFailCode = new Memory(failCodes[0].size() * nMaxCount);
+ stOut.pFailCode.clear(failCodes[0].size() * nMaxCount);
+
+ ToolKits.SetStructArrToPointerData(faces, stOut.pFaceInfo);
+ ToolKits.SetStructArrToPointerData(failCodes, stOut.pFailCode);
+
+ stIn.write();
+ stOut.write();
+ if (LoginModule.netsdk.CLIENT_OperateAccessFaceService(lLong, emtype,
+ stIn.getPointer(), stOut.getPointer(), 5000)) {
+ // 将获取到的结果信息转成具体的结构体
+ ToolKits.GetPointerDataToStructArr(stOut.pFaceInfo, faces);
+ ToolKits.GetPointerDataToStructArr(stOut.pFailCode, failCodes);
+
+ File path = new File(".");
+
+ // 打印具体信息
+ // nMaxCount 几个用户
+ for (int i = 0; i < nMaxCount; i++) {
+ System.out.println("[" + i + "]用户ID : "
+ + new String(faces[i].szUserID).trim());
+
+ // 保存查询到的图片
+ String savePath = "";
+ for (int j = 0; j < faces[i].nFacePhoto; j++) {
+
+ if (faces[i].nFacePhoto == 0
+ || faces[i].pFacePhotos[j].pFacePhoto == null) {
+ return;
+ }
+
+ savePath = path.getAbsoluteFile().getParent() + "/"
+ + "qyc" + "_"
+ + new String(faces[i].szUserID).trim() + ".jpg";
+ System.out.println("路径:" + savePath);
+ // 人脸图片数据
+ byte[] buffer = faces[i].pFacePhotos[j].pFacePhoto
+ .getByteArray(0, faces[i].nOutFacePhotoLen[j]);
+
+ ByteArrayInputStream byteInputStream = new ByteArrayInputStream(
+ buffer);
+ try {
+ BufferedImage bufferedImage = ImageIO
+ .read(byteInputStream);
+ if (bufferedImage == null) {
+ return;
+ }
+ ImageIO.write(bufferedImage, "jpg", new File(savePath));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ System.out.println("[" + i + "]获取人脸结果 : "
+ + failCodes[i].nFailCode);
+ }
+ } else {
System.err.println("修改人脸失败!" + ToolKits.getErrorCodePrint());
- return false;
}
- return true;
+ stIn.read();
+ stOut.read();
}
+
/**
* 删除人脸(单个删除)
*
diff --git a/cloud/dahua/src/main/java/com/example/dahua/service/imp/PermissFaceServiceImp.java b/cloud/dahua/src/main/java/com/example/dahua/service/imp/PermissFaceServiceImp.java
index e91777d..e5b9000 100644
--- a/cloud/dahua/src/main/java/com/example/dahua/service/imp/PermissFaceServiceImp.java
+++ b/cloud/dahua/src/main/java/com/example/dahua/service/imp/PermissFaceServiceImp.java
@@ -276,7 +276,7 @@ public class PermissFaceServiceImp implements PermissFaceService {
} else if (clintType.equals("22") || clintType.equals("29")) {
HttpUtils.uploadImgs(saveImgFile, schoolId, studentcode
- , clintType, userType);
+ , clintType, userType,attendanceBean.getClint_id());
}
}
diff --git a/cloud/dahua/src/main/java/com/example/dahua/utils/HttpUtils.java b/cloud/dahua/src/main/java/com/example/dahua/utils/HttpUtils.java
index a4f810c..64afc30 100644
--- a/cloud/dahua/src/main/java/com/example/dahua/utils/HttpUtils.java
+++ b/cloud/dahua/src/main/java/com/example/dahua/utils/HttpUtils.java
@@ -12,6 +12,7 @@ import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
+import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.client.RestTemplate;
@@ -21,7 +22,7 @@ import java.util.Map;
public class HttpUtils {
- public static boolean uploadImgs(File file, String schoolId, String studentCode, String clint_type, int userType) {
+ public static boolean uploadImgs(File file, String schoolId, String studentCode, String clint_type, int userType,String deviceId) {
if (!file.exists()) {
System.out.println("图片不存在");
@@ -29,37 +30,39 @@ public class HttpUtils {
}
String targPath = FilePath.picPathComp + studentCode + ".jpg";
// String targPath = "C:\\Users\\taohandong\\Desktop\\comp\\"+userInfoBean.getStudentcode()+".jpg";
- try {
- CompressPic.CompressPic(file.getAbsolutePath(), targPath, studentCode);//压缩后的图片
- } catch (Exception e) {
- e.printStackTrace();
- }
String url = "http://121.40.109.21:8991/file/uploadImg";
-// String url = "http://localhost:8991/file/uploadImg";
- RestTemplate restTemplate = new RestTemplate();
-
- HttpHeaders headers = new HttpHeaders();
-
- MediaType mediaType = MediaType.parseMediaType(MediaType.MULTIPART_FORM_DATA_VALUE);
-
- headers.setContentType(mediaType);
-
+ //String url = "http://localhost:8991/file/uploadImg";
MultiValueMap multivaluedMap = new LinkedMultiValueMap<>();
+ HttpHeaders headers = new HttpHeaders();
+ RestTemplate restTemplate = new RestTemplate();
+ HttpEntity> httpEntity = null;
+ ResponseEntity responseEntity = null;
+ try {
+ CompressPic.CompressPic(file.getAbsolutePath(), targPath, studentCode);//压缩后的图片
- FileSystemResource fileSystemResource = new FileSystemResource(targPath);
-
- multivaluedMap.add("file", fileSystemResource);
- multivaluedMap.add("schoolId", schoolId);
- multivaluedMap.add("studentCode", studentCode);
- multivaluedMap.add("clint_type", clint_type);
- multivaluedMap.add("userType", userType);
-
- HttpEntity> httpEntity = new HttpEntity<>(multivaluedMap, headers);
+ MediaType mediaType = MediaType.parseMediaType(MediaType.MULTIPART_FORM_DATA_VALUE);
- ResponseEntity responseEntity = restTemplate.postForEntity(url, httpEntity, String.class);
+ headers.setContentType(mediaType);
- System.out.println("responseEntity:" + responseEntity.getBody());
- return responseEntity.getBody().equals("1");
+ FileSystemResource fileSystemResource = new FileSystemResource(targPath);
+
+ multivaluedMap.add("file", fileSystemResource);
+ multivaluedMap.add("schoolId", schoolId);
+ multivaluedMap.add("studentCode", studentCode);
+ multivaluedMap.add("clint_type", clint_type);
+ multivaluedMap.add("userType", userType);
+ if(!StringUtils.isEmpty(deviceId)){
+ multivaluedMap.add("deviceId", deviceId);
+ }
+ httpEntity = new HttpEntity<>(multivaluedMap, headers);
+ responseEntity = restTemplate.postForEntity(url, httpEntity, String.class);
+
+ System.out.println("responseEntity:" + responseEntity.getBody());
+ return responseEntity.getBody().equals("1");
+ } catch (Exception e) {
+ e.printStackTrace();
+ return responseEntity.getBody().equals("0");
+ }
}
--
libgit2 0.21.0