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

import java.util.List;

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

import cn.com.qmth.stmms.biz.exam.model.Marker;
import cn.com.qmth.stmms.biz.lock.LockService;
import cn.com.qmth.stmms.biz.mark.service.MarkService;
import cn.com.qmth.stmms.biz.utils.SpringContextHolder;
import cn.com.qmth.stmms.common.enums.LockType;

/**
 * 评卷员计算评卷质量指标工作包装线程
 * 
 * @author luoshi
 *
 */
public class MarkQualityThread implements Runnable {

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

    private List<Marker> markers;

    private String lockKey;

    public MarkQualityThread(List<Marker> markers, String lockKey) {
        this.markers = markers;
        this.lockKey = lockKey;
    }

    @Override
    public void run() {
        LockService lockService = SpringContextHolder.getBean(LockService.class);
        MarkService markService = SpringContextHolder.getBean(MarkService.class);
        if (markers != null && markService != null) {
            for (Marker marker : markers) {
                try {
                    markService.updateQuality(marker);
                } catch (Exception e) {
                    log.error("marker quality thread error", e);
                }
            }
        }
        lockService.unlock(LockType.BATCH_QUALITY, lockKey);
    }
}
