|
@@ -273,55 +273,57 @@ public class AcsService {
|
|
|
@Resource
|
|
|
private AdminUserService userService;
|
|
|
|
|
|
- //添加单个用户的照片和信息
|
|
|
|
|
|
//用户添加自己的照片(也可以对考勤机那添加用户信息照片或更新照片)
|
|
|
@Transactional(rollbackFor = Exception.class) //
|
|
|
public String addSelfImage(MultipartFile image) throws Exception {
|
|
|
- if (isValidImageName(image.getName()).equals("照片格式正确")) {
|
|
|
+ if (isValidImageName(image.getOriginalFilename()).equals("照片格式正确")) {
|
|
|
Long loginId = SecurityFrameworkUtils.getLoginUserId();
|
|
|
AdminUserDO user = userService.getUser(loginId);
|
|
|
- File newFile = new File(image.getName());
|
|
|
- String photoUrl = fileApi.createFile(Files.readAllBytes(newFile.toPath()));
|
|
|
- user.setPhotoUrl(photoUrl);
|
|
|
- String userNumber = user.getUserNumber();
|
|
|
- String result =getUser(userNumber);
|
|
|
- if (result!=null) {
|
|
|
- Gson gson = new Gson();
|
|
|
- JsonObject jsonObject = gson.fromJson(result, JsonObject.class);
|
|
|
- JsonArray userInfoArray = jsonObject
|
|
|
- .getAsJsonObject("UserInfoSearch")
|
|
|
- .getAsJsonArray("UserInfo");
|
|
|
- if (userInfoArray!=null) {
|
|
|
- JsonObject userInfo = userInfoArray.getAsJsonObject();
|
|
|
- String empNo = userInfo.get("employeeNo").getAsString();
|
|
|
- if (empNo != null) {
|
|
|
- addFaceByUrl(userNumber, user.getPhotoUrl());
|
|
|
- }
|
|
|
- }
|
|
|
- }else {
|
|
|
- //确保在执行完增加用户后执行增加人脸
|
|
|
- CompletableFuture<Void> userFuture = CompletableFuture.runAsync(() -> {
|
|
|
- try {
|
|
|
- addUser(userNumber, user.getNickname());
|
|
|
- } catch (JSONException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- } catch (UnsupportedEncodingException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- } catch (InterruptedException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
- });
|
|
|
- userFuture.thenRun(() -> {
|
|
|
- try {
|
|
|
- addFaceByUrl(userNumber, photoUrl);
|
|
|
- } catch (JSONException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- return "添加用户并且增加照片成功";
|
|
|
- }
|
|
|
+ //创建临时文件目录
|
|
|
+ File tempDir = Files.createTempDirectory("user_image").toFile();
|
|
|
+ try {
|
|
|
+ File newFile =new File(tempDir,image.getOriginalFilename());
|
|
|
+ //将内容写入
|
|
|
+ image.transferTo(newFile);
|
|
|
+ String photoUrl = fileApi.createFile(Files.readAllBytes(newFile.toPath()));
|
|
|
+ user.setPhotoUrl(photoUrl);
|
|
|
+ String userNumber = user.getUserNumber();
|
|
|
+
|
|
|
+ String result = getUser(userNumber);
|
|
|
+ Gson gson = new Gson();
|
|
|
+ JsonObject jsonObject = gson.fromJson(result, JsonObject.class);
|
|
|
+ JsonArray userInfoArray = jsonObject
|
|
|
+ .getAsJsonObject("UserInfoSearch")
|
|
|
+ .getAsJsonArray("UserInfo");
|
|
|
+
|
|
|
+ if (userInfoArray != null) {
|
|
|
+ addFaceByUrl(userNumber, user.getPhotoUrl());
|
|
|
+ } else {
|
|
|
+ //确保在执行完增加用户后执行增加人脸
|
|
|
+ CompletableFuture<Void> userFuture = CompletableFuture.runAsync(() -> {
|
|
|
+ try {
|
|
|
+ addUser(userNumber, user.getNickname());
|
|
|
+ } catch (JSONException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ userFuture.thenRun(() -> {
|
|
|
+ try {
|
|
|
+ addFaceByUrl(userNumber, photoUrl);
|
|
|
+ } catch (JSONException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return "添加用户并且增加照片成功";
|
|
|
+ }
|
|
|
+ }finally {
|
|
|
+ FileUtils.deleteDirectory(tempDir);
|
|
|
+ }
|
|
|
return "更新照片成功";
|
|
|
}else{
|
|
|
return "照片格式有问题";
|
|
@@ -329,31 +331,34 @@ public class AcsService {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+ //教师添加或更新照片
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public String teacherUpdateUserImage(String employeeNo, MultipartFile image) throws Exception {
|
|
|
- if (isValidImageName(image.getName()).equals("照片格式正确")) {
|
|
|
- File newFile = new File(image.getName());
|
|
|
- String photoUrl = fileApi.createFile(Files.readAllBytes(newFile.toPath()));
|
|
|
- String result =getUser(employeeNo);
|
|
|
- if (result!=null) {
|
|
|
+ if (isValidImageName( image.getOriginalFilename()).equals("照片格式正确")) {
|
|
|
+ //创建临时文件
|
|
|
+ File tempDir = Files.createTempDirectory("user_image").toFile();
|
|
|
+ try {
|
|
|
+ //创建临时文件
|
|
|
+ File newFile =new File(tempDir,image.getOriginalFilename());
|
|
|
+ //将内容写入
|
|
|
+ image.transferTo(newFile);
|
|
|
+ String photoUrl = fileApi.createFile(Files.readAllBytes(newFile.toPath()));
|
|
|
+ String result = getUser(employeeNo);
|
|
|
Gson gson = new Gson();
|
|
|
JsonObject jsonObject = gson.fromJson(result, JsonObject.class);
|
|
|
JsonArray userInfoArray = jsonObject
|
|
|
.getAsJsonObject("UserInfoSearch")
|
|
|
.getAsJsonArray("UserInfo");
|
|
|
- if (userInfoArray!=null) {
|
|
|
- JsonObject userInfo = userInfoArray.getAsJsonObject();
|
|
|
- String empNo = userInfo.get("employeeNo").getAsString();
|
|
|
- if (empNo != null) {
|
|
|
- String msg = addFaceByUrl(employeeNo,photoUrl);
|
|
|
- if (msg.contains("下发人脸成功") && !msg.contains("但是有异常情况")) {
|
|
|
- return "更新照片成功";
|
|
|
- } else {
|
|
|
- return "更新照片失败,请检查照片大小";
|
|
|
- }
|
|
|
+ if (userInfoArray != null) {
|
|
|
+ String msg = addFaceByUrl(employeeNo, photoUrl);
|
|
|
+ if (msg.contains("下发人脸成功") && msg.contains("但是有异常情况")) {
|
|
|
+ return "更新照片失败,请检查照片大小";
|
|
|
+ } else {
|
|
|
+ return "更新照片成功";
|
|
|
}
|
|
|
}
|
|
|
+ }finally {
|
|
|
+ FileUtils.deleteDirectory(tempDir);
|
|
|
}
|
|
|
return "该学号的用户不存在";
|
|
|
}else{
|
|
@@ -361,9 +366,7 @@ public class AcsService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- //导入用户信息
|
|
|
+ //批量导入用户信息
|
|
|
@Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入
|
|
|
public attendanceImportRespVO importUserList(List<attendanceImportExcelVO> importUsers, boolean isUpdateSupport) {
|
|
|
|
|
@@ -373,21 +376,15 @@ public class AcsService {
|
|
|
|
|
|
try {
|
|
|
String result = getUser(importUser.getEmployeeNo());
|
|
|
- if ( result==null) {
|
|
|
Gson gson = new Gson();
|
|
|
JsonObject jsonObject = gson.fromJson(result, JsonObject.class);
|
|
|
JsonArray userInfoArray = jsonObject
|
|
|
.getAsJsonObject("UserInfoSearch")
|
|
|
.getAsJsonArray("UserInfo");
|
|
|
- if (userInfoArray!=null) {
|
|
|
- JsonObject userInfo = userInfoArray.get(0).getAsJsonObject();
|
|
|
- String empNo = userInfo.get("employeeNo").getAsString();
|
|
|
- if (empNo != null) {
|
|
|
- UserManage.addUserInfo(lUserID, importUser.getEmployeeNo(), importUser.getName());
|
|
|
- respVO.getCreateUsernames().add(importUser.getName());
|
|
|
- }
|
|
|
+ if (userInfoArray==null) {//没有userInfo
|
|
|
+ UserManage.addUserInfo(lUserID, importUser.getEmployeeNo(), importUser.getName());
|
|
|
+ respVO.getCreateUsernames().add(importUser.getName());
|
|
|
}
|
|
|
- }
|
|
|
} catch (UnsupportedEncodingException | InterruptedException | JSONException e) {
|
|
|
throw new RuntimeException("添加用户信息失败: " + e.getMessage(), e);
|
|
|
}
|
|
@@ -431,7 +428,7 @@ public class AcsService {
|
|
|
}
|
|
|
}
|
|
|
String result =getUser(userNumber);
|
|
|
- if (result!=null) {
|
|
|
+
|
|
|
Gson gson = new Gson();
|
|
|
JsonObject jsonObject = gson.fromJson(result, JsonObject.class);
|
|
|
|
|
@@ -439,27 +436,21 @@ public class AcsService {
|
|
|
.getAsJsonObject("UserInfoSearch")
|
|
|
.getAsJsonArray("UserInfo");
|
|
|
if (userInfoArray!=null) {
|
|
|
- JsonObject userInfo = userInfoArray.get(0).getAsJsonObject();
|
|
|
- String empNo = userInfo.get("employeeNo").getAsString();
|
|
|
- if (empNo != null) {
|
|
|
- // 上传文件并获取 URL
|
|
|
- AdminUserDO user = userService.findUserByUserNumber(userNumber);
|
|
|
- String photoUrl = fileApi.createFile(Files.readAllBytes(newFile.toPath()));
|
|
|
- user.setPhotoUrl(photoUrl);
|
|
|
- userService.updateUser((BeanUtils.toBean(user, UserSaveReqVO.class)));
|
|
|
- //给对应学号的人的照片添加
|
|
|
- String msg = addFaceByUrl(user.getUserNumber(), photoUrl);
|
|
|
- if (msg.contains("下发人脸成功") && !msg.contains("但是有异常情况")) {
|
|
|
- successUsers.add(studentName);
|
|
|
- } else {
|
|
|
- failUsers.add(studentName);
|
|
|
- }
|
|
|
+ // 上传文件并获取 URL
|
|
|
+ AdminUserDO user = userService.findUserByUserNumber(userNumber);
|
|
|
+ String photoUrl = fileApi.createFile(Files.readAllBytes(newFile.toPath()));
|
|
|
+ user.setPhotoUrl(photoUrl);
|
|
|
+ userService.updateUser((BeanUtils.toBean(user, UserSaveReqVO.class)));
|
|
|
+ //给对应学号的人的照片添加
|
|
|
+ String msg = addFaceByUrl(user.getUserNumber(), photoUrl);
|
|
|
+ if (msg.contains("下发人脸成功") && msg.contains("但是有异常情况")) {
|
|
|
+ failUsers.add(studentName);
|
|
|
+ } else {
|
|
|
+ successUsers.add(studentName);
|
|
|
}
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
nullUsers.add(studentName);
|
|
|
}
|
|
|
- }
|
|
|
}else{
|
|
|
errorImages.add(entry.getName());
|
|
|
}
|
|
@@ -506,9 +497,8 @@ public class AcsService {
|
|
|
//获取去除后缀名的文件名,需要设置成学号
|
|
|
String userNumber = entry.getName().substring(0, entry.getName().lastIndexOf('-'));
|
|
|
String studentName = entry.getName().substring(entry.getName().lastIndexOf('-') + 1, entry.getName().lastIndexOf('.'));
|
|
|
- System.out.println("学号:" + userNumber);
|
|
|
- System.out.println("学生名字:" + studentName);
|
|
|
-
|
|
|
+// System.out.println("学号:" + userNumber);
|
|
|
+// System.out.println("学生名字:" + studentName);
|
|
|
File newFile = new File(tempDir, entry.getName());
|
|
|
// 进行解压
|
|
|
try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(newFile))) {
|
|
@@ -519,7 +509,7 @@ public class AcsService {
|
|
|
}
|
|
|
}
|
|
|
String result =getUser(userNumber);
|
|
|
- if (result!=null){//用户不为空,为用户添加人脸
|
|
|
+ //用户不为空,为用户添加人脸
|
|
|
Gson gson = new Gson();
|
|
|
JsonObject jsonObject = gson.fromJson(result, JsonObject.class);
|
|
|
|
|
@@ -527,22 +517,17 @@ public class AcsService {
|
|
|
.getAsJsonObject("UserInfoSearch")
|
|
|
.getAsJsonArray("UserInfo");
|
|
|
if (userInfoArray!=null) {
|
|
|
- JsonObject userInfo = userInfoArray.get(0).getAsJsonObject();
|
|
|
- String empNo = userInfo.get("employeeNo").getAsString();
|
|
|
- if (empNo != null) {
|
|
|
- String photoUrl = fileApi.createFile(Files.readAllBytes(newFile.toPath()));
|
|
|
- //给对应学号的人的照片添加
|
|
|
- String msg = addFaceByUrl(userNumber, photoUrl);
|
|
|
- //System.out.println("数据"+msg);
|
|
|
- if (msg.contains("下发人脸成功") && msg.contains("但是有异常情况")) {
|
|
|
- failUsers.add(studentName);
|
|
|
- } else {
|
|
|
- successUsers.add(studentName);
|
|
|
- }
|
|
|
+ String photoUrl = fileApi.createFile(Files.readAllBytes(newFile.toPath()));
|
|
|
+ //给对应学号的人的照片添加
|
|
|
+ String msg = addFaceByUrl(userNumber, photoUrl);
|
|
|
+ //System.out.println("数据"+msg);
|
|
|
+ if (msg.contains("下发人脸成功") && msg.contains("但是有异常情况")) {
|
|
|
+ failUsers.add(studentName);
|
|
|
+ } else {
|
|
|
+ successUsers.add(studentName);
|
|
|
}
|
|
|
- }
|
|
|
- }else{
|
|
|
- nullUsers.add(studentName);//添加找不到的用户
|
|
|
+ } else{
|
|
|
+ nullUsers.add(studentName);//添加找不到的用户
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -604,7 +589,7 @@ public class AcsService {
|
|
|
|
|
|
|
|
|
|
|
|
- @Transactional(rollbackFor = Exception.class) // 事务管理
|
|
|
+ @Transactional(rollbackFor = Exception.class) // 是先插入的
|
|
|
public String testData(MultipartFile excelFile, MultipartFile imageFile, boolean updateSupport) throws Exception {
|
|
|
// 1. 导入用户信息
|
|
|
if (excelFile!=null){
|