HealthNewsController.java 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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.http.MediaType;
  8. import org.springframework.stereotype.Controller;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RequestMethod;
  11. import org.springframework.web.bind.annotation.ResponseBody;
  12. import com.yihu.wlyy.entity.education.HealthNews;
  13. import com.yihu.wlyy.service.app.health.HealthNewsService;
  14. import com.yihu.wlyy.util.DateUtil;
  15. import com.yihu.wlyy.web.BaseController;
  16. /**
  17. * 患者端:健康资讯控制类
  18. * @author George
  19. *
  20. */
  21. @Controller
  22. @RequestMapping(value = "/patient/health/news", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  23. @Api(description = "患者端-健康资讯")
  24. public class HealthNewsController extends BaseController {
  25. @Autowired
  26. private HealthNewsService healthNewsService;
  27. /**
  28. * 查询资讯列表
  29. * @param pagesize 分页大小
  30. * @return 列表
  31. */
  32. @RequestMapping(value = "list")
  33. @ResponseBody
  34. public String list(long id, int pagesize) {
  35. try {
  36. Page<HealthNews> list = healthNewsService.findAll(id, pagesize);
  37. JSONArray jsonArray = new JSONArray();
  38. if (list != null) {
  39. for (HealthNews news : list) {
  40. JSONObject json = new JSONObject();
  41. json.put("id", news.getId());
  42. // 设置新闻图片
  43. json.put("photo", news.getPhoto());
  44. // 文章标题
  45. json.put("title", news.getTitle());
  46. // 文章查看URL
  47. json.put("url", news.getUrl());
  48. // 文章简介
  49. json.put("summary", news.getSummary());
  50. // 添加日期
  51. json.put("czrq", DateUtil.dateToStrLong(news.getCzrq()));
  52. jsonArray.put(json);
  53. }
  54. }
  55. return write(200, "查询成功", "list", jsonArray);
  56. } catch (Exception ex) {
  57. error(ex);
  58. return invalidUserException(ex, -1, "查询失败!");
  59. }
  60. }
  61. }