|
|
@@ -6,22 +6,19 @@ 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; |
|
|
import com.iformall.domain.po.WxCoupon; |
|
|
|
|
|
import com.iformall.domain.po.WxCouponPassword; |
|
|
import com.iformall.domain.po.WxCouponPassword; |
|
|
import com.iformall.domain.po.WxCouponPresent; |
|
|
import com.iformall.domain.po.WxCouponPresent; |
|
|
import com.iformall.domain.po.msg.WxMsgRecord; |
|
|
import com.iformall.domain.po.msg.WxMsgRecord; |
|
|
import com.iformall.enums.*; |
|
|
import com.iformall.enums.*; |
|
|
import com.iformall.exception.MallinkException; |
|
|
|
|
|
import com.iformall.mapper.WxCouponPasswordMapper; |
|
|
import com.iformall.mapper.WxCouponPasswordMapper; |
|
|
import com.iformall.mapper.WxCouponPresentMapper; |
|
|
import com.iformall.mapper.WxCouponPresentMapper; |
|
|
import com.iformall.mq.MqBaseProducer; |
|
|
import com.iformall.mq.MqBaseProducer; |
|
|
import com.iformall.service.PushLimitService; |
|
|
|
|
|
import com.iformall.service.WxAppinfoService; |
|
|
import com.iformall.service.WxAppinfoService; |
|
|
import com.iformall.service.WxCouponPresentService; |
|
|
import com.iformall.service.WxCouponPresentService; |
|
|
import com.iformall.service.WxCouponService; |
|
|
|
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
import org.springframework.scheduling.annotation.Async; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
import java.util.*; |
|
|
import java.util.*; |
|
|
@@ -36,12 +33,6 @@ public class WxCouponPresentServiceImpl implements WxCouponPresentService { |
|
|
@Autowired |
|
|
@Autowired |
|
|
WxCouponPresentMapper wxCouponPresentMapper; |
|
|
WxCouponPresentMapper wxCouponPresentMapper; |
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
PushLimitService pushLimitService; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
WxCouponService wxCouponService; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
WxCouponPasswordMapper wxCouponPasswordMapper; |
|
|
WxCouponPasswordMapper wxCouponPasswordMapper; |
|
|
|
|
|
|
|
|
@@ -61,26 +52,11 @@ public class WxCouponPresentServiceImpl implements WxCouponPresentService { |
|
|
return wxCouponPresentMapper.selectByPrimaryKey(id); |
|
|
return wxCouponPresentMapper.selectByPrimaryKey(id); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Async |
|
|
@Override |
|
|
@Override |
|
|
public ResultData add(WxCouponPresent record) { |
|
|
public ResultData add(WxCouponPresent record) { |
|
|
String tenantId = record.getTenantId(); |
|
|
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 phones = record.getPhones(); |
|
|
String[] phoneSplit = phones.split(","); |
|
|
String[] phoneSplit = phones.split(","); |
|
|
Set<String> phoneSet = new HashSet<>(phoneSplit.length); |
|
|
Set<String> phoneSet = new HashSet<>(phoneSplit.length); |
|
|
@@ -89,7 +65,6 @@ public class WxCouponPresentServiceImpl implements WxCouponPresentService { |
|
|
phoneSet.add(phone); |
|
|
phoneSet.add(phone); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//查询有效券数量 |
|
|
//查询有效券数量 |
|
|
WxCouponPassword wxCouponPassword = new WxCouponPassword(); |
|
|
WxCouponPassword wxCouponPassword = new WxCouponPassword(); |
|
|
wxCouponPassword.setTenantId(tenantId); |
|
|
wxCouponPassword.setTenantId(tenantId); |
|
|
@@ -97,20 +72,20 @@ public class WxCouponPresentServiceImpl implements WxCouponPresentService { |
|
|
wxCouponPassword.setStatus(EnumCouponPasswordStatus.INIT.getCode()); |
|
|
wxCouponPassword.setStatus(EnumCouponPasswordStatus.INIT.getCode()); |
|
|
List<WxCouponPassword> list = wxCouponPasswordMapper.findList(wxCouponPassword); |
|
|
List<WxCouponPassword> list = wxCouponPasswordMapper.findList(wxCouponPassword); |
|
|
if (phoneSet.size() > list.size()) { |
|
|
if (phoneSet.size() > list.size()) { |
|
|
|
|
|
logger.info(ErrorCode.REMAIN_IS_EMPTY.getMessage()); |
|
|
return new ResultData(ErrorCode.REMAIN_IS_EMPTY); |
|
|
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(); |
|
|
record.setId(id); |
|
|
record.setId(id); |
|
|
record.setCouponName(wxCoupon.getTitle()); |
|
|
|
|
|
record.setSendAmount(phoneSet.size()); |
|
|
record.setSendAmount(phoneSet.size()); |
|
|
wxCouponPresentMapper.insertSelective(record); |
|
|
wxCouponPresentMapper.insertSelective(record); |
|
|
//小程序 |
|
|
//小程序 |
|
|
WxAppinfo appInfo = wxAppinfoService.getCAppInfo(tenantId); |
|
|
WxAppinfo appInfo = wxAppinfoService.getCAppInfo(tenantId); |
|
|
String title = wxCoupon.getTitle(); |
|
|
|
|
|
|
|
|
String title = record.getCouponName(); |
|
|
String name = appInfo.getName(); |
|
|
String name = appInfo.getName(); |
|
|
List<WxCouponPassword> tempList = wxCouponPasswordMapper.findList(wxCouponPassword); |
|
|
|
|
|
|
|
|
List<WxCouponPassword> tempList = new ArrayList<>(); |
|
|
//循环发送 |
|
|
//循环发送 |
|
|
int i = 0; |
|
|
int i = 0; |
|
|
for (String phone : phoneSet) { |
|
|
for (String phone : phoneSet) { |
|
|
|