package com.platform.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.platform.dao.IRegionalismCodeDao;
import com.platform.dao.ISystemCodeDao;
import com.platform.entities.RegionalismEntity;
import com.platform.entities.SystemEntity;
import com.platform.service.ICodeService;

/** 地区、系统code--名称-业务类
 * @author chen
 *
 */
@Service(value = "codeService")
public class CodeServiceImpl implements ICodeService {
	
	/**
	 * 日志
	 */
	public final static Logger log = Logger.getLogger(CodeServiceImpl.class);
	
	@Resource(name = "systemCodeDao")
	private ISystemCodeDao systemCodeDao;
	
	@Resource(name = "regionalismCodeDao")
	private IRegionalismCodeDao regionalismCodeDao;
	
	@Override
	public List<SystemEntity> findSystem(SystemEntity sys) throws Exception {
		List<SystemEntity> result = null;
		try {
			result = new ArrayList<SystemEntity>();
			result = systemCodeDao.findSubSystemByCode(sys);
		} catch (Exception e) {
			log.error(e);
		}
		return result;
	}

	@Override
	public List<RegionalismEntity> findRegionalism(RegionalismEntity region) throws Exception {
		List<RegionalismEntity> result = null;
		try {
			result = regionalismCodeDao.findSubRegionalism(region);
		} catch (Exception e) {
			log.error(e);
		}
		return result;
	}

	@Override
	public Map<String, Object> findAll() throws Exception {
		Map<String, Object> result = new HashMap<String, Object>();
		try {
			List<RegionalismEntity> regions = regionalismCodeDao.findAllRegionalism();
			List<SystemEntity> syss = systemCodeDao.findAllSystem();
			result.put("system", syss);
			result.put("regionalism", regions);
		} catch (Exception e) {
			log.error(e);
		}
		return result;
	}
	

}
