ManagerUtilController.java 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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.service.common.util.ManageUtilService;
  8. import com.yihu.wlyy.service.common.util.SignTeamAndGroupRunnable;
  9. import com.yihu.wlyy.web.BaseController;
  10. import io.swagger.annotations.Api;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.data.redis.core.StringRedisTemplate;
  13. import org.springframework.data.redis.hash.HashMapper;
  14. import org.springframework.http.MediaType;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import org.springframework.web.bind.annotation.RequestMethod;
  17. import org.springframework.web.bind.annotation.RestController;
  18. import java.text.SimpleDateFormat;
  19. import java.util.Date;
  20. import java.util.HashMap;
  21. /**
  22. * Created by lyr on 2016/09/13.
  23. */
  24. @RestController
  25. @RequestMapping(value = "/manage_util", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  26. @Api(description = "管理工具及后台任务控制")
  27. public class ManagerUtilController extends BaseController {
  28. @Autowired
  29. PatientDiseaseService diseaseService;
  30. @Autowired
  31. StringRedisTemplate redisTemplate;
  32. @Autowired
  33. QuartzHelper quartzHelper;
  34. @Autowired
  35. DoctorWorkTimeService workTimeService;
  36. @Autowired
  37. StatisticsService statisticsService;
  38. @Autowired
  39. ManageUtilService manageUtilService;
  40. /*********************************************患者疾病相关******************************************/
  41. /**
  42. * 更新到redis
  43. *
  44. * @return
  45. */
  46. @RequestMapping(value = "/disease/to_redis")
  47. public String updateToRedid() {
  48. try {
  49. diseaseService.updateToRedis();
  50. return write(200, "更新成功");
  51. } catch (Exception e) {
  52. return error(-1, "更新失败");
  53. }
  54. }
  55. /**
  56. * 更新到疾病表
  57. *
  58. * @return
  59. */
  60. @RequestMapping(value = "/disease/to_disease")
  61. public String updateToDisease() {
  62. try {
  63. diseaseService.updateToDisease();
  64. return write(200, "更新成功");
  65. } catch (Exception e) {
  66. e.printStackTrace();
  67. return error(-1, "更新失败");
  68. }
  69. }
  70. /**
  71. * 查询患者redis疾病
  72. *
  73. * @param patient
  74. * @return
  75. */
  76. @RequestMapping(value = "/disease/patient")
  77. public String getDiseaseFromRedis(String patient) {
  78. try {
  79. return write(200, "查询成功", "data", redisTemplate.opsForValue().get("disease:" + patient));
  80. } catch (Exception e) {
  81. e.printStackTrace();
  82. return error(-1, "查询失败");
  83. }
  84. }
  85. /***********************************************名医咨询相关****************************************/
  86. /**
  87. * 开始名医咨询剩余次数统计任务
  88. *
  89. * @return
  90. */
  91. @RequestMapping(value = "/famous_doctor/start_job")
  92. public String startConsultTimesJob() {
  93. try {
  94. if (!quartzHelper.isExistJob("famous-doctor-times")) {
  95. quartzHelper.addJob(FamousConsultTimesJob.class, "0 0 0 * * ?", "famous-doctor-times", new HashMap<String, Object>());
  96. return write(200, "启动成功");
  97. } else {
  98. return write(200, "任务已存在");
  99. }
  100. } catch (Exception e) {
  101. e.printStackTrace();
  102. return error(-1, "启动失败");
  103. }
  104. }
  105. /**
  106. * 名医咨询剩余次数手动更新
  107. *
  108. * @return
  109. */
  110. @RequestMapping(value = "/famous_doctor/times_update")
  111. public String famousConsultTimeUpdate() {
  112. try {
  113. workTimeService.consultTimesRemain(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
  114. return write(200, "更新成功");
  115. } catch (Exception e) {
  116. e.printStackTrace();
  117. return error(-1, "更新失败");
  118. }
  119. }
  120. /*********************************************统计相关*******************************************/
  121. /**
  122. * 更新人口数据到redis
  123. *
  124. * @return
  125. */
  126. @RequestMapping(value = "/people_num_to_redis")
  127. public String peopleNumToRedis() {
  128. try {
  129. statisticsService.peopleNumToRedis();
  130. return write(200, "更新成功");
  131. } catch (Exception e) {
  132. e.printStackTrace();
  133. return error(-1, "更新失败");
  134. }
  135. }
  136. /**
  137. * 签约同步数据设置团队和分组
  138. *
  139. * @return
  140. */
  141. @RequestMapping(value = "/sign_set_group_team")
  142. public String signSetGroupAndTeam(){
  143. try {
  144. manageUtilService.signPatientSetGroup();
  145. return write(200, "更新成功");
  146. } catch (Exception e) {
  147. e.printStackTrace();
  148. return error(-1, "更新失败");
  149. }
  150. }
  151. /**
  152. * 签约同步数据设置团队和分组
  153. *
  154. * @return
  155. */
  156. @RequestMapping(value = "/sign_set_group_team_page")
  157. public String signSetGroupAndTeamPage(int page){
  158. try {
  159. manageUtilService.setSignTeamAndGroupByPage(page);
  160. return write(200, "更新成功");
  161. } catch (Exception e) {
  162. e.printStackTrace();
  163. return error(-1, "更新失败");
  164. }
  165. }
  166. /**
  167. * 签约同步数据设置团队和分组
  168. *
  169. * @return
  170. */
  171. @RequestMapping(value = "/sign_set_group_team_id")
  172. public String signSetGroupAndTeamId(Long id){
  173. try {
  174. manageUtilService.setSignTeamAndGroupById(id);
  175. return write(200, "更新成功");
  176. } catch (Exception e) {
  177. e.printStackTrace();
  178. return error(-1, "更新失败");
  179. }
  180. }
  181. /**
  182. * 签约同步数据设置团队和分组
  183. *
  184. * @return
  185. */
  186. @RequestMapping(value = "/sign_error_page_id")
  187. public String getErrorPage(int type){
  188. try {
  189. if(type == 1){
  190. return write(200, "查询成功","data",ManageUtilService.page);
  191. }else if(type == 2){
  192. return write(200, "查询成功","data",ManageUtilService.errorPages);
  193. } else{
  194. return write(200, "查询成功","data",ManageUtilService.errorSigns);
  195. }
  196. } catch (Exception e) {
  197. e.printStackTrace();
  198. return error(-1, "查询失败");
  199. }
  200. }
  201. /**
  202. * 签约同步数据设置团队和分组
  203. *
  204. * @return
  205. */
  206. @RequestMapping(value = "/sign_team_group_thread")
  207. public String getErrorPage(long start,long end){
  208. try {
  209. new Thread(new SignTeamAndGroupRunnable(start,end)).start();
  210. return write(200,"启动成功");
  211. } catch (Exception e) {
  212. e.printStackTrace();
  213. return error(-1, "启动失败");
  214. }
  215. }
  216. }