package com.zhgd.xmgl.modules.basicdata.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhgd.xmgl.modules.basicdata.constant.CacheConstants;
import com.zhgd.xmgl.modules.basicdata.entity.SystemDictData;
import com.zhgd.xmgl.modules.basicdata.mapper.SystemDictDataMapper;
import com.zhgd.xmgl.modules.basicdata.service.ISystemDictDataService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 字典数据
 * @author： pds
 * @date：   2023-02-15
 * @version： V1.0
 */
@Service
public class SystemDictDataServiceImpl extends ServiceImpl<SystemDictDataMapper, SystemDictData> implements ISystemDictDataService {


    @Override
    @Cacheable(value = CacheConstants.DICT_DETAILS, key = "#type", unless = "#result.isEmpty()")
    public List<SystemDictData> getByType(String type) {
        return this.list(Wrappers.<SystemDictData>lambdaQuery()
                .eq(SystemDictData::getDictType, type).orderByAsc(SystemDictData::getDictSort));
    }

    @Override
    @CacheEvict(value = CacheConstants.DICT_DETAILS, key = "#systemDictData.dictType")
    public boolean delInfo(SystemDictData systemDictData) {
        return baseMapper.deleteById(systemDictData.getDictCode()) == 1 ? true : false;
    }
}
