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

package market.Api.Mes.impl;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import market.Api.Lms.impl.LmsApiServiceImpl;
import market.Api.Mes.service.MesApiService;
import market.Api.Qms.impl.QmsApiServiceImpl;
import market.Api.Qms.vo.JudgeResult;
import market.Com.impl.PbModelDbServiceImpl;
import market.Com.mapper.ComBaseInfoMapper;
import market.Com.mapper.ComDsnCutstdMapper;
import market.Com.mapper.ComDsnPltlmtMapper;
import market.Com.vo.ComBaseInfo;
import market.Com.vo.ComDsnCutstd;
import market.Com.vo.ComDsnPltlmt;
import market.Com.vo.CommonPage;
import market.Com.vo.PbModelDb;
import market.Com.vo.ResultModel;
import market.Lms.Warehouse.mapper.YdmProductDetailMapper;
import market.Lms.Warehouse.vo.YdmProductDetail;
import market.Mes.Lengthwise.Design.mapper.PlnLengthwiseDsnMainMapper;
import market.Mes.Lengthwise.Design.mapper.PlnLengthwiseDsnMultinfoMapper;
import market.Mes.Lengthwise.Design.vo.PlnLengthwiseDsnMain;
import market.Mes.Lengthwise.Design.vo.PlnLengthwiseDsnMultinfo;
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.MesCrSlittingDSum;
import market.Mes.Lengthwise.Performance.vo.MesCrSlittingM;
import market.Mes.Lengthwise.Performance.vo.MesQmsView;
import market.Mes.Lengthwise.Plan.mapper.MesCrCrossCuttingDMapper;
import market.Mes.Lengthwise.Plan.mapper.MesCrCrossCuttingMMapper;
import market.Mes.Lengthwise.Plan.mapper.PlnLengthwisePlanDetailMapper;
import market.Mes.Lengthwise.Plan.mapper.PlnLengthwisePlanMapper;
import market.Mes.Lengthwise.Plan.mapper.PlnLwPlanStatisticMapper;
import market.Mes.Lengthwise.Plan.mapper.PlnMaterielDetailMapper;
import market.Mes.Lengthwise.Plan.mapper.PlnMaterielInvalidMapper;
import market.Mes.Lengthwise.Plan.mapper.PlnProcessPlanMapper;
import market.Mes.Lengthwise.Plan.vo.MesCrCrossCuttingD;
import market.Mes.Lengthwise.Plan.vo.MesCrCrossCuttingM;
import market.Mes.Lengthwise.Plan.vo.PlnLengthwisePlan;
import market.Mes.Lengthwise.Plan.vo.PlnLengthwisePlanDetail;
import market.Mes.Lengthwise.Plan.vo.PlnLwPlanStatistic;
import market.Mes.Lengthwise.Plan.vo.PlnMaterielDetail;
import market.Mes.Lengthwise.Plan.vo.PlnMaterielInvalid;
import market.Mes.Lengthwise.Plan.vo.PlnProcessPlan;
import market.Mes.MaterielTrack.mapper.PrcMaterielExtinfoMapper;
import market.Mes.MaterielTrack.mapper.PrcMaterielProcessMapper;
import market.Mes.MaterielTrack.mapper.PrcMaterielRelationMapper;
import market.Mes.MaterielTrack.mapper.PrcMaterielVtProcessMapper;
import market.Mes.MaterielTrack.mapper.PrcMatprocBlacklistMapper;
import market.Mes.MaterielTrack.mapper.PrcMatprocWhitelistMapper;
import market.Mes.MaterielTrack.vo.PrcMaterielProcess;
import market.Mes.MaterielTrack.vo.PrcMaterielRelation;
import market.Mes.MaterielTrack.vo.PrcMaterielVtProcess;
import market.Mes.MaterielTrack.vo.PrcMatprocBlacklist;
import market.Mes.MaterielTrack.vo.PrcMatprocWhitelist;
import market.Mes.OrderManager.Plan.mapper.PlnOrderStatisticMapper;
import market.Mes.OrderManager.Plan.mapper.PlnProdorderMapper;
import market.Mes.OrderManager.Plan.mapper.PlnProdorderStatisticMapper;
import market.Mes.OrderManager.Plan.vo.PlnOrderStatistic;
import market.Mes.OrderManager.Plan.vo.PlnProdorder;
import market.Mes.OrderManager.Plan.vo.PlnProdorderStatistic;
import market.Mes.Pickle.Performance.mapper.MesPlmMMapper;
import market.Mes.Pickle.Performance.vo.MesPlmD;
import market.Mes.Pickle.Performance.vo.MesPlmM;
import market.Mes.Rolling.Performance.mapper.MesRcmMMapper;
import market.Mes.Rolling.Performance.vo.MesRcmD;
import market.Mes.Rolling.Performance.vo.MesRcmM;
import market.Mes.Tpm.mapper.MesTpmMMapper;
import market.Mes.Tpm.vo.MesTpmD;
import market.Mes.Tpm.vo.MesTpmM;
import market.Mes.anneal.mapper.MesCrAnnealMMapper;
import market.Mes.anneal.vo.MesCrAnnealM;
import market.Qms.qcm.mapper.QcmJudgeSurfaceFlawMapper;
import market.Qms.qcm.mapper.QcmJudgeSurfaceMapper;
import market.Qms.qcm.vo.QcmJudgeSurface;
import market.Qms.qcm.vo.QcmJudgeSurfaceFlaw;
import market.Qms.slmord.mapper.SlmOrdDesignMscPlStiMapper;
import market.Qms.slmord.vo.SlmOrdDesignMscPlSti;
import market.Slm.FundManagement.impl.SlmFundFirstDetailServiceImpl;
import market.Slm.OrderManagement.mapper.SlmOrderInfoMapper;
import market.Slm.OrderManagement.vo.SlmOrderInfo;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.transaction.annotation.Transactional;

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

//@SuppressWarnings("rawtypes")
@RemoteService(path = "MesApiService")
public class MesApiServiceImpl extends BaseServiceImpl implements MesApiService {

	// --------------------------------分条上料、下PDI
	// Start----------------------------------------------------
	/**
	 * 分条上料接口 下PDI 验证 分条计划号、虚拟物料号
	 * 
	 * @throws Exception 其实都是单条操作
	 */
	public void MesCrSlittingMAddValid(List<MesCrSlittingM> oci) throws Exception {
		// 循环 根据(分条计划号数组，虚拟物料号数组) 读取 分条计划明细表【PLN_LENGTHWISE_PLAN_DETAIL】
		for (MesCrSlittingM mcsm : oci) {
			PlnLengthwisePlanDetail plpd = new PlnLengthwisePlanDetail();
			plpd.setLw_plan_no(mcsm.getSchedule_no());
			plpd.setObject_no_vt(mcsm.getMaterial_no_vt());
			// 如果不存在，则报错退出“分条计划[xxxxx][xx]信息不存在！”
			List<PlnLengthwisePlanDetail> lppd = this.getMapper(PlnLengthwisePlanDetailMapper.class).find(plpd, 0, 0);
			if (lppd == null || lppd.size() == 0) {
				throw new Exception("分条计划[" + mcsm.getSchedule_no() + "][" + mcsm.getMaterial_no_vt() + "]信息不存在！");
			}

			PlnMaterielDetail M1 = new PlnMaterielDetail();
			// 读取 根据计划明细表中的虚拟物料号(母卷号)，查找虚拟物料表【PLN_MATERIEL_DETAIL】，获取虚拟母卷信息 M1
			M1.setObject_no_vt(mcsm.getMaterial_no_vt());
			List<PlnMaterielDetail> lpmd = this.getMapper(PlnMaterielDetailMapper.class).find(M1, 0, 0);
			if (lpmd == null || lpmd.size() == 0) {
				throw new Exception("虚拟物料[" + mcsm.getMaterial_no_vt() + "]信息不存在！");
			}

			// 判断虚拟母卷信息里的 物料号【OBJECT_NO】，如果为空，则报错退出
			M1 = lpmd.get(0);
			if (M1.getObject_no() == null || "".equals(M1.getObject_no())) {
				throw new Exception("分条计划[" + mcsm.getSchedule_no() + "][" + mcsm.getMaterial_no_vt() + "]尚未挂料！");
			}
			// 实际上只有一条
			for (PlnLengthwisePlanDetail ppdc : lppd) {
				// 判断分条计划明细的状态【STATUS】
				if (ppdc.getStatus().compareTo("5BLW02") > 0) {
					throw new Exception(
							"分条计划[" + mcsm.getSchedule_no() + "][" + mcsm.getMaterial_no_vt() + "]已上料，不能再次操作！");
				}
			}
		}
	}

	/**
	 * 分条上料接口 下PDI
	 * 
	 * @throws Exception 其实都是单条操作
	 */
	public void MesCrSlittingMAdd(List<MesCrSlittingM> oci) throws Exception {

		String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);

		// 循环 根据(分条计划号数组，虚拟物料号数组) 读取 分条计划明细表【PLN_LENGTHWISE_PLAN_DETAIL】
		for (MesCrSlittingM mcsm : oci) {
			PlnLengthwisePlanDetail plpd = new PlnLengthwisePlanDetail();
			plpd.setLw_plan_no(mcsm.getSchedule_no());
			plpd.setObject_no_vt(mcsm.getMaterial_no_vt());
			// 如果不存在，则报错退出“分条计划[xxxxx][xx]信息不存在！”
			List<PlnLengthwisePlanDetail> lppd = this.getMapper(PlnLengthwisePlanDetailMapper.class).find(plpd, 0, 0);
			if (lppd == null || lppd.size() == 0) {
				throw new Exception("分条计划[" + mcsm.getSchedule_no() + "][" + mcsm.getMaterial_no_vt() + "]信息不存在！");
			}

			PlnMaterielDetail M1 = new PlnMaterielDetail();
			// 读取 根据计划明细表中的虚拟物料号(母卷号)，查找虚拟物料表【PLN_MATERIEL_DETAIL】，获取虚拟母卷信息 M1
			M1.setObject_no_vt(mcsm.getMaterial_no_vt());
			List<PlnMaterielDetail> lpmd = this.getMapper(PlnMaterielDetailMapper.class).find(M1, 0, 0);
			if (lpmd == null || lpmd.size() == 0) {
				throw new Exception("虚拟物料[" + mcsm.getMaterial_no_vt() + "]信息不存在！");
			}

			// 判断虚拟母卷信息里的 物料号【OBJECT_NO】，如果为空，则报错退出
			M1 = lpmd.get(0);
			if (M1.getObject_no() == null || "".equals(M1.getObject_no())) {
				throw new Exception("分条计划[" + mcsm.getSchedule_no() + "][" + mcsm.getMaterial_no_vt() + "]尚未挂料！");
			}

			// 实际上只有一条
			for (PlnLengthwisePlanDetail ppdc : lppd) {
				// 判断分条计划明细的状态【STATUS】
				if (ppdc.getStatus().compareTo("5BLW02") > 0) {
					throw new Exception(
							"分条计划[" + mcsm.getSchedule_no() + "][" + mcsm.getMaterial_no_vt() + "]已上料，不能再次操作！");
				}
				PrcMaterielProcess pmp = new PrcMaterielProcess();
				pmp.setPrc_code("5BLW03");// 新增的状态

				// 这里的格式要和字符串日期的格式匹配，不然会抛出转换异常
				SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
				if (mcsm.getMemo() != null && !"".equals(mcsm.getMemo())) {
					Date createdate = dateFormat.parse(mcsm.getMemo());
					pmp.setCreate_time(createdate);
				} else {
					pmp.setCreate_time(new Date());
				}

				pmp.setObject_no(M1.getObject_no());
				pmp.setCreate_man_name(userName);
				pmp.setRemark(mcsm.getMemo());
				// 新增物料跟踪：
				INSERT_OBJ_PROCESS(pmp);

				// 修改分条计划明细表
				PlnLengthwisePlanDetail plpdu = new PlnLengthwisePlanDetail();
				plpdu.setStatus("5BLW03");
				plpdu.setSerial_no(ppdc.getSerial_no());
				this.getMapper(PlnLengthwisePlanDetailMapper.class).update(plpdu);
			}

			// 根据母卷号，查询对应的所有子卷信息
			PlnMaterielDetail pmdq = new PlnMaterielDetail();
			pmdq.setMat_object_no_vt(lpmd.get(0).getObject_no_vt());
			List<PlnMaterielDetail> lpmdc = this.getMapper(PlnMaterielDetailMapper.class).findWithCondition(pmdq,
					"  nvl (invalid_flg, '0') <> 1 ", "", 0, 0);
			for (PlnMaterielDetail ppdc : lpmdc) {
				// 修改各子卷的 状态 STATUS= 0PLW03;
				PlnMaterielDetail pmdu = new PlnMaterielDetail();
				pmdu.setSerial_no(ppdc.getSerial_no());
				pmdu.setStatus("0PLW03");
				this.getMapper(PlnMaterielDetailMapper.class).update(pmdu);

				// 增加子卷的 虚拟物料履历表
				InsertMatVtProc(ppdc.getObject_no_vt(), "0PLW03", userName, new Date());
			}

			// 修改分条计划主表
			doUpdatePlnLengthwisePlan(mcsm.getSchedule_no());
			PlnMaterielDetail pmdu = new PlnMaterielDetail();
			// 修改(母卷)虚拟物料表【PLN_MATERIEL_DETAIL】
			pmdu.setSerial_no(lpmd.get(0).getSerial_no());
			pmdu.setStatus("0PLW03");
			this.getMapper(PlnMaterielDetailMapper.class).update(pmdu);
			// 写虚拟物料履历，状态填: 0PLW03 母卷
			InsertMatVtProc(lpmd.get(0).getObject_no_vt(), "0PLW03", userName, new Date());
		}
	}

	/**
	 * 撤销分条上料接口 下PDI 验证1
	 * 
	 * @param 虚拟子卷号
	 * @throws Exception 其实都是单条操作
	 */
	public void MesCrSlittingMCancelValid(List<MesCrSlittingM> oci) throws Exception {
		// 循环 根据(分条计划号数组，虚拟物料号数组) 读取 分条计划明细表【PLN_LENGTHWISE_PLAN_DETAIL】
		for (MesCrSlittingM mcsm : oci) {
			PlnLengthwisePlanDetail plpd = new PlnLengthwisePlanDetail();
			plpd.setLw_plan_no(mcsm.getSchedule_no());
			plpd.setObject_no_vt(mcsm.getMaterial_no_vt());
			// 如果不存在，则报错退出“分条计划[xxxxx][xx]信息不存在！”
			List<PlnLengthwisePlanDetail> lppd = this.getMapper(PlnLengthwisePlanDetailMapper.class).find(plpd, 0, 0);
			if (lppd == null || lppd.size() == 0) {
				throw new Exception("分条计划[" + mcsm.getSchedule_no() + "][" + mcsm.getMaterial_no_vt() + "]信息不存在！");
			}

			PlnMaterielDetail M1 = new PlnMaterielDetail();
			// 读取 根据计划明细表中的虚拟物料号(母卷号)，查找虚拟物料表【PLN_MATERIEL_DETAIL】，获取虚拟母卷信息 M1
			M1.setObject_no_vt(mcsm.getMaterial_no_vt());
			List<PlnMaterielDetail> lpmd = this.getMapper(PlnMaterielDetailMapper.class).find(M1, 0, 0);
			if (lpmd == null || lpmd.size() == 0) {
				throw new Exception("虚拟物料[" + mcsm.getMaterial_no_vt() + "]信息不存在！");
			}

			// 判断虚拟母卷信息里的 物料号【OBJECT_NO】，如果为空，则报错退出
			M1 = lpmd.get(0);
			if (M1.getObject_no() == null || "".equals(M1.getObject_no())) {
				throw new Exception("分条计划[" + mcsm.getSchedule_no() + "][" + mcsm.getMaterial_no_vt() + "]尚未挂料！");
			}

			// 实际上只有一条
			for (PlnLengthwisePlanDetail ppdc : lppd) {
				// 判断分条计划明细的状态【STATUS】
				if (!"5BLW03".equals(ppdc.getStatus())) {
					throw new Exception(
							"分条计划[" + mcsm.getSchedule_no() + "][" + mcsm.getMaterial_no_vt() + "]上料后，经过其他操作，不允许撤销！");
				}
			}
		}
	}

	/**
	 * 撤销分条上料接口 下PDI
	 * 
	 * @param 虚拟子卷号
	 * @throws Exception 其实都是单条操作
	 */
	public void MesCrSlittingMCancel(List<MesCrSlittingM> oci) throws Exception {
		String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);

		// 循环 根据(分条计划号数组，虚拟物料号数组) 读取 分条计划明细表【PLN_LENGTHWISE_PLAN_DETAIL】
		for (MesCrSlittingM mcsm : oci) {
			PlnLengthwisePlanDetail plpd = new PlnLengthwisePlanDetail();
			plpd.setLw_plan_no(mcsm.getSchedule_no());
			plpd.setObject_no_vt(mcsm.getMaterial_no_vt());
			// 如果不存在，则报错退出“分条计划[xxxxx][xx]信息不存在！”
			List<PlnLengthwisePlanDetail> lppd = this.getMapper(PlnLengthwisePlanDetailMapper.class).find(plpd, 0, 0);
			if (lppd == null || lppd.size() == 0) {
				throw new Exception("分条计划[" + mcsm.getSchedule_no() + "][" + mcsm.getMaterial_no_vt() + "]信息不存在！");
			}

			PlnMaterielDetail M1 = new PlnMaterielDetail();
			// 读取 根据计划明细表中的虚拟物料号(母卷号)，查找虚拟物料表【PLN_MATERIEL_DETAIL】，获取虚拟母卷信息 M1
			M1.setObject_no_vt(mcsm.getMaterial_no_vt());
			List<PlnMaterielDetail> lpmd = this.getMapper(PlnMaterielDetailMapper.class).find(M1, 0, 0);
			if (lpmd == null || lpmd.size() == 0) {
				throw new Exception("虚拟物料[" + mcsm.getMaterial_no_vt() + "]信息不存在！");
			}

			// 判断虚拟母卷信息里的 物料号【OBJECT_NO】，如果为空，则报错退出
			M1 = lpmd.get(0);
			if (M1.getObject_no() == null || "".equals(M1.getObject_no())) {
				throw new Exception("分条计划[" + mcsm.getSchedule_no() + "][" + mcsm.getMaterial_no_vt() + "]尚未挂料！");
			}

			// 实际上只有一条
			for (PlnLengthwisePlanDetail ppdc : lppd) {
				// 判断分条计划明细的状态【STATUS】
				if (!"5BLW03".equals(ppdc.getStatus())) {
					throw new Exception(
							"分条计划[" + mcsm.getSchedule_no() + "][" + mcsm.getMaterial_no_vt() + "]上料后，经过其他操作，不允许撤销！");
				}
				PrcMaterielProcess pmp = new PrcMaterielProcess();
				pmp.setObject_no(M1.getObject_no());
				pmp.setPrc_code("5BLW03");
				pmp.setRemark("回退上料");
				pmp.setKeep_sametime_status(0);
				ResultModel al = ARRAYLIST(pmp);
				// 撤销实物物料状态跟踪
				if (!"0".equals(al.getState())) {
					throw new Exception("物料状态不是已上料状态，不允许撤销！");
				}
				// 修改分条计划明细表
				PlnLengthwisePlanDetail plpdu = new PlnLengthwisePlanDetail();
				// V_最后状态
				plpdu.setStatus(((PrcMaterielProcess) al.getData()).getPrc_code());// "5BLW02"
				plpdu.setSerial_no(ppdc.getSerial_no());
				this.getMapper(PlnLengthwisePlanDetailMapper.class).update(plpdu);
			}

			// 根据母卷号，查询对应的所有子卷信息
			PlnMaterielDetail pmdq = new PlnMaterielDetail();
			pmdq.setMat_object_no_vt(lpmd.get(0).getObject_no_vt());
			List<PlnMaterielDetail> lpmdc = this.getMapper(PlnMaterielDetailMapper.class).findWithCondition(pmdq,
					"  nvl (invalid_flg, '0') <> 1 ", "", 0, 0);
			for (PlnMaterielDetail ppdc : lpmdc) {
				// 修改各子卷的 状态 STATUS= 0PLW02;
				PlnMaterielDetail pmdu = new PlnMaterielDetail();
				pmdu.setSerial_no(ppdc.getSerial_no());
				pmdu.setStatus("0PLW02");
				this.getMapper(PlnMaterielDetailMapper.class).update(pmdu);
				// 增加子卷的 虚拟物料履历表
				InsertMatVtProc(ppdc.getObject_no_vt(), "0PLW02", userName, new Date());
			}
			// 修改分条计划主表
			doUpdatePlnLengthwisePlan(mcsm.getSchedule_no());
			PlnMaterielDetail pmdu = new PlnMaterielDetail();
			// 修改(母卷)虚拟物料表【PLN_MATERIEL_DETAIL】
			pmdu.setSerial_no(lpmd.get(0).getSerial_no());
			pmdu.setStatus("0PLW02");
			this.getMapper(PlnMaterielDetailMapper.class).update(pmdu);
			// 写虚拟物料履历，状态填: 0PLW02 母卷
			InsertMatVtProc(lpmd.get(0).getObject_no_vt(), "0PLW02", userName, new Date());
		}
	}
	// --------------------------------分条上料、下PDI
	// End----------------------------------------------------

	// --------------------------------分条完成
	// Start----------------------------------------------------
	/**
	 * 完成 实物 生成接口 产生实物，未挂上单时调用
	 * 
	 * @param OBJECT_NO     实物母卷号
	 * @param SUB_OBJECT_NO 实物子卷号
	 * @param RELATION_TYPE 关系类型 1:改号(原-现号码对应)；2:轧制(板坯-钢板对应)；3:剪切/切割(母-子对应)
	 * @throws Exception
	 */
	public void LengthwiseFinsh_PrcMatRelAdd(PrcMaterielRelation pmr) throws Exception {
		String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		Date createTime = new Date();
		// 调用 新增实物物料状态跟踪: 传入（实物子卷号,5BLW10，操作时间，操作人，""）
		PrcMaterielProcess pmp = new PrcMaterielProcess();
		pmp.setObject_no(pmr.getSub_object_no());
		pmp.setPrc_code("5BLW10");// 新增的状态
		pmp.setCreate_time(createTime);
		pmp.setCreate_man_name(userName);
		pmp.setRemark("");
		// 新增物料跟踪：
		INSERT_OBJ_PROCESS(pmp);

		// 调用公共函数2 建立物料母子对应关系
		pmr.setCreate_man_name(userName);
		pmr.setCreate_time(createTime);
		pmr.setRelation_type(3);
		pmr.setPrc_code("5BLW10");
		pmr.setRemark("");
		doBuildRelation(pmr);
	}

	/**
	 * 撤销分条 实物 撤销生成接口 产生实物，未挂上单时调用
	 * 
	 * @param OBJECT_NO     实物母卷号
	 * @param SUB_OBJECT_NO 实物子卷号
	 * @throws Exception
	 */
	public void LengthwiseFinsh_PrcMatRelRemove(PrcMaterielRelation pmr) throws Exception {
		// 回退子卷物料跟踪：
		PrcMaterielProcess pmp = new PrcMaterielProcess();
		pmp.setObject_no(pmr.getSub_object_no());
		pmp.setPrc_code("5BLW10");
		pmp.setKeep_sametime_status(0);
		pmp.setRemark("撤销分条实物生成");
		ResultModel al = ARRAYLIST(pmp);
		// 撤销实物物料状态跟踪
		if (!"0".equals(al.getState())) {
			throw new Exception("实物[" + pmp.getObject_no() + "]状态已发生改变，不能撤销！");
		}

		// 调用公共函数3 断开物料母子对应关系
		PrcMaterielRelation pmrd = new PrcMaterielRelation();
		pmrd.setObject_no(pmr.getObject_no());
		pmr.setSub_object_no(pmr.getSub_object_no());
		doBuildRelationRemove(pmr);
	}

	/**
	 * 分条完成 虚拟子卷 挂料接口
	 * 
	 * @param dLower       上限
	 * @param dUpper       下限
	 * @param material_no  母卷号
	 * @param OBJECT_NO    实物子卷号
	 * @param object_no_vt 虚拟子卷号
	 * @param create_time  操作时间 注意 传入操作时间 新增履历表和实物进程表的创建时间，使用传入的操作时间
	 * @throws Exception
	 */
	public void LengthwiseFinsh_Relation(PlnMaterielDetail pmd, double dUpper, double dLower) throws Exception {
		String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		Date createTime = new Date();
		// 工序点信息
		List<ComBaseInfo> info = this.getMapper(ComBaseInfoMapper.class).findWithCondition(null,
				"sort_code = '2002' AND validflag = '1'", null, 0, 0);
		ProcessPoint processpoint = new ProcessPoint(info);

		// 新增物料附加信息
		this.getBean(MesApiDesignInfoImpl.class).addChildMaterielExinfo(pmd.getMaterial_no(), pmd.getObject_no(),
				pmd.getObject_no_vt(), processpoint.slitting_code);

		// 调用物流接口，获取实物子卷信息。
		YdmProductDetail ypd = new YdmProductDetail();
		ypd.setCoilno(pmd.getObject_no());
		List<YdmProductDetail> lypd = this.getMapper(YdmProductDetailMapper.class).find(ypd, 0, 0);
		if (lypd == null || lypd.size() == 0) {
			throw new Exception("库存中无[" + pmd.getObject_no() + "]实物卷!");
		}

		// 分条工序代码processpoint.slitting_code 2018-06-13
		// 读取虚拟物料表【PLN_MATERIEL_DETAIL】，获取虚拟子卷信息
		PlnMaterielDetail pmdq = new PlnMaterielDetail();
		pmdq.setObject_no_vt(pmd.getObject_no_vt());
		List<PlnMaterielDetail> lpmd = this.getMapper(PlnMaterielDetailMapper.class).find(pmdq, 0, 0);
		if (lpmd == null || lpmd.size() == 0) {
			throw new Exception("虚拟物料无[" + pmd.getObject_no_vt() + "]卷!");
		}

		if (!lypd.get(0).getSteelcode().equals(lpmd.get(0).getSteel_code())) {
//			throw new Exception("实物卷[" + pmd.getObject_no() + "]和虚拟卷[" + pmd.getObject_no_vt() + "]的牌号不匹配，不能绑定");
		}
		// 2018-08-27 生产完成后厚度按实际情况取值,很有可能和计划不一致,故去此验证.
//		if(lypd.get(0).getThick().doubleValue()!=lpmd.get(0).getThick().doubleValue()){
//			throw new Exception("实物卷["+pmd.getObject_no()+"]和虚拟卷["+pmd.getObject_no_vt()+"]的厚不匹配，不能绑定");
//		}
		// ------------------------2018-03-16------------------------------
		// 100-100>5 考虑偏差
		if ((lypd.get(0).getWidth().doubleValue() - lpmd.get(0).getWidth().doubleValue() > dUpper)
				|| (lypd.get(0).getWidth().doubleValue() - lpmd.get(0).getWidth().doubleValue() < dLower)) {
			throw new Exception("实物卷[" + pmd.getObject_no() + "]和虚拟卷[" + pmd.getObject_no_vt() + "]的宽不匹配，不能绑定");
		}
		// ----------------------------------------------------------------
		if (lpmd.get(0).getObject_no() != null && !"".equals(lpmd.get(0).getObject_no())) {
			// throw new Exception("实物卷[" + pmd.getObject_no() + "]已绑定其他计划, 不能再次绑定！");
		}

		// 调用 新增实物物料状态跟踪: 传入（实物子卷号,5BLW10，操作时间，操作人，""）
		PrcMaterielProcess pmp = new PrcMaterielProcess();
		pmp.setObject_no(pmd.getObject_no());
		pmp.setPrc_code("5BLW10");// 新增的状态
		pmp.setCreate_time(createTime);
		pmp.setCreate_man_name(userName);
		pmp.setRemark("");
		// 新增物料跟踪：
		INSERT_OBJ_PROCESS(pmp);

		// 修改虚拟物料表
		pmdq.setSerial_no(lpmd.get(0).getSerial_no());
		pmdq.setObject_no(pmd.getObject_no());
		pmdq.setStatus("0PLW10");
		pmdq.setIs_finished("1");
		pmdq.setPrev_process_code(processpoint.slitting_code);
		// 获取下个工序代码暂时方法,将来从质量取值
//		String process_code = this.getBean(MesApiCrCrossCuttingMServiceImpl.class).getNext_process("2", pmd.getObject_no_vt());
//		if (process_code != null && !"".equals(process_code)) {
//			pmdq.setNext_process_code(process_code);
//		}
		this.getMapper(PlnMaterielDetailMapper.class).update(pmdq);
		// 新增虚拟子物料履历
		InsertMatVtProc(lpmd.get(0).getObject_no_vt(), "0PLW10", userName, createTime);

		// 2018-06-19 去掉 判断下一工序==null条件(判断虚拟子物料是否是其他子料的原料)
		// 修改改虚拟子物料对应的 订单进程表[PLN_ORDER_STATISTIC]
		PlnOrderStatistic pos = new PlnOrderStatistic();
		pos.setOrder_no(lpmd.get(0).getOrder_no());
		pos.setLw(lpmd.get(0).getSingle_weight());
		pos.setLw_cnt(1);
		this.getMapper(PlnOrderStatisticMapper.class).doUpdatePlaned(pos);

		// 生产订单进程表[PLN_PRODORDER_STATISTIC]信息
		PlnProdorderStatistic pps = new PlnProdorderStatistic();
		pps.setProd_order_no(lpmd.get(0).getProd_order_no());
		pps.setLw(lpmd.get(0).getSingle_weight());
		pps.setLw_cnt(1);
		this.getMapper(PlnProdorderStatisticMapper.class).doUpdatePlaned(pps);

		// 修改虚拟物料对应的 分条计划进程表
		PlnMaterielDetail pmdmq = new PlnMaterielDetail();
		pmdmq.setObject_no_vt(lpmd.get(0).getMat_object_no_vt());
		List<PlnMaterielDetail> lpmdm = this.getMapper(PlnMaterielDetailMapper.class).find(pmdmq, 0, 1);
		PlnLwPlanStatistic plps = new PlnLwPlanStatistic();
		plps.setLw_plan_no(lpmdm.get(0).getLw_plan_no());
		plps.setLw(lpmd.get(0).getSingle_weight());
		plps.setLw_cnt(1);
		this.getMapper(PlnLwPlanStatisticMapper.class).doUpdatePlaned(plps);

		// 调用公共函数2 建立物料母子对应关系
		PrcMaterielRelation pmr = new PrcMaterielRelation();
		pmr.setObject_no(pmd.getMaterial_no());
		pmr.setSub_object_no(pmd.getSub_object_no());
		pmr.setCreate_man_name(userName);
		pmr.setCreate_time(createTime);
		pmr.setRemark("");
		pmr.setRelation_type(3);
		doBuildRelation(pmr);
	}

	/**
	 * 分条完成 不符合计划 实物生成, 新增虚拟子卷挂料
	 * 
	 * @param sub_object_no 实物子卷号
	 * @param material_no   实物母卷号
	 * @param create_time   操作时间 注意 传入操作时间 新增履历表和实物进程表的创建时间，使用传入的操作时间
	 * @throws Exception 2018-06-19
	 */
	public ResultModel LengthwiseFinsh_No_Plan(PlnMaterielDetail pmd) throws Exception {
		ResultModel rm = new ResultModel("200", "");
		String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		// 工序点信息
		List<ComBaseInfo> info = this.getMapper(ComBaseInfoMapper.class).findWithCondition(null,
				"sort_code = '2002' AND validflag = '1'", null, 0, 0);
		ProcessPoint processpoint = new ProcessPoint(info);

		Date createTime = new Date();
		// 调用物流接口，获取实物子卷信息。
		YdmProductDetail ypd = new YdmProductDetail();
		ypd.setCoilno(pmd.getSub_object_no());
		List<YdmProductDetail> lypd = this.getMapper(YdmProductDetailMapper.class).find(ypd, 0, 0);
		if (lypd == null || lypd.size() == 0) {
			throw new Exception("库存中无[" + pmd.getSub_object_no() + "]实物卷!");
		}
		// 获取母卷虚拟物料信息
		PlnMaterielDetail pmdcm = new PlnMaterielDetail();
		pmdcm.setObject_no(pmd.getObject_no());
		List<PlnMaterielDetail> pmdpp = this.getMapper(PlnMaterielDetailMapper.class).findWithCondition(pmdcm,
				" nvl(invalid_flg,0) = 0 ", "", 0, 1);
		if (pmdpp == null || pmdpp.size() == 0) {
			rm.setState("500");
			rm.setMsgInfo("实物[" + pmd.getObject_no() + "]的虚拟物料信息不存在!");
			return rm;
		}
		PlnProdorder pp = new PlnProdorder();
		pp.setProd_order_no(pmdpp.get(0).getProd_order_no());
		List<PlnProdorder> lpp = this.getMapper(PlnProdorderMapper.class).find(pp, 0, 1);
		if (lpp == null || lpp.size() == 0) {
			rm.setState("500");
			rm.setMsgInfo("生产订单[" + pp.getProd_order_no() + "]不存在!");
			return rm;
		}

		// 获取下一个工序
		String temp = this.getBean(MesApiDesignInfoImpl.class)
				.getPath(lpp.get(0).getWhole_process_codes(), processpoint.slitting_code, pmdpp.get(0).getProc_repeat_index());
		String[] path =  temp.split("-");
		ArrayList<String> validpath = this.getBean(MesApiDesignInfoImpl.class).getProcessPath(path);

		// 新建虚拟物料表【PLN_MATERIEL_DETAIL】虚拟子卷信息
		PlnMaterielDetail pmdc = new PlnMaterielDetail();
		// 获取序列号
		List<PlnMaterielDetail> lpmd = this.getMapper(PlnMaterielDetailMapper.class).findWithCondition(null, null,
				" serial_no desc ", 0, 1);
		long PMDNo = lpmd == null ? 1 : (lpmd.size() == 0 ? 1 : (lpmd.get(0).getSerial_no() + 1));
		// 6位日期
		String sDate = new SimpleDateFormat("yyMMdd").format(new Date());
		// 6位流水号
		int objectnoVtNo = this.getMapper(PlnMaterielDetailMapper.class).getObjectVtMaxNoForDate(sDate) + 1;
		pmdc.setSerial_no(PMDNo);
		// 年月日(6位)+6位流水
		pmdc.setObject_no_vt(sDate + String.format("%06d", objectnoVtNo));
		pmdc.setOrder_no(lpp.get(0).getOrder_no());
		pmdc.setObject_no(pmd.getSub_object_no());
		pmdc.setPline_code(lpp.get(0).getPline_code());
		pmdc.setStatus("0PLW10");
		pmdc.setIs_finished("1");
		pmdc.setPrev_dsn_process_code(processpoint.slitting_code);
		pmdc.setPrev_process_code(processpoint.slitting_code);
		// 获取下个工序代码暂时方法,将来从质量取值
//		List<PlnProcessPlan> ppp = this.getMapper(PlnProcessPlanMapper.class).findWithCondition(null, " produce_no = '"+lpp.get(0).getProduce_no()+"' and valid_flag = 1 and cut_order_no = 1", "", 0, 0);
//		if (ppp != null && ppp.size()>0) {
//			if (ppp.get(0).getCut_type() != null && "3".equals(ppp.get(0).getCut_type())) {
//				 pmdc.setNext_process_code(processpoint.cross_cutting_code);
//				 pmdc.setNext_dsn_process_code(processpoint.cross_cutting_code);
//			}
//		}
		if (Utils.isNotEmpty(validpath)) {
			pmdc.setNext_dsn_process_code(validpath.get(0));
			pmdc.setNext_process_code(validpath.get(0));
		}
		pmdc.setIs_prev_dsn_finished("1");// 母卷：0
		pmdc.setCreate_design_no(pmdpp.get(0).getLw_design_no());
		pmdc.setCreate_process_code(processpoint.slitting_code);
		pmdc.setIs_mat(0);// 母卷：1
		pmdc.setOrder_no(lpp.get(0).getOrder_no());
		pmdc.setProd_order_no(lpp.get(0).getProd_order_no());
		pmdc.setPline_code(lpp.get(0).getPline_code());
		pmdc.setLw_design_no(pmdpp.get(0).getLw_design_no());
		pmdc.setCl_plan_no(pmdpp.get(0).getCl_plan_no());
		pmdc.setMat_object_no_vt(pmdpp.get(0).getObject_no_vt());
		pmdc.setIs_multi("0");
		pmdc.setSteel_code(lpp.get(0).getSteel_code());
		pmdc.setWidth(lypd.get(0).getWidth());
		pmdc.setThick(lypd.get(0).getThick());
		pmdc.setLength(lypd.get(0).getLength());
		pmdc.setDiameter_inn(lypd.get(0).getDiameter_inn());
		pmdc.setDiameter_out(lypd.get(0).getDiameter_out());
		pmdc.setSingle_weight(lypd.get(0).getFactweight());
		pmdc.setFixed_length_type_no(lpp.get(0).getFixed_length_type_no());
		pmdc.setCut_edge_type_no(lpp.get(0).getCut_edge_type_no());
		pmdc.setOrd_flg("2");
		pmdc.setCreate_man_name(userName);
		pmdc.setCreate_time(createTime);
		pmdc.setDeliver_date_earliest(lpp.get(0).getDeliver_date());
		pmdc.setDeliver_date_latest(lpp.get(0).getDeliver_date());
		this.getMapper(PlnMaterielDetailMapper.class).insert(pmdc);

		// 新增物料附加信息
		this.getBean(MesApiDesignInfoImpl.class).addChildMaterielExinfo(pmd.getObject_no(), pmd.getSub_object_no(),
				pmdc.getObject_no_vt(), processpoint.slitting_code);

		// 子卷存在下一个工序
		if (Utils.isNotEmpty(validpath)) {
			// 调用设计信息接口
			List<DesignInfo> infos = new ArrayList<>();
			DesignInfo infor = new DesignInfo();
			infor.setCurrentProcIndex(0);
			infor.setObject_no(pmd.getSub_object_no());
			infor.setObject_no_vt(pmdc.getObject_no_vt());
			infor.setProcess(validpath);
			infor.setProd_order_no(pmdpp.get(0).getProd_order_no());
			infor.setSingle_wgt(lypd.get(0).getFactweight());
			infos.add(infor);
			ResultModel result = this.getBean(MesApiDesignInfoImpl.class).Design_Plan_Info(infos, null);
			if (!"200".equals(result.getState())) {
				throw new Exception("生产设计信息失败" + result.getMsgInfo());
			}
		}

		// 反写子卷实绩的虚拟物料号 2018-09-20
		MesCrSlittingD mcd = new MesCrSlittingD();
		mcd.setCoil_no(pmd.getSub_object_no());
		mcd.setCoil_no_vt(pmdc.getObject_no_vt());
		this.getMapper(MesCrSlittingDMapper.class).update(mcd);

		// 反写实物虚拟物料号
		ypd.setObject_no_vt(pmdc.getObject_no_vt());
		this.getMapper(YdmProductDetailMapper.class).update(ypd);

		// 调用 新增实物物料状态跟踪: 传入（实物子卷号,5BLW10，操作时间，操作人，""）
		PrcMaterielProcess pmp = new PrcMaterielProcess();
		pmp.setObject_no(pmd.getSub_object_no());
		pmp.setPrc_code("5BLW10");
		pmp.setCreate_time(createTime);
		pmp.setCreate_man_name(userName);
		pmp.setRemark("");
		// 新增物料跟踪：
		INSERT_OBJ_PROCESS(pmp);

		// 新增虚拟子物料履历
		InsertMatVtProc(pmdc.getObject_no_vt(), "0PLW10", userName, createTime);

		// 修改改虚拟子物料对应的 订单进程表[PLN_ORDER_STATISTIC]
		PlnOrderStatistic pos = new PlnOrderStatistic();
		pos.setOrder_no(lpp.get(0).getOrder_no());
		pos.setLw(pmdc.getSingle_weight());
		pos.setLw_cnt(1);
		this.getMapper(PlnOrderStatisticMapper.class).doUpdatePlaned(pos);

		// 生产订单进程表[PLN_PRODORDER_STATISTIC]信息
		PlnProdorderStatistic pps = new PlnProdorderStatistic();
		pps.setProd_order_no(pmdc.getProd_order_no());
		pps.setLw(pmdc.getSingle_weight());
		pps.setLw_cnt(1);
		this.getMapper(PlnProdorderStatisticMapper.class).doUpdatePlaned(pps);

		// 修改虚拟物料对应的 分条计划进程表
		PlnMaterielDetail pmdmq = new PlnMaterielDetail();
		pmdmq.setObject_no_vt(pmdc.getMat_object_no_vt());
		List<PlnMaterielDetail> lpmdm = this.getMapper(PlnMaterielDetailMapper.class).find(pmdmq, 0, 1);
		PlnLwPlanStatistic plps = new PlnLwPlanStatistic();
		plps.setLw_plan_no(lpmdm.get(0).getLw_plan_no());
		plps.setLw(pmdc.getSingle_weight());
		plps.setLw_cnt(1);
		this.getMapper(PlnLwPlanStatisticMapper.class).doUpdatePlaned(plps);

		// 调用公共函数2 建立物料母子对应关系
		PrcMaterielRelation pmr = new PrcMaterielRelation();
		pmr.setObject_no(pmd.getMaterial_no());
		pmr.setSub_object_no(pmd.getSub_object_no());
		pmr.setCreate_man_name(userName);
		pmr.setCreate_time(createTime);
		pmr.setRemark("");
		pmr.setRelation_type(3);
		doBuildRelation(pmr);
		return rm;
	}

	/**
	 * 撤销分条 虚拟子卷 挂料接口
	 * 
	 * @param OBJECT_NO    实物子卷号
	 * @param object_no_vt 虚拟子卷号
	 * @throws Exception
	 */
	public void LengthwiseFinsh_RelationCancel(PlnMaterielDetail pmd) throws Exception {
		String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		// 工序点信息
		List<ComBaseInfo> info = this.getMapper(ComBaseInfoMapper.class).findWithCondition(null,
				"sort_code = '2002' AND validflag = '1'", null, 0, 0);
		ProcessPoint processpoint = new ProcessPoint(info);

		// 调用物流接口，获取实物子卷信息。
		YdmProductDetail ypd = new YdmProductDetail();
		ypd.setCoilno(pmd.getObject_no());
		List<YdmProductDetail> lypd = this.getMapper(YdmProductDetailMapper.class).find(ypd, 0, 0);
		if (lypd == null || lypd.size() == 0) {
			throw new Exception("库存中无[" + pmd.getObject_no() + "]实物卷!");
		}

		// 读取虚拟物料表【PLN_MATERIEL_DETAIL】，获取虚拟子卷信息
		List<PlnMaterielDetail> lpmd = this.getMapper(PlnMaterielDetailMapper.class).findWithCondition(null,
				"object_no_vt = '" + pmd.getObject_no_vt() + "' and nvl(invalid_flg,0) = '0'", null, 0, 1);
		if (lpmd == null || lpmd.size() == 0) {
			throw new Exception("虚拟物料无[" + pmd.getObject_no_vt() + "]卷!");
		}

		// 读取虚拟物料表【PLN_MATERIEL_DETAIL】，获取虚拟子卷的母卷信息
		List<PlnMaterielDetail> lpmdm = this.getMapper(PlnMaterielDetailMapper.class).findWithCondition(null,
				"object_no_vt = '" + lpmd.get(0).getMat_object_no_vt() + "' and nvl(invalid_flg,0) = '0'", null, 0, 1);
		if (lpmdm == null || lpmdm.size() == 0) {
			throw new Exception("虚拟物料无[" + pmd.getObject_no_vt() + "]卷!");
		}

		if (lpmdm.get(0).getObject_no() == null || "".equals(lpmdm.get(0).getObject_no())) {
			throw new Exception("实物卷[" + pmd.getObject_no() + "]尚未绑定该计划，不能回退！");
		}

		// 下一个工序做了计划就不能回退
		if (Utils.isNotEmpty(pmd.getNext_dsn_process_code())) {
			this.getBean(MesApiDesignInfoImpl.class).JudgeIsOrNotPlan(lpmd.get(0));
		}

		// 物料充当脱单履历
//		this.getBean(MesApiDesignInfoImpl.class).createMatLog(lpmd.get(0), "厂内合同取消交工",userName, lpmd.get(0).getPrev_process_code() , "-1", pmd.getObject_no());
		
		// 回退子卷物料跟踪：
		PrcMaterielProcess pmp = new PrcMaterielProcess();
		pmp.setObject_no(pmd.getObject_no());
		pmp.setPrc_code("5BLW10");
		pmp.setKeep_sametime_status(0);
		pmp.setRemark("撤销子卷挂料");
		ResultModel al = ARRAYLIST(pmp);
		// 撤销实物物料状态跟踪
		if (!"0".equals(al.getState())) {
			throw new Exception("分条完成后，实物[" + pmp.getObject_no() + "]状态已发生改变，不能撤销！");
		}

		// 修改虚拟物料表
		PlnMaterielDetail pmdu = new PlnMaterielDetail();
		pmdu.setObject_no_vt(pmd.getObject_no_vt());
		pmdu.setSerial_no(lpmd.get(0).getSerial_no());
		pmdu.setStatus("0PLW03");
		pmdu.setIs_finished("0");
		pmdu.setPrev_process_code(processpoint.slitting_code);
		// 获取下个工序代码暂时方法,将来从质量取值
//		String process_code = this.getBean(MesApiCrCrossCuttingMServiceImpl.class).getNext_process("2",
//				pmd.getObject_no_vt());
//		if (process_code != null && !"".equals(process_code)) {
//			pmdu.setNext_process_code(process_code);
//		}
		this.getMapper(PlnMaterielDetailMapper.class).doUpdateCancelRelation(pmdu);
		// 新增虚拟子物料履历
		InsertMatVtProc(lpmd.get(0).getObject_no_vt(), "0PLW03", userName, new Date());
		// 判断虚拟子物料是否有其他子料的原料 2018-10-16 去掉测验证和交工保持一致
//		if(lpmd.get(0).getNext_dsn_process_code()==null||"".equals(lpmd.get(0).getNext_dsn_process_code())){
		// 修改改虚拟子物料对应的 订单进程表[PLN_ORDER_STATISTIC]
		PlnOrderStatistic pos = new PlnOrderStatistic();
		pos.setOrder_no(lpmd.get(0).getOrder_no());
		pos.setLw(lpmd.get(0).getSingle_weight() == null ? null : (-lpmd.get(0).getSingle_weight()));
		pos.setLw_cnt(-1);
		this.getMapper(PlnOrderStatisticMapper.class).doUpdatePlaned(pos);
		// 生产订单进程表[PLN_PRODORDER_STATISTIC]信息
		PlnProdorderStatistic pps = new PlnProdorderStatistic();
		pps.setProd_order_no(lpmd.get(0).getProd_order_no());
		pps.setLw(lpmd.get(0).getSingle_weight() == null ? null : (-lpmd.get(0).getSingle_weight()));
		pps.setLw_cnt(-1);
		this.getMapper(PlnProdorderStatisticMapper.class).doUpdatePlaned(pps);
//		}

		// 修改虚拟物料对应的 分条计划进程表
		PlnLwPlanStatistic plps = new PlnLwPlanStatistic();
		plps.setLw_plan_no(lpmdm.get(0).getLw_plan_no());
		plps.setLw(lpmd.get(0).getSingle_weight() == null ? null : (-lpmd.get(0).getSingle_weight()));
		plps.setLw_cnt(-1);
		this.getMapper(PlnLwPlanStatisticMapper.class).doUpdatePlaned(plps);
		// 调用公共函数3 断开物料母子对应关系
		PrcMaterielRelation pmr = new PrcMaterielRelation();
		pmr.setObject_no(lpmdm.get(0).getObject_no());
		pmr.setSub_object_no(lpmd.get(0).getObject_no());
		doBuildRelationRemove(pmr);

		// 厂内合同子卷生产完成时,清空库存信息订单信息
//		boolean flag_Ct = this.getBean(MesApiDesignInfoImpl.class).getContractType(lpmd.get(0).getProd_order_no());
//		boolean flag_Mf = this.getBean(MesApiDesignInfoImpl.class).matIsFinish(pmd.getObject_no());
//		if (flag_Mf && flag_Ct) {
//			YdmProductDetail ydm = new YdmProductDetail();
//			ydm.setCoilno(pmd.getObject_no());
//			ydm.setProdorderno(lpmd.get(0).getProd_order_no());
//			ydm.setOrderno(lpmd.get(0).getOrder_no());
//			ydm.setObject_no_vt(pmd.getObject_no_vt());
//			this.getMapper(YdmProductDetailMapper.class).update(ydm);
//			;
//		}
		// 删除物料附加信息
		this.getMapper(PrcMaterielExtinfoMapper.class).delete(pmd.getObject_no());

		// 判断虚拟子卷信息，是否是额外的成品(ORD_FLG = 2), 如果是，则需释放虚拟子堆垛，调用接口:纵剪——虚拟子堆垛 释放接口
		if ("2".equals(lpmd.get(0).getOrd_flg())) {
			LengthwiseFinsh_Release(pmd);
		}
	}

	/**
	 * 分条完成 虚拟子卷 释放接口
	 * 
	 * @param object_no_vt 虚拟子卷号
	 * @throws Exception
	 */
	public void LengthwiseFinsh_Release(PlnMaterielDetail pmd) throws Exception {
		String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		// 工序点信息
		List<ComBaseInfo> info = this.getMapper(ComBaseInfoMapper.class).findWithCondition(null,
				"sort_code = '2002' AND validflag = '1'", null, 0, 0);
		ProcessPoint processpoint = new ProcessPoint(info);

		// 读取虚拟物料表【PLN_MATERIEL_DETAIL】，获取虚拟子卷信息
		PlnMaterielDetail pmdq = new PlnMaterielDetail();
		pmdq.setObject_no_vt(pmd.getObject_no_vt());
		List<PlnMaterielDetail> lpmd = this.getMapper(PlnMaterielDetailMapper.class).find(pmdq, 0, 0);
		if (lpmd == null || lpmd.size() == 0) {
			throw new Exception("虚拟物料无[" + pmd.getObject_no_vt() + "]卷!");
		}

		// ------------------------2018-06-19-------------------------
		// 判断虚拟子卷信息，是否是额外的成品(ORD_FLG = 2), 如果不成立， 则报错退出，“虚拟物料[xxx]不是额外成品，不能释放！”
		if (!"2".equals(lpmd.get(0).getOrd_flg())) {
			throw new Exception("虚拟物料[" + pmd.getObject_no_vt() + "]不是额外成品，不能释放！");
		}
		// 判断虚拟子卷是否是分条的虚拟成品
		if (!processpoint.slitting_code.equals(lpmd.get(0).getPrev_dsn_process_code())) {
			throw new Exception("虚拟子卷[" + pmd.getObject_no_vt() + "]不是分条设计成品，无法释放！");
		}
		PlnMaterielDetail pmdqd = new PlnMaterielDetail();
		pmdqd.setMat_object_no_vt(pmd.getObject_no_vt());
		List<PlnMaterielDetail> child = this.getMapper(PlnMaterielDetailMapper.class).findWithCondition(null,
				"mat_object_no_vt = '" + pmd.getObject_no_vt() + "' and nvl(invalid_flg,0) = '0'", null, 0, 0);
//		int count = this.getMapper(PlnMaterielDetailMapper.class).count(pmdqd);
		if (Utils.isNotEmpty(child)) {
			// 删除子卷
			this.getBean(MesApiDesignInfoImpl.class).deleteChildTrue(child);
//			throw new Exception("虚拟子卷["+pmd.getObject_no_vt()+"]作为后一工序的原料，已经挂单，无法释放！");
		}
		// ------------------------------------------------------------

		// 判断虚拟子卷是否是其他物料母卷: IF(NEXT_DSN_PROCESS_CODE == NULL)
		// if(lpmd.get(0).getNext_dsn_process_code()==null||"".equals(lpmd.get(0).getNext_dsn_process_code())){

		// 新增虚拟物料履历表【PRC_MATERIEL_VT_PROCESS】记录，状态标记为“0PLWXX”
		InsertMatVtProc(lpmd.get(0).getObject_no_vt(), "0PLWXX", userName, new Date());

		// 将虚拟物料信息 从虚拟物料表【PLN_MATERIEL_DETAIL】移动到 无效虚拟物料表【PLN_MATERIEL_INVALID】.
		// (两个表结构一样，移动后，保持serial_no不变，删除原表记录)
		List<PlnMaterielInvalid> pmin = this.getMapper(PlnMaterielInvalidMapper.class).findWithCondition(null, " serial_no = '"+lpmd.get(0).getSerial_no()+"' or object_no_vt = '"+lpmd.get(0).getObject_no_vt()+"'", "", 0, 0);
		if (pmin !=null && pmin.size()>0) {
			this.getMapper(PlnMaterielInvalidMapper.class).delete(lpmd.get(0).getSerial_no());
		}
		PlnMaterielInvalid pmi=new PlnMaterielInvalid();
		BeanUtils.copyProperties(lpmd.get(0), pmi);
		this.getMapper(PlnMaterielInvalidMapper.class).insert(pmi);
		this.getMapper(PlnMaterielDetailMapper.class).doDeleteId(lpmd.get(0));

//			//MesCrSlittingD mcsd=this.getMapper(MesCrSlittingDMapper.class).findById(lpmd.get(0).getObject_no());
//			//修改 虚拟子卷 对应的分条计划进程表【PLN_LW_PLAN_STATISTIC】，PLANED 总成品量-=子卷重量；PLANED_CNT 总成品数-=1
//			PlnLwPlanStatistic plps=new PlnLwPlanStatistic();
//			plps.setLw_plan_no(pmi.getLw_plan_no());
//			plps.setPlaned(pmi.getSingle_weight()==null?null:(-pmi.getSingle_weight()));//-mcsd.getCoil_act_wgt()
//			plps.setPlaned_cnt(-1);
//			this.getMapper(PlnLwPlanStatisticMapper.class).doUpdatePlaned(plps);
//			
//			PlnProdorderStatistic pps=new PlnProdorderStatistic();
//			Double db=lpmd.get(0).getSingle_weight()==null?null:(-lpmd.get(0).getSingle_weight());
//			pps.setProd_order_no(lpmd.get(0).getProd_order_no());
//			pps.setUnscheduled(lpmd.get(0).getSingle_weight());
//			pps.setUnscheduled_cnt(1);
//			pps.setLw_dsn(db);
//			pps.setLw_dsn_cnt(-1);
//			pps.setLw_undsn(lpmd.get(0).getSingle_weight());
//			pps.setLw_undsn_cnt(1);
//			pps.setLw_planed(db);
//			pps.setLw_planed_cnt(-1);
//			this.getMapper(PlnProdorderStatisticMapper.class).doUpdatePlaned(pps);
//		}else{
//			//断开此子卷和其母卷的关联
//			//一期不会出现此情况，可暂时不写
//			PlnMaterielDetail pmdu=new PlnMaterielDetail();
//			pmdu.setPrev_process_code(processpoint.slitting_code);
//			pmdu.setObject_no_vt(pmd.getObject_no_vt());
//			//pmdu.setNext_process_code("(后期需要根据 工艺路径 填写)");
//			this.getMapper(PlnMaterielDetailMapper.class).doUpdateRelease(pmdu);
//		
//			//根据 虚拟子卷信息中的【CREATE_DESIGN_NO 生成时的设计号】
//			//读取 坯料设计订单组成表【PLN_DSN_ORDER_INFO】的相关联的所有生产订单统计信息
//			//并修改对应的生产订单进程表【PLN_PRODORDER_STATISTIC】数据:
//			PlnDsnOrderInfo pdoi=new PlnDsnOrderInfo();
//			pdoi.setDesign_no(lpmd.get(0).getCreate_design_no());
//			List<PlnDsnOrderInfo> lpdoi=this.getBean(PlnDsnOrderInfoMapper.class).find(pdoi, 0, 0);
//			//PlnDsnOrderInfo唯一键是Design_no+prod_order_no
//			for(PlnDsnOrderInfo pdoic:lpdoi){
//				PlnProdorderStatistic pps=new PlnProdorderStatistic();
//				pps.setLw_dsn(-pdoic.getWeight_in_one());
//				pps.setLw_dsn_cnt(-pdoic.getQuantity_in_one());
//				pps.setLw_undsn(pdoic.getWeight_in_one());
//				pps.setLw_undsn_cnt(1);//(非空时计算)
//				pps.setLw_planed(-pdoic.getWeight_in_one());
//				pps.setLw_planed_cnt(-1);
//				this.getMapper(PlnProdorderStatisticMapper.class).doUpdatePlaned(pps);
//			}
//			
//			//修改 虚拟子卷 对应的订单进程表【PLN_PRODORDER_STATISTIC】
//			PlnOrderStatistic pos=new PlnOrderStatistic();
//			pos.setOrder_no(lpmd.get(0).getOrder_no());
//			Double db=lpmd.get(0).getSingle_weight()==null?null:(-lpmd.get(0).getSingle_weight());
//			pos.setOrder_no(lpmd.get(0).getOrder_no());
//			pos.setUnscheduled(lpmd.get(0).getSingle_weight());
//			pos.setUnscheduled_cnt(1);
//			pos.setLw_dsn(db);
//			pos.setLw_dsn_cnt(-1);
//			pos.setLw_undsn(lpmd.get(0).getSingle_weight());
//			pos.setLw_undsn_cnt(1);//(非空时计算)
//			pos.setLw_planed(db);
//			pos.setLw_planed_cnt(-1);
//			this.getMapper(PlnOrderStatisticMapper.class).doUpdatePlaned(pos);
//			
//		}
	}

	/**
	 * 分条完成 虚拟母卷统计
	 * 
	 * @param object_no_vt 虚拟母卷号
	 * @param object_no    实物母卷号 2018-09-28 修改 未挂单子卷标记为无效 方便撤销的时候恢复 2018-12-12
	 *                     取消未挂单子卷标记为无效 步骤
	 * @throws Exception
	 */
	public void LengthwiseFinsh_Sum(PlnMaterielDetail pmd) throws Exception {
		String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		Date createTime = new Date();
		String plan_no = null ;
		// 工序点信息
		List<ComBaseInfo> infoi = this.getMapper(ComBaseInfoMapper.class).findWithCondition(null,
				"sort_code = '2002' AND validflag = '1'", null, 0, 0);
		ProcessPoint processpoint = new ProcessPoint(infoi);

		// 修改物料附加信息
		this.getBean(MesApiDesignInfoImpl.class).updateMExInfo(pmd.getObject_no(), processpoint.slitting_code, true);
		// 读取虚拟物料表【PLN_MATERIEL_DETAIL】，获取虚拟母卷信息
		PlnMaterielDetail pmdq = new PlnMaterielDetail();
		pmdq.setObject_no_vt(pmd.getObject_no_vt());
		List<PlnMaterielDetail> lpmd = this.getMapper(PlnMaterielDetailMapper.class).findWithCondition(pmdq, "nvl(invalid_flg , 0) <> 1", null, 0, 1);
		if (lpmd == null || lpmd.size() == 0) {
			throw new Exception("虚拟物料无[" + pmd.getObject_no_vt() + "]卷!");
		}
		if (lpmd.get(0).getObject_no() == null || "".equals(lpmd.get(0).getObject_no())) {
			throw new Exception("计划母卷[" + pmd.getObject_no_vt() + "]未上料, 不能分条！");
		}
		plan_no = lpmd.get(0).getLw_plan_no();
		// 新增母卷物料跟踪：调用 新增实物物料状态跟踪
		PrcMaterielProcess pmp = new PrcMaterielProcess();
		pmp.setPrc_code("5BLW10");// 新增的状态
		pmp.setCreate_time(createTime);
		pmp.setObject_no(pmd.getObject_no());
		pmp.setCreate_man_name(userName);
		pmp.setRemark("");
		// 新增物料跟踪：
		INSERT_OBJ_PROCESS(pmp);
		// 判断虚拟母卷对应的虚拟子卷是否 挂料完成
		PlnMaterielDetail pmdc = new PlnMaterielDetail();
		pmdc.setMat_object_no_vt(lpmd.get(0).getObject_no_vt());
		List<PlnMaterielDetail> lpmdc = this.getMapper(PlnMaterielDetailMapper.class).findWithCondition(null,
				"mat_object_no_vt = '" + lpmd.get(0).getObject_no_vt() + "' and nvl(invalid_flg,0) =0", "", 0, 0);
		int isum = 0;
		if (lpmdc != null && lpmdc.size() > 0) {
			for (PlnMaterielDetail pmdcc : lpmdc) {
				PlnMaterielDetail pmdcu = new PlnMaterielDetail();
				pmdcu.setSerial_no(pmdcc.getSerial_no());
				pmdcu.setIs_finished("1");
				this.getMapper(PlnMaterielDetailMapper.class).update(pmdcu);
				if (pmdcc.getObject_no() == null || "".equals(pmdcc.getObject_no())) {
					// 统计 (OBJECT_NO=NULL的子卷数量)、虚拟子卷总数量
					isum += 1;
				}
			}
			// 如果（OBJECT_NO为NULL的数量==子卷总数
			if (isum == lpmdc.size()) {
				// 读取物料关系表【PRC_MATERIEL_RELATION】(where OBJECT_NO=实物母卷号 AND RELATION_TYPE=3)的记录
				PrcMaterielRelation pmr = new PrcMaterielRelation();
				pmr.setObject_no(lpmd.get(0).getObject_no());
				pmr.setRelation_type(3);
				List<PrcMaterielRelation> lpmr = this.getMapper(PrcMaterielRelationMapper.class).find(pmr, 0, 0);
				if (lpmr == null || lpmr.size() == 0) {
					// 如果 关系表记录为空（说明实物卷未切割，计划未执行）,直接报错退出“母卷xxxx尚未进行切割操作！”；
					throw new Exception("母卷[" + pmr.getObject_no() + "]尚未进行切割操作！");
				} else {
					// 修改虚拟物料表的母卷记录：OBJECT_NO=NULL; NEED_EXTOPT=1; LW_PLAN_NO=NULL
					PlnMaterielDetail pmdu = new PlnMaterielDetail();
					pmdu.setObject_no_vt(lpmd.get(0).getObject_no_vt());
					pmdu.setNeed_extopt("1");
					this.getMapper(PlnMaterielDetailMapper.class).doUpdateLengthwiseFinshSum(pmdu);
				}
			} else {
				// 获取虚拟母卷的下一工序代码，计算下一工序的 已设计量/数，欠设计量：欠设计量 +=(母卷单重 )
				// 获取下个工序代码暂时方法,将来从质量取值
//				String process_code = this.getBean(MesApiCrCrossCuttingMServiceImpl.class).getNext_process("2",
//						pmd.getObject_no_vt());
//				// 横剪,将来加上12mm
//				if (process_code != null && processpoint.cross_cutting_code.equals(process_code)) {
//					// 修改生产订单进程表
//					PlnProdorderStatistic pps = new PlnProdorderStatistic();
//					pps.setProd_order_no(lpmd.get(0).getProd_order_no());
//					pps.setCl_undsn(lpmd.get(0).getSingle_weight());
//					this.getMapper(PlnProdorderStatisticMapper.class).doUpdatePlaned(pps);
//					// 修改订单进程表
//					PlnOrderStatistic pos = new PlnOrderStatistic();
//					pos.setOrder_no(lpmd.get(0).getOrder_no());
//					pos.setCl_undsn(lpmd.get(0).getSingle_weight());
//					this.getMapper(PlnOrderStatisticMapper.class).doUpdateClPlaned(pos);
//				}
//				this.getBean(MesApiDesignInfoImpl.class).updatePlnStatic(lpmd.get(0).getProd_order_no(), lpmd.get(0).getOrder_no(), lpmd.get(0).getNext_dsn_process_code(), lpmd.get(0).getSingle_weight(), true);
			}
		}

		// 修改虚拟物料表OPT_TIMES+=1; STATUS= 0PLW10；
		// IS_NEXT_FINISHED=1(2018-06-19)（同步修改S1的[OPT_TIMES]、[STATUS]
		PlnMaterielDetail pmdu = new PlnMaterielDetail();
		pmdu.setSerial_no(lpmd.get(0).getSerial_no());
		pmdu.setIs_next_finished("1");
		pmdu.setOpt_times((lpmd.get(0).getOpt_times() == null ? 0 : lpmd.get(0).getOpt_times()) + 1);
		pmdu.setStatus("0PLW10");
		this.getMapper(PlnMaterielDetailMapper.class).update(pmdu);

		// 新增虚拟物料履历表【PRC_MATERIEL_VT_PROCESS】记录
		// -------------2018-03-21-------这个地方的lw_plan_no有点特殊的地方，所以没有直接调用InsertMatVtProc接口------------
		PlnMaterielDetail pmdcq = new PlnMaterielDetail();
		pmdcq.setObject_no_vt(lpmd.get(0).getObject_no_vt());
		List<PlnMaterielDetail> lpmdq = this.getMapper(PlnMaterielDetailMapper.class).find(pmdcq, 0, 0);
		// 写虚拟物料履历，状态填: 子卷
		PrcMaterielVtProcess pmvpc = new PrcMaterielVtProcess();
		
		// 20191001
		long serial_no = 0l;
		List<PrcMaterielVtProcess> pmpQ = this.getMapper(PrcMaterielVtProcessMapper.class).findWithCondition(null, "", "serial_no desc", 0, 1);
		if (Utils.isNotEmpty(pmpQ)) {
			serial_no = pmpQ.get(0).getSerial_no()+1;
		}
		pmvpc.setSerial_no(serial_no);
		// end
		
		pmvpc.setObject_no_vt(lpmdq.get(0).getObject_no_vt());
		pmvpc.setObject_no(lpmdq.get(0).getObject_no());
		pmvpc.setObject_type(lpmdq.get(0).getObject_type());
		pmvpc.setPline_code(lpmdq.get(0).getPline_code());
		pmvpc.setStatus("0PLW10");
		pmvpc.setOrder_no(lpmdq.get(0).getOrder_no());
		pmvpc.setProd_order_no(lpmdq.get(0).getProd_order_no());
		pmvpc.setLw_design_no(lpmdq.get(0).getLw_design_no());
		pmvpc.setCl_design_no(lpmdq.get(0).getCl_design_no());
		pmvpc.setRl_design_no(lpmdq.get(0).getRl_design_no());
		pmvpc.setLw_plan_no(plan_no);
		pmvpc.setCl_plan_no(lpmdq.get(0).getCl_plan_no());
		pmvpc.setRl_plan_no(lpmdq.get(0).getRl_plan_no());
		pmvpc.setSr_plan_no(lpmd.get(0).getSr_plan_no());
		pmvpc.setSr_design_no(lpmd.get(0).getSr_design_no());
		pmvpc.setAn_plan_no(lpmd.get(0).getAn_plan_no());
		pmvpc.setAn_design_no(lpmd.get(0).getAn_design_no());
		pmvpc.setBatch_no(lpmdq.get(0).getBatch_no());
		pmvpc.setCreate_man_name(userName);
		pmvpc.setCreate_time(createTime);
		this.getMapper(PrcMaterielVtProcessMapper.class).doAdd(pmvpc);
		// ----------------------------------------------------------------------

		// 修改虚拟物料对应的 分条计划进程表
		// MesCrSlittingD
		// mcsd=this.getMapper(MesCrSlittingDMapper.class).findById(lpmd.get(0).getObject_no());
		PlnLwPlanStatistic plps = new PlnLwPlanStatistic();
		plps.setMat_lw(lpmd.get(0).getSingle_weight());// mcsd.getCoil_act_wgt());
		plps.setMat_lw_cnt(1);
		plps.setLw_plan_no(plan_no);
		this.getMapper(PlnLwPlanStatisticMapper.class).doUpdatePlaned(plps);

		// 分条计划明细表【PLN_LENGTHWISE_PLAN_DETAIL】：STATUS= 5BLW10
		PlnLengthwisePlanDetail plpd = new PlnLengthwisePlanDetail();
		plpd.setLw_plan_no(plan_no);
		// 分条计划明细表【PLN_LENGTHWISE_PLAN_DETAIL】：STATUS= 5BLW10
		plpd.setStatus("5BLW10");
		plpd.setObject_no_vt(pmd.getObject_no_vt());
		this.getMapper(PlnLengthwisePlanDetailMapper.class).doUpdate(plpd);

		// 分条计划主表【PLN_LENGTHWISE_PLAN】：调用公共函数1（分条计划号）;
		doUpdatePlnLengthwisePlan(plan_no);

		// 将未挂单的子卷 置为无效
//		List<PlnMaterielDetail> child=this.getMapper(PlnMaterielDetailMapper.class).findWithCondition(null, "mat_object_no_vt = '"+lpmd.get(0).getObject_no_vt()+"' and nvl(invalid_flg,0) =0 and object_no is null", "", 0, 0);
//		if (Utils.isNotEmpty(child)) {
//			this.getBean(MesApiDesignInfoImpl.class).deleteChild(child);
//		}
	}

	/**
	 * 撤销分条 撤销虚拟母卷统计
	 * 
	 * @param object_no_vt 虚拟母卷号
	 * @param object_no    实物母卷号
	 * @throws Exception
	 */
	public void LengthwiseFinsh_SumCancel(PlnMaterielDetail pmd) throws Exception {
		String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);

		// 工序点信息
		List<ComBaseInfo> infoi = this.getMapper(ComBaseInfoMapper.class).findWithCondition(null,
				"sort_code = '2002' AND validflag = '1'", null, 0, 0);
		ProcessPoint processpoint = new ProcessPoint(infoi);

		// 修改物料附加信息
		this.getBean(MesApiDesignInfoImpl.class).updateMExInfo(pmd.getObject_no(), processpoint.slitting_code, false);

		// 读取虚拟物料表【PLN_MATERIEL_DETAIL】，获取虚拟母卷信息
		PlnMaterielDetail pmdq = new PlnMaterielDetail();
		pmdq.setObject_no_vt(pmd.getObject_no_vt());
		List<PlnMaterielDetail> lpmd = this.getMapper(PlnMaterielDetailMapper.class).find(pmdq, 0, 0);
		if (lpmd == null || lpmd.size() == 0) {
			throw new Exception("虚拟物料无[" + pmd.getObject_no_vt() + "]卷!");
		}

		// 将无效的虚拟物料子卷恢复
//		List<PlnMaterielDetail> child = this.getMapper(
//				PlnMaterielDetailMapper.class).findWithCondition(
//				null,
//				"mat_object_no_vt = '" + lpmd.get(0).getObject_no_vt()
//						+ "' and invalid_flg = '1'",
//				"", 0, 0);
//		if (Utils.isNotEmpty(child)) {
//			this.getBean(MesApiDesignInfoImpl.class).recoveryChild(child);
//		}
		// 读取虚拟物料履历表【PRC_MATERIEL_VT_PROCESS】，获取虚拟母卷最后一条
		PrcMaterielVtProcess pmvp = new PrcMaterielVtProcess();
		pmvp.setStatus("0PLW10");
		pmvp.setObject_no_vt(lpmd.get(0).getObject_no_vt());
		List<PrcMaterielVtProcess> lpmvp = this.getMapper(PrcMaterielVtProcessMapper.class).findWithCondition(pmvp, "",
				" create_time desc ", 0, 1);

		// 循环 (MAT_OBJECT_NO_VT=虚拟母卷号) 的所有虚拟子卷记录
		PlnMaterielDetail pmdc = new PlnMaterielDetail();
		pmdc.setMat_object_no_vt(lpmd.get(0).getObject_no_vt());
		List<PlnMaterielDetail> lpmdc = this.getMapper(PlnMaterielDetailMapper.class).find(pmdc, 0, 0);
		for (PlnMaterielDetail pmdcc : lpmdc) {
			PlnMaterielDetail pmdu = new PlnMaterielDetail();
			pmdu.setSerial_no(pmdcc.getSerial_no());
			pmdu.setIs_finished("0");
			// 修改虚拟物料表【PLN_MATERIEL_DETAIL】：IS_FINISHED=0;
			this.getMapper(PlnMaterielDetailMapper.class).update(pmdu);
		}

		// 修改虚拟物料表_母卷信息
		PlnMaterielDetail pmdu = new PlnMaterielDetail();
		pmdu.setSerial_no(lpmd.get(0).getSerial_no());
		pmdu.setNeed_extopt("0");
		pmdu.setIs_next_finished("0");
		pmdu.setLw_plan_no(lpmvp.get(0).getLw_plan_no());
		pmdu.setStatus_desc("0PLW03");

		if (lpmd.get(0).getObject_no() == null || "".equals(lpmd.get(0).getObject_no())) {
			pmdu.setObject_no(lpmvp.get(0).getObject_no());
		}
		// 2018-06-23 opt_Times 之前一直没减,判断条件不对
		if (lpmd.get(0).getOpt_times() != null) {
			pmdu.setOpt_times(lpmd.get(0).getOpt_times() - 1);
		}
		this.getMapper(PlnMaterielDetailMapper.class).update(pmdu);

		// 新增虚拟物料履历表【PRC_MATERIEL_VT_PROCESS】记录
		InsertMatVtProc(lpmd.get(0).getObject_no_vt(), "0PLW03", userName, new Date());

		// 修改虚拟物料对应的 分条计划进程表
		PlnLwPlanStatistic plps = new PlnLwPlanStatistic();
		plps.setMat_lw(-lpmd.get(0).getSingle_weight());
		plps.setMat_lw_cnt(-1);
		plps.setLw_plan_no(lpmd.get(0).getLw_plan_no());
		this.getMapper(PlnLwPlanStatisticMapper.class).doUpdatePlaned(plps);

		// 回退实物母卷的物料跟踪
		PrcMaterielProcess pmp = new PrcMaterielProcess();
		pmp.setObject_no(lpmd.get(0).getObject_no());
		pmp.setPrc_code("5BLW10");
		pmp.setRemark("撤销母卷分条");
		pmp.setKeep_sametime_status(0);

		ResultModel rm = ARRAYLIST(pmp);
		if (!"0".equals(rm.getState())) {
			throw new Exception("分条完成后，母卷状态已发生改变，不能撤销！");
		}

		// 分条计划明细表【PLN_LENGTHWISE_PLAN_DETAIL】：STATUS= 5BLW03
		PlnLengthwisePlanDetail plpd = new PlnLengthwisePlanDetail();
		plpd.setLw_plan_no(lpmd.get(0).getLw_plan_no());
		plpd.setStatus("5BLW03");
		plpd.setObject_no_vt(pmd.getObject_no_vt());
		this.getMapper(PlnLengthwisePlanDetailMapper.class).doUpdate(plpd);

		// 分条计划主表【PLN_LENGTHWISE_PLAN】：调用公共函数1（分条计划号）;
		doUpdatePlnLengthwisePlan(lpmd.get(0).getLw_plan_no());
		// ----------------------------2018-06-19-------------------------------
		// 获取虚拟母卷的下一工序代码，计算下一工序的 已设计量/数，欠设计量：欠设计量 +=(母卷单重 )
		// --------------2018-10-16 修改,欠设计量在挂单的时候就一起减了
		// 获取下个工序代码暂时方法,将来从质量取值
//		String process_code = this.getBean(MesApiCrCrossCuttingMServiceImpl.class).getNext_process("2",pmd.getObject_no_vt());
//		// 横剪,将来加上12mm
//		if (process_code != null && processpoint.cross_cutting_code.equals(process_code)) {
//			// 修改生产订单进程表
//			PlnProdorderStatistic pps = new PlnProdorderStatistic();
//			pps.setProd_order_no(lpmd.get(0).getProd_order_no());
//			pps.setCl_undsn(lpmd.get(0).getSingle_weight());
//			this.getMapper(PlnProdorderStatisticMapper.class).doUpdatePlaned(pps);
//			// 修改订单进程表
//			PlnOrderStatistic pos = new PlnOrderStatistic();
//			pos.setOrder_no(lpmd.get(0).getOrder_no());
//			pos.setCl_undsn(lpmd.get(0).getSingle_weight());
//			this.getMapper(PlnOrderStatisticMapper.class).doUpdateClPlaned(pos);
//		}
//		this.getBean(MesApiDesignInfoImpl.class).updatePlnStatic(lpmd.get(0).getProd_order_no(), lpmd.get(0).getOrder_no(), lpmd.get(0).getNext_dsn_process_code(), lpmd.get(0).getSingle_weight(), false);
	}
	// --------------------------------分条完成
	// End-----------------------------------------------------

	// --------------------------------公共函数Start----------------------------------------------------
	/**
	 * 公共函数1 修改分条计划主表状态
	 * 
	 * @param 分条计划号
	 * @throws Exception
	 */
	public void doUpdatePlnLengthwisePlan(String lwPlanNo) throws Exception {
		PlnLengthwisePlan plp = new PlnLengthwisePlan();
		plp.setLw_plan_no(lwPlanNo);
		boolean flag = false;
		String MIN_STATUS = "";
		PlnLengthwisePlanDetail plpd = new PlnLengthwisePlanDetail();
		plpd.setLw_plan_no(lwPlanNo);
		List<PlnLengthwisePlanDetail> lplpd = this.getMapper(PlnLengthwisePlanDetailMapper.class)
				.findWithCondition(plpd, "status <> '0PLWXX'", " status asc ", 0, 0);
		if (lplpd == null || lplpd.size() == 0) {
			throw new Exception("未找到分条计划明细数据!");
		}
		MIN_STATUS = lplpd.get(0).getStatus();

		// 2018-06-11修改
		// 如果明细记录中有卷开始作业,主表状态改为开始作业
		for (PlnLengthwisePlanDetail plnL : lplpd) {
			if ("5BLW03".equals(plnL.getStatus())) {
				flag = true;
				break;
			}
		}
		if (flag) {
			plp.setStatus("0PLW03");
		} else if ("5BLW01".equals(MIN_STATUS)) {
			plp.setStatus("0PLW01");
		} else if (MIN_STATUS.compareTo("5BLW02") <= 0) {
			plp.setStatus("0PLW02");
		} else if (MIN_STATUS.compareTo("5BLW03") <= 0) {
			plp.setStatus("0PLW03");
		} else if (MIN_STATUS.compareTo("5BLW10") <= 0) {
			plp.setStatus("0PLW10");
		}
		this.getMapper(PlnLengthwisePlanMapper.class).doUpdate(plp);
	}

	/**
	 * 公共函数2 建立物料母子对应关系:
	 * 
	 * @param OBJECT_NO     实物母卷号
	 * @param SUB_OBJECT_NO 实物子卷号
	 * @param RELATION_TYPE 关系类型 1:改号(原-现号码对应)；2:轧制(板坯-钢板对应)；3:剪切/切割(母-子对应)
	 * @param REMARK        备注
	 * @throws Exception
	 */
	public void doBuildRelation(PrcMaterielRelation pmr) throws Exception {

		Date createTime = new Date();
		// 判断物料关系表【PRC_MATERIEL_RELATION】中，是否存在对应关系 (OBJECT_NO=实物母卷号 AND
		// SUB_OBJECT_NO=实物子卷号)
		PrcMaterielRelation pmrQ = new PrcMaterielRelation();
		pmrQ.setObject_no(pmr.getObject_no());
		pmrQ.setSub_object_no(pmr.getSub_object_no());
		// 如果有实际上只有一条
		List<PrcMaterielRelation> lpmrQ = this.getMapper(PrcMaterielRelationMapper.class).find(pmrQ, 0, 0);
		if (lpmrQ != null && lpmrQ.size() > 0) {
			// 存在则 UPDATE RELATION_TYPE=关系类型 where OBJECT_NO=实物母卷号 AND SUB_OBJECT_NO=实物子卷号;
			for (PrcMaterielRelation pmrc : lpmrQ) {
				PrcMaterielRelation pmrU = new PrcMaterielRelation();
				pmrU.setRelation_type(pmr.getRelation_type());
				pmrU.setSerial_no(pmrc.getSerial_no());
				this.getMapper(PrcMaterielRelationMapper.class).update(pmrU);
			}
		} else {
			String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);

			// 不存在则，插入对应关系：
			PrcMaterielRelation pmrI = new PrcMaterielRelation();
			pmrI.setObject_no(pmr.getObject_no());
			pmrI.setSub_object_no(pmr.getSub_object_no());
			pmrI.setRelation_type(pmr.getRelation_type());
			pmrI.setPrc_code(pmr.getPrc_code());// 产生工序
			pmrI.setCreate_man_name(userName);
			pmrI.setCreate_time(createTime);
			pmrI.setRemark(pmr.getRemark());
			this.getMapper(PrcMaterielRelationMapper.class).doAdd(pmrI);
		}

	}

	/**
	 * 公共函数3 断开物料母子对应关系:
	 * 
	 * @param OBJECT_NO     实物母卷号
	 * @param SUB_OBJECT_NO 实物子卷号
	 * @throws Exception
	 */
	public void doBuildRelationRemove(PrcMaterielRelation pmr) throws Exception {
		// 判断物料关系表【PRC_MATERIEL_RELATION】中，是否存在对应关系 (OBJECT_NO=实物母卷号 AND
		// SUB_OBJECT_NO=实物子卷号)
		PrcMaterielRelation pmrQ = new PrcMaterielRelation();
		pmrQ.setObject_no(pmr.getObject_no());
		pmrQ.setSub_object_no(pmr.getSub_object_no());
		// 如果有实际上只有一条
		List<PrcMaterielRelation> lpmrQ = this.getMapper(PrcMaterielRelationMapper.class).find(pmrQ, 0, 0);
		if (lpmrQ != null && lpmrQ.size() > 0) {
			// 存在则删除
			for (PrcMaterielRelation pmrc : lpmrQ) {
				this.getMapper(PrcMaterielRelationMapper.class).delete(pmrc.getSerial_no());
			}
		}
	}

	// --------------------------------公共函数End----------------------------------------------------

	// --------------------------------插入实物进程表函数Start----------------------------------------------------
	/**
	 * 插入实物进程表函数
	 * 
	 * @param pmp object_no 实物物料号 prc_code status 新增的状态 create_time 操作时间 remark 备注
	 * @throws Exception
	 */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public int INSERT_OBJ_PROCESS(PrcMaterielProcess pmp) throws Exception {
		boolean IS_OK = true;
		ArrayList<String> BEFORE_PROCS = new ArrayList<String>();
		String B_STATUS = "";

		if (pmp.getPrc_code() == null || "".equals(pmp.getPrc_code())) {
			return 0;
		}

		// 循环查询集合
		List<PrcMaterielProcess> lpmp = this.getMapper(PrcMaterielProcessMapper.class).doQuery(pmp);
		int i = 0;
		boolean ycjs = false;
		for (PrcMaterielProcess pmpc : lpmp) {
			if (pmpc.getRemark() != null && pmpc.getRemark().contains("一次结算")) {
				ycjs = true;
			}
			BEFORE_PROCS.add(pmpc.getPrc_code());
			// 第一次循环（物料最后一个状态数据），保存 操作时间和状态
			if (i == 0) {
				B_STATUS = pmpc.getPrc_code();
			}
			i++;
		}
		if (BEFORE_PROCS.contains(pmp.getPrc_code()) && !ycjs) {
			return 0; // 如果最后状态中，存在传入状态。则直接退出，不新增。
		}

		// 进程转移白名单 （暂时实现“必须唯一的转移”功能。即有限制时，前后进程状态必须满足此条件）
		IS_OK = true;
		PrcMatprocWhitelist pmw = new PrcMatprocWhitelist();
		pmw.setPrc_code(pmp.getPrc_code());
		pmw.setAllow_type(1);
		String creatTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(pmp.getCreate_time());
		String sWhere = " begin_time<= to_date('" + creatTime
				+ "', 'yyyy-mm-dd hh24:mi:ss') - 1/24/60/60	and end_time>= to_date('" + creatTime
				+ "', 'yyyy-mm-dd hh24:mi:ss') + 1/24/60/60 ";
		List<PrcMatprocWhitelist> lpmw = this.getMapper(PrcMatprocWhitelistMapper.class).findWithCondition(pmw, sWhere,
				"", 0, 0);
		for (PrcMatprocWhitelist pmwc : lpmw) {
			IS_OK = false;
			if ("*".equals(pmwc.getPrc_code_bf()) || BEFORE_PROCS.indexOf(pmwc.getPrc_code()) > -1) {
				IS_OK = true;
				break;
			}
		}
		if (!IS_OK) {
			throw new Exception("不满足进程转移条件！[白名单]");
		}

		// 进程转移黑名单 （暂时实现“必须唯一的转移”功能。即有限制时，前后进程状态必须满足此条件）
		IS_OK = true;
		PrcMatprocBlacklist pmb = new PrcMatprocBlacklist();
		pmb.setPrc_code(pmp.getPrc_code());
		pmb.setAllow_type(1);
		List<PrcMatprocBlacklist> lpmb = this.getMapper(PrcMatprocBlacklistMapper.class).findWithCondition(pmb, sWhere,
				"", 0, 0);
		if (lpmb != null && lpmb.size() > 0) {
			for (PrcMatprocBlacklist pmwb : lpmb) {
				if (BEFORE_PROCS.indexOf(pmwb.getPrc_code()) > -1) {
					IS_OK = false;
					break;
				}
			}
		}
		if (!IS_OK) {
			throw new Exception("不满足进程转移条件！[黑名单]");
		}

		PlnMaterielDetail pmd = new PlnMaterielDetail();
		// pmd.setInvalid_flg(1);
		pmd.setObject_no(pmp.getObject_no());
		List<PlnMaterielDetail> lpmd = this.getMapper(PlnMaterielDetailMapper.class).findWithCondition(pmd,
				" nvl (invalid_flg, '0') <> 1 ", "", 0, 1);
		if (lpmd != null && lpmd.size() > 0) {
			pmp.setObject_type(lpmd.get(0).getObject_type());
			pmp.setPline_code(lpmd.get(0).getPline_code());
			pmp.setOrder_no(lpmd.get(0).getOrder_no());
			pmp.setProd_order_no(lpmd.get(0).getProd_order_no());
			pmp.setLw_design_no(lpmd.get(0).getLw_design_no());
			pmp.setLw_plan_no(lpmd.get(0).getLw_plan_no());
			pmp.setCl_design_no(lpmd.get(0).getCl_design_no());
			pmp.setCl_plan_no(lpmd.get(0).getCl_plan_no());
			pmp.setRl_design_no(lpmd.get(0).getRl_design_no());
			pmp.setRl_plan_no(lpmd.get(0).getRl_plan_no());
			pmp.setBatch_no(lpmd.get(0).getBatch_no());
		}
		pmp.setPrc_code_bf(B_STATUS);

		List<PrcMaterielProcess> lpmpNo = this.getMapper(PrcMaterielProcessMapper.class).findWithCondition(null, "",
				" serial_no desc ", 0, 1);
		if (lpmpNo == null || lpmpNo.size() == 0) {
			pmp.setSerial_no(1);
		} else {
			pmp.setSerial_no(lpmpNo.get(0).getSerial_no() + 1);
		}

		// 增加进程跟踪记录
		this.getMapper(PrcMaterielProcessMapper.class).insert(pmp);
		
		// 增加物料进程记录抛送到tbdipdo：202301013刘侣
		ResultModel prm = this.getBean(SlmFundFirstDetailServiceImpl.class).doProsIns(pmp);
		if ("500".equals(prm.getState())) {
			throw new Exception(prm.getMsgInfo());
		}
		// end
		
		
		return 1;
	}

	/**
	 * 撤销实物物料状态跟踪函数
	 * 
	 * @param pmp object_no 实物物料号 prc_code status 要删除的最后状态，可传空 keep_sametime_status
	 *            是否保留同时间点的其他状态 remark 备注
	 * @return 将要回退的状态
	 */
	public ResultModel ARRAYLIST(PrcMaterielProcess pmp) throws Exception {
		ResultModel rm = new ResultModel();

		int num;
		int V_GO_NEXT = 0;
		List<PrcMaterielProcess> lpmp = this.getMapper(PrcMaterielProcessMapper.class).doQueryAry1(pmp);
		PrcMaterielProcess pmpr = null;
		if (pmp.getPrc_code() != null) {
			pmpr = null;
			// 查找传入状态值是否是最后状态
			num = 1;// 这里>0表示未找到数据
			if (lpmp != null && lpmp.size() > 0) {
				for (PrcMaterielProcess pmpc : lpmp) {
					if (pmpc.getRn() == 1) {
						if (num == 1) {
							pmpr = pmpc;
						}
						// 如果保留同时间点的其他状态，则传入状态必须是最后一条记录, 否则退出
						if (num == 1 && pmp.getKeep_sametime_status() != 0
								&& !pmpc.getPrc_code().equals(pmp.getPrc_code())) {
							break;
						}
						// 找到数据，传入的要删除的状态是 最后状态
						if (pmpc.getPrc_code().equals(pmp.getPrc_code())) {
							num = 0;
							break;
						}
						num++;
					}
				}
			}
			// --不是最后状态，返回最后状态值。
			if (num > 0) {
				rm.setState("-2");
				rm.setData(pmpr);
				return rm;
			}
		}

		if (lpmp != null && lpmp.size() > 0) {
			for (PrcMaterielProcess pmpc : lpmp) {
				if (pmpc.getRn() == 2 || V_GO_NEXT == 1) {
					pmpr = pmpc;
					break;
				}

				PrcMaterielProcess pmpu = new PrcMaterielProcess();
				pmpu.setSerial_no(pmpc.getSerial_no());
				pmpu.setInvalid_flg(1);

				// ‘传入状态’为空(无论参数4如何设置), 或 对‘传入状态’不为空,参数4设为0（不保留）的 最后时间的所有状态 置为无效
				if (pmpc.getRn() == 1 && (pmp.getKeep_sametime_status() == 0
						|| (pmp.getPrc_code() == null || "".equals(pmp.getPline_code())))) {
					if (pmp.getRemark() != null && !"".equals(pmp.getRemark())) {
						pmpu.setRemark(pmpc.getRemark() + ";" + pmp.getRemark());
					} else {
						pmpu.setRemark(pmpc.getRemark());
					}
					this.getMapper(PrcMaterielProcessMapper.class).update(pmpu);
					
					// 增加物料进程记录抛送到tbdipdo：202301013刘侣
					ResultModel prm = this.getBean(SlmFundFirstDetailServiceImpl.class).doProsUpd(pmpu);
					if ("500".equals(prm.getState())) {
						throw new Exception(prm.getMsgInfo());
					}
					// end
				}
				// ‘传入状态’不为空,参数4的值为1(保留)，将最后时间的指定状态 置为无效
				else if (pmp.getKeep_sametime_status() != 0
						&& (pmp.getPrc_code() == null || "".equals(pmp.getPline_code()))) {
					if (pmp.getRemark() != null && !"".equals(pmp.getRemark())) {
						pmpu.setRemark(pmpc.getRemark() + ";" + pmp.getRemark());
					} else {
						pmpu.setRemark(pmpc.getRemark());
					}
					this.getMapper(PrcMaterielProcessMapper.class).update(pmpu);
					
					// 增加物料进程记录抛送到tbdipdo：202301013刘侣
					ResultModel prm = this.getBean(SlmFundFirstDetailServiceImpl.class).doProsUpd(pmpu);
					if ("500".equals(prm.getState())) {
						throw new Exception(prm.getMsgInfo());
					}
					// end

					V_GO_NEXT = 1;
				} else {
					pmpr = pmpc;
					break;
				}
			}
		}
		rm.setState("0");
		rm.setData(pmpr);
		return rm;
	}
	// --------------------------------插入实物进程表函数End----------------------------------------------------

	/**
	 * 新增虚拟物料履历表数据
	 * 
	 * @param ObjectNoVt
	 * @param status
	 * @param createUserName
	 * @param createTime
	 */
	public void InsertMatVtProc(String ObjectNoVt, String status, String createUserName, Date createTime) {
		PlnMaterielDetail pmdc = new PlnMaterielDetail();
		pmdc.setObject_no_vt(ObjectNoVt);
		List<PlnMaterielDetail> lpmd = this.getMapper(PlnMaterielDetailMapper.class).find(pmdc, 0, 0);
		long serial_no = 0l;
		List<PrcMaterielVtProcess> pmp = this.getMapper(PrcMaterielVtProcessMapper.class).findWithCondition(null, "", "serial_no desc", 0, 1);
		if (Utils.isNotEmpty(pmp)) {
			serial_no = pmp.get(0).getSerial_no()+1;
		}
		// 写虚拟物料履历，状态填: 子卷
		PrcMaterielVtProcess pmvpc = new PrcMaterielVtProcess();
		pmvpc.setSerial_no(serial_no);
		pmvpc.setObject_no_vt(lpmd.get(0).getObject_no_vt());
		pmvpc.setObject_no(lpmd.get(0).getObject_no());
		pmvpc.setObject_type(lpmd.get(0).getObject_type());
		pmvpc.setPline_code(lpmd.get(0).getPline_code());
		pmvpc.setStatus(status);
		pmvpc.setOrder_no(lpmd.get(0).getOrder_no());
		pmvpc.setProd_order_no(lpmd.get(0).getProd_order_no());
		pmvpc.setLw_design_no(lpmd.get(0).getLw_design_no());
		pmvpc.setCl_design_no(lpmd.get(0).getCl_design_no());
		pmvpc.setRl_design_no(lpmd.get(0).getRl_design_no());
		pmvpc.setSr_plan_no(lpmd.get(0).getSr_plan_no());
		pmvpc.setSr_design_no(lpmd.get(0).getSr_design_no());
		pmvpc.setAn_plan_no(lpmd.get(0).getAn_plan_no());
		pmvpc.setAn_design_no(lpmd.get(0).getAn_design_no());
		pmvpc.setLw_plan_no(lpmd.get(0).getLw_plan_no());
		pmvpc.setCl_plan_no(lpmd.get(0).getCl_plan_no());
		pmvpc.setRl_plan_no(lpmd.get(0).getRl_plan_no());
		pmvpc.setBatch_no(lpmd.get(0).getBatch_no());
		pmvpc.setCreate_man_name(createUserName);
		pmvpc.setCreate_time(createTime);
		this.getMapper(PrcMaterielVtProcessMapper.class).doAdd(pmvpc);
	}

	/**
	 * 函数_通过加工计划产生设计
	 * 
	 * @param pro_order_no    生产订单号
	 * @param design_quantity 设计原料卷总数
	 * @param ypd             物料信息
	 * @param machine_code    机台代码 M0001/M0002
	 * @throws Exception
	 */
	public PlnLengthwiseDsnMain ProcessingPlanDsn(String pro_order_no, Integer design_quantity, YdmProductDetail ypd,
			String pd, String machine_code) throws Exception {
		PlnLengthwiseDsnMain slw_design_no = null;
		String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		PlnProdorder pp = new PlnProdorder();
		pp.setProd_order_no(pro_order_no);
		List<PlnProdorder> lpp = this.getMapper(PlnProdorderMapper.class).find(pp, 0, 1);
		// 根据传入的生产订单号，读取生产订单对应的生产加工表[PLN_PROCESS_PLAN]
		PlnProcessPlan ppp = new PlnProcessPlan();
		ppp.setOrder_no(lpp.get(0).getOrder_no());
		ppp.setValid_flag("1");
		List<PlnProcessPlan> lppp = this.getMapper(PlnProcessPlanMapper.class).findWithCondition(ppp, null,
				" cut_order_no ", 0, 0);
		if (lppp == null || lppp.size() == 0) {
			throw new Exception("未找到生产订单[" + ppp.getOrder_no() + "]对应的生产加工信息");
		}
		double sWidth = 0;
		int iCutCount = 0;
		for (PlnProcessPlan pppc : lppp) {
			sWidth += pppc.getWidth().doubleValue() * pppc.getCut_num().intValue();
			iCutCount += pppc.getCut_num().intValue();
		}

		// 保存设计主表数据： 纵剪设计号：DLW+YYMMDD+6流水号
		String sDate = new SimpleDateFormat("yyMMdd").format(new Date());
		PlnLengthwiseDsnMain pldm = new PlnLengthwiseDsnMain();
		List<PlnLengthwiseDsnMain> lpdmNo = this.getMapper(PlnLengthwiseDsnMainMapper.class).findWithCondition(null, "",
				" serial_no desc ", 0, 1);
		// long No=this.getMapper(PlnLengthwiseDsnMainMapper.class).doQueryMaxNo();
		pldm.setLw_design_no("DLW" + sDate + String.format("%06d", 1));
		if (lpdmNo != null && lpdmNo.size() > 0) {
			pldm.setSerial_no(lpdmNo.get(0).getSerial_no() + 1);
			if (sDate.equals(lpdmNo.get(0).getLw_design_no().substring(3, 9))) {
				pldm.setLw_design_no("DLW" + sDate + String.format("%06d",
						Integer.parseInt(lpdmNo.get(0).getLw_design_no().substring(9, 15)) + 1));
			}
		}

		pldm.setProd_order_no(lpp.get(0).getProd_order_no());
		pldm.setOrder_no(lpp.get(0).getOrder_no());
		pldm.setPline_code(lpp.get(0).getPline_code());
		pldm.setSteel_code(lpp.get(0).getSteel_code());

		String isMulti = "0";// 是否拼料 根据订单数判断，多个订单填1，否则填0
		pldm.setIs_multi(isMulti);
		pldm.setMat_diameter_inn(ypd.getDiameter_inn());
		pldm.setMat_diameter_out(ypd.getDiameter_out());
		pldm.setMat_single_weight(ypd.getFactweight());
		pldm.setMat_width(ypd.getWidth());
		pldm.setProd_rate(sWidth / lppp.get(0).getMat_width().doubleValue());
		pldm.setSub_count(iCutCount);
		pldm.setMat_thick(lppp.get(0).getThick());
		pldm.setMat_length(lppp.get(0).getLength());
		pldm.setSingle_weight(ypd.getFactweight());
		if (lppp.size() == 1) {
			pldm.setThick(lppp.get(0).getThick());
			pldm.setWidth(lppp.get(0).getWidth());
			pldm.setLength(lppp.get(0).getLength());
			pldm.setDiameter_inn(lppp.get(0).getDiameter_inn());
			pldm.setDiameter_out(lppp.get(0).getDiameter_out());
			pldm.setSingle_weight(lppp.get(0).getEstimate_weight());
		}

		if (!"1".equals(lpp.get(0).getOrder_nature()) && !"3".equals(lpp.get(0).getOrder_nature())) {
			pldm.setCut_style(lppp.get(0).getCut_style());
		}

		pldm.setCrosscut_style(lppp.get(0).getCrosscut_style());
		pldm.setFixed_length_type_no(lpp.get(0).getFixed_length_type_no());
		pldm.setCut_edge_type_no(lpp.get(0).getCut_edge_type_no());
		pldm.setDeliver_date(lpp.get(0).getDeliver_date());
		pldm.setDesign_quantity(design_quantity);
		pldm.setDesign_weight(ypd.getFactweight());

		pldm.setDeliver_date_earliest(lpp.get(0).getDeliver_date());
		pldm.setDeliver_date_latest(lpp.get(0).getDeliver_date());
		pldm.setCreate_man_name(userName);
		pldm.setCreate_time(new Date());
		pldm.setIs_finished(0);
		pldm.setReserve_1(lppp.get(0).getProduce_no());
		this.getMapper(PlnLengthwiseDsnMainMapper.class).insert(pldm);
		slw_design_no = pldm;

		// 倒叙取一条
		List<PlnLengthwiseDsnMultinfo> lpdmM = this.getMapper(PlnLengthwiseDsnMultinfoMapper.class)
				.findWithCondition(null, "", " serial_no desc ", 0, 1);
		long DsnNo = 1;
		if (lpdmM != null && lpdmM.size() > 0) {
			DsnNo = lpdmM.get(0).getSerial_no() + 1;
		}

		int iCrosscut = 0;
		if ("2".equals(lppp.get(0).getCrosscut_style()) || "3".equals(lppp.get(0).getCrosscut_style())) {
			iCrosscut = Integer.parseInt(lppp.get(0).getCrosscut_style());
		} else {
			iCrosscut = 1;
		}

		int isubSeq = 1;
		for (int idx_hq = 1; idx_hq <= iCrosscut; idx_hq++) {
			int V_分条序号 = 1;
			for (PlnProcessPlan pppc : lppp) {
				for (int idx_sub = 1; idx_sub <= pppc.getCut_num().intValue(); idx_sub++) {
					// 其中：LW_SEQ 分条序号=V_分条序号; SEG_SEQ 分段序号=idx_hq;
					// -----------------写拼料-----------------------------
					PlnLengthwiseDsnMultinfo pldmc = new PlnLengthwiseDsnMultinfo();
					pldmc.setSerial_no(DsnNo++);
					pldmc.setLw_design_no(pldm.getLw_design_no());
					pldmc.setLw_seq(V_分条序号++);
					pldmc.setSeg_seq(idx_hq);
					pldmc.setOrder_no(lpp.get(0).getOrder_no());
					pldmc.setProd_order_no(lpp.get(0).getProd_order_no());
					pldmc.setThick(pppc.getThick());
					pldmc.setWidth(pppc.getWidth());
					pldmc.setLength(pppc.getLength());
					pldmc.setDiameter_inn(pppc.getDiameter_inn());
					pldmc.setDiameter_out(pppc.getDiameter_out());
					pldmc.setWeight(pldm.getSingle_weight().doubleValue() * pppc.getWidth().doubleValue()
							/ (pldm.getMat_width().doubleValue() * Integer.parseInt(pldm.getCrosscut_style())));
					pldmc.setFixed_length_type_no(lpp.get(0).getFixed_length_type_no());
					pldmc.setCut_edge_type_no(lpp.get(0).getCut_edge_type_no());
					pldmc.setSub_seq(isubSeq++);

					if (pldmc.getSub_seq() >= 1000 || pldmc.getLw_seq() >= 1000) {
						throw new Exception(
								"子卷序号[" + pldmc.getSub_seq() + "]和分条序号[" + pldmc.getLw_seq() + "]不在设备限制范围内！");
					}
					this.getMapper(PlnLengthwiseDsnMultinfoMapper.class).insert(pldmc);
				}
			}
		}

		return slw_design_no;
	}

	/**
	 * 根据产线获取产线的规格参数
	 * 
	 * @param thick 厚度度
	 * @throws Exception
	 */
	public List<ComDsnPltlmt> getMachineRestrictDb(Double thick, String machine_code) throws Exception {
		ComDsnPltlmt cdp = new ComDsnPltlmt();
		cdp.setPlt("Y1");// 工厂
		cdp.setPlt_line(machine_code);// 产线
		List<ComDsnPltlmt> lcdp = this.getMapper(ComDsnPltlmtMapper.class).find(cdp, 0, 0);
		if (lcdp == null || lcdp.size() == 0) {
			throw new Exception("未找到产线");
		}
		// 最大分条数
		List<ComDsnCutstd> lcdc = this.getMapper(ComDsnCutstdMapper.class).findWithCondition(null,
				"APPLY_ITEM = '20001'  AND PLT_line = '" + machine_code + "' and limit1_min<=" + thick
						+ " and limit1_max>=" + thick,
				"", 0, 0);
		if (lcdc == null || lcdc.size() == 0) {
			throw new Exception("厚度[" + thick + "]未找到最大分条数");
		}
		cdp.setApply_item("lim_max_split");
		cdp.setMin(lcdc.get(0).getValue1());
		lcdp.add(cdp);

		return lcdp;
	}

	/**
	 * 获取基础数据比较厚度值
	 * 
	 * @param a 订单值
	 * @param b 实绩值
	 */
	public ResultModel CompareValues(double a, double b) {
		ResultModel rm = this.getBean(PbModelDbServiceImpl.class).findPlnThickRangeCmbDb();
		if (!"200".equals(rm.getState())) {
			rm.setMsgInfo("获取厚度公差范围失败！");
			return rm;
		}
		List<PbModelDb> lpmd = (List<PbModelDb>) rm.getData();
		if (lpmd == null || lpmd.size() == 0) {
			rm.setState("500");
			rm.setMsgInfo("请先配置厚度公差范围！");
			return rm;
		}
		int i = 0;
		try {
			for (PbModelDb pmd : lpmd) {
				if (pmd.getId().equals("200101")) {// 范围
					if (b - a > (Double.parseDouble(pmd.getRegionkey()))) {
						rm.setState("500");
						rm.setMsgInfo("厚度差额 [实际值-订单值 : "
								+ new BigDecimal(b - a).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue()
								+ "] 超出最大公差[" + Double.parseDouble(pmd.getRegionkey()) + "],不能挂单!");
						return rm;
					}
					i++;
				}

				if (pmd.getId().equals("200102")) {
					if (b - a < (Double.parseDouble(pmd.getRegionkey()))) {
						rm.setState("500");
						rm.setMsgInfo("厚度差额[实际值-订单值 :"
								+ new BigDecimal(b - a).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue() + "]小于最小公差["
								+ Double.parseDouble(pmd.getRegionkey()) + "],不能挂单！");
						return rm;
					}
					i++;
				}
			}
			if (i != 2) {
				rm.setState("500");
				rm.setMsgInfo("厚度公差配置错误！");
				return rm;
			}
			rm.setState("200");
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("厚度公差配置错误！");
			return rm;
		}
		return rm;
	}

	/**
	 * 给物流的接口 订单统计信息 新增入库量、回退入库量
	 * 
	 * @param prod_order_no 生产订单号
	 * @param coilNo        实物卷号
	 * @param optionType    操作类型 1为新增入库量 2为回退入库量
	 * @throws Exception
	 */
	public ResultModel YdmUpdateOrderStatisticsInfo(String prod_order_no, String coilNo, String optionType)
			throws Exception {
		ResultModel rm = new ResultModel();

		PlnProdorderStatistic pps = new PlnProdorderStatistic();
		pps.setProd_order_no(prod_order_no);
		List<PlnProdorderStatistic> lpps = this.getMapper(PlnProdorderStatisticMapper.class).find(pps, 0, 1);
		if (lpps == null || lpps.size() == 0) {
			rm.setState("500");
			rm.setMsgInfo("未找到生产订单进程数据！");
			return rm;
		}
		PlnOrderStatistic pos = new PlnOrderStatistic();
		pos.setOrder_no(lpps.get(0).getOrder_no());
		List<PlnOrderStatistic> lpos = this.getMapper(PlnOrderStatisticMapper.class).find(pos, 0, 1);
		if (lpos == null || lpos.size() == 0) {
			rm.setState("500");
			rm.setMsgInfo("未找到订单进程数据");
			return rm;
		}

		CommonPage<YdmProductDetail> cp = new CommonPage<YdmProductDetail>();
		// 判断实物，和订单原料卷的厚、牌号、交货状态是否匹配
		YdmProductDetail ypd = new YdmProductDetail();
		ypd.setCoilno(coilNo);
		cp.setObject(ypd);
		ResultModel rmValid = this.getBean(LmsApiServiceImpl.class).doFindCoilno(cp);
		if (!"200".equals(rmValid.getState())) {
			return rmValid;
		}
		List<YdmProductDetail> lypd = (List<YdmProductDetail>) rmValid.getData();
		double weights = (lypd.get(0).getFactweight() == null ? 0 : lypd.get(0).getFactweight().doubleValue());

		if (optionType.equals("1")) {
			pps.setStocked(weights);
			pps.setStocked_cnt(1);
			pos.setStocked(weights);
			pos.setStocked_cnt(1);
		} else {
			pps.setStocked(-weights);
			pps.setStocked_cnt(-1);
			pos.setStocked(-weights);
			pos.setStocked_cnt(-1);
		}

		this.getMapper(PlnProdorderStatisticMapper.class).doUpdatePlaned(pps);
		this.getMapper(PlnOrderStatisticMapper.class).doUpdatePlaned(pos);
		rm.setState("200");
		return rm;
	}

	/**
	 * 给物流的接口 通过订单号，找 采购合同号
	 * 
	 * @param order_no 订单号
	 * @throws Exception
	 */
	public ResultModel getPurchaseContractNoInfo(String order_no) throws Exception {
		ResultModel rm = new ResultModel();
		try {
//			PlnProcessPlan ppp=new PlnProcessPlan();
//			ppp.setOrder_no(order_no);
//			List<PlnProcessPlan> lppp = this.getMapper(PlnProcessPlanMapper.class).find(ppp, 0, 0);

			PlnProdorder p = new PlnProdorder();
			p.setOrder_no(order_no);
			List<PlnProdorder> lppq = this.getMapper(PlnProdorderMapper.class).find(p, 0, 0);
			if (lppq != null && lppq.size() > 0) {
				rm.setState("200");
				rm.setData(lppq.get(0).getPurchase_contract_no());
			} else {
				rm.setState("400");
				rm.setErrorInfo("未找到数据");
			}
		} catch (Exception ex) {
			rm.setState("500");
			rm.setErrorInfo("未找到数据：" + ex.getMessage());
		}
		return rm;
	}

	/**
	 * 根据订单号查询生产订单信息
	 * 
	 * @param order_no
	 * @return order_no销售订单号, prod_order_no生产订单号, customer_no客户编号,
	 *         customer_name客户名称, reciver_unit_no收货单位编号, reciver_unit_name收货单位名称
	 */
	public ResultModel YdmCoilNoForPlnProdorder(String order_no) {
		ResultModel rm = new ResultModel();
		try {
			List<PlnProdorder> lppp = this.getMapper(PlnProdorderMapper.class).YdmCoilNoForPlnProdorder(order_no);
			if (lppp != null && lppp.size() > 0) {
				for (PlnProdorder ppp : lppp) {
					SlmOrderInfo soi = new SlmOrderInfo();
					soi.setContract_no(ppp.getContract_no());
					soi.setContract_line_no(ppp.getContract_line_no());
					soi.setOrder_seq(ppp.getOrder_seq());
					List<SlmOrderInfo> lsoi = this.getMapper(SlmOrderInfoMapper.class).find(soi, 0, 1);
					if (lsoi != null && lsoi.size() != 0) {
						ppp.setOrder_no(lsoi.get(0).getOrder_no());
					}
				}
				rm.setState("200");
				rm.setData(lppp);
			} else {
				rm.setState("400");
				rm.setErrorInfo("未找到数据");
			}
		} catch (Exception ex) {
			rm.setState("500");
			rm.setErrorInfo("未找到数据：" + ex.getMessage());
		}
		return rm;
	}

	/**
	 * 3mm [ { "object": { "order_no": "", "heatno": "", "batchno": "",
	 * "surface_rst": "" "machine_code":"" }, "memo1": "", "startTime":
	 * "2018-08-15", "endTime": "2018-09-14", "pageIndex": 4, "pageSize": 25 } ]
	 * 调用生产计划模块提供的接口获取，未进行综合判定的物料信息 分页查询 startTime 开始时间 endTime 结束时间 memo2：投料卷号
	 * memo1 上表、下表或者边部检验页面（U、D、E） memo1="U" -----为上表
	 */
	public ResultModel doQueryMesCrWeb_3mm(CommonPage<MesCrCrossCuttingD> cp) {
		ResultModel rm = new ResultModel();
		int pageSize = cp.getPageSize();
		int pageIndex = cp.getPageIndex();
		MesCrCrossCuttingD y = cp.getObject();
		PageModel<HashMap> pm = new PageModel<HashMap>(pageIndex, pageSize);
		String swhere = "";
		if (y.getOrder_no() != null && y.getOrder_no().equals("")) {
			swhere += " and ydm.ORDERNO like '%" + y.getOrder_no() + "%'";
		}
		if (y.getHeatno() != null && y.getHeatno().equals("")) {
			swhere += " and ydm.HEATNO like '%" + y.getHeatno() + "%'";
		}
		if (y.getBatchno() != null && y.getBatchno().equals("")) {
			swhere += " and ydm.BATCHNO like '%" + y.getBatchno() + "%'";
		}
		if (cp.getMemo4() != null && !"".equals(cp.getMemo4())) {
			swhere += " and ydm.materailcoilno like '%" + cp.getMemo4() + "%'";
		}
		List<HashMap> list = new ArrayList<>();

		try {
			// 增加页面"检查结果"查询临时方法,将来可修改。
			if ("B".equals(cp.getMemo1().trim())) {
				swhere = " and ydm.SURFACERESULT = " + cp.getObject().getSurface_rst() + "";
				list = this.getMapper(MesCrCrossCuttingDMapper.class).doQueryMesCrWeb1((pageIndex - 1) * pageSize,
						(pageIndex - 1) * pageSize + pageSize, cp.getObject(), cp.getStartTime(), cp.getEndTime(),
						swhere, cp.getMemo2());
			}
			else {
				swhere = " and ydm.MEASURE_RESULT = " + cp.getObject().getSurface_rst() + "";
				list = this.getMapper(MesCrCrossCuttingDMapper.class).doQueryMesCrWeb2((pageIndex - 1) * pageSize,
						(pageIndex - 1) * pageSize + pageSize, cp.getObject(), cp.getStartTime(), cp.getEndTime(),
						swhere, cp.getMemo2());
			}

			for (HashMap hashMap : list) {
				if (hashMap.get("COIL_NO") != null) {
					QcmJudgeSurface qjs = new QcmJudgeSurface();
					qjs.setMaterial_no((String) hashMap.get("COIL_NO"));

					List<QcmJudgeSurface> lqjsq = this.getMapper(QcmJudgeSurfaceMapper.class).find(qjs, 0, 0);
					if (lqjsq != null && lqjsq.size() > 0) {
						for (QcmJudgeSurface q : lqjsq) {
							if (q.getSurface_id().contains("U")) {
								qjs.setSf_type("U");
								QcmJudgeSurface qq = this.getMapper(QcmJudgeSurfaceMapper.class).findMaxS(qjs);

								QcmJudgeSurfaceFlaw qjsf = new QcmJudgeSurfaceFlaw();
								qjsf.setSurface_id(qq.getSurface_id());
								qjsf.setPrimary_flag("1");
								List<QcmJudgeSurfaceFlaw> list2 = this.getMapper(QcmJudgeSurfaceFlawMapper.class)
										.findWithCondition(qjsf, null, null, 0, 0);
								if (list2 != null && list2.size() > 0) {
									hashMap.put("FLAW_CODE_U", list2.get(0).getFlaw_code());
									hashMap.put("FLAW_DESC_U", list2.get(0).getFlaw_desc());
								}

							} else if (q.getSurface_id().contains("D")) {
								qjs.setSf_type("D");
								QcmJudgeSurface qq = this.getMapper(QcmJudgeSurfaceMapper.class).findMaxS(qjs);

								QcmJudgeSurfaceFlaw qjsf = new QcmJudgeSurfaceFlaw();
								qjsf.setSurface_id(qq.getSurface_id());
								qjsf.setPrimary_flag("1");
								List<QcmJudgeSurfaceFlaw> list2 = this.getMapper(QcmJudgeSurfaceFlawMapper.class)
										.findWithCondition(qjsf, null, null, 0, 0);
								if (list2 != null && list2.size() > 0) {
									hashMap.put("FLAW_CODE_D", list2.get(0).getFlaw_code());
									hashMap.put("FLAW_DESC_D", list2.get(0).getFlaw_desc());
								}
							} else if (q.getSurface_id().contains("E")) {
								qjs.setSf_type("E");
								QcmJudgeSurface qq = this.getMapper(QcmJudgeSurfaceMapper.class).findMaxS(qjs);

								QcmJudgeSurfaceFlaw qjsf = new QcmJudgeSurfaceFlaw();
								qjsf.setSurface_id(qq.getSurface_id());
								qjsf.setPrimary_flag("1");
								List<QcmJudgeSurfaceFlaw> list2 = this.getMapper(QcmJudgeSurfaceFlawMapper.class)
										.findWithCondition(qjsf, null, null, 0, 0);
								if (list2 != null && list2.size() > 0) {
									hashMap.put("FLAW_CODE_E", list2.get(0).getFlaw_code());
									hashMap.put("FLAW_DESC_E", list2.get(0).getFlaw_desc());
								}
							}

						}
					}
					
				}
			}

			pm.setRows(list);
			pm.setTotal(this.getMapper(MesCrCrossCuttingDMapper.class).doQueryMesCrWebCount1(cp.getObject(),
					cp.getStartTime(), cp.getEndTime(), cp.getMemo2(), swhere));
			rm.setState("200");
			rm.setData(pm);
		} catch (Exception ex) {
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!" + ex.getMessage());
		}
		return rm;
	}

	
	/**
	 *轧机 调用生产计划模块提供的接口获取，未进行综合判定的物料信息 分页查询 startTime 开始时间 endTime 结束时间
	 * memo2:投料卷号 memo1 上表、下表或者边部检验页面（U、D、E） memo1="U" -----为上表
	 */
	public ResultModel doQueryMesCrWeb_rcm(CommonPage<MesRcmD> cp) {
		ResultModel rm = new ResultModel();
		int pageSize = cp.getPageSize();
		int pageIndex = cp.getPageIndex();
		MesRcmD y = cp.getObject();
		PageModel<HashMap> pm = new PageModel<HashMap>(pageIndex, pageSize);
		String swhere = "";
		if (y.getOrder_no() != null && !y.getOrder_no().equals("")) {
			swhere += " and ydm.ORDERNO like '%" + y.getOrder_no() + "%'";
		}
		if (y.getHeatno() != null && !y.getHeatno().equals("")) {
			swhere += " and ydm.HEATNO like '%" + y.getHeatno() + "%'";
		}
		if (y.getBatchno() != null && !y.getBatchno().equals("")) {
			swhere += " and ydm.BATCHNO like '%" + y.getBatchno() + "%'";
		}
		if (cp.getMemo4() != null && !"".equals(cp.getMemo4())) {
			swhere += " and ydm.materailcoilno like '%" + cp.getMemo4() + "%'";
		}
		List<HashMap> list = new ArrayList<>();

		try {
			// 增加页面"检查结果"查询临时方法,将来可修改。
			if ("B".equals(cp.getMemo1().trim())) {
				swhere = " and ydm.SURFACERESULT = " + cp.getObject().getSurface_rst() + "";
				list = this.getMapper(MesRcmMMapper.class).doQueryMesCrWeb1((pageIndex - 1) * pageSize,
						(pageIndex - 1) * pageSize + pageSize, cp.getObject(), cp.getStartTime(), cp.getEndTime(),
						swhere, cp.getMemo2());
			}
			else {
				swhere = " and ydm.MEASURE_RESULT = " + cp.getObject().getSurface_rst() + "";
				list = this.getMapper(MesRcmMMapper.class).doQueryMesCrWeb2((pageIndex - 1) * pageSize,
						(pageIndex - 1) * pageSize + pageSize, cp.getObject(), cp.getStartTime(), cp.getEndTime(),
						swhere, cp.getMemo2());
			}

			for (HashMap hashMap : list) {
				if (hashMap.get("COIL_NO") != null) {
					QcmJudgeSurface qjs = new QcmJudgeSurface();
					qjs.setMaterial_no((String) hashMap.get("COIL_NO"));

					List<QcmJudgeSurface> lqjsq = this.getMapper(QcmJudgeSurfaceMapper.class).find(qjs, 0, 0);
					if (lqjsq != null && lqjsq.size() > 0) {
						for (QcmJudgeSurface q : lqjsq) {
							if (q.getSurface_id().contains("U")) {
								qjs.setSf_type("U");
								QcmJudgeSurface qq = this.getMapper(QcmJudgeSurfaceMapper.class).findMaxS(qjs);

								QcmJudgeSurfaceFlaw qjsf = new QcmJudgeSurfaceFlaw();
								qjsf.setSurface_id(qq.getSurface_id());
								qjsf.setPrimary_flag("1");
								List<QcmJudgeSurfaceFlaw> list2 = this.getMapper(QcmJudgeSurfaceFlawMapper.class)
										.findWithCondition(qjsf, null, null, 0, 0);
								if (list2 != null && list2.size() > 0) {
									hashMap.put("FLAW_CODE_U", list2.get(0).getFlaw_code());
									hashMap.put("FLAW_DESC_U", list2.get(0).getFlaw_desc());
								}

							} else if (q.getSurface_id().contains("D")) {
								qjs.setSf_type("D");
								QcmJudgeSurface qq = this.getMapper(QcmJudgeSurfaceMapper.class).findMaxS(qjs);

								QcmJudgeSurfaceFlaw qjsf = new QcmJudgeSurfaceFlaw();
								qjsf.setSurface_id(qq.getSurface_id());
								qjsf.setPrimary_flag("1");
								List<QcmJudgeSurfaceFlaw> list2 = this.getMapper(QcmJudgeSurfaceFlawMapper.class)
										.findWithCondition(qjsf, null, null, 0, 0);
								if (list2 != null && list2.size() > 0) {
									hashMap.put("FLAW_CODE_D", list2.get(0).getFlaw_code());
									hashMap.put("FLAW_DESC_D", list2.get(0).getFlaw_desc());
								}
							} else if (q.getSurface_id().contains("E")) {
								qjs.setSf_type("E");
								QcmJudgeSurface qq = this.getMapper(QcmJudgeSurfaceMapper.class).findMaxS(qjs);

								QcmJudgeSurfaceFlaw qjsf = new QcmJudgeSurfaceFlaw();
								qjsf.setSurface_id(qq.getSurface_id());
								qjsf.setPrimary_flag("1");
								List<QcmJudgeSurfaceFlaw> list2 = this.getMapper(QcmJudgeSurfaceFlawMapper.class)
										.findWithCondition(qjsf, null, null, 0, 0);
								if (list2 != null && list2.size() > 0) {
									hashMap.put("FLAW_CODE_E", list2.get(0).getFlaw_code());
									hashMap.put("FLAW_DESC_E", list2.get(0).getFlaw_desc());
								}
							}

						}
					}
					
				}
			}

			pm.setRows(list);
			pm.setTotal(this.getMapper(MesRcmMMapper.class).doQueryMesCrWebCount1(cp.getObject(),
					cp.getStartTime(), cp.getEndTime(), cp.getMemo2(), swhere));
			rm.setState("200");
			rm.setData(pm);
		} catch (Exception ex) {
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!" + ex.getMessage());
		}
		return rm;
	}

	
	/**
	 *酸洗 调用生产计划模块提供的接口获取，未进行综合判定的物料信息 分页查询 startTime 开始时间 endTime 结束时间
	 * memo2:投料卷号 memo1 上表、下表或者边部检验页面（U、D、E） memo1="U" -----为上表
	 */
	public ResultModel doQueryMesCrWeb_plm(CommonPage<MesPlmD> cp) {
		ResultModel rm = new ResultModel();
		int pageSize = cp.getPageSize();
		int pageIndex = cp.getPageIndex();
		MesPlmD y = cp.getObject();
		PageModel<HashMap> pm = new PageModel<HashMap>(pageIndex, pageSize);
		String swhere = "";
		if (y.getOrder_no() != null && !y.getOrder_no().equals("")) {
			swhere += " and ydm.ORDERNO like '%" + y.getOrder_no() + "%'";
		}
		if (y.getHeatno() != null && !y.getHeatno().equals("")) {
			swhere += " and ydm.HEATNO like '%" + y.getHeatno() + "%'";
		}
		if (y.getBatchno() != null && !y.getBatchno().equals("")) {
			swhere += " and ydm.BATCHNO like '%" + y.getBatchno() + "%'";
		}
		if (cp.getMemo4() != null && !"".equals(cp.getMemo4())) {
			swhere += " and ydm.materailcoilno like '%" + cp.getMemo4() + "%'";
		}
		List<HashMap> list = new ArrayList<>();

		try {
			// 增加页面"检查结果"查询临时方法,将来可修改。
			if ("B".equals(cp.getMemo1().trim())) {
				swhere = " and ydm.SURFACERESULT = " + cp.getObject().getSurface_rst() + "";
				list = this.getMapper(MesPlmMMapper.class).doQueryMesCrWeb1((pageIndex - 1) * pageSize,
						(pageIndex - 1) * pageSize + pageSize, cp.getObject(), cp.getStartTime(), cp.getEndTime(),
						swhere, cp.getMemo2());
			} else {
				swhere = " and ydm.MEASURE_RESULT = " + cp.getObject().getSurface_rst() + "";
				list = this.getMapper(MesPlmMMapper.class).doQueryMesCrWeb2((pageIndex - 1) * pageSize,
						(pageIndex - 1) * pageSize + pageSize, cp.getObject(), cp.getStartTime(), cp.getEndTime(),
						swhere, cp.getMemo2());
			}

			for (HashMap hashMap : list) {
				if (hashMap.get("COIL_NO") != null) {
					QcmJudgeSurface qjs = new QcmJudgeSurface();
					qjs.setMaterial_no((String) hashMap.get("COIL_NO"));

					List<QcmJudgeSurface> lqjsq = this.getMapper(QcmJudgeSurfaceMapper.class).find(qjs, 0, 0);
					if (lqjsq != null && lqjsq.size() > 0) {
						for (QcmJudgeSurface q : lqjsq) {
							if (q.getSurface_id().contains("U")) {
								qjs.setSf_type("U");
								QcmJudgeSurface qq = this.getMapper(QcmJudgeSurfaceMapper.class).findMaxS(qjs);

								QcmJudgeSurfaceFlaw qjsf = new QcmJudgeSurfaceFlaw();
								qjsf.setSurface_id(qq.getSurface_id());
								qjsf.setPrimary_flag("1");
								List<QcmJudgeSurfaceFlaw> list2 = this.getMapper(QcmJudgeSurfaceFlawMapper.class)
										.findWithCondition(qjsf, null, null, 0, 0);
								if (list2 != null && list2.size() > 0) {
									hashMap.put("FLAW_CODE_U", list2.get(0).getFlaw_code());
									hashMap.put("FLAW_DESC_U", list2.get(0).getFlaw_desc());
								}

							} else if (q.getSurface_id().contains("D")) {
								qjs.setSf_type("D");
								QcmJudgeSurface qq = this.getMapper(QcmJudgeSurfaceMapper.class).findMaxS(qjs);

								QcmJudgeSurfaceFlaw qjsf = new QcmJudgeSurfaceFlaw();
								qjsf.setSurface_id(qq.getSurface_id());
								qjsf.setPrimary_flag("1");
								List<QcmJudgeSurfaceFlaw> list2 = this.getMapper(QcmJudgeSurfaceFlawMapper.class)
										.findWithCondition(qjsf, null, null, 0, 0);
								if (list2 != null && list2.size() > 0) {
									hashMap.put("FLAW_CODE_D", list2.get(0).getFlaw_code());
									hashMap.put("FLAW_DESC_D", list2.get(0).getFlaw_desc());
								}
							} else if (q.getSurface_id().contains("E")) {
								qjs.setSf_type("E");
								QcmJudgeSurface qq = this.getMapper(QcmJudgeSurfaceMapper.class).findMaxS(qjs);

								QcmJudgeSurfaceFlaw qjsf = new QcmJudgeSurfaceFlaw();
								qjsf.setSurface_id(qq.getSurface_id());
								qjsf.setPrimary_flag("1");
								List<QcmJudgeSurfaceFlaw> list2 = this.getMapper(QcmJudgeSurfaceFlawMapper.class)
										.findWithCondition(qjsf, null, null, 0, 0);
								if (list2 != null && list2.size() > 0) {
									hashMap.put("FLAW_CODE_E", list2.get(0).getFlaw_code());
									hashMap.put("FLAW_DESC_E", list2.get(0).getFlaw_desc());
								}
							}

						}
					}
					YdmProductDetail ydd = this.getMapper(YdmProductDetailMapper.class).findById((String) hashMap.get("COIL_NO"));
					if(ydd==null || ydd.getCoilno()==null){
//						rm.setState("500");
//						rm.setMsgInfo("暂无出口卷库存信息！");
//						return rm;
					}else{
						if ("40740302".equals(ydd.getMeasure_result())) {
							hashMap.put("BASE_NAME", "不合格");	
						}else {
							hashMap.put("BASE_NAME", "合格");
						}
						hashMap.put("up_result", ydd.getUp_surface_result());
						hashMap.put("ud_result", ydd.getUd_surface_result());
						hashMap.put("ue_result", ydd.getMarginal_result());
						if ("40740601".equals(ydd.getUp_surface_result()) && "40740601".equals(ydd.getUd_surface_result())
								&& "40740601".equals(ydd.getMarginal_result())) {
							hashMap.put("SF_RESULT_DESC", "合格");
						} else if ("40740603".equals(ydd.getUp_surface_result())
								|| "40740603".equals(ydd.getUd_surface_result())
								|| "40740603".equals(ydd.getMarginal_result())) {
							hashMap.put("SF_RESULT_DESC", "待判");
							// 把库存表状态改为质量锁定
						} else if ("40740604".equals(ydd.getUp_surface_result())
								|| "40740604".equals(ydd.getUd_surface_result())
								|| "40740604".equals(ydd.getMarginal_result())) {
							hashMap.put("SF_RESULT_DESC", "判废");
							// 把库存表状态改为质量锁定
						} else {
							hashMap.put("SF_RESULT_DESC", "不合格");
						}
					}
					
				}
			}

			pm.setRows(list);
			pm.setTotal(this.getMapper(MesPlmMMapper.class).doQueryMesCrWebCount1(cp.getObject(),
					cp.getStartTime(), cp.getEndTime(), cp.getMemo2(), swhere));
			rm.setState("200");
			rm.setData(pm);
		} catch (Exception ex) {
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!" + ex.getMessage());
		}
		return rm;
	}
	
	
	/**
	 * 平整机 调用生产计划模块提供的接口获取，未进行综合判定的物料信息 分页查询 startTime 开始时间 endTime 结束时间
	 * memo2:投料卷号 memo1 上表、下表或者边部检验页面（U、D、E） memo1="U" -----为上表
	 */
	public ResultModel doQueryMesCrWeb_tpm(CommonPage<MesTpmD> cp) {
		ResultModel rm = new ResultModel();
		int pageSize = cp.getPageSize();
		int pageIndex = cp.getPageIndex();
		MesTpmD y = cp.getObject();
		PageModel<HashMap> pm = new PageModel<HashMap>(pageIndex, pageSize);
		String swhere = "";
		if (y.getOrder_no() != null && !y.getOrder_no().equals("")) {
			swhere += " and ydm.ORDERNO like '%" + y.getOrder_no() + "%'";
		}
		if (y.getHeatno() != null && !y.getHeatno().equals("")) {
			swhere += " and ydm.HEATNO like '%" + y.getHeatno() + "%'";
		}
		if (y.getBatchno() != null && !y.getBatchno().equals("")) {
			swhere += " and ydm.BATCHNO like '%" + y.getBatchno() + "%'";
		}
		if (cp.getMemo4() != null && !"".equals(cp.getMemo4())) {
			swhere += " and ydm.materailcoilno like '%" + cp.getMemo4() + "%'";
		}
		List<HashMap> list = new ArrayList<>();

		try {
			// 增加页面"检查结果"查询临时方法,将来可修改。
			if ("B".equals(cp.getMemo1().trim())) {
				swhere = " and ydm.SURFACERESULT = " + cp.getObject().getSurface_rst() + "";
				list = this.getMapper(MesTpmMMapper.class).doQueryMesCrWeb1((pageIndex - 1) * pageSize,
						(pageIndex - 1) * pageSize + pageSize, cp.getObject(), cp.getStartTime(), cp.getEndTime(),
						swhere, cp.getMemo2());
			} else {
				swhere = " and ydm.MEASURE_RESULT = " + cp.getObject().getSurface_rst() + "";
				list = this.getMapper(MesTpmMMapper.class).doQueryMesCrWeb2((pageIndex - 1) * pageSize,
						(pageIndex - 1) * pageSize + pageSize, cp.getObject(), cp.getStartTime(), cp.getEndTime(),
						swhere, cp.getMemo2());
			}

			for (HashMap hashMap : list) {
				if (hashMap.get("COIL_NO") != null) {
					QcmJudgeSurface qjs = new QcmJudgeSurface();
					qjs.setMaterial_no((String) hashMap.get("COIL_NO"));

					List<QcmJudgeSurface> lqjsq = this.getMapper(QcmJudgeSurfaceMapper.class).find(qjs, 0, 0);
					if (lqjsq != null && lqjsq.size() > 0) {
						for (QcmJudgeSurface q : lqjsq) {
							if (q.getSurface_id().contains("U")) {
								qjs.setSf_type("U");
								QcmJudgeSurface qq = this.getMapper(QcmJudgeSurfaceMapper.class).findMaxS(qjs);

								QcmJudgeSurfaceFlaw qjsf = new QcmJudgeSurfaceFlaw();
								qjsf.setSurface_id(qq.getSurface_id());
								qjsf.setPrimary_flag("1");
								List<QcmJudgeSurfaceFlaw> list2 = this.getMapper(QcmJudgeSurfaceFlawMapper.class)
										.findWithCondition(qjsf, null, null, 0, 0);
								if (list2 != null && list2.size() > 0) {
									hashMap.put("FLAW_CODE_U", list2.get(0).getFlaw_code());
									hashMap.put("FLAW_DESC_U", list2.get(0).getFlaw_desc());
								}

							} else if (q.getSurface_id().contains("D")) {
								qjs.setSf_type("D");
								QcmJudgeSurface qq = this.getMapper(QcmJudgeSurfaceMapper.class).findMaxS(qjs);

								QcmJudgeSurfaceFlaw qjsf = new QcmJudgeSurfaceFlaw();
								qjsf.setSurface_id(qq.getSurface_id());
								qjsf.setPrimary_flag("1");
								List<QcmJudgeSurfaceFlaw> list2 = this.getMapper(QcmJudgeSurfaceFlawMapper.class)
										.findWithCondition(qjsf, null, null, 0, 0);
								if (list2 != null && list2.size() > 0) {
									hashMap.put("FLAW_CODE_D", list2.get(0).getFlaw_code());
									hashMap.put("FLAW_DESC_D", list2.get(0).getFlaw_desc());
								}
							} else if (q.getSurface_id().contains("E")) {
								qjs.setSf_type("E");
								QcmJudgeSurface qq = this.getMapper(QcmJudgeSurfaceMapper.class).findMaxS(qjs);

								QcmJudgeSurfaceFlaw qjsf = new QcmJudgeSurfaceFlaw();
								qjsf.setSurface_id(qq.getSurface_id());
								qjsf.setPrimary_flag("1");
								List<QcmJudgeSurfaceFlaw> list2 = this.getMapper(QcmJudgeSurfaceFlawMapper.class)
										.findWithCondition(qjsf, null, null, 0, 0);
								if (list2 != null && list2.size() > 0) {
									hashMap.put("FLAW_CODE_E", list2.get(0).getFlaw_code());
									hashMap.put("FLAW_DESC_E", list2.get(0).getFlaw_desc());
								}
							}

						}
					}
				}
			}

			pm.setRows(list);
			pm.setTotal(this.getMapper(MesTpmMMapper.class).doQueryMesCrWebCount1(cp.getObject(),
					cp.getStartTime(), cp.getEndTime(), cp.getMemo2(), swhere));
			rm.setState("200");
			rm.setData(pm);
		} catch (Exception ex) {
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!" + ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 外观检测管理，公差检测管理，综合判定管理
	 * 4mm,12mm
	 * @param cp
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public ResultModel doQueryMaterialWeb(CommonPage<MesCrSlittingD> cp) {
		ResultModel rm = new ResultModel();
		int pageSize = cp.getPageSize();
		int pageIndex = cp.getPageIndex();
		MesCrSlittingD mcd = cp.getObject();
		PageModel<HashMap> pm = new PageModel<HashMap>(pageIndex, pageSize);
		String swhere = " and substr(d.coil_no,-1,1) not in ('B','H')";		
		
		if (StringUtils.isNotEmpty(cp.getMemo2())) {				//投料卷号
			swhere += " and (m.material_no like '%"+cp.getMemo2().trim()+"%' or mypd.materailcoilno like '%" + cp.getMemo2().trim() + "%')";
		}		
		if (cp.getMemo4() != null && !"".equals(cp.getMemo4())) {	//原料卷号
			swhere += " and (m.material_no like '%"+cp.getMemo4().trim()+"%' or mypd.materailcoilno like '%" + cp.getMemo4().trim() + "%')";
		}
		if (StringUtils.isNotEmpty(mcd.getMachine_code())) {		//机组
			swhere += " and m.machine_code = '"+mcd.getMachine_code()+"'";
		}
		if (StringUtils.isNotEmpty(cp.getStartTime())) {			//开始时间
			swhere += " and m.create_time >= to_date('"+cp.getStartTime()+"', 'yyyy-MM-dd hh24:mi:ss')";
		}
		if (StringUtils.isNotEmpty(cp.getEndTime())) {				//结束时间
			swhere += " and m.create_time <= to_date('"+cp.getEndTime()+"', 'yyyy-MM-dd hh24:mi:ss')";
		}
		
		if (StringUtils.isNotEmpty(cp.getMemo5())) {
			if ("0".equals(cp.getMemo5())) { 		// 0：查询未判
				if ("B".equals(cp.getMemo1())) {
					swhere += " and not exists (select qjs.material_no from qcm_judge_surface qjs where qjs.material_no = d.coil_no)";
				}else if ("M".equals(cp.getMemo1())) {
					swhere += " and not exists (select qjm.material_no from qcm_judge_measure qjm where qjm.material_no = d.coil_no)";
				}else if ("Z".equals(cp.getMemo1())){
					swhere += " and exists (select ypd.coilno from ydm_product_detail ypd where ypd.coilno = d.coil_no and ypd.judgeresult is null)";
				}				
			}
		}
				
		try {
			List<HashMap> list = this.getMapper(MesCrSlittingDMapper.class).doQueryMesCrWeb1_mat((pageIndex - 1) * pageSize,
						(pageIndex - 1) * pageSize + pageSize, swhere);			
			pm.setRows(list);
			if (list != null && list.size() > 0) {
				pm.setTotal(list.size());
			} else {
				pm.setTotal(0);
			}
			rm.setState("200");
			rm.setData(pm);
		} catch (Exception ex) {
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!" + ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 外观检测管理，公差检测管理，综合判定管理
	 * 3mm横剪机组
	 * @param cp
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public ResultModel doQueryMaterialWeb_3mm(CommonPage<MesCrCrossCuttingD> cp) {
		ResultModel rm = new ResultModel();
		int pageSize = cp.getPageSize();
		int pageIndex = cp.getPageIndex();
		MesCrCrossCuttingD mccd = cp.getObject();
		PageModel<HashMap> pm = new PageModel<HashMap>(pageIndex, pageSize);
		String swhere = " and substr(d.packing_no,-1,1) not in ('B','H')";		
		
		if (StringUtils.isNotEmpty(cp.getMemo2())) {				//投料卷号
			swhere += " and (m.material_no like '%"+cp.getMemo2().trim()+"%' or mypd.materailcoilno like '%" + cp.getMemo2().trim() + "%')";
		}		
		if (cp.getMemo4() != null && !"".equals(cp.getMemo4())) {	//原料卷号
			swhere += " and (m.material_no like '%"+cp.getMemo4().trim()+"%' or mypd.materailcoilno like '%" + cp.getMemo4().trim() + "%')";
		}
		if (StringUtils.isNotEmpty(mccd.getMachine_code())) {		//机组
			swhere += " and m.machine_code = '"+mccd.getMachine_code()+"'";
		}
		if (StringUtils.isNotEmpty(cp.getStartTime())) {			//开始时间
			swhere += " and m.create_time >= to_date('"+cp.getStartTime()+"', 'yyyy-MM-dd hh24:mi:ss')";
		}
		if (StringUtils.isNotEmpty(cp.getEndTime())) {				//结束时间
			swhere += " and m.create_time <= to_date('"+cp.getEndTime()+"', 'yyyy-MM-dd hh24:mi:ss')";
		}
		
		if (StringUtils.isNotEmpty(cp.getMemo5())) {
			if ("0".equals(cp.getMemo5())) { 		// 0：查询未判
				if ("B".equals(cp.getMemo1())) {
					swhere += " and not exists (select qjs.material_no from qcm_judge_surface qjs where qjs.material_no = d.packing_no)";
				}else if ("M".equals(cp.getMemo1())) {
					swhere += " and not exists (select qjm.material_no from qcm_judge_measure qjm where qjm.material_no = d.packing_no)";
				}else if ("Z".equals(cp.getMemo1())){
					swhere += " and exists (select ypd.coilno from ydm_product_detail ypd where ypd.coilno = d.packing_no and ypd.judgeresult is null)";
				}				
			}
		}
		
		try {
			List<HashMap> list = this.getMapper(MesCrCrossCuttingDMapper.class).doQueryMesCrWeb1_mat((pageIndex - 1) * pageSize,
					(pageIndex - 1) * pageSize + pageSize, swhere);
			pm.setRows(list);
			if (list != null && list.size() > 0) {
				pm.setTotal(list.size());
			} else {
				pm.setTotal(0);
			}
			rm.setState("200");
			rm.setData(pm);
		} catch (Exception ex) {
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!" + ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 外观检测管理，公差检测管理，综合判定管理
	 * 平整机组
	 * @param cp
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public ResultModel doQueryMaterialWeb_tpm(CommonPage<MesTpmD> cp) {
		ResultModel rm = new ResultModel();
		int pageSize = cp.getPageSize();
		int pageIndex = cp.getPageIndex();
		MesTpmD mtd = cp.getObject();
		PageModel<HashMap> pm = new PageModel<HashMap>(pageIndex, pageSize);
		String swhere = " and substr(d.coil_no,-1,1) not in ('B','H')";		
		
		if (StringUtils.isNotEmpty(cp.getMemo2())) {				//投料卷号
			swhere += " and (m.material_no like '%"+cp.getMemo2().trim()+"%' or mypd.materailcoilno like '%" + cp.getMemo2().trim() + "%')";
		}		
		if (cp.getMemo4() != null && !"".equals(cp.getMemo4())) {	//原料卷号
			swhere += " and (m.material_no like '%"+cp.getMemo4().trim()+"%' or mypd.materailcoilno like '%" + cp.getMemo4().trim() + "%')";
		}
		if (StringUtils.isNotEmpty(mtd.getMachine_code())) {		//机组
			swhere += " and m.machine_code = '"+mtd.getMachine_code()+"'";
		}
		if (StringUtils.isNotEmpty(cp.getStartTime())) {			//开始时间
			swhere += " and m.create_time >= to_date('"+cp.getStartTime()+"', 'yyyy-MM-dd hh24:mi:ss')";
		}
		if (StringUtils.isNotEmpty(cp.getEndTime())) {				//结束时间
			swhere += " and m.create_time <= to_date('"+cp.getEndTime()+"', 'yyyy-MM-dd hh24:mi:ss')";
		}
		if (StringUtils.isNotEmpty(cp.getMemo5())) {
			if ("0".equals(cp.getMemo5())) { 		// 0：查询未判
				if ("B".equals(cp.getMemo1())) {
					swhere += " and not exists (select qjs.material_no from qcm_judge_surface qjs where qjs.material_no = d.coil_no)";
				}else if ("M".equals(cp.getMemo1())) {
					swhere += " and not exists (select qjm.material_no from qcm_judge_measure qjm where qjm.material_no = d.coil_no)";
				}else if ("Z".equals(cp.getMemo1())){
					swhere += " and exists (select ypd.coilno from ydm_product_detail ypd where ypd.coilno = d.coil_no and ypd.judgeresult is null)";
				}				
			}
		}

		try {
			List<HashMap> list = this.getMapper(MesTpmMMapper.class).doQueryMesCrWeb1_mat((pageIndex - 1) * pageSize,
					(pageIndex - 1) * pageSize + pageSize, swhere);
			pm.setRows(list);
			if (list != null && list.size() > 0) {
				pm.setTotal(list.size());
			} else {
				pm.setTotal(0);
			}
			rm.setState("200");
			rm.setData(pm);
		} catch (Exception ex) {
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!" + ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 外观检测管理，公差检测管理，综合判定管理
	 * 轧机机组
	 * @param cp
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public ResultModel doQueryMaterialWeb_rcm(CommonPage<MesRcmD> cp) {
		ResultModel rm = new ResultModel();
		int pageSize = cp.getPageSize();
		int pageIndex = cp.getPageIndex();
		MesRcmD mrd = cp.getObject();
		PageModel<HashMap> pm = new PageModel<HashMap>(pageIndex, pageSize);
		String swhere = " and substr(d.coil_no,-1,1) not in ('B','H')";		
		
		if (StringUtils.isNotEmpty(cp.getMemo2())) {				//投料卷号
			swhere += " and (m.material_no like '%"+cp.getMemo2().trim()+"%' or mypd.materailcoilno like '%" + cp.getMemo2().trim() + "%')";
		}		
		if (cp.getMemo4() != null && !"".equals(cp.getMemo4())) {	//原料卷号
			swhere += " and (m.material_no like '%"+cp.getMemo4().trim()+"%' or mypd.materailcoilno like '%" + cp.getMemo4().trim() + "%')";
		}
		if (StringUtils.isNotEmpty(mrd.getMachine_code())) {		//机组
			swhere += " and m.machine_code = '"+mrd.getMachine_code()+"'";
		}
		if (StringUtils.isNotEmpty(cp.getStartTime())) {			//开始时间
			swhere += " and m.create_time >= to_date('"+cp.getStartTime()+"', 'yyyy-MM-dd hh24:mi:ss')";
		}
		if (StringUtils.isNotEmpty(cp.getEndTime())) {				//结束时间
			swhere += " and m.create_time <= to_date('"+cp.getEndTime()+"', 'yyyy-MM-dd hh24:mi:ss')";
		}
		if (StringUtils.isNotEmpty(cp.getMemo5())) {
			if ("0".equals(cp.getMemo5())) { 		// 0：查询未判
				if ("B".equals(cp.getMemo1())) {
					swhere += " and not exists (select qjs.material_no from qcm_judge_surface qjs where qjs.material_no = d.coil_no)";
				}else if ("M".equals(cp.getMemo1())) {
					swhere += " and not exists (select qjm.material_no from qcm_judge_measure qjm where qjm.material_no = d.coil_no)";
				}else if ("Z".equals(cp.getMemo1())){
					swhere += " and exists (select ypd.coilno from ydm_product_detail ypd where ypd.coilno = d.coil_no and ypd.judgeresult is null)";
				}				
			}
		}

		try {
			List<HashMap> list = this.getMapper(MesRcmMMapper.class).doQueryMesCrWeb1_mat((pageIndex - 1) * pageSize,
					(pageIndex - 1) * pageSize + pageSize,  swhere);			 
			pm.setRows(list);
			if (list != null && list.size() > 0) {
				pm.setTotal(list.size());
			} else {
				pm.setTotal(0);
			}
			rm.setState("200");
			rm.setData(pm);
		} catch (Exception ex) {
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!" + ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 外观检测管理，公差检测管理，综合判定管理
	 * 酸洗机组
	 * @param cp
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public ResultModel doQueryMaterialWeb_plm(CommonPage<MesPlmD> cp) {
		ResultModel rm = new ResultModel();
		int pageSize = cp.getPageSize();
		int pageIndex = cp.getPageIndex();
		MesPlmD mpd = cp.getObject();
		PageModel<HashMap> pm = new PageModel<HashMap>(pageIndex, pageSize);
		String swhere = " and substr(d.coil_no,-1,1) not in ('B','H')";		
		
		if (StringUtils.isNotEmpty(cp.getMemo2())) {				//投料卷号
			swhere += " and (m.material_no like '%"+cp.getMemo2().trim()+"%' or mypd.materailcoilno like '%" + cp.getMemo2().trim() + "%')";
		}		
		if (cp.getMemo4() != null && !"".equals(cp.getMemo4())) {	//原料卷号
			swhere += " and (m.material_no like '%"+cp.getMemo4().trim()+"%' or mypd.materailcoilno like '%" + cp.getMemo4().trim() + "%')";
		}
		if (StringUtils.isNotEmpty(mpd.getMachine_code())) {		//机组
			swhere += " and m.machine_code = '"+mpd.getMachine_code()+"'";
		}
		if (StringUtils.isNotEmpty(cp.getStartTime())) {			//开始时间
			swhere += " and m.create_time >= to_date('"+cp.getStartTime()+"', 'yyyy-MM-dd hh24:mi:ss')";
		}
		if (StringUtils.isNotEmpty(cp.getEndTime())) {				//结束时间
			swhere += " and m.create_time <= to_date('"+cp.getEndTime()+"', 'yyyy-MM-dd hh24:mi:ss')";
		}
		if (StringUtils.isNotEmpty(cp.getMemo5())) {
			if ("0".equals(cp.getMemo5())) { 		// 0：查询未判
				if ("B".equals(cp.getMemo1())) {
					swhere += " and not exists (select qjs.material_no from qcm_judge_surface qjs where qjs.material_no = d.coil_no)";
				}else if ("M".equals(cp.getMemo1())) {
					swhere += " and not exists (select qjm.material_no from qcm_judge_measure qjm where qjm.material_no = d.coil_no)";
				}else if ("Z".equals(cp.getMemo1())){
					swhere += " and exists (select ypd.coilno from ydm_product_detail ypd where ypd.coilno = d.coil_no and ypd.judgeresult is null)";
				}else {
					//酸洗的公差外观检测管理
					swhere += " and (not exists (select qjm.material_no from qcm_judge_measure qjm where qjm.material_no = d.coil_no)"
							+ " or"
							+ " not exists (select qjm.material_no from qcm_judge_measure qjm where qjm.material_no = d.coil_no))";
				}			
			}
		}

		try {
			List<HashMap> list = this.getMapper(MesPlmMMapper.class).doQueryMesCrWeb1_mat((pageIndex - 1) * pageSize,
						(pageIndex - 1) * pageSize + pageSize, swhere);			 
			pm.setRows(list);
			if (list != null && list.size() > 0) {
				pm.setTotal(list.size());
			} else {
				pm.setTotal(0);
			}
			rm.setState("200");
			rm.setData(pm);
		} catch (Exception ex) {
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!" + ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 外观检测管理，公差检测管理，综合判定管理
	 * 退火机组
	 * @param cp
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public ResultModel doQueryMaterialWeb_anneal(CommonPage<MesCrAnnealM> cp) {
		ResultModel rm = new ResultModel();
		int pageSize = cp.getPageSize();
		int pageIndex = cp.getPageIndex();
		MesCrAnnealM mcam = cp.getObject();
		PageModel<HashMap> pm = new PageModel<HashMap>(pageIndex, pageSize);
		String swhere = " and substr(m.coil_no, -1, 1) not in ('B', 'H') and m.hand_over_status ='1'";		
		
		if (StringUtils.isNotEmpty(cp.getMemo2())) {				//投料卷号
			swhere += " and (m.material_no like '%"+cp.getMemo2().trim()+"%' or mypd.materailcoilno like '%" + cp.getMemo2().trim() + "%')";
		}		
		if (cp.getMemo4() != null && !"".equals(cp.getMemo4())) {	//原料卷号
			swhere += " and (m.material_no like '%"+cp.getMemo4().trim()+"%' or mypd.materailcoilno like '%" + cp.getMemo4().trim() + "%')";
		}
		if (StringUtils.isNotEmpty(mcam.getMachine_code())) {		//机组
			//swhere += " and m.machine_code = '"+mcam.getMachine_code()+"'";
		}
		if (StringUtils.isNotEmpty(cp.getStartTime())) {			//开始时间
			swhere += " and m.create_time >= to_date('"+cp.getStartTime()+"', 'yyyy-MM-dd hh24:mi:ss')";
		}
		if (StringUtils.isNotEmpty(cp.getEndTime())) {				//结束时间
			swhere += " and m.create_time <= to_date('"+cp.getEndTime()+"', 'yyyy-MM-dd hh24:mi:ss')";
		}
		if (StringUtils.isNotEmpty(cp.getMemo5())) {
			if ("0".equals(cp.getMemo5())) { 		// 0：查询未判
				if ("B".equals(cp.getMemo1())) {
					swhere += " and not exists (select qjs.material_no from qcm_judge_surface qjs where qjs.material_no = m.coil_no)";
				}else if ("M".equals(cp.getMemo1())) {
					swhere += " and not exists (select qjm.material_no from qcm_judge_measure qjm where qjm.material_no = m.coil_no)";
				}else if ("Z".equals(cp.getMemo1())){
					swhere += " and exists (select ypd.coilno from ydm_product_detail ypd where ypd.coilno = m.coil_no and ypd.judgeresult is null)";
				}				
			}
		}

		try {		 
			List<HashMap> list = this.getMapper(MesCrAnnealMMapper.class).doQueryMesCrWeb1_mat((pageIndex - 1) * pageSize,
						(pageIndex - 1) * pageSize + pageSize,  swhere);			 
			pm.setRows(list);
			if (list != null && list.size() > 0) {
				pm.setTotal(list.size());
			} else {
				pm.setTotal(0);
			}
			rm.setState("200");
			rm.setData(pm);
		} catch (Exception ex) {
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!" + ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 退火炉 调用生产计划模块提供的接口获取，未进行综合判定的物料信息 分页查询 startTime 开始时间 endTime 结束时间
	 * memo2:投料卷号 memo1 上表、下表或者边部检验页面（U、D、E） memo1="U" -----为上表
	 */
	public ResultModel doQueryMesCrWeb_anneal(CommonPage<MesCrAnnealM> cp) {
		ResultModel rm = new ResultModel();
		int pageSize = cp.getPageSize();
		int pageIndex = cp.getPageIndex();
		MesCrAnnealM y = cp.getObject();
		PageModel<HashMap> pm = new PageModel<HashMap>(pageIndex, pageSize);
		String swhere = "";
		if (y.getOrder_no() != null && !y.getOrder_no().equals("")) {
			swhere += " and ydm.ORDERNO like '%" + y.getOrder_no() + "%'";
		}
		if (y.getHeatno() != null && !y.getHeatno().equals("")) {
			swhere += " and ydm.HEATNO like '%" + y.getHeatno() + "%'";
		}
		if (y.getBatchno() != null && !y.getBatchno().equals("")) {
			swhere += " and ydm.BATCHNO like '%" + y.getBatchno() + "%'";
		}
		if (cp.getMemo4() != null && !"".equals(cp.getMemo4())) {
			swhere += " and ydm.materailcoilno like '%" + cp.getMemo4() + "%'";
		}
		List<HashMap> list = new ArrayList<>();

		try {
			// 增加页面"检查结果"查询临时方法,将来可修改。
			if ("B".equals(cp.getMemo1().trim())) {
				swhere = " and ydm.SURFACERESULT = " + cp.getObject().getSurface_rst() + "";
				list = this.getMapper(MesCrAnnealMMapper.class).doQueryMesCrWeb1((pageIndex - 1) * pageSize,
						(pageIndex - 1) * pageSize + pageSize, cp.getObject(), cp.getStartTime(), cp.getEndTime(),
						swhere, cp.getMemo2());
			}
			else {
				swhere = " and ydm.MEASURE_RESULT = " + cp.getObject().getSurface_rst() + "";
				list = this.getMapper(MesCrAnnealMMapper.class).doQueryMesCrWeb2((pageIndex - 1) * pageSize,
						(pageIndex - 1) * pageSize + pageSize, cp.getObject(), cp.getStartTime(), cp.getEndTime(),
						swhere, cp.getMemo2());
			}

			for (HashMap hashMap : list) {
				if (hashMap.get("COIL_NO") != null) {
					QcmJudgeSurface qjs = new QcmJudgeSurface();
					qjs.setMaterial_no((String) hashMap.get("COIL_NO"));

					List<QcmJudgeSurface> lqjsq = this.getMapper(QcmJudgeSurfaceMapper.class).find(qjs, 0, 0);
					if (lqjsq != null && lqjsq.size() > 0) {
						for (QcmJudgeSurface q : lqjsq) {
							if (q.getSurface_id().contains("U")) {
								qjs.setSf_type("U");
								QcmJudgeSurface qq = this.getMapper(QcmJudgeSurfaceMapper.class).findMaxS(qjs);

								QcmJudgeSurfaceFlaw qjsf = new QcmJudgeSurfaceFlaw();
								qjsf.setSurface_id(qq.getSurface_id());
								qjsf.setPrimary_flag("1");
								List<QcmJudgeSurfaceFlaw> list2 = this.getMapper(QcmJudgeSurfaceFlawMapper.class)
										.findWithCondition(qjsf, null, null, 0, 0);
								if (list2 != null && list2.size() > 0) {
									hashMap.put("FLAW_CODE_U", list2.get(0).getFlaw_code());
									hashMap.put("FLAW_DESC_U", list2.get(0).getFlaw_desc());
								}

							} else if (q.getSurface_id().contains("D")) {
								qjs.setSf_type("D");
								QcmJudgeSurface qq = this.getMapper(QcmJudgeSurfaceMapper.class).findMaxS(qjs);

								QcmJudgeSurfaceFlaw qjsf = new QcmJudgeSurfaceFlaw();
								qjsf.setSurface_id(qq.getSurface_id());
								qjsf.setPrimary_flag("1");
								List<QcmJudgeSurfaceFlaw> list2 = this.getMapper(QcmJudgeSurfaceFlawMapper.class)
										.findWithCondition(qjsf, null, null, 0, 0);
								if (list2 != null && list2.size() > 0) {
									hashMap.put("FLAW_CODE_D", list2.get(0).getFlaw_code());
									hashMap.put("FLAW_DESC_D", list2.get(0).getFlaw_desc());
								}
							} else if (q.getSurface_id().contains("E")) {
								qjs.setSf_type("E");
								QcmJudgeSurface qq = this.getMapper(QcmJudgeSurfaceMapper.class).findMaxS(qjs);

								QcmJudgeSurfaceFlaw qjsf = new QcmJudgeSurfaceFlaw();
								qjsf.setSurface_id(qq.getSurface_id());
								qjsf.setPrimary_flag("1");
								List<QcmJudgeSurfaceFlaw> list2 = this.getMapper(QcmJudgeSurfaceFlawMapper.class)
										.findWithCondition(qjsf, null, null, 0, 0);
								if (list2 != null && list2.size() > 0) {
									hashMap.put("FLAW_CODE_E", list2.get(0).getFlaw_code());
									hashMap.put("FLAW_DESC_E", list2.get(0).getFlaw_desc());
								}
							}

						}
					}
					
				}
			}

			pm.setRows(list);
			pm.setTotal(this.getMapper(MesCrAnnealMMapper.class).doQueryMesCrWebCount1(cp.getObject(),
					cp.getStartTime(), cp.getEndTime(), cp.getMemo2(), swhere));
			rm.setState("200");
			rm.setData(pm);
		} catch (Exception ex) {
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!" + ex.getMessage());
		}
		return rm;
	}
			
	/**
	 * 4mm,12mm 调用生产计划模块提供的接口获取，未进行综合判定的物料信息 分页查询 startTime 开始时间 endTime 结束时间
	 * memo2:投料卷号 memo1 上表、下表或者边部检验页面（U、D、E） memo1="U" -----为上表
	 */
	public ResultModel doQueryMesCrWeb(CommonPage<MesCrSlittingD> cp) {
		ResultModel rm = new ResultModel();
		int pageSize = cp.getPageSize();
		int pageIndex = cp.getPageIndex();
		MesCrSlittingD y = cp.getObject();
		PageModel<HashMap> pm = new PageModel<HashMap>(pageIndex, pageSize);
		String swhere = "";
		if (y.getOrderno() != null && !y.getOrderno().equals("")) {
			swhere += " and ydm.orderno like '%" + y.getOrderno() + "%'";
		}
		if (y.getHeatno() != null && !y.getHeatno().equals("")) {
			swhere += " and ydm.heatno like '%" + y.getHeatno() + "%'";
		}
		if (y.getBatchno() != null && !y.getBatchno().equals("")) {
			swhere += " and ydm.batchno like '%" + y.getBatchno() + "%'";
		}
		if (cp.getMemo4() != null && !"".equals(cp.getMemo4())) {
			swhere += " and ydm.materailcoilno like '%" + cp.getMemo4() + "%'";
		}
		List<HashMap> list = new ArrayList<>();

		try {
			// 增加页面"检查结果"查询临时方法,将来可修改。
			if ("B".equals(cp.getMemo1().trim())) {
				swhere = " and ydm.SURFACERESULT = " + cp.getObject().getSurface_rst() + "";
				list = this.getMapper(MesCrSlittingDMapper.class).doQueryMesCrWeb1((pageIndex - 1) * pageSize,
						(pageIndex - 1) * pageSize + pageSize, cp.getObject(), cp.getStartTime(), cp.getEndTime(),
						swhere, cp.getMemo2());
			}
			else {
				swhere = " and ydm.MEASURE_RESULT = " + cp.getObject().getSurface_rst() + "";
				list = this.getMapper(MesCrSlittingDMapper.class).doQueryMesCrWeb2((pageIndex - 1) * pageSize,
						(pageIndex - 1) * pageSize + pageSize, cp.getObject(), cp.getStartTime(), cp.getEndTime(),
						swhere, cp.getMemo2());
			}

			for (HashMap hashMap : list) {
				if (hashMap.get("COIL_NO") != null) {
					QcmJudgeSurface qjs = new QcmJudgeSurface();
					qjs.setMaterial_no((String) hashMap.get("COIL_NO"));

					List<QcmJudgeSurface> lqjsq = this.getMapper(QcmJudgeSurfaceMapper.class).find(qjs, 0, 0);
					if (lqjsq != null && lqjsq.size() > 0) {
						for (QcmJudgeSurface q : lqjsq) {
							if (q.getSurface_id().contains("U")) {
								qjs.setSf_type("U");
								QcmJudgeSurface qq = this.getMapper(QcmJudgeSurfaceMapper.class).findMaxS(qjs);

								QcmJudgeSurfaceFlaw qjsf = new QcmJudgeSurfaceFlaw();
								qjsf.setSurface_id(qq.getSurface_id());
								qjsf.setPrimary_flag("1");
								List<QcmJudgeSurfaceFlaw> list2 = this.getMapper(QcmJudgeSurfaceFlawMapper.class)
										.findWithCondition(qjsf, null, null, 0, 0);
								if (list2 != null && list2.size() > 0) {
									hashMap.put("FLAW_CODE_U", list2.get(0).getFlaw_code());
									hashMap.put("FLAW_DESC_U", list2.get(0).getFlaw_desc());
								}

							} else if (q.getSurface_id().contains("D")) {
								qjs.setSf_type("D");
								QcmJudgeSurface qq = this.getMapper(QcmJudgeSurfaceMapper.class).findMaxS(qjs);

								QcmJudgeSurfaceFlaw qjsf = new QcmJudgeSurfaceFlaw();
								qjsf.setSurface_id(qq.getSurface_id());
								qjsf.setPrimary_flag("1");
								List<QcmJudgeSurfaceFlaw> list2 = this.getMapper(QcmJudgeSurfaceFlawMapper.class)
										.findWithCondition(qjsf, null, null, 0, 0);
								if (list2 != null && list2.size() > 0) {
									hashMap.put("FLAW_CODE_D", list2.get(0).getFlaw_code());
									hashMap.put("FLAW_DESC_D", list2.get(0).getFlaw_desc());
								}
							} else if (q.getSurface_id().contains("E")) {
								qjs.setSf_type("E");
								QcmJudgeSurface qq = this.getMapper(QcmJudgeSurfaceMapper.class).findMaxS(qjs);

								QcmJudgeSurfaceFlaw qjsf = new QcmJudgeSurfaceFlaw();
								qjsf.setSurface_id(qq.getSurface_id());
								qjsf.setPrimary_flag("1");
								List<QcmJudgeSurfaceFlaw> list2 = this.getMapper(QcmJudgeSurfaceFlawMapper.class)
										.findWithCondition(qjsf, null, null, 0, 0);
								if (list2 != null && list2.size() > 0) {
									hashMap.put("FLAW_CODE_E", list2.get(0).getFlaw_code());
									hashMap.put("FLAW_DESC_E", list2.get(0).getFlaw_desc());
								}
							}

						}
					}					
					
				}
			}

			pm.setRows(list);
			pm.setTotal(this.getMapper(MesCrSlittingDMapper.class).doQueryMesCrWebCount1(cp.getObject(),
					cp.getStartTime(), cp.getEndTime(), cp.getMemo2(), swhere));
			rm.setState("200");
			rm.setData(pm);
		} catch (Exception ex) {
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!" + ex.getMessage());
		}
		return rm;
	}

	public ResultModel doQueryMesLWeb(CommonPage<YdmProductDetail> cp) {
		ResultModel rm = new ResultModel();
		if (cp == null || cp.getObject() == null || cp.getObject().getBatchno() == null) {
			rm.setState("500");
			rm.setMsgInfo("请输入参数!");
			return rm;
		}
		try {
			List<String> list = new ArrayList<>();
			list = this.getMapper(MesCrSlittingMMapper.class).findMat(cp.getObject().getBatchno());
			rm.setState("200");
			rm.setData(list);
		} catch (Exception ex) {
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!" + ex.getMessage());
		}
		return rm;
	}

	public ResultModel doQueryMesL2Web(CommonPage<MesCrSlittingM> cp) {
		ResultModel rm = new ResultModel();
		if (cp == null || cp.getObject() == null || cp.getObject().getMaterial_no() == null) {
			rm.setState("500");
			rm.setMsgInfo("请输入参数!");
			return rm;
		}
		try {
			List<String> list = new ArrayList<>();
			list = this.getMapper(MesCrSlittingMMapper.class).doFind(cp.getObject().getMaterial_no());
			rm.setState("200");
			rm.setData(list);
		} catch (Exception ex) {
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!" + ex.getMessage());
		}
		return rm;
	}

	/**
	 * object: material_no:检验号
	 * 
	 * @param cp
	 * @return
	 */
	public ResultModel doQueryMesL3Web(CommonPage<MesCrSlittingM> cp) {
		ResultModel rm = new ResultModel();
		if (cp == null || cp.getObject() == null || cp.getObject().getMaterial_no() == null) {
			rm.setState("500");
			rm.setMsgInfo("请输入参数!");
			return rm;
		}
		try {
			List<MesCrSlittingDSum> list = new ArrayList<>();
			list = this.getMapper(MesCrSlittingMMapper.class).doFindD(cp.getObject().getMaterial_no());
			rm.setState("200");
			rm.setData(list);
		} catch (Exception ex) {
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!" + ex.getMessage());
		}
		return rm;
	}

	/**
	 * 给质量的接口 查询生产订单信息
	 * 
	 * @param order_no 订单号
	 * @return 2018-06-13
	 */
	public PlnProdorder getPlnOrderByOrderNo(String order_no) {
		PlnProdorder ppo = new PlnProdorder();
		ppo.setOrder_no(order_no);
		List<PlnProdorder> plpo = this.getMapper(PlnProdorderMapper.class).findWithCondition(ppo, null,
				" create_time desc", 0, 1);
		return plpo.get(0);
	}
	
	
	/**
	 * 获取实物计划规格
	 * 
	 * @param   object_no  实物卷号 
	 * @return  thick width length 
	 */
	public PlnMaterielDetail getDsnSizeOfMat(String object_no) {
		PlnMaterielDetail  rst = null;
		// 获取虚拟物料信息
		List<PlnMaterielDetail> pmds = this.getMapper(PlnMaterielDetailMapper.class)
				.findWithCondition(null, " object_no = '"+object_no+"' and nvl(invalid_flg,0) = 0 ", "", 0, 1);
		if(Utils.isNotEmpty(pmds)) {
			rst =  pmds.get(0);
		}
		return rst;
		
	}

	/**
	 * 称重保存-自动计算边丝重量
	 * 
	 * @param msm 母卷实绩
	 * @return 子卷实重和
	 * @throws Exception
	 */
	public double ClcOffcutWeight(MesCrSlittingM msm) throws Exception {
		double y = 0d;
		MesCrSlittingD mcsd = new MesCrSlittingD();
		mcsd.setProcess_no(msm.getProcess_no());
		// 查询所有子卷实绩
		List<MesCrSlittingD> lmcsdq = this.getMapper(MesCrSlittingDMapper.class).findWithCondition(mcsd,
				" coil_no not like '%B' ", null, 0, 0);
		if (lmcsdq == null || lmcsdq.size() == 0) {
			throw new Exception("母卷[" + msm.getMaterial_no_vt() + "]的子卷实绩信息不存在！无法找到子卷信息!");
		}
		for (MesCrSlittingD mescr : lmcsdq) {
			y += mescr.getCoil_act_wgt() == null ? 0 : mescr.getCoil_act_wgt();
		}
		return y;
	}

	/**
	 * 判断订单的计重方式
	 * 
	 * @param prod_order_no
	 * @return
	 * @throws Exception
	 */
	public boolean judgeOrderWeightType(String prod_order_no) throws Exception {
		boolean flag = false;
		if (prod_order_no == null || "".equals(prod_order_no)) {
			throw new Exception("请传入生产订单号!");
		}
		List<PlnProdorder> ppo = this.getMapper(PlnProdorderMapper.class).findWithCondition(null,
				"prod_order_no = '" + prod_order_no + "'", "", 0, 1);
		if (ppo == null) {
			throw new Exception("未找到生产订单[" + prod_order_no + "]信息!");
		} else if (ppo.get(0).getWeight_type_no() != null && "102301".equals(ppo.get(0).getWeight_type_no())) {
			flag = true;
		}
		return flag;
	}

	// 查询4mm正在生产的数据
	public ResultModel doQueryMes4mmWeb(CommonPage<MesCrSlittingM> cp) {
		ResultModel rm = new ResultModel();
		try {
			List<MesCrSlittingM> list = new ArrayList<>();
			String machine_code = "M0001";
			list = this.getMapper(MesCrSlittingMMapper.class).findWithCondition(null,
					"machine_code='" + machine_code + "' and nvl(hand_over_status,'0') = '0' ", null, 0, 0);
			rm.setState("200");
			rm.setData(list);
		} catch (Exception ex) {
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!" + ex.getMessage());
		}
		return rm;
	}

	// 查询12mm正在生产的数据
	public ResultModel doQueryMes12mmWeb(CommonPage<MesCrSlittingM> cp) {
		ResultModel rm = new ResultModel();
		try {
			List<MesCrSlittingM> list = new ArrayList<>();
			String machine_code = "M0002";
			list = this.getMapper(MesCrSlittingMMapper.class).findWithCondition(null,
					"machine_code='" + machine_code + "' and nvl(hand_over_status,'0') = '0' ", null, 0, 0);
			rm.setState("200");
			rm.setData(list);
		} catch (Exception ex) {
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!" + ex.getMessage());
		}
		return rm;
	}

	// 查询3mm正在生产的数据
	public ResultModel doQueryMes3mmWeb(CommonPage<MesCrCrossCuttingM> cp) {
		ResultModel rm = new ResultModel();
		try {
			List<MesCrCrossCuttingM> list = new ArrayList<>();
			String machine_code = "M0003";
			list = this.getMapper(MesCrCrossCuttingMMapper.class).findWithCondition(null,
					"machine_code='" + machine_code + "' and nvl(hand_over_status,'0') = '0' ", null, 0, 0);
			rm.setState("200");
			rm.setData(list);
		} catch (Exception ex) {
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!" + ex.getMessage());
		}
		return rm;
	}

	// 查询退火炉正在生产的数据
	public ResultModel doQueryMesAnnealWeb(CommonPage<MesCrAnnealM> cp) {
		ResultModel rm = new ResultModel();
		try {
			List<MesCrAnnealM> list = new ArrayList<>();
			// String machine_code="M0003";
			list = this.getMapper(MesCrAnnealMMapper.class).findWithCondition(null, "nvl(hand_over_status,'0') = '0' ",
					null, 0, 0);
			rm.setState("200");
			rm.setData(list);
		} catch (Exception ex) {
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!" + ex.getMessage());
		}
		return rm;
	}

	// 查询平整机正在生产的数据
	public ResultModel doQueryMesTpmWeb(CommonPage<MesTpmM> cp) {
		ResultModel rm = new ResultModel();
		try {
			List<MesTpmM> list = new ArrayList<>();
			list = this.getMapper(MesTpmMMapper.class).findWithCondition(null, "nvl(hand_over_status,'0') = '0' ", null,
					0, 0);
			rm.setState("200");
			rm.setData(list);
		} catch (Exception ex) {
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!" + ex.getMessage());
		}
		return rm;
	}
	
	// 传入参数就是成品物料号，返回原料卷号就可以了
	public ResultModel doQueryMesYdmWeb(CommonPage<YdmProductDetail> cp) {
		ResultModel rm = new ResultModel();
		try {
			List<YdmProductDetail> list = new ArrayList<>();
			list = this.getMapper(YdmProductDetailMapper.class).findWithCondition(null, "coilno='"+cp.getMemo1()+"'", null,
					0, 0);
			if(list!=null && list.size()>0){
				rm.setData(list.get(0));
			}
			rm.setState("200");
		} catch (Exception ex) {
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!" + ex.getMessage());
		}
		return rm;
	}
	
	
	/**memo1:产线代码
	 * memo2:批次号
	 * @param cp
	 * @return
	 */
	public ResultModel doQueryBatchNoWeb(CommonPage<YdmProductDetail> cp) {
		ResultModel rm = new ResultModel();
		try {
			List<MesQmsView> list = new ArrayList<>();
			if("C001".equals(cp.getMemo1())){
				if(cp.getMemo2()==null){
					cp.setMemo2("");
				}
				list=this.getMapper(MesCrSlittingDMapper.class).doQuery3(cp.getMemo2());
			}else if("C002".equals(cp.getMemo1())){
				if(cp.getMemo2()==null){
					cp.setMemo2("");
				}
				list=this.getMapper(MesCrSlittingDMapper.class).doQuery3(cp.getMemo2());
			}else if("C011".equals(cp.getMemo1())){
				if(cp.getMemo2()==null){
					cp.setMemo2("");
				}
				list=this.getMapper(MesCrSlittingDMapper.class).doQuery3tpm(cp.getMemo2());
			}else if("C012".equals(cp.getMemo1())){
				if(cp.getMemo2()==null){
					cp.setMemo2("");
				}
				list=this.getMapper(MesCrSlittingDMapper.class).doQuery33mm(cp.getMemo2());
			}else if("C013".equals(cp.getMemo1()) || "C014".equals(cp.getMemo1())
					|| "C015".equals(cp.getMemo1()) || "C017".equals(cp.getMemo1())){
				if(cp.getMemo2()==null){
					cp.setMemo2("");
				}
				list=this.getMapper(MesCrSlittingDMapper.class).doQuery3Anneal(cp.getMemo2());
			}
			rm.setData(list);
			rm.setState("200");
		} catch (Exception ex) {
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!" + ex.getMessage());
		}
		return rm;
	}
	
	/**
	 startTime：开始时间
	 endTime：结束时间
	* @param oci
	* @return
	*/
	public ResultModel doQueryWeb_gejizu(CommonPage<MesTpmM> oci){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesTpmMMapper.class).doQuerygejizuWeb(oci.getStartTime(),oci.getEndTime(),oci.getMemo1(),oci.getMemo2()));
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 只处理作业完成的吨位
	 startTime：开始时间
	 endTime：结束时间
	* @param oci
	* @return
	*/
	public ResultModel doQueryWeb_gejizu2(CommonPage<MesTpmM> oci){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesTpmMMapper.class).doQueryWeb_gejizu2(oci.getStartTime(),oci.getEndTime(),oci.getMemo1(),oci.getMemo2()));
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	}
	
	
	
	
	public void Match_Rl_Thk(String prod_order_no , double mat_thk) {
		// 获取订单信息
		// 获取质量设计信息
	}
	
	//查询退火炉三级二级数据--质量
	public ResultModel doQueryWeb_tuihuo(CommonPage<MesCrAnnealM> oci){
		ResultModel rm=new ResultModel();
		MesCrAnnealM mes=oci.getObject();
		try{			
			List<HashMap> list = this.getMapper(MesCrAnnealMMapper.class).doQueryWeb_zhiliang(mes,oci.getStartTime(),oci.getEndTime(),oci.getMemo1(),oci.getMemo2());
			rm.setState("200");
			rm.setData(list);
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	} 
	
	//查询平整三级二级数据--质量
	public ResultModel doQueryWeb_pingzheng(CommonPage<MesTpmM> oci){
		ResultModel rm=new ResultModel();
		MesTpmM mes=oci.getObject();
		try{
			List<HashMap> list = this.getMapper(MesTpmMMapper.class).doQueryWeb_zhiliang(mes,oci.getStartTime(),oci.getEndTime(),oci.getMemo1(),oci.getMemo2());
			rm.setState("200");
			rm.setData(list);
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	}
	
	//查询轧机三级二级数据--质量
	public ResultModel doQueryWeb_zhaji(CommonPage<MesRcmM> oci){
		ResultModel rm=new ResultModel();
		MesRcmM mes=oci.getObject();
		try{
			List<HashMap> list = this.getMapper(MesRcmMMapper.class).doQueryWeb_zhiliang(mes,oci.getStartTime(),oci.getEndTime(),oci.getMemo1(),oci.getMemo2());
			rm.setState("200");
			rm.setData(list);
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	}
	//查询小纵剪实绩数据--质量
	public ResultModel doQueryWeb_Slitting(CommonPage<MesCrSlittingM> oci){
		ResultModel rm=new ResultModel();
		MesCrSlittingM mes=oci.getObject();
		try{
			List<HashMap> list = this.getMapper(MesCrSlittingMMapper.class).doQueryWeb_zhiliang(mes,oci.getStartTime(),oci.getEndTime(),oci.getMemo1(),oci.getMemo2());
			rm.setState("200");
			rm.setData(list);
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	}
	
	//查询横剪三级二级数据--质量
	public ResultModel doQueryWeb_Cutting(CommonPage<MesCrCrossCuttingM> oci){
		ResultModel rm=new ResultModel();
		MesCrCrossCuttingM mes=oci.getObject();
		try{
			List<HashMap> list = this.getMapper(MesCrCrossCuttingMMapper.class).doQueryWeb_zhiliang(mes,oci.getStartTime(),oci.getEndTime(),oci.getMemo1(),oci.getMemo2());
			rm.setState("200");
			rm.setData(list);
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	}
	//查询酸洗三级二级数据--质量
	public ResultModel doQueryWeb_Pickle(CommonPage<MesPlmM> oci){
		ResultModel rm=new ResultModel();
		MesPlmM mes=oci.getObject();
		try{
			List<HashMap> list = this.getMapper(MesPlmMMapper.class).doQueryWeb_zhiliang(mes,oci.getStartTime(),oci.getEndTime(),oci.getMemo1(),oci.getMemo2());
			rm.setState("200");
			rm.setData(list);
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	}
	
	
	
	/**
	 * 生产交工前调用检验判定接口
	 * 
	 * @param object_no       实物号
	 * @param prod_order_no   生产订单号
	 * @param prc_code        工序代码
	 * @return
	 * @throws Exception 
	 */
	public ResultModel hasJudegeResult(String object_no , String prod_order_no , String prc_code) throws Exception {
		ResultModel rm =  new ResultModel("200", "");
		String lastChar = object_no.substring(object_no.length()-1);
		// 边丝和头尾卷不存与检验
		if ("B".equals(lastChar) || "H".equals(lastChar)) {
			return rm ; 
		}
		if(Utils.isEmpty(prod_order_no) || Utils.isEmpty(prc_code)) {
			return rm ;
		}
		boolean blnIsJug = false ;
		StringBuilder strRst = new StringBuilder("物料["+object_no+"]还未完成检验,不能交工!");
		// 获取判定结果
		ResultModel tmp_rst = this.getBean(QmsApiServiceImpl.class).doQueryJudegeResult(object_no);
		if(!"200".equals(tmp_rst.getState())) {
			throw new Exception("获取物料["+object_no+"]检验信息失败!"+tmp_rst.getMsgInfo());
		}
		// 获取订单信息
		List<PlnProdorder> ppo = this.getMapper(PlnProdorderMapper.class)
				.findWithCondition(null, " prod_order_no = '"+prod_order_no+"'", "", 0, 1);
		if(Utils.isEmpty(ppo)) {
			return rm ; 
		}
		// 获取制程信息( 403203 公差类 403210 表检类)
		SlmOrdDesignMscPlSti sti = new SlmOrdDesignMscPlSti();
		sti.setDesign_key(ppo.get(0).getDesign_key());
		sti.setMsc_pline(ppo.get(0).getMsc_pline());
		sti.setProcess_code(prc_code);
		sti.setProcess_point_type("403203");
		List<SlmOrdDesignMscPlSti> measure_sti = this.getMapper(SlmOrdDesignMscPlStiMapper.class).findWithCondition(sti, null, "", 0, 0);
		sti.setProcess_point_type("403210");
		List<SlmOrdDesignMscPlSti> surface_sti = this.getMapper(SlmOrdDesignMscPlStiMapper.class).findWithCondition(sti, null, "", 0, 0);
		JudgeResult jr = (JudgeResult) tmp_rst.getData();
		if(Utils.isEmpty(jr)) {
			throw new Exception("未找到物料["+object_no+"]的检验判定信息!");
		} 
		if(Utils.isNotEmpty(surface_sti)) {
//			if(Utils.isEmpty(jr.getUd_surface_result())) {
//				blnIsJug = true ;
//				strRst.append("下表面未检验!");
//			} 
			if(Utils.isEmpty(jr.getUp_surface_result())) {
				blnIsJug = true ;
				strRst.append("表面未检验!");
			} 
			
//			if(Utils.isEmpty(jr.getMarginal_result())) {
//				blnIsJug = true ;
//				strRst.append("边部未检验!");
//			}
		}
		if(Utils.isEmpty(jr.getMeasure_result()) && Utils.isNotEmpty(measure_sti)) {
			blnIsJug = true ;
			strRst.append("公差未检验!");
		} 
		if(blnIsJug) {
			rm.setData(strRst);
			rm.setState("500");
		}
		return rm;
	}

	
}
