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.framework.util.DateUtils;
import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.module.device.model.DeviceLogQuery;
import com.mortals.xhx.module.device.service.DeviceLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Service;

/**
 * 同步用户,唯一标识为用户名。
 */
@Slf4j
@Service("SyncUserTask")
@ConditionalOnExpression("'${platform.type:null}'=='cloud'")
public class SyncUserTaskImpl implements ITaskExcuteService {

    @Autowired
    private UserService userService;
    @Autowired
    private DeviceLogService deviceLogService;

    @Override
    public void excuteTask(ITask task) throws AppException {
        log.info("同步用户任务");
        userService.refreshUser();


        //定时删除日志 7天前
        DeviceLogQuery contidion = new DeviceLogQuery();
        contidion.setCreateTimeEnd(DateUtils.getDateTimeStr(DateUtils.addCurrDate(-3), DateUtils.P_yyyy_MM_dd_HH_mm_ss));
        deviceLogService.getDao().delete(contidion);
    }


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

    }


}
