CreditsDetailController.java 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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.yihu.jw.entity.health.bank.AccountDO;
  7. import com.yihu.jw.entity.health.bank.CreditsDetailDO;
  8. import com.yihu.jw.entity.health.bank.TaskPatientDetailDO;
  9. import com.yihu.jw.restmodel.common.Envelop;
  10. import com.yihu.jw.restmodel.common.EnvelopRestController;
  11. import com.yihu.jw.rm.health.bank.HealthBankMapping;
  12. import com.yihu.jw.service.CreditsDetailService;
  13. import io.swagger.annotations.Api;
  14. import io.swagger.annotations.ApiOperation;
  15. import io.swagger.annotations.ApiParam;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.cloud.sleuth.Tracer;
  18. import org.springframework.web.bind.annotation.*;
  19. import java.util.ArrayList;
  20. import java.util.List;
  21. /**
  22. * @author wangzhinan
  23. * @create 2018-04-27 16:51
  24. * @desc credits log info
  25. **/
  26. @RestController
  27. @RequestMapping(HealthBankMapping.api_health_bank_common)
  28. @Api(tags = "健康积分相关操作",description = "健康积分相关操作")
  29. public class CreditsDetailController extends EnvelopRestController {
  30. @Autowired
  31. private Tracer tracer;
  32. @Autowired
  33. private CreditsDetailService service;
  34. /**
  35. * 查看积分记录
  36. *
  37. * @param creditsDetail 积分对象
  38. * @param page 页码
  39. * @param size 分页大小
  40. * @return
  41. */
  42. @PostMapping(value = HealthBankMapping.healthBank.findCreditsLogInfo)
  43. @ApiOperation(value = "查看积分记录")
  44. public Envelop<CreditsDetailDO> selectCreditsLogInfo(@ApiParam(name = "creditsDetail",value = "积分记录JSON")
  45. @RequestParam(value = "creditsDetail",required = false)String creditsDetail,
  46. @ApiParam(name = "page", value = "第几页,从1开始")
  47. @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
  48. @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
  49. @RequestParam(value = "size", required = false)Integer size){
  50. try{
  51. CreditsDetailDO creditsDetailDO = toEntity(creditsDetail,CreditsDetailDO.class);
  52. return service.findByCondition(creditsDetailDO,page,size);
  53. }catch (Exception e){
  54. e.printStackTrace();
  55. tracer.getCurrentSpan().logEvent(e.getMessage());
  56. return Envelop.getError(e.getMessage());
  57. }
  58. }
  59. /**
  60. * 添加积分
  61. *
  62. * @param creditsDetail 积分对象
  63. * @return
  64. */
  65. @PostMapping(value = HealthBankMapping.healthBank.createCreditsDetail)
  66. @ApiOperation(value = "添加积分记录")
  67. public Envelop<CreditsDetailDO> insert(@ApiParam(name = "creditsDetail",value = "积分记录JSON")
  68. @RequestParam(value = "creditsDetail",required = true)String creditsDetail){
  69. try {
  70. CreditsDetailDO creditsDetailDO = toEntity(creditsDetail,CreditsDetailDO.class);
  71. return service.insert(creditsDetailDO);
  72. }catch (Exception e){
  73. e.printStackTrace();
  74. tracer.getCurrentSpan().logEvent(e.getMessage());
  75. return Envelop.getError(e.getMessage());
  76. }
  77. }
  78. /**
  79. * 根据活动查找积分
  80. *
  81. * @param activityId 活动id
  82. *
  83. * @param patientId 居民id
  84. *
  85. * @param page 页码
  86. *
  87. * @param size 分页大小
  88. *
  89. * @return
  90. */
  91. @PostMapping(value = HealthBankMapping.healthBank.selectByActivity)
  92. @ApiOperation(value = "根据活动查找积分")
  93. public Envelop<CreditsDetailDO> seletcByActivity(@ApiParam(name = "activityId",value = "活动id")
  94. @RequestParam(value = "activityId",required = true)String activityId,
  95. @ApiParam(name = "patientId",value = "居民id")
  96. @RequestParam(value = "patientId",required = true) String patientId,
  97. @ApiParam(name = "page", value = "第几页,从1开始")
  98. @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
  99. @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
  100. @RequestParam(value = "size", required = false)Integer size){
  101. try{
  102. return service.selectByActivity(activityId,patientId,page,size);
  103. }catch (Exception e){
  104. e.printStackTrace();
  105. tracer.getCurrentSpan().logEvent(e.getMessage());
  106. return Envelop.getError(e.getMessage());
  107. }
  108. }
  109. /**
  110. * 查看积分排行
  111. *
  112. * @param object {"filter":[""],"page":"","size":""}
  113. * @return
  114. */
  115. @PostMapping(value = HealthBankMapping.healthBank.selectByRanking)
  116. @ApiOperation(value = "查询积分排名")
  117. public Envelop<AccountDO> selectByRanking(@RequestBody JSONObject object){
  118. try{
  119. JSONArray array = object.getJSONArray("filter");
  120. Integer page = object.getInteger("page");
  121. Integer size = object.getInteger("size");
  122. List<String> patientIds = new ArrayList<>();
  123. for (int i=0;array != null && array.size()!=0&& i<array.size();i++){
  124. patientIds.add(array.getString(i));
  125. }
  126. return service.selectByRanking(patientIds,page,size);
  127. }catch (Exception e){
  128. e.printStackTrace();
  129. tracer.getCurrentSpan().logEvent(e.getMessage());
  130. return Envelop.getError(e.getMessage());
  131. }
  132. }
  133. /**
  134. * 活动排名
  135. * @param object
  136. * @return
  137. */
  138. @PostMapping(value = HealthBankMapping.healthBank.selectByActivityRanking)
  139. @ApiOperation(value = "活动排名")
  140. public Envelop<TaskPatientDetailDO> selectByActivityRanking(@RequestBody JSONObject object){
  141. try{
  142. JSONArray array = object.getJSONArray("filter");
  143. String activityId = object.getString("activityId");
  144. Integer page = object.getInteger("page");
  145. Integer size = object.getInteger("size");
  146. List<String> ids = new ArrayList<>();
  147. for (int i=0;array != null && array.size()!=0&& i<array.size();i++){
  148. ids.add(array.getString(i));
  149. }
  150. return service.selectByActivityRanking(activityId,ids,page,size);
  151. }catch (Exception e){
  152. e.printStackTrace();
  153. tracer.getCurrentSpan().logEvent(e.getMessage());
  154. return Envelop.getError(e.getMessage());
  155. }
  156. }
  157. }