ActivityController.java 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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.ObjEnvelop;
  8. import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
  9. import com.yihu.jw.rm.health.bank.HealthBankMapping;
  10. import com.yihu.jw.service.ActivityService;
  11. import io.swagger.annotations.Api;
  12. import io.swagger.annotations.ApiOperation;
  13. import io.swagger.annotations.ApiParam;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.cloud.sleuth.Tracer;
  16. import org.springframework.web.bind.annotation.PostMapping;
  17. import org.springframework.web.bind.annotation.RequestMapping;
  18. import org.springframework.web.bind.annotation.RequestParam;
  19. import org.springframework.web.bind.annotation.RestController;
  20. import java.util.ArrayList;
  21. import java.util.List;
  22. /**
  23. * @author wangzhinan
  24. * @create 2018-04-27 14:14
  25. * @desc 健康活动
  26. **/
  27. @RestController
  28. @RequestMapping(HealthBankMapping.api_health_bank_common)
  29. @Api(tags = "健康活动相关操作",description = "健康活动相关操作")
  30. public class ActivityController extends EnvelopRestEndpoint {
  31. @Autowired
  32. private ActivityService service;
  33. @Autowired
  34. private Tracer tracer;
  35. /**
  36. * publish activity
  37. *
  38. * @param activity 活动对象
  39. * @return
  40. */
  41. @PostMapping(value = HealthBankMapping.healthBank.createActivity)
  42. @ApiOperation(value = "发布活动")
  43. public MixEnvelop<Boolean, Boolean> publishActivity(@ApiParam(name = "activity",value = "健康活动JSON")
  44. @RequestParam(value = "activity",required = true)String activity,
  45. @ApiParam(name = "value1",value = "积分JSON")
  46. @RequestParam(value = "value1",required = false)String value1,
  47. @ApiParam(name = "value2",value = "时间规则")
  48. @RequestParam(value = "value2",required = false)String value2,
  49. @ApiParam(name = "value3",value = "兑奖规则")
  50. @RequestParam(value = "value3",required = false)String value3){
  51. try {
  52. ActivityDO activityDO = toEntity(activity,ActivityDO.class);
  53. return service.insert(activityDO,value1,value2,value3);
  54. }catch (Exception e){
  55. e.printStackTrace();
  56. tracer.getCurrentSpan().logEvent(e.getMessage());
  57. return MixEnvelop.getError(e.getMessage());
  58. }
  59. }
  60. /**
  61. * find health activity
  62. *
  63. * @param activity 活动对象
  64. * @param page 页码
  65. * @param size 分页大小
  66. * @return
  67. */
  68. @PostMapping(value = HealthBankMapping.healthBank.findActivity)
  69. @ApiOperation(value = "查看健康活动")
  70. public MixEnvelop<ActivityDO, ActivityDO> getActivity(@ApiParam(name = "activity",value = "健康活动JSON")
  71. @RequestParam(value = "activity",required = false)String activity,
  72. @ApiParam(name = "page", value = "第几页,从1开始")
  73. @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
  74. @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
  75. @RequestParam(value = "size", required = false)Integer size){
  76. try{
  77. ActivityDO activityDO = toEntity(activity,ActivityDO.class);
  78. return service.findByCondition(activityDO,page,size);
  79. }catch (Exception e){
  80. e.printStackTrace();
  81. tracer.getCurrentSpan().logEvent(e.getMessage());
  82. return MixEnvelop.getError(e.getMessage());
  83. }
  84. }
  85. /**
  86. * out activity
  87. *
  88. * @param activity 活动对象
  89. * @return
  90. */
  91. @PostMapping(value = HealthBankMapping.healthBank.updateActivity)
  92. @ApiOperation(value = "编辑活动")
  93. public MixEnvelop<Boolean, Boolean> outActivity(@ApiParam(name = "activity", value = "健康活动JSON")
  94. @RequestParam(value = "activity", required = true) String activity,
  95. @ApiParam(name = "value1", value = "活动币JSON")
  96. @RequestParam(value = "value1", required = false) String value1,
  97. @ApiParam(name = "value2", value = "活动时间")
  98. @RequestParam(value = "value2", required = false) String value2,
  99. @ApiParam(name = "value3", value = "兑奖设置")
  100. @RequestParam(value = "value3", required = false) String value3) {
  101. try {
  102. ActivityDO activityDO = toEntity(activity, ActivityDO.class);
  103. return service.update(activityDO,value1,value2,value3);
  104. } catch (Exception e) {
  105. e.printStackTrace();
  106. tracer.getCurrentSpan().logEvent(e.getMessage());
  107. return MixEnvelop.getError(e.getMessage());
  108. }
  109. }
  110. /**
  111. * 查看参与的活动
  112. *
  113. * @param activity 活动对象
  114. * @param page 页码
  115. * @param size 分页大小
  116. * @return
  117. */
  118. @PostMapping(value = HealthBankMapping.healthBank.selectByPatient)
  119. @ApiOperation(value = "参与的活动")
  120. public MixEnvelop<ActivityDO, ActivityDO> selectByPatient(@ApiParam(name = "activity",value = "健康活动JSON")
  121. @RequestParam(value = "activity",required = false)String activity,
  122. @ApiParam(name = "page", value = "第几页,从1开始")
  123. @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
  124. @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
  125. @RequestParam(value = "size", required = false)Integer size){
  126. try{
  127. ActivityDO activityDO = toEntity(activity,ActivityDO.class);
  128. return service.selectByPatient(activityDO,page,size);
  129. }catch (Exception e){
  130. e.printStackTrace();
  131. tracer.getCurrentSpan().logEvent(e.getMessage());
  132. return MixEnvelop.getError(e.getMessage());
  133. }
  134. }
  135. /**
  136. * 批量删除数据
  137. *
  138. * @param ids id集合[""]
  139. * @return
  140. */
  141. @PostMapping(value = HealthBankMapping.healthBank.batchActivity)
  142. @ApiOperation(value = "批量删除活动")
  143. public MixEnvelop<Boolean, Boolean> batchDelete(@ApiParam(name="ids",value = "id集合")
  144. @RequestParam(value = "ids",required = false)String ids){
  145. try{
  146. MixEnvelop<Boolean, Boolean> envelop = new MixEnvelop<>();
  147. JSONArray array = JSONArray.parseArray(ids);
  148. List<String> activityIds = new ArrayList<>();
  149. for (int i = 0;i<array.size();i++){
  150. activityIds.add(array.getString(i));
  151. }
  152. service.batchDelete(activityIds);
  153. envelop.setObj(true);
  154. return envelop;
  155. }catch (Exception e){
  156. e.printStackTrace();
  157. tracer.getCurrentSpan().logEvent(e.getMessage());
  158. return MixEnvelop.getError(e.getMessage());
  159. }
  160. }
  161. /**
  162. * 编辑活动:上下线、推荐
  163. *
  164. * @param id
  165. * @param type
  166. * @return
  167. */
  168. @PostMapping(value = HealthBankMapping.healthBank.editActivity)
  169. @ApiOperation(value = "编辑活动:上下线、推荐")
  170. public ObjEnvelop<Boolean> editActivity(
  171. @ApiParam(name = "id", value = "活动id")
  172. @RequestParam(value = "id", required = true) String id,
  173. @ApiParam(name = "type", value = "操作类型:上线:0,下线:2,推荐:3")
  174. @RequestParam(value = "type", required = true) String type) {
  175. try {
  176. ActivityDO activityDO=service.editActivity(id, type);
  177. return ObjEnvelop.getSuccess("操作成功!",activityDO);
  178. } catch (Exception e) {
  179. e.printStackTrace();
  180. tracer.getCurrentSpan().logEvent(e.getMessage());
  181. return ObjEnvelop.getError(e.getMessage());
  182. }
  183. }
  184. }