44323
2023-11-27 aa925d851857f50eff0556411366690d9a78a0e5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package com.dsh.other.controller;
 
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dsh.other.entity.FrequentlyAskedQuestions;
import com.dsh.other.model.vo.questionVo.QuestionChangeStateVO;
import com.dsh.other.model.vo.questionVo.QuestionDetailsVo;
import com.dsh.other.model.vo.questionVo.QuestionIns;
import com.dsh.other.model.vo.questionVo.QuestionSearchVO;
import com.dsh.other.service.FrequentlyAskedQuestionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
@RestController
@RequestMapping("")
public class AskedQuestionsController {
 
 
    @Autowired
    private FrequentlyAskedQuestionsService faqService;
 
 
    private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
 
    /**
     * 添加常见问题
     */
    @RequestMapping("/base/question/addQuestion")
    public Object addQuestion(@RequestBody FrequentlyAskedQuestions frequentlyAskedQuestions) {
        frequentlyAskedQuestions.setInsertTime(new Date());
        frequentlyAskedQuestions.setState(1);
        return faqService.save(frequentlyAskedQuestions);
    }
 
    /**
     * 修改常见问题
     */
    @RequestMapping("/base/question/editQuestion")
    public Object editQuestion(@RequestBody FrequentlyAskedQuestions frequentlyAskedQuestions) {
        return faqService.updateById(frequentlyAskedQuestions);
    }
 
    /**
     * 上/下架、删除常见问题 type=1为上架 2为下架 3为删除
     */
    @RequestMapping("/base/question/changeState")
    public Object changeState(@RequestBody QuestionChangeStateVO vo) {
        return faqService.changeState(vo);
    }
 
    /**
     * 查看详情
     */
    @RequestMapping("/base/question/getInfo")
    public FrequentlyAskedQuestions getInfo(@RequestBody Integer id) {
        return faqService.getInfo(id);
    }
 
    /**
     * 编辑常见问题
     */
    @RequestMapping("/base/question/updateQuestion")
    public Object updateQuestion(@RequestBody FrequentlyAskedQuestions frequentlyAskedQuestions) {
        return faqService.updateById(frequentlyAskedQuestions);
    }
 
    /**
     * 获取所有常见问题
     *
     * @return
     */
    @RequestMapping("/base/question/listAll")
    public List<FrequentlyAskedQuestions> listAll(@RequestBody QuestionSearchVO vo) {
        QueryWrapper<FrequentlyAskedQuestions> frequentlyAskedQuestionsQueryWrapper = new QueryWrapper<>();
        if (vo.getState() != null) {
            frequentlyAskedQuestionsQueryWrapper.eq("state", vo.getState());
        }
        if (vo.getContent() != null && !vo.getContent().equals("")) {
            frequentlyAskedQuestionsQueryWrapper.like("content", vo.getContent());
        }
        frequentlyAskedQuestionsQueryWrapper.ne("state", 3);
        frequentlyAskedQuestionsQueryWrapper.orderByDesc("sort");
        List<FrequentlyAskedQuestions> list = faqService.list(frequentlyAskedQuestionsQueryWrapper);
        return list;
    }
 
    @ResponseBody
    @PostMapping("/base/notice/queryQuestionDetails")
    public List<QuestionIns> getSysQuestionDetails() {
        List<QuestionIns> sysS = new ArrayList<>();
        List<FrequentlyAskedQuestions> list = faqService.list(new QueryWrapper<FrequentlyAskedQuestions>()
                .eq("state", 1)
                .orderByDesc("insertTime"));
        if (list.size() > 0) {
            list.forEach(noList -> {
                QuestionIns notice = new QuestionIns();
                notice.setQuesId(noList.getId());
                notice.setQuesTitle(noList.getContent());
                notice.setQuesContents(noList.getAnswer());
                sysS.add(notice);
            });
        }
        return sysS;
    }
 
 
    @PostMapping("/base/notice/queryQuestion")
    public QuestionIns getSysQuestionBuId(@RequestParam("quesId") Integer quesId) {
        QuestionIns sysNotice = new QuestionIns();
        FrequentlyAskedQuestions notice = faqService.getById(quesId);
        if (null != notice) {
            sysNotice.setQuesId(notice.getId());
            sysNotice.setQuesTitle(notice.getContent());
            sysNotice.setQuesContents(notice.getAnswer());
            sysNotice.setQuesTime(format.format(notice.getInsertTime()));
        }
        return sysNotice;
    }
}