ActivityController.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package com.yihu.jw.controller;/**
  2. * Created by nature of king on 2018/4/27.
  3. */
  4. import com.yihu.jw.entity.health.bank.ActivityDO;
  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.ActivityService;
  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.*;
  15. /**
  16. * @author wangzhinan
  17. * @create 2018-04-27 14:14
  18. * @desc 健康活动
  19. **/
  20. @RestController
  21. @RequestMapping(HealthBankMapping.api_health_bank_common)
  22. @Api(tags = "健康活动相关操作",description = "健康活动相关操作")
  23. public class ActivityController extends EnvelopRestController{
  24. @Autowired
  25. private ActivityService service;
  26. @Autowired
  27. private Tracer tracer;
  28. /**
  29. * publish activity
  30. *
  31. * @param activity 活动对象
  32. * @return
  33. */
  34. @PostMapping(value = HealthBankMapping.healthBank.createActivity)
  35. @ApiOperation(value = "发布活动")
  36. public Envelop<Boolean> publishActivity(@ApiParam(name = "activity",value = "健康活动JSON")
  37. @RequestParam(value = "activity",required = true)String activity){
  38. try {
  39. ActivityDO activityDO = toEntity(activity,ActivityDO.class);
  40. return service.insert(activityDO);
  41. }catch (Exception e){
  42. e.printStackTrace();
  43. tracer.getCurrentSpan().logEvent(e.getMessage());
  44. return Envelop.getError(e.getMessage());
  45. }
  46. }
  47. /**
  48. * find health activity
  49. *
  50. * @param activity 活动对象
  51. * @param page 页码
  52. * @param size 分页大小
  53. * @return
  54. */
  55. @PostMapping(value = HealthBankMapping.healthBank.findActivity)
  56. @ApiOperation(value = "查看健康活动")
  57. public Envelop<ActivityDO> getActivity(@ApiParam(name = "activity",value = "健康活动JSON")
  58. @RequestParam(value = "activity",required = false)String activity,
  59. @ApiParam(name = "page", value = "第几页,从1开始")
  60. @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
  61. @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
  62. @RequestParam(value = "size", required = false)Integer size){
  63. try{
  64. ActivityDO activityDO = toEntity(activity,ActivityDO.class);
  65. return service.findByCondition(activityDO,page,size);
  66. }catch (Exception e){
  67. e.printStackTrace();
  68. tracer.getCurrentSpan().logEvent(e.getMessage());
  69. return Envelop.getError(e.getMessage());
  70. }
  71. }
  72. /**
  73. * out activity
  74. *
  75. * @param activity 活动对象
  76. * @return
  77. */
  78. @PostMapping(value = HealthBankMapping.healthBank.updateActivity)
  79. @ApiOperation(value = "下架活动")
  80. public Envelop<Boolean> outActivity(@ApiParam(name = "activity",value = "健康活动JSON")
  81. @RequestParam(value = "activity",required = true)String activity){
  82. try {
  83. ActivityDO activityDO = toEntity(activity,ActivityDO.class);
  84. return service.update(activityDO);
  85. }catch (Exception e){
  86. e.printStackTrace();
  87. tracer.getCurrentSpan().logEvent(e.getMessage());
  88. return Envelop.getError(e.getMessage());
  89. }
  90. }
  91. }