ActivityController.java 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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.web.MixEnvelop;
  7. import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
  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 EnvelopRestEndpoint {
  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 MixEnvelop<Boolean, Boolean> publishActivity(@ApiParam(name = "activity",value = "健康活动JSON")
  43. @RequestParam(value = "activity",required = true)String activity,
  44. @ApiParam(name = "value1",value = "积分JSON")
  45. @RequestParam(value = "value1",required = false)String value1,
  46. @ApiParam(name = "value2",value = "时间规则")
  47. @RequestParam(value = "value2",required = false)String value2,
  48. @ApiParam(name = "value3",value = "兑奖规则")
  49. @RequestParam(value = "value3",required = false)String value3){
  50. try {
  51. ActivityDO activityDO = toEntity(activity,ActivityDO.class);
  52. return service.insert(activityDO,value1,value2,value3);
  53. }catch (Exception e){
  54. e.printStackTrace();
  55. tracer.getCurrentSpan().logEvent(e.getMessage());
  56. return MixEnvelop.getError(e.getMessage());
  57. }
  58. }
  59. /**
  60. * find health activity
  61. *
  62. * @param activity 活动对象
  63. * @param page 页码
  64. * @param size 分页大小
  65. * @return
  66. */
  67. @PostMapping(value = HealthBankMapping.healthBank.findActivity)
  68. @ApiOperation(value = "查看健康活动")
  69. public MixEnvelop<ActivityDO, ActivityDO> getActivity(@ApiParam(name = "activity",value = "健康活动JSON")
  70. @RequestParam(value = "activity",required = false)String activity,
  71. @ApiParam(name = "page", value = "第几页,从1开始")
  72. @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
  73. @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
  74. @RequestParam(value = "size", required = false)Integer size){
  75. try{
  76. ActivityDO activityDO = toEntity(activity,ActivityDO.class);
  77. return service.findByCondition(activityDO,page,size);
  78. }catch (Exception e){
  79. e.printStackTrace();
  80. tracer.getCurrentSpan().logEvent(e.getMessage());
  81. return MixEnvelop.getError(e.getMessage());
  82. }
  83. }
  84. /**
  85. * out activity
  86. *
  87. * @param activity 活动对象
  88. * @return
  89. */
  90. @PostMapping(value = HealthBankMapping.healthBank.updateActivity)
  91. @ApiOperation(value = "编辑活动")
  92. public MixEnvelop<Boolean, Boolean> outActivity(@ApiParam(name = "activity", value = "健康活动JSON")
  93. @RequestParam(value = "activity", required = true) String activity,
  94. @ApiParam(name = "value1", value = "活动币JSON")
  95. @RequestParam(value = "value1", required = false) String value1,
  96. @ApiParam(name = "value2", value = "活动时间")
  97. @RequestParam(value = "value2", required = false) String value2,
  98. @ApiParam(name = "value3", value = "兑奖设置")
  99. @RequestParam(value = "value3", required = false) String value3) {
  100. try {
  101. ActivityDO activityDO = toEntity(activity, ActivityDO.class);
  102. return service.update(activityDO,value1,value2,value3);
  103. } catch (Exception e) {
  104. e.printStackTrace();
  105. tracer.getCurrentSpan().logEvent(e.getMessage());
  106. return MixEnvelop.getError(e.getMessage());
  107. }
  108. }
  109. /**
  110. * 查看参与的活动
  111. *
  112. * @param activity 活动对象
  113. * @param page 页码
  114. * @param size 分页大小
  115. * @return
  116. */
  117. @PostMapping(value = HealthBankMapping.healthBank.selectByPatient)
  118. @ApiOperation(value = "参与的活动")
  119. public MixEnvelop<ActivityDO, ActivityDO> selectByPatient(@ApiParam(name = "activity",value = "健康活动JSON")
  120. @RequestParam(value = "activity",required = false)String activity,
  121. @ApiParam(name = "page", value = "第几页,从1开始")
  122. @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
  123. @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
  124. @RequestParam(value = "size", required = false)Integer size){
  125. try{
  126. ActivityDO activityDO = toEntity(activity,ActivityDO.class);
  127. return service.selectByPatient(activityDO,page,size);
  128. }catch (Exception e){
  129. e.printStackTrace();
  130. tracer.getCurrentSpan().logEvent(e.getMessage());
  131. return MixEnvelop.getError(e.getMessage());
  132. }
  133. }
  134. /**
  135. * 批量删除数据
  136. *
  137. * @param ids id集合[""]
  138. * @return
  139. */
  140. @PostMapping(value = HealthBankMapping.healthBank.batchActivity)
  141. @ApiOperation(value = "批量删除活动")
  142. public MixEnvelop<Boolean, Boolean> batchDelete(@ApiParam(name="ids",value = "id集合")
  143. @RequestParam(value = "ids",required = false)String ids){
  144. try{
  145. MixEnvelop<Boolean, Boolean> envelop = new MixEnvelop<>();
  146. JSONArray array = JSONArray.parseArray(ids);
  147. List<String> activityIds = new ArrayList<>();
  148. for (int i = 0;i<array.size();i++){
  149. activityIds.add(array.getString(i));
  150. }
  151. service.batchDelete(activityIds);
  152. envelop.setObj(true);
  153. return envelop;
  154. }catch (Exception e){
  155. e.printStackTrace();
  156. tracer.getCurrentSpan().logEvent(e.getMessage());
  157. return MixEnvelop.getError(e.getMessage());
  158. }
  159. }
  160. }