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.
 
 
 
 
 

103 lines
4.1 KiB

  1. package com.simple.controller;
  2. import com.github.pagehelper.PageInfo;
  3. import com.simple.common.ErrorCode;
  4. import com.simple.common.Result;
  5. import com.simple.common.ResultData;
  6. import com.simple.domain.po.WxCoupon;
  7. import com.simple.domain.po.WxCouponSend;
  8. import com.simple.enums.EnumCouponSendType;
  9. import com.simple.enums.EnumCouponStatus;
  10. import com.simple.service.WxCouponSendService;
  11. import com.simple.service.WxCouponService;
  12. import io.swagger.annotations.ApiImplicitParam;
  13. import io.swagger.annotations.ApiImplicitParams;
  14. import io.swagger.annotations.ApiOperation;
  15. import org.slf4j.Logger;
  16. import org.slf4j.LoggerFactory;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.web.bind.annotation.*;
  19. import java.util.List;
  20. @RestController
  21. @RequestMapping("wxCouponSend")
  22. public class WxCouponSendController extends BaseController {
  23. private final Logger logger = LoggerFactory.getLogger(this.getClass());
  24. @Autowired
  25. private WxCouponSendService wxCouponSendService;
  26. @Autowired
  27. private WxCouponService wxCouponService;
  28. @ApiOperation("分页列表接口")
  29. @GetMapping("list")
  30. @ApiImplicitParams({
  31. @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
  32. @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)})
  33. public ResultData list(@ModelAttribute WxCouponSend wxCouponSend, Integer pageNum, Integer pageSize) {
  34. if (null == wxCouponSend) wxCouponSend = new WxCouponSend();
  35. wxCouponSend.setTenantId(getTenantId());
  36. final PageInfo<WxCouponSend> page = wxCouponSendService.listAsPage(wxCouponSend, pageNum, pageSize);
  37. return new ResultData(page);
  38. }
  39. @ApiOperation("新增接口")
  40. @PostMapping("add")
  41. public ResultData add(@RequestBody WxCouponSend wxCouponSend) {
  42. if (null == wxCouponSend) {
  43. return new ResultData(ErrorCode.SYS_PARAMETER_ERROR);
  44. }
  45. wxCouponSend.setTenantId(getTenantId());
  46. wxCouponSend.setStatus(0);
  47. List<WxCouponSend> wxCouponSendList = wxCouponSendService.listAsPage(wxCouponSend, 1, 1).getList();
  48. if (wxCouponSendList != null && wxCouponSendList.size() > 0) {
  49. return new ResultData(ErrorCode.COUPON_SEND_IS_EXISTED);
  50. }
  51. WxCoupon wxCoupon = wxCouponService.getById(wxCouponSend.getCouponId());
  52. if (wxCoupon.getStatus() != EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode()){
  53. return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF);
  54. }
  55. if (wxCoupon.getSendType() != EnumCouponSendType.PASSIVE.getCode()) {
  56. return new ResultData(ErrorCode.COUPON_TYPE_IS_NOT_PASSIVE);
  57. }
  58. wxCouponSend.setMerchantId(wxCoupon.getMerchantId());
  59. wxCouponSend.setType(wxCoupon.getType());
  60. wxCouponSend.setTenantId(wxCoupon.getTenantId());
  61. wxCouponSend.setTitle(wxCoupon.getTitle());
  62. //Assert.notNull(wxCouponSend.getName(), "角色名不能为空");
  63. //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名");
  64. wxCouponSendService.saveOrUpdate(wxCouponSend);
  65. return new ResultData();
  66. }
  67. @ApiOperation("根据id更新接口")
  68. @PostMapping("update")
  69. public ResultData update(@RequestBody WxCouponSend wxCouponSend) {
  70. wxCouponSend.setTenantId(getTenantId());
  71. wxCouponSendService.saveOrUpdate(wxCouponSend);
  72. return new ResultData();
  73. }
  74. @ApiOperation("根据id删除接口")
  75. @GetMapping("/del")
  76. @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)
  77. public ResultData delete(Long id) {
  78. wxCouponSendService.deleteById(id);
  79. return new ResultData(Result.SUCCESS, "删除成功", null);
  80. }
  81. @ApiOperation("根据id查询接口")
  82. @GetMapping("/findById")
  83. @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)
  84. public ResultData findById(Long id) {
  85. return new ResultData(Result.SUCCESS, "查询成功", wxCouponSendService.getById(id));
  86. }
  87. }