package com.zd.exam.service.impl;

import com.zd.common.core.utils.DateUtils;
import com.zd.common.core.utils.SecurityUtils;
import com.zd.common.datascope.annotation.DataScope;
import com.zd.common.security.service.TokenService;
import com.zd.exam.domain.ElSafeTrain;
import com.zd.exam.domain.vo.ElSafeTrainVO;
import com.zd.exam.mapper.ElSafeTrainMapper;
import com.zd.exam.service.IElSafeTrainService;
import com.zd.system.api.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 安全培训Service业务层处理
 *
 * @author zd
 * @date 2021-09-07
 */
@Service
public class ElSafeTrainServiceImpl implements IElSafeTrainService {
    @Autowired
    private ElSafeTrainMapper elSafeTrainMapper;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询安全培训
     *
     * @param id 安全培训主键
     * @return 安全培训
     */
    @Override
    public ElSafeTrain selectElSafeTrainById(Long id) {
        return elSafeTrainMapper.selectElSafeTrainById(id);
    }

    /**
     * 查询安全培训列表
     *
     * @param elSafeTrain 安全培训
     * @return 安全培训
     */
    @Override
    @DataScope(deptAlias = "t")
    public List<ElSafeTrain> selectElSafeTrainList(ElSafeTrain elSafeTrain) {
        return elSafeTrainMapper.selectElSafeTrainList(elSafeTrain);
    }

    /**
     * 查询安全培训列表vo
     *
     * @param elSafeTrain 安全培训
     * @return 安全培训集合
     */
    @Override
    @DataScope(deptAlias = "t")
    public List<ElSafeTrainVO> selectElSafeTrainVOList(ElSafeTrain elSafeTrain) {
        return elSafeTrainMapper.selectElSafeTrainVOList(elSafeTrain, SecurityUtils.getUserId());
    }

    /**
     * 新增安全培训
     *
     * @param elSafeTrain 安全培训
     * @return 结果
     */
    @Override
    public int insertElSafeTrain(ElSafeTrain elSafeTrain) {
        SysUser user = tokenService.getLoginUser().getSysUser();

        elSafeTrain.setCreateTime(DateUtils.getNowDate());
        elSafeTrain.setCreateBy(user.getUserName());
        elSafeTrain.setUserId(user.getUserId());
        elSafeTrain.setDeptId(user.getDeptId());
        elSafeTrain.setDeptName(user.getDeptName());

        return elSafeTrainMapper.insertElSafeTrain(elSafeTrain);
    }

    /**
     * 修改安全培训
     *
     * @param elSafeTrain 安全培训
     * @return 结果
     */
    @Override
    public int updateElSafeTrain(ElSafeTrain elSafeTrain) {
        elSafeTrain.setUpdateTime(DateUtils.getNowDate());
        elSafeTrain.setUpdateBy(SecurityUtils.getUsername());
        return elSafeTrainMapper.updateElSafeTrain(elSafeTrain);
    }

    /**
     * 批量删除安全培训
     *
     * @param ids 需要删除的安全培训主键
     * @return 结果
     */
    @Override
    public int deleteElSafeTrainByIds(Long[] ids) {
        return elSafeTrainMapper.deleteElSafeTrainByIds(ids);
    }

    /**
     * 删除安全培训信息
     *
     * @param id 安全培训主键
     * @return 结果
     */
    @Override
    public int deleteElSafeTrainById(Long id) {
        return elSafeTrainMapper.deleteElSafeTrainById(id);
    }
}
