|
|
@@ -1,31 +1,47 @@
|
|
|
package com.xjrsoft.module.base.service.impl;
|
|
|
|
|
|
+import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.github.yulichang.base.MPJBaseServiceImpl;
|
|
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
|
+import com.xjrsoft.common.constant.GlobalConstant;
|
|
|
import com.xjrsoft.common.enums.DeleteMark;
|
|
|
import com.xjrsoft.common.enums.EnabledMark;
|
|
|
+import com.xjrsoft.common.enums.RoleEnum;
|
|
|
+import com.xjrsoft.common.exception.MyException;
|
|
|
+import com.xjrsoft.common.utils.RedisUtil;
|
|
|
import com.xjrsoft.module.attendance.dto.AttendanceStatisticDto;
|
|
|
import com.xjrsoft.module.attendance.vo.ClassStatisticsVo;
|
|
|
+import com.xjrsoft.module.base.dto.AddBaseClassPageDto;
|
|
|
import com.xjrsoft.module.base.dto.BaseClassPageDto;
|
|
|
+import com.xjrsoft.module.base.dto.UpdateBaseClassPageDto;
|
|
|
import com.xjrsoft.module.base.entity.BaseClass;
|
|
|
import com.xjrsoft.module.base.mapper.BaseClassMapper;
|
|
|
import com.xjrsoft.module.base.service.IBaseClassService;
|
|
|
import com.xjrsoft.module.base.vo.BaseClassPageVo;
|
|
|
import com.xjrsoft.module.base.vo.StudentClassVo;
|
|
|
+import com.xjrsoft.module.organization.entity.User;
|
|
|
+import com.xjrsoft.module.organization.entity.UserDeptRelation;
|
|
|
+import com.xjrsoft.module.organization.entity.UserRoleRelation;
|
|
|
import com.xjrsoft.module.organization.entity.UserStudent;
|
|
|
+import com.xjrsoft.module.organization.service.IUserRoleRelationService;
|
|
|
import com.xjrsoft.module.organization.service.IUserStudentService;
|
|
|
import com.xjrsoft.module.organization.vo.UserStudentVo;
|
|
|
+import com.xjrsoft.module.student.entity.BaseClassMajorSet;
|
|
|
import com.xjrsoft.module.student.entity.BaseStudent;
|
|
|
import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
|
|
|
import com.xjrsoft.module.student.entity.BaseStudentUser;
|
|
|
+import com.xjrsoft.module.student.service.IBaseClassMajorSetService;
|
|
|
import com.xjrsoft.module.teacher.entity.XjrUser;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
@@ -36,6 +52,12 @@ public class BaseClassServiceImpl extends MPJBaseServiceImpl<BaseClassMapper, Ba
|
|
|
|
|
|
private final BaseClassMapper baseClassMapper;
|
|
|
|
|
|
+ private final IBaseClassMajorSetService majorSetService;
|
|
|
+
|
|
|
+ private final IUserRoleRelationService roleRelationService;
|
|
|
+
|
|
|
+ private final RedisUtil redisUtil;
|
|
|
+
|
|
|
/**
|
|
|
* 获取家长关联的学生 id 是家长的ID
|
|
|
* @param id
|
|
|
@@ -126,5 +148,134 @@ public class BaseClassServiceImpl extends MPJBaseServiceImpl<BaseClassMapper, Ba
|
|
|
return null;
|
|
|
}
|
|
|
return list.get(0).getId();
|
|
|
- };
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean addClass(AddBaseClassPageDto dto) {
|
|
|
+ BaseClass baseClass = BeanUtil.toBean(dto, BaseClass.class);
|
|
|
+ baseClass.setDeleteMark(DeleteMark.NODELETE.getCode());
|
|
|
+ baseClass.setCreateDate(new Date());
|
|
|
+ baseClass.setEnabledMark(EnabledMark.ENABLED.getCode());
|
|
|
+ baseClass.setCreateUserId(StpUtil.getLoginIdAsLong());
|
|
|
+ if(baseClass.getTeacherId() != null){
|
|
|
+ //查询该班主任是否是其他在读班级
|
|
|
+ long count = this.count(
|
|
|
+ new QueryWrapper<BaseClass>().lambda()
|
|
|
+ .eq(BaseClass::getIsGraduate, 1)
|
|
|
+ .eq(BaseClass::getTeacherId, baseClass.getTeacherId())
|
|
|
+ .eq(BaseClass::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ .eq(BaseClass::getEnabledMark, EnabledMark.ENABLED.getCode())
|
|
|
+ );
|
|
|
+ if(count > 0){
|
|
|
+ throw new MyException("该老师已是其他在读班级班主任,无法添加");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean isSuccess = this.save(baseClass);
|
|
|
+
|
|
|
+ if(isSuccess){
|
|
|
+ BaseClassMajorSet majorSet = new BaseClassMajorSet();
|
|
|
+ majorSet.setClassId(baseClass.getId());
|
|
|
+ majorSet.setMajorSetId(dto.getMajorSetId());
|
|
|
+ majorSet.setCreateDate(new Date());
|
|
|
+ majorSetService.save(majorSet);
|
|
|
+ //给该老师添加班主任角色
|
|
|
+ if(baseClass.getTeacherId() != null){
|
|
|
+ long count = roleRelationService.count(
|
|
|
+ new QueryWrapper<UserRoleRelation>().lambda()
|
|
|
+ .eq(UserRoleRelation::getUserId, dto.getTeacherId())
|
|
|
+ .eq(UserRoleRelation::getRoleId, RoleEnum.CLASSTE.getCode())
|
|
|
+ );
|
|
|
+ if(count == 0){
|
|
|
+ roleRelationService.save(
|
|
|
+ new UserRoleRelation(){{
|
|
|
+ setRoleId(RoleEnum.CLASSTE.getCode());
|
|
|
+ setUserId(dto.getTeacherId());
|
|
|
+ }}
|
|
|
+ );
|
|
|
+
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ List<UserRoleRelation> userRoleRelationList = roleRelationService.list(Wrappers.lambdaQuery(UserRoleRelation.class));
|
|
|
+ redisUtil.set(GlobalConstant.USER_ROLE_RELATION_CACHE_KEY, userRoleRelationList);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return isSuccess;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean updateClass(UpdateBaseClassPageDto dto) {
|
|
|
+ BaseClass aClass = this.getById(dto.getId());
|
|
|
+ //设置了班主任,需要判断新设置的班主任是否已经是其它在读班级的
|
|
|
+ if(dto.getTeacherId() != null && !dto.getTeacherId().equals(aClass.getTeacherId())){
|
|
|
+ long count = this.count(
|
|
|
+ new QueryWrapper<BaseClass>().lambda()
|
|
|
+ .eq(BaseClass::getIsGraduate, 1)
|
|
|
+ .eq(BaseClass::getTeacherId, dto.getTeacherId())
|
|
|
+ .eq(BaseClass::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ .eq(BaseClass::getEnabledMark, EnabledMark.ENABLED.getCode())
|
|
|
+ .ne(BaseClass::getId, dto.getId())
|
|
|
+ );
|
|
|
+ if(count > 0){
|
|
|
+ throw new MyException("该老师已是其他在读班级班主任,无法添加");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ BaseClass baseClass = BeanUtil.toBean(dto, BaseClass.class);
|
|
|
+ baseClass.setModifyDate(new Date());
|
|
|
+ baseClass.setModifyUserId(StpUtil.getLoginIdAsLong());
|
|
|
+ boolean update = this.updateById(baseClass);
|
|
|
+ if(update){
|
|
|
+ BaseClassMajorSet majorSet = majorSetService.getOne(
|
|
|
+ new QueryWrapper<BaseClassMajorSet>().lambda()
|
|
|
+ .eq(BaseClassMajorSet::getClassId, baseClass.getId())
|
|
|
+ );
|
|
|
+ if(majorSet != null){
|
|
|
+ majorSet.setClassId(baseClass.getId());
|
|
|
+ majorSet.setMajorSetId(dto.getMajorSetId());
|
|
|
+ majorSet.setModifyDate(new Date());
|
|
|
+ majorSetService.updateById(majorSet);
|
|
|
+ }
|
|
|
+ if(baseClass.getTeacherId() != null){
|
|
|
+ long count = roleRelationService.count(
|
|
|
+ new QueryWrapper<UserRoleRelation>().lambda()
|
|
|
+ .eq(UserRoleRelation::getUserId, dto.getTeacherId())
|
|
|
+ .eq(UserRoleRelation::getRoleId, RoleEnum.CLASSTE.getCode())
|
|
|
+ );
|
|
|
+ if(count == 0){
|
|
|
+ roleRelationService.save(
|
|
|
+ new UserRoleRelation(){{
|
|
|
+ setRoleId(RoleEnum.CLASSTE.getCode());
|
|
|
+ setUserId(dto.getTeacherId());
|
|
|
+ }}
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(baseClass.getTeacherId() == null && aClass.getTeacherId() != null){
|
|
|
+ long count = this.count(
|
|
|
+ new QueryWrapper<BaseClass>().lambda()
|
|
|
+ .eq(BaseClass::getIsGraduate, 1)
|
|
|
+ .eq(BaseClass::getTeacherId, aClass.getTeacherId())
|
|
|
+ .eq(BaseClass::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ .eq(BaseClass::getEnabledMark, EnabledMark.ENABLED.getCode())
|
|
|
+ .ne(BaseClass::getId, dto.getId())
|
|
|
+ );
|
|
|
+ if(count == 0){
|
|
|
+ roleRelationService.remove(
|
|
|
+ new QueryWrapper<UserRoleRelation>().lambda()
|
|
|
+ .eq(UserRoleRelation::getUserId, aClass.getTeacherId())
|
|
|
+ .eq(UserRoleRelation::getRoleId, RoleEnum.CLASSTE.getCode())
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ List<UserRoleRelation> userRoleRelationList = roleRelationService.list(Wrappers.lambdaQuery(UserRoleRelation.class));
|
|
|
+ redisUtil.set(GlobalConstant.USER_ROLE_RELATION_CACHE_KEY, userRoleRelationList);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return update;
|
|
|
+ }
|
|
|
+
|
|
|
}
|