DictDataServiceImpl.java 4.81 KB
package com.huaheng.pc.system.dict.service;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.huaheng.common.support.Convert;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.pc.system.dict.domain.DictData;
import com.huaheng.pc.system.dict.mapper.DictDataMapper;

import java.util.ArrayList;
import java.util.List;

/**
 * 字典 业务层处理
 * 
 * @author huaheng
 */
@Service
public class DictDataServiceImpl implements IDictDataService
{

    @Autowired
    private DictDataMapper dictDataMapper;
    /**
     * 根据条件分页查询字典数据
     * 
     * @param dictData 字典数据信息
     * @return 字典数据集合信息
     */
    @Override
    public List<DictData> selectDictDataList(DictData dictData)
    {
        if (dictData.getWarehouseCode() == null) {
            dictData.setWarehouseCode(ShiroUtils.getWarehouseCode());
        }
        return dictDataMapper.selectDictDataList(dictData);
    }

    /**
     * 根据字典类型查询字典数据
     * 
     * @param dictType 字典类型
     * @return 字典数据集合信息
     */
    @Override
    public List<DictData> selectDictDataByType(String dictType)
    {
        return dictDataMapper.selectDictDataByType(ShiroUtils.getWarehouseCode(), dictType);
    }

    /**
     * 根据字典类型和字典键值查询字典数据信息
     * 
     * @param dictType 字典类型
     * @param dictValue 字典键值
     * @return 字典标签
     */
    @Override
    public String selectDictLabel(String dictType, String dictValue)
    {
        return dictDataMapper.selectDictLabel(ShiroUtils.getWarehouseCode(), dictType, dictValue);
    }

    /**
     * 根据字典数据ID查询信息
     * 
     * @param id 字典数据ID
     * @return 字典数据
     */
    @Override
    public DictData selectDictDataById(Integer id)
    {
        return dictDataMapper.selectDictDataById(ShiroUtils.getWarehouseCode(), id);
    }

    /**
     * 通过字典ID删除字典数据信息
     * 
     * @param id 字典数据ID
     * @return 结果
     */
    @Override
    public int deleteDictDataById(Integer id)
    {
        return dictDataMapper.deleteDictDataById(ShiroUtils.getWarehouseCode(), id);
    }

    /**
     * 批量删除字典数据
     * 
     * @param ids 需要删除的数据
     * @return 结果
     */
    @Override
    public int deleteDictDataByIds(String ids)
    {
        return dictDataMapper.deleteDictDataByIds(ShiroUtils.getWarehouseCode(), Convert.toStrArray(ids));
    }

    /**
     * 新增保存字典数据信息
     * 
     * @param dictData 字典数据信息
     * @return 结果
     */
    @Override
    public int insertDictData(DictData dictData)
    {
        if (dictData.getWarehouseCode() == null) {
            dictData.setWarehouseCode(ShiroUtils.getWarehouseCode());
        }
        dictData.setCreateBy(ShiroUtils.getLoginName());
        return dictDataMapper.insertDictData(dictData);
    }

    /**
     * 修改保存字典数据信息
     * 
     * @param dictData 字典数据信息
     * @return 结果
     */
    @Override
    public int updateDictData(DictData dictData)
    {
        dictData.setWarehouseCode(ShiroUtils.getWarehouseCode());
        dictData.setUpdateBy(ShiroUtils.getLoginName());
        return dictDataMapper.updateDictData(dictData);
    }

    /**
     * 验证指定仓库id的code是否存在
     * @param dictValue
     * @param type
     * @return
     */
    @Override
    public Boolean checkConfig(String type, String dictValue){
        DictData dictData = new DictData();
        dictData.setWarehouseCode(ShiroUtils.getWarehouseCode());
        dictData.setDictType(type);
        dictData.setDictValue(dictValue);
        Integer id = dictDataMapper.checkConfig(dictData);
        if (id == null) {
            return false;
        } else {
            return  true;
        }
    }


     /**
     * 根据warehouseId删除DictData
    * @param warehouseCode
    * @return
    */
    @Override
    public int deleteDictDataByWarehouseCode(String warehouseCode){
        return dictDataMapper.deleteDictDataByWarehouseCode(warehouseCode);
    }

    @Override
    public int insertDictDatas(List<DictData> dictDatas)
    {
        List<DictData> dictDataList=new ArrayList<>();
        for(DictData dictData: dictDatas) {
            if (dictData.getWarehouseCode() == null) {
                dictData.setWarehouseCode(ShiroUtils.getWarehouseCode());
            }
            dictData.setCreateBy(ShiroUtils.getLoginName());
            dictDataList.add(dictData);
        }
        return dictDataMapper.insertDictDatas(dictDataList);
    }

    @Override
    public DictData selectModel(DictData dictData) {
        return dictDataMapper.selectModel(dictData);
    }
}