|
@@ -345,64 +345,67 @@ public class AcsService {
|
|
|
//教师添加或更新照片
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public String teacherUpdateUserImage(String employeeNo, String photoUrl) throws Exception {
|
|
|
- AdminUserDO user = userService.findUserByUserNumber(employeeNo);
|
|
|
- String result = getUser(employeeNo);
|
|
|
- Gson gson = new Gson();
|
|
|
- JsonObject jsonObject = gson.fromJson(result, JsonObject.class);
|
|
|
- JsonArray userInfoArray = jsonObject
|
|
|
- .getAsJsonObject("UserInfoSearch")
|
|
|
- .getAsJsonArray("UserInfo");
|
|
|
-
|
|
|
- if (photoUrl.trim().isEmpty()&&user.getPhotoUrl()!=null){//去除空格后为空,删除人脸
|
|
|
- deleteFace(employeeNo);//考勤机里的
|
|
|
- user.setPhotoUrl(photoUrl.trim());//同步更新user表里的
|
|
|
- user.setPhotoUpdateTime(LocalDateTime.now());//更新时间
|
|
|
- userService.updateUser(BeanUtils.toBean(user, UserSaveReqVO.class));
|
|
|
- return "删除照片成功";
|
|
|
- }else {
|
|
|
- if (userInfoArray != null) {
|
|
|
- String msg = addFaceByUrl(employeeNo, photoUrl);
|
|
|
- if (msg.contains("下发人脸成功") && msg.contains("但是有异常情况")) {
|
|
|
- return "更新照片失败,请检查照片大小并确保包含人脸";
|
|
|
- } else {
|
|
|
- if (user != null) {
|
|
|
- user.setPhotoUrl(photoUrl);
|
|
|
- user.setPhotoUpdateTime(LocalDateTime.now());
|
|
|
- userService.updateUser((BeanUtils.toBean(user, UserSaveReqVO.class)));
|
|
|
- }
|
|
|
- return "更新照片成功";
|
|
|
- }
|
|
|
- }else {//考勤及里面没用户
|
|
|
- //确保在执行完增加用户后执行增加人脸
|
|
|
- CompletableFuture<Void> userFuture = CompletableFuture.runAsync(() -> {
|
|
|
- try {
|
|
|
- addUser(employeeNo, user.getNickname());
|
|
|
- } catch (JSONException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- } catch (UnsupportedEncodingException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- } catch (InterruptedException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
+ if (employeeNo!=null) {
|
|
|
+ AdminUserDO user = userService.findUserByUserNumber(employeeNo);
|
|
|
+ String result = getUser(employeeNo);
|
|
|
+ Gson gson = new Gson();
|
|
|
+ JsonObject jsonObject = gson.fromJson(result, JsonObject.class);
|
|
|
+ JsonArray userInfoArray = jsonObject
|
|
|
+ .getAsJsonObject("UserInfoSearch")
|
|
|
+ .getAsJsonArray("UserInfo");
|
|
|
+
|
|
|
+ if (photoUrl.trim().isEmpty() && user.getPhotoUrl() != null) {//去除空格后为空,删除人脸
|
|
|
+ deleteFace(employeeNo);//考勤机里的
|
|
|
+ user.setPhotoUrl(photoUrl.trim());//同步更新user表里的
|
|
|
+ user.setPhotoUpdateTime(LocalDateTime.now());//更新时间
|
|
|
+ userService.updateUser(BeanUtils.toBean(user, UserSaveReqVO.class));
|
|
|
+ return "删除照片成功";
|
|
|
+ } else {
|
|
|
+ if (userInfoArray != null) {
|
|
|
+ String msg = addFaceByUrl(employeeNo, photoUrl);
|
|
|
+ if (msg.contains("下发人脸成功") && msg.contains("但是有异常情况")) {
|
|
|
+ return "更新照片失败,请检查照片大小并确保包含人脸";
|
|
|
+ } else {
|
|
|
+ if (user != null) {
|
|
|
+ user.setPhotoUrl(photoUrl);
|
|
|
+ user.setPhotoUpdateTime(LocalDateTime.now());
|
|
|
+ userService.updateUser((BeanUtils.toBean(user, UserSaveReqVO.class)));
|
|
|
+ }
|
|
|
+ return "更新照片成功";
|
|
|
}
|
|
|
- });
|
|
|
- userFuture.thenRun(() -> {
|
|
|
- try {
|
|
|
- String msg = addFaceByUrl(employeeNo, photoUrl);
|
|
|
- if (msg.contains("下发人脸成功") && msg.contains("但是有异常情况")) {
|
|
|
- } else {
|
|
|
- if (user!=null) {
|
|
|
- user.setPhotoUpdateTime(LocalDateTime.now());
|
|
|
- user.setPhotoUrl(photoUrl);
|
|
|
- userService.updateUser((BeanUtils.toBean(user, UserSaveReqVO.class)));
|
|
|
+ } else {//考勤及里面没用户
|
|
|
+ //确保在执行完增加用户后执行增加人脸
|
|
|
+ CompletableFuture<Void> userFuture = CompletableFuture.runAsync(() -> {
|
|
|
+ try {
|
|
|
+ addUser(employeeNo, 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 {
|
|
|
+ String msg = addFaceByUrl(employeeNo, photoUrl);
|
|
|
+ if (msg.contains("下发人脸成功") && msg.contains("但是有异常情况")) {
|
|
|
+ } else {
|
|
|
+ if (user != null) {
|
|
|
+ user.setPhotoUpdateTime(LocalDateTime.now());
|
|
|
+ user.setPhotoUrl(photoUrl);
|
|
|
+ userService.updateUser((BeanUtils.toBean(user, UserSaveReqVO.class)));
|
|
|
+ }
|
|
|
}
|
|
|
+ } catch (JSONException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
- } catch (JSONException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
- });
|
|
|
- return "添加考勤用户并且增加照片成功";
|
|
|
+ });
|
|
|
+ return "更新照片成功";
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ return "该用户无学号/工号";
|
|
|
}
|
|
|
|
|
|
//批量导入用户信息
|
|
@@ -453,7 +456,7 @@ public class AcsService {
|
|
|
while ((entry = zipInputStream.getNextEntry()) != null) {
|
|
|
if (!entry.isDirectory()) {
|
|
|
if (isValidImageName(entry.getName()).equals("照片格式正确")) {
|
|
|
-// System.out.println(entry.getName());
|
|
|
+ LocalDateTime nowTime =LocalDateTime.now();
|
|
|
//获取去除后缀名的文件名,需要设置成学号
|
|
|
String userNumber = entry.getName().substring(0, entry.getName().lastIndexOf('-'));
|
|
|
String studentName = entry.getName().substring(entry.getName().lastIndexOf('-') + 1, entry.getName().lastIndexOf('.'));
|
|
@@ -486,7 +489,7 @@ public class AcsService {
|
|
|
} else {
|
|
|
respVO.getCreateImages().add(studentName);//添加成功
|
|
|
if (user!=null) {
|
|
|
- user.setPhotoUpdateTime(LocalDateTime.now());//更新时间
|
|
|
+ user.setPhotoUpdateTime(nowTime);//更新时间
|
|
|
user.setPhotoUrl(photoUrl);
|
|
|
userService.updateUser((BeanUtils.toBean(user, UserSaveReqVO.class)));
|
|
|
}
|