ManagerUtilController.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. package com.yihu.wlyy.web.common.util;
  2. import com.yihu.wlyy.job.QuartzHelper;
  3. import com.yihu.wlyy.job.consult.FamousConsultTimesJob;
  4. import com.yihu.wlyy.service.app.disease.PatientDiseaseService;
  5. import com.yihu.wlyy.service.app.scheduling.DoctorWorkTimeService;
  6. import com.yihu.wlyy.service.app.statistics.StatisticsService;
  7. import com.yihu.wlyy.web.BaseController;
  8. import io.swagger.annotations.Api;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.data.redis.core.StringRedisTemplate;
  11. import org.springframework.data.redis.hash.HashMapper;
  12. import org.springframework.http.MediaType;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RequestMethod;
  15. import org.springframework.web.bind.annotation.RestController;
  16. import java.text.SimpleDateFormat;
  17. import java.util.Date;
  18. import java.util.HashMap;
  19. /**
  20. * Created by lyr on 2016/09/13.
  21. */
  22. @RestController
  23. @RequestMapping(value = "/manage_util", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  24. @Api(description = "管理工具及后台任务控制")
  25. public class ManagerUtilController extends BaseController {
  26. @Autowired
  27. PatientDiseaseService diseaseService;
  28. @Autowired
  29. StringRedisTemplate redisTemplate;
  30. @Autowired
  31. QuartzHelper quartzHelper;
  32. @Autowired
  33. DoctorWorkTimeService workTimeService;
  34. @Autowired
  35. StatisticsService statisticsService;
  36. /*********************************************患者疾病相关******************************************/
  37. /**
  38. * 更新到redis
  39. *
  40. * @return
  41. */
  42. @RequestMapping(value = "/disease/to_redis")
  43. public String updateToRedid() {
  44. try {
  45. diseaseService.updateToRedis();
  46. return write(200, "更新成功");
  47. } catch (Exception e) {
  48. return error(-1, "更新失败");
  49. }
  50. }
  51. /**
  52. * 更新到疾病表
  53. *
  54. * @return
  55. */
  56. @RequestMapping(value = "/disease/to_disease")
  57. public String updateToDisease() {
  58. try {
  59. diseaseService.updateToDisease();
  60. return write(200, "更新成功");
  61. } catch (Exception e) {
  62. e.printStackTrace();
  63. return error(-1, "更新失败");
  64. }
  65. }
  66. /**
  67. * 查询患者redis疾病
  68. *
  69. * @param patient
  70. * @return
  71. */
  72. @RequestMapping(value = "/disease/patient")
  73. public String getDiseaseFromRedis(String patient) {
  74. try {
  75. return write(200, "查询成功", "data", redisTemplate.opsForValue().get("disease:" + patient));
  76. } catch (Exception e) {
  77. e.printStackTrace();
  78. return error(-1, "查询失败");
  79. }
  80. }
  81. /***********************************************名医咨询相关****************************************/
  82. /**
  83. * 开始名医咨询剩余次数统计任务
  84. *
  85. * @return
  86. */
  87. @RequestMapping(value = "/famous_doctor/start_job")
  88. public String startConsultTimesJob() {
  89. try {
  90. if (!quartzHelper.isExistJob("famous-doctor-times")) {
  91. quartzHelper.addJob(FamousConsultTimesJob.class, "0 0 0 * * ?", "famous-doctor-times", new HashMap<String, Object>());
  92. return write(200, "启动成功");
  93. } else {
  94. return write(200, "任务已存在");
  95. }
  96. } catch (Exception e) {
  97. e.printStackTrace();
  98. return error(-1, "启动失败");
  99. }
  100. }
  101. /**
  102. * 名医咨询剩余次数手动更新
  103. *
  104. * @return
  105. */
  106. @RequestMapping(value = "/famous_doctor/times_update")
  107. public String famousConsultTimeUpdate() {
  108. try {
  109. workTimeService.consultTimesRemain(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
  110. return write(200, "更新成功");
  111. } catch (Exception e) {
  112. e.printStackTrace();
  113. return error(-1, "更新失败");
  114. }
  115. }
  116. /*********************************************统计相关*******************************************/
  117. /**
  118. * 更新人口数据到redis
  119. *
  120. * @return
  121. */
  122. @RequestMapping(value = "/people_num_to_redis")
  123. public String peopleNumToRedis() {
  124. try {
  125. statisticsService.peopleNumToRedis();
  126. return write(200, "更新成功");
  127. } catch (Exception e) {
  128. e.printStackTrace();
  129. return error(-1, "更新失败");
  130. }
  131. }
  132. }