package integration.anyframe.services.corebasis;

import java.util.List;

import org.springframework.stereotype.Repository;

import anyframe.common.Page;
import anyframe.common.util.SearchVO;
import anyframe.common.util.StringUtil;
import anyframe.core.basis.dao.hibernate.GenericDaoHibernate;

@Repository("usersDao")
public class UsersDaoHibernateImpl extends GenericDaoHibernate<Users, String> implements UsersDao {

    public UsersDaoHibernateImpl() {
        super(Users.class);
    }
    
	  public Page getList(SearchVO searchVO) throws Exception {
        int pageIndex = searchVO.getPageIndex();
        int pageSize = this.getPropertiesService().getInt("PAGE_SIZE");
        int pageUnit = this.getPropertiesService().getInt("PAGE_UNIT");

        String searchCondition = StringUtil.null2str(searchVO.getSearchCondition());
        String searchKeyword = StringUtil.null2str(searchVO.getSearchKeyword());
        String isNumeric = StringUtil.isNumeric(searchKeyword) ? "true" : "false";
        
        Object[] args = new Object[4];		            
        args[0] = "condition=" + searchCondition;
        args[1] = "keywordStr=%" + searchKeyword + "%";
        args[2] = "keywordNum=" + searchKeyword + "";
        args[3] = "isNumeric=" + isNumeric;

        List resultList = this.getDynamicHibernateService().findList("findUsersList", args, pageIndex, pageSize);
        Long totalSize = (Long) this.getDynamicHibernateService().find("countUsersList", args);

        Page resultPage = new Page(resultList, pageIndex, totalSize.intValue(), pageUnit, pageSize);
        return resultPage;
	  }        
}

