package com.bonus.sharedstation.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bonus.sharedstation.api.dto.DictDataRespDTO;
import com.bonus.sharedstation.api.mapper.DictMapper;
import com.bonus.sharedstation.api.service.DictService;
import com.bonus.sharedstation.api.vo.DictDataInfoDO;
import org.springframework.stereotype.Service;

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

/**
 * 字典类型 Service 实现类
 *
 * @author roof
 */
@Service
public class DictServiceImpl implements DictService {


    @Resource
    private DictMapper dictMapper;

    /**
     * 查询字典数据
     *
     * @param dataType
     * @return
     */
    @Override
    public List<DictDataInfoDO> getDataByType(String dataType) {
        if (dataType != null && !"".equals(dataType)) {
            return dictMapper.selectList(new LambdaQueryWrapper<DictDataInfoDO>().eq(DictDataInfoDO::getDataType, dataType));
        }
        return null;
    }

    @Override
    public List<DictDataInfoDO> queryDictDataByCode(String dataType, String dataCode, long tenantId) {
        if (dataType != null && !"".equals(dataType)) {
            return dictMapper.selectList(new LambdaQueryWrapper<DictDataInfoDO>()
                    .eq(DictDataInfoDO::getDataType, dataType)
                    .eq(DictDataInfoDO::getDataCode, dataCode)
                    .eq(DictDataInfoDO::getTenantId, tenantId));
        }
        return null;
    }

    @Override
    public List<DictDataInfoDO> getDictionaryInfo(String dataType) {
        if (dataType != null && !"".equals(dataType)) {
            return dictMapper.selectList(new LambdaQueryWrapper<DictDataInfoDO>()
                    .eq(DictDataInfoDO::getDataType, dataType));
        }
        return null;
    }

    @Override
    public DictDataInfoDO getDictionaryData(String dataType) {
        if (dataType != null && !"".equals(dataType)) {
            return dictMapper.selectOne(new LambdaQueryWrapper<DictDataInfoDO>()
                    .eq(DictDataInfoDO::getDataType, dataType));
        }
        return null;
    }

    @Override
    public DictDataInfoDO getDictionaryDataByCondition(String dataType, String dataCode) {
        if (dataType != null && !"".equals(dataType)) {
            return dictMapper.selectOne(new LambdaQueryWrapper<DictDataInfoDO>()
                    .eq(DictDataInfoDO::getDataType, dataType)
                    .eq(DictDataInfoDO::getDataType, dataCode));
        }
        return null;
    }
}
