package org.springblade.system.service.impl;

import jakarta.annotation.Resource;
import org.springblade.common.core.domain.AjaxResult;
import org.springblade.system.domain.FileIndexDto;
import org.springblade.system.mapper.FileIndexMapper;
import org.springblade.system.service.FileIndexService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author：liang.chao
 * @Date：2025/10/30 - 16:21
 */
@Service
public class FileIndexServiceImpl implements FileIndexService {

    @Resource
    private FileIndexMapper mapper;
    @Override
    public List<FileIndexDto> getList(FileIndexDto dto) {
        return mapper.getList(dto);
    }

    @Override
    public AjaxResult add(FileIndexDto dto) {
        // 查询名称是否重复
        Integer count = mapper.getCount(dto);
        if (count > 0) {
            return AjaxResult.error("名称已重复，请重新修改");
        }
        Integer add = mapper.add(dto);
        return add > 0 ? AjaxResult.success("添加成功") : AjaxResult.error("添加失败");
    }

    @Override
    public AjaxResult update(FileIndexDto dto) {
        // 查询名称是否重复
        Integer count = mapper.getCount(dto);
        if (count > 0) {
            return AjaxResult.error("名称已重复，请重新修改");
        }
        Integer update = mapper.update(dto);
        return update > 0 ? AjaxResult.success("修改成功") : AjaxResult.error("修改失败");
    }

    @Override
    public AjaxResult del(FileIndexDto dto) {
        Integer del = mapper.del(dto);
        return del > 0 ? AjaxResult.success("删除成功") : AjaxResult.error("删除失败");
    }
}
