package com.schisandra.system.infra.basic.service.impl;


import com.schisandra.system.infra.basic.dao.SchisandraSysConfigDao;
import com.schisandra.system.infra.basic.entity.SchisandraSysConfig;
import com.schisandra.system.infra.basic.entity.table.SchisandraSysConfigTableDef;
import com.schisandra.system.infra.basic.service.SchisandraSysConfigService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 表服务实现类
 *
 * @author landaiqing
 * @since 2024-05-11 22:45:55
 */
@Service("SchisandraSysConfigService")
public class SchisandraSysConfigServiceImpl implements SchisandraSysConfigService {

    @Resource
    private SchisandraSysConfigDao schisandraSysConfigDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SchisandraSysConfig queryById(Long id) {
        return this.schisandraSysConfigDao.selectOneById(id);
    }

    /**
     * 新增数据
     *
     * @param schisandraSysConfig 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(SchisandraSysConfig schisandraSysConfig) {
        return this.schisandraSysConfigDao.insert(schisandraSysConfig);
    }

    /**
     * 修改数据
     *
     * @param schisandraSysConfig 实例对象
     * @return 实例对象
     */
    @Override
    public int update(SchisandraSysConfig schisandraSysConfig) {
        return this.schisandraSysConfigDao.update(schisandraSysConfig, true);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.schisandraSysConfigDao.deleteById(id) > 0;
    }

    /**
     * 通过关键字查找配置
     *
     * @param key key
     * @return 实体
     */
    @Override
    public SchisandraSysConfig getConfigByKey(String key) {
        return schisandraSysConfigDao.selectOneByCondition(SchisandraSysConfigTableDef.SCHISANDRA_SYS_CONFIG.CONFIG_KEY.eq(key));
    }

}
