TaskController.java 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. import java.util.ArrayList;
  18. import java.util.List;
  19. /**
  20. * @author wangzhinan
  21. * @create 2018-04-27 9:29
  22. * @desc health blank Controller
  23. **/
  24. @RestController
  25. @RequestMapping(HealthBankMapping.api_health_bank_common)
  26. @Api(tags = "健康任务相关操作",description = "健康银行相关操作")
  27. public class TaskController extends EnvelopRestController {
  28. @Autowired
  29. private TaskService service;
  30. @Autowired
  31. private Tracer tracer;
  32. /**
  33. * 指派任务
  34. *
  35. * @param task 任务对象
  36. * @return
  37. */
  38. @PostMapping(value = HealthBankMapping.healthBank.createTask)
  39. @ApiOperation(value = "添加任务")
  40. public Envelop<Boolean> assigningTask(@ApiParam(name = "task",value = "健康任务JSON")
  41. @RequestParam(value = "task",required = true)String task){
  42. try {
  43. TaskDO taskDO = toEntity(task,TaskDO.class);
  44. return service.insert(taskDO);
  45. }catch (Exception e){
  46. e.printStackTrace();
  47. tracer.getCurrentSpan().logEvent(e.getMessage());
  48. return Envelop.getError(e.getMessage());
  49. }
  50. }
  51. /**
  52. * 查询任务
  53. *
  54. * @param task 任务对象
  55. * @param page 页码
  56. * @param size 分页大小
  57. * @return
  58. */
  59. @PostMapping(value = HealthBankMapping.healthBank.findTask)
  60. @ApiOperation(value = "查询任务")
  61. public Envelop<TaskDO> assigningTask(@ApiParam(name = "task",value = "健康任务JSON")
  62. @RequestParam(value = "task",required = true)String task,
  63. @ApiParam(name = "page", value = "第几页,从1开始")
  64. @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
  65. @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
  66. @RequestParam(value = "size", required = false)Integer size){
  67. try {
  68. TaskDO taskDO = toEntity(task,TaskDO.class);
  69. return service.selectByCondition(taskDO,page,size);
  70. }catch (Exception e){
  71. e.printStackTrace();
  72. tracer.getCurrentSpan().logEvent(e.getMessage());
  73. return Envelop.getError(e.getMessage());
  74. }
  75. }
  76. /**
  77. * 根据编码查询
  78. *
  79. * @param object
  80. * @return
  81. */
  82. @PostMapping(value = HealthBankMapping.healthBank.selectByCode)
  83. @ApiOperation(value = "根据编码查询")
  84. public Envelop<TaskDO> selectByCode(@RequestBody JSONObject object){
  85. try {
  86. JSONArray array = object.getJSONArray("taskCode");
  87. String patientId = object.getString("patientId");
  88. Integer page = object.getInteger("page");
  89. Integer size = object.getInteger("size");
  90. return service.selectByTask(array,patientId,page,size);
  91. }catch (Exception e){
  92. e.printStackTrace();
  93. tracer.getCurrentSpan().logEvent(e.getMessage());
  94. return Envelop.getError(e.getMessage());
  95. }
  96. }
  97. /**
  98. * 更新任务
  99. *
  100. * @param task 任务对象
  101. * @return
  102. */
  103. @PostMapping(value = HealthBankMapping.healthBank.updateTask)
  104. @ApiOperation(value = "更新任务")
  105. public Envelop<Boolean> udpateTask(@ApiParam(name = "task",value = "健康任务JSON")
  106. @RequestParam(value = "task",required = true)String task){
  107. try {
  108. TaskDO taskDO = toEntity(task,TaskDO.class);
  109. return service.update(taskDO);
  110. }catch (Exception e){
  111. e.printStackTrace();
  112. tracer.getCurrentSpan().logEvent(e.getMessage());
  113. return Envelop.getError(e.getMessage());
  114. }
  115. }
  116. /**
  117. * 删除任务
  118. *
  119. * @param ids id集合[]
  120. * @return
  121. */
  122. @PostMapping(value = HealthBankMapping.healthBank.batchTask)
  123. @ApiOperation(value = "批量删除任务")
  124. public Envelop<Boolean> batchDelete(@ApiParam(name="ids",value = "id集合[]")
  125. @RequestParam(value = "ids",required = false)String ids){
  126. try{
  127. Envelop<Boolean> envelop = new Envelop<>();
  128. JSONArray array = JSONArray.parseArray(ids);
  129. List<String> taskIds = new ArrayList<>();
  130. for (int i = 0;i<array.size();i++){
  131. taskIds.add(array.getString(i));
  132. }
  133. service.batchDelete(taskIds);
  134. envelop.setObj(true);
  135. return envelop;
  136. }catch (Exception e){
  137. e.printStackTrace();
  138. tracer.getCurrentSpan().logEvent(e.getMessage());
  139. return Envelop.getError(e.getMessage());
  140. }
  141. }
  142. /**//**
  143. * patient find health task
  144. *
  145. * @param patientId
  146. * @param page
  147. * @param size
  148. * @return
  149. *//*
  150. @GetMapping(value = HealthBankMapping.healthBank.findTask)
  151. @ApiOperation(value = "查看健康任务")
  152. public Envelop<TaskPatientDetailDO> getTaskByPatient(@ApiParam(name = "patientId",value = "居民Id")
  153. @RequestParam(value = "patientId",required = false)String patientId,
  154. @ApiParam(name = "doctorId",value = "家庭医生Id")
  155. @RequestParam(value = "doctorId",required = false)String doctorId,
  156. @ApiParam(name = "page", value = "第几页,从1开始")
  157. @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
  158. @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
  159. @RequestParam(value = "size", required = false)Integer size){
  160. try{
  161. return service.findTaskByPatient(patientId,doctorId,page,size);
  162. }catch (Exception e){
  163. e.printStackTrace();
  164. tracer.getCurrentSpan().logEvent(e.getMessage());
  165. return Envelop.getError(e.getMessage());
  166. }
  167. }
  168. @PostMapping(value = HealthBankMapping.healthBank.updateTask)
  169. @ApiOperation(value = "居民执行健康任务")
  170. public Envelop<Boolean> updateTask(@ApiParam(name = "taskInfo",value = "健康任务JSON")
  171. @RequestParam(value = "taskInfo",required = true)String taskInfo){
  172. try{
  173. TaskPatientDetailDO taskDetailDO = toEntity(taskInfo,TaskPatientDetailDO.class);
  174. return service.update(taskDetailDO);
  175. }catch (Exception e){
  176. e.printStackTrace();
  177. tracer.getCurrentSpan().logEvent(e.getMessage());
  178. return Envelop.getError(e.getMessage());
  179. }
  180. }*/
  181. }