TaskController.java 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. package com.yihu.jw.controller;/**
  2. * Created by nature of king on 2018/4/27.
  3. */
  4. import com.alibaba.fastjson.JSONArray;
  5. import com.alibaba.fastjson.JSONObject;
  6. import com.yihu.jw.entity.health.bank.TaskDO;
  7. import com.yihu.jw.restmodel.common.Envelop;
  8. import com.yihu.jw.restmodel.common.EnvelopRestController;
  9. import com.yihu.jw.rm.health.bank.HealthBankMapping;
  10. import com.yihu.jw.service.TaskService;
  11. import io.swagger.annotations.Api;
  12. import io.swagger.annotations.ApiOperation;
  13. import io.swagger.annotations.ApiParam;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.cloud.sleuth.Tracer;
  16. import org.springframework.web.bind.annotation.*;
  17. /**
  18. * @author wangzhinan
  19. * @create 2018-04-27 9:29
  20. * @desc health blank Controller
  21. **/
  22. @RestController
  23. @RequestMapping(HealthBankMapping.api_health_bank_common)
  24. @Api(tags = "健康任务相关操作",description = "健康银行相关操作")
  25. public class TaskController extends EnvelopRestController {
  26. @Autowired
  27. private TaskService service;
  28. @Autowired
  29. private Tracer tracer;
  30. /**
  31. * 指派任务
  32. *
  33. * @param task 任务对象
  34. * @return
  35. */
  36. @PostMapping(value = HealthBankMapping.healthBank.createTask)
  37. @ApiOperation(value = "添加任务")
  38. public Envelop<Boolean> assigningTask(@ApiParam(name = "task",value = "健康任务JSON")
  39. @RequestParam(value = "task",required = true)String task){
  40. try {
  41. TaskDO taskDO = toEntity(task,TaskDO.class);
  42. return service.insert(taskDO);
  43. }catch (Exception e){
  44. e.printStackTrace();
  45. tracer.getCurrentSpan().logEvent(e.getMessage());
  46. return Envelop.getError(e.getMessage());
  47. }
  48. }
  49. /**
  50. * 查询任务
  51. *
  52. * @param task 任务对象
  53. * @param page 页码
  54. * @param size 分页大小
  55. * @return
  56. */
  57. @PostMapping(value = HealthBankMapping.healthBank.findTask)
  58. @ApiOperation(value = "查询任务")
  59. public Envelop<TaskDO> assigningTask(@ApiParam(name = "task",value = "健康任务JSON")
  60. @RequestParam(value = "task",required = true)String task,
  61. @ApiParam(name = "page", value = "第几页,从1开始")
  62. @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
  63. @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
  64. @RequestParam(value = "size", required = false)Integer size){
  65. try {
  66. TaskDO taskDO = toEntity(task,TaskDO.class);
  67. return service.selectByCondition(taskDO,page,size);
  68. }catch (Exception e){
  69. e.printStackTrace();
  70. tracer.getCurrentSpan().logEvent(e.getMessage());
  71. return Envelop.getError(e.getMessage());
  72. }
  73. }
  74. /**
  75. * 根据编码查询
  76. *
  77. * @param object
  78. * @return
  79. */
  80. @PostMapping(value = HealthBankMapping.healthBank.selectByCode)
  81. @ApiOperation(value = "根据编码查询")
  82. public Envelop<TaskDO> selectByCode(@RequestBody JSONObject object){
  83. try {
  84. JSONArray array = object.getJSONArray("taskCode");
  85. String patientId = object.getString("patientId");
  86. Integer page = object.getInteger("page");
  87. Integer size = object.getInteger("size");
  88. return service.selectByTask(array,patientId,page,size);
  89. }catch (Exception e){
  90. e.printStackTrace();
  91. tracer.getCurrentSpan().logEvent(e.getMessage());
  92. return Envelop.getError(e.getMessage());
  93. }
  94. }
  95. /**
  96. * 更新任务
  97. *
  98. * @param task 任务对象
  99. * @return
  100. */
  101. @PostMapping(value = HealthBankMapping.healthBank.updateTask)
  102. @ApiOperation(value = "更新任务")
  103. public Envelop<Boolean> udpateTask(@ApiParam(name = "task",value = "健康任务JSON")
  104. @RequestParam(value = "task",required = true)String task){
  105. try {
  106. TaskDO taskDO = toEntity(task,TaskDO.class);
  107. return service.update(taskDO);
  108. }catch (Exception e){
  109. e.printStackTrace();
  110. tracer.getCurrentSpan().logEvent(e.getMessage());
  111. return Envelop.getError(e.getMessage());
  112. }
  113. }
  114. /**//**
  115. * patient find health task
  116. *
  117. * @param patientId
  118. * @param page
  119. * @param size
  120. * @return
  121. *//*
  122. @GetMapping(value = HealthBankMapping.healthBank.findTask)
  123. @ApiOperation(value = "查看健康任务")
  124. public Envelop<TaskPatientDetailDO> getTaskByPatient(@ApiParam(name = "patientId",value = "居民Id")
  125. @RequestParam(value = "patientId",required = false)String patientId,
  126. @ApiParam(name = "doctorId",value = "家庭医生Id")
  127. @RequestParam(value = "doctorId",required = false)String doctorId,
  128. @ApiParam(name = "page", value = "第几页,从1开始")
  129. @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
  130. @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
  131. @RequestParam(value = "size", required = false)Integer size){
  132. try{
  133. return service.findTaskByPatient(patientId,doctorId,page,size);
  134. }catch (Exception e){
  135. e.printStackTrace();
  136. tracer.getCurrentSpan().logEvent(e.getMessage());
  137. return Envelop.getError(e.getMessage());
  138. }
  139. }
  140. @PostMapping(value = HealthBankMapping.healthBank.updateTask)
  141. @ApiOperation(value = "居民执行健康任务")
  142. public Envelop<Boolean> updateTask(@ApiParam(name = "taskInfo",value = "健康任务JSON")
  143. @RequestParam(value = "taskInfo",required = true)String taskInfo){
  144. try{
  145. TaskPatientDetailDO taskDetailDO = toEntity(taskInfo,TaskPatientDetailDO.class);
  146. return service.update(taskDetailDO);
  147. }catch (Exception e){
  148. e.printStackTrace();
  149. tracer.getCurrentSpan().logEvent(e.getMessage());
  150. return Envelop.getError(e.getMessage());
  151. }
  152. }*/
  153. }