package com.willalp.quartz.task;

import com.willalp.canteen.domain.HsCanteenOrder;
import com.willalp.canteen.service.IHsCanteenOrderService;
import com.willalp.common.utils.StringUtils;
import com.willalp.control.netty.model.ControlDataModel;
import com.willalp.control.service.ControlService;
import com.willalp.control.service.IHsControlDeviceInfoService;
import com.willalp.control.service.IHsControlStatService;
import com.willalp.control.service.IHsControlTimingService;
import com.willalp.event.service.IHsEventService;
import com.willalp.push.service.IHsAppPushService;
import com.willalp.wx.domain.WxMsgTemplateAppointment;
import com.willalp.wx.enums.WxTemplateKeyEnum;
import com.willalp.wx.service.WxMsgService;
import com.willalp.wx.utils.WxUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 定时任务调度测试
 *
 * @author willalp
 */
@Component("willalpTask")
public class RyTask {
    @Resource
    private IHsControlDeviceInfoService controlDeviceInfoService;

    @Resource
    private IHsControlTimingService controlTimingService;

    @Resource
    private ControlService controlService;

    @Resource
    private IHsControlStatService statService;

    @Resource
    private ControlDataModel controlDataModel;

    @Resource
    private IHsCanteenOrderService canteenOrderService;

    @Resource
    private WxMsgService wxMsgService;

    @Resource
    private WxUtils wxUtils;

    @Resource
    private IHsAppPushService pushService;

    @Resource
    private IHsEventService eventService;

    public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) {
        System.out.println(StringUtils.format("执行多参方法： 字符串类型{}，布尔类型{}，长整型{}，浮点型{}，整形{}", s, b, l, d, i));
    }

    public void ryParams(String params) {
        System.out.println("执行有参方法：" + params);
    }

    public void ryNoParams() {
        System.out.println("执行无参方法");
    }


    @Scheduled(fixedRate = 1, timeUnit = TimeUnit.MINUTES)
    public void timingUpdateEventStatus() {
        eventService.timingUpdateEventStatus();
    }

    public void reserveRemind() {
        //获取今日未下单用户
        List<HsCanteenOrder> hsCanteenOrders = canteenOrderService.todayNotOrderUser();
        WxMsgTemplateAppointment w = new WxMsgTemplateAppointment();
        w.setThing3(wxUtils.getFormat("会助理提醒您，请进入小程序提前预定明日菜品"));
        w.setThing3(wxUtils.getFormat(""));
        for (HsCanteenOrder hsCanteenOrder : hsCanteenOrders) {
            wxMsgService.sendQRCodeMsg(hsCanteenOrder.getUserNumber(), w, WxTemplateKeyEnum.APPOINTMENT, true);
        }
    }
}
