ActivityController.java 24 KB

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