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.DriveSchoolSwiper;
import cn.iocoder.yudao.module.jx.mapper.DriveSchoolInfoMapper;
import cn.iocoder.yudao.module.jx.mapper.DriveSchoolSwiperMapper;
import cn.iocoder.yudao.module.jx.service.IDriveSchoolSwiperService;
import cn.iocoder.yudao.module.jx.vo.DriveSchoolInfoVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.thoughtworks.xstream.core.SecurityUtils;
import org.apache.commons.lang3.ObjectUtils;
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-03-19
 */
@Service
public class DriveSchoolSwiperServiceImpl implements IDriveSchoolSwiperService
{
    @Autowired
    private DriveSchoolSwiperMapper driveSchoolSwiperMapper;

    @Resource
    private AdminUserApi userApi;

    /**
     * 查询驾校-轮播图
     *
     * @param id 驾校-轮播图主键
     * @return 驾校-轮播图
     */
    @Override
    public DriveSchoolSwiper selectDriveSchoolSwiperById(Long id)
    {
        return driveSchoolSwiperMapper.selectDriveSchoolSwiperById(id);
    }

    /**
     * 查询驾校-轮播图列表
     *
     * @param driveSchoolSwiper 驾校-轮播图
     * @return 驾校-轮播图
     */
    @Override
    public List<DriveSchoolSwiper> selectDriveSchoolSwiperList(DriveSchoolSwiper driveSchoolSwiper)
    {

        return driveSchoolSwiperMapper.selectDriveSchoolSwiperList(driveSchoolSwiper);
    }

    @Resource
    private DriveSchoolInfoMapper driveSchoolInfoMapper;

    /**
     * 分页查询驾校-轮播图
     *
     * @param driveSchoolSwiper 驾校-轮播图
     * @return 结果
     */
    @Override
    public IPage<DriveSchoolSwiper> selectDriveSchoolSwiperPclist(DriveSchoolSwiper driveSchoolSwiper, Page<DriveSchoolSwiper> page) {
        Long deptId = 0L;
        if (ObjectUtils.isNotEmpty(driveSchoolSwiper.getJxId())) {
            DriveSchoolInfoVO schoolInfoByDeptId = driveSchoolInfoMapper.findInfoByJxId(driveSchoolSwiper.getJxId());
            deptId = schoolInfoByDeptId.getDeptId();
        } else {
            Long userId = SecurityFrameworkUtils.getLoginUserId();
            AdminUserRespDTO user = userApi.getUser(userId);
            deptId = user.getDeptId();
        }
        driveSchoolSwiper.setDeptId(deptId);

        // 创建分页对象
//        Page<DriveSchoolSwiper> page = new Page<>(driveSchoolSwiper.getPageNum(), driveSchoolSwiper.getPageSize());
        return driveSchoolSwiperMapper.selectDriveSchoolSwiperPage(driveSchoolSwiper,page);
    }

    /**
     * 新增驾校-轮播图
     *
     * @param driveSchoolSwiper 驾校-轮播图
     * @return 结果
     */
    @Override
    public int insertDriveSchoolSwiper(DriveSchoolSwiper driveSchoolSwiper)
    {
        Long userId = SecurityFrameworkUtils.getLoginUserId();
        AdminUserRespDTO user = userApi.getUser(userId);
        Long deptId = user.getDeptId();
        driveSchoolSwiper.setDeptId(deptId);
        return driveSchoolSwiperMapper.insertDriveSchoolSwiper(driveSchoolSwiper);
    }

    /**
     * 修改驾校-轮播图
     *
     * @param driveSchoolSwiper 驾校-轮播图
     * @return 结果
     */
    @Override
    public int updateDriveSchoolSwiper(DriveSchoolSwiper driveSchoolSwiper)
    {
        //driveSchoolSwiper.setUpdateTime(DateUtils.getNowDate());
        return driveSchoolSwiperMapper.updateDriveSchoolSwiper(driveSchoolSwiper);
    }

    /**
     * 批量删除驾校-轮播图
     *
     * @param ids 需要删除的驾校-轮播图主键
     * @return 结果
     */
    @Override
    public int deleteDriveSchoolSwiperByIds(Long[] ids)
    {
        return driveSchoolSwiperMapper.deleteDriveSchoolSwiperByIds(ids);
    }

    /**
     * 删除驾校-轮播图信息
     *
     * @param id 驾校-轮播图主键
     * @return 结果
     */
    @Override
    public int deleteDriveSchoolSwiperById(Long id)
    {
        return driveSchoolSwiperMapper.deleteDriveSchoolSwiperById(id);
    }
}
