贵州装备导入学生自动给权限(一年,由赵杰分发)

This commit is contained in:
joylink_zhangsai 2020-12-02 18:34:43 +08:00
parent fd869b3ed7
commit 2eb8da551d
8 changed files with 176 additions and 102 deletions

View File

@ -27,8 +27,7 @@ public interface IOrderService {
/**
* 创建订单
* @param createVO
* @param user
* @return orderCode
*/
String createOrder(OrderCreateVO createVO, UserVO user);

View File

@ -1,5 +1,6 @@
package club.joylink.rtss.services;
import club.joylink.rtss.entity.Permission;
import club.joylink.rtss.vo.UserVO;
import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.client.permission.PermissionCreateVO;
@ -30,21 +31,10 @@ public interface IPermissionService {
List<PermissionVO> findByMapId(Long mapId);
List<PermissionVO> findPermissionPackageOrBasePermission(Boolean isPackage);
PermissionVO getById(Long permissionId);
List<PermissionVO> findPermissionByRelPermissionIds(List<Long> asList);
List<PermissionVO> getPermissionByRelPermissionIds(List<Long> relPermissionIds);
/**
* 查询包含该权限的权限包
* @param id 被包含的权限的id
* @return
*/
List<PermissionVO> findPackageContainsPermission(Long id);
PermissionVO getJointSimulationPermissionByMapId(Long mapId);
PermissionVO getTeachPermissionByMapId(Long mapId);
@ -54,4 +44,14 @@ public interface IPermissionService {
* @param user
*/
void realGenerate(UserVO user);
/**
* 根据mapIds查询教学权限
*/
List<Permission> findTeachPermissionEntity(List<Long> mapIds);
/**
* 根据mapId查询教学权限
*/
Permission findTeachPermissionEntity(Long mapId);
}

View File

@ -2,6 +2,7 @@ package club.joylink.rtss.services;
import club.joylink.rtss.constants.StatusEnum;
import club.joylink.rtss.entity.PermissionDistribute;
import club.joylink.rtss.entity.UserPermission;
import club.joylink.rtss.vo.UserVO;
import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.client.permission.DistributeSelectVO;
@ -53,10 +54,6 @@ public interface IUserPermissionService {
List<UserPermissionVO> queryByDistribute(Long id);
List<UserPermissionVO> getByDistributeId(Long id);
List<UserPermissionVO> findByDistributeId(Long distributeId);
void restorePermissionToDistribute(Long userPermissionId);
List<UserPermissionVO> findByDistributeIdAndStatus(Long distributeId, StatusEnum status);
@ -72,14 +69,6 @@ public interface IUserPermissionService {
*/
void invalidateUserPermissionByDistributeId(Long distributeId);
/**
* 查询这张地图下该用户可用的综合演练权限
* @param mapId
* @param userId
* @return
*/
List<UserPermissionVO> findValidJointTrainingUserPermissionByMapIdAndUserId(Long mapId, Long userId);
/**
* 获取个人所有用户权限
* @param user
@ -93,4 +82,9 @@ public interface IUserPermissionService {
* @param permissionConfigVOList
*/
void generateUserPermissions(UserVO userVO, List<PermissionGenerateConfigVO> permissionConfigVOList);
/**
* 查询有效的用户教学权限
*/
List<UserPermission> findEntity(List<Long> userIds, Boolean valid);
}

View File

@ -463,13 +463,6 @@ public class PermissionService implements IPermissionService {
return voList;
}
@Override
public List<PermissionVO> getPermissionByRelPermissionIds(List<Long> relPermissionIds) {
List<PermissionVO> voList = findPermissionByRelPermissionIds(relPermissionIds);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertCollectionNotEmpty(voList);
return voList;
}
@Override
public List<PermissionVO> findByMapId(Long mapId) {
PermissionExample example = new PermissionExample();
@ -517,6 +510,31 @@ public class PermissionService implements IPermissionService {
}
}
@Override
public List<Permission> findTeachPermissionEntity(List<Long> mapIds) {
PermissionExample example = new PermissionExample();
example.createCriteria()
.andMapIdIn(mapIds)
.andTypeEqualTo(PermissionTypeEnum.Teaching_Package.getCode())
.andIsPackageEqualTo(true);
return permissionDAO.selectByExample(example);
}
@Override
public Permission findTeachPermissionEntity(Long mapId) {
PermissionExample example = new PermissionExample();
example.createCriteria()
.andMapIdEqualTo(mapId)
.andTypeEqualTo(PermissionTypeEnum.Teaching_Package.getCode())
.andIsPackageEqualTo(true);
List<Permission> permissions = permissionDAO.selectByExample(example);
if (CollectionUtils.isEmpty(permissions)) {
return null;
} else {
return permissions.get(0);
}
}
/**
* 根据mapId获取该地图下的综合演练权限
*/
@ -534,25 +552,4 @@ public class PermissionService implements IPermissionService {
return new PermissionVO(permissions.get(0));
}
/**
* 查询所有权限包或所有基础权限
*
* @return
*/
@Override
public List<PermissionVO> findPermissionPackageOrBasePermission(Boolean isPackage) {
PermissionExample example = new PermissionExample();
example.createCriteria()
.andIsPackageEqualTo(isPackage);
List<Permission> permissionList = permissionDAO.selectByExample(example);
List<PermissionVO> voList = permissionList.stream().map(permission -> new PermissionVO(permission)).collect(Collectors.toList());
return voList;
}
public List<PermissionVO> findPackageContainsPermission(Long relPermissionId) {
PermissionExample example = new PermissionExample();
example.createCriteria().andRelPermissionsLike(String.format("%%%s%%", relPermissionId));
List<Permission> permissionList = permissionDAO.selectByExample(example);
return PermissionVO.convert2VOList(permissionList);
}
}

View File

@ -341,15 +341,6 @@ public class UserPermissionService implements IUserPermissionService {
return userPermissionDAO.selectByExample(example);
}
@Override
public List<UserPermissionVO> getByDistributeId(Long distributeId) {
List<UserPermission> userPermissionList = this.findEntityByDistributeId(distributeId);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertCollectionNotEmpty(userPermissionList,
String.format("distributeId为[%s]的用户权限不存在", distributeId));
List<UserPermissionVO> voList = userPermissionList.stream().map(userPermission -> new UserPermissionVO(userPermission)).collect(Collectors.toList());
return voList;
}
public List<UserPermissionVO> findByPermissionIdAndUserId(Long permissionId, Long userId) {
UserPermissionExample example = new UserPermissionExample();
example.createCriteria()
@ -447,12 +438,6 @@ public class UserPermissionService implements IUserPermissionService {
return this.findByPermissionIdAndUserId(permission.getId(), userId);
}
@Override
public List<UserPermissionVO> findByDistributeId(Long distributeId) {
List<UserPermission> upList = findEntityByDistributeId(distributeId);
return upList.stream().map(UserPermissionVO::new).collect(Collectors.toList());
}
@Transactional
@Override
public void restorePermissionToDistribute(Long userPermissionId) {
@ -495,19 +480,6 @@ public class UserPermissionService implements IUserPermissionService {
userPermissionDAO.updateInvalidByDistributeId(distributeId);
}
@Override
public List<UserPermissionVO> findValidJointTrainingUserPermissionByMapIdAndUserId(Long mapId, Long userId) {
PermissionVO permission = iPermissionService.getJointSimulationPermissionByMapId(mapId);
UserPermissionExample example = new UserPermissionExample();
example.createCriteria()
.andPermissionIdEqualTo(permission.getId())
.andUserIdEqualTo(userId)
.andStatusEqualTo(StatusEnum.Valid.getCode())
.andRemainsGreaterThan(0);
List<UserPermission> userPermissionList = userPermissionDAO.selectByExample(example);
return userPermissionList.stream().map(UserPermissionVO::new).collect(Collectors.toList());
}
@Override
public List<UserPermissionVO> queryPersonalUserPermission(UserVO user) {
List<UserPermissionVO> voList = findByUserId(user.getId());
@ -526,6 +498,20 @@ public class UserPermissionService implements IUserPermissionService {
}
}
@Override
public List<UserPermission> findEntity(List<Long> userIds, Boolean valid) {
StatusEnum status = null;
if (valid != null) {
status = valid ? StatusEnum.Valid : StatusEnum.Invalid;
}
UserPermissionExample example = new UserPermissionExample();
UserPermissionExample.Criteria criteria = example.createCriteria().andUserIdIn(userIds);
if (status != null) {
criteria.andStatusEqualTo(status.getCode());
}
return userPermissionDAO.selectByExample(example);
}
private List<UserPermissionVO> findByUserId(Long userId) {
UserPermissionExample example = new UserPermissionExample();
example.createCriteria().andUserIdEqualTo(userId);

View File

@ -1,27 +1,37 @@
package club.joylink.rtss.services.student;
import club.joylink.rtss.constants.BusinessConsts;
import club.joylink.rtss.constants.Client;
import club.joylink.rtss.constants.*;
import club.joylink.rtss.dao.*;
import club.joylink.rtss.entity.*;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.services.ILessonService;
import club.joylink.rtss.services.*;
import club.joylink.rtss.vo.UserVO;
import club.joylink.rtss.vo.client.LessonVO;
import club.joylink.rtss.vo.client.goods.GoodsVO;
import club.joylink.rtss.vo.client.map.MapVO;
import club.joylink.rtss.vo.client.order.OrderCreateVO;
import club.joylink.rtss.vo.client.order.OrderDetailCreateVO;
import club.joylink.rtss.vo.client.permissionDistribute.DistributeVO;
import club.joylink.rtss.vo.client.student.*;
import club.joylink.rtss.vo.client.userPermission.UserPermissionAndAmountVO;
import club.joylink.rtss.vo.client.userPermission.UserPermissionDistributeVO;
import club.joylink.rtss.vo.client.userPermission.UserPermissionVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
/**处理 学生-用户-班级-课程 试卷子数据及关系*/
/**
* 处理 学生-用户-班级-课程 试卷子数据及关系
*/
@Slf4j
@Service
public class ClassStudentUserServiceImpl implements IClassStudentUserService {
@ -57,7 +67,28 @@ public class ClassStudentUserServiceImpl implements IClassStudentUserService {
private ILessonService lessonService;
@Autowired
private StudentRelExamClassDAO studentRelExamClassDAO;
private StudentRelExamClassDAO studentRelExamClassDAO;
@Autowired
private IPermissionService iPermissionService;
@Autowired
private IMapService iMapService;
@Autowired
private IUserPermissionService iUserPermissionService;
@Autowired
private IPermissionDistributeService iPermissionDistributeService;
@Autowired
private IGoodsService iGoodsService;
@Autowired
private ISysUserService iSysUserService;
@Autowired
private IOrderService iOrderService;
@Override
@Transactional
@ -97,8 +128,8 @@ public class ClassStudentUserServiceImpl implements IClassStudentUserService {
List<SysUser> users = this.sysUserDAO.selectByExample(userExample);
if (!CollectionUtils.isEmpty(users)) {
oldSysUsers.add(users.get(0));
StudentRelIdClassExample relIdClassExample = new StudentRelIdClassExample();
relIdClassExample.createCriteria().andStudentUserIdEqualTo(users.get(0).getId()).andClassIdNotEqualTo(studentClass.getId());
StudentRelIdClassExample relIdClassExample = new StudentRelIdClassExample();
relIdClassExample.createCriteria().andStudentUserIdEqualTo(users.get(0).getId()).andClassIdNotEqualTo(studentClass.getId());
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertTrue(this.studentRelIdClassDAO.countByExample(relIdClassExample) <= 0,
"其他班级已存在相同学号的学生!");
// relIdClassExample.clear();
@ -114,17 +145,31 @@ public class ClassStudentUserServiceImpl implements IClassStudentUserService {
}
oldSysUsers.addAll(newSysUsers);
//增加班级-用户关系
(finalClassExist?newSysUsers:oldSysUsers).forEach(sysUser -> {
(finalClassExist ? newSysUsers : oldSysUsers).forEach(sysUser -> {
StudentRelIdClass studentRelIdClass = new StudentRelIdClass();
studentRelIdClass.setClassId(studentClass.getId());
studentRelIdClass.setStudentUserId(sysUser.getId());
this.studentRelIdClassDAO.insert(studentRelIdClass);
});
//只考虑了贵州装备项目检查学生的权限自动给没有权限的学生分发权限创建权限分发给赵杰从赵杰的权限再分发给学生---
if (CollectionUtils.isEmpty(oldSysUsers)) return;
List<MapVO> gzbMaps = iMapService.queryOnlineMapInfoListOfProject(Project.valueOf(projectCode));
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertCollectionNotEmpty(gzbMaps,
String.format("项目[%s]没有在线的地图", projectCode));
Long gzbMapId = gzbMaps.get(0).getId();
Permission permission = iPermissionService.findTeachPermissionEntity(gzbMapId);
log.warn(String.format("项目[%s]没有有效的教学权限", projectCode));
if (permission == null) return;
GoodsVO good = iGoodsService.selectGoodsByPermissionId(permission.getId());
List<Long> userIds = oldSysUsers.stream().map(SysUser::getId).collect(Collectors.toList());
List<UserPermission> userPermissions = iUserPermissionService.findEntity(userIds, true);
List<Long> usersWithPermissions = userPermissions.stream()
.filter(up -> permission.getId().equals(up.getPermissionId())).map(UserPermission::getUserId).collect(Collectors.toList());
distributePermissions2ZJ(good.getId(), userIds, usersWithPermissions);
}
@Override
public List<StudentClassVO> getClassesByProjectCode(String projectCode){
public List<StudentClassVO> getClassesByProjectCode(String projectCode) {
StudentClassExample classExample = new StudentClassExample();
classExample.createCriteria().andProjectCodeEqualTo(projectCode);
List<StudentClass> studentClasses = this.studentClassDAO.selectByExample(classExample);
@ -132,13 +177,13 @@ public class ClassStudentUserServiceImpl implements IClassStudentUserService {
}
@Override
public List<StudentClassVO> getClassesByLesson(Long lessonId){
public List<StudentClassVO> getClassesByLesson(Long lessonId) {
List<StudentClass> classes = this.studentClassDAO.getClasses(lessonId);
return StudentClassVO.convertFromDBList(classes);
}
@Override
public List<StudentClassVO> getClassesByExamId(Long examId){
public List<StudentClassVO> getClassesByExamId(Long examId) {
StudentRelExamClassExample example = new StudentRelExamClassExample();
example.createCriteria().andExamIdEqualTo(examId);
List<StudentClass> classes = this.studentClassDAO.getClassesByExamId(examId);
@ -146,7 +191,7 @@ public class ClassStudentUserServiceImpl implements IClassStudentUserService {
}
@Override
public List<StudentRelLessonClass> getRelLessonsByClass(Integer classId){
public List<StudentRelLessonClass> getRelLessonsByClass(Integer classId) {
StudentRelLessonClassExample relLessonClassExample = new StudentRelLessonClassExample();
relLessonClassExample.createCriteria().andClassIdEqualTo(classId);
List<StudentRelLessonClass> studentClasses = this.studentRelLessonClassDAO.selectByExample(relLessonClassExample);
@ -154,7 +199,7 @@ public class ClassStudentUserServiceImpl implements IClassStudentUserService {
}
@Override
public List<String> getRelclassByLessonId(Long LessonId){
public List<String> getRelclassByLessonId(Long LessonId) {
List<String> classes = this.studentRelLessonClassDAO.getClassNames(LessonId);
return classes;
}
@ -168,13 +213,13 @@ public class ClassStudentUserServiceImpl implements IClassStudentUserService {
}
@Override
public List<LessonVO> getLessonByClass(Integer classId){
public List<LessonVO> getLessonByClass(Integer classId) {
List<Long> lessonIds = getRelLessonsByClass(classId).stream().map(StudentRelLessonClass::getLessonId).collect(Collectors.toList());
return lessonService.getValidLesson(lessonIds, null);
}
@Override
public List<StudentRelIdClass> getRelClassByUser(Long userId){
public List<StudentRelIdClass> getRelClassByUser(Long userId) {
StudentRelIdClassExample relIdClassExample = new StudentRelIdClassExample();
relIdClassExample.createCriteria().andStudentUserIdEqualTo(userId);
List<StudentRelIdClass> studentRelIdClasses = this.studentRelIdClassDAO.selectByExample(relIdClassExample);
@ -206,19 +251,19 @@ public class ClassStudentUserServiceImpl implements IClassStudentUserService {
//查询出勤天数
Integer days = this.sysUserLoginDAO.loginDays(studentRelIdClass.getStudentUserId(), Client.Joylink.getName(), infoExportParam.getTermBeginDate(), infoExportParam.getTermEndDate());
//出勤率
exportStudentInfo.setAttendance((float) Math.round((Objects.isNull(days) ? 0 : (days>infoExportParam.getAttendanceDays()?infoExportParam.getAttendanceDays():days)) * 100 / infoExportParam.getAttendanceDays()) / 100);
exportStudentInfo.setAttendance((float) Math.round((Objects.isNull(days) ? 0 : (days > infoExportParam.getAttendanceDays() ? infoExportParam.getAttendanceDays() : days)) * 100 / infoExportParam.getAttendanceDays()) / 100);
infoExportParam.getPrdParams().forEach(prdParam -> {
PrdStudentScoretInfo prdStudentScoretInfo = new PrdStudentScoretInfo();
prdStudentScoretInfo.setPrdType(prdParam.getPrdType());
//查询课程下不同实训的测验通过数
Integer passedNum = this.userTrainingStatsMapper.countBy(studentRelIdClass.getStudentUserId(), prdParam.getLessonId(), 0, BusinessConsts.Training.Mode.Mode04, 1,infoExportParam.getTermBeginDate(), infoExportParam.getTermEndDate());
Integer passedNum = this.userTrainingStatsMapper.countBy(studentRelIdClass.getStudentUserId(), prdParam.getLessonId(), 0, BusinessConsts.Training.Mode.Mode04, 1, infoExportParam.getTermBeginDate(), infoExportParam.getTermEndDate());
//技能操作通过率
if (prd2TrainNums.get(prdParam.getPrdType()) != 0) {
prdStudentScoretInfo.setLessonPassRate((float) Math.round((Objects.isNull(passedNum) ? 0 : passedNum) * 100 / prd2TrainNums.get(prdParam.getPrdType())) / 100);
}
//查询考试得分
Integer maxScore = this.userExamMapper.getMaxScoreBy(studentRelIdClass.getStudentUserId(), prdParam.getExamPaperId(),infoExportParam.getTermBeginDate(), infoExportParam.getTermEndDate());
Integer maxScore = this.userExamMapper.getMaxScoreBy(studentRelIdClass.getStudentUserId(), prdParam.getExamPaperId(), infoExportParam.getTermBeginDate(), infoExportParam.getTermEndDate());
//考试成绩占总分比
prdStudentScoretInfo.setExamSocreRadio((float) Math.round((Objects.isNull(maxScore) ? 0 : maxScore) * 100 / prd2Fullpoint.get(prdParam.getPrdType())) / 100);
exportStudentInfo.getScores().add(prdStudentScoretInfo);
@ -228,7 +273,7 @@ public class ClassStudentUserServiceImpl implements IClassStudentUserService {
}
@Override
public void addExamRelClass(Long examId, Integer classId){
public void addExamRelClass(Long examId, Integer classId) {
StudentRelExamClass studentRelExamClass = new StudentRelExamClass();
studentRelExamClass.setExamId(examId);
studentRelExamClass.setClassId(classId);
@ -236,9 +281,53 @@ public class ClassStudentUserServiceImpl implements IClassStudentUserService {
}
@Override
public void deleteExamRelClass(Long examId){
public void deleteExamRelClass(Long examId) {
StudentRelExamClassExample example = new StudentRelExamClassExample();
example.createCriteria().andExamIdEqualTo(examId);
studentRelExamClassDAO.deleteByExample(example);
}
/**
* 创建权限分发给赵杰再从赵杰的权限创建权限分发给学生领取
*/
private void distributePermissions2ZJ(Long goodId, List<Long> importUserIds, List<Long> userIdsWithPermissions) {
int goodAmount = importUserIds.size() - userIdsWithPermissions.size();
if (goodAmount <= 0) return; //不需要发权限
//创建权限分发
OrderCreateVO orderCreate = new OrderCreateVO();
orderCreate.setOrganizationId(48L);
orderCreate.setOrderType(SaleOrderTypeEnum.Internal_Distribution.getCode());
orderCreate.setForever(false);
orderCreate.setStartTime(LocalDateTime.now());
orderCreate.setMonthAmount(12);
orderCreate.setPayStatus(SaleOrderPayStatusEnum.No_Need.getCode());
orderCreate.setDetailCreateVOList(List.of(new OrderDetailCreateVO(goodId, goodAmount)));
UserVO userZJ = iSysUserService.findUserById(163L);
String orderCode = iOrderService.createOrder(orderCreate, userZJ);
iPermissionDistributeService.distributeFromOrder(orderCode, userZJ);
//给赵杰领权限
DistributeVO distribute = iPermissionDistributeService.getByOrderCode(orderCode);
Long distributeId = distribute.getId();
iPermissionDistributeService.getUserPermission(distributeId, userZJ);
//从赵杰的权限创建权限分发
UserPermissionVO userPermission = iUserPermissionService.findValidByUserIdAndDistributeId(userZJ.getId(), distributeId).get(0);
UserPermissionDistributeVO distributeFromUP = new UserPermissionDistributeVO();
distributeFromUP.setStartTime(distribute.getStartTime());
distributeFromUP.setEndTime(distribute.getEndTime());
distributeFromUP.setDistribute(false);
UserPermissionAndAmountVO upAndAmount = new UserPermissionAndAmountVO(userPermission.getId(), distribute.getAmount());
List<UserPermissionAndAmountVO> upAndAmountList = new ArrayList<>();
upAndAmountList.add(upAndAmount);
distributeFromUP.setUserPermissionAndAmountVOList(upAndAmountList);
iPermissionDistributeService.distributeFromUserPermission(distributeFromUP, userZJ);
//给没权限的学生领权限
DistributeVO distribute4Student = iPermissionDistributeService.getByFromUserPermissionId(userPermission.getId()).get(0);
List<Long> needPermissionUserIds = importUserIds;
needPermissionUserIds.removeAll(userIdsWithPermissions);
List<SysUser> needPermissionUsers = iSysUserService.findEntity(needPermissionUserIds);
for (SysUser student : needPermissionUsers) {
UserVO studentVO = new UserVO(student);
iPermissionDistributeService.getUserPermission(distribute4Student.getId(), studentVO);
}
}
}

View File

@ -18,6 +18,11 @@ public class OrderDetailCreateVO {
@NotNull(message = "商品数量不能为空")
private Integer goodsAmount;
public OrderDetailCreateVO(Long goodsId, Integer goodsAmount) {
this.goodsId = goodsId;
this.goodsAmount = goodsAmount;
}
public SaleOrderDetail convert2DB() {
SaleOrderDetail detail = new SaleOrderDetail();
detail.setGoodsId(goodsId);

View File

@ -22,4 +22,8 @@ public class UserPermissionAndAmountVO {
@NotNull(message = "用户权限数量不能为空")
private Integer amount;
public UserPermissionAndAmountVO(Long userPermissionId, Integer amount) {
this.userPermissionId = userPermissionId;
this.amount = amount;
}
}