| @@ -5,14 +5,13 @@ import com.iformall.annotation.SystemControllerLog; | |||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.controller.base.BaseController; | import com.iformall.controller.base.BaseController; | ||||
| import com.iformall.domain.po.BaseEntity; | |||||
| import com.iformall.domain.po.MallUserInfo; | |||||
| import com.iformall.domain.po.WxCoupon; | |||||
| import com.iformall.domain.po.WxCouponPresent; | |||||
| import com.iformall.domain.po.*; | |||||
| import com.iformall.enums.EnumCouponPasswordStatus; | |||||
| import com.iformall.enums.EnumCouponStatus; | import com.iformall.enums.EnumCouponStatus; | ||||
| import com.iformall.enums.EnumCouponValidType; | import com.iformall.enums.EnumCouponValidType; | ||||
| import com.iformall.exception.MallinkException; | import com.iformall.exception.MallinkException; | ||||
| import com.iformall.service.PushLimitService; | import com.iformall.service.PushLimitService; | ||||
| import com.iformall.service.WxCouponPasswordService; | |||||
| import com.iformall.service.WxCouponPresentService; | import com.iformall.service.WxCouponPresentService; | ||||
| import com.iformall.service.WxCouponService; | import com.iformall.service.WxCouponService; | ||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| @@ -25,6 +24,9 @@ import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||
| import java.util.Date; | import java.util.Date; | ||||
| import java.util.HashSet; | |||||
| import java.util.List; | |||||
| import java.util.Set; | |||||
| /** | /** | ||||
| * @author gongbiao | * @author gongbiao | ||||
| @@ -44,6 +46,9 @@ public class WxCouponPresentController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| WxCouponService wxCouponService; | WxCouponService wxCouponService; | ||||
| @Autowired | |||||
| WxCouponPasswordService wxCouponPasswordService; | |||||
| @ApiOperation("分页列表接口") | @ApiOperation("分页列表接口") | ||||
| @GetMapping("/list") | @GetMapping("/list") | ||||
| @ApiImplicitParams({ | @ApiImplicitParams({ | ||||
| @@ -99,8 +104,30 @@ public class WxCouponPresentController extends BaseController { | |||||
| if (!wxCoupon.getStatus().equals(EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode())) { | if (!wxCoupon.getStatus().equals(EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode())) { | ||||
| return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF); | return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF); | ||||
| } | } | ||||
| //获取手机号 | |||||
| String phones = wxCouponPresent.getPhones(); | |||||
| String[] phoneSplit = phones.split(","); | |||||
| Set<String> phoneSet = new HashSet<>(phoneSplit.length); | |||||
| for (String phone : phoneSplit) { | |||||
| if (!phone.isEmpty()) { | |||||
| phoneSet.add(phone); | |||||
| } | |||||
| } | |||||
| //查询有效券数量 | |||||
| WxCouponPassword wxCouponPassword = new WxCouponPassword(); | |||||
| wxCouponPassword.setTenantId(user.getTenantId()); | |||||
| wxCouponPassword.setCouponId(wxCouponPresent.getCouponId()); | |||||
| wxCouponPassword.setStatus(EnumCouponPasswordStatus.INIT.getCode()); | |||||
| List<WxCouponPassword> list = wxCouponPasswordService.findList(wxCouponPassword); | |||||
| if (phoneSet.size() > list.size()) { | |||||
| logger.info(ErrorCode.REMAIN_IS_EMPTY.getMessage()); | |||||
| return new ResultData(ErrorCode.REMAIN_IS_EMPTY); | |||||
| } | |||||
| wxCouponPresent.setCouponName(wxCoupon.getTitle()); | wxCouponPresent.setCouponName(wxCoupon.getTitle()); | ||||
| return wxCouponPresentService.add(wxCouponPresent); | |||||
| wxCouponPresentService.add(wxCouponPresent, list, phoneSet); | |||||
| return new ResultData(); | |||||
| } | } | ||||
| } | } | ||||
| @@ -6,6 +6,7 @@ import com.iformall.domain.vo.WxCouponPasswordCountInfoVO; | |||||
| import javax.servlet.http.HttpServletRequest; | import javax.servlet.http.HttpServletRequest; | ||||
| import javax.servlet.http.HttpServletResponse; | import javax.servlet.http.HttpServletResponse; | ||||
| import java.util.List; | |||||
| public interface WxCouponPasswordService { | public interface WxCouponPasswordService { | ||||
| @@ -67,4 +68,5 @@ public interface WxCouponPasswordService { | |||||
| PageInfo<WxCouponPasswordCountInfoVO> findCouponList(WxCouponPassword wxCouponPassword, Integer pageNum, Integer pageSize); | PageInfo<WxCouponPasswordCountInfoVO> findCouponList(WxCouponPassword wxCouponPassword, Integer pageNum, Integer pageSize); | ||||
| List<WxCouponPassword> findList(WxCouponPassword wxCouponPassword); | |||||
| } | } | ||||
| @@ -2,8 +2,12 @@ package com.iformall.service; | |||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.WxCouponPassword; | |||||
| import com.iformall.domain.po.WxCouponPresent; | import com.iformall.domain.po.WxCouponPresent; | ||||
| import java.util.List; | |||||
| import java.util.Set; | |||||
| /** | /** | ||||
| * @author gongbiao | * @author gongbiao | ||||
| */ | */ | ||||
| @@ -14,6 +18,6 @@ public interface WxCouponPresentService { | |||||
| WxCouponPresent findById(Long id); | WxCouponPresent findById(Long id); | ||||
| ResultData add(WxCouponPresent wxCouponPresent); | |||||
| ResultData add(WxCouponPresent wxCouponPresent, List<WxCouponPassword> list, Set<String> phoneSet); | |||||
| } | } | ||||
| @@ -161,6 +161,11 @@ public class WxCouponPasswordServiceImpl implements WxCouponPasswordService { | |||||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponPasswordMapper.findCouponCountInfo(record)); | return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponPasswordMapper.findCouponCountInfo(record)); | ||||
| } | } | ||||
| @Override | |||||
| public List<WxCouponPassword> findList(WxCouponPassword wxCouponPassword) { | |||||
| return wxCouponPasswordMapper.findList(wxCouponPassword); | |||||
| } | |||||
| /* | /* | ||||
| public static void main(String[] args) { | public static void main(String[] args) { | ||||
| WxCouponPasswordServiceImpl ll = new WxCouponPasswordServiceImpl(); | WxCouponPasswordServiceImpl ll = new WxCouponPasswordServiceImpl(); | ||||
| @@ -2,7 +2,6 @@ package com.iformall.service.impl; | |||||
| import com.github.pagehelper.PageHelper; | import com.github.pagehelper.PageHelper; | ||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.IdWorker; | import com.iformall.common.IdWorker; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.WxAppinfo; | import com.iformall.domain.po.WxAppinfo; | ||||
| @@ -54,27 +53,9 @@ public class WxCouponPresentServiceImpl implements WxCouponPresentService { | |||||
| @Async | @Async | ||||
| @Override | @Override | ||||
| public ResultData add(WxCouponPresent record) { | |||||
| public ResultData add(WxCouponPresent record, List<WxCouponPassword> list, Set<String> phoneSet) { | |||||
| String tenantId = record.getTenantId(); | String tenantId = record.getTenantId(); | ||||
| //获取手机号 | |||||
| String phones = record.getPhones(); | |||||
| String[] phoneSplit = phones.split(","); | |||||
| Set<String> phoneSet = new HashSet<>(phoneSplit.length); | |||||
| for (String phone : phoneSplit) { | |||||
| if (!phone.isEmpty()) { | |||||
| phoneSet.add(phone); | |||||
| } | |||||
| } | |||||
| //查询有效券数量 | |||||
| WxCouponPassword wxCouponPassword = new WxCouponPassword(); | |||||
| wxCouponPassword.setTenantId(tenantId); | |||||
| wxCouponPassword.setCouponId(record.getCouponId()); | |||||
| wxCouponPassword.setStatus(EnumCouponPasswordStatus.INIT.getCode()); | |||||
| List<WxCouponPassword> list = wxCouponPasswordMapper.findList(wxCouponPassword); | |||||
| if (phoneSet.size() > list.size()) { | |||||
| logger.info(ErrorCode.REMAIN_IS_EMPTY.getMessage()); | |||||
| return new ResultData(ErrorCode.REMAIN_IS_EMPTY); | |||||
| } | |||||
| //添加记录 | //添加记录 | ||||
| final IdWorker idWorker = IdWorker.get(); | final IdWorker idWorker = IdWorker.get(); | ||||
| long id = idWorker.nextId(); | long id = idWorker.nextId(); | ||||