GoodsController.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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.GoodsDO;
  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.GoodsService;
  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:42
  21. * @desc goods service
  22. **/
  23. @RestController
  24. @RequestMapping(HealthBankMapping.api_health_bank_common)
  25. @Api(tags = "健康服务商品相关操作",description = "健康服务商品相关操作")
  26. public class GoodsController extends EnvelopRestController {
  27. @Autowired
  28. private GoodsService service;
  29. @Autowired
  30. private Tracer tracer;
  31. /**
  32. * patient publish gooods
  33. *
  34. * @param goods 商品对象
  35. * @return
  36. */
  37. @PostMapping(value = HealthBankMapping.healthBank.createGoods)
  38. @ApiOperation(value = "上架服务商品")
  39. public Envelop<Boolean> publishGoods(@ApiParam(name = "goods",value = "健康服务商品JSON")
  40. @RequestParam(value = "goods",required = true)String goods){
  41. try {
  42. GoodsDO goodsDO = toEntity(goods,GoodsDO.class);
  43. service.insert(goodsDO);
  44. return service.insert(goodsDO);
  45. }catch (Exception e){
  46. e.printStackTrace();
  47. tracer.getCurrentSpan().logEvent(e.getMessage());
  48. return Envelop.getError(e.getMessage());
  49. }
  50. }
  51. /**
  52. * find health goods
  53. *
  54. * @param goods 商品对象
  55. * @param page 页码
  56. * @param size 每页大小
  57. * @return
  58. */
  59. @PostMapping(value = HealthBankMapping.healthBank.findGoods)
  60. @ApiOperation(value = "查看健康服务商品")
  61. public Envelop<GoodsDO> getActivityInfo(@ApiParam(name = "goods",value = "健康服务商品JSON")
  62. @RequestParam(value = "goods",required = false)String goods,
  63. @ApiParam(name = "page", value = "第几页,从1开始")
  64. @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
  65. @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
  66. @RequestParam(value = "size", required = false)Integer size){
  67. try{
  68. GoodsDO goodsDO = toEntity(goods,GoodsDO.class);
  69. return service.findByCondition(goodsDO,page,size);
  70. }catch (Exception e){
  71. e.printStackTrace();
  72. tracer.getCurrentSpan().logEvent(e.getMessage());
  73. return Envelop.getError(e.getMessage());
  74. }
  75. }
  76. /**
  77. * patient update goods status
  78. *
  79. * @param goods 商品对象
  80. * @return
  81. */
  82. @PostMapping(value = HealthBankMapping.healthBank.updateGoods)
  83. @ApiOperation(value = "更新健康服务商品")
  84. public Envelop<Boolean> updateActivity(@ApiParam(name = "goods",value = "健康服务商品JSON")
  85. @RequestParam(value = "goods",required = true)String goods){
  86. try {
  87. GoodsDO goodsDO = toEntity(goods,GoodsDO.class);
  88. return service.update(goodsDO);
  89. }catch (Exception e){
  90. e.printStackTrace();
  91. tracer.getCurrentSpan().logEvent(e.getMessage());
  92. return Envelop.getError(e.getMessage());
  93. }
  94. }
  95. }