/***文档注释***********************************************
 * 作者               :                   龙文航
 * 创建日期      :                   2017.11.23
 * 描述               :                   仓库管理-原料库在制品库成品库管理-倒垛管理
 * 注意事项      :                   无
 * 遗留BUG :                   无
 * 修改日期      :                   
 * 修改人员      :                   
 * 修改内容      :                   
***********************************************************/
package market.Lms.Warehouse.impl;

import java.util.List;

import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Lms.Warehouse.mapper.YdmBaseButtressconfigMapper;
import market.Lms.Warehouse.mapper.YdmProductButtresslistMapper;
import market.Lms.Warehouse.service.YdmProductButtresslistService;
import market.Lms.Warehouse.vo.YdmBaseButtressconfig;
import market.Lms.Warehouse.vo.YdmProductButtresslist;

import com.hnshituo.basic.service.impl.BaseServiceImpl;
import com.hnshituo.basic.spring.remoting.annotation.RemoteService;

@RemoteService(path="YdmProductButtresslistService")
public class YdmProductButtresslistServiceImpl extends BaseServiceImpl<YdmProductButtresslist,Object> implements YdmProductButtresslistService {

	/**
	 * 倒垛管理 
	 * 判断对应传入的垛位，区域，位置的数据是否存在
	 * */
	public ResultModel IsExist(CommonPage<YdmProductButtresslist> cp)
	{
		ResultModel rm= new ResultModel();
		try
		{
			List<YdmProductButtresslist> yp=cp.getObjectList();
			//int i=1;
			String msg="";
			Boolean exist=false;
			//ydm_base_buttressconfig
			for (YdmProductButtresslist ys : yp) {
				YdmBaseButtressconfig ybb =new YdmBaseButtressconfig(); 
				ybb.setButtressno(ys.getButtressno());
				YdmBaseButtressconfig ybb1=this.getMapper(YdmBaseButtressconfigMapper.class).findById(ybb.getButtressno());
				if (ys.getLocality()>ybb1.getColwidth()) {
					msg="选中行位置超出最大位置";
					exist=true;
				}
			}
//			for (int j = 0; j < yp.size(); j++) {
//				for (int j2 = 0; j2 < yp.size(); j2++) {
//					if(j!=j2)
//					{
//					if (yp.get(j).getAreano().equals(yp.get(j2).getAreano())) {
//						if (yp.get(j).getButtressno().equals(yp.get(j2).getButtressno())) {
//							if (yp.get(j).getLocality()==yp.get(j2).getLocality()) {
//								msg="选取行的数据位置重复!";
//								exist=true;
//							}
//						}
//					}
//					}
//				}
//			}
//			for(YdmProductButtresslist ypb:yp)
//			{
//				YdmProductButtresslist ydm =new YdmProductButtresslist();
//				ydm.setStorageattr(ypb.getStorageattr());
//				ydm.setButtressno(ypb.getButtressno());
//				ydm.setLocality(ypb.getLocality());
//				ydm.setAreano(ypb.getAreano());
//				List<YdmProductButtresslist> lt1=this.getMapper(YdmProductButtresslistMapper.class).find(ydm, 0, 0);
//				if(lt1!=null&&lt1.size()>0)
//				{
//					exist=true;
//					msg="选取行的数据位置已被占用!";
//				}
//				i++;
//			}
			if(exist)
			{
				rm.setMsgInfo(msg);
				rm.setState("500");
			}
			else 
				rm.setState("200");
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("服务端异常，判断失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 倒垛管理  根据卷号/箱号删除
	 * 本表无主键，无法直接使用对象delete方法
	 * */
	public ResultModel doDelete(String coilno,String boxno){
		ResultModel rm=new ResultModel();
		try{
			this.getMapper(YdmProductButtresslistMapper.class).doDelete(coilno, boxno);
			rm.setState("200");
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("服务端异常，删除失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	
	
	
	
	/**
	 * 倒垛管理  最大层
	 * 
	 * */
	public ResultModel getMaxlayer(YdmProductButtresslist ydmcp)
	{
		ResultModel rm=new ResultModel();
		try
		{
			//得到当前可用层高
			int lay = this.getMapper(YdmProductButtresslistMapper.class).getMaxlayerXy(ydmcp);
			//得到剁位配置的最大层高
			int maxlayer = this.getMapper(YdmProductButtresslistMapper.class).getMaxlayer(ydmcp);
			if (lay>maxlayer) {
				lay=-1;
			}
			rm.setState("200");
			rm.setData(lay);
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("服务端异常，删除失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	
	
	/**
	 * 倒垛管理  所有层
	 * 
	 * */
	public ResultModel getMaxlayerlist(YdmProductButtresslist ydmcp) {
		ResultModel rm=new ResultModel();
		try{
			List<Integer> lay = this.getMapper(YdmProductButtresslistMapper.class).getMaxlayerlist(ydmcp);
			rm.setState("200");
			rm.setData(lay);
		}
		catch(Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("服务端异常，删除失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	
	
	/**
	 * 倒垛管理  所有层
	 * 
	 * */
	public ResultModel getMaxlayerXy(YdmProductButtresslist ydmcp)
	{
		ResultModel rm=new ResultModel();
		try
		{
			//得到当前可用层高
			int lay = this.getMapper(YdmProductButtresslistMapper.class).getMaxlayerXy(ydmcp);
			//得到剁位配置的最大层高
			int maxlayer = this.getMapper(YdmProductButtresslistMapper.class).getMaxlayer(ydmcp);
			if (lay>maxlayer) {
				lay=-1;
			}
			rm.setState("200");
			rm.setData(lay);
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("服务端异常，删除失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	/**
	 * h获取最大层
	 * @param sum
	 * @return
	 */
	public ResultModel getLayer(CommonPage<YdmProductButtresslist> sum){
		ResultModel rm = new ResultModel();
//		if(sum.getObject().getButtressno()==null||"".equals(sum.getObject())){
//			rm.setState("500");
//			rm.setMsgInfo("请传入参数");
//			return rm;
//		}else{
//		List<YdmProductButtresslist> ypb = this.getMapper(YdmProductButtresslistMapper.class).find(sum.getObject(),0,0);
//		if(ypb.size()>0){
//			rm.setState("200");
//			rm.setData(ypb.get(0).getLayer());
//		}
//		else{
//			rm.setState("500");
//			rm.setMsgInfo("请传入正确的剁位编码+位置");
//			return rm;
//		 }
//		}
//		return rm;
//	}
		YdmProductButtresslist ypb = new YdmProductButtresslist();
		ypb.setButtressno(sum.getObject().getButtressno());
		ypb.setLocality(sum.getObject().getLocality());
		try
		{
		  int  lay = 	this.getMapper(YdmProductButtresslistMapper.class).getMaxlayerXy(ypb);
			rm.setState("200");
			rm.setData(lay);
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("服务端异常，删除失败!");
			ex.printStackTrace();
		}
		return rm;
}
}