package com.engine.kq.cmd.hrmAttProcSet;

import com.api.browser.bean.SearchConditionItem;
import com.api.hrm.bean.HrmFieldBean;
import com.api.hrm.util.HrmFieldSearchConditionComInfo;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;

/**
 * 获取自定义考勤流程 查询条件
 * @author pzy
 *
 */
public class GetCustomKQFlowSearchConditionCmd extends AbstractCommonCommand<Map<String, Object>>{

	public GetCustomKQFlowSearchConditionCmd(Map<String, Object> params, User user) {
		this.user = user;
		this.params = params;
	}

	@Override
	public BizLogContext getLogContext() {
		return null;
	}


	@Override
	public Map<String, Object> execute(CommandContext commandContext) {
    Map<String,Object> retmap = new HashMap<String,Object>();
    List<Map<String,Object>> grouplist = new ArrayList<Map<String,Object>>();
    Map<String,Object> groupitem = null;
    List<Object> itemlist = null;
    try{

      //名称 报表显示名称
      String[] fields = new String[]{"name,34067,1,1","reportname,515882,1,1"};

      HrmFieldSearchConditionComInfo hrmFieldSearchConditionComInfo = new HrmFieldSearchConditionComInfo();
      SearchConditionItem searchConditionItem = null;
      HrmFieldBean hrmFieldBean = null;
      itemlist = new ArrayList<Object>();
      groupitem = new HashMap<String,Object>();
      groupitem.put("title", SystemEnv.getHtmlLabelName(20331, user.getLanguage()));
      groupitem.put("defaultshow", true);
      for(int i=0;i<fields.length;i++){
        String[] fieldinfo = fields[i].split(",");
        hrmFieldBean = new HrmFieldBean();
        hrmFieldBean.setFieldname(fieldinfo[0]);
        hrmFieldBean.setFieldlabel(fieldinfo[1]);
        hrmFieldBean.setFieldhtmltype(fieldinfo[2]);
        hrmFieldBean.setType(fieldinfo[3]);

        searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
        if(searchConditionItem.getBrowserConditionParam()!=null){
          searchConditionItem.getBrowserConditionParam().setViewAttr(2);
        }
        searchConditionItem.setViewAttr(2);
        itemlist.add(searchConditionItem);
      }
      groupitem.put("items", itemlist);
      grouplist.add(groupitem);
      retmap.put("status", "1");
      retmap.put("conditions", grouplist);
    }catch (Exception e) {
      retmap.put("status", "-1");
      retmap.put("message",  SystemEnv.getHtmlLabelName(382661,user.getLanguage()));
      writeLog(e);
    }
    return retmap;
  }
	
}
