wangliang 3 жил өмнө
parent
commit
9922452086

+ 13 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/entity/SysOrg.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
 import com.qmth.teachcloud.common.base.BaseEntity;
+import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.enums.OrgTypeEnum;
 import io.swagger.annotations.ApiModelProperty;
 
@@ -62,6 +63,18 @@ public class SysOrg extends BaseEntity implements Serializable {
     @ApiModelProperty("历史机构名")
     private String historicName;
 
+    public SysOrg() {
+
+    }
+
+    public SysOrg(Long schoolId, String name) {
+        setId(SystemConstant.getDbUuid());
+        this.schoolId = schoolId;
+        this.type = OrgTypeEnum.SCHOOL;
+        this.name = name;
+        this.enable = true;
+    }
+
     public String getHistoricName() {
         return historicName;
     }

+ 2 - 2
teachcloud-common/src/main/java/com/qmth/teachcloud/common/mapper/SysOrgMapper.java

@@ -1,6 +1,6 @@
 package com.qmth.teachcloud.common.mapper;
 
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.qmth.teachcloud.common.base.CustomBaseMapper;
 import com.qmth.teachcloud.common.bean.dto.OrgDto;
 import com.qmth.teachcloud.common.entity.SysOrg;
 import com.qmth.teachcloud.common.entity.SysUser;
@@ -16,7 +16,7 @@ import java.util.List;
  * @author xf
  * @since 2021-03-23
  */
-public interface SysOrgMapper extends BaseMapper<SysOrg> {
+public interface SysOrgMapper extends CustomBaseMapper<SysOrg> {
 
     /**
      * 根据机构类型查找用户

+ 26 - 7
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/AuthInfoServiceImpl.java

@@ -9,16 +9,15 @@ import com.qmth.teachcloud.common.bean.dto.AuthOrgInfoDto;
 import com.qmth.teachcloud.common.config.DictionaryConfig;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.BasicSchool;
+import com.qmth.teachcloud.common.entity.SysOrg;
 import com.qmth.teachcloud.common.entity.TSAuth;
 import com.qmth.teachcloud.common.enums.AuthEnum;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.enums.UploadFileEnum;
 import com.qmth.teachcloud.common.mapper.BasicSchoolMapper;
+import com.qmth.teachcloud.common.mapper.SysOrgMapper;
 import com.qmth.teachcloud.common.mapper.TSAuthMapper;
-import com.qmth.teachcloud.common.service.AuthInfoService;
-import com.qmth.teachcloud.common.service.BasicSchoolService;
-import com.qmth.teachcloud.common.service.CommonCacheService;
-import com.qmth.teachcloud.common.service.TSAuthService;
+import com.qmth.teachcloud.common.service.*;
 import com.qmth.teachcloud.common.util.FileStoreUtil;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.slf4j.Logger;
@@ -74,6 +73,12 @@ public class AuthInfoServiceImpl implements AuthInfoService {
     @Resource
     AuthInfoService authInfoService;
 
+    @Resource
+    SysOrgService sysOrgService;
+
+    @Resource
+    SysOrgMapper sysOrgMapper;
+
     /**
      * 授权信息初始化
      *
@@ -171,10 +176,12 @@ public class AuthInfoServiceImpl implements AuthInfoService {
         List<TSAuth> tsAuthList = null;
         Set<Long> orgIdsSet = null;
         Set<BasicSchool> basicSchoolSet = null;
+        Set<SysOrg> sysOrgSet = null;
         if (!CollectionUtils.isEmpty(orgInfoList)) {
             tsAuthList = new ArrayList<>();
             orgIdsSet = new HashSet<>();
             basicSchoolSet = new HashSet<>();
+            sysOrgSet = new HashSet<>();
         }
         boolean oss = dictionaryConfig.sysDomain().isOss();
         for (OrgInfo o : orgInfoList) {
@@ -192,9 +199,9 @@ public class AuthInfoServiceImpl implements AuthInfoService {
 
             QueryWrapper<BasicSchool> basicSchoolQueryWrapper = new QueryWrapper<>();
             basicSchoolQueryWrapper.lambda().eq(BasicSchool::getCode, o.getCode());
-            int count = basicSchoolService.count(basicSchoolQueryWrapper);
-            if (count == 0) {//不存在则创建学校
-                BasicSchool basicSchool = new BasicSchool(o.getCode(), o.getName(), o.getAccessKey(), o.getAccessSecret());
+            BasicSchool basicSchool = basicSchoolService.getOne(basicSchoolQueryWrapper);
+            if (Objects.isNull(basicSchool)) {//不存在则创建学校
+                basicSchool = new BasicSchool(o.getCode(), o.getName(), o.getAccessKey(), o.getAccessSecret());
                 if (Objects.nonNull(o.getLogo()) && (!o.getLogo().startsWith("https:") || !o.getLogo().startsWith("http"))) {
                     String filePath = SystemConstant.TEMP_FILES_DIR + File.separator + SystemConstant.getUuid() + ".jpg";
                     File logoFile = new File(filePath);
@@ -224,7 +231,15 @@ public class AuthInfoServiceImpl implements AuthInfoService {
                 }
                 basicSchoolSet.add(basicSchool);
             }
+
+            QueryWrapper<SysOrg> sysOrgQueryWrapper = new QueryWrapper<>();
+            sysOrgQueryWrapper.lambda().eq(SysOrg::getSchoolId, basicSchool.getId());
+            int count = sysOrgService.count(sysOrgQueryWrapper);
+            if (count == 0) {
+                sysOrgSet.add(new SysOrg(basicSchool.getId(), basicSchool.getName()));
+            }
         }
+
         if (!CollectionUtils.isEmpty(tsAuthList) && !CollectionUtils.isEmpty(orgIdsSet)) {
             QueryWrapper<TSAuth> tsAuthQueryWrapper = new QueryWrapper<>();
             tsAuthQueryWrapper.lambda().in(TSAuth::getSchoolId, orgIdsSet);
@@ -234,6 +249,10 @@ public class AuthInfoServiceImpl implements AuthInfoService {
             if (!CollectionUtils.isEmpty(basicSchoolSet)) {
                 basicSchoolMapper.insertBatch(basicSchoolSet);
             }
+
+            if (!CollectionUtils.isEmpty(sysOrgSet)) {
+                sysOrgMapper.insertBatch(sysOrgSet);
+            }
         }
     }
 }