/***文档注释***********************************************
 * 作者               :                   龙文航
 * 创建日期      :                   2017.11.21
 * 描述               :                   仓库管理-成品库管理-调拨单管理
 * 注意事项      :                   无
 * 遗留BUG :                   无
 * 修改日期      :                   
 * 修改人员      :                   
 * 修改内容      :                   
***********************************************************/

package market.Lms.Warehouse.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import market.Api.Mes.impl.MesApiServiceImpl;
import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Lms.Warehouse.mapper.YdmAllotMainMapper;
import market.Lms.Warehouse.mapper.YdmBaseButtressconfigMapper;
import market.Lms.Warehouse.mapper.YdmProductButtresslistMapper;
import market.Lms.Warehouse.mapper.YdmProductDetailMapper;
import market.Lms.Warehouse.mapper.YdmProductMoveMapper;
import market.Lms.Warehouse.mapper.YdmProductOutlistMapper;
import market.Lms.Warehouse.service.YdmAllotMainService;
import market.Lms.Warehouse.vo.YdmAllotMain;
import market.Lms.Warehouse.vo.YdmBaseButtressconfig;
import market.Lms.Warehouse.vo.YdmProductButtresslist;
import market.Lms.Warehouse.vo.YdmProductDetail;
import market.Lms.Warehouse.vo.YdmProductMove;
import market.Lms.Warehouse.vo.YdmProductOutlist;
import market.Mes.MaterielTrack.vo.PrcMaterielProcess;

import com.hnshituo.basic.service.impl.BaseServiceImpl;
import com.hnshituo.basic.service.support.PageModel;
import com.hnshituo.basic.spring.remoting.annotation.RemoteService;
import com.hnshituo.core.auth.service.HomeService;

@SuppressWarnings("rawtypes")
@RemoteService(path="YdmAllotMainService")
public class YdmAllotMainServiceImpl extends BaseServiceImpl<YdmAllotMain,Object> implements YdmAllotMainService {
	/**
	 * 调拨单查询 暂不使用
	 * 没有汇总功能
	 **/
	public ResultModel doQueryWeb(CommonPage<YdmAllotMain> cp)
	{
		ResultModel rm=new ResultModel();
		int pageIndex=cp.getPageIndex();
		int pageSize=cp.getPageSize();
		PageModel<YdmAllotMain> pm = new PageModel<YdmAllotMain>(pageIndex,pageSize);
		try
		{
			YdmAllotMain yam=cp.getObject();
			String sWhere="1=1";
			if(cp.getStartTime()!=null&&cp.getStartTime()!="")
			{
				String starttime=cp.getStartTime();
				sWhere=" and PLANDATE>=to_date(concat("+starttime+",' 00:00:00'),'yyyy-MM-dd HH24:MI:SS') ";
			}
			if(cp.getEndTime()!=null&&cp.getEndTime()!="")
			{
				String endtime=cp.getEndTime();
				sWhere=" and PLANDATE<=to_date(concat("+endtime+",' 00:00:00'),'yyyy-MM-dd HH24:MI:SS') ";
			}
			if(cp.getObject().getAllot_no()!=null&&cp.getObject().getAllot_no()!="")
			{
				String allotno=cp.getObject().getAllot_no();
				sWhere=" and ALLOT_NO like '%"+allotno+"%'";
			}
			yam.setAllot_no(null);
			yam.setPlandate(null);
			pm.setRows(this.getMapper(YdmAllotMainMapper.class).findWithCondition(yam, sWhere, "ALLOT_NO", (pageIndex-1)*pageSize, pageSize));
			pm.setTotal(this.getMapper(YdmAllotMainMapper.class).countWithCondition(yam,sWhere));
			rm.setState("200");
			rm.setData(pm);
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("服务端异常，查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 调拨单查询
	 * SQL实现
	 * 条件+汇总+分页
	 * */
	public ResultModel doQueryWebBySQL(CommonPage<YdmAllotMain> cp)
	{
		ResultModel rm=new ResultModel();
		int pageSize=cp.getPageSize();
		int pageIndex=cp.getPageIndex();
		PageModel<YdmAllotMain> pm = new PageModel<YdmAllotMain>(pageIndex,pageSize);
		try
		{
			pm.setRows(this.getMapper(YdmAllotMainMapper.class).doQueryWebBySQL
					((pageIndex-1)*pageSize, (pageIndex-1)*pageSize+pageSize, cp.getStartTime(), cp.getEndTime(), cp.getObject().getAllot_no(), cp.getObject().getSender_stock(),cp.getObject().getReceiver_stock(),cp.getObject().getState()));
			pm.setTotal(this.getMapper(YdmAllotMainMapper.class).doQueryWebBySQLCount
					(cp.getStartTime(), cp.getEndTime(), cp.getObject().getAllot_no(), cp.getObject().getSender_stock(),cp.getObject().getReceiver_stock(),cp.getObject().getState()));
			rm.setData(pm);
			rm.setState("200");
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 生成主键
	 * @return
	 * @throws Exception 
	 */
	public String createAllotNo() throws Exception
	{
		try 
		{
			String allotno="";
			List<HashMap> list = this.getMapper(YdmAllotMainMapper.class).getNo("AL"+(new SimpleDateFormat("yyyyMMdd").format(new Date())));
			allotno = (String) list.get(0).get("MAXNO");
			return allotno;
		} 
		catch (Exception ex) 
		{
			throw (ex);
		}
	}
	
	/**
	 * 调拨单编制
	 * */
	public ResultModel doAddWeb(CommonPage<YdmAllotMain> cp)
	{
		ResultModel rm=new ResultModel();
		try 
		{
			YdmAllotMain yam=cp.getObject();
			String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			yam.setAllot_no(this.createAllotNo());
			yam.setCreater(userName);
			yam.setCreatedate(new Date());
			yam.setState("0");
			yam.setSource("0");
			yam.setFactcount("0");
			yam.setFactweight((double) 0);
			this.getMapper(YdmAllotMainMapper.class).insert(yam);
			rm.setState("200");
		} 
		catch (Exception ex) 
		{
			rm.setState("500");
			rm.setMsgInfo("服务端异常，新增失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 调拨单撤销
	 * */
	public ResultModel doCancelWeb(CommonPage<YdmAllotMain> cp)
	{
		ResultModel rm=new ResultModel();
		List<YdmAllotMain> lyam=cp.getObjectList();
		try
		{
			for(YdmAllotMain yam:lyam)
			{
				this.getMapper(YdmAllotMainMapper.class).doDelete(yam.getAllot_no());
			}
			rm.setState("200");
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("服务端异常，撤销失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 调拨单关闭
	 * */
	public ResultModel doCloseWeb(CommonPage<YdmAllotMain> cp)
	{
		ResultModel rm=new ResultModel();
		try
		{
			for(YdmAllotMain yam:cp.getObjectList())
			{
				yam.setState("2");
				this.getMapper(YdmAllotMainMapper.class).update(yam);
			}
			rm.setState("200");
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("服务端异常，关闭失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 调拨单撤销关闭
	 * */
	public ResultModel doCancelCloseWeb(CommonPage<YdmAllotMain> cp)
	{
		ResultModel rm=new ResultModel();
		try
		{
			for(YdmAllotMain yam:cp.getObjectList())
			{
				yam.setState("1");
				this.getMapper(YdmAllotMainMapper.class).update(yam);
			}
			rm.setState("200");
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("服务端异常，撤销关闭失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 调拨单修改
	 * */
	public ResultModel doUpdate(CommonPage<YdmAllotMain> cp)
	{
		ResultModel rm=new ResultModel();
		try
		{
			YdmAllotMain y=cp.getObject();
			String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			y.setUpdater(userName);
			y.setUpdatedate(new Date());
			this.getMapper(YdmAllotMainMapper.class).update(y);
			rm.setState("200");
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("服务端异常，修改失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 调拨装车管理 调拨查询
	 * SQL实现
	 * 条件+汇总+分页
	 * */
	public ResultModel doQueryWebBySQLCar(CommonPage<YdmAllotMain> cp)
	{
		ResultModel rm=new ResultModel();
		int pageSize=cp.getPageSize();
		int pageIndex=cp.getPageIndex();
		PageModel<YdmAllotMain> pm = new PageModel<YdmAllotMain>(pageIndex,pageSize);
		try
		{
			pm.setRows(this.getMapper(YdmAllotMainMapper.class).doQueryWebBySQLCar
					((pageIndex-1)*pageSize, (pageIndex-1)*pageSize+pageSize, cp.getStartTime(), cp.getEndTime(), cp.getObject().getAllot_no(), cp.getObject().getSender_stock(),cp.getObject().getReceiver_stock()));
			pm.setTotal(this.getMapper(YdmAllotMainMapper.class).doQueryWebBySQLCarCount
					(cp.getStartTime(), cp.getEndTime(), cp.getObject().getAllot_no(), cp.getObject().getSender_stock(),cp.getObject().getReceiver_stock()));
			rm.setData(pm);
			rm.setState("200");
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 调拨装车管理  可装查询
	 * */
	public ResultModel doQueryEnable(CommonPage<YdmProductDetail> cp)
	{
		ResultModel rm=new ResultModel();
		int pageSize=cp.getPageSize();
		int pageIndex=cp.getPageIndex();
		PageModel<YdmProductDetail> pm = new PageModel<YdmProductDetail>(pageIndex,pageSize);
		try 
		{
			pm.setRows(this.getMapper(YdmProductDetailMapper.class).doQueryEnable
					((pageIndex-1)*pageSize, (pageIndex-1)*pageSize+pageSize,cp.getObject().getAllot_no(),cp.getObject().getStorageattr(),cp.getObject().getState()));
			pm.setTotal(this.getMapper(YdmProductDetailMapper.class).doQueryEnableCount
					(cp.getObject().getAllot_no(),cp.getObject().getStorageattr(),cp.getObject().getState()));
			rm.setData(pm);
			rm.setState("200");
		} 
		catch (Exception ex) 
		{
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 调拨装车管理 调拨确认
	 * memo1-4分别传编辑区车号，区域，货位，位置
	 * */
	public ResultModel doConfrim(CommonPage<YdmProductDetail> cp)
	{
		ResultModel rm=new ResultModel();
		SimpleDateFormat sdff = new SimpleDateFormat("yyyyMMddHHmmss");
	    String remark = sdff.format(new Date());
		try
		{
			List<YdmProductDetail> list=cp.getObjectList();
			String billno=this.getBean(YdmProductMoveServiceImpl.class).createBILLNO();
			Date date=new Date();
			String order=(String)this.getSession().getAttribute(HomeService.SESSION_WORK_ORD);
			String team=(String)this.getSession().getAttribute(HomeService.SESSION_WORK_GRP);
			String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			for(YdmProductDetail ypd:list)
			{
				//插入出库信息
				YdmProductOutlist ypo=new YdmProductOutlist();
				ypo.setCreatedate(date);
				ypo.setCreater(userName);
				ypo.setOutbillno(this.getBean(YdmProductOutlistServiceImpl.class).createOUTBILLNO());
				ypo.setOutdate(date);
				ypo.setOutoperator(userName);
				ypo.setOuttype("500506");
				ypo.setOutorder(order);
				ypo.setOutteam(team);
				ypo.setCoilno(ypd.getCoilno());
				if (ypd.getCoiltype()!=null) {
					ypo.setCoiltype(ypd.getCoiltype());
				}
				if (ypd.getSource()!=null) {
					ypo.setSource(ypd.getSource());
				}
				if (ypd.getMaterailsupplier()!=null) {
					ypo.setMaterailsupplier(ypd.getMaterailsupplier());
				}
				if (ypd.getIsbox()!=null) {
					ypo.setIsbox(ypd.getIsbox());
				}
				if (ypd.getBoxno()!=null) {
					ypo.setBoxno(ypd.getBoxno());
				}
				if (ypd.getDrawingno()!=null) {
					ypo.setDrawingno(ypd.getDrawingno());
				}
				if (ypd.getBatchno()!=null) {
					ypo.setBatchno(ypd.getBatchno());
				}
				if (ypd.getBatchno()!=null) {
					ypo.setHeatno(ypd.getBatchno());
				}
				if (ypd.getSmpno()!=null) {
					ypo.setSmpno(ypd.getSmpno());
				}
				if (ypd.getManagementno()!=null) {
					ypo.setManagementno(ypd.getManagementno());
				}
				if (ypd.getStorageattr()!=null) {
					ypo.setStorageattr(ypd.getStorageattr());
				}
				if (ypd.getProd_code()!=null) {
					ypo.setProd_code(ypd.getProd_code());
				}
				if (ypd.getProd_name()!=null) {
					ypo.setProd_name(ypd.getProd_name());
				}
				if (ypd.getStd_code()!=null) {
					ypo.setStd_code(ypd.getStd_code());
				}
				if (ypd.getStd_name()!=null) {
					ypo.setStd_name(ypd.getStd_name());
				}
				if (ypd.getUse_code()!=null) {
					ypo.setUse_code(ypd.getUse_code());
				}
				if (ypd.getUse_name()!=null) {
					ypo.setUse_name(ypd.getUse_name());
				}
				if (ypd.getPline_name()!=null) {
					ypo.setPline_name(ypd.getPline_name());
				}
				if (ypd.getPostid()!=null) {
					ypo.setPostid(ypd.getPostid());
				}
				if (ypd.getThick()!=null) {
					ypo.setThick(ypd.getThick());
				}
				if (ypd.getWidth()!=null) {
					ypo.setWidth(ypd.getWidth());
				}
				if (ypd.getLength()!=null) {
					ypo.setLength(ypd.getLength());
				}
				if (ypd.getDiameter_inn()!=null) {
					ypo.setDiameter_inn(ypd.getDiameter_inn());
				}
				if (ypd.getDiameter_out()!=null) {
					ypo.setDiameter_out(ypd.getDiameter_out());
				}
				if(ypd.getQuantity()==null||"".equals(ypd.getQuantity()))
				{
					ypd.setQuantity(0);
				}
				if (ypd.getQuantity()!=null) {
					ypo.setQuantity(ypd.getQuantity());
				}
				if (ypd.getTheoryweight()!=null) {
					ypo.setTheoryweight(ypd.getTheoryweight());
				}
				if (ypd.getCoreweight()!=null) {
					ypo.setCoreweight(ypd.getCoreweight());
				}
				if (ypd.getGrossweight()!=null) {
					ypo.setGrossweight(ypd.getGrossweight());
				}
				if (ypd.getPackweight()!=null) {
					ypo.setPackweight(ypd.getPackweight());
				}
				if (ypd.getFactweight()!=null) {
					ypo.setFactweight(ypd.getFactweight());
				}
				if (ypd.getCustomer_nm()!=null) {
					ypo.setCustomer_nm(ypd.getCustomer_nm());
				}
				if (ypd.getCustomer_no()!=null) {
					ypo.setCustomer_no(ypd.getCustomer_no());
				}
				if (ypd.getReceiv_no()!=null) {
					ypo.setReceiv_no(ypd.getReceiv_no());
				}
				if (ypd.getReceiv_nm()!=null) {
					ypo.setReceiv_nm(ypd.getReceiv_nm());
				}
				if (ypd.getOrderno()!=null) {
					ypo.setOrderno(ypd.getOrderno());
				}
				if (ypd.getProdorderno()!=null) {
					ypo.setProdorderno(ypd.getProdorderno());
				}
				if (ypd.getSteelcode()!=null) {
					ypo.setSteelcode(ypd.getSteelcode());
				}
				if (ypd.getJudgesteelcode()!=null) {
					ypo.setJudgesteelcode(ypd.getJudgesteelcode());
				}
				if (ypd.getPacking_group()!=null) {
					ypo.setPacking_group(ypd.getPacking_group());
				}
				if (ypd.getChemresult()!=null) {
					ypo.setChemresult(ypd.getChemresult());
				}
				if (ypd.getSizeresult()!=null) {
					ypo.setSizeresult(ypd.getSizeresult());
				}
				if (ypd.getSurfaceresult()!=null) {
					ypo.setSurfaceresult(ypd.getSurfaceresult());
				}
				if (ypd.getWeightresult()!=null) {
					ypo.setWeightresult(ypd.getWeightresult());
				}
				if (ypd.getJudgeresult()!=null) {
					ypo.setJudgeresult(ypd.getJudgeresult());
				}
				if (ypd.getPhysresult()!=null) {
					ypo.setPhysresult(ypd.getPhysresult());
				}
				if (ypd.getSpyresult()!=null) {
					ypo.setSpyresult(ypd.getSpyresult());
				}
				if (ypd.getProducedate()!=null) {
					ypo.setProducedate(ypd.getProducedate());
				}
				if (ypd.getProduceorder()!=null) {
					ypo.setProduceorder(ypd.getProduceorder());
				}
				if (ypd.getProduceteam()!=null) {
					ypo.setProduceteam(ypd.getProduceteam());
				}
				if (ypd.getIndate()!=null) {
					ypo.setIndate(ypd.getIndate());
				}
				if (ypd.getInorder()!=null) {
					ypo.setInorder(ypd.getInorder());
				}
				if (ypd.getInteam()!=null) {
					ypo.setInteam(ypd.getInteam());
				}
				if (cp.getMemo3()!=null) {
					ypo.setButtressno(cp.getMemo3());
				}
				ypo.setLayer((long)1);
				if(cp.getMemo4()!=null&&cp.getMemo4()!="")
					ypo.setLocality(Long.valueOf(cp.getMemo4()).longValue());
				
				// 加入物料属性：20230725刘侣
				ypo.setObj_attr_out(ypd.getObject_attr());
				// end
				
				this.getMapper(YdmProductOutlistMapper.class).insert(ypo);
				//删除垛位信息
				if((ypd.getBoxno()!=null&&ypd.getBoxno()!="")||(ypd.getCoilno()!=null&&ypd.getCoilno()!=""))
					this.getMapper(YdmProductButtresslistMapper.class).doDelete(ypd.getCoilno(), ypd.getBoxno());
				//修改库存信息
				ypd.setState("1");
				ypd.setUpdater(userName);
				ypd.setUpdatedate(date);
				this.getMapper(YdmProductDetailMapper.class).doUpdate(ypd);
				//调用生产计划模块物料跟踪接口
				PrcMaterielProcess pmp = new PrcMaterielProcess();
				Date date1 =new  Date();
				pmp.setObject_no(ypd.getCoilno());
				pmp.setPrc_code("5BYZ10");
				pmp.setCreate_time(date1);
				pmp.setRemark("调拨装车出库");
				pmp.setCreate_man_name(userName);
				PrcMaterielProcess pmp1 = new PrcMaterielProcess();
				pmp1.setObject_no(ypd.getCoilno());
				pmp1.setPrc_code("5BYZ03");
				pmp1.setCreate_time(date1);
				pmp1.setRemark(""+remark);
				pmp1.setCreate_man_name(userName);
				int tmp1= this.getBean(MesApiServiceImpl.class).INSERT_OBJ_PROCESS(pmp1);
				int tmp= this.getBean(MesApiServiceImpl.class).INSERT_OBJ_PROCESS(pmp);
				if(tmp1==-1){
					throw new Exception("物料跟踪失败");
				}
				if(tmp==-1){
					throw new Exception("物料跟踪失败");
				}
				//插入移库信息
				YdmProductMove ypm=new YdmProductMove();
				ypm.setMovebillno(this.getBean(YdmProductMoveServiceImpl.class).createMOVEBILLNO());
				if (ypo.getOutbillno()!=null) {
					ypm.setOutbillno(ypo.getOutbillno());
				}
				if (ypd.getAllot_no()!=null) {
					ypm.setAllot_no(ypd.getAllot_no());
				}
				ypm.setBillno(billno);
				ypm.setMovedate(date);
				ypm.setMoveoperator(userName);
				ypm.setCreatedate(date);
				ypm.setCreater(userName);
				ypm.setCarno(cp.getMemo1());
				if (ypd.getCoilno()!=null) {
					ypm.setCoilno(ypd.getCoilno());
				}
				if (ypd.getCoiltype()!=null) {
					ypm.setCoiltype(ypd.getCoiltype());
				}
				if (ypd.getMaterailtype()!=null) {
					ypm.setMaterailtype(ypd.getMaterailtype());
				}
				if (ypd.getSource()!=null) {
					ypm.setSource(ypd.getSource());
				}
				if (ypd.getMaterailsupplier()!=null) {
					ypm.setMaterailsupplier(ypd.getMaterailsupplier());
				}
				if (ypd.getIsbox()!=null) {
					ypm.setIsbox(ypd.getIsbox());
				}
				if (ypd.getBoxno()!=null) {
					ypm.setBoxno(ypd.getBoxno());
				}
				if (ypd.getDrawingno()!=null) {
					ypm.setDrawingno(ypd.getDrawingno());
				}
				if (ypd.getBatchno()!=null) {
					ypm.setBatchno(ypd.getBatchno());
				}
				if (ypd.getBatchno()!=null) {
					ypm.setHeatno(ypd.getBatchno());
				}
				if (ypd.getSmpno()!=null) {
					ypm.setSmpno(ypd.getSmpno());
				}
				if (ypd.getManagementno()!=null) {
					ypm.setManagementno(ypd.getManagementno());
				}
				if (ypd.getStorageattr()!=null) {
					ypm.setStorageattr(ypd.getStorageattr());
				}
				if (ypd.getProd_code()!=null) {
					ypm.setProd_code(ypd.getProd_code());
				}
				if (ypd.getProd_name()!=null) {
					ypm.setProd_name(ypd.getProd_name());
				}
				if (ypd.getStd_code()!=null) {
					ypm.setStd_code(ypd.getStd_code());
				}
				if (ypd.getStd_name()!=null) {
					ypm.setStd_name(ypd.getStd_name());
				}
				if (ypd.getUse_code()!=null) {
					ypm.setUse_code(ypd.getUse_code());
				}
				if (ypd.getUse_name()!=null) {
					ypm.setUse_name(ypd.getUse_name());
				}
				if (ypd.getPline_name()!=null) {
					ypm.setPline_name(ypd.getPline_name());
				}
				if (ypd.getPostid()!=null) {
					ypm.setPostid(ypd.getPostid());
				}
				if (ypd.getThick()!=null) {
					ypm.setThick(ypd.getThick());
				}
				if (ypd.getWidth()!=null) {
					ypm.setWidth(ypd.getWidth());
				}
				if (ypd.getLength()!=null) {
					ypm.setLength(ypd.getLength());
				}
				if (ypd.getDiameter_inn()!=null) {
					ypm.setDiameter_inn(ypd.getDiameter_inn());
				}
				if (ypd.getDiameter_out()!=null) {
					ypm.setDiameter_out(ypd.getDiameter_out());
				}
				if (ypd.getQuantity()!=null) {
					ypm.setQuantity(ypd.getQuantity());
				}
				if (ypd.getTheoryweight()!=null) {
					ypm.setTheoryweight(ypd.getTheoryweight());
				}
				if (ypd.getCoreweight()!=null) {
					ypm.setCoreweight(ypd.getCoreweight());
				}
				if (ypd.getGrossweight()!=null) {
					ypm.setGrossweight(ypd.getGrossweight());
				}
				if (ypd.getPackweight()!=null) {
					ypm.setPackweight(ypd.getPackweight());
				}
				if (ypd.getFactweight()!=null) {
					ypm.setFactweight(ypd.getFactweight());
				}
				if (ypd.getCustomer_nm()!=null) {
					ypm.setCustomer_nm(ypd.getCustomer_nm());
				}
				if (ypd.getCustomer_no()!=null) {
					ypm.setCustomer_no(ypd.getCustomer_no());
				}
				if (ypd.getReceiv_no()!=null) {
					ypm.setReceiv_no(ypd.getReceiv_no());
				}
				if (ypd.getReceiv_nm()!=null) {
					ypm.setReceiv_nm(ypd.getReceiv_nm());
				}
				if (ypd.getOrderno()!=null) {
					ypm.setOrderno(ypd.getOrderno());
				}
				if (ypd.getProdorderno()!=null) {
					ypm.setProdorderno(ypd.getProdorderno());
				}
				if (ypd.getSteelcode()!=null) {
					ypm.setSteelcode(ypd.getSteelcode());
				}
				if (ypd.getJudgesteelcode()!=null) {
					ypm.setJudgesteelcode(ypd.getJudgesteelcode());
				}
				if (ypd.getPacking_group()!=null) {
					ypm.setPacking_group(ypd.getPacking_group());
				}
				if (ypd.getChemresult()!=null) {
					ypm.setChemresult(ypd.getChemresult());
				}
				if (ypd.getSizeresult()!=null) {
					ypm.setSizeresult(ypd.getSizeresult());
				}
				if (ypd.getSurfaceresult()!=null) {
					ypm.setSurfaceresult(ypd.getSurfaceresult());
				}
				if (ypd.getWeightresult()!=null) {
					ypm.setWeightresult(ypd.getWeightresult());
				}
				if (ypd.getJudgeresult()!=null) {
					ypm.setJudgeresult(ypd.getJudgeresult());
				}
				if (ypd.getPhysresult()!=null) {
					ypm.setPhysresult(ypd.getPhysresult());
				}
				if (ypd.getSpyresult()!=null) {
					ypm.setSpyresult(ypd.getSpyresult());
				}
				if (ypd.getProducedate()!=null) {
					ypm.setProducedate(ypd.getProducedate());
				}
				if (ypd.getProduceorder()!=null) {
					ypm.setProduceorder(ypd.getProduceorder());
				}
				if (ypd.getProduceteam()!=null) {
					ypm.setProduceteam(ypd.getProduceteam());
				}
				if (ypd.getIndate()!=null) {
					ypm.setIndate(ypd.getIndate());
				}
				if (ypd.getInorder()!=null) {
					ypm.setInorder(ypd.getInorder());
				}
				if (ypd.getInteam()!=null) {
					ypm.setInteam(ypd.getInteam());
				}
				ypm.setIsaccept("0");
				this.getMapper(YdmProductMoveMapper.class).insert(ypm);
				//修改调拨信息
				if(ypd.getAllot_no()!=null&&ypd.getAllot_no()!="")
				{
					YdmAllotMain yam =new YdmAllotMain();
					if (this.getMapper(YdmAllotMainMapper.class).findById(ypd.getAllot_no())==null) {
						rm.setState("500");
						rm.setMsgInfo("未找到对应调拨单信息");
					}else {
						yam=this.getMapper(YdmAllotMainMapper.class).findById(ypd.getAllot_no());
						yam.setState("1");
						if(yam.getFactcount()!=null&&yam.getFactcount()!="")
							yam.setFactcount(String.valueOf((Integer.valueOf(yam.getFactcount()).intValue()+1)).toString());
						if(yam.getPlancount()!=null)
							yam.setPlancount(yam.getPlancount()+1);
						yam.setFactweight(yam.getFactweight()+ypd.getFactweight());
						yam.setTheoryweight(yam.getTheoryweight()+ypd.getTheoryweight());
						yam.setUpdatedate(date);
						yam.setUpdater(userName);
						this.getMapper(YdmAllotMainMapper.class).update(yam);
						rm.setState("200");
					}
				}
			}
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("确认失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 调拨装车管理 撤销调拨
	 * */
	public ResultModel doCancelAllot(CommonPage<YdmProductMove> cp) {
		ResultModel rm=new ResultModel();
		String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		try
		{
			List<YdmProductMove> list=cp.getObjectList();
			for(YdmProductMove ypm:list)
			{
				YdmProductOutlist ypo=new YdmProductOutlist();
				YdmBaseButtressconfig yb=new YdmBaseButtressconfig();
				YdmBaseButtressconfig ybb=new YdmBaseButtressconfig();
				//获取层，位置，垛位编码
				if(ypm.getOutbillno()!=null&&ypm.getOutbillno()!="")
				{
					 ypo=this.getMapper(YdmProductOutlistMapper.class).findById(ypm.getOutbillno());
					 if(ypo!=null)
					 {
						//获取区域
						if(ypo.getButtressno()!=null&&ypo.getButtressno()!="")
							yb=this.getMapper(YdmBaseButtressconfigMapper.class).findById(ypo.getButtressno());
						if(yb!=null)
						{
							if(yb.getSortcode()!=null&&yb.getSortcode()!="")
								ybb=this.getMapper(YdmBaseButtressconfigMapper.class).findById(yb.getSortcode());
						}
						//插入垛位信息
						YdmProductButtresslist ypb=new YdmProductButtresslist();
						ypb.setCreatedate(new Date());
						ypb.setCreater(userName);
						ypb.setButtressno(ypo.getButtressno());
						ypb.setCoilno(ypo.getCoilno());
						ypb.setBoxno(ypm.getBoxno());
						if(ypo.getLayer()!=null)
							ypb.setLayer(ypo.getLayer().intValue());
						if(ypo.getLocality()!=null)
							ypb.setLocality(ypo.getLocality().intValue());
						ypb.setAreano(ybb.getButtressno());
						ypb.setStorageattr(ypm.getStorageattr());
						this.getMapper(YdmProductButtresslistMapper.class).doInsert(ypb);
					 }
				}
				//删除出库信息
				if(ypm.getOutbillno()!=null&&ypm.getOutbillno()!="")
					this.getMapper(YdmProductOutlistMapper.class).doDelete(ypm.getOutbillno());
				//修改库存信息
				YdmProductDetail ypd=new YdmProductDetail();
				ypd.setState("0");
				ypd.setCoilno(ypm.getCoilno());
				ypd.setBoxno(ypm.getBoxno());
				ypd.setUpdatedate(new Date());
				ypd.setUpdater(userName);
				if((ypd.getBoxno()!=null&&ypd.getBoxno()!="")||(ypd.getCoilno()!=null&&ypd.getCoilno()!=""))
					{
					 this.getMapper(YdmProductDetailMapper.class).doUpdate(ypd);
					 PrcMaterielProcess pmp =new PrcMaterielProcess();
						pmp.setObject_no(ypd.getCoilno());
						pmp.setPrc_code("5BYZ10");
						pmp.setKeep_sametime_status(0);
						pmp.setRemark("调拨装车撤销");
						this.getBean(MesApiServiceImpl.class).ARRAYLIST(pmp).getState();
						/*String tmp = this.getBean(MesApiServiceImpl.class).ARRAYLIST(pmp).getState();
						if(tmp=="-1"){
							throw new Exception("出现程序异常！撤销跟踪失败！");
						}else if(tmp=="-2"){
							throw new Exception("出现程序异常！撤销跟踪失败");
						}else{
							
						}*/
					}
				//删除移库信息
				if(ypm.getMovebillno()!=null&&ypm.getMovebillno()!="")
					this.getMapper(YdmProductMoveMapper.class).doDelete(ypm.getMovebillno());
				//修改调拨信息
				YdmAllotMain yam=new YdmAllotMain();
				if(ypm.getAllot_no()!=null&&ypm.getAllot_no()!="")
				{
					yam=this.getMapper(YdmAllotMainMapper.class).findById(ypm.getAllot_no());
					if(yam.getPlancount()!=null)
					{
						yam.setPlancount(yam.getPlancount()-1);
						if(yam.getPlancount()==0)
							yam.setState("0");
					}
					if(yam.getFactcount()!=null&&yam.getFactcount()!="")
					{
						yam.setFactcount(String.valueOf((Integer.valueOf(yam.getFactcount()).intValue()-1)).toString());
						if("0".equals(yam.getFactcount()))
							yam.setState("0");
					}
					yam.setFactweight(yam.getFactweight()-ypm.getFactweight());
					yam.setTheoryweight(yam.getTheoryweight()-ypm.getTheoryweight());
					yam.setUpdatedate(new Date());
					yam.setUpdater(userName);
					this.getMapper(YdmAllotMainMapper.class).update(yam);
				}
			}		
			rm.setState("200");
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("撤销失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 调拨装车管理 调拨单关闭
	 * */
	public ResultModel doCloseAllot(CommonPage<YdmAllotMain> cp)
	{
		ResultModel rm=new ResultModel();
		String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		try
		{
			List<YdmAllotMain> list=cp.getObjectList();
			for(YdmAllotMain yam:list)
			{
				yam.setUpdatedate(new Date());
				yam.setUpdater(userName);
				yam.setState("2");
				if(yam.getAllot_no()!=null&&yam.getAllot_no()!=null)
					this.getMapper(YdmAllotMainMapper.class).update(yam);
			}
			rm.setState("200");
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("关闭失败!");
			ex.printStackTrace();
		}
		return rm;
	}
}
