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.DriveSchoolNotice;
import cn.iocoder.yudao.module.jx.mapper.DriveSchoolNoticeMapper;
import cn.iocoder.yudao.module.jx.service.IDriveSchoolNoticeService;
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 javax.imageio.IIOParam;
import java.util.List;
/**
 * 通知Service业务层处理
 *
 * @author ruoyi
 * @date 2024-05-28
 */
@Service
public class DriveSchoolNoticeServiceImpl implements IDriveSchoolNoticeService
{
    @Autowired
    private DriveSchoolNoticeMapper driveSchoolNoticeMapper;

    @Resource
    private AdminUserApi userApi;

    /**
     * 查询通知
     *
     * @param id 通知主键
     * @return 通知
     */
    @Override
    public DriveSchoolNotice selectDriveSchoolNoticeById(Long id)
    {
        return driveSchoolNoticeMapper.selectDriveSchoolNoticeById(id);
    }

    /**
     * 查询通知列表
     *
     * @param driveSchoolNotice 通知
     * @return 通知
     */
    @Override
    public IPage<DriveSchoolNotice> selectDriveSchoolNoticeList(DriveSchoolNotice driveSchoolNotice, Page<DriveSchoolNotice> page)
    {
        Long userId = SecurityFrameworkUtils.getLoginUserId();
        AdminUserRespDTO user = userApi.getUser(userId);
        Long deptId = user.getDeptId();
        driveSchoolNotice.setDeptId(deptId);
        if (deptId == 100){
            driveSchoolNotice.setDeptId(null);
        }
        return driveSchoolNoticeMapper.selectDriveSchoolNoticeList(driveSchoolNotice,page);
    }

    @Override
    public List<DriveSchoolNotice> selectDriveSchoolNoticeAppList(DriveSchoolNotice driveSchoolNotice)
    {
        Long userId = SecurityFrameworkUtils.getLoginUserId();
        AdminUserRespDTO user = userApi.getUser(userId);
        Long deptId = user.getDeptId();
        driveSchoolNotice.setDeptId(deptId);
        return driveSchoolNoticeMapper.selectDriveSchoolNoticeListAll(driveSchoolNotice);
    }

    /**
     * 新增通知
     *
     * @param driveSchoolNotice 通知
     * @return 结果
     */
    @Override
    public int insertDriveSchoolNotice(DriveSchoolNotice driveSchoolNotice)
    {
        return driveSchoolNoticeMapper.insertDriveSchoolNotice(driveSchoolNotice);
    }

    /**
     * 修改通知
     *
     * @param driveSchoolNotice 通知
     * @return 结果
     */
    @Override
    public int updateDriveSchoolNotice(DriveSchoolNotice driveSchoolNotice)
    {
        //driveSchoolNotice.setUpdateTime(DateUtils.getNowDate());
        return driveSchoolNoticeMapper.updateDriveSchoolNotice(driveSchoolNotice);
    }

    /**
     * 批量删除通知
     *
     * @param ids 需要删除的通知主键
     * @return 结果
     */
    @Override
    public int deleteDriveSchoolNoticeByIds(Long[] ids)
    {
        return driveSchoolNoticeMapper.deleteDriveSchoolNoticeByIds(ids);
    }

    /**
     * 删除通知信息
     *
     * @param id 通知主键
     * @return 结果
     */
    @Override
    public int deleteDriveSchoolNoticeById(Long id)
    {
        return driveSchoolNoticeMapper.deleteDriveSchoolNoticeById(id);
    }
}
