package org.springblade.system.service.impl;

import jakarta.annotation.Resource;
import org.springblade.common.core.domain.R;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.system.domain.FilesClassifyNameStandardDto;
import org.springblade.system.mapper.FilesClassifyNameStandardMapper;
import org.springblade.system.service.FilesClassifyNameStandardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;



/**
 * @Author：liang.chao
 * @Date：2025/9/12 - 10:43
 */
@Service
public class FilesClassifyNameStandardServiceImpl implements FilesClassifyNameStandardService {

    @Resource
    private FilesClassifyNameStandardMapper filesClassifyNameStandardMapper;
    @Override
    public List<FilesClassifyNameStandardDto> getClassifyNameStandardList(FilesClassifyNameStandardDto dto) {
        return filesClassifyNameStandardMapper.getClassifyNameStandardList(dto);
    }

    @Override
    public R add(FilesClassifyNameStandardDto dto) {
        dto.setCreateUserId(AuthUtil.getUser().getUserId().intValue());
        dto.setCreateUserName(AuthUtil.getUser().getUserName());
        dto.setUpdateUserId(AuthUtil.getUser().getUserId().intValue());
        dto.setUpdateUserName(AuthUtil.getUser().getUserName());
        // 查询档案名称是否重复
        Integer i = filesClassifyNameStandardMapper.selectClassifyNameStandard(dto);
        if (i > 0) {
            return R.fail("规范识别值已重复");
        }
        return R.ok(filesClassifyNameStandardMapper.add(dto));
    }

    @Override
    public R edit(FilesClassifyNameStandardDto dto) {
        dto.setUpdateUserId(AuthUtil.getUser().getUserId().intValue());
        dto.setUpdateUserName(AuthUtil.getUser().getUserName());
        // 查询档案名称是否重复
        Integer i = filesClassifyNameStandardMapper.selectClassifyNameStandard(dto);
        if (i > 0) {
            return R.fail("规范识别值已重复");
        }
        return R.ok(filesClassifyNameStandardMapper.edit(dto));
    }

    @Override
    public R del(FilesClassifyNameStandardDto dto) {
        return R.ok(filesClassifyNameStandardMapper.del(dto));
    }
}
