package com.qmth.themis.business.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qmth.themis.business.cache.ExamRecordCacheUtil;
import com.qmth.themis.business.constant.SystemConstant;
import com.qmth.themis.business.dao.TGErrorMapper;
import com.qmth.themis.business.entity.TGError;
import com.qmth.themis.business.service.TGErrorService;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @Description: 全局异常错误信息 服务实现类
 * @Param:
 * @return:
 * @Author: wangliang
 * @Date: 2020/11/17
 */
@Service
public class TGErrorServiceImpl extends ServiceImpl<TGErrorMapper, TGError> implements TGErrorService {

    /**
     * 保存考试错误信息
     *
     * @param s
     */
    @Override
    public void saveExamTgError(Object... s) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put(SystemConstant.RECORD_ID, (Long) s[0]);
        jsonObject.put("method", s[1]);
        if (Objects.nonNull(ExamRecordCacheUtil.getStatus((Long) s[0]))) {
            jsonObject.put("examStatus", ExamRecordCacheUtil.getStatus((Long) s[0]));
        }
        TGError tgError = new TGError(jsonObject.toJSONString(), System.currentTimeMillis());
        this.save(tgError);
    }
}