This commit is contained in:
2026-08-31 10:14:44 +08:00
parent 762e880a41
commit 7c6f93e68d
@@ -1,31 +1,69 @@
package com.yunhai.bschclassmanage.controller.oapi.oa; package com.yunhai.bschclassmanage.controller.oapi.oa;
import com.yunhai.bschclassmanage.Repository.SchInfoRepository;
import com.yunhai.bschclassmanage.config.Config; import com.yunhai.bschclassmanage.config.Config;
import com.yunhai.bschclassmanage.entity.SchInfo;
import com.yunhai.bschclassmanage.model.vo.oa.SchInfoVO; import com.yunhai.bschclassmanage.model.vo.oa.SchInfoVO;
import com.yunhai.bschclassmanage.service.ISchInfoService; import com.yunhai.bschclassmanage.service.ISchInfoService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.*;
import java.util.stream.Collectors;
@RestController @RestController
@RequestMapping(Config.OAPI+"/SchInfo/") @RequestMapping(Config.OAPI+"/SchInfo/")
@CrossOrigin(originPatterns = {"*"}, allowCredentials = "true") @CrossOrigin(originPatterns = {"*"}, allowCredentials = "true")
public class SchInfoController { public class SchInfoController {
@Autowired private ISchInfoService schInfoService;
@Autowired @Autowired private SchInfoRepository schInfoRepository;
private ISchInfoService schInfoService;
@GetMapping("GetSchlist") @GetMapping("GetSchlist")
public ResponseEntity<List<SchInfoVO>> GetSchlist(@RequestParam(required = false) String SchIDArr) { public ResponseEntity<List<SchInfoVO>> GetSchlist(@RequestParam(required = false) String SchIDArr) {
return ResponseEntity.ok(schInfoService.getSchVOList(SchIDArr)); return ResponseEntity.ok(schInfoService.getSchVOList(SchIDArr));
} }
@GetMapping("AllList")
public ResponseEntity<List<SchInfoVO>> AllList() { return ResponseEntity.ok(schInfoService.getSchVOList(null)); }
@GetMapping("GetSchFirst") @GetMapping("GetSchFirst")
public ResponseEntity<SchInfoVO> GetSchFirst(@RequestParam String SchID) { public ResponseEntity<SchInfoVO> GetSchFirst(@RequestParam(required = false) String SchID) {
return ResponseEntity.ok(schInfoService.GetSchFirst(SchID)); return ResponseEntity.ok(SchID == null ? null : schInfoService.GetSchFirst(SchID));
} }
@GetMapping("GetUserSchFirst")
public ResponseEntity<SchInfoVO> GetUserSchFirst(@RequestParam(required = false) Integer UserSchID) {
return ResponseEntity.ok(UserSchID == null ? null : schInfoService.GetSchFirst(UserSchID));
}
@GetMapping("GetUserSchlist")
public ResponseEntity<List<SchInfoVO>> GetUserSchlist(@RequestParam(required = false) String UserSchIds) {
if (UserSchIds == null || UserSchIds.trim().isEmpty()) return ResponseEntity.ok(Collections.emptyList());
Set<Integer> ids = parseInts(UserSchIds);
return ResponseEntity.ok(schInfoRepository.findAll().stream()
.filter(s -> ids.contains(s.getId()) || ids.contains(s.getSchId()))
.map(this::toVo).collect(Collectors.toList()));
}
@GetMapping("GetSchoolByGroupId")
public ResponseEntity<List<SchInfoVO>> GetSchoolByGroupId(@RequestParam(required = false) Integer groupId) {
if (groupId == null || groupId == 0) return ResponseEntity.ok(Collections.emptyList());
return ResponseEntity.ok(schInfoRepository.findAll().stream()
.filter(s -> Objects.equals(s.getSchId(), groupId)).map(this::toVo).collect(Collectors.toList()));
}
@GetMapping("GetSchoolBySchoolenId")
public ResponseEntity<List<Map<String, Object>>> GetSchoolBySchoolenId(@RequestParam(required = false) Integer groupId) {
return ResponseEntity.ok(Collections.emptyList());
}
private SchInfoVO toVo(SchInfo s) {
return SchInfoVO.builder().schSerId(s.getSchSerId()).userSchSerId(s.getId()).schName(s.getName()).build();
}
private Set<Integer> parseInts(String value) {
Set<Integer> result = new HashSet<>();
for (String token : value.split(",")) try { result.add(Integer.valueOf(token.trim())); } catch (NumberFormatException ignored) { }
return result;
}
} }