package com.api.browser.service.impl;

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

import weaver.general.Util;
import weaver.systeminfo.SystemEnv;

import com.api.browser.bean.SplitTableBean;
import com.api.browser.bean.SplitTableColBean;
import com.api.browser.service.BrowserService;
import com.api.browser.util.BoolAttr;
import com.api.browser.util.BrowserConstant;
import com.api.browser.util.ConditionFactory;
import com.api.browser.util.SplitTableUtil;
import com.api.browser.bean.SearchConditionItem;
import com.api.browser.util.ConditionType;

/**
 * 职务类别
 * 
 * @author lvyi
 * 
 */
public class JobActivitiesBrowserService extends BrowserService {

	@Override
	public Map<String, Object> getBrowserData(Map<String, Object> params) throws Exception {
		Map<String, Object> apidatas = new HashMap<String, Object>();
		String jobactivitymark = Util.null2String(params.get("jobactivitymark"));
		String jobactivityname = Util.null2String(params.get("jobactivityname"));
		String sqlwhere = "where 1 = 1 and a.jobgroupid = b.id ";
		String backfields = "";
		String fromSql = "";
		String orderby = "";
		if(!jobactivitymark.equals("")){
			sqlwhere += " and a.Jobactivitymark like '%";
			sqlwhere += Util.fromScreen2(jobactivitymark,user.getLanguage());
			sqlwhere += "%'";
		}
		if(!jobactivityname.equals("")){
			sqlwhere += " and a.jobactivityname like '%";
			sqlwhere += Util.fromScreen2(jobactivityname,user.getLanguage());
			sqlwhere += "%'";
		}

		List<SplitTableColBean> cols = new ArrayList<SplitTableColBean>();
		backfields = " a.id,a.jobactivitymark,a.jobactivityname,b.jobgroupname ";
		fromSql = " HrmJobActivities a , HrmJobGroups b ";
		orderby = " a.id ";

		cols.add(new SplitTableColBean("true", "id"));
		cols.add(new SplitTableColBean("25%", "子序列简称", "jobactivitymark", "jobactivitymark").setIsInputCol(BoolAttr.TRUE));
		cols.add(new SplitTableColBean("25%", "子序列全称", "jobactivityname", "jobactivityname"));
		cols.add(new SplitTableColBean("25%", "序列", "jobgroupname", "jobgroupname"));


		SplitTableBean tableBean = new SplitTableBean(backfields, fromSql, sqlwhere, orderby, "a.id", cols);
		
		tableBean.setSqlsortway("ASC");
		tableBean.setSqlisdistinct("true");
		apidatas.putAll(SplitTableUtil.makeListDataResult(tableBean));
		return apidatas;
	}

	@Override
	public Map<String, Object> getBrowserConditionInfo(Map<String, Object> params) throws Exception {
		Map<String, Object> apidatas = new HashMap<String, Object>();
		List<SearchConditionItem> conditions = new ArrayList<SearchConditionItem>();
		apidatas.put(BrowserConstant.BROWSER_RESULT_CONDITIONS, conditions);
		ConditionFactory conditionFactory = new ConditionFactory(user);
		conditions.add(conditionFactory.createCondition(ConditionType.INPUT, 399, "jobactivitymark", true));
		conditions.add(conditionFactory.createCondition(ConditionType.INPUT, 15767, "jobactivityname"));

		return apidatas;
	}

}
