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 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 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 toTeacherGroupSelect(UserSysRole curRole) { return schTeacherService.toTeacherGroupSelect(curRole.getSchId()); } @GetMapping("groupSelectBySchId") public List toTeacherGroupSelect(@RequestParam Integer schId) { return schTeacherService.toTeacherGroupSelect(schId); } @GetMapping("select") public List toIdAndNameSelect(UserSysRole curRole,@RequestParam(required = false) Integer groupId) { return schTeacherService.toIdAndNameSelect(groupId,curRole.getSchId()); } @GetMapping("transferOutSchSelect") public List 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 list=new ArrayList<>(); String fileName="教师导入模板"; String titleName ="教师信息导入" ; ExportParams exportParams = new ExportParams(titleName, ""); List 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); } }