TaskDictController.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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.TaskDictDO;
  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.TaskDictService;
  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:42
  21. * @desc 任务字典 Controller
  22. **/
  23. @RestController
  24. @RequestMapping(HealthBankMapping.api_health_bank_common)
  25. @Api(tags = "健康任务字典相关操作",description = "健康任务字典相关操作")
  26. public class TaskDictController extends EnvelopRestController {
  27. @Autowired
  28. private TaskDictService service;
  29. @Autowired
  30. private Tracer tracer;
  31. /**
  32. * 添加任务字典
  33. *
  34. * @param taskDict 任务字典对象
  35. *
  36. * @return
  37. */
  38. @PostMapping(value = HealthBankMapping.healthBank.createTaskDict)
  39. @ApiOperation(value = "添加任务字典")
  40. public Envelop<Boolean> insert(@ApiParam(name = "taskDict",value = "任务字典JSON")
  41. @RequestParam(value = "taskDict",required = true)String taskDict){
  42. try {
  43. TaskDictDO taskDictDO = toEntity(taskDict,TaskDictDO.class);
  44. return service.insert(taskDictDO);
  45. }catch (Exception e){
  46. e.printStackTrace();
  47. tracer.getCurrentSpan().logEvent(e.getMessage());
  48. return Envelop.getError(e.getMessage());
  49. }
  50. }
  51. /**
  52. * 更新任务字典
  53. * @param taskDict 更新任务字典
  54. * @return
  55. */
  56. @PostMapping(value = HealthBankMapping.healthBank.updateTaskDict)
  57. @ApiOperation(value = "更新任务字典")
  58. public Envelop<Boolean> update(@ApiParam(name = "taskDict",value = "任务字典JSON")
  59. @RequestParam(value = "taskDict",required = true)String taskDict){
  60. try {
  61. TaskDictDO taskDictDO = toEntity(taskDict,TaskDictDO.class);
  62. return service.update(taskDictDO);
  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 taskDict 任务字典对象
  73. * @param page 页码
  74. * @param size 分页大小
  75. * @return
  76. */
  77. @PostMapping(value = HealthBankMapping.healthBank.findTaskDict)
  78. @ApiOperation(value = "查询任务字典")
  79. public Envelop<TaskDictDO> select(@ApiParam(name = "taskDict",value = "任务字典JSON")
  80. @RequestParam(value = "taskDict",required = true)String taskDict,
  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. TaskDictDO taskDictDO = toEntity(taskDict,TaskDictDO.class);
  87. return service.selectByCondition(taskDictDO,page,size);
  88. }catch (Exception e){
  89. e.printStackTrace();
  90. tracer.getCurrentSpan().logEvent(e.getMessage());
  91. return Envelop.getError(e.getMessage());
  92. }
  93. }
  94. }