TaskRuleController.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package com.yihu.jw.controller;/**
  2. * Created by nature of king on 2018/6/8.
  3. */
  4. import com.alibaba.fastjson.JSONArray;
  5. import com.yihu.jw.entity.health.bank.TaskRuleDO;
  6. import com.yihu.jw.restmodel.common.Envelop;
  7. import com.yihu.jw.restmodel.common.EnvelopRestController;
  8. import com.yihu.jw.rm.health.bank.HealthBankMapping;
  9. import com.yihu.jw.service.TaskRuleService;
  10. import io.swagger.annotations.Api;
  11. import io.swagger.annotations.ApiOperation;
  12. import io.swagger.annotations.ApiParam;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.cloud.sleuth.Tracer;
  15. import org.springframework.web.bind.annotation.PostMapping;
  16. import org.springframework.web.bind.annotation.RequestMapping;
  17. import org.springframework.web.bind.annotation.RequestParam;
  18. import org.springframework.web.bind.annotation.RestController;
  19. import java.util.ArrayList;
  20. import java.util.List;
  21. /**
  22. * @author wangzhinan
  23. * @create 2018-06-08 16:25
  24. * @desc 任务规则 controller
  25. **/
  26. @RestController
  27. @RequestMapping(HealthBankMapping.api_health_bank_common)
  28. @Api(tags = "健康任务规则相关操作",description = "健康任务规则相关操作")
  29. public class TaskRuleController extends EnvelopRestController {
  30. @Autowired
  31. private TaskRuleService service;
  32. @Autowired
  33. private Tracer tracer;
  34. /**
  35. * 添加任务规则
  36. *
  37. * @param taskRule 任务规则对象
  38. * @return
  39. */
  40. @PostMapping(value = HealthBankMapping.healthBank.createTaskRule)
  41. @ApiOperation(value = "添加任务规则")
  42. public Envelop<Boolean> insert(@ApiParam(name = "taskRule",value = "健康任务规则JSON")
  43. @RequestParam(value = "taskRule",required = true)String taskRule){
  44. try {
  45. TaskRuleDO taskRuleDO = toEntity(taskRule,TaskRuleDO.class);
  46. return service.insert(taskRuleDO);
  47. }catch (Exception e){
  48. e.printStackTrace();
  49. tracer.getCurrentSpan().logEvent(e.getMessage());
  50. return Envelop.getError(e.getMessage());
  51. }
  52. }
  53. /**
  54. * 更新任务规则
  55. *
  56. * @param taskRule 任务规则对象
  57. * @return
  58. */
  59. @PostMapping(value = HealthBankMapping.healthBank.updateTaskRule)
  60. @ApiOperation(value = "更新任务规则")
  61. public Envelop<Boolean> update(@ApiParam(name = "taskRule",value = "健康任务规则JSON")
  62. @RequestParam(value = "taskRule",required = true)String taskRule){
  63. try {
  64. TaskRuleDO taskRuleDO = toEntity(taskRule,TaskRuleDO.class);
  65. return service.update(taskRuleDO);
  66. }catch (Exception e){
  67. e.printStackTrace();
  68. tracer.getCurrentSpan().logEvent(e.getMessage());
  69. return Envelop.getError(e.getMessage());
  70. }
  71. }
  72. /**
  73. * 查看任务规则
  74. *
  75. * @param taskRule 任务规则对象
  76. * @param page 页码
  77. * @param size 分页大小
  78. * @return
  79. */
  80. @PostMapping(value = HealthBankMapping.healthBank.findTaskRule)
  81. @ApiOperation(value = "查询任务规则")
  82. public Envelop<TaskRuleDO> select(@ApiParam(name = "taskRule",value = "健康任务规则JSON")
  83. @RequestParam(value = "taskRule",required = true)String taskRule,
  84. @ApiParam(name = "page", value = "第几页,从1开始")
  85. @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
  86. @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
  87. @RequestParam(value = "size", required = false)Integer size){
  88. try {
  89. TaskRuleDO taskRuleDO = toEntity(taskRule,TaskRuleDO.class);
  90. return service.selectByCondition(taskRuleDO,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 ids []
  101. * @return
  102. */
  103. @PostMapping(value = HealthBankMapping.healthBank.batchTaskRule)
  104. @ApiOperation(value = "批量删除任务规则")
  105. public Envelop<Boolean> batchDelete(@ApiParam(name="ids",value = "id集合[]")
  106. @RequestParam(value = "ids",required = false)String ids){
  107. try{
  108. Envelop<Boolean> envelop = new Envelop<>();
  109. JSONArray array = JSONArray.parseArray(ids);
  110. List<String> taskRuleIds = new ArrayList<>();
  111. for (int i = 0;i<array.size();i++){
  112. taskRuleIds.add(array.getString(i));
  113. }
  114. service.batchDelete(taskRuleIds);
  115. envelop.setObj(true);
  116. return envelop;
  117. }catch (Exception e){
  118. e.printStackTrace();
  119. tracer.getCurrentSpan().logEvent(e.getMessage());
  120. return Envelop.getError(e.getMessage());
  121. }
  122. }
  123. }