Files
UserclassService/src/main/java/com/bestsch/bschclassmanage/controller/api/SchTeacherController.java
T
Allen 66cd0f1515 refactor: 项目重构为 bschclassmanage 包结构,修复启动/CORS/路由问题
- 根包 com.bestsch.classicalchinese 重命名为 com.bestsch.bschclassmanage
- 修复 CORS 启动失败:allowCredentials=true 时 allowedOrigins 不能含 "*",
  23 个 Controller 的 @CrossOrigin 改用语义等价的 originPatterns
- 修复 /api/* 与 /oapi/* 接口 404:API_PATH/OAPI 常量去掉尾斜杠,
  消除 Spring Boot 2.7 PathPattern 下的双斜杠(/api//subject/) 导致的匹配失败
- UserSysRoleArgumentResolver 增加从 URL 参数 currentrole 回退解析(便于本地调试),
  原请求头 currentrole 注入方式保持不变
2026-08-12 16:59:57 +08:00

144 lines
6.2 KiB
Java

package com.bestsch.bschclassmanage.controller.api;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.bestsch.bschclassmanage.config.Config;
import com.bestsch.bschclassmanage.controller.BaseController;
import com.bestsch.bschclassmanage.model.dto.SchTeacherDTO;
import com.bestsch.bschclassmanage.model.dto.TeaTransferGroupDTO;
import com.bestsch.bschclassmanage.model.dto.TeaTransferInGroupDTO;
import com.bestsch.bschclassmanage.model.excel.TeacherExcelColumn;
import com.bestsch.bschclassmanage.model.tool.UserSysRole;
import com.bestsch.bschclassmanage.model.vo.PageVO;
import com.bestsch.bschclassmanage.model.vo.SchTeacherTOutVO;
import com.bestsch.bschclassmanage.model.vo.SchTeacherVO;
import com.bestsch.bschclassmanage.model.vo.SelectIntVO;
import com.bestsch.bschclassmanage.service.IComSchTreeService;
import com.bestsch.bschclassmanage.service.ISchTeacherService;
import com.bestsch.bschclassmanage.utils.EasyPoiUtils;
import com.bestsch.bschclassmanage.utils.UserContext;
import com.yunhai.platform.utils.model.BoaUser;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping(Config.API_PATH+"/teacher/")
@CrossOrigin(originPatterns = {"*"}, allowCredentials = "true")
public class SchTeacherController extends BaseController {
@Autowired
private ISchTeacherService schTeacherService; // 使用接口
@Autowired
private IComSchTreeService comSchTreeService; // 使用接口
@GetMapping("search")
public PageVO<SchTeacherVO> searchSchTeacher(UserSysRole curRole,
@RequestParam(required = false) Integer groupId,
@RequestParam(required = false) String keyword,
Pageable pageable) {
return schTeacherService.searchSchTeacher(curRole.getSchId(),groupId,keyword,pageable);
}
@GetMapping("searchTransferOut")
public PageVO<SchTeacherTOutVO> searchTransferOutTeacher(@RequestParam(required = false) Integer schId,
@RequestParam(required = false) Integer groupId,
@RequestParam(required = false) String keyword,
Pageable pageable) {
return schTeacherService.searchTransferOutTeacher(schId,groupId,keyword,pageable);
}
@PostMapping("save")
public void saveTeacher(BoaUser authUserWithDept, UserSysRole curRole, @Valid @RequestBody SchTeacherDTO model) {
schTeacherService.saveTeacher(UserContext.getCurrentUserInfo(),model);
}
@PostMapping("delete/{ids}")
public void deleteTeacher(BoaUser authUserWithDept, UserSysRole curRole,@PathVariable String ids ) {
schTeacherService.deleteTeacher(UserContext.getCurrentUserInfo(),ids);
}
@PostMapping("moveGroup")
public void moveGroup(BoaUser authUserWithDept, UserSysRole curRole,@Valid @RequestBody TeaTransferGroupDTO model) {
schTeacherService.moveGroup(UserContext.getCurrentUserInfo(),model);
}
@PostMapping("setStatus")
public void setTeacherStatus(BoaUser authUserWithDept, UserSysRole curRole, String ids,Integer status){
schTeacherService.setTeacherStatus(UserContext.getCurrentUserInfo(),ids,status);
}
@GetMapping("groupSelect") // 当前用户
public List<SelectIntVO> toTeacherGroupSelect(UserSysRole curRole) {
return schTeacherService.toTeacherGroupSelect(curRole.getSchId());
}
@GetMapping("groupSelectBySchId")
public List<SelectIntVO> toTeacherGroupSelect(@RequestParam Integer schId) {
return schTeacherService.toTeacherGroupSelect(schId);
}
@GetMapping("select")
public List<SelectIntVO> toIdAndNameSelect(UserSysRole curRole,@RequestParam(required = false) Integer groupId) {
return schTeacherService.toIdAndNameSelect(groupId,curRole.getSchId());
}
@GetMapping("transferOutSchSelect")
public List<SelectIntVO> transferOutSchSelect() {
return schTeacherService.transferOutSchSelect();
}
@PostMapping("setTransferOut/{ids}")
public void setTransferOut(BoaUser authUserWithDept, UserSysRole curRole,@PathVariable String ids){
schTeacherService.setTransferOut(UserContext.getCurrentUserInfo(),ids);
}
@PostMapping("setTransferIn")
public void setTransferIn(BoaUser authUserWithDept, UserSysRole curRole,@Valid @RequestBody TeaTransferInGroupDTO model) {
schTeacherService.setTransferIn(UserContext.getCurrentUserInfo(),model);
}
@GetMapping("downloadTemplate")
public void downloadTemplate(UserSysRole curRole,HttpServletResponse response) {
List<TeacherExcelColumn> list=new ArrayList<>();
String fileName="教师导入模板";
String titleName ="教师信息导入" ;
ExportParams exportParams = new ExportParams(titleName, "");
List<SelectIntVO> teaGroupNameList = comSchTreeService.getTeaGroupNameList(curRole.getSchId(),null);
for (SelectIntVO group:teaGroupNameList)
{
TeacherExcelColumn column=new TeacherExcelColumn();
column.setGroupName(group.getName());
column.setAccount("");
column.setPassword("");
column.setTeaName("");
column.setIdCard("");
column.setTel("");
column.setGender("");
list.add(column);
}
Workbook workbook2 = ExcelExportUtil.exportExcel(exportParams, TeacherExcelColumn.class, list);
EasyPoiUtils.downLoadExcel(fileName + ".xls", response, workbook2);
}
@PostMapping("importTeachers")
public void importTeachers(BoaUser authUserWithDept, UserSysRole curRole,@RequestPart("file") MultipartFile file) {
schTeacherService.importTeachers(UserContext.getCurrentUserInfo(),file);
}
}