ManagerUtilController.java 4.2 KB

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