package com.ruoyi.jarvis.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.jarvis.domain.ErpOpenConfig;
import com.ruoyi.jarvis.mapper.ErpOpenConfigMapper;
import com.ruoyi.jarvis.service.IErpOpenConfigService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ErpOpenConfigServiceImpl implements IErpOpenConfigService {

    @Resource
    private ErpOpenConfigMapper erpOpenConfigMapper;

    @Override
    public ErpOpenConfig selectById(Long id) {
        return erpOpenConfigMapper.selectById(id);
    }

    @Override
    public ErpOpenConfig selectByAppKey(String appKey) {
        if (appKey == null) {
            return null;
        }
        return erpOpenConfigMapper.selectByAppKey(appKey.trim());
    }

    @Override
    public ErpOpenConfig selectFirstEnabled() {
        List<ErpOpenConfig> list = erpOpenConfigMapper.selectEnabledOrderBySort();
        return list == null || list.isEmpty() ? null : list.get(0);
    }

    @Override
    public List<ErpOpenConfig> selectList(ErpOpenConfig query) {
        return erpOpenConfigMapper.selectList(query);
    }

    @Override
    public List<ErpOpenConfig> selectEnabledOrderBySort() {
        return erpOpenConfigMapper.selectEnabledOrderBySort();
    }

    @Override
    public int insert(ErpOpenConfig row) {
        row.setCreateTime(DateUtils.getNowDate());
        return erpOpenConfigMapper.insert(row);
    }

    @Override
    public int update(ErpOpenConfig row) {
        row.setUpdateTime(DateUtils.getNowDate());
        return erpOpenConfigMapper.update(row);
    }

    @Override
    public int deleteById(Long id) {
        return erpOpenConfigMapper.deleteById(id);
    }
}
