Parcourir la source

学生学院被学院级机构包含

caozixuan il y a 2 ans
Parent
commit
a216dc895c

+ 3 - 3
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/GradeBatchPaperServiceImpl.java

@@ -65,7 +65,7 @@ public class GradeBatchPaperServiceImpl extends ServiceImpl<GradeBatchPaperMappe
         IPage<GradeBatchPaperResult> datasource = this.baseMapper.findGradeBatchPaperPage(new Page<>(pageNumber, pageSize), batchId, examId, courseName, schoolId);
         for (GradeBatchPaperResult record : datasource.getRecords()) {
             Long teachingRoomId = record.getTeachingRoomId();
-            SysOrg teachCollege = sysOrgService.findTeachCollegeByOrgId(teachingRoomId);
+            SysOrg teachCollege = sysOrgService.findCollegeLevelOrgByOrgId(teachingRoomId);
             record.setTeachCollegeId(teachCollege.getId());
             record.setTeachCollegeName(teachCollege.getName());
         }
@@ -86,7 +86,7 @@ public class GradeBatchPaperServiceImpl extends ServiceImpl<GradeBatchPaperMappe
         for (GradeBatchPaperResult gradeBatchPaperResult : datasource) {
             // 额外处理开课学院
             Long teachingRoomId = gradeBatchPaperResult.getTeachingRoomId();
-            SysOrg teachCollege = sysOrgService.findTeachCollegeByOrgId(teachingRoomId);
+            SysOrg teachCollege = sysOrgService.findCollegeLevelOrgByOrgId(teachingRoomId);
             if (SystemConstant.longNotNull(collegeId) && !collegeId.equals(teachCollege.getId())) {
                 continue;
             }
@@ -342,7 +342,7 @@ public class GradeBatchPaperServiceImpl extends ServiceImpl<GradeBatchPaperMappe
         List<SysOrg> teachOrgList = new ArrayList<>();
         Map<Long, Long> keyMap = new HashMap<>();
         for (Long orgId : teachingRoomIdList) {
-            SysOrg sysOrg = sysOrgService.findTeachCollegeByOrgId(orgId);
+            SysOrg sysOrg = sysOrgService.findCollegeLevelOrgByOrgId(orgId);
             Long id = sysOrg.getId();
             if (!keyMap.containsKey(id)) {
                 teachOrgList.add(sysOrg);

+ 1 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/GradeBatchServiceImpl.java

@@ -472,7 +472,7 @@ public class GradeBatchServiceImpl extends ServiceImpl<GradeBatchMapper, GradeBa
             List<Long> orgIds = dtoList.stream().map(m -> m.getCourseCode() + "##" + m.getPaperNumber()).distinct().map(m -> {
                 String[] strings = m.split("##");
                 ExamTask examTask = examTaskService.getByCourseCodeAndPaperNumber(schoolId, strings[0], strings[1]);
-                SysOrg sysOrg = sysOrgService.findTeachCollegeByOrgId(examTask.getTeachingRoomId());
+                SysOrg sysOrg = sysOrgService.findCollegeLevelOrgByOrgId(examTask.getTeachingRoomId());
                 return sysOrg.getId();
             }).distinct().collect(Collectors.toList());
             if (orgIds.size() != 1) {

+ 7 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/PrintCommonServiceImpl.java

@@ -154,6 +154,9 @@ public class PrintCommonServiceImpl implements PrintCommonService {
     @Resource
     CreatePrintPdfUtil createPrintPdfUtil;
 
+    @Resource
+    CommonCacheService commonCacheService;
+
     /**
      * 保存附件
      *
@@ -797,7 +800,10 @@ public class PrintCommonServiceImpl implements PrintCommonService {
     public boolean sysOrgRemove(Long id) {
         // 机构校验
         validateOrg(id);
-        return sysOrgService.removeById(id);
+        boolean result = sysOrgService.removeById(id);
+        Long schoolId = SystemConstant.convertIdToLong(String.valueOf(ServletUtil.getRequestHeaderSchoolId()));
+        commonCacheService.removeOrgCollegeLevelCache(schoolId);
+        return result;
     }
 
     private void validateOrg(Long id) {

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

@@ -152,6 +152,7 @@ public class SystemConstant {
     public static final String SYS_CONFIG_CACHE = "sys:config:cache";
     public static final String CUSTOM_PRIVILEGE_CACHE = "custom:privilege:cache";
     public static final String NUMBER_CACHE = "school:number:cache:";
+    public static final String ORG_COLLEGE_LEVEL_CACHE = "org:college:level:cache";
 
     /**
      * 报表缓存

+ 23 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/CommonCacheService.java

@@ -406,4 +406,27 @@ public interface CommonCacheService {
      * @param key
      */
     public void removeSysConfigCache(Long schoolId, String key);
+
+    /**
+     * 添加学院级别机构缓存
+     *
+     * @param schoolId 学校id
+     * @return 学院级别机构集合
+     */
+    List<SysOrg> addOrgCollegeLevelCache(Long schoolId);
+
+    /**
+     * 修改学院级别机构缓存
+     *
+     * @param schoolId 学校id
+     * @return 学院级别机构集合
+     */
+    List<SysOrg> updateOrgCollegeLevelCache(Long schoolId);
+
+    /**
+     * 删除学院级别机构缓存
+     *
+     * @param schoolId 学校id
+     */
+    void removeOrgCollegeLevelCache(Long schoolId);
 }

+ 10 - 2
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/SysOrgService.java

@@ -135,10 +135,18 @@ public interface SysOrgService extends IService<SysOrg> {
     Map<String, Long> createOrGetOrgByOrgInfo(List<String> orgInfoList, SysUser requestUser);
 
     /**
-     * 根据机构id查询开课学院
+     * 根据机构id查询学院级机构
      *
      * @param orgId 机构id(课程所在教研室)
      * @return 开课学院
      */
-    SysOrg findTeachCollegeByOrgId(Long orgId);
+    SysOrg findCollegeLevelOrgByOrgId(Long orgId);
+
+    /**
+     * 查询学院级别机构集合
+     *
+     * @param schoolId 学校id
+     * @return 学院级机构集合
+     */
+    List<SysOrg> findCollegeLevelOrgList(Long schoolId);
 }

+ 8 - 3
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/BasicCollegeServiceImpl.java

@@ -11,9 +11,7 @@ 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.mapper.BasicCollegeMapper;
-import com.qmth.teachcloud.common.service.BasicCollegeService;
-import com.qmth.teachcloud.common.service.BasicMajorService;
-import com.qmth.teachcloud.common.service.BasicStudentService;
+import com.qmth.teachcloud.common.service.*;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -33,6 +31,8 @@ public class BasicCollegeServiceImpl extends ServiceImpl<BasicCollegeMapper, Bas
     private BasicMajorService basicMajorService;
     @Resource
     private BasicStudentService basicStudentService;
+    @Resource
+    private CommonCacheService commonCacheService;
 
     @Override
     public IPage<BasicCollegeResult> basicCollegePage(Long schoolId, String collegeName, int pageNumber, int pageSize) {
@@ -48,6 +48,11 @@ public class BasicCollegeServiceImpl extends ServiceImpl<BasicCollegeMapper, Bas
         Long id = basicCollegeParams.getId();
         Long schoolId = requestUser.getSchoolId();
         String collegeName = basicCollegeParams.getCollegeName();
+        // 检验学院名称一定和二级机构(学院级机构)名称一致 
+        List<SysOrg> collegeOrgList = commonCacheService.addOrgCollegeLevelCache(schoolId);
+        if (collegeOrgList.stream().noneMatch(e -> collegeName.equals(e.getName()))){
+            throw ExceptionResultEnum.ERROR.exception("学生所在的学院名称【" + collegeName + "】不在学院机构中");
+        }
 
         // 校验专业唯一性(名称在学院下)
         BasicCollege checkName = this.getOne(new QueryWrapper<BasicCollege>().lambda()

+ 18 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/CommonCacheServiceImpl.java

@@ -644,4 +644,22 @@ public class CommonCacheServiceImpl implements CommonCacheService {
     public void removeSysConfigCache(Long schoolId, String key) {
 
     }
+
+    @Override
+    @Cacheable(value = SystemConstant.ORG_COLLEGE_LEVEL_CACHE, key = "#p0")
+    public List<SysOrg> addOrgCollegeLevelCache(Long schoolId) {
+        return sysOrgService.findCollegeLevelOrgList(schoolId);
+    }
+
+    @Override
+    @CachePut(value = SystemConstant.ORG_COLLEGE_LEVEL_CACHE, key = "#p0")
+    public List<SysOrg> updateOrgCollegeLevelCache(Long schoolId) {
+        return sysOrgService.findCollegeLevelOrgList(schoolId);
+    }
+
+    @Override
+    @CacheEvict(value = SystemConstant.ORG_COLLEGE_LEVEL_CACHE, key = "#p0")
+    public void removeOrgCollegeLevelCache(Long schoolId) {
+
+    }
 }

+ 27 - 6
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/SysOrgServiceImpl.java

@@ -16,6 +16,7 @@ import com.qmth.teachcloud.common.enums.OrgTypeEnum;
 import com.qmth.teachcloud.common.enums.RoleTypeEnum;
 import com.qmth.teachcloud.common.enums.userPush.SpecialPrivilegeEnum;
 import com.qmth.teachcloud.common.mapper.SysOrgMapper;
+import com.qmth.teachcloud.common.service.CommonCacheService;
 import com.qmth.teachcloud.common.service.SysOrgService;
 import com.qmth.teachcloud.common.service.SysRoleService;
 import com.qmth.teachcloud.common.service.SysUserService;
@@ -44,12 +45,12 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
 
     @Resource
     private SysUserService sysUserService;
-
     @Resource
     private SysRoleService sysRoleService;
-
     @Resource
-    SysOrgMapper sysOrgMapper;
+    private SysOrgMapper sysOrgMapper;
+    @Resource
+    private CommonCacheService commonCacheService;
 
     @Override
     public List<OrgDto> listOrgTree(SpecialPrivilegeEnum specialPrivilegeEnum,boolean withoutPrintingRoom) {
@@ -126,6 +127,7 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
                 org.updateInfo(sysUser.getId());
                 success = this.updateById(org);
             }
+            commonCacheService.updateOrgCollegeLevelCache(schoolId);
         } catch (Exception e) {
             if (e instanceof DuplicateKeyException) {
                 String errorColumn = e.getCause().toString();
@@ -393,17 +395,17 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
                 }
             }
         }
+        commonCacheService.updateOrgCollegeLevelCache(requestUser.getSchoolId());
         return map;
     }
 
 
     @Override
-    public SysOrg findTeachCollegeByOrgId(Long orgId) {
+    public SysOrg findCollegeLevelOrgByOrgId(Long orgId) {
         if (!SystemConstant.longNotNull(orgId)) {
             throw ExceptionResultEnum.ERROR.exception("机构id不存在");
         }
 
-
         List<SysOrg> orgList = this.findParentsByOrgId(orgId).stream().distinct().collect(Collectors.toList());
         List<SysOrg> schoolOrgList = orgList.stream().filter(e -> OrgTypeEnum.SCHOOL.equals(e.getType())).collect(Collectors.toList());
         if (schoolOrgList.size() != 1){
@@ -411,13 +413,31 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
         }
         SysOrg schoolOrg = schoolOrgList.get(0);
         Long schoolOrgId = schoolOrg.getId();
-        List<SysOrg> collegeOrgList = orgList.stream().filter(e -> schoolOrgId.equals(e.getParentId())).collect(Collectors.toList());;
+        List<SysOrg> collegeOrgList = orgList.stream().filter(e -> schoolOrgId.equals(e.getParentId())).collect(Collectors.toList());
         if (collegeOrgList.size() != 1){
             throw ExceptionResultEnum.ERROR.exception("开课学院异常");
         }
         return collegeOrgList.get(0);
     }
 
+    @Override
+    public List<SysOrg> findCollegeLevelOrgList(Long schoolId) {
+        SysOrg schoolOrg = this.getOne(new QueryWrapper<SysOrg>()
+                .lambda()
+                .eq(SysOrg::getSchoolId,schoolId)
+                .eq(SysOrg::getType,OrgTypeEnum.SCHOOL));
+
+        Long schoolOrgId = schoolOrg.getId();
+
+        return this.list(new QueryWrapper<SysOrg>()
+                .lambda()
+                .eq(SysOrg::getSchoolId,schoolId)
+                .eq(SysOrg::getParentId,schoolOrgId))
+                .stream()
+                .filter(e -> !OrgTypeEnum.PRINTING_HOUSE.equals(e.getType()))
+                .collect(Collectors.toList());
+    }
+
     /**
      * 根据子机构id深度优先搜索其父机构们
      *
@@ -497,6 +517,7 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
         sysOrg.setName(orgName);
         sysOrg.setEnable(true);
         this.save(sysOrg);
+
         return sysOrg;
     }
 }