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.DriveSchoolDial;
import cn.iocoder.yudao.module.jx.mapper.DriveSchoolDialMapper;
import cn.iocoder.yudao.module.jx.service.IDriveSchoolDialService;
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 DriveSchoolDialServiceImpl implements IDriveSchoolDialService
{
    @Autowired
    private DriveSchoolDialMapper driveSchoolDialMapper;

    @Resource
    private AdminUserApi userApi;

    /**
     * 查询日常日志
     *
     * @param id 日常日志主键
     * @return 日常日志
     */
    @Override
    public DriveSchoolDial selectDriveSchoolDialById(Long id)
    {
        return driveSchoolDialMapper.selectDriveSchoolDialById(id);
    }

    /**
     * 查询日常日志列表
     *
     * @param driveSchoolDial 日常日志
     * @return 日常日志
     */
    @Override
    public IPage<DriveSchoolDial> selectDriveSchoolDialList(DriveSchoolDial driveSchoolDial, Page<DriveSchoolDial> page)
    {
        Long userId = SecurityFrameworkUtils.getLoginUserId();
        AdminUserRespDTO user = userApi.getUser(userId);
        Long deptId = user.getDeptId();
        driveSchoolDial.setDeptId(deptId);
        if (deptId == 100){
            driveSchoolDial.setDeptId(null);
        }
        return driveSchoolDialMapper.selectDriveSchoolDialList(driveSchoolDial,page);
    }

    @Override
    public IPage<DriveSchoolDial> selectDriveSchoolDialAppList(DriveSchoolDial driveSchoolDial, Page<DriveSchoolDial> page)
    {
        Long userId = SecurityFrameworkUtils.getLoginUserId();
        driveSchoolDial.setJlId(userId);
        return driveSchoolDialMapper.selectDriveSchoolDialList(driveSchoolDial,page);
    }

//    @Resource
//    private SysUserMapper sysUserMapper;
    /**
     * 新增日常日志
     *
     * @param driveSchoolDial 日常日志
     * @return 结果
     */
    @Override
    public int insertDriveSchoolDial(DriveSchoolDial driveSchoolDial)
    {
        Long userId = SecurityFrameworkUtils.getLoginUserId();

        driveSchoolDial.setJlId(userId);
        AdminUserRespDTO sysUser = userApi.getUser(userId);
        driveSchoolDial.setJlId(userId);
        driveSchoolDial.setName(sysUser.getNickname());
        driveSchoolDial.setDeptId(sysUser.getDeptId());
        return driveSchoolDialMapper.insertDriveSchoolDial(driveSchoolDial);
    }

    /**
     * 修改日常日志
     *
     * @param driveSchoolDial 日常日志
     * @return 结果
     */
    @Override
    public int updateDriveSchoolDial(DriveSchoolDial driveSchoolDial)
    {
        //driveSchoolDial.setUpdateTime(DateUtils.getNowDate());
        return driveSchoolDialMapper.updateDriveSchoolDial(driveSchoolDial);
    }

    /**
     * 批量删除日常日志
     *
     * @param ids 需要删除的日常日志主键
     * @return 结果
     */
    @Override
    public int deleteDriveSchoolDialByIds(Long[] ids)
    {
        return driveSchoolDialMapper.deleteDriveSchoolDialByIds(ids);
    }

    /**
     * 删除日常日志信息
     *
     * @param id 日常日志主键
     * @return 结果
     */
    @Override
    public int deleteDriveSchoolDialById(Long id)
    {
        return driveSchoolDialMapper.deleteDriveSchoolDialById(id);
    }
}
