package com.engine.kq.cmd.shiftschedule;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.api.hrm.bean.WeaRadioGroup;
import com.api.hrm.util.HrmAdvancedSearchUtil;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.hrm.settings.ChgPasswdReminder;
import weaver.hrm.settings.RemindSettings;
import weaver.systeminfo.SystemEnv;

/**
 * 获取排班查询条件
 * @author pzy
 *
 */
public class GetSearchConditionCmd extends AbstractCommonCommand<Map<String, Object>>{
	
	public GetSearchConditionCmd(Map<String, Object> params, User user) {
		this.user = user;
		this.params = params;
	}

	@Override
	public Map<String, Object> execute(CommandContext commandContext) {Map<String,Object> retmap = new HashMap<String,Object>();
		List<Object> lsCondition = new ArrayList<Object>();
		String[] options = null;
		String[] selectLinkageDatas = null;
		try{
			HrmAdvancedSearchUtil hrmAdvancedSearchUtil = new HrmAdvancedSearchUtil();

			boolean hasViewAllRight=false;
			if(HrmUserVarify.checkUserRight("HrmKQGroup:Add", user)){
				hasViewAllRight=true;
			}
			String _level = "";
			if(hasViewAllRight){
				_level = Util.null2String(HrmUserVarify.getRightLevel("HrmKQGroup:Add", user));
			}

			//查看范围、数据范围
			options = new String[]{"0,140,true","1,141,false","2,124,false","3,1867,false"};
			selectLinkageDatas = new String[]{"1,subCompanyId,141,3,194","2,departmentId,124,3,57","3,resourceId,1867,3,17"};
			WeaRadioGroup wrg = hrmAdvancedSearchUtil.getAdvanceCondition("viewscope","34102",options,selectLinkageDatas,user);
			wrg.setLabelcol(3);
			wrg.setFieldcol(20);
			lsCondition.add(wrg);

      WeaRadioGroup wrg1 = new WeaRadioGroup();

      ChgPasswdReminder reminder = new ChgPasswdReminder();
      RemindSettings settings = reminder.getRemindSettings();
      String checkUnJob = Util.null2String(settings.getCheckUnJob(), "0");
      List<String> statusList = Lists.newArrayList();
      if ("1".equals(checkUnJob)) {//启用后，只有有“离职人员查看”权限的用户才能检索非在职人员
        if (HrmUserVarify.checkUserRight("hrm:departureView", user)) {
          statusList.add("9,332,false");
        }
      } else {
        statusList.add("9,332,false");
      }
      statusList.add("0,15710,false");
      statusList.add("1,15711,false");
      statusList.add("2,480,false");
      statusList.add("3,15844,false");
      if ("1".equals(checkUnJob)) {//启用后，只有有“离职人员查看”权限的用户才能检索非在职人员
        if (HrmUserVarify.checkUserRight("hrm:departureView", user)) {
          statusList.add("4,6094,false");
          statusList.add("5,6091,false");
          statusList.add("6,6092,false");
          statusList.add("7,2245,false");
        }
      } else {
        statusList.add("4,6094,false");
        statusList.add("5,6091,false");
        statusList.add("6,6092,false");
        statusList.add("7,2245,false");
      }
      statusList.add("8,1831,true");
      options = new String[statusList.size()];
      for(int i = 0 ; i < statusList.size() ; i++){
        String statusStr = statusList.get(i);
        options[i] = statusStr;
      }

      wrg1 = hrmAdvancedSearchUtil.getAdvanceCondition("status","602",options,null,user);
      wrg1.setLabelcol(3);
      wrg1.setFieldcol(20);
      lsCondition.add(wrg1);

			retmap.put("status", "1");
			retmap.put("conditions", lsCondition);
		}catch (Exception e) {
			writeLog(e);
			retmap.put("status", "-1");
			retmap.put("message", ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10004510,weaver.general.ThreadVarLanguage.getLang())+"");
		}
		return retmap;
	}

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

}
