package com.zd.base.job.task;

import com.zd.common.core.domain.R;
import com.zd.system.api.exam.RemoteExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 考试定时调度任务
 *
 * @author liubo
 */
@Component("examTask")
public class ExamTask {

    @Autowired
    private RemoteExamService remoteExamService;

    /**
     * 超时弃考 调度任务
     */
    public void abandonPaper() {
        remoteExamService.abandonPaper();
    }

    /**
     * 一个月无违规获取配置表的奖励分 调度任务
     */
    public void getPointByNoViolation() {
        Map map = new HashMap();
        R r = remoteExamService.getBonusPointsConfig(map);
        List <Map<String,Object>> list = (List<Map<String,Object>>) r.getData();
        if(list.size()>0){
            Map<String,Object> noViolation = list.get(0);
            Integer monthNoviolationScore= Integer.parseInt(noViolation.get("monthNoviolationScore")+"");
            if(monthNoviolationScore!=null){
                Map violationMap = new HashMap();
                R rlv = remoteExamService.getLastMonthViolation(violationMap);
                List <Map<String,String>> recordList = (List <Map<String,String>>) rlv.getData();
                for(Map key:recordList){
                    Map <String,Object> obtainMap = new HashMap<>();
                    // 用户
                    obtainMap.put("joinUserId", key.get("joinUserId"));
                    // 奖励的分数
                    obtainMap.put("deductPoints", monthNoviolationScore);
                    // 奖励的原因
                    obtainMap.put("reason", "一个月无违规，奖励积分："+monthNoviolationScore);
                    remoteExamService.obtainBonusPoints(obtainMap);
                }
            }
        }
    }
}
