package cn.com.qmth.stmms.biz.school.thread;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.com.qmth.stmms.biz.config.service.impl.SystemCache;
import cn.com.qmth.stmms.biz.lock.LockService;
import cn.com.qmth.stmms.biz.school.service.SchoolService;
import cn.com.qmth.stmms.biz.utils.SpringContextHolder;
import cn.com.qmth.stmms.common.enums.LockType;

public class OrgSyncThread implements Runnable {

    protected static Logger log = LoggerFactory.getLogger(OrgSyncThread.class);

    private SchoolService schoolService;

    private SystemCache authCache;

    public OrgSyncThread(SchoolService schoolService, SystemCache authCache) {
        this.schoolService = schoolService;
        this.authCache = authCache;
    }

    @Override
    public void run() {
        LockService lockService = SpringContextHolder.getBean(LockService.class);
        try {
            schoolService.updateOrg();
        } catch (Exception e) {
            authCache.setAuth(false);
            log.error("OrgSyncThread error", e);
        }
        lockService.unlock(LockType.SCHOOL, "");
    }

}
