package com.ekexiu.portal.service;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import org.jfw.apt.annotation.Autowrie;
import org.jfw.apt.annotation.Nullable;
import org.jfw.apt.web.annotation.Path;
import org.jfw.apt.web.annotation.operate.Get;
import org.jfw.apt.web.annotation.param.JdbcConn;
import org.jfw.apt.web.annotation.param.PathVar;

import com.ekexiu.portal.basepo.LogicDict;
import com.ekexiu.portal.dao.DataDictDao;

@Path("/dict")
public class DictService {
	@Autowrie
	private DataDictDao dataDictDao;
	
	private int limit=10;
	private int defaultLimit=10;
	
	private int genLimitRows(Integer rows){
		if(limit>0) return limit;
		return rows==null?defaultLimit:rows.intValue();
	}
	
	@Get
	@Path("/{dictCode}")
	public List<LogicDict> query(@JdbcConn Connection con,@PathVar String dictCode) throws SQLException{
		return dataDictDao.queryLogicDict(con, dictCode);
	}
	@Path("/lq")
	public List<LogicDict> query(@JdbcConn Connection con,String dictCode,@Nullable Integer rows) throws SQLException
	{
		return dataDictDao.limitQuery(con, dictCode, this.genLimitRows(rows));
	}

	public DataDictDao getDataDictDao() {
		return dataDictDao;
	}

	public void setDataDictDao(DataDictDao dataDictDao) {
		this.dataDictDao = dataDictDao;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public int getDefaultLimit() {
		return defaultLimit;
	}

	public void setDefaultLimit(int defaultLimit) {
		this.defaultLimit = defaultLimit;
	}
	
}
