Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 

174 строки
7.0 KiB

  1. package com.simple.controller;
  2. import com.simple.domain.po.WxCouponChannel;
  3. import com.simple.service.WxCouponChannelService;
  4. import org.apache.commons.lang3.StringUtils;
  5. import org.apache.log4j.Logger;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.web.bind.annotation.GetMapping;
  8. import org.springframework.web.bind.annotation.ModelAttribute;
  9. import org.springframework.web.bind.annotation.PostMapping;
  10. import org.springframework.web.bind.annotation.RequestBody;
  11. import org.springframework.web.bind.annotation.RequestMapping;
  12. import org.springframework.web.bind.annotation.RestController;
  13. import com.alibaba.fastjson.JSON;
  14. import com.github.pagehelper.PageInfo;
  15. import com.simple.common.Result;
  16. import com.simple.common.ResultData;
  17. import com.simple.domain.dto.WxCounponDto;
  18. import com.simple.domain.po.WxCoupon;
  19. import com.simple.domain.po.WxMerchant;
  20. import com.simple.service.WxCouponService;
  21. import com.simple.service.WxMerchantService;
  22. import io.swagger.annotations.Api;
  23. import io.swagger.annotations.ApiImplicitParam;
  24. import io.swagger.annotations.ApiImplicitParams;
  25. import io.swagger.annotations.ApiOperation;
  26. import java.util.ArrayList;
  27. import java.util.Collections;
  28. import java.util.List;
  29. import java.util.Map;
  30. import java.util.stream.Collectors;
  31. @RestController
  32. @RequestMapping("wxCoupon")
  33. @Api(description="优惠券接口")
  34. public class WxCouponController extends BaseController
  35. {
  36. @Autowired
  37. private WxCouponService wxCouponService;
  38. @Autowired
  39. private WxMerchantService wxMerchantService;
  40. @Autowired
  41. private WxCouponChannelService wxCouponChannelService;
  42. private Logger logger = Logger.getLogger(WxCouponController.class);
  43. @ApiOperation("分页列表接口")
  44. @GetMapping("list")
  45. @ApiImplicitParams({
  46. @ApiImplicitParam(name="pageNum",value="页数",dataType="int", paramType = "query",required=true),
  47. @ApiImplicitParam(name="pageSize",value="每页条数",dataType="int", paramType = "query",required=true)})
  48. public ResultData list(@ModelAttribute WxCoupon wxCoupon,Integer pageNum, Integer pageSize) {
  49. if (null == wxCoupon) wxCoupon = new WxCoupon();
  50. wxCoupon.setTenantId(getTenantId());
  51. PageInfo<WxCoupon> page = null;
  52. if (wxCoupon.getStatus() != null && wxCoupon.getStatus() == -1) {
  53. page = wxCouponService.findEnableList(wxCoupon, pageNum, pageSize);
  54. }else {
  55. page = wxCouponService.listAsPage(wxCoupon, pageNum, pageSize);
  56. }
  57. List<WxCoupon> wxCouponList = page.getList();
  58. List<Long> ids = wxCouponList.stream().map(p->p.getId()).collect(Collectors.toList());
  59. WxCouponChannel wxCouponChannel = new WxCouponChannel();
  60. wxCouponChannel.setTenantId(getTenantId());
  61. wxCouponChannel.setCouponIds(ids);
  62. wxCouponChannel.setStatus(0);
  63. //上架状态
  64. List<WxCouponChannel> list = wxCouponChannelService.listAsPage(wxCouponChannel,1,5).getList();
  65. if(!list.isEmpty()){
  66. Map<Long, List<WxCouponChannel>> groupBy = list.stream().collect(Collectors.groupingBy(WxCouponChannel::getCouponId));
  67. for (WxCoupon temp:wxCouponList) {
  68. List<Integer> channels=new ArrayList<>();
  69. if(groupBy.get(temp.getId())!=null){
  70. for (WxCouponChannel tempchannel:groupBy.get(temp.getId())) {
  71. channels.add(tempchannel.getTargetAd());
  72. }
  73. }
  74. String sss = JSON.toJSONString(channels);
  75. temp.setChannels(sss);
  76. }
  77. }
  78. return new ResultData(page);
  79. }
  80. @ApiOperation("新增接口")
  81. @PostMapping("add")
  82. public ResultData add(@RequestBody WxCoupon wxCoupon) {
  83. //Assert.notNull(wxCoupon.getName(), "角色名不能为空");
  84. //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名");
  85. if(StringUtils.isNotEmpty(wxCoupon.getSalePriceStr())){
  86. wxCoupon.setSalePrice((int)Double.parseDouble(wxCoupon.getSalePriceStr())*100);
  87. }
  88. if(StringUtils.isNotEmpty(wxCoupon.getUsePriceStr())){
  89. wxCoupon.setUsePrice((int)Double.parseDouble(wxCoupon.getUsePriceStr())*100);
  90. }
  91. if(StringUtils.isNotEmpty(wxCoupon.getPriceStr())){
  92. wxCoupon.setPrice((int)Double.parseDouble(wxCoupon.getPriceStr())*100);
  93. }
  94. if(StringUtils.isNotBlank(wxCoupon.getBusiness())) {
  95. String[] arys = wxCoupon.getBusiness().split(",");
  96. wxCoupon.setBusiness(JSON.toJSONString(arys));
  97. }
  98. wxCoupon.setTenantId(getUser().getTenantId());
  99. Long id = wxCouponService.saveOrUpdate(wxCoupon);
  100. return new ResultData(id);
  101. }
  102. @ApiOperation("根据id更新接口")
  103. @PostMapping("update")
  104. public ResultData update(@RequestBody WxCoupon wxCoupon) {
  105. if(wxCoupon.getId()==null) {
  106. return new ResultData(ResultData.ERROR,"缺少id");
  107. }
  108. if(wxCoupon.getStatus()!=null){
  109. if(wxCoupon.getStatus()==3){ //已作废
  110. WxCoupon temp = wxCouponService.getById(wxCoupon.getId());
  111. if(temp.getStatus()==1){
  112. return new ResultData(Result.ERROR,"生效的卡券,不能修改");
  113. }
  114. }
  115. }
  116. if(StringUtils.isNotBlank(wxCoupon.getBusiness())) {
  117. String[] arys = wxCoupon.getBusiness().split(",");
  118. wxCoupon.setBusiness(JSON.toJSONString(arys));
  119. }
  120. Long id = wxCouponService.saveOrUpdate(wxCoupon);
  121. return new ResultData(id);
  122. }
  123. @ApiOperation("根据id删除接口")
  124. @GetMapping("/del")
  125. @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true)
  126. public ResultData delete(Long id) {
  127. wxCouponService.deleteById(id);
  128. return new ResultData(Result.SUCCESS, "删除成功", null);
  129. }
  130. @ApiOperation("根据id查询接口")
  131. @GetMapping("/findById")
  132. @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true)
  133. public ResultData findById(Long id) {
  134. WxCoupon c = wxCouponService.getById(id);
  135. WxCounponDto dto = new WxCounponDto();
  136. org.springframework.beans.BeanUtils.copyProperties(c, dto);
  137. WxMerchant merchant = wxMerchantService.getById(c.getMerchantId());
  138. dto.setWxMerchant(merchant);
  139. return new ResultData(Result.SUCCESS,"查询成功",dto);
  140. }
  141. @ApiOperation("分页列表接口")
  142. @GetMapping("send/list")
  143. @ApiImplicitParams({
  144. @ApiImplicitParam(name="pageNum",value="页数",dataType="int", paramType = "query",required=true),
  145. @ApiImplicitParam(name="pageSize",value="每页条数",dataType="int", paramType = "query",required=true)})
  146. public ResultData sendList(@ModelAttribute WxCoupon wxCoupon,Integer pageNum, Integer pageSize) {
  147. if (null == wxCoupon) wxCoupon = new WxCoupon();
  148. wxCoupon.setTenantId(getTenantId());
  149. wxCoupon.setStatus(1);
  150. PageInfo<WxCoupon> page = null;
  151. page = wxCouponService.findCanSendList(wxCoupon, pageNum, pageSize);
  152. return new ResultData(page);
  153. }
  154. }