CreditsDetailController.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. @PostMapping(value = HealthBankMapping.healthBank.findCreditsLogInfo)
  34. @ApiOperation(value = "查看积分记录")
  35. public Envelop<CreditsDetailDO> selectCreditsLogInfo(@ApiParam(name = "creditsDetail",value = "积分记录JSON")
  36. @RequestParam(value = "creditsDetail",required = false)String creditsDetail,
  37. @ApiParam(name = "page", value = "第几页,从1开始")
  38. @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
  39. @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
  40. @RequestParam(value = "size", required = false)Integer size){
  41. try{
  42. CreditsDetailDO creditsDetailDO = toEntity(creditsDetail,CreditsDetailDO.class);
  43. return service.findByCondition(creditsDetailDO,page,size);
  44. }catch (Exception e){
  45. e.printStackTrace();
  46. tracer.getCurrentSpan().logEvent(e.getMessage());
  47. return Envelop.getError(e.getMessage());
  48. }
  49. }
  50. /**
  51. * 添加积分
  52. *
  53. * @param creditsDetail
  54. * @return
  55. */
  56. @PostMapping(value = HealthBankMapping.healthBank.createCreditsDetail)
  57. @ApiOperation(value = "添加积分记录")
  58. public Envelop<Boolean> insert(@ApiParam(name = "creditsDetail",value = "积分记录JSON")
  59. @RequestParam(value = "creditsDetail",required = true)String creditsDetail){
  60. try {
  61. CreditsDetailDO creditsDetailDO = toEntity(creditsDetail,CreditsDetailDO.class);
  62. return service.insert(creditsDetailDO);
  63. }catch (Exception e){
  64. e.printStackTrace();
  65. tracer.getCurrentSpan().logEvent(e.getMessage());
  66. return Envelop.getError(e.getMessage());
  67. }
  68. }
  69. @PostMapping(value = HealthBankMapping.healthBank.selectByRanking)
  70. @ApiOperation(value = "查询积分排名")
  71. public Envelop<AccountDO> selectByRanking(@RequestBody JSONObject object){
  72. try{
  73. JSONArray array = object.getJSONArray("filter");
  74. Integer page = object.getInteger("page");
  75. Integer size = object.getInteger("size");
  76. List<String> patientIds = new ArrayList<>();
  77. for (int i=0;array != null && array.size()!=0&& i<array.size();i++){
  78. patientIds.add(array.getString(i));
  79. }
  80. return service.selectByRanking(patientIds,page,size);
  81. }catch (Exception e){
  82. e.printStackTrace();
  83. tracer.getCurrentSpan().logEvent(e.getMessage());
  84. return Envelop.getError(e.getMessage());
  85. }
  86. }
  87. }