ActivityController.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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.alibaba.fastjson.JSONObject;
  6. import com.sun.org.apache.xpath.internal.operations.Bool;
  7. import com.yihu.jw.entity.health.bank.ActivityDO;
  8. import com.yihu.jw.restmodel.web.MixEnvelop;
  9. import com.yihu.jw.restmodel.web.ObjEnvelop;
  10. import com.yihu.jw.restmodel.web.PageEnvelop;
  11. import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
  12. import com.yihu.jw.rm.health.bank.HealthBankMapping;
  13. import com.yihu.jw.service.ActivityService;
  14. import com.yihu.jw.util.date.DateUtil;
  15. import io.swagger.annotations.Api;
  16. import io.swagger.annotations.ApiOperation;
  17. import io.swagger.annotations.ApiParam;
  18. import org.apache.commons.lang3.StringUtils;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.cloud.sleuth.Tracer;
  21. import org.springframework.web.bind.annotation.*;
  22. import java.text.SimpleDateFormat;
  23. import java.util.ArrayList;
  24. import java.util.Date;
  25. import java.util.List;
  26. /**
  27. * @author wangzhinan
  28. * @create 2018-04-27 14:14
  29. * @desc 健康活动
  30. **/
  31. @RestController
  32. @RequestMapping(HealthBankMapping.api_health_bank_common)
  33. @Api(tags = "健康活动相关操作",description = "健康活动相关操作")
  34. public class ActivityController extends EnvelopRestEndpoint {
  35. @Autowired
  36. private ActivityService service;
  37. @Autowired
  38. private Tracer tracer;
  39. /**
  40. * publish activity
  41. *
  42. * @param activity 活动对象
  43. * @return
  44. */
  45. @PostMapping(value = HealthBankMapping.healthBank.createActivity)
  46. @ApiOperation(value = "发布活动")
  47. public MixEnvelop<Boolean, Boolean> publishActivity(@ApiParam(name = "activity",value = "健康活动JSON")
  48. @RequestParam(value = "activity",required = true)String activity,
  49. @ApiParam(name = "value1",value = "积分JSON")
  50. @RequestParam(value = "value1",required = false)String value1,
  51. @ApiParam(name = "value2",value = "时间规则")
  52. @RequestParam(value = "value2",required = false)String value2,
  53. @ApiParam(name = "value3",value = "兑奖规则")
  54. @RequestParam(value = "value3",required = false)String value3){
  55. try {
  56. ActivityDO activityDO = toEntity(activity,ActivityDO.class);
  57. return service.insert(activityDO,value1,value2,value3);
  58. }catch (Exception e){
  59. e.printStackTrace();
  60. // tracer.getCurrentSpan().logEvent(e.getMessage());
  61. return MixEnvelop.getError(e.getMessage());
  62. }
  63. }
  64. /**
  65. * find health activity
  66. *
  67. * @param activity 活动对象
  68. * @param page 页码
  69. * @param size 分页大小
  70. * @return
  71. */
  72. @PostMapping(value = HealthBankMapping.healthBank.findActivity)
  73. @ApiOperation(value = "查看健康活动")
  74. public MixEnvelop<ActivityDO, ActivityDO> getActivity(@ApiParam(name = "activity",value = "健康活动JSON")
  75. @RequestParam(value = "activity",required = false)String activity,
  76. @ApiParam(name = "page", value = "第几页,从1开始")
  77. @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
  78. @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
  79. @RequestParam(value = "size", required = false)Integer size){
  80. try{
  81. ActivityDO activityDO = toEntity(activity,ActivityDO.class);
  82. return service.findByCondition(activityDO,page,size);
  83. }catch (Exception e){
  84. e.printStackTrace();
  85. tracer.getCurrentSpan().logEvent(e.getMessage());
  86. return MixEnvelop.getError(e.getMessage());
  87. }
  88. }
  89. /**
  90. * out activity
  91. *
  92. * @param activity 活动对象
  93. * @return
  94. */
  95. @PostMapping(value = HealthBankMapping.healthBank.updateActivity)
  96. @ApiOperation(value = "编辑活动")
  97. public MixEnvelop<Boolean, Boolean> outActivity(@ApiParam(name = "activity", value = "健康活动JSON")
  98. @RequestParam(value = "activity", required = true) String activity,
  99. @ApiParam(name = "value1", value = "活动币JSON")
  100. @RequestParam(value = "value1", required = false) String value1,
  101. @ApiParam(name = "value2", value = "活动时间")
  102. @RequestParam(value = "value2", required = false) String value2,
  103. @ApiParam(name = "value3", value = "兑奖设置")
  104. @RequestParam(value = "value3", required = false) String value3) {
  105. try {
  106. ActivityDO activityDO = toEntity(activity, ActivityDO.class);
  107. return service.update(activityDO,value1,value2,value3);
  108. } catch (Exception e) {
  109. e.printStackTrace();
  110. tracer.getCurrentSpan().logEvent(e.getMessage());
  111. return MixEnvelop.getError(e.getMessage());
  112. }
  113. }
  114. /**
  115. * 查看参与的活动
  116. *
  117. * @param activity 活动对象
  118. * @param page 页码
  119. * @param size 分页大小
  120. * @return
  121. */
  122. @PostMapping(value = HealthBankMapping.healthBank.selectByPatient)
  123. @ApiOperation(value = "参与的活动")
  124. public MixEnvelop<ActivityDO, ActivityDO> selectByPatient(@ApiParam(name = "activity",value = "健康活动JSON")
  125. @RequestParam(value = "activity",required = false)String activity,
  126. @ApiParam(name = "page", value = "第几页,从1开始")
  127. @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
  128. @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
  129. @RequestParam(value = "size", required = false)Integer size){
  130. try{
  131. ActivityDO activityDO = toEntity(activity,ActivityDO.class);
  132. return service.selectByPatient(activityDO,page,size);
  133. }catch (Exception e){
  134. e.printStackTrace();
  135. tracer.getCurrentSpan().logEvent(e.getMessage());
  136. return MixEnvelop.getError(e.getMessage());
  137. }
  138. }
  139. /**
  140. * 批量删除数据
  141. *
  142. * @param ids id集合[""]
  143. * @return
  144. */
  145. @PostMapping(value = HealthBankMapping.healthBank.batchActivity)
  146. @ApiOperation(value = "批量删除活动")
  147. public MixEnvelop<Boolean, Boolean> batchDelete(@ApiParam(name="ids",value = "id集合")
  148. @RequestParam(value = "ids",required = false)String ids){
  149. try{
  150. MixEnvelop<Boolean, Boolean> envelop = new MixEnvelop<>();
  151. JSONArray array = JSONArray.parseArray(ids);
  152. List<String> activityIds = new ArrayList<>();
  153. for (int i = 0;i<array.size();i++){
  154. activityIds.add(array.getString(i));
  155. }
  156. service.batchDelete(activityIds);
  157. envelop.setObj(true);
  158. return envelop;
  159. }catch (Exception e){
  160. e.printStackTrace();
  161. tracer.getCurrentSpan().logEvent(e.getMessage());
  162. return MixEnvelop.getError(e.getMessage());
  163. }
  164. }
  165. /**
  166. * 获取活动排行
  167. *
  168. * @param activityId
  169. * @param patient
  170. * @param page
  171. * @param size
  172. * @return
  173. */
  174. @PostMapping(value = HealthBankMapping.healthBank.selectActivityRanking)
  175. @ApiOperation(value = "获取活动排行")
  176. public MixEnvelop<JSONObject, JSONObject> selectActivityRanking(@ApiParam(name="activityId",value = "活动id")
  177. @RequestParam(value = "activityId",required = false)String activityId,
  178. @ApiParam(name="patient",value = "居民id")
  179. @RequestParam(value = "patient",required = false)String patient,
  180. @ApiParam(name = "page", value = "第几页,从1开始")
  181. @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
  182. @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
  183. @RequestParam(value = "size", required = false)Integer size,
  184. @ApiParam(name="street",value = "街道")
  185. @RequestParam(value = "street",required = false)String street,
  186. @ApiParam(name="town",value = "区")
  187. @RequestParam(value = "town",required = false)String town){
  188. try{
  189. return service.selectActivityRanking(activityId,patient,page,size,street,town);
  190. }catch (Exception e){
  191. e.printStackTrace();
  192. tracer.getCurrentSpan().logEvent(e.getMessage());
  193. return MixEnvelop.getError(e.getMessage());
  194. }
  195. }
  196. /**
  197. * 删除数据
  198. *
  199. * @param id 活动id
  200. * @return
  201. */
  202. @PostMapping(value = HealthBankMapping.healthBank.daleteActivity)
  203. @ApiOperation(value = "删除活动")
  204. public MixEnvelop<Boolean, Boolean> daleteActivity(@ApiParam(name="id",value = "id集合")
  205. @RequestParam(value = "id",required = false)String id){
  206. try{
  207. MixEnvelop<Boolean, Boolean> envelop = new MixEnvelop<>();
  208. service.daleteActivity(id);
  209. envelop.setObj(true);
  210. return envelop;
  211. }catch (Exception e){
  212. e.printStackTrace();
  213. tracer.getCurrentSpan().logEvent(e.getMessage());
  214. return MixEnvelop.getError(e.getMessage());
  215. }
  216. }
  217. /**
  218. * 编辑活动:上下线、推荐
  219. *
  220. * @param id
  221. * @param type
  222. * @return
  223. */
  224. @PostMapping(value = HealthBankMapping.healthBank.editActivity)
  225. @ApiOperation(value = "编辑活动:上下线、推荐")
  226. public ObjEnvelop<ActivityDO> editActivity(
  227. @ApiParam(name = "id", value = "活动id")
  228. @RequestParam(value = "id", required = true) String id,
  229. @ApiParam(name = "type", value = "操作类型:上线:0,下线:2,推荐:3,取消推荐:4")
  230. @RequestParam(value = "type", required = true) String type) {
  231. try {
  232. ActivityDO activityDO=service.editActivity(id, type);
  233. return ObjEnvelop.getSuccess("操作成功!",activityDO);
  234. } catch (Exception e) {
  235. e.printStackTrace();
  236. // tracer.getCurrentSpan().logEvent(e.getMessage());
  237. return ObjEnvelop.getError(e.getMessage());
  238. }
  239. }
  240. /**
  241. * 编辑活动:上下线、推荐
  242. *
  243. * @param id
  244. * @return
  245. */
  246. @PostMapping(value = HealthBankMapping.healthBank.findActivityById)
  247. @ApiOperation(value = "根据id获取活动详情+活动规则")
  248. public ObjEnvelop<JSONObject> findActivityById(
  249. @ApiParam(name = "id", value = "活动id")
  250. @RequestParam(value = "id", required = true) String id) {
  251. try {
  252. JSONObject activityDO=service.findActivityById(id);
  253. return ObjEnvelop.getSuccess("获取成功!",activityDO);
  254. } catch (Exception e) {
  255. e.printStackTrace();
  256. tracer.getCurrentSpan().logEvent(e.getMessage());
  257. return ObjEnvelop.getError("获取失败!"+e.getMessage());
  258. }
  259. }
  260. @PostMapping(value = HealthBankMapping.healthBank.pageActivity)
  261. @ApiOperation(value = "分页查询活动")
  262. public PageEnvelop<ActivityDO> pageActivity(@ApiParam(name = "type", value = "活动类型")
  263. @RequestParam(value = "type", required = false) String type,
  264. @ApiParam(name = "status", value = "活动状态:1上线,2下线")
  265. @RequestParam(value = "status", required = false) String status,
  266. @ApiParam(name = "crowdType", value = "人群类型:1:签约居民、2平台用户")
  267. @RequestParam(value = "crowdType", required = false) String crowdType,
  268. @ApiParam(name = "releaseTime", value = "下线开始时间")
  269. @RequestParam(value = "releaseTime", required = false) String releaseTime,
  270. @ApiParam(name = "activityOfflineTime", value = "下线结束时间")
  271. @RequestParam(value = "activityOfflineTime", required = false) String activityOfflineTime,
  272. @ApiParam(name = "filter", value = "活动名、发布机构、面向范围名称")
  273. @RequestParam(value = "filter", required = false) String filter,
  274. @ApiParam(name = "page", value = "第几页,从1开始")
  275. @RequestParam(value = "page", defaultValue = "1", required = false) Integer page,
  276. @ApiParam(name = "size", defaultValue = "10", value = ",每页分页大小")
  277. @RequestParam(value = "size", required = false) Integer size) {
  278. try{
  279. StringBuffer stringBuffer=new StringBuffer();
  280. stringBuffer.append("delFlag=1;");
  281. if (StringUtils.isNotEmpty(type)) {
  282. stringBuffer.append("type=").append(type).append(";");
  283. }
  284. if (StringUtils.isNotEmpty(filter)) {
  285. stringBuffer.append("title?").append(filter).append(" g1;").append("organizer?").append(filter).append(" g1;").append("areaName?").append(filter).append(" g1;");
  286. }
  287. if (null != status && "2".equals(status) ) {
  288. stringBuffer.append("status=-1,2;");
  289. } else if (null != status && "1".equals(status) ) {
  290. stringBuffer.append("status=0,1;");
  291. }
  292. if(null!=crowdType&&StringUtils.isNotBlank(crowdType)){
  293. stringBuffer.append("crowdType="+crowdType+";");
  294. }
  295. if(StringUtils.isNotBlank(releaseTime)){
  296. stringBuffer.append("activityOfflineTime>="+releaseTime+" 00:00:00;");
  297. }
  298. if(StringUtils.isNotBlank(activityOfflineTime)){
  299. stringBuffer.append("activityOfflineTime<="+ activityOfflineTime+" 59:59:59;");
  300. }
  301. String sorts="-createTime";
  302. List<ActivityDO> activityDOList = service.search("", stringBuffer.toString(), sorts, page, size);
  303. int count = (int) service.getCount(stringBuffer.toString());
  304. return success(activityDOList, count, page, size);
  305. }catch (Exception e){
  306. e.printStackTrace();
  307. tracer.getCurrentSpan().logEvent(e.getMessage());
  308. return PageEnvelop.getError("获取失败"+e.getMessage(),-1);
  309. }
  310. }
  311. /**
  312. * 编辑活动:上下线、推荐
  313. *
  314. * @param type
  315. * @return
  316. */
  317. @PostMapping(value = HealthBankMapping.healthBank.findActivityByType)
  318. @ApiOperation(value = "获取是否存在在线的竞走活动")
  319. public ObjEnvelop<Boolean> findActivityByType(
  320. @ApiParam(name = "type", value = "活动类型")
  321. @RequestParam(value = "type", required = true) String type) {
  322. try {
  323. JSONObject obj=service.findActivityByType(type);
  324. return ObjEnvelop.getSuccess("获取成功!",obj);
  325. } catch (Exception e) {
  326. e.printStackTrace();
  327. tracer.getCurrentSpan().logEvent(e.getMessage());
  328. return ObjEnvelop.getError("获取失败!"+e.getMessage());
  329. }
  330. }
  331. }