package com.goafanti.business.service.impl;

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

import org.springframework.stereotype.Service;

import com.goafanti.business.service.JtBusinessServiceWithCategoryMapper;
import com.goafanti.common.dao.JtBusinessCategoryMapper;
import com.goafanti.common.model.JtBusinessCategory;
import com.goafanti.common.utils.StringUtils;
import com.goafanti.core.mybatis.BaseMybatisDao;
import com.goafanti.core.mybatis.page.Pagination;

@Service
public class JtBusinessServiceWithCategoryMapperImpl   extends BaseMybatisDao<JtBusinessCategoryMapper> implements JtBusinessServiceWithCategoryMapper{
		@SuppressWarnings("unchecked")
		@Override
		public Pagination<JtBusinessCategory> getCategoryListByCondition(JtBusinessCategory jtBusinessCategory,Integer pageNo,Integer pageSize) {
			
			Map<String, Object>params=disposeCategoryParams(jtBusinessCategory.getName(), jtBusinessCategory.getLayer(),jtBusinessCategory.getModule());
			if(pageNo==null ||pageNo<1)pageNo=1;
			if(pageSize==null ||pageSize<1)pageSize=10;
			// TODO Auto-generated method stub
			return (Pagination<JtBusinessCategory>)findPage("getCategoryListByCondition", "getCategoryCountByCondition", params, pageNo, pageSize);
		}
		
		private Map<String, Object> disposeCategoryParams(String name,Integer layer ,Integer module) {
			Map<String, Object> params = new HashMap<>();

			if (layer!=null) {
				params.put("layer", layer);
			}

			if (module!=null) {
				params.put("module", module);
			}

		
			if (StringUtils.isNotBlank(name)) {
				params.put("name", name);
			}

			
			return params;
		}

}
