@@ -106,41 +106,6 @@ public class DormController {
|
||||
dormService.setMonitor(roomId, studentId);
|
||||
}
|
||||
|
||||
/** 可添加学生名单:bschclass 在册学生,排除已保存到 dorm_student 的(供前端勾选)。 */
|
||||
@GetMapping("AvailableStudents")
|
||||
public List<Map<String, Object>> availableStudents(@RequestParam(required = false) String keyword) {
|
||||
return dormService.availableStudents(keyword);
|
||||
}
|
||||
|
||||
/** 保存前端勾选的学生到待安排池(roomId=0),返回新增人数。 */
|
||||
@PostMapping("SaveStudents")
|
||||
public Map<String, Object> saveStudents(@RequestParam String studentIds) {
|
||||
Map<String, Object> r = new java.util.LinkedHashMap<>();
|
||||
r.put("added", dormService.saveStudents(parseIds(studentIds)));
|
||||
return r;
|
||||
}
|
||||
|
||||
/** 手动删除已保存的学生(在住者重排该房床位),返回删除人数。 */
|
||||
@PostMapping("DeleteStudents")
|
||||
public Map<String, Object> deleteStudents(@RequestParam String studentIds) {
|
||||
Map<String, Object> r = new java.util.LinkedHashMap<>();
|
||||
r.put("removed", dormService.deleteStudents(parseIds(studentIds)));
|
||||
return r;
|
||||
}
|
||||
|
||||
private static List<Integer> parseIds(String csv) {
|
||||
List<Integer> ids = new java.util.ArrayList<>();
|
||||
if (csv != null) {
|
||||
for (String s : csv.split(",")) {
|
||||
String t = s.trim();
|
||||
if (!t.isEmpty()) {
|
||||
ids.add(Integer.parseInt(t));
|
||||
}
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
private static Map<String, Object> toObj(Map<String, String> src) {
|
||||
return src.entrySet().stream().collect(java.util.stream.Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
}
|
||||
|
||||
@@ -40,16 +40,4 @@ public interface IDormService {
|
||||
|
||||
/** 楼栋→楼层→房间树(ztree,供发布选房间;对应 base/GetDormTree)。 */
|
||||
List<Map<String, Object>> dormTree();
|
||||
|
||||
/**
|
||||
* 可添加学生名单:从 bschclass 学籍拉取本校在册学生,排除已保存到 dorm_student 的,供前端勾选。
|
||||
* 返回项:{studentId, studentName, className}。
|
||||
*/
|
||||
List<Map<String, Object>> availableStudents(String keyword);
|
||||
|
||||
/** 保存前端勾选的学生到 dorm_student(roomId=0 待安排池),已存在的跳过;返回新增人数。 */
|
||||
int saveStudents(List<Integer> studentIds);
|
||||
|
||||
/** 手动删除 dorm_student 中的学生(在住者删除后重排该房床位);返回删除人数。 */
|
||||
int deleteStudents(List<Integer> studentIds);
|
||||
}
|
||||
|
||||
@@ -434,7 +434,7 @@ public class DormService implements IDormService {
|
||||
}
|
||||
}
|
||||
|
||||
// ============================ bschclass 学籍(前端选择保存) ============================
|
||||
// ============================ bschclass 学籍(在册名单) ============================
|
||||
|
||||
private static final class Roster {
|
||||
final List<SchStudentDto> students;
|
||||
@@ -471,101 +471,6 @@ public class DormService implements IDormService {
|
||||
return new Roster(stus, classNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> availableStudents(String keyword) {
|
||||
List<Map<String, Object>> out = new ArrayList<>();
|
||||
Roster roster = fetchRoster();
|
||||
if (roster == null) {
|
||||
return out;
|
||||
}
|
||||
Set<Integer> savedIds = studentRepository.findAll().stream()
|
||||
.map(DormStudent::getStudentId).filter(Objects::nonNull).collect(Collectors.toSet());
|
||||
String kw = keyword == null ? "" : keyword.trim();
|
||||
for (SchStudentDto s : roster.students) {
|
||||
if (s.getStuId() == null || savedIds.contains(s.getStuId())) {
|
||||
continue; // 排除已保存到 dorm_student 的
|
||||
}
|
||||
if (!kw.isEmpty() && !String.valueOf(s.getStuName()).contains(kw)) {
|
||||
continue;
|
||||
}
|
||||
Map<String, Object> m = new LinkedHashMap<>();
|
||||
m.put("studentId", s.getStuId());
|
||||
m.put("studentName", s.getStuName());
|
||||
m.put("className", roster.classNames.get(s.getClassId()));
|
||||
out.add(m);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public int saveStudents(List<Integer> studentIds) {
|
||||
if (studentIds == null || studentIds.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
Integer schId = UserContext.getSchId();
|
||||
// 用最新在册名单补全姓名/班级(拿不到也不阻断,按 id 落库)
|
||||
Map<Integer, SchStudentDto> rosterById = new HashMap<>();
|
||||
Map<Integer, String> classNames = new HashMap<>();
|
||||
Roster roster = fetchRoster();
|
||||
if (roster != null) {
|
||||
for (SchStudentDto s : roster.students) {
|
||||
if (s.getStuId() != null) {
|
||||
rosterById.put(s.getStuId(), s);
|
||||
}
|
||||
}
|
||||
classNames = roster.classNames;
|
||||
}
|
||||
int added = 0;
|
||||
for (Integer id : studentIds) {
|
||||
if (id == null || studentRepository.findByStudentId(id).isPresent()) {
|
||||
continue; // 已存在跳过,幂等
|
||||
}
|
||||
SchStudentDto s = rosterById.get(id);
|
||||
DormStudent d = new DormStudent();
|
||||
d.setStudentId(id);
|
||||
d.setStudentName(s != null ? s.getStuName() : null);
|
||||
d.setClassName(s != null ? classNames.get(s.getClassId()) : null);
|
||||
d.setRoomId(0);
|
||||
d.setIsMonitor(false);
|
||||
d.setSourceDesc("学籍在册未分配床位");
|
||||
d.setSchId(schId);
|
||||
studentRepository.save(d);
|
||||
added++;
|
||||
}
|
||||
log.info("[saveStudents] schId={} 勾选 {} 人,新增保存 {} 人", schId, studentIds.size(), added);
|
||||
return added;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public int deleteStudents(List<Integer> studentIds) {
|
||||
if (studentIds == null || studentIds.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
int removed = 0;
|
||||
Set<Integer> roomsToRenumber = new HashSet<>();
|
||||
for (Integer id : studentIds) {
|
||||
if (id == null) {
|
||||
continue;
|
||||
}
|
||||
Optional<DormStudent> opt = studentRepository.findByStudentId(id);
|
||||
if (opt.isPresent()) {
|
||||
Integer rid = opt.get().getRoomId();
|
||||
studentRepository.delete(opt.get());
|
||||
if (rid != null && rid > 0) {
|
||||
roomsToRenumber.add(rid);
|
||||
}
|
||||
removed++;
|
||||
}
|
||||
}
|
||||
for (Integer rid : roomsToRenumber) {
|
||||
renumberBeds(rid);
|
||||
}
|
||||
log.info("[deleteStudents] 手动删除 {} 人", removed);
|
||||
return removed;
|
||||
}
|
||||
|
||||
// ============================ 辅助 ============================
|
||||
|
||||
private List<DormBuilding> buildingsOfSch() {
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -409,7 +410,7 @@ public class NoticeService implements INoticeService {
|
||||
@Override
|
||||
public Map<String, Object> statis(String startTime, String endTime) {
|
||||
List<Notice> list = noticeRepository.findAll();
|
||||
LocalDateTime st = parseDt(startTime), et = parseDt(endTime);
|
||||
LocalDateTime st = parseDt(startTime), et = parseDateEnd(endTime);
|
||||
if (st != null) list = list.stream().filter(n -> !nz(n.getCreateTime()).isBefore(st)).collect(Collectors.toList());
|
||||
if (et != null) list = list.stream().filter(n -> !nz(n.getCreateTime()).isAfter(et)).collect(Collectors.toList());
|
||||
|
||||
@@ -1108,7 +1109,7 @@ public class NoticeService implements INoticeService {
|
||||
if (StringUtils.hasText(ns) && !"all".equals(ns)) {
|
||||
out = out.stream().filter(n -> ns.equals(n.getNoticeStatus())).collect(Collectors.toList());
|
||||
}
|
||||
LocalDateTime st = parseDt(q.get("startTime")), et = parseDt(q.get("endTime"));
|
||||
LocalDateTime st = parseDt(q.get("startTime")), et = parseDateEnd(q.get("endTime"));
|
||||
if (st != null) out = out.stream().filter(n -> !nz(n.getEffectiveTime() == null ? n.getCreateTime() : n.getEffectiveTime()).isBefore(st)).collect(Collectors.toList());
|
||||
if (et != null) out = out.stream().filter(n -> !nz(n.getEffectiveTime() == null ? n.getCreateTime() : n.getEffectiveTime()).isAfter(et)).collect(Collectors.toList());
|
||||
int rt = intg(q.get("readType"), 0);
|
||||
@@ -1194,6 +1195,18 @@ public class NoticeService implements INoticeService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析查询区间的结束时间:纯日期(yyyy-MM-dd)时取当天末尾 23:59:59.999999999,使区间包含当天
|
||||
*/
|
||||
private LocalDateTime parseDateEnd(Object o) {
|
||||
LocalDateTime t = parseDt(o);
|
||||
if (t == null || o == null) {
|
||||
return t;
|
||||
}
|
||||
String s = String.valueOf(o).trim();
|
||||
return s.length() == 10 ? t.toLocalDate().atTime(LocalTime.MAX) : t;
|
||||
}
|
||||
|
||||
private Map<String, Object> parseFill(Object o) {
|
||||
if (o == null) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user