|
|
@@ -1,10 +1,15 @@
|
|
|
package com.xjrsoft.module.attendance.service.impl;
|
|
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.github.yulichang.base.MPJBaseServiceImpl;
|
|
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
|
import com.xjrsoft.common.enums.DeleteMark;
|
|
|
+import com.xjrsoft.common.exception.MyException;
|
|
|
+import com.xjrsoft.common.utils.VoToColumnUtil;
|
|
|
+import com.xjrsoft.module.app.entity.AppFuncDesign;
|
|
|
+import com.xjrsoft.module.app.vo.AppFuncDesignPageVo;
|
|
|
import com.xjrsoft.module.attendance.entity.AttendanceRuleCategory;
|
|
|
import com.xjrsoft.module.attendance.entity.AttendanceRuleDetails;
|
|
|
import com.xjrsoft.module.attendance.entity.AttendanceUserRelation;
|
|
|
@@ -14,6 +19,8 @@ import com.xjrsoft.module.attendance.mapper.AttendanceUserRelationMapper;
|
|
|
import com.xjrsoft.module.attendance.service.IAttendanceRuleCategoryService;
|
|
|
import com.xjrsoft.module.concat.service.IXjrUserService;
|
|
|
import com.xjrsoft.module.organization.entity.UserDeptRelation;
|
|
|
+import com.xjrsoft.module.student.entity.BaseStudent;
|
|
|
+import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
|
|
|
import com.xjrsoft.module.teacher.entity.BaseTeacher;
|
|
|
import com.xjrsoft.module.teacher.entity.XjrUser;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
@@ -45,17 +52,29 @@ public class AttendanceRuleCategoryServiceImpl extends MPJBaseServiceImpl<Attend
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Boolean add(AttendanceRuleCategory attendanceRuleCategory) {
|
|
|
+ attendanceRuleCategory.setCreateDate(new Date());
|
|
|
categoryMapper.insert(attendanceRuleCategory);
|
|
|
for (AttendanceRuleDetails attendanceRuleDetails : attendanceRuleCategory.getAttendanceRuleDetailsList()) {
|
|
|
attendanceRuleDetails.setAttendanceRuleCategoryId(attendanceRuleCategory.getId());
|
|
|
detailsMapper.insert(attendanceRuleDetails);
|
|
|
}
|
|
|
-
|
|
|
+ List<XjrUser> insertList = new ArrayList<>();
|
|
|
if(attendanceRuleCategory.getRoleId() != null && attendanceRuleCategory.getRoleId() == 2){
|
|
|
- List<XjrUser> insertList = new ArrayList<>();
|
|
|
if(attendanceRuleCategory.getAttendanceRange() == 1){
|
|
|
+ //首先判断是否已经存在一个全体教职工的考勤规则
|
|
|
+ Long count = categoryMapper.selectCount(
|
|
|
+ new QueryWrapper<AttendanceRuleCategory>()
|
|
|
+ .lambda()
|
|
|
+ .eq(AttendanceRuleCategory::getRoleId, attendanceRuleCategory.getRoleId())
|
|
|
+ .eq(AttendanceRuleCategory::getAttendanceRange, attendanceRuleCategory.getAttendanceRange())
|
|
|
+ .eq(AttendanceRuleCategory::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ );
|
|
|
+ if(count > 0){
|
|
|
+ throw new MyException("已存在一个全体教职工的考勤规则,无法添加");
|
|
|
+ }
|
|
|
List<XjrUser> userList = xjrUserService.list(
|
|
|
new MPJLambdaWrapper<XjrUser>()
|
|
|
+ .select(XjrUser.class, x -> VoToColumnUtil.fieldsToColumns(XjrUser.class).contains(x.getProperty()))
|
|
|
.leftJoin(BaseTeacher.class, BaseTeacher::getUserId, XjrUser::getId)
|
|
|
.eq(BaseTeacher::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
.eq(XjrUser::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
@@ -68,28 +87,118 @@ public class AttendanceRuleCategoryServiceImpl extends MPJBaseServiceImpl<Attend
|
|
|
deptIds.add(relation.getDeptId());
|
|
|
}
|
|
|
}
|
|
|
+ List<Long> userIds = new ArrayList<>();
|
|
|
+ for (AttendanceUserRelation relation : attendanceRuleCategory.getAttendanceUserRelationList()) {
|
|
|
+ if(relation.getUserId() != null){
|
|
|
+ userIds.add(relation.getUserId());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
List<XjrUser> userList = xjrUserService.list(
|
|
|
new MPJLambdaWrapper<XjrUser>()
|
|
|
+ .select(XjrUser.class, x -> VoToColumnUtil.fieldsToColumns(XjrUser.class).contains(x.getProperty()))
|
|
|
.leftJoin(BaseTeacher.class, BaseTeacher::getUserId, XjrUser::getId)
|
|
|
.leftJoin(UserDeptRelation.class, UserDeptRelation::getUserId, XjrUser::getId)
|
|
|
.eq(BaseTeacher::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
.eq(XjrUser::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
- .in(UserDeptRelation::getDeptId, deptIds)
|
|
|
+ .in(!deptIds.isEmpty(), UserDeptRelation::getDeptId, deptIds)
|
|
|
+ .in(!userIds.isEmpty(), XjrUser::getId, userIds)
|
|
|
+ );
|
|
|
+ //查询这部分人中是否已经有人有规则了
|
|
|
+ List<Long> relationUserIds = userList.stream().map(XjrUser::getId).collect(Collectors.toList());
|
|
|
+ List<XjrUser> relations = xjrUserService.list(
|
|
|
+ new MPJLambdaWrapper<XjrUser>()
|
|
|
+ .select(XjrUser.class, x -> VoToColumnUtil.fieldsToColumns(XjrUser.class).contains(x.getProperty()))
|
|
|
+ .leftJoin(AttendanceUserRelation.class, AttendanceUserRelation::getUserId, XjrUser::getId)
|
|
|
+ .eq(AttendanceUserRelation::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ .in(AttendanceUserRelation::getUserId, relationUserIds)
|
|
|
);
|
|
|
+ String peopleName = "";
|
|
|
+ for (int i = 0; i < relations.size(); i ++){
|
|
|
+ if(i > 0){
|
|
|
+ peopleName += ",";
|
|
|
+ }
|
|
|
+ peopleName += relations.get(i).getName();
|
|
|
+ }
|
|
|
+ if(!relations.isEmpty()){
|
|
|
+ throw new MyException("以下教职工:【" + peopleName + "】已绑定考勤规则,无法添加");
|
|
|
+ }
|
|
|
insertList.addAll(userList);
|
|
|
}
|
|
|
+ }else if(attendanceRuleCategory.getRoleId() != null && attendanceRuleCategory.getRoleId() == 3){//学生
|
|
|
+ if(attendanceRuleCategory.getAttendanceRange() == 1){
|
|
|
+ //首先判断是否已经存在一个全体学生的考勤规则
|
|
|
+ Long count = categoryMapper.selectCount(
|
|
|
+ new QueryWrapper<AttendanceRuleCategory>()
|
|
|
+ .lambda()
|
|
|
+ .eq(AttendanceRuleCategory::getRoleId, attendanceRuleCategory.getRoleId())
|
|
|
+ .eq(AttendanceRuleCategory::getAttendanceRange, attendanceRuleCategory.getAttendanceRange())
|
|
|
+ .eq(AttendanceRuleCategory::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ );
|
|
|
+ if(count > 0){
|
|
|
+ throw new MyException("已存在一个全体学生的考勤规则,无法添加");
|
|
|
+ }
|
|
|
+ List<XjrUser> userList = xjrUserService.list(
|
|
|
+ new MPJLambdaWrapper<XjrUser>()
|
|
|
+ .select(XjrUser.class, x -> VoToColumnUtil.fieldsToColumns(XjrUser.class).contains(x.getProperty()))
|
|
|
+ .leftJoin(BaseStudent.class, BaseStudent::getUserId, XjrUser::getId)
|
|
|
+ .eq(BaseStudent::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ .eq(XjrUser::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ );
|
|
|
+ insertList.addAll(userList);
|
|
|
+ }else if(attendanceRuleCategory.getAttendanceRange() == 2){
|
|
|
+ List<Long> classIds = new ArrayList<>();
|
|
|
+ for (AttendanceUserRelation relation : attendanceRuleCategory.getAttendanceUserRelationList()) {
|
|
|
+ if(relation.getClassId() != null){
|
|
|
+ classIds.add(relation.getClassId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Long> userIds = new ArrayList<>();
|
|
|
+ for (AttendanceUserRelation relation : attendanceRuleCategory.getAttendanceUserRelationList()) {
|
|
|
+ if(relation.getUserId() != null){
|
|
|
+ userIds.add(relation.getUserId());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- for (XjrUser user : insertList) {
|
|
|
- AttendanceUserRelation relation = new AttendanceUserRelation();
|
|
|
- relation.setCreateDate(new Date());
|
|
|
- relation.setCreateUserId(StpUtil.getLoginIdAsLong());
|
|
|
- relation.setUserId(user.getId());
|
|
|
- relation.setAttendanceRuleCategoryId(attendanceRuleCategory.getId());
|
|
|
- relationMapper.insert(relation);
|
|
|
+ List<XjrUser> userList = xjrUserService.list(
|
|
|
+ new MPJLambdaWrapper<XjrUser>()
|
|
|
+ .select(XjrUser.class, x -> VoToColumnUtil.fieldsToColumns(XjrUser.class).contains(x.getProperty()))
|
|
|
+ .leftJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getUserId, XjrUser::getId)
|
|
|
+ .eq(BaseStudentSchoolRoll::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ .eq(XjrUser::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ .in(!classIds.isEmpty(), BaseStudentSchoolRoll::getClassId, classIds)
|
|
|
+ .in(!userIds.isEmpty(), XjrUser::getId, userIds)
|
|
|
+ );
|
|
|
+ //查询这部分人中是否已经有人有规则了
|
|
|
+ List<Long> relationUserIds = userList.stream().map(XjrUser::getId).collect(Collectors.toList());
|
|
|
+ List<XjrUser> relations = xjrUserService.list(
|
|
|
+ new MPJLambdaWrapper<XjrUser>()
|
|
|
+ .select(XjrUser.class, x -> VoToColumnUtil.fieldsToColumns(XjrUser.class).contains(x.getProperty()))
|
|
|
+ .leftJoin(AttendanceUserRelation.class, AttendanceUserRelation::getUserId, XjrUser::getId)
|
|
|
+ .eq(AttendanceUserRelation::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ .in(AttendanceUserRelation::getUserId, relationUserIds)
|
|
|
+ );
|
|
|
+ String peopleName = "";
|
|
|
+ for (int i = 0; i < relations.size(); i ++){
|
|
|
+ if(i > 0){
|
|
|
+ peopleName += ",";
|
|
|
+ }
|
|
|
+ peopleName += relations.get(i).getName();
|
|
|
+ }
|
|
|
+ if(!relations.isEmpty()){
|
|
|
+ throw new MyException("以下学生:【" + peopleName + "】已绑定考勤规则,无法添加");
|
|
|
+ }
|
|
|
+ insertList.addAll(userList);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ for (XjrUser user : insertList) {
|
|
|
+ AttendanceUserRelation relation = new AttendanceUserRelation();
|
|
|
+ relation.setCreateDate(new Date());
|
|
|
+ relation.setCreateUserId(StpUtil.getLoginIdAsLong());
|
|
|
+ relation.setUserId(user.getId());
|
|
|
+ relation.setAttendanceRuleCategoryId(attendanceRuleCategory.getId());
|
|
|
+ relationMapper.insert(relation);
|
|
|
+ }
|
|
|
|
|
|
return true;
|
|
|
}
|