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 listAll(@RequestBody QuestionSearchVO vo) { QueryWrapper 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 list = faqService.list(frequentlyAskedQuestionsQueryWrapper); return list; } @ResponseBody @PostMapping("/base/notice/queryQuestionDetails") public List getSysQuestionDetails() { List sysS = new ArrayList<>(); List list = faqService.list(new QueryWrapper() .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; } }