/***文档注释***********************************************
 * 作者               :                   龙文航
 * 创建日期      :                   2017.11.29
 * 描述               :                   Lms提供其他系统调用的公共接口
 * 注意事项      :                   无
 * 遗留BUG :                   无
 * 修改日期      :                   
 * 修改人员      :                   
 * 修改内容      :                   
 ***********************************************************/

package market.Api.Lms.impl;

import static market.Api.Mes.impl.RestfulHttpClient.getClient;

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

import market.Api.Lms.service.LmsApiService;
import market.Api.Mes.impl.MesApiDesignInfoImpl;
import market.Api.Mes.impl.MesApiServiceImpl;
import market.Api.Mes.impl.ProcessPoint;
import market.Api.Mes.impl.RestfulHttpClient;
import market.Api.Mes.impl.Utils;
import market.Api.Qms.impl.QmsApiServiceImpl;
import market.Com.mapper.ComBaseInfoMapper;
import market.Com.mapper.ComBaseMachineMapper;
import market.Com.vo.ComBaseInfo;
import market.Com.vo.ComBaseMachine;
import market.Com.vo.CommonPage;
import market.Com.vo.PassportInfo;
import market.Com.vo.PbModelDb;
import market.Com.vo.ResultModel;
import market.Lms.Warehouse.impl.IfRawMtrCoilChemServiceImpl;
import market.Lms.Warehouse.impl.IfRawMtrCoilPfmcServiceImpl;
import market.Lms.Warehouse.impl.YdmProductOutlistServiceImpl;
import market.Lms.Warehouse.mapper.IfRawMtrCoilChemMapper;
import market.Lms.Warehouse.mapper.IfRawMtrCoilChemMidMapper;
import market.Lms.Warehouse.mapper.IfRawMtrCoilMMapper;
import market.Lms.Warehouse.mapper.IfRawMtrCoilMMidMapper;
import market.Lms.Warehouse.mapper.IfRawMtrCoilPfmcMapper;
import market.Lms.Warehouse.mapper.IfRawMtrCoilPfmcMidMapper;
import market.Lms.Warehouse.mapper.YdmBaseButtressconfigMapper;
import market.Lms.Warehouse.mapper.YdmProductButtresslistMapper;
import market.Lms.Warehouse.mapper.YdmProductDetailMapper;
import market.Lms.Warehouse.mapper.YdmProductInlistMapper;
import market.Lms.Warehouse.mapper.YdmProductOutlistMapper;
import market.Lms.Warehouse.vo.IfRawMtrCoilChem;
import market.Lms.Warehouse.vo.IfRawMtrCoilChemMid;
import market.Lms.Warehouse.vo.IfRawMtrCoilM;
import market.Lms.Warehouse.vo.IfRawMtrCoilMMid;
import market.Lms.Warehouse.vo.IfRawMtrCoilPfmc;
import market.Lms.Warehouse.vo.IfRawMtrCoilPfmcMid;
import market.Lms.Warehouse.vo.YdmProductButtresslist;
import market.Lms.Warehouse.vo.YdmProductDetail;
import market.Lms.Warehouse.vo.YdmProductInlist;
import market.Lms.Warehouse.vo.YdmProductOutlist;
import market.Mes.Lengthwise.Performance.mapper.MesCrSlittingDMapper;
import market.Mes.Lengthwise.Performance.mapper.MesCrSlittingMMapper;
import market.Mes.Lengthwise.Performance.vo.MesCrSlittingD;
import market.Mes.Lengthwise.Performance.vo.MesCrSlittingM;
import market.Mes.Lengthwise.Plan.mapper.MesCrCrossCuttingDMapper;
import market.Mes.Lengthwise.Plan.mapper.MesCrCrossCuttingMMapper;
import market.Mes.Lengthwise.Plan.mapper.PlnMatReplaceLogMapper;
import market.Mes.Lengthwise.Plan.vo.MesCrCrossCuttingD;
import market.Mes.Lengthwise.Plan.vo.MesCrCrossCuttingM;
import market.Mes.Lengthwise.Plan.vo.PlnMatReplaceLog;
import market.Mes.MaterielTrack.vo.PrcMaterielProcess;
import market.Mes.OrderManager.Plan.mapper.PlnProdorderMapper;
import market.Mes.OrderManager.Plan.vo.PlnProdorder;
import market.Mes.Packing.Performance.mapper.MesCoilPackingMMapper;
import market.Mes.Packing.Performance.vo.MesCoilPackingM;
import market.Mes.anneal.vo.MesCrAnnealM;
import market.Qms.common.DataHelper;
import market.Qms.slmord.vo.SlmOrdDesignMscPlSti;
import market.Qms.slmord.vo.SlmOrdDesignMscTic;
import market.Qms.slmord.vo.SlmOrdDesignMscTicItem;
import market.Slm.DeliveryManagement.mapper.SlmLadingBillHeatMapper;
import market.Slm.DeliveryManagement.vo.SlmLadingBillHeat;
import market.Slm.OrderManagement.impl.SlmOrderInfoServiceImpl;
import market.Slm.OrderManagement.mapper.SlmOrderInfoMapper;
import market.Slm.OrderManagement.vo.SlmOrderInfo;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.transaction.annotation.Transactional;

import com.google.gson.Gson;
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;

@RemoteService(path="LmsApiService")
public class LmsApiServiceImpl extends BaseServiceImpl implements LmsApiService {	

	/**
	 * 查询库存信息中是否存在相应卷号的数据
	 * */
	public ResultModel doFindCoilno(CommonPage<YdmProductDetail> cp)
	{
		ResultModel rm=new ResultModel();
		try
		{
			//			YdmProductDetail ypd=new YdmProductDetail();
			//			ypd.setCoilno(cp.getObject().getCoilno());
			List<YdmProductDetail> lypd=this.getMapper(YdmProductDetailMapper.class).find(cp.getObject(), 0, 0);
			if(lypd!=null&&lypd.size()>0)
			{
				rm.setState("200");
				rm.setData(lypd);
			}
			else
			{
				rm.setState("500");
				rm.setMsgInfo("库存中无实物["+cp.getObject().getCoilno()+"]信息!");
			}
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("服务端异常，查询卷号失败!");
			ex.printStackTrace();
		}
		return rm;
	}

	/**
	 * 查询库存信息
	 * */
	@SuppressWarnings("rawtypes")
	public ResultModel doQueryWebBySQLOther(CommonPage<YdmProductDetail> cp) {
		ResultModel rm=new ResultModel();
		int pageIndex=cp.getPageIndex();
		int pageSize=cp.getPageSize();
		PageModel<HashMap> pm = new PageModel<HashMap>(pageIndex,pageSize);
		try {
			cp.setMemo1(null);
			cp.setMemo2(null);

			Object wjmin="",wjmax="";
			if(cp.getMemo1()!=null&&cp.getMemo1()!="")
				wjmin=Double.valueOf(cp.getMemo1()).doubleValue();
			if(cp.getMemo2()!=null&&cp.getMemo2()!="")
				wjmax=Double.valueOf(cp.getMemo2()).doubleValue();
			Object thick,width;
			if(cp.getObject().getThick()!=null && cp.getObject().getThick()==0)
				thick="";
			else 
				thick=cp.getObject().getThick();
			if(cp.getObject().getWidth()!=null && cp.getObject().getWidth()==0)
				width="";
			else 
				width=cp.getObject().getWidth();

			if((cp.getObject().getJudgesteelcode()==null||"".equals(cp.getObject().getJudgesteelcode()))&&cp.getObject().getSteelcode()!=null&&!"".equals(cp.getObject().getSteelcode()))
				cp.getObject().setJudgesteelcode(cp.getObject().getSteelcode());


			pm.setRows(this.getMapper(YdmProductDetailMapper.class).doQueryWebBySQLOther
					((pageIndex-1)*pageSize, (pageIndex-1)*pageSize+pageSize, cp.getStartTime(), cp.getEndTime(), cp.getObject().getCoilno(), cp.getObject().getSteel_name(), 
							thick,width,wjmin,wjmax,cp.getObject().getStorageattr(),cp.getObject().getJudgesteelcode()));
			pm.setTotal(this.getMapper(YdmProductDetailMapper.class).doQueryWebBySQLCountOther
					(cp.getStartTime(), cp.getEndTime(), cp.getObject().getCoilno(), cp.getObject().getSteel_name(), 
							thick,width,wjmin,wjmax,cp.getObject().getStorageattr(),cp.getObject().getJudgesteelcode()));
			rm.setData(pm);
			rm.setState("200");
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("服务端异常，查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}

	/**
	 * 投料出库
	 * cp.object<YdmProductDetail>,ypd.setCoilno()
	 * @throws Exception 
	 * */
	public void doOutStorage(CommonPage<YdmProductDetail> cp) throws Exception {
		YdmProductDetail ypdo= new YdmProductDetail();
		ypdo.setCoilno(cp.getObject().getCoilno());	
		ypdo.setState("0");
		List<YdmProductDetail> list=this.getMapper(YdmProductDetailMapper.class).find(ypdo, 0, 0);
		String username=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		Date now = new Date();
		if(list!=null && list.size()>0) {
			for(YdmProductDetail ypd:list) {
				String lastChar = ypd.getCoilno().substring(ypd.getCoilno().length()-1);
				if (!"B".equals(lastChar) && !"H".equals(lastChar)) {
					if (ypd.getJudgeresult()==null || "".equals(ypd.getJudgeresult())) {
						throw new Exception("卷号【"+ypd.getCoilno()+"】没有综合判定，无法投料出库");
					}
				}
				
				//插入出库信息
				YdmProductOutlist ypo=new YdmProductOutlist();
				ypo.setOutbillno(this.getBean(YdmProductOutlistServiceImpl.class).createOUTBILLNO());
				ypo.setCreater(username);
				ypo.setCreatedate(now);
				ypo.setOuttype("500501");
				ypo.setOutdate(now);
				ypo.setOutoperator(username);
				ypo.setOutorder("2");
				ypo.setOutteam("3");

				ypo.setCoilno(ypd.getCoilno());
				//QmsApiServiceImpl.Copy(ypd, ypo);
				ypo.setCoiltype(ypd.getCoiltype());
				ypo.setMaterailtype(ypd.getMaterailtype());
				ypo.setSource(ypd.getSource());
				ypo.setMaterailsupplier(ypd.getMaterailsupplier());
				ypo.setIsbox(ypd.getIsbox());
				ypo.setBoxno(ypd.getBoxno());
				ypo.setDrawingno(ypd.getDrawingno());
				ypo.setBatchno(ypd.getBatchno());
				ypo.setHeatno(ypd.getBatchno());
				ypo.setSmpno(ypd.getSmpno());
				ypo.setManagementno(ypd.getManagementno());
				ypo.setStorageattr(ypd.getStorageattr());
				ypo.setProd_code(ypd.getProd_code());
				ypo.setProd_name(ypd.getProd_name());
				ypo.setStd_code(ypd.getStd_code());
				ypo.setStd_name(ypd.getStd_name());
				ypo.setUse_code(ypd.getUse_code());
				ypo.setUse_name(ypd.getUse_name());
				ypo.setPline_name(ypd.getPline_name());
				ypo.setPostid(ypd.getPostid());
				ypo.setThick(ypd.getThick());
				ypo.setWidth(ypd.getWidth());
				ypo.setLength(ypd.getLength());
				ypo.setDiameter_inn(ypd.getDiameter_inn());
				ypo.setDiameter_out(ypd.getDiameter_out());
				ypo.setQuantity(ypd.getQuantity());
				ypo.setTheoryweight(ypd.getTheoryweight());
				ypo.setCoreweight(ypd.getCoreweight());
				ypo.setGrossweight(ypd.getGrossweight());
				ypo.setPackweight(ypd.getPackweight());
				ypo.setFactweight(ypd.getFactweight());
				ypo.setCustomer_nm(ypd.getCustomer_nm());
				ypo.setCustomer_no(ypd.getCustomer_no());
				ypo.setReceiv_no(ypd.getReceiv_no());
				ypo.setReceiv_nm(ypd.getReceiv_nm());
				ypo.setOrderno(ypd.getOrderno());
				ypo.setProdorderno(ypd.getProdorderno());
				ypo.setSteelcode(ypd.getSteelcode());
				ypo.setJudgesteelcode(ypd.getJudgesteelcode());
				ypo.setPacking_group(ypd.getPacking_group());
				ypo.setChemresult(ypd.getChemresult());
				ypo.setSizeresult(ypd.getSizeresult());
				ypo.setSurfaceresult(ypd.getSurfaceresult());
				ypo.setWeightresult(ypd.getWeightresult());
				ypo.setJudgeresult(ypd.getJudgeresult());
				ypo.setPhysresult(ypd.getPhysresult());
				ypo.setSpyresult(ypd.getSpyresult());
				ypo.setProducedate(ypd.getProducedate());
				ypo.setProduceorder(ypd.getProduceorder());
				ypo.setProduceteam(ypd.getProduceteam());
				ypo.setIndate(ypd.getIndate());
				ypo.setInorder(ypd.getInorder());
				ypo.setInteam(ypd.getInteam());

				YdmProductButtresslist but = new YdmProductButtresslist();
				but.setCoilno(ypd.getCoilno());
				List<YdmProductButtresslist> butlist =	this.getMapper(YdmProductButtresslistMapper.class).find(but, 0, 0);
				if(butlist!=null&&butlist.size()>0) {
					ypo.setButtressno(butlist.get(0).getButtressno());
					ypo.setLocality((long)butlist.get(0).getLocality());
					ypo.setLayer((long) 1);
				}
				else {
					ypo.setButtressno(ypd.getButtressno());
				}
				
				// 加入物料属性：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.setUpdater(username);
				ypd.setUpdatedate(now);
				ypd.setState("5");
				this.getMapper(YdmProductDetailMapper.class).doUpdate(ypd);

				//调用生产计划模块物料跟踪接口
				PrcMaterielProcess pmp = new PrcMaterielProcess();
				pmp.setObject_no(ypd.getCoilno());
				pmp.setPrc_code("5BYS10");

				//这里的格式要和字符串日期的格式匹配，不然会抛出转换异常   
				SimpleDateFormat   dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
				Date date2 = dateFormat.parse(cp.getObject().getMemo());
				if(date2!=null&&!"".equals(date2)) {
					pmp.setCreate_time(date2);
				}
				else {
					pmp.setCreate_time(now);
				}
				pmp.setRemark("投料出库");
				pmp.setCreate_man_name(username);
				this.getBean(MesApiServiceImpl.class).INSERT_OBJ_PROCESS(pmp);
				//int tmp= this.getBean(MesApiServiceImpl.class).INSERT_OBJ_PROCESS(pmp);
			}
		}
		else{
			throw new Exception("不在库不允许操作!");
		}
	}





	/**
	 * 生成主键
	 * @return
	 * @throws Exception 
	 */
	@SuppressWarnings("rawtypes")
	public String createINBILLNO() throws Exception {
		try {
			String inbillno="";
			List<HashMap> list = this.getMapper(YdmProductInlistMapper.class).getNo("IN"+(new SimpleDateFormat("yyyyMMdd").format(new Date())));
			inbillno = (String) list.get(0).get("MAXNO");
			return inbillno;
		} 
		catch (Exception ex) 
		{
			throw (ex);
		}
	}

	/**
	 * 原料卷退回原料库
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doCanceOutStorage(CommonPage<YdmProductDetail> cp) throws Exception
	{

		//YdmProductDetail ypdo=cp.getObject();
		//ypdo.setState("0");
		//	List<YdmProductDetail> list=this.getMapper(YdmProductDetailMapper.class).find(ypdo, 0, 0);
		String username=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);

		ResultModel rm=new ResultModel();
		for(YdmProductDetail ypd:cp.getObjectList())
		{
			YdmProductDetail yd= new YdmProductDetail();
			yd.setCoilno(ypd.getMaterailcoilno());
			//获取老卷号信息
			List<YdmProductDetail> ago = this.getMapper(YdmProductDetailMapper.class).find(yd, 0, 1);

			yd = ago.get(0);

			yd.setCoilno(ypd.getCoilno());

			yd.setLength(ypd.getLength());
			yd.setDiameter_inn(ypd.getDiameter_inn());
			yd.setDiameter_out(ypd.getDiameter_out());
			yd.setTheoryweight(ypd.getTheoryweight());
			yd.setFactweight(ypd.getFactweight());
			yd.setOrderno(null);
			yd.setProdorderno(null);
			yd.setState("0");

			this.getMapper(YdmProductDetailMapper.class).doInsert(yd);

			//插入垛位信息
			YdmProductButtresslist ybt = new YdmProductButtresslist();
			ybt.setButtressno("100102001");
			ybt.setCoilno(ypd.getCoilno());
			ybt.setStorageattr(ypd.getSteelcode());
			ybt.setCreatedate(new Date());
			ybt.setAreano("100102");
			ybt.setLayer(1);
			ybt.setLocality(0);
			this.getMapper(YdmProductButtresslistMapper.class).doInsert(ybt);


			//插入入库信息
			YdmProductInlist ypi=new YdmProductInlist();
			ypi.setInbillno(this.createINBILLNO());
			if(ypi.getCreatedate()==null||"".equals(ypi.getCreatedate())) {
				ypi.setCreatedate(new Date());
			}
			if (ypi.getCreater()==null||"".equals(ypi.getCreater())) {
				ypi.setCreater(username);
			}
			ypi.setCoilno(yd.getCoilno());
			ypi.setCoiltype(yd.getCoiltype());
			ypi.setMaterailtype(yd.getMaterailtype());
			ypi.setSource(yd.getSource());
			ypi.setMaterailsupplier(yd.getMaterailsupplier());
			ypi.setIsbox(yd.getIsbox());
			ypi.setBoxno(yd.getBoxno());
			ypi.setDrawingno(yd.getDrawingno());
			ypi.setBatchno(yd.getBatchno());
			ypi.setHeatno(yd.getBatchno());
			ypi.setSmpno(yd.getSmpno());
			ypi.setManagementno(yd.getManagementno());
			ypi.setStorageattr(yd.getStorageattr());
			ypi.setProd_code(yd.getProd_code());
			ypi.setProd_name(yd.getProd_name());
			ypi.setStd_code(yd.getStd_code());
			ypi.setStd_name(yd.getStd_name());
			ypi.setUse_code(yd.getUse_code());
			ypi.setUse_name(yd.getUse_name());
			ypi.setPline_name(yd.getPline_name());
			ypi.setPostid(yd.getPostid());
			ypi.setThick(yd.getThick());
			ypi.setWidth(yd.getWidth());
			ypi.setLength(yd.getLength());
			ypi.setDiameter_inn(yd.getDiameter_inn());
			ypi.setDiameter_out(yd.getDiameter_out());
			ypi.setQuantity(yd.getQuantity());
			ypi.setTheoryweight(yd.getTheoryweight());
			ypi.setCoreweight(yd.getCoreweight());
			ypi.setGrossweight(yd.getGrossweight());
			ypi.setPackweight(yd.getPackweight());
			ypi.setFactweight(yd.getFactweight());
			ypi.setCustomer_nm(yd.getCustomer_nm());
			ypi.setCustomer_no(yd.getCustomer_no());
			ypi.setReceiv_no(yd.getReceiv_no());
			ypi.setReceiv_nm(yd.getReceiv_nm());
			ypi.setOrderno(yd.getOrderno());
			ypi.setProdorderno(yd.getProdorderno());
			ypi.setSteelcode(yd.getSteelcode());
			ypi.setJudgesteelcode(yd.getJudgesteelcode());
			ypi.setPacking_group(yd.getPacking_group());
			ypi.setChemresult(yd.getChemresult());
			ypi.setSizeresult(yd.getSizeresult());
			ypi.setSurfaceresult(yd.getSurfaceresult());
			ypi.setWeightresult(yd.getWeightresult());
			ypi.setJudgeresult(yd.getJudgeresult());
			ypi.setPhysresult(yd.getPhysresult());
			ypi.setSpyresult(yd.getSpyresult());
			ypi.setProducedate(yd.getProducedate());
			ypi.setProduceorder(yd.getProduceorder());
			ypi.setProduceteam(yd.getProduceteam());
			if(ypi.getIndate()==null||"".equals(ypi.getIndate()))
			{
				ypi.setIndate(new Date());
			}
			///ypi.setInorder(order);
			//ypi.setInteam(team);
			ypi.setOperator(username);
			ypi.setIntype("500405");
			ypi.setLocality("1");

			ypi.setPosition("0");
			ypi.setMemo(yd.getMemo());
			ypi.setButtressno("100102001");
			
			// 加入物料属性：20230725刘侣
			ypi.setObj_attr_in(yd.getObject_attr());
			// end
			
			this.getMapper(YdmProductInlistMapper.class).insert(ypi);




			rm.setState("200");

		}

		return rm;

	}


	/**
	 * 判断是否允许出库撤销
	 * cp.object<YdmProductDetail>,ypd.setCoilno()
	 * */
	public ResultModel doDepend(CommonPage<YdmProductDetail> cp)
	{
		ResultModel rm=new ResultModel();
		try
		{
			YdmProductDetail ypdo= new  YdmProductDetail();
			ypdo.setCoilno(cp.getObject().getCoilno());
			ypdo.setState("5");
			List<YdmProductDetail> list=this.getMapper(YdmProductDetailMapper.class).find(ypdo, 0, 0);
			if(list!=null&&list.size()>0)
			{
				rm.setState("200");
			}
			else 
			{
				rm.setState("500");
				rm.setMsgInfo("未出库不允许操作!");
			}
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("服务端异常，判断失败!");
			ex.printStackTrace();
		}
		return rm;
	}

	/**
	 * 撤销出库
	 * cp.object<YdmProductDetail>,ypd.setCoilno()
	 * @throws Exception 
	 * */
	public void doCancelOut(CommonPage<YdmProductDetail> cp) throws Exception
	{

		YdmProductDetail ypdo= new YdmProductDetail();
		ypdo.setCoilno(cp.getObject().getCoilno());
		ypdo.setState("5");
		List<YdmProductDetail> list=this.getMapper(YdmProductDetailMapper.class).find(ypdo, 0, 0);
		String username=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		if(list!=null&&list.size()>0)
		{
			for(YdmProductDetail ypd:list)
			{
				//修改库存信息
				ypd.setState("0");
				ypd.setUpdatedate(new Date());
				ypd.setUpdater(username);
				this.getMapper(YdmProductDetailMapper.class).doUpdate(ypd);
				YdmProductOutlist ypo=new YdmProductOutlist();
				ypo.setOuttype("500501");
				ypo.setCoilno(ypd.getCoilno());				
				if(ypo.getCoilno()!=null&&ypo.getCoilno()!="")
				{
					//保存要删除的最近一条出库记录的垛位信息
					YdmProductOutlist ypo1=new YdmProductOutlist();
					ypo1=this.getMapper(YdmProductOutlistMapper.class).doFindRecent(ypo.getCoilno(), ypo.getOuttype());
					//插入垛位信息
					YdmProductButtresslist ypb=new YdmProductButtresslist();
					ypb.setCoilno(ypo1.getCoilno());
					if(ypo1.getLayer()!=null)
						ypb.setLayer(ypo1.getLayer().intValue());
					ypb.setButtressno(ypo1.getButtressno());
					if(ypo1.getLocality()!=null)
						ypb.setLocality(ypo1.getLocality().intValue());
					ypb.setStorageattr(ypo1.getStorageattr());
					ypb.setBoxno(ypo1.getBoxno());
					ypb.setCreater(username);
					ypb.setCreatedate(new Date());
					this.getMapper(YdmProductButtresslistMapper.class).doInsert(ypb);
					//删除最近一条出库记录
					this.getMapper(YdmProductOutlistMapper.class).doDeleteRecent(ypo.getCoilno(), ypo.getOuttype());
				}
			}
		}
		else {
			throw new Exception("未出库不允许操作!");
		}

	}

	/**
	 * 修改包装等级
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doUpdatePackingGroup(CommonPage<YdmProductDetail> cp) throws Exception
	{
		ResultModel rm=new ResultModel();
		List<YdmProductDetail> list=cp.getObjectList();
		String username=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		//修改库存信息
		for(YdmProductDetail ypd:list)
		{
			if(ypd.getCoilno()!=null&&ypd.getCoilno()!="")
			{
				YdmProductDetail ypd1=new YdmProductDetail();
				ypd1=this.getMapper(YdmProductDetailMapper.class).doFind(ypd.getCoilno(), ypd.getBoxno());
				if(ypd1!=null)
				{
					ypd1.setUpdatedate(new Date());
					ypd1.setUpdater(username);
					ypd1.setPacking_group(ypd.getPacking_group());
					this.getMapper(YdmProductDetailMapper.class).doUpdate(ypd1);
				}
				else 
				{
					throw new Exception();
				}
			}
			else 
			{
				rm.setState("500");
				rm.setMsgInfo(rm.getMsgInfo()+"传入的卷号为空!");
			}
		}
		rm.setState("200");
		return rm;
	}

	/**
	 * 原始钢卷出库
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doRollOut(CommonPage<YdmProductDetail> cp) throws Exception
	{
		ResultModel rm=new ResultModel();
		List<YdmProductDetail> list=cp.getObjectList();
		String username=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		//修改库存信息
		for(YdmProductDetail ypd:list)
		{
			YdmProductDetail ypd1=new YdmProductDetail();
			if(ypd.getCoilno()!=null&&ypd.getCoilno()!="")
			{
				ypd1=this.getMapper(YdmProductDetailMapper.class).doFind(ypd.getCoilno(), ypd.getBoxno());
				if(ypd1!=null)
				{
					ypd1.setUpdatedate(new Date());
					ypd1.setUpdater(username);
					ypd1.setState("4");
					this.getMapper(YdmProductDetailMapper.class).doUpdate(ypd1);
					//插入出库信息
					YdmProductOutlist ypo=new YdmProductOutlist();
					ypo.setCreatedate(new Date());
					ypo.setCreater(username);
					ypo.setOutbillno(this.getBean(YdmProductOutlistServiceImpl.class).createOUTBILLNO());
					ypo.setOutdate(new Date());
					ypo.setOutoperator(username);
					ypo.setOuttype("500507");
					ypo.setOutorder("2");
					ypo.setOutteam("3");
					ypo.setCoilno(ypd1.getCoilno());
					ypo.setCoiltype(ypd1.getCoiltype());
					ypo.setMaterailtype(ypd1.getMaterailtype());
					ypo.setSource(ypd1.getSource());
					ypo.setMaterailsupplier(ypd1.getMaterailsupplier());
					ypo.setIsbox(ypd1.getIsbox());
					ypo.setBoxno(ypd1.getBoxno());
					ypo.setDrawingno(ypd1.getDrawingno());
					ypo.setBatchno(ypd1.getBatchno());
					ypo.setHeatno(ypd1.getBatchno());
					ypo.setSmpno(ypd1.getSmpno());
					ypo.setManagementno(ypd1.getManagementno());
					ypo.setStorageattr(ypd1.getStorageattr());
					ypo.setProd_code(ypd1.getProd_code());
					ypo.setProd_name(ypd1.getProd_name());
					ypo.setStd_code(ypd1.getStd_code());
					ypo.setStd_name(ypd1.getStd_name());
					ypo.setUse_code(ypd1.getUse_code());
					ypo.setUse_name(ypd1.getUse_name());
					ypo.setPline_name(ypd1.getPline_name());
					ypo.setPostid(ypd1.getPostid());
					ypo.setThick(ypd1.getThick());
					ypo.setWidth(ypd1.getWidth());
					ypo.setLength(ypd1.getLength());
					ypo.setDiameter_inn(ypd1.getDiameter_inn());
					ypo.setDiameter_out(ypd1.getDiameter_out());
					ypo.setQuantity(ypd1.getQuantity());
					ypo.setTheoryweight(ypd1.getTheoryweight());
					ypo.setCoreweight(ypd1.getCoreweight());
					ypo.setGrossweight(ypd1.getGrossweight());
					ypo.setPackweight(ypd1.getPackweight());
					ypo.setFactweight(ypd1.getFactweight());
					ypo.setCustomer_nm(ypd1.getCustomer_nm());
					ypo.setCustomer_no(ypd1.getCustomer_no());
					ypo.setReceiv_no(ypd1.getReceiv_no());
					ypo.setReceiv_nm(ypd1.getReceiv_nm());
					ypo.setOrderno(ypd1.getOrderno());
					ypo.setProdorderno(ypd1.getProdorderno());
					ypo.setSteelcode(ypd1.getSteelcode());
					ypo.setJudgesteelcode(ypd1.getJudgesteelcode());
					ypo.setPacking_group(ypd1.getPacking_group());
					ypo.setChemresult(ypd1.getChemresult());
					ypo.setSizeresult(ypd1.getSizeresult());
					ypo.setSurfaceresult(ypd1.getSurfaceresult());
					ypo.setWeightresult(ypd1.getWeightresult());
					ypo.setJudgeresult(ypd1.getJudgeresult());
					ypo.setPhysresult(ypd1.getPhysresult());
					ypo.setSpyresult(ypd1.getSpyresult());
					ypo.setProducedate(ypd1.getProducedate());
					ypo.setProduceorder(ypd1.getProduceorder());
					ypo.setProduceteam(ypd1.getProduceteam());
					ypo.setIndate(ypd1.getIndate());
					ypo.setInorder(ypd1.getInorder());
					ypo.setInteam(ypd1.getInteam());
					ypo.setButtressno(ypd1.getButtressno());
					
					// 加入物料属性：20230725刘侣
					ypo.setObj_attr_out(ypd1.getObject_attr());
					// end
					
					this.getMapper(YdmProductOutlistMapper.class).insert(ypo);
				}
				else 
				{
					throw new Exception();
				}
			}
			else 
			{
				rm.setState("500");
				rm.setMsgInfo(rm.getMsgInfo()+"传入的卷号为空!");
			}
		}
		rm.setState("200");
		return rm;
	}

	/**
	 * 成品包号插入库存
	 * @throws Exception 
	 * */
	public ResultModel doFinishedIn(CommonPage<YdmProductDetail> cp) throws Exception
	{
		ResultModel rm=new ResultModel();
		YdmProductDetail ypd=cp.getObject();
		String username=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		if(ypd.getPacking_no()!=null&&ypd.getPacking_no()!=null)
		{
			//插入库存
			MesCoilPackingM mes=this.getMapper(MesCoilPackingMMapper.class).findById(ypd.getPacking_no());
			if(mes!=null)
			{
				YdmProductDetail ypd2=new YdmProductDetail();
				ypd2.setCreatedate(new Date());
				ypd2.setCreater(username);
				ypd2.setCoiltype("2");
				ypd2.setState("-1");
				ypd2.setSource("1");
				ypd2.setSteelcode(mes.getSteel_code());
				ypd2.setCoilno(mes.getPacking_no());
				ypd2.setThick(mes.getOrd_thk());
				ypd2.setWidth(mes.getOrd_wdt());
				ypd2.setLength(mes.getOrd_len());
				ypd2.setDiameter_inn(mes.getOrd_inn_dia());
				ypd2.setDiameter_out(mes.getOrd_out_dia());
				ypd2.setQuantity(mes.getCoil_cnt());
				ypd2.setGrossweight(mes.getCoil_gross_wgt());
				ypd2.setFactweight(mes.getCoil_net_wgt());
				ypd2.setPackweight(mes.getCoil_tare_wgt());
				ypd2.setOrderno(mes.getOrder_no());
				ypd2.setProdorderno(mes.getProd_order_no());
				this.getMapper(YdmProductDetailMapper.class).doInsert(ypd2);
				rm.setState("200");
			}
			else 
			{
				throw new Exception();
			}
		}
		else 
		{
			rm.setState("500");
			rm.setMsgInfo("传入的包装卷包号为空!");
		}
		return rm;
	}

	/**
	 * 验证包装出库
	 * */
	public ResultModel doConfirmPackingOut(CommonPage<YdmProductDetail> cp)
	{
		ResultModel rm=new ResultModel();
		try 
		{
			YdmProductDetail ypd=cp.getObject();
			if(ypd.getCoilno()!=null&&!"".equals(ypd.getCoilno()))
			{
				YdmProductDetail ypd1=this.getMapper(YdmProductDetailMapper.class).doFind(ypd.getCoilno(), ypd.getBoxno());
				if(ypd1!=null)
				{
					if("4".equals(ypd1.getState()))
						rm.setState("200");
					else 
					{
						rm.setState("500");
						rm.setMsgInfo("库存记录状态不为包装出库!");
					}
				}
				else 
				{
					rm.setState("500");
					rm.setMsgInfo("库存记录不存在!");
				}
			}
			else 
			{
				rm.setState("500");
				rm.setMsgInfo("传入卷号为空!");
			}
		} 
		catch (Exception ex) 
		{
			rm.setState("500");
			rm.setMsgInfo("服务端异常，验证包装出库失败!");
			ex.printStackTrace();
		}
		return rm;
	}

	/**
	 * cp.getObject().getCoilno()
	 * 传入卷号进行验证，验证卷号是否为待入库状态
	 * 验证待入库
	 * */
	public ResultModel doConfirmWaitIn(CommonPage<YdmProductDetail> cp)
	{
		ResultModel rm=new ResultModel();
		try 
		{
			YdmProductDetail ypd=cp.getObject();
			if(ypd.getCoilno()!=null&&!"".equals(ypd.getCoilno()))
			{
				YdmProductDetail ypd1=this.getMapper(YdmProductDetailMapper.class).doFind(ypd.getCoilno(), ypd.getBoxno());
				if(ypd1!=null)
				{
					if("-1".equals(ypd1.getState()))
						rm.setState("200");
					else 
					{
						rm.setState("500");
						rm.setMsgInfo("库存记录状态不为待入库!");
					}
				}
				else 
				{
					rm.setState("500");
					rm.setMsgInfo("库存记录不存在!");
				}
			}
			else 
			{
				rm.setState("500");
				rm.setMsgInfo("传入卷号为空!");
			}
		} 
		catch (Exception ex) 
		{
			rm.setState("500");
			rm.setMsgInfo("服务端异常，验证包装出库失败!");
			ex.printStackTrace();
		}
		return rm;
	}

	/**
	 * 撤销包装出库
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doCancelPackingOut(CommonPage<YdmProductDetail> cp) throws Exception
	{
		ResultModel rm=new ResultModel();
		List<YdmProductDetail> list=cp.getObjectList();
		String username=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		for(YdmProductDetail ypd:list)
		{
			if(ypd.getCoilno()!=null&&!"".equals(ypd.getCoilno()))
			{
				YdmProductDetail ypd1=this.getMapper(YdmProductDetailMapper.class).doFind(ypd.getCoilno(), ypd.getBoxno());
				if(ypd1!=null)
				{
					//修改库存信息
					ypd1.setUpdatedate(new Date());
					ypd1.setUpdater(username);
					ypd1.setPacking_group(null);
					ypd1.setState("0");
					this.getMapper(YdmProductDetailMapper.class).doUpdate(ypd1);
					//删除出库记录
					this.getMapper(YdmProductOutlistMapper.class).doDeleteByCoilno(ypd1.getCoilno());
					rm.setState("200");
				}
				else 
				{
					throw new Exception();
				}
			}
			else 
			{
				rm.setState("500");
				rm.setMsgInfo(rm.getMsgInfo()+"传入的卷号为空!");
			}
		}
		return rm;
	}

	/**
	 * 删除包装后库存
	 * */
	public ResultModel doDeleteFinishedRoll(CommonPage<YdmProductDetail> cp)
	{
		ResultModel rm=new ResultModel();
		YdmProductDetail ypd=cp.getObject();
		if(ypd.getCoilno()!=""&&ypd.getCoilno()!=null)
		{
			this.getMapper(YdmProductDetailMapper.class).doDelete(ypd.getCoilno(), ypd.getBoxno());
			rm.setState("200");
		}
		else 
		{
			rm.setState("500");
			rm.setMsgInfo("传入的卷号为空!");
		}
		return rm;
	}

	/**
	 * 修改卷包库存明细
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doUpdateDetail(CommonPage<YdmProductDetail> cp) throws Exception
	{
		ResultModel rm=new ResultModel();
		String username=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		YdmProductDetail ypd=cp.getObject();
		if(ypd.getCoilno()!=""&&ypd.getCoilno()!=null)
		{
			YdmProductDetail ypd1=this.getMapper(YdmProductDetailMapper.class).doFind(ypd.getCoilno(), ypd.getBoxno());
			if(ypd1!=null)
			{
				ypd1.setPacking_group(ypd.getPacking_group());
				ypd1.setGrossweight(ypd.getGrossweight());
				ypd1.setFactweight(ypd.getFactweight());
				ypd1.setPackweight(ypd.getPackweight());
				ypd1.setUpdatedate(new Date());
				ypd1.setUpdater(username);
				this.getMapper(YdmProductDetailMapper.class).doUpdate(ypd1);
				rm.setState("200");
			}
			else 
			{
				throw new Exception();
			}
		}
		else 
		{
			rm.setState("500");
			rm.setMsgInfo("传入的卷号为空!");
		}
		return rm;
	}

	/**
	 * 修改库存班次班组
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doUpdateOrderTeam(CommonPage<YdmProductDetail> cp) throws Exception
	{
		ResultModel rm=new ResultModel();
		String username=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		List<YdmProductDetail> list=cp.getObjectList();
		for(YdmProductDetail ypd:list)
		{
			if(ypd.getCoilno()!=null&&ypd.getCoilno()!="")
			{
				YdmProductDetail ypd1=this.getMapper(YdmProductDetailMapper.class).doFind(ypd.getCoilno(), ypd.getBoxno());
				if(ypd1!=null)
				{
					ypd1.setUpdatedate(new Date());
					ypd1.setUpdater(username);
					ypd1.setProducedate(ypd.getProducedate());
					ypd1.setProduceorder(ypd.getProduceorder());
					ypd1.setProduceteam(ypd.getProduceteam());
					this.getMapper(YdmProductDetailMapper.class).doUpdate(ypd1);
					rm.setState("200");
				}
				else 
				{
					throw new Exception();
				}
			}
			else 
			{
				rm.setState("500");
				rm.setMsgInfo(rm.getMsgInfo()+"传入的卷号为空!");
			}
		}
		return rm;
	}

	/**
	 * cp.getObject(),传入卷号或者箱号
	 * 分条/包装生产下线
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doProduceOutLine(CommonPage<YdmProductDetail> cp)
	{
		ResultModel rm=new ResultModel();
		String username=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		YdmProductDetail ypd=cp.getObject();
		if((ypd.getCoilno()!=null&&ypd.getCoilno()!="")||(ypd.getBoxno()!=null&&ypd.getBoxno()!=""))
		{
			YdmProductDetail ypdtest=this.getMapper(YdmProductDetailMapper.class).doFind(ypd.getCoilno(), ypd.getBoxno());
			if(ypdtest!=null)
			{
				rm.setState("500");
				rm.setMsgInfo("已存在对应箱号/卷号的库存信息!");
			}
			else 
			{
				//新增库存记录
				if(ypd.getStorageattr()!=null&&!"".equals(ypd.getStorageattr()))
				{
					ypd.setManagementno(this.getMapper(YdmBaseButtressconfigMapper.class).GetManagementNo(ypd.getStorageattr()));
				}
				ypd.setCreatedate(new Date());
				ypd.setCreater(username);
				ypd.setJudgesteelcode(ypd.getSteelcode());
				ypd.setState("-1");
				ypd.setSource("0");
				this.getMapper(YdmProductDetailMapper.class).doInsert(ypd);
			}
		}
		else 
		{
			rm.setState("500");
			rm.setMsgInfo("传入的卷号/箱号均为空!");
		}
		return rm;
	}

	/**
	 * cp.getObject();传入卷号或者箱号
	 * 入库撤销
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doCancelIn(CommonPage<YdmProductDetail> cp) throws Exception
	{
		ResultModel rm=new ResultModel();
		YdmProductDetail ypd=cp.getObject();
		if((ypd.getCoilno()!=null&&!"".equals(ypd.getCoilno()))||(ypd.getBoxno()!=null&&!"".equals(ypd.getBoxno())))
		{
			YdmProductDetail ypd1=this.getMapper(YdmProductDetailMapper.class).doFind(ypd.getCoilno(), ypd.getBoxno());
			if(ypd1!=null&&"-1".equals(ypd1.getState()))
			{
				this.getMapper(YdmProductDetailMapper.class).doDelete(ypd.getCoilno(), ypd.getBoxno());
			}
			else 
			{
				throw new Exception();
			}
		}
		else 
		{
			rm.setState("500");
			rm.setMsgInfo("传入的卷号/箱号为空!");
		}
		return rm;
	}

	/**
	 * 新钢原料卷获取
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doGetRoll() throws Exception {
		ResultModel rm=new ResultModel();
		IfRawMtrCoilMMid mmid = new IfRawMtrCoilMMid();
		mmid.setStatus("0");
		List<IfRawMtrCoilMMid> list=this.getMapper(IfRawMtrCoilMMidMapper.class).find(mmid, 0, 0);
		if(list!=null&&list.size()>0) {
			for(IfRawMtrCoilMMid mid:list) {
				String chemid="";
				String physid="";
				//成分处理
				if(mid.getHeatno()!=null&&mid.getHeatno()!="") {
					IfRawMtrCoilChem Chem=new IfRawMtrCoilChem();
					Chem.setHeatno(mid.getHeatno());
					Chem.setSource("0");
					List<IfRawMtrCoilChem> lchem=this.getMapper(IfRawMtrCoilChemMapper.class).find(Chem,0,0);
					if(lchem!=null&&lchem.size()>0) {
						for(IfRawMtrCoilChem chem1:lchem) {
							chemid=chem1.getChemid();
						}
					}
					else {
						chemid=this.getBean(IfRawMtrCoilChemServiceImpl.class).createXGChemID();
					}
					IfRawMtrCoilChemMid chemMid=new IfRawMtrCoilChemMid();
					chemMid.setHeatno(mid.getHeatno());

					List<IfRawMtrCoilChemMid> lchemMid=this.getMapper(IfRawMtrCoilChemMidMapper.class).find(chemMid, 0, 0);
					if(lchemMid!=null&&lchemMid.size()>0) {
						for(IfRawMtrCoilChemMid chemmid:lchemMid) {
							IfRawMtrCoilChem chem2=new IfRawMtrCoilChem();
							chem2.setChemid(chemid);
							chem2.setChemCode(chemmid.getChemCode());
							chem2.setCreateOpr(chemmid.getCreateOpr());
							chem2.setCreateTime(chemmid.getCreateTime());
							chem2.setSource("0");
							chem2.setHeatno(mid.getHeatno());
							chem2.setChemValue(chemmid.getChemValue());
							chem2.setInspectTime(chemmid.getInspectTime());
							chem2.setRemark(chemmid.getRemark());
							this.getMapper(IfRawMtrCoilChemMapper.class).insert(chem2);
						}
					}
				}
				//材质处理
				if(mid.getSmpNo()!=null&&mid.getSmpNo()!="")
				{
					IfRawMtrCoilPfmc pfmc=new IfRawMtrCoilPfmc();
					pfmc.setSmpNo(mid.getSmpNo());
					pfmc.setSource("0");
					List<IfRawMtrCoilPfmc> lpfmc=this.getMapper(IfRawMtrCoilPfmcMapper.class).find(pfmc,0,0);
					if(lpfmc!=null&&lpfmc.size()>0)
					{
						for(IfRawMtrCoilPfmc pfmc1:lpfmc)
						{
							physid=pfmc1.getPhysid();
						}
					}
					else 
					{
						physid=this.getBean(IfRawMtrCoilPfmcServiceImpl.class).createXGPhySID();
					}
					IfRawMtrCoilPfmcMid pfmcMid=new IfRawMtrCoilPfmcMid();
					pfmcMid.setSmpNo(mid.getSmpNo());
					List<IfRawMtrCoilPfmcMid> lpfmcMid=this.getMapper(IfRawMtrCoilPfmcMidMapper.class).find(pfmcMid, 0, 0);
					if(lpfmcMid!=null&&lpfmcMid.size()>0)
					{
						for(IfRawMtrCoilPfmcMid pfmcmid:lpfmcMid)
						{
							IfRawMtrCoilPfmc pfmc2=new IfRawMtrCoilPfmc();
							pfmc2.setPhysid(physid);
							pfmc2.setSmpNo(mid.getSmpNo());



							pfmc2.setCreateOpr(pfmcmid.getCreateOpr());
							pfmc2.setCreateTime(pfmcmid.getCreateTime());
							pfmc2.setSource("0");

							pfmc2.setPfmcCode(pfmcmid.getPfmcCode());
							pfmc2.setPfmcName(pfmcmid.getPfmcName());
							pfmc2.setPfmcValue((double) pfmcmid.getPfmcValue());
							pfmc2.setPfmcTypeCode(pfmcmid.getPfmcTypeCode());
							pfmc2.setPfmcTypeName(pfmcmid.getPfmcTypeName());
							pfmc2.setPfmcUnitCode(pfmcmid.getPfmcUnitCode());
							pfmc2.setPfmcUnitName(pfmcmid.getPfmcUnitName());
							pfmc2.setInspectTime(pfmcmid.getInspectTime());
							pfmc2.setRemark(pfmcmid.getRemark());
							this.getMapper(IfRawMtrCoilPfmcMapper.class).doInsert(pfmc2);
						}
					}
				}
				//插入原料主实绩
				IfRawMtrCoilM m=new IfRawMtrCoilM();

				DataHelper.CopyEntity(mid, m);

				//				m.setCoilNo(mid.getCoilNo());
				m.setCoilSource("0");
				//				m.setCoilSort(mid.getCoilSort());
				//				m.setSupplierCode(mid.getSupplierCode());
				//				m.setSupplierName(mid.getSupplierName());
				//				m.setHeatno(mid.getHeatno());
				//				m.setSmpNo(mid.getSmpNo());
				//				m.setPrdCode(mid.getPrdCode());
				//				m.setPrdName(mid.getPrdName());
				//				m.setStdCode(mid.getStdCode());
				//				m.setStdName(mid.getStdName());
				//				m.setSteelCode(mid.getSteelCode());
				//				m.setSteelName(mid.getSteelName());
				//				m.setCoilThk(mid.getCoilThk());
				//				m.setCoilWdt(mid.getCoilWdt());
				//				m.setCoilLen(mid.getCoilLen());
				//				m.setCoilInnDia(mid.getCoilInnDia());
				//				m.setCoilOutDia(mid.getCoilOutDia());
				//				m.setCoilThrWgt(mid.getCoilThrWgt());
				//				m.setCoilActWgt(mid.getCoilActWgt());
				//				m.setProduceTime(mid.getProduceTime());
				//				m.setFlawCode1(mid.getFlawCode1());
				//				m.setFlawCode2(mid.getFlawCode2());
				//				m.setFlawCode3(mid.getFlawCode3());
				//				m.setFlawCode4(mid.getFlawCode4());
				//				m.setFlawCode5(mid.getFlawCode5());
				//				m.setFlawName1(mid.getFlawName1());
				//				m.setFlawName2(mid.getFlawName2());
				//				m.setFlawName3(mid.getFlawName3());
				//				m.setFlawName4(mid.getFlawName4());
				//				m.setFlawName5(mid.getFlawName5());
				//				m.setChemDecRstCode(mid.getChemDecRstCode());
				//				m.setChemDecRstName(mid.getChemDecRstName());
				//				m.setSurfaceDecRstCode(mid.getSurfaceDecRstCode());
				//				m.setSurfaceDecRstName(mid.getSurfaceDecRstName());
				//				m.setSizeDecRstCode(mid.getSizeDecRstCode());
				//				m.setSizeDecRstName(mid.getSizeDecRstName());
				//				m.setPfmcDecRstCode(mid.getPfmcDecRstCode());
				//				m.setPfmcDecRstName(mid.getPfmcDecRstName());
				//				m.setWgtDecRstCode(mid.getWgtDecRstCode());
				//				m.setWgtDecRstName(mid.getWgtDecRstName());
				//				m.setTotalDecRstCode(mid.getTotalDecRstCode());
				//				m.setTotalDecRstName(mid.getTotalDecRstName());
				m.setStatus("0");
				//				m.setRemark(mid.getRemark());
				//				m.setCreateOpr(mid.getCreateOpr());
				//				m.setCreateTime(mid.getCreateTime());
				m.setChemid(chemid);
				m.setPhysid(physid);
				this.getMapper(IfRawMtrCoilMMapper.class).insert(m);

				mid.setStatus("1");
				this.getMapper(IfRawMtrCoilMMidMapper.class).update(mid);
			}
			rm.setState("200");
		}
		else 
		{
			rm.setState("500");
			rm.setState("原料库中间表为空!");
		}
		return rm;
	}

	/**
	 *分条脱单 库存品查询
	 * */
	public ResultModel doQueryWebBySQLOutBill(CommonPage<YdmProductDetail> cp) {
		ResultModel rm=new ResultModel();
		int pageIndex=cp.getPageIndex();
		int pageSize=cp.getPageSize();
		PageModel<YdmProductDetail> pm = new PageModel<YdmProductDetail>(pageIndex,pageSize);
		try {
			Object wjmin="",wjmax="";
			if(cp.getMemo1()!=null&&cp.getMemo1()!="") 
				wjmin=Double.valueOf(cp.getMemo1()).doubleValue();
			if(cp.getMemo2()!=null&&cp.getMemo2()!="")
				wjmax=Double.valueOf(cp.getMemo2()).doubleValue();
			Object thick,width;
			if(cp.getObject().getThick() ==null || cp.getObject().getThick()==0)
				thick="";
			else 
				thick=cp.getObject().getThick();
			if(cp.getObject().getWidth() ==null || cp.getObject().getWidth()==0)
				width="";
			else 
				width=cp.getObject().getWidth();
			pm.setRows(this.getMapper(YdmProductDetailMapper.class).doQueryWebBySQLOutBill
					((pageIndex-1)*pageSize, (pageIndex-1)*pageSize+pageSize, cp.getStartTime(), cp.getEndTime(), cp.getObject().getCoilno(), cp.getObject().getJudgesteelcode(), 
							thick,width,wjmin,wjmax,cp.getObject().getContract_no(),cp.getObject().getOrderno()));
			pm.setTotal(this.getMapper(YdmProductDetailMapper.class).doQueryWebBySQLOutBillCount
					(cp.getStartTime(), cp.getEndTime(), cp.getObject().getCoilno(), cp.getObject().getJudgesteelcode(), 
							thick,width,wjmin,wjmax,cp.getObject().getContract_no(),cp.getObject().getOrderno()));
			rm.setData(pm);
			rm.setState("200");
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("服务端异常，查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}

	/**
	 *分条挂单 库存品查询
	 * */
	public ResultModel doQueryWebBySQLOnBill(CommonPage<YdmProductDetail> cp)
	{
		ResultModel rm=new ResultModel();
		int pageIndex=cp.getPageIndex();
		int pageSize=cp.getPageSize();
		PageModel<YdmProductDetail> pm = new PageModel<YdmProductDetail>(pageIndex,pageSize);
		try {
			Object wjmin="",wjmax="",thickmin="",thickmax="";
			if(cp.getMemo1()!=null&&!"".equals(cp.getMemo1()))
				wjmin=Double.valueOf(cp.getMemo1()).doubleValue();
			if(cp.getMemo2()!=null&&!"".equals(cp.getMemo2()))
				wjmax=Double.valueOf(cp.getMemo2()).doubleValue();

			if(cp.getMemo3()!=null&&!"".equals(cp.getMemo3()))
				thickmin=Double.valueOf(cp.getMemo3()).doubleValue();
			if(cp.getMemo4()!=null&&!"".equals(cp.getMemo4()))
				thickmax=Double.valueOf(cp.getMemo4()).doubleValue();

			Object thick,width;
			if(cp.getObject().getThick()!=null&&cp.getObject().getThick()==0)
				thick="";
			else 
				thick=cp.getObject().getThick();
			if(cp.getObject().getWidth()!=null&&cp.getObject().getWidth()==0)
				width="";
			else 
				width=cp.getObject().getWidth();
			String order =null,condition = null ,ord_pk = null ;
			// 匹配采购订单号
			if (cp.getObject().getOrderno()!=null&&!"".equals(cp.getObject().getOrderno())) {
				ResultModel rms =this.getBean(MesApiServiceImpl.class).getPurchaseContractNoInfo(cp.getObject().getOrderno());
				if (rms.getData()==null) {
					order =null;
				}else {
					order =rms.getData().toString();
				}
			}
			// 拆分订单所挂物料锁定在原订单范围内
			if (cp.getObject().getMaterailorderno()!=null&&!"".equals(cp.getObject().getMaterailorderno())) {
				List<PlnProdorder> lppq = this.getMapper(PlnProdorderMapper.class)
						.findWithCondition(null, " order_no = '"+cp.getObject().getMaterailorderno()+"'", null, 0, 1);
				// 是拆分订单
				if (Utils.isNotEmpty(lppq) && lppq.get(0).getIs_split() != null && "1".equals(lppq.get(0).getIs_split())) {
					// 获取原订单数据
					List<PlnProdorder> lppo = this.getMapper(PlnProdorderMapper.class)
							.findWithCondition(null, " ord_pk = '"+lppq.get(0).getP_order_no()+"'", null, 0, 1);
//					condition = " (select distinct object_no from pln_mat_replace_log where length(object_no) > 8 and order_no = '"+lppo.get(0).getOrder_no()+"')";
					// 有可能被拆分的订单就没有经过加工, 卷号还是没变.
					condition = " (select distinct object_no from pln_mat_replace_log where order_no = '"+lppo.get(0).getOrder_no()+"')";
				}
			}
			if((cp.getObject().getJudgesteelcode()==null||"".equals(cp.getObject().getJudgesteelcode()))&&cp.getObject().getSteelcode()!=null&&!"".equals(cp.getObject().getSteelcode()))
				cp.getObject().setJudgesteelcode(cp.getObject().getSteelcode());

			pm.setRows(this.getMapper(YdmProductDetailMapper.class).doQueryWebBySQLOnBill(
					(pageIndex-1)*pageSize, (pageIndex-1)*pageSize+pageSize, null, null, cp.getObject().getCoilno(), cp.getObject().getSteel_name(), 
					thick,width,null,null,cp.getObject().getJudgesteelcode()
					,thickmin,thickmax,order,cp.getObject().getOrder_nature(),cp.getObject().getStorageattr(),cp.getObject().getOrder_nature()
					,cp.getObject().getMaterailcoilno(),cp.getMemo5(),condition)
					

					);
			pm.setTotal(this.getMapper(YdmProductDetailMapper.class).doQueryWebBySQLOnBillCount
					(null, null, cp.getObject().getCoilno(), cp.getObject().getSteel_name(), 
							thick,width,null,null,cp.getObject().getJudgesteelcode()
							,thickmin,thickmax,order,cp.getObject().getOrder_nature(),cp.getObject().getStorageattr(),cp.getObject().getOrder_nature()
							,cp.getObject().getMaterailcoilno(),cp.getMemo5(),condition
							));
			rm.setData(pm);
			rm.setState("200");
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("服务端异常，查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}

	/**
	 *开平挂单 库存品查询
	 * */
	public ResultModel doQueryCuttoLengthWeb(CommonPage<YdmProductDetail> cp)
	{
		ResultModel rm=new ResultModel();
		int pageIndex=cp.getPageIndex();
		int pageSize=cp.getPageSize();
		PageModel<YdmProductDetail> pm = new PageModel<YdmProductDetail>(pageIndex,pageSize);
		try
		{
			Object wjmin="",wjmax="",thickmin="",thickmax="";
			if(cp.getMemo1()!=null&&!"".equals(cp.getMemo1()))
				wjmin=Double.valueOf(cp.getMemo1()).doubleValue();
			if(cp.getMemo2()!=null&&!"".equals(cp.getMemo2()))
				wjmax=Double.valueOf(cp.getMemo2()).doubleValue();

			if(cp.getMemo3()!=null&&!"".equals(cp.getMemo3()))
				thickmin=Double.valueOf(cp.getMemo3()).doubleValue();
			if(cp.getMemo4()!=null&&!"".equals(cp.getMemo4()))
				thickmax=Double.valueOf(cp.getMemo4()).doubleValue();

			Object thick,width;
			if(cp.getObject().getThick()!=null&&cp.getObject().getThick()==0)
				thick="";
			else 
				thick=cp.getObject().getThick();
			if(cp.getObject().getWidth()!=null&&cp.getObject().getWidth()==0)
				width="";
			else 
				width=cp.getObject().getWidth();
			String order =null,condition = null ,ord_pk = null ;
			// 匹配采购订单号
			if (cp.getObject().getOrderno()!=null&&!"".equals(cp.getObject().getOrderno())) {
				ResultModel rms =this.getBean(MesApiServiceImpl.class).getPurchaseContractNoInfo(cp.getObject().getOrderno());
				if (rms.getData()==null) {
					order =null;
				}else {
					order =rms.getData().toString();
				}
			}
			// 拆分订单所挂物料锁定在原订单范围内
			if (cp.getObject().getMaterailorderno()!=null&&!"".equals(cp.getObject().getMaterailorderno())) {
				List<PlnProdorder> lppq = this.getMapper(PlnProdorderMapper.class)
						.findWithCondition(null, " order_no = '"+cp.getObject().getMaterailorderno()+"'", null, 0, 1);
				// 是拆分订单
				if (Utils.isNotEmpty(lppq) && lppq.get(0).getIs_split() != null && "1".equals(lppq.get(0).getIs_split())) {
					// 获取原订单数据
					List<PlnProdorder> lppo = this.getMapper(PlnProdorderMapper.class)
							.findWithCondition(null, " ord_pk = '"+lppq.get(0).getP_order_no()+"'", null, 0, 1);
//					condition = " (select distinct object_no from pln_mat_replace_log where length(object_no) > 8 and order_no = '"+lppo.get(0).getOrder_no()+"')";
					// 有可能被拆分的订单就没有经过加工, 卷号还是没变.
					condition = " (select distinct object_no from pln_mat_replace_log where order_no = '"+lppo.get(0).getOrder_no()+"')";
				}
			}
			if((cp.getObject().getJudgesteelcode()==null||"".equals(cp.getObject().getJudgesteelcode()))&&cp.getObject().getSteelcode()!=null&&!"".equals(cp.getObject().getSteelcode()))
				cp.getObject().setJudgesteelcode(cp.getObject().getSteelcode());

			pm.setRows(this.getMapper(YdmProductDetailMapper.class).doQueryCuttoLengthWeb(
					(pageIndex-1)*pageSize, (pageIndex-1)*pageSize+pageSize, null, null, cp.getObject().getCoilno(), cp.getObject().getSteel_name(), 
					thick,width,null,null,cp.getObject().getJudgesteelcode()
					,thickmin,thickmax,order,cp.getObject().getOrder_nature(),cp.getObject().getStorageattr(),cp.getObject().getOrder_nature()
					,cp.getObject().getMaterailcoilno(),cp.getMemo5(),condition)
					);
			pm.setTotal(this.getMapper(YdmProductDetailMapper.class).doQueryCuttoLengthWebCount
					(null, null, cp.getObject().getCoilno(), cp.getObject().getSteel_name(), 
							thick,width,null,null,cp.getObject().getJudgesteelcode()
							,thickmin,thickmax,order,cp.getObject().getOrder_nature(),cp.getObject().getStorageattr(),cp.getObject().getOrder_nature()
							,cp.getObject().getMaterailcoilno(),cp.getMemo5(),condition
							));
			rm.setData(pm);
			rm.setState("200");
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("服务端异常，查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}

	/**
	 *罩退挂单 库存品查询
	 * */
	public ResultModel doQueryAnnealWeb(CommonPage<YdmProductDetail> cp) {
		ResultModel rm=new ResultModel();
		int pageIndex=cp.getPageIndex();
		int pageSize=cp.getPageSize();
		PageModel<YdmProductDetail> pm = new PageModel<YdmProductDetail>(pageIndex,pageSize);
		try {
			Object wjmin="",wjmax="",thickmin="",thickmax="";
			if(cp.getMemo1()!=null&&!"".equals(cp.getMemo1()))
				wjmin=Double.valueOf(cp.getMemo1()).doubleValue();
			if(cp.getMemo2()!=null&&!"".equals(cp.getMemo2()))
				wjmax=Double.valueOf(cp.getMemo2()).doubleValue();

			if(cp.getMemo3()!=null&&!"".equals(cp.getMemo3()))
				thickmin=Double.valueOf(cp.getMemo3()).doubleValue();
			if(cp.getMemo4()!=null&&!"".equals(cp.getMemo4()))
				thickmax=Double.valueOf(cp.getMemo4()).doubleValue();

			Object thick,width;
			if(cp.getObject().getThick()!=null&&cp.getObject().getThick()==0)
				thick="";
			else 
				thick=cp.getObject().getThick();
			if(cp.getObject().getWidth()!=null&&cp.getObject().getWidth()==0)
				width="";
			else 
				width=cp.getObject().getWidth();
			String order =null , condition = null ,ord_pk = null ;
			// 匹配采购订单号
			if (cp.getObject().getOrderno()!=null&&!"".equals(cp.getObject().getOrderno())) {
				ResultModel rms =this.getBean(MesApiServiceImpl.class).getPurchaseContractNoInfo(cp.getObject().getOrderno());
				if (rms.getData()==null) {
					order =null;
				}else {
					order =rms.getData().toString();
				}
			}
			// 拆分订单所挂物料锁定在原订单范围内
			if (cp.getObject().getMaterailorderno()!=null&&!"".equals(cp.getObject().getMaterailorderno())) {
				List<PlnProdorder> lppq = this.getMapper(PlnProdorderMapper.class)
						.findWithCondition(null, " order_no = '"+cp.getObject().getMaterailorderno()+"'", null, 0, 1);
				// 是拆分订单
				if (Utils.isNotEmpty(lppq) && lppq.get(0).getIs_split() != null && "1".equals(lppq.get(0).getIs_split())) {
					// 获取原订单数据
					List<PlnProdorder> lppo = this.getMapper(PlnProdorderMapper.class)
							.findWithCondition(null, " ord_pk = '"+lppq.get(0).getP_order_no()+"'", null, 0, 1);
//					condition = " (select distinct object_no from pln_mat_replace_log where length(object_no) > 8 and order_no = '"+lppo.get(0).getOrder_no()+"')";
					// 有可能被拆分的订单就没有经过加工, 卷号还是没变.
					condition = " (select distinct object_no from pln_mat_replace_log where order_no = '"+lppo.get(0).getOrder_no()+"')";
				}
			}
			if((cp.getObject().getJudgesteelcode()==null||"".equals(cp.getObject().getJudgesteelcode()))&&cp.getObject().getSteelcode()!=null&&!"".equals(cp.getObject().getSteelcode()))
				cp.getObject().setJudgesteelcode(cp.getObject().getSteelcode());

			pm.setRows(this.getMapper(YdmProductDetailMapper.class).doQueryAnnealWeb(
					(pageIndex-1)*pageSize, (pageIndex-1)*pageSize+pageSize, null, null, cp.getObject().getCoilno(), cp.getObject().getSteel_name(), 
					thick,width,null,null,cp.getObject().getJudgesteelcode()
					,thickmin,thickmax,order,cp.getObject().getOrder_nature(),cp.getObject().getStorageattr(),cp.getObject().getOrder_nature()
					,cp.getObject().getMaterailcoilno(),cp.getMemo5(),condition)
					);
			pm.setTotal(this.getMapper(YdmProductDetailMapper.class).doQueryAnnealWebCount
					(null, null, cp.getObject().getCoilno(), cp.getObject().getSteel_name(), 
							thick,width,null,null,cp.getObject().getJudgesteelcode()
							,thickmin,thickmax,order,cp.getObject().getOrder_nature(),cp.getObject().getStorageattr(),cp.getObject().getOrder_nature()
							,cp.getObject().getMaterailcoilno(),cp.getMemo5(),condition
							));
			rm.setData(pm);
			rm.setState("200");
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("服务端异常，查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	/**
	 *轧制挂单 库存品查询
	 * @throws Exception 
	 * */
	public ResultModel doQueryRollingWeb(CommonPage<YdmProductDetail> cp) throws Exception
	{
		ResultModel rm=new ResultModel();
		int pageIndex=cp.getPageIndex();
		int pageSize=cp.getPageSize();
		
		PageModel<YdmProductDetail> pm = new PageModel<YdmProductDetail>(pageIndex,pageSize);
		// 工序点信息
		List<ComBaseInfo> infoI = this.getMapper(ComBaseInfoMapper.class).findWithCondition(null,
				"sort_code = '2002' AND validflag = '1'", null, 0, 0);
		ProcessPoint processpoint = new ProcessPoint(infoI);
		Object thickmin="",thickmax="";
		// 如果生产订单号不为空获取入口厚度范围
		if (Utils.isNotEmpty(cp.getObject().getProdorderno())) {
			// 获取生产订单信息
			List<PlnProdorder> ppo = this.getMapper(PlnProdorderMapper.class)
					.findWithCondition(null, " prod_order_no = '"+cp.getObject().getProdorderno()+"'", null, 0, 1);
			// 获取质量设计信息取第一次轧制
			SlmOrdDesignMscPlSti sti = new SlmOrdDesignMscPlSti();
//			List<SlmOrdDesignMscTic> tics = new ArrayList<SlmOrdDesignMscTic>();
			sti.setDesign_key(ppo.get(0).getDesign_key());
			sti.setMsc_pline(ppo.get(0).getMsc_pline());
			sti.setProcess_code(processpoint.rolling_code);
			
			List<SlmOrdDesignMscPlSti> stis = this.getBean(MesApiDesignInfoImpl.class).getQcmDesignInfo(sti);
//			for (SlmOrdDesignMscPlSti pl : stis) {
//				SlmOrdDesignMscTic tmp = new SlmOrdDesignMscTic();
//				BeanUtils.copyProperties(pl, tmp);
//				tmp.setPline_code("C016");
//				tmp.setMachine_code("M0008");
//				tics.add(tmp);
//			}
			SlmOrdDesignMscTic tmp = new SlmOrdDesignMscTic();
			BeanUtils.copyProperties(stis.get(0), tmp);
			tmp.setPline_code("C016");
			tmp.setMachine_code("M0008");
			CommonPage<SlmOrdDesignMscTic> com = new CommonPage<SlmOrdDesignMscTic>();
			com.setObject(tmp);
			ResultModel tic_f = this.getBean(QmsApiServiceImpl.class).getGongYi(com);
			if ("500".equals(tic_f.getState())) {
				throw new Exception("获取["+tmp.getProcess_point_desc()+"]工艺标准失败!"+tic_f.getMsgInfo());
			}
			List<SlmOrdDesignMscTicItem> item_f = (List<SlmOrdDesignMscTicItem>) tic_f.getData();
			if (Utils.isNotEmpty(item_f)) {
			// 获取轧制原卷和成品厚度范围的代码
			List<PbModelDb> code = this.getBean(MesApiDesignInfoImpl.class).getBase_Name("201001");
			if (item_f.get(0).getCraft_param_code().equals(code.get(0).getText())) {
				if (Utils.isNotEmpty(item_f.get(0).getMin_value())) {
					thickmin = Double.valueOf(item_f.get(0).getMin_value());
				}
				if (Utils.isNotEmpty(item_f.get(0).getMax_value())) {
					thickmax = Double.valueOf(item_f.get(0).getMax_value());
				}
			}
			
//			for (SlmOrdDesignMscTicItem slm : item_f) {
//				// 入口厚度
//				if (slm.getCraft_param_code().equals(code.get(0).getText())) {
//					if (Utils.isNotEmpty(slm.getMin_value())) {
//						thickmin = Double.valueOf(slm.getMin_value());
//					}
//					if (Utils.isNotEmpty(slm.getMax_value())) {
//						thickmax = Double.valueOf(slm.getMax_value());
//					}
//					break;
//				}
//			}
		  }
		}
		
		try
		{
			Object thick,width;
			if(cp.getObject().getThick()!=null&&cp.getObject().getThick()==0)
				thick="";
			else 
				thick=cp.getObject().getThick();
			if(cp.getObject().getWidth()!=null&&cp.getObject().getWidth()==0)
				width="";
			else 
				width=cp.getObject().getWidth();
			String order =null , condition = null ,ord_pk = null;
			// 匹配采购订单号
			if (cp.getObject().getOrderno()!=null&&!"".equals(cp.getObject().getOrderno())) {
				ResultModel rms =this.getBean(MesApiServiceImpl.class).getPurchaseContractNoInfo(cp.getObject().getOrderno());
				if (rms.getData()==null) {
					order =null;
				}else {
					order =rms.getData().toString();
				}
			}
			// 拆分订单所挂物料锁定在原订单范围内
			if (cp.getObject().getMaterailorderno()!=null&&!"".equals(cp.getObject().getMaterailorderno())) {
				List<PlnProdorder> lppq = this.getMapper(PlnProdorderMapper.class)
						.findWithCondition(null, " order_no = '"+cp.getObject().getMaterailorderno()+"'", null, 0, 1);
				// 是拆分订单
				if (Utils.isNotEmpty(lppq) && lppq.get(0).getIs_split() != null && "1".equals(lppq.get(0).getIs_split())) {
					// 获取原订单数据
					List<PlnProdorder> lppo = this.getMapper(PlnProdorderMapper.class)
							.findWithCondition(null, " ord_pk = '"+lppq.get(0).getP_order_no()+"'", null, 0, 1);
//					condition = " (select distinct object_no from pln_mat_replace_log where length(object_no) > 8 and order_no = '"+lppo.get(0).getOrder_no()+"')";
					// 有可能被拆分的订单就没有经过加工, 卷号还是没变.
					condition = " (select distinct object_no from pln_mat_replace_log where order_no = '"+lppo.get(0).getOrder_no()+"')";
				}
			}
			if((cp.getObject().getJudgesteelcode()==null||"".equals(cp.getObject().getJudgesteelcode()))&&cp.getObject().getSteelcode()!=null&&!"".equals(cp.getObject().getSteelcode()))
				cp.getObject().setJudgesteelcode(cp.getObject().getSteelcode());
			
			pm.setRows(this.getMapper(YdmProductDetailMapper.class).doQueryRollingWeb(
					(pageIndex-1)*pageSize, (pageIndex-1)*pageSize+pageSize, null, null, cp.getObject().getCoilno(), cp.getObject().getSteel_name(), 
					thick,width,null,null,cp.getObject().getJudgesteelcode()
					,thickmin,thickmax,order,cp.getObject().getOrder_nature(),cp.getObject().getStorageattr(),cp.getObject().getOrder_nature()
					,cp.getObject().getMaterailcoilno(),cp.getMemo5(),condition)
					);
			pm.setTotal(this.getMapper(YdmProductDetailMapper.class).doQueryRollingWebCount
					(null, null, cp.getObject().getCoilno(), cp.getObject().getSteel_name(), 
							thick,width,null,null,cp.getObject().getJudgesteelcode()
							,thickmin,thickmax,order,cp.getObject().getOrder_nature(),cp.getObject().getStorageattr(),cp.getObject().getOrder_nature()
							,cp.getObject().getMaterailcoilno(),cp.getMemo5(),condition
							));
			rm.setData(pm);
			rm.setState("200");
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("服务端异常，查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}


	/**
	 * Mes插入库存（大小纵剪 12mm---4mm）
	 * @throws Exception 
	 * */
	public  ResultModel doMesIn(CommonPage<MesCrSlittingD> cp) throws Exception{
		ResultModel rm = new ResultModel();
		String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		MesCrSlittingD mes=cp.getObject();
		String username=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		if(mes.getCoil_no()!=null&&mes.getCoil_no()!=""){
			MesCrSlittingD mesD=this.getMapper(MesCrSlittingDMapper.class).findById(mes.getCoil_no());

			if(mesD!=null){
				YdmProductDetail ypd=new YdmProductDetail();
				//调用库存接口存数据时,保存 虚拟物料号 ,机台代码，机台名称
				MesCrSlittingM mcsm = this.getMapper(MesCrSlittingMMapper.class).findById(mesD.getProcess_no());
				List<ComBaseMachine> listcom=this.getMapper(ComBaseMachineMapper.class).findWithCondition(null, "machine_code='"+mcsm.getMachine_code()+"'", null, 0, 0);
				ypd.setMachine_code(mcsm.getMachine_code());
				if(listcom!=null && listcom.size()>0){
					ypd.setMachine_name(listcom.get(0).getMachine_name());
				}
				List<YdmProductDetail> list = this.getMapper(YdmProductDetailMapper.class).findWithCondition(null, "coilno ='"+mcsm.getMaterial_no()+"'", null, 0, 0);
				if(list!=null && list.size()>0){
					ypd.setMaterailtype(list.get(0).getMaterailtype());
				}
				ypd.setObject_no_vt(mes.getCoil_no_vt());
				ypd.setOrderno(mesD.getOrder_no());
				ypd.setProdorderno(mesD.getProd_order_no());

				String order_pk="";
				if(mesD.getProd_order_no()!=null&&!"".equals(mesD.getProd_order_no())){
					PlnProdorder pp=new PlnProdorder();
					pp.setProd_order_no(mesD.getProd_order_no());
					List<PlnProdorder> lpp=this.getMapper(PlnProdorderMapper.class).find(pp, 0, 1);
					if(lpp!=null&&lpp.size()>0){
						ypd.setCustomer_no(lpp.get(0).getCustomer_no());
						ypd.setCustomer_nm(lpp.get(0).getCustomer_name());
						ypd.setPsc(lpp.get(0).getPsc());
						ypd.setDelivery_state_code(lpp.get(0).getDelivery_state_code());//交货状态
						ypd.setDelivery_state_desc(lpp.get(0).getDelivery_state_desc());
						ypd.setProd_code(lpp.get(0).getProd_code());
						ypd.setProd_name(lpp.get(0).getProd_name());
						ypd.setStd_code(lpp.get(0).getStd_code());
						ypd.setStd_name(lpp.get(0).getStd_name());
						ypd.setUse_code(lpp.get(0).getUse_code());
						ypd.setUse_name(lpp.get(0).getUser_name());
						ypd.setPlan_code(lpp.get(0).getPline_code());
						ypd.setPline_name(lpp.get(0).getPline_name());
						ypd.setReceiv_no(lpp.get(0).getReciver_unit_no());
						ypd.setReceiv_nm(lpp.get(0).getReciver_unit_name());
						order_pk=lpp.get(0).getOrd_pk();
					}

					//------------------------------------------2018-06-25 边丝单独处理(没有生产订单信息),取第一个子卷的生产订单信息。
				}else if (mes.getCoil_no()!=null && "B".equals(mes.getCoil_no().substring(mes.getCoil_no().length()-1))) {
					//如果第一个子卷xxx01没有。则返回的bsMesd为null。即findById没有找到对应的值，返回null。
					//MesCrSlittingD bsMesd=this.getMapper(MesCrSlittingDMapper.class).findById(mes.getCoil_no().substring(0, mes.getCoil_no().length()-1)+"1");
					List<MesCrSlittingD> bsMesd_list = this.getMapper(MesCrSlittingDMapper.class).findWithCondition(null, "coil_no like '%"+mes.getCoil_no().substring(0, mes.getCoil_no().length()-2)+"%' and order_no is not null and prod_order_no is not null ", 
							"coil_no", 0, 0);
					MesCrSlittingD bsMesd=null;
					if(bsMesd_list !=null && bsMesd_list.size()>0){
						bsMesd=bsMesd_list.get(0);
					}
					if(bsMesd!=null && bsMesd.getProd_order_no()!=null&&!"".equals(bsMesd.getProd_order_no())){
						PlnProdorder pp=new PlnProdorder();
						pp.setProd_order_no(bsMesd.getProd_order_no());
						List<PlnProdorder> lpp=this.getMapper(PlnProdorderMapper.class).find(pp, 0, 1);
						if(lpp!=null&&lpp.size()>0){
							ypd.setCustomer_no(lpp.get(0).getCustomer_no());
							ypd.setCustomer_nm(lpp.get(0).getCustomer_name());
							ypd.setPsc(lpp.get(0).getPsc());
							ypd.setDelivery_state_code(lpp.get(0).getDelivery_state_code());//交货状态
							ypd.setDelivery_state_desc(lpp.get(0).getDelivery_state_desc());
							ypd.setProd_code(lpp.get(0).getProd_code());
							ypd.setProd_name(lpp.get(0).getProd_name());
							ypd.setStd_code(lpp.get(0).getStd_code());
							ypd.setStd_name(lpp.get(0).getStd_name());
							ypd.setUse_code(lpp.get(0).getUse_code());
							ypd.setUse_name(lpp.get(0).getUser_name());
							ypd.setPlan_code(lpp.get(0).getPline_code());
							ypd.setPline_name(lpp.get(0).getPline_name());
							ypd.setProdorderno(bsMesd.getProd_order_no());
							ypd.setOrderno(bsMesd.getOrder_no());
							ypd.setReceiv_no(lpp.get(0).getReciver_unit_no());
							ypd.setReceiv_nm(lpp.get(0).getReciver_unit_name());
							order_pk=lpp.get(0).getOrd_pk();
						}
					}
				}
				ypd.setCreater(username);
				ypd.setCreatedate(new Date());
				ypd.setCoilno(mesD.getCoil_no());
				ypd.setSteelcode(mesD.getSteel_code());
				
				// 改为获取投料卷信息里的判定牌号：20240722刘侣 改回来不动 20240815
				ypd.setJudgesteelcode(mesD.getSteel_code());	
//				ypd.setJudgesteelcode(list.get(0).getJudgesteelcode());	
				
				
				ypd.setSurfaceresult(mesD.getSurface_rst());
				ypd.setProduceorder(mesD.getWrk_ord());
				ypd.setProduceteam(mesD.getWrk_grp());
				if (mesD.getWrk_date()!=null && !"".equals(mesD.getWrk_date())) {
					// new SimpleDateFormat("yyyy-MM-dd").parse(mesD.getWrk_date()) 改成当前时间
					ypd.setProducedate(new Date());					
				}
				//ypd.setProducedate(mesD.getProduce_time());
				ypd.setState("-1");
				ypd.setSource("0");
				if(cp.getMemo1()==null || "".equals(cp.getMemo1())){
					ypd.setStorageattr("500203");					
				}else{
					ypd.setStorageattr(cp.getMemo1());
				}
				ypd.setCoiltype("500203".equals(ypd.getStorageattr())?"2":"1");
				ypd.setThick(mesD.getAct_thk());
				ypd.setWidth(mesD.getAct_wdt());
				ypd.setLength(mesD.getAct_len());
				//20191018:包括目标宽度，目标厚度到库存表
				ypd.setLz_thick(mesD.getAim_thk());//合同厚度(目标厚度)
				ypd.setLz_width(mesD.getAim_wdt());//合同宽度(目标宽度)
				ypd.setDiameter_inn(mesD.getAct_inn_dia());
				ypd.setDiameter_out(mesD.getAct_out_dia());
				ypd.setFactweight(mesD.getCoil_act_wgt());
				ypd.setTheoryweight(mesD.getCoil_thr_wgt());
				ypd.setPsc("");
				ypd.setPlan_code("");
				ypd.setInspection_lot("");
				ypd.setObject_no_xg("");
				String order1=(String)this.getSession().getAttribute(HomeService.SESSION_WORK_ORD);
				String team1=(String)this.getSession().getAttribute(HomeService.SESSION_WORK_GRP);
				ypd.setInorder(order1);
				ypd.setInteam(team1);
				YdmProductDetail yyd=new YdmProductDetail();
				yyd = this.getMapper(YdmProductDetailMapper.class).doFind(mcsm.getMaterial_no(), null);
				if(yyd==null){
					yyd=new YdmProductDetail();
				}
				if(yyd.getMaterailcoilno()!=null&&!"".equals(yyd.getMaterailcoilno())){
					ypd.setMaterailcoilno(yyd.getMaterailcoilno());
				}
				//炉号
				if(yyd.getHeatno()!=null&&!"".equals(yyd.getHeatno())){
					ypd.setHeatno(yyd.getHeatno());
				}
				//增加物料属性
				if(yyd.getObject_attr()!=null&&!"".equals(yyd.getObject_attr())){
					ypd.setObject_attr(yyd.getObject_attr());
				}
				//2019-02-21  物料属性
				if(cp.getMemo3()!=null && !"".equals(cp.getMemo3())){
					ypd.setObject_attr(cp.getMemo3());
					ypd.setIsbl("1");
				}
				//检验号
				ypd.setInspection_lot(mesD.getInspection_lot());
				ypd.setBatchno(mcsm.getSchedule_no());

				if(yyd.getLzorderno()!=null&&!"".equals(yyd.getLzorderno()))
				{
					ypd.setLzorderno(yyd.getLzorderno());
				}

				//20190801 边丝和头尾卷默认综判判废//20191025 进废副品库
				String lastChar = ypd.getCoilno().substring(ypd.getCoilno().length()-1);
				if ("B".equals(lastChar) || "H".equals(lastChar)) {
					ypd.setJudgeresult("40740804");
					//20200317 净重的头尾卷及边丝入废钢库  毛重进成品库 黄涛提出
					String condition = "contract_no||contract_line_seq||order_seq = '"+ypd.getOrderno()+"' and nvl(change_flag,'0')<>'1'";
					List<SlmOrderInfo> soiList = this.getMapper(SlmOrderInfoMapper.class).findWithCondition(null, condition, null, 0, 0);
					if (soiList!=null && soiList.size()>0) {
						String weight_type_no = soiList.get(0).getWeight_type_no();
						if ("102301".equals(weight_type_no)) {//净重:入废副品库，脱单
							
							// 净重的头尾卷和边丝脱单后需要手动插入脱单信息：20230725刘侣
							// 前提是这个卷没有做过脱单插入：
							String conditiontd = " and OBJECT_NO = '"+ypd.getCoilno()+"' and OPT_TYPE = '0'";
							List<PlnMatReplaceLog> pmrList = this.getMapper(PlnMatReplaceLogMapper.class).findWithCondition(null, conditiontd, null, 0, 0);
							if (pmrList.size() == 0) {
								List<PlnMatReplaceLog> lmmrl = this.getMapper(PlnMatReplaceLogMapper.class).findWithCondition(null, "",
										" serial_no desc ", 0, 1);
								long iNo = 1;
								if (lmmrl != null && lmmrl.size() > 0) {
									iNo = lmmrl.get(0).getSerial_no() + 1;
								}
								PlnMatReplaceLog mmrl = new PlnMatReplaceLog();
								mmrl.setSerial_no(iNo++);
								mmrl.setObject_no(ypd.getCoilno());
								mmrl.setOpt_type("0");
								mmrl.setStatus("0");
								mmrl.setOrder_no(ypd.getOrderno());
								
								mmrl.setCreate_man_name(userName);
								mmrl.setCreate_time(new Date());
								mmrl.setMemo("净重头尾边丝卷补脱单信息");
								this.getMapper(PlnMatReplaceLogMapper.class).insert(mmrl);
							}
							
							// end
							
							ypd.setStorageattr("500210");
							ypd.setOrderno("");
							ypd.setProdorderno("");
							ypd.setObject_no_vt("");
							
						}else if ("102302".equals(weight_type_no)) {//毛重：进成品库，不脱单
							ypd.setStorageattr("500203");
							// 毛重头尾边丝默认合格：20231024刘侣
							ypd.setJudgeresult("40740801");
						}
					}
				}
				//包装状态(20191016)
				ypd.setIs_package("0");
				this.getMapper(YdmProductDetailMapper.class).insert(ypd);				

				//-------2018.3.27-----修改销售订单状态 -----vir-----
				if(mesD.getOrder_no()!=null&&mesD.getOrder_no().length()>6){
					String contract_no=mesD.getOrder_no().substring(0, mesD.getOrder_no().length()-6);
					String contract_line_seq=mesD.getOrder_no().substring(mesD.getOrder_no().length()-6, mesD.getOrder_no().length()-3);
					String order_seq=mesD.getOrder_no().substring(mesD.getOrder_no().length()-3);
					SlmOrderInfo order=new SlmOrderInfo();
					order.setContract_no(contract_no);
					order.setContract_line_seq(contract_line_seq);
					order.setOrder_seq(order_seq);
					order.setValid_flag("1");
					List<SlmOrderInfo> orderList=this.getBean(SlmOrderInfoServiceImpl.class).doQuery(order);
					boolean in=true;
					if(orderList.size()==1){
						order=orderList.get(0);
					}else if(orderList.size()>1 && order_pk!=null && (!"".equals(order_pk))){
						SlmOrderInfo pk_order=this.getMapper(SlmOrderInfoMapper.class).findById(order_pk);
						if(pk_order!=null)
							order=pk_order;
					}else{
						in=false;
					}
					if(in){
						order.setP_order_flag_no(order.getOrder_flag_no());
						order.setP_order_flag_name(order.getOrder_flag_name());
						order.setOrder_flag_no("103409");
						order.setOrder_flag_name("缴库");
						this.getBean(SlmOrderInfoServiceImpl.class).doUpdate(order);
						
					}
				}

			}
			else {
				rm.setState("500");
				rm.setMsgInfo("传入的主键为空!");
			}
		}
		rm.setState("200");
		return rm;
	}

	//===============20180709============================
	/**
	 * Mes横剪插入库存
	 * @throws Exception 
	 * */
	public  ResultModel doMesIn1(CommonPage<MesCrCrossCuttingD> cp) throws Exception{
		ResultModel rm = new ResultModel();

		MesCrCrossCuttingD mesxx=cp.getObject();
		String username=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		if(mesxx.getPacking_no()!=null&&mesxx.getPacking_no()!=""){
			MesCrCrossCuttingD mcccD=this.getMapper(MesCrCrossCuttingDMapper.class).findById(mesxx.getPacking_no());
			if(mcccD!=null){
				YdmProductDetail ypd=new YdmProductDetail();
				ypd.setObject_no_xg(mcccD.getPacking_no_ext());
				//调用库存接口存数据时,保存 虚拟物料号,机台代码，机台名称
				MesCrCrossCuttingM mcccm=new MesCrCrossCuttingM();
				mcccm.setProcess_no(mcccD.getProcess_no());
				MesCrCrossCuttingM mcsm = this.getMapper(MesCrCrossCuttingMMapper.class).findById(mcccm.getProcess_no());
				List<ComBaseMachine> listcom=this.getMapper(ComBaseMachineMapper.class).findWithCondition(null, "machine_code='"+mcsm.getMachine_code()+"'", null, 0, 0);
				ypd.setMachine_code(mcsm.getMachine_code());
				if(listcom!=null && listcom.size()>0){
					ypd.setMachine_name(listcom.get(0).getMachine_name());
				}		
				List<YdmProductDetail> list = this.getMapper(YdmProductDetailMapper.class).findWithCondition(null, "coilno ='"+mcsm.getMaterial_no()+"'", null, 0, 0);
				if(list!=null && list.size()>0){
					ypd.setMaterailtype(list.get(0).getMaterailtype());
				}

				//				//20180418新增 保存 虚拟物料号
				//				if(mcsm!=null){
				//					ypd.setObject_no_vt(mcsm.getMaterial_no_vt());//虚拟原料卷号
				//				}

				ypd.setMaterailcoilno(mcsm.getMaterial_no_src());
				ypd.setObject_no_vt(mcccD.getPacking_no_vt());
				ypd.setOrderno(mcccD.getOrder_no());
				ypd.setProdorderno(mcccD.getProd_order_no());
				String order_pk="";
				if(mcccD.getProd_order_no()!=null&&!"".equals(mcccD.getProd_order_no())){
					PlnProdorder pp=new PlnProdorder();
					pp.setProd_order_no(mcccD.getProd_order_no());
					List<PlnProdorder> lpp=this.getMapper(PlnProdorderMapper.class).find(pp, 0, 1);
					if(lpp!=null&&lpp.size()>0){
						pp = lpp.get(0);
						ypd.setCustomer_no(pp.getCustomer_no());
						ypd.setCustomer_nm(pp.getCustomer_name());
						ypd.setPsc(pp.getPsc());
						ypd.setDelivery_state_code(pp.getDelivery_state_code());//交货状态
						ypd.setDelivery_state_desc(pp.getDelivery_state_desc());
						ypd.setProd_code(pp.getProd_code());
						ypd.setProd_name(pp.getProd_name());
						ypd.setStd_code(pp.getStd_code());
						ypd.setStd_name(pp.getStd_name());
						ypd.setUse_code(pp.getUse_code());
						ypd.setUse_name(pp.getUser_name());
						ypd.setPlan_code(pp.getPline_code());
						ypd.setPline_name(pp.getPline_name());
						ypd.setSteelcode(pp.getSteel_code());
						ypd.setReceiv_no(pp.getReciver_unit_no());
						ypd.setReceiv_nm(pp.getReciver_unit_name()); 
					}

					//------------------------------------------2018-06-25 边丝单独处理(没有生产订单信息),取第一个子卷的生产订单信息。
				}else if (mcccD.getPacking_no()!=null && "B".equals(mcccD.getPacking_no().substring(mcccD.getPacking_no().length()-1))) {
					//MesCrCrossCuttingD bsMesd=this.getMapper(MesCrCrossCuttingDMapper.class).findById(mcccD.getPacking_no().substring(0, mcccD.getPacking_no().length()-1)+"1");
					List<MesCrCrossCuttingD> bsMesd_list = this.getMapper(MesCrCrossCuttingDMapper.class).findWithCondition(null, "packing_no like '%"+mcccD.getPacking_no().substring(0, mcccD.getPacking_no().length()-2)+"%' and order_no is not null and prod_order_no is not null ", 
							"packing_no", 0, 0);
					MesCrCrossCuttingD bsMesd=null;
					if(bsMesd_list!=null && bsMesd_list.size()>0){
						bsMesd=bsMesd_list.get(0);
					}
					if(bsMesd!=null && bsMesd.getProd_order_no()!=null&&!"".equals(bsMesd.getProd_order_no())){
						PlnProdorder pp=new PlnProdorder();
						pp.setProd_order_no(bsMesd.getProd_order_no());
						List<PlnProdorder> lpp=this.getMapper(PlnProdorderMapper.class).find(pp, 0, 1);
						if(lpp!=null&&lpp.size()>0){
							ypd.setProdorderno(bsMesd.getProd_order_no());
							ypd.setOrderno(bsMesd.getOrder_no());
							ypd.setPsc(lpp.get(0).getPsc());
							ypd.setDelivery_state_code(lpp.get(0).getDelivery_state_code());//交货状态
							ypd.setDelivery_state_desc(lpp.get(0).getDelivery_state_desc());
							ypd.setProd_code(lpp.get(0).getProd_code());
							ypd.setProd_name(lpp.get(0).getProd_name());
							ypd.setStd_code(lpp.get(0).getStd_code());
							ypd.setStd_name(lpp.get(0).getStd_name());
							ypd.setUse_code(lpp.get(0).getUse_code());
							ypd.setUse_name(lpp.get(0).getUser_name());
							ypd.setPline_name(lpp.get(0).getPline_name());
							ypd.setCustomer_no(lpp.get(0).getCustomer_no());
							ypd.setCustomer_nm(lpp.get(0).getCustomer_name());
							ypd.setReceiv_no(lpp.get(0).getReciver_unit_no());
							ypd.setReceiv_nm(lpp.get(0).getReciver_unit_name());
							order_pk=lpp.get(0).getOrd_pk();
						}
					}
				}
				ypd.setCreater(username);
				ypd.setCreatedate(new Date());
				ypd.setCoilno(mcccD.getPacking_no());
				ypd.setSteelcode(mcccD.getSteel_code());
				ypd.setJudgesteelcode(mcccD.getSteel_code());
				ypd.setSurfaceresult(mcccD.getSurface_rst());
				ypd.setProduceorder(mcccD.getWrk_ord());
				ypd.setProduceteam(mcccD.getWrk_grp());
				if (mcccD.getWrk_date()!=null && !"".equals(mcccD.getWrk_date())) {
					ypd.setProducedate(new SimpleDateFormat("yyyy-MM-dd").parse(mcccD.getWrk_date()));				
				}
				//ypd.setProducedate(mcccD.getProduce_time());
				ypd.setState("-1");
				ypd.setSource("0");
				if(cp.getMemo1()==null || "".equals(cp.getMemo1())){
					ypd.setStorageattr("500203");
				}else{
					ypd.setStorageattr(cp.getMemo1());
				}
				ypd.setCoiltype("500203".equals(ypd.getStorageattr())?"2":"1");
				ypd.setThick(mcccD.getAct_thk());
				ypd.setWidth(mcccD.getAct_wdt());
				ypd.setLength(mcccD.getAct_len());
				//20191018:包括目标宽度，目标厚度到库存表
				ypd.setLz_thick(mcccD.getAim_thk());//合同厚度(目标厚度)
				ypd.setLz_width(mcccD.getAim_wdt());//合同宽度(目标宽度)
				//ypd.setDiameter_inn(mcccD.getAct_inn_dia());
				//ypd.setDiameter_out(mcccD.getAct_out_dia());
				//ypd.setProducedate(mcccD.getProduce_time());
				ypd.setFactweight(mcccD.getPacking_net_wgt());
				ypd.setTheoryweight(mcccD.getPacking_thr_wgt());

				//20180709
				ypd.setGrossweight(mcccD.getPacking_ttl_wgt());
				//库存的块数
				if(mcccD.getPlate_cnt()!=null){
					ypd.setQuantity(mcccD.getPlate_cnt().intValue());
				}

				ypd.setPsc("");
				ypd.setPlan_code("");
				ypd.setInspection_lot("");
				ypd.setObject_no_xg("");
				String order1=(String)this.getSession().getAttribute(HomeService.SESSION_WORK_ORD);
				String team1=(String)this.getSession().getAttribute(HomeService.SESSION_WORK_GRP);
				ypd.setInorder(order1);
				ypd.setInteam(team1);
				//String coco = mcccD.getPacking_no().substring(0,8);
				//2018-07-09
				YdmProductDetail yyd=new YdmProductDetail();
				yyd = this.getMapper(YdmProductDetailMapper.class).doFind(mcsm.getMaterial_no(), null);
				if(yyd==null){
					yyd=new YdmProductDetail();
				}
				if(yyd.getMaterailcoilno()!=null&&!"".equals(yyd.getMaterailcoilno())){
					ypd.setMaterailcoilno(yyd.getMaterailcoilno());
				}
				//炉号
				if(yyd.getHeatno()!=null&&!"".equals(yyd.getHeatno())){
					ypd.setHeatno(yyd.getHeatno());
				}
				// 增加物料属性
				if(yyd.getObject_attr()!=null&&!"".equals(yyd.getObject_attr())){
					ypd.setObject_attr(yyd.getObject_attr());
				}
				//2019-02-21  物料属性
				if(cp.getMemo3()!=null && !"".equals(cp.getMemo3())){
					ypd.setObject_attr(cp.getMemo3());
					ypd.setIsbl("1");
				}
				//检验号
				ypd.setInspection_lot(mcccD.getInspection_lot());
				ypd.setBatchno(mcsm.getSchedule_no());

				if(yyd.getLzorderno()!=null&&!"".equals(yyd.getLzorderno())){
					ypd.setLzorderno(yyd.getLzorderno());
				}
				ypd.setMaterailcoilno(mcsm.getMaterial_no_src());//主表的原始卷号。

				//20190801 边丝和头尾卷默认综判判废
				//20191025 进废副品库
				String lastChar = ypd.getCoilno().substring(ypd.getCoilno().length()-1);
				if ("B".equals(lastChar) || "H".equals(lastChar)) {
					ypd.setJudgeresult("40740804");
					//20200317 净重的头尾卷及边丝入废钢库  毛重进成品库 黄涛提出
					String condition = "contract_no||contract_line_seq||order_seq = '"+ypd.getOrderno()+"' and nvl(change_flag,'0')<>'1'";
					List<SlmOrderInfo> soiList = this.getMapper(SlmOrderInfoMapper.class).findWithCondition(null, condition, null, 0, 0);
					if (soiList!=null && soiList.size()>0) {
						String weight_type_no = soiList.get(0).getWeight_type_no();
						if ("102301".equals(weight_type_no)) {//净重:需要脱单，入废副品
							ypd.setStorageattr("500210");
							ypd.setOrderno("");
							ypd.setProduceorder("");
							ypd.setObject_no_vt("");
						}else if ("102302".equals(weight_type_no)) {//毛重：不脱单，入成品库
							ypd.setStorageattr("500203");
							// 毛重头尾边丝默认合格：20231024刘侣
							ypd.setJudgeresult("40740801");
						}
					}
				}
				//包装状态(20191016)
				ypd.setIs_package("0");
				
				
				this.getMapper(YdmProductDetailMapper.class).insert(ypd);
				rm.setState("200");

				//-------2018.3.27-----修改销售订单状态 -----vir-----
				if(mcccD.getOrder_no()!=null&&mcccD.getOrder_no().length()>6){
						String contract_no=mcccD.getOrder_no().substring(0, mcccD.getOrder_no().length()-6);
						String contract_line_seq=mcccD.getOrder_no().substring(mcccD.getOrder_no().length()-6, mcccD.getOrder_no().length()-3);
						String order_seq=mcccD.getOrder_no().substring(mcccD.getOrder_no().length()-3);
						SlmOrderInfo order=new SlmOrderInfo();
						order.setContract_no(contract_no);
						order.setContract_line_seq(contract_line_seq);
						order.setOrder_seq(order_seq);
						order.setValid_flag("1");
						List<SlmOrderInfo> orderList=this.getBean(SlmOrderInfoServiceImpl.class).doQuery(order);
						boolean in=true;
						if(orderList.size()==1){
							order=orderList.get(0);
						}else if(orderList.size()>1&&order_pk!=null && (!"".equals(order_pk))){
							SlmOrderInfo pk_order=this.getMapper(SlmOrderInfoMapper.class).findById(order_pk);
							if(pk_order!=null)
								order=pk_order;
						}else{
							in=false;
						}
						if(in){
							order.setP_order_flag_no(order.getOrder_flag_no());
							order.setP_order_flag_name(order.getOrder_flag_name());
							order.setOrder_flag_no("103409");
							order.setOrder_flag_name("缴库");
							this.getBean(SlmOrderInfoServiceImpl.class).doUpdate(order);
						}
					}
				//-------2018.3.27-----修改销售订单状态 -----vir-----
				//}
				//else 
				//{
				//	rm.setState("500");
				//	rm.setMsgInfo("不存在记录!");
				//}
			}
			else {
				rm.setState("500");
				rm.setMsgInfo("传入的主键为空!");
			}

		}
		return rm;
	}

	/**
	 * 罩退入库接口
	 * @param cp2
	 * @return
	 * @throws Exception 
	 */
	public ResultModel doMesIn2(CommonPage<MesCrAnnealM> cp2) throws Exception {
		ResultModel rm = new ResultModel();

		MesCrAnnealM mesxx=cp2.getObject();
		String username=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		Date now = new Date();
		if(mesxx.getCoil_no()!=null&&mesxx.getCoil_no()!=""){
			YdmProductDetail ypd=new YdmProductDetail();
			//调用库存接口存数据时,保存 虚拟物料号,机台代码，机台名称
			List<ComBaseMachine> listcom=this.getMapper(ComBaseMachineMapper.class).findWithCondition(null, "machine_code='"+mesxx.getMachine_code()+"'", null, 0, 0);
			ypd.setMachine_code(mesxx.getMachine_code());
			if(listcom!=null && listcom.size()>0){
				ypd.setMachine_name(listcom.get(0).getMachine_name());
			}	
			List<YdmProductDetail> list = this.getMapper(YdmProductDetailMapper.class).findWithCondition(null, "coilno ='"+mesxx.getMaterial_no()+"'", null, 0, 0);
			if(list!=null && list.size()>0){
				ypd.setMaterailtype(list.get(0).getMaterailtype());
			}
			//ypd.setMaterailcoilno(mesxx.getMaterial_no());
			ypd.setMaterailcoilno(mesxx.getMaterial_no_src());
			ypd.setObject_no_vt(mesxx.getMaterial_no_vt());
			ypd.setOrderno(mesxx.getOrder_no());
			ypd.setProdorderno(mesxx.getProd_order_no());

			
			
			String order_pk="";
			if(mesxx.getProd_order_no()!=null&&!"".equals(mesxx.getProd_order_no())){
				//注意!!
				PlnProdorder pp=new PlnProdorder();
				pp.setProd_order_no(mesxx.getProd_order_no());
				List<PlnProdorder> lpp=this.getMapper(PlnProdorderMapper.class).find(pp, 0, 1);
				if(lpp!=null&&lpp.size()>0){
					pp = lpp.get(0);
					ypd.setCustomer_no(pp.getCustomer_no());
					ypd.setCustomer_nm(pp.getCustomer_name());
					ypd.setPsc(pp.getPsc());
					ypd.setDelivery_state_code(pp.getDelivery_state_code());//交货状态
					ypd.setDelivery_state_desc(pp.getDelivery_state_desc());
					ypd.setProd_code(pp.getProd_code());
					ypd.setProd_name(pp.getProd_name());
					ypd.setStd_code(pp.getStd_code());
					ypd.setStd_name(pp.getStd_name());
					ypd.setUse_code(pp.getUse_code());
					ypd.setUse_name(pp.getUser_name());
					ypd.setPlan_code(pp.getPline_code());
					ypd.setPline_name(pp.getPline_name());
					ypd.setSteelcode(pp.getSteel_code());
					ypd.setReceiv_no(pp.getReciver_unit_no());
					ypd.setReceiv_nm(pp.getReciver_unit_name()); 
				}

			}
			ypd.setCreater(username);
			ypd.setCreatedate(now);
			ypd.setCoilno(mesxx.getCoil_no());
			
			ypd.setSteelcode(mesxx.getSteel_code());
			
			// 改为获取投料卷信息里的判定牌号：20240722刘侣 改回来不动 20240815
			ypd.setJudgesteelcode(mesxx.getSteel_code());	
//			ypd.setJudgesteelcode(list.get(0).getJudgesteelcode());	
			
			
			//ypd.setSurfaceresult(mesxx.getSurface_rst());
			//ypd.setProduceorder(mesxx.getWrk_ord());
			//ypd.setProduceteam(mcccD.getWrk_grp());
			ypd.setProduceorder(mesxx.getDischarge_ord());//产出班次
			ypd.setProduceteam(mesxx.getDischarge_grp());//产出班组
			/*if (mesxx.getDischarge_date()!=null && !"".equals(mesxx.getDischarge_date())) {				
				ypd.setProducedate(new SimpleDateFormat("yyyy-MM-dd").parse(mesxx.getDischarge_date()));//产出时间/生产结束时间
			}
			if (ypd.getProducedate()==null) {
			}*/
			//20210628 取交工时间
			ypd.setProducedate(now);//产出时间/生产结束时间
			//ypd.setProducedate(mesxx.getDischarge_time());//产出时间/生产结束时间
			ypd.setState("-1");
			ypd.setSource("0");
			//ypd.setStorageattr("500203");//？
			ypd.setStorageattr(cp2.getMemo1());
			ypd.setCoiltype("500203".equals(ypd.getStorageattr())?"2":"1");
			ypd.setThick(mesxx.getAct_thk());
			ypd.setWidth(mesxx.getAct_wdt());
			ypd.setLength(mesxx.getAct_len());
			//20191018:包括目标宽度，目标厚度到库存表
			ypd.setLz_thick(mesxx.getAim_thk());//合同厚度(目标厚度)
			ypd.setLz_width(mesxx.getAim_wdt());//合同宽度(目标宽度)
			ypd.setDiameter_inn(mesxx.getAct_inn_dia());
			ypd.setDiameter_out(mesxx.getAct_out_dia());
			//ypd.setProducedate(mesxx.getProduce_time());
			ypd.setFactweight(mesxx.getCoil_act_wgt());//产出卷实重    不是原料卷实重？
			ypd.setTheoryweight(mesxx.getCoil_thr_wgt());
			ypd.setQuantity(1);

			ypd.setPsc("");
			ypd.setPlan_code("");
			ypd.setInspection_lot("");
			ypd.setObject_no_xg("");
			String order1=(String)this.getSession().getAttribute(HomeService.SESSION_WORK_ORD);
			String team1=(String)this.getSession().getAttribute(HomeService.SESSION_WORK_GRP);
			ypd.setInorder(order1);
			ypd.setInteam(team1);
			//String coco = mesxx.getCoil_no().substring(0,8);
			//2018-07-09
			YdmProductDetail yyd=new YdmProductDetail();
			yyd = this.getMapper(YdmProductDetailMapper.class).doFind(mesxx.getMaterial_no(), null);
			if(yyd==null){
				yyd=new YdmProductDetail();
			}
			
			// 退火交工将投料卷的表面判定结果id赋值道产出的退火卷中库存表的up_surface_flaw列中：20230419刘侣:bug修复：20230706
//			if (yyd.getUp_surface_result_id() != null && !"".equals(yyd.getUp_surface_result_id())) {
			ypd.setUp_surface_flaw(yyd.getUp_surface_result_id());
//			}
			// end
			
			if(yyd.getMaterailcoilno()!=null&&!"".equals(yyd.getMaterailcoilno())){
				ypd.setMaterailcoilno(yyd.getMaterailcoilno());
			}
			//炉号
			if(yyd.getHeatno()!=null&&!"".equals(yyd.getHeatno())){
				ypd.setHeatno(yyd.getHeatno());
			}
			// 增加物料属性
			if(yyd.getObject_attr()!=null&&!"".equals(yyd.getObject_attr())){
				ypd.setObject_attr(yyd.getObject_attr());
			}
			//2019-02-21  物料属性
			if(cp2.getMemo3()!=null && !"".equals(cp2.getMemo3())){
				ypd.setObject_attr(cp2.getMemo3());
				ypd.setIsbl("1");
			}
			//检验号
			ypd.setInspection_lot(mesxx.getInspection_lot());
			ypd.setBatchno(mesxx.getBatch_no());


			if(yyd.getLzorderno()!=null&&!"".equals(yyd.getLzorderno())){
				ypd.setLzorderno(yyd.getLzorderno());
			}
			ypd.setMaterailcoilno(mesxx.getMaterial_no_src());//主表的原始卷号。

			//20190801 边丝和头尾卷默认综判判废//20191025 进废副品库
			String lastChar = ypd.getCoilno().substring(ypd.getCoilno().length()-1);
			if ("B".equals(lastChar) || "H".equals(lastChar)) {
				ypd.setJudgeresult("40740804");
				//20200317 净重的头尾卷及边丝入废钢库  毛重进成品库 黄涛提出
				String condition = "contract_no||contract_line_seq||order_seq = '"+ypd.getOrderno()+"' and nvl(change_flag,'0')<>'1'";
				List<SlmOrderInfo> soiList = this.getMapper(SlmOrderInfoMapper.class).findWithCondition(null, condition, null, 0, 0);
				if (soiList!=null && soiList.size()>0) {
					String weight_type_no = soiList.get(0).getWeight_type_no();
					if ("102301".equals(weight_type_no)) {//净重
						
						// 净重的头尾卷和边丝脱单后需要手动插入脱单信息：20230725刘侣
						// 前提是这个卷没有做过脱单插入：
						String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
						String conditiontd = " and OBJECT_NO = '"+ypd.getCoilno()+"' and OPT_TYPE = '0'";
						List<PlnMatReplaceLog> pmrList = this.getMapper(PlnMatReplaceLogMapper.class).findWithCondition(null, conditiontd, null, 0, 0);
						if (pmrList.size() == 0) {
							List<PlnMatReplaceLog> lmmrl = this.getMapper(PlnMatReplaceLogMapper.class).findWithCondition(null, "",
									" serial_no desc ", 0, 1);
							long iNo = 1;
							if (lmmrl != null && lmmrl.size() > 0) {
								iNo = lmmrl.get(0).getSerial_no() + 1;
							}
							PlnMatReplaceLog mmrl = new PlnMatReplaceLog();
							mmrl.setSerial_no(iNo++);
							mmrl.setObject_no(ypd.getCoilno());
							mmrl.setOpt_type("0");
							mmrl.setStatus("0");
							mmrl.setOrder_no(ypd.getOrderno());
							
							mmrl.setCreate_man_name(userName);
							mmrl.setCreate_time(new Date());
							mmrl.setMemo("净重头尾边丝卷补脱单信息");
							this.getMapper(PlnMatReplaceLogMapper.class).insert(mmrl);
						}
						
						// end
						
						ypd.setStorageattr("500210");
						ypd.setOrderno("");
						ypd.setProdorderno("");
						ypd.setObject_no_vt("");
					}else if ("102302".equals(weight_type_no)) {//毛重
						ypd.setStorageattr("500203");
						// 毛重头尾边丝默认合格：20231024刘侣
						ypd.setJudgeresult("40740801");
					}
				}
			}
			//包装状态(20191016)
			ypd.setIs_package("0");
			//20200716退火默认合格
			ypd.setJudgeresult("40740801");
			this.getMapper(YdmProductDetailMapper.class).insert(ypd);
			rm.setState("200");

			//-------2018.3.27-----修改销售订单状态 -----vir-----
			if(mesxx.getOrder_no()!=null&&mesxx.getOrder_no().length()>6){
					String contract_no=mesxx.getOrder_no().substring(0, mesxx.getOrder_no().length()-6);
					String contract_line_seq=mesxx.getOrder_no().substring(mesxx.getOrder_no().length()-6, mesxx.getOrder_no().length()-3);
					String order_seq=mesxx.getOrder_no().substring(mesxx.getOrder_no().length()-3);
					SlmOrderInfo order=new SlmOrderInfo();
					order.setContract_no(contract_no);
					order.setContract_line_seq(contract_line_seq);
					order.setOrder_seq(order_seq);
					order.setValid_flag("1");
					List<SlmOrderInfo> orderList=this.getBean(SlmOrderInfoServiceImpl.class).doQuery(order);
					boolean in=true;
					if(orderList.size()==1){
						order=orderList.get(0);
					}else if(orderList.size()>1&&order_pk!=null && (!"".equals(order_pk))){
						SlmOrderInfo pk_order=this.getMapper(SlmOrderInfoMapper.class).findById(order_pk);
						if(pk_order!=null)
							order=pk_order;
					}else{
						in=false;
					}
					if(in){
						order.setP_order_flag_no(order.getOrder_flag_no());
						order.setP_order_flag_name(order.getOrder_flag_name());
						order.setOrder_flag_no("103409");
						order.setOrder_flag_name("缴库");
						this.getBean(SlmOrderInfoServiceImpl.class).doUpdate(order);
					}
				}
			//-------2018.3.27-----修改销售订单状态 -----vir-----
			//}
			//else 
			//{
			//	rm.setState("500");
			//	rm.setMsgInfo("不存在记录!");
			//}
		}
		else {
			rm.setState("500");
			rm.setMsgInfo("传入的主键为空!");
		}
		return rm;
	}

	/**
	 * 吊销卷插入,就是原料卷退回原料库
	 * queryNo:原始卷号;ypdi:吊销卷信息[新卷号Coilno(吊销卷卷号)，长度Length、内径Diameter_inn、外径Diameter_out、理重Theoryweight、实重Factweight]
	 * */
	public ResultModel doInsertRevoke(String queryNo,YdmProductDetail ypdi)
	{
		ResultModel rm=new ResultModel();
		try 
		{
			if(queryNo!=null&&queryNo!="")
			{
				YdmProductDetail ypd=this.getMapper(YdmProductDetailMapper.class).doFind(queryNo, null);
				if(ypd!=null)
				{
					if(ypdi.getCoilno()!=null)
					{
						YdmProductDetail yd = ypd;

						yd.setCoilno(ypdi.getCoilno());
						yd.setLength(ypdi.getLength());
						yd.setDiameter_inn(ypdi.getDiameter_inn());
						yd.setDiameter_out(ypdi.getDiameter_out());
						yd.setTheoryweight(ypdi.getTheoryweight());
						yd.setFactweight(ypdi.getFactweight());
						yd.setOrderno(null);
						yd.setProdorderno(null);
						yd.setState("0");

						List<YdmProductDetail> list = this.getMapper(YdmProductDetailMapper.class).find(yd, 0, 1);
						if (list!=null && list.size()>0) {
							rm.setState("500");
							rm.setMsgInfo("新增卷号重复!");
						}else{
							this.getMapper(YdmProductDetailMapper.class).doInsert(yd);
						}

						//插入垛位信息
						YdmProductButtresslist ybt = new YdmProductButtresslist();
						ybt.setButtressno("100102001");
						ybt.setCoilno(ypd.getCoilno());
						ybt.setStorageattr(ypd.getSteelcode());
						ybt.setCreatedate(new Date());
						ybt.setAreano("100102");
						ybt.setLayer(1);
						ybt.setLocality(0);
						this.getMapper(YdmProductButtresslistMapper.class).doInsert(ybt);


						//插入入库信息
						YdmProductInlist ypi=new YdmProductInlist();
						ypi.setInbillno(this.createINBILLNO());
						if(ypi.getCreatedate()==null||"".equals(ypi.getCreatedate())) {
							ypi.setCreatedate(new Date());
						}
						if (ypi.getCreater()==null||"".equals(ypi.getCreater())) {
							ypi.setCreater("");
						}
						ypi.setCoilno(yd.getCoilno());
						ypi.setCoiltype(yd.getCoiltype());
						ypi.setMaterailtype(yd.getMaterailtype());
						ypi.setSource(yd.getSource());
						ypi.setMaterailsupplier(yd.getMaterailsupplier());
						ypi.setIsbox(yd.getIsbox());
						ypi.setBoxno(yd.getBoxno());
						ypi.setDrawingno(yd.getDrawingno());
						ypi.setBatchno(yd.getBatchno());
						ypi.setHeatno(yd.getBatchno());
						ypi.setSmpno(yd.getSmpno());
						ypi.setManagementno(yd.getManagementno());
						ypi.setStorageattr(yd.getStorageattr());
						ypi.setProd_code(yd.getProd_code());
						ypi.setProd_name(yd.getProd_name());
						ypi.setStd_code(yd.getStd_code());
						ypi.setStd_name(yd.getStd_name());
						ypi.setUse_code(yd.getUse_code());
						ypi.setUse_name(yd.getUse_name());
						ypi.setPline_name(yd.getPline_name());
						ypi.setPostid(yd.getPostid());
						ypi.setThick(yd.getThick());
						ypi.setWidth(yd.getWidth());
						ypi.setLength(yd.getLength());
						ypi.setDiameter_inn(yd.getDiameter_inn());
						ypi.setDiameter_out(yd.getDiameter_out());
						ypi.setQuantity(yd.getQuantity());
						ypi.setTheoryweight(yd.getTheoryweight());
						ypi.setCoreweight(yd.getCoreweight());
						ypi.setGrossweight(yd.getGrossweight());
						ypi.setPackweight(yd.getPackweight());
						ypi.setFactweight(yd.getFactweight());
						ypi.setCustomer_nm(yd.getCustomer_nm());
						ypi.setCustomer_no(yd.getCustomer_no());
						ypi.setReceiv_no(yd.getReceiv_no());
						ypi.setReceiv_nm(yd.getReceiv_nm());
						ypi.setOrderno(yd.getOrderno());
						ypi.setProdorderno(yd.getProdorderno());
						ypi.setSteelcode(yd.getSteelcode());
						ypi.setJudgesteelcode(yd.getJudgesteelcode());
						ypi.setPacking_group(yd.getPacking_group());
						ypi.setChemresult(yd.getChemresult());
						ypi.setSizeresult(yd.getSizeresult());
						ypi.setSurfaceresult(yd.getSurfaceresult());
						ypi.setWeightresult(yd.getWeightresult());
						ypi.setJudgeresult(yd.getJudgeresult());
						ypi.setPhysresult(yd.getPhysresult());
						ypi.setSpyresult(yd.getSpyresult());
						ypi.setProducedate(yd.getProducedate());
						ypi.setProduceorder(yd.getProduceorder());
						ypi.setProduceteam(yd.getProduceteam());
						if(ypi.getIndate()==null||"".equals(ypi.getIndate()))
						{
							ypi.setIndate(new Date());
						}
						///ypi.setInorder(order);
						//ypi.setInteam(team);
						ypi.setOperator("");
						ypi.setIntype("500405");
						ypi.setLocality("1");

						ypi.setPosition("0");
						ypi.setMemo(yd.getMemo());
						ypi.setButtressno("100102001");
						//20190220:赵淋支:将库存表的检验号待入到入库表
						ypi.setInspection_lot(yd.getInspection_lot());
						
						// 加入物料属性：20230725刘侣
						ypi.setObj_attr_in(yd.getObject_attr());
						// end
						
						this.getMapper(YdmProductInlistMapper.class).insert(ypi);


						rm.setState("200");

					}
					else
					{
						rm.setState("500");
						rm.setMsgInfo("新增卷号为空!");
					}
				}
				else 
				{
					rm.setState("500");
					rm.setMsgInfo("库存中不存在原始卷号记录!");
				}
			}
			else
			{
				rm.setState("500");
				rm.setMsgInfo("原始卷号为空!");
			}
			rm.setState("200");
		} 
		catch (Exception ex) 
		{
			rm.setState("500");
			rm.setMsgInfo("服务端异常，吊销卷插入库存失败!");
			ex.printStackTrace();
		}
		return rm;
	}


	/**
	 * 吊销卷插入撤销
	 * queryNo:吊销卷卷号
	 * */
	public ResultModel doInsertRevokeCanl(String queryNo)
	{
		ResultModel rm=new ResultModel();
		try 
		{
			if(queryNo!=null&&queryNo!="")
			{
				YdmProductDetail ypd=this.getMapper(YdmProductDetailMapper.class).doFind(queryNo, null);
				if(ypd!=null)
				{
					if(!"0".equals(ypd.getState())||!"500201".equals(ypd.getStorageattr()))
					{
						rm.setState("500");
						rm.setMsgInfo("原料卷不在库或或不在原料库，不能撤销!");
						return rm;
					}
					this.getMapper(YdmProductButtresslistMapper.class).doDelete(queryNo, null);
					//2018-09-26
					//this.getMapper(YdmProductInlistMapper.class).doDelete(queryNo);
					this.getMapper(YdmProductInlistMapper.class).doDeleteByCoilno(queryNo,"500405");
					this.getMapper(YdmProductDetailMapper.class).doDelete(queryNo, null);
					rm.setState("200");
				}
				else 
				{
					rm.setState("500");
					rm.setMsgInfo("库存中不存在卷号记录!");
				}
			}
			else
			{
				rm.setState("500");
				rm.setMsgInfo("卷号为空!");
			}
			rm.setState("200");
		} 
		catch (Exception ex) 
		{
			rm.setState("500");
			rm.setMsgInfo("服务端异常，吊销卷插入库存失败!");
			ex.printStackTrace();
		}
		return rm;

	}

	/**
	 * 可充当原料卷查询
	 * 从原料库存YDM_PRODUCT_DETAIL中查询可充当的原料卷
	 * */
	public ResultModel doFindYD(){
		ResultModel rm=new ResultModel();
		try {
			rm.setData(this.getMapper(YdmProductDetailMapper.class).doFindPD());
			rm.setState("200");
		} catch (Exception e) {
			rm.setMsgInfo("查询失败！");
			rm.setState("500");
		}
		return rm;	
	}
	/**
	 * 原料卷充当-重制
	 * sum.coilno 充当卷号
	 * sum.prodorderno 生产订单号
	 * sum.orderno 销售订单号
	 * sum.object_no_vt 虚拟物料号
	 * sum.customer_no 客户编码
	 * sum.customer_nm 客户名称
	 * sum.receiv_no 收货单位编码
	 * sum.receiv_nm 收货单位名称
	 * */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doVolRawMat(CommonPage<YdmProductDetail> sum)
			throws Exception{
		ResultModel rm=new ResultModel();
		try {
			YdmProductDetail yd=sum.getObject();
			if(yd==null){
				throw new Exception("请传入数据");
			}
			//有效性检查
			YdmProductDetail yd2=this.getMapper(YdmProductDetailMapper.class).doFindById(yd);
			if(yd2.getProdorderno()!=null||!yd2.getState().equals("0")||(!yd2.getStorageattr().equals("500201")&&!yd2.getStorageattr().equals("500204"))){
				rm.setState("500");
				rm.setMsgInfo("不允许进行充当!");
			}
			//修改对应卷号数据设置 生产订单号、销售订单号、虚拟物料号、客户编码、客户名称、收货单位编码、收货单位名称
			this.getMapper(YdmProductDetailMapper.class).update(yd);
			rm.setState("200");

		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("充当失败!");
			e.printStackTrace();
		}
		return rm;
	}
	/**
	 * 原料卷充当撤销
	 * sum.coilno 充当卷号
	 * */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doCanlVolRawMat(CommonPage<YdmProductDetail> sum)
			throws Exception{
		ResultModel rm=new ResultModel();
		try {
			YdmProductDetail yd=sum.getObject();
			if(yd==null){
				throw new Exception("请传入数据");
			}
			//有效性检查
			YdmProductDetail yd2=this.getMapper(YdmProductDetailMapper.class).doFindById(yd);
			if(yd2.getProdorderno()==null||!yd2.getState().equals("0")||(!yd2.getStorageattr().equals("500201")&&!yd2.getStorageattr().equals("500204"))){
				rm.setState("500");
				rm.setMsgInfo("不允许撤销充当!");
			}
			this.getMapper(YdmProductDetailMapper.class).DoUpdateRM(yd);
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("撤销充当失败!");
			e.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 原料卷充当
	 * @throws Exception 
	 * */
	public ResultModel doFinshedProductActUpdate(YdmProductDetail queryNo) throws Exception {
		ResultModel rm=new ResultModel();
		if(queryNo.getCoilno()!=""&&queryNo.getCoilno()!=null) {
			YdmProductDetail ypd1=this.getMapper(YdmProductDetailMapper.class).doFind(queryNo.getCoilno(), null);
			if(ypd1!=null) {
				if(!"0".equals(ypd1.getState())||!"".equals(ypd1.getProdorderno())||ypd1.getProdorderno()!=null
						 ||(!"500201".equals(ypd1.getStorageattr())&&!"500204".equals(ypd1.getStorageattr()))) {
					rm.setState("500");
					rm.setMsgInfo("原料卷不在库或生产订单号不为空或不在原料库，不能充当!");
					return rm;
				}
				this.getMapper(YdmProductDetailMapper.class).doFinshedProductActUpdate(queryNo);
				rm.setState("200");
			}
			else {
				throw new Exception();
			}
		}
		else {
			rm.setState("500");
			rm.setMsgInfo("传入的卷号为空!");
		}
		return rm;
	}

	/**
	 * 撤销原料卷充当
	 * @throws Exception 
	 * */
	public ResultModel doActAs(String queryNo) throws Exception {
		ResultModel rm=new ResultModel();
		if(queryNo!=""&&queryNo!=null) {
			YdmProductDetail ypd1=this.getMapper(YdmProductDetailMapper.class).doFind(queryNo, null);
			if(ypd1!=null) {
				if(!"0".equals(ypd1.getState())||"".equals(ypd1.getProdorderno()) ||ypd1.getProdorderno()==null
						|| (!"500201".equals(ypd1.getStorageattr())&&!"500204".equals(ypd1.getStorageattr()))) {
					rm.setState("500");
					rm.setMsgInfo("原料卷不在库或生产订单号为空或不在原料库，不能撤销充当!");
					return rm;
				}
				YdmProductDetail ypd2 = new YdmProductDetail();
				ypd2.setCoilno(queryNo);
				this.getMapper(YdmProductDetailMapper.class).doMaterialReplaceUpdateB(ypd2);
				rm.setState("200");
			} else {
				throw new Exception();
			}
		} else {
			rm.setState("500");
			rm.setMsgInfo("传入的卷号为空!");
		}
		return rm;
	}



	/**
	 * 可发资源查询（查询可发明细）
	 * */
	public ResultModel doQueryWebBySales(CommonPage<YdmProductDetail> cp) {
		ResultModel rm=new ResultModel();
		int pageIndex=cp.getPageIndex();
		int pageSize=cp.getPageSize();
		PageModel<YdmProductDetail> pm = new PageModel<YdmProductDetail>(pageIndex,pageSize);
		try {
			cp.setMemo1(null);
			cp.setMemo2(null);
			Object wjmin="",wjmax="";
			if(cp.getMemo1()!=null&&cp.getMemo1()!="")
				wjmin=Double.valueOf(cp.getMemo1()).doubleValue();
			if(cp.getMemo2()!=null&&cp.getMemo2()!="")
				wjmax=Double.valueOf(cp.getMemo2()).doubleValue();
			Object thick,width;
			if(cp.getObject().getThick()!=null && cp.getObject().getThick()==0)
				thick="";
			else 
				thick=cp.getObject().getThick();
			if(cp.getObject().getWidth()!=null && cp.getObject().getWidth()==0)
				width="";
			else 
				width=cp.getObject().getWidth();
			String State =cp.getObject().getState();
			if ("1".equals(State)) {
				pm.setRows(this.getMapper(YdmProductDetailMapper.class).doQueryWebBySale
						((pageIndex-1)*pageSize, (pageIndex-1)*pageSize+pageSize, cp.getStartTime(), cp.getEndTime(), cp.getObject().getCoilno(), cp.getObject().getJudgesteelcode(), 
								thick,width,wjmin,wjmax,cp.getObject().getStorageattr(),cp.getObject().getOrderno()));
				pm.setTotal(this.getMapper(YdmProductDetailMapper.class).doQueryWebBySaleCount
						(cp.getStartTime(), cp.getEndTime(), cp.getObject().getCoilno(), cp.getObject().getJudgesteelcode(), 
								thick,width,wjmin,wjmax,cp.getObject().getStorageattr(),cp.getObject().getOrderno()));
			}else {
				String order_no=cp.getObject().getOrderno();
				String whole="0";
				if(order_no!=null){
					String contract_no=order_no.substring(0,order_no.length()-6);
					String line_seq=order_no.substring(order_no.length()-6,order_no.length()-3);
					String order_seq=order_no.substring(order_no.length()-3);
					SlmOrderInfo order=new SlmOrderInfo();
					order.setContract_no(contract_no);
					order.setContract_line_seq(line_seq);
					order.setOrder_seq(order_seq);
					List<SlmOrderInfo> order_list=this.getMapper(SlmOrderInfoMapper.class).find(order,0,0);
					if(order_list.size()>0){
						if("1".equals(order_list.get(0).getWhole_coil()))
							whole="1";
					}
				}
				pm.setRows(this.getMapper(YdmProductDetailMapper.class).doQueryWebBySales
						((pageIndex-1)*pageSize, (pageIndex-1)*pageSize+pageSize, cp.getStartTime(), cp.getEndTime(), cp.getObject().getCoilno(), cp.getObject().getJudgesteelcode(), 
								thick,width,wjmin,wjmax,cp.getObject().getStorageattr(),cp.getObject().getOrderno(),cp.getObject().getOrder_nature(),cp.getObject().getWeight_type_no(),whole));
				pm.setTotal(this.getMapper(YdmProductDetailMapper.class).doQueryWebBySalesCount
						(cp.getStartTime(), cp.getEndTime(), cp.getObject().getCoilno(), cp.getObject().getJudgesteelcode(), 
								thick,width,wjmin,wjmax,cp.getObject().getStorageattr(),cp.getObject().getOrderno(),cp.getObject().getOrder_nature(),cp.getObject().getWeight_type_no(),whole));
			}
			rm.setData(pm);
			rm.setState("200");
		}
		catch(Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("服务端异常，查询失败!"+ex.getMessage());
			ex.printStackTrace();
		}
		return rm;
	}


	/**
	 * 提货单指定物料
	 * */
	public ResultModel doShippingLock(CommonPage<YdmProductDetail> cp) {
		ResultModel rm=new ResultModel();
		try {
			if(cp.getObject().getCoilno()!=null&&!"".equals(cp.getObject().getCoilno())) {
				YdmProductDetail ypd = new YdmProductDetail();
				ypd.setCoilno(cp.getObject().getCoilno());
				if(cp.getObject().getBoxno()!=null&&!"".equals(cp.getObject().getBoxno())) {
					ypd.setBoxno(cp.getObject().getBoxno());
				}
				ypd.setState("0");
				List<YdmProductDetail> lst = this.getMapper(YdmProductDetailMapper.class).find(ypd, 0, 0);
				if(lst==null||lst.size()==0) {
					rm.setState("500");
					rm.setMsgInfo("库存状态发生改变，请重新查询再操作!");
					return rm; 
				}

				ypd.setState("2");
				if(cp.getObject().getBill_no()!=null&&!"".equals(cp.getObject().getBill_no()))
					ypd.setBill_no(cp.getObject().getBill_no());
				if(cp.getObject().getLine_no()!=null&&!"".equals(cp.getObject().getLine_no()))
					ypd.setLine_no(cp.getObject().getLine_no());
				ypd.setUpdatedate(new Date());
				this.getMapper(YdmProductDetailMapper.class).doUpdate(ypd);
				rm.setState("200");
			} else {
				rm.setState("500");
				rm.setMsgInfo("传入卷号COILNO 箱号BOXNO 为空,不允许操作!");
				return rm;
			}
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("服务端异常，查询失败!"+e.getMessage());
			e.printStackTrace();
		}
		return rm;
	}


	/**
	 * 提货单指定物料
	 * */
	public ResultModel doShippingLockCanl(CommonPage<YdmProductDetail> cp) {
		ResultModel rm=new ResultModel();
		try {
			if(cp.getObject().getCoilno()!=null&&!"".equals(cp.getObject().getCoilno())) {
				YdmProductDetail ypd = new YdmProductDetail();
				ypd.setCoilno(cp.getObject().getCoilno());
				if(cp.getObject().getBoxno()!=null&&!"".equals(cp.getObject().getBoxno())) {
					ypd.setBoxno(cp.getObject().getBoxno());
				}
				ypd.setState("2");
				List<YdmProductDetail> lst = 	this.getMapper(YdmProductDetailMapper.class).find(ypd, 0, 0);
				if(lst==null||lst.size()==0) {
					rm.setState("500");
					rm.setMsgInfo("库存状态发生改变，请重新查询再操作!");
					return rm; 
				}
				ypd.setState("0");
				ypd.setUpdatedate(new Date());
				this.getMapper(YdmProductDetailMapper.class).doUpdateApi(ypd);
			} else {
				rm.setState("500");
				rm.setMsgInfo("传入卷号COILNO 箱号BOXNO 为空,不允许操作!");
				return rm;
			}
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("服务端异常，查询失败!");
			e.printStackTrace();
		}
		return rm;
	}

	/**
	 * 查询原始卷号
	 * */
	public ResultModel dogetDetailCoilno(CommonPage<YdmProductDetail> cp) {
		ResultModel rm=new ResultModel();

		try {
			if(cp.getObject().getCoilno()!=null&&!"".equals(cp.getObject().getCoilno())) {
				YdmProductDetail ypd = new YdmProductDetail();
				ypd.setCoilno(cp.getObject().getCoilno());
				List<YdmProductDetail> list1 = this.getMapper(YdmProductDetailMapper.class).find(ypd, 0, 0);
				if(list1.size()>0){					
					rm.setData(list1.get(0));
				}
			}
			else {
				rm.setState("500");
				rm.setMsgInfo("传入卷号 为空,不允许操作!");
				return rm;
			}
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("服务端异常，查询失败!");
			e.printStackTrace();
		}
		rm.setState("200");
		return rm;
	}

	/**
	 * 内部接口-获取成品物料检验、判定结果  
	 * @param sum
	 * @return
	 */
	public ResultModel doFindResultByCoilno(CommonPage<YdmProductDetail> sum){
		ResultModel rm =new ResultModel();
		if(sum.getObject()==null){
			rm.setState("500");
			rm.setMsgInfo("请传入参数");
			return rm;
		}
		if(sum.getObject().getCoilno()==null){
			rm.setState("500");
			rm.setMsgInfo("请传入物料号");
			return rm;
		}
		YdmProductDetail ypd = sum.getObject();
		//int count = this.getMapper(YdmProductDetailMapper.class).countWithCondition(sum.getObject(), null);
		try {
			rm.setData(this.getMapper(YdmProductDetailMapper.class).doFindResultByCoilno(ypd));
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			e.getStackTrace();
			rm.setMsgInfo("获取失败！"+e.getMessage());
		}
		return rm;
	}


	/**
	 * 更新成品物料检验、判定结果接口
	 * @param
	 * @return
	 */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doUpdateResultByCoilno(CommonPage<YdmProductDetail> sum) throws Exception{
		ResultModel rm =new ResultModel();
		if(sum.getObjectList().size()<=0){
			throw new Exception("请传入参数");
		}
		List<YdmProductDetail> ypd = sum.getObjectList();
		for (YdmProductDetail ypdd : ypd) {
			YdmProductDetail y = ypdd;
			this.getMapper(YdmProductDetailMapper.class).update(y);
		}
		rm.setState("200");
		return rm;
	}
	/***
	 * 调用物流模块提供的接口从库存表中获取物料状态=‘在库’的物料信息；默认显示未进行综合判定的物料信息
	 * @param cp
	 * @return
	 */
	public ResultModel doFindYdmQS(CommonPage<YdmProductDetail> cp){
		ResultModel r=new ResultModel();
		YdmProductDetail ydm = cp.getObject();
		int index = cp.getPageIndex();
		int size = cp.getPageSize();
		PageModel<YdmProductDetail> pm = new PageModel<YdmProductDetail>(index,size);
		try{
			List<YdmProductDetail> findbyYDM = this.getMapper(YdmProductDetailMapper.class).findYdmQS(ydm==null?new YdmProductDetail():ydm,index,size);
			int count = this.getMapper(YdmProductDetailMapper.class).findYdmQSCount(ydm==null?new YdmProductDetail():ydm);
			pm.setRows(findbyYDM);
			pm.setTotal(count);
			r.setData(pm);
			r.setState("200");
		}catch(Exception e){
			e.printStackTrace();
			r.setState("500");
			r.setErrorInfo("查询失败");
		}
		return r;
	}
	/**
	 * 
	 * @param cp
	 * @return
	 */
	public ResultModel doCheckQS(CommonPage<YdmProductDetail> cp){
		ResultModel rm= new ResultModel();
		boolean b = true ;
		try{
			List<YdmProductDetail> list = cp.getObjectList();
			for (YdmProductDetail y : list) {
				List<YdmProductDetail> qs = this.getMapper(YdmProductDetailMapper.class).doCheckQS(y);
				if (qs==null || qs.isEmpty()) {
					rm.setData("500");
					rm.setErrorInfo("查询失败，没有【"+y.getCoilno()+"】对应的物料");
					return rm;
				}else{
					YdmProductDetail detail = qs.get(0);
					String st = detail.getState();
					if (st==null || "".equals(st)) {
						rm.setData("500");
						rm.setErrorInfo("数据不对，没有【"+y.getCoilno()+"】物料的在库状态，请联系DBA或相关人员检查数据。");
						return rm;
					}else{
						if (!"0".equals(st)) {
							b=false;
							break;
						}
					}
				}
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			if (b) {
				rm.setState("200");
			}else{
				rm.setState("500");
			}
		}
		return rm;
	}
	/*
	 * 更新综合判定结果
	 * 
	 * */
	public ResultModel updareUlJudgeResult(String UlId,String result){
		ResultModel rm=new ResultModel();
		try {
			this.getMapper(YdmProductDetailMapper.class).updateUlJudgeResult(UlId, result);
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("更新结果失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}
	/**
	 * 提货单跟踪页面调用,查询提货单（提货单跟踪页面，添加更多查询条件，卷号、原料卷号、合同号）
	 * @return
	 */
	public ResultModel BillHeat_doQueryWeb(CommonPage<SlmLadingBillHeat> sum){
		ResultModel rm=new ResultModel();
		SlmLadingBillHeat heat=sum.getObject();
		int pageIndex=sum.getPageIndex();
		int pageSize=sum.getPageSize(); 
		String startTime=sum.getStartTime();
		String endTime=sum.getEndTime();
		PageModel<SlmLadingBillHeat> pm=new PageModel<SlmLadingBillHeat>(pageIndex, pageSize);
		try{
			if(startTime!=null&&!"".equals(startTime))		startTime+=" 00:00:00";
			if(endTime!=null&&!"".equals(endTime))		endTime+=" 23:59:59";
			List<SlmLadingBillHeat> map = this.getMapper(SlmLadingBillHeatMapper.class).findBillHeats(heat==null?new SlmLadingBillHeat():heat,pageIndex,pageSize,startTime,endTime);
			int count = this.getMapper(SlmLadingBillHeatMapper.class).CountfindBillHeat(heat==null?new SlmLadingBillHeat():heat,startTime,endTime);
			pm.setRows(map);
			pm.setTotal(count);
			rm.setData(pm);
			rm.setState("200");
		}catch(Exception e){
			e.printStackTrace();
			rm.setState("500");
			rm.setErrorInfo("查询失败"+e.getMessage());
		}
		return rm;
	}

	/**
	 * 库存质量锁定
	 * @param Coilno
	 * @param state
	 * @return
	 * @throws Exception 
	 */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel  UpdateYdmState(String Coilno,String state) throws Exception
	{
		ResultModel rm =new ResultModel();
		if(Coilno!=null&&!"".equals(Coilno)&&state!=null&&!"".equals(state)) {
			YdmProductDetail ypd = new YdmProductDetail();
			//根据传入状态  分 6锁定和0解锁
			if(state.equals("0")) {
				ypd.setCoilno(Coilno);
				ypd.setState("6");
				List<YdmProductDetail> listYdm =	this.getMapper(YdmProductDetailMapper.class).find(ypd, 0, 0);
				if(listYdm!=null&&listYdm.size()>0) {
					ypd.setState(state);
					this.getMapper(YdmProductDetailMapper.class).update(ypd);
					this.getMapper(YdmProductDetailMapper.class).kctbYdd(Coilno);
				}
				else {
					rm.setState("500");
					throw  new Exception("钢材状态不为质量锁定，无法解锁");
				}

			}
			else if(state.equals("6")) {
				ypd.setCoilno(Coilno);
				ypd.setState("0");
				List<YdmProductDetail> listYdm =	this.getMapper(YdmProductDetailMapper.class).find(ypd, 0, 0);
				if(listYdm!=null&&listYdm.size()>0) {
					ypd.setState(state);
					this.getMapper(YdmProductDetailMapper.class).update(ypd);
				}
				else {
					rm.setState("500");
					throw  new Exception("钢材状态不为在库，无法质量锁定");
				}
			}
		}
		else {
			rm.setState("500");
			throw  new Exception("卷号和状态不能为空");
		}
		rm.setState("200");
		return rm;
	}

	/**
	 * 查询没有销售订单号并且在库的所有成品
	 * @return
	 */
	public ResultModel selectYdm(){
		ResultModel rm = new ResultModel();
		try {
			List<YdmProductDetail> list = this.getMapper(YdmProductDetailMapper.class).selectYdm();
			rm.setData(list);
			rm.setState("200");
		} catch (Exception e) {
			rm.setMsgInfo("查询失败!");
			rm.setState("500");
		}
		return rm;
	}

	/**
	 * @author 赵淋支
	 * @date   2018年12月1日
	 * @description 查询所有的投料卷
	 */
	public ResultModel doQuaryDetailForM(CommonPage<YdmProductDetail> cp){
		ResultModel rm = new ResultModel();
		try {
			YdmProductDetail ydm = cp.getObject();
			int pageIndex = cp.getPageIndex();
			int pageSize = cp.getPageSize();
			String swhere = "";
			// 原料卷
			if (ydm.getCoilno()!=null && !"".equals(ydm.getCoilno())) {
				swhere += " and ypd.coilno like '%"+ydm.getCoilno()+"%'";
			}
			// 机台号
			if (ydm.getMachine_code()!=null && !"".equals(ydm.getMachine_code())) {
				swhere += " and mcm.machine_code like '%"+ydm.getMachine_code()+"%'";
			}
			List<YdmProductDetail> list = this.getMapper(YdmProductDetailMapper.class).doQuaryDetailForM(swhere,(pageIndex-1)*pageSize, (pageIndex-1)*pageSize+pageSize);
			rm.setData(list);
			rm.setState("200");
		} catch (Exception e) {
			rm.setMsgInfo("查询失败!");
			rm.setState("500");
		}
		return rm;
	}

	/**
	 * 
	 * @author 赵淋支
	 * @date   2018年12月1日
	 * @description 投料卷：通过大卷，查询下面的小卷
	 */
	public ResultModel doQuaryDetailForC(CommonPage<YdmProductDetail> cp){
		ResultModel rm = new ResultModel();
		try {
			YdmProductDetail ydm = cp.getObject();
			if (ydm.getCoilno()==null || "".equals(ydm.getCoilno())) {
				rm.setState("200");
				rm.setMsgInfo("请传入投料大卷号!");
				return rm;
			}
			String swhere = "";
			// 原料卷
			if (ydm.getCoilno()!=null && !"".equals(ydm.getCoilno())) {
				swhere += " and mcm.material_no = '"+ydm.getCoilno()+"'";
			}
			rm.setData(this.getMapper(YdmProductDetailMapper.class).doQuaryDetailForC(swhere));
			rm.setState("200");
		} catch (Exception e) {
			rm.setMsgInfo("查询失败!");
			rm.setState("500");
		}
		return rm;
	}

	/**
	 * 
	 * @author 赵淋支
	 * @date   2019年1月22日
	 * @parameter 
	 * @return 
	 * @description 订单变更时，处理仓库的变动
	 */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doChangeMaterialStorage(CommonPage<YdmProductDetail> cp)
			throws Exception{
		ResultModel rm = new ResultModel();
		if (cp.getObjectList() == null || cp.getObjectList().size() == 0) {
			rm.setState("500");
			rm.setMsgInfo("请选择库存数据！");
			return rm;
		}
		String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		//String team = (String) this.getSession().getAttribute(HomeService.SESSION_WORK_GRP);
		//String order = (String) this.getSession().getAttribute(HomeService.SESSION_WORK_ORD);
		String toStorage = cp.getMemo1(); //去向仓库

		Date now = new Date();
		for (YdmProductDetail YPD : cp.getObjectList()) {
			YdmProductDetail ypd = this.getMapper(YdmProductDetailMapper.class).doFind(YPD.getCoilno(),null);
			if (ypd==null) {
				throw new Exception("卷号【"+YPD.getCoilno()+"】数据不存在");
			}
			if ("-1".equals(ypd.getState())) { //物料还没有入库
				//1.修改库存记录的仓库
				YdmProductDetail newYpd = new YdmProductDetail();
				newYpd.setCoilno(ypd.getCoilno());
				newYpd.setStorageattr(toStorage);//设置新仓库
				newYpd.setMemo(YPD.getMemo());//挪库原因
				this.getMapper(YdmProductDetailMapper.class).update(newYpd);
				//2.修改入库记录的仓库
				YdmProductInlist YPI = new YdmProductInlist();
				YPI.setCoilno(ypd.getCoilno());
				YPI.setStorageattr(ypd.getStorageattr());
				List<YdmProductInlist> ypiList = this.getMapper(YdmProductInlistMapper.class).find(YPI, 0, 0);
				if (ypiList!=null && ypiList.size()>0) {
					YdmProductInlist ypi = new YdmProductInlist();
					ypi.setInbillno(ypiList.get(0).getInbillno());
					ypi.setStorageattr(toStorage);//设置新仓库
					this.getMapper(YdmProductInlistMapper.class).update(ypi);
				}
			}else if ("0".equals(ypd.getState())) { //物料处于在库状态  
				YdmProductInlist YPI = new YdmProductInlist();
				YPI.setCoilno(ypd.getCoilno());
				YPI.setStorageattr(ypd.getStorageattr());
				List<YdmProductInlist> ypiList = this.getMapper(YdmProductInlistMapper.class).find(YPI, 0, 0);
				if (ypiList!=null && ypiList.size()>0) {
					//1.从（前仓库）先撤销入库
					this.getMapper(YdmProductInlistMapper.class).delete(ypiList.get(0).getInbillno());
					//2.删除（前仓库）垛位信息
					this.getMapper(YdmProductButtresslistMapper.class).doDelete(ypd.getCoilno(), ypd.getBoxno());				
					//3.修改库存的仓库及状态
					YdmProductDetail newYpd = new YdmProductDetail();
					newYpd.setCoilno(ypd.getCoilno());
					newYpd.setStorageattr(toStorage);//设置新仓库
					newYpd.setState("-1");//新仓库变成待入库状态
					if (cp.getMemo2()!=null && !"".equals(cp.getMemo2())) {
						newYpd.setState(cp.getMemo2());//新仓库变成待入库状态/入库状态						
					}
					newYpd.setIs_can_load("0");// 将卷子可发运状态取消20230210刘侣
					newYpd.setMemo(YPD.getMemo());//挪库原因
					this.getMapper(YdmProductDetailMapper.class).update(newYpd);
					this.getMapper(YdmProductDetailMapper.class).kctbYdd(newYpd.getCoilno());
					//4.调用生产计划模块物料跟踪接口
					PrcMaterielProcess pmp = new PrcMaterielProcess();
					pmp.setObject_no(ypd.getCoilno());
					pmp.setPrc_code("5BYA05");
					pmp.setCreate_time(now);
					if ("-1".equals(cp.getMemo2())) {
						pmp.setRemark("订单变更成待入库");
					}else if ("0".equals(cp.getMemo2())) {
						pmp.setRemark("订单变更成入库");
					}					
					pmp.setCreate_man_name(userName);
					int tmp= this.getBean(MesApiServiceImpl.class).INSERT_OBJ_PROCESS(pmp);
					if(tmp==-1){
						throw new Exception("物料跟踪失败");
					}
				}
			}else if (!"-1".equals(ypd.getState()) && !"0".equals(ypd.getState())) {
				// 物料不是待入库也不是在库的
				throw new Exception("当前物料不是在库,也不是待入库!");
			}
		}
		rm.setState("200");
		rm.setMsgInfo("操作成功！");
		return rm;
	}

	/**
	 * 调用铁前MES新增出厂证接口
	 * @param passportInfo
	 * @return
	 */
	public ResultModel insertPassport(PassportInfo passportInfo, int current, int limit) {
		ResultModel rm = new ResultModel();
		try {
			// 以前的
//			String url = "http://172.16.0.18/ZyTg/services/Passport/sv";
			// 现在的，待测试 20230506 刘侣
			String url = "http://172.16.0.169:82/ZyTg/services/Passport/sv";
			Gson gson = new Gson();
			String str = gson.toJson(passportInfo);
			System.out.println("参数：" + str);
			RestfulHttpClient.HttpResponse response = getClient(url)
					.post()
					.addHeader("Content-Type", "application/json; charset=utf-8")
					.body(str)
					.request();
			if (response.getCode() == 200) {
				String result = response.getContent();
				System.out.println("result: " + result + ", " + passportInfo.getForecast());
				
//				System.out.println("最终result: " + result);
				
				JSONObject jo = JSONObject.fromObject(result);
				if (StringUtils.isNotEmpty(jo.getString("status")) && "TRUE" .equals(jo.getString("status").toUpperCase())) {
					rm.setState("200");
					rm.setMsgInfo("新增出厂证成功！");
				} else {
					if (jo.toString().contains("发货单已经存在")) {
						rm.setState("200");
						rm.setMsgInfo("发货单已经存在");
					}else {					
						rm.setState("500");
						rm.setMsgInfo("新增出厂证失败！");
						rm.setErrorInfo(jo.getString("errMsg") + "aa");
					}
				}
			} else {
				rm.setState("500");
				rm.setMsgInfo("新增出厂证失败！");
				rm.setErrorInfo(response.getContent() + "bb");
			}
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("新增出厂证失败！");
			rm.setErrorInfo(e.getMessage() + "cc");
		}
		return rm;
	}

	/**
	 * 调用铁前MES作废出厂证接口
	 * @param forecastNo 发运号
	 * @param reason 原因
	 * @param username 操作人
	 * @return
	 */
	public ResultModel cancelPassport(String forecastNo,String reason,String username){
		ResultModel rm = new ResultModel();
		try {
			String url = "http://172.16.0.169:82/ZyTg/services/Passport/sv";
			String params = "{\n" +
					"    \"Forecast\": \""+forecastNo+"\"," +
					"    \"Reason\": \""+reason+"\",\n" +
					"    \"Recoder\": \""+username+"\"\n" +
					"}";
			RestfulHttpClient.HttpResponse response = getClient(url)
					.put()
					.addHeader("Content-Type", "application/json; charset=utf-8")
					.body(params)
					.request();
			if (response.getCode() == 200) {
				String result = response.getContent();
				System.out.println("result: " + result);
				JSONObject jo = JSONObject.fromObject(result);
				if (StringUtils.isNotEmpty(jo.getString("status")) && "TRUE".equals(jo.getString("status").toUpperCase())) {
					rm.setState("200");
					rm.setMsgInfo("作废出厂证成功！");
				} else {
					rm.setState("500");
					rm.setMsgInfo(result);
					rm.setErrorInfo(jo.getString("errMsg"));
				}
			} else {
				rm.setState("500");
				rm.setMsgInfo("作废出厂证失败！");
				rm.setErrorInfo(response.getContent());
			}
		}catch (Exception e){
			rm.setState("500");
			rm.setMsgInfo("作废出厂证失败！");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}

	/**
	 * 以发运号查询铁前MES出厂信息
	 * @param listForecastNo 发运号数组
	 * @return
	 */
	public ResultModel queryPassportInfo(List<String> listForecastNo){
		ResultModel rm = new ResultModel();
		try {
			String url = "http://172.16.0.169:82/ZyTg/services/Passport/sv?forecastList=";
			String params = "";
			for(String forecastNo:listForecastNo){
				params+=forecastNo+"','";
			}
			if (StringUtils.isNotBlank(params) && params.length() > 3){
				params = params.substring(0,params.length()-3);
			}
			url += "'"+params+"'";
			RestfulHttpClient.HttpResponse response = getClient(url)
					.get()
					.addHeader("Content-Type", "application/json; charset=utf-8")
					//.addQueryParam("forecastList",params)
					.request();
			if (response.getCode() == 200) {
				String result = response.getContent();
				rm.setData(JSONArray.fromObject(result));
				rm.setState("200");
				rm.setMsgInfo("查询成功！");
			} else {
				rm.setState("500");
				rm.setMsgInfo("查询失败！");
				rm.setErrorInfo(response.getContent());
			}
		}catch (Exception e){
			rm.setState("500");
			rm.setMsgInfo("查询失败！");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}
	
	public ResultModel queryPassportWeight(List<String> carnoList){
		ResultModel rm = new ResultModel();
		try {
			String url = "http://172.16.0.169:82/ZyTg/services/Passport/weight?plateList=";
			String params = "";
			for(String carno:carnoList){
				params+=carno+"','";
			}
			if (StringUtils.isNotBlank(params) && params.length() > 3){
				params = params.substring(0,params.length()-3);
			}
			url += "'"+params+"'";
			RestfulHttpClient.HttpResponse response = getClient(url)
					.get()
					.addHeader("Content-Type", "application/json; charset=utf-8")
					//.addQueryParam("forecastList",params)
					.request();
			if (response.getCode() == 200) {
				String result = response.getContent();
				rm.setData(JSONArray.fromObject(result));
				rm.setState("200");
				rm.setMsgInfo("查询成功！");
			} else {
				rm.setState("500");
				rm.setMsgInfo("查询失败！");
				rm.setErrorInfo(response.getContent());
			}
		}catch (Exception e){
			rm.setState("500");
			rm.setMsgInfo("查询失败！");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}
	
}

