| @@ -64,14 +64,15 @@ public class CouponOrderExpiringSchedule { | |||||
| return wxMallMapper.findList(wxMall); | 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秒中一次 | // @Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 | ||||
| public void couponOrderExpiringSchedule() { | public void couponOrderExpiringSchedule() { | ||||
| CouponOrderExpiringSchedule proxy = (CouponOrderExpiringSchedule) AopContext.currentProxy(); | CouponOrderExpiringSchedule proxy = (CouponOrderExpiringSchedule) AopContext.currentProxy(); | ||||
| List<WxMall> malls = getMalls(); | List<WxMall> malls = getMalls(); | ||||
| for (WxMall mall: malls) { | for (WxMall mall: malls) { | ||||
| List<WxCouponOrder> list = wxCouponOrderMapper.findExpiredFreeCouponOrderByValidDate(mall.getTenantId()); | |||||
| List<WxCouponOrder> list = wxCouponOrderMapper.findExpiredFreeCouponOrderByValidDate(mall.getTenantId(),new Date()); | |||||
| if (null != list && list.size() > 0 ) { | if (null != list && list.size() > 0 ) { | ||||
| list.stream().forEach(co -> { | 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秒中一次 | //@Scheduled(cron = "0 */10 * * * ?") // 测试10秒中一次 | ||||
| public void couponOrderRefundSchedule() { | public void couponOrderRefundSchedule() { | ||||
| CouponOrderExpiringSchedule proxy = (CouponOrderExpiringSchedule) AopContext.currentProxy(); | CouponOrderExpiringSchedule proxy = (CouponOrderExpiringSchedule) AopContext.currentProxy(); | ||||
| List<WxMall> malls = getMalls(); | List<WxMall> malls = getMalls(); | ||||
| for (WxMall mall: malls) { | for (WxMall mall: malls) { | ||||
| List<WxCouponOrder> list = wxCouponOrderMapper.findExpiredCouponOrderByValidDate(mall.getTenantId()); | |||||
| List<WxCouponOrder> list = wxCouponOrderMapper.findExpiredCouponOrderByValidDate(mall.getTenantId(),new Date()); | |||||
| if (null != list && list.size() > 0 ) { | if (null != list && list.size() > 0 ) { | ||||
| list.stream().forEach(co -> { | list.stream().forEach(co -> { | ||||
| try { | try { | ||||
| @@ -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); | |||||
| } | |||||
| }); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -22,9 +22,9 @@ public interface WxCouponOrderMapper extends CommonMapper<WxCouponOrder, Long> { | |||||
| List<WxCouponOrder> findListOfOrderedByDate(Map dateMap); | List<WxCouponOrder> findListOfOrderedByDate(Map dateMap); | ||||
| List<WxCouponOrder> findListOfVerifiedByDate(Map dateMap); | List<WxCouponOrder> findListOfVerifiedByDate(Map dateMap); | ||||
| List<WxCouponOrder> findExpiredFreeCouponOrderByValidDate(@Param("tenantId")String tenantId); | |||||
| List<WxCouponOrder> findExpiredFreeCouponOrderByValidDate(@Param("tenantId")String tenantId,@Param("expiredTime")Date expiredTime); | |||||
| List<WxCouponOrder> findExpiredCouponOrderByValidDate(@Param("tenantId")String tenantId); | |||||
| List<WxCouponOrder> findExpiredCouponOrderByValidDate(@Param("tenantId")String tenantId,@Param("expiredTime")Date expiredTime); | |||||
| List<WxCouponOrder> findExpiredCouponOrderGoodsVerify(@Param("tenantId")String tenantId); | List<WxCouponOrder> findExpiredCouponOrderGoodsVerify(@Param("tenantId")String tenantId); | ||||
| @@ -717,14 +717,14 @@ | |||||
| GROUP BY xTime | GROUP BY xTime | ||||
| </select> | </select> | ||||
| <select id="findExpiredFreeCouponOrderByValidDate" parameterType="String" resultMap="BaseResultMap"> | |||||
| <select id="findExpiredFreeCouponOrderByValidDate" parameterType="map" resultMap="BaseResultMap"> | |||||
| select <include refid="allColumns" /> from wx_coupon_order | select <include refid="allColumns" /> 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> | </select> | ||||
| <select id="findExpiredCouponOrderByValidDate" parameterType="String" resultMap="BaseResultMap"> | |||||
| <select id="findExpiredCouponOrderByValidDate" parameterType="map" resultMap="BaseResultMap"> | |||||
| select <include refid="allColumns" /> from wx_coupon_order | select <include refid="allColumns" /> 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> | </select> | ||||
| <select id="findExpiredCouponOrderGoodsVerify" parameterType="String" resultMap="BaseResultMap"> | <select id="findExpiredCouponOrderGoodsVerify" parameterType="String" resultMap="BaseResultMap"> | ||||