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

import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.jx.domain.DriveSchoolDailyManagement;
import cn.iocoder.yudao.module.jx.mapper.DriveSchoolDailyManagementMapper;
import cn.iocoder.yudao.module.jx.service.IDriveSchoolDailyManagementService;
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 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-24
 */
@Service
public class DriveSchoolDailyManagementServiceImpl implements IDriveSchoolDailyManagementService
{
    @Autowired
    private DriveSchoolDailyManagementMapper driveSchoolDailyManagementMapper;

    @Resource
    private AdminUserApi userApi;

    /**
     * 查询驾校日常管理
     *
     * @param id 驾校日常管理主键
     * @return 驾校日常管理
     */
    @Override
    public DriveSchoolDailyManagement selectDriveSchoolDailyManagementById(Long id)
    {
        return driveSchoolDailyManagementMapper.selectDriveSchoolDailyManagementById(id);
    }

    /**
     * 查询驾校日常管理列表
     *
     * @param driveSchoolDailyManagement 驾校日常管理
     * @return 驾校日常管理
     */
    @Override
    public IPage<DriveSchoolDailyManagement> selectDriveSchoolDailyManagementList(DriveSchoolDailyManagement driveSchoolDailyManagement, Page<DriveSchoolDailyManagement> page)
    {
        Long userId = SecurityFrameworkUtils.getLoginUserId();
        AdminUserRespDTO user = userApi.getUser(userId);
        Long deptId = user.getDeptId();
        driveSchoolDailyManagement.setDeptId(deptId);
        return driveSchoolDailyManagementMapper.selectDriveSchoolDailyManagementList(driveSchoolDailyManagement,page);
    }

    /**
     * 新增驾校日常管理
     *
     * @param driveSchoolDailyManagement 驾校日常管理
     * @return 结果
     */
    @Override
    public int insertDriveSchoolDailyManagement(DriveSchoolDailyManagement driveSchoolDailyManagement)
    {
        Long userId = SecurityFrameworkUtils.getLoginUserId();
        AdminUserRespDTO user = userApi.getUser(userId);
        Long deptId = user.getDeptId();
        driveSchoolDailyManagement.setDeptId(deptId);
        //driveSchoolDailyManagement.setCreateTime(DateUtils.getNowDate());
        return driveSchoolDailyManagementMapper.insertDriveSchoolDailyManagement(driveSchoolDailyManagement);
    }

    /**
     * 修改驾校日常管理
     *
     * @param driveSchoolDailyManagement 驾校日常管理
     * @return 结果
     */
    @Override
    public int updateDriveSchoolDailyManagement(DriveSchoolDailyManagement driveSchoolDailyManagement)
    {
        Long userId = SecurityFrameworkUtils.getLoginUserId();
        AdminUserRespDTO user = userApi.getUser(userId);
        Long deptId = user.getDeptId();
        driveSchoolDailyManagement.setDeptId(deptId);
        //driveSchoolDailyManagement.setUpdateTime(DateUtils.getNowDate());
        return driveSchoolDailyManagementMapper.updateDriveSchoolDailyManagement(driveSchoolDailyManagement);
    }

    /**
     * 批量删除驾校日常管理
     *
     * @param ids 需要删除的驾校日常管理主键
     * @return 结果
     */
    @Override
    public int deleteDriveSchoolDailyManagementByIds(Long[] ids)
    {
        return driveSchoolDailyManagementMapper.deleteDriveSchoolDailyManagementByIds(ids);
    }

    /**
     * 删除驾校日常管理信息
     *
     * @param id 驾校日常管理主键
     * @return 结果
     */
    @Override
    public int deleteDriveSchoolDailyManagementById(Long id)
    {
        return driveSchoolDailyManagementMapper.deleteDriveSchoolDailyManagementById(id);
    }
}
