|
|
package com.controller;
|
|
|
|
|
|
// 导入用于格式化日期的类
|
|
|
import java.text.SimpleDateFormat;
|
|
|
// 导入用于创建和操作动态数组的类
|
|
|
import java.util.ArrayList;
|
|
|
// 导入用于操作数组的工具类
|
|
|
import java.util.Arrays;
|
|
|
// 导入用于处理日期和时间的类
|
|
|
import java.util.Calendar;
|
|
|
// 导入用于表示键值对映射的接口
|
|
|
import java.util.Map;
|
|
|
// 导入用于实现 Map 接口的类
|
|
|
import java.util.HashMap;
|
|
|
// 导入用于遍历集合的迭代器接口
|
|
|
import java.util.Iterator;
|
|
|
// 导入用于表示日期的类
|
|
|
import java.util.Date;
|
|
|
// 导入用于表示列表的接口
|
|
|
import java.util.List;
|
|
|
// 导入用于处理 HTTP 请求的类
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
// 导入自定义的验证工具类
|
|
|
import com.utils.ValidatorUtils;
|
|
|
// 导入 Apache Commons Lang 库中的字符串处理工具类
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
// 导入 Spring 框架中的自动注入注解
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
// 导入 Spring 框架中用于日期格式化的注解
|
|
|
import org.springframework.format.annotation.DateTimeFormat;
|
|
|
// 导入 Spring 框架中用于处理路径变量的注解
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
// 导入 Spring 框架中用于处理请求体的注解
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
// 导入 Spring 框架中用于处理请求映射的注解
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
// 导入 Spring 框架中用于处理请求参数的注解
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
// 导入 Spring 框架中用于将类标记为 RESTful 控制器的注解
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
// 导入 MyBatis-Plus 框架中用于构建查询条件的实体包装器类
|
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
|
|
// 导入 MyBatis-Plus 框架中用于构建查询条件的包装器接口
|
|
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
|
|
// 导入自定义的忽略认证注解
|
|
|
import com.annotation.IgnoreAuth;
|
|
|
|
|
|
// 导入试题实体类
|
|
|
import com.entity.ExamquestionEntity;
|
|
|
// 导入试题视图类
|
|
|
import com.entity.view.ExamquestionView;
|
|
|
|
|
|
// 导入试题服务类
|
|
|
import com.service.ExamquestionService;
|
|
|
// 导入令牌服务类
|
|
|
import com.service.TokenService;
|
|
|
// 导入自定义的分页工具类
|
|
|
import com.utils.PageUtils;
|
|
|
// 导入自定义的返回结果工具类
|
|
|
import com.utils.R;
|
|
|
// 导入自定义的 MD5 加密工具类
|
|
|
import com.utils.MD5Util;
|
|
|
// 导入自定义的 MyBatis-Plus 工具类
|
|
|
import com.utils.MPUtil;
|
|
|
// 导入自定义的通用工具类
|
|
|
import com.utils.CommonUtil;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 试题表
|
|
|
* 后端接口
|
|
|
* @author
|
|
|
* @email
|
|
|
* @date 2021-05-09 15:46:15
|
|
|
*/
|
|
|
// 将该类标记为 RESTful 控制器,用于处理 HTTP 请求
|
|
|
@RestController
|
|
|
// 定义该控制器处理的请求路径前缀
|
|
|
@RequestMapping("/examquestion")
|
|
|
public class ExamquestionController {
|
|
|
// 自动注入试题服务类的实例
|
|
|
@Autowired
|
|
|
private ExamquestionService examquestionService;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 后端列表
|
|
|
*/
|
|
|
// 处理 /examquestion/page 路径的请求
|
|
|
@RequestMapping("/page")
|
|
|
// 该方法用于获取试题的分页列表
|
|
|
public R page(@RequestParam Map<String, Object> params,ExamquestionEntity examquestion,
|
|
|
HttpServletRequest request){
|
|
|
// 创建一个用于构建查询条件的实体包装器
|
|
|
EntityWrapper<ExamquestionEntity> ew = new EntityWrapper<ExamquestionEntity>();
|
|
|
// 调用试题服务类的 queryPage 方法进行分页查询
|
|
|
PageUtils page = examquestionService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, examquestion), params), params));
|
|
|
|
|
|
// 返回成功响应,并将分页数据放入响应结果中
|
|
|
return R.ok().put("data", page);//测试
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 前端列表
|
|
|
*/
|
|
|
// 处理 /examquestion/list 路径的请求
|
|
|
@RequestMapping("/list")
|
|
|
// 该方法用于获取试题的分页列表(前端使用)
|
|
|
public R list(@RequestParam Map<String, Object> params,ExamquestionEntity examquestion,
|
|
|
HttpServletRequest request){
|
|
|
// 创建一个用于构建查询条件的实体包装器
|
|
|
EntityWrapper<ExamquestionEntity> ew = new EntityWrapper<ExamquestionEntity>();
|
|
|
// 调用试题服务类的 queryPage 方法进行分页查询
|
|
|
PageUtils page = examquestionService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, examquestion), params), params));
|
|
|
// 返回成功响应,并将分页数据放入响应结果中
|
|
|
return R.ok().put("data", page);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 列表
|
|
|
*/
|
|
|
// 处理 /examquestion/lists 路径的请求
|
|
|
@RequestMapping("/lists")
|
|
|
// 该方法用于获取试题列表
|
|
|
public R list( ExamquestionEntity examquestion){
|
|
|
// 创建一个用于构建查询条件的实体包装器
|
|
|
EntityWrapper<ExamquestionEntity> ew = new EntityWrapper<ExamquestionEntity>();
|
|
|
// 设置查询条件为所有字段相等
|
|
|
ew.allEq(MPUtil.allEQMapPre( examquestion, "examquestion"));
|
|
|
// 返回成功响应,并将查询到的试题列表放入响应结果中
|
|
|
return R.ok().put("data", examquestionService.selectListView(ew));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询
|
|
|
*/
|
|
|
// 处理 /examquestion/query 路径的请求
|
|
|
@RequestMapping("/query")
|
|
|
// 该方法用于查询单个试题信息
|
|
|
public R query(ExamquestionEntity examquestion){
|
|
|
// 创建一个用于构建查询条件的实体包装器
|
|
|
EntityWrapper< ExamquestionEntity> ew = new EntityWrapper< ExamquestionEntity>();
|
|
|
// 设置查询条件为所有字段相等
|
|
|
ew.allEq(MPUtil.allEQMapPre( examquestion, "examquestion"));
|
|
|
// 调用试题服务类的 selectView 方法查询单个试题信息
|
|
|
ExamquestionView examquestionView = examquestionService.selectView(ew);
|
|
|
// 返回成功响应,并将查询到的试题信息放入响应结果中
|
|
|
return R.ok("查询试题表成功").put("data", examquestionView);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 后端详情
|
|
|
*/
|
|
|
// 处理 /examquestion/info/{id} 路径的请求,{id} 为路径变量
|
|
|
@RequestMapping("/info/{id}")
|
|
|
// 该方法用于获取单个试题的详细信息
|
|
|
public R info(@PathVariable("id") Long id){
|
|
|
// 调用试题服务类的 selectById 方法根据 ID 查询试题信息
|
|
|
ExamquestionEntity examquestion = examquestionService.selectById(id);
|
|
|
// 返回成功响应,并将查询到的试题信息放入响应结果中
|
|
|
return R.ok().put("data", examquestion);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 前端详情
|
|
|
*/
|
|
|
// 处理 /examquestion/detail/{id} 路径的请求,{id} 为路径变量
|
|
|
@RequestMapping("/detail/{id}")
|
|
|
// 该方法用于获取单个试题的详细信息(前端使用)
|
|
|
public R detail(@PathVariable("id") Long id){
|
|
|
// 调用试题服务类的 selectById 方法根据 ID 查询试题信息
|
|
|
ExamquestionEntity examquestion = examquestionService.selectById(id);
|
|
|
// 返回成功响应,并将查询到的试题信息放入响应结果中
|
|
|
return R.ok().put("data", examquestion);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 后端保存
|
|
|
*/
|
|
|
// 处理 /examquestion/save 路径的 POST 请求
|
|
|
@RequestMapping("/save")
|
|
|
// 该方法用于保存新的试题信息
|
|
|
public R save(@RequestBody ExamquestionEntity examquestion, HttpServletRequest request){
|
|
|
// 为试题设置一个唯一的 ID,由当前时间戳加上一个随机数组成
|
|
|
examquestion.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
|
|
|
// 暂时注释掉实体验证逻辑
|
|
|
//ValidatorUtils.validateEntity(examquestion);
|
|
|
// 调用试题服务类的 insert 方法将试题信息插入数据库
|
|
|
examquestionService.insert(examquestion);
|
|
|
// 返回成功响应
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 前端保存
|
|
|
*/
|
|
|
// 处理 /examquestion/add 路径的 POST 请求
|
|
|
@RequestMapping("/add")
|
|
|
// 该方法用于保存新的试题信息(前端使用)
|
|
|
public R add(@RequestBody ExamquestionEntity examquestion, HttpServletRequest request){
|
|
|
// 为试题设置一个唯一的 ID,由当前时间戳加上一个随机数组成
|
|
|
examquestion.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
|
|
|
// 暂时注释掉实体验证逻辑
|
|
|
//ValidatorUtils.validateEntity(examquestion);
|
|
|
// 调用试题服务类的 insert 方法将试题信息插入数据库
|
|
|
examquestionService.insert(examquestion);
|
|
|
// 返回成功响应
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改
|
|
|
*/
|
|
|
// 处理 /examquestion/update 路径的 POST 请求
|
|
|
@RequestMapping("/update")
|
|
|
// 该方法用于更新试题信息
|
|
|
public R update(@RequestBody ExamquestionEntity examquestion, HttpServletRequest request){
|
|
|
// 暂时注释掉实体验证逻辑
|
|
|
//ValidatorUtils.validateEntity(examquestion);
|
|
|
// 调用试题服务类的 updateById 方法根据 ID 更新试题信息
|
|
|
examquestionService.updateById(examquestion);//全部更新
|
|
|
// 返回成功响应
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 删除
|
|
|
*/
|
|
|
// 处理 /examquestion/delete 路径的 POST 请求
|
|
|
@RequestMapping("/delete")
|
|
|
// 该方法用于批量删除试题信息
|
|
|
public R delete(@RequestBody Long[] ids){
|
|
|
// 调用试题服务类的 deleteBatchIds 方法根据 ID 批量删除试题信息
|
|
|
examquestionService.deleteBatchIds(Arrays.asList(ids));
|
|
|
// 返回成功响应
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 提醒接口
|
|
|
*/
|
|
|
// 处理 /examquestion/remind/{columnName}/{type} 路径的请求,{columnName} 和 {type} 为路径变量
|
|
|
@RequestMapping("/remind/{columnName}/{type}")
|
|
|
// 该方法用于统计符合提醒条件的试题数量
|
|
|
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
|
|
|
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
|
|
|
// 将列名和提醒类型放入请求参数中
|
|
|
map.put("column", columnName);
|
|
|
map.put("type", type);
|
|
|
|
|
|
// 如果提醒类型为 2
|
|
|
if(type.equals("2")) {
|
|
|
// 创建一个用于格式化日期的对象
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
// 创建一个 Calendar 实例用于处理日期
|
|
|
Calendar c = Calendar.getInstance();
|
|
|
// 定义提醒开始日期和结束日期
|
|
|
Date remindStartDate = null;
|
|
|
Date remindEndDate = null;
|
|
|
// 如果请求参数中包含提醒开始时间
|
|
|
if(map.get("remindstart")!=null) {
|
|
|
// 将提醒开始时间转换为整数
|
|
|
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
|
|
|
// 设置 Calendar 的时间为当前时间
|
|
|
c.setTime(new Date());
|
|
|
// 在当前时间基础上加上提醒开始时间的天数
|
|
|
c.add(Calendar.DAY_OF_MONTH,remindStart);
|
|
|
// 获取提醒开始日期
|
|
|
remindStartDate = c.getTime();
|
|
|
// 将格式化后的提醒开始日期放入请求参数中
|
|
|
map.put("remindstart", sdf.format(remindStartDate));
|
|
|
}
|
|
|
// 如果请求参数中包含提醒结束时间
|
|
|
if(map.get("remindend")!=null) {
|
|
|
// 将提醒结束时间转换为整数
|
|
|
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
|
|
|
// 设置 Calendar 的时间为当前时间
|
|
|
c.setTime(new Date());
|
|
|
// 在当前时间基础上加上提醒结束时间的天数
|
|
|
c.add(Calendar.DAY_OF_MONTH,remindEnd);
|
|
|
// 获取提醒结束日期
|
|
|
remindEndDate = c.getTime();
|
|
|
// 将格式化后的提醒结束日期放入请求参数中
|
|
|
map.put("remindend", sdf.format(remindEndDate));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 创建一个用于构建查询条件的包装器
|
|
|
Wrapper<ExamquestionEntity> wrapper = new EntityWrapper<ExamquestionEntity>();
|
|
|
// 如果请求参数中包含提醒开始时间
|
|
|
if(map.get("remindstart")!=null) {
|
|
|
// 设置查询条件为列值大于等于提醒开始时间
|
|
|
wrapper.ge(columnName, map.get("remindstart"));
|
|
|
}
|
|
|
// 如果请求参数中包含提醒结束时间
|
|
|
if(map.get("remindend")!=null) {
|
|
|
// 设置查询条件为列值小于等于提醒结束时间
|
|
|
wrapper.le(columnName, map.get("remindend"));
|
|
|
}
|
|
|
|
|
|
|
|
|
// 调用试题服务类的 selectCount 方法统计符合条件的试题数量
|
|
|
int count = examquestionService.selectCount(wrapper);
|
|
|
// 返回成功响应,并将统计结果放入响应结果中
|
|
|
return R.ok().put("count", count);
|
|
|
}
|
|
|
|
|
|
|
|
|
} |