package com.sifang.modules.task;


import com.jfinal.plugin.activerecord.Db;
import com.sifang.modules.smallprogram.stategrid.service.StateGridService;
import com.sifang.modules.sys.common.utils.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class StateGridTask {

    private Logger logger = LoggerFactory.getLogger(getClass());


    @Autowired
    StateGridService stateGridService;
    // second, minute, hour, day, month, weekday.
//    @Scheduled(cron = "0 */10 * * * ?")
    @Scheduled(cron = "0 0/10 * * * ?")
    public void selectStatus() {
        long begin = System.currentTimeMillis();
        logger.info("开始同步光e宝授权状态》》》》》》》》");
        stateGridService.selectStatus();
        long end = System.currentTimeMillis();
        logger.info("光e宝授权状态同步完毕》》》》》》》》 共耗时：[" + (end-begin) / 1000 + "]秒");
    }


    //每天晚上23:00判断合同是否到期，如果到期了，那么改变合同状态
    @Scheduled(cron = "0 0 23 * * ? ")
    public void changeStatusContent(){
        logger.info("....changeStatusContent   Date:{}", DateUtils.getDate("yyyy-MM-dd HH:mm:ss"));
        int count=Db.update(" UPDATE `crm_trader_contract` SET status='5' WHERE NOW()>=end_time AND status='4' ");
        logger.info("...changeStatusContent  count:{}",count);
    }

    //每天晚上23:40判断印章授权是否到期，如果到期了，那么改变印章授权状态
    @Scheduled(cron = "0 40 23 * * ? ")
    public void changeSealAuthStatus(){
        logger.info("....changeSealAuthStatus   Date:{}", DateUtils.getDate("yyyy-MM-dd HH:mm:ss"));
        int count=Db.update(" UPDATE `crm_project_company_settings` SET seal_external_auth='4' WHERE NOW()>=seal_expire_time AND seal_external_auth='3' ");
        logger.info("...changeSealAuthStatus  count:{}",count);
    }
}
