package com.engine.kq.cmd.schedulecode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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 weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;
 

public class GetScheduleDeviceFormCmd extends AbstractCommonCommand<Map<String, Object>>{
	
	public GetScheduleDeviceFormCmd(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>();
		RecordSet rs = new RecordSet();
		String sql = "";
		try {
			if (!HrmUserVarify.checkUserRight("ScheduleCode:Edit", user)) {
				retmap.put("status", "-1");
				retmap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage()));
				return retmap;
			}
			List<Map<String, Object>> groupList = new ArrayList<Map<String, Object>>();
			Map<String, Object> groupItem = new HashMap<String, Object>();
			List<Object> itemList = new ArrayList<Object>();
			HrmFieldSearchConditionComInfo hrmFieldSearchConditionComInfo = new HrmFieldSearchConditionComInfo();
			SearchConditionItem searchConditionItem = null;

			String id = Util.null2String(params.get("id"));
			String devicename = "";
			String devicecode = "";
			String ip = "";
			String subcompanyids = "";

			sql = "  select * from kq_schedule_device where id = ? ";
			rs.executeQuery(sql,id);
			if(rs.next()){
				devicename = Util.null2String(rs.getString("devicename"));
				devicecode = Util.null2String(rs.getString("devicecode"));
				ip = Util.null2String(rs.getString("ip"));
				subcompanyids = Util.null2String(rs.getString("subcompanyids"));
			}

			HrmFieldBean hrmFieldBean = null;
			hrmFieldBean = new HrmFieldBean();
			hrmFieldBean.setFieldname("id");
			hrmFieldBean.setFieldlabel("512449");
			hrmFieldBean.setFieldhtmltype("1");
			hrmFieldBean.setType("1");
			hrmFieldBean.setFieldvalue(id);
			Map<String, Object> otherParams = new HashMap<String, Object>();
			otherParams.put("hide", true);
			hrmFieldBean.setOtherparam(otherParams);
			searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
			itemList.add(searchConditionItem);

			hrmFieldBean = new HrmFieldBean();
			hrmFieldBean.setFieldname("devicename");
			hrmFieldBean.setFieldlabel("512449");
			hrmFieldBean.setFieldhtmltype("1");
			hrmFieldBean.setType("1");
			hrmFieldBean.setFieldvalue(devicename);
			hrmFieldBean.setViewAttr(3);
			hrmFieldBean.setRules("required|string");
			searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
			itemList.add(searchConditionItem);

			hrmFieldBean = new HrmFieldBean();
			hrmFieldBean.setFieldname("devicecode");
			hrmFieldBean.setFieldlabel("512448");
			hrmFieldBean.setFieldhtmltype("1");
			hrmFieldBean.setType("1");
			hrmFieldBean.setFieldvalue(devicecode);
			hrmFieldBean.setViewAttr(3);
			hrmFieldBean.setRules("required|string");
			searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
			itemList.add(searchConditionItem);

			hrmFieldBean = new HrmFieldBean();
			hrmFieldBean.setFieldname("ip");
			hrmFieldBean.setFieldlabel("32531");
			hrmFieldBean.setFieldhtmltype("1");
			hrmFieldBean.setType("1");
			hrmFieldBean.setFieldvalue(ip);
			hrmFieldBean.setViewAttr(2);
			searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
			itemList.add(searchConditionItem);

			hrmFieldBean = new HrmFieldBean();
			hrmFieldBean.setFieldname("subcompanyids");
			hrmFieldBean.setFieldlabel("506413");
			hrmFieldBean.setFieldhtmltype("3");
			hrmFieldBean.setType("194");
			hrmFieldBean.setFieldvalue(subcompanyids);
			hrmFieldBean.setViewAttr(2);
			searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
			itemList.add(searchConditionItem);

			groupItem.put("items", itemList);
			groupList.add(groupItem);
			retmap.put("condition", groupList);
			retmap.put("status", "1");
		} catch (Exception e) {
			retmap.put("status", "-1");
			retmap.put("message",  SystemEnv.getHtmlLabelName(382661,user.getLanguage()));
			writeLog(e);
		}
		return retmap;
	}
	
	
	@Override
	public BizLogContext getLogContext() {
		// TODO Auto-generated method stub
		return null;
	}
	
	
}
