Skip to content

Commit 29e7d9f

Browse files
authored
Merge pull request #99 from Boyuan-IT-Club/Red_Moon
新增简历排序逻辑,重构excel格式
2 parents e259569 + b01ed45 commit 29e7d9f

File tree

8 files changed

+113
-25
lines changed

8 files changed

+113
-25
lines changed

src/main/java/club/boyuan/official/controller/ResumeController.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,8 @@ public ResponseEntity<ResponseMessage<?>> queryResumes(
817817
@RequestParam(required = false) String status,
818818
@RequestParam(required = false, defaultValue = "0") Integer page,
819819
@RequestParam(required = false, defaultValue = "10") Integer size,
820+
@RequestParam(required = false) String sortBy,
821+
@RequestParam(required = false) String sortOrder,
820822
HttpServletRequest request) {
821823
try {
822824
String token = request.getHeader("Authorization");
@@ -832,13 +834,13 @@ public ResponseEntity<ResponseMessage<?>> queryResumes(
832834
}
833835

834836
// 如果page和size参数都为默认值,则使用原来的查询方法(保持向后兼容)
835-
if (page == 0 && size == 10) {
837+
if (page == 0 && size == 10 && sortBy == null) {
836838
List<ResumeDTO> result = resumeService.queryResumes(name, major, expectedDepartment, cycleId, status);
837839
logger.info("管理员{}执行条件查询简历,结果数量: {}", username, result.size());
838840
return ResponseEntity.ok(ResponseMessage.success(result));
839841
} else {
840842
// 使用分页查询
841-
PageResultDTO<ResumeDTO> result = resumeService.queryResumesWithPagination(name, major, expectedDepartment, cycleId, status, page, size);
843+
PageResultDTO<ResumeDTO> result = resumeService.queryResumesWithPagination(name, major, expectedDepartment, cycleId, status, page, size, sortBy, sortOrder);
842844
logger.info("管理员{}执行分页条件查询简历,结果数量: {},总记录数: {}", username, result.getContent().size(), result.getTotalElements());
843845
return ResponseEntity.ok(ResponseMessage.success(result));
844846
}

src/main/java/club/boyuan/official/dto/InterviewAssignmentResultDTO.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public static class AssignedInterviewDTO {
7676
private String major; // 添加专业字段
7777
private String grade; // 添加年级字段
7878
private String preferredDepartments; // 添加期望部门字段(第一、第二志愿)
79+
private String preferredTimes; // 添加期望时间字段
7980
private LocalDateTime interviewTime;
8081
private String period; // 上午/下午
8182
private String interviewDepartment; // 面试部门(第一志愿)
@@ -85,7 +86,7 @@ public AssignedInterviewDTO() {
8586
}
8687

8788
public AssignedInterviewDTO(Integer userId, String username, String name, String email,
88-
String major, String grade, String preferredDepartments,
89+
String major, String grade, String preferredDepartments, String preferredTimes,
8990
LocalDateTime interviewTime, String period, String interviewDepartment, String classroom) {
9091
this.userId = userId;
9192
this.username = username;
@@ -94,6 +95,7 @@ public AssignedInterviewDTO(Integer userId, String username, String name, String
9495
this.major = major;
9596
this.grade = grade;
9697
this.preferredDepartments = preferredDepartments;
98+
this.preferredTimes = preferredTimes;
9799
this.interviewTime = interviewTime;
98100
this.period = period;
99101
this.interviewDepartment = interviewDepartment;
@@ -158,6 +160,14 @@ public void setPreferredDepartments(String preferredDepartments) {
158160
this.preferredDepartments = preferredDepartments;
159161
}
160162

163+
public String getPreferredTimes() {
164+
return preferredTimes;
165+
}
166+
167+
public void setPreferredTimes(String preferredTimes) {
168+
this.preferredTimes = preferredTimes;
169+
}
170+
161171
public LocalDateTime getInterviewTime() {
162172
return interviewTime;
163173
}

src/main/java/club/boyuan/official/mapper/ResumeMapper.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,15 @@ List<Resume> queryResumes(@Param("name") String name, @Param("major") String maj
8888
* @param status 简历状态(可选),支持多个状态,用逗号分隔,如"2,3,4,5"
8989
* @param offset 偏移量
9090
* @param limit 限制数量
91+
* @param sortBy 排序字段
92+
* @param sortOrder 排序顺序
9193
* @return 简历列表
9294
*/
9395
List<Resume> queryResumesWithPagination(@Param("name") String name, @Param("major") String major,
9496
@Param("expectedDepartment") String expectedDepartment,
9597
@Param("cycleId") Integer cycleId, @Param("status") String status,
96-
@Param("offset") int offset, @Param("limit") int limit);
98+
@Param("offset") int offset, @Param("limit") int limit,
99+
@Param("sortBy") String sortBy, @Param("sortOrder") String sortOrder);
97100

98101
/**
99102
* 统计多条件查询简历数量

src/main/java/club/boyuan/official/service/IResumeService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,11 @@ public interface IResumeService {
118118
* @param status 简历状态(可选),支持多个状态,用逗号分隔,如"2,3,4,5"
119119
* @param page 页码(从0开始)
120120
* @param size 每页大小
121+
* @param sortBy 排序字段
122+
* @param sortOrder 排序顺序(ASC/DESC)
121123
* @return 分页结果DTO
122124
*/
123-
PageResultDTO<ResumeDTO> queryResumesWithPagination(String name, String major, String expectedDepartment, Integer cycleId, String status, int page, int size);
125+
PageResultDTO<ResumeDTO> queryResumesWithPagination(String name, String major, String expectedDepartment, Integer cycleId, String status, int page, int size, String sortBy, String sortOrder);
124126

125127
/**
126128
* 根据cycleId获取所有简历

src/main/java/club/boyuan/official/service/impl/InterviewAssignmentServiceImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class InterviewAssignmentServiceImpl implements IInterviewAssignmentServi
4343
private static final LocalTime MORNING_START = LocalTime.of(9, 0);
4444
private static final LocalTime MORNING_END = LocalTime.of(11, 0);
4545
private static final LocalTime AFTERNOON_START = LocalTime.of(13, 0);
46-
private static final LocalTime AFTERNOON_END = LocalTime.of(17, 0);
46+
private static final LocalTime AFTERNOON_END = LocalTime.of(17, 30);
4747
private static final LocalTime EVENING_START = LocalTime.of(19, 0);
4848
private static final LocalTime EVENING_END = LocalTime.of(21, 0);
4949
private static final int INTERVIEW_DURATION = 10; // 面试时长10分钟
@@ -1030,8 +1030,10 @@ private boolean tryAssignInterviewTime(User user, Resume resume, List<String> pr
10301030
String grade = getResumeGrade(resume);
10311031
// 获取格式化的期望部门信息
10321032
String preferredDepartments = getFormattedPreferredDepartments(user.getUserId(), userPreferredDepartments);
1033+
// 获取用户期望的面试时间
1034+
String preferredTimesStr = String.join(", ", preferredTimes);
10331035
assignedInterviews.add(new InterviewAssignmentResultDTO.AssignedInterviewDTO(
1034-
user.getUserId(), user.getUsername(), name, email, major, grade, preferredDepartments, assignedSlot, period, department, classroom));
1036+
user.getUserId(), user.getUsername(), name, email, major, grade, preferredDepartments, preferredTimesStr, assignedSlot, period, department, classroom));
10351037
return true;
10361038
} else {
10371039
// 没有可用教室,需要释放时间槽

src/main/java/club/boyuan/official/service/impl/ResumeServiceImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,8 @@ public List<ResumeDTO> queryResumes(String name, String major, String expectedDe
292292
}
293293

294294
@Override
295-
public PageResultDTO<ResumeDTO> queryResumesWithPagination(String name, String major, String expectedDepartment, Integer cycleId, String status, int page, int size) {
296-
logger.info("分页条件查询简历:name={}, major={}, expectedDepartment={}, cycleId={}, status={}, page={}, size={}", name, major, expectedDepartment, cycleId, status, page, size);
295+
public PageResultDTO<ResumeDTO> queryResumesWithPagination(String name, String major, String expectedDepartment, Integer cycleId, String status, int page, int size, String sortBy, String sortOrder) {
296+
logger.info("分页条件查询简历:name={}, major={}, expectedDepartment={}, cycleId={}, status={}, page={}, size={}, sortBy={}, sortOrder={}", name, major, expectedDepartment, cycleId, status, page, size, sortBy, sortOrder);
297297

298298
try {
299299
// 参数校验
@@ -308,7 +308,7 @@ public PageResultDTO<ResumeDTO> queryResumesWithPagination(String name, String m
308308
int totalElements = resumeMapper.countResumes(name, major, expectedDepartment, cycleId, status);
309309

310310
// 查询数据
311-
List<Resume> resumes = resumeMapper.queryResumesWithPagination(name, major, expectedDepartment, cycleId, status, offset, size);
311+
List<Resume> resumes = resumeMapper.queryResumesWithPagination(name, major, expectedDepartment, cycleId, status, offset, size, sortBy, sortOrder);
312312

313313
// 转换为DTO
314314
List<ResumeDTO> result = new ArrayList<>();

src/main/java/club/boyuan/official/utils/ExcelExportUtil.java

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public static byte[] exportInterviewAssignmentsToExcel(InterviewAssignmentResult
183183

184184
Sheet classroomSheet = workbook.createSheet(classroom);
185185
Row classroomHeader = classroomSheet.createRow(0);
186-
String[] classroomHeaders = {"用户名", "姓名", "邮箱", "专业", "年级", "期望部门", "所属部门", "面试时间", "时间段"};
186+
String[] classroomHeaders = {"用户名", "姓名", "邮箱", "专业", "年级", "期望部门", "所属部门", "面试时间", "时间段", "期望时间"};
187187

188188
for (int i = 0; i < classroomHeaders.length; i++) {
189189
Cell cell = classroomHeader.createCell(i);
@@ -251,6 +251,11 @@ public static byte[] exportInterviewAssignmentsToExcel(InterviewAssignmentResult
251251
Cell cell8 = row.createCell(8);
252252
cell8.setCellValue(dto.getPeriod() != null ? dto.getPeriod() : "");
253253
cell8.setCellStyle(dataStyle);
254+
255+
// 添加期望时间字段
256+
Cell cell9 = row.createCell(9);
257+
cell9.setCellValue(dto.getPreferredTimes() != null ? dto.getPreferredTimes() : "");
258+
cell9.setCellStyle(dataStyle);
254259
}
255260

256261
for (int i = 0; i < classroomHeaders.length; i++) {
@@ -273,13 +278,33 @@ public static byte[] exportInterviewAssignmentsToExcel(InterviewAssignmentResult
273278
for (InterviewAssignmentResultDTO.UnassignedUserDTO dto : result.getUnassignedUsers()) {
274279
Row row = unassignedSheet.createRow(unassignedRowNum++);
275280

276-
row.createCell(0).setCellValue(dto.getUsername() != null ? dto.getUsername() : "");
277-
row.createCell(1).setCellValue(dto.getName() != null ? dto.getName() : "");
278-
row.createCell(2).setCellValue(dto.getEmail() != null ? dto.getEmail() : "");
279-
row.createCell(3).setCellValue(dto.getMajor() != null ? dto.getMajor() : "");
280-
row.createCell(4).setCellValue(dto.getGrade() != null ? dto.getGrade() : "");
281-
row.createCell(5).setCellValue(dto.getPreferredTimes() != null ? dto.getPreferredTimes() : "");
282-
row.createCell(6).setCellValue(dto.getPreferredDepartments() != null ? dto.getPreferredDepartments() : "");
281+
Cell cell0 = row.createCell(0);
282+
cell0.setCellValue(dto.getUsername() != null ? dto.getUsername() : "");
283+
cell0.setCellStyle(dataStyle);
284+
285+
Cell cell1 = row.createCell(1);
286+
cell1.setCellValue(dto.getName() != null ? dto.getName() : "");
287+
cell1.setCellStyle(dataStyle);
288+
289+
Cell cell2 = row.createCell(2);
290+
cell2.setCellValue(dto.getEmail() != null ? dto.getEmail() : "");
291+
cell2.setCellStyle(dataStyle);
292+
293+
Cell cell3 = row.createCell(3);
294+
cell3.setCellValue(dto.getMajor() != null ? dto.getMajor() : "");
295+
cell3.setCellStyle(dataStyle);
296+
297+
Cell cell4 = row.createCell(4);
298+
cell4.setCellValue(dto.getGrade() != null ? dto.getGrade() : "");
299+
cell4.setCellStyle(dataStyle);
300+
301+
Cell cell5 = row.createCell(5);
302+
cell5.setCellValue(dto.getPreferredTimes() != null ? dto.getPreferredTimes() : "");
303+
cell5.setCellStyle(dataStyle);
304+
305+
Cell cell6 = row.createCell(6);
306+
cell6.setCellValue(dto.getPreferredDepartments() != null ? dto.getPreferredDepartments() : "");
307+
cell6.setCellStyle(dataStyle);
283308
}
284309
}
285310

@@ -302,11 +327,25 @@ public static byte[] exportInterviewAssignmentsToExcel(InterviewAssignmentResult
302327
for (InterviewAssignmentResultDTO.NoPreferenceUserDTO dto : result.getNoPreferenceUsers()) {
303328
Row row = noPreferenceSheet.createRow(noPreferenceRowNum++);
304329

305-
row.createCell(0).setCellValue(dto.getUsername() != null ? dto.getUsername() : "");
306-
row.createCell(1).setCellValue(dto.getName() != null ? dto.getName() : "");
307-
row.createCell(2).setCellValue(dto.getEmail() != null ? dto.getEmail() : "");
308-
row.createCell(3).setCellValue(dto.getMajor() != null ? dto.getMajor() : "");
309-
row.createCell(4).setCellValue(dto.getGrade() != null ? dto.getGrade() : "");
330+
Cell cell0 = row.createCell(0);
331+
cell0.setCellValue(dto.getUsername() != null ? dto.getUsername() : "");
332+
cell0.setCellStyle(dataStyle);
333+
334+
Cell cell1 = row.createCell(1);
335+
cell1.setCellValue(dto.getName() != null ? dto.getName() : "");
336+
cell1.setCellStyle(dataStyle);
337+
338+
Cell cell2 = row.createCell(2);
339+
cell2.setCellValue(dto.getEmail() != null ? dto.getEmail() : "");
340+
cell2.setCellStyle(dataStyle);
341+
342+
Cell cell3 = row.createCell(3);
343+
cell3.setCellValue(dto.getMajor() != null ? dto.getMajor() : "");
344+
cell3.setCellStyle(dataStyle);
345+
346+
Cell cell4 = row.createCell(4);
347+
cell4.setCellValue(dto.getGrade() != null ? dto.getGrade() : "");
348+
cell4.setCellStyle(dataStyle);
310349
}
311350
}
312351

src/main/resources/mapper/ResumeMapper.xml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,22 @@
8080
</choose>
8181
</if>
8282
</where>
83-
ORDER BY r.created_at DESC
83+
<choose>
84+
<when test="sortBy != null and sortBy != ''">
85+
ORDER BY r.${sortBy}
86+
<choose>
87+
<when test="sortOrder != null and sortOrder != ''">
88+
${sortOrder}
89+
</when>
90+
<otherwise>
91+
DESC
92+
</otherwise>
93+
</choose>
94+
</when>
95+
<otherwise>
96+
ORDER BY r.created_at DESC
97+
</otherwise>
98+
</choose>
8499
</select>
85100

86101
<!-- 多条件查询简历列表(分页) -->
@@ -131,7 +146,22 @@
131146
</choose>
132147
</if>
133148
</where>
134-
ORDER BY r.created_at DESC
149+
<choose>
150+
<when test="sortBy != null and sortBy != ''">
151+
ORDER BY r.${sortBy}
152+
<choose>
153+
<when test="sortOrder != null and sortOrder != ''">
154+
${sortOrder}
155+
</when>
156+
<otherwise>
157+
DESC
158+
</otherwise>
159+
</choose>
160+
</when>
161+
<otherwise>
162+
ORDER BY r.created_at DESC
163+
</otherwise>
164+
</choose>
135165
LIMIT #{offset}, #{limit}
136166
</select>
137167

0 commit comments

Comments
 (0)