package cn.iocoder.yudao.module.jx.service.impl;

import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.jx.utils.DateUtils;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import cn.iocoder.yudao.module.jx.domain.DriveSchoolCredentials;
import cn.iocoder.yudao.module.jx.mapper.DriveSchoolCredentialsMapper;
import cn.iocoder.yudao.module.jx.service.IDriveSchoolCredentialsService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
/**
 * 驾校资质信息Service业务层处理
 *
 * @author ruoyi
 * @date 2024-05-23
 */
@Service
public class DriveSchoolCredentialsServiceImpl implements IDriveSchoolCredentialsService
{
    @Autowired
    private DriveSchoolCredentialsMapper driveSchoolCredentialsMapper;

    @Resource
    private AdminUserApi userApi;

    /**
     * 查询驾校资质信息
     *
     * @param id 驾校资质信息主键
     * @return 驾校资质信息
     */
    @Override
    public DriveSchoolCredentials selectDriveSchoolCredentialsById(Long id)
    {
        return driveSchoolCredentialsMapper.selectDriveSchoolCredentialsById(id);
    }

    /**
     * 查询驾校资质信息列表
     *
     * @param driveSchoolCredentials 驾校资质信息
     * @return 驾校资质信息
     */
    @Override
    public IPage<DriveSchoolCredentials> selectDriveSchoolCredentialsList(DriveSchoolCredentials driveSchoolCredentials, Page<DriveSchoolCredentials> page)
    {
        Long userId = SecurityFrameworkUtils.getLoginUserId();
        AdminUserRespDTO user = userApi.getUser(userId);
        Long deptId = user.getDeptId();
        driveSchoolCredentials.setDeptId(deptId);
        return driveSchoolCredentialsMapper.selectDriveSchoolCredentialsList(driveSchoolCredentials,page);
    }

    /**
     * 新增驾校资质信息
     *
     * @param driveSchoolCredentials 驾校资质信息
     * @return 结果
     */
    @Override
    public int insertDriveSchoolCredentials(DriveSchoolCredentials driveSchoolCredentials)
    {
        Long userId = SecurityFrameworkUtils.getLoginUserId();
        AdminUserRespDTO user = userApi.getUser(userId);
        Long deptId = user.getDeptId();
        driveSchoolCredentials.setDeptId(deptId);
        //driveSchoolCredentials.setCreateTime(DateUtils.getNowDate());
        return driveSchoolCredentialsMapper.insertDriveSchoolCredentials(driveSchoolCredentials);
    }

    /**
     * 修改驾校资质信息
     *
     * @param driveSchoolCredentials 驾校资质信息
     * @return 结果
     */
    @Override
    public int updateDriveSchoolCredentials(DriveSchoolCredentials driveSchoolCredentials)
    {
        Long userId = SecurityFrameworkUtils.getLoginUserId();
        AdminUserRespDTO user = userApi.getUser(userId);
        Long deptId = user.getDeptId();
        driveSchoolCredentials.setDeptId(deptId);
        //driveSchoolCredentials.setUpdateTime(DateUtils.getNowDate());
        return driveSchoolCredentialsMapper.updateDriveSchoolCredentials(driveSchoolCredentials);
    }

    /**
     * 批量删除驾校资质信息
     *
     * @param ids 需要删除的驾校资质信息主键
     * @return 结果
     */
    @Override
    public int deleteDriveSchoolCredentialsByIds(Long[] ids)
    {
        return driveSchoolCredentialsMapper.deleteDriveSchoolCredentialsByIds(ids);
    }

    /**
     * 删除驾校资质信息信息
     *
     * @param id 驾校资质信息主键
     * @return 结果
     */
    @Override
    public int deleteDriveSchoolCredentialsById(Long id)
    {
        return driveSchoolCredentialsMapper.deleteDriveSchoolCredentialsById(id);
    }
}
