ActivityController.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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 = "registrationNumber",value = "报名人数")
  50. @RequestParam(value = "registrationNumber",required = false)String registrationNumber,
  51. @ApiParam(name = "value1",value = "积分JSON")
  52. @RequestParam(value = "value1",required = false)String value1,
  53. @ApiParam(name = "value2",value = "时间规则")
  54. @RequestParam(value = "value2",required = false)String value2,
  55. @ApiParam(name = "value3",value = "兑奖规则")
  56. @RequestParam(value = "value3",required = false)String value3){
  57. try {
  58. ActivityDO activityDO = toEntity(activity,ActivityDO.class);
  59. return service.insert(activityDO,value1,value2,value3,registrationNumber);
  60. }catch (Exception e){
  61. e.printStackTrace();
  62. // tracer.getCurrentSpan().logEvent(e.getMessage());
  63. return MixEnvelop.getError(e.getMessage());
  64. }
  65. }
  66. /**
  67. * find health activity
  68. *
  69. * @param activity 活动对象
  70. * @param page 页码
  71. * @param size 分页大小
  72. * @return
  73. */
  74. @PostMapping(value = HealthBankMapping.healthBank.findActivity)
  75. @ApiOperation(value = "查看健康活动")
  76. public MixEnvelop<ActivityDO, ActivityDO> getActivity(@ApiParam(name = "activity",value = "健康活动JSON")
  77. @RequestParam(value = "activity",required = false)String activity,
  78. @ApiParam(name = "page", value = "第几页,从1开始")
  79. @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
  80. @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
  81. @RequestParam(value = "size", required = false)Integer size){
  82. try{
  83. ActivityDO activityDO = toEntity(activity,ActivityDO.class);
  84. return service.findByCondition(activityDO,page,size);
  85. }catch (Exception e){
  86. e.printStackTrace();
  87. tracer.getCurrentSpan().logEvent(e.getMessage());
  88. return MixEnvelop.getError(e.getMessage());
  89. }
  90. }
  91. /**
  92. * out activity
  93. *
  94. * @param activity 活动对象
  95. * @return
  96. */
  97. @PostMapping(value = HealthBankMapping.healthBank.updateActivity)
  98. @ApiOperation(value = "编辑活动")
  99. public MixEnvelop<Boolean, Boolean> outActivity(@ApiParam(name = "activity", value = "健康活动JSON")
  100. @RequestParam(value = "activity", required = true) String activity,
  101. @ApiParam(name = "registrationNumber",value = "报名人数")
  102. @RequestParam(value = "registrationNumber",required = false)String registrationNumber,
  103. @ApiParam(name = "value1", value = "活动币JSON")
  104. @RequestParam(value = "value1", required = false) String value1,
  105. @ApiParam(name = "value2", value = "活动时间")
  106. @RequestParam(value = "value2", required = false) String value2,
  107. @ApiParam(name = "value3", value = "兑奖设置")
  108. @RequestParam(value = "value3", required = false) String value3) {
  109. try {
  110. ActivityDO activityDO = toEntity(activity, ActivityDO.class);
  111. return service.update(activityDO,value1,value2,value3,registrationNumber);
  112. } catch (Exception e) {
  113. e.printStackTrace();
  114. tracer.getCurrentSpan().logEvent(e.getMessage());
  115. return MixEnvelop.getError(e.getMessage());
  116. }
  117. }
  118. /**
  119. * 查看参与的活动
  120. *
  121. * @param activity 活动对象
  122. * @param page 页码
  123. * @param size 分页大小
  124. * @return
  125. */
  126. @PostMapping(value = HealthBankMapping.healthBank.selectByPatient)
  127. @ApiOperation(value = "参与的活动")
  128. public MixEnvelop<ActivityDO, ActivityDO> selectByPatient(@ApiParam(name = "activity",value = "健康活动JSON")
  129. @RequestParam(value = "activity",required = false)String activity,
  130. @ApiParam(name = "page", value = "第几页,从1开始")
  131. @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
  132. @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
  133. @RequestParam(value = "size", required = false)Integer size){
  134. try{
  135. ActivityDO activityDO = toEntity(activity,ActivityDO.class);
  136. return service.selectByPatient(activityDO,page,size);
  137. }catch (Exception e){
  138. e.printStackTrace();
  139. tracer.getCurrentSpan().logEvent(e.getMessage());
  140. return MixEnvelop.getError(e.getMessage());
  141. }
  142. }
  143. /**
  144. * 批量删除数据
  145. *
  146. * @param ids id集合[""]
  147. * @return
  148. */
  149. @PostMapping(value = HealthBankMapping.healthBank.batchActivity)
  150. @ApiOperation(value = "批量删除活动")
  151. public MixEnvelop<Boolean, Boolean> batchDelete(@ApiParam(name="ids",value = "id集合")
  152. @RequestParam(value = "ids",required = false)String ids){
  153. try{
  154. MixEnvelop<Boolean, Boolean> envelop = new MixEnvelop<>();
  155. JSONArray array = JSONArray.parseArray(ids);
  156. List<String> activityIds = new ArrayList<>();
  157. for (int i = 0;i<array.size();i++){
  158. activityIds.add(array.getString(i));
  159. }
  160. service.batchDelete(activityIds);
  161. envelop.setObj(true);
  162. return envelop;
  163. }catch (Exception e){
  164. e.printStackTrace();
  165. tracer.getCurrentSpan().logEvent(e.getMessage());
  166. return MixEnvelop.getError(e.getMessage());
  167. }
  168. }
  169. /**
  170. * 获取活动排行
  171. *
  172. * @param activityId
  173. * @param patient
  174. * @param page
  175. * @param size
  176. * @return
  177. */
  178. @PostMapping(value = HealthBankMapping.healthBank.selectActivityRanking)
  179. @ApiOperation(value = "获取活动排行")
  180. public MixEnvelop<JSONObject, JSONObject> selectActivityRanking(@ApiParam(name="activityId",value = "活动id")
  181. @RequestParam(value = "activityId",required = false)String activityId,
  182. @ApiParam(name="patient",value = "居民id")
  183. @RequestParam(value = "patient",required = false)String patient,
  184. @ApiParam(name = "page", value = "第几页,从1开始")
  185. @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
  186. @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
  187. @RequestParam(value = "size", required = false)Integer size,
  188. @ApiParam(name="street",value = "街道")
  189. @RequestParam(value = "street",required = false)String street,
  190. @ApiParam(name="town",value = "区")
  191. @RequestParam(value = "town",required = false)String town){
  192. try{
  193. return service.selectActivityRanking(activityId,patient,page,size,street,town);
  194. }catch (Exception e){
  195. e.printStackTrace();
  196. tracer.getCurrentSpan().logEvent(e.getMessage());
  197. return MixEnvelop.getError(e.getMessage());
  198. }
  199. }
  200. /**
  201. * 删除数据
  202. *
  203. * @param id 活动id
  204. * @return
  205. */
  206. @PostMapping(value = HealthBankMapping.healthBank.daleteActivity)
  207. @ApiOperation(value = "删除活动")
  208. public MixEnvelop<Boolean, Boolean> daleteActivity(@ApiParam(name="id",value = "id集合")
  209. @RequestParam(value = "id",required = false)String id){
  210. try{
  211. MixEnvelop<Boolean, Boolean> envelop = new MixEnvelop<>();
  212. service.daleteActivity(id);
  213. envelop.setObj(true);
  214. return envelop;
  215. }catch (Exception e){
  216. e.printStackTrace();
  217. tracer.getCurrentSpan().logEvent(e.getMessage());
  218. return MixEnvelop.getError(e.getMessage());
  219. }
  220. }
  221. /**
  222. * 编辑活动:上下线、推荐
  223. *
  224. * @param id
  225. * @param type
  226. * @return
  227. */
  228. @PostMapping(value = HealthBankMapping.healthBank.editActivity)
  229. @ApiOperation(value = "编辑活动:上下线、推荐")
  230. public ObjEnvelop<ActivityDO> editActivity(
  231. @ApiParam(name = "id", value = "活动id")
  232. @RequestParam(value = "id", required = true) String id,
  233. @ApiParam(name = "type", value = "操作类型:上线:0,下线:2,推荐:3,取消推荐:4")
  234. @RequestParam(value = "type", required = true) String type) {
  235. try {
  236. ActivityDO activityDO=service.editActivity(id, type);
  237. return ObjEnvelop.getSuccess("操作成功!",activityDO);
  238. } catch (Exception e) {
  239. e.printStackTrace();
  240. // tracer.getCurrentSpan().logEvent(e.getMessage());
  241. return ObjEnvelop.getError(e.getMessage());
  242. }
  243. }
  244. /**
  245. * 编辑活动:上下线、推荐
  246. *
  247. * @param id
  248. * @return
  249. */
  250. @PostMapping(value = HealthBankMapping.healthBank.findActivityById)
  251. @ApiOperation(value = "根据id获取活动详情+活动规则")
  252. public ObjEnvelop<JSONObject> findActivityById(
  253. @ApiParam(name = "id", value = "活动id")
  254. @RequestParam(value = "id", required = true) String id) {
  255. try {
  256. JSONObject activityDO=service.findActivityById(id);
  257. return ObjEnvelop.getSuccess("获取成功!",activityDO);
  258. } catch (Exception e) {
  259. e.printStackTrace();
  260. tracer.getCurrentSpan().logEvent(e.getMessage());
  261. return ObjEnvelop.getError("获取失败!"+e.getMessage());
  262. }
  263. }
  264. @PostMapping(value = HealthBankMapping.healthBank.pageActivity)
  265. @ApiOperation(value = "分页查询活动")
  266. public PageEnvelop<ActivityDO> pageActivity(@ApiParam(name = "type", value = "活动类型")
  267. @RequestParam(value = "type", required = false) String type,
  268. @ApiParam(name = "status", value = "活动状态:1上线,2下线")
  269. @RequestParam(value = "status", required = false) String status,
  270. @ApiParam(name = "crowdType", value = "人群类型:1:签约居民、2平台用户")
  271. @RequestParam(value = "crowdType", required = false) String crowdType,
  272. @ApiParam(name = "releaseTime", value = "下线开始时间")
  273. @RequestParam(value = "releaseTime", required = false) String releaseTime,
  274. @ApiParam(name = "activityOfflineTime", value = "下线结束时间")
  275. @RequestParam(value = "activityOfflineTime", required = false) String activityOfflineTime,
  276. @ApiParam(name = "filter", value = "活动名、发布机构、面向范围名称")
  277. @RequestParam(value = "filter", required = false) String filter,
  278. @ApiParam(name = "page", value = "第几页,从1开始")
  279. @RequestParam(value = "page", defaultValue = "1", required = false) Integer page,
  280. @ApiParam(name = "size", defaultValue = "10", value = ",每页分页大小")
  281. @RequestParam(value = "size", required = false) Integer size) {
  282. try{
  283. JSONObject obj = service.ListActivityDO(type, status,crowdType,releaseTime,activityOfflineTime,filter,page,size);
  284. // int count = (int) service.getCount(stringBuffer.toString());
  285. List<ActivityDO> list=(List<ActivityDO>)obj.get("activityDOList");
  286. int count =obj.getInteger("count");
  287. return success(list, count, page, size);
  288. }catch (Exception e){
  289. e.printStackTrace();
  290. tracer.getCurrentSpan().logEvent(e.getMessage());
  291. return PageEnvelop.getError("获取失败"+e.getMessage(),-1);
  292. }
  293. }
  294. /**
  295. * 编辑活动:上下线、推荐
  296. *
  297. * @param type
  298. * @return
  299. */
  300. @PostMapping(value = HealthBankMapping.healthBank.findActivityByType)
  301. @ApiOperation(value = "获取是否存在在线的竞走活动")
  302. public ObjEnvelop<Boolean> findActivityByType(
  303. @ApiParam(name = "type", value = "活动类型")
  304. @RequestParam(value = "type", required = true) String type) {
  305. try {
  306. JSONObject obj=service.findActivityByType(type);
  307. return ObjEnvelop.getSuccess("获取成功!",obj);
  308. } catch (Exception e) {
  309. e.printStackTrace();
  310. tracer.getCurrentSpan().logEvent(e.getMessage());
  311. return ObjEnvelop.getError("获取失败!"+e.getMessage());
  312. }
  313. }
  314. /**
  315. * 获取排序数据
  316. * @return
  317. */
  318. @PostMapping(value = HealthBankMapping.healthBank.selectActivitys)
  319. @ApiOperation(value = "获取排序数据")
  320. public MixEnvelop<ActivityDO,ActivityDO> select() {
  321. try {
  322. MixEnvelop<ActivityDO,ActivityDO> envelop = new MixEnvelop<>();
  323. envelop.setDetailModelList(service.select());
  324. return envelop;
  325. } catch (Exception e) {
  326. e.printStackTrace();
  327. tracer.getCurrentSpan().logEvent(e.getMessage());
  328. return MixEnvelop.getError(e.getMessage());
  329. }
  330. }
  331. /**
  332. * 调整顺序
  333. * @param activitys
  334. * @return
  335. */
  336. @PostMapping(value = HealthBankMapping.healthBank.updateSort)
  337. @ApiOperation(value = "调整顺序")
  338. public MixEnvelop updateSort(String activitys) {
  339. try {
  340. JSONArray array = JSONArray.parseArray(activitys);
  341. return service.updateSort(array);
  342. } catch (Exception e) {
  343. e.printStackTrace();
  344. tracer.getCurrentSpan().logEvent(e.getMessage());
  345. return MixEnvelop.getError(e.getMessage());
  346. }
  347. }
  348. @PostMapping(value = HealthBankMapping.healthBank.selectByUnionId)
  349. @ApiOperation(value = "查询参与的竟步走活动")
  350. public MixEnvelop<ActivityDO, ActivityDO> selectActivityRanking(@ApiParam(name="unionId",value = "unionId")
  351. @RequestParam(value = "unionId",required = true)String unionId,
  352. @ApiParam(name="patient",value = "居民id")
  353. @RequestParam(value = "patient",required = false)String patient,
  354. @ApiParam(name="idCard",value = "身份证")
  355. @RequestParam(value = "idCard",required = false)String idCard,
  356. @ApiParam(name = "page", value = "第几页,从1开始")
  357. @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
  358. @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
  359. @RequestParam(value = "size", required = false)Integer size){
  360. try{
  361. return service.selectByUnionId(unionId,patient,idCard,page,size);
  362. }catch (Exception e){
  363. e.printStackTrace();
  364. tracer.getCurrentSpan().logEvent(e.getMessage());
  365. return MixEnvelop.getError(e.getMessage());
  366. }
  367. }
  368. /**
  369. * 获取当前居民参加的活动
  370. * @param unionId
  371. * @param patient
  372. * @param idCard
  373. * @return
  374. */
  375. @PostMapping(value = HealthBankMapping.healthBank.selectNowByUnionId)
  376. @ApiOperation(value = "获取当前居民参加的活动")
  377. public MixEnvelop<ActivityDO, ActivityDO> selectNowByUnionId(@ApiParam(name="unionId",value = "unionId")
  378. @RequestParam(value = "unionId",required = true)String unionId,
  379. @ApiParam(name="patient",value = "居民id")
  380. @RequestParam(value = "patient",required = false)String patient,
  381. @ApiParam(name="idCard",value = "身份证")
  382. @RequestParam(value = "idCard",required = false)String idCard){
  383. try{
  384. MixEnvelop<ActivityDO,ActivityDO> envelop = new MixEnvelop<>();
  385. envelop.setDetailModelList(service.selectNowByUnionId(unionId,patient,idCard));
  386. return envelop;
  387. }catch (Exception e){
  388. e.printStackTrace();
  389. tracer.getCurrentSpan().logEvent(e.getMessage());
  390. return MixEnvelop.getError(e.getMessage());
  391. }
  392. }
  393. /**
  394. * 小程序-居民积分排行
  395. * @param patients
  396. * @param taskId
  397. * @param size
  398. * @return
  399. */
  400. @PostMapping(value = HealthBankMapping.healthBank.selectAppletsRanking)
  401. @ApiOperation(value = "小程序-居民积分排行")
  402. public MixEnvelop selectAppletsRanking(@ApiParam(name="patients",value = "居民code列表")
  403. @RequestParam(value = "patients",required = false)String patients,
  404. @ApiParam(name="taskId",value = "任务id")
  405. @RequestParam(value = "taskId",required = true)String taskId,
  406. @ApiParam(name="size",value = "展示多少列")
  407. @RequestParam(value = "size",required = true)Integer size,
  408. @ApiParam(name="patient",value = "居民code")
  409. @RequestParam(value = "patient",required = true)String patient){
  410. try{
  411. MixEnvelop envelop = new MixEnvelop<>();
  412. JSONArray array = JSONArray.parseArray(patients);
  413. envelop.setObj(service.selectAppletsRanking(array,taskId,size,patient));
  414. return envelop;
  415. }catch (Exception e){
  416. e.printStackTrace();
  417. tracer.getCurrentSpan().logEvent(e.getMessage());
  418. return MixEnvelop.getError(e.getMessage());
  419. }
  420. }
  421. }