|
|
|
@@ -2,21 +2,50 @@ package com.iformall.service.impl; |
|
|
|
|
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import com.iformall.common.ErrorCode; |
|
|
|
import com.iformall.common.IdWorker; |
|
|
|
import com.iformall.common.ResultData; |
|
|
|
import com.iformall.domain.po.WxCoupon; |
|
|
|
import com.iformall.domain.po.WxCouponPassword; |
|
|
|
import com.iformall.domain.po.WxCouponPresent; |
|
|
|
import com.iformall.enums.EnumCouponPasswordStatus; |
|
|
|
import com.iformall.enums.EnumCouponStatus; |
|
|
|
import com.iformall.enums.EnumCouponValidType; |
|
|
|
import com.iformall.exception.MallinkException; |
|
|
|
import com.iformall.mapper.WxCouponPasswordMapper; |
|
|
|
import com.iformall.mapper.WxCouponPresentMapper; |
|
|
|
import com.iformall.service.PushLimitService; |
|
|
|
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.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashSet; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* @author gongbiao |
|
|
|
*/ |
|
|
|
@Service |
|
|
|
public class WxCouponPresentServiceImpl implements WxCouponPresentService { |
|
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass()); |
|
|
|
|
|
|
|
@Autowired |
|
|
|
WxCouponPresentMapper wxCouponPresentMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
PushLimitService pushLimitService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
WxCouponService wxCouponService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
WxCouponPasswordMapper wxCouponPasswordMapper; |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageInfo<WxCouponPresent> listAsPage(WxCouponPresent record, Integer pageIndex, Integer pageSize) { |
|
|
|
@@ -28,4 +57,50 @@ public class WxCouponPresentServiceImpl implements WxCouponPresentService { |
|
|
|
return wxCouponPresentMapper.selectByPrimaryKey(id); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public ResultData add(WxCouponPresent record) { |
|
|
|
try { |
|
|
|
pushLimitService.checkSendTime(record.getTenantId()); |
|
|
|
} 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<String> phoneSetTemp = new HashSet<>(Arrays.asList(phoneSplit)); |
|
|
|
Set<String> phoneSet = phoneSetTemp.stream().filter(p -> !p.isEmpty()).collect(Collectors.toSet()); |
|
|
|
|
|
|
|
WxCouponPassword wxCouponPassword = new WxCouponPassword(); |
|
|
|
wxCouponPassword.setTenantId(record.getTenantId()); |
|
|
|
wxCouponPassword.setCouponId(record.getCouponId()); |
|
|
|
wxCouponPassword.setStatus(EnumCouponPasswordStatus.INIT.getCode()); |
|
|
|
int inventory = wxCouponPasswordMapper.selectCount(wxCouponPassword); |
|
|
|
if (phoneSet.size() > inventory) { |
|
|
|
return new ResultData(ErrorCode.REMAIN_IS_EMPTY); |
|
|
|
} |
|
|
|
|
|
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
|
record.setId(idWorker.nextId()); |
|
|
|
|
|
|
|
record.setCouponName(wxCoupon.getTitle()); |
|
|
|
record.setSendAmount(phoneSet.size()); |
|
|
|
|
|
|
|
wxCouponPresentMapper.insertSelective(record); |
|
|
|
//发送短信 |
|
|
|
return new ResultData(); |
|
|
|
} |
|
|
|
|
|
|
|
} |