package com.yeejoin.amos.maintenance.business.util;

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

import org.springframework.util.ObjectUtils;

import com.yeejoin.amos.maintenance.business.param.RoutePageParam;
import com.yeejoin.amos.maintenance.core.common.request.CommonPageable;
import com.yeejoin.amos.maintenance.core.common.request.CommonRequest;

public class RoutePageParamUtil {

	public static RoutePageParam fillRouteInfoParam(List<CommonRequest> queryRequests, CommonPageable commonPageable,
			HashMap<String, Object> orgCodeMap) {
		RoutePageParam param = new RoutePageParam();
		for (CommonRequest queryRequest : queryRequests) {
			String name = queryRequest.getName();
			if ("name".equals(name)) {
				param.setName(toString(queryRequest.getValue()));
			} else if ("remark".equals(name)) {
				param.setRemark(toString(queryRequest.getValue()));
			} else if ("ownerId".equals(name)) {
				if (!ObjectUtils.isEmpty(queryRequest.getValue())) {
					param.setOwnerId(toString(queryRequest.getValue()));
				}
			}
		}

		param.setOrgCode(orgCodeMap.get("orgCode") == null ? null:orgCodeMap.get("orgCode").toString());
		if (param.getDeptId() == null) {
			param.setDeptId(orgCodeMap.get("deptId") == null ? null:Long.valueOf(orgCodeMap.get("deptId").toString()));

		}
		if (commonPageable != null) {
			param.setPageNumber(commonPageable.getPageNumber());
			param.setPageSize(commonPageable.getPageSize());
		}
		return param;
	}

	private static String toString(Object value) {
		if (null == value || value == "") {
			return null;
		} else {
			return value.toString();
		}
	}
	
	public static HashMap<String, Object> fillRouteInfo(List<CommonRequest> queryRequests, HashMap<String, Object> param) {
//		HashMap<String, Object> param = new HashMap<String, Object>();
		if (ObjectUtils.isEmpty(queryRequests)) {
			return param;
		}
		for (CommonRequest request : queryRequests) {
			if (!ObjectUtils.isEmpty(request) && !ObjectUtils.isEmpty(request.getName())) {
				param.put(request.getName(), request.getValue());
			}
		}
		return param;
	}
}
