package cn.estsh.i3plus.core.apiservice.schedulejob;

import cn.estsh.i3plus.core.api.iservice.busi.ISysMessageService;
import cn.estsh.i3plus.platform.common.tool.TimeTool;
import cn.estsh.i3plus.platform.common.util.PlatformConstWords;
import cn.estsh.i3plus.pojo.base.enumutil.ImppEnumUtil;
import cn.estsh.i3plus.pojo.platform.bean.SysMessage;
import cn.estsh.impp.framework.base.schedule.BaseImppScheduleJob;
import cn.estsh.impp.framework.boot.init.ApplicationProperties;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.ApiOperation;
import org.quartz.JobExecutionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Description :  定时任务
 * @Reference :
 * @Author : alwaysfrin
 * @CreateDate : 2018-09-30 13:25
 * @Modify:
 **/
@ApiOperation("定时任务demo")
public class DemoJob extends BaseImppScheduleJob {
    public static final Logger LOGGER = LoggerFactory.getLogger(DemoJob.class);

    public DemoJob() {
        super(DemoJob.class,"定时任务demo");
    }

    @Autowired
    private ISysMessageService sysMessageService;

    @Override
    public void executeImppJob(JobExecutionContext context, ApplicationProperties applicationProperties) {
        System.out.println("定时任务被执行");
        LOGGER.info("projectName：{},port:{}",applicationProperties.getApplicationName(),applicationProperties.getServerPort());

        SysMessage sysMessage = new SysMessage();
        sysMessage.setMessageTitle("定时邮件发送");
        sysMessage.setMessageContent("定时任务name："+context.getJobDetail().getKey().getName()
                +"定时任务groupName："+context.getJobDetail().getKey().getGroup()
                +"定时邮件内容"+TimeTool.getNowTime(true));
        sysMessage.setMessageType(ImppEnumUtil.MESSAGE_TYPE.MAIL.getValue());
        sysMessage.setMessageContentType(ImppEnumUtil.MESSAGE_TYPE_CONTENT.HTML.getValue());
        sysMessage.setMessageReceiversId(PlatformConstWords.CONTACT_MAIL);
        sysMessage.setMessageReceiversNameRdd(PlatformConstWords.CONTACT_MAIL);
        sysMessage.setMessageReceiverType(ImppEnumUtil.MESSAGE_RECEIVER_TYPE.URGENT.getValue());
        sysMessageService.doSendSysMessage(sysMessage);
    }
}
