From 8458e64aab474c0fc2f49ae4ff22fb11ce5cf6e2 Mon Sep 17 00:00:00 2001 From: “djh” <“3298565835@qq.com”> Date: 星期一, 11 十一月 2024 16:55:28 +0800 Subject: [PATCH] 批次新增学员查询条件,新增题目导入接口 --- exam-system/src/main/java/com/gkhy/exam/system/service/impl/ExPhaseStudentServiceImpl.java | 34 +++++++++++++++++++++++++--------- 1 files changed, 25 insertions(+), 9 deletions(-) diff --git a/exam-system/src/main/java/com/gkhy/exam/system/service/impl/ExPhaseStudentServiceImpl.java b/exam-system/src/main/java/com/gkhy/exam/system/service/impl/ExPhaseStudentServiceImpl.java index cb50083..57b17ec 100644 --- a/exam-system/src/main/java/com/gkhy/exam/system/service/impl/ExPhaseStudentServiceImpl.java +++ b/exam-system/src/main/java/com/gkhy/exam/system/service/impl/ExPhaseStudentServiceImpl.java @@ -3,6 +3,7 @@ import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.gkhy.exam.common.api.CommonPage; +import com.gkhy.exam.common.constant.UserConstant; import com.gkhy.exam.common.domain.entity.SysUser; import com.gkhy.exam.common.enums.UserTypeEnum; import com.gkhy.exam.common.exception.ApiException; @@ -10,10 +11,7 @@ import com.gkhy.exam.common.utils.SecurityUtils; import com.gkhy.exam.system.domain.*; import com.gkhy.exam.system.domain.vo.StudentStudyVO; -import com.gkhy.exam.system.mapper.ExCoursePhaseMapper; -import com.gkhy.exam.system.mapper.ExPhaseStudentMapper; -import com.gkhy.exam.system.mapper.ExStudentMapper; -import com.gkhy.exam.system.mapper.ExStudentStudyMapper; +import com.gkhy.exam.system.mapper.*; import com.gkhy.exam.system.service.ExCompanyPeriodService; import com.gkhy.exam.system.service.ExPhaseStudentService; import com.gkhy.exam.system.service.ExStudentStudyService; @@ -22,6 +20,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.math.BigDecimal; import java.util.Collections; import java.util.List; import java.util.Objects; @@ -49,6 +48,8 @@ private SysCompanyService companyService; @Autowired private ExCompanyPeriodService companyPeriodService; + @Autowired + private ExCourseChapterPeriodMapper courseChapterPeriodMapper; @Override @@ -71,6 +72,9 @@ @Override @Transactional(rollbackFor = RuntimeException.class) public int batchAddPhaseStudent(List<ExPhaseStudent> phaseStudents) { + if(phaseStudents==null|| phaseStudents.isEmpty()){ + throw new ApiException("学员数据不能为空"); + } checkUserAllowed(phaseStudents.get(0)); checkStudentUnique(phaseStudents); for(ExPhaseStudent phaseStudent:phaseStudents){ @@ -95,7 +99,7 @@ throw new ApiException("没有权限操作"); } ExCoursePhase coursePhase=coursePhaseMapper.selectById(phaseStudent.getPhaseId()); - if(!currentUser.getCompanyId().equals(coursePhase.getCompanyId())){ + if(!coursePhase.getCompanyId().equals(currentUser.getCompanyId())){ throw new ApiException("没有权限操作其他企业批次"); } @@ -109,6 +113,17 @@ } PageUtils.startPage(); List<ExPhaseStudent> phaseStudentList=baseMapper.selectPhaseStudentList(phaseStudent); + if(phaseStudentList.size()>0) { + //获取课程所有课时数量 + int count = courseChapterPeriodMapper.selectCountByCourseId(phaseStudentList.get(0).getCourse().getId()); + if(count>0) { + for (ExPhaseStudent ps : phaseStudentList) { + if (ps.getTotalProgress() != null) { + ps.setTotalProgress(ps.getTotalProgress().divide(BigDecimal.valueOf(count), BigDecimal.ROUND_UP)); + } + } + } + } return CommonPage.restPage(phaseStudentList); } @@ -128,7 +143,7 @@ public int deletePhaseStudent(Long phaseStudentId) { ExPhaseStudent phaseStudent=baseMapper.selectPhaseStudentById(phaseStudentId); if(ObjectUtil.isNull(phaseStudent)){ - throw new ApiException(String.format("该批次下不存在该学员<>",phaseStudent.getStudentName())); + throw new ApiException("该批次下不存在该学员id"); } checkUserAllowed(phaseStudent); int studentStudyCount=studentStudyMapper.countByPhaseId(phaseStudent.getPhaseId(),phaseStudent.getStudentId()); @@ -161,7 +176,7 @@ @Override public List<StudentStudyVO> getPhaseStudentById(Long phaseStudentId) { ExPhaseStudent phaseStudent=getById(phaseStudentId); - return studentStudyService.selectStudyByPhaseAndStundentId(phaseStudent.getPhaseId(),phaseStudent.getStudentId()); + return studentStudyService.selectStudyByPhaseAndStundentId(phaseStudent.getPhaseId(),phaseStudent.getStudentId(), UserConstant.ENABLE); } @@ -170,13 +185,14 @@ ExCoursePhase coursePhase= coursePhaseMapper.selectCoursePhaseById(phaseId); ExCompanyPeriod companyPeriod=new ExCompanyPeriod(); companyPeriod.setPhaseId(phaseId); - companyPeriod.setModifyPeriod(-1*studentCount*coursePhase.getCoursePeriod()); + companyPeriod.setModifyPeriod(-1L*studentCount*coursePhase.getCoursePeriod()); companyPeriod.setOrigin("\""+coursePhase.getName()+"\"新增学员消耗"); SysCompany company=companyService.getById(coursePhase.getCompanyId()); - int remainPeriod=company.getTotalPeriod()+companyPeriod.getModifyPeriod(); + Long remainPeriod=company.getRemainPeriod()+companyPeriod.getModifyPeriod(); if(remainPeriod<0){ throw new ApiException("企业剩余课时不足"); } + companyPeriod.setCompanyId(company.getId()); companyPeriod.setRemainPeriod(remainPeriod); companyPeriodService.save(companyPeriod); company.setRemainPeriod(companyPeriod.getRemainPeriod()); -- Gitblit v1.9.2