package com.vctgo.file.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vctgo.common.core.text.Convert;
import com.vctgo.common.core.utils.ServletUtils;
import com.vctgo.common.mybatisplus.constant.MybatisPageConstants;
import com.vctgo.common.security.utils.SecurityUtils;
import com.vctgo.file.domain.FileAuthGroup;
import com.vctgo.file.mapper.FileAuthGroupMapper;
import com.vctgo.file.service.IFileAuthGroupService;
import com.vctgo.file.utils.ConstantUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 文件权限分组Service业务层处理
 *
 * @author caesar
 * @date 2024-01-31
 */
@Slf4j
@Service
public class FileAuthGroupServiceImpl implements IFileAuthGroupService {
    @Autowired
    private FileAuthGroupMapper fileAuthGroupMapper;

    /**
     * 查询文件权限分组
     *
     * @param id 文件权限分组主键
     * @return 文件权限分组
     */
    @Override
    public FileAuthGroup selectFileAuthGroupById(Long id) {
        return fileAuthGroupMapper.selectById(id);
    }

    /**
     * 查询文件权限分组列表-分页
     *
     * @param fileAuthGroup 文件权限分组
     * @return 文件权限分组
     */
    @Override
    public IPage<FileAuthGroup> selectFileAuthGroupPage(FileAuthGroup fileAuthGroup) {
        Page mpPage = new Page(Convert.toLong(ServletUtils.getParameterToInt(MybatisPageConstants.PAGE_NUM), 1L)
                , Convert.toLong(ServletUtils.getParameterToInt(MybatisPageConstants.PAGE_SIZE), 10L));
        return fileAuthGroupMapper.selectFileAuthGroupList(mpPage, fileAuthGroup);
    }

    /**
     * 查询文件权限分组列表
     *
     * @param fileAuthGroup 文件权限分组
     * @return 文件权限分组
     */
    @Override
    public List<FileAuthGroup> selectFileAuthGroupList(FileAuthGroup fileAuthGroup) {
        return fileAuthGroupMapper.selectFileAuthGroupList(fileAuthGroup);
    }

    /**
     * 新增文件权限分组
     *
     * @param fileAuthGroup 文件权限分组
     * @return 结果
     */

    @Override
    public int insertFileAuthGroup(FileAuthGroup fileAuthGroup) {
        return fileAuthGroupMapper.insert(fileAuthGroup);
    }

    /**
     * 修改文件权限分组
     *
     * @param fileAuthGroup 文件权限分组
     * @return 结果
     */
    @Override
    public int updateFileAuthGroup(FileAuthGroup fileAuthGroup) {
        return fileAuthGroupMapper.updateById(fileAuthGroup);
    }

    /**
     * 逻辑删除文件权限分组
     *
     * @param ids 需要删除的文件权限分组主键
     * @return 结果
     */
    @Override
    public int logicalDeleteFileAuthGroupByIds(Long[] ids) {
        FileAuthGroup fileAuthGroup = new FileAuthGroup();
        fileAuthGroup.setUpdateById(SecurityUtils.getUserId());
        fileAuthGroup.setUpdateTime(new Date());
        fileAuthGroup.setIsDeleted(ConstantUtils.IS_DELETED_1);
        return fileAuthGroupMapper.logicalDeleteFileAuthGroupByIds(ids, fileAuthGroup);
    }

    /**
     * 批量删除文件权限分组
     *
     * @param ids 需要删除的文件权限分组主键
     * @return 结果
     */
    @Override
    public int deleteFileAuthGroupByIds(Long[] ids) {
        return fileAuthGroupMapper.deleteFileAuthGroupByIds(ids);
    }

    /**
     * 删除文件权限分组信息
     *
     * @param id 文件权限分组主键
     * @return 结果
     */
    @Override
    public int deleteFileAuthGroupById(Long id) {
        return fileAuthGroupMapper.deleteById(id);
    }

    @Override
    public List<FileAuthGroup> getGroupList(String groupType) {
        return fileAuthGroupMapper.selectList(new QueryWrapper<FileAuthGroup>().lambda().eq(FileAuthGroup::getGroupType,groupType).eq(FileAuthGroup::getIsShow,ConstantUtils.IS_SHOW_0));
    }
}
