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.DriveSchoolReimbursement;
import cn.iocoder.yudao.module.jx.mapper.DriveSchoolReimbursementMapper;
import cn.iocoder.yudao.module.jx.service.IDriveSchoolReimbursementService;
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-05-19
 */
@Service
public class DriveSchoolReimbursementServiceImpl implements IDriveSchoolReimbursementService
{
    @Autowired
    private DriveSchoolReimbursementMapper driveSchoolReimbursementMapper;

//    @Resource
//    private ISysUserService iSysUserService;

    @Resource
    private AdminUserApi userApi;

    /**
     * 查询报销审核
     *
     * @param id 报销审核主键
     * @return 报销审核
     */
    @Override
    public DriveSchoolReimbursement selectDriveSchoolReimbursementById(Long id)
    {
        return driveSchoolReimbursementMapper.selectDriveSchoolReimbursementById(id);
    }

    /**
     * 查询报销审核列表
     *
     * @param driveSchoolReimbursement 报销审核
     * @return 报销审核
     */
    @Override
    public IPage<DriveSchoolReimbursement> selectDriveSchoolReimbursementList(DriveSchoolReimbursement driveSchoolReimbursement, Page<DriveSchoolReimbursement> page)
    {
        Long userId = SecurityFrameworkUtils.getLoginUserId();
        AdminUserRespDTO user = userApi.getUser(userId);
        Long deptId = user.getDeptId();
        driveSchoolReimbursement.setDeptId(deptId);
        return driveSchoolReimbursementMapper.selectDriveSchoolReimbursementList(driveSchoolReimbursement,page);
    }

    /**
     * 新增报销审核
     *
     * @param driveSchoolReimbursement 报销审核
     * @return 结果
     */
    @Override
    public int insertDriveSchoolReimbursement(DriveSchoolReimbursement driveSchoolReimbursement)
    {
        Long userId = SecurityFrameworkUtils.getLoginUserId();
        AdminUserRespDTO sysUser = userApi.getUser(userId);
        Long deptId = sysUser.getDeptId();
        driveSchoolReimbursement.setDeptId(deptId);

//        Long userId = SecurityFrameworkUtils.getLoginUserId();
//        SysUser sysUser = iSysUserService.selectUserById(userId);
        if (ObjectUtils.isNotEmpty(sysUser) && ObjectUtils.isNotEmpty(sysUser.getNickname())){
            driveSchoolReimbursement.setUserName(sysUser.getNickname());
        }
        return driveSchoolReimbursementMapper.insertDriveSchoolReimbursement(driveSchoolReimbursement);
    }

    /**
     * 修改报销审核
     *
     * @param driveSchoolReimbursement 报销审核
     * @return 结果
     */
    @Override
    public int updateDriveSchoolReimbursement(DriveSchoolReimbursement driveSchoolReimbursement)
    {
        //driveSchoolReimbursement.setUpdateTime(DateUtils.getNowDate());
        return driveSchoolReimbursementMapper.updateDriveSchoolReimbursement(driveSchoolReimbursement);
    }

    /**
     * 批量删除报销审核
     *
     * @param ids 需要删除的报销审核主键
     * @return 结果
     */
    @Override
    public int deleteDriveSchoolReimbursementByIds(Long[] ids)
    {
        return driveSchoolReimbursementMapper.deleteDriveSchoolReimbursementByIds(ids);
    }

    /**
     * 删除报销审核信息
     *
     * @param id 报销审核主键
     * @return 结果
     */
    @Override
    public int deleteDriveSchoolReimbursementById(Long id)
    {
        return driveSchoolReimbursementMapper.deleteDriveSchoolReimbursementById(id);
    }
}
