package com.mortals.xhx.daemon.applicationservice;

import com.mortals.framework.springcloud.service.IApplicationStartedService;
import com.mortals.xhx.base.system.resource.service.ResourceService;
import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.feign.device.IDeviceFeign;
import com.mortals.xhx.feign.site.ISiteFeign;
import com.mortals.xhx.module.device.service.DeviceService;
import com.mortals.xhx.module.skin.service.SkinService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class DemoStartedService implements IApplicationStartedService {


    @Autowired
    private ResourceService resourceService;
    @Autowired
    private UserService userService;
    @Autowired
    private DeviceService deviceService;
    @Autowired
    private SkinService skinService;

    @Override
    public void start() {
        log.info("开始服务..[配置已加载完成，并且所有框架都已经初始化]");

        //初始执行同步用户与皮肤任务
        log.info("开始同步设备列表！");
        deviceService.syncDevice();
        log.info("结束同步设备列表！");

        log.info("开始同步皮肤列表！");

        skinService.syncSkin();
        log.info("结束同步皮肤列表！");

        log.info("开始同步用户！");
        userService.refreshUser();
        log.info("结束同步用户！");

        try {
            resourceService.refreshResourceUrl("com.mortals.xhx", null);
        } catch (Exception e) {
            log.error("刷新资源失败", e);
        }
    }

    @Override
    public void stop() {
        log.info("停止服务..");
    }

    @Override
    public int getOrder() {
        return 10;
    }

}
