package org.cs.mgr.product.dao.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

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

import org.cs.core.dao.impl.BaseDao;
import org.cs.util.Pager;
import org.cs.util.StringUtil;
import org.cs.mgr.product.model.MgmProductCategory;
import org.cs.mgr.product.dao.IMgmProductCategoryDao;

/**
 * 
 * @ClassName: MgmProductCategoryDao
 * @Description:  
 * @author: sunny_shi
 * @date: 2018-06-09 13:29:09
 */
@Repository
public class MgmProductCategoryDao extends BaseDao<MgmProductCategory> implements IMgmProductCategoryDao {
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Override
	public Pager queryMgmProductCategorys(Pager page){
		String hql = "from MgmProductCategory where isDelete = false";
		return findPageByHql(hql, page, null);
	}
	
	@Override
	public List<MgmProductCategory> nextCategory(Integer id){
		Map<String, Object> params = new HashMap<>();
		params.put("id", id);
		params.put("isdelete", false);
		return (List<MgmProductCategory>) this.findByHql("from MgmProductCategory where gcParentId=:id and isDelete=:isdelete order by gcSort asc", params);
	}
	
	@Override
	public List<MgmProductCategory> firstCategory(){
		Map<String, Object> params = new HashMap<>();
		params.put("isdelete", false);
		return (List<MgmProductCategory>) this.findByHql("from MgmProductCategory where (gcParentId=0 or gcParentId= null) and isDelete=:isdelete", params);
	}
	
	@Override
	public List<MgmProductCategory> queryShowCategory(Map<String, String> map){
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("isdelete", false);
		
		StringBuffer sb = new StringBuffer("from MgmProductCategory where isDelete=:isdelete ");
		if(StringUtil.isNotBlank(map.get("id"))){
			sb.append(" and gcParentId=:gcid");
			params.put("gcid", Integer.valueOf(map.get("id")));
		}else{//��һ��Ŀ¼
			sb.append(" and type=:type and num=:num");
			params.put("type", "2");
			params.put("num", 1);
		}
		sb.append(" order by gcSort asc");
		return (List<MgmProductCategory>) this.findByHql(sb.toString(), params);
	}
}
