Kaynağa Gözat

//tt test

release_toaliyun_real
xhxu 3 yıl önce
ebeveyn
işleme
c1d6ccad5a
1 değiştirilmiş dosya ile 165 ekleme ve 165 silme
  1. +165
    -165
      mallinkSchedule/src/main/java/com/iformall/schedule/CouponSendScheduleTest.java

+ 165
- 165
mallinkSchedule/src/main/java/com/iformall/schedule/CouponSendScheduleTest.java Dosyayı Görüntüle

@@ -1,167 +1,167 @@
package com.iformall.schedule;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.iformall.domain.dto.WxCUserBasicInfoDto;
import com.iformall.domain.po.*;
import com.iformall.domain.po.base.TenantEntity;
import com.iformall.domain.po.msg.WxMsgRecord;
import com.iformall.domain.vo.WxCouponSendVo;
import com.iformall.enums.*;
import com.iformall.mapper.*;
import com.iformall.mq.MqBaseProducer;
import com.iformall.service.*;
import com.iformall.sms.EnumSMSChannel;
import com.iformall.sms.SMSFactory;
import com.iformall.utils.CreditUtil;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.stream.Collectors;

import static java.util.stream.Collectors.toList;

@Component
public class CouponSendScheduleTest {

private final Logger logger = LoggerFactory.getLogger(this.getClass());

@Autowired
private WxMallMapper wxMallMapper;

@Autowired
private WxCUserBasicInfoMapper wxCUserBasicInfoMapper;

@Autowired
private WxCUserBasicInfoService wxCUserBasicInfoService;

@Autowired
private WxOrderService wxOrderService;

@Autowired
private WxCouponActionLogService wxCouponActionLogService;

@Autowired
private WxCouponSendInjectMapper wxCouponSendInjectMapper;

@Autowired
private MqBaseProducer mqBaseProducer;


@Async
//@Scheduled(cron = "0 0 6 1 * ?") // 每月1号发放会员的权益券
@Scheduled(cron = "0 */10 * * * ?") // 测试每天6点发券
//@Scheduled(cron = "*/30 * * * * ?") // 测试30秒中一次
public void couponSendSchedule() {

WxCouponSendInject sendInject = new WxCouponSendInject();
sendInject.setSendStatus(EnumYesOrNo.NO.getCode());

List<WxCouponSendInject> list = wxCouponSendInjectMapper.findList(sendInject);
for (WxCouponSendInject inject:list) {
try {
WxCouponOrder couponOrder = wxOrderService.sendFreeCouponToUser(inject.getUserId(), inject,inject.getCouponId(), null,EnumPayWay.PAY_WAY_NOT_UNPAY_INJECT_SEND,null,null);
if(couponOrder != null){
inject.setSendStatus(EnumYesOrNo.YES.getCode());
inject.setOrderId(couponOrder.getOrderId());
inject.setCouponOrderId(couponOrder.getId());
inject.setUpdateTime(new Date());
wxCouponSendInjectMapper.updateById(inject);
wxCouponActionLogService.addOne(inject, inject.getCouponId(), couponOrder.getId(), EnumCouponSendSendType.INJECT.getCode(), 0L,0L);
}

} catch (Exception e) {
logger.error("定时发券:发券失败 couponId=" + inject.getCouponId() + " userId=" + inject.getUserId() + e.getMessage());
continue;
}
}

}

//package com.iformall.schedule;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;
//import com.iformall.domain.dto.WxCUserBasicInfoDto;
//import com.iformall.domain.po.*;
//import com.iformall.domain.po.base.TenantEntity;
//import com.iformall.domain.po.msg.WxMsgRecord;
//import com.iformall.domain.vo.WxCouponSendVo;
//import com.iformall.enums.*;
//import com.iformall.mapper.*;
//import com.iformall.mq.MqBaseProducer;
//import com.iformall.service.*;
//import com.iformall.sms.EnumSMSChannel;
//import com.iformall.sms.SMSFactory;
//import com.iformall.utils.CreditUtil;
//import org.apache.commons.collections.CollectionUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Lazy;
//import org.springframework.scheduling.annotation.Async;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
//import java.math.BigDecimal;
//import java.text.DateFormat;
//import java.text.SimpleDateFormat;
//import java.time.LocalDateTime;
//import java.time.LocalTime;
//import java.time.ZoneId;
//import java.time.temporal.TemporalAdjusters;
//import java.util.*;
//import java.util.stream.Collectors;
//
//import static java.util.stream.Collectors.toList;
//
//@Component
//public class CouponSendScheduleTest {
//
// private final Logger logger = LoggerFactory.getLogger(this.getClass());
//
// @Autowired
// private WxMallMapper wxMallMapper;
//
// @Autowired
// private WxCUserBasicInfoMapper wxCUserBasicInfoMapper;
//
// @Autowired
// private WxCUserBasicInfoService wxCUserBasicInfoService;
//
// @Autowired
// private WxOrderService wxOrderService;
//
// @Autowired
// private WxCouponActionLogService wxCouponActionLogService;
//
// @Autowired
// private WxCouponSendInjectMapper wxCouponSendInjectMapper;
//
// @Autowired
// private MqBaseProducer mqBaseProducer;
//
//
// @Async
//@Scheduled(cron = "0 0 6 1 * ?") // 每月1号发放会员的权益券
// //@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("1038");


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);

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());
}

}
}
// //@Scheduled(cron = "*/30 * * * * ?") // 测试30秒中一次
// public void couponSendSchedule() {
//
// WxCouponSendInject sendInject = new WxCouponSendInject();
// sendInject.setSendStatus(EnumYesOrNo.NO.getCode());
//
// List<WxCouponSendInject> list = wxCouponSendInjectMapper.findList(sendInject);
// for (WxCouponSendInject inject:list) {
// try {
// WxCouponOrder couponOrder = wxOrderService.sendFreeCouponToUser(inject.getUserId(), inject,inject.getCouponId(), null,EnumPayWay.PAY_WAY_NOT_UNPAY_INJECT_SEND,null,null);
// if(couponOrder != null){
// inject.setSendStatus(EnumYesOrNo.YES.getCode());
// inject.setOrderId(couponOrder.getOrderId());
// inject.setCouponOrderId(couponOrder.getId());
// inject.setUpdateTime(new Date());
// wxCouponSendInjectMapper.updateById(inject);
// wxCouponActionLogService.addOne(inject, inject.getCouponId(), couponOrder.getId(), EnumCouponSendSendType.INJECT.getCode(), 0L,0L);
// }
//
// } catch (Exception e) {
// logger.error("定时发券:发券失败 couponId=" + inject.getCouponId() + " userId=" + inject.getUserId() + e.getMessage());
// continue;
// }
// }
//
// }
//
//// @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("1038");
//
//
// 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);
//
// 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());
// }
//
// }
//}

Yükleniyor…
İptal
Kaydet