ActivityController.java 25 KB

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