123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- package com.qxgmat.controller.admin;
- import com.github.pagehelper.Page;
- import com.nuliji.tools.*;
- import com.nuliji.tools.exception.ParameterException;
- import com.qxgmat.data.constants.enums.module.QuestionModule;
- import com.qxgmat.data.constants.enums.status.AskStatus;
- import com.qxgmat.data.constants.enums.status.DirectionStatus;
- import com.qxgmat.data.constants.enums.user.AskTarget;
- import com.qxgmat.data.constants.enums.user.MoneyRange;
- import com.qxgmat.data.dao.entity.*;
- import com.qxgmat.data.relation.entity.QuestionNoRelation;
- import com.qxgmat.dto.admin.extend.*;
- import com.qxgmat.dto.admin.request.*;
- import com.qxgmat.dto.admin.response.QuestionDetailDto;
- import com.qxgmat.dto.admin.response.UserAskQuestionDetailDto;
- import com.qxgmat.dto.admin.response.UserAskQuestionListDto;
- import com.qxgmat.help.ShiroHelp;
- import com.qxgmat.service.UserQuestionService;
- import com.qxgmat.service.extend.MessageExtendService;
- import com.qxgmat.service.inline.*;
- import com.qxgmat.service.ManagerService;
- import com.qxgmat.service.UsersService;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.http.MediaType;
- import org.springframework.validation.annotation.Validated;
- import org.springframework.web.bind.annotation.*;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpSession;
- import java.util.Collection;
- import java.util.Date;
- import java.util.List;
- @RestController("AdminQuestionController")
- @RequestMapping("/admin/question")
- @Api(tags = "题目接口", description = "题目相关", produces = MediaType.APPLICATION_JSON_VALUE)
- public class QuestionController {
- private static final Logger logger = LoggerFactory.getLogger(QuestionController.class);
- @Autowired
- private ShiroHelp shiroHelp;
- @Autowired
- private ManagerLogService managerLogService;
- @Autowired
- private ExercisePaperService exercisePaperService;
- @Autowired
- private QuestionNoService questionNoService;
- @Autowired
- private QuestionService questionService;
- @Autowired
- private UserAskQuestionService userAskQuestionService;
- @Autowired
- private ManagerService managerService;
- @Autowired
- private UsersService usersService;
- @Autowired
- private UserQuestionService userQuestionService;
- @Autowired
- private UserReportService userReportService;
- @Autowired
- private MessageExtendService messageExtendService;
- @RequestMapping(value = "/add", method = RequestMethod.POST)
- @ApiOperation(value = "添加题目", httpMethod = "POST")
- public Response<Question> add(@RequestBody @Validated QuestionDto dto, HttpServletRequest request) {
- Question entity = Transform.dtoToEntity(dto);
- entity.setQuestionModule(QuestionModule.BASE.key);
- entity = questionService.add(entity);
- // 更新编号绑定
- questionNoService.bindQuestion(dto.getQuestionNoIds(), entity.getId());
- // 更新编号关联
- questionNoService.relationQuestion(dto.getRelationQuestion());
- managerLogService.log(request);
- return ResponseHelp.success(entity);
- }
- @RequestMapping(value = "/edit", method = RequestMethod.PUT)
- @ApiOperation(value = "修改题目", httpMethod = "PUT")
- public Response<Boolean> edit(@RequestBody @Validated QuestionDto dto, HttpServletRequest request) {
- logger.info("dto: {}, {}, {}", dto, dto.getAnswer(), dto.getContent());
- Question entity = Transform.dtoToEntity(dto);
- logger.info("entity: {}", entity);
- entity = questionService.edit(entity);
- // 更新编号绑定
- questionNoService.bindQuestion(dto.getQuestionNoIds(), entity.getId());
- // 更新编号关联
- questionNoService.relationQuestion(dto.getRelationQuestion());
- managerLogService.log(request);
- return ResponseHelp.success(true);
- }
- @RequestMapping(value = "/detail", method = RequestMethod.GET)
- @ApiOperation(value = "获取题目", httpMethod = "GET")
- public Response<QuestionDetailDto> detail(int id, HttpServletRequest request) {
- Question entity = questionService.get(id);
- QuestionDetailDto dto = Transform.convert(entity, QuestionDetailDto.class);
- List<QuestionNo> questionNoList = questionNoService.listByQuestion(entity.getId());
- Integer[] ids = new Integer[questionNoList.size()];
- for (int index = 0; index < questionNoList.size(); index++) {
- ids[index] = questionNoList.get(index).getId();
- }
- dto.setQuestionNoIds(ids);
- // List<QuestionNo> questionNoList = questionNoService.listByQuestion(entity.getId());
- // List<QuestionNoExtendDto> questionNos = Transform.convert(questionNoList, QuestionNoExtendDto.class);
- // dto.setQuestionNos(questionNos);
- return ResponseHelp.success(dto);
- }
- @RequestMapping(value = "/add/no", method = RequestMethod.POST)
- @ApiOperation(value = "添加编号", httpMethod = "POST")
- public Response<QuestionNo> addNo(@RequestBody @Validated QuestionNoDto dto, HttpServletRequest request) {
- QuestionNo entity = Transform.dtoToEntity(dto);
- entity = questionNoService.add(entity);
- managerLogService.log(request);
- return ResponseHelp.success(entity);
- }
- @RequestMapping(value = "/delete/no", method = RequestMethod.DELETE)
- @ApiOperation(value = "删除题目编号", httpMethod = "DELETE")
- public Response<Boolean> delete(int id, HttpServletRequest request) {
- questionNoService.delete(id);
- managerLogService.log(request);
- return ResponseHelp.success(true);
- }
- @RequestMapping(value = "/list/no", method = RequestMethod.POST)
- @ApiOperation(value = "题目编号列表:通过id/编号", httpMethod = "POST")
- public Response<List<QuestionNoExtendDto>> listNo(@RequestBody @Validated QuestionNoSearchDto dto, HttpServletRequest request) {
- List<QuestionNoRelation> questionNos;
- if (dto.getIds() != null && dto.getIds().length > 0){
- questionNos = questionNoService.listWithRelationByIds(dto.getIds());
- }else if(dto.getNos() != null && dto.getNos().length > 0){
- questionNos = questionNoService.listWithRelationByNos(dto.getNos(), dto.getModule());
- }else{
- throw new ParameterException("需要id或编号");
- }
- List<QuestionNoExtendDto> questionNoExtendDtos = Transform.convert(questionNos, QuestionNoExtendDto.class);
- return ResponseHelp.success(questionNoExtendDtos);
- }
- @RequestMapping(value = "/search/stem", method = RequestMethod.POST)
- @ApiOperation(value = "搜索题目编号列表:题干搜索", httpMethod = "POST")
- public Response<PageMessage<QuestionNoExtendDto>> searchStem(@RequestBody @Validated QuestionNoSearchDto dto, HttpServletRequest request) {
- PageResult<QuestionNoRelation> p = questionNoService.searchStem(dto.getPage(), dto.getSize(), dto.getContent());
- List<QuestionNoExtendDto> pr = Transform.convert(p, QuestionNoExtendDto.class);
- return ResponseHelp.success(pr, dto.getPage(), dto.getSize(), p.getTotal());
- }
- @RequestMapping(value = "/search/no", method = RequestMethod.POST)
- @ApiOperation(value = "搜索题目编号列表:题目编号搜索", httpMethod = "POST")
- public Response<PageMessage<QuestionNoExtendDto>> searchNo(@RequestBody @Validated QuestionNoSearchDto dto, HttpServletRequest request) {
- PageResult<QuestionNoRelation> p = questionNoService.searchNo(dto.getPage(), dto.getSize(), dto.getKeyword(), dto.getModule());
- List<QuestionNoExtendDto> pr = Transform.convert(p, QuestionNoExtendDto.class);
- return ResponseHelp.success(pr, dto.getPage(), dto.getSize(), p.getTotal());
- }
- @RequestMapping(value = "/ask/edit", method = RequestMethod.PUT)
- @ApiOperation(value = "修改提问信息", httpMethod = "PUT")
- public Response<Boolean> editAsk(@RequestBody @Validated UserAskQuestionDto dto, HttpServletRequest request) {
- UserAskQuestion entity = Transform.dtoToEntity(dto);
- UserAskQuestion in = userAskQuestionService.get(entity.getId());
- // 调整回答
- if(entity.getAnswer() != null && (!entity.getAnswer().isEmpty() || !in.getAnswer().equals(entity.getAnswer()))){
- entity.setAnswerTime(new Date());
- entity.setAnswerStatus(AskStatus.ANSWER.index);
- Manager manager = shiroHelp.getLoginManager();
- entity.setManagerId(manager.getId());
- User user = usersService.get(in.getUserId());
- messageExtendService.sendAskQuestion(user, entity);
- }
- if (dto.getIgnoreStatus() != null && dto.getIgnoreStatus() > 0){
- entity.setAnswerStatus(AskStatus.IGNORE.index);
- User user = usersService.get(in.getUserId());
- messageExtendService.sendAskQuestion(user, entity);
- }
- entity = userAskQuestionService.edit(entity);
- if (dto.getOther() !=null && dto.getOther().length > 0){
- // 更新回答排序
- userAskQuestionService.updateOrder(dto.getOther());
- }
- managerLogService.log(request);
- return ResponseHelp.success(true);
- }
- @RequestMapping(value = "/ask/detail", method = RequestMethod.GET)
- @ApiOperation(value = "提问详情", httpMethod = "GET")
- public Response<UserAskQuestionDetailDto> detailAsk(@RequestParam int id, HttpServletRequest request) {
- UserAskQuestion entity = userAskQuestionService.get(id);
- UserAskQuestionDetailDto dto = Transform.convert(entity, UserAskQuestionDetailDto.class);
- if (entity.getManagerId() != null && entity.getManagerId() > 0){
- Manager manager = managerService.get(entity.getManagerId());
- if (manager != null)
- dto.setManager(Transform.convert(manager, ManagerExtendDto.class));
- }
- User user = usersService.get(entity.getUserId());
- dto.setUser(Transform.convert(user, UserExtendDto.class));
- Question question = questionService.get(entity.getQuestionId());
- dto.setQuestion(Transform.convert(question, QuestionExtendDto.class));
- QuestionNo questionNo = questionNoService.get(entity.getQuestionNoId());
- dto.setQuestionNo(Transform.convert(questionNo, QuestionNoExtendDto.class));
- // 所有回答
- List<UserAskQuestion> userAskList = userAskQuestionService.listByQuestion(entity.getQuestionId(), true);
- dto.setOthers(Transform.convert(userAskList, UserAskQuestionExtendDto.class));
- return ResponseHelp.success(dto);
- }
- @RequestMapping(value = "/ask/list", method = RequestMethod.GET)
- @ApiOperation(value = "提问列表", httpMethod = "GET")
- public Response<PageMessage<UserAskQuestionListDto>> listAsk(
- @RequestParam(required = false, defaultValue = "1") int page,
- @RequestParam(required = false, defaultValue = "100") int size,
- @RequestParam(required = false) String askModule,
- @RequestParam(required = false) String questionType,
- @RequestParam(required = false) String questionModule,
- @RequestParam(required = false) Number userId,
- @RequestParam(required = false) Number questionNoId,
- @RequestParam(required = false) String target,
- @RequestParam(required = false) Integer answerStatus,
- @RequestParam(required = false) Integer showStatus,
- @RequestParam(required = false) Integer moneyRang,
- @RequestParam(required = false) Boolean hasRecord,
- @RequestParam(required = false) String startTime,
- @RequestParam(required = false) String endTime,
- @RequestParam(required = false, defaultValue = "id") String order,
- @RequestParam(required = false, defaultValue = "desc") String direction,
- HttpSession session) {
- Page<UserAskQuestion> p = userAskQuestionService.listAdmin(page, size, askModule, questionType, questionModule, userId, questionNoId, AskTarget.ValueOf(target), AskStatus.ValueOf(answerStatus), showStatus, MoneyRange.ValueOf(moneyRang), hasRecord, startTime, endTime, order, DirectionStatus.ValueOf(direction));
- List<UserAskQuestionListDto> pr = Transform.convert(p, UserAskQuestionListDto.class);
- // 绑定题目
- Collection questionIds = Transform.getIds(p, UserAskQuestion.class, "questionId");
- List<Question> questionList = questionService.select(questionIds);
- Transform.combine(pr, questionList, UserAskQuestionListDto.class, "questionId", "question", Question.class, "id", QuestionExtendDto.class);
- // 绑定题目编号
- Collection questionNoIds = Transform.getIds(p, UserAskQuestion.class, "questionNoId");
- List<QuestionNo> questionNoList = questionNoService.select(questionNoIds);
- Transform.combine(pr, questionNoList, UserAskQuestionListDto.class, "questionNoId", "questionNo", QuestionNo.class, "id", QuestionNoExtendDto.class);
- // 绑定用户
- Collection userIds = Transform.getIds(p, UserAskQuestion.class, "userId");
- List<User> userList = usersService.select(userIds);
- Transform.combine(pr, userList, UserAskQuestionListDto.class, "userId", "user", User.class, "id", UserExtendDto.class);
- // 绑定管理员
- Collection managerIds = Transform.getIds(p, UserAskQuestion.class, "managerId");
- List<Manager> managerList = managerService.select(managerIds);
- Transform.combine(pr, managerList, UserAskQuestionListDto.class, "managerId", "manager", Manager.class, "id", ManagerExtendDto.class);
- return ResponseHelp.success(pr, page, size, p.getTotal());
- }
- }
|