package org.springblade.system.service.impl;

import jakarta.annotation.Resource;
import org.springblade.common.core.domain.R;
import org.springblade.common.core.domain.entity.SysEncryType;
import org.springblade.system.mapper.SysEncryTypeMapper;
import org.springblade.system.service.ISysEncryTypeService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author：liang.chao
 * @Date：2025/9/10 - 10:33
 */
@Service
public class SysEncryTypeServiceImpl implements ISysEncryTypeService {

    @Resource
    private SysEncryTypeMapper sysEncryTypeMapper;

    @Override
    public List<SysEncryType> selectSysEncryTypeList(SysEncryType sysEncryType) {
        return sysEncryTypeMapper.selectSysEncryTypeList(sysEncryType);
    }

    @Override
    public R edit(SysEncryType sysEncryType) {
        try {
            Integer i = sysEncryTypeMapper.selectSysEncryType(sysEncryType);
            if (i > 0) {
                return R.fail("该加密名称已存在");
            }
            return R.ok(sysEncryTypeMapper.edit(sysEncryType));
        }catch (Exception e){
            return R.fail("修改失败");
        }
    }

    @Override
    public R add(SysEncryType sysEncryType) {
        try {
            Integer i = sysEncryTypeMapper.selectSysEncryType(sysEncryType);
            if (i > 0) {
                return R.fail("该加密名称已存在");
            }
            return R.ok(sysEncryTypeMapper.add(sysEncryType));
        }catch (Exception e){
            return R.fail("新增失败");
        }
    }

    @Override
    public Integer del(SysEncryType sysEncryType) {
        return sysEncryTypeMapper.del(sysEncryType);
    }



    @Override
    public List<SysEncryType> selectSysEncryTypeListFile(SysEncryType sysEncryType) {
        return sysEncryTypeMapper.selectSysEncryTypeListFile(sysEncryType);
    }

    @Override
    public R editFile(SysEncryType sysEncryType) {
        try {
            Integer i = sysEncryTypeMapper.selectSysEncryTypeFile(sysEncryType);
            if (i > 0) {
                return R.fail("该加密名称已存在");
            }
            return R.ok(sysEncryTypeMapper.editFile(sysEncryType));
        }catch (Exception e){
            return R.fail("修改失败");
        }
    }

    @Override
    public R addFile(SysEncryType sysEncryType) {
        try {
            Integer i = sysEncryTypeMapper.selectSysEncryTypeFile(sysEncryType);
            if (i > 0) {
                return R.fail("该加密名称已存在");
            }
            return R.ok(sysEncryTypeMapper.addFile(sysEncryType));
        }catch (Exception e){
            return R.fail("新增失败");
        }
    }

    @Override
    public Integer delFile(SysEncryType sysEncryType) {
        return sysEncryTypeMapper.delFile(sysEncryType);
    }
}
