com.greenline.guahao.biz.manager.hrs.impl.DictManagerImpl.java Source code

Java tutorial

Introduction

Here is the source code for com.greenline.guahao.biz.manager.hrs.impl.DictManagerImpl.java

Source

/*
 * Project: guahao-portal-biz-core
 * 
 * File Created at 2012-5-23
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */
package com.greenline.guahao.biz.manager.hrs.impl;

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

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;

import com.greenline.guahao.biz.manager.hrs.DictManager;
import com.greenline.guahao.biz.manager.hrs.dataobject.DictDO;
import com.greenline.hrs.biz.service.DictService;
import com.greenline.hrs.biz.service.dto.dict.DictDTO;

/**
 * @Type DictManagerImpl
 * @Desc ?
 * @author weirui.shenwr
 * @date 2012-5-23
 * @Version V1.0
 */
public class DictManagerImpl implements DictManager {

    @Resource
    private DictService dictService;

    /**
     * ?
     * 
     * @param dictId
     * @return List<DictDO>
     */
    @Override
    public List<DictDO> listDicts(String dictId) {
        if (StringUtils.isEmpty(dictId)) {
            return null;
        }
        return covert2DOList(dictService.listDicts(dictId));
    }

    /**
     * ?IDkey?
     * 
     * @param dictId
     * @param value
     * @return String
     */
    @Override
    public String getDictName(String dictId, String key) {
        List<DictDO> dictlist = listDicts(dictId);
        return getValue(dictlist, key);
    }

    /**
     * ?
     * 
     * @param dtoList
     * @return List<DictDO>
     */
    private List<DictDO> covert2DOList(List<DictDTO> dtoList) {
        if (dtoList != null) {
            List<DictDO> dtolist = new ArrayList<DictDO>();
            for (DictDTO vo : dtoList) {
                dtolist.add(covert2DO(vo));
            }
            return dtolist;
        } else {
            return null;
        }
    }

    /**
     * DTO?
     * 
     * @param dto
     * @return DictDO
     */
    private DictDO covert2DO(DictDTO dto) {
        DictDO retDo = new DictDO();
        retDo.setValue(dto.getValue());
        retDo.setName(dto.getName());
        return retDo;
    }

    /**
     * ?value
     * 
     * @param dictlist
     * @param key
     * @return String
     */
    private String getValue(List<DictDO> dictlist, String key) {
        for (DictDO ddo : dictlist) {
            if (ddo.getValue().equals(key))
                return ddo.getName();
        }
        return null;
    }
}