TaskRuleController.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package com.yihu.jw.controller;/**
  2. * Created by nature of king on 2018/6/8.
  3. */
  4. import com.yihu.jw.entity.health.bank.TaskRuleDO;
  5. import com.yihu.jw.restmodel.common.Envelop;
  6. import com.yihu.jw.restmodel.common.EnvelopRestController;
  7. import com.yihu.jw.rm.health.bank.HealthBankMapping;
  8. import com.yihu.jw.service.TaskRuleService;
  9. import io.swagger.annotations.Api;
  10. import io.swagger.annotations.ApiOperation;
  11. import io.swagger.annotations.ApiParam;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.cloud.sleuth.Tracer;
  14. import org.springframework.web.bind.annotation.PostMapping;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import org.springframework.web.bind.annotation.RequestParam;
  17. import org.springframework.web.bind.annotation.RestController;
  18. /**
  19. * @author wangzhinan
  20. * @create 2018-06-08 16:25
  21. * @desc 任务规则 controller
  22. **/
  23. @RestController
  24. @RequestMapping(HealthBankMapping.api_health_bank_common)
  25. @Api(tags = "健康任务规则相关操作",description = "健康任务规则相关操作")
  26. public class TaskRuleController extends EnvelopRestController {
  27. @Autowired
  28. private TaskRuleService service;
  29. @Autowired
  30. private Tracer tracer;
  31. /**
  32. * 添加任务规则
  33. *
  34. * @param taskRule 任务规则对象
  35. * @return
  36. */
  37. @PostMapping(value = HealthBankMapping.healthBank.createTaskRule)
  38. @ApiOperation(value = "添加任务规则")
  39. public Envelop<Boolean> insert(@ApiParam(name = "taskRule",value = "健康任务规则JSON")
  40. @RequestParam(value = "taskRule",required = true)String taskRule){
  41. try {
  42. TaskRuleDO taskRuleDO = toEntity(taskRule,TaskRuleDO.class);
  43. return service.insert(taskRuleDO);
  44. }catch (Exception e){
  45. e.printStackTrace();
  46. tracer.getCurrentSpan().logEvent(e.getMessage());
  47. return Envelop.getError(e.getMessage());
  48. }
  49. }
  50. /**
  51. * 更新任务规则
  52. *
  53. * @param taskRule 任务规则对象
  54. * @return
  55. */
  56. @PostMapping(value = HealthBankMapping.healthBank.updateTaskRule)
  57. @ApiOperation(value = "更新任务规则")
  58. public Envelop<Boolean> update(@ApiParam(name = "taskRule",value = "健康任务规则JSON")
  59. @RequestParam(value = "taskRule",required = true)String taskRule){
  60. try {
  61. TaskRuleDO taskRuleDO = toEntity(taskRule,TaskRuleDO.class);
  62. return service.update(taskRuleDO);
  63. }catch (Exception e){
  64. e.printStackTrace();
  65. tracer.getCurrentSpan().logEvent(e.getMessage());
  66. return Envelop.getError(e.getMessage());
  67. }
  68. }
  69. /**
  70. * 查看任务规则
  71. *
  72. * @param taskRule 任务规则对象
  73. * @param page 页码
  74. * @param size 分页大小
  75. * @return
  76. */
  77. @PostMapping(value = HealthBankMapping.healthBank.findTaskRule)
  78. @ApiOperation(value = "查询任务规则")
  79. public Envelop<TaskRuleDO> select(@ApiParam(name = "taskRule",value = "健康任务规则JSON")
  80. @RequestParam(value = "taskRule",required = true)String taskRule,
  81. @ApiParam(name = "page", value = "第几页,从1开始")
  82. @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
  83. @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
  84. @RequestParam(value = "size", required = false)Integer size){
  85. try {
  86. TaskRuleDO taskRuleDO = toEntity(taskRule,TaskRuleDO.class);
  87. return service.selectByCondition(taskRuleDO,page,size);
  88. }catch (Exception e){
  89. e.printStackTrace();
  90. tracer.getCurrentSpan().logEvent(e.getMessage());
  91. return Envelop.getError(e.getMessage());
  92. }
  93. }
  94. }