|
@@ -26,6 +26,7 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.validation.Valid;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
@@ -268,26 +269,64 @@ public class DeptController {
|
|
|
@Operation(summary = "获取毕业达成率")
|
|
|
public CommonResult<List<DeptRespVO>> getGraduationSource(DeptListReqVO reqVO) {
|
|
|
List<DeptDO> list = deptService.getDeptList(reqVO);
|
|
|
+
|
|
|
+ // 如果 deptList 为空,直接返回空结果
|
|
|
+ if (list == null || list.isEmpty()) {
|
|
|
+ return success(new ArrayList<DeptRespVO>());
|
|
|
+ }
|
|
|
UserPageReqVO req = new UserPageReqVO();
|
|
|
+
|
|
|
+ LocalDate now = LocalDate.now();
|
|
|
+ Integer currentYear = now.getYear();
|
|
|
+ LocalDate cutoffDate = LocalDate.of(currentYear, 9, 1);
|
|
|
+
|
|
|
for (DeptDO dept : list) {
|
|
|
// 毕业达成率
|
|
|
req.setDeptId(dept.getId());
|
|
|
- List<AdminUserDO> studentList = adminUserService.getUserList1(req); // 获取这个工作间下的学生
|
|
|
- double graduationRate = 0.0; // 初始化 graduationRate
|
|
|
- // 计算毕业达成率
|
|
|
- if (studentList != null && !studentList.isEmpty()) {
|
|
|
- long totalStudents = studentList.size();
|
|
|
- long graduatedStudents = studentList.stream()
|
|
|
- .filter(student -> student.getIsGraduate() == 0) // 0 表示毕业
|
|
|
- .count();
|
|
|
- // 计算达成率
|
|
|
+ List<AdminUserDO> studentList = adminUserService.getUserList1(req); // 获取这个部门下的学生
|
|
|
+ // 如果没有学生,跳过当前部门
|
|
|
+ if (studentList == null || studentList.isEmpty()) {
|
|
|
+ dept.setGraduationRate("0.00%");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ double graduationRate = 0.0;
|
|
|
+
|
|
|
+ List<AdminUserDO> filteredStudents = studentList.stream()
|
|
|
+ .filter(student -> {
|
|
|
+ if (student.getGrade() != null) {
|
|
|
+ try {
|
|
|
+ Integer studentGrade = Integer.parseInt(student.getGrade()); // 将年级转换为整数
|
|
|
+
|
|
|
+ if (now.isBefore(cutoffDate)) {
|
|
|
+ return studentGrade != (currentYear - 1); // 排除上一年级的学生
|
|
|
+ } else {
|
|
|
+ return studentGrade != currentYear; // 排除当前年级的学生
|
|
|
+ }
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ long totalStudents = filteredStudents.size();
|
|
|
+ long graduatedStudents = filteredStudents.stream()
|
|
|
+ .filter(student -> student.getIsGraduate() != null && student.getIsGraduate() == 0) // 确保 getIsGraduate() 不为 null,且为 0 表示毕业
|
|
|
+ .count();
|
|
|
+
|
|
|
+ if (totalStudents > 0) {
|
|
|
graduationRate = (double) graduatedStudents / totalStudents * 100; // 转换成百分比
|
|
|
}
|
|
|
+
|
|
|
String graduationRateWithPercentage = String.format("%.2f%%", graduationRate);
|
|
|
- dept.setGraduationRate(graduationRateWithPercentage);
|
|
|
+ dept.setGraduationRate(graduationRateWithPercentage); // 设置部门的毕业达成率
|
|
|
}
|
|
|
- return success(BeanUtils.toBean(list, DeptRespVO.class));
|
|
|
+ return success(BeanUtils.toBean(list, DeptRespVO.class)); // 返回成功结果
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|