HealthEduArticleController.java 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package com.yihu.wlyy.web.patient.health;
  2. import io.swagger.annotations.Api;
  3. import org.json.JSONArray;
  4. import org.json.JSONObject;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.data.domain.Page;
  7. import org.springframework.stereotype.Controller;
  8. import org.springframework.web.bind.annotation.RequestMapping;
  9. import org.springframework.web.bind.annotation.ResponseBody;
  10. import com.yihu.wlyy.entity.education.HealthEduArticlePatient;
  11. import com.yihu.wlyy.service.app.health.HealthEduArticleService;
  12. import com.yihu.wlyy.util.DateUtil;
  13. import com.yihu.wlyy.web.BaseController;
  14. /**
  15. * 患者端:健康教育控制类
  16. * @author George
  17. *
  18. */
  19. @Controller
  20. @RequestMapping(value = "/patient/health/edu")
  21. @Api(description = "患者端-健康教育")
  22. public class HealthEduArticleController extends BaseController {
  23. @Autowired
  24. private HealthEduArticleService healthEduArticleService;
  25. /**
  26. * 查询文章列表
  27. * @param pagesize 分页大小
  28. * @return 列表
  29. */
  30. @RequestMapping(value = "list")
  31. @ResponseBody
  32. public String list(long id, int pagesize) {
  33. try {
  34. Page<HealthEduArticlePatient> list = healthEduArticleService.findByPatient(getUID(), id, pagesize);
  35. JSONArray jsonArray = new JSONArray();
  36. if (list != null) {
  37. for (HealthEduArticlePatient article : list) {
  38. JSONObject json = new JSONObject();
  39. json.put("id", article.getId());
  40. // 文章标识
  41. json.put("article", article.getArticle());
  42. // 医生姓名
  43. json.put("doctorName", article.getDoctorName());
  44. // 文章标题
  45. json.put("title", article.getTitle());
  46. // 文章查看URL
  47. json.put("url", article.getUrl());
  48. // 文章简介
  49. json.put("content", article.getContent());
  50. // 是否已读:0已读,1未读
  51. json.put("read", article.getRead());
  52. // 添加日期
  53. json.put("czrq", DateUtil.dateToStrLong(article.getCzrq()));
  54. jsonArray.put(json);
  55. }
  56. }
  57. return write(200, "查询成功", "list", jsonArray);
  58. } catch (Exception ex) {
  59. error(ex);
  60. return invalidUserException(ex, -1, "查询失败!");
  61. }
  62. }
  63. /**
  64. * 更新文章为已读
  65. * @param article 文章标识
  66. * @return
  67. */
  68. @RequestMapping(value = "read")
  69. @ResponseBody
  70. public String read(String article) {
  71. try {
  72. healthEduArticleService.updateRead(getUID(), article);
  73. return success("操作成功!");
  74. } catch (Exception ex) {
  75. error(ex);
  76. return invalidUserException(ex, -1, "操作失败!");
  77. }
  78. }
  79. }