CreditsDetailController.java 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 javafx.beans.binding.BooleanExpression;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.cloud.sleuth.Tracer;
  19. import org.springframework.web.bind.annotation.*;
  20. import java.util.ArrayList;
  21. import java.util.List;
  22. /**
  23. * @author wangzhinan
  24. * @create 2018-04-27 16:51
  25. * @desc credits log info
  26. **/
  27. @RestController
  28. @RequestMapping(HealthBankMapping.api_health_bank_common)
  29. @Api(tags = "健康积分相关操作",description = "健康积分相关操作")
  30. public class CreditsDetailController extends EnvelopRestController {
  31. @Autowired
  32. private Tracer tracer;
  33. @Autowired
  34. private CreditsDetailService service;
  35. /**
  36. * 查看积分记录
  37. *
  38. * @param creditsDetail 积分对象
  39. * @param page 页码
  40. * @param size 分页大小
  41. * @return
  42. */
  43. @PostMapping(value = HealthBankMapping.healthBank.findCreditsLogInfo)
  44. @ApiOperation(value = "查看积分记录")
  45. public Envelop<CreditsDetailDO> selectCreditsLogInfo(@ApiParam(name = "creditsDetail",value = "积分记录JSON")
  46. @RequestParam(value = "creditsDetail",required = false)String creditsDetail,
  47. @ApiParam(name = "page", value = "第几页,从1开始")
  48. @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
  49. @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
  50. @RequestParam(value = "size", required = false)Integer size){
  51. try{
  52. CreditsDetailDO creditsDetailDO = toEntity(creditsDetail,CreditsDetailDO.class);
  53. return service.findByCondition(creditsDetailDO,page,size);
  54. }catch (Exception e){
  55. e.printStackTrace();
  56. tracer.getCurrentSpan().logEvent(e.getMessage());
  57. return Envelop.getError(e.getMessage());
  58. }
  59. }
  60. /**
  61. * 添加积分
  62. *
  63. * @param creditsDetail 积分对象
  64. * @return
  65. */
  66. @PostMapping(value = HealthBankMapping.healthBank.createCreditsDetail)
  67. @ApiOperation(value = "添加积分记录")
  68. public Envelop<CreditsDetailDO> insert(@ApiParam(name = "creditsDetail",value = "积分记录JSON")
  69. @RequestParam(value = "creditsDetail",required = true)String creditsDetail){
  70. try {
  71. CreditsDetailDO creditsDetailDO = toEntity(creditsDetail,CreditsDetailDO.class);
  72. return service.insert(creditsDetailDO);
  73. }catch (Exception e){
  74. e.printStackTrace();
  75. tracer.getCurrentSpan().logEvent(e.getMessage());
  76. return Envelop.getError(e.getMessage());
  77. }
  78. }
  79. /**
  80. * 根据活动查找积分
  81. *
  82. * @param activityId 活动id
  83. *
  84. * @param patientId 居民id
  85. *
  86. * @param page 页码
  87. *
  88. * @param size 分页大小
  89. *
  90. * @return
  91. */
  92. @PostMapping(value = HealthBankMapping.healthBank.selectByActivity)
  93. @ApiOperation(value = "根据活动查找积分")
  94. public Envelop<CreditsDetailDO> seletcByActivity(@ApiParam(name = "activityId",value = "活动id")
  95. @RequestParam(value = "activityId",required = true)String activityId,
  96. @ApiParam(name = "patientId",value = "居民id")
  97. @RequestParam(value = "patientId",required = true) String patientId,
  98. @ApiParam(name = "page", value = "第几页,从1开始")
  99. @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
  100. @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
  101. @RequestParam(value = "size", required = false)Integer size){
  102. try{
  103. return service.selectByActivity(activityId,patientId,page,size);
  104. }catch (Exception e){
  105. e.printStackTrace();
  106. tracer.getCurrentSpan().logEvent(e.getMessage());
  107. return Envelop.getError(e.getMessage());
  108. }
  109. }
  110. /**
  111. * 查看积分排行
  112. *
  113. * @param object {"filter":[""],"page":"","size":""}
  114. * @return
  115. */
  116. @PostMapping(value = HealthBankMapping.healthBank.selectByRanking)
  117. @ApiOperation(value = "查询积分排名")
  118. public Envelop<AccountDO> selectByRanking(@RequestBody JSONObject object){
  119. try{
  120. JSONArray array = object.getJSONArray("filter");
  121. Integer page = object.getInteger("page");
  122. Integer size = object.getInteger("size");
  123. List<String> patientIds = new ArrayList<>();
  124. for (int i=0;array != null && array.size()!=0&& i<array.size();i++){
  125. patientIds.add(array.getString(i));
  126. }
  127. return service.selectByRanking(patientIds,page,size);
  128. }catch (Exception e){
  129. e.printStackTrace();
  130. tracer.getCurrentSpan().logEvent(e.getMessage());
  131. return Envelop.getError(e.getMessage());
  132. }
  133. }
  134. /**
  135. * 活动排名
  136. * @param object
  137. * @return
  138. */
  139. @PostMapping(value = HealthBankMapping.healthBank.selectByActivityRanking)
  140. @ApiOperation(value = "活动排名")
  141. public Envelop<TaskPatientDetailDO> selectByActivityRanking(@RequestBody JSONObject object){
  142. try{
  143. JSONArray array = object.getJSONArray("filter");
  144. String activityId = object.getString("activityId");
  145. Integer page = object.getInteger("page");
  146. Integer size = object.getInteger("size");
  147. List<String> ids = new ArrayList<>();
  148. for (int i=0;array != null && array.size()!=0&& i<array.size();i++){
  149. ids.add(array.getString(i));
  150. }
  151. return service.selectByActivityRanking(activityId,ids,page,size);
  152. }catch (Exception e){
  153. e.printStackTrace();
  154. tracer.getCurrentSpan().logEvent(e.getMessage());
  155. return Envelop.getError(e.getMessage());
  156. }
  157. }
  158. /**
  159. * 根据活动id查找全部活动
  160. *
  161. * @param activityId 活动ID
  162. * @param page 页码
  163. * @param size 分页大小
  164. * @return
  165. */
  166. @PostMapping(value = HealthBankMapping.healthBank.selectByActivityRanking1)
  167. @ApiOperation(value = "根据活动id查找全部排行")
  168. public Envelop<TaskPatientDetailDO> selectByActivityRanking1(@ApiParam(name = "activityId",value = "活动id")
  169. @RequestParam(value = "activityId",required = true)String activityId,
  170. @ApiParam(name = "page", value = "第几页,从1开始")
  171. @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
  172. @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
  173. @RequestParam(value = "size", required = false)Integer size){
  174. try{
  175. return service.selectByActivityRanking1(activityId,page,size);
  176. }catch (Exception e){
  177. e.printStackTrace();
  178. tracer.getCurrentSpan().logEvent(e.getMessage());
  179. return Envelop.getError(e.getMessage());
  180. }
  181. }
  182. @PostMapping(value = HealthBankMapping.healthBank.doctorAddIntegrate)
  183. @ApiOperation(value = "添加积分记录")
  184. public Envelop<Boolean> doctorAddIntegrate(@RequestBody JSONObject object){
  185. try {
  186. JSONArray array = object.getJSONArray("patient");
  187. String ruleId = object.getString("ruleId");
  188. String description = object.getString("description");
  189. return service.doctorAddIntegrate(array,ruleId,description);
  190. }catch (Exception e){
  191. e.printStackTrace();
  192. tracer.getCurrentSpan().logEvent(e.getMessage());
  193. return Envelop.getError(e.getMessage());
  194. }
  195. }
  196. /**
  197. * 步数获取积分
  198. *
  199. * @param creditsDetail 积分对象
  200. * @return
  201. */
  202. @PostMapping(value = HealthBankMapping.healthBank.addStepIntegrate)
  203. @ApiOperation(value = "步数获取积分")
  204. public Envelop<CreditsDetailDO> addStepIntegrate(@ApiParam(name = "creditsDetail",value = "积分记录JSON")
  205. @RequestParam(value = "creditsDetail",required = true)String creditsDetail){
  206. try {
  207. CreditsDetailDO creditsDetailDO = toEntity(creditsDetail,CreditsDetailDO.class);
  208. return service.stepAddIntegrate(creditsDetailDO);
  209. }catch (Exception e){
  210. e.printStackTrace();
  211. tracer.getCurrentSpan().logEvent(e.getMessage());
  212. return Envelop.getError(e.getMessage());
  213. }
  214. }
  215. }