You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
233 lines
8.1 KiB
233 lines
8.1 KiB
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接口
|
|
* <p>
|
|
* 用于提供前端页面所需的接口
|
|
* </p>
|
|
* @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<HashMap<String, Object>> getBatcheOption() {
|
|
// 获取所有批次信息
|
|
List<Batch> batches = thingService.getBatchOption();
|
|
// 封装返回数据
|
|
HashMap<String, Object> map = new HashMap<>();
|
|
// 将批次信息存入map中
|
|
map.put("list", batches);
|
|
// 创建ApiResponseData对象, 用于封装返回数据
|
|
ApiResponseData<HashMap<String, Object>> responseData = new ApiResponseData<>();
|
|
// 设置返回数据的状态码和消息
|
|
responseData.setCode("0");
|
|
// 设置返回数据的消息
|
|
responseData.setMessage("获取批次数据");
|
|
// 设置返回数据
|
|
responseData.setData(map);
|
|
// 返回ApiResponseData对象
|
|
return responseData;
|
|
}
|
|
|
|
/**
|
|
* 获取岗位下拉框内容
|
|
*
|
|
* @return 岗位集合{岗位名-id}
|
|
*/
|
|
@GetMapping("getPositionOption")
|
|
public ApiResponseData<HashMap<String, Object>> getPositionOption() {
|
|
// 获取所有岗位信息
|
|
List<Position> list = thingService.getPositionOption();
|
|
// 封装返回数据
|
|
ApiResponseData<HashMap<String, Object>> responseData = new ApiResponseData<>();
|
|
// 设置返回数据的状态码和消息
|
|
HashMap<String, Object> 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<HashMap<String, Object>> 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<String, Object> 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<HashMap<String, Object>> responseData = new ApiResponseData<>();
|
|
// 设置返回数据的状态码和消息
|
|
responseData.setCode("0");
|
|
// 设置返回数据的消息
|
|
responseData.setMessage("获取批次数据");
|
|
// 设置返回数据
|
|
responseData.setData(map);
|
|
// 返回ApiResponseData对象
|
|
return responseData;
|
|
}
|
|
|
|
/**
|
|
* 搜索岗位
|
|
*
|
|
* @param authorizationHeader 请求头Token
|
|
* @param requestBody 请求体
|
|
* @return 岗位集合
|
|
*/
|
|
@PostMapping("searchPositions")
|
|
public ApiResponseData<HashMap<String, Object>> 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<Position> positionList = thingService.getSomePosition(batchId, offset, size);
|
|
// 封装返回数据
|
|
HashMap<String, Object> map = new HashMap<>();
|
|
// 将批次信息存入map中
|
|
map.put("list", positionList);
|
|
// 创建ApiResponseData对象, 用于封装返回数据
|
|
ApiResponseData<HashMap<String, Object>> responseData = new ApiResponseData<>();
|
|
// 设置返回数据的状态码和消息
|
|
responseData.setCode("0");
|
|
// 设置返回数据的消息
|
|
responseData.setMessage("获取部门数据");
|
|
// 设置返回数据
|
|
responseData.setData(map);
|
|
// 返回ApiResponseData对象
|
|
return responseData;
|
|
}
|
|
|
|
}
|