diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponPresentController.java b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponPresentController.java index c07cc5c23..7e84eb485 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponPresentController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponPresentController.java @@ -7,8 +7,14 @@ import com.iformall.common.ResultData; 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.enums.EnumCouponStatus; +import com.iformall.enums.EnumCouponValidType; +import com.iformall.exception.MallinkException; +import com.iformall.service.PushLimitService; import com.iformall.service.WxCouponPresentService; +import com.iformall.service.WxCouponService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -18,6 +24,8 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.util.Date; + /** * @author gongbiao */ @@ -30,6 +38,12 @@ public class WxCouponPresentController extends BaseController { @Autowired private WxCouponPresentService wxCouponPresentService; + @Autowired + PushLimitService pushLimitService; + + @Autowired + WxCouponService wxCouponService; + @ApiOperation("分页列表接口") @GetMapping("/list") @ApiImplicitParams({ @@ -67,11 +81,25 @@ public class WxCouponPresentController extends BaseController { if (wxCouponPresent.getPhones().isEmpty()) { return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "请填写手机号"); } - MallUserInfo user = getUser(); - wxCouponPresent.setTenantId(user.getTenantId()); wxCouponPresent.setUserId(user.getId()); - + wxCouponPresent.setTenantId(user.getTenantId()); + try { + pushLimitService.checkSendTime(user.getTenantId()); + } catch (MallinkException e) { + logger.error(e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + } + WxCoupon wxCoupon = wxCouponService.getById(wxCouponPresent.getCouponId()); + if (wxCoupon.getValidType().equals(EnumCouponValidType.BETWEEN_TWO_TIME.getCode())) { //时间范围 + if (new Date().after(wxCoupon.getValidEndDate())) { + return new ResultData(ErrorCode.COUPON_IS_EXPIRED); + } + } + if (!wxCoupon.getStatus().equals(EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode())) { + return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF); + } + wxCouponPresent.setCouponName(wxCoupon.getTitle()); return wxCouponPresentService.add(wxCouponPresent); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponPresentServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponPresentServiceImpl.java index ced576818..79aca266d 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponPresentServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponPresentServiceImpl.java @@ -6,22 +6,19 @@ import com.iformall.common.ErrorCode; import com.iformall.common.IdWorker; import com.iformall.common.ResultData; import com.iformall.domain.po.WxAppinfo; -import com.iformall.domain.po.WxCoupon; import com.iformall.domain.po.WxCouponPassword; import com.iformall.domain.po.WxCouponPresent; import com.iformall.domain.po.msg.WxMsgRecord; import com.iformall.enums.*; -import com.iformall.exception.MallinkException; import com.iformall.mapper.WxCouponPasswordMapper; import com.iformall.mapper.WxCouponPresentMapper; import com.iformall.mq.MqBaseProducer; -import com.iformall.service.PushLimitService; import com.iformall.service.WxAppinfoService; import com.iformall.service.WxCouponPresentService; -import com.iformall.service.WxCouponService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import java.util.*; @@ -36,12 +33,6 @@ public class WxCouponPresentServiceImpl implements WxCouponPresentService { @Autowired WxCouponPresentMapper wxCouponPresentMapper; - @Autowired - PushLimitService pushLimitService; - - @Autowired - WxCouponService wxCouponService; - @Autowired WxCouponPasswordMapper wxCouponPasswordMapper; @@ -61,26 +52,11 @@ public class WxCouponPresentServiceImpl implements WxCouponPresentService { return wxCouponPresentMapper.selectByPrimaryKey(id); } + @Async @Override public ResultData add(WxCouponPresent record) { String tenantId = record.getTenantId(); - try { - pushLimitService.checkSendTime(tenantId); - } catch (MallinkException e) { - logger.error(e.getMessage()); - return new ResultData(e.getErrorCode(), e.getMessage()); - } - WxCoupon wxCoupon = wxCouponService.getById(record.getCouponId()); - if (wxCoupon.getValidType().equals(EnumCouponValidType.BETWEEN_TWO_TIME.getCode())) { //时间范围 - if (new Date().after(wxCoupon.getValidEndDate())) { - return new ResultData(ErrorCode.COUPON_IS_EXPIRED); - } - } - if (!wxCoupon.getStatus().equals(EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode())) { - return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF); - } //获取手机号 - record.setCouponName(wxCoupon.getTitle()); String phones = record.getPhones(); String[] phoneSplit = phones.split(","); Set phoneSet = new HashSet<>(phoneSplit.length); @@ -89,7 +65,6 @@ public class WxCouponPresentServiceImpl implements WxCouponPresentService { phoneSet.add(phone); } } - //查询有效券数量 WxCouponPassword wxCouponPassword = new WxCouponPassword(); wxCouponPassword.setTenantId(tenantId); @@ -97,20 +72,20 @@ public class WxCouponPresentServiceImpl implements WxCouponPresentService { wxCouponPassword.setStatus(EnumCouponPasswordStatus.INIT.getCode()); List 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(); long id = idWorker.nextId(); record.setId(id); - record.setCouponName(wxCoupon.getTitle()); record.setSendAmount(phoneSet.size()); wxCouponPresentMapper.insertSelective(record); //小程序 WxAppinfo appInfo = wxAppinfoService.getCAppInfo(tenantId); - String title = wxCoupon.getTitle(); + String title = record.getCouponName(); String name = appInfo.getName(); - List tempList = wxCouponPasswordMapper.findList(wxCouponPassword); + List tempList = new ArrayList<>(); //循环发送 int i = 0; for (String phone : phoneSet) {