package com.zd.exam.service.impl;

import java.sql.SQLIntegrityConstraintViolationException;
import java.util.List;

import com.zd.common.core.exception.ServiceException;
import com.zd.common.core.utils.DateUtils;
import com.zd.common.core.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zd.exam.mapper.ElSafeTrainRecordMapper;
import com.zd.exam.domain.ElSafeTrainRecord;
import com.zd.exam.service.IElSafeTrainRecordService;

/**
 * 培训学习记录Service业务层处理
 *
 * @author zhoupan
 * @date 2021-09-07
 */
@Service
public class ElSafeTrainRecordServiceImpl implements IElSafeTrainRecordService {
    @Autowired
    private ElSafeTrainRecordMapper elSafeTrainRecordMapper;

    /**
     * 查询培训学习记录
     *
     * @param id 培训学习记录主键
     * @return 培训学习记录
     */
    @Override
    public ElSafeTrainRecord selectElSafeTrainRecordById(Long id) {
        return elSafeTrainRecordMapper.selectElSafeTrainRecordById(id);
    }

    /**
     * 查询培训学习记录列表
     *
     * @param elSafeTrainRecord 培训学习记录
     * @return 培训学习记录
     */
    @Override
    public List<ElSafeTrainRecord> selectElSafeTrainRecordList(ElSafeTrainRecord elSafeTrainRecord) {
        return elSafeTrainRecordMapper.selectElSafeTrainRecordList(elSafeTrainRecord);
    }

    /**
     * 新增培训学习记录
     *
     * @param elSafeTrainRecord 培训学习记录
     * @return 结果
     */
    @Override
    public int insertElSafeTrainRecord(ElSafeTrainRecord elSafeTrainRecord) {
        elSafeTrainRecord.setCreateTime(DateUtils.getNowDate());
        elSafeTrainRecord.setCreateBy(SecurityUtils.getUsername());
        elSafeTrainRecord.setUserId(SecurityUtils.getUserId());
        try {
            return elSafeTrainRecordMapper.insertElSafeTrainRecord(elSafeTrainRecord);
        } catch (Exception e) {
            throw new ServiceException("您已完成该培训资料学习，请勿重复提交！");
        }


    }

    /**
     * 修改培训学习记录
     *
     * @param elSafeTrainRecord 培训学习记录
     * @return 结果
     */
    @Override
    public int updateElSafeTrainRecord(ElSafeTrainRecord elSafeTrainRecord) {
        elSafeTrainRecord.setUpdateTime(DateUtils.getNowDate());
        return elSafeTrainRecordMapper.updateElSafeTrainRecord(elSafeTrainRecord);
    }

    /**
     * 批量删除培训学习记录
     *
     * @param ids 需要删除的培训学习记录主键
     * @return 结果
     */
    @Override
    public int deleteElSafeTrainRecordByIds(Long[] ids) {
        return elSafeTrainRecordMapper.deleteElSafeTrainRecordByIds(ids);
    }

    /**
     * 删除培训学习记录信息
     *
     * @param id 培训学习记录主键
     * @return 结果
     */
    @Override
    public int deleteElSafeTrainRecordById(Long id) {
        return elSafeTrainRecordMapper.deleteElSafeTrainRecordById(id);
    }
}
