You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

102 lines
3.8 KiB

  1. package com.simple.controller;
  2. import org.apache.commons.lang3.StringUtils;
  3. import org.apache.log4j.Logger;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.web.bind.annotation.GetMapping;
  6. import org.springframework.web.bind.annotation.ModelAttribute;
  7. import org.springframework.web.bind.annotation.PostMapping;
  8. import org.springframework.web.bind.annotation.RequestBody;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RestController;
  11. import com.alibaba.fastjson.JSON;
  12. import com.github.pagehelper.PageInfo;
  13. import com.simple.common.Result;
  14. import com.simple.common.ResultData;
  15. import com.simple.domain.po.WxCoupon;
  16. import com.simple.domain.po.WxMerchant;
  17. import com.simple.service.WxCouponService;
  18. import com.simple.service.WxMerchantService;
  19. import io.swagger.annotations.Api;
  20. import io.swagger.annotations.ApiImplicitParam;
  21. import io.swagger.annotations.ApiImplicitParams;
  22. import io.swagger.annotations.ApiOperation;
  23. @RestController
  24. @RequestMapping("wxCoupon")
  25. @Api(description="优惠券接口")
  26. public class WxCouponController extends BaseController
  27. {
  28. @Autowired
  29. private WxCouponService wxCouponService;
  30. @Autowired
  31. private WxMerchantService wxMerchantService;
  32. private Logger logger = Logger.getLogger(WxCouponController.class);
  33. @ApiOperation("分页列表接口")
  34. @GetMapping("list")
  35. @ApiImplicitParams({
  36. @ApiImplicitParam(name="pageNum",value="页数",dataType="int", paramType = "query",required=true),
  37. @ApiImplicitParam(name="pageSize",value="每页条数",dataType="int", paramType = "query",required=true)})
  38. public ResultData list(@ModelAttribute WxCoupon wxCoupon,Integer pageNum, Integer pageSize) {
  39. if (null == wxCoupon) wxCoupon = new WxCoupon();
  40. if(wxCoupon.getType()!=null&&wxCoupon.getType()==-1){
  41. wxCoupon.setType(null);
  42. }
  43. final PageInfo<WxCoupon> page = wxCouponService.listAsPage(wxCoupon, pageNum, pageSize);
  44. return new ResultData(page);
  45. }
  46. @ApiOperation("新增接口")
  47. @PostMapping("add")
  48. public ResultData add(@RequestBody WxCoupon wxCoupon) {
  49. //Assert.notNull(wxCoupon.getName(), "角色名不能为空");
  50. //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名");
  51. if(StringUtils.isNotBlank(wxCoupon.getBusiness())) {
  52. String[] arys = wxCoupon.getBusiness().split(",");
  53. wxCoupon.setBusiness(JSON.toJSONString(arys));
  54. }
  55. Long id = wxCouponService.saveOrUpdate(wxCoupon);
  56. return new ResultData(id);
  57. }
  58. @ApiOperation("根据id更新接口")
  59. @PostMapping("update")
  60. public ResultData update(@RequestBody WxCoupon wxCoupon) {
  61. if(wxCoupon.getId()==null) {
  62. return new ResultData(ResultData.ERROR,"缺少id");
  63. }
  64. if(StringUtils.isNotBlank(wxCoupon.getBusiness())) {
  65. String[] arys = wxCoupon.getBusiness().split(",");
  66. wxCoupon.setBusiness(JSON.toJSONString(arys));
  67. }
  68. Long id = wxCouponService.saveOrUpdate(wxCoupon);
  69. return new ResultData(id);
  70. }
  71. @ApiOperation("根据id删除接口")
  72. @GetMapping("/del")
  73. @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true)
  74. public ResultData delete(Long id) {
  75. wxCouponService.deleteById(id);
  76. return new ResultData(Result.SUCCESS, "删除成功", null);
  77. }
  78. @ApiOperation("根据id查询接口")
  79. @GetMapping("/findById")
  80. @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true)
  81. public ResultData findById(Long id) {
  82. WxCoupon c = wxCouponService.getById(id);
  83. WxMerchant merchant = wxMerchantService.getById(c.getMerchantId());
  84. c.setWxMerchant(merchant);
  85. return new ResultData(Result.SUCCESS,"查询成功",c);
  86. }
  87. }