package com.yunfeiyun.agmp.fms.scheduler;

import com.yunfeiyun.agmp.common.enums.SysWarnEnum;
import com.yunfeiyun.agmp.common.utils.DateUtils;
import com.yunfeiyun.agmp.fms.mapper.SpmOrderMapper;
import com.yunfeiyun.agmp.fms.domain.resvo.SpmOrderResVo;
import com.yunfeiyun.agmp.fms.service.ISysWarnService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Component
public class SpmOrderOverTimeScheduler {
    @Resource
    private ISysWarnService sysWarnService;

    @Resource
    private SpmOrderMapper spmOrderMapper;

    @Scheduled(cron = "0 0/10 * * * ?")
    public void checkSpmOrderSendTime(){
        List<SpmOrderResVo> spmOrderList = spmOrderMapper.selectUndeliveredOrder(DateUtils.dateNow());
        for(SpmOrderResVo spmOrder:spmOrderList){
            String remark = "订单编号：" +
                    spmOrder.getOrderNo() +
                    "," +
                    spmOrder.getFinishgoodsName() +
                    "送往" +
                    spmOrder.getOrderConsigneeaddress() +
                    "已超期,请跟踪确认";
            sysWarnService.genWarn("", remark, SysWarnEnum.SysWarnType.DELAYED_DELIVERY , SysWarnEnum.SysWarnClass.TRANSPORTATION_PROCESS);
        }

    }
}
