CreditsDetailController.java 5.9 KB

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