FaqController.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package com.wechat.controller;
  2. import java.io.IOException;
  3. import javax.annotation.Resource;
  4. import javax.servlet.http.HttpServletRequest;
  5. import javax.servlet.http.HttpServletResponse;
  6. import org.springframework.stereotype.Controller;
  7. import org.springframework.web.bind.annotation.RequestBody;
  8. import org.springframework.web.bind.annotation.RequestMapping;
  9. import org.springframework.web.bind.annotation.RequestMethod;
  10. import org.springframework.web.bind.annotation.RequestParam;
  11. import com.alibaba.fastjson.JSON;
  12. import com.wechat.callback.tencentrequests.UserSentTextRequest;
  13. import com.wechat.common.utils.MvcUtil;
  14. import com.wechat.global.base.BaseController;
  15. import com.wechat.model.dbEntity.TdtgFaqInfo;
  16. import com.wechat.model.responseDto.JsonResp;
  17. import com.wechat.service.FaqService;
  18. /**
  19. * FAQ问答
  20. *
  21. */
  22. @Controller
  23. @RequestMapping("faq")
  24. public class FaqController extends BaseController {
  25. @Resource
  26. private FaqService faqService;
  27. /**
  28. * 通过用户发送的信息,取得FAQ的问题
  29. *
  30. * @param userSentTextRequest 用户发送的信息
  31. */
  32. @RequestMapping(value = "getFaqInfo", method = RequestMethod.POST)
  33. public void getFaqInfoByMsg(@RequestBody UserSentTextRequest userSentTextRequest, HttpServletRequest request, HttpServletResponse response)
  34. throws Exception {
  35. JsonResp<TdtgFaqInfo> ret = new JsonResp<TdtgFaqInfo>();
  36. // 通过用户发送的信息,检索FAQ内容
  37. TdtgFaqInfo faqInfo = faqService.getInfoByKeyWord(userSentTextRequest.getContent());
  38. ret.setInfo(faqInfo);
  39. String json = JSON.toJSONString(ret, true);
  40. try {
  41. MvcUtil.writeJson(request, response, json);
  42. } catch (IOException e) {
  43. // TODO Auto-generated catch block
  44. log.error(e);
  45. }
  46. }
  47. /**
  48. * FAQ信息取得ID查询
  49. *
  50. * @param int ID信息
  51. */
  52. @RequestMapping(value = "getFaqInfoById", method = RequestMethod.GET)
  53. public void getFaqInfoById(@RequestParam int id, HttpServletRequest request, HttpServletResponse response)throws Exception {
  54. JsonResp<String> ret = new JsonResp<String>();
  55. TdtgFaqInfo faqInfo = faqService.getInfoById(id);
  56. if(faqInfo != null)
  57. {
  58. ret.setInfo(faqInfo.getNewsContent());
  59. }
  60. String json = JSON.toJSONString(ret, true);
  61. try {
  62. MvcUtil.writeJson(request, response, json);
  63. } catch (IOException e) {
  64. log.error(e);
  65. }
  66. }
  67. }