|
|
|
@@ -0,0 +1,162 @@ |
|
|
|
package com.iformall.schedule; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.iformall.common.ErrorCode; |
|
|
|
import com.iformall.common.ResultData; |
|
|
|
import com.iformall.domain.dto.WxSharingOrderDto; |
|
|
|
import com.iformall.domain.po.*; |
|
|
|
import com.iformall.domain.po.msg.WxMsg; |
|
|
|
import com.iformall.enums.*; |
|
|
|
import com.iformall.exception.MallinkException; |
|
|
|
import com.iformall.mapper.*; |
|
|
|
import com.iformall.service.WxCouponOrderService; |
|
|
|
import com.iformall.service.WxMsgService; |
|
|
|
import com.iformall.service.WxOrderService; |
|
|
|
import com.iformall.service.WxProfitSharingOrderService; |
|
|
|
import com.iformall.service.WxRefundOrderService; |
|
|
|
import com.iformall.service.WxTemplateMsgService; |
|
|
|
import com.iformall.service.order.entity.WxComposeChildOrderShare; |
|
|
|
import com.iformall.utils.DateUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.aop.framework.AopContext; |
|
|
|
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 org.springframework.transaction.annotation.Propagation; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
@Component |
|
|
|
public class CouponOrderNoticeSchedule { |
|
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass()); |
|
|
|
|
|
|
|
@Lazy |
|
|
|
@Autowired |
|
|
|
private WxMsgService wxMsgService; |
|
|
|
|
|
|
|
@Lazy |
|
|
|
@Autowired |
|
|
|
private WxTemplateMsgService wxTemplateMsgService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxMallMapper wxMallMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxCouponOrderMapper wxCouponOrderMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxCUserMapper wxCUserMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxCouponMapper wxCouponMapper; |
|
|
|
|
|
|
|
|
|
|
|
private List<WxMall> getMalls() { |
|
|
|
WxMall wxMall = new WxMall(); |
|
|
|
return wxMallMapper.findList(wxMall); |
|
|
|
} |
|
|
|
|
|
|
|
private void sendCouponRemind(WxMall mall,WxCouponOrder couponOrder){ |
|
|
|
try { |
|
|
|
WxCoupon couponQ = new WxCoupon(); |
|
|
|
couponQ.updateTenantInfo(mall); |
|
|
|
couponQ.setId(couponOrder.getCouponId()); |
|
|
|
WxCoupon c = wxCouponMapper.findSimpleDetail(couponQ); |
|
|
|
if (c == null) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
WxCUser wcuQ = new WxCUser(); |
|
|
|
wcuQ.updateTenantInfo(mall); |
|
|
|
wcuQ.setUserId(couponOrder.getCUserId()); |
|
|
|
List<WxCUser> list = wxCUserMapper.findList(wcuQ); |
|
|
|
WxCUser user = null; |
|
|
|
if(list != null && list.size() > 0){ |
|
|
|
user = list.get(0); |
|
|
|
} |
|
|
|
if (null == user) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
WxTemplateMsg temp = new WxTemplateMsg(); |
|
|
|
temp.updateTenantInfo(mall); |
|
|
|
temp.setType(EnumTemplateType.SEND_COUPON_REMIND.getCode()); |
|
|
|
temp = wxTemplateMsgService.getByObj(temp); |
|
|
|
if(temp.getId() != null){ |
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
WxMsg msg = new WxMsg(); |
|
|
|
msg.updateTenantInfo(mall); |
|
|
|
msg.setPhones(user.getOpenId()); |
|
|
|
msg.setModelId(temp.getId()); |
|
|
|
Map<String,String> map = new HashMap<>(); |
|
|
|
map.put("thing1",c.getTitle()); |
|
|
|
map.put("time3",dateFormat.format(couponOrder.getCreateDate())); |
|
|
|
map.put("time4",dateFormat.format(couponOrder.getExpiredTime())); |
|
|
|
map.put("thing5","你的优惠券马上过期,请立即使用哦!"); |
|
|
|
if(EnumCouponType.COUPON_TINGCHE.getCode().equals(couponOrder.getCouponType()) |
|
|
|
|| EnumCouponType.COUPON_CREDIT_PARK.getCode().equals(couponOrder.getCouponType())){ |
|
|
|
map.put("goToPage","pages/index/index?type=pc"); |
|
|
|
}else{ |
|
|
|
map.put("goToPage","pages/index/index?type=mc"); |
|
|
|
} |
|
|
|
|
|
|
|
msg.setMsg(JSONObject.toJSONString(map)); |
|
|
|
wxMsgService.batchSendAppinfo(msg); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Async |
|
|
|
@Scheduled(cron = "0 */5 * * * ?") // 每天凌晨15:30 |
|
|
|
public void couponOrderExpiringSchedule() { |
|
|
|
List<WxMall> malls = getMalls(); |
|
|
|
for (WxMall mall: malls) { |
|
|
|
Date oneDayBefore = DateUtils.getTimeAfterDays(-1, new Date()); |
|
|
|
List<WxCouponOrder> list = wxCouponOrderMapper.findExpiredFreeCouponOrderByValidDate(mall.getTenantId(),oneDayBefore); |
|
|
|
if (null != list && list.size() > 0 ) { |
|
|
|
list.stream().forEach(co -> { |
|
|
|
// 券过期,更改状态及库存退回 |
|
|
|
try { |
|
|
|
sendCouponRemind(mall,co); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error(e.getMessage(),e); |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Async |
|
|
|
@Scheduled(cron = "0 */5 * * * ?") |
|
|
|
//@Scheduled(cron = "0 15 30 * * ?") // 每天凌晨00:05 |
|
|
|
public void couponOrderRefundSchedule() { |
|
|
|
List<WxMall> malls = getMalls(); |
|
|
|
for (WxMall mall: malls) { |
|
|
|
Date oneDayBefore = DateUtils.getTimeAfterDays(-1, new Date()); |
|
|
|
List<WxCouponOrder> list = wxCouponOrderMapper.findExpiredCouponOrderByValidDate(mall.getTenantId(),oneDayBefore); |
|
|
|
if (null != list && list.size() > 0 ) { |
|
|
|
list.stream().forEach(co -> { |
|
|
|
try { |
|
|
|
sendCouponRemind(mall,co); |
|
|
|
}catch(Exception e) { |
|
|
|
logger.error(e.getMessage(),e); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |