新增教研室和教员的时候,同步创建部门和教员账号

This commit is contained in:
2026-09-17 12:00:44 +08:00
parent f7299c36e8
commit 95a3571c69
25 changed files with 1452 additions and 50 deletions
@@ -71,6 +71,92 @@ public class DownloadController {
downloadTemplate(response, "教研室模板.xls");
}
/**
* 教员导入模板(动态生成:数据 sheet + 填写说明 sheet)。
* <p>列序与 /jys/teacher/import 解析一致:
* 教员编号、教员姓名、教研室代号、职称、专业技术职务等级、教员类别、
* 性别、手机号、身份证号、备注、序号、虚实类型。</p>
*/
@GetMapping("/jy")
public void downloadJy(HttpServletResponse response) throws IOException {
org.apache.poi.ss.usermodel.Workbook workbook = new org.apache.poi.xssf.usermodel.XSSFWorkbook();
try {
org.apache.poi.ss.usermodel.CellStyle headerStyle = workbook.createCellStyle();
org.apache.poi.ss.usermodel.Font headerFont = workbook.createFont();
headerFont.setBold(true);
headerStyle.setFont(headerFont);
org.apache.poi.ss.usermodel.CellStyle requiredStyle = workbook.createCellStyle();
org.apache.poi.ss.usermodel.Font requiredFont = workbook.createFont();
requiredFont.setBold(true);
requiredFont.setColor(org.apache.poi.ss.usermodel.IndexedColors.RED.getIndex());
requiredStyle.setFont(requiredFont);
String[] headers = {"教员编号", "教员姓名*", "教研室代号*", "职称", "专业技术职务等级",
"教员类别", "性别", "手机号", "身份证号", "备注", "序号", "虚实类型"};
org.apache.poi.ss.usermodel.Sheet dataSheet = workbook.createSheet("教员");
org.apache.poi.ss.usermodel.Row headerRow = dataSheet.createRow(0);
for (int i = 0; i < headers.length; i++) {
org.apache.poi.ss.usermodel.Cell cell = headerRow.createCell(i);
cell.setCellValue(headers[i]);
cell.setCellStyle(headers[i].endsWith("*") ? requiredStyle : headerStyle);
dataSheet.setColumnWidth(i, 16 * 256);
}
String[][] instructions = {
{"教员编号", "选填", "留空则系统自动生成(JY+流水号);手填须唯一"},
{"教员姓名", "必填", "文本"},
{"教研室代号", "必填", "教研室表中的教研室代号(非名称),必须已存在"},
{"职称", "选填", "文本,如:讲师、副教授"},
{"专业技术职务等级", "选填", "文本,如:初级、中级、高级"},
{"教员类别", "选填", "文本,如:专业技术军官"},
{"性别", "选填", "数字:1=男,0=女"},
{"手机号", "选填", "文本"},
{"身份证号", "选填", "文本"},
{"备注", "选填", "文本"},
{"序号", "选填", "数字"},
{"虚实类型", "选填", "数字:0=实员"}
};
org.apache.poi.ss.usermodel.Sheet helpSheet = workbook.createSheet("填写说明");
org.apache.poi.ss.usermodel.Row titleRow = helpSheet.createRow(0);
org.apache.poi.ss.usermodel.Cell titleCell = titleRow.createCell(0);
titleCell.setCellValue("教员导入填写说明(红色表头列为必填;导入只写教员档案不建账号,账号用列表【对齐到用户表】批量开通)");
titleCell.setCellStyle(headerStyle);
String[] helpHeaders = {"列名", "是否必填", "填写说明"};
org.apache.poi.ss.usermodel.Row helpHeaderRow = helpSheet.createRow(1);
for (int i = 0; i < helpHeaders.length; i++) {
org.apache.poi.ss.usermodel.Cell cell = helpHeaderRow.createCell(i);
cell.setCellValue(helpHeaders[i]);
cell.setCellStyle(headerStyle);
}
for (int i = 0; i < instructions.length; i++) {
org.apache.poi.ss.usermodel.Row row = helpSheet.createRow(i + 2);
for (int j = 0; j < 3; j++) {
row.createCell(j).setCellValue(instructions[i][j]);
}
if ("必填".equals(instructions[i][1])) {
row.getCell(1).setCellStyle(requiredStyle);
}
}
helpSheet.setColumnWidth(0, 18 * 256);
helpSheet.setColumnWidth(1, 10 * 256);
helpSheet.setColumnWidth(2, 60 * 256);
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
FileUtils.setAttachmentResponseHeader(response, "教员导入模板.xlsx");
workbook.write(response.getOutputStream());
response.getOutputStream().flush();
} catch (IOException e) {
throw e;
} catch (Exception e) {
throw new ServiceException("生成教员导入模板失败:" + e.getMessage());
} finally {
try {
workbook.close();
} catch (IOException ignored) {
}
}
}
/**
* 联教连训管理模板
*/
@@ -38,7 +38,7 @@ public class FacultyController {
*/
@PostMapping("/office/add")
public Result<Void> addOffice(@RequestBody JYSB entity) {
facultyService.addJYSB(entity);
facultyService.addJYSB(entity, null);
return Result.success();
}
@@ -49,7 +49,7 @@ public class FacultyController {
*/
@PostMapping("/office/disable")
public Result<Void> disableOffice(@RequestParam("jysdh") String jysdh) {
facultyService.disableJYSB(jysdh);
facultyService.disableJYSB(jysdh, null);
return Result.success();
}
@@ -58,7 +58,7 @@ public class FacultyController {
*/
@PostMapping("/office/update")
public Result<Void> updateOffice(@RequestBody JYSB entity) {
facultyService.updateJYSB(entity);
facultyService.updateJYSB(entity, null);
return Result.success();
}
@@ -60,14 +60,18 @@ public class JYSController {
@Resource
private TeachingTaskManageService teachingTaskManageService;
@Resource
private com.roomroot.jwgl.service.OrgSyncService orgSyncService;
// ======================== 教研室管理 ========================
/**
* 新增教研室
*/
@PostMapping("/office/add")
public Result<Void> addOffice(@RequestBody JYSB entity) {
facultyService.addJYSB(entity);
public Result<Void> addOffice(@RequestBody JYSB entity,
@RequestParam(required = false) Boolean syncDept) {
facultyService.addJYSB(entity, syncDept);
return Result.success();
}
@@ -79,8 +83,9 @@ public class JYSController {
* @param jysdh 教研室代号
*/
@PostMapping("/office/disable")
public Result<Void> disableOffice(@RequestParam("jysdh") String jysdh) {
facultyService.disableJYSB(jysdh);
public Result<Void> disableOffice(@RequestParam("jysdh") String jysdh,
@RequestParam(required = false) Boolean syncDept) {
facultyService.disableJYSB(jysdh, syncDept);
return Result.success();
}
@@ -88,11 +93,35 @@ public class JYSController {
* 更新教研室
*/
@PostMapping("/office/update")
public Result<Void> updateOffice(@RequestBody JYSB entity) {
facultyService.updateJYSB(entity);
public Result<Void> updateOffice(@RequestBody JYSB entity,
@RequestParam(required = false) Boolean syncDeptName) {
facultyService.updateJYSB(entity, syncDeptName);
return Result.success();
}
/**
* 单个教研室补建/对齐组织部门(幂等:已关联则直接返回部门编号)。
*/
@PostMapping("/office/sync-dept")
public Result<Long> syncOfficeDept(@RequestParam("jysdh") String jysdh) {
JYSB entity = facultyService.getJYSBById(jysdh);
if (entity == null) {
return Result.error("教研室不存在:" + jysdh);
}
return Result.success(orgSyncService.ensureOfficeDept(entity));
}
/**
* 对齐组织部门:为教研室批量创建/复用组织部门(直接执行,幂等)。
* body{ "ids": ["JYS01", ...] }ids 不传 = 全部教研室。
*/
@PostMapping("/org/align-dept")
public Result<com.roomroot.jwgl.vo.orgsync.OrgAlignResultVO> alignDepts(
@RequestBody(required = false) java.util.Map<String, List<String>> body) {
List<String> ids = body == null ? null : body.get("ids");
return Result.success(orgSyncService.alignDepts(ids));
}
/**
* 根据代号查询教研室详情
*
@@ -144,8 +173,9 @@ public class JYSController {
* </p>
*/
@PostMapping("/office/import")
public Result<Integer> importOffice(@RequestParam("file") MultipartFile file) throws Exception {
int count = facultyService.importJYSBFromExcel(file);
public Result<Integer> importOffice(@RequestParam("file") MultipartFile file,
@RequestParam(required = false) Boolean syncDept) throws Exception {
int count = facultyService.importJYSBFromExcel(file, syncDept);
return Result.success("导入成功,共" + count + "条记录", count);
}
// ======================== 教员管理 ========================
@@ -171,6 +201,44 @@ public class JYSController {
return Result.success();
}
/**
* 单个教员补建/对齐系统账号(幂等:已有账号直接返回用户编号)。
*/
@PostMapping("/teacher/sync-user")
public Result<Long> syncTeacherUser(@RequestParam("jybh") String jybh,
@RequestParam(required = false) String loginName,
@RequestParam(required = false) String password,
@RequestParam(required = false) Long roleId) {
JYB entity = facultyService.getJYBById(jybh);
if (entity == null) {
return Result.error("教员不存在:" + jybh);
}
return Result.success(orgSyncService.ensureTeacherUser(entity, loginName, password, roleId));
}
/**
* 对齐到用户表:为无账号教员批量建账号(直接执行,幂等,逐条返回明细)。
* body{ "ids": ["JY01", ...] }ids 不传 = 全部无账号教员。
*/
@PostMapping("/teacher/align-user")
public Result<com.roomroot.jwgl.vo.orgsync.OrgAlignResultVO> alignUsers(
@RequestBody(required = false) java.util.Map<String, List<String>> body) {
List<String> ids = body == null ? null : body.get("ids");
return Result.success(orgSyncService.alignUsers(ids));
}
/**
* 一键对齐:先对齐组织部门、再对齐用户账号(同一事务,幂等)。
*/
@PostMapping("/org/align-apply")
public Result<java.util.Map<String, com.roomroot.jwgl.vo.orgsync.OrgAlignResultVO>> alignApply() {
java.util.Map<String, com.roomroot.jwgl.vo.orgsync.OrgAlignResultVO> result =
new java.util.LinkedHashMap<>();
result.put("dept", orgSyncService.alignDepts(null));
result.put("user", orgSyncService.alignUsers(null));
return Result.success(result);
}
/**
* 更新教员基本信息
* <p>支持教学单位调整(修改教研室代号)、职称调整(修改职称、专业技术职务等级)。</p>
@@ -101,4 +101,13 @@ public class TeachingTaskController {
teachingTaskService.endPublish(bh);
return Result.success();
}
/**
* 导出教学任务书 Excel(该教学任务下全部教研室任务书课程明细)。
*/
@GetMapping("/exportTaskBook")
public void exportTaskBook(jakarta.servlet.http.HttpServletResponse response,
@RequestParam("bh") String bh) throws Exception {
teachingTaskService.exportTaskBook(response, bh);
}
}