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.
133 lines
4.8 KiB
133 lines
4.8 KiB
package com.yf.exam.modules.repo.controller;
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.yf.exam.core.api.ApiRest;
|
|
import com.yf.exam.core.api.controller.BaseController;
|
|
import com.yf.exam.core.api.dto.BaseIdReqDTO;
|
|
import com.yf.exam.core.api.dto.BaseIdsReqDTO;
|
|
import com.yf.exam.core.api.dto.PagingReqDTO;
|
|
import com.yf.exam.modules.qu.dto.request.QuRepoBatchReqDTO;
|
|
import com.yf.exam.modules.qu.service.QuRepoService;
|
|
import com.yf.exam.modules.repo.dto.RepoDTO;
|
|
import com.yf.exam.modules.repo.dto.request.RepoReqDTO;
|
|
import com.yf.exam.modules.repo.dto.response.RepoRespDTO;
|
|
import com.yf.exam.modules.repo.entity.Repo;
|
|
import com.yf.exam.modules.repo.service.RepoService;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import org.apache.shiro.authz.annotation.RequiresRoles;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
/**
|
|
* <p>
|
|
* 题库控制器,处理与题库相关的 HTTP 请求
|
|
* </p>
|
|
*
|
|
* @author 聪明笨狗
|
|
* @since 2020-05-25 13:25
|
|
*/
|
|
@Api(tags={"题库"})
|
|
@RestController
|
|
@RequestMapping("/exam/api/repo")
|
|
public class RepoController extends BaseController {
|
|
|
|
/**
|
|
* 注入题库服务,用于处理题库相关的业务逻辑
|
|
*/
|
|
@Autowired
|
|
private RepoService baseService;
|
|
|
|
/**
|
|
* 注入题目与题库关联服务,用于处理题目与题库的批量操作
|
|
*/
|
|
@Autowired
|
|
private QuRepoService quRepoService;
|
|
|
|
/**
|
|
* 添加或修改题库信息
|
|
* @param reqDTO 包含题库信息的请求数据传输对象
|
|
* @return 操作结果,封装在 ApiRest 对象中
|
|
*/
|
|
@RequiresRoles("sa")
|
|
@ApiOperation(value = "添加或修改")
|
|
@RequestMapping(value = "/save", method = { RequestMethod.POST})
|
|
public ApiRest save(@RequestBody RepoDTO reqDTO) {
|
|
// 调用服务层方法保存或更新题库信息
|
|
baseService.save(reqDTO);
|
|
// 返回操作成功的响应
|
|
return super.success();
|
|
}
|
|
|
|
/**
|
|
* 批量删除题库
|
|
* @param reqDTO 包含要删除的题库 ID 列表的请求数据传输对象
|
|
* @return 操作结果,封装在 ApiRest 对象中
|
|
*/
|
|
@RequiresRoles("sa")
|
|
@ApiOperation(value = "批量删除")
|
|
@RequestMapping(value = "/delete", method = { RequestMethod.POST})
|
|
public ApiRest edit(@RequestBody BaseIdsReqDTO reqDTO) {
|
|
// 根据 ID 列表删除题库
|
|
baseService.removeByIds(reqDTO.getIds());
|
|
// 返回操作成功的响应
|
|
return super.success();
|
|
}
|
|
|
|
/**
|
|
* 查找单个题库的详情信息
|
|
* @param reqDTO 包含要查找的题库 ID 的请求数据传输对象
|
|
* @return 包含题库详情信息的操作结果,封装在 ApiRest 对象中
|
|
*/
|
|
@RequiresRoles("sa")
|
|
@ApiOperation(value = "查找详情")
|
|
@RequestMapping(value = "/detail", method = { RequestMethod.POST})
|
|
public ApiRest<RepoDTO> find(@RequestBody BaseIdReqDTO reqDTO) {
|
|
// 根据 ID 获取题库实体
|
|
Repo entity = baseService.getById(reqDTO.getId());
|
|
// 创建一个新的 DTO 对象
|
|
RepoDTO dto = new RepoDTO();
|
|
// 将实体对象的属性复制到 DTO 对象中
|
|
BeanUtils.copyProperties(entity, dto);
|
|
// 返回包含 DTO 对象的操作成功响应
|
|
return super.success(dto);
|
|
}
|
|
|
|
/**
|
|
* 分页查找题库信息
|
|
* @param reqDTO 包含分页和查询条件的请求数据传输对象
|
|
* @return 包含分页查询结果的操作结果,封装在 ApiRest 对象中
|
|
*/
|
|
@RequiresRoles("sa")
|
|
@ApiOperation(value = "分页查找")
|
|
@RequestMapping(value = "/paging", method = { RequestMethod.POST})
|
|
public ApiRest<IPage<RepoRespDTO>> paging(@RequestBody PagingReqDTO<RepoReqDTO> reqDTO) {
|
|
|
|
// 调用服务层方法进行分页查询并转换结果
|
|
IPage<RepoRespDTO> page = baseService.paging(reqDTO);
|
|
|
|
// 返回包含分页结果的操作成功响应
|
|
return super.success(page);
|
|
}
|
|
|
|
/**
|
|
* 批量操作,批量加入或从题库移除题目
|
|
* @param reqDTO 包含批量操作信息的请求数据传输对象
|
|
* @return 操作结果,封装在 ApiRest 对象中
|
|
*/
|
|
@RequiresRoles("sa")
|
|
@ApiOperation(value = "批量操作", notes = "批量加入或从题库移除")
|
|
@RequestMapping(value = "/batch-action", method = { RequestMethod.POST})
|
|
public ApiRest batchAction(@RequestBody QuRepoBatchReqDTO reqDTO) {
|
|
|
|
// 调用服务层方法进行批量操作
|
|
quRepoService.batchAction(reqDTO);
|
|
// 返回操作成功的响应
|
|
return super.success();
|
|
}
|
|
}
|