caozixuan 4 rokov pred
rodič
commit
206c6366e1

+ 2 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/contant/SystemConstant.java

@@ -39,6 +39,7 @@ public class SystemConstant {
     public static final String ERROR = "/error";
     public static final String METHOD = "post";
     public static final String DEFAULT_PASSWORD = "MTIzNDU2";
+    public static final String DEFAULT_MOBILE_NUMBER = "11111111111";
     public static final String UPDATE_TIME = "updateTime";
     public static final String PATH = "path";
     public static final String PDF_PATH = "pdfPath";
@@ -67,6 +68,7 @@ public class SystemConstant {
     public static final int OPER_SCALE = 8;
     public static final String HYPHEN = "-";
     public static final String DEFAULT_SIGN = "#";
+    public static final String PARENT_ORG = "武汉大学教务处";
 //    public static final int MAX_RETRY_CREATE_PDF_COUNT = 5;
 
     /**

+ 7 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/SysUserService.java

@@ -51,4 +51,11 @@ public interface SysUserService extends IService<SysUser> {
      * @return 学院数据
      */
     SysUser findByForeignKey(Long schoolId, String teacherCode, String teacherName);
+
+    /**
+     * 临时-不鉴权保存用户 (默认创建用户角色为该学校管理员)
+     * @param userSaveParams 用户参数
+     * @return 结果
+     */
+    boolean saveUserNoAuth(UserSaveParams userSaveParams);
 }

+ 56 - 9
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/SysOrgServiceImpl.java

@@ -3,18 +3,23 @@ package com.qmth.teachcloud.common.service.impl;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.teachcloud.common.bean.dto.OrgDto;
+import com.qmth.teachcloud.common.bean.params.UserSaveParams;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.SysOrg;
+import com.qmth.teachcloud.common.entity.SysRole;
 import com.qmth.teachcloud.common.entity.SysUser;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
+import com.qmth.teachcloud.common.enums.RoleTypeEnum;
 import com.qmth.teachcloud.common.mapper.SysOrgMapper;
 import com.qmth.teachcloud.common.service.SysOrgService;
+import com.qmth.teachcloud.common.service.SysRoleService;
 import com.qmth.teachcloud.common.service.SysUserService;
 import com.qmth.teachcloud.common.util.ServletUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.annotation.Resource;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -29,8 +34,10 @@ import java.util.stream.Collectors;
 @Service
 public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> implements SysOrgService {
 
-    @Autowired
+    @Resource
     private SysUserService sysUserService;
+    @Resource
+    private SysRoleService sysRoleService;
 
     @Override
     public List<OrgDto> listOrgTree() {
@@ -128,14 +135,27 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
 
     @Transactional(rollbackFor = Exception.class)
     @Override
-    public Long searchOrInsert(Long schoolId,String collegeName) {
+    public Long searchOrInsert(Long schoolId, String collegeName) {
         Long orgId;
-        List<SysOrg> sysOrgList = this.list(new QueryWrapper<SysOrg>().lambda().eq(SysOrg::getSchoolId,schoolId));
-        // TODO: 2021/6/23 第一次开课学院进入漏掉了主 武大教务处 
-        SysOrg parentOrg = sysOrgList.stream().filter(e -> e.getParentId() == null || e.getParentId() == 0).collect(Collectors.toList()).get(0);
+        List<SysOrg> sysOrgList = this.list(new QueryWrapper<SysOrg>().lambda().eq(SysOrg::getSchoolId, schoolId));
+        List<SysOrg> parentOrgList = sysOrgList.stream().filter(e -> e.getParentId() == null || e.getParentId() == 0).collect(Collectors.toList());
+        Long parentId;
+        if (parentOrgList.size() == 0) {
+            parentId = SystemConstant.getDbUuid();
+            SysOrg parentTemp = new SysOrg();
+            parentTemp.setId(parentId);
+            parentTemp.setEnable(true);
+            parentTemp.setSchoolId(schoolId);
+            parentTemp.setName(SystemConstant.PARENT_ORG);
+            parentTemp.setCode(SystemConstant.PARENT_ORG);
+            this.save(parentTemp);
+        } else {
+            parentId = parentOrgList.get(0).getId();
+        }
 
-        SysOrg sysOrg = this.getOne(new QueryWrapper<SysOrg>().lambda().eq(SysOrg::getSchoolId,schoolId).eq(SysOrg::getName,collegeName));
-        if (Objects.isNull(sysOrg)){
+        SysOrg sysOrg = this.getOne(new QueryWrapper<SysOrg>().lambda().eq(SysOrg::getSchoolId, schoolId).eq(SysOrg::getName, collegeName));
+        if (Objects.isNull(sysOrg)) {
+            // 创建学院
             orgId = SystemConstant.getDbUuid();
             SysOrg temp = new SysOrg();
             temp.setId(orgId);
@@ -143,9 +163,36 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
             temp.setCode(collegeName);
             temp.setSchoolId(schoolId);
             temp.setEnable(true);
-            temp.setParentId(parentOrg.getId());
+            temp.setParentId(parentId);
             this.save(temp);
-        }else {
+
+            // 创建院长用户
+            SysUser old = sysUserService.getOne(new QueryWrapper<SysUser>().lambda()
+                    .eq(SysUser::getSchoolId, schoolId)
+                    .eq(SysUser::getLoginName, collegeName)
+                    .eq(SysUser::getRealName, collegeName));
+            Long id = 0L;
+            if (Objects.nonNull(old)) {
+                id = old.getId();
+            }
+            SysRole role = sysRoleService.list(new QueryWrapper<SysRole>().lambda().eq(SysRole::getType, RoleTypeEnum.PRESIDENT)).get(0);
+            List<Long> roleIds = new ArrayList<>();
+            roleIds.add(role.getId());
+
+            UserSaveParams userSaveParams = new UserSaveParams();
+            if (id > 0) {
+                userSaveParams.setId(id);
+            }
+
+            userSaveParams.setSchoolId(schoolId);
+            userSaveParams.setLoginName(collegeName);
+            userSaveParams.setRealName(collegeName);
+            userSaveParams.setPassword(SystemConstant.DEFAULT_PASSWORD);
+            userSaveParams.setOrgId(orgId);
+            userSaveParams.setEnable(true);
+            userSaveParams.setRoleIds(roleIds.toArray(new Long[0]));
+            sysUserService.saveUserNoAuth(userSaveParams);
+        } else {
             orgId = sysOrg.getId();
         }
         return orgId;

+ 102 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/SysUserServiceImpl.java

@@ -352,4 +352,106 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
         }
         return isSuccess;
     }
+
+
+    /**
+     * 临时保存用户不鉴权
+     * @param userSaveParams 用户参数
+     * @return 结果
+     */
+    public boolean saveUserNoAuth(UserSaveParams userSaveParams) {
+        boolean isSuccess = true;
+        try {
+            Long schoolId = Objects.nonNull(ServletUtil.getRequestHeaderSchoolIdByNotVaild()) ? Long.valueOf(ServletUtil.getRequestHeaderSchoolIdByNotVaild().toString()) : null;
+            if (schoolId == null){
+                schoolId = userSaveParams.getSchoolId();
+            }
+            List<SysUser> requestUserList = this.list(new QueryWrapper<SysUser>().lambda().eq(SysUser::getSchoolId,schoolId).like(SysUser::getLoginName,"admin"));
+            if (requestUserList.size() == 0){
+                throw ExceptionResultEnum.ERROR.exception("该学校没有内置的学校管理员");
+            }
+            SysUser requestUser = requestUserList.get(0);
+            Gson gson = new Gson();
+            userSaveParams.setSchoolId(schoolId);
+            SysUser sysUser = gson.fromJson(gson.toJson(userSaveParams), SysUser.class);
+            if (Objects.isNull(sysUser.getId())) {//新增用户
+                // 登录名是否唯一
+                QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
+                if (Objects.isNull(schoolId)) {
+                    queryWrapper.lambda().isNull(SysUser::getSchoolId);
+                } else {
+                    queryWrapper.lambda().eq(SysUser::getSchoolId, schoolId);
+                }
+                queryWrapper.lambda().eq(SysUser::getLoginName, sysUser.getLoginName());
+                SysUser user = sysUserService.getOne(queryWrapper);
+                if (user != null) {
+                    throw ExceptionResultEnum.ERROR.exception("用户名已存在");
+                }
+
+                sysUser.setInsertInfo(requestUser.getId());
+                sysUserService.save(sysUser);
+                for (Long roleId : userSaveParams.getRoleIds()) {
+                    commonService.addUserRolePrivilege(sysUser, roleId);
+                }
+            } else {//修改用户
+                List<SysUserRole> sysUserRoleList = cacheService.userRolePrivilegeCache(sysUser.getId());
+                List<Long> userRolesList = Arrays.asList(userSaveParams.getRoleIds());
+                Set<Long> dbUserRolesList = sysUserRoleList.stream().map(SysUserRole::getRoleId).collect(Collectors.toSet());
+                int count = (int) dbUserRolesList.stream().filter(s -> userRolesList.contains(s)).count();
+                SysUser dbUser = sysUserService.getById(sysUser.getId());
+                sysUser.setUpdateInfo(requestUser.getId());
+                sysUserService.updateById(sysUser);
+                List<SysRole> list = sysUserRoleService.listRoleByUserId(sysUser.getId());
+                boolean containsQuestionTeacher = list.stream().filter(m -> RoleTypeEnum.SCHOOL_ADMIN.equals(m.getType())).count() > 0;
+                if (containsQuestionTeacher || count == 0 || dbUserRolesList.size() != userRolesList.size()) {
+                    QueryWrapper<SysUserRole> sysUserRoleQueryWrapper = new QueryWrapper<>();
+                    sysUserRoleQueryWrapper.lambda().eq(SysUserRole::getUserId, sysUser.getId());
+                    sysUserRoleService.remove(sysUserRoleQueryWrapper);
+
+                    cacheService.removeUserRolePrivilegeCache(sysUser.getId());
+                    for (Long roleId : userSaveParams.getRoleIds()) {
+                        commonService.addUserRolePrivilege(sysUser, roleId);
+                    }
+                }
+                //如果修改了角色,需要重新登录
+                if (count == 0 || dbUserRolesList.size() != userRolesList.size()) {
+                    commonService.removeUserInfo(sysUser.getId());
+                }
+                //如果修改了机构或手机号,需更新用户缓存
+                if (Objects.nonNull(dbUser.getOrgId())){
+                    if (containsQuestionTeacher || dbUser.getOrgId().longValue() != sysUser.getOrgId().longValue()
+                            || !Objects.equals(dbUser.getMobileNumber(), sysUser.getMobileNumber())) {
+                        cacheService.updateUserCache(sysUser.getId());
+                        cacheService.updateUserAuthCache(sysUser.getId());
+                    }
+                }
+            }
+            //用户科目全量删除全量增加
+            QueryWrapper<BasicUserCourse> basicUserCourseQueryWrapper = new QueryWrapper<>();
+            basicUserCourseQueryWrapper.lambda().eq(BasicUserCourse::getUserId, sysUser.getId());
+            basicUserCourseService.remove(basicUserCourseQueryWrapper);
+
+            List<SysRole> sysRoles = sysRoleService.list(sysUser.getRoleIds(), RoleTypeEnum.QUESTION_TEACHER.name());
+            if (sysRoles != null && sysRoles.size() > 0) {
+                Long[] courseIds = sysUser.getCourseIds();
+                if (courseIds.length == 0) {
+                    throw ExceptionResultEnum.ERROR.exception("请选择课程");
+                }
+                basicUserCourseService.saveBatch(sysUser);
+            }
+        } catch (Exception e) {
+            log.error("请求出错", e);
+            isSuccess = false;
+            if (e instanceof DuplicateKeyException) {
+                String errorColumn = e.getCause().toString();
+                String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3, errorColumn.length()).replaceAll("'", "");
+                throw ExceptionResultEnum.SQL_ERROR.exception("[" + FieldUniqueEnum.convertToTitle(columnStr) + "]数据不允许重复插入");
+            } else if (e instanceof ApiException) {
+                ResultUtil.error((ApiException) e, e.getMessage());
+            } else {
+                ResultUtil.error(e.getMessage());
+            }
+        }
+        return isSuccess;
+    }
 }

+ 1 - 1
teachcloud-report-business/src/main/java/com/qmth/teachcloud/report/business/service/CourseReportService.java

@@ -10,6 +10,6 @@ import com.qmth.teachcloud.report.business.enums.SemesterEnum;
  */
 public interface CourseReportService {
 
-    InspectCourseTotalReportResult findInfoInspectCourseExamTotal(Long schoolId, SemesterEnum semester, Long examId);
+    InspectCourseTotalReportResult findInfoInspectCourseExamTotal(Long schoolId, SemesterEnum semester, Long examId,Long collegeId);
 
 }

+ 2 - 10
teachcloud-report-business/src/main/java/com/qmth/teachcloud/report/business/service/impl/CourseReportServiceImpl.java

@@ -28,16 +28,8 @@ public class CourseReportServiceImpl implements CourseReportService {
     private CourseReportMapper courseReportMapper;
 
     @Override
-    @Cacheable(value = SystemConstant.COLLEGE_DEAN_REPORT, key = "#schoolId + '-' + #semester + '-' + #examId")
-    public InspectCourseTotalReportResult findInfoInspectCourseExamTotal(Long schoolId, SemesterEnum semester, Long examId) {
-        SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
-        if (Objects.isNull(sysUser)) {
-            throw ExceptionResultEnum.NOT_LOGIN.exception();
-        }
-        Long collegeId = sysUser.getOrgId();
-        if (Objects.isNull(collegeId)){
-            throw ExceptionResultEnum.ERROR.exception("学院id不存在");
-        }
+    @Cacheable(value = SystemConstant.COLLEGE_DEAN_REPORT, key = "#schoolId + '-' + #semester + '-' + #examId + '-' +#collegeId")
+    public InspectCourseTotalReportResult findInfoInspectCourseExamTotal(Long schoolId, SemesterEnum semester, Long examId,Long collegeId) {
 
         // 考试总览数据
         List<ExamBaseInfo> examBaseInfoList = courseReportMapper.findExamTotalByExamId(examId);

+ 1 - 1
teachcloud-report-business/src/main/resources/mapper/TBExamCourseMapper.xml

@@ -9,7 +9,7 @@
         join sys_org so on
         <choose>
             <when test="inspect != null and inspect == true">
-                so.id = tbs.inspect_college_id
+                so.id = tbs.inspect_college_id and tbs.absent = 0
             </when>
             <otherwise>
                 so.id = tbs.teach_college_id

+ 3 - 22
teachcloud-report/src/main/java/com/qmth/teachcloud/report/api/BasicDatasourceController.java

@@ -1032,28 +1032,9 @@ public class BasicDatasourceController {
      * @param tbSchoolCollegeDtoList 基础学院数据源
      */
     private void saveCollegeInfo(List<TBSchoolCollegeDto> tbSchoolCollegeDtoList) {
-        List<SysOrg> sysOrgList = new ArrayList<>();
         for (TBSchoolCollegeDto tbSchoolCollegeDto : tbSchoolCollegeDtoList) {
-            SysOrg old = sysOrgService.getOne(new QueryWrapper<SysOrg>().lambda()
-                    .eq(SysOrg::getSchoolId, tbSchoolCollegeDto.getSchoolId())
-                    .eq(SysOrg::getCode, tbSchoolCollegeDto.getCollegeCode())
-                    .eq(SysOrg::getName, tbSchoolCollegeDto.getCollegeName()));
-            Long id;
-            if (Objects.nonNull(old)) {
-                id = old.getId();
-            } else {
-                id = SystemConstant.getDbUuid();
-            }
-
-            SysOrg sysOrg = new SysOrg();
-            sysOrg.setId(id);
-            sysOrg.setSchoolId(tbSchoolCollegeDto.getSchoolId());
-            sysOrg.setCode(tbSchoolCollegeDto.getCollegeCode());
-            sysOrg.setName(tbSchoolCollegeDto.getCollegeName());
-            sysOrg.setEnable(true);
-            sysOrgList.add(sysOrg);
+            sysOrgService.searchOrInsert(tbSchoolCollegeDto.getSchoolId(),tbSchoolCollegeDto.getCollegeName());
         }
-        sysOrgService.saveOrUpdateBatch(sysOrgList);
     }
 
     /**
@@ -1085,10 +1066,10 @@ public class BasicDatasourceController {
             userSaveParams.setLoginName(tbSchoolTeacherDto.getTeacherCode());
             userSaveParams.setRealName(tbSchoolTeacherDto.getTeacherName());
             userSaveParams.setPassword(SystemConstant.DEFAULT_PASSWORD);
-            userSaveParams.setMobileNumber("11111111111");
+            userSaveParams.setMobileNumber(SystemConstant.DEFAULT_MOBILE_NUMBER);
             userSaveParams.setEnable(true);
             userSaveParams.setRoleIds(roleIds.toArray(new Long[0]));
-            sysUserService.saveUser(userSaveParams);
+            sysUserService.saveUserNoAuth(userSaveParams);
         }
     }
 }

+ 9 - 1
teachcloud-report/src/main/java/com/qmth/teachcloud/report/api/CourseController.java

@@ -163,7 +163,15 @@ public class CourseController {
                                     @ApiParam(value = "学校id", required = false) @RequestParam(required = false) String schoolId) {
         Object obj = ServletUtil.getRequestHeaderSchoolId();
         Long tmp = SystemConstant.convertIdToLong(String.valueOf(obj));
-        return ResultUtil.ok(courseReportService.findInfoInspectCourseExamTotal(Objects.isNull(schoolId) ? tmp : SystemConstant.convertIdToLong(schoolId), semester, SystemConstant.convertIdToLong(examId)));
+        SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
+        if (Objects.isNull(sysUser)) {
+            throw ExceptionResultEnum.NOT_LOGIN.exception();
+        }
+        Long collegeId = sysUser.getOrgId();
+        if (Objects.isNull(collegeId)){
+            throw ExceptionResultEnum.ERROR.exception("学院id不存在");
+        }
+        return ResultUtil.ok(courseReportService.findInfoInspectCourseExamTotal(Objects.isNull(schoolId) ? tmp : SystemConstant.convertIdToLong(schoolId), semester, SystemConstant.convertIdToLong(examId),collegeId));
     }
 
     @ApiOperation(value = "考查课程考试分析接口")