diff --git a/mallinkSchedule/src/main/java/com/iformall/schedule/CouponOrderExpiringSchedule.java b/mallinkSchedule/src/main/java/com/iformall/schedule/CouponOrderExpiringSchedule.java index 33033768f..dc19e9bdc 100644 --- a/mallinkSchedule/src/main/java/com/iformall/schedule/CouponOrderExpiringSchedule.java +++ b/mallinkSchedule/src/main/java/com/iformall/schedule/CouponOrderExpiringSchedule.java @@ -64,14 +64,15 @@ public class CouponOrderExpiringSchedule { return wxMallMapper.findList(wxMall); } - @Scheduled(cron = "0 0 5 * * ?") // 每天凌晨00:05 + //@Scheduled(cron = "0 0 5 * * ?") // 每天凌晨00:05 + @Scheduled(cron = "0 */5 * * * ?") // @Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 public void couponOrderExpiringSchedule() { CouponOrderExpiringSchedule proxy = (CouponOrderExpiringSchedule) AopContext.currentProxy(); List malls = getMalls(); for (WxMall mall: malls) { - List list = wxCouponOrderMapper.findExpiredFreeCouponOrderByValidDate(mall.getTenantId()); + List list = wxCouponOrderMapper.findExpiredFreeCouponOrderByValidDate(mall.getTenantId(),new Date()); if (null != list && list.size() > 0 ) { list.stream().forEach(co -> { // 券过期,更改状态及库存退回 @@ -87,13 +88,14 @@ public class CouponOrderExpiringSchedule { } - @Scheduled(cron = "0 0 5 * * ?") // 每天凌晨00:05 + //@Scheduled(cron = "0 0 5 * * ?") // 每天凌晨00:05 + @Scheduled(cron = "0 */5 * * * ?") //@Scheduled(cron = "0 */10 * * * ?") // 测试10秒中一次 public void couponOrderRefundSchedule() { CouponOrderExpiringSchedule proxy = (CouponOrderExpiringSchedule) AopContext.currentProxy(); List malls = getMalls(); for (WxMall mall: malls) { - List list = wxCouponOrderMapper.findExpiredCouponOrderByValidDate(mall.getTenantId()); + List list = wxCouponOrderMapper.findExpiredCouponOrderByValidDate(mall.getTenantId(),new Date()); if (null != list && list.size() > 0 ) { list.stream().forEach(co -> { try { diff --git a/mallinkSchedule/src/main/java/com/iformall/schedule/CouponOrderNoticeSchedule.java b/mallinkSchedule/src/main/java/com/iformall/schedule/CouponOrderNoticeSchedule.java new file mode 100644 index 000000000..65ba0c433 --- /dev/null +++ b/mallinkSchedule/src/main/java/com/iformall/schedule/CouponOrderNoticeSchedule.java @@ -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 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 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 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 malls = getMalls(); + for (WxMall mall: malls) { + Date oneDayBefore = DateUtils.getTimeAfterDays(-1, new Date()); + List 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 malls = getMalls(); + for (WxMall mall: malls) { + Date oneDayBefore = DateUtils.getTimeAfterDays(-1, new Date()); + List 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); + } + }); + } + } + } + + +} \ No newline at end of file diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxCouponOrderMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxCouponOrderMapper.java index 1f3d162c3..35a51fff3 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxCouponOrderMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxCouponOrderMapper.java @@ -22,9 +22,9 @@ public interface WxCouponOrderMapper extends CommonMapper { List findListOfOrderedByDate(Map dateMap); List findListOfVerifiedByDate(Map dateMap); - List findExpiredFreeCouponOrderByValidDate(@Param("tenantId")String tenantId); + List findExpiredFreeCouponOrderByValidDate(@Param("tenantId")String tenantId,@Param("expiredTime")Date expiredTime); - List findExpiredCouponOrderByValidDate(@Param("tenantId")String tenantId); + List findExpiredCouponOrderByValidDate(@Param("tenantId")String tenantId,@Param("expiredTime")Date expiredTime); List findExpiredCouponOrderGoodsVerify(@Param("tenantId")String tenantId); diff --git a/mallinkService/src/main/resources/mapper/WxCouponOrderMapper.xml b/mallinkService/src/main/resources/mapper/WxCouponOrderMapper.xml index 9ed845877..e6b537e2d 100644 --- a/mallinkService/src/main/resources/mapper/WxCouponOrderMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCouponOrderMapper.xml @@ -717,14 +717,14 @@ GROUP BY xTime - select from wx_coupon_order - where tenant_id = #{tenantId} and expired_time >= date_sub(curdate(),interval 360 day) and expired_time < now() and coupon_price = 0 and coupon_order_status in (0, 4) + where tenant_id = #{tenantId} and expired_time >= date_sub(curdate(),interval 360 day) and expired_time <=#{expiredTime} and coupon_price = 0 and coupon_order_status in (0, 4) - select from wx_coupon_order - where tenant_id = #{tenantId} and expired_time >= date_sub(curdate(),interval 360 day) and expired_time < now() and coupon_price > 0 and coupon_order_status in (0, 4) + where tenant_id = #{tenantId} and expired_time >= date_sub(curdate(),interval 360 day) and expired_time <=#{expiredTime} and coupon_price > 0 and coupon_order_status in (0, 4)