|
|
@@ -1,5 +1,6 @@ |
|
|
package com.iformall.schedule; |
|
|
package com.iformall.schedule; |
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.iformall.domain.dto.WxCUserBasicInfoDto; |
|
|
import com.iformall.domain.dto.WxCUserBasicInfoDto; |
|
|
import com.iformall.domain.po.*; |
|
|
import com.iformall.domain.po.*; |
|
|
@@ -10,6 +11,8 @@ import com.iformall.enums.*; |
|
|
import com.iformall.mapper.*; |
|
|
import com.iformall.mapper.*; |
|
|
import com.iformall.mq.MqBaseProducer; |
|
|
import com.iformall.mq.MqBaseProducer; |
|
|
import com.iformall.service.*; |
|
|
import com.iformall.service.*; |
|
|
|
|
|
import com.iformall.sms.EnumSMSChannel; |
|
|
|
|
|
import com.iformall.sms.SMSFactory; |
|
|
import com.iformall.utils.CreditUtil; |
|
|
import com.iformall.utils.CreditUtil; |
|
|
import org.apache.commons.collections.CollectionUtils; |
|
|
import org.apache.commons.collections.CollectionUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
@@ -31,6 +34,8 @@ import java.time.temporal.TemporalAdjusters; |
|
|
import java.util.*; |
|
|
import java.util.*; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
import static java.util.stream.Collectors.toList; |
|
|
|
|
|
|
|
|
@Component |
|
|
@Component |
|
|
public class CouponSendScheduleTest { |
|
|
public class CouponSendScheduleTest { |
|
|
|
|
|
|
|
|
@@ -88,25 +93,75 @@ public class CouponSendScheduleTest { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Async |
|
|
|
|
|
//@Scheduled(cron = "0 0 6 1 * ?") // 每月1号发放会员的权益券 |
|
|
|
|
|
@Scheduled(cron = "0 */10 * * * ?") // 测试每天6点发券 |
|
|
|
|
|
//@Scheduled(cron = "*/30 * * * * ?") // 测试30秒中一次 |
|
|
|
|
|
public void couponSendMsgSchedule() { |
|
|
|
|
|
|
|
|
|
|
|
TenantEntity tenantEntity = new TenantEntity(); |
|
|
|
|
|
tenantEntity.setTenantId("1028"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WxCouponSendInject sendInject = new WxCouponSendInject(); |
|
|
|
|
|
sendInject.updateTenantInfo(tenantEntity); |
|
|
|
|
|
sendInject.setSendStatus(EnumYesOrNo.YES.getCode()); |
|
|
|
|
|
sendInject.setSendMsg(EnumYesOrNo.NO.getCode()); |
|
|
|
|
|
sendInject.setCouponId(698841722461515776l); |
|
|
|
|
|
|
|
|
|
|
|
List<WxCouponSendInject> list1 = wxCouponSendInjectMapper.findList(sendInject); |
|
|
|
|
|
sendSMS(tenantEntity,list1,"0.5元购大桶爆米花"); |
|
|
|
|
|
|
|
|
|
|
|
sendInject.setCouponId(698842872011190272l); |
|
|
|
|
|
|
|
|
private void sendSMS(WxCUserBasicInfo cUserBasicInfo, WxMall mall, int birthdayScale) { |
|
|
|
|
|
WxMsgRecord wxMsgRecord = new WxMsgRecord(); |
|
|
|
|
|
wxMsgRecord.setMsgType(EnumMsgRecordType.SMS.getCode()); |
|
|
|
|
|
wxMsgRecord.setReceiver(cUserBasicInfo.getPhone()); |
|
|
|
|
|
wxMsgRecord.updateTenantInfo(mall.getTenantInfo()); |
|
|
|
|
|
Map<String, String> dynamicContentMap = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
if (birthdayScale > WxScoreRules.DEFAULT_SCALE) { |
|
|
|
|
|
float creditScale = new BigDecimal(birthdayScale).divide(new BigDecimal(WxScoreRules.DEFAULT_SCALE)).floatValue(); |
|
|
|
|
|
dynamicContentMap.put("creditScale", String.valueOf(creditScale)); |
|
|
|
|
|
wxMsgRecord.setModelType(EnumMsgModel.COUPON_BIRTHDAY_OPENED.getCode()); |
|
|
|
|
|
} else { |
|
|
|
|
|
//没有配置积分规则 |
|
|
|
|
|
wxMsgRecord.setModelType(EnumMsgModel.COUPON_BIRTHDAY_OPENED_NO.getCode()); |
|
|
|
|
|
|
|
|
List<WxCouponSendInject> list2 = wxCouponSendInjectMapper.findList(sendInject); |
|
|
|
|
|
sendSMS(tenantEntity,list2,"9.9元购普通厅单人观影票"); |
|
|
|
|
|
|
|
|
|
|
|
sendInject.setCouponId(698843398773829632l); |
|
|
|
|
|
|
|
|
|
|
|
List<WxCouponSendInject> list3 = wxCouponSendInjectMapper.findList(sendInject); |
|
|
|
|
|
sendSMS(tenantEntity,list3,"49.9元购双人欢乐套餐"); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void sendSMS(TenantEntity tenantEntity ,List<WxCouponSendInject> list1,String couponTitle) { |
|
|
|
|
|
|
|
|
|
|
|
String validDate = "2022年6月30日"; |
|
|
|
|
|
try{ |
|
|
|
|
|
if(list1 != null && list1.size() > 0){ |
|
|
|
|
|
List<Long> userIds = list1.stream().map(s -> s.getUserId()).collect(toList()); |
|
|
|
|
|
WxCUserBasicInfo cUserBasicInfoQ = new WxCUserBasicInfo(); |
|
|
|
|
|
cUserBasicInfoQ.setFinalTenantId(tenantEntity.getFinalTenantId()); |
|
|
|
|
|
cUserBasicInfoQ.setIds(userIds); |
|
|
|
|
|
List<WxCUserBasicInfo> listPhoneAndNameByIds = wxCUserBasicInfoMapper.findListPhoneAndNameByIds(cUserBasicInfoQ); |
|
|
|
|
|
List<String> collect = listPhoneAndNameByIds.stream().map(u -> u.getPhone()).collect(toList()); |
|
|
|
|
|
String phone = String.join(",", collect); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WxMsgConfig wxMsgConfig = new WxMsgConfig(); |
|
|
|
|
|
wxMsgConfig.setSmsChannel(EnumSMSChannel.ALIYUN.getCode()); |
|
|
|
|
|
Map<String, String> dynamicContentMap = new HashMap<>(); |
|
|
|
|
|
dynamicContentMap.put("couponTitle",couponTitle); |
|
|
|
|
|
dynamicContentMap.put("validDate",validDate); |
|
|
|
|
|
String result = SMSFactory.sendSms(wxMsgConfig, phone, "富茂", null, |
|
|
|
|
|
null, null, JSON.toJSONString(dynamicContentMap), |
|
|
|
|
|
"SMS_243651558",null); |
|
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObjectResult = JSONObject.parseObject(result); |
|
|
|
|
|
String ret = jsonObjectResult.get("ret").toString(); |
|
|
|
|
|
String batchNo = jsonObjectResult.get("data").toString(); |
|
|
|
|
|
if (ret.equals("1")) { |
|
|
|
|
|
wxCouponSendInjectMapper.updateMsgByUserIds(userIds); |
|
|
|
|
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
logger.error("发短信失败 couponId="+couponTitle); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
}catch(Exception e){ |
|
|
|
|
|
logger.error("发短信失败 couponId="+couponTitle+e.getMessage()); |
|
|
} |
|
|
} |
|
|
dynamicContentMap.put("userName", Objects.isNull(cUserBasicInfo.getNickName()) ? "" : cUserBasicInfo.getNickName()); |
|
|
|
|
|
dynamicContentMap.put("mallName", mall.getName()); |
|
|
|
|
|
wxMsgRecord.setDynamicContentMap(dynamicContentMap); |
|
|
|
|
|
mqBaseProducer.sendMessage(wxMsgRecord, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |