package com.wsm.admin.service.impl;

import java.util.Date;
import java.util.List;

import com.wsm.admin.dao.IDataDictionaryDao;
import com.wsm.admin.model.DataDictionary;
import com.wsm.admin.service.IDataDictionaryService;
import com.wsm.common.dao.IBaseDao;
import com.wsm.common.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  数据字典 服务实现类
 * </p>
 *
 * @author SPPan
 * @since 2016-12-28
 */
@Service
public class DataDictionaryServiceImpl extends BaseServiceImpl<DataDictionary, Long> implements IDataDictionaryService {

    @Autowired
    private IDataDictionaryDao dataDictionaryDao;

    @Override
    public IBaseDao<DataDictionary, Long> getBaseDao() {
        return this.dataDictionaryDao;
    }
    
    @Override
    public void saveOrUpdate(DataDictionary dataDictionary) {
        if (dataDictionary.getId() != null) {
        	DataDictionary dbDictionary = find(dataDictionary.getId());
        	dbDictionary.setDataKey(dataDictionary.getDataKey());
        	dbDictionary.setDataValue(dataDictionary.getDataValue());
        	dbDictionary.setCode(dataDictionary.getCode());
        	dbDictionary.setDescription(dataDictionary.getDescription());
        	dbDictionary.setParam1(dataDictionary.getParam1());
        	dbDictionary.setParam2(dataDictionary.getParam2());
        	dbDictionary.setParam3(dataDictionary.getParam3());
            update(dbDictionary);
        } else {
            save(dataDictionary);
        }
    }

	@Override
	public DataDictionary findByCodeAndDataKey(String code, String dataKey) {
		return dataDictionaryDao.findByCodeAndDataKey(code, dataKey);
	}
	
	@Override
	public List<DataDictionary> findByCode(String code){
		return dataDictionaryDao.findByCode(code);
	}
}
