ActivityController.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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. @ApiParam(name="hospital",value = "社区")
  193. @RequestParam(value = "hospital",required = false)String hospital){
  194. try{
  195. return service.selectActivityRanking(activityId,patient,page,size,street,town,hospital);
  196. }catch (Exception e){
  197. e.printStackTrace();
  198. tracer.getCurrentSpan().logEvent(e.getMessage());
  199. return MixEnvelop.getError(e.getMessage());
  200. }
  201. }
  202. /**
  203. * 删除数据
  204. *
  205. * @param id 活动id
  206. * @return
  207. */
  208. @PostMapping(value = HealthBankMapping.healthBank.daleteActivity)
  209. @ApiOperation(value = "删除活动")
  210. public MixEnvelop<Boolean, Boolean> daleteActivity(@ApiParam(name="id",value = "id集合")
  211. @RequestParam(value = "id",required = false)String id){
  212. try{
  213. MixEnvelop<Boolean, Boolean> envelop = new MixEnvelop<>();
  214. service.daleteActivity(id);
  215. envelop.setObj(true);
  216. return envelop;
  217. }catch (Exception e){
  218. e.printStackTrace();
  219. tracer.getCurrentSpan().logEvent(e.getMessage());
  220. return MixEnvelop.getError(e.getMessage());
  221. }
  222. }
  223. /**
  224. * 编辑活动:上下线、推荐
  225. *
  226. * @param id
  227. * @param type
  228. * @return
  229. */
  230. @PostMapping(value = HealthBankMapping.healthBank.editActivity)
  231. @ApiOperation(value = "编辑活动:上下线、推荐")
  232. public ObjEnvelop<ActivityDO> editActivity(
  233. @ApiParam(name = "id", value = "活动id")
  234. @RequestParam(value = "id", required = true) String id,
  235. @ApiParam(name = "type", value = "操作类型:上线:0,下线:2,推荐:3,取消推荐:4")
  236. @RequestParam(value = "type", required = true) String type) {
  237. try {
  238. ActivityDO activityDO=service.editActivity(id, type);
  239. return ObjEnvelop.getSuccess("操作成功!",activityDO);
  240. } catch (Exception e) {
  241. e.printStackTrace();
  242. // tracer.getCurrentSpan().logEvent(e.getMessage());
  243. return ObjEnvelop.getError(e.getMessage());
  244. }
  245. }
  246. /**
  247. * 编辑活动:上下线、推荐
  248. *
  249. * @param id
  250. * @return
  251. */
  252. @PostMapping(value = HealthBankMapping.healthBank.findActivityById)
  253. @ApiOperation(value = "根据id获取活动详情+活动规则")
  254. public ObjEnvelop<JSONObject> findActivityById(
  255. @ApiParam(name = "id", value = "活动id")
  256. @RequestParam(value = "id", required = true) String id) {
  257. try {
  258. JSONObject activityDO=service.findActivityById(id);
  259. return ObjEnvelop.getSuccess("获取成功!",activityDO);
  260. } catch (Exception e) {
  261. e.printStackTrace();
  262. tracer.getCurrentSpan().logEvent(e.getMessage());
  263. return ObjEnvelop.getError("获取失败!"+e.getMessage());
  264. }
  265. }
  266. @PostMapping(value = HealthBankMapping.healthBank.pageActivity)
  267. @ApiOperation(value = "分页查询活动")
  268. public PageEnvelop<ActivityDO> pageActivity(@ApiParam(name = "type", value = "活动类型")
  269. @RequestParam(value = "type", required = false) String type,
  270. @ApiParam(name = "status", value = "活动状态:1上线,2下线")
  271. @RequestParam(value = "status", required = false) String status,
  272. @ApiParam(name = "crowdType", value = "人群类型:1:签约居民、2平台用户")
  273. @RequestParam(value = "crowdType", required = false) String crowdType,
  274. @ApiParam(name = "releaseTime", value = "下线开始时间")
  275. @RequestParam(value = "releaseTime", required = false) String releaseTime,
  276. @ApiParam(name = "activityOfflineTime", value = "下线结束时间")
  277. @RequestParam(value = "activityOfflineTime", required = false) String activityOfflineTime,
  278. @ApiParam(name = "filter", value = "活动名、发布机构、面向范围名称")
  279. @RequestParam(value = "filter", required = false) String filter,
  280. @ApiParam(name = "page", value = "第几页,从1开始")
  281. @RequestParam(value = "page", defaultValue = "1", required = false) Integer page,
  282. @ApiParam(name = "size", defaultValue = "10", value = ",每页分页大小")
  283. @RequestParam(value = "size", required = false) Integer size) {
  284. try{
  285. JSONObject obj = service.ListActivityDO(type, status,crowdType,releaseTime,activityOfflineTime,filter,page,size);
  286. // int count = (int) service.getCount(stringBuffer.toString());
  287. List<ActivityDO> list=(List<ActivityDO>)obj.get("activityDOList");
  288. int count =obj.getInteger("count");
  289. return success(list, count, page, size);
  290. }catch (Exception e){
  291. e.printStackTrace();
  292. tracer.getCurrentSpan().logEvent(e.getMessage());
  293. return PageEnvelop.getError("获取失败"+e.getMessage(),-1);
  294. }
  295. }
  296. /**
  297. * 编辑活动:上下线、推荐
  298. *
  299. * @param type
  300. * @return
  301. */
  302. @PostMapping(value = HealthBankMapping.healthBank.findActivityByType)
  303. @ApiOperation(value = "获取是否存在在线的竞走活动")
  304. public ObjEnvelop<Boolean> findActivityByType(
  305. @ApiParam(name = "type", value = "活动类型")
  306. @RequestParam(value = "type", required = true) String type) {
  307. try {
  308. JSONObject obj=service.findActivityByType(type);
  309. return ObjEnvelop.getSuccess("获取成功!",obj);
  310. } catch (Exception e) {
  311. e.printStackTrace();
  312. tracer.getCurrentSpan().logEvent(e.getMessage());
  313. return ObjEnvelop.getError("获取失败!"+e.getMessage());
  314. }
  315. }
  316. /**
  317. * 获取排序数据
  318. * @return
  319. */
  320. @PostMapping(value = HealthBankMapping.healthBank.selectActivitys)
  321. @ApiOperation(value = "获取排序数据")
  322. public MixEnvelop<ActivityDO,ActivityDO> select() {
  323. try {
  324. MixEnvelop<ActivityDO,ActivityDO> envelop = new MixEnvelop<>();
  325. envelop.setDetailModelList(service.select());
  326. return envelop;
  327. } catch (Exception e) {
  328. e.printStackTrace();
  329. tracer.getCurrentSpan().logEvent(e.getMessage());
  330. return MixEnvelop.getError(e.getMessage());
  331. }
  332. }
  333. /**
  334. * 调整顺序
  335. * @param activitys
  336. * @return
  337. */
  338. @PostMapping(value = HealthBankMapping.healthBank.updateSort)
  339. @ApiOperation(value = "调整顺序")
  340. public MixEnvelop updateSort(String activitys) {
  341. try {
  342. JSONArray array = JSONArray.parseArray(activitys);
  343. return service.updateSort(array);
  344. } catch (Exception e) {
  345. e.printStackTrace();
  346. tracer.getCurrentSpan().logEvent(e.getMessage());
  347. return MixEnvelop.getError(e.getMessage());
  348. }
  349. }
  350. @PostMapping(value = HealthBankMapping.healthBank.selectByUnionId)
  351. @ApiOperation(value = "查询参与的竟步走活动")
  352. public MixEnvelop<ActivityDO, ActivityDO> selectActivityRanking(@ApiParam(name="unionId",value = "unionId")
  353. @RequestParam(value = "unionId",required = true)String unionId,
  354. @ApiParam(name="patient",value = "居民id")
  355. @RequestParam(value = "patient",required = false)String patient,
  356. @ApiParam(name="idCard",value = "身份证")
  357. @RequestParam(value = "idCard",required = false)String idCard,
  358. @ApiParam(name = "page", value = "第几页,从1开始")
  359. @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
  360. @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
  361. @RequestParam(value = "size", required = false)Integer size){
  362. try{
  363. return service.selectByUnionId(unionId,patient,idCard,page,size);
  364. }catch (Exception e){
  365. e.printStackTrace();
  366. tracer.getCurrentSpan().logEvent(e.getMessage());
  367. return MixEnvelop.getError(e.getMessage());
  368. }
  369. }
  370. /**
  371. * 获取当前居民参加的活动
  372. * @param unionId
  373. * @param patient
  374. * @param idCard
  375. * @return
  376. */
  377. @PostMapping(value = HealthBankMapping.healthBank.selectNowByUnionId)
  378. @ApiOperation(value = "获取当前居民参加的活动")
  379. public MixEnvelop<ActivityDO, ActivityDO> selectNowByUnionId(@ApiParam(name="unionId",value = "unionId")
  380. @RequestParam(value = "unionId",required = true)String unionId,
  381. @ApiParam(name="patient",value = "居民id")
  382. @RequestParam(value = "patient",required = false)String patient,
  383. @ApiParam(name="idCard",value = "身份证")
  384. @RequestParam(value = "idCard",required = false)String idCard){
  385. try{
  386. MixEnvelop<ActivityDO,ActivityDO> envelop = new MixEnvelop<>();
  387. envelop.setDetailModelList(service.selectNowByUnionId(unionId,patient,idCard));
  388. return envelop;
  389. }catch (Exception e){
  390. e.printStackTrace();
  391. tracer.getCurrentSpan().logEvent(e.getMessage());
  392. return MixEnvelop.getError(e.getMessage());
  393. }
  394. }
  395. /**
  396. * 小程序-居民积分排行
  397. * @param patients
  398. * @param taskId
  399. * @param size
  400. * @return
  401. */
  402. @PostMapping(value = HealthBankMapping.healthBank.selectAppletsRanking)
  403. @ApiOperation(value = "小程序-居民积分排行")
  404. public MixEnvelop selectAppletsRanking(@ApiParam(name="flag",value = "居民code列表")
  405. @RequestParam(value = "flag",required = false)Integer flag,
  406. @ApiParam(name="flagName",value = "居民code列表")
  407. @RequestParam(value = "flagName",required = false)String flagName,
  408. @ApiParam(name="taskId",value = "任务id")
  409. @RequestParam(value = "taskId",required = true)String taskId,
  410. @ApiParam(name="size",value = "展示多少列")
  411. @RequestParam(value = "size",required = true)Integer size,
  412. @ApiParam(name="patient",value = "居民code")
  413. @RequestParam(value = "patient",required = true)String patient){
  414. try{
  415. MixEnvelop envelop = new MixEnvelop<>();
  416. envelop.setObj(service.selectAppletsRanking(flag,flagName,taskId,size,patient));
  417. return envelop;
  418. }catch (Exception e){
  419. e.printStackTrace();
  420. tracer.getCurrentSpan().logEvent(e.getMessage());
  421. return MixEnvelop.getError(e.getMessage());
  422. }
  423. }
  424. }