From 082e0631ce6e8f9632c824ee0ee08304619a0bc3 Mon Sep 17 00:00:00 2001 From: cs <2268380485@qq.com> Date: Tue, 29 Apr 2025 18:30:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E:=E6=B7=BB=E5=8A=A0controller?= =?UTF-8?q?,mapper,model=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recruit/controller/AdminController.java | 1182 +++++++++++++++++ .../controller/AuthenticationController.java | 510 +++++++ .../recruit/controller/RestFulController.java | 232 ++++ .../controller/SuperAdminController.java | 898 +++++++++++++ .../recruit/controller/UserController.java | 1084 +++++++++++++++ .../edu/hfbu/recruit/mapper/AdminInter.java | 124 ++ .../edu/hfbu/recruit/mapper/ThingInter.java | 435 ++++++ .../edu/hfbu/recruit/mapper/UserInter.java | 204 +++ .../java/edu/hfbu/recruit/model/Admin.java | 67 + .../hfbu/recruit/model/ApiResponseData.java | 54 + .../java/edu/hfbu/recruit/model/Batch.java | 102 ++ .../java/edu/hfbu/recruit/model/Position.java | 164 +++ .../edu/hfbu/recruit/model/RefuseDataMap.java | 34 + .../recruit/model/SwitchMethodStatus.java | 27 + .../java/edu/hfbu/recruit/model/Thing.java | 177 +++ .../edu/hfbu/recruit/model/ThingWithUser.java | 46 + .../java/edu/hfbu/recruit/model/User.java | 212 +++ .../model/api/ImageCaptchaResponse.java | 40 + .../hfbu/recruit/model/api/JsonReader.java | 49 + .../hfbu/recruit/model/api/SMApiResponse.java | 63 + .../recruit/model/api/VerifyCodeResponse.java | 42 + .../edu/hfbu/recruit/model/export/Excel.java | 209 +++ .../edu/hfbu/recruit/model/export/Ticket.java | 88 ++ .../edu/hfbu/recruit/model/page/Page.java | 56 + .../model/page/SearchAndPageOfAdmin.java | 51 + .../model/page/SearchAndPageOfBatches.java | 52 + .../model/page/SearchAndPageOfDepartment.java | 39 + .../model/page/SearchAndPageOfPosition.java | 31 + .../page/SearchAndPageOfPositionByUser.java | 40 + .../model/page/SearchAndPageOfResult.java | 102 ++ .../model/page/SearchAndPageOfUsers.java | 79 ++ .../hfbu/recruit/model/resume/Education.java | 70 + .../model/resume/FamilyConnections.java | 54 + .../edu/hfbu/recruit/model/resume/Paper.java | 73 + .../hfbu/recruit/model/resume/Project.java | 73 + .../hfbu/recruit/model/resume/Research.java | 33 + .../hfbu/recruit/model/resume/UserInfo.java | 162 +++ .../hfbu/recruit/model/resume/UserResume.java | 165 +++ .../recruit/model/resume/WorkExperience.java | 62 + .../model/token/CustomUserDetailsService.java | 35 + .../edu/hfbu/recruit/model/token/Token.java | 151 +++ 41 files changed, 7371 insertions(+) create mode 100644 src/main/java/edu/hfbu/recruit/controller/AdminController.java create mode 100644 src/main/java/edu/hfbu/recruit/controller/AuthenticationController.java create mode 100644 src/main/java/edu/hfbu/recruit/controller/RestFulController.java create mode 100644 src/main/java/edu/hfbu/recruit/controller/SuperAdminController.java create mode 100644 src/main/java/edu/hfbu/recruit/controller/UserController.java create mode 100644 src/main/java/edu/hfbu/recruit/mapper/AdminInter.java create mode 100644 src/main/java/edu/hfbu/recruit/mapper/ThingInter.java create mode 100644 src/main/java/edu/hfbu/recruit/mapper/UserInter.java create mode 100644 src/main/java/edu/hfbu/recruit/model/Admin.java create mode 100644 src/main/java/edu/hfbu/recruit/model/ApiResponseData.java create mode 100644 src/main/java/edu/hfbu/recruit/model/Batch.java create mode 100644 src/main/java/edu/hfbu/recruit/model/Position.java create mode 100644 src/main/java/edu/hfbu/recruit/model/RefuseDataMap.java create mode 100644 src/main/java/edu/hfbu/recruit/model/SwitchMethodStatus.java create mode 100644 src/main/java/edu/hfbu/recruit/model/Thing.java create mode 100644 src/main/java/edu/hfbu/recruit/model/ThingWithUser.java create mode 100644 src/main/java/edu/hfbu/recruit/model/User.java create mode 100644 src/main/java/edu/hfbu/recruit/model/api/ImageCaptchaResponse.java create mode 100644 src/main/java/edu/hfbu/recruit/model/api/JsonReader.java create mode 100644 src/main/java/edu/hfbu/recruit/model/api/SMApiResponse.java create mode 100644 src/main/java/edu/hfbu/recruit/model/api/VerifyCodeResponse.java create mode 100644 src/main/java/edu/hfbu/recruit/model/export/Excel.java create mode 100644 src/main/java/edu/hfbu/recruit/model/export/Ticket.java create mode 100644 src/main/java/edu/hfbu/recruit/model/page/Page.java create mode 100644 src/main/java/edu/hfbu/recruit/model/page/SearchAndPageOfAdmin.java create mode 100644 src/main/java/edu/hfbu/recruit/model/page/SearchAndPageOfBatches.java create mode 100644 src/main/java/edu/hfbu/recruit/model/page/SearchAndPageOfDepartment.java create mode 100644 src/main/java/edu/hfbu/recruit/model/page/SearchAndPageOfPosition.java create mode 100644 src/main/java/edu/hfbu/recruit/model/page/SearchAndPageOfPositionByUser.java create mode 100644 src/main/java/edu/hfbu/recruit/model/page/SearchAndPageOfResult.java create mode 100644 src/main/java/edu/hfbu/recruit/model/page/SearchAndPageOfUsers.java create mode 100644 src/main/java/edu/hfbu/recruit/model/resume/Education.java create mode 100644 src/main/java/edu/hfbu/recruit/model/resume/FamilyConnections.java create mode 100644 src/main/java/edu/hfbu/recruit/model/resume/Paper.java create mode 100644 src/main/java/edu/hfbu/recruit/model/resume/Project.java create mode 100644 src/main/java/edu/hfbu/recruit/model/resume/Research.java create mode 100644 src/main/java/edu/hfbu/recruit/model/resume/UserInfo.java create mode 100644 src/main/java/edu/hfbu/recruit/model/resume/UserResume.java create mode 100644 src/main/java/edu/hfbu/recruit/model/resume/WorkExperience.java create mode 100644 src/main/java/edu/hfbu/recruit/model/token/CustomUserDetailsService.java create mode 100644 src/main/java/edu/hfbu/recruit/model/token/Token.java diff --git a/src/main/java/edu/hfbu/recruit/controller/AdminController.java b/src/main/java/edu/hfbu/recruit/controller/AdminController.java new file mode 100644 index 0000000..dd969b7 --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/controller/AdminController.java @@ -0,0 +1,1182 @@ +package edu.ahbvc.recruit.controller; + +// 导入各种必要的类和接口 +// 方法开关切面类 + +import edu.ahbvc.recruit.aspect.MethodSwitch; +import edu.ahbvc.recruit.model.*; +import edu.ahbvc.recruit.model.page.SearchAndPageOfBatches; +import edu.ahbvc.recruit.model.page.SearchAndPageOfPosition; +import edu.ahbvc.recruit.model.page.SearchAndPageOfResult; +import edu.ahbvc.recruit.model.page.SearchAndPageOfUsers; +import edu.ahbvc.recruit.model.token.Token; +import edu.ahbvc.recruit.service.ThingServiceImpl; +import edu.ahbvc.recruit.service.UserServiceImpl; +import edu.ahbvc.recruit.util.JwtUtil; +import edu.ahbvc.recruit.util.file.FilePatch; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 管理员控制器类 + * 处理所有需要管理员权限(普通HR及以上)的请求 + * 使用@RestController注解表示这是一个RESTful控制器 + * 使用@RequestMapping注解定义基础路径为"/api/admin" + * + * @author c215 作者信息 + */ +@RestController +// 利用URI前缀来区分不同的控制器, 方便管理和维护 +// 例如, 所有与管理员相关的请求都以/api/admin开头 +// 利用URI天然支持权限隔离的特性, 可以方便地实现权限控制 +@RequestMapping("api/admin") +public class AdminController { + + // 是否为开发环境标志(计划通过配置文件控制) + // true表示开发环境,false表示生产环境 +// API到期了,验证码什么的功能先不做了 +// 所以先注释掉 +// private static final boolean IS_DEV = false; + + // 用户服务实现类实例 + private UserServiceImpl userServiceImpl; + + // 事项服务实现类实例 + private ThingServiceImpl thingServiceImpl; + + // /** +// * 6位验证码 +// */ +// API到期了,验证码什么的功能先不做了 +// private String captcha = "1"; + @Autowired + public void setUserServiceImpl(UserServiceImpl userServiceImpl) { + this.userServiceImpl = userServiceImpl; + } + + // 使用@Autowired实现依赖注入 + // 注入ThingServiceImpl实例 + @Autowired + public void setThingServiceImpl(ThingServiceImpl thingService) { + this.thingServiceImpl = thingService; + } + + +// +// * 获取管理员首页 +// * @param authorizationHeader JWT token +// * @return 管理员首页所需数据 + + /** + * 获取管理员首页 + * + * @param authorizationHeader JWT token + * @return 管理员首页所需数据 + */ + @GetMapping("adminDashboard") + public ApiResponseData> getAdminStartMenu( + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT token + Token token = JwtUtil.parseJWT(authorizationHeader); + + // 令牌验证 + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 1) { + // 用户角色权限不足,返回500错误 + return new ApiResponseData<>("500", null, "用户无权操作"); + } + + // 获取各种功能开关状态 + // 注册功能开关 + boolean enableRegister = MethodSwitch.isEnabled(MethodSwitch.REGISTER); + // 放弃功能开关 + boolean enableAbandon = MethodSwitch.isEnabled(MethodSwitch.ABANDON); + // 提交功能开关 + boolean enableSubmit = MethodSwitch.isEnabled(MethodSwitch.SUBMIT); + // 重试提交功能开关 + boolean enableReTrySubmit = MethodSwitch.isEnabled(MethodSwitch.TRY_SUBMIT); + + // 获取各种统计数据 + // 用户总数 + int userTotal = userServiceImpl.getUsersNum(); + // 开放批次总数 + int openBatchTotal = thingServiceImpl.getBatchesNum(null, 1); + // 未处理事项数量 + int unsettledThingsNum = thingServiceImpl.getUnsettledThingsNum(); + + // 将数据封装到Map中 + // 用户总数 + HashMap map = new HashMap<>(); + map.put("userTotal", userTotal); + // 开放批次总数 + map.put("openBatchTotal", openBatchTotal); + // 未处理事项数量 + map.put("unsettledThingsNum", unsettledThingsNum); + // 注册功能开关状态(1开启/0关闭) + map.put("enableRegister", enableRegister ? 1 : 0); + // 放弃功能开关状态 + map.put("enableAbandon", enableAbandon ? 1 : 0); + // 提交功能开关状态 + map.put("enableSubmit", enableSubmit ? 1 : 0); + // 重试提交功能开关状态 + map.put("enableTrySubmit", enableReTrySubmit ? 1 : 0); + + // 封装响应数据 + ApiResponseData> responseData = new ApiResponseData<>(); + // 成功状态码 + responseData.setCode("0"); + // 成功消息 + responseData.setMessage("获取首页信息"); + // 响应数据 + responseData.setData(map); + // 返回响应 + return responseData; + } + +// * 获取用户列表 +// * @param requestBody 封装好了的搜索与分页信息 +// * @param authorizationHeader JWT token +// * @return 用户列表 + + /** + * 获取用户列表 + * + * @param requestBody 封装好了的搜索与分页信息 + * @param authorizationHeader JWT token + * @return 用户列表 + */ + @PostMapping("tableUsers") + public ApiResponseData> getUsers(@RequestBody SearchAndPageOfUsers requestBody, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT token + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 如果token为空或者用户角色小于1(即不是管理员), 返回错误信息 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 1) { + // 如果用户角色小于1(即不是管理员), 返回错误信息 + return new ApiResponseData<>("500", null, "用户无权操作"); + } + // 获取搜索与分页信息 + int size = requestBody.getSize(); + int beginIndex = (requestBody.getCurrentPage() - 1) * size; + // 获取搜索条件 + String name = requestBody.getName(); + String phone = requestBody.getPhone(); + String idNum = requestBody.getIdnum(); + Integer degree = requestBody.getDegree(); + // 获取用户列表 + List userList = userServiceImpl.getUsers(beginIndex, size, name, phone, idNum, degree); + // 获取用户总数 + int num = userServiceImpl.getUsersNum(name, phone, idNum, degree); + // 将用户列表和用户总数封装到Map中 + HashMap map = new HashMap<>(); + map.put("list", userList); + map.put("total", num); + // 封装响应数据 + ApiResponseData> responseData = new ApiResponseData<>(); + responseData.setCode("0"); + responseData.setMessage("获取用户列表成功"); + responseData.setData(map); + return responseData; + } + + +// * 添加用户 +// * @param user 用户信息(JSON) +// * @param authorizationHeader JWT token +// * @return 响应 + + /** + * 添加用户 + * + * @param user 用户信息(JSON) + * @param authorizationHeader JWT token + * @return 响应 + */ + @PostMapping("tableUser") + public ApiResponseData addUser(@RequestBody User user, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT token + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 如果token为空或者用户角色小于1(即不是管理员), 返回错误信息 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 1) { + // 如果用户角色小于1(即不是管理员), 返回错误信息 + return new ApiResponseData<>("500", null, "用户无权操作"); + } + // 调用业务层实现添加用户 + int result = userServiceImpl.addUser(user); + // 封装响应数据 + ApiResponseData responseData = new ApiResponseData<>(); + if (result == 1) { + // 添加成功 + responseData.setCode("0"); + // 添加成功消息 + responseData.setMessage("添加用户成功"); + } else { + // 添加失败 + responseData.setCode("500"); + // 添加失败消息 + responseData.setMessage("添加用户失败"); + } + // 返回响应 + return responseData; + } + + +// * 删除用户 +// * @param id 用户ID +// * @param authorizationHeader JWT token +// * @return 响应 + + /** + * 删除用户 + * + * @param id 用户ID + * @param authorizationHeader JWT token + * @return 响应 + */ + @DeleteMapping("tableUser/{id}") + public ApiResponseData deleteUser(@PathVariable("id") Integer id, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT token + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 1) { + // 如果用户角色小于1(即不是管理员), 返回错误信息 + return new ApiResponseData<>("500", null, "用户无权操作"); + } + // 调用业务层实现删除用户 + int result = userServiceImpl.delUser(id); + // 封装响应数据 + ApiResponseData responseData = new ApiResponseData<>(); + if (result == 1) { + responseData.setCode("0"); + responseData.setMessage("删除用户成功"); + } else { + responseData.setCode("500"); + responseData.setMessage("删除用户失败"); + } + return responseData; + } + +// * 修改用户信息 +// * @param user 用户信息(JSON) +// * @param authorizationHeader JWT token +// * @return 响应 + + /** + * 修改用户信息 + * + * @param user 用户信息(JSON) + * @param authorizationHeader JWT token + * @return 响应 + */ + @PutMapping("tableUser") + public ApiResponseData updateUser(@RequestBody User user, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT token + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 如果token为空或者用户角色小于1(即不是管理员), 返回错误信息 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 1) { + // 如果用户角色小于1(即不是管理员), 返回错误信息 + return new ApiResponseData<>("500", null, "用户无权操作"); + } + // 调用业务层获取被修改用户信息 + User oldUser = userServiceImpl.getOne(user.getId()); + // 调用业务层实现修改用户信息 + int result = userServiceImpl.updateUserName(user); + // 通过文件操作记录日志 + FilePatch.modifyLogToFile(oldUser.getIdNum(), oldUser.getName(), user.getIdNum(), user.getName()); + // 封装响应数据 + ApiResponseData responseData = new ApiResponseData<>(); + if (result == 1) { + // 修改成功 + responseData.setCode("0"); + // 修改成功消息 + responseData.setMessage("更新用户实名信息成功"); + } else { + // 修改失败 + responseData.setCode("500"); + // 修改失败消息 + responseData.setMessage("更新用户实名信息失败"); + } + // 返回响应 + return responseData; + } + + +// * 获取批次信息 +// * @param requestBody 封装好了的搜索和翻页参数 +// * @param authorizationHeader jwt请求头参数 +// * @return 批次列表 + + /** + * 获取批次信息 + * + * @param requestBody 封装好了的搜索和翻页参数 + * @param authorizationHeader jwt请求头参数 + * @return 批次列表 + */ + @PostMapping("tableBatches") + public ApiResponseData> getAllBatches(@RequestBody SearchAndPageOfBatches requestBody, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT token + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 1) { + // 用户角色权限不足,返回500错误 + return new ApiResponseData<>("500", null, "用户无权操作"); + } + // 获取翻页参数 + int size = requestBody.getSize(); + int beginIndex = (requestBody.getCurrentPage() - 1) * size; + // 获取搜索参数 + String key = requestBody.getKey(); + Integer state = requestBody.getState() == null ? null : requestBody.getState() - 1; + // 获取批次列表和批次总数 + List batches = thingServiceImpl.getBatches(beginIndex, size, key, state); + int total = thingServiceImpl.getBatchesNum(key, state); + // 将批次列表和批次总数封装到Map中 + HashMap map = new HashMap<>(); + map.put("list", batches); + map.put("total", total); + // 封装响应数据 + ApiResponseData> responseData = new ApiResponseData<>(); + // 成功状态码 + responseData.setCode("0"); + // 成功消息 + responseData.setMessage("获取批次数据"); + // 响应数据 + responseData.setData(map); + // 返回响应 + return responseData; + } + +// * 添加批次 +// * @param batch 批次信息(JSON) +// * @param authorizationHeader jwt请求头参数 +// * @return 响应 + + /** + * 添加批次 + * + * @param batch 批次信息(JSON) + * @param authorizationHeader jwt请求头参数 + * @return 响应 + */ + @PostMapping("tableBatch") + public ApiResponseData addBatch(@RequestBody Batch batch, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT token + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 2) { + // 用户角色权限不足,返回500错误 + return new ApiResponseData<>("500", null, "用户无权操作"); + } + // 调用业务层实现添加批次 + int result = thingServiceImpl.addBatch(batch); + // 封装响应数据 + ApiResponseData responseData = new ApiResponseData<>(); + if (result == 1) { + // 成功状态码 + responseData.setCode("0"); + // 成功消息 + responseData.setMessage("修改成功"); + } else { + // 失败状态码 + responseData.setCode("500"); + // 失败消息 + responseData.setMessage("修改失败"); + } + // 返回响应 + return responseData; + } + +// * 删除批次 +// * @param id 批次ID +// * @param authorizationHeader jwt请求头参数 +// * @return 响应 + + /** + * 删除批次 + * + * @param id 批次ID + * @param authorizationHeader jwt请求头参数 + * @return 响应 + */ + @DeleteMapping("tableBatch/{id}") + public ApiResponseData deleteBatch(@PathVariable("id") Integer id, + @RequestHeader("Authorization") String authorizationHeader) { + + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 2) { + // 用户角色权限不足,返回500错误 + return new ApiResponseData<>("500", null, "用户无权操作"); + } + // 调用业务层实现删除批次 + int result = thingServiceImpl.delBatch(id); + // 封装响应数据 + ApiResponseData responseData = new ApiResponseData<>(); + if (result == 1) { + // 成功状态码 + responseData.setCode("0"); + // 成功消息 + responseData.setMessage("删除成功"); + } else { + // 失败状态码 + responseData.setCode("500"); + // 失败消息 + responseData.setMessage("删除失败"); + } + // 返回响应 + return responseData; + } + +// * 修改批次信息 +// * @param batch 批次信息(JSON) +// * @param authorizationHeader jwt请求头参数 +// * @return 响应 + + /** + * 修改批次信息 + * + * @param batch 批次信息(JSON) + * @param authorizationHeader jwt请求头参数 + * @return 响应 + */ + @PutMapping("tableBatch") + public ApiResponseData updateBatch(@RequestBody Batch batch, + @RequestHeader("Authorization") String authorizationHeader) { + // 解析JWT token + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 2) { + // 用户角色权限不足,返回500错误 + return new ApiResponseData<>("500", null, "用户无权操作"); + } + // 获取旧的批次信息 + int id = batch.getId(); + // 获取旧的批次信息 + Batch oldBatch = thingServiceImpl.getBatch(id); + if (oldBatch.getOpen() != batch.getOpen()) { + // 获取当前日期和时间 + Date now = new Date(); + // 创建日期格式化对象 + // 格式化日期为"yyyy-MM-dd"格式 + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + // 格式化日期为字符串 + String formattedDate = dateFormat.format(now); + // 如果旧的批次状态和新的批次状态不同 + // 则设置批次的开始日期或截止日期 + System.out.println(formattedDate); + // 如果旧的批次状态和新的批次状态不同 + // 则设置批次的开始日期或截止日期 + if (oldBatch.getOpen() > batch.getOpen()) { + // 从启用改为禁用,将截止日期设置为现在 + batch.setDeadline(formattedDate); + } else { + // 从禁用用改为启用用,将开始日期设置为现在 + batch.setStartTime(formattedDate); + } + } + // 调用业务层实现修改批次信息 + int result = thingServiceImpl.updateBatch(batch); + // 封装响应数据 + ApiResponseData responseData = new ApiResponseData<>(); + if (result == 1) { + // 成功状态码 + responseData.setCode("0"); + // 成功消息 + responseData.setMessage("修改成功"); + } else { + // 失败状态码 + responseData.setCode("500"); + // 失败消息 + responseData.setMessage("修改失败"); + } + // 返回响应 + return responseData; + } + +// * 根据条件返回指定页的岗位信息 +// * @param requestBody 封装好了的搜索参数和分页参数 +// * @param authorizationHeader jwt token(通过请求头传递) +// * @return 岗位列表 + + /** + * 根据条件返回指定页的岗位信息 + * + * @param requestBody 封装好了的搜索参数和分页参数 + * @param authorizationHeader jwt token(通过请求头传递) + * @return 岗位列表 + */ + @PostMapping("tablePositions") + public ApiResponseData> getPosition(@RequestBody SearchAndPageOfPosition requestBody, + @RequestHeader("Authorization") String authorizationHeader) { + // 解析JWT token + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 1) { + // 用户角色权限不足,返回500错误 + return new ApiResponseData<>("500", null, "用户无权操作"); + } + // 获取翻页参数 + int pageSize = requestBody.getSize(); + int startIndex = (requestBody.getCurrentPage() - 1) * pageSize; + // 调用业务层实现获取岗位信息 + List list = thingServiceImpl.getPositions(startIndex, pageSize); + // 获取岗位总数 + int total = thingServiceImpl.getPositionsNum(); + + // 将岗位列表和岗位总数封装到Map中 + ApiResponseData> responseData = new ApiResponseData<>(); + HashMap map = new HashMap<>(); + map.put("list", list); + map.put("total", total); + + if (list != null) { + // 成功状态码 + responseData.setCode("0"); + // 成功消息 + responseData.setMessage("获取岗位信息成功"); + // 响应数据 + responseData.setData(map); + } else { + // 失败状态码 + responseData.setCode("500"); + // 失败消息 + responseData.setMessage("获取岗位信息失败"); + } + // 返回响应 + return responseData; + } + +// * 添加岗位 +// * @param position 岗位信息(JSON) +// * @param authorizationHeader jwt请求头参数 +// * @return 响应 + + /** + * 添加岗位 + * + * @param position 岗位信息(JSON) + * @param authorizationHeader jwt请求头参数 + * @return 响应 + */ + @PostMapping("tablePosition") + public ApiResponseData addPosition(@RequestBody Position position, + @RequestHeader("Authorization") String authorizationHeader) { + // 解析JWT token + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 1) { + // 用户角色权限不足,返回500错误 + return new ApiResponseData<>("500", null, "用户无权操作"); + } + // 调用业务层实现添加岗位 + int result = thingServiceImpl.addPosition(position); + // 封装响应数据 + ApiResponseData responseData = new ApiResponseData<>(); + if (result == 1) { + // 成功状态码 + responseData.setCode("0"); + // 成功消息 + responseData.setMessage("添加成功"); + } else { + // 失败状态码 + responseData.setCode("500"); + // 失败消息 + responseData.setMessage("添加失败"); + } + // 返回响应 + return responseData; + } + + +// * 删除岗位 +// * @param id 岗位ID +// * @param authorizationHeader jwt请求头参数 +// * @return 响应 + + /** + * 删除岗位 + * + * @param id 岗位ID + * @param authorizationHeader jwt请求头参数 + * @return 响应 + */ + @DeleteMapping("tablePosition/{id}") + public ApiResponseData deletePosition(@PathVariable("id") Integer id, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT token + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 1) { + // 用户角色权限不足,返回500错误 + return new ApiResponseData<>("500", null, "用户无权操作"); + } + // 调用业务层实现删除岗位 + int result = thingServiceImpl.delPosition(id); + // 封装响应数据 + ApiResponseData responseData = new ApiResponseData<>(); + if (result == 1) { + // 成功状态码 + responseData.setCode("0"); + // 成功消息 + responseData.setMessage("删除成功"); + } else { + // 失败状态码 + responseData.setCode("500"); + // 失败消息 + responseData.setMessage("删除失败"); + } + // 返回响应 + return responseData; + } + +// * 批量删除岗位 +// * @param list 岗位ID列表 +// * @param authorizationHeader jwt token(通过请求头传递) +// * @return 响应 + + /** + * 批量删除岗位 + * + * @param list 岗位ID列表 + * @param authorizationHeader jwt token(通过请求头传递) + * @return 响应 + */ + @PostMapping("tablePositionDel") + public ApiResponseData deletePosition2(@RequestBody List list, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT token + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 1) { + // 用户角色权限不足,返回500错误 + return new ApiResponseData<>("500", null, "用户无权操作"); + } + // 获取要删除的岗位数量 + int size = list.size(); + // 调用业务层实现批量删除岗位 + int total = thingServiceImpl.delPositions(list); + // 封装响应数据 + ApiResponseData responseData = new ApiResponseData<>(); + if (total == -1) { + // 外键约束错误,返回500错误 + responseData.setCode("500"); + // 失败消息 + responseData.setMessage("有的岗位存在未完成的投递"); + } else if (size == total) { + // 成功状态码 + responseData.setCode("0"); + // 成功消息 + responseData.setMessage("删除" + total + "个,共" + size + "个"); + } else { + // 失败状态码 + responseData.setCode("500"); + // 失败消息 + responseData.setMessage("删除" + total + "个,共" + size + "个"); + } + // 返回响应 + return responseData; + } + +// * 修改岗位信息 +// * @param position 岗位信息(JSON) +// * @param authorizationHeader jwt token(通过请求头传递) +// * @return 响应 + /** + * 修改岗位信息 + * + * @param position 岗位信息(JSON) + * @param authorizationHeader jwt token(通过请求头传递) + * @return 响应 + */ + @PutMapping("tablePosition") + public ApiResponseData updatePosition(@RequestBody Position position, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT token + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 1) { + // 用户角色权限不足,返回500错误 + return new ApiResponseData<>("500", null, "用户无权操作"); + } + // 调用业务层实现修改岗位信息 + int result = thingServiceImpl.updatePosition(position); + // 封装响应数据 + ApiResponseData responseData = new ApiResponseData<>(); + if (result == 1) { + // 成功状态码 + responseData.setCode("0"); + // 成功消息 + responseData.setMessage("修改成功"); + } else { + // 失败状态码 + responseData.setCode("500"); + // 失败消息 + responseData.setMessage("修改失败"); + } + // 返回响应 + return responseData; + } + +// * 获取招聘岗位列表 +// * Result表示拥有批次属性的position(岗位) +// * 但是因为项目需求变更,导致批次相关属性被废,此功能待重构 + /** + * 获取招聘岗位列表 + * Result表示拥有批次属性的position(岗位) + * 但是因为项目需求变更,导致批次相关属性被废,此功能待重构 + * + * @param requestBody 含有搜索条件和分页参数的请求体 + * @param authorizationHeader jwt token(通过请求头传递) + * @return 招聘岗位列表 + */ + @PostMapping("tableResults") + public ApiResponseData> gettableResultBySearch( + @RequestBody SearchAndPageOfResult requestBody, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT token + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 1) { + // 用户角色权限不足,返回500错误 + return new ApiResponseData<>("500", null, "用户无权操作"); + } + // 获取翻页参数 + int size = requestBody.getSize(); + int beginIndex = (requestBody.getCurrentPage() - 1) * size; + // 获取搜索参数 + List batches = requestBody.getBatches(); + List jobTitles = requestBody.getJobTitles(); + // 获取招聘岗位列表和总记录数 + ApiResponseData> responseData = new ApiResponseData<>(); + + // 调用业务层实现获取招聘岗位列表 + List list = thingServiceImpl.getRecruits(beginIndex, size, jobTitles, batches); + // 调用业务层实现获取总记录数 + int total = thingServiceImpl.getRecruitNum(jobTitles, batches); + // 将招聘岗位列表和总记录数封装到Map中 + HashMap map = new HashMap<>(); + map.put("list", list); + map.put("total", total); + if (list != null) { + // 成功状态码 + responseData.setCode("0"); + // 成功消息 + responseData.setMessage("获取招聘信息成功"); + // 响应数据 + responseData.setData(map); + } else { + // 失败状态码 + responseData.setCode("500"); + // 失败消息 + responseData.setMessage("获取招聘信息失败"); + } + // 返回响应 + return responseData; + } + +// * 添加招聘岗位 +// * @param map 封装了批次ID和岗位ID的Map +// * @param authorizationHeader jwt token(通过请求头传递) +// * @return 响应 + /** + * 添加招聘岗位 + * @param map 封装了批次ID和岗位ID的Map + * @param authorizationHeader jwt token(通过请求头传递) + * @return 响应 + */ + @PostMapping("tableResult") + public ApiResponseData addTableResult(@RequestBody HashMap map, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT token + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 1) { + // 用户角色权限不足,返回500错误 + return new ApiResponseData<>("500", null, "用户无权操作"); + } + // 调用业务层实现添加招聘岗位 + int result = thingServiceImpl.addRecruit(map.get("batchId"), map.get("positionId")); + // 封装响应数据 + ApiResponseData responseData = new ApiResponseData<>(); + if (result == 1) { + // 成功状态码 + responseData.setCode("0"); + // 成功消息 + responseData.setMessage("添加成功"); + } else { + // 失败状态码 + responseData.setCode("500"); + // 失败消息 + responseData.setMessage("添加失败"); + } + // 返回响应 + return responseData; + } + +// * 删除招聘岗位 +// * @param id 招聘岗位ID +// * @param authorizationHeader jwt token(通过请求头传递) +// * @return 响应 + /** + * 删除招聘岗位 + * @param id 招聘岗位ID + * @param authorizationHeader jwt token(通过请求头传递) + * @return 响应 + */ + @DeleteMapping("tableResult/{id}") + public ApiResponseData deleteTableResult(@PathVariable("id") Integer id, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT token + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 1) { + // 用户角色权限不足,返回500错误 + return new ApiResponseData<>("500", null, "用户无权操作"); + } + // 调用业务层实现删除招聘岗位 + int result = thingServiceImpl.deleteRecruit(id); + // 封装响应数据 + ApiResponseData responseData = new ApiResponseData<>(); + + if (result == 1) { + // 成功状态码 + responseData.setCode("0"); + // 成功消息 + responseData.setMessage("删除成功"); + } else if (result == -1) { + // 外键约束错误,返回500错误 + responseData.setCode("500"); + // 失败消息 + responseData.setMessage("该岗位还有投递信息未处理"); + } + // 返回响应 + return responseData; + } + +// * 修改招聘岗位信息 +// * @param map 封装了批次ID和岗位ID的Map +// * @param authorizationHeader jwt token(通过请求头传递) +// * @return 响应 + /** + * 修改招聘岗位信息 + * @param map 封装了批次ID和岗位ID的Map + * @param authorizationHeader jwt token(通过请求头传递) + * @return 响应 + */ + @PutMapping("tableResult") + public ApiResponseData updateTableResult(@RequestBody HashMap map, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT token + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 1) { + // 用户角色权限不足,返回500错误 + return new ApiResponseData<>("500", null, "用户无权操作"); + } + // 调用业务层实现修改招聘岗位信息 + int result = thingServiceImpl.updateRecruit(map.get("id"), map.get("batchId"), map.get("positionId")); + // 封装响应数据 + ApiResponseData responseData = new ApiResponseData<>(); + if (result == 1) { + // 成功状态码 + responseData.setCode("0"); + // 成功消息 + responseData.setMessage("修改成功"); + } else { + // 失败状态码 + responseData.setCode("500"); + // 失败消息 + responseData.setMessage("修改失败"); + } + // 返回响应 + return responseData; + } + +// * 获取用户投递的招聘信息(获取用户投递列表) +// * +// * @param requestBody 封装好了的搜索和翻页参数 +// * @return 获取用户投递的招聘信息(获取用户投递列表) + /** + * 获取用户投递的招聘信息(获取用户投递列表) + * + * @param requestBody 封装好了的搜索和翻页参数 + * @return 获取用户投递的招聘信息(获取用户投递列表) + */ + @PostMapping("tableThing2") + public ApiResponseData> getThingBySearch(@RequestBody SearchAndPageOfResult requestBody, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT token + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 1) { + // 用户角色权限不足,返回500错误 + return new ApiResponseData<>("500", null, "用户无权操作"); + } + // 获取翻页参数 + int size = requestBody.getSize(); + int beginIndex = (requestBody.getCurrentPage() - 1) * size; + // 获取搜索参数 + List batches = requestBody.getBatches(); + List jobTitles = requestBody.getJobTitles(); + List status = requestBody.getStatus(); + String name = requestBody.getName(); + // 获取用户投递的招聘信息(获取用户投递列表) + List things = thingServiceImpl.getThings(beginIndex, size, jobTitles, batches, status, name); + // 获取用户投递的招聘信息(获取用户投递列表)总数 + int total = thingServiceImpl.getThingsNum(jobTitles, batches, status, name); + // 将用户投递的招聘信息(获取用户投递列表)和总数封装到Map中 + HashMap map = new HashMap<>(); + map.put("list", things); + map.put("total", total); + // 封装响应数据 + ApiResponseData> responseData = new ApiResponseData<>(); + if (things != null) { + // 成功状态码 + responseData.setCode("0"); + // 成功消息 + responseData.setMessage("获取招聘信息成功"); + // 响应数据 + responseData.setData(map); + } else { + // 失败状态码 + responseData.setCode("500"); + // 失败消息 + responseData.setMessage("获取招聘信息失败"); + } + // 返回响应 + return responseData; + } + +// * 获取用户上传的资历文件 +// * user权限中也有类似接口,但查询范围受限 +// * +// * @param id 事务(投递)id +// * @return 用户上传的资历文件, 包括文件名和路径 + /** + * 获取用户上传的资历文件 + * user权限中也有类似接口,但查询范围受限 + * + * @param id 事务(投递)id + * @return 用户上传的资历文件, 包括文件名和路径 + */ + @GetMapping("tableThing") + public ApiResponseData> getThingInfo(@RequestParam("id") Integer id, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT token + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } + + // 获取用户上传的资历文件 + ThingWithUser thingInfo = thingServiceImpl.getOneThing(id); + if (thingInfo == null) { + // 失败状态码 + return new ApiResponseData<>("500", null, "获取招聘信息失败"); + } + // 封装响应数据 + HashMap map = userServiceImpl.getThingAndResume(thingInfo); + ApiResponseData> responseData = new ApiResponseData<>(); + + // 成功状态码 + responseData.setCode("0"); + // 成功消息 + responseData.setMessage("获取招聘信息成功"); + // 响应数据 + responseData.setData(map); + // 返回响应 + return responseData; + } + +// * 初审未通过 +// * +// * @param requestBody 前端传来的请求体参数 +// * @param authorizationHeader jwt 请求头 +// * @return 操作结果 + /** + * 初审未通过 + * + * @param requestBody 前端传来的请求体参数 + * @param authorizationHeader jwt 请求头 + * @return 操作结果 + */ + @PostMapping("refuse") + public ApiResponseData refuse(@RequestBody RefuseDataMap requestBody, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT token + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 1) { + // 用户角色权限不足,返回500错误 + return new ApiResponseData<>("500", null, "无权操作"); + } + // 调用业务层实现拒绝投递 + int i = thingServiceImpl.refuseThing(requestBody.getThingId(), -1, requestBody.getQualificationResult()); + // 封装响应数据 + ApiResponseData responseData = new ApiResponseData<>(); + if (i == 1) { + // 成功状态码 + responseData.setCode("0"); + // 成功消息 + responseData.setMessage("操作成功"); + } else { + // 失败状态码 + responseData.setCode("500"); + // 失败消息 + responseData.setMessage("操作失败"); + } + // 返回响应 + return responseData; + } + +// * 初审通过 +// * +// * @param map 前端传来的请求参数 +// * @param authorizationHeader jwt 请求头 token +// * @return 操作结果 + /** + * 初审通过 + * + * @param map 前端传来的请求参数 + * @param authorizationHeader jwt 请求头 token + * @return 操作结果 + */ + @PostMapping("accept") + public ApiResponseData agree(@RequestBody HashMap map, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT token + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 1) { + // 用户角色权限不足,返回500错误 + return new ApiResponseData<>("500", null, "无权操作"); + } + // 调用业务层实现通过投递 + int i = thingServiceImpl.updateThingStatus(map.get("thingId"), 1); + // 封装响应数据 + ApiResponseData responseData = new ApiResponseData<>(); + if (i == 1) { + // 成功状态码 + responseData.setCode("0"); + // 成功消息 + responseData.setMessage("批准成功"); + } else { + // 失败状态码 + responseData.setCode("500"); + // 失败消息 + responseData.setMessage("批准失败"); + } + // 返回响应 + return responseData; + } + +// * 获取用户是否有正在进行中的投递 +// * +// * @param authorizationHeader 授权请求头(包含授权信息) +// * @return 判断用户是否有正在进行中的投递 + /** + * 获取用户是否有正在进行中的投递 + * + * @param authorizationHeader 授权请求头(包含授权信息) + * @return 判断用户是否有正在进行中的投递 + */ + @GetMapping("userAlreadyRecruit") + public ApiResponseData getUserAlreadyRecruit(@RequestParam Integer id, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT token + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 1) { + // 用户角色权限不足,返回500错误 + return new ApiResponseData<>("500", null, "接口权限异常"); + } + // 调用业务层实现判断用户是否有正在进行中的投递 + boolean alreadyRecruit = userServiceImpl.alreadyRecruit(String.valueOf(id)); + // 封装响应数据 + ApiResponseData responseData = new ApiResponseData<>(); + // 成功状态码 + responseData.setCode("0"); + // 成功消息 + responseData.setMessage("用户信息获取成功"); + // 响应数据 + responseData.setData(alreadyRecruit); + // 返回响应 + return responseData; + } +} diff --git a/src/main/java/edu/hfbu/recruit/controller/AuthenticationController.java b/src/main/java/edu/hfbu/recruit/controller/AuthenticationController.java new file mode 100644 index 0000000..2ecbd93 --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/controller/AuthenticationController.java @@ -0,0 +1,510 @@ +package edu.ahbvc.recruit.controller; + +// 导入必要的类和接口 +// 自定义注解,用于方法开关控制 +import edu.ahbvc.recruit.annotation.SwitchMethod; +// 方法开关枚举类 +import edu.ahbvc.recruit.aspect.MethodSwitch; +// 管理员模型类 +import edu.ahbvc.recruit.model.Admin; +// API响应数据封装类 +import edu.ahbvc.recruit.model.ApiResponseData; +// 用户模型类 +import edu.ahbvc.recruit.model.User; +// 图片验证码API响应类 +import edu.ahbvc.recruit.model.api.ImageCaptchaResponse; +import edu.ahbvc.recruit.model.api.SMApiResponse; +// JWT令牌模型类 +import edu.ahbvc.recruit.model.token.Token; +// 管理员服务实现类 +import edu.ahbvc.recruit.service.AdminServiceImpl; +// 用户服务实现类 +import edu.ahbvc.recruit.service.UserServiceImpl; +// 第三方API服务接口 +import edu.ahbvc.recruit.service.api.ApiService; +// JWT工具类 +import edu.ahbvc.recruit.util.JwtUtil; +// HTTP会话对象 +import jakarta.servlet.http.HttpSession; +// 日志接口 +import org.slf4j.Logger; +// 日志工厂类 +import org.slf4j.LoggerFactory; +// Spring依赖注入注解 +import org.springframework.beans.factory.annotation.Autowired; +// Spring MVC注解 +import org.springframework.web.bind.annotation.*; + +// 导入Java标准库类 +// 动态数组实现 +import java.util.ArrayList; +// HashMap实现 +import java.util.HashMap; +// Map接口 +import java.util.Map; +/** + * 认证控制器类 + * 处理登录、注册等无需权限的接口 + * 使用@RestController注解表示这是一个RESTful控制器 + * 使用@RequestMapping注解定义基础路径为"/api" + * + * @author c215 作者信息 + */ +@RestController +@RequestMapping("api") +public class AuthenticationController { + // 日志记录器实例,用于记录调试和错误信息 + private static final Logger log = LoggerFactory.getLogger(AuthenticationController.class); + + // 定义角色常量 + // 超级管理员角色标识 + private static final int SUPER_ADMIN = 2; + // 普通管理员角色标识 + private static final int ADMIN = 1; + /** + * 图片验证码字符串 + * 存储从API获取的六位验证码 + * 注意:当前为public修饰符,存在安全隐患,建议改为private并提供getter方法 + */ + public String imgVerifyCode; + // API服务实例,用于调用第三方API + private ApiService api; + // 用户服务实现类实例 + private UserServiceImpl userServiceImpl; + + // 管理员服务实现类实例 + private AdminServiceImpl adminServiceImpl; + + // 使用@Autowired实现依赖注入 + // 注入AdminServiceImpl实例 + @Autowired + public void setAdminServiceImpl(AdminServiceImpl adminServiceImpl) { + this.adminServiceImpl = adminServiceImpl; + } + + // 使用@Autowired实现依赖注入 + // 注入UserServiceImpl实例 + @Autowired + public void setUserServiceImpl(UserServiceImpl userServiceImpl) { + this.userServiceImpl = userServiceImpl; + } + + // 使用@Autowired实现依赖注入 + // 注入ApiService实例 + @Autowired + public void setApi(ApiService api) { + this.api = api; + } + + /** + * 获取登录验证码API + * 处理GET请求,路径为/api/login/code + * + * @return 包含验证码信息的ApiResponseData对象 + */ + @GetMapping("login/code") + public ApiResponseData getLoginCode() { + // 创建API响应对象 + ApiResponseData apiResponseData = new ApiResponseData<>(); + + // 调用API获取图片验证码 + ImageCaptchaResponse imgCode = api.getImgCode(); + + // 获取API返回状态码 + String imgCodeApiResponseCode = imgCode.getDesc(); + + // 验证API调用是否成功 + if (!"000000".equals(imgCodeApiResponseCode)) { + // API调用失败,记录错误日志并返回错误响应 + log.error("api异常"); + apiResponseData.setMessage("图片验证码api异常"); + apiResponseData.setCode("500"); + return apiResponseData; + } else { + // API调用成功,处理返回数据 + // 获取验证码 + String code = imgCode.getResult().getVerifyCode(); + // 设置成功消息 + apiResponseData.setMessage("获取验证码成功"); + // 设置成功状态码 + apiResponseData.setCode("0"); + // 设置返回数据 + apiResponseData.setData(imgCode.getResult().getFileName()); + // 记录验证码日志 + log.info("当前验证码" + code); + // 存储验证码 + imgVerifyCode = code; + // 返回响应 + return apiResponseData; + } + } + + /** + * 管理员登录接口 + * 处理POST请求,路径为/api/admin/login + * + * @param session HTTP会话对象,用于存储用户信息 + * @param requestData 包含用户名和密码的请求数据 + * @return 包含登录结果的ApiResponseData对象 + */ + @PostMapping("admin/login") + public ApiResponseData> adlogin(HttpSession session, + @RequestBody Map requestData) { + // 创建响应对象 + ApiResponseData> responseData = new ApiResponseData<>(); +// String code = requestData.get("code"); + +// if (code.equals(imgVerifyCode)) { +// 从请求数据中获取用户名和密码 + String username = requestData.get("username"); + String password = requestData.get("password"); + + // 检查用户是否为管理员 + String isadmin = adminServiceImpl.isAdmin(username); + if (isadmin == null || isadmin.isEmpty()) { + // 普通用户登录逻辑 + User userlogin = userServiceImpl.login(username, password); + if (userlogin != null && userlogin.getName() != null) { + // 登录成功,生成JWT令牌 + int userId = userlogin.getId(); + // 创建普通用户令牌 + Token ut = new Token(userId, 0); + // 生成JWT + String token = JwtUtil.createJWT(ut); + // 记录调试日志 + log.debug("用户登录生成token= " + token); + + // 设置会话属性 + session.setAttribute("ROLE", "editor"); + // userRole是动态获取的用户角色 + session.setAttribute("USERNAME", userlogin.getName()); + + // 构建响应数据 + HashMap hashMap = new HashMap<>(); + hashMap.put("token", token); + responseData.setCode("0"); + responseData.setMessage("登录成功"); + responseData.setData(hashMap); + } else { + // 登录失败 + responseData.setCode("500"); + responseData.setMessage("账号或密码错误"); + } + } else { + // 管理员登录逻辑 + Admin admin = adminServiceImpl.login(username, password); + if (admin != null && admin.getAccount() != null) { + // 根据管理员权限级别生成不同令牌 + String token; + if (admin.getPromise() == 1) { + // 超级管理员 + Token token2 = new Token(admin.getId(), 2); + token = JwtUtil.createJWT(token2); + session.setAttribute("ROLE", "superadmin"); + } else { + // 普通管理员 + token = JwtUtil.createJWT(new Token(admin.getId(), 1)); + session.setAttribute("ROLE", "admin"); + } + + // 设置会话属性 + session.setAttribute("USERNAME", admin.getName()); + + // 构建响应数据 + HashMap hashMap = new HashMap<>(); + // 将令牌添加到响应数据中 + hashMap.put("token", token); + // 设置响应状态码和消息 + responseData.setCode("0"); + responseData.setMessage("登录成功"); + // 设置响应数据 + responseData.setData(hashMap); + } else { + // 管理员登录失败 + responseData.setCode("500"); + // 设置响应消息 + responseData.setMessage("账号或密码错误"); + } + } +// } else { +// // 验证码错误 +// responseData.setCode("500"); +// responseData.setMessage("验证码错误"); +// } + // 返回响应 + return responseData; + } + + /** + * @return 登录方法, 登录成功返回token + */ + @PostMapping("login") + public ApiResponseData> login(HttpSession session, + @RequestBody Map requestData) { + ApiResponseData> responseData = new ApiResponseData<>(); +// String code = requestData.get("code"); +// if (code.equals(imgVerifyCode)) { + // 从请求数据中获取用户名和密码 + String username = requestData.get("username"); + String password = requestData.get("password"); + // 检查用户是否为管理员 + String isAdmin = adminServiceImpl.isAdmin(username); + if (isAdmin == null || isAdmin.isEmpty()) { + // 普通用户登录逻辑 + User userLogin = userServiceImpl.login(username, password); + if (userLogin != null && userLogin.getName() != null) { + int userId = userLogin.getId(); + Token ut = new Token(userId, 0); + String token = JwtUtil.createJWT(ut); + log.debug("用户登录生成token= " + token); + // 记录调试日志 + responseData.setCode("0"); + // 设置响应状态码和消息 + responseData.setMessage("登录成功"); + // 设置会话属性 + session.setAttribute("ROLE", "editor"); + // userRole是动态获取的用户角色 + session.setAttribute("USERNAME", userLogin.getName()); + // 构建响应数据 + HashMap hashMap = new HashMap<>(); + // 将令牌添加到响应数据中 + hashMap.put("token", token); + // 设置响应数据 + responseData.setData(hashMap); + } else { +// 用户账号密码错误 + // 设置响应消息 + responseData.setCode("500"); + // 设置响应状态码 + responseData.setMessage("账号或密码错误"); + } + } else { + // 管理员登录逻辑 + Admin admin = adminServiceImpl.login(username, password); + if (admin != null && admin.getAccount() != null) { + // 根据管理员权限级别生成不同令牌 + String token; + if (admin.getPromise() == 1) { + // 超级管理员 + Token token2 = new Token(admin.getId(), 2); + // 生成JWT + token = JwtUtil.createJWT(token2); + // 设置会话属性 + session.setAttribute("ROLE", "superadmin"); + } else { + // 普通管理员 + token = JwtUtil.createJWT(new Token(admin.getId(), 1)); + // 设置会话属性 + session.setAttribute("ROLE", "admin"); + } + // 设置会话属性 + session.setAttribute("USERNAME", admin.getName()); + // 构建响应数据 + HashMap hashMap = new HashMap<>(); + // 将令牌添加到响应数据中 + hashMap.put("token", token); + // 设置响应状态码和消息 + responseData.setCode("0"); + // 设置响应消息 + responseData.setMessage("登录成功"); + // 设置响应数据 + responseData.setData(hashMap); + } else { + // 管理员账号密码错误 + responseData.setCode("500"); + // 设置响应消息 + responseData.setMessage("账号或密码错误"); + } + } +// } else { +// // 验证码错误 +// responseData.setCode("500"); +// responseData.setMessage("验证码错误"); +// } + // 返回响应 + return responseData; + } + +// * 注册短信验证码API(登录前发送验证码时调用) +// * 暂时使用mock验证码, 后续需要替换为真实验证码 +// * 处理GET请求,路径为/api/register/code +// * @param phone 手机号 +// * @return 包含验证码信息的ApiResponseData对象 + + /** + * 注册短信验证码API(登录前发送验证码时调用) + * 暂时使用mock验证码, 后续需要替换为真实验证码 + * 处理GET请求,路径为/api/register/code + * + * @param phone 手机号 + * @return 包含验证码信息的ApiResponseData对象 + */ + @PostMapping("register/code") + public ApiResponseData> registerCode(@RequestBody String phone) { + ApiResponseData> responseData = new ApiResponseData<>(); + + // 调用API获取图片验证码 + SMApiResponse smApiResponse = api.sendSM(ApiService.MOCK_CAPTCHA, phone); + try { + // 获取API返回状态码 + log.info("sendsms" + smApiResponse); + } catch (Exception e) { + // 处理异常 + responseData.setCode("500"); + // 设置响应消息 + responseData.setMessage("短信验证码API异常"); + // 设置响应数据 + responseData.setData(null); + return responseData; + } + // 验证API调用是否成功 + if (smApiResponse.getCode() != null && "0".equals(smApiResponse.getCode())) { + // 构建响应数据 + responseData.setCode("0"); + // 设置响应消息 + responseData.setMessage("验证码发送成功"); + // 设置响应数据 + responseData.setData(null); + } else { + // 处理异常 + responseData.setCode("500"); + // 设置响应消息 + responseData.setMessage("短信验证码API异常"); + // 设置响应数据 + responseData.setData(null); + // 记录错误日志 + log.error("短信验证码API异常,手机号" + phone + "注册失败"); + } + // 返回响应 + return responseData; + } + +// * 注册接口 +// * 处理POST请求,路径为/api/user/register +// * @param requestData 包含手机号、密码和验证码的请求数据 +// * @return 包含注册结果的ApiResponseData对象 + + /** + * 注册接口 + * 处理POST请求,路径为/api/user/register + * + * @param requestData 包含手机号、密码和验证码的请求数据 + * @return 包含注册结果的ApiResponseData对象 + */ + @SwitchMethod(MethodSwitch.REGISTER) + @PostMapping("user/register") + public ApiResponseData> register(@RequestBody HashMap requestData) { + ApiResponseData> responseData = new ApiResponseData<>(); + // 从请求数据中获取手机号、密码和验证码 + String phone = requestData.get("phone"); + String pwd = requestData.get("password"); + +// String userVerifyCode = requestData.get("code"); + // 检查手机号是否已注册 + int exists = userServiceImpl.existsByPhone(phone); + if (exists == 0) { +// if (captcha.equals(userVerifyCode)) { + // 注册用户 + User newUser = userServiceImpl.registerByPhone(phone, pwd); + if (newUser != null) { + // 注册成功,生成JWT令牌 + HashMap hashMap = new HashMap<>(); + // 创建普通用户令牌 + String token = JwtUtil.createJWT(new Token(newUser.getId(), 0)); + // 记录调试日志 + hashMap.put("token", token); + // 设置会话属性 + responseData.setCode("0"); + // 设置响应状态码和消息 + responseData.setData(hashMap); + // 设置响应数据 + responseData.setMessage("注册成功,请在个人信息页面完成实名认证"); + // 设置响应消息 + log.info("手机号" + phone + "注册成功"); + } else { + // 注册失败 + responseData.setCode("500"); + // 设置响应消息 + responseData.setMessage("注册失败"); + // 设置响应数据 + responseData.setData(null); + // 记录错误日志 + log.info("手机号" + phone + "注册失败"); + } +// } else { +// responseData.setCode("500"); +// responseData.setMessage("验证码错误"); +// responseData.setData(null); +// logger.info("验证码错误,手机号" + phone + "注册失败"); +// } + } else { + // 手机号已注册 + responseData.setCode("500"); + // 设置响应消息 + responseData.setData(null); + // 设置响应状态码 + responseData.setMessage("该手机号已经注册"); + // 记录错误日志 + log.info("手机号已经存在"); + } + // 返回响应 + return responseData; + } + +// * 获取用户信息接口 +// * 处理GET请求,路径为/api/users/info +// * @param authorizationHeader 包含JWT令牌的请求头 +// * @return 包含用户信息的ApiResponseData对象 + + /** + * 获取用户信息接口 + * 处理GET请求,路径为/api/users/info + * + * @param authorizationHeader 包含JWT令牌的请求头 + * @return 包含用户信息的ApiResponseData对象 + */ + @GetMapping("users/info") + public ApiResponseData> userInfoRoles(@RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT令牌,获取用户信息 + ApiResponseData> responseData = new ApiResponseData<>(); + HashMap map = new HashMap<>(); + ArrayList list = new ArrayList<>(); + if (authorizationHeader != null) { + // 响应数据封装 + responseData.setCode("0"); + responseData.setMessage("获取信息成功"); + // 解析JWT令牌,获取用户信息 + Token token = JwtUtil.parseJWT(authorizationHeader); + Integer userRole; + String username = "访客"; + if (token != null) { + // 检查用户角色,添加角色到列表 + userRole = token.getUserRole(); + if (userRole == SUPER_ADMIN) { + // 超级管理员角色 + list.add("superadmin"); + } else if (userRole == ADMIN) { + // 普通管理员角色 + list.add("admin"); + } else { + // 普通用户角色 + list.add("editor"); + } + // 设置用户名 + username = token.getUsername(); + } + // 将用户名和角色列表添加到响应数据中 + map.put("username", username); + map.put("roles", list); + } else { + // 处理未提供JWT令牌的情况 + responseData.setCode("500"); + responseData.setMessage("获取信息失败"); + } + // 设置响应数据 + responseData.setData(map); + // 返回响应 + return responseData; + } +} diff --git a/src/main/java/edu/hfbu/recruit/controller/RestFulController.java b/src/main/java/edu/hfbu/recruit/controller/RestFulController.java new file mode 100644 index 0000000..49e8fb9 --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/controller/RestFulController.java @@ -0,0 +1,232 @@ +package edu.ahbvc.recruit.controller; + +import edu.ahbvc.recruit.aspect.MethodSwitch; +import edu.ahbvc.recruit.model.*; +import edu.ahbvc.recruit.model.page.*; +import edu.ahbvc.recruit.model.token.Token; +import edu.ahbvc.recruit.service.ThingServiceImpl; +import edu.ahbvc.recruit.service.UserServiceImpl; +import edu.ahbvc.recruit.util.JwtUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.HashMap; +import java.util.List; + +/** + * Restful API接口 + *

+ * 用于提供前端页面所需的接口 + *

+ * @author c215 + */ +@RestController +@RequestMapping("api") +public class RestFulController { + + /** + * 开发环境下为true, 生产环境下为false + * 本地开发环境下, 为了方便测试, 所有接口都返回模拟数据 + * 生产环境下, 所有接口都返回真实数据 + * 为了避免在生产环境下, 出现错误, 导致数据泄露, 请在生产环境下, 关闭该功能 + * 关闭方法: 将下方isDev的值改为false + */ + private final boolean isDev = false; + + /** + * 注入UserService和ThingService + * 用于获取用户信息和批次信息 + */ + private UserServiceImpl userService; + + /** + * 注入ThingService + * 用于获取批次信息 + */ + private ThingServiceImpl thingService; + + /** + * 注入UserService + * 用于获取用户信息 + * + * @param userService 用户服务 + */ + @Autowired + public void setUserService(UserServiceImpl userService) { + this.userService = userService; + } + + /** + * 注入ThingService + * 用于获取批次信息 + * + * @param thingService 批次服务 + */ + @Autowired + public void setThingService(ThingServiceImpl thingService) { + this.thingService = thingService; + } + + + /** + * 获取所有批次的{名称-id}以供前端下拉框使用 + * + * @return 批次集合{名称-id} + */ + @GetMapping("tableBatchOption") + public ApiResponseData> getBatcheOption() { + // 获取所有批次信息 + List batches = thingService.getBatchOption(); + // 封装返回数据 + HashMap map = new HashMap<>(); + // 将批次信息存入map中 + map.put("list", batches); + // 创建ApiResponseData对象, 用于封装返回数据 + ApiResponseData> responseData = new ApiResponseData<>(); + // 设置返回数据的状态码和消息 + responseData.setCode("0"); + // 设置返回数据的消息 + responseData.setMessage("获取批次数据"); + // 设置返回数据 + responseData.setData(map); + // 返回ApiResponseData对象 + return responseData; + } + + /** + * 获取岗位下拉框内容 + * + * @return 岗位集合{岗位名-id} + */ + @GetMapping("getPositionOption") + public ApiResponseData> getPositionOption() { + // 获取所有岗位信息 + List list = thingService.getPositionOption(); + // 封装返回数据 + ApiResponseData> responseData = new ApiResponseData<>(); + // 设置返回数据的状态码和消息 + HashMap map = new HashMap<>(); + // 将岗位信息存入map中 + map.put("list", list); + + if (list != null) { + // 设置返回数据的状态码和消息 + responseData.setCode("0"); + // 设置返回数据的消息 + responseData.setMessage("获取信息成功"); + // 设置返回数据 + responseData.setData(map); + + } else { + // 设置返回数据的状态码和消息 + responseData.setCode("500"); + // 设置返回数据的消息 + responseData.setMessage("获取信息失败"); + + } + // 返回ApiResponseData对象 + return responseData; + } + + /** + * @param authorizationHeader 请求头Token + * @return 用户前台获取当前批次 + */ + @GetMapping("batchs") + public ApiResponseData> getBatches( + @RequestHeader("Authorization") String authorizationHeader) { + // 解析Token + Token user; + // 判断Token是否为空 + user = JwtUtil.parseJWT(authorizationHeader); + if (user == null) { + // 返回ApiResponseData对象 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } + // 获取当前批次信息 + int infoIntegrity = 0; + // 获取当前批次信息 + Batch batch = thingService.getCurrentBatches(); + // 获取当前用户信息 + User one = userService.getOne(user.getUserId()); + // 判断当前用户是否已经报名 + boolean alreadyRecruit = userService.alreadyRecruit(String.valueOf(user.getUserId())); + if (one.getIdNum() != null) { + // 判断当前用户是否已经填写过信息 + infoIntegrity = 1; + } + // 判断当前批次是否已经结束 + boolean disableSubmit = !MethodSwitch.isEnabled(MethodSwitch.SUBMIT); + // 封装返回数据 + HashMap map = new HashMap<>(10); + // 将批次信息存入map中 + map.put("oneBatch", batch); + // 将信息完整性存入map中 + map.put("infoIntegrity", infoIntegrity); + // 将是否已经报名存入map中 + map.put("disableRecruit", disableSubmit); + // 将是否已经报名存入map中 + map.put("alreadyRecruit", alreadyRecruit); + // 创建ApiResponseData对象, 用于封装返回数据 + ApiResponseData> responseData = new ApiResponseData<>(); + // 设置返回数据的状态码和消息 + responseData.setCode("0"); + // 设置返回数据的消息 + responseData.setMessage("获取批次数据"); + // 设置返回数据 + responseData.setData(map); + // 返回ApiResponseData对象 + return responseData; + } + + /** + * 搜索岗位 + * + * @param authorizationHeader 请求头Token + * @param requestBody 请求体 + * @return 岗位集合 + */ + @PostMapping("searchPositions") + public ApiResponseData> getPositions(@RequestBody SearchAndPageOfPositionByUser requestBody, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析Token + Token token; + token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 返回ApiResponseData对象 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } + // 获取当前批次信息 + int batchId = requestBody.getBatchId(); + // 获取当前批次信息 + int offset = 0; + // 获取当前批次信息 + int size = Integer.MAX_VALUE; +// String code = requestBody.getCode(); + // 获取当前批次信息 + int positionsNum = thingService.getPositionsNum(); + // 判断当前批次是否已经结束 + if (requestBody.getCurrentPage() >= positionsNum) { + // 返回ApiResponseData对象 + return new ApiResponseData<>("500", null, "参数异常"); + } + // 获取当前批次信息 + List positionList = thingService.getSomePosition(batchId, offset, size); + // 封装返回数据 + HashMap map = new HashMap<>(); + // 将批次信息存入map中 + map.put("list", positionList); + // 创建ApiResponseData对象, 用于封装返回数据 + ApiResponseData> responseData = new ApiResponseData<>(); + // 设置返回数据的状态码和消息 + responseData.setCode("0"); + // 设置返回数据的消息 + responseData.setMessage("获取部门数据"); + // 设置返回数据 + responseData.setData(map); + // 返回ApiResponseData对象 + return responseData; + } + +} diff --git a/src/main/java/edu/hfbu/recruit/controller/SuperAdminController.java b/src/main/java/edu/hfbu/recruit/controller/SuperAdminController.java new file mode 100644 index 0000000..9375eeb --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/controller/SuperAdminController.java @@ -0,0 +1,898 @@ +package edu.ahbvc.recruit.controller; + +// 导入各种必要的类和接口 +// 方法开关切面类,用于控制功能开关 +import edu.ahbvc.recruit.aspect.MethodSwitch; +// 导入所有模型类,包括Admin、User等 +import edu.ahbvc.recruit.model.*; +// 管理员搜索和分页参数封装类 +import edu.ahbvc.recruit.model.page.SearchAndPageOfAdmin; +// 结果搜索和分页参数封装类 +import edu.ahbvc.recruit.model.page.SearchAndPageOfResult; +// JWT令牌模型类,用于用户认证 +import edu.ahbvc.recruit.model.token.Token; +// 管理员服务实现类 +import edu.ahbvc.recruit.service.AdminServiceImpl; +// 事项服务实现类 +import edu.ahbvc.recruit.service.ThingServiceImpl; +// 用户服务实现类 +import edu.ahbvc.recruit.service.UserServiceImpl; +// JWT工具类,用于生成和解析JWT令牌 +import edu.ahbvc.recruit.util.JwtUtil; +// HTTP响应对象,用于文件下载等操作 +import jakarta.servlet.http.HttpServletResponse; +// 日志接口 +import org.slf4j.Logger; +// 日志工厂类 +import org.slf4j.LoggerFactory; +// Spring依赖注入注解 +import org.springframework.beans.factory.annotation.Autowired; +// Spring MVC注解,用于定义RESTful接口 +import org.springframework.web.bind.annotation.*; + +// 导入Java标准库类 +// IO异常类 +import java.io.IOException; +// HashMap实现类 +import java.util.HashMap; +// List接口 +import java.util.List; +// Map接口 +import java.util.Map; + +/** + * 人事负责人权限控制器 + * + * @author c215 + * 超级管理员控制器类 + * 处理需要超级管理员权限(人事负责人)的请求 + * 使用@RestController注解表示这是一个RESTful控制器 + * 使用@RequestMapping注解定义基础路径为"/api/superAdmin" + * 所有接口都需要超级管理员权限(role >= 2) + * @author c215 作者信息 + */ +@RestController +@RequestMapping("/api/superAdmin") +public class SuperAdminController { + + // 日志记录器实例,用于记录调试和错误信息 + // 使用LoggerFactory.getLogger获取指定类的日志记录器 + private static final Logger log = LoggerFactory.getLogger(SuperAdminController.class); + + // 用户服务实现类实例,用于操作用户相关业务 + // 通过@Autowired注解实现依赖注入 + private UserServiceImpl userServiceImpl; + + // 管理员服务实现类实例,用于操作管理员相关业务 + // 通过@Autowired注解实现依赖注入 + private AdminServiceImpl adminServiceImpl; + + // 事项服务实现类实例,用于操作事项相关业务 + // 通过@Autowired注解实现依赖注入 + private ThingServiceImpl thingServiceImpl; + + /** + * 设置管理员服务实现类 + * 使用@Autowired注解实现依赖注入 + * + * @param adminServiceImpl 管理员服务实现类实例 + */ + @Autowired + public void setAdminServiceImpl(AdminServiceImpl adminServiceImpl) { + // 将传入的adminServiceImpl实例赋值给当前类的adminServiceImpl字段 + this.adminServiceImpl = adminServiceImpl; + } + + /** + * 设置用户服务实现类 + * 使用@Autowired注解实现依赖注入 + * + * @param userServiceImpl 用户服务实现类实例 + */ + @Autowired + public void setUserServiceImpl(UserServiceImpl userServiceImpl) { + // 将传入的userServiceImpl实例赋值给当前类的userServiceImpl字段 + this.userServiceImpl = userServiceImpl; + } + + /** + * 设置事项服务实现类 + * 使用@Autowired注解实现依赖注入 + * + * @param thingServiceImpl 事项服务实现类实例 + */ + @Autowired + public void setThingServiceImpl(ThingServiceImpl thingServiceImpl) { + // 将传入的thingServiceImpl实例赋值给当前类的thingServiceImpl字段 + this.thingServiceImpl = thingServiceImpl; + } + +// * 获取管理员列表接口 +// * 处理POST请求,路径为/api/superAdmin/tableAdmins +// * 需要超级管理员权限(role >= 2) +// * @param requestBody 包含搜索和分页参数的请求体 +// * @param authorizationHeader 请求头中的JWT令牌 +// * @return 包含管理员列表和总数的ApiResponseData对象 + + /** + * 获取管理员列表接口 + * 处理POST请求,路径为/api/superAdmin/tableAdmins + * 需要超级管理员权限(role >= 2) + * + * @param requestBody 包含搜索和分页参数的请求体 + * @param authorizationHeader 请求头中的JWT令牌 + * @return 包含管理员列表和总数的ApiResponseData对象 + */ + @PostMapping("tableAdmins") + public ApiResponseData> getAdmins( + @RequestBody SearchAndPageOfAdmin requestBody, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT令牌,获取用户信息 + Token token = JwtUtil.parseJWT(authorizationHeader); + + // 检查令牌有效性 + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 1) { + // 用户权限不足,返回500错误 + // 缺陷:这里应该检查role >= 2而不是1 + return new ApiResponseData<>("500", null, "用户无权操作"); + } + + // 获取分页参数 + int size = requestBody.getSize(); + // 每页记录数 + int beginIndex = (requestBody.getCurrentPage() - 1) * size; + // 起始索引 + + // 获取搜索条件 + String name = requestBody.getName(); + // 管理员姓名 + String phone = requestBody.getPhone(); + // 管理员电话 + + // 调用服务层获取管理员列表 + List admins = adminServiceImpl.getAdmins(beginIndex, size, name, phone); + + // 调用服务层获取管理员总数 + int total = adminServiceImpl.getAdminsNum(name, phone); + + // 创建响应对象 + ApiResponseData> response = new ApiResponseData<>(); + // 设置成功状态码 + response.setCode("0"); + // 设置响应消息 + response.setMessage("信息"); + + // 创建数据Map,包含列表和总数 + Map data = new HashMap<>(); + // 管理员列表 + data.put("list", admins); + // 管理员总数 + data.put("total", total); + + // 将数据设置到响应对象中 + response.setData(data); + + // 返回响应对象 + return response; + } + +// * 添加管理员接口 +// * 处理POST请求,路径为/api/superAdmin/tableAdmin +// * 需要超级管理员权限(role >= 2) +// * @param admin 要添加的管理员信息 +// * @param authorizationHeader 请求头中的JWT令牌 +// * @return 包含操作结果的ApiResponseData对象 + + /** + * 添加管理员接口 + * 处理POST请求,路径为/api/superAdmin/tableAdmin + * 需要超级管理员权限(role >= 2) + * + * @param admin 要添加的管理员信息 + * @param authorizationHeader 请求头中的JWT令牌 + * @return 包含操作结果的ApiResponseData对象 + */ + @PostMapping("tableAdmin") + public ApiResponseData addAdmin(@RequestBody Admin admin, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT令牌,获取用户信息 + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 2) { + // 用户权限不足,返回500错误 + return new ApiResponseData<>("500", null, "用户无权操作"); + } + // 调用服务层添加管理员 + ApiResponseData responseData = new ApiResponseData<>(); + // 调用服务层添加管理员 + int i = adminServiceImpl.addAdmin(admin); + if (i == 1) { + // 添加成功,设置成功状态码和消息 + responseData.setCode("0"); + // 设置响应消息 + responseData.setMessage("修改成功"); + } else { + // 添加失败,设置错误状态码和消息 + responseData.setCode("500"); + // 设置响应消息 + responseData.setMessage("修改失败"); + } + // 返回响应对象 + return responseData; + } + +// * 删除管理员接口 +// * 处理DELETE请求,路径为/api/superAdmin/tableAdmin/{id} +// * 需要超级管理员权限(role >= 2) +// * @param id 要删除的管理员ID +// * @param authorizationHeader 请求头中的JWT令牌 +// * @return 包含操作结果的ApiResponseData对象 + + /** + * 删除管理员接口 + * 处理DELETE请求,路径为/api/superAdmin/tableAdmin/{id} + * 需要超级管理员权限(role >= 2) + * + * @param id 要删除的管理员ID + * @param authorizationHeader 请求头中的JWT令牌 + * @return 包含操作结果的ApiResponseData对象 + */ + @DeleteMapping("tableAdmin/{id}") + public ApiResponseData deleteAdmin(@PathVariable("id") Integer id, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT令牌,获取用户信息 + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 2) { + // 用户权限不足,返回500错误 + return new ApiResponseData<>("500", null, "用户无权操作"); + } + // 调用服务层删除管理员 + int i = adminServiceImpl.delAdmin(id); + // 创建响应对象 + ApiResponseData data = new ApiResponseData<>(); + if (i != 1) { + // 删除失败,设置错误状态码和消息 + data.setCode("500"); + data.setMessage("删除管理员失败"); + } else { + // 删除成功,设置成功状态码和消息 + data.setCode("0"); + data.setMessage("删除管理员成功"); + } + // 返回响应对象 + return data; + } + + +// * 修改管理员信息 +// * 处理PUT请求,路径为/api/superAdmin/tableAdmin +// * 需要超级管理员权限(role >= 2) +// * @param ad 管理员信息 +// * @param authorizationHeader 请求头中的JWT令牌 +// * @return 包含操作结果的ApiResponseData对象 + + /** + * 修改管理员信息 + * 处理PUT请求,路径为/api/superAdmin/tableAdmin + * 需要超级管理员权限(role >= 2) + * + * @param ad 管理员信息 + * @param authorizationHeader 请求头中的JWT令牌 + * @return 包含操作结果的ApiResponseData对象 + */ + @PutMapping("tableAdmin") + public ApiResponseData updateAdmin(@RequestBody Admin ad, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT令牌,获取用户信息 + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 2) { + // 用户权限不足,返回500错误 + return new ApiResponseData<>("500", null, "用户无权操作"); + } + // 调用服务层修改管理员信息 + int i = adminServiceImpl.updateAdmin(ad); + // 创建响应对象 + ApiResponseData responseData = new ApiResponseData<>(); + if (i == 1) { + // 修改成功,设置成功状态码 + responseData.setCode("0"); + // 设置响应消息 + responseData.setMessage("修改成功"); + } else { + // 修改失败,设置错误状态码 + responseData.setCode("500"); + // 设置响应消息 + responseData.setMessage("修改失败"); + } + // 返回响应对象 + return responseData; + } + +// * 获取用户列表 +// * 处理POST请求,路径为/api/superAdmin/tableUsers +// * 需要超级管理员权限(role >= 2) +// * @param id 用户ID +// * @param authorizationHeader 请求头中的JWT令牌 +// * @return 包含用户列表和总数的ApiResponseData对象 + + /** + * 获取用户列表 + * 处理POST请求,路径为/api/superAdmin/tableUsers + * 需要超级管理员权限(role >= 2) + * + * @param id 用户ID + * @param authorizationHeader 请求头中的JWT令牌 + * @return 包含用户列表和总数的ApiResponseData对象 + */ + @GetMapping("tableBatch/open") + public ApiResponseData batchesOpenSwitch(@RequestParam("id") Integer id, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT令牌,获取用户信息 + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 2) { + // 用户权限不足,返回500错误 + return new ApiResponseData<>("500", null, "用户无权操作"); + } + // 调用服务层获取用户列表 + ApiResponseData responseData = new ApiResponseData<>(); + // 调用服务层获取用户列表 + int batches = thingServiceImpl.switchBatchOpen(id); + if (batches != 1) { + // 获取用户列表失败,设置错误状态码和消息 + return new ApiResponseData<>("500", null, "切换失败"); + } + // 设置成功状态码 + responseData.setCode("0"); + // 设置响应消息 + responseData.setMessage("修改成功"); + // 返回响应对象 + return responseData; + } + + + /** + * @param requestBody 请求体 + * @return 获取普通管理员初审过招聘信息(暂时无用) + */ + @PostMapping("tableAudit") + public ApiResponseData> getAuditDataBySearch(@RequestBody SearchAndPageOfResult requestBody, + @RequestHeader("Authorization") String authorizationHeader) { + // @TODO 未开发完成的端点 + // 解析JWT令牌,获取用户信息 + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 2) { + // 用户权限不足,返回500错误 + return new ApiResponseData<>("500", null, "用户无权操作"); + } + // 获取分页参数 + int size = requestBody.getSize(); + int beginIndex = (requestBody.getCurrentPage() - 1) * size; + // 获取搜索条件 + List batchs = requestBody.getBatches(); + // 获取搜索条件 + List jobTitles = requestBody.getJobTitles(); + // 获取搜索条件 + List status = requestBody.getStatus(); + // 调用服务层获取用户列表 + List things = thingServiceImpl.getAuditThings(beginIndex, size, jobTitles, batchs); +// int total = thingServiceImpl.getThingsNum(jobTitles, batchs, status); + // 创建响应对象 + HashMap map = new HashMap<>(); + // 将用户列表和总数存入响应对象中 + map.put("list", things); + // 将用户列表和总数存入响应对象中 + map.put("total", 99); + // 创建响应对象 + ApiResponseData> responseData = new ApiResponseData<>(); + if (things != null) { + // 设置成功状态码 + responseData.setCode("0"); + // 设置响应消息 + responseData.setMessage("获取招聘信息成功"); + // 将用户列表和总数存入响应对象中 + responseData.setData(map); + } else { + // 获取用户列表失败,设置错误状态码 + responseData.setCode("500"); + // 设置响应消息 + responseData.setMessage("获取招聘信息失败"); + } + // 返回响应对象 + return responseData; + } + +// * 超级管理员复审不通过 +// * @param requestBody 请求体 +// * @param authorizationHeader 请求头中的JWT令牌 +// * @return 包含响应信息的 ApiResponseData对象 + + /** + * 超级管理员复审不通过 + * + * @param requestBody 请求体 + * @param authorizationHeader 请求头中的JWT令牌 + * @return 包含响应信息的 ApiResponseData对象 + */ + @PostMapping("refuse2") + public ApiResponseData refuse2(@RequestBody RefuseDataMap requestBody, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT令牌,获取用户信息 + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 2) { + // 用户权限不足,返回500错误 + return new ApiResponseData<>("500", null, "无权操作"); + } + // 调用服务层获取用户列表 + int i = thingServiceImpl.refuseThing(requestBody.getThingId(), -2, requestBody.getQualificationResult()); + // 创建响应对象 + ApiResponseData responseData = new ApiResponseData<>(); + if (i == 1) { + // 设置成功状态码 + responseData.setCode("0"); + // 设置响应消息 + responseData.setMessage("操作成功"); + } else { + // 获取用户列表失败,设置错误状态码 + responseData.setCode("500"); + // 设置响应消息 + responseData.setMessage("操作失败"); + } + // 返回响应对象 + return responseData; + } + +// * 超级管理员复审通过 +// * @param requestBody 请求体 +// * @param authorizationHeader 请求头中的JWT令牌 +// * @return 包含响应信息的 ApiResponseData对象 + + /** + * 超级管理员复审通过 + * + * @param map 请求体 请求参数 + * @param authorizationHeader 请求头中的JWT令牌 + * @return 包含响应信息的 ApiResponseData对象 + */ + @PostMapping("accept2") + public ApiResponseData agree2(@RequestBody HashMap map, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT令牌,获取用户信息 + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 2) { + // 用户权限不足,返回500错误 + return new ApiResponseData<>("500", null, "无权操作"); + } + // 调用服务层获取用户列表 + int i = thingServiceImpl.updateThingStatus(Integer.parseInt(map.get("thingId")), 2); + // 创建响应对象 + thingServiceImpl.updateThingInfo(Integer.parseInt(map.get("thingId")), map.get("qualificationResult")); + // 创建响应对象 + ApiResponseData responseData = new ApiResponseData<>(); + if (i == 1) { + // 设置成功状态码 + responseData.setCode("0"); + // 设置响应消息 + responseData.setMessage("批准成功"); + } else { + // 获取用户列表失败,设置错误状态码 + responseData.setCode("500"); + // 设置响应消息 + responseData.setMessage("批准失败"); + } + // 返回响应对象 + return responseData; + } + +// * 管理员修改用户密码 +// * @param id 要修改的用户的id +// * @param authorizationHeader 用户权限(token) +// * @return 管理员修改用户密码 + + /** + * 管理员修改用户密码 + * + * @param id 要修改的用户的id + * @param authorizationHeader 用户权限(token) + * @return 管理员修改用户密码 + */ + @GetMapping("userNewPwd") + public ApiResponseData setUserPwd(@RequestParam Integer id, + @RequestHeader("Authorization") String authorizationHeader) { + // 解析JWT令牌,获取用户信息 + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 2) { + // 用户权限不足,返回500错误 + return new ApiResponseData<>("500", null, "接口权限异常"); + } + // 调用服务层获取用户列表 + int num = userServiceImpl.updateUserPwd(id, "12345678"); + // 创建响应对象 + ApiResponseData responseData = new ApiResponseData<>(); + if (num == 1) { + // 设置成功状态码 + responseData.setCode("0"); + // 设置响应消息 + responseData.setMessage("用户密码修改成功"); + } else { + // 获取用户列表失败,设置错误状态码 + responseData.setCode("500"); + // 设置响应消息 + responseData.setMessage("用户密码修改异常"); + } + // 返回响应对象 + return responseData; + } + +// * 获取批次列表 +// * @param data 请求体 +// * @param authorizationHeader 用户权限(token) +// * @return 批次列表 + + /** + * 获取批次列表 + * + * @param data 请求体 + * @param authorizationHeader 用户权限(token) + * @return 批次列表 + */ + @PostMapping("switch/register") + public ApiResponseData switchRegister(@RequestBody SwitchMethodStatus data, + @RequestHeader("Authorization") String authorizationHeader) { + // 解析JWT令牌,获取用户信息 + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } + if (token.getUserRole() < 2) { + // 用户权限不足,返回500错误 + return new ApiResponseData<>("500", null, "用户权限异常"); + } + + // 创建响应对象 + ApiResponseData responseData = new ApiResponseData<>(); +// 1是启用,0是禁用 + if (data.getOpen() == 0) { + // 调用服务层设置开关 + log.warn("关闭注册功能"); + MethodSwitch.setSwitch(MethodSwitch.REGISTER, false); + } else { + // 调用服务层设置开关 + log.warn("启用注册功能"); + MethodSwitch.setSwitch(MethodSwitch.REGISTER, true); + } + // 设置成功状态码 + responseData.setCode("0"); + // 设置响应消息 + responseData.setMessage("操作成功"); + // 返回响应对象 + return responseData; + } + +// * 修改投递功能开关状态 +// * @param data 请求体 +// * @param authorizationHeader 用户权限(token) +// * @return 包含响应信息的 ApiResponseData对象 + + /** + * 修改投递功能开关状态 + * + * @param data 请求体 + * @param authorizationHeader 用户权限(token) + * @return 包含响应信息的 ApiResponseData对象 + */ + @PostMapping("switch/submit") + public ApiResponseData switchSubmit(@RequestBody SwitchMethodStatus data, + @RequestHeader("Authorization") String authorizationHeader) { + // 解析JWT令牌,获取用户信息 + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } + if (token.getUserRole() < 2) { + // 用户权限不足,返回500错误 + return new ApiResponseData<>("500", null, "用户权限异常"); + } + + // 创建响应对象 + ApiResponseData responseData = new ApiResponseData<>(); + if (data.getOpen() == 0) { + // 调用服务层设置开关 + log.warn("关闭用户投递功能"); + MethodSwitch.setSwitch(MethodSwitch.SUBMIT, false); + } else { + // 调用服务层设置开关 + log.warn("启用用户投递功能"); + MethodSwitch.setSwitch(MethodSwitch.SUBMIT, true); + } + // 设置成功状态码 + responseData.setCode("0"); + // 设置响应消息 + responseData.setMessage("操作成功"); + // 返回响应对象 + return responseData; + } + +// * 修改重新投递功能开关状态 +// * @param data 请求体 +// * @param authorizationHeader 用户权限(token) +// * @return 包含响应信息的 ApiResponseData对象 + + /** + * 修改重新投递功能开关状态 + * + * @param data 请求体 + * @param authorizationHeader 用户权限(token) + * @return 包含响应信息的 ApiResponseData对象 + */ + @PostMapping("switch/resubmit") + public ApiResponseData switchReSubmit(@RequestBody SwitchMethodStatus data, + @RequestHeader("Authorization") String authorizationHeader) { + // 解析JWT令牌,获取用户信息 + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } + if (token.getUserRole() < 2) { + // 用户权限不足,返回500错误 + return new ApiResponseData<>("500", null, "用户权限异常"); + } + + // 创建响应对象 + ApiResponseData responseData = new ApiResponseData<>(); + if (data.getOpen() == 0) { + // 调用服务层设置开关 + log.warn("关闭重新投递功能"); + MethodSwitch.setSwitch(MethodSwitch.TRY_SUBMIT, false); + } else { + // 调用服务层设置开关 + log.warn("启用重新投递功能"); + MethodSwitch.setSwitch(MethodSwitch.TRY_SUBMIT, true); + } + // 设置成功状态码 + responseData.setCode("0"); + // 设置响应消息 + responseData.setMessage("操作成功"); + // 返回响应对象 + return responseData; + } + +// * 设置放弃功能开关状态 +// * @param data 请求体 +// * @param authorizationHeader 用户权限(token) +// * @return 包含响应信息的 ApiResponseData对象 + + /** + * 设置放弃功能开关状态 + * + * @param data 请求体 + * @param authorizationHeader 用户权限(token) + * @return 包含响应信息的 ApiResponseData对象 + */ + @PostMapping("switch/abandon") + public ApiResponseData switchAbandon(@RequestBody SwitchMethodStatus data, + @RequestHeader("Authorization") String authorizationHeader) { + // 解析JWT令牌,获取用户信息 + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } + if (token.getUserRole() < 2) { + // 用户权限不足,返回500错误 + return new ApiResponseData<>("500", null, "用户权限异常"); + } + // 创建响应对象 + ApiResponseData responseData = new ApiResponseData<>(); + // 0是关闭,1是启用 + if (data.getOpen() == 0) { + // 调用服务层设置开关 + log.warn("关闭放弃功能"); + MethodSwitch.setSwitch(MethodSwitch.ABANDON, false); + } else { + // 调用服务层设置开关 + log.warn("启用放弃功能"); + MethodSwitch.setSwitch(MethodSwitch.ABANDON, true); + } + // 设置成功状态码 + responseData.setCode("0"); + // 设置响应消息 + responseData.setMessage("操作成功"); + // 返回响应对象 + return responseData; + } + +// * 判断是否已经打印过准考证 +// * @param id 投递的id(thing-user表的主键) +// * @param authorizationHeader 请求头token,jwt +// * @return 包含响应信息的 ApiResponseData对象 + + /** + * 判断是否已经打印过准考证 + * + * @param id 投递的id(thing-user表的主键) + * @param authorizationHeader 请求头token,jwt + * @return 包含响应信息的 ApiResponseData对象 + */ + @GetMapping("isPrinted") + public ApiResponseData> canPreviewAdmissionTicket( + @RequestParam("id") Integer id, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT令牌,获取用户信息 + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 2) { + // 用户权限不足,返回500错误 + return new ApiResponseData<>("500", null, "用户无权操作"); + } + // 创建响应对象 + ApiResponseData> responseData = new ApiResponseData<>(); + // 判断是否已经打印过准考证 + boolean printed = thingServiceImpl.isPrintedTicket(id); + if (printed) { + // 设置成功状态码 + responseData.setCode("200"); + // 设置响应消息 + responseData.setMessage("已经打印过此准考证"); + // 设置响应数据 + responseData.setData(null); + // 返回响应对象 + return responseData; + } else { + // 设置成功状态码 + responseData.setCode("0"); + // 设置响应消息 + responseData.setData(null); + // 设置响应数据 + return responseData; + } + } + +// * 预览准考证 +// * @param thingId 投递的岗位的id(thing表的主键) +// * @param recruitId 投递的id(thing-user表的主键) +// * @param response 写入响应文件 +// * @param authorizationHeader 请求头token,jwt +// * @return 响应体 + + /** + * 预览准考证 + * + * @param thingId 投递的岗位的id(thing表的主键) + * @param recruitId 投递的id(thing-user表的主键) + * @param response 写入响应文件 + * @param authorizationHeader 请求头token,jwt + * @return 响应体 + */ + @GetMapping("previewTicket") + public ApiResponseData> previewAdmissionTicket( + @RequestParam Integer thingId, @RequestParam Integer recruitId, + HttpServletResponse response, @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT令牌,获取用户信息 + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 2) { + // 用户权限不足,返回500错误 + return new ApiResponseData<>("500", null, "用户无权操作"); + } + + // 声明响应对象 + ApiResponseData> responseData = new ApiResponseData<>(); + if (thingId == null) { + // 设置成功状态码 + responseData.setCode("500"); + // 设置响应消息 + responseData.setMessage("参数异常"); + // 设置响应数据 + responseData.setData(null); + // 返回响应对象 + return responseData; + } + // 获取在服务器端生成准考证文件地址 + String path = thingServiceImpl.previewTicket(thingId, recruitId); + try { + // 将文件写入响应 + UserServiceImpl.writeFileToResponse(false, path, response); + } catch (IOException e) { + log.error("保存准考证时发生IO异常"); + } + // 文件直接写入响应流中,无需返回数据 + return null; + } + +// * 导出总表 +// * @param authorizationHeader 请求头token +// * @param response 响应 +// * @return 用户导出资格审查表 导出总表 + + /** + * 导出总表 + * + * @param authorizationHeader 请求头token + * @param response 响应 + * @return 用户导出资格审查表 导出总表 + */ + @GetMapping("excel") + public ApiResponseData adminExportExcel( + @RequestHeader("Authorization") String authorizationHeader, + HttpServletResponse response) { + // 解析JWT令牌,获取用户信息 + ApiResponseData responseData = new ApiResponseData<>(); + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() < 2) { + // 用户权限不足,返回500错误 + return new ApiResponseData<>("500", null, "接口权限异常"); + } + + // 调用服务层获取文件地址 + String outPutExcel = thingServiceImpl.outPutExcel(); + // 检查文件路径和文件是否存在 + if (outPutExcel == null) { + // 文件不存在,返回错误信息或跳转到错误页面 + responseData.setCode("500"); + // 设置响应消息 + responseData.setMessage("导出失败"); + // 设置响应数据 + return responseData; + } + try { + // 将文件写入响应 + UserServiceImpl.writeFileToResponse(true, outPutExcel, response); + } catch (IOException e) { + // 处理文件写入异常 + log.error("导出总表时出现IO异常"); + // 返回错误信息或跳转到错误页面 + responseData.setCode("500"); + // 设置响应消息 + responseData.setMessage("导出总表时出现IO异常"); + // 设置响应数据 + return responseData; + } + // 文件直接写入响应流中,无需返回数据 + return responseData; + } +} diff --git a/src/main/java/edu/hfbu/recruit/controller/UserController.java b/src/main/java/edu/hfbu/recruit/controller/UserController.java new file mode 100644 index 0000000..7034c68 --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/controller/UserController.java @@ -0,0 +1,1084 @@ +package edu.ahbvc.recruit.controller; + +// 导入必要的包和类 +import edu.ahbvc.recruit.aspect.MethodSwitch; +import edu.ahbvc.recruit.model.ApiResponseData; +import edu.ahbvc.recruit.model.Thing; +import edu.ahbvc.recruit.model.ThingWithUser; +import edu.ahbvc.recruit.model.User; +import edu.ahbvc.recruit.model.resume.*; +import edu.ahbvc.recruit.model.token.Token; +import edu.ahbvc.recruit.service.ThingServiceImpl; +import edu.ahbvc.recruit.service.UserServiceImpl; +import edu.ahbvc.recruit.util.JwtUtil; +import edu.ahbvc.recruit.util.file.FilePatch; +import edu.ahbvc.recruit.util.file.FilePathModel; +import edu.ahbvc.recruit.util.file.UserQualificationsCreator; +import jakarta.servlet.http.HttpServletResponse; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +/** + * @author c215 + * + * UserController 类 - 处理用户相关操作的控制器 + * 提供用户信息管理、简历投递、文件上传等功能的API接口 + */ +@RestController // 标识这是一个RESTful控制器 +@RequestMapping("api") // 设置基础路径为/api +public class UserController { + // 使用Log4j2进行日志记录 + private static final Logger logger = LogManager.getLogger(UserController.class); + + /** + * 系统上下文物理地址 + * 问题:当前为空字符串,可能导致文件保存路径问题 + * 建议:应该从配置文件中读取或设置为实际物理路径 + */ + private final String contextPath = ""; + + // 用户服务实现类 + private UserServiceImpl userServiceImpl; + // 岗位服务实现类 + private ThingServiceImpl thingServiceImpl; + + /** + * 设置用户服务实现类 + * @param userServiceImpl 用户服务实现类实例 + */ + @Autowired // 自动注入依赖 + public void setUserServiceImpl(UserServiceImpl userServiceImpl) { + this.userServiceImpl = userServiceImpl; + } + + /** + * 设置岗位服务实现类 + * @param thingServiceImpl 岗位服务实现类实例 + */ + @Autowired // 自动注入依赖 + public void setThingServiceImpl(ThingServiceImpl thingServiceImpl) { + this.thingServiceImpl = thingServiceImpl; + } + + /** + * 获取当前用户投递的岗位 + * @param authorizationHeader 包含JWT令牌的请求头 + * @return 包含用户投递岗位列表的ApiResponseData对象 + */ + @GetMapping("userAboutThing") // 处理GET请求,路径为/api/userAboutThing + public ApiResponseData> showThingAboutUser( + @RequestHeader("Authorization") String authorizationHeader) { + + Token token; + // 解析JWT令牌 + token = JwtUtil.parseJWT(authorizationHeader); + // 检查令牌有效性 + if (token == null) { + // 令牌无效或过期,返回401未授权错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } + // 通过用户ID获取投递的岗位列表 + List list = thingServiceImpl.getThingAboutUser(token.getUserId()); + // 创建响应对象 + ApiResponseData> responseData = new ApiResponseData<>(); + responseData.setCode("0"); + // 设置响应消息 + responseData.setMessage("获取用户投递信息成功"); + // 设置响应数据 + responseData.setData(list); + return responseData; + } + + /** + * 用户提交简历(POST方式) + * 问题:方法名userSubmit2不够明确,建议改为submitResume或类似更具描述性的名称 + * @param requestBody 包含用户简历信息的请求体 + * @param authorizationHeader 包含JWT令牌的请求头 + * @return 操作结果的ApiResponseData对象 + */ + @PostMapping("submit") // 处理POST请求,路径为/api/submit + public ApiResponseData userSubmit2(@RequestBody UserResume requestBody, + @RequestHeader("Authorization")String authorizationHeader) { + + // 解析JWT令牌 + Token token = JwtUtil.parseJWT(authorizationHeader); + // 检查令牌有效性 + if (token == null) { + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() > 0) { + // 用户权限不足,返回500错误 + return new ApiResponseData<>("500", null, "接口权限异常"); + } + // 获取用户ID + Integer userId = token.getUserId(); + // 获取招聘ID + int recruitId = requestBody.getRecruitId(); + + // 清除用户之前的简历信息 + userServiceImpl.delUserResumeAllData(userId); + + // 读取请求参数 + UserInfo info = requestBody.getInfo(); + // 设置用户ID + info.setId(userId); + // 获取教育经历 + ArrayList education = requestBody.getEducation(); + // 获取工作经历 + ArrayList workExperience = requestBody.getWorkExperience(); + // 创建响应对象 + ApiResponseData responseData = new ApiResponseData<>(); + + // 获取论文和项目信息 + ArrayList paper = requestBody.getPaper(); + ArrayList project = requestBody.getProject(); + // 添加论文信息 + userServiceImpl.addPaper(userId, paper); + // 添加项目信息 + userServiceImpl.addProject(userId, project); + + // 获取其他表单数据 + ArrayList research = requestBody.getResearch(); + String awardsAndPunishments = requestBody.getAwardsAndPunishments(); + ArrayList family = requestBody.getFamily(); + String note = requestBody.getNote(); + + // 检查用户是否已经投递过岗位 + boolean alreadyRecruit = userServiceImpl.alreadyRecruit(String.valueOf(userId)); + if (alreadyRecruit) { + responseData.setCode("500"); + responseData.setMessage("只能投递一个岗位"); + responseData.setData(null); + return responseData; + } + + // 提交岗位申请 + int applyJob = userServiceImpl.applyJob2(token.getUserId(), recruitId, awardsAndPunishments, note); + if (applyJob == 2) { + responseData.setCode("500"); + responseData.setMessage("已经投递过此岗位"); + responseData.setData(null); + return responseData; + } + + // 添加研究经历和家庭关系 + userServiceImpl.addResearch(userId, research); + userServiceImpl.addFamilyConnections(userId, family); + + // 更新用户信息到数据库 + userServiceImpl.updateUser(info); + userServiceImpl.addEducation(userId, education); + userServiceImpl.addWorkExperience(userId, workExperience); + + // 设置成功响应 + responseData.setCode("0"); + responseData.setMessage("成功"); + responseData.setData(null); + return responseData; + } + + /** + * 用户提交简历(PUT方式) + * 问题:与userSubmit2功能相似,建议统一处理逻辑 + * @param requestBody 包含用户简历信息的请求体 + * @param authorizationHeader 包含JWT令牌的请求头 + * @return 操作结果的ApiResponseData对象 + */ + // 处理PUT请求,路径为/api/submit + @PutMapping("submit") + public ApiResponseData userSubmit(@RequestBody UserResume requestBody, + @RequestHeader("Authorization") String authorizationHeader) { + // 解析JWT令牌 + Token token = JwtUtil.parseJWT(authorizationHeader); + // 检查令牌有效性 + if (token == null) { + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() > 0) { + return new ApiResponseData<>("500", null, "接口权限异常"); + } + // 获取岗位ID + int thingId = requestBody.getThingId(); + // 创建岗位对象 + Thing oneThing = new Thing(); + oneThing.setThingId(thingId); + // 创建响应对象 + ApiResponseData responseData = new ApiResponseData<>(); + // 获取各种简历信息 + ArrayList research = requestBody.getResearch(); + String awardsAndPunishments = requestBody.getAwardsAndPunishments(); + ArrayList family = requestBody.getFamily(); + String note = requestBody.getNote(); + String qualificationResult = requestBody.getQualificationResult(); + // 更新岗位信息 + thingServiceImpl.updateThingInfo(oneThing.getThingId(), awardsAndPunishments, note, qualificationResult); + // 获取用户ID + Integer userId = token.getUserId(); + /* 待实现 信息填入 功能和 信息覆盖 功能 */ + logger.info("上传资料:userId:{}\n{}", userId, requestBody); + + // 将岗位与用户关联 + int applyJob = userServiceImpl.reTryJob(userId, thingId); + if (applyJob != 1) { + responseData.setCode("500"); + responseData.setMessage("请求异常"); + responseData.setData(null); + return responseData; + } + // 设置成功响应 + responseData.setCode("0"); + responseData.setMessage("成功"); + responseData.setData(""); + return responseData; + } + + + /** + * 用户提交资历文件 + * @param part 文件在简历中的位置标识(1-6分别代表不同部分) + * @param code 对应的岗位代码,用于文件分类存储 + * @param files 用户上传的MultipartFile文件对象 + * @param authorizationHeader 包含JWT令牌的Authorization请求头 + * @return 包含操作结果的ApiResponseData对象 + */ + @PostMapping("userResume") + public ApiResponseData userSubmitFile(@RequestParam Integer part, @RequestParam String code, + @RequestPart("file") MultipartFile files, + @RequestHeader("Authorization") String authorizationHeader) { + // 记录接收文件的日志 + logger.info("接收文件,part=" + part); + + // 解析JWT令牌验证用户身份 + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效返回401错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() > 0) { + // 权限不足返回500错误 + return new ApiResponseData<>("500", null, "接口权限异常"); + } + + // 获取用户ID + Integer userId = token.getUserId(); + // 调用文件服务保存文件 + String savedPath = FilePatch.setFile(contextPath, code, userId, part, false, files); + + // 创建并返回成功响应 + ApiResponseData responseData = new ApiResponseData<>(); + responseData.setCode("0"); + responseData.setMessage("接收成功"); + responseData.setData(""); + return responseData; + } + + /** + * 用户提交身份证照片 + * 问题:缺少文件类型和大小校验,存在安全风险 + * @param files 用户上传的身份证照片文件 + * @param authorizationHeader 包含JWT令牌的Authorization请求头 + * @return 包含操作结果的ApiResponseData对象 + */ + @PostMapping("userResume/idnum") + public ApiResponseData userSubmitIdNumPhoto(@RequestPart("file") MultipartFile files, + @RequestHeader("Authorization") String authorizationHeader) { + // 解析JWT令牌验证用户身份 + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() > 0) { + return new ApiResponseData<>("500", null, "接口权限异常"); + } + + // 获取用户ID + Integer userId = token.getUserId(); + // 保存身份证照片文件,part=0表示身份证照片 + String savedPath = FilePatch.setFile(contextPath, "", userId, 0, true, files); + + // 创建并返回成功响应 + ApiResponseData responseData = new ApiResponseData<>(); + responseData.setCode("0"); + responseData.setMessage("接收成功"); + responseData.setData(""); + return responseData; + } + + + /** + * 用户提交简历(简化版) + * 问题:与POST方式的submit功能重复,建议合并 + * @param authorizationHeader 包含JWT令牌的Authorization请求头 + * @param id 岗位ID + * @return 包含操作结果的ApiResponseData对象 + */ + @GetMapping("submit") + public ApiResponseData userSubmit(@RequestHeader("Authorization") String authorizationHeader, + @RequestParam("recruitId") Integer id) { + // 解析JWT令牌验证用户身份 + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() > 0) { + return new ApiResponseData<>("500", null, "接口权限异常"); + } + + // 调用服务层提交岗位申请 + int i = userServiceImpl.applyJob(token.getUserId(), id); + + // 根据返回结果设置不同响应 + ApiResponseData responseData; + if (i == 1) { + responseData = new ApiResponseData<>("0", null, "投递成功"); + } else if (i == 2) { + responseData = new ApiResponseData<>("500", null, "已经投递过此岗位"); + } else { + responseData = new ApiResponseData<>("500", null, "投递失败"); + } + return responseData; + } + + /** + * 用户放弃已投递的岗位 + * 问题:缺少对岗位存在性和用户关联性的校验 + * @param authorizationHeader 包含JWT令牌的Authorization请求头 + * @param id 要放弃的岗位ID + * @return 包含操作结果的ApiResponseData对象 + */ + @GetMapping("abandon") + public ApiResponseData userAbandon(@RequestHeader("Authorization") String authorizationHeader, + @RequestParam("id") Integer id) { + // 解析JWT令牌验证用户身份 + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效返回401错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } + + // 创建响应对象 + ApiResponseData responseData = new ApiResponseData<>(); + if (id != null) { + // 调用服务层放弃岗位 + int i = userServiceImpl.abandon(token.getUserId(), id); + if (i == 1) { + // 设置成功响应 + responseData.setCode("0"); + // 设置成功消息 + responseData.setMessage("删除成功"); + } else if (i != 0) { + // 设置错误响应 + responseData.setCode("500"); + responseData.setMessage("系统异常"); + } else { + // 设置未找到响应 + responseData.setCode("500"); + responseData.setMessage("未投递该岗位"); + } + } else { + // 参数为空返回错误 + responseData.setCode("500"); + responseData.setMessage("请求异常"); + } + // 返回响应对象 + return responseData; + } + + /** + * 获取用户的个人信息 + * @param authorizationHeader 用户token + * @return 获取用户基本信息 + */ + @GetMapping("userInfo") + public ApiResponseData> getuserinfo( + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT令牌验证用户身份 + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效返回401错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() > 0) { + // 权限不足返回500错误 + return new ApiResponseData<>("500", null, "接口权限异常"); + } + // 获取用户ID + User i = userServiceImpl.getOne(token.getUserId()); + // 设置成功响应 + boolean alreadyRecruit = userServiceImpl.alreadyRecruit(String.valueOf(token.getUserId())); + // 创建响应对象 + ApiResponseData> responseData = new ApiResponseData<>(); + // 封装返回数据 + HashMap hashMap = new HashMap<>(); + // 将用户信息存入map中 + hashMap.put("user", i); + // 将是否已经投递过岗位信息存入map中 + hashMap.put("canEdit", !alreadyRecruit); + // 根据用户信息设置不同响应 + if (i != null) { + // 设置成功响应码 + responseData.setCode("0"); + // 设置成功消息 + responseData.setMessage("用户信息获取成功"); + // 设置返回数据 + responseData.setData(hashMap); + } else { + // 设置错误响应码 + responseData.setCode("500"); + // 设置错误消息 + responseData.setMessage("用户信息获取失败"); + } + // 返回响应对象 + return responseData; + } + +// * 用户修改密码 +// * @param map 旧密码和新密码 +// * @param authorizationHeader 用户token +// * @return 操作结果 + /** + * 用户修改密码 + * @param map 旧密码和新密码 + * @param authorizationHeader 用户token + * @return 操作结果 + */ + @PostMapping("user/pwd") + public ApiResponseData setuserPwdByUser(@RequestBody HashMap map, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT令牌验证用户身份 + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效返回401错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } else if (token.getUserRole() > 1) { + // 权限不足返回500错误 + return new ApiResponseData<>("500", null, "接口权限异常"); + } + // 获取用户ID + int userid = token.getUserId(); + // 获取旧密码 + int num = userServiceImpl.updateUserPwdByOld(userid, map.get("oldPwd"), map.get("newPwd")); + // 创建响应对象 + ApiResponseData responseData = new ApiResponseData<>(); + if (num == 1) { + // 设置成功响应码 + responseData.setCode("0"); + // 设置成功消息 + responseData.setMessage("密码修改成功"); + } else { + // 设置错误响应码 + responseData.setCode("500"); + // 设置错误消息 + responseData.setMessage("旧密码不正确"); + } + // 返回响应对象 + return responseData; + } + + +// * 投递前设置(修改)用户基本信息 +// * @param user 用户信息 +// * @param authorizationHeader 用户token +// * @return 操作结果 + /** + * 投递前设置(修改)用户基本信息 + * @param user 用户信息 + * @param authorizationHeader 用户token + * @return 操作结果 + */ + @PostMapping("userInfo") + public ApiResponseData updateUserInfo(@RequestBody User user, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT令牌验证用户身份 + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效返回401错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } + // 获取用户ID + ApiResponseData responseData = new ApiResponseData<>(); + // 设置用户ID + int i = userServiceImpl.updateUser2(user); + if (i == 1) { + // 设置成功响应码 + responseData.setCode("0"); + // 设置成功消息 + responseData.setMessage("修改成功"); + } else { + // 设置错误响应码 + responseData.setCode("500"); + // 设置错误消息 + responseData.setMessage("修改失败"); + } + // 返回响应对象 + return responseData; + } + + /** + * 用户实名认证 + * @param requestData 包含姓名(name)和身份证号(idnum)的HashMap + * @param authorizationHeader 包含JWT令牌的Authorization请求头 + * @return 包含操作结果的ApiResponseData对象 + */ + @PostMapping("realName") + public ApiResponseData realName(@RequestBody HashMap requestData, + @RequestHeader("Authorization") String authorizationHeader) { + // 创建响应对象 + ApiResponseData responseData = new ApiResponseData<>(); + + // 解析JWT令牌验证用户身份 + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效返回401错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } + + // 获取用户ID + int id = token.getUserId(); + // 从请求数据中获取姓名 + String name = requestData.get("name"); + // 从请求数据中获取身份证号 + String idnum = requestData.get("idnum"); + + // 调用服务层更新实名信息 + int i = userServiceImpl.updateRealName(id, idnum, name); + + // 根据返回结果设置不同响应 + if (i == 1) { + // 设置成功响应码 + responseData.setCode("0"); + // 设置成功消息 + responseData.setMessage("认证成功"); + } else if (i == 2) { + // 设置身份证已被注册错误 + responseData.setCode("500"); + responseData.setMessage("身份证已经被注册"); + } else { + // 设置认证失败错误 + responseData.setCode("500"); + responseData.setMessage("认证失败"); + } + // 返回响应对象 + return responseData; + } + + /** + * 文件下载:管理员获取用户上传的资历文件,返回blob,浏览器不下载 + * 问题:方法返回null不符合RESTful规范,建议返回统一响应对象 + * @param response HttpServletResponse对象用于文件下载 + * @param file 包含文件路径的FilePathModel对象 + * @param authorizationHeader 包含JWT令牌的Authorization请求头 + * @return 操作结果的ApiResponseData对象 + */ + @PostMapping("previewUserFile") + public ApiResponseData previewUserFile(HttpServletResponse response, @RequestBody FilePathModel file, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT令牌验证用户身份 + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效返回401错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } + + // 创建响应对象 + ApiResponseData responseData = new ApiResponseData<>(); + // 设置响应头信息为Word文档类型 + response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document"); + // 设置响应头指定下载文件名 + response.setHeader("Content-Disposition", "attachment; filename=userFile"); + + // 声明文件输入流 + FileInputStream fileInputStream = null; + // 声明输出流 + OutputStream outputStream = null; + + try { + // 拼接完整文件路径 + String filePath = FilePatch.SaveUserFileContextPath + file.getPath(); + // 记录文件下载日志 + logger.info("管理员获取文件:" + filePath); + // 创建文件输入流 + fileInputStream = new FileInputStream(filePath); + // 获取响应输出流 + outputStream = response.getOutputStream(); + + // 创建缓冲区 + byte[] buffer = new byte[4096]; + int bytesRead; + // 循环读取文件并写入响应流 + while ((bytesRead = fileInputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); + } + + // 刷新输出流 + outputStream.flush(); + } catch (IOException e) { + // 捕获IO异常 + responseData.setCode("500"); + responseData.setMessage("服务端异常"); + return responseData; + } finally { + // 关闭文件输入流 + if (fileInputStream != null) { + try { + fileInputStream.close(); + } catch (IOException e) { + // 忽略关闭异常 + } + } + // 关闭输出流 + if (outputStream != null) { + try { + outputStream.close(); + } catch (IOException e) { + // 忽略关闭异常 + } + } + } + // 问题:直接返回null不符合RESTful规范 + return null; + + } + + /** + * 文件下载:用户导出资格审查表 + * 问题:方法返回null不符合RESTful规范,建议返回统一响应对象 + * @param response HttpServletResponse对象用于文件下载 + * @param id 岗位ID + * @param authorizationHeader 包含JWT令牌的Authorization请求头 + * @return 操作结果的ApiResponseData对象 + */ + @GetMapping("exportForm") + public ApiResponseData exportForm(HttpServletResponse response, @RequestParam Integer id, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT令牌验证用户身份 + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效返回401错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } + + // 创建响应对象 + ApiResponseData responseData = new ApiResponseData<>(); + // 设置下载文件名 + String fileName = "EligibilityForm.docx"; + + // 获取岗位详细信息 + ThingWithUser oneThing = thingServiceImpl.getOneThing(id); + // 获取奖惩信息 + String awardsAndPunishments = oneThing.getAwardsAndPunishments(); + // 获取备注信息 + String note = oneThing.getNote(); + // 获取资格审查结果 + String qualificationResult = oneThing.getQualificationResult(); + // 获取岗位代码 + String code = oneThing.getCode(); + // 获取用户ID + int userId = oneThing.getUserId(); + + // 获取用户基本信息 + UserInfo user = userServiceImpl.getOneInfo(userId); + // 获取教育经历 + ArrayList education = userServiceImpl.getEducation(userId); + // 获取工作经历 + ArrayList workExperience = userServiceImpl.getWorkExperience(userId); + // 获取论文信息 + ArrayList paper = userServiceImpl.getPaper(userId); + // 获取项目信息 + ArrayList project = userServiceImpl.getProject(userId); + // 获取研究经历 + ArrayList research = userServiceImpl.getResearch(userId); + // 获取家庭关系 + ArrayList familyConnections = userServiceImpl.getFamilyConnections(userId); + + // 创建简历对象并填充数据 + UserResume data1 = new UserResume(); + data1.setCode(code); + data1.setInfo(user); + data1.setEducation(education); + data1.setWorkExperience(workExperience); + data1.setPaper(paper); + data1.setProject(project); + data1.setResearch(research); + data1.setAwardsAndPunishments(awardsAndPunishments); + data1.setNote(note); + data1.setQualificationResult(qualificationResult); + data1.setFamily(familyConnections); + + // 生成用户文档 + String generateUserDocument = UserQualificationsCreator.generateUserDocument(data1); + if (generateUserDocument == null) { + // 文档生成失败返回null + return null; + } + + // 设置响应头信息为Word文档类型 + response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document"); + // 设置响应头指定下载文件名 + response.setHeader("Content-Disposition", "attachment; filename=" + fileName); + + // 声明文件输入流 + FileInputStream fileInputStream = null; + // 声明输出流 + OutputStream outputStream = null; + + try { + // 记录文件地址日志 + logger.info("文件地址:" + generateUserDocument); + // 创建文件输入流 + fileInputStream = new FileInputStream(generateUserDocument); + // 获取响应输出流 + outputStream = response.getOutputStream(); + + // 创建缓冲区 + byte[] buffer = new byte[4096]; + int bytesRead; + // 循环读取文件并写入响应流 + while ((bytesRead = fileInputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); + } + + // 刷新输出流 + outputStream.flush(); + } catch (IOException e) { + // 捕获IO异常 + responseData.setCode("500"); + responseData.setMessage("服务端异常"); + return responseData; + } finally { + // 关闭文件输入流 + if (fileInputStream != null) { + try { + fileInputStream.close(); + } catch (IOException e) { + // 忽略关闭异常 + } + } + // 关闭输出流 + if (outputStream != null) { + try { + outputStream.close(); + } catch (IOException e) { + // 忽略关闭异常 + } + } + } + // 问题:直接返回null不符合RESTful规范 + return null; + } + +// * 文件下载:用户导出空白资格审查表 +// *

+// * @param response 响应对象 +// * @return 操作结果 + /** + * 文件下载:用户导出空白资格审查表 + *

+ * @param response 响应对象 + * @return 操作结果 + */ + @GetMapping("exportBlankForm") + public ApiResponseData exportBlankForm(HttpServletResponse response, + @RequestHeader("Authorization") String authorizationHeader) { + + // 解析JWT令牌验证用户身份 + Token token = JwtUtil.parseJWT(authorizationHeader); + if (token == null) { + // 令牌无效返回401错误 + return new ApiResponseData<>("401", null, "登录失效,请重新登录"); + } + // 创建响应对象 + ApiResponseData responseData = new ApiResponseData<>(); + // 下载文件的名称 + String fileName = "BlankForm.docx"; + + // 生成用户文档 + String generateUserDocument = UserQualificationsCreator.BLANK_TEMPLATE_PATH; + // 设置响应头信息 + response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document"); + response.setHeader("Content-Disposition", "attachment; filename=" + fileName); + // 获取文件输入流 + FileInputStream fileInputStream = null; + // 获取响应的输出流 + OutputStream outputStream = null; + try { + // 记录文件地址日志 + logger.info("文件地址:" + generateUserDocument); + // 创建文件输入流 + fileInputStream = new FileInputStream(generateUserDocument); + // 获取响应的输出流 + outputStream = response.getOutputStream(); + + // 将文件数据写入响应的输出流 + byte[] buffer = new byte[4096]; + // 循环读取文件数据 + int bytesRead; + // 读取文件数据并写入输出流 + while ((bytesRead = fileInputStream.read(buffer)) != -1) { + // 将读取到的数据写入输出流 + outputStream.write(buffer, 0, bytesRead); + } + + // 刷新缓冲区 + outputStream.flush(); + } catch (IOException e) { + // 捕获IO异常 + responseData.setCode("500"); + // 设置错误信息 + responseData.setMessage("服务端异常"); + // 返回错误响应 + return responseData; + } finally { + // 关闭流 + if (fileInputStream != null) { + try { + // 关闭文件输入流 + fileInputStream.close(); + } catch (IOException e) { + // 处理关闭流异常 + } + } + // 关闭流 + if (outputStream != null) { + try { + // 关闭输出流 + outputStream.close(); + } catch (IOException e) { + // 处理关闭流异常 + } + } + } + // 问题:直接返回null不符合RESTful规范 + return null; + } + +// * 用户获取投递的详细信息 +// * @param authorizationHeader 用户token +// * @param thingId 投递id +// * @return 用户获取投递的详细信息 + /** + * 用户获取投递的详细信息 + * @param authorizationHeader 用户token + * @param thingId 投递id + * @return 用户获取投递的详细信息 + */ + @GetMapping("tableThing") + public ApiResponseData> userGetThingInfo(@RequestParam("id") Integer thingId, + @RequestHeader("Authorization") String authorizationHeader) { + // 解析JWT令牌验证用户身份 + ThingWithUser oneThing = thingServiceImpl.getOneThing(thingId); + // 解析JWT令牌验证用户身份 + Token token = JwtUtil.parseJWT(authorizationHeader); + // 判断Token是否为空 + if (token != null && oneThing.getUserId() != token.getUserId()) { + // 返回ApiResponseData对象 + ApiResponseData> objectApiResponseData = new ApiResponseData<>(); + // 设置返回数据的消息 + objectApiResponseData.setData(null); + // 设置返回数据的消息 + objectApiResponseData.setMessage("权限异常"); + // 设置返回数据的消息 + objectApiResponseData.setCode("500"); + // 返回ApiResponseData对象 + return objectApiResponseData; + } + // 调用服务层获取用户投递的详细信息 + HashMap thingAndResume = userServiceImpl.getThingAndResume(oneThing); + // 判断获取的信息是否为空 + ApiResponseData> objectApiResponseData = new ApiResponseData<>(); + if (thingAndResume != null) { + // 创建ApiResponseData对象, 用于封装返回数据 + // 设置返回数据的消息 + objectApiResponseData.setData(thingAndResume); + // 设置返回数据的消息 + objectApiResponseData.setCode("0"); + // 设置返回数据的消息 + } else { + // 创建ApiResponseData对象, 用于封装返回数据 + // 设置返回数据的消息 + objectApiResponseData.setData(null); + // 设置返回数据的消息 + objectApiResponseData.setMessage("获取信息失败"); + // 设置返回数据的消息 + objectApiResponseData.setCode("500"); + // 返回ApiResponseData对象 + } + return objectApiResponseData; + } + +// * 打印准考证,在服务器端生成准考证号,并将准考证号记录到数据库中 +// * @param thingId 投递id +// * @param recruitId 岗位id +// * @return 打印准考证 + /** + * 打印准考证,在服务器端生成准考证号,并将准考证号记录到数据库中 + * @param thingId 投递id + * @param recruitId 岗位id + * @return 打印准考证 + */ + @GetMapping("print") + public ApiResponseData printAdmissionTicket( + @RequestParam Integer thingId, @RequestParam Integer recruitId) { + // 调用服务层生成准考证号 + ApiResponseData responseData = new ApiResponseData<>(); + int conformPrintTicket = thingServiceImpl.conformPrintTicket(thingId, recruitId); + // 判断生成的准考证号是否为空 + if (conformPrintTicket != 1) { + // 设置返回数据的消息 + responseData.setCode("500"); + // 设置返回数据的消息 + responseData.setData(null); + // 设置返回数据的消息 + responseData.setMessage("确认准考证号参数异常"); + // 返回ApiResponseData对象 + return responseData; + + } + // 设置返回数据的消息 + responseData.setCode("0"); + // 设置返回数据的消息 + responseData.setData(null); + // 设置返回数据的消息 + responseData.setMessage("准考证号已记录"); + // 返回ApiResponseData对象 + return responseData; + } + + /** + * @return 获取注册功能状态 + *

+ * 0:关闭 1:开启 + */ + @GetMapping("switch/register") + public ApiResponseData switchGetRegister() { + // 声明返回对象 + ApiResponseData responseData = new ApiResponseData<>(); + // 调用服务层获取注册功能状态 + boolean enableRecruit = MethodSwitch.isEnabled(MethodSwitch.REGISTER); + // 判断获取的状态是否为空 + if (enableRecruit) { + // 设置返回数据的消息 + responseData.setMessage("获取注册功能状态:开启"); + // 设置返回数据的状态码 + responseData.setCode("0"); + // 设置返回数据 + responseData.setData(1); + } else { + // 设置返回数据的消息 + responseData.setMessage("获取注册功能状态:关闭"); + // 设置返回数据的状态码 + responseData.setCode("0"); + // 设置返回数据 + responseData.setData(0); + } + // 返回ApiResponseData对象 + return responseData; + } + + /** + * + * @return 获取投递功能状态 + *

+ * 0:关闭 1:开启 + */ + @GetMapping("switch/submit") + public ApiResponseData switchGetSubmit() { + // 声明返回对象 + ApiResponseData responseData = new ApiResponseData<>(); + // 调用服务层获取投递功能状态 + boolean enableSubmit = MethodSwitch.isEnabled(MethodSwitch.SUBMIT); + // 判断获取的状态是否为空 + if (enableSubmit) { + // 设置返回数据的消息 + responseData.setMessage("获取投递功能状态:关闭"); + // 设置返回数据的状态码 + responseData.setCode("0"); + // 设置返回数据 + responseData.setData(0); + // 返回ApiResponseData对象 + responseData.setData(1); + } else { + // 设置返回数据的消息 + responseData.setMessage("获取投递功能状态:开启"); + // 设置返回数据的状态码 + responseData.setCode("0"); + // 设置返回数据 + responseData.setData(0); + } + // 返回ApiResponseData对象 + return responseData; + } + + /** + * + * @return 获取重新注册功能状态 + *

+ * 0:关闭 1:开启 + */ + @GetMapping("switch/resubmit") + public ApiResponseData switchGetReSubmit() { + // 声明返回对象 + ApiResponseData responseData = new ApiResponseData<>(); + // 调用服务层获取重新注册功能状态 + boolean enableTrySubmit = MethodSwitch.isEnabled(MethodSwitch.TRY_SUBMIT); + // 判断获取的状态是否为空 + if (enableTrySubmit) { + // 设置返回数据的消息 + responseData.setMessage("获取重新注册功能状态:开启"); + // 设置返回数据的状态码 + responseData.setCode("0"); + // 设置返回数据 + responseData.setData(0); + } else { + // 设置返回数据的消息 + responseData.setMessage("获取重新注册功能状态:关闭"); + // 设置返回数据的状态码 + responseData.setCode("0"); + // 设置返回数据 + responseData.setData(1); + } + // 返回ApiResponseData对象 + return responseData; + } + + /** + * @return 获取放弃投递功能状态 + *

+ * 0:关闭 1:开启 + */ + @GetMapping("switch/abandon") + public ApiResponseData switchGetAbandon() { + // 声明返回对象 + ApiResponseData responseData = new ApiResponseData<>(); + // 调用服务层获取放弃投递功能状态 + boolean enableAbandon = MethodSwitch.isEnabled(MethodSwitch.ABANDON); + // 判断获取的状态是否为空 + if (enableAbandon) { + // 设置返回数据的消息 + responseData.setMessage("获取放弃功能状态:开启"); + // 设置返回数据的状态码 + responseData.setCode("0"); + // 设置返回数据 + responseData.setData(0); + } else { + // 设置返回数据的消息 + responseData.setMessage("获取放弃功能状态:关闭"); + // 设置返回数据的状态码 + responseData.setCode("0"); + // 设置返回数据 + responseData.setData(1); + } + // 返回ApiResponseData对象 + return responseData; + } + +} diff --git a/src/main/java/edu/hfbu/recruit/mapper/AdminInter.java b/src/main/java/edu/hfbu/recruit/mapper/AdminInter.java new file mode 100644 index 0000000..721fed0 --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/mapper/AdminInter.java @@ -0,0 +1,124 @@ +package edu.ahbvc.recruit.mapper; + +import edu.ahbvc.recruit.model.Admin; +import org.apache.ibatis.annotations.*; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author c215 + */ +@Repository +@Mapper +public interface AdminInter { + +// * 根据id查询管理员 +// * @param id: 管理员id +// * @return 管理员(Admin) + /** + * 根据id查询管理员 + * @param id: 管理员id + * @return 管理员(Admin) + */ + @Select("select * from admin where id = #{id}") + Admin getOne(int id); + +// * 根据账号查询管理员 +// * @param account: 管理员账号(手机号) +// * @return 管理员(Admin) + /** + * 根据账号查询管理员 + * @param account: 管理员账号(手机号) + * @return 管理员(Admin) + */ + @Select("select phone from admin where phone = #{account}") + String isAdmin(String account); + +// * 管理员登录 +// * @param account: 管理员账号(手机号) +// * @param pwd: 管理员密码 +// * @return 管理员(Admin) + /** + * 管理员登录 + * @param account: 管理员账号(手机号) + * @param pwd: 管理员密码 + * @return 管理员(Admin) + */ + @Select("select * from admin where phone = #{account} and pwd = #{pwd}") + Admin login(@Param("account") String account, @Param("pwd") String pwd); + +// * 管理员分页查询 +// * @param offset: 偏移量 +// * @param size: 每页大小 +// * @param name: 管理员姓名 +// * @param phone: 管理员手机号 +// * @return 管理员列表(List) + /** + * 管理员分页查询 + * @param offset: 偏移量 + * @param size: 每页大小 + * @param name: 管理员姓名 + * @param phone: 管理员手机号 + * @return 管理员列表(List) + */ + @Select("select * from `admin`" + + " WHERE `admin`.`name` LIKE CONCAT('%',IFNULL(#{name}, ''),'%')" + + " AND `admin`.`phone` LIKE CONCAT('%',IFNULL(#{phone}, ''),'%')" + + " LIMIT #{offset}, #{size}") + List getAdmins(@Param("offset")int offset, @Param("size")int size, @Param("name")String name, @Param("phone")String phone); + +// * 管理员数量查询(配合分页查询) +// * @param name: 管理员姓名 +// * @param phone: 管理员手机号 +// * @return 符合条件的管理员数量(Integer) +// * @see edu.ahbvc.recruit.mapper.AdminInter#getAdmins + /** + * 管理员数量查询(配合分页查询) + * @param name: 管理员姓名 + * @param phone: 管理员手机号 + * @return 符合条件的管理员数量(Integer) + * @see edu.ahbvc.recruit.mapper.AdminInter#getAdmins + */ + @Select("select count(id) from `admin`" + + " WHERE `admin`.`name` LIKE CONCAT('%',IFNULL(#{name}, ''),'%')" + + " AND `admin`.`phone` LIKE CONCAT('%',IFNULL(#{phone}, ''),'%')") + Integer getAdminsNum(@Param("name")String name, @Param("phone")String phone); + +// * 添加管理员 +// * @param admin: 管理员(Admin) +// * @return 添加成功返回1,否则返回0 + /** + * 添加管理员 + * @param admin: 管理员(Admin) + * @return 添加成功返回1,否则返回0 + */ + @Insert("INSERT INTO `admin` (`name`, `account`, `pwd`, `phone`, `promise`)" + + " VALUES(#{name}, #{account}, #{pwd}, #{phone}, #{viewOnly})") + @Options(useGeneratedKeys = true, keyProperty = "id") + int addAdmin(Admin admin); + +// * 删除管理员 +// * @param id: 管理员id +// * @return 删除成功返回1,否则返回0 + /** + * 删除管理员 + * @param id: 管理员id + * @return 删除成功返回1,否则返回0 + */ + @Delete("delete from `admin` where id = #{id}") + int delAdmin(int id); + +// * 更新管理员信息 +// * @param ad: 管理员(Admin) +// * @return 更新成功返回1,否则返回0 + /** + * 更新管理员信息 + * @param ad: 管理员(Admin) + * @return 更新成功返回1,否则返回0 + */ + @Update("update `admin` set name=#{name}, account=#{account}, " + + "pwd=#{pwd}, phone=#{phone}, promise=#{viewOnly} where id = #{id}") + int updateAdmin(Admin ad); + +} diff --git a/src/main/java/edu/hfbu/recruit/mapper/ThingInter.java b/src/main/java/edu/hfbu/recruit/mapper/ThingInter.java new file mode 100644 index 0000000..d20e44a --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/mapper/ThingInter.java @@ -0,0 +1,435 @@ +package edu.ahbvc.recruit.mapper; + +import edu.ahbvc.recruit.model.Batch; +import edu.ahbvc.recruit.model.Position; +import edu.ahbvc.recruit.model.Thing; +import edu.ahbvc.recruit.model.ThingWithUser; +import edu.ahbvc.recruit.model.export.Excel; +import edu.ahbvc.recruit.model.export.Ticket; +import org.apache.ibatis.annotations.*; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.stereotype.Repository; + +import java.util.ArrayList; +import java.util.List; + +package edu.ahbvc.recruit.mapper; + +// 导入必要的模型类和注解 +import edu.ahbvc.recruit.model.Batch; +import edu.ahbvc.recruit.model.Position; +import edu.ahbvc.recruit.model.Thing; +import edu.ahbvc.recruit.model.ThingWithUser; +import edu.ahbvc.recruit.model.export.Excel; +import edu.ahbvc.recruit.model.export.Ticket; +import org.apache.ibatis.annotations.*; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.stereotype.Repository; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author c215 + * + * ThingInter 接口 - 招聘事务相关的数据库操作接口 + * 提供对招聘批次、岗位、用户投递关系等数据的CRUD操作 + */ +@Repository // 标识为Spring的Repository组件 +@Mapper // MyBatis的Mapper接口 +public interface ThingInter { + + /** + * 获取准考证数据 + * @param recruitId 招聘ID + * @param id 投递记录ID + * @return 包含准考证数据的Ticket对象 + */ + @Select("SELECT `u`.idnum, `u`.`name`, `u`.phone tel, p.`code`, " + + "CASE WHEN p.jobTitle LIKE '管%' THEN " + + "'行政部门' " + "WHEN p.jobTitle LIKE '专业%' THEN " + + "'二级学院' ELSE '其他部门'" + " END AS department ," + + "(CASE WHEN ut.ticket_num = 0 THEN " + + "(SELECT MAX(ut2.ticket_num)+1 FROM `USER-thing` AS ut2 WHERE `thingid` = #{recruitId}) " + + "ELSE ut.ticket_num END) AS ticketNumber " + + "FROM " + + "`USER-thing` AS ut " + "LEFT JOIN `batch-position` AS `bp` ON `bp`.id = ut.thingid " + + "LEFT JOIN `positions` AS p ON `p`.id = bp.positionid " + + "LEFT JOIN `USER` AS u ON ut.userid = u.id " + + "LEFT JOIN batchs ON batchs.id = bp.batchid" + " WHERE " + + "ut.id = #{id}") + Ticket getTicketData(@Param("recruitId")Integer recruitId, @Param("id")Integer id); + + /** + * 获取指定招聘的最大准考证号 + * @param recruitId 招聘ID + * @return 最大准考证号 + */ + @Select("SELECT MAX(ticket_num) FROM `user-thing` WHERE `thingid` = #{recruitId}") + int getTicketNum(Integer recruitId); + + /** + * 检查准考证是否已打印 + * @param thingid 投递记录ID + * @return 准考证号(0表示未打印) + */ + @Select("SELECT `ticket_num` FROM `user-thing` where `id`=#{thingid}") + int isPrintedTicket(Integer thingid); + + /** + * 设置准考证已打印 + * @param ticketNum 准考证号 + * @param thingId 投递记录ID + * @return 影响的行数 + */ + @Update("UPDATE `user-thing` " + + "SET `ticket_num` = #{arg0} WHERE `id` = #{arg1}") + int setTicketPrinted(Integer ticketNum, Integer thingId); + + /** + * 获取用户可投递的招聘批次信息 + * @param userid 用户ID + * @param batch 批次ID(0表示全部) + * @return 批次列表 + */ + List getthingForuser(@Param("userid") int userid, @Param("batch") int batch); + + /** + * 获取用户已投递的招聘信息 + * @param userid 用户ID + * @return 招聘信息列表 + */ + List getThingAboutUser(@Param("userid") int userid); + + /** + * 分页获取招聘信息(管理员用) + * @param currentPage 当前页 + * @param size 每页大小 + * @param jobTitles 岗位名称列表 + * @param batches 批次列表 + * @param status 状态列表 + * @param name 名称 + * @return 招聘信息列表 + */ + List getThings(@Param("currentPage") int currentPage, @Param("size") int size, + @Param("jobTitles") List jobTitles, @Param("batches") List batches, + @Param("status") List status, @Param("name") String name); + + /** + * 分页获取待审核招聘信息(超级管理员用) + * @param currentPage 当前页 + * @param size 每页大小 + * @param jobTitles 岗位名称列表 + * @param batches 批次列表 + * @return 招聘信息列表 + */ + List getAuditThings(@Param("currentPage") int currentPage, @Param("size") int size, + @Param("jobTitles") List jobTitles, @Param("batches") List batches); + + /** + * 根据ID列表获取招聘信息 + * @param id ID列表 + * @return 招聘信息列表 + */ + List getThingsById(@Param("thingId") List id); + + /** + * 获取单个招聘详细信息 + * @param thingId 招聘ID + * @return 招聘详细信息 + */ + @Select("SELECT `ut`.`id` thingId, `ut`.`status`,bp.id recruitId," + + "`ut`.`awardsAndPunishments`, `ut`.`note`, `ut`.`qualificationResult`," + + "batchs.id batchid,batchs.`name` batchname,p.id positionId, p.code, p.jobTitle," + + "u.id userId, u.`name` username" + " FROM `user-thing` AS ut" + + " LEFT JOIN `batch-position` AS `bp` ON `bp`.id = ut.thingid " + + " LEFT JOIN `positions` AS p ON `p`.id = bp.positionid" + " LEFT JOIN `user` AS u ON ut.userid = u.id " + + " LEFT JOIN batchs ON batchs.id=bp.batchid" + " WHERE ut.id = #{id}") + ThingWithUser getOneThing(@Param("id") int thingId); + + /** + * 获取未处理的招聘数量 + * @return 未处理数量 + */ + @Select("SELECT count(id) FROM `user-thing` WHERE `status` = '0' LIMIT 0,1000") + int getUnsettledThingsNum(); + + /** + * 获取招聘信息数量 + * @param jobTitles 岗位名称列表 + * @param batches 批次列表 + * @param status 状态列表 + * @param name 名称 + * @return 数量 + */ + Integer getThingsNum(@Param("jobTitles") List jobTitles, @Param("batches") List batches, + @Param("status") List status, @Param("name") String name); + + /** + * 更新招聘状态 + * @param thingid 招聘ID + * @param status 状态 + * @return 影响的行数 + */ + @Update("UPDATE `user-thing` SET `user-thing`.`status`= ${status} WHERE `user-thing`.id=${thingid}") + int updateThingStatus(@Param("thingid") int thingid, @Param("status") int status); + + /** + * 拒绝招聘申请 + * @param thingid 招聘ID + * @param status 状态 + * @param qualificationResult 资格审查结果 + * @return 影响的行数 + */ + @Update("UPDATE `user-thing` SET `user-thing`.`status`= ${status},`user-thing`.`qualificationResult` = #{qualificationResult} WHERE `user-thing`.id=${thingid}") + int refuseThing(@Param("thingid") int thingid, @Param("status") int status, + @Param("qualificationResult") String qualificationResult); + + /** + * 更新招聘信息 + * @param thingid 招聘ID + * @param awardsAndPunishments 奖惩信息 + * @param note 备注 + * @param qualificationResult 资格审查结果 + * @return 影响的行数 + */ + @Update("UPDATE `user-thing` SET " + "`user-thing`.`awardsAndPunishments`= IFNULL(#{awardsAndPunishments}, '')," + + "`user-thing`.`note`= IFNULL(#{note}, '')," + + "`user-thing`.`qualificationResult`= IFNULL(#{qualificationResult}, '')" + + "WHERE `user-thing`.id = #{thingid}") + int updateThingInfo(@Param("thingid") int thingid, + @Param("awardsAndPunishments") String awardsAndPunishments, @Param("note") String note, + @Param("qualificationResult") String qualificationResult); + + /** + * 更新资格审查结果 + * @param thingid 招聘ID + * @param qualificationResult 资格审查结果 + * @return 影响的行数 + */ + @Update("UPDATE `user-thing` SET " + + "`user-thing`.`qualificationResult`= IFNULL(#{qualificationResult}, '')" + + "WHERE `user-thing`.id = #{thingid}") + int updateThingQualification(@Param("thingid") int thingid, + @Param("qualificationResult") String qualificationResult); + + // 批次相关操作 + /** + * 获取所有批次选项 + * @return 批次列表 + */ + @Select("SELECT batchs.id,batchs.name FROM `batchs`") + List getBatchOption(); + + /** + * 获取单个批次信息 + * @param id 批次ID + * @return 批次信息 + */ + @Select("SELECT batchs.*, COUNT(positions.id) num " + "FROM `batchs` " + + "LEFT JOIN `batch-position` ON `batch-position`.batchid = batchs.id " + + "LEFT JOIN positions ON positions.id=`batch-position`.positionid " + + "GROUP BY batchs.id having batchs.id=#{id}") + Batch getBatch(int id); + + /** + * 分页获取批次列表 + * @param currentPage 当前页 + * @param size 每页大小 + * @param key 关键字 + * @param state 状态 + * @return 批次列表 + */ + List getBatches(@Param("currentPage") int currentPage, @Param("size") int size, + @Param("key") String key, @Param("state") Integer state); + + /** + * 获取当前开放的批次 + * @return 批次信息 + */ + @Select("SELECT batchs.*, COUNT(positions.id) positionNum " + "FROM `batchs` " + + "LEFT JOIN `batch-position` ON `batch-position`.batchid = batchs.id " + + "LEFT JOIN positions ON positions.id=`batch-position`.positionid " + + "GROUP BY batchs.id having batchs.open=1 LIMIT 1") + Batch getCurrentBatch(); + + /** + * 获取批次数量 + * @param key 关键字 + * @param state 状态 + * @return 数量 + */ + int getBatchesNum(@Param("key") String key, @Param("state") Integer state); + + /** + * 更新批次信息 + * @param batch 批次对象 + * @return 影响的行数 + */ + @Update("UPDATE batchs SET name = #{name},startime = #{startime}," + + "deadline = #{deadline},open = #{open}, `disableAutoUpdate`=#{disableAutoUpdate} where id = #{id}") + int updateBatch(Batch batch); + + /** + * 开启批次 + * @param id 批次ID + * @return 影响的行数 + */ + @Update("UPDATE batchs SET open = 1 where id = #{id}") + int updateBatchOpen(int id); + + /** + * 关闭所有批次 + * @return 影响的行数 + */ + @Update("UPDATE batchs SET open = 0") + int updateBatchClose(); + + /** + * 添加批次 + * @param batch 批次对象 + * @return 影响的行数 + */ + @Insert("INSERT INTO `batchs` (`open`, `name`, `disableAutoUpdate`) VALUES (#{open}, #{name}, #{disableAutoUpdate})") + int addBatch(Batch batch); + + /** + * 删除批次 + * @param id 批次ID + * @return 影响的行数 + */ + @Delete("DELETE FROM `batchs` WHERE `id` = #{id}") + int delBatch(int id); + + // 岗位相关操作 + /** + * 分页获取岗位列表 + * @param currentPage 当前页 + * @param size 每页大小 + * @return 岗位列表 + */ + List getPositions(@Param("currentPage") int currentPage, @Param("size") int size); + + /** + * 获取岗位数量 + * @return 数量 + */ + int getPositionsNum(); + + /** + * 获取岗位选项 + * @return 岗位选项列表 + */ + @Select("SELECT positions.id, CONCAT(positions.code, ' - ', positions.jobTitle) AS jobTitle FROM positions") + List getPositionOption(); + + /** + * 分页获取指定批次的岗位 + * @param batchid 批次ID + * @param offset 偏移量 + * @param size 每页大小 + * @return 岗位列表 + */ + List getSomePosition(@Param("batchid") int batchid, @Param("offset") int offset, + @Param("size") int size); + + /** + * 获取单个岗位详情 + * @param id 岗位ID + * @return 岗位详情 + */ + @Select("SELECT positions.*, COUNT(`user-thing`.userid) toll," + + " batchs.id bid,batchs.`open`, batchs.`name`, batchs.startime bstart" + + " FROM positions " + + " LEFT JOIN `user-thing` ON `user-thing`.thingid = positions.id" + + " LEFT JOIN batchs ON batchs.id = positions.batch WHERE positions.id = ${id}" + + " GROUP BY positions.id") + Position getOnePosition(int id); + + /** + * 添加岗位 + * @param p 岗位对象 + * @return 影响的行数 + */ + @Insert("INSERT INTO positions (`jobTitle`, `code`, `type`, `specialty`, `education`, `degree`, `maxAge`, `sex`, `zzmm`, `info`, `toll`, `require`) " + + "VALUES (#{jobTitle}, #{code}, #{type}, #{specialty}, #{education}, #{degree}, #{maxAge}, #{sex}, #{zzmm}, #{info}, #{toll}, #{require})") + int addPosition(Position p); + + /** + * 删除岗位 + * @param id 岗位ID + * @return 影响的行数 + */ + @Delete("DELETE FROM `positions` WHERE `id` = #{id}") + int delPosition(int id); + + /** + * 批量删除岗位 + * @param id 岗位ID列表 + * @return 影响的行数 + */ + int delPositions(@Param("id") List id); + + /** + * 更新岗位信息 + * @param p 岗位对象 + * @return 影响的行数 + */ + @Update("UPDATE `positions` SET `jobTitle` = #{jobTitle}, `code` = #{code}, `type` = #{type}, `specialty` = #{specialty}, `education` = #{education}, `degree` = #{degree}, `maxAge` = #{maxAge}, `sex` = #{sex}, `zzmm` = #{zzmm}, `info` = #{info}, `toll` = #{toll}, `require` = #{require} WHERE `id` = #{id}") + int updatePosition(Position p); + + // 招聘岗位相关操作 + /** + * 分页获取招聘岗位列表 + * @param currentPage 当前页 + * @param size 每页大小 + * @param jobTitle 岗位名称列表 + * @param batchs 批次列表 + * @return 招聘岗位列表 + */ + List getRecruits(@Param("currentPage") int currentPage, @Param("size") int size, + @Param("jobTitle") List jobTitle, @Param("batch") List batchs); + + /** + * 获取招聘岗位数量 + * @param jobTitle 岗位名称列表 + * @param batch 批次列表 + * @return 数量 + */ + int getRecruitNum(@Param("jobTitle") List jobTitle, @Param("batch") List batch); + + /** + * 添加招聘岗位 + * @param batchid 批次ID + * @param positionid 岗位ID + * @return 影响的行数 + */ + @Insert("INSERT INTO `batch-position` (`batchid`, `positionid`) VALUES (#{batchid}, #{positionid})") + int addRecruit(@Param("batchid") Integer batchid, @Param("positionid") Integer positionid); + + /** + * 更新招聘岗位 + * @param id IDm + * @param batchid 批次ID + * @param positionid 岗位ID + * @return 影响的行数 + */ + @Update("UPDATE `batch-position` SET `batchid` = #{batchid}, `positionid` = #{positionid} WHERE id = #{id}") + int updateRecruit(@Param("id") Integer id, @Param("batchid") Integer batchid, + @Param("positionid") Integer positionid); + + /** + * 删除招聘岗位 + * @param id ID + * @return 影响的行数 + */ + @Delete("DELETE FROM `batch-position` WHERE id = #{id}") + int deleteRecruit(int id); + + /** + * 获取导出总表的数据 + * @return 准备导出的Excel数据 + */ + ArrayList getPrintData(); + +} diff --git a/src/main/java/edu/hfbu/recruit/mapper/UserInter.java b/src/main/java/edu/hfbu/recruit/mapper/UserInter.java new file mode 100644 index 0000000..c0ff085 --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/mapper/UserInter.java @@ -0,0 +1,204 @@ +// 定义包路径 +package edu.ahbvc.recruit.mapper; + +// 导入所需的类 +import edu.ahbvc.recruit.model.User; +import edu.ahbvc.recruit.model.resume.*; +import org.apache.ibatis.annotations.*; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.stereotype.Repository; + +import java.util.ArrayList; +import java.util.List; + +/** + * 用户数据访问接口 + * 提供了和数据库交互的方法 + * @author c215 + */ +// 标识这是一个Spring数据访问组件 +@Repository +// MyBatis注解,标识这是一个Mapper接口 +@Mapper +public interface UserInter { + + // 根据ID查询单个用户信息 + @Select("select * from `user` where id = #{id}") + User getOne(int id); + + // 根据ID查询单个用户的基本信息 + @Select("select * from `user` where id = #{id}") + UserInfo getOneInfo(int id); + + // 分页查询用户列表,支持按姓名、身份证号、手机号模糊查询 + @Select("SELECT * FROM `user`" + " WHERE (`name` LIKE CONCAT('%', IFNULL(#{name}, ''), '%') )" + + " AND (`idnum` LIKE CONCAT('%', IFNULL(#{idnum}, ''), '%') )" + + " AND (`phone` LIKE CONCAT('%', IFNULL(#{phone}, ''), '%') )" + + " LIMIT #{offset}, #{size}") + List getUsers(@Param("offset") int offset, @Param("size") int size, @Param("name") String name, + @Param("phone") String phone, @Param("idnum") String idnum); + + // 获取符合条件的用户总数 + @Select("select COUNT(id) from `user`" + " WHERE (`name` LIKE CONCAT('%', IFNULL(#{name}, ''), '%') )" + + " AND (`idnum` LIKE CONCAT('%', IFNULL(#{idnum}, ''), '%') )" + + " AND (`phone` LIKE CONCAT('%', IFNULL(#{phone}, ''), '%') )") + int getUsersNum(@Param("name") String name, @Param("phone") String phone, @Param("idnum") String idnum, + @Param("degree") Integer degree); + + // 根据事项ID查询参与该事项的用户列表 + @Select("SELECT `user`.* FROM `user-thing` LEFT JOIN `user` ON `user`.id = `user-thing`.userid where `user-thing`.thingid = #{thingId}") + List getThingUsers(int thingId); + + // 用户登录验证,支持身份证号或手机号登录 + @Select("SELECT * FROM `user` WHERE (idnum = #{idnum} OR phone = #{idnum}) AND pwd = #{pwd}") + User login(@Param("idnum") String account, @Param("pwd") String pwd); + + // 通过手机号注册用户 + @Insert("INSERT INTO `user` (`name`, `phone`, `pwd`)" + " VALUES ('访客', #{phone}, #{pwd})") + int registerByPhone(@Param("phone") String phone, @Param("pwd") String pwd); + + // 检查身份证号是否已存在 + @Select("SELECT count(`id`) FROM `user` WHERE `user`.idnum=#{idnum}") + int exists(String idnum); + + // 检查用户是否已经参与过招聘 + @Select("SELECT count(id) FROM `user-thing` WHERE `userid` = #{arg0} AND `status` !=-2") + int alreadyRecruit(String userId); + + // 检查手机号是否已存在 + @Select("SELECT count(*) FROM `user` WHERE `user`.phone=#{phone}") + int existsByPhone(String phone); + + // 获取最新创建的用户 + @Select("SELECT * FROM `user` ORDER BY `id` DESC LIMIT 1;") + User getNewUser(); + + // 检查用户是否已申请某个招聘事项 + @Select("SELECT COUNT(id) FROM `user-thing` WHERE `userid`=#{userid} and `thingid`=#{recruitId}") + int thingExist(int userid, int recruitId); + + // 检查事项是否存在 + @Select("SELECT COUNT(id) FROM `user-thing` WHERE `id`= #{arg0}") + int thingExist2(int thingId); + + // 申请职位 + @Insert("INSERT INTO `user-thing` (`userid`, `thingid`, `time`)" + + " VALUES (#{arg0}, #{arg1}, NOW())") + int applyJob(int userid, int recruitId); + + // 申请职位(带奖惩情况和备注) + @Insert("INSERT INTO `user-thing` (`userid`, `thingid`, `time`, `awardsAndPunishments`, `note`)" + + " VALUES (#{userid}, #{recruitId}, NOW(), #{awardsAndPunishments}, #{note})") + int applyJob2(int userid, int recruitId, String awardsAndPunishments, String note); + + // 重新尝试申请职位 + @Insert("UPDATE `user-thing` set `status`=0, `qualificationResult` = NULL WHERE `id` = #{arg0}") + int reTryJob(int thingid); + + // 放弃申请 + @Delete("Delete FROM `user-thing` WHERE id = #{thingid} and userid = #{userid}") + int abandon(int thingid, int userid); + + // 添加新用户 + @Insert("INSERT INTO `user` (`name`, `sex`, `phone`, `birthPlace`, `nation`, `zzmm`, `email`," + + " `birthday`, `idnum`, `married`, `nativePlace`, `address`, `specialtiesCertificates`, `pwd`)" + + " VALUES (#{name}, #{sex}, #{phone}, #{birthPlace}, #{nation}, #{zzmm}, #{email}" + + ", #{birthday}, #{idnum}, #{married}, #{nativePlace}, #{address}, #{specialtiesCertificates}, #{pwd})") + int addUser(User u); + + // 删除用户 + @Delete("DELETE FROM `user` WHERE id = #{id}") + int delUser(int id); + + /** + * 更新指定用户实名信息 + * @param u 更新的用户信息 + * @return 更新的user数量 + *

更新身份证号码(idnum)和姓名(name)字段

+ */ + @Update("UPDATE user SET name = #{u.name}, idnum = #{u.idnum} " + "WHERE id = #{u.id}") + int updateUserName(@Param("u") User u); + + /** + * 更新用户信息(不包括身份证号、姓名和手机号) + * @param u 更新的用户信息 + * @return 更新的user数量 + */ + @Update("UPDATE user SET sex = #{u.sex}, birthPlace = #{u.birthPlace}, " + + "nation = #{u.nation}, zzmm = #{u.zzmm}, email = #{u.email}, birthday = #{u.birthday}, " + + "married = #{u.married}, nativePlace = #{u.nativePlace}, " + + "address = #{u.address}, specialtiesCertificates = #{u.specialtiesCertificates} " + "WHERE id = #{u.id}") + int updateUser2(@Param("u") User u); + + // 更新用户密码 + @Update("UPDATE user SET `pwd` = #{arg1} " + "WHERE id = #{arg0}") + int updateUserPwd(int id, String pwd); + + // 使用旧密码验证后更新密码 + @Update("UPDATE user SET `pwd` = #{arg1} " + "WHERE id = #{arg0} AND `pwd` = #{arg2}") + int updateUserPwdByOld(int id, String pwd, String oldpwd); + + /** + * 更新用户信息(不包括身份证号、姓名和手机号) + * @param u 更新的用户信息 + * @return 更新的数量 + */ + @Update("UPDATE user SET sex = #{u.sex}, birthPlace = #{u.birthPlace}, " + + "nation = #{u.nation}, zzmm = #{u.politicalStatus}, email = #{u.email}, birthday = #{u.birthday}, " + + "married = #{u.married}, nativePlace = #{u.nativePlace}, " + + "address = #{u.address}, specialtiesCertificates = #{u.specialtiesCertificates} " + "WHERE id = #{u.id}") + int updateUser(@Param("u") UserInfo u); + + // 更新用户实名信息 + @Update("UPDATE `user` SET `name` = #{name}, `idnum` = #{idnum} WHERE `id` = #{id}") + int updateRealName(@Param("id") int id, @Param("idnum") String idnum, @Param("name") String name); + + // 获取用户教育经历 + @Select("SELECT * FROM `education` WHERE id = #{userId};") + ArrayList getEducation(@Param("userId") int processedUserid); + + // 添加教育经历 + int addEducation(@Param("e")ArrayList e); + + // 获取用户工作经历 + @Select("SELECT * FROM `workexperience` WHERE id = #{userId}") + ArrayList getWorkExperience(@Param("userId") int processedUserid); + + // 添加工作经历 + int addWorkExperience(@Param("w")ArrayList w); + + // 获取用户论文信息 + @Select("SELECT * FROM Paper WHERE id = #{userId}") + ArrayList getPaper(@Param("userId") int processedUserid); + + // 添加论文信息 + int addPaper(@Param("p") ArrayList p); + + // 获取用户项目经历 + @Select("SELECT * FROM Project WHERE id = #{userId}") + ArrayList getProject(@Param("userId") int processedUserid); + + // 添加项目经历 + int addProject(@Param("p")ArrayList p); + + // 获取用户科研经历 + @Select("SELECT * FROM Research WHERE id = #{userId}") + ArrayList getResearch(@Param("userId") int processedUserid); + + // 添加科研经历 + int addResearch(@Param("r")ArrayList r); + + // 获取用户家庭成员信息 + @Select("SELECT * FROM FamilyConnections WHERE id = #{userId}") + ArrayList getFamilyConnections(@Param("userId") int processedUserid); + + // 添加家庭成员信息 + int addFamilyConnections(@Param("f")ArrayList f); + + // 删除用户所有简历相关数据 + void delUserResumeAllData(@Param("userid") int processedUserid); + + // 根据用户名加载用户详情(用于Spring Security) + @Select("SELECT * FROM `user-thing` WHERE `userid` = #{arg0}") + UserDetails loadUserByUsername(String username); +} \ No newline at end of file diff --git a/src/main/java/edu/hfbu/recruit/model/Admin.java b/src/main/java/edu/hfbu/recruit/model/Admin.java new file mode 100644 index 0000000..83de930 --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/Admin.java @@ -0,0 +1,67 @@ +package edu.ahbvc.recruit.model; + + +/** + * @author c215 + */ +public class Admin { + + private int id; + private String name; + private String account; + private String pwd; + private String phone; + private Integer promise; + public Admin() { + super(); + } + public Admin(int id, String name, String num, String pwd, String tel, Integer viewOnly) { + super(); + this.id = id; + this.name = name; + this.account = num; + this.pwd = pwd; + this.phone = tel; + this.promise = viewOnly; + } + public int getId() { + return id; + } + public void setId(int id) { + this.id = id; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public String getAccount() { + return account; + } + public void setAccount(String num) { + this.account = num; + } + public String getPwd() { + return pwd; + } + public void setPwd(String pwd) { + this.pwd = pwd; + } + public String getPhone() { + return phone; + } + public void setPhone(String tel) { + this.phone = tel; + } + public Integer getPromise() { + return promise; + } + public void setPromise(Integer viewOnly) { + this.promise = viewOnly; + } + @Override + public String toString() { + return "Admin [id=" + id + ", name=" + name + ", account=" + account + ", pwd=" + pwd + ", phone=" + phone + "]"; + } +} diff --git a/src/main/java/edu/hfbu/recruit/model/ApiResponseData.java b/src/main/java/edu/hfbu/recruit/model/ApiResponseData.java new file mode 100644 index 0000000..afd5737 --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/ApiResponseData.java @@ -0,0 +1,54 @@ +package edu.ahbvc.recruit.model; + +/** + * @author c215 + * 封装返回数据 + * 统一返回数据格式 + */ +public class ApiResponseData { + + public String code; + public T data; + public String message; + + public ApiResponseData() { + super(); + } + + public ApiResponseData(String code, T data, String message) { + super(); + this.code = code; + this.data = data; + this.message = message; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + @Override + public String toString() { + return "ApiResponseData [code=" + code + ", data=" + data + ", message=" + message + "]"; + } + +} diff --git a/src/main/java/edu/hfbu/recruit/model/Batch.java b/src/main/java/edu/hfbu/recruit/model/Batch.java new file mode 100644 index 0000000..e528657 --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/Batch.java @@ -0,0 +1,102 @@ +package edu.ahbvc.recruit.model; + +import com.fasterxml.jackson.annotation.JsonIgnore; + +public class Batch { + private int id; + @JsonIgnore + private int index; + private String name; + private String startTime; + private String deadline; + private int open; + private int disableAutoUpdate; + private int positionNum; + + public Batch() { + super(); + } + + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getStartTime() { + return startTime; + } + + public void setStartTime(String startTime) { + this.startTime = startTime; + } + + public String getDeadline() { + return deadline; + } + + public void setDeadline(String deadline) { + this.deadline = deadline; + } + + public int getPositionNum() { + return positionNum; + } + + public void setPositionNum(int positionNum) { + this.positionNum = positionNum; + } + + public int getOpen() { + return open; + } + + public void setOpen(int canuse) { + this.open = canuse; + } + + public int getDisableAutoUpdate() { + return disableAutoUpdate; + } + + public void setDisableAutoUpdate(int disableAutoUPDATE) { + this.disableAutoUpdate = disableAutoUPDATE; + } + + + public int getNum() { + return positionNum; + } + + public void setNum(int num) { + this.positionNum = num; + } + + @Override + public String toString() { + return "Batch [id=" + id + ", index=" + index + ", name=" + name + ", startime=" + startTime + ", deadline=" + + deadline + ", open=" + open + ", disableAutoUpdate=" + disableAutoUpdate + ", positionNum=" + + positionNum + "]"; + } + + +} diff --git a/src/main/java/edu/hfbu/recruit/model/Position.java b/src/main/java/edu/hfbu/recruit/model/Position.java new file mode 100644 index 0000000..0ed18e1 --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/Position.java @@ -0,0 +1,164 @@ +package edu.ahbvc.recruit.model; + +/** + * 岗位信息 + * + * @author c215 + */ +public class Position { + private int id; + /** + * 标识该岗位在对应批次下的编号(序号) 例如 2003 01 001 + */ + private int recruitId; + private String code; + private String jobTitle; + private int toll; + private String type; + private String specialty; + private int education; + private int degree; + /** + * 性别要求 0不限 1男 2女 + * 数据库类型 tinyint + * 默认值 0 不限 + */ + private int sex; + /** + * 政治面貌 + */ + private String politicalStatus; + private int maxAge; + private String info; + private String require; + + + public Position() { + super(); + } + + public Position(int id, int recruitId, String code, String jobTitle, int toll, + int education, int degree, int maxAge, String info, String require) { + super(); + this.id = id; + this.recruitId = recruitId; + this.code = code; + this.jobTitle = jobTitle; + this.toll = toll; + this.education = education; + this.degree = degree; + this.maxAge = maxAge; + this.info = info; + this.require = require; + } + + public int getId() { + return id; + } + public void setId(int id) { + this.id = id; + } + public int getRecruitId() { + return recruitId; + } + + public void setRecruitId(int recruitId) { + this.recruitId = recruitId; + } + + public String getCode() { + return code; + } + public void setCode(String code) { + this.code = code; + } + public String getJobTitle() { + return jobTitle; + } + public void setJobTitle(String jobTitle) { + this.jobTitle = jobTitle; + } + public int getEducation() { + return education; + } + public void setEducation(int degree) { + this.education = degree; + } + public int getMaxAge() { + return maxAge; + } + + public void setMaxAge(int maxAge) { + this.maxAge = maxAge; + } + + public String getInfo() { + return info; + } + public void setInfo(String info) { + this.info = info; + } + + public int getDegree() { + return degree; + } + + public void setDegree(int degree) { + this.degree = degree; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getSpecialty() { + return specialty; + } + + public void setSpecialty(String specialty) { + this.specialty = specialty; + } + + public String getPoliticalStatus() { + return politicalStatus; + } + + public void setPoliticalStatus(String politicalStatus) { + this.politicalStatus = politicalStatus; + } + + public int getSex() { + return sex; + } + + public void setSex(int sex) { + this.sex = sex; + } + + public int getToll() { + return toll; + } + public void setToll(int toll) { + this.toll = toll; + } + + public String getRequire() { + return require; + } + + public void setRequire(String require) { + this.require = require; + } + + @Override + public String toString() { + return "Position [id=" + id + ", recruitId=" + recruitId + ", code=" + code + ", jobTitle=" + jobTitle + + ", toll=" + toll + ", maxAge=" + maxAge + ", education=" + + education + ", info=" + info + ", require=" + require + "]"; + } + +} diff --git a/src/main/java/edu/hfbu/recruit/model/RefuseDataMap.java b/src/main/java/edu/hfbu/recruit/model/RefuseDataMap.java new file mode 100644 index 0000000..43263e7 --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/RefuseDataMap.java @@ -0,0 +1,34 @@ +package edu.ahbvc.recruit.model; + +/** + * 在管理员拒绝用户的投递时接收(投递编号和拒绝理由) + * @author c215 + */ +public class RefuseDataMap { + private Integer thingId; + private String qualificationResult; + + public Integer getThingId() { + return thingId; + } + + public void setThingId(Integer thingId) { + this.thingId = thingId; + } + + public String getQualificationResult() { + return qualificationResult; + } + + public void setQualificationResult(String qualificationResult) { + this.qualificationResult = qualificationResult; + } + + @Override + public String toString() { + return "RefuseDataMap{" + + "thingId=" + thingId + + ", qualificationResult='" + qualificationResult + '\'' + + '}'; + } +} diff --git a/src/main/java/edu/hfbu/recruit/model/SwitchMethodStatus.java b/src/main/java/edu/hfbu/recruit/model/SwitchMethodStatus.java new file mode 100644 index 0000000..6c71d52 --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/SwitchMethodStatus.java @@ -0,0 +1,27 @@ +package edu.ahbvc.recruit.model; + +/** + * @author c215 + */ +public class SwitchMethodStatus { + + private Integer open; + + public SwitchMethodStatus() { + super(); + } + + public SwitchMethodStatus(Integer open) { + super(); + this.open = open; + } + + public Integer getOpen() { + return open; + } + + public void setOpen(Integer open) { + this.open = open; + } + +} diff --git a/src/main/java/edu/hfbu/recruit/model/Thing.java b/src/main/java/edu/hfbu/recruit/model/Thing.java new file mode 100644 index 0000000..584cd3d --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/Thing.java @@ -0,0 +1,177 @@ +package edu.ahbvc.recruit.model; + +import com.fasterxml.jackson.annotation.JsonFormat; + +import java.util.Date; + +public class Thing { + /** 岗位id */ + private int positionId; + /** 岗位与批次关系表的主键id */ + private int recruitId; + /** 用户与<岗位批次>关系表的主键id */ + private int thingId; + private String jobTitle; + private String code; + private Integer ticketNum; + private int batchId; + private String batchname; + private int degree; + private int status; + private String awardsAndPunishments; + private String note; + private String qualificationResult; + /** + * 用户投递时间 + */ + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd,HH-mm-ss") + private Date time; + /** + * 对应用户是否申请过该岗位,无用 + */ + private int ok; + + public Thing() { + super(); + } + + public Thing(int id, int recruitId, String batch, int batchid, int degree, int status, + String jobTitle, int ok) { + super(); + this.positionId = id; + this.recruitId = recruitId; + this.batchname = batch; + this.batchId = batchid; + this.degree = degree; + this.status = status; + this.jobTitle = jobTitle; + this.ok = ok; + } + + public int getPositionId() { + return positionId; + } + + public void setPositionId(int id) { + this.positionId = id; + } + + public int getRecruitId() { + return recruitId; + } + + public void setRecruitId(int recruitId) { + this.recruitId = recruitId; + } + + public int getThingId() { + return thingId; + } + + public void setThingId(int thingId) { + this.thingId = thingId; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public Integer getTicketNum() { + return ticketNum; + } + + public void setTicketNum(Integer ticketNum) { + this.ticketNum = ticketNum; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public String getBatchname() { + return batchname; + } + + public void setBatchname(String batch) { + this.batchname = batch; + } + + public int getDegree() { + return degree; + } + + public void setDegree(int degree) { + this.degree = degree; + } + + public String getJobTitle() { + return jobTitle; + } + + public void setJobTitle(String jobTitle) { + this.jobTitle = jobTitle; + } + + public int getOk() { + return ok; + } + + public void setOk(int ok) { + this.ok = ok; + } + + public int getBatchId() { + return batchId; + } + + public void setBatchId(int batchid) { + this.batchId = batchid; + } + + public String getAwardsAndPunishments() { + return awardsAndPunishments; + } + + public void setAwardsAndPunishments(String awardsAndPunishments) { + this.awardsAndPunishments = awardsAndPunishments; + } + + public String getNote() { + return note; + } + + public void setNote(String note) { + this.note = note; + } + + public String getQualificationResult() { + return qualificationResult; + } + + public void setQualificationResult(String qualificationResult) { + this.qualificationResult = qualificationResult; + } + + public Date getTime() { + return time; + } + + public void setTime(Date time) { + this.time = time; + } + + @Override + public String toString() { + return "TableDataThing [positionId=" + positionId + "," + jobTitle + ", batchname=" + batchname + ", degree=" + degree + + ", status=" + status + ", ok=" + ok + "]"; + } + +} diff --git a/src/main/java/edu/hfbu/recruit/model/ThingWithUser.java b/src/main/java/edu/hfbu/recruit/model/ThingWithUser.java new file mode 100644 index 0000000..81b095d --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/ThingWithUser.java @@ -0,0 +1,46 @@ +package edu.ahbvc.recruit.model; + +public class ThingWithUser extends Thing{ + + private String username; + private int userId; + + public ThingWithUser() { + super(); + } + + public ThingWithUser(int id, int recruitId, String batch, int batchId, int degree, int status, + String department, String jobTitle, int ok) { + super(id, recruitId, batch, batchId, degree, status, jobTitle, ok); + } + + public ThingWithUser(String username, int userId) { + super(); + this.username = username; + this.userId = userId; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public int getUserId() { + return userId; + } + + public void setUserId(int userId) { + this.userId = userId; + } + + @Override + public String toString() { + return "TableDataThingWithUser [username=" + username + ", userId=" + userId + "]"; + } + + + +} diff --git a/src/main/java/edu/hfbu/recruit/model/User.java b/src/main/java/edu/hfbu/recruit/model/User.java new file mode 100644 index 0000000..ce81e3d --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/User.java @@ -0,0 +1,212 @@ +package edu.ahbvc.recruit.model; + + +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; + +import java.util.Collection; +import java.util.List; + +/** + * 用户的授权信息,Authorization (like 'Token') + * 用户的详细信息是{@link edu.ahbvc.recruit.model.resume.UserInfo}(暂时和它一样) + * @author c215 + */ +public class User implements UserDetails { + + private int id; + private String name; + private int sex; + private String phone; + private String birthPlace; + private String nation; + private String politicalStatus; + private String email; + private String birthday; + private String idNum; + private String married; + /** + * 户口所在地 + */ + private String nativePlace; + /** + * 家庭详细地址 + */ + private String address; + /** + * 曾获何种专业证书,有何特长 + */ + private String specialtiesCertificates; + + + public User() { + super(); + } + + public User(int id, String name, int sex, String phone, String birthPlace, String nation, String politicalStatus, String email, + String birthday, String idNum, String married, String nativePlace, String address, + String specialtiesCertificates) { + super(); + this.id = id; + this.name = name; + this.sex = sex; + this.phone = phone; + this.birthPlace = birthPlace; + this.nation = nation; + this.politicalStatus = politicalStatus; + this.email = email; + this.birthday = birthday; + this.idNum = idNum; + this.married = married; + this.nativePlace = nativePlace; + this.address = address; + this.specialtiesCertificates = specialtiesCertificates; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getSex() { + return sex; + } + + public void setSex(int sex) { + this.sex = sex; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getBirthPlace() { + return birthPlace; + } + + public void setBirthPlace(String birthPlace) { + this.birthPlace = birthPlace; + } + + public String getNation() { + return nation; + } + + public void setNation(String nation) { + this.nation = nation; + } + + + public String getPoliticalStatus() { + return politicalStatus; + } + + public void setPoliticalStatus(String politicalStatus) { + this.politicalStatus = politicalStatus; + } + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getBirthday() { + return birthday; + } + + public void setBirthday(String birthday) { + this.birthday = birthday; + } + + public String getIdNum() { + return idNum; + } + + public void setIdNum(String idNum) { + this.idNum = idNum; + } + + public String getMarried() { + return married; + } + + public void setMarried(String married) { + this.married = married; + } + + public String getNativePlace() { + return nativePlace; + } + + public void setNativePlace(String nativePlace) { + this.nativePlace = nativePlace; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getSpecialtiesCertificates() { + return specialtiesCertificates; + } + + public void setSpecialtiesCertificates(String specialtiesCertificates) { + this.specialtiesCertificates = specialtiesCertificates; + } + + @Override + public String toString() { + return "User{" + + "id=" + id + + ", name='" + name + '\'' + + ", sex=" + sex + + ", phone='" + phone + '\'' + + ", birthPlace='" + birthPlace + '\'' + + ", nation='" + nation + '\'' + + ", politicalStatus='" + politicalStatus + '\'' + + ", email='" + email + '\'' + + ", birthday='" + birthday + '\'' + + ", idNum='" + idNum + '\'' + + ", married='" + married + '\'' + + ", nativePlace='" + nativePlace + '\'' + + ", address='" + address + '\'' + + ", specialtiesCertificates='" + specialtiesCertificates + '\'' + + '}'; + } + + @Override + public Collection getAuthorities() { + return List.of(); + } + + @Override + public String getPassword() { + return ""; + } + + @Override + public String getUsername() { + return ""; + } +} \ No newline at end of file diff --git a/src/main/java/edu/hfbu/recruit/model/api/ImageCaptchaResponse.java b/src/main/java/edu/hfbu/recruit/model/api/ImageCaptchaResponse.java new file mode 100644 index 0000000..8f8cfc2 --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/api/ImageCaptchaResponse.java @@ -0,0 +1,40 @@ +package edu.ahbvc.recruit.model.api; + +public class ImageCaptchaResponse { + /** + * API响应状态码 + */ + public String statusCode; + /** + * 状态码说明 + */ + public String desc; + /** + * 接口的返回信息 + */ + public VerifyCodeResponse result; + + public String getStatusCode() { + return statusCode; + } + + public void setStatusCode(String statusCode) { + this.statusCode = statusCode; + } + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } + + public VerifyCodeResponse getResult() { + return result; + } + + public void setResult(VerifyCodeResponse result) { + this.result = result; + } +} diff --git a/src/main/java/edu/hfbu/recruit/model/api/JsonReader.java b/src/main/java/edu/hfbu/recruit/model/api/JsonReader.java new file mode 100644 index 0000000..41d2c00 --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/api/JsonReader.java @@ -0,0 +1,49 @@ +package edu.ahbvc.recruit.model.api; + +// 导入Jackson库用于JSON处理 +import com.fasterxml.jackson.databind.ObjectMapper; +// 导入日志相关类 +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author c215 + * + * JsonReader 泛型类 - 用于处理API返回的JSON响应 + * @param 泛型参数,表示要转换的目标类型 + */ +public class JsonReader { + + // 使用SLF4J日志框架 + private static final Logger log = LoggerFactory.getLogger(JsonReader.class); + + /** + * 处理API返回的JSON响应并转换为指定类型的对象 + * 问题:方法没有处理空响应的情况 + * @param apiResponse API返回的JSON字符串 + * @param clazz 目标类型的Class对象 + * @return 转换后的对象,转换失败返回null + */ + public T processApiResponse(String apiResponse, Class clazz) { + // 初始化返回对象 + // 问题:建议添加null检查,或者抛出特定异常而不是返回null + // 返回转换结果 + T temp = null; + + try { + // 解析JSON响应 + ObjectMapper objectMapper = new ObjectMapper(); + temp = objectMapper.readValue(apiResponse, clazz); + } catch (Exception e) { + // 处理解析异常 + // 捕获并记录JSON解析异常 + // 问题:这里可以添加更详细的错误信息,如原始JSON内容 + // 将JSON字符串转换为指定类型的对象 + // 创建Jackson ObjectMapper实例 + log.error("解析JSON失败",e); + } + + return temp; + + } +} \ No newline at end of file diff --git a/src/main/java/edu/hfbu/recruit/model/api/SMApiResponse.java b/src/main/java/edu/hfbu/recruit/model/api/SMApiResponse.java new file mode 100644 index 0000000..7842f85 --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/api/SMApiResponse.java @@ -0,0 +1,63 @@ +package edu.ahbvc.recruit.model.api; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * API响应数据模型 + * 用于封装API响应数据 + * 使用于发短信验证码的API响应 + * + * @author c215 + */ +public class SMApiResponse { + // 响应状态码 + public String code; + // 响应消息 + @JsonProperty("msg") + public String message; + // 短信验证码UUID + @JsonProperty("smUuid") + public String smUuid; + + // 构造函数 + public SMApiResponse() { + super(); + } + + // getter方法 + public String getCode() { + return code; + } + + // setter方法 + public void setCode(String code) { + this.code = code; + } + + // getter方法 + public String getMessage() { + return message; + } + + // setter方法 + public void setMessage(String message) { + this.message = message; + } + + // getter方法 + public String getSmUuid() { + return smUuid; + } + + // setter方法 + public void setSmUuid(String smUuid) { + this.smUuid = smUuid; + } + + // 重写toString方法 + @Override + public String toString() { + return "APIVerifyCodeResponse [code=" + code + ", message=" + message + ", data=" + smUuid + "]"; + } +} + diff --git a/src/main/java/edu/hfbu/recruit/model/api/VerifyCodeResponse.java b/src/main/java/edu/hfbu/recruit/model/api/VerifyCodeResponse.java new file mode 100644 index 0000000..434a74e --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/api/VerifyCodeResponse.java @@ -0,0 +1,42 @@ +package edu.ahbvc.recruit.model.api; + +/** + * @author c215 + *

+ * 验证码响应对象 + * 用于封装验证码相关信息 + * 图片验证码响应 + */ +public class VerifyCodeResponse { + /** + * 图片验证码地址 + */ + private String fileName; + /** + * 图片对应的验证码(开发者设定为6位数字,可更改) + */ + private String verifyCode; + + // getter方法 + public String getFileName() { + return fileName; + } + + // setter方法 + public void setFileName(String fileName) { + this.fileName = fileName; + } + + /** + * 获取图片对应的验证码 + * @return 验证码字符串 + */ + public String getVerifyCode() { + return verifyCode; + } + + // setter方法 + public void setVerifyCode(String verifyCode) { + this.verifyCode = verifyCode; + } +} diff --git a/src/main/java/edu/hfbu/recruit/model/export/Excel.java b/src/main/java/edu/hfbu/recruit/model/export/Excel.java new file mode 100644 index 0000000..c7be289 --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/export/Excel.java @@ -0,0 +1,209 @@ +package edu.ahbvc.recruit.model.export; + +import edu.ahbvc.recruit.model.resume.Education; + +import java.util.ArrayList; + +/** + * Excel 导出总表数据模型 + * @author c215 + */ +public class Excel { + + /** + * 序号 + */ + protected int no; + /** + * 用户id + */ + protected int userid; + /** + * 岗位代码 + */ + protected String code; + /** + * 姓名 + */ + protected String name; + /** + * 性别 + */ + protected int sex; + /** + * 出生日期 + */ + protected String birthday; + /** + * 身份证号 + */ + protected String idnum; + /** + * 教育经历 + */ + protected ArrayList education; + /** + * 政治面貌 + */ + protected String zzmm; + /** + * 民族 + */ + protected String nation; + /** + * 联系电话 + */ + protected String phone; + /** + * 状态 + */ + protected int status; + /** + * 备注 + */ + protected String note; + + public Excel() { + super(); + } + + public Excel(int no, String code, String name, int sex, String birthday, String idnum, + ArrayList education, String zzmm, String nation, String phone, int status, String note) { + super(); + this.no = no; + this.code = code; + this.name = name; + this.sex = sex; + this.birthday = birthday; + this.idnum = idnum; + this.education = education; + this.zzmm = zzmm; + this.nation = nation; + this.phone = phone; + this.status = status; + this.note = note; + } + + public int getNo() { + return no; + } + + public void setNo(int no) { + this.no = no; + } + + public int getUserid() { + return userid; + } + + public void setUserid(int userid) { + this.userid = userid; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getSex() { + return sex; + } + + public void setSex(int sex) { + this.sex = sex; + } + + public String getBirthday() { + return birthday; + } + + public void setBirthday(String birthday) { + this.birthday = birthday; + } + + public String getIdnum() { + return idnum; + } + + public void setIdnum(String idnum) { + this.idnum = idnum; + } + + public ArrayList getEducation() { + return education; + } + + public void setEducation(ArrayList education) { + this.education = education; + } + + public String getZzmm() { + return zzmm; + } + + public void setZzmm(String zzmm) { + this.zzmm = zzmm; + } + + public String getNation() { + return nation; + } + + public void setNation(String nation) { + this.nation = nation; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public String getNote() { + return note; + } + + public void setNote(String note) { + this.note = note; + } + + @Override + public String toString() { + return "Excel{" + + "no=" + no + + ", userid=" + userid + + ", code='" + code + '\'' + + ", name='" + name + '\'' + + ", sex=" + sex + + ", birthday='" + birthday + '\'' + + ", idnum='" + idnum + '\'' + + ", education=" + education + + ", zzmm='" + zzmm + '\'' + + ", nation='" + nation + '\'' + + ", phone='" + phone + '\'' + + ", status=" + status + + ", note='" + note + '\'' + + '}'; + } +} diff --git a/src/main/java/edu/hfbu/recruit/model/export/Ticket.java b/src/main/java/edu/hfbu/recruit/model/export/Ticket.java new file mode 100644 index 0000000..850a7cd --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/export/Ticket.java @@ -0,0 +1,88 @@ +package edu.ahbvc.recruit.model.export; + +/** + * 准考证数据模型 + * 用于封装准考证相关信息 + * @author c215 + */ +public class Ticket { + + /** + * 岗位代码 + */ + protected String code; + /** + * 准考证号 + */ + protected String ticketNumber; + protected String name; + protected String tel; + protected String idnum; + protected String department; + protected String batch; + + + public Ticket() { + super(); + } + public Ticket(String myindex, String myindexWithUser, String name, String tel, String idnum, + String department, String batch) { + super(); + this.code = myindex; + this.ticketNumber = myindexWithUser; + this.name = name; + this.tel = tel; + this.idnum = idnum; + this.department = department; + this.batch = batch; + } + public String getCode() { + return code; + } + public void setCode(String myindex) { + this.code = myindex; + } + public String getTicketNumber() { + return ticketNumber; + } + public void setTicketNumber(String myindexWithUser) { + this.ticketNumber = myindexWithUser; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public String getTel() { + return tel; + } + public void setTel(String tel) { + this.tel = tel; + } + public String getIdnum() { + return idnum; + } + public void setIdnum(String idnum) { + this.idnum = idnum; + } + public String getDepartment() { + return department; + } + public void setDepartment(String department) { + this.department = department; + } + + public String getBatch() { + return batch; + } + public void setBatch(String batch) { + this.batch = batch; + } + @Override + public String toString() { + return "PrintCertificate [code=" + code + ", ticketNumber=" + ticketNumber + ", name=" + name + + ", tel=" + tel + ", idnum=" + idnum + ", department=" + department + ", batch=" + batch + "]"; + } + +} diff --git a/src/main/java/edu/hfbu/recruit/model/page/Page.java b/src/main/java/edu/hfbu/recruit/model/page/Page.java new file mode 100644 index 0000000..5cc4ad0 --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/page/Page.java @@ -0,0 +1,56 @@ +package edu.ahbvc.recruit.model.page; + +/** + * 分页工具类 + * @author c215 + */ +public class Page { + /** + * 当前页码 + */ + protected int currentPage; + /** + * 每页显示的记录数 + */ + protected int size; + + /** + * 无参构造函数 + */ + public Page() { + super(); + } + + /** + * 有参构造函数 + * @param currentPage 当前页码 + * @param size 每页显示的记录数 + */ + public Page(int currentPage, int size) { + super(); + this.currentPage = currentPage; + this.size = size; + } + + public int getCurrentPage() { + return currentPage; + } + + public void setCurrentPage(int currentPage) { + this.currentPage = currentPage; + } + + public int getSize() { + return size; + } + + public void setSize(int size) { + this.size = size; + } + + @Override + public String toString() { + return "PageUtil [currentPage=" + currentPage + ", size=" + size + "]"; + } + +} diff --git a/src/main/java/edu/hfbu/recruit/model/page/SearchAndPageOfAdmin.java b/src/main/java/edu/hfbu/recruit/model/page/SearchAndPageOfAdmin.java new file mode 100644 index 0000000..a86d751 --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/page/SearchAndPageOfAdmin.java @@ -0,0 +1,51 @@ +package edu.ahbvc.recruit.model.page; + +/** + * @author c215 + */ +public class SearchAndPageOfAdmin extends Page { + /** + * 姓名 + */ + protected String name; + /** + * 电话 + */ + protected String phone; + + public SearchAndPageOfAdmin() { + super(); + } + + public SearchAndPageOfAdmin(int currentPage, int size) { + super(currentPage, size); + } + + public SearchAndPageOfAdmin(String name, String phone) { + super(); + this.name = name; + this.phone = phone; + } + + public String getName() { + return name; + } + + public void setName(String key) { + this.name = key; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + @Override + public String toString() { + return "SearchAndPageOfAdmin [name=" + name + ", phone=" + phone + "]"; + } + +} diff --git a/src/main/java/edu/hfbu/recruit/model/page/SearchAndPageOfBatches.java b/src/main/java/edu/hfbu/recruit/model/page/SearchAndPageOfBatches.java new file mode 100644 index 0000000..47e6aa1 --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/page/SearchAndPageOfBatches.java @@ -0,0 +1,52 @@ +package edu.ahbvc.recruit.model.page; + +/** + * 搜索和分页工具类 + * @author c215 + */ +public class SearchAndPageOfBatches extends Page { + /** + * 关键字 + */ + protected String key; + /** + * 状态 + */ + protected Integer state; + + public SearchAndPageOfBatches() { + super(); + } + + public SearchAndPageOfBatches(int currentPage, int size) { + super(currentPage, size); + } + + public SearchAndPageOfBatches(String key, Integer state) { + super(); + this.key = key; + this.state = state; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public Integer getState() { + return state; + } + + public void setState(Integer state) { + this.state = state; + } + + @Override + public String toString() { + return "SearchAndPageOfBatches [key=" + key + ", state=" + state + "]"; + } + +} diff --git a/src/main/java/edu/hfbu/recruit/model/page/SearchAndPageOfDepartment.java b/src/main/java/edu/hfbu/recruit/model/page/SearchAndPageOfDepartment.java new file mode 100644 index 0000000..fcfc9cf --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/page/SearchAndPageOfDepartment.java @@ -0,0 +1,39 @@ +package edu.ahbvc.recruit.model.page; + +/** + * 搜索和分页工具类 + * @author c215 + */ +public class SearchAndPageOfDepartment extends Page { + /** + * 关键字 + */ + protected String key; + + public SearchAndPageOfDepartment() { + super(); + } + + public SearchAndPageOfDepartment(int currentPage, int size) { + super(currentPage, size); + } + + public SearchAndPageOfDepartment(String key) { + super(); + this.key = key; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + @Override + public String toString() { + return "SearchAndPageOfDepartment [key=" + key + "]"; + } + +} diff --git a/src/main/java/edu/hfbu/recruit/model/page/SearchAndPageOfPosition.java b/src/main/java/edu/hfbu/recruit/model/page/SearchAndPageOfPosition.java new file mode 100644 index 0000000..425ed76 --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/page/SearchAndPageOfPosition.java @@ -0,0 +1,31 @@ +package edu.ahbvc.recruit.model.page; + +import java.util.List; + +/** + * 搜索和分页工具类 + * @author c215 + */ +public class SearchAndPageOfPosition extends Page { + /** + * 关键字 + */ + private List departments; + + public SearchAndPageOfPosition() { + super(); + } + + public SearchAndPageOfPosition(int currentPage, int size) { + super(currentPage, size); + } + + public List getDepartments() { + return departments; + } + + public void setDepartments(List departments) { + this.departments = departments; + } + +} diff --git a/src/main/java/edu/hfbu/recruit/model/page/SearchAndPageOfPositionByUser.java b/src/main/java/edu/hfbu/recruit/model/page/SearchAndPageOfPositionByUser.java new file mode 100644 index 0000000..057d6a6 --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/page/SearchAndPageOfPositionByUser.java @@ -0,0 +1,40 @@ +package edu.ahbvc.recruit.model.page; + +/** + * 搜索和分页工具类 + * @author c215 + */ +public class SearchAndPageOfPositionByUser extends Page { + + public String code; + public int batchId; + + + public SearchAndPageOfPositionByUser() { + super(); + } + public SearchAndPageOfPositionByUser(int currentPage, int size) { + super(currentPage, size); + } + public SearchAndPageOfPositionByUser(String code, int batchId) { + super(); + this.code = code; + this.batchId = batchId; + } + public String getCode() { + return code; + } + public void setCode(String code) { + this.code = code; + } + public int getBatchId() { + return batchId; + } + public void setBatchId(int batchId) { + this.batchId = batchId; + } + @Override + public String toString() { + return "SearchAndPageOfPositionByUser [code=" + code + ", batchId=" + batchId + "]"; + } +} \ No newline at end of file diff --git a/src/main/java/edu/hfbu/recruit/model/page/SearchAndPageOfResult.java b/src/main/java/edu/hfbu/recruit/model/page/SearchAndPageOfResult.java new file mode 100644 index 0000000..82aa35b --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/page/SearchAndPageOfResult.java @@ -0,0 +1,102 @@ +package edu.ahbvc.recruit.model.page; + +import java.util.List; + +/** + * 搜索和分页工具类 + * @author c215 + */ +public class SearchAndPageOfResult extends Page { + /** + * 批次列表 + */ + private List batches; + /** + * 职位列表 + */ + private List jobTitles; + /** + * 状态列表 + */ + private List status; + /** + * 关键字 + */ + private String name; + + public SearchAndPageOfResult() { + super(); + } + + public SearchAndPageOfResult(int currentPage, int size, List batches, List jobTitles, + List departments) { + super(); + super.currentPage = currentPage; + super.size = size; + this.batches = batches; + this.jobTitles = jobTitles; + this.status = departments; + } + + @Override + public int getCurrentPage() { + return super.getCurrentPage(); + } + + @Override + public void setCurrentPage(int currentPage) { + super.setCurrentPage(currentPage); + } + + @Override + public int getSize() { + return super.getSize(); + } + + @Override + public void setSize(int size) { + super.setSize(size); + } + + public List getBatches() { + return batches; + } + + public void setBatches(List batches) { + this.batches = batches; + } + + public List getJobTitles() { + return jobTitles; + } + + public void setJobTitles(List jobTitles) { + this.jobTitles = jobTitles; + } + + public List getStatus() { + return status; + } + + public void setStatus(List departments) { + this.status = departments; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + final int maxLen = 10; + return "SearchAndPageOfResult [batches=" + + (batches != null ? batches.subList(0, Math.min(batches.size(), maxLen)) : null) + ", jobTitles=" + + (jobTitles != null ? jobTitles.subList(0, Math.min(jobTitles.size(), maxLen)) : null) + + ", status=" + + (status != null ? status.subList(0, Math.min(status.size(), maxLen)) : null) + "]"; + } +} diff --git a/src/main/java/edu/hfbu/recruit/model/page/SearchAndPageOfUsers.java b/src/main/java/edu/hfbu/recruit/model/page/SearchAndPageOfUsers.java new file mode 100644 index 0000000..2381641 --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/page/SearchAndPageOfUsers.java @@ -0,0 +1,79 @@ +package edu.ahbvc.recruit.model.page; + +/** + * 搜索和分页工具类 + * @author c215 + */ +public class SearchAndPageOfUsers extends Page { + /** + * 关键字 + */ + protected String name; + /** + * 手机号 + */ + protected String phone; + /** + * 身份证号 + */ + protected String idnum; + /** + * 学历 + */ + protected Integer degree; + + public SearchAndPageOfUsers() { + super(); + } + + public SearchAndPageOfUsers(int currentPage, int size) { + super(currentPage, size); + } + + public SearchAndPageOfUsers(String name, String tel, String idnum, Integer degree) { + super(); + this.name = name; + this.phone = tel; + this.idnum = idnum; + this.degree = degree; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getIdnum() { + return idnum; + } + + public void setIdnum(String idnum) { + this.idnum = idnum; + } + + public Integer getDegree() { + return degree; + } + + public void setDegree(Integer degree) { + this.degree = degree; + } + + @Override + public String toString() { + return "SearchAndPageOfUsers [name=" + name + ", phone=" + phone + ", idnum=" + idnum + ", degree=" + degree + + "]"; + } + +} diff --git a/src/main/java/edu/hfbu/recruit/model/resume/Education.java b/src/main/java/edu/hfbu/recruit/model/resume/Education.java new file mode 100644 index 0000000..17f5f7d --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/resume/Education.java @@ -0,0 +1,70 @@ +package edu.ahbvc.recruit.model.resume; + +public class Education { + private int id; + private String school; + private String graduationTime; + private int degree; + private int education; + private String specialty; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getSchool() { + return school; + } + + public void setSchool(String school) { + this.school = school; + } + + public String getGraduationTime() { + return graduationTime; + } + + public void setGraduationTime(String graduationTime) { + this.graduationTime = graduationTime; + } + + public int getDegree() { + return degree; + } + + public void setDegree(int degree) { + this.degree = degree; + } + + public int getEducation() { + return education; + } + + public void setEducation(int education) { + this.education = education; + } + + public String getSpecialty() { + return specialty; + } + + public void setSpecialty(String specialty) { + this.specialty = specialty; + } + + @Override + public String toString() { + return "Education{" + + "id=" + id + + ", school='" + school + '\'' + + ", graduationTime='" + graduationTime + '\'' + + ", degree=" + degree + + ", education=" + education + + ", specialty='" + specialty + '\'' + + '}'; + } +} diff --git a/src/main/java/edu/hfbu/recruit/model/resume/FamilyConnections.java b/src/main/java/edu/hfbu/recruit/model/resume/FamilyConnections.java new file mode 100644 index 0000000..143e909 --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/resume/FamilyConnections.java @@ -0,0 +1,54 @@ +package edu.ahbvc.recruit.model.resume; + +/** + * @author c215 + */ +public class FamilyConnections { + + private int id; + private String name; + private String connection; + private String work; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getConnection() { + return connection; + } + + public void setConnection(String connection) { + this.connection = connection; + } + + public String getWork() { + return work; + } + + public void setWork(String work) { + this.work = work; + } + + @Override + public String toString() { + return "FamilyConnections{" + + "id=" + id + + ", name='" + name + '\'' + + ", connection='" + connection + '\'' + + ", work='" + work + '\'' + + '}'; + } +} diff --git a/src/main/java/edu/hfbu/recruit/model/resume/Paper.java b/src/main/java/edu/hfbu/recruit/model/resume/Paper.java new file mode 100644 index 0000000..7b93b7f --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/resume/Paper.java @@ -0,0 +1,73 @@ +package edu.ahbvc.recruit.model.resume; + +/** + * @author c215 + */ +public class Paper { + private int id; + private String journal; + private String title; + private String time; + private String journalNum; + public Paper() { + } + + public Paper(int id, String journal, String title, String time, String journalNum) { + this.id = id; + this.journal = journal; + this.title = title; + this.time = time; + this.journalNum = journalNum; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getJournal() { + return journal; + } + + public void setJournal(String journal) { + this.journal = journal; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getTime() { + return time; + } + + public void setTime(String time) { + this.time = time; + } + + public String getJournalNum() { + return journalNum; + } + + public void setJournalNum(String journalNum) { + this.journalNum = journalNum; + } + + @Override + public String toString() { + return "Paper{" + + "id=" + id + + ", journal='" + journal + '\'' + + ", title='" + title + '\'' + + ", time='" + time + '\'' + + ", journalNum='" + journalNum + '\'' + + '}'; + } +} diff --git a/src/main/java/edu/hfbu/recruit/model/resume/Project.java b/src/main/java/edu/hfbu/recruit/model/resume/Project.java new file mode 100644 index 0000000..f72d039 --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/resume/Project.java @@ -0,0 +1,73 @@ +package edu.ahbvc.recruit.model.resume; + +/** + * @author c215 + */ +public class Project { + private int id; + private int type; + private String time; + private String title; + private String level; + private String rank; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } + + public String getTime() { + return time; + } + + public void setTime(String time) { + this.time = time; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getLevel() { + return level; + } + + public void setLevel(String level) { + this.level = level; + } + + public String getRank() { + return rank; + } + + public void setRank(String rank) { + this.rank = rank; + } + + @Override + public String toString() { + return "Project{" + + "id=" + id + + ", type=" + type + + ", time='" + time + '\'' + + ", title='" + title + '\'' + + ", level='" + level + '\'' + + ", rank='" + rank + '\'' + + '}'; + } +} diff --git a/src/main/java/edu/hfbu/recruit/model/resume/Research.java b/src/main/java/edu/hfbu/recruit/model/resume/Research.java new file mode 100644 index 0000000..c5fef99 --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/resume/Research.java @@ -0,0 +1,33 @@ +package edu.ahbvc.recruit.model.resume; + +/** + * @author c215 + */ +public class Research { + private int id; + private String name; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return "Research{" + + "id=" + id + + ", name='" + name + '\'' + + '}'; + } +} diff --git a/src/main/java/edu/hfbu/recruit/model/resume/UserInfo.java b/src/main/java/edu/hfbu/recruit/model/resume/UserInfo.java new file mode 100644 index 0000000..06dcee1 --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/resume/UserInfo.java @@ -0,0 +1,162 @@ +package edu.ahbvc.recruit.model.resume; + +/** + * @author c215 + */ +public class UserInfo { + private int id; + private String name; + private int sex; + private String phone; + private String birthPlace; + private String nation; + private String politicalStatus; + private String email; + private String birthday; + private String idNum; + private String married; + /** + * 户口所在地 + */ + private String nativePlace; + /** + * 家庭详细地址 + */ + private String address; + /** + * 曾获何种专业证书,有何特长 + */ + private String specialtiesCertificates; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getSex() { + return sex; + } + + public void setSex(int sex) { + this.sex = sex; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getBirthPlace() { + return birthPlace; + } + + public void setBirthPlace(String birthPlace) { + this.birthPlace = birthPlace; + } + + public String getNation() { + return nation; + } + + public void setNation(String nation) { + this.nation = nation; + } + + public String getPoliticalStatus() { + return politicalStatus; + } + + public void setPoliticalStatus(String politicalStatus) { + this.politicalStatus = politicalStatus; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getBirthday() { + return birthday; + } + + public void setBirthday(String birthday) { + this.birthday = birthday; + } + + public String getIdNum() { + return idNum; + } + + public void setIdNum(String idNum) { + this.idNum = idNum; + } + + public String getMarried() { + return married; + } + + public void setMarried(String married) { + this.married = married; + } + + public String getNativePlace() { + return nativePlace; + } + + public void setNativePlace(String nativePlace) { + this.nativePlace = nativePlace; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getSpecialtiesCertificates() { + return specialtiesCertificates; + } + + public void setSpecialtiesCertificates(String specialtiesCertificates) { + this.specialtiesCertificates = specialtiesCertificates; + } + + @Override + public String toString() { + return "UserInfo{" + + "id=" + id + + ", name='" + name + '\'' + + ", sex=" + sex + + ", phone='" + phone + '\'' + + ", birthPlace='" + birthPlace + '\'' + + ", nation='" + nation + '\'' + + ", zzmm='" + politicalStatus + '\'' + + ", email='" + email + '\'' + + ", birthday='" + birthday + '\'' + + ", idNum='" + idNum + '\'' + + ", married='" + married + '\'' + + ", nativePlace='" + nativePlace + '\'' + + ", address='" + address + '\'' + + ", specialtiesCertificates='" + specialtiesCertificates + '\'' + + '}'; + } +} diff --git a/src/main/java/edu/hfbu/recruit/model/resume/UserResume.java b/src/main/java/edu/hfbu/recruit/model/resume/UserResume.java new file mode 100644 index 0000000..9a450bb --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/resume/UserResume.java @@ -0,0 +1,165 @@ +package edu.ahbvc.recruit.model.resume; + +import java.util.ArrayList; + +/** + * 用户的详细信息加上求职的岗位代码加上其他资质信息(简历) + * @author c215 + */ +public class UserResume { + private UserInfo info; + private String code; + private ArrayList education; + private ArrayList workExperience; + private ArrayList paper; + private ArrayList project; + private ArrayList research; + private String awardsAndPunishments; + private ArrayList family; + private String note; + private String qualificationResult; + private int thingId; + private int recruitId; + + public UserResume() { + } + + public UserResume(UserInfo info, String code, ArrayList education, ArrayList workExperience, ArrayList paper, ArrayList project, ArrayList research, String awardsAndPunishments, ArrayList family, String note, String qualificationResult, int thingId, int recruitId) { + this.info = info; + this.code = code; + this.education = education; + this.workExperience = workExperience; + this.paper = paper; + this.project = project; + this.research = research; + this.awardsAndPunishments = awardsAndPunishments; + this.family = family; + this.note = note; + this.qualificationResult = qualificationResult; + this.thingId = thingId; + this.recruitId = recruitId; + } + + public UserInfo getInfo() { + return info; + } + + public void setInfo(UserInfo info) { + this.info = info; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public ArrayList getEducation() { + return education; + } + + public void setEducation(ArrayList education) { + this.education = education; + } + + public ArrayList getWorkExperience() { + return workExperience; + } + + public void setWorkExperience(ArrayList workExperience) { + this.workExperience = workExperience; + } + + public ArrayList getPaper() { + return paper; + } + + public void setPaper(ArrayList paper) { + this.paper = paper; + } + + public ArrayList getProject() { + return project; + } + + public void setProject(ArrayList project) { + this.project = project; + } + + public ArrayList getResearch() { + return research; + } + + public void setResearch(ArrayList research) { + this.research = research; + } + + public String getAwardsAndPunishments() { + return awardsAndPunishments; + } + + public void setAwardsAndPunishments(String awardsAndPunishments) { + this.awardsAndPunishments = awardsAndPunishments; + } + + public ArrayList getFamily() { + return family; + } + + public void setFamily(ArrayList family) { + this.family = family; + } + + public String getNote() { + return note; + } + + public void setNote(String note) { + this.note = note; + } + + public String getQualificationResult() { + return qualificationResult; + } + + public void setQualificationResult(String qualificationResult) { + this.qualificationResult = qualificationResult; + } + + public int getThingId() { + return thingId; + } + + public void setThingId(int thingId) { + this.thingId = thingId; + } + + public int getRecruitId() { + return recruitId; + } + + public void setRecruitId(int recruitId) { + this.recruitId = recruitId; + } + + @Override + public String toString() { + return "UserResume{" + + "info=" + info + + ", code='" + code + '\'' + + ", education=" + education + + ", workExperience=" + workExperience + + ", paper=" + paper + + ", project=" + project + + ", research=" + research + + ", awardsAndPunishments='" + awardsAndPunishments + '\'' + + ", family=" + family + + ", note='" + note + '\'' + + ", qualificationResult='" + qualificationResult + '\'' + + ", thingId=" + thingId + + ", recruitId=" + recruitId + + '}'; + } +} diff --git a/src/main/java/edu/hfbu/recruit/model/resume/WorkExperience.java b/src/main/java/edu/hfbu/recruit/model/resume/WorkExperience.java new file mode 100644 index 0000000..ea8eb96 --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/resume/WorkExperience.java @@ -0,0 +1,62 @@ +package edu.ahbvc.recruit.model.resume; +/** + * @author c215 + */ +public class WorkExperience { + private int id; + private String company; + private String workTimeStart; + private String workTimeEnd; + private String position; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getCompany() { + return company; + } + + public void setCompany(String company) { + this.company = company; + } + + public String getWorkTimeStart() { + return workTimeStart; + } + + public void setWorkTimeStart(String workTimeStart) { + this.workTimeStart = workTimeStart; + } + + public String getWorkTimeEnd() { + return workTimeEnd; + } + + public void setWorkTimeEnd(String workTimeEnd) { + this.workTimeEnd = workTimeEnd; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + @Override + public String toString() { + return "WorkExperience{" + + "id=" + id + + ", company='" + company + '\'' + + ", workTimeStart='" + workTimeStart + '\'' + + ", workTimeEnd='" + workTimeEnd + '\'' + + ", position='" + position + '\'' + + '}'; + } +} diff --git a/src/main/java/edu/hfbu/recruit/model/token/CustomUserDetailsService.java b/src/main/java/edu/hfbu/recruit/model/token/CustomUserDetailsService.java new file mode 100644 index 0000000..181fbe2 --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/token/CustomUserDetailsService.java @@ -0,0 +1,35 @@ +package edu.ahbvc.recruit.model.token; + +import edu.ahbvc.recruit.mapper.UserInter; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Service; + +/** + * 利用UserInter实现了UserDetailsService中根据名字找用户的抽象方法 + * @author c215 + */ +@Service +public class CustomUserDetailsService implements UserDetailsService { + + // 这个类被注解为Service, 所以会被Spring容器管理 + // 控制翻转!!! + // 依赖注入!!! + // + // 所以可以自动通过构造函数注入UserInter + final UserInter userInter; + + public CustomUserDetailsService(UserInter userInter) { + this.userInter = userInter; + } + + @Override + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException{ + // UserInter中实现了根据名字找用户的方法 + // 因为JWT认证和更规范的权限管理暂暂未实现,所以此处用不到 + // SELECT * FROM `user-thing` WHERE `userid` = #{arg0} + UserDetails userDetails = userInter.loadUserByUsername(username); + return userDetails; + } +} diff --git a/src/main/java/edu/hfbu/recruit/model/token/Token.java b/src/main/java/edu/hfbu/recruit/model/token/Token.java new file mode 100644 index 0000000..cde4a7c --- /dev/null +++ b/src/main/java/edu/hfbu/recruit/model/token/Token.java @@ -0,0 +1,151 @@ +package edu.ahbvc.recruit.model.token; + +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; + +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; + +/** + * + * @author c215 + */ +public class Token implements UserDetails { + private Integer userId; + /** + * Token所有者的角色,管理员或用户 + */ + private Integer userRole; + /** + * 授权的过期时间 + */ + private Date expiration; + /** + * 授权的颁发时间 + */ + private Date issuedAt; + + public Token() { + super(); + // 当前时间 + this.issuedAt = new Date(); + + Calendar c = Calendar.getInstance(); + c.setTime(this.issuedAt); + // 添加一天 + c.add(Calendar.DATE, 1); + // 过期时间为一天后 + this.expiration = c.getTime(); + } + + public Token(Integer userId, Integer userRole) { + super(); + this.userId = userId; + this.userRole = userRole; + // 当前时间 + this.issuedAt = new Date(); + + Calendar c = Calendar.getInstance(); + c.setTime(this.issuedAt); + // 添加一天 + c.add(Calendar.DATE, 1); + // 过期时间为一天后 + this.expiration = c.getTime(); + } + + public Integer getUserId() { + return userId; + } + + public void setUserId(Integer userId) { + this.userId = userId; + } + + public Integer getUserRole() { + return userRole; + } + + public void setUserRole(Integer userRole) { + this.userRole = userRole; + } + + public Date getExpiration() { + return expiration; + } + + public void setExpiration(Date expiration) { + this.expiration = expiration; + } + + public Date getIssuedAt() { + return issuedAt; + } + + public void setIssuedAt(Date issuedAt) { + this.issuedAt = issuedAt; + } + + @Override + public String toString() { + return "Token{" + + "userId=" + userId + + ", userRole=" + userRole + + ", expiration=" + expiration + + ", issuedAt=" + issuedAt + + '}'; + } + + @Override + public Collection getAuthorities() { + return null; + } + + @Override + public String getPassword() { + return null; + } + + @Override + public String getUsername() { + return null; + } + + /** + * 指示用户的账户是否已过期。账户过期通常会禁止用户认证。 + * @return boolean,true?normal:forbid + */ + @SuppressWarnings("OverridingMethodOnlyCallsSuper") + @Override + public boolean isAccountNonExpired() { + return UserDetails.super.isAccountNonExpired(); + } + + /** + * 指示用户是否未被锁定。用户账户被锁定通常是由于多次登录失败。 + * @return boolean,true?normal:forbid + */ + @Override + public boolean isAccountNonLocked() { + return UserDetails.super.isAccountNonLocked(); + } + + /** + * 指示用户的凭证(密码)是否过期。 + * @return boolean,true?normal:forbid + */ + @Override + public boolean isCredentialsNonExpired() { + return UserDetails.super.isCredentialsNonExpired(); + } + + /** + * 用户是否被禁用(拉黑) + * @return boolean,true?normal:forbid + */ + @Override + public boolean isEnabled() { + return UserDetails.super.isEnabled(); + } +}