Browse Source

fix: 用户同步

caozixuan 3 years ago
parent
commit
5d8fce78a2

+ 1 - 1
distributed-print/src/main/resources/application-dev.properties

@@ -144,7 +144,7 @@ sync.config.studentScoreUrl=/api/exam/student/score
 # ͬ²½ÊÔ¾í½á¹¹
 sync.config.structureUrl=/api/exam/paper/save
 # Óû§Í¬²½
-sync.config.userSaveUrl=/api/user/save
+sync.config.userSaveUrl=/api/user/external/save
 
 
 sms.config.smsNormalCode=qmth

+ 3 - 4
distributed-print/src/test/java/com/qmth/distributed/print/SyncHelpTest.java

@@ -1,10 +1,9 @@
 package com.qmth.distributed.print;
 
 import com.qmth.teachcloud.common.bean.params.UserPushParam;
-import com.qmth.distributed.print.business.service.DataSyncService;
 import com.qmth.teachcloud.common.enums.userPush.SpecialPrivilegeEnum;
-import com.qmth.teachcloud.common.service.CallApiOrgCenterService;
 import com.qmth.teachcloud.common.service.SysUserService;
+import com.qmth.teachcloud.common.sync.StmmsUtils;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.boot.test.context.SpringBootTest;
@@ -22,7 +21,7 @@ import javax.annotation.Resource;
 public class SyncHelpTest {
 
     @Resource
-    private CallApiOrgCenterService callApiOrgCenterService;
+    private StmmsUtils stmmsUtils;
     @Resource
     private SysUserService sysUserService;
 
@@ -40,7 +39,7 @@ public class SyncHelpTest {
             }else {
                 userPushParam.setRole(SpecialPrivilegeEnum.SUBJECT_HEADER);
             }
-            callApiOrgCenterService.basicSyncUser(userPushParam,2L);
+            stmmsUtils.syncUser(userPushParam,2L);
         }
     }
 

+ 11 - 5
teachcloud-common/src/main/java/com/qmth/teachcloud/common/enums/userPush/SpecialPrivilegeEnum.java

@@ -6,21 +6,23 @@ package com.qmth.teachcloud.common.enums.userPush;
  * @Date: 2021-10-27
  */
 public enum SpecialPrivilegeEnum {
-    MARKER("评卷员权限","Marker","M_"),
-    SUBJECT_HEADER("科组长权限","SubjectHeader","S_"),
-    COMPOSITE("复合权限","Composite",null),
-    UNIDENTIFIED("无特殊权限","Unidentified",null),
+    SUBJECT_HEADER("科组长权限","SubjectHeader","S_", 4),
+    MARKER("评卷员权限","Marker","M_", 5),
+    COMPOSITE("复合权限","Composite",null, 0),
+    UNIDENTIFIED("无特殊权限","Unidentified",null, 0),
     ;
 
-    SpecialPrivilegeEnum(String title, String id, String prefix) {
+    SpecialPrivilegeEnum(String title, String id, String prefix, int value) {
         this.title = title;
         this.id = id;
         this.prefix = prefix;
+        this.value = value;
     }
 
     private final String title;
     private final String id;
     private final String prefix;
+    private final int value;
 
     public String getTitle() {
         return title;
@@ -33,4 +35,8 @@ public enum SpecialPrivilegeEnum {
     public String getPrefix() {
         return prefix;
     }
+
+    public int getValue() {
+        return value;
+    }
 }

+ 0 - 12
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/CallApiOrgCenterService.java

@@ -1,7 +1,5 @@
 package com.qmth.teachcloud.common.service;
 
-import com.qmth.teachcloud.common.bean.params.UserPushParam;
-
 import java.io.IOException;
 import java.util.List;
 import java.util.Map;
@@ -19,14 +17,4 @@ public interface CallApiOrgCenterService {
      * @throws IOException 异常
      */
     List<Map> callOrgInfo() throws IOException;
-
-
-    /**
-     * 基础用户同步(推送)云阅卷接口
-     *
-     * @param userPushParam 用户推送参数
-     * @param schoolId 学校主键
-     * @return 是否成功
-     */
-    boolean basicSyncUser(UserPushParam userPushParam, Long schoolId) throws IllegalAccessException;
 }

+ 0 - 39
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/CallApiOrgCenterServiceImpl.java

@@ -1,11 +1,8 @@
 package com.qmth.teachcloud.common.service.impl;
 
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.qmth.boot.tools.signature.SignatureEntity;
 import com.qmth.boot.tools.signature.SignatureType;
-import com.qmth.teachcloud.common.bean.params.UserPushParam;
-import com.qmth.teachcloud.common.bean.result.DBVerifyResult;
 import com.qmth.teachcloud.common.config.DictionaryConfig;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
@@ -72,40 +69,4 @@ public class CallApiOrgCenterServiceImpl implements CallApiOrgCenterService {
         }
         return orgList;
     }
-
-
-    @Override
-    public boolean basicSyncUser(UserPushParam userPushParam, Long schoolId) throws IllegalAccessException {
-        DBVerifyResult dbVerifyResult = SystemConstant.verifyDBFields(userPushParam, userPushParam.getClass());
-        boolean result = dbVerifyResult.getStatus();
-        if (!result) {
-            log.warn(dbVerifyResult.getMessage());
-            return false;
-        }
-//        String hostUrl = dictionaryConfig.syncDataDomain().getHostUrl();
-//        String userSaveUrl = dictionaryConfig.syncDataDomain().getUserSaveUrl();
-//        String postUrl = hostUrl.concat(userSaveUrl);
-//        // 参数
-//        Map paramMap = JSON.parseObject(JSON.toJSONString(userPushParam), Map.class);
-//
-//        String httpResult = HttpKit.sendPost(postUrl, getHeaders(schoolId, userSaveUrl), paramMap, null, null, null);
-//        JSONObject jsonObject = JSONObject.parseObject(httpResult);
-//        if (jsonObject.containsKey("updateTime")) {
-//            return true;
-//        } else {
-//            log.warn("用户推送(同步)失败");
-//            return false;
-//        }
-        {
-            // 模拟云阅卷返回结果 3/5的成功率
-            int x = (int) (Math.random() * 10);
-            if (x > 0) {
-                // 失败
-                log.warn("x = " + x + ",云阅卷用户同步失败 \n" + JSON.toJSONString(userPushParam));
-                return false;
-            } else {
-                return true;
-            }
-        }
-    }
 }

+ 7 - 6
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/SysUserServiceImpl.java

@@ -32,13 +32,11 @@ import com.qmth.teachcloud.common.enums.userPush.SpecialPrivilegeEnum;
 import com.qmth.teachcloud.common.enums.userPush.SyncStatusEnum;
 import com.qmth.teachcloud.common.mapper.SysUserMapper;
 import com.qmth.teachcloud.common.service.*;
+import com.qmth.teachcloud.common.sync.StmmsUtils;
 import com.qmth.teachcloud.common.util.Base64Util;
 import com.qmth.teachcloud.common.util.ResultUtil;
 import com.qmth.teachcloud.common.util.ServletUtil;
-import javassist.bytecode.stackmap.BasicBlock;
 import org.apache.commons.lang3.StringUtils;
-import org.redisson.api.ExpiredObjectListener;
-import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.dao.DuplicateKeyException;
 import org.springframework.stereotype.Service;
@@ -109,6 +107,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
     @Resource
     PushUserErrorService pushUserErrorService;
 
+    @Resource
+    StmmsUtils stmmsUtils;
+
 
     @Override
     public IPage<UserDto> list(String loginName, String roleId, Boolean enable, String realName, Integer pageNumber, Integer pageSize) {
@@ -934,10 +935,10 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
 
     @Transactional
     @Override
-    public boolean userPushService(List<UserPushParam> userPushParamList, SysUser requestUser) throws IllegalAccessException {
+    public boolean userPushService(List<UserPushParam> userPushParamList, SysUser requestUser) {
         boolean result = true;
         for (UserPushParam userPushParam : userPushParamList) {
-            boolean syncResult = callApiOrgCenterService.basicSyncUser(userPushParam, requestUser.getSchoolId());
+            boolean syncResult = stmmsUtils.syncUser(userPushParam, requestUser.getSchoolId());
             if (!syncResult) {
                 log.warn("-----------------------------用户同步推送失败----------------------------");
                 result = false;
@@ -1249,6 +1250,6 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
         String code = dbUser.getCode();
         Set<Long> roleIdList = new HashSet<>(sysRoleService.getUserRoles(userId));
         PushBeforeRoleParam pushBeforeRoleParam = new PushBeforeRoleParam(null, BeforeJudgeEnum.FORBIDDEN_NECESSARY);
-        return this.analyzeUserPushSpecialPrivilege(userId, schoolId, code, null, null, roleIdList, pushBeforeRoleParam, enable);
+        return this.analyzeUserPushSpecialPrivilege(userId, schoolId, code, dbUser.getRealName(), dbUser.getPassword(), roleIdList, pushBeforeRoleParam, enable);
     }
 }

+ 43 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/sync/StmmsUtils.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.qmth.boot.tools.signature.SignatureType;
 import com.qmth.teachcloud.common.SignatureEntityTest;
 import com.qmth.teachcloud.common.bean.dto.SyncStructureData;
+import com.qmth.teachcloud.common.bean.params.UserPushParam;
 import com.qmth.teachcloud.common.config.DictionaryConfig;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.BasicSchool;
@@ -77,6 +78,48 @@ public class StmmsUtils {
         }
     }
 
+    public boolean syncUser(UserPushParam userPushParam,Long schoolId) {
+        String account = userPushParam.getAccount();
+        String name = userPushParam.getName();
+        String password = userPushParam.getPassword();
+        int roleValue = userPushParam.getRole().getValue();
+        Boolean enable = userPushParam.getEnable();
+
+
+        String hostUrl = dictionaryConfig.syncDataDomain().getHostUrl();
+        String userSaveUrl = dictionaryConfig.syncDataDomain().getUserSaveUrl();
+        String postUrl = hostUrl.concat(userSaveUrl);
+        // 参数
+        Map<String, Object> map = new HashMap<>();
+        map.put("account", validParam(account, null, true, "关联名称(唯一标识)"));
+        map.put("name", validParam(name, null, false, "名称"));
+        map.put("password", validParam(password, null, false, "密码"));
+        map.put("role", validParam(String.valueOf(roleValue), null, true, "类型:MARKER、SUBJECT_HEADER"));
+        map.put("enable", validParam(enable, true, false, "是否启用"));
+
+
+        String result = HttpKit.sendPost(postUrl, getHeaders(schoolId, userSaveUrl), map, null, null, null);
+        JSONObject jsonObject = JSONObject.parseObject(result);
+        if (jsonObject.containsKey("updateTime")) {
+            return true;
+        } else {
+            log.warn("用户推送(同步)失败");
+            return false;
+        }
+
+//        {
+//            // 模拟云阅卷返回结果 3/5的成功率
+//            int x = (int) (Math.random() * 10);
+//            if (x > 0) {
+//                // 失败
+//                log.warn("x = " + x + ",云阅卷用户同步失败 \n");
+//                return false;
+//            } else {
+//                return true;
+//            }
+//        }
+    }
+
     /**
      * 考生创建/更新接口
      *