package com.dev.swms.client.ui.data;

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

import com.dev.swms.client.ui.constant.CT_IV;
import com.dev.swms.client.ui.javabean.JB_IV;
import com.dev.swms.client.ui.javabean.JB_Location_IV;
import com.dev.swms.client.ui.javabean.JB_Location_IV_List;
import com.dev.swms.client.ui.javabean.JB_Location_Inventory;
import com.dev.swms.client.ui.javabean.JB_Location_RC_IV_List;
import com.dev.swms.client.ui.javabean.JB_Zone_IV;
import com.dev.energy.client.data.DataAccessor;
import com.dev.energy.client.message.IMessagePage;

/**
 *@author  dev
 *@version $Project:swms $Date$Version:V1.1
 */
public class Page_IV_DataAccessor extends DataAccessor{
	
	/** 消息句柄--初始化库存可视化 */
	public static final String MSG_INIT_IV_DATA = "msg_initIVDatas";
	public static final String MSG_INIT_ZONE_DATAS = "init_zone_datas";
	public static final String MSG_INIT_LOCATION_DATAS = "msg_init_location_datas";
	public static final String MSG_INIT_LOCATION_RC_DATAS = "msg_init_location_rc_datas";
	public static final String MSG_INIT_INVENTORY_DATAS = "msg_init_inventory_datas";
	public static final String MSG_CLOSE_ALL_COLUMN_CHART = "msg_close_charts";
	public static final String MSG_REFRESH_NAVIGATE_PANEL = "msg_refresh_navigate";
	public static final String MSG_OPEN_W_IMAGE_PANEL = "msg_open_w_panel";
	public static final String MSG_OPEN_Z_IMAGE_PANEL = "msg_open_z_panel";
	public static final String MSG_OPEN_L_IMAGE_PANEL = "msg_open_l_panel";
	
	public static final String MSG_UPDATE_IV_DATA = "msg_updateIVData";
	public static final String MSG_UPDATE_ZIV_DATA = "msg_updateZIVData";
	
	/** 所有仓库的容积率 */
	private List<JB_IV> ivs;
	/** 所有库区的容积率 */
	private List<JB_Zone_IV> zivs;
	/** 所有库位道排的容积率 */
	private List<JB_Location_IV_List> livs;
	/** 所有库位层列的容积率 */
	private List<JB_Location_RC_IV_List> lrivs;
	/** 所有库存 */
	private List<JB_Location_Inventory> lis;
	/** 当前选中的仓库 */
	private JB_IV cur_JB_IV;
	/** 当前选中的库区 */
	private JB_Zone_IV cur_JB_Zone_IV;
	
	public Page_IV_DataAccessor(IMessagePage page) {
		super(page);
	}
	/** 远程调用后台方法获取库存可视化数据 */
	public void initIVDatas(){
		this.remoteCall(MSG_INIT_IV_DATA , CT_IV.IV_MANAGER , CT_IV.IV_INIT_DATA , new HashMap());
	}
	//远程调用后台方法改变库存可视化数据中的坐标值
	public void updateIVData(){
		this.remoteCall(MSG_UPDATE_IV_DATA,CT_IV.IV_MANAGER,CT_IV.IV_UPDATE_DATA,construct_WarehousePos_Param());
	}
	public void updateZIVData(){
		this.remoteCall(MSG_UPDATE_ZIV_DATA,CT_IV.IV_MANAGER,CT_IV.ZIV_UPDATE_DATA,construct_ZonePos_Param());
	}
	/** 异步获取后台的库区容积率 */
	public void initZoneIvDatas() {
		this.remoteCall(MSG_INIT_ZONE_DATAS,CT_IV.IV_MANAGER , CT_IV.IV_INIT_ZONE_DATA ,construct_Zone_Param());
	}
	/** 异步获取后台的库位道排容积率 */
	public void initLocationIvDatas() {
		this.remoteCall(MSG_INIT_LOCATION_DATAS,CT_IV.IV_MANAGER , CT_IV.IV_INIT_LOCATION_DATA ,construct_Location_Param());
	}
	/** 异步获取后台的库位层列容积率 */
	public void initLocationIvRCDatas(Map params) {
		this.remoteCall(MSG_INIT_LOCATION_RC_DATAS,CT_IV.IV_MANAGER , CT_IV.IV_INIT_LOCATION_RC_DATA ,params);
	}
	/** 异步获取后台的库存信息 */
	public void initInventoryDatas(Map params) {
		this.remoteCall(MSG_INIT_INVENTORY_DATAS,CT_IV.IV_MANAGER , CT_IV.IV_INIT_INVENTORY_DATA ,params);
	}
	
	/** 设置当前正在操作的仓库容积对象 */
	public void setCur_JB_IV(JB_IV cur_JB_IV) {
		this.cur_JB_IV = cur_JB_IV;
	}
	public void setCur_JB_IV_POS(int cur_JB_IV_XPOS,int cur_JB_IV_YPOS){
		this.cur_JB_IV.setX_Pos(cur_JB_IV_XPOS);
		this.cur_JB_IV.setY_Pos(cur_JB_IV_YPOS);
	}
	
	public void setCur_JB_Zone_IV(JB_Zone_IV ziv) {
		this.cur_JB_Zone_IV = ziv;
	}
	public void setCur_JB_Zone_IV_POS(int cur_JB_Zone_IV_XPOS,int cur_JB_Zone_IV_YPOS){
		this.cur_JB_Zone_IV.setLoc_xPos(cur_JB_Zone_IV_XPOS);
		this.cur_JB_Zone_IV.setLoc_yPos(cur_JB_Zone_IV_YPOS);
	}
	
	public JB_Zone_IV getCur_JB_Zone_IV(){
		return this.cur_JB_Zone_IV;
	}
	
	public JB_IV current_JB_IV(){
		return this.cur_JB_IV;
	}
	
	public List<JB_IV> all_IV() {
		return this.ivs;
	}
	
	public List<JB_Zone_IV> all_Zone_IV() {
		return this.zivs;
	}
	
	public List<JB_Location_IV_List> all_Location_IV(){
		return this.livs;
	}
	
	public List<JB_Location_RC_IV_List> all_Location_RC_IV(){
		return this.lrivs;
	}
	
	public List<JB_Location_Inventory> all_Location_Inv(){
		return this.lis;
	}
	
	public JB_Location_IV getCur_JB_Location_IV(int row ,int col) {
		return this.livs.get(row).get(col);
	}
	
	//param of the current warehousePos param
	public Map construct_WarehousePos_Param(){
		Map<String,Long> param = new HashMap<String,Long>();
		param.put(CT_IV.IV_WH_ID , this.cur_JB_IV.getIv_wh_id());
		
		Integer itx = new Integer(this.cur_JB_IV.getX_Pos());
		Long lox = new Long(itx.longValue());
		
		Integer ity = new Integer(this.cur_JB_IV.getY_Pos());
		Long loy = new Long(ity.longValue());
		
		param.put(CT_IV.IV_WH_XPOS,lox);
		param.put(CT_IV.IV_WH_YPOS,loy);
	    return param;
		
	}
   //param of zone pos 
	public Map construct_ZonePos_Param(){
		Map<String,Long> param = new HashMap<String,Long>();
		param.put(CT_IV.IV_ZONE_ID , this.cur_JB_Zone_IV.getLoc_id());
		
		Integer itx = new Integer(this.cur_JB_Zone_IV.getLoc_xPos());
		Long lox = new Long(itx.longValue());
		
		Integer ity = new Integer(this.cur_JB_Zone_IV.getLoc_yPos());
		Long loy = new Long(ity.longValue());
		
		param.put(CT_IV.IV_ZONE_XPOS,lox);
		param.put(CT_IV.IV_ZONE_YPOS,loy);
	    return param;
		
	}
	
	public Map construct_Zone_Param() {
		Map<String,Long> param = new HashMap<String,Long>();
		param.put(CT_IV.IV_WH_ID , this.cur_JB_IV.getIv_wh_id());
		return param;
	}
	
	private Map construct_Location_Param(){
		Map<String,Long> params = new HashMap<String,Long>();
		params.put(CT_IV.IV_ZONE_ID , this.getCur_JB_Zone_IV().getLoc_id());
		return params;
	}

	@SuppressWarnings("unchecked")
	public void onSuccess(String message, Map result) {
		if(MSG_INIT_IV_DATA.equals(message)) {
			this.ivs = (List) result.get(CT_IV.IV_RESULT);
			this.sendMessage(MSG_INIT_IV_DATA);
		}else if(MSG_INIT_ZONE_DATAS.equals(message)) {
			this.zivs = (List)result.get(CT_IV.IV_RESULT);
			this.sendMessage(MSG_INIT_ZONE_DATAS);
		}else if(MSG_INIT_LOCATION_DATAS.equals(message)) {
			this.livs = (List)result.get(CT_IV.IV_RESULT);
			this.sendMessage(MSG_INIT_LOCATION_DATAS);
		}else if(MSG_INIT_LOCATION_RC_DATAS.equals(message)) {
			this.lrivs = (List)result.get(CT_IV.IV_RESULT);
			this.sendMessage(MSG_INIT_LOCATION_RC_DATAS);
		}else if(MSG_INIT_INVENTORY_DATAS.equals(message)) {
			this.lis = (List)result.get(CT_IV.IV_RESULT);
			this.sendMessage(MSG_INIT_INVENTORY_DATAS);
		}else if(MSG_UPDATE_IV_DATA.equals(message)){
			this.sendMessage(MSG_UPDATE_IV_DATA);
			System.out.println("Success!!!");
		}else if(MSG_UPDATE_ZIV_DATA.equals(message)){
			this.sendMessage(MSG_UPDATE_ZIV_DATA);
			System.out.println("SuccessAgain!!!");
		}
	
	}

	public void onFailure(String message, Map result) {
		
	}

	public boolean onTimeOutFailure(String message) {
		return false;
	}

}
