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.DriveSchoolTeachingJournal;
import cn.iocoder.yudao.module.jx.mapper.DriveSchoolTeachingJournalMapper;
import cn.iocoder.yudao.module.jx.service.IDriveSchoolTeachingJournalService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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-05-19
 */
@Service
public class DriveSchoolTeachingJournalServiceImpl implements IDriveSchoolTeachingJournalService
{
    @Autowired
    private DriveSchoolTeachingJournalMapper driveSchoolTeachingJournalMapper;

//    @Resource
//    private ISysUserService iSysUserService;

    @Resource
    private AdminUserApi userApi;

    /**
     * 查询教学日志
     *
     * @param id 教学日志主键
     * @return 教学日志
     */
    @Override
    public DriveSchoolTeachingJournal selectDriveSchoolTeachingJournalById(Long id)
    {
        return driveSchoolTeachingJournalMapper.selectDriveSchoolTeachingJournalById(id);
    }

    /**
     * 查询教学日志列表
     *
     * @param driveSchoolTeachingJournal 教学日志
     * @return 教学日志
     */
    @Override
    public IPage<DriveSchoolTeachingJournal> selectDriveSchoolTeachingJournalList(DriveSchoolTeachingJournal driveSchoolTeachingJournal, Page<DriveSchoolTeachingJournal> page)
    {
        Long deptId = SecurityFrameworkUtils.getLoginUserDeptId();
        driveSchoolTeachingJournal.setDeptId(deptId);
        return driveSchoolTeachingJournalMapper.selectDriveSchoolTeachingJournalList(driveSchoolTeachingJournal,page);
    }

    /**
     * 新增教学日志
     *
     * @param driveSchoolTeachingJournal 教学日志
     * @return 结果
     */
    @Override
    public int insertDriveSchoolTeachingJournal(DriveSchoolTeachingJournal driveSchoolTeachingJournal)
    {
        Long userId = SecurityFrameworkUtils.getLoginUserId();
        AdminUserRespDTO sysUser = userApi.getUser(userId);
        Long deptId = sysUser.getDeptId();
        driveSchoolTeachingJournal.setDeptId(deptId);
//        Long userId = SecurityFrameworkUtils.getLoginUserId();
//        SysUser sysUser = iSysUserService.selectUserById(userId);
        if (ObjectUtils.isNotEmpty(sysUser) && ObjectUtils.isNotEmpty(sysUser.getNickname())){
            driveSchoolTeachingJournal.setUserName(sysUser.getNickname());
        }
        return driveSchoolTeachingJournalMapper.insertDriveSchoolTeachingJournal(driveSchoolTeachingJournal);
    }

    /**
     * 修改教学日志
     *
     * @param driveSchoolTeachingJournal 教学日志
     * @return 结果
     */
    @Override
    public int updateDriveSchoolTeachingJournal(DriveSchoolTeachingJournal driveSchoolTeachingJournal)
    {
        //driveSchoolTeachingJournal.setUpdateTime(DateUtils.getNowDate());
        return driveSchoolTeachingJournalMapper.updateDriveSchoolTeachingJournal(driveSchoolTeachingJournal);
    }

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

    /**
     * 删除教学日志信息
     *
     * @param id 教学日志主键
     * @return 结果
     */
    @Override
    public int deleteDriveSchoolTeachingJournalById(Long id)
    {
        return driveSchoolTeachingJournalMapper.deleteDriveSchoolTeachingJournalById(id);
    }
}
