package com.mortals.xhx.daemon.task;

import com.mortals.framework.exception.AppException;
import com.mortals.framework.service.ITask;
import com.mortals.framework.service.ITaskExcuteService;
import com.mortals.xhx.common.code.SendStatusEnum;
import com.mortals.xhx.common.utils.SendSmsTask;
import com.mortals.xhx.common.utils.SendTaskThreadPool;
import com.mortals.xhx.module.alarm.model.AlarmSmsSendEntity;
import com.mortals.xhx.module.alarm.model.AlarmSmsSendQuery;
import com.mortals.xhx.module.alarm.service.AlarmSmsSendService;
import lombok.extern.apachecommons.CommonsLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.security.DenyAll;
import java.util.List;

/**
 * 短信发送任务
 *
 * @author: zxfei
 * @date: 2022/3/9 15:19
 */
@CommonsLog
@Service("SmsSendTask")
public class SmsSendTaskImpl implements ITaskExcuteService {

    @Autowired
    private AlarmSmsSendService alarmSmsSendService;

    @Autowired
    private SendTaskThreadPool sendTaskThreadPool;

    @Override
    public void excuteTask(ITask task) throws AppException {

        List<AlarmSmsSendEntity> sendList = alarmSmsSendService.find(new AlarmSmsSendQuery().sendStatus(SendStatusEnum.未发送.getValue()));
        sendList.stream().forEach(sms->{
            SendSmsTask sendSmsTask = new SendSmsTask(sms, "xxx");
            sendTaskThreadPool.execute(sendSmsTask);
        });

    }


    @Override
    public void stopTask(ITask task) throws AppException {

    }


}
