|
|
@@ -1,21 +1,23 @@
|
|
|
package com.cyksj.web.controller.sys;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.dto.Result;
|
|
|
import com.cyksj.enums.GatewayResponse;
|
|
|
-import com.cyksj.mapper.manage.help.HelpQuestionClassificationMapper;
|
|
|
import com.cyksj.mapper.manage.help.HelpQuestionMapper;
|
|
|
import com.cyksj.model.entity.HelpQuestion;
|
|
|
-import com.cyksj.model.entity.HelpQuestionClassification;
|
|
|
import com.cyksj.model.entity.SysConfig;
|
|
|
+import com.cyksj.model.views.HelpQuestionClassificationView;
|
|
|
import com.cyksj.service.sys.SysConfigService;
|
|
|
-import com.cyksj.service.sys.SysHelpService;
|
|
|
+import com.ejlchina.searcher.BeanSearcher;
|
|
|
+import com.ejlchina.searcher.SearchResult;
|
|
|
+import com.ejlchina.searcher.util.MapUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+
|
|
|
/**
|
|
|
* @author chan
|
|
|
* @date 2022/10/20 10:08 AM
|
|
|
@@ -28,11 +30,9 @@ public class SysConfigController {
|
|
|
|
|
|
private final SysConfigService sysConfigService;
|
|
|
|
|
|
- private final SysHelpService sysHelpService;
|
|
|
-
|
|
|
- private final HelpQuestionClassificationMapper classificationMapper;
|
|
|
+ private final HelpQuestionMapper helpQuestionMapper;
|
|
|
|
|
|
- private final HelpQuestionMapper helpQuestionMapper;
|
|
|
+ private final BeanSearcher beanSearcher;
|
|
|
|
|
|
@GetMapping("/get")
|
|
|
public Result<SysConfig> get(String key){
|
|
|
@@ -66,125 +66,21 @@ public class SysConfigController {
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 新增问题分类
|
|
|
- */
|
|
|
- @PostMapping("/help/question/classification")
|
|
|
- public Result<String> saveHelpQuestionClassification(@RequestBody HelpQuestionClassification helpQuestionClassification) {
|
|
|
- sysHelpService.postQuestionClassification(helpQuestionClassification);
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult("新增问题分类成功");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 删除问题分类
|
|
|
- */
|
|
|
- @DeleteMapping("/help/question/classification/{id}")
|
|
|
- public Result<String> deleteHelpQuestionClassificationById(@PathVariable Long id) {
|
|
|
- HelpQuestionClassification helpQuestionClassification = classificationMapper.selectById(id);
|
|
|
- if (helpQuestionClassification != null) {
|
|
|
- helpQuestionClassification.setDeleted(false);
|
|
|
- classificationMapper.updateById(helpQuestionClassification);
|
|
|
- }
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult("删除问题分类成功");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 编辑问题分类
|
|
|
- */
|
|
|
- @PutMapping("/help/question/classification")
|
|
|
- public Result<String> editHelpQuestionClassification(@RequestBody HelpQuestionClassification helpQuestionClassification) {
|
|
|
- sysHelpService.editQuestionClassification(helpQuestionClassification);
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult("新增问题分类成功");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 问题分类列表
|
|
|
- */
|
|
|
- @GetMapping("/help/question/classification")
|
|
|
- public Result<Page<HelpQuestionClassification>> saveHelpQuestionClassification(@RequestParam(defaultValue = "1") Integer start, @RequestParam(defaultValue = "5") Integer limit) {
|
|
|
- Page<HelpQuestionClassification> page = classificationMapper.selectPage(new Page<>(start, limit), Wrappers.lambdaQuery(HelpQuestionClassification.class)
|
|
|
- .eq(HelpQuestionClassification::getDeleted, true)
|
|
|
- .orderByDesc(HelpQuestionClassification::getSort));
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult(page);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 上下架分类
|
|
|
- */
|
|
|
- @PutMapping("/help/question/classification/status/{id}")
|
|
|
- public Result<String> updateHelpQuestionClassificationStatus(@PathVariable Long id) {
|
|
|
- HelpQuestionClassification classification = classificationMapper.selectById(id);
|
|
|
- if (classification == null || !classification.getDeleted()) {
|
|
|
- throw BusinessRuntimeException.getInstance("分类不存在");
|
|
|
- }
|
|
|
- classification.setStatus(!classification.getStatus());
|
|
|
- classificationMapper.updateById(classification);
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult("操作成功");
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
- * 新增问题
|
|
|
+ * 问题分类列表
|
|
|
*/
|
|
|
- @PostMapping("/help/question")
|
|
|
- public Result<String> saveHelpQuestion(@RequestBody HelpQuestion helpQuestion) {
|
|
|
- sysHelpService.saveHelpQuestion(helpQuestion);
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult("新增问题成功");
|
|
|
+ @GetMapping("/help/question/classification/get")
|
|
|
+ public Result<SearchResult<HelpQuestionClassificationView>> get(HttpServletRequest request) {
|
|
|
+ SearchResult<HelpQuestionClassificationView> search = beanSearcher.search(HelpQuestionClassificationView.class,
|
|
|
+ MapUtils.flatBuilder(request.getParameterMap())
|
|
|
+ .orderBy(HelpQuestionClassificationView::getSort).desc()
|
|
|
+ .build());
|
|
|
+ search.getDataList().forEach(data -> {
|
|
|
+ data.setQuestions(helpQuestionMapper.selectList(Wrappers.lambdaQuery(HelpQuestion.class)
|
|
|
+ .eq(HelpQuestion::getClassificationId, data.getId())
|
|
|
+ .eq(HelpQuestion::getDeleted, true)
|
|
|
+ .orderByDesc(HelpQuestion::getSort)));
|
|
|
+ });
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 删除问题
|
|
|
- */
|
|
|
- @DeleteMapping("/help/question/{id}")
|
|
|
- public Result<String> deleteHelpQuestionById(@PathVariable Long id) {
|
|
|
- HelpQuestion helpQuestion = helpQuestionMapper.selectById(id);
|
|
|
- if (helpQuestion == null || !helpQuestion.getDeleted()) {
|
|
|
- throw BusinessRuntimeException.getInstance("问题不存在");
|
|
|
- }
|
|
|
- helpQuestion.setDeleted(false);
|
|
|
- helpQuestionMapper.updateById(helpQuestion);
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult("删除问题成功");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 修改问题
|
|
|
- */
|
|
|
- @PutMapping("/help/question")
|
|
|
- public Result<String> editHelpQuestion(@RequestBody HelpQuestion helpQuestion) {
|
|
|
- sysHelpService.editHelpQuestion(helpQuestion);
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult("编辑问题成功");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 问题列表
|
|
|
- */
|
|
|
- @GetMapping("/help/question")
|
|
|
- public Result<Page<HelpQuestion>> saveHelpQuestion(Long classificationId, @RequestParam(defaultValue = "1") Integer start, @RequestParam(defaultValue = "5") Integer limit) {
|
|
|
- if (classificationId == null) {
|
|
|
- throw BusinessRuntimeException.getInstance("问题分类id为空");
|
|
|
- }
|
|
|
- HelpQuestionClassification helpQuestionClassification = classificationMapper.selectById(classificationId);
|
|
|
- if (helpQuestionClassification == null || !helpQuestionClassification.getDeleted()) {
|
|
|
- throw BusinessRuntimeException.getInstance("该分类已被删除");
|
|
|
- }
|
|
|
- Page<HelpQuestion> page = helpQuestionMapper.selectPage(new Page<>(start, limit),
|
|
|
- Wrappers.lambdaQuery(HelpQuestion.class)
|
|
|
- .eq(HelpQuestion::getClassificationId, classificationId)
|
|
|
- .eq(HelpQuestion::getDeleted, true)
|
|
|
- .orderByDesc(HelpQuestion::getSort));
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult(page);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 上下架问题
|
|
|
- */
|
|
|
- @PutMapping("/help/question/status/{id}")
|
|
|
- public Result<String> saveHelpQuestion(@PathVariable Long id) {
|
|
|
- HelpQuestion helpQuestion = helpQuestionMapper.selectById(id);
|
|
|
- if (helpQuestion == null || !helpQuestion.getDeleted()) {
|
|
|
- throw BusinessRuntimeException.getInstance("问题不存在");
|
|
|
- }
|
|
|
- helpQuestion.setStatus(!helpQuestion.getStatus());
|
|
|
- helpQuestionMapper.updateById(helpQuestion);
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult("操作成功");
|
|
|
- }
|
|
|
}
|