From f0f00e9ba8a755e4317e029d73b69a92ad9f9df1 Mon Sep 17 00:00:00 2001
From: kongzy <kongzy>
Date: Sat, 14 Sep 2024 17:02:41 +0800
Subject: [PATCH] update
---
exam-system/src/main/java/com/gkhy/exam/system/service/impl/ExPhaseStudentServiceImpl.java | 31 +++++++++++++++++++++++--------
1 files changed, 23 insertions(+), 8 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 1bc23d0..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
@@ -11,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;
@@ -23,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;
@@ -50,6 +48,8 @@
private SysCompanyService companyService;
@Autowired
private ExCompanyPeriodService companyPeriodService;
+ @Autowired
+ private ExCourseChapterPeriodMapper courseChapterPeriodMapper;
@Override
@@ -72,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){
@@ -96,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("没有权限操作其他企业批次");
}
@@ -110,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);
}
@@ -129,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());
@@ -171,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