DataController.java 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package com.yihu.wlyy.web.common.data;
  2. import java.util.List;
  3. import io.swagger.annotations.Api;
  4. import org.json.JSONArray;
  5. import org.json.JSONObject;
  6. import org.springframework.beans.factory.annotation.Autowired;
  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.dict.Disease;
  13. import com.yihu.wlyy.service.common.data.DataService;
  14. import com.yihu.wlyy.web.BaseController;
  15. @RequestMapping(value = "/common/data", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  16. @Controller
  17. @Api(description = "疾病与社区")
  18. public class DataController extends BaseController {
  19. @Autowired
  20. private DataService dataService;
  21. @RequestMapping(value = "diseases")
  22. @ResponseBody
  23. public String diseases() {
  24. try {
  25. JSONArray array = new JSONArray();
  26. List<Disease> list = dataService.findAllDisease();
  27. for (Disease temp : list) {
  28. if (temp == null) {
  29. continue;
  30. }
  31. JSONObject json = new JSONObject();
  32. json.put("code", temp.getCode());
  33. json.put("name", temp.getName());
  34. array.put(json);
  35. }
  36. return write(200, "获取疾病成功!", "list", array);
  37. } catch (Exception e) {
  38. error(e);
  39. return error(-1, "获取疾病失败!");
  40. }
  41. }
  42. @RequestMapping(value = "diseases_community")
  43. @ResponseBody
  44. public String diseasesCommunity() {
  45. try {
  46. JSONArray array = new JSONArray();
  47. List<Disease> list = dataService.findAllDisease();
  48. for (Disease temp : list) {
  49. if (temp == null) {
  50. continue;
  51. }
  52. JSONObject json = new JSONObject();
  53. json.put("code", temp.getCode());
  54. json.put("name", temp.getName() + "社区");
  55. array.put(json);
  56. }
  57. return write(200, "获取疾病社区成功!", "list", array);
  58. } catch (Exception e) {
  59. error(e);
  60. return error(-1, "获取疾病社区失败!");
  61. }
  62. }
  63. }