夏文涛 6 months ago
parent
commit
d8c312f641

+ 4 - 0
src/main/java/com/template/api/SmartUserControllerAPI.java

@@ -129,6 +129,10 @@ public interface SmartUserControllerAPI {
     @ApiOperation(value = "编辑用户数据", notes = "编辑用户数据", httpMethod = "POST")
     CommonResult updateSmartUserById(@Validated @RequestBody updateSmartUserRequest ra, BindingResult bindingResult) throws Exception;
 
+    @PostMapping(value = "/updateSmartUserImageById")
+    @ApiOperation(value = "编辑用户人脸数据", notes = "编辑用户人脸数据", httpMethod = "POST")
+    CommonResult updateSmartUserImageById(@Validated @RequestBody updateSmartUserImageRequest ra, BindingResult bindingResult) throws Exception;
+
     @GetMapping(value = "/queryPageSmartUser")
     @ApiOperation(value = "用户分页数据", notes = "用户分页数据", httpMethod = "GET")
     CommonResult queryPageSmartUser(@RequestParam int currentPage, @RequestParam int pageCount, Integer departmentId, String name,Integer ifGraduate, @RequestHeader("user_head") String userhead);

+ 113 - 0
src/main/java/com/template/controller/SmartUserController.java

@@ -5630,6 +5630,119 @@ public class SmartUserController implements SmartUserControllerAPI {
         //endregion
         return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
     }
+
+    @Override
+    public CommonResult updateSmartUserImageById(updateSmartUserImageRequest usur, BindingResult bindingResult) throws Exception {
+        if (bindingResult.hasErrors()) {
+            String st = paramUtils.getParamError(bindingResult);
+            return CommonResult.fail(st);
+        }
+
+        //region 参数判断
+        if (usur.getHeadImage() == null) {
+            return CommonResult.fail("学生人脸照片不能为空");
+        }
+
+        //endregion
+
+        int useXw = 1;
+        int useBs = 1;
+
+        //更新的同时将百胜用户信息同步过去或者同步过来?
+        SmartUser su = smartUserService.getSmartById(usur.getId());
+        if (su == null) {
+            return CommonResult.fail("用户数据已失效,修改失败!");
+        }
+
+
+        Integer oldSchoolClass = su.getOldSchoolClass();
+        if (ObjectUtils.isEmpty(oldSchoolClass)) {
+            oldSchoolClass = su.getSchoolClass();
+        }
+
+        SmartClass classData = smartClassService.getSmartClassById(oldSchoolClass);
+        if(classData == null){
+            return CommonResult.fail("班级数据无效,更新失败");
+        }
+        SmartGrade gradeData = smartGradeService.querySmartGradeById(su.getGrade() == null || su.getGrade() == "" ? null : Integer.valueOf(su.getGrade()));
+        if (gradeData == null) {
+            return CommonResult.fail("年级数据无效,更新失败");
+        }
+
+        SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
+
+        su.setHeadImage(usur.getHeadImage());
+
+        //region 更新希沃学生信息
+        if (useXw == 1) {
+            CommonResult updateStudent = SeewoUpdateStudent(seewoClient, su);
+            if (!updateStudent.isSuccess()) {
+                if (updateStudent.getMessage().contains("学生不存在")) {
+                    CommonResult<String> insertStudent = SeewoInsertStudent(seewoClient, su.getName(), su.getCardNo(), su.getSexId(), su.getPhone(), classData.getClassUid());
+                    if (!insertStudent.isSuccess()) {
+                        return CommonResult.fail("希沃平台:" + insertStudent.getMessage());
+                    }
+                }
+            } else {
+                if (!su.getSchoolClass().equals(oldSchoolClass)) {
+                    //获取班级Uid
+                    SmartClass oldClassData = smartClassService.getSmartClassById(oldSchoolClass);
+                    if (oldClassData == null) {
+                        return CommonResult.fail("班级数据无效,更新失败");
+                    }
+
+                    CommonResult changeClass = SeewoChangeClass(seewoClient, seewoConfig.getSchoolId(), su.getXwStudentUid(), oldClassData.getClassUid(), classData.getClassUid());
+                    if (!changeClass.isSuccess()) {
+                        return CommonResult.fail("希沃平台:" + changeClass.getMessage());
+                    }
+                }
+
+            }
+
+            //上传图片
+            List<PhotoServiceSavePhotosParam.ThirdSavePhotoQuery> photoList = new ArrayList<>();
+            PhotoServiceSavePhotosParam.ThirdSavePhotoQuery photo = new PhotoServiceSavePhotosParam.ThirdSavePhotoQuery();
+            photo.setPhotoUrl(su.getHeadImage());
+            photo.setUserCode(su.getCardNo());
+            photoList.add(photo);
+            CommonResult result = SeewoInsertBatchPhoto(seewoClient, photoList, eSeewoUserType.Student.getValue());
+            if (!result.isSuccess()) {
+                return result;
+            }
+        }
+        //endregion
+
+        //region 更新百胜学生信息
+        if (useBs == 1) {
+            /**
+             * 学生数据的有效期是到毕业年份的8月31日
+             */
+            String startTime = TimeExchange.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
+            String endTime = queryGraduationYear(gradeData.getGradeNo());
+            CommonResult updateBsStudent = bsUpdateStudent(su, classData.getBsClassNo(), startTime, endTime);
+            if (!updateBsStudent.isSuccess()) {
+
+                return CommonResult.fail("百胜平台:" + updateBsStudent.getMessage());
+            }
+        }
+        //endregion
+
+        int result = smartUserService.updateSmartUser(su);
+//        修改需同步到海康平台
+        if (result > 0) {
+            Integer identityId = su.getIdentityId();
+            if (2 == identityId || identityId == 3) {
+                Integer id = su.getId();
+                SmartOperationUser smartOperationUser = new SmartOperationUser();
+                smartOperationUser.setOperationId(id);
+                smartOperationUser.setOperationMode("2");
+                smartOperationUser.setStatus(1);
+                smartOperationUser.setType(identityId);
+                smartOperationUserService.save(smartOperationUser);
+            }
+        }
+        return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
+    }
     //endregion
 
     //region 希沃增删改查方法

+ 34 - 0
src/main/java/com/template/model/request/updateSmartUserImageRequest.java

@@ -0,0 +1,34 @@
+package com.template.model.request;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+import java.util.List;
+
+
+/**
+ * <p>
+ *
+ * </p>
+ *
+ * @author ceshi
+ * @since 2023-12-04
+ */
+@Data
+public class updateSmartUserImageRequest {
+
+    /**
+     * 数据ID
+     */
+    @NotNull(message = "数据ID不能为空")
+    private Integer id;
+
+    /**
+     * 人脸照片
+     */
+    @NotBlank(message = "人脸照片不能为空")
+    private String headImage;
+
+}