package com.kmall.schedule.quartz;

import com.kmall.schedule.service.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component("orderTask")
public class OrderTask {
    private static Log logger = LogFactory.getLog(OrderTask.class);

    @Autowired
    QzOrderService qzOrderService;
    @Autowired
    QzStorePromService qzStorePromService;
    @Autowired
    QzStoreTicketDiscountService qzStoreTicketDiscountService;
    @Autowired
    QzStoreTopicStatisService qzStoreTopicStatisService;
    @Autowired
    QzStoreCampMinusService qzStoreCampMinusService;

    /**
     * 方法描述：拼团进度通知
     * 每日凌晨2:00
     */
    /*@Scheduled(cron = "0 0 2 * * ?")
    public void groupProgressRemind() {
        logger.info(">>>>>>>>>>>>>>>>>>>>groupProgressRemind is start ");
        qzOrderService.groupProgressRemind();
        logger.info(">>>>>>>>>>>>>>>>>>>>groupProgressRemind is end ");
    }*/

    /**
     * 未评价订单(发送微信模版消息提醒用户)
     * 每日凌晨2:00
     *//*
    @Scheduled(cron = "0 0 2 * * ?")
    public void orderUnEvaluateRemind() {
        logger.info(">>>>>>>>>>>>>>>>>>>>groupProgressRemind is start ");
        qzOrderService.orderUnEvaluateRemind();
        logger.info(">>>>>>>>>>>>>>>>>>>>groupProgressRemind is end ");
    }*/

    /**
     * 未支付的现场商品且已人脸识别通过的订单(发送微信模版消息提醒用户)
     */
    @Scheduled(cron = "0/5 * * * * ?")
    public void unPayAndFaceSuccessOrder() {
        logger.info(">>>>>>>>>>>>>>>>>>>>unPayAndFaceSuccessOrder is start ");
        qzOrderService.unPayAndFaceSuccessOrder();
        logger.info(">>>>>>>>>>>>>>>>>>>>unPayAndFaceSuccessOrder is end ");
    }
    /**
     * 方法描述：更新过期未支付订单
     * 二分钟更新未付款订单
     */
//    @Scheduled(fixedRate = 1000 * 60 * 2)
    public void unpayPastUpdate() {
        logger.info(">>>>>>>>>>>>>>>>>>>>unpayPastUpdate is start ");
        qzOrderService.unpayPastUpdate();
        logger.info(">>>>>>>>>>>>>>>>>>>>unpayPastUpdate is end ");
    }

    /**
     * 方法描述：查询已申请退款订单以及退款中订单，查询微信退款更新订单状态
     * 二分钟更新订单
     */
//    @Scheduled(fixedRate = 1000 * 60 * 1)
    public void refundUpdate() {
        logger.info(">>>>>>>>>>>>>>>>>>>>refundUpdate is start ");
        qzOrderService.refundUpdate();
        logger.info(">>>>>>>>>>>>>>>>>>>>refundUpdate is end ");
    }

    /**
     * 方法描述：查询支付中的订单以及小程序更新支付信息异常订单，查询微信订单信息更新订单状态
     * 二分钟更新订单
     */
//    @Scheduled(fixedRate = 1000 * 60 * 1)
    public void orderQueryUpdate() {
        logger.info(">>>>>>>>>>>>>>>>>>>>orderQueryUpdate is start ");
        qzOrderService.orderQueryUpdate();
        logger.info(">>>>>>>>>>>>>>>>>>>>orderQueryUpdate is end ");
    }

    /**
     * 方法描述：查询支付中的订单以及小程序更新支付信息异常订单，查询平安订单信息更新订单状态
     * 二分钟更新订单
     */
//    @Scheduled(fixedRate = 1000 * 60 * 1)
    public void pinganOrderQueryUpdate() {
        logger.info(">>>>>>>>>>>>>>>>>>>>pinganOrderQueryUpdate is start ");
        qzOrderService.pinganOrderQueryUpdate();
        logger.info(">>>>>>>>>>>>>>>>>>>>pinganOrderQueryUpdate is end ");
    }

    /**
     * 方法描述：商品发货后7天自动确认收货
     */
//    @Scheduled(fixedRate = 1000 * 60 * 1)
    public void shipmentOrderAutoTakeGoods() {
        logger.info(">>>>>>>>>>>>>>>>>>>>shipmentOrderAutoTakeGoods is start ");
        qzOrderService.shipmentOrderAutoTakeGoods();
        logger.info(">>>>>>>>>>>>>>>>>>>>shipmentOrderAutoTakeGoods is end ");
    }

    /**
     * 方法描述：确认收货后30天自动确认好评
     */
//    @Scheduled(fixedRate = 1000 * 60 * 1)
    public void receiptOrderAutoComment() {
        logger.info(">>>>>>>>>>>>>>>>>>>>receiptOrderAutoComment is start ");
        qzOrderService.receiptOrderAutoComment();
        logger.info(">>>>>>>>>>>>>>>>>>>>receiptOrderAutoComment is end ");
    }

    /**
     * 方法描述：返回海关所需获取的支付相关实时数据
     * 五分钟更新未付款订单
     */
//    @Scheduled(fixedRate = 1000 * 60 * 5)
    public void realTimeDataUp() {
        logger.info(">>>>>>>>>>>>>>>>>>>>realTimeDataUp is start ");
        qzOrderService.realTimeDataUp();
        logger.info(">>>>>>>>>>>>>>>>>>>>realTimeDataUp is end ");
    }

    /**
     * 方法描述：用户确认收货后，记录商品分销购买记录
     * 1分钟更新
     */
//    @Scheduled(fixedRate = 1000 * 60 * 1)
    public void receiptOrderSaveDistSellStatis() {
        logger.info(">>>>>>>>>>>>>>>>>>>>receiptOrderSaveDistSellStatis is start ");
        qzOrderService.receiptOrderSaveDistSellStatis();
        logger.info(">>>>>>>>>>>>>>>>>>>>receiptOrderSaveDistSellStatis is end ");
    }
    /**
     * 方法描述：查询渠道推广有效开始时间是否过期，过期则修改结束状态为已结束
     * 1分钟更新
     */
//    @Scheduled(fixedRate = 1000 * 60 * 1)
    public void updateQueryStoreProm() {
        logger.info(">>>>>>>>>>>>>>>>>>>>updateQueryStoreProm is start ");
        qzStorePromService.updateQueryStoreProm();
        logger.info(">>>>>>>>>>>>>>>>>>>>updateQueryStoreProm is end ");
    }
    /**
     * 方法描述：支付成功且是渠道推广订单统计支付数据
     * 1分钟更新
     */
//    @Scheduled(fixedRate = 1000 * 60 * 1)
    public void updatePromStatByPaySuccess() {
        logger.info(">>>>>>>>>>>>>>>>>>>>updatePromStatByPaySuccess is start ");
        qzStorePromService.updatePromStatByPaySuccess();
        logger.info(">>>>>>>>>>>>>>>>>>>>updatePromStatByPaySuccess is end ");
    }
    /**
     * 方法描述：退款成功且是渠道推广订单统计支付数据
     * 1分钟更新
     */
//    @Scheduled(fixedRate = 1000 * 60 * 1)
    public void updatePromStatByRefundSuccess() {
        logger.info(">>>>>>>>>>>>>>>>>>>>updatePromStatByRefundSuccess is start ");
        qzStorePromService.updatePromStatByRefundSuccess();
        logger.info(">>>>>>>>>>>>>>>>>>>>updatePromStatByRefundSuccess is end ");
    }
    /**
     * 方法描述：查询优惠券有效时间是否过期，修改过期优惠券数据结束状态为无效，修改过期用户优惠券状态为无效
     * 1分钟更新
     */
//    @Scheduled(fixedRate = 1000 * 60 * 1)
    public void updateQueryTicketDiscount() {
        logger.info(">>>>>>>>>>>>>>>>>>>>updateQueryTicketDiscount is start ");
        qzStoreTicketDiscountService.updateQueryTicketDiscount();
        logger.info(">>>>>>>>>>>>>>>>>>>>updateQueryTicketDiscount is end ");
    }

    /**
     * 方法描述：支付成功且是门店优惠券活动订单统计支付数据
     * 1分钟更新
     */
//    @Scheduled(fixedRate = 1000 * 60 * 1)
    public void updateTopicStatByPaySuccess() {
        logger.info(">>>>>>>>>>>>>>>>>>>>updateTopicStatByPaySuccess is start ");
        qzStoreTopicStatisService.updateTopicStatByPaySuccess();
        logger.info(">>>>>>>>>>>>>>>>>>>>updateTopicStatByPaySuccess is end ");
    }

    /**
     * 方法描述：退款成功且是门店优惠券活动订单统计支付数据
     * 1分钟更新
     */
//    @Scheduled(fixedRate = 1000 * 60 * 1)
    public void updateTopicStatByRefundSuccess() {
        logger.info(">>>>>>>>>>>>>>>>>>>>updateTopicStatByRefundSuccess is start ");
        qzStoreTopicStatisService.updateTopicStatByRefundSuccess();
        logger.info(">>>>>>>>>>>>>>>>>>>>updateTopicStatByRefundSuccess is end ");
    }

    /**
     * 方法描述：修改过期满减满折数据结束状态为无效，修改未开始且开始时间已小于或等于当前时间的满减满折结束状态为进行中
     * 1分钟更新
     */
//    @Scheduled(fixedRate = 1000 * 60 * 1)
    public void updateQueryStoreCampMinus() {
        logger.info(">>>>>>>>>>>>>>>>>>>>updateQueryStoreCampMinus is start ");
        qzStoreCampMinusService.updateQueryStoreCampMinus();
        logger.info(">>>>>>>>>>>>>>>>>>>>updateQueryStoreCampMinus is end ");
    }

    /**
     * 方法描述：支付成功且是门店促销满减活动订单统计支付数据
     * 1分钟更新
     */
//    @Scheduled(fixedRate = 1000 * 60 * 1)
    public void updateCampTopicStatByPaySuccess() {
        logger.info(">>>>>>>>>>>>>>>>>>>>updateCampTopicStatByPaySuccess is start ");
        qzStoreTopicStatisService.updateCampTopicStatByPaySuccess();
        logger.info(">>>>>>>>>>>>>>>>>>>>updateCampTopicStatByPaySuccess is end ");
    }

    /**
     * 方法描述：退款成功且是门店促销满减活动订单统计支付数据
     * 1分钟更新
     */
//    @Scheduled(fixedRate = 1000 * 60 * 1)
    public void updateCampTopicStatByRefundSuccess() {
        logger.info(">>>>>>>>>>>>>>>>>>>>updateCampTopicStatByRefundSuccess is start ");
        qzStoreTopicStatisService.updateCampTopicStatByRefundSuccess();
        logger.info(">>>>>>>>>>>>>>>>>>>>updateCampTopicStatByRefundSuccess is end ");
    }

    @Scheduled(fixedRate = 1000 * 60 * 1)
    public void updateSellVolume() {
        logger.info(">>>>>>>>>>>>>>>>>>>>updateSellVolume is start ");
        qzOrderService.updateSellVolume();
        logger.info(">>>>>>>>>>>>>>>>>>>>updateSellVolume is end ");
    }

    /**
     * 查询商品库存数量变化后未共享的商品数据，批量修改该商品的门店商品库存信息
     * 10秒执行一次
     */
//    @Scheduled(cron = "0/10 * * * * ?")
    public void updateProductStoreByGoodsShareStock() {
        logger.info(">>>>>>>>>>>>>>>>>>>>updateProductStoreByGoodsShareStock is start ");
        qzOrderService.updateProductStoreByGoodsShareStock();
        logger.info(">>>>>>>>>>>>>>>>>>>>updateProductStoreByGoodsShareStock is end ");
    }
}
