All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.zznote.basecommon.service.impl.TDictDataServiceImpl Maven / Gradle / Ivy

The newest version!
package com.zznote.basecommon.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zznote.basecommon.common.constant.UserConstants;
import com.zznote.basecommon.common.page.PageInfo;
import com.zznote.basecommon.common.page.PageQuery;
import com.zznote.basecommon.common.util.DictUtils;
import com.zznote.basecommon.dao.TDictDataDao;
import com.zznote.basecommon.entity.system.TDictData;
import com.zznote.basecommon.service.TDictDataService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

@RequiredArgsConstructor
@Service
public class TDictDataServiceImpl extends ServiceImpl implements TDictDataService {

    @Override
    public List selectDictDataByType(String dictType) {
        return lambdaQuery()
                .eq(TDictData::getStatus, UserConstants.DICT_NORMAL)
                .eq(TDictData::getDictType, dictType)
                .orderByAsc(TDictData::getDictSort).list();
    }

    @Override
    public PageInfo selectPageDictDataList(TDictData dictData, PageQuery pageQuery) {
        LambdaQueryWrapper lqw = new LambdaQueryWrapper()
                .eq(StringUtils.isNotBlank(dictData.getDictType()), TDictData::getDictType, dictData.getDictType())
                .like(StringUtils.isNotBlank(dictData.getDictLabel()), TDictData::getDictLabel, dictData.getDictLabel())
                .eq(StringUtils.isNotBlank(dictData.getStatus()), TDictData::getStatus, dictData.getStatus())
                .orderByAsc(TDictData::getDictSort);
        Page page = baseMapper.selectPage(pageQuery.build(), lqw);
        return PageInfo.build(page);
    }

    /**
     * 根据条件分页查询字典数据
     *
     * @param dictData 字典数据信息
     * @return 字典数据集合信息
     */
    @Override
    public List selectDictDataList(TDictData dictData) {
        return baseMapper.selectList(new LambdaQueryWrapper()
                .eq(StringUtils.isNotBlank(dictData.getDictType()), TDictData::getDictType, dictData.getDictType())
                .like(StringUtils.isNotBlank(dictData.getDictLabel()), TDictData::getDictLabel, dictData.getDictLabel())
                .eq(StringUtils.isNotBlank(dictData.getStatus()), TDictData::getStatus, dictData.getStatus())
                .orderByAsc(TDictData::getDictSort));
    }

    /**
     * 根据字典类型和字典键值查询字典数据信息
     *
     * @param dictType  字典类型
     * @param dictValue 字典键值
     * @return 字典标签
     */
    @Override
    public String selectDictLabel(String dictType, String dictValue) {
        return baseMapper.selectOne(new LambdaQueryWrapper()
                        .select(TDictData::getDictLabel)
                        .eq(TDictData::getDictType, dictType)
                        .eq(TDictData::getDictValue, dictValue))
                .getDictLabel();
    }

    /**
     * 根据字典数据ID查询信息
     *
     * @param dictCode 字典数据ID
     * @return 字典数据
     */
    @Override
    public TDictData selectDictDataById(Long dictCode) {
        return baseMapper.selectById(dictCode);
    }

    /**
     * 批量删除字典数据信息
     *
     * @param dictCodes 需要删除的字典数据ID
     */
    @Override
    public void deleteDictDataByIds(Long[] dictCodes) {
        for (Long dictCode : dictCodes) {
            TDictData data = selectDictDataById(dictCode);
            baseMapper.deleteById(dictCode);
            List dictDatas = baseMapper.selectDictDataByType(data.getDictType());
            DictUtils.setDictCache(data.getDictType(), dictDatas);
        }
    }

    /**
     * 新增保存字典数据信息
     *
     * @param data 字典数据信息
     * @return 结果
     */
    @Override
    public int insertDictData(TDictData data) {
        int row = baseMapper.insert(data);
        if (row > 0) {
            List dictDatas = baseMapper.selectDictDataByType(data.getDictType());
            DictUtils.setDictCache(data.getDictType(), dictDatas);
        }
        return row;
    }

    /**
     * 修改保存字典数据信息
     *
     * @param data 字典数据信息
     * @return 结果
     */
    @Override
    public int updateDictData(TDictData data) {
        int row = baseMapper.updateById(data);
        if (row > 0) {
            List dictDatas = baseMapper.selectDictDataByType(data.getDictType());
            DictUtils.setDictCache(data.getDictType(), dictDatas);
        }
        return row;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy