|
@@ -1,20 +1,28 @@
|
|
|
package com.qxgmat.controller.admin;
|
|
|
|
|
|
|
|
|
+import com.github.pagehelper.Page;
|
|
|
import com.nuliji.tools.*;
|
|
|
import com.nuliji.tools.exception.ParameterException;
|
|
|
-import com.qxgmat.data.dao.entity.Question;
|
|
|
-import com.qxgmat.data.dao.entity.QuestionNo;
|
|
|
+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.QuestionNoExtendDto;
|
|
|
-import com.qxgmat.dto.admin.request.QuestionDto;
|
|
|
-import com.qxgmat.dto.admin.request.QuestionNoDto;
|
|
|
-import com.qxgmat.dto.admin.request.QuestionNoSearchDto;
|
|
|
+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.ExercisePaperService;
|
|
|
+import com.qxgmat.service.ManagerService;
|
|
|
+import com.qxgmat.service.UsersService;
|
|
|
import com.qxgmat.service.inline.ManagerLogService;
|
|
|
import com.qxgmat.service.inline.QuestionNoService;
|
|
|
import com.qxgmat.service.inline.QuestionService;
|
|
|
+import com.qxgmat.service.inline.UserAskQuestionService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -23,12 +31,17 @@ 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 {
|
|
|
+ @Autowired
|
|
|
+ private ShiroHelp shiroHelp;
|
|
|
|
|
|
@Autowired
|
|
|
private ManagerLogService managerLogService;
|
|
@@ -42,6 +55,15 @@ public class QuestionController {
|
|
|
@Autowired
|
|
|
private QuestionService questionService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private UserAskQuestionService userAskQuestionService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ManagerService managerService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UsersService usersService;
|
|
|
+
|
|
|
@RequestMapping(value = "/add", method = RequestMethod.POST)
|
|
|
@ApiOperation(value = "添加题目", httpMethod = "POST")
|
|
|
public Response<Question> add(@RequestBody @Validated QuestionDto dto, HttpServletRequest request) {
|
|
@@ -54,7 +76,6 @@ public class QuestionController {
|
|
|
return ResponseHelp.success(entity);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
@RequestMapping(value = "/edit", method = RequestMethod.PUT)
|
|
|
@ApiOperation(value = "修改题目", httpMethod = "PUT")
|
|
|
public Response<Boolean> edit(@RequestBody @Validated QuestionDto dto, HttpServletRequest request) {
|
|
@@ -137,4 +158,97 @@ public class QuestionController {
|
|
|
|
|
|
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().isEmpty() || !in.getAnswer().equals(entity.getAnswer())){
|
|
|
+ entity.setAnswerTime(new Date());
|
|
|
+ entity.setAnswerStatus(AskStatus.ANSWER.index);
|
|
|
+ Manager manager = shiroHelp.getLoginManager();
|
|
|
+ entity.setManagerId(manager.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 type,
|
|
|
+ @RequestParam(required = false) Integer category,
|
|
|
+ @RequestParam(required = false) Number userId,
|
|
|
+ @RequestParam(required = false) Number questionNoId,
|
|
|
+ @RequestParam(required = false) String target,
|
|
|
+ @RequestParam(required = false) Integer status,
|
|
|
+ @RequestParam(required = false) Integer showStatus,
|
|
|
+ @RequestParam(required = false) Integer moneyRang,
|
|
|
+ @RequestParam(required = false, defaultValue = "id") String order,
|
|
|
+ @RequestParam(required = false, defaultValue = "desc") String direction,
|
|
|
+ HttpSession session) {
|
|
|
+ Page<UserAskQuestion> p = userAskQuestionService.listWithUser(page, size, type, category, userId, questionNoId, AskTarget.ValueOf(target), AskStatus.ValueOf(status), showStatus, MoneyRange.ValueOf(moneyRang), 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());
|
|
|
+ }
|
|
|
}
|