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.
 
 
 
 
 

113 lines
4.3 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.dto.WxCounponDto;
  16. import com.simple.domain.po.WxCoupon;
  17. import com.simple.domain.po.WxMerchant;
  18. import com.simple.service.WxCouponService;
  19. import com.simple.service.WxMerchantService;
  20. import io.swagger.annotations.Api;
  21. import io.swagger.annotations.ApiImplicitParam;
  22. import io.swagger.annotations.ApiImplicitParams;
  23. import io.swagger.annotations.ApiOperation;
  24. @RestController
  25. @RequestMapping("wxCoupon")
  26. @Api(description="优惠券接口")
  27. public class WxCouponController extends BaseController
  28. {
  29. @Autowired
  30. private WxCouponService wxCouponService;
  31. @Autowired
  32. private WxMerchantService wxMerchantService;
  33. private Logger logger = Logger.getLogger(WxCouponController.class);
  34. @ApiOperation("分页列表接口")
  35. @GetMapping("list")
  36. @ApiImplicitParams({
  37. @ApiImplicitParam(name="pageNum",value="页数",dataType="int", paramType = "query",required=true),
  38. @ApiImplicitParam(name="pageSize",value="每页条数",dataType="int", paramType = "query",required=true)})
  39. public ResultData list(@ModelAttribute WxCoupon wxCoupon,Integer pageNum, Integer pageSize) {
  40. if (null == wxCoupon) wxCoupon = new WxCoupon();
  41. if(wxCoupon.getType()!=null&&wxCoupon.getType()==-1){
  42. wxCoupon.setType(null);
  43. }
  44. final PageInfo<WxCoupon> page = wxCouponService.listAsPage(wxCoupon, pageNum, pageSize);
  45. return new ResultData(page);
  46. }
  47. @ApiOperation("新增接口")
  48. @PostMapping("add")
  49. public ResultData add(@RequestBody WxCoupon wxCoupon) {
  50. //Assert.notNull(wxCoupon.getName(), "角色名不能为空");
  51. //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名");
  52. if(StringUtils.isNotBlank(wxCoupon.getBusiness())) {
  53. String[] arys = wxCoupon.getBusiness().split(",");
  54. wxCoupon.setBusiness(JSON.toJSONString(arys));
  55. }
  56. Long id = wxCouponService.saveOrUpdate(wxCoupon);
  57. return new ResultData(id);
  58. }
  59. @ApiOperation("根据id更新接口")
  60. @PostMapping("update")
  61. public ResultData update(@RequestBody WxCoupon wxCoupon) {
  62. if(wxCoupon.getId()==null) {
  63. return new ResultData(ResultData.ERROR,"缺少id");
  64. }
  65. if(wxCoupon.getStatus()!=null){
  66. if(wxCoupon.getStatus()==3){ //已作废
  67. WxCoupon temp = wxCouponService.getById(wxCoupon.getId());
  68. if(temp.getStatus()==1){
  69. return new ResultData(Result.ERROR,"生效的卡券,不能修改");
  70. }
  71. }
  72. }
  73. if(StringUtils.isNotBlank(wxCoupon.getBusiness())) {
  74. String[] arys = wxCoupon.getBusiness().split(",");
  75. wxCoupon.setBusiness(JSON.toJSONString(arys));
  76. }
  77. Long id = wxCouponService.saveOrUpdate(wxCoupon);
  78. return new ResultData(id);
  79. }
  80. @ApiOperation("根据id删除接口")
  81. @GetMapping("/del")
  82. @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true)
  83. public ResultData delete(Long id) {
  84. wxCouponService.deleteById(id);
  85. return new ResultData(Result.SUCCESS, "删除成功", null);
  86. }
  87. @ApiOperation("根据id查询接口")
  88. @GetMapping("/findById")
  89. @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true)
  90. public ResultData findById(Long id) {
  91. WxCoupon c = wxCouponService.getById(id);
  92. WxCounponDto dto = new WxCounponDto();
  93. org.springframework.beans.BeanUtils.copyProperties(c, dto);
  94. WxMerchant merchant = wxMerchantService.getById(c.getMerchantId());
  95. dto.setWxMerchant(merchant);
  96. return new ResultData(Result.SUCCESS,"查询成功",dto);
  97. }
  98. }