|
@@ -1,23 +1,13 @@
|
|
|
package com.qmth.teachcloud.report.start;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.qmth.teachcloud.common.bean.params.UserSaveParams;
|
|
|
-import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
|
-import com.qmth.teachcloud.common.entity.*;
|
|
|
-import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
|
-import com.qmth.teachcloud.common.enums.OrgTypeEnum;
|
|
|
-import com.qmth.teachcloud.common.enums.RoleTypeEnum;
|
|
|
-import com.qmth.teachcloud.common.service.*;
|
|
|
+import com.qmth.teachcloud.common.service.AuthInfoService;
|
|
|
+import com.qmth.teachcloud.common.service.SysUserService;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.boot.CommandLineRunner;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @Description: 服务启动时初始化运行,哪个微服务模块需要则拿此模版去用
|
|
@@ -33,60 +23,13 @@ public class StartRunning implements CommandLineRunner {
|
|
|
@Resource
|
|
|
AuthInfoService authInfoService;
|
|
|
@Resource
|
|
|
- BasicSchoolService basicSchoolService;
|
|
|
- @Resource
|
|
|
- SysRoleService sysRoleService;
|
|
|
- @Resource
|
|
|
- SysOrgService sysOrgService;
|
|
|
- @Resource
|
|
|
SysUserService sysUserService;
|
|
|
- @Resource
|
|
|
- SysUserRoleService sysUserRoleService;
|
|
|
|
|
|
@Override
|
|
|
- public void run(String... args) throws IllegalAccessException {
|
|
|
+ public void run(String... args) {
|
|
|
log.info("服务器启动时执行 start");
|
|
|
authInfoService.appInfoInit();
|
|
|
-
|
|
|
- // 为没有学校管理员的学校自动创建一个学校管理员
|
|
|
- List<BasicSchool> basicSchoolList = basicSchoolService.list();
|
|
|
- SysRole role = sysRoleService.list(new QueryWrapper<SysRole>().lambda().eq(SysRole::getType, RoleTypeEnum.SCHOOL_ADMIN)).get(0);
|
|
|
- List<Long> roleIds = new ArrayList<>();
|
|
|
- roleIds.add(role.getId());
|
|
|
- for (BasicSchool basicSchool : basicSchoolList) {
|
|
|
- Long schoolId = basicSchool.getId();
|
|
|
- SysOrg schoolOrg = sysOrgService.getOne(new QueryWrapper<SysOrg>().lambda()
|
|
|
- .eq(SysOrg::getSchoolId, schoolId)
|
|
|
- .eq(SysOrg::getType, OrgTypeEnum.SCHOOL));
|
|
|
- if (Objects.isNull(schoolOrg)) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("未找到学校对应的顶级机构");
|
|
|
- }
|
|
|
- // 用户id集合
|
|
|
- List<Long> adminUserIdList = sysUserRoleService.list(new QueryWrapper<SysUserRole>().lambda()
|
|
|
- .in(SysUserRole::getRoleId,roleIds))
|
|
|
- .stream()
|
|
|
- .map(SysUserRole::getUserId)
|
|
|
- .distinct().collect(Collectors.toList());
|
|
|
- if (adminUserIdList.size() > 0){
|
|
|
- List<SysUser> adminUserList = sysUserService.list(new QueryWrapper<SysUser>().lambda()
|
|
|
- .eq(SysUser::getSchoolId,schoolId)
|
|
|
- .in(SysUser::getId,adminUserIdList));
|
|
|
- if (adminUserList.size() > 0){
|
|
|
- // 存在管理员
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
- UserSaveParams userSaveParams = new UserSaveParams();
|
|
|
- userSaveParams.setSchoolId(schoolId);
|
|
|
- userSaveParams.setLoginName("admin");
|
|
|
- userSaveParams.setRealName("学校管理员");
|
|
|
- userSaveParams.setPassword(SystemConstant.DEFAULT_PASSWORD);
|
|
|
-
|
|
|
- userSaveParams.setOrgId(schoolOrg.getId());
|
|
|
- userSaveParams.setEnable(true);
|
|
|
- userSaveParams.setRoleIds(roleIds.toArray(new Long[0]));
|
|
|
- sysUserService.saveUserNoAuth(userSaveParams);
|
|
|
- }
|
|
|
+ sysUserService.buildAdministratorForSchool();
|
|
|
log.info("服务器启动时执行 end");
|
|
|
}
|
|
|
}
|