CreditsDetailController.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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.restmodel.common.Envelop;
  9. import com.yihu.jw.restmodel.common.EnvelopRestController;
  10. import com.yihu.jw.rm.health.bank.HealthBankMapping;
  11. import com.yihu.jw.service.CreditsDetailService;
  12. import io.swagger.annotations.Api;
  13. import io.swagger.annotations.ApiOperation;
  14. import io.swagger.annotations.ApiParam;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.cloud.sleuth.Tracer;
  17. import org.springframework.web.bind.annotation.*;
  18. import java.util.ArrayList;
  19. import java.util.List;
  20. /**
  21. * @author wangzhinan
  22. * @create 2018-04-27 16:51
  23. * @desc credits log info
  24. **/
  25. @RestController
  26. @RequestMapping(HealthBankMapping.api_health_bank_common)
  27. @Api(tags = "健康积分相关操作",description = "健康积分相关操作")
  28. public class CreditsDetailController extends EnvelopRestController {
  29. @Autowired
  30. private Tracer tracer;
  31. @Autowired
  32. private CreditsDetailService service;
  33. /**
  34. * 查看积分记录
  35. *
  36. * @param creditsDetail 积分对象
  37. * @param page 页码
  38. * @param size 分页大小
  39. * @return
  40. */
  41. @PostMapping(value = HealthBankMapping.healthBank.findCreditsLogInfo)
  42. @ApiOperation(value = "查看积分记录")
  43. public Envelop<CreditsDetailDO> selectCreditsLogInfo(@ApiParam(name = "creditsDetail",value = "积分记录JSON")
  44. @RequestParam(value = "creditsDetail",required = false)String creditsDetail,
  45. @ApiParam(name = "page", value = "第几页,从1开始")
  46. @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
  47. @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
  48. @RequestParam(value = "size", required = false)Integer size){
  49. try{
  50. CreditsDetailDO creditsDetailDO = toEntity(creditsDetail,CreditsDetailDO.class);
  51. return service.findByCondition(creditsDetailDO,page,size);
  52. }catch (Exception e){
  53. e.printStackTrace();
  54. tracer.getCurrentSpan().logEvent(e.getMessage());
  55. return Envelop.getError(e.getMessage());
  56. }
  57. }
  58. /**
  59. * 添加积分
  60. *
  61. * @param creditsDetail 积分对象
  62. * @return
  63. */
  64. @PostMapping(value = HealthBankMapping.healthBank.createCreditsDetail)
  65. @ApiOperation(value = "添加积分记录")
  66. public Envelop<CreditsDetailDO> insert(@ApiParam(name = "creditsDetail",value = "积分记录JSON")
  67. @RequestParam(value = "creditsDetail",required = true)String creditsDetail){
  68. try {
  69. CreditsDetailDO creditsDetailDO = toEntity(creditsDetail,CreditsDetailDO.class);
  70. return service.insert(creditsDetailDO);
  71. }catch (Exception e){
  72. e.printStackTrace();
  73. tracer.getCurrentSpan().logEvent(e.getMessage());
  74. return Envelop.getError(e.getMessage());
  75. }
  76. }
  77. /**
  78. * 查看积分排行
  79. *
  80. * @param object {"filter":[""],"page":"","size":""}
  81. * @return
  82. */
  83. @PostMapping(value = HealthBankMapping.healthBank.selectByRanking)
  84. @ApiOperation(value = "查询积分排名")
  85. public Envelop<AccountDO> selectByRanking(@RequestBody JSONObject object){
  86. try{
  87. JSONArray array = object.getJSONArray("filter");
  88. Integer page = object.getInteger("page");
  89. Integer size = object.getInteger("size");
  90. List<String> patientIds = new ArrayList<>();
  91. for (int i=0;array != null && array.size()!=0&& i<array.size();i++){
  92. patientIds.add(array.getString(i));
  93. }
  94. return service.selectByRanking(patientIds,page,size);
  95. }catch (Exception e){
  96. e.printStackTrace();
  97. tracer.getCurrentSpan().logEvent(e.getMessage());
  98. return Envelop.getError(e.getMessage());
  99. }
  100. }
  101. }