ActivityController.java 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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.yihu.jw.entity.health.bank.ActivityDO;
  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.ActivityService;
  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-04-27 14:14
  24. * @desc 健康活动
  25. **/
  26. @RestController
  27. @RequestMapping(HealthBankMapping.api_health_bank_common)
  28. @Api(tags = "健康活动相关操作",description = "健康活动相关操作")
  29. public class ActivityController extends EnvelopRestController{
  30. @Autowired
  31. private ActivityService service;
  32. @Autowired
  33. private Tracer tracer;
  34. /**
  35. * publish activity
  36. *
  37. * @param activity 活动对象
  38. * @return
  39. */
  40. @PostMapping(value = HealthBankMapping.healthBank.createActivity)
  41. @ApiOperation(value = "发布活动")
  42. public Envelop<Boolean> publishActivity(@ApiParam(name = "activity",value = "健康活动JSON")
  43. @RequestParam(value = "activity",required = true)String activity){
  44. try {
  45. ActivityDO activityDO = toEntity(activity,ActivityDO.class);
  46. return service.insert(activityDO);
  47. }catch (Exception e){
  48. e.printStackTrace();
  49. tracer.getCurrentSpan().logEvent(e.getMessage());
  50. return Envelop.getError(e.getMessage());
  51. }
  52. }
  53. /**
  54. * find health activity
  55. *
  56. * @param activity 活动对象
  57. * @param page 页码
  58. * @param size 分页大小
  59. * @return
  60. */
  61. @PostMapping(value = HealthBankMapping.healthBank.findActivity)
  62. @ApiOperation(value = "查看健康活动")
  63. public Envelop<ActivityDO> getActivity(@ApiParam(name = "activity",value = "健康活动JSON")
  64. @RequestParam(value = "activity",required = false)String activity,
  65. @ApiParam(name = "page", value = "第几页,从1开始")
  66. @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
  67. @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
  68. @RequestParam(value = "size", required = false)Integer size){
  69. try{
  70. ActivityDO activityDO = toEntity(activity,ActivityDO.class);
  71. return service.findByCondition(activityDO,page,size);
  72. }catch (Exception e){
  73. e.printStackTrace();
  74. tracer.getCurrentSpan().logEvent(e.getMessage());
  75. return Envelop.getError(e.getMessage());
  76. }
  77. }
  78. /**
  79. * out activity
  80. *
  81. * @param activity 活动对象
  82. * @return
  83. */
  84. @PostMapping(value = HealthBankMapping.healthBank.updateActivity)
  85. @ApiOperation(value = "下架活动")
  86. public Envelop<Boolean> outActivity(@ApiParam(name = "activity",value = "健康活动JSON")
  87. @RequestParam(value = "activity",required = true)String activity){
  88. try {
  89. ActivityDO activityDO = toEntity(activity,ActivityDO.class);
  90. return service.update(activityDO);
  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 activity 活动对象
  101. * @param page 页码
  102. * @param size 分页大小
  103. * @return
  104. */
  105. @PostMapping(value = HealthBankMapping.healthBank.selectByPatient)
  106. @ApiOperation(value = "参与的活动")
  107. public Envelop<ActivityDO> selectByPatient(@ApiParam(name = "activity",value = "健康活动JSON")
  108. @RequestParam(value = "activity",required = false)String activity,
  109. @ApiParam(name = "page", value = "第几页,从1开始")
  110. @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
  111. @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
  112. @RequestParam(value = "size", required = false)Integer size){
  113. try{
  114. ActivityDO activityDO = toEntity(activity,ActivityDO.class);
  115. return service.selectByPatient(activityDO,page,size);
  116. }catch (Exception e){
  117. e.printStackTrace();
  118. tracer.getCurrentSpan().logEvent(e.getMessage());
  119. return Envelop.getError(e.getMessage());
  120. }
  121. }
  122. /**
  123. * 批量删除数据
  124. *
  125. * @param ids id集合[""]
  126. * @return
  127. */
  128. @PostMapping(value = HealthBankMapping.healthBank.batchActivity)
  129. @ApiOperation(value = "批量删除活动")
  130. public Envelop<Boolean> batchDelete(@ApiParam(name="ids",value = "id集合")
  131. @RequestParam(value = "ids",required = false)String ids){
  132. try{
  133. Envelop<Boolean> envelop = new Envelop<>();
  134. JSONArray array = JSONArray.parseArray(ids);
  135. List<String> activityIds = new ArrayList<>();
  136. for (int i = 0;i<array.size();i++){
  137. activityIds.add(array.getString(i));
  138. }
  139. service.batchDelete(activityIds);
  140. envelop.setObj(true);
  141. return envelop;
  142. }catch (Exception e){
  143. e.printStackTrace();
  144. tracer.getCurrentSpan().logEvent(e.getMessage());
  145. return Envelop.getError(e.getMessage());
  146. }
  147. }
  148. }