Files
UserclassService/src/main/java/com/yunhai/bschclassmanage/controller/api/SchTeacherController.java
T
2026-08-13 16:53:39 +08:00

141 lines
5.6 KiB
Java

package com.yunhai.bschclassmanage.controller.api;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.yunhai.bschclassmanage.config.Config;
import com.yunhai.bschclassmanage.controller.BaseController;
import com.yunhai.bschclassmanage.model.dto.SchTeacherDTO;
import com.yunhai.bschclassmanage.model.dto.TeaTransferGroupDTO;
import com.yunhai.bschclassmanage.model.dto.TeaTransferInGroupDTO;
import com.yunhai.bschclassmanage.model.excel.TeacherExcelColumn;
import com.yunhai.bschclassmanage.model.vo.PageVO;
import com.yunhai.bschclassmanage.model.vo.SchTeacherTOutVO;
import com.yunhai.bschclassmanage.model.vo.SchTeacherVO;
import com.yunhai.bschclassmanage.model.vo.SelectIntVO;
import com.yunhai.bschclassmanage.service.IComSchTreeService;
import com.yunhai.bschclassmanage.service.ISchTeacherService;
import com.yunhai.bschclassmanage.utils.EasyPoiUtils;
import com.yunhai.bschclassmanage.utils.UserContext;
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(@RequestParam(required = false) Integer groupId,
@RequestParam(required = false) String keyword,
Pageable pageable) {
return schTeacherService.searchSchTeacher(UserContext.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(@Valid @RequestBody SchTeacherDTO model) {
schTeacherService.saveTeacher(UserContext.getCurrentUser(),model);
}
@PostMapping("delete/{ids}")
public void deleteTeacher(@PathVariable String ids ) {
schTeacherService.deleteTeacher(UserContext.getCurrentUser(),ids);
}
@PostMapping("moveGroup")
public void moveGroup(@Valid @RequestBody TeaTransferGroupDTO model) {
schTeacherService.moveGroup(UserContext.getCurrentUser(),model);
}
@PostMapping("setStatus")
public void setTeacherStatus(String ids,Integer status){
schTeacherService.setTeacherStatus(UserContext.getCurrentUser(),ids,status);
}
@GetMapping("groupSelect") // 当前用户
public List<SelectIntVO> toTeacherGroupSelect() {
return schTeacherService.toTeacherGroupSelect(UserContext.getSchId());
}
@GetMapping("groupSelectBySchId")
public List<SelectIntVO> toTeacherGroupSelect(@RequestParam Integer schId) {
return schTeacherService.toTeacherGroupSelect(schId);
}
@GetMapping("select")
public List<SelectIntVO> toIdAndNameSelect(@RequestParam(required = false) Integer groupId) {
return schTeacherService.toIdAndNameSelect(groupId,UserContext.getSchId());
}
@GetMapping("transferOutSchSelect")
public List<SelectIntVO> transferOutSchSelect() {
return schTeacherService.transferOutSchSelect();
}
@PostMapping("setTransferOut/{ids}")
public void setTransferOut(@PathVariable String ids){
schTeacherService.setTransferOut(UserContext.getCurrentUser(),ids);
}
@PostMapping("setTransferIn")
public void setTransferIn(@Valid @RequestBody TeaTransferInGroupDTO model) {
schTeacherService.setTransferIn(UserContext.getCurrentUser(),model);
}
@GetMapping("downloadTemplate")
public void downloadTemplate(HttpServletResponse response) {
List<TeacherExcelColumn> list=new ArrayList<>();
String fileName="教师导入模板";
String titleName ="教师信息导入" ;
ExportParams exportParams = new ExportParams(titleName, "");
List<SelectIntVO> teaGroupNameList = comSchTreeService.getTeaGroupNameList(UserContext.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(@RequestPart("file") MultipartFile file) {
schTeacherService.importTeachers(UserContext.getCurrentUser(),file);
}
}