/***文档注释***********************************************
 * 作者               :                   易鑫
 * 创建日期      :                   2017.11.27
 * 描述               :        			订单信息
 * 注意事项      :                   无
 * 遗留BUG :                   无
 * 修改日期      :                   
 * 修改人员      :                   
 * 修改内容      :                   
 ***********************************************************/

package market.Mes.OrderManager.Plan.impl;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import market.Api.Mes.impl.MesApiDesignInfoImpl;
import market.Api.Mes.impl.MesApiServiceImpl;
import market.Api.Mes.impl.ProcessPoint;
import market.Api.Mes.impl.Utils;
import market.Api.Qms.impl.QmsApiServiceImpl;
import market.Com.mapper.ComBaseInfoMapper;
import market.Com.mapper.ComDsnPltlmtMapper;
import market.Com.vo.ComBaseInfo;
import market.Com.vo.ComDsnPltlmt;
import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Lms.Warehouse.mapper.YdmProductDetailMapper;
import market.Lms.Warehouse.vo.YdmProductDetail;
import market.Mes.Cuttolength.Design.vo.ClRestrict;
import market.Mes.Lengthwise.Plan.mapper.PlnMaterielDetailMapper;
import market.Mes.Lengthwise.Plan.mapper.PlnProcessPlanMapper;
import market.Mes.Lengthwise.Plan.vo.PlnMaterielDetail;
import market.Mes.Lengthwise.Plan.vo.PlnProcessPlan;
import market.Mes.MaterielTrack.mapper.PrcMaterielExtinfoMapper;
import market.Mes.MaterielTrack.vo.PrcMaterielExtinfo;
import market.Mes.OrderManager.Plan.mapper.PlnOrderStatisticMapper;
import market.Mes.OrderManager.Plan.mapper.PlnProdorderBakMapper;
import market.Mes.OrderManager.Plan.mapper.PlnProdorderExtinfoMapper;
import market.Mes.OrderManager.Plan.mapper.PlnProdorderMapper;
import market.Mes.OrderManager.Plan.mapper.PlnProdorderStatisticMapper;
import market.Mes.OrderManager.Plan.service.PlnProdorderService;
import market.Mes.OrderManager.Plan.vo.PlnOrderStatistic;
import market.Mes.OrderManager.Plan.vo.PlnProdorder;
import market.Mes.OrderManager.Plan.vo.PlnProdorderBak;
import market.Mes.OrderManager.Plan.vo.PlnProdorderExtinfo;
import market.Mes.OrderManager.Plan.vo.PlnProdorderStatistic;
import market.Qms.slmord.mapper.SlmOrdDesignMscMapper;
import market.Qms.slmord.vo.SlmOrdDesignMsc;
import market.Qms.slmord.vo.SlmOrdDesignMscPl;
import market.Slm.BaseInformation.impl.SlmBaseUnitConversionServiceImpl;
import market.Slm.ContractManagement.impl.SlmContractPaymentServiceImpl;
import market.Slm.ContractManagement.mapper.SlmContractHeatInfoMapper;
import market.Slm.ContractManagement.mapper.SlmContractLineInfoMapper;
import market.Slm.ContractManagement.vo.SlmContractHeatInfo;
import market.Slm.ContractManagement.vo.SlmContractLineInfo;
import market.Slm.DeliveryManagement.mapper.SlmLadingBillDetailMapper;
import market.Slm.DeliveryManagement.vo.SlmLadingBillDetail;
import market.Slm.OrderManagement.impl.SlmOrderInfoServiceImpl;
import market.Slm.OrderManagement.mapper.SlmOrderChangeApplyMapper;
import market.Slm.OrderManagement.mapper.SlmOrderInfoMapper;
import market.Slm.OrderManagement.mapper.SlmProcessPlanMapper;
import market.Slm.OrderManagement.vo.SlmOrderChangeApply;
import market.Slm.OrderManagement.vo.SlmOrderInfo;
import market.Slm.OrderManagement.vo.SlmProcessPlan;

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;
import com.ibm.icu.math.BigDecimal;

@RemoteService(path = "PlnProdorderService")
public class PlnProdorderServiceImpl extends BaseServiceImpl<PlnProdorder, Object> implements PlnProdorderService {

	/**
	 * 查询已接收订单信息 * memo1 1则为下发产生时间 为2交货时间 memo3 默认全部 1原料卷 2 需加工 3非计划
	 */
	public ResultModel doQueryOrderReceivedWeb(CommonPage<PlnProdorder> sum) {
		ResultModel rm = new ResultModel();
		try {
			PageModel<PlnProdorder> pm = new PageModel<PlnProdorder>(sum.getPageIndex(), sum.getPageSize());
			// 假如为1则为下发产生时间 为2交货时间 3接收时间
			String sWhere = "";
			if ("1".equals(sum.getMemo1())) {
				sWhere += " and o.issuer_time between to_date('" + sum.getStartTime()
						+ "','yyyy-MM-dd HH24:mi:ss') and to_date('" + sum.getEndTime() + "','yyyy-MM-dd HH24:mi:ss') ";
			} else if ("2".equals(sum.getMemo1())) {
				sWhere += " and t.deliver_date between to_date('" + sum.getStartTime().substring(0, 10)
						+ "','yyyy-MM-dd') and to_date('" + sum.getEndTime().substring(0, 10) + "','yyyy-MM-dd') ";
			}

			if (Utils.isNotEmpty(sum.getMemo3())) {
				sWhere += " and t.order_nature = '" + sum.getMemo3() + "'";
			}
			List<PlnProdorder> list = this.getMapper(PlnProdorderMapper.class).doQueryOrderReceived(sum.getObject(),
					sWhere, (sum.getPageIndex() - 1) * sum.getPageSize(), sum.getPageIndex() * sum.getPageSize());
			long count = this.getMapper(PlnProdorderMapper.class).doQueryOrderReceivedCount(sum.getObject(), sWhere);
			// 获得加工计划备注
//			for (PlnProdorder orders : list) {
//				SlmProcessPlan plan = new SlmProcessPlan();
//				plan.setContract_line_no(orders.getContract_line_no());
//				plan.setContract_line_seq(orders.getContract_line_seq());
//				plan.setOrder_seq(orders.getOrder_seq());
//				plan.setValid_flag("1");
//				List<SlmProcessPlan> planList = this.getMapper(SlmProcessPlanMapper.class).findWithCondition(plan, "",
//						" cut_order_no", 0, 0);
//				if (planList.size() > 0) {
//					// 关联加工计划信息表SLM_PROCESS_PLAN查询加工计划备注
//					orders.setProcessMemo(planList.get(0).getMemo());
//				}
//			}
			pm.setRows(list);
			pm.setTotal(count);
			rm.setState("200");
			rm.setData(pm);
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("查询失败！");
			ex.printStackTrace();
			rm.setErrorInfo(ex.getMessage());
		}
		return rm;
	}

	/**
	 * 查询已接收订单信息 memo1 1则为下发产生时间 为2交货时间 3接收时间 memo2 1已下发 2未下发设计 3全部 memo3
	 * 1分条设计界面查询功能 memo4 默认全部 1原料卷 2 需加工 3非计划
	 */
	public ResultModel doQueryWeb(CommonPage<PlnProdorder> sum) {
		ResultModel rm = new ResultModel();
		try {
			PageModel<PlnProdorder> pm = new PageModel<PlnProdorder>(sum.getPageIndex(), sum.getPageSize());

			String sWhere = " 1=1 ";
			// 假如为1则为下发产生时间 为2交货时间 3接收时间
			if ("1".equals(sum.getMemo1())) {
				sWhere += " and t.send_time between to_date('" + sum.getStartTime()
						+ "','yyyy-MM-dd HH24:mi:ss') and to_date('" + sum.getEndTime() + "','yyyy-MM-dd HH24:mi:ss') ";
			} else if ("2".equals(sum.getMemo1())) {
				sWhere += " and t.deliver_date between to_date('" + sum.getStartTime().substring(0, 10)
						+ "','yyyy-MM-dd') and to_date('" + sum.getEndTime().substring(0, 10) + "','yyyy-MM-dd') ";
			} else if ("3".equals(sum.getMemo1())) {
				sWhere += " and t.create_time between to_date('" + sum.getStartTime()
						+ "','yyyy-MM-dd HH24:mi:ss') and to_date('" + sum.getEndTime() + "','yyyy-MM-dd HH24:mi:ss') ";
			}

			if (sum.getObject() != null) {
				if (sum.getObject().getDiameter_out_max() != null) {
					sWhere += " and t.diameter_out<=" + sum.getObject().getDiameter_out_max();
					sum.getObject().setDiameter_out_max(null);
				}
				if (sum.getObject().getDiameter_out_min() != null) {
					sWhere += " and t.diameter_out>=" + sum.getObject().getDiameter_out_min();
					sum.getObject().setDiameter_out_min(null);
				}
				if (sum.getObject().getContract_no() != null && !"".equals(sum.getObject().getContract_no().trim())) {
					sWhere += " and t.contract_no like '%" + sum.getObject().getContract_no().trim() + "%' ";
					sum.getObject().setContract_no(null);
				}
				if (sum.getObject().getOrder_no() != null && !"".equals(sum.getObject().getOrder_no().trim())) {
					sWhere += " and t.order_no like '%" + sum.getObject().getOrder_no().trim() + "%' ";
					sum.getObject().setOrder_no(null);
				}
				if (sum.getObject().getProd_order_no() != null
						&& !"".equals(sum.getObject().getProd_order_no().trim())) {
					sWhere += " and t.prod_order_no like '%" + sum.getObject().getProd_order_no().trim() + "%' ";
					sum.getObject().setProd_order_no(null);
				}

				if (sum.getObject().getSteel_name() != null && !"".equals(sum.getObject().getSteel_name().trim())) {
					sWhere += " and t.steel_name like '%" + sum.getObject().getSteel_name().trim() + "%' ";
					sum.getObject().setSteel_name(null);
				}
				if (sum.getObject().getStatus() == null || "".equals(sum.getObject().getStatus().trim())) {
					if ("1".equals(sum.getMemo2())) {// 已下发
						sWhere += " and t.status>'0PAA10' ";
					} else if ("2".equals(sum.getMemo2())) {// 未下发设计
						sWhere += " and t.status='0PAA10' ";
					} else if ("3".equals(sum.getMemo2())) {// 全部
						sWhere += " and t.status>='0PAA10' ";
					}
				}else {
					 sWhere += " and t.status = '"+sum.getObject().getStatus()+"'";
				}
				if (Utils.isNotEmpty(sum.getMemo4())) {
					sWhere += " and t.order_nature = '" + sum.getMemo4() + "'";
				}

			}

			if ("1".equals(sum.getMemo3())) {
				sWhere += " and exists(select 1 from pln_prodorder_statistic where lw_undsn>0 or an_undsn>0 or sr_undsn>0 or cl_undsn>0 or pc_undsn>0 or rl_undsn>0) ";
			}

			List<PlnProdorder> plnList = this.getMapper(PlnProdorderMapper.class).doQuery(sum.getObject(), sWhere,
					(sum.getPageIndex() - 1) * sum.getPageSize(), sum.getPageIndex() * sum.getPageSize());
			pm.setRows(plnList);
			pm.setTotal(this.getMapper(PlnProdorderMapper.class).doQueryCount(sum.getObject(), sWhere));
			rm.setState("200");
			rm.setData(pm);
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("查询失败！");
			ex.printStackTrace();
			rm.setErrorInfo(ex.getMessage());
		}
		return rm;
	}

	/**
	 * 订单接收
	 * 
	 * 2019-01-10 增加变更订单接收
	 * 
	 * @throws Exception
	 */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doOrderReceiveWeb(CommonPage<PlnProdorder> sum) throws Exception {
		ResultModel rm = new ResultModel();
		List<PlnProdorder> lp = sum.getObjectList();
		if (lp == null || lp.size() == 0) {
			rm.setState("500");
			rm.setMsgInfo("请传入参数！");
			return rm;
		}

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

		// 查询唯一一条数据
		List<PlnProdorder> ppq = this.getMapper(PlnProdorderMapper.class).findWithCondition(null, "",
				" prod_order_no desc ", 0, 1);
		int maxId = 0;
		if (ppq != null && ppq.size() > 0) {
			maxId = Integer.parseInt(ppq.get(0).getSerial_no());
		}
		String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		// 新建生产订单表
		String No = new SimpleDateFormat("yyMMdd").format(new Date());
		List<PlnProdorder> lpCount = this.getMapper(PlnProdorderMapper.class).findWithCondition(null,
				" substr(prod_order_no,1,6)='" + No + "' ", " to_number(serial_no) desc ", 0, 1);
		int iprodCount = 0;
		if (lpCount == null || lpCount.size() == 0) {
			iprodCount = 0;
		} else {
			iprodCount = Integer.parseInt(lpCount.get(0).getProd_order_no().substring(6, 13));
		}

		int produceNo = 0;
		List<PlnProcessPlan> lpppCount = this.getMapper(PlnProcessPlanMapper.class).findWithCondition(null,
				" substr(produce_no,3,6)='" + No + "' and valid_flag = 1 ", " produce_no desc ", 0, 1);
		if (lpppCount != null && lpppCount.size() > 0) {
			produceNo = Integer.parseInt(lpppCount.get(0).getProduce_no().substring(8, 13));
		}

		int iPOSCount = this.getMapper(PlnOrderStatisticMapper.class).doQueryMaxNo();
		int iPPSCount = this.getMapper(PlnProdorderStatisticMapper.class).doQueryMaxNo();

		for (PlnProdorder p : lp) {
			++produceNo;
			SlmOrderInfo soi = new SlmOrderInfo();
			soi.setOrder_no(p.getOrder_no());
			List<SlmOrderInfo> soiDbb = this.getMapper(SlmOrderInfoMapper.class).findWithCondition(null,
					"order_no like '%" + p.getOrder_no() + "%'", " create_time desc ", 0, 1);
			if (soiDbb == null || soiDbb.size() == 0) {
				throw new Exception("订单[" + p.getOrder_no() + "]信息不存在！请刷新页面再操作!");
			}
			SlmOrderInfo soiDb = soiDbb.get(0);
			// 判断订单是否是拆分订单
			if (soiDb.getIs_split() != null && "1".equals(soiDb.getIs_split())) {
//				String ord_pk = StringUtils.substringBefore(p.getOrder_no(), "-");
				// 获取原生产订单
				List<PlnProdorder> plp = this.getMapper(PlnProdorderMapper.class).findWithCondition(null, " ord_pk = '"+soiDb.getP_order_no()+"'", null, 0, 1);
				if (Utils.isNotEmpty(plp)) {
					// 修改生产订单总量以及未设计量(总量-已设计量)
					plp.get(0).setEstimate_weight(plp.get(0).getEstimate_weight()-this.getBean(SlmBaseUnitConversionServiceImpl.class)
							.doUnitConversion(soiDb.getEstimate_weight(), soiDb.getEstimate_weight_unit_no(), "100305"));
					this.getMapper(PlnProdorderMapper.class).update(plp.get(0));
					List<PlnProdorderStatistic> plps = this.getMapper(PlnProdorderStatisticMapper.class)
							.findWithCondition(null, " prod_order_no = '"+plp.get(0).getProd_order_no()+"'", null, 0, 1) ; 
					plps.get(0).setProd_ordered(plps.get(0).getProd_ordered() - this.getBean(SlmBaseUnitConversionServiceImpl.class)
							.doUnitConversion(soiDb.getEstimate_weight(), soiDb.getEstimate_weight_unit_no(), "100305"));
					if (plp.get(0).getWhole_process_codes().contains(processpoint.slitting_code)) {
						plps.get(0).setLw_undsn(plps.get(0).getProd_ordered()-(plps.get(0).getLw_dsn()==null?0:plps.get(0).getLw_dsn()));
					}
					// 开平
					if (plp.get(0).getWhole_process_codes().contains(processpoint.cross_cutting_code)) {
						plps.get(0).setCl_undsn(plps.get(0).getProd_ordered()-(plps.get(0).getCl_dsn()==null?0:plps.get(0).getCl_dsn()));
					}
					// 罩退
					if (plp.get(0).getWhole_process_codes().contains(processpoint.anneal_code)) {
						plps.get(0).setAn_undsn(plps.get(0).getProd_ordered()-(plps.get(0).getAn_dsn()==null?0:plps.get(0).getAn_dsn()));
					}
					// 平整
					if (plp.get(0).getWhole_process_codes().contains(processpoint.smooth_code)) {
						plps.get(0).setSr_undsn(plps.get(0).getProd_ordered() - (plps.get(0).getSr_dsn()==null?0:plps.get(0).getSr_dsn()));
					}
					// 轧制
					if (plp.get(0).getWhole_process_codes().contains(processpoint.rolling_code)) {
						plps.get(0).setRl_undsn(plps.get(0).getProd_ordered() - (plps.get(0).getRl_dsn()==null?0:plps.get(0).getRl_dsn()));
					}
					// 酸洗
					if (plp.get(0).getWhole_process_codes().contains(processpoint.pickle_code)) {
						plps.get(0).setPc_undsn(plps.get(0).getProd_ordered() - (plps.get(0).getPc_dsn()==null?0:plps.get(0).getPc_dsn()));
					}
					this.getMapper(PlnProdorderStatisticMapper.class).update(plps.get(0));
				}
			}
			// 获取生产订单信息
			PlnProdorder pp = new PlnProdorder();
			pp.setOrder_no(soiDb.getContract_no() + soiDb.getContract_line_seq() + soiDb.getOrder_seq());
			List<PlnProdorder> pp_old = this.getMapper(PlnProdorderMapper.class).find(pp, 0, 0);
			// 接收变更的订单
			// 变更属性的订单有可能是拆分订单,拆分订单的话是没有对应的生产订单的直接生成新生产订单
			// 修改订单对应的物料附加信息的作业路径
			if ("3".equals(soiDb.getChange_flag()) && Utils.isNotEmpty(pp_old)) {
				for (PlnProdorder pln : pp_old) {
					String cTypes = ""; // 更改类型
					String prc_old = pln.getWhole_process_codes();
					PlnProdorderBak ppbak = new PlnProdorderBak();
					BeanUtils.copyProperties(pln, ppbak);
					// 查询唯一一条数据
					List<PlnProdorderBak> ppqbak = this.getMapper(PlnProdorderBakMapper.class).findWithCondition(null,
							"", " to_number(Serial_no) desc ", 0, 1);
					int bakId = 0;
					if (ppqbak != null && ppqbak.size() > 0) {
						bakId = Integer.parseInt(ppqbak.get(0).getSerial_no());
					}
					ppbak.setSerial_no(bakId + 1 + "");
					// 备份生产订单信息
					this.getMapper(PlnProdorderBakMapper.class).insert(ppbak);
					// 将老加工计划置为无效
					List<PlnProcessPlan> ppp_old = this.getMapper(PlnProcessPlanMapper.class).findWithCondition(null,
							"produce_no = '" + pln.getProduce_no() + "' and valid_flag = 1 ", "", 0, 0);
					if (Utils.isNotEmpty(ppp_old)) {
						for (PlnProcessPlan pnn : ppp_old) {
							pnn.setValid_flag("0");
							this.getMapper(PlnProcessPlanMapper.class).update(pnn);
						}
					}

					// 合同行信息
					SlmContractLineInfo scli = new SlmContractLineInfo();
					scli.setContract_line_no(pln.getContract_line_no());
					List<SlmContractLineInfo> lschi = this.getMapper(SlmContractLineInfoMapper.class).find(scli, 0, 0);

					// 获取新的加工计划信息
					SlmProcessPlan spp = new SlmProcessPlan();
					spp.setContract_no(soiDb.getContract_no());
					spp.setContract_line_seq(soiDb.getContract_line_seq());
					spp.setOrder_seq(soiDb.getOrder_seq());
					spp.setValid_flag("1");
					List<SlmProcessPlan> lspp = new ArrayList<>();
					lspp = this.getMapper(SlmProcessPlanMapper.class).findWithCondition(spp, null, " cut_order_no ", 0,
							0);
					if (lspp == null || lspp.size() == 0) {
						throw new Exception("订单[" + soiDb.getOrder_no() + "]对应的加工计划信息未找到！");
					}

					List<SlmOrdDesignMscPl> msc_pline = new ArrayList<SlmOrdDesignMscPl>();

					// 选择design_key 以及制程产线确认,只有需加工订单才确认制程产线
					// 修改生产订单附加信息
					PlnProdorderExtinfo ppextinfo = new PlnProdorderExtinfo();
					ppextinfo.setProd_order_no(pln.getProd_order_no());
					ppextinfo.setOrder_no(pln.getOrder_no());

					// 如果只有一条加工计划并且是不切直接取一条工艺路径
					if (lspp.size() == 1 && lspp.get(0).getCut_type().equals("0")) {
						// 1、获取design_key
						SlmOrdDesignMsc som = new SlmOrdDesignMsc();
						som.setContract_line_no(lspp.get(0).getPlan_no()); // 通过加工计划号找design_key
						CommonPage<SlmOrdDesignMsc> sodm = new CommonPage<SlmOrdDesignMsc>();
						sodm.setObject(som);
						ResultModel result_DK = this.getBean(QmsApiServiceImpl.class).GetAllByDesignKey(sodm);
						if (!"200".equals(result_DK.getState())) {
							throw new Exception("自动确认制程产线失败!" + result_DK.getMsgInfo());
						}
						// 2、获取工艺路径：这个design_key没有也行：20230914刘侣
						List<SlmOrdDesignMsc> design_key = (List<SlmOrdDesignMsc>) result_DK.getData();
						ResultModel result_ZC = this.getBean(MesApiDesignInfoImpl.class)
								.GetMscByDesignKey(design_key.get(0).getDesign_key());
						if (!"200".equals(result_ZC.getState())) {
							throw new Exception("自动确认工艺路径失败!" + result_ZC.getMsgInfo());
						}
						msc_pline = (List<SlmOrdDesignMscPl>) result_ZC.getData();
						if (design_key.size() > 1 || msc_pline.size() > 1) {
							ppextinfo.setHas_multi_procedure(1l);
						} else {
							ppextinfo.setHas_multi_procedure(0l);
						} 
						// 这些如果没有可以从订单那里获取到工艺路径：20230914刘侣
						pln.setDesign_key(design_key.get(0).getDesign_key());
						pln.setMsc_pline(msc_pline.get(0).getMsc_pline());
						pln.setWhole_process_codes(msc_pline.get(0).getStations_code());
						pln.setWhole_process_names(msc_pline.get(0).getStations_desc());
						pln.setWhole_process_seqs(msc_pline.get(0).getWarn_desc());		
						// 修改生产订单附加信息
						this.getMapper(PlnProdorderExtinfoMapper.class).update(ppextinfo);
					} else {
						// 2018-09-04 自动选择design_key 制程
						// plan : <design_key : 制程对象集合>
						List<Map<String, Map<String, List<SlmOrdDesignMscPl>>>> params = new ArrayList<>();
						SlmOrdDesignMscPl rst_path = new SlmOrdDesignMscPl();
						String rst_design_key = "";
						int i = 0;
						boolean flag_cross_cutting = false, flag_slitting = false;
						// 获取公共工艺路径
						for (SlmProcessPlan slm : lspp) {
							if (slm.getCut_type().equals("1")) {
								flag_cross_cutting = true;
							} else if (slm.getCut_type().equals("2")) {
								flag_slitting = true;
							} else if (slm.getCut_type().equals("3")) {
								flag_cross_cutting = true;
								flag_slitting = true;
							}
							Map<String, List<SlmOrdDesignMscPl>> map = new HashMap<String, List<SlmOrdDesignMscPl>>();
							Map<String, Map<String, List<SlmOrdDesignMscPl>>> plan_no = new HashMap<String, Map<String, List<SlmOrdDesignMscPl>>>();
							// 1、获取design_key
							SlmOrdDesignMsc som = new SlmOrdDesignMsc();
							som.setContract_line_no(slm.getPlan_no()); // 通过加工计划号找design_key
							CommonPage<SlmOrdDesignMsc> sodm = new CommonPage<SlmOrdDesignMsc>();
							sodm.setObject(som);
							ResultModel result_DK = this.getBean(QmsApiServiceImpl.class).GetAllByDesignKey(sodm);
							if (!"200".equals(result_DK.getState())) {
								throw new Exception("自动确认制程产线失败!" + result_DK.getMsgInfo());
							}
							// 2、获取工艺路径
							List<SlmOrdDesignMsc> design_key = (List<SlmOrdDesignMsc>) result_DK.getData();
							for (SlmOrdDesignMsc design : design_key) {
								ResultModel result_ZC = this.getBean(MesApiDesignInfoImpl.class)
										.GetMscByDesignKey(design.getDesign_key());
								if (!"200".equals(result_ZC.getState())) {
									throw new Exception("自动确认工艺路径失败!" + result_ZC.getMsgInfo());
								}
								msc_pline = (List<SlmOrdDesignMscPl>) result_ZC.getData();
								map.put(design.getDesign_key(), msc_pline);
							}
							plan_no.put(slm.getPlan_no(), map);
							params.add(plan_no);
						}
						// design : 制程对象集合
						Map<String, List<SlmOrdDesignMscPl>> result = getCommonPath(params);
						if (Utils.isNotEmpty(result)) {
							if (result.size() > 1) {
								ppextinfo.setHas_multi_procedure(1l);
							} else {
								ppextinfo.setHas_multi_procedure(0l);
							}
							for (Entry<String, List<SlmOrdDesignMscPl>> map : result.entrySet()) {
								// 取第一个赋值
								if (i == 0) {
									rst_design_key = map.getKey();
									rst_path = map.getValue().get(0);
								}
								break;
							}
							if (Utils.isNotEmpty(rst_path.getStations_code())) {
								// 开平找不到加工计划报错
								if (rst_path.getStations_code().contains(processpoint.cross_cutting_code)
										&& !flag_cross_cutting) {
									throw new Exception("工艺路径中包含开平工序,但是不存在开平加工计划!请重新质量设计!");
								} else if (rst_path.getStations_code().contains(processpoint.slitting_code)
										&& !flag_slitting) {
									throw new Exception("工艺路径中包含分条工序,但是不存在分条加工计划!请重新质量设计!");
								}
							}
							pln.setDesign_key(rst_design_key);
							pln.setMsc_pline(rst_path.getMsc_pline());
							pln.setWhole_process_codes(rst_path.getStations_code());
							pln.setWhole_process_names(rst_path.getStations_desc());
							pln.setWhole_process_seqs(rst_path.getWarn_desc());
							// 修改生产订单附加信息
							this.getMapper(PlnProdorderExtinfoMapper.class).update(ppextinfo);
						}
					}

					// 修改物料附加信息
					PrcMaterielExtinfo pme = new PrcMaterielExtinfo();
					pme.setOrder_no(pln.getOrder_no());
					pme.setTask_process_codes(pln.getWhole_process_codes());
					pme.setTask_process_names(pln.getWhole_process_names());
					this.getMapper(PrcMaterielExtinfoMapper.class).updateByOrder(pme);
					
					
					// 如果有轧制工序 ,判断厚度范围是否符合,第一道次的入口厚度小于订单厚度报错,最后道次出口厚度不包含订单厚度报错
//					if (pln.getWhole_process_codes().contains(processpoint.rolling_code)) {
//						SlmOrdDesignMscPlSti sti = new SlmOrdDesignMscPlSti();
//						List<SlmOrdDesignMscTic> tics = new ArrayList<SlmOrdDesignMscTic>();
//						sti.setDesign_key(pln.getDesign_key());
//						sti.setMsc_pline(pln.getMsc_pline());
//						sti.setProcess_code(processpoint.rolling_code);
//						// 只查询工艺类工序点
//						sti.setProcess_point_type("403206");
//						List<SlmOrdDesignMscPlSti> stis = this.getBean(MesApiDesignInfoImpl.class).getQcmDesignInfo(sti);
//						for (SlmOrdDesignMscPlSti pl : stis) {
//							SlmOrdDesignMscTic tmp = new SlmOrdDesignMscTic();
//							BeanUtils.copyProperties(pl, tmp);
//							tmp.setPline_code("C016");
//							tmp.setMachine_code("M0008");
//							tics.add(tmp);
//						}
//						this.getBean(MesApiDesignInfoImpl.class).checkFirstProc(tics, pln.getThick());
//						this.getBean(MesApiDesignInfoImpl.class).checkLastProc(tics, pln.getThick());
//						this.getBean(MesApiDesignInfoImpl.class).comp_Proc_Std(tics);
//					}
					
					pln.setProduce_no("PN" + No + String.format("%05d", produceNo)); // 修改加工计划号

					// 新建加工计划表[PLN_PROCESS_PLAN]记录：（一个订单对应多条记录，要全部从销售加工计划表复制过来）
					String sCutStyle = "";
					double width_total = 0;
					List<PlnProcessPlan> lppp = new ArrayList<PlnProcessPlan>();
					long cutOrdNo = 1;
					for (SlmProcessPlan sppc : lspp) {
						PlnProcessPlan ppp = new PlnProcessPlan();
						ppp.setProduce_no(pln.getProduce_no());
						ppp.setPlan_no(sppc.getPlan_no());
						ppp.setCut_order_no(cutOrdNo++);
						ppp.setOrder_no(pln.getOrder_no());
						ppp.setPurchase_contract_no(sppc.getPurchase_contract_no());
						ppp.setSteel_code(sppc.getSteel_code());
						ppp.setSteel_name(sppc.getSteel_name());
						ppp.setSpec(sppc.getSpec());
						ppp.setWidth(this.getBean(SlmBaseUnitConversionServiceImpl.class)
								.doUnitConversion(sppc.getWidth(), lschi.get(0).getWidth_unit_no(), "100304 "));
						ppp.setThick(this.getBean(SlmBaseUnitConversionServiceImpl.class)
								.doUnitConversion(sppc.getThick(), lschi.get(0).getThick_unit_no(), "100304 "));
						ppp.setLength(this.getBean(SlmBaseUnitConversionServiceImpl.class)
								.doUnitConversion(sppc.getLen(), lschi.get(0).getLengt_no(), "100304 "));
						ppp.setEstimate_weight(this.getBean(SlmBaseUnitConversionServiceImpl.class).doUnitConversion(
								sppc.getEstimate_weight(), sppc.getEstimate_weight_unit_no(), "100305"));
						if (lschi.get(0).getWidth() <= 0)
							throw new Exception(
									"订单[" + soiDb.getOrder_no() + "]对应的加工计划[" + sppc.getPlan_no() + "]的宽度错误！");
						if (lschi.get(0).getThick() <= 0)
							throw new Exception(
									"订单[" + soiDb.getOrder_no() + "]对应的加工计划[" + sppc.getPlan_no() + "]的厚度错误！");

						ppp.setMat_width(this.getBean(SlmBaseUnitConversionServiceImpl.class)
								.doUnitConversion(lschi.get(0).getWidth(), lschi.get(0).getWidth_unit_no(), "100304 "));
						ppp.setMat_thick(this.getBean(SlmBaseUnitConversionServiceImpl.class)
								.doUnitConversion(lschi.get(0).getThick(), lschi.get(0).getThick_unit_no(), "100304 "));
						ppp.setCrosscut_style(sppc.getCrosscut_stype());

						ppp.setCut_type(sppc.getCut_type());
						ppp.setCut_num(sppc.getCut_num());
						ppp.setRemark(sppc.getMemo());
						ppp.setValid_flag(sppc.getValid_flag());
						ppp.setCreate_man_name(userName);
						ppp.setCreate_time(new Date());

						ppp.setWall_thick(this.getBean(SlmBaseUnitConversionServiceImpl.class)
								.doUnitConversion(sppc.getWall_thick(), lschi.get(0).getThick_unit_no(), "100304 "));
						ppp.setMono_stack_max_weight(
								this.getBean(SlmBaseUnitConversionServiceImpl.class).doUnitConversion(
										sppc.getMono_stack_max_weight(), sppc.getEstimate_weight_unit_no(), "100305"));
						ppp.setMono_stack_min_weight(
								this.getBean(SlmBaseUnitConversionServiceImpl.class).doUnitConversion(
										sppc.getMono_stack_min_weight(), sppc.getEstimate_weight_unit_no(), "100305"));
						lppp.add(ppp);

						if (sppc.getCut_type() != null && "1".equals(sppc.getCut_type())) { // 横剪
							double weightupper = 0;
//							 读取基础配置 产线机组限制表
							ComDsnPltlmt cdp = new ComDsnPltlmt();
							cdp.setPlt("Y1");// 工厂
							cdp.setPlt_line("Y1");// 产线
							List<ComDsnPltlmt> lc = this.getMapper(ComDsnPltlmtMapper.class).find(cdp, 0, 0);
							if (lc == null || lc.size() == 0) {
								throw new Exception("未找到产线");
							}
//							 获取所有的限制条件
							ClRestrict MachineRestrict = new ClRestrict(lc);
							if (ppp.getMono_stack_max_weight() == null) {
								weightupper = MachineRestrict.lim_max_box_wgt;
							} else if (ppp.getMono_stack_max_weight() != null) {
								weightupper = ppp.getMono_stack_max_weight();
								if (ppp.getMono_stack_max_weight().doubleValue()
										- MachineRestrict.lim_max_box_wgt > 0) {
									throw new Exception("订单[" + soiDb.getOrder_no() + "]的加工计划中单剁重量上限(单位是吨)超出设备重量限制!");
								}
							}
							if (ppp.getLength() != null) {
								sCutStyle += ppp.getLength().doubleValue() + "*"
										+ new BigDecimal(p.getEstimate_weight() / 1000)
												.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue()
										+ "T(" + new BigDecimal(weightupper / 1000)
												.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue()
										+ "T)+";
							}
						} else if (sppc.getCut_type() != null && "2".equals(sppc.getCut_type())) {// 纵剪
							sCutStyle += ppp.getWidth().doubleValue() + "*" + ppp.getCut_num().intValue() + "+";
							width_total += ppp.getWidth().doubleValue() * ppp.getCut_num().intValue();
						}
					}
					// 有不切的情况
					if (sCutStyle != null && !"".equals(sCutStyle)) {
						sCutStyle = sCutStyle.substring(0, sCutStyle.length() - 1);
					}
					for (PlnProcessPlan ppp : lppp) {
						if (lppp.size() >= 1) {
							ppp.setCut_style(sCutStyle);
							if (ppp.getCut_type() != null && "2".equals(ppp.getCut_type())) {
								ppp.setWidth_total(width_total);
							}
							// 新老加工计划如果不一样就记录变更类型20
							if (Utils.isEmpty(ppp) || !ppp_old.get(0).getCut_type().equals(ppp.getCut_type())
									|| (Utils.isNotEmpty(ppp_old.get(0).getCut_style()) && Utils.isNotEmpty(ppp.getCut_style()) && !ppp_old.get(0).getCut_style().equals(ppp.getCut_style()))
									) {
								cTypes = "20,";
							}
						}
						this.getMapper(PlnProcessPlanMapper.class).insert(ppp);
					}
					// 比较新老工艺路径 判断工艺路径
					if (!prc_old.equals(pln.getWhole_process_codes())) {
						// 获取有效的工艺路径
						String[] arr_old = prc_old.split("-");
						String[] arr_new = pln.getWhole_process_codes().split("-");
						List<String> validpath_old = this.getBean(MesApiDesignInfoImpl.class).getProcessPath(arr_old);
						List<String> validpath_new = this.getBean(MesApiDesignInfoImpl.class).getProcessPath(arr_new);
						if (!validpath_old.equals(validpath_new)) {
							for (String str_old : validpath_old) {
								boolean flag_c = false;
								for (String str_new : validpath_new) {
									if (str_new.equals(str_old)) {
										flag_c = true;
										break;
									}
								}
								if (!flag_c) {
									cTypes += "0" + str_old.substring(0, 1) + ",";
								}
							}
							for (String str_new : validpath_new) {
								boolean flag_j = false;
								for (String str_old : validpath_old) {
									if (str_new.equals(str_old)) {
										flag_j = true;
										break;
									}
								}
								if (!flag_j) {
									cTypes += "1" + str_new.substring(0, 1) + ",";
								}
							}
						}
					}

					if (Utils.isNotEmpty(cTypes)) {
						cTypes = cTypes.substring(0, cTypes.length() - 1);
						// 判断能否变更
						boolean flag = this.getBean(MesApiDesignInfoImpl.class).canOrderChange(pln.getOrder_no(),
								cTypes);
						if (!flag) {
							throw new Exception("该订单[" + pln.getOrder_no() + "]不能变更,请退回重新操作!");
						}
					}
					// 注意修改生产订单一定要在验证是否能变更之后
					// 修改老生产订单信息
					pln.setContract_line_no(soiDb.getContract_line_no());
					pln.setContract_line_seq(soiDb.getContract_line_seq());
					pln.setOrder_memo(soiDb.getMemo()); // 订单备注
					pln.setFinished_status("0"); // 生产未完成
					pln.setChange_flag(soiDb.getChange_flag()); // 变更标志
					pln.setOrd_pk(soiDb.getOrder_no()); // 销售订单主键
					pln.setP_order_no(soiDb.getP_order_no());
					pln.setIs_split(soiDb.getIs_split());// 是否拆分
					pln.setCustomer_no(soiDb.getCustomer_no());
					pln.setCustomer_name(soiDb.getCustomer_name()); 
					pln.setReciver_unit_no(soiDb.getReciver_unit_no());
					pln.setReciver_unit_name(soiDb.getReciver_unit_name());
					pln.setReciver_address(soiDb.getReciver_address());
					pln.setPk_ask_code(scli.getPk_ask_code());
					pln.setPk_ask_desc(scli.getPk_ask_desc());
					this.getMapper(PlnProdorderMapper.class).update(pln);

					// 修改生产订单进程表
					List<PlnProdorderStatistic> pps = this.getMapper(PlnProdorderStatisticMapper.class)
							.findWithCondition(null, "prod_order_no = '" + pln.getProd_order_no() + "'", "", 0, 1);

					// 修改订单进程表
					List<PlnOrderStatistic> pos = this.getMapper(PlnOrderStatisticMapper.class).findWithCondition(null,
							"order_no = '" + pln.getOrder_no() + "'", "", 0, 1);
					double nums = pps.get(0).getProd_ordered();

					// 获取订单对应的虚拟母卷信息
					List<PlnMaterielDetail> pmd = this.getMapper(PlnMaterielDetailMapper.class).findWithCondition(null,
							"prod_order_no = '" + pln.getProd_order_no()
									+ "' and nvl(invalid_flg,0) != 1 and mat_object_no_vt is null",
							"", 0, 0);
					if (Utils.isNotEmpty(pmd)) {
						// 获取母卷下一个工序对应的未设计量
						if (processpoint.slitting_code.equals(pmd.get(0).getNext_process_code())) {
							nums = pps.get(0).getLw_undsn() == 0 ? pps.get(0).getLw_dsn() : pps.get(0).getLw_undsn();
						} else if (processpoint.cross_cutting_code.equals(pmd.get(0).getNext_process_code())) {
							nums = pps.get(0).getCl_undsn() == 0 ? pps.get(0).getCl_dsn() : pps.get(0).getCl_undsn();
						} else if (processpoint.smooth_code.equals(pmd.get(0).getNext_process_code())) {
							nums = pps.get(0).getSr_undsn() == 0 ? pps.get(0).getSr_dsn() : pps.get(0).getSr_undsn();
						} else if (processpoint.anneal_code.equals(pmd.get(0).getNext_process_code())) {
							nums = pps.get(0).getAn_undsn() == 0 ? pps.get(0).getAn_dsn() : pps.get(0).getAn_undsn();
						} else if (processpoint.rolling_code.equals(pmd.get(0).getNext_process_code())) {
							nums = pps.get(0).getRl_undsn() == 0 ? pps.get(0).getRl_dsn() : pps.get(0).getRl_undsn();
						} else if (processpoint.pickle_code.equals(pmd.get(0).getNext_process_code())) {
							nums = pps.get(0).getPc_undsn() == 0 ? (pps.get(0).getRl_dsn()==null?0d:pps.get(0).getRl_dsn()) : pps.get(0).getPc_undsn();
							//nums = pps.get(0).getPc_undsn() == 0 ? pps.get(0).getRl_dsn() : pps.get(0).getPc_undsn();
						}
						// 订单变更
						this.getBean(MesApiDesignInfoImpl.class).ChangeProcess(pmd, pln.getWhole_process_codes(), -1);
					}

					String[] c_arr = cTypes.split(",");
					for (int i = 0; i < c_arr.length; i++) {
						switch (c_arr[i]) {
						case "0B":
							pps.get(0).setAn_undsn(0d);
							pps.get(0).setAn_dsn(0d);
							pos.get(0).setAn_undsn(0d);
							pos.get(0).setAn_dsn(0d);
							break;
						case "0E":
							pps.get(0).setLw_undsn(0d);
							pps.get(0).setLw_dsn(0d);
							pos.get(0).setLw_undsn(0d);
							pos.get(0).setLw_dsn(0d);
							break;
						case "0D":
							pps.get(0).setCl_undsn(0d);
							pps.get(0).setCl_dsn(0d);
							pos.get(0).setCl_undsn(0d);
							pos.get(0).setCl_dsn(0d);
							break;
						case "0C":
							pps.get(0).setSr_undsn(0d);
							pps.get(0).setSr_dsn(0d);
							pos.get(0).setSr_undsn(0d);
							pos.get(0).setSr_dsn(0d);
						case "0A":
							pps.get(0).setRl_undsn(0d);
							pps.get(0).setRl_dsn(0d);
							pos.get(0).setRl_undsn(0d);
							pos.get(0).setRl_dsn(0d);
						case "0P":
							pps.get(0).setPc_undsn(0d);
							pps.get(0).setPc_dsn(0d);
							pos.get(0).setPc_undsn(0d);
							pos.get(0).setPc_dsn(0d);
							break;
						case "1B":
							pps.get(0).setAn_undsn(nums);
							pos.get(0).setAn_undsn(nums);
							break;
						case "1E":
							pps.get(0).setLw_undsn(nums);
							pos.get(0).setLw_undsn(nums);
							break;
						case "1D":
							pps.get(0).setCl_undsn(nums);
							pos.get(0).setCl_undsn(nums);
							break;
						case "1C":
							pps.get(0).setSr_undsn(nums);
							pos.get(0).setSr_undsn(nums);
							break;
						case "1A":
							pps.get(0).setRl_undsn(nums);
							pos.get(0).setRl_undsn(nums);
							break;
						case "1P":
							pps.get(0).setPc_undsn(nums);
							pos.get(0).setPc_undsn(nums);
							break;
						default:
							break;
						}
					}

					this.getMapper(PlnProdorderStatisticMapper.class).update(pps.get(0));
					this.getMapper(PlnOrderStatisticMapper.class).update(pos.get(0));

					// 获取订单变更申报表
					List<SlmOrderChangeApply> sca = this.getMapper(SlmOrderChangeApplyMapper.class).findWithCondition(
							null, " order_no = '" + pln.getOrder_no() + "'", " create_time desc ", 0, 1);
					// 修改状态已下发
					if (Utils.isNotEmpty(sca)) {
						sca.get(0).setStatus("6");
						this.getMapper(SlmOrderChangeApplyMapper.class).update(sca.get(0));
					}

					// 修改订单状态为接收
					SlmOrderInfo soiu = new SlmOrderInfo();
					soiu.setOrder_no(soiDb.getOrder_no());
					soiu.setOrder_flag_no("103407");
					soiu.setOrder_flag_name("接收");
					this.getMapper(SlmOrderInfoMapper.class).update(soiu);
					rm.setState("200");
				}
			} else {
				if (!"103406".equals(soiDb.getOrder_flag_no())) {
					throw new Exception("当前订单[" + soiDb.getContract_no() + soiDb.getContract_line_seq()
							+ soiDb.getOrder_seq() + "]状态已发生改变，无法下发！请刷新页面再操作!");
				}

//				PlnProdorder pp = new PlnProdorder();
//				pp.setOrder_no(soiDb.getContract_no() + soiDb.getContract_line_seq() + soiDb.getOrder_seq());
				int icount = this.getMapper(PlnProdorderMapper.class).count(pp);
				if (icount > 0) {
					throw new Exception("订单[" + soiDb.getContract_no() + soiDb.getContract_line_seq()
							+ soiDb.getOrder_seq() + "]已接收！请刷新页面再操作!");
				}


				p.setSerial_no(++maxId + "");// 自增id
				p.setProd_order_no(No + String.format("%07d", ++iprodCount));
				p.setStatus("0PAA10");
				p.setFinished_status("0"); // 生产未完成
				// p.setMsc_pline("*******调用质量接口获取");
				p.setCreate_man_name(userName);
				p.setCreate_time(new Date());
				// 下面的实际上前端可以传过来
				p.setIs_split(soiDb.getIs_split());
				p.setOrd_pk(soiDb.getOrder_no()); // 销售订单主键
				p.setP_order_no(soiDb.getP_order_no());
				p.setContract_no(soiDb.getContract_no());
				p.setContract_line_no(soiDb.getContract_line_no());
				p.setContract_line_seq(soiDb.getContract_line_seq());
				p.setOrder_no(soiDb.getContract_no() + soiDb.getContract_line_seq() + soiDb.getOrder_seq());
				p.setOrder_seq(soiDb.getOrder_seq());
				p.setOrder_quantity(soiDb.getOrder_quantity());
				p.setQuantity_unit_name(soiDb.getQuantity_unit_name());
				p.setQuantity_unit_no(soiDb.getQuantity_unit_no());
				// 增加整卷发运标志 2018-11-13
				p.setWhole_coil(soiDb.getWhole_coil());
				p.setProcess(soiDb.getProcess());
				p.setChange_flag(soiDb.getChange_flag());
				// 重量数据转换
				p.setEstimate_weight(this.getBean(SlmBaseUnitConversionServiceImpl.class)
						.doUnitConversion(soiDb.getEstimate_weight(), soiDb.getEstimate_weight_unit_no(), "100305"));
				p.setEstimate_weight_unit_name("kg");
				p.setEstimate_weight_unit_no("100305");
				/*
				 * p.setEstimate_weight(soiDb.getEstimate_weight());
				 * p.setEstimate_weight_unit_name(soiDb.getEstimate_weight_unit_name());
				 * p.setEstimate_weight_unit_no(soiDb.getEstimate_weight_unit_no());
				 */

				p.setEnsu_total_len(soiDb.getEnsu_total_len());
				p.setReciver_address(soiDb.getReciver_address());
				p.setReciver_unit_name(soiDb.getReciver_unit_name());
				p.setReciver_unit_no(soiDb.getReciver_unit_no());
				p.setDeliver_date(soiDb.getDeliver_date());
				p.setSend_time(soiDb.getIssuer_time());
				p.setSend_man_name(soiDb.getIssuer_man_name());

				// 有且仅有一条，合同头信息
				SlmContractHeatInfo schi = new SlmContractHeatInfo();
				schi.setContract_no(soiDb.getContract_no());
				List<SlmContractHeatInfo> lschis = this.getMapper(SlmContractHeatInfoMapper.class).find(schi, 0, 0);
				p.setTxt_contract_no(lschis.get(0).getTxt_contract_no());
				p.setContract_type_no(lschis.get(0).getContract_type_no());
				p.setContract_type_name(lschis.get(0).getContract_type_name());
				p.setCustomer_no(lschis.get(0).getCustomer_no());
				p.setCustomer_name(lschis.get(0).getCustomer_name());

				// 合同行信息
				SlmContractLineInfo scli = new SlmContractLineInfo();
				scli.setContract_line_no(p.getContract_line_no());
				List<SlmContractLineInfo> lschi = this.getMapper(SlmContractLineInfoMapper.class).find(scli, 0, 0);

				p.setPk_ask_code(lschi.get(0).getPk_ask_code());
				p.setPk_ask_desc(lschi.get(0).getPk_ask_desc());
				
				// 订单估算重量 合同行最大重量/合同重量*订单重量=最大值 合同行最大重量/合同重量*订单重量=最小值
				DecimalFormat df = new DecimalFormat("#.00");
				// 得到两个值的比例
				double max = Double.parseDouble(df.format(lschi.get(0).getDelivery_error_max().doubleValue()
						/ lschi.get(0).getEstimate_weight().doubleValue()));
				double min = Double.parseDouble(df.format(lschi.get(0).getDelivery_error_min().doubleValue()
						/ lschi.get(0).getEstimate_weight().doubleValue()));

				p.setPsc(lschi.get(0).getPsc());
				p.setPsc_desc(lschi.get(0).getPsc_desc());
				// SLM_ORDER_INFO没有则找SLM_CONTRACT_LINE_INFO
				p.setMsc(soiDb.getMsc() == null ? lschi.get(0).getMsc() : soiDb.getMsc());
				p.setMsc_desc(soiDb.getMsc_desc() == null ? lschi.get(0).getMsc_desc() : soiDb.getMsc_desc());
				p.setMsc_type_no(
						soiDb.getMsc_type_no() == null ? lschi.get(0).getMsc_type_no() : soiDb.getMsc_type_no());
				p.setMsc_type_name(
						soiDb.getMsc_type_name() == null ? lschi.get(0).getMsc_type_name() : soiDb.getMsc_type_name());

				p.setUse_code(soiDb.getUse_code() == null ? lschi.get(0).getUse_code() : soiDb.getUse_code());
				p.setUse_desc(soiDb.getUse_desc() == null ? lschi.get(0).getUse_desc() : soiDb.getUse_desc());
				p.setProd_cls_no(
						soiDb.getProd_cls_no() == null ? lschi.get(0).getProd_cls_no() : soiDb.getProd_cls_no());
				p.setProd_cls_name(
						soiDb.getProd_cls_name() == null ? lschi.get(0).getProd_cls_name() : soiDb.getProd_cls_name());
				p.setProd_code(soiDb.getProd_code() == null ? lschi.get(0).getProd_code() : soiDb.getProd_code());
				p.setProd_name(soiDb.getProd_name() == null ? lschi.get(0).getProd_name() : soiDb.getProd_name());
				p.setStd_code(soiDb.getStd_code() == null ? lschi.get(0).getStd_code() : soiDb.getStd_code());
				p.setStd_name(soiDb.getStd_name() == null ? lschi.get(0).getStd_name() : soiDb.getStd_name());
				p.setSteel_code(soiDb.getSteel_code() == null ? lschi.get(0).getSteel_code() : soiDb.getSteel_code());
				p.setSteel_name(soiDb.getSteel_name() == null ? lschi.get(0).getSteel_name() : soiDb.getSteel_name());
				p.setStd_type_no(
						soiDb.getStd_type_no() == null ? lschi.get(0).getStd_type_no() : soiDb.getStd_type_no());
				p.setStd_type_name(
						soiDb.getStd_type_name() == null ? lschi.get(0).getStd_type_name() : soiDb.getStd_type_name());
				p.setProd_figure_no(soiDb.getProd_figure_no() == null ? lschi.get(0).getProd_figure_no()
						: soiDb.getProd_figure_no());
				p.setProd_figure_name(soiDb.getProd_figure_name() == null ? lschi.get(0).getProd_figure_name()
						: soiDb.getProd_figure_name());
				p.setOrder_nature(soiDb.getOrder_nature());

				p.setDelivery_weight_type(lschi.get(0).getDelivery_weight_type());
				p.setDelivery_error_max(p.getEstimate_weight().doubleValue() * max);
				p.setDelivery_error_min(p.getEstimate_weight().doubleValue() * min);
				p.setDelivery_unit_no("100305");
				p.setDelivery_unit_name("kg");
				p.setWeight_type_no(lschi.get(0).getWeight_type_no());
				p.setWeight_type_name(lschi.get(0).getWeight_type_name());
				// p.setSingle_weight( lschi.get(0).getSingle_weight());
				p.setSingle_weight(this.getBean(SlmBaseUnitConversionServiceImpl.class).doUnitConversion(
						lschi.get(0).getSingle_weight(), lschi.get(0).getSingle_weight_unit_no(), "100305"));
				p.setSingle_weight_max(this.getBean(SlmBaseUnitConversionServiceImpl.class).doUnitConversion(
						lschi.get(0).getSingle_weight_max(), lschi.get(0).getSingle_weight_unit_no(), "100305"));
				p.setSingle_weight_min(this.getBean(SlmBaseUnitConversionServiceImpl.class).doUnitConversion(
						lschi.get(0).getSingle_weight_min(), lschi.get(0).getSingle_weight_unit_no(), "100305"));
				p.setSingle_weight_unit_no("100305");
				p.setSingle_weight_unit_name("kg");

				p.setSingle_length(lschi.get(0).getSingle_length());
				p.setSingle_length_max(lschi.get(0).getSingle_length_max());
				p.setSingle_length_min(lschi.get(0).getSingle_length_min());
				p.setCnt_number(lschi.get(0).getCnt_number());
				p.setFixed_length_type_no(lschi.get(0).getFixed_length_type_no());
				p.setFixed_length_type_name(lschi.get(0).getFixed_length_type_name());

				p.setCut_edge_type_no(lschi.get(0).getCut_edge_type_no());
				p.setCut_edge_type_name(lschi.get(0).getCut_edge_type_name());

				p.setDiameter_inn(lschi.get(0).getDiameter_inn());
				p.setDiameter_inn_max(lschi.get(0).getDiameter_inn_max());
				p.setDiameter_inn_min(lschi.get(0).getDiameter_inn_min());
				p.setDiameter_inn_unit_no(lschi.get(0).getDiameter_inn_unit_no());
				p.setDiameter_inn_unit_name(lschi.get(0).getDiameter_inn_unit_name());

				p.setSpec_other(lschi.get(0).getSpec_other());

				p.setDiameter_out(lschi.get(0).getDiameter_out());
				p.setDiameter_out_max(lschi.get(0).getDiameter_out_max());
				p.setDiameter_out_min(lschi.get(0).getDiameter_out_min());
				p.setDiameter_out_unit_no(lschi.get(0).getDiameter_out_unit_no());
				p.setDiameter_out_unit_name(lschi.get(0).getDiameter_out_unit_name());

				p.setThick(this.getBean(SlmBaseUnitConversionServiceImpl.class)
						.doUnitConversion(lschi.get(0).getThick(), lschi.get(0).getThick_unit_no(), "100304 "));
				p.setThick_max(this.getBean(SlmBaseUnitConversionServiceImpl.class)
						.doUnitConversion(lschi.get(0).getThick_max(), lschi.get(0).getThick_unit_no(), "100304 "));
				p.setThick_min(this.getBean(SlmBaseUnitConversionServiceImpl.class)
						.doUnitConversion(lschi.get(0).getThick_min(), lschi.get(0).getThick_unit_no(), "100304 "));
				p.setThick_unit_no("100304");
				p.setThick_unit_name("mm");

				p.setDiam(lschi.get(0).getDiameter_inn());
				p.setDiam_up(lschi.get(0).getDiameter_inn_max());
				p.setDiam_down(lschi.get(0).getDiameter_inn_min());
				p.setDiam_unit_no(lschi.get(0).getDiameter_inn_unit_no());
				p.setDiam_unit_name(lschi.get(0).getDiameter_inn_unit_name());

				p.setWidth(this.getBean(SlmBaseUnitConversionServiceImpl.class)
						.doUnitConversion(lschi.get(0).getWidth(), lschi.get(0).getWidth_unit_no(), "100304 "));
				p.setWidth_max(this.getBean(SlmBaseUnitConversionServiceImpl.class)
						.doUnitConversion(lschi.get(0).getWidth_max(), lschi.get(0).getWidth_unit_no(), "100304 "));
				p.setWidth_min(this.getBean(SlmBaseUnitConversionServiceImpl.class)
						.doUnitConversion(lschi.get(0).getWidth_min(), lschi.get(0).getWidth_unit_no(), "100304 "));
				p.setWidth_unit_no("100304");
				p.setWidth_unit_name("mm");

				p.setLength(this.getBean(SlmBaseUnitConversionServiceImpl.class)
						.doUnitConversion(lschi.get(0).getLength(), lschi.get(0).getLengt_no(), "100304 "));
				p.setLength_max(this.getBean(SlmBaseUnitConversionServiceImpl.class)
						.doUnitConversion(lschi.get(0).getLength_max(), lschi.get(0).getLengt_no(), "100304 "));
				p.setLength_min(this.getBean(SlmBaseUnitConversionServiceImpl.class)
						.doUnitConversion(lschi.get(0).getLength_min(), lschi.get(0).getLengt_no(), "100304 "));
				p.setLength_unit_no("100304");
				p.setLength_unit_name("mm");

				p.setShort_ruler_ratio(lschi.get(0).getShort_ruler_ratio());
				p.setShort_ruler_length(lschi.get(0).getShort_ruler_length());
				p.setShort_ruler_unit_no(lschi.get(0).getShort_ruler_unit_no());
				p.setShort_ruler_unit_name(lschi.get(0).getShort_ruler_unit_name());
				p.setLong_ruler_ratio(lschi.get(0).getLong_ruler_ratio());
				p.setLong_ruler_length(lschi.get(0).getLong_ruler_length());
				p.setLong_ruler_unit_no(lschi.get(0).getLong_ruler_unit_no());
				p.setLong_ruler_unit_name(lschi.get(0).getLong_ruler_unit_name());
				p.setIs_together(lschi.get(0).getIs_together());
				p.setOut_average_length(lschi.get(0).getOut_average_length());
				p.setAverage_length_unit_no(lschi.get(0).getAverage_length_unit_no());
				p.setAverage_length_unit_name(lschi.get(0).getAverage_length_unit_name());
				p.setLong_and_short(lschi.get(0).getLong_and_short());
				p.setLas_unit_no(lschi.get(0).getLas_unit_no());
				p.setLas_unit_name(lschi.get(0).getLas_unit_name());
				p.setTolerance(lschi.get(0).getTolerance());
				p.setTolerance_unit_no(lschi.get(0).getTolerance_unit_no());
				p.setTolerance_unit_name(lschi.get(0).getTolerance_unit_name());
				p.setSingle_ruler_length(lschi.get(0).getSingle_ruler_length());
				p.setSrl_unit_no(lschi.get(0).getSrl_unit_no());
				p.setSrl_unit_name(lschi.get(0).getSrl_unit_name());
				p.setModel_code(lschi.get(0).getModel_code());
				p.setModel_name(lschi.get(0).getModel_name());
				p.setUser_no(lschi.get(0).getUser_no());
				p.setUser_name(lschi.get(0).getUser_name());
				p.setAdd_ask_no(lschi.get(0).getAdd_ask_no());
				p.setAdd_ask_desc(lschi.get(0).getAdd_ask_desc());
				p.setCustomer_alpha_no(lschi.get(0).getCustomer_alpha_no());
				p.setCustomer_alpha_desc(lschi.get(0).getCustomer_alpha_desc());
				p.setDelivery_state_code(lschi.get(0).getDelivery_state_code());
				p.setDelivery_state_desc(lschi.get(0).getDelivery_state_desc());
				p.setProduce_no("PN" + No + String.format("%05d", produceNo));

				p.setContract_memo(lschi.get(0).getMemo());
				p.setOrder_memo(soiDb.getMemo());
				// 20180417 采购合同号
				p.setPurchase_contract_no(soiDb.getPurchase_contract_no());

				SlmProcessPlan spp = new SlmProcessPlan();
				spp.setContract_no(soiDb.getContract_no());
				spp.setContract_line_seq(soiDb.getContract_line_seq());
				spp.setOrder_seq(soiDb.getOrder_seq());
				spp.setValid_flag("1");
				List<SlmProcessPlan> lspp = new ArrayList<>();
				// 整卷发运的订单可能有加工计划有的没有
				if (!"1".equals(soiDb.getOrder_nature()) && !"3".equals(soiDb.getOrder_nature())) {
					lspp = this.getMapper(SlmProcessPlanMapper.class).findWithCondition(spp, null, " cut_order_no ", 0,
							0);
					
					if(Utils.isNotEmpty(lspp)) {
						if (!"1".equals(p.getWhole_coil())) {
							List<SlmOrdDesignMscPl> msc_pline = new ArrayList<SlmOrdDesignMscPl>();
							// 选择design_key 以及制程产线确认,只有需加工订单才确认制程产线
							PlnProdorderExtinfo ppextinfo = new PlnProdorderExtinfo();
							ppextinfo.setProd_order_no(p.getProd_order_no());
							ppextinfo.setOrder_no(p.getOrder_no());
		
							// 如果只有一条加工计划并且是不切直接取一条工艺路径
							if (lspp.size() == 1 && lspp.get(0).getCut_type().equals("0")) {
								// 1、获取design_key
								SlmOrdDesignMsc som = new SlmOrdDesignMsc();
								som.setContract_line_no(lspp.get(0).getPlan_no()); // 通过加工计划号找design_key
								CommonPage<SlmOrdDesignMsc> sodm = new CommonPage<SlmOrdDesignMsc>();
								sodm.setObject(som);
								ResultModel result_DK = this.getBean(QmsApiServiceImpl.class).GetAllByDesignKey(sodm);
								if (!"200".equals(result_DK.getState())) {
									throw new Exception("自动确认制程产线失败!" + result_DK.getMsgInfo());
								}
								// 2、获取工艺路径
								List<SlmOrdDesignMsc> design_key = (List<SlmOrdDesignMsc>) result_DK.getData();
								ResultModel result_ZC = this.getBean(MesApiDesignInfoImpl.class)
										.GetMscByDesignKey(design_key.get(0).getDesign_key());
								if (!"200".equals(result_ZC.getState())) {
									throw new Exception("自动确认工艺路径失败!" + result_ZC.getMsgInfo());
								}
								msc_pline = (List<SlmOrdDesignMscPl>) result_ZC.getData();
								if (design_key.size() > 1 || msc_pline.size() > 1) {
									ppextinfo.setHas_multi_procedure(1l);
								} else {
									ppextinfo.setHas_multi_procedure(0l);
								}
								p.setDesign_key(design_key.get(0).getDesign_key());
								p.setMsc_pline(msc_pline.get(0).getMsc_pline());
								p.setWhole_process_codes(msc_pline.get(0).getStations_code());
								p.setWhole_process_names(msc_pline.get(0).getStations_desc());
								p.setWhole_process_seqs(msc_pline.get(0).getWarn_desc());
								this.getMapper(PlnProdorderExtinfoMapper.class).insert(ppextinfo);
							} else {
								// 2018-09-04 自动选择design_key 制程
								// plan : <design_key : 制程对象集合>
								List<Map<String, Map<String, List<SlmOrdDesignMscPl>>>> params = new ArrayList<>();
								SlmOrdDesignMscPl rst_path = new SlmOrdDesignMscPl();
								String rst_design_key = "";
								int i = 0;
								boolean flag_cross_cutting = false, flag_slitting = false;
								// 获取公共工艺路径
								for (SlmProcessPlan slm : lspp) {
									if (slm.getCut_type().equals("1")) {
										flag_cross_cutting = true;
									} else if (slm.getCut_type().equals("2")) {
										flag_slitting = true;
									} else if (slm.getCut_type().equals("3")) {
										flag_cross_cutting = true;
										flag_slitting = true;
									}
									Map<String, List<SlmOrdDesignMscPl>> map = new HashMap<String, List<SlmOrdDesignMscPl>>();
									Map<String, Map<String, List<SlmOrdDesignMscPl>>> plan_no = new HashMap<String, Map<String, List<SlmOrdDesignMscPl>>>();
									// 1、获取design_key
									SlmOrdDesignMsc som = new SlmOrdDesignMsc();
									som.setContract_line_no(slm.getPlan_no()); // 通过加工计划号找design_key
									CommonPage<SlmOrdDesignMsc> sodm = new CommonPage<SlmOrdDesignMsc>();
									sodm.setObject(som);
									ResultModel result_DK = this.getBean(QmsApiServiceImpl.class).GetAllByDesignKey(sodm);
									if (!"200".equals(result_DK.getState())) {
										throw new Exception("自动确认制程产线失败!" + result_DK.getMsgInfo());
									}
									// 2、获取工艺路径
									List<SlmOrdDesignMsc> design_key = (List<SlmOrdDesignMsc>) result_DK.getData();
									for (SlmOrdDesignMsc design : design_key) {
										ResultModel result_ZC = this.getBean(MesApiDesignInfoImpl.class)
												.GetMscByDesignKey(design.getDesign_key());
										if (!"200".equals(result_ZC.getState())) {
											throw new Exception("自动确认工艺路径失败!" + result_ZC.getMsgInfo());
										}
										msc_pline = (List<SlmOrdDesignMscPl>) result_ZC.getData();
										map.put(design.getDesign_key(), msc_pline);
									}
									plan_no.put(slm.getPlan_no(), map);
									params.add(plan_no);
								}
								// design : 制程对象集合
								Map<String, List<SlmOrdDesignMscPl>> result = getCommonPath(params);
								if (Utils.isNotEmpty(result)) {
									if (result.size() > 1) {
										ppextinfo.setHas_multi_procedure(1l);
									} else {
										ppextinfo.setHas_multi_procedure(0l);
									}
									for (Entry<String, List<SlmOrdDesignMscPl>> map : result.entrySet()) {
										// 取第一个赋值
										if (i == 0) {
											rst_design_key = map.getKey();
											rst_path = map.getValue().get(0);
										}
										break;
									}
									if (Utils.isNotEmpty(rst_path.getStations_code())) {
										// 开平找不到加工计划报错
										if (rst_path.getStations_code().contains(processpoint.cross_cutting_code)
												&& !flag_cross_cutting) {
											throw new Exception("工艺路径中包含开平工序,但是不存在开平加工计划!请重新质量设计!");
										} else if (rst_path.getStations_code().contains(processpoint.slitting_code)
												&& !flag_slitting) {
											throw new Exception("工艺路径中包含分条工序,但是不存在分条加工计划!请重新质量设计!");
										}
		
									}
									p.setDesign_key(rst_design_key);
									p.setMsc_pline(rst_path.getMsc_pline());
									p.setWhole_process_codes(rst_path.getStations_code());
									p.setWhole_process_names(rst_path.getStations_desc());
									p.setWhole_process_seqs(rst_path.getWarn_desc());
									this.getMapper(PlnProdorderExtinfoMapper.class).insert(ppextinfo);
								}
							}
						}
					}else if (!"1".equals(p.getWhole_coil()) ) {
						throw new Exception("订单[" + soiDb.getOrder_no() + "]对应的加工计划信息未找到！");
					}
					// 2019-07-19 质量不维护次工艺参数取消验证
					// 如果存在轧制工序 ,判断厚度范围是否符合
//					if (p.getWhole_process_codes().contains(processpoint.rolling_code)) {
//						SlmOrdDesignMscPlSti sti = new SlmOrdDesignMscPlSti();
//						List<SlmOrdDesignMscTic> tics = new ArrayList<SlmOrdDesignMscTic>();
//						sti.setDesign_key(p.getDesign_key());
//						sti.setMsc_pline(p.getMsc_pline());
//						sti.setProcess_code(processpoint.rolling_code);
//						// 只查询工艺类工序点
//						sti.setProcess_point_type("403206");
//						List<SlmOrdDesignMscPlSti> stis = this.getBean(MesApiDesignInfoImpl.class).getQcmDesignInfo(sti);
//						if(Utils.isNotEmpty(stis)) {
//							for (SlmOrdDesignMscPlSti pl : stis) {
//								SlmOrdDesignMscTic tmp = new SlmOrdDesignMscTic();
//								BeanUtils.copyProperties(pl, tmp);
//								tmp.setPline_code("C016");
//								tmp.setMachine_code("M0008");
//								tics.add(tmp);
//							}
//							this.getBean(MesApiDesignInfoImpl.class).checkFirstProc(tics, p.getThick());
//							this.getBean(MesApiDesignInfoImpl.class).checkLastProc(tics, p.getThick());
//							this.getBean(MesApiDesignInfoImpl.class).comp_Proc_Std(tics);
//						}
//					}
				} else {
					// 20180417 从0417开始，销售的[原料卷]类型订单，不下发加工计划。 为了保持逻辑统一减少修改，生产接收时，自动生成一条加工计划。
					SlmProcessPlan sppc = new SlmProcessPlan();

					sppc.setPlan_no("0001");
					sppc.setPurchase_contract_no(p.getPurchase_contract_no());
					sppc.setSteel_code(p.getSteel_code());
					sppc.setSteel_name(p.getSteel_name());
					sppc.setSpec("" + p.getThick() + "*" + p.getWidth());
					sppc.setWidth(p.getWidth());
					sppc.setThick(p.getThick());
					sppc.setLen(p.getLength());
					sppc.setEstimate_weight(p.getEstimate_weight());
					sppc.setEstimate_weight_unit_no("100305");// 千克kg
					sppc.setCrosscut_stype("1");// 1：不横切
					sppc.setCut_type("0");// 0：不切
					sppc.setCut_num(1L);
					sppc.setMemo(p.getProcessMemo());
					sppc.setValid_flag("1");
					sppc.setCreate_man_name(userName);
					sppc.setCreate_time(new Date());
					lspp.add(sppc);
				}
				this.getMapper(PlnProdorderMapper.class).insert(p);
				// 将可能存在的订单号相同的数据设置为不可用
				PlnProcessPlan pppu = new PlnProcessPlan();
				pppu.setOrder_no(p.getOrder_no());
				pppu.setValid_flag("0");
				this.getMapper(PlnProcessPlanMapper.class).doUpdate(pppu);

				// 新建加工计划表[PLN_PROCESS_PLAN]记录：（一个订单对应多条记录，要全部从销售加工计划表复制过来）
				String sCutStyle = "";
				double width_total = 0;
				List<PlnProcessPlan> lppp = new ArrayList<PlnProcessPlan>();
				long cutOrdNo = 1;
				for (SlmProcessPlan sppc : lspp) {
					PlnProcessPlan ppp = new PlnProcessPlan();
					ppp.setProduce_no(p.getProduce_no());
					ppp.setPlan_no(sppc.getPlan_no());
					ppp.setCut_order_no(cutOrdNo++);
					ppp.setOrder_no(p.getOrder_no());
					ppp.setPurchase_contract_no(sppc.getPurchase_contract_no());
					ppp.setSteel_code(sppc.getSteel_code());
					ppp.setSteel_name(sppc.getSteel_name());
					ppp.setSpec(sppc.getSpec());
					ppp.setWidth(this.getBean(SlmBaseUnitConversionServiceImpl.class).doUnitConversion(sppc.getWidth(),
							lschi.get(0).getWidth_unit_no(), "100304 "));
					ppp.setThick(this.getBean(SlmBaseUnitConversionServiceImpl.class).doUnitConversion(sppc.getThick(),
							lschi.get(0).getThick_unit_no(), "100304 "));
					ppp.setLength(this.getBean(SlmBaseUnitConversionServiceImpl.class).doUnitConversion(sppc.getLen(),
							lschi.get(0).getLengt_no(), "100304 "));
					ppp.setEstimate_weight(this.getBean(SlmBaseUnitConversionServiceImpl.class)
							.doUnitConversion(sppc.getEstimate_weight(), sppc.getEstimate_weight_unit_no(), "100305"));
					if (Utils.isNotEmpty(lschi.get(0).getWidth())) {
						if (lschi.get(0).getWidth() <= 0) {
							throw new Exception("订单[" + soiDb.getOrder_no() + "]对应的加工计划[" + sppc.getPlan_no() + "]的宽度错误！");
						}
						ppp.setMat_width(this.getBean(SlmBaseUnitConversionServiceImpl.class)
								.doUnitConversion(lschi.get(0).getWidth(), lschi.get(0).getWidth_unit_no(), "100304 "));
						
					}
					if (Utils.isNotEmpty(lschi.get(0).getThick())) {
						if (lschi.get(0).getThick() <= 0) {
							throw new Exception("订单[" + soiDb.getOrder_no() + "]对应的加工计划[" + sppc.getPlan_no() + "]的厚度错误！");
						}
						ppp.setMat_thick(this.getBean(SlmBaseUnitConversionServiceImpl.class)
								.doUnitConversion(lschi.get(0).getThick(), lschi.get(0).getThick_unit_no(), "100304 "));
					}

					if (sppc.getCrosscut_stype() != null && !"".equals(sppc.getCrosscut_stype())) {
						try {
							int i = Integer.parseInt(sppc.getCrosscut_stype().trim());
							switch (i) {
							case 1:
							case 2:
							case 3:
							case 4:
							case 5:
							case 6:
							case 7:
							case 8:
								ppp.setCrosscut_style(sppc.getCrosscut_stype().trim());
								break;
							default:
								ppp.setCrosscut_style("1");
								break;
							}
						} catch (Exception ex) {
							throw new Exception(
									"订单[" + soiDb.getOrder_no() + "]对应的加工计划[" + sppc.getPlan_no() + "]的横切方式错误！");
						}
					}

					ppp.setCut_type(sppc.getCut_type());
					ppp.setCut_num(sppc.getCut_num());
					ppp.setRemark(sppc.getMemo());
					ppp.setValid_flag(sppc.getValid_flag());
					ppp.setCreate_man_name(userName);
					ppp.setCreate_time(new Date());

					ppp.setWall_thick(this.getBean(SlmBaseUnitConversionServiceImpl.class)
							.doUnitConversion(sppc.getWall_thick(), lschi.get(0).getThick_unit_no(), "100304 "));
					ppp.setMono_stack_max_weight(this.getBean(SlmBaseUnitConversionServiceImpl.class).doUnitConversion(
							sppc.getMono_stack_max_weight(), sppc.getEstimate_weight_unit_no(), "100305"));
					ppp.setMono_stack_min_weight(this.getBean(SlmBaseUnitConversionServiceImpl.class).doUnitConversion(
							sppc.getMono_stack_min_weight(), sppc.getEstimate_weight_unit_no(), "100305"));

					lppp.add(ppp);

					if (sppc.getCut_type() != null && "1".equals(sppc.getCut_type())) { // 横剪
						double weightupper = 0;
//					 读取基础配置 产线机组限制表
						ComDsnPltlmt cdp = new ComDsnPltlmt();
						cdp.setPlt("Y1");// 工厂
						cdp.setPlt_line("Y1");// 产线
						List<ComDsnPltlmt> lc = this.getMapper(ComDsnPltlmtMapper.class).find(cdp, 0, 0);
						if (lc == null || lc.size() == 0) {
							throw new Exception("未找到产线");
						}
//					 获取所有的限制条件
						ClRestrict MachineRestrict = new ClRestrict(lc);
						if (ppp.getMono_stack_max_weight() == null) {
							weightupper = MachineRestrict.lim_max_box_wgt;
						} else if (ppp.getMono_stack_max_weight() != null) {
							weightupper = ppp.getMono_stack_max_weight();
							if (ppp.getMono_stack_max_weight().doubleValue() - MachineRestrict.lim_max_box_wgt > 0) {
								throw new Exception("订单[" + soiDb.getOrder_no() + "]的加工计划中单剁重量上限(单位是吨)超出设备重量限制!");
							}
						}
						// 获取子堆垛总数和单堆垛块数
						// Double[] result =
						// this.getBean(MesApiCrCrossCuttingMServiceImpl.class).getBoxCount(ppp,MachineRestrict.lim_max_box_height);
						// 子板重量
						// double subweight
						// =this.getBean(MesApiCrCrossCuttingMServiceImpl.class).GetWeightBySize(ppp.getThick(),
						// ppp.getWidth(), ppp.getLength());
						if (ppp.getLength() != null) {
							sCutStyle += ppp.getLength().doubleValue() + "*"
									+ new BigDecimal(p.getEstimate_weight() / 1000)
											.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue()
									+ "T(" + new BigDecimal(weightupper / 1000).setScale(1, BigDecimal.ROUND_HALF_UP)
											.doubleValue()
									+ "T)+";
						}
					} else if (sppc.getCut_type() != null && "2".equals(sppc.getCut_type())) {// 纵剪
						sCutStyle += ppp.getWidth().doubleValue() + "*" + ppp.getCut_num().intValue() + "+";
						width_total += ppp.getWidth().doubleValue() * ppp.getCut_num().intValue();
					}
				}
				// 有不切的情况
				if (sCutStyle != null && !"".equals(sCutStyle)) {
					sCutStyle = sCutStyle.substring(0, sCutStyle.length() - 1);
				}
				for (PlnProcessPlan ppp : lppp) {
					if (lppp.size() >= 1) {
						ppp.setCut_style(sCutStyle);
						if (ppp.getCut_type() != null && "2".equals(ppp.getCut_type())) {
							ppp.setWidth_total(width_total);
						}
					}
					this.getMapper(PlnProcessPlanMapper.class).insert(ppp);
				}

				// 新建 订单进程表
				PlnOrderStatistic pos = new PlnOrderStatistic();
				pos.setSerial_no(++iPOSCount + "");
				pos.setOrder_no(p.getOrder_no());
				pos.setOrdered(p.getEstimate_weight());
				pos.setUnscheduled(p.getEstimate_weight());

				// 新建 生产订单进程表
				PlnProdorderStatistic pps = new PlnProdorderStatistic();
				pps.setOrder_no(p.getOrder_no());
				pps.setSerial_no(++iPPSCount + "");
				pps.setProd_order_no(p.getProd_order_no());
				pps.setProd_ordered(p.getEstimate_weight());
				pps.setUnscheduled(p.getEstimate_weight());

				// 订单最后一个需要坯料设计的工序 E0002为分条
				/*
				 * String WrkCode=this.getBean(QmsApiServiceImpl.class).GetWrkPlanCode("");
				 * if(processpoint.slitting_code.equals(WrkCode)){ //如果最后工序是分条，则填写：LW_UNDSN
				 * 欠分条设计_成品量=订单总量；LW_UNDSN_CNT 欠分条设计_成品数=订单总量
				 * pos.setLw_undsn(p.getEstimate_weight());
				 * pps.setLw_undsn(p.getEstimate_weight()); }
				 */

				// 验证生产订单表是否生成：20230413刘侣
				PlnProdorder pd = new PlnProdorder();
				pd.setProd_order_no(p.getProd_order_no());
				List<PlnProdorder> po = this.getMapper(PlnProdorderMapper.class).find(pd, 0, 0);
				if (po == null || po.size() == 0) {
					throw new Exception(p.getOrder_no() + " 未生成生产订单数据， 请联系管理员");
				}
				// end
				
				this.getMapper(PlnOrderStatisticMapper.class).insert(pos);
				this.getMapper(PlnProdorderStatisticMapper.class).insert(pps);

				// 修改订单状态为接收
				SlmOrderInfo soiu = new SlmOrderInfo();
				soiu.setOrder_no(soi.getOrder_no());
				soiu.setOrder_flag_no("103407");
				soiu.setOrder_flag_name("接收");
				this.getMapper(SlmOrderInfoMapper.class).update(soiu);
				rm.setState("200");
			}
		}
		return rm;
	}

	
	
	/**
	 * 订单接收
	 * 
	 * 2019-01-10 增加变更订单接收
	 * 这个是接收一体化订单的新接口
	 * 
	 * @throws Exception
	 */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doOrderReceiveWebNew(CommonPage<PlnProdorder> sum) throws Exception {
		ResultModel rm = new ResultModel();
		List<PlnProdorder> lp = sum.getObjectList();
		if (lp == null || lp.size() == 0) {
			rm.setState("500");
			rm.setMsgInfo("请传入参数！");
			return rm;
		}

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

		// 查询唯一一条数据
		List<PlnProdorder> ppq = this.getMapper(PlnProdorderMapper.class).findWithCondition(null, "",
				" prod_order_no desc ", 0, 1);
		int maxId = 0;
		if (ppq != null && ppq.size() > 0) {
			maxId = Integer.parseInt(ppq.get(0).getSerial_no());
		}
		String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		// 新建生产订单表
		String No = new SimpleDateFormat("yyMMdd").format(new Date());
		List<PlnProdorder> lpCount = this.getMapper(PlnProdorderMapper.class).findWithCondition(null,
				" substr(prod_order_no,1,6)='" + No + "' ", " to_number(serial_no) desc ", 0, 1);
		int iprodCount = 0;
		if (lpCount == null || lpCount.size() == 0) {
			iprodCount = 0;
		} else {
			iprodCount = Integer.parseInt(lpCount.get(0).getProd_order_no().substring(6, 13));
		}

		int produceNo = 0;
		List<PlnProcessPlan> lpppCount = this.getMapper(PlnProcessPlanMapper.class).findWithCondition(null,
				" substr(produce_no,3,6)='" + No + "' and valid_flag = 1 ", " produce_no desc ", 0, 1);
		if (lpppCount != null && lpppCount.size() > 0) {
			produceNo = Integer.parseInt(lpppCount.get(0).getProduce_no().substring(8, 13));
		}

		int iPOSCount = this.getMapper(PlnOrderStatisticMapper.class).doQueryMaxNo();
		int iPPSCount = this.getMapper(PlnProdorderStatisticMapper.class).doQueryMaxNo();

		for (PlnProdorder p : lp) {
			++produceNo;
			SlmOrderInfo soi = new SlmOrderInfo();
			soi.setOrder_no(p.getOrder_no());
			List<SlmOrderInfo> soiDbb = this.getMapper(SlmOrderInfoMapper.class).findWithCondition(null,
					"order_no like '%" + p.getOrder_no() + "%'", " create_time desc ", 0, 1);
			if (soiDbb == null || soiDbb.size() == 0) {
				throw new Exception("订单[" + p.getOrder_no() + "]信息不存在！请刷新页面再操作!");
			}
			
			// 检测该订单是否有下发质量设计：废掉：整卷发运订单不需要质量设计；20231012刘侣
//			String ythOrder = p.getOrder_no().substring(0, p.getOrder_no().length() - 3);
//			SlmOrdDesignMsc msc = this.getMapper(SlmOrdDesignMscMapper.class).findById(ythOrder);
//			if (msc == null || "".equals(msc)) {
//				throw new Exception("订单[" + p.getOrder_no() + "]质量设计信息未下发!");
//			}
			
			SlmOrderInfo soiDb = soiDbb.get(0);
			// 判断订单是否是拆分订单
			if (soiDb.getIs_split() != null && "1".equals(soiDb.getIs_split())) {
//				String ord_pk = StringUtils.substringBefore(p.getOrder_no(), "-");
				// 获取原生产订单
				List<PlnProdorder> plp = this.getMapper(PlnProdorderMapper.class).findWithCondition(null, " ord_pk = '"+soiDb.getP_order_no()+"'", null, 0, 1);
				if (Utils.isNotEmpty(plp)) {
					// 修改生产订单总量以及未设计量(总量-已设计量)
					plp.get(0).setEstimate_weight(plp.get(0).getEstimate_weight()-this.getBean(SlmBaseUnitConversionServiceImpl.class)
							.doUnitConversion(soiDb.getEstimate_weight(), soiDb.getEstimate_weight_unit_no(), "100305"));
					this.getMapper(PlnProdorderMapper.class).update(plp.get(0));
					List<PlnProdorderStatistic> plps = this.getMapper(PlnProdorderStatisticMapper.class)
							.findWithCondition(null, " prod_order_no = '"+plp.get(0).getProd_order_no()+"'", null, 0, 1) ; 
					plps.get(0).setProd_ordered(plps.get(0).getProd_ordered() - this.getBean(SlmBaseUnitConversionServiceImpl.class)
							.doUnitConversion(soiDb.getEstimate_weight(), soiDb.getEstimate_weight_unit_no(), "100305"));
					if (plp.get(0).getWhole_process_codes().contains(processpoint.slitting_code)) {
						plps.get(0).setLw_undsn(plps.get(0).getProd_ordered()-(plps.get(0).getLw_dsn()==null?0:plps.get(0).getLw_dsn()));
					}
					// 开平
					if (plp.get(0).getWhole_process_codes().contains(processpoint.cross_cutting_code)) {
						plps.get(0).setCl_undsn(plps.get(0).getProd_ordered()-(plps.get(0).getCl_dsn()==null?0:plps.get(0).getCl_dsn()));
					}
					// 罩退
					if (plp.get(0).getWhole_process_codes().contains(processpoint.anneal_code)) {
						plps.get(0).setAn_undsn(plps.get(0).getProd_ordered()-(plps.get(0).getAn_dsn()==null?0:plps.get(0).getAn_dsn()));
					}
					// 平整
					if (plp.get(0).getWhole_process_codes().contains(processpoint.smooth_code)) {
						plps.get(0).setSr_undsn(plps.get(0).getProd_ordered() - (plps.get(0).getSr_dsn()==null?0:plps.get(0).getSr_dsn()));
					}
					// 轧制
					if (plp.get(0).getWhole_process_codes().contains(processpoint.rolling_code)) {
						plps.get(0).setRl_undsn(plps.get(0).getProd_ordered() - (plps.get(0).getRl_dsn()==null?0:plps.get(0).getRl_dsn()));
					}
					// 酸洗
					if (plp.get(0).getWhole_process_codes().contains(processpoint.pickle_code)) {
						plps.get(0).setPc_undsn(plps.get(0).getProd_ordered() - (plps.get(0).getPc_dsn()==null?0:plps.get(0).getPc_dsn()));
					}
					this.getMapper(PlnProdorderStatisticMapper.class).update(plps.get(0));
				}
			}
			// 获取生产订单信息
			PlnProdorder pp = new PlnProdorder();
			pp.setOrder_no(soiDb.getContract_no() + soiDb.getContract_line_seq() + soiDb.getOrder_seq());
			List<PlnProdorder> pp_old = this.getMapper(PlnProdorderMapper.class).find(pp, 0, 0);
			// 接收变更的订单
			// 变更属性的订单有可能是拆分订单,拆分订单的话是没有对应的生产订单的直接生成新生产订单
			// 修改订单对应的物料附加信息的作业路径
			if ("3".equals(soiDb.getChange_flag()) && Utils.isNotEmpty(pp_old)) {
				for (PlnProdorder pln : pp_old) {
					String cTypes = ""; // 更改类型
					String prc_old = pln.getWhole_process_codes();
					PlnProdorderBak ppbak = new PlnProdorderBak();
					BeanUtils.copyProperties(pln, ppbak);
					// 查询唯一一条数据
					List<PlnProdorderBak> ppqbak = this.getMapper(PlnProdorderBakMapper.class).findWithCondition(null,
							"", " to_number(Serial_no) desc ", 0, 1);
					int bakId = 0;
					if (ppqbak != null && ppqbak.size() > 0) {
						bakId = Integer.parseInt(ppqbak.get(0).getSerial_no());
					}
					ppbak.setSerial_no(bakId + 1 + "");
					// 备份生产订单信息
					this.getMapper(PlnProdorderBakMapper.class).insert(ppbak);
					// 将老加工计划置为无效
					List<PlnProcessPlan> ppp_old = this.getMapper(PlnProcessPlanMapper.class).findWithCondition(null,
							"produce_no = '" + pln.getProduce_no() + "' and valid_flag = 1 ", "", 0, 0);
					if (Utils.isNotEmpty(ppp_old)) {
						for (PlnProcessPlan pnn : ppp_old) {
							pnn.setValid_flag("0");
							this.getMapper(PlnProcessPlanMapper.class).update(pnn);
						}
					}

					// 合同行信息
					SlmContractLineInfo scli = new SlmContractLineInfo();
					scli.setContract_line_no(pln.getContract_line_no());
					List<SlmContractLineInfo> lschi = this.getMapper(SlmContractLineInfoMapper.class).find(scli, 0, 0);

					// 获取新的加工计划信息
					SlmProcessPlan spp = new SlmProcessPlan();
					spp.setContract_no(soiDb.getContract_no());
					spp.setContract_line_seq(soiDb.getContract_line_seq());
					spp.setOrder_seq(soiDb.getOrder_seq());
					spp.setValid_flag("1");
					List<SlmProcessPlan> lspp = new ArrayList<>();
					lspp = this.getMapper(SlmProcessPlanMapper.class).findWithCondition(spp, null, " cut_order_no ", 0,
							0);
					if (lspp == null || lspp.size() == 0) {
						throw new Exception("订单[" + soiDb.getOrder_no() + "]对应的加工计划信息未找到！");
					}

					List<SlmOrdDesignMscPl> msc_pline = new ArrayList<SlmOrdDesignMscPl>();

					// 选择design_key 以及制程产线确认,只有需加工订单才确认制程产线
					// 修改生产订单附加信息
					PlnProdorderExtinfo ppextinfo = new PlnProdorderExtinfo();
					ppextinfo.setProd_order_no(pln.getProd_order_no());
					ppextinfo.setOrder_no(pln.getOrder_no());

					// 如果只有一条加工计划并且是不切直接取一条工艺路径
					if (lspp.size() == 1 && lspp.get(0).getCut_type().equals("0")) {
						// 1、获取design_key
						SlmOrdDesignMsc som = new SlmOrdDesignMsc();
						som.setContract_line_no(lspp.get(0).getPlan_no()); // 通过加工计划号找design_key
						CommonPage<SlmOrdDesignMsc> sodm = new CommonPage<SlmOrdDesignMsc>();
						sodm.setObject(som);
						ResultModel result_DK = this.getBean(QmsApiServiceImpl.class).GetAllByDesignKey(sodm);
						if (!"200".equals(result_DK.getState())) {
							throw new Exception("自动确认制程产线失败!" + result_DK.getMsgInfo());
						}
						// 2、获取工艺路径：这个design_key没有也行：20230914刘侣
						List<SlmOrdDesignMsc> design_key = (List<SlmOrdDesignMsc>) result_DK.getData();
						ResultModel result_ZC = this.getBean(MesApiDesignInfoImpl.class)
								.GetMscByDesignKey(design_key.get(0).getDesign_key());
						if (!"200".equals(result_ZC.getState())) {
							throw new Exception("自动确认工艺路径失败!" + result_ZC.getMsgInfo());
						}
						msc_pline = (List<SlmOrdDesignMscPl>) result_ZC.getData();
						if (design_key.size() > 1 || msc_pline.size() > 1) {
							ppextinfo.setHas_multi_procedure(1l);
						} else {
							ppextinfo.setHas_multi_procedure(0l);
						} 
						// 这些如果没有可以从订单那里获取到工艺路径：20230914刘侣
						pln.setDesign_key(design_key.get(0).getDesign_key());
						pln.setMsc_pline(msc_pline.get(0).getMsc_pline());
						pln.setWhole_process_codes(msc_pline.get(0).getStations_code());
						pln.setWhole_process_names(msc_pline.get(0).getStations_desc());
						pln.setWhole_process_seqs(msc_pline.get(0).getWarn_desc());		
						// 修改生产订单附加信息
						this.getMapper(PlnProdorderExtinfoMapper.class).update(ppextinfo);
					} else {
						// 2018-09-04 自动选择design_key 制程
						// plan : <design_key : 制程对象集合>
						List<Map<String, Map<String, List<SlmOrdDesignMscPl>>>> params = new ArrayList<>();
						SlmOrdDesignMscPl rst_path = new SlmOrdDesignMscPl();
						String rst_design_key = "";
						int i = 0;
						boolean flag_cross_cutting = false, flag_slitting = false;
						// 获取公共工艺路径
						for (SlmProcessPlan slm : lspp) {
							if (slm.getCut_type().equals("1")) {
								flag_cross_cutting = true;
							} else if (slm.getCut_type().equals("2")) {
								flag_slitting = true;
							} else if (slm.getCut_type().equals("3")) {
								flag_cross_cutting = true;
								flag_slitting = true;
							}
							Map<String, List<SlmOrdDesignMscPl>> map = new HashMap<String, List<SlmOrdDesignMscPl>>();
							Map<String, Map<String, List<SlmOrdDesignMscPl>>> plan_no = new HashMap<String, Map<String, List<SlmOrdDesignMscPl>>>();
							// 1、获取design_key
							SlmOrdDesignMsc som = new SlmOrdDesignMsc();
							som.setContract_line_no(slm.getPlan_no()); // 通过加工计划号找design_key
							CommonPage<SlmOrdDesignMsc> sodm = new CommonPage<SlmOrdDesignMsc>();
							sodm.setObject(som);
							ResultModel result_DK = this.getBean(QmsApiServiceImpl.class).GetAllByDesignKey(sodm);
							if (!"200".equals(result_DK.getState())) {
								throw new Exception("自动确认制程产线失败!" + result_DK.getMsgInfo());
							}
							// 2、获取工艺路径
							List<SlmOrdDesignMsc> design_key = (List<SlmOrdDesignMsc>) result_DK.getData();
							for (SlmOrdDesignMsc design : design_key) {
								ResultModel result_ZC = this.getBean(MesApiDesignInfoImpl.class)
										.GetMscByDesignKey(design.getDesign_key());
								if (!"200".equals(result_ZC.getState())) {
									throw new Exception("自动确认工艺路径失败!" + result_ZC.getMsgInfo());
								}
								msc_pline = (List<SlmOrdDesignMscPl>) result_ZC.getData();
								map.put(design.getDesign_key(), msc_pline);
							}
							plan_no.put(slm.getPlan_no(), map);
							params.add(plan_no);
						}
						// design : 制程对象集合
						Map<String, List<SlmOrdDesignMscPl>> result = getCommonPath(params);
						if (Utils.isNotEmpty(result)) {
							if (result.size() > 1) {
								ppextinfo.setHas_multi_procedure(1l);
							} else {
								ppextinfo.setHas_multi_procedure(0l);
							}
							for (Entry<String, List<SlmOrdDesignMscPl>> map : result.entrySet()) {
								// 取第一个赋值
								if (i == 0) {
									rst_design_key = map.getKey();
									rst_path = map.getValue().get(0);
								}
								break;
							}
							if (Utils.isNotEmpty(rst_path.getStations_code())) {
								// 开平找不到加工计划报错
								if (rst_path.getStations_code().contains(processpoint.cross_cutting_code)
										&& !flag_cross_cutting) {
									throw new Exception("工艺路径中包含开平工序,但是不存在开平加工计划!请重新质量设计!");
								} else if (rst_path.getStations_code().contains(processpoint.slitting_code)
										&& !flag_slitting) {
									throw new Exception("工艺路径中包含分条工序,但是不存在分条加工计划!请重新质量设计!");
								}
							}
							pln.setDesign_key(rst_design_key);
							pln.setMsc_pline(rst_path.getMsc_pline());
							pln.setWhole_process_codes(rst_path.getStations_code());
							pln.setWhole_process_names(rst_path.getStations_desc());
							pln.setWhole_process_seqs(rst_path.getWarn_desc());
							// 修改生产订单附加信息
							this.getMapper(PlnProdorderExtinfoMapper.class).update(ppextinfo);
						}
					}

					// 修改物料附加信息
					PrcMaterielExtinfo pme = new PrcMaterielExtinfo();
					pme.setOrder_no(pln.getOrder_no());
					pme.setTask_process_codes(pln.getWhole_process_codes());
					pme.setTask_process_names(pln.getWhole_process_names());
					this.getMapper(PrcMaterielExtinfoMapper.class).updateByOrder(pme);
					
					
					// 如果有轧制工序 ,判断厚度范围是否符合,第一道次的入口厚度小于订单厚度报错,最后道次出口厚度不包含订单厚度报错
//					if (pln.getWhole_process_codes().contains(processpoint.rolling_code)) {
//						SlmOrdDesignMscPlSti sti = new SlmOrdDesignMscPlSti();
//						List<SlmOrdDesignMscTic> tics = new ArrayList<SlmOrdDesignMscTic>();
//						sti.setDesign_key(pln.getDesign_key());
//						sti.setMsc_pline(pln.getMsc_pline());
//						sti.setProcess_code(processpoint.rolling_code);
//						// 只查询工艺类工序点
//						sti.setProcess_point_type("403206");
//						List<SlmOrdDesignMscPlSti> stis = this.getBean(MesApiDesignInfoImpl.class).getQcmDesignInfo(sti);
//						for (SlmOrdDesignMscPlSti pl : stis) {
//							SlmOrdDesignMscTic tmp = new SlmOrdDesignMscTic();
//							BeanUtils.copyProperties(pl, tmp);
//							tmp.setPline_code("C016");
//							tmp.setMachine_code("M0008");
//							tics.add(tmp);
//						}
//						this.getBean(MesApiDesignInfoImpl.class).checkFirstProc(tics, pln.getThick());
//						this.getBean(MesApiDesignInfoImpl.class).checkLastProc(tics, pln.getThick());
//						this.getBean(MesApiDesignInfoImpl.class).comp_Proc_Std(tics);
//					}
					
					pln.setProduce_no("PN" + No + String.format("%05d", produceNo)); // 修改加工计划号

					// 新建加工计划表[PLN_PROCESS_PLAN]记录：（一个订单对应多条记录，要全部从销售加工计划表复制过来）
					String sCutStyle = "";
					double width_total = 0;
					List<PlnProcessPlan> lppp = new ArrayList<PlnProcessPlan>();
					long cutOrdNo = 1;
					for (SlmProcessPlan sppc : lspp) {
						PlnProcessPlan ppp = new PlnProcessPlan();
						ppp.setProduce_no(pln.getProduce_no());
						ppp.setPlan_no(sppc.getPlan_no());
						ppp.setCut_order_no(cutOrdNo++);
						ppp.setOrder_no(pln.getOrder_no());
						ppp.setPurchase_contract_no(sppc.getPurchase_contract_no());
						ppp.setSteel_code(sppc.getSteel_code());
						ppp.setSteel_name(sppc.getSteel_name());
						ppp.setSpec(sppc.getSpec());
						ppp.setWidth(this.getBean(SlmBaseUnitConversionServiceImpl.class)
								.doUnitConversion(sppc.getWidth(), lschi.get(0).getWidth_unit_no(), "100304 "));
						ppp.setThick(this.getBean(SlmBaseUnitConversionServiceImpl.class)
								.doUnitConversion(sppc.getThick(), lschi.get(0).getThick_unit_no(), "100304 "));
						ppp.setLength(this.getBean(SlmBaseUnitConversionServiceImpl.class)
								.doUnitConversion(sppc.getLen(), lschi.get(0).getLengt_no(), "100304 "));
						ppp.setEstimate_weight(this.getBean(SlmBaseUnitConversionServiceImpl.class).doUnitConversion(
								sppc.getEstimate_weight(), sppc.getEstimate_weight_unit_no(), "100305"));
						if (lschi.get(0).getWidth() <= 0)
							throw new Exception(
									"订单[" + soiDb.getOrder_no() + "]对应的加工计划[" + sppc.getPlan_no() + "]的宽度错误！");
						if (lschi.get(0).getThick() <= 0)
							throw new Exception(
									"订单[" + soiDb.getOrder_no() + "]对应的加工计划[" + sppc.getPlan_no() + "]的厚度错误！");

						ppp.setMat_width(this.getBean(SlmBaseUnitConversionServiceImpl.class)
								.doUnitConversion(lschi.get(0).getWidth(), lschi.get(0).getWidth_unit_no(), "100304 "));
						ppp.setMat_thick(this.getBean(SlmBaseUnitConversionServiceImpl.class)
								.doUnitConversion(lschi.get(0).getThick(), lschi.get(0).getThick_unit_no(), "100304 "));
						ppp.setCrosscut_style(sppc.getCrosscut_stype());

						ppp.setCut_type(sppc.getCut_type());
						ppp.setCut_num(sppc.getCut_num());
						ppp.setRemark(sppc.getMemo());
						ppp.setValid_flag(sppc.getValid_flag());
						ppp.setCreate_man_name(userName);
						ppp.setCreate_time(new Date());

						ppp.setWall_thick(this.getBean(SlmBaseUnitConversionServiceImpl.class)
								.doUnitConversion(sppc.getWall_thick(), lschi.get(0).getThick_unit_no(), "100304 "));
						ppp.setMono_stack_max_weight(
								this.getBean(SlmBaseUnitConversionServiceImpl.class).doUnitConversion(
										sppc.getMono_stack_max_weight(), sppc.getEstimate_weight_unit_no(), "100305"));
						ppp.setMono_stack_min_weight(
								this.getBean(SlmBaseUnitConversionServiceImpl.class).doUnitConversion(
										sppc.getMono_stack_min_weight(), sppc.getEstimate_weight_unit_no(), "100305"));
						lppp.add(ppp);

						if (sppc.getCut_type() != null && "1".equals(sppc.getCut_type())) { // 横剪
							double weightupper = 0;
//							 读取基础配置 产线机组限制表
							ComDsnPltlmt cdp = new ComDsnPltlmt();
							cdp.setPlt("Y1");// 工厂
							cdp.setPlt_line("Y1");// 产线
							List<ComDsnPltlmt> lc = this.getMapper(ComDsnPltlmtMapper.class).find(cdp, 0, 0);
							if (lc == null || lc.size() == 0) {
								throw new Exception("未找到产线");
							}
//							 获取所有的限制条件
							ClRestrict MachineRestrict = new ClRestrict(lc);
							if (ppp.getMono_stack_max_weight() == null) {
								weightupper = MachineRestrict.lim_max_box_wgt;
							} else if (ppp.getMono_stack_max_weight() != null) {
								weightupper = ppp.getMono_stack_max_weight();
								if (ppp.getMono_stack_max_weight().doubleValue()
										- MachineRestrict.lim_max_box_wgt > 0) {
									throw new Exception("订单[" + soiDb.getOrder_no() + "]的加工计划中单剁重量上限(单位是吨)超出设备重量限制!");
								}
							}
							if (ppp.getLength() != null) {
								sCutStyle += ppp.getLength().doubleValue() + "*"
										+ new BigDecimal(p.getEstimate_weight() / 1000)
												.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue()
										+ "T(" + new BigDecimal(weightupper / 1000)
												.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue()
										+ "T)+";
							}
						} else if (sppc.getCut_type() != null && "2".equals(sppc.getCut_type())) {// 纵剪
							sCutStyle += ppp.getWidth().doubleValue() + "*" + ppp.getCut_num().intValue() + "+";
							width_total += ppp.getWidth().doubleValue() * ppp.getCut_num().intValue();
						}
					}
					// 有不切的情况
					if (sCutStyle != null && !"".equals(sCutStyle)) {
						sCutStyle = sCutStyle.substring(0, sCutStyle.length() - 1);
					}
					for (PlnProcessPlan ppp : lppp) {
						if (lppp.size() >= 1) {
							ppp.setCut_style(sCutStyle);
							if (ppp.getCut_type() != null && "2".equals(ppp.getCut_type())) {
								ppp.setWidth_total(width_total);
							}
							// 新老加工计划如果不一样就记录变更类型20
							if (Utils.isEmpty(ppp) || !ppp_old.get(0).getCut_type().equals(ppp.getCut_type())
									|| (Utils.isNotEmpty(ppp_old.get(0).getCut_style()) && Utils.isNotEmpty(ppp.getCut_style()) && !ppp_old.get(0).getCut_style().equals(ppp.getCut_style()))
									) {
								cTypes = "20,";
							}
						}
						this.getMapper(PlnProcessPlanMapper.class).insert(ppp);
					}
					// 比较新老工艺路径 判断工艺路径
					if (!prc_old.equals(pln.getWhole_process_codes())) {
						// 获取有效的工艺路径
						String[] arr_old = prc_old.split("-");
						String[] arr_new = pln.getWhole_process_codes().split("-");
						List<String> validpath_old = this.getBean(MesApiDesignInfoImpl.class).getProcessPath(arr_old);
						List<String> validpath_new = this.getBean(MesApiDesignInfoImpl.class).getProcessPath(arr_new);
						if (!validpath_old.equals(validpath_new)) {
							for (String str_old : validpath_old) {
								boolean flag_c = false;
								for (String str_new : validpath_new) {
									if (str_new.equals(str_old)) {
										flag_c = true;
										break;
									}
								}
								if (!flag_c) {
									cTypes += "0" + str_old.substring(0, 1) + ",";
								}
							}
							for (String str_new : validpath_new) {
								boolean flag_j = false;
								for (String str_old : validpath_old) {
									if (str_new.equals(str_old)) {
										flag_j = true;
										break;
									}
								}
								if (!flag_j) {
									cTypes += "1" + str_new.substring(0, 1) + ",";
								}
							}
						}
					}

					if (Utils.isNotEmpty(cTypes)) {
						cTypes = cTypes.substring(0, cTypes.length() - 1);
						// 判断能否变更
						boolean flag = this.getBean(MesApiDesignInfoImpl.class).canOrderChange(pln.getOrder_no(),
								cTypes);
						if (!flag) {
							throw new Exception("该订单[" + pln.getOrder_no() + "]不能变更,请退回重新操作!");
						}
					}
					// 注意修改生产订单一定要在验证是否能变更之后
					// 修改老生产订单信息
					pln.setContract_line_no(soiDb.getContract_line_no());
					pln.setContract_line_seq(soiDb.getContract_line_seq());
					pln.setOrder_memo(soiDb.getMemo()); // 订单备注
					pln.setFinished_status("0"); // 生产未完成
					pln.setChange_flag(soiDb.getChange_flag()); // 变更标志
					pln.setOrd_pk(soiDb.getOrder_no()); // 销售订单主键
					pln.setP_order_no(soiDb.getP_order_no());
					pln.setIs_split(soiDb.getIs_split());// 是否拆分
					pln.setCustomer_no(soiDb.getCustomer_no());
					pln.setCustomer_name(soiDb.getCustomer_name()); 
					pln.setReciver_unit_no(soiDb.getReciver_unit_no());
					pln.setReciver_unit_name(soiDb.getReciver_unit_name());
					pln.setReciver_address(soiDb.getReciver_address());
					pln.setPk_ask_code(scli.getPk_ask_code());
					pln.setPk_ask_desc(scli.getPk_ask_desc());
					this.getMapper(PlnProdorderMapper.class).update(pln);

					// 修改生产订单进程表
					List<PlnProdorderStatistic> pps = this.getMapper(PlnProdorderStatisticMapper.class)
							.findWithCondition(null, "prod_order_no = '" + pln.getProd_order_no() + "'", "", 0, 1);

					// 修改订单进程表
					List<PlnOrderStatistic> pos = this.getMapper(PlnOrderStatisticMapper.class).findWithCondition(null,
							"order_no = '" + pln.getOrder_no() + "'", "", 0, 1);
					double nums = pps.get(0).getProd_ordered();

					// 获取订单对应的虚拟母卷信息
					List<PlnMaterielDetail> pmd = this.getMapper(PlnMaterielDetailMapper.class).findWithCondition(null,
							"prod_order_no = '" + pln.getProd_order_no()
									+ "' and nvl(invalid_flg,0) != 1 and mat_object_no_vt is null",
							"", 0, 0);
					if (Utils.isNotEmpty(pmd)) {
						// 获取母卷下一个工序对应的未设计量
						if (processpoint.slitting_code.equals(pmd.get(0).getNext_process_code())) {
							nums = pps.get(0).getLw_undsn() == 0 ? pps.get(0).getLw_dsn() : pps.get(0).getLw_undsn();
						} else if (processpoint.cross_cutting_code.equals(pmd.get(0).getNext_process_code())) {
							nums = pps.get(0).getCl_undsn() == 0 ? pps.get(0).getCl_dsn() : pps.get(0).getCl_undsn();
						} else if (processpoint.smooth_code.equals(pmd.get(0).getNext_process_code())) {
							nums = pps.get(0).getSr_undsn() == 0 ? pps.get(0).getSr_dsn() : pps.get(0).getSr_undsn();
						} else if (processpoint.anneal_code.equals(pmd.get(0).getNext_process_code())) {
							nums = pps.get(0).getAn_undsn() == 0 ? pps.get(0).getAn_dsn() : pps.get(0).getAn_undsn();
						} else if (processpoint.rolling_code.equals(pmd.get(0).getNext_process_code())) {
							nums = pps.get(0).getRl_undsn() == 0 ? pps.get(0).getRl_dsn() : pps.get(0).getRl_undsn();
						} else if (processpoint.pickle_code.equals(pmd.get(0).getNext_process_code())) {
							nums = pps.get(0).getPc_undsn() == 0 ? (pps.get(0).getRl_dsn()==null?0d:pps.get(0).getRl_dsn()) : pps.get(0).getPc_undsn();
							//nums = pps.get(0).getPc_undsn() == 0 ? pps.get(0).getRl_dsn() : pps.get(0).getPc_undsn();
						}
						// 订单变更
						this.getBean(MesApiDesignInfoImpl.class).ChangeProcess(pmd, pln.getWhole_process_codes(), -1);
					}

					String[] c_arr = cTypes.split(",");
					for (int i = 0; i < c_arr.length; i++) {
						switch (c_arr[i]) {
						case "0B":
							pps.get(0).setAn_undsn(0d);
							pps.get(0).setAn_dsn(0d);
							pos.get(0).setAn_undsn(0d);
							pos.get(0).setAn_dsn(0d);
							break;
						case "0E":
							pps.get(0).setLw_undsn(0d);
							pps.get(0).setLw_dsn(0d);
							pos.get(0).setLw_undsn(0d);
							pos.get(0).setLw_dsn(0d);
							break;
						case "0D":
							pps.get(0).setCl_undsn(0d);
							pps.get(0).setCl_dsn(0d);
							pos.get(0).setCl_undsn(0d);
							pos.get(0).setCl_dsn(0d);
							break;
						case "0C":
							pps.get(0).setSr_undsn(0d);
							pps.get(0).setSr_dsn(0d);
							pos.get(0).setSr_undsn(0d);
							pos.get(0).setSr_dsn(0d);
						case "0A":
							pps.get(0).setRl_undsn(0d);
							pps.get(0).setRl_dsn(0d);
							pos.get(0).setRl_undsn(0d);
							pos.get(0).setRl_dsn(0d);
						case "0P":
							pps.get(0).setPc_undsn(0d);
							pps.get(0).setPc_dsn(0d);
							pos.get(0).setPc_undsn(0d);
							pos.get(0).setPc_dsn(0d);
							break;
						case "1B":
							pps.get(0).setAn_undsn(nums);
							pos.get(0).setAn_undsn(nums);
							break;
						case "1E":
							pps.get(0).setLw_undsn(nums);
							pos.get(0).setLw_undsn(nums);
							break;
						case "1D":
							pps.get(0).setCl_undsn(nums);
							pos.get(0).setCl_undsn(nums);
							break;
						case "1C":
							pps.get(0).setSr_undsn(nums);
							pos.get(0).setSr_undsn(nums);
							break;
						case "1A":
							pps.get(0).setRl_undsn(nums);
							pos.get(0).setRl_undsn(nums);
							break;
						case "1P":
							pps.get(0).setPc_undsn(nums);
							pos.get(0).setPc_undsn(nums);
							break;
						default:
							break;
						}
					}

					this.getMapper(PlnProdorderStatisticMapper.class).update(pps.get(0));
					this.getMapper(PlnOrderStatisticMapper.class).update(pos.get(0));

					// 获取订单变更申报表
					List<SlmOrderChangeApply> sca = this.getMapper(SlmOrderChangeApplyMapper.class).findWithCondition(
							null, " order_no = '" + pln.getOrder_no() + "'", " create_time desc ", 0, 1);
					// 修改状态已下发
					if (Utils.isNotEmpty(sca)) {
						sca.get(0).setStatus("6");
						this.getMapper(SlmOrderChangeApplyMapper.class).update(sca.get(0));
					}

					// 修改订单状态为接收
					SlmOrderInfo soiu = new SlmOrderInfo();
					soiu.setOrder_no(soiDb.getOrder_no());
					soiu.setOrder_flag_no("103407");
					soiu.setOrder_flag_name("接收");
					this.getMapper(SlmOrderInfoMapper.class).update(soiu);
					rm.setState("200");
				}
			} else {
				// 不是变更订单：
				if (!"103406".equals(soiDb.getOrder_flag_no())) {
					throw new Exception("当前订单[" + soiDb.getContract_no() + soiDb.getContract_line_seq()
							+ soiDb.getOrder_seq() + "]状态已发生改变，无法下发！请刷新页面再操作!");
				}

//				PlnProdorder pp = new PlnProdorder();
//				pp.setOrder_no(soiDb.getContract_no() + soiDb.getContract_line_seq() + soiDb.getOrder_seq());
				int icount = this.getMapper(PlnProdorderMapper.class).count(pp);
				if (icount > 0) {
					throw new Exception("订单[" + soiDb.getContract_no() + soiDb.getContract_line_seq()
							+ soiDb.getOrder_seq() + "]已接收！请刷新页面再操作!");
				}


				p.setSerial_no(++maxId + "");// 自增id
				p.setProd_order_no(No + String.format("%07d", ++iprodCount));
				p.setStatus("0PAA10");
				p.setFinished_status("0"); // 生产未完成
				// p.setMsc_pline("*******调用质量接口获取");
				p.setCreate_man_name(userName);
				p.setCreate_time(new Date());
				// 下面的实际上前端可以传过来
				p.setIs_split(soiDb.getIs_split());
				p.setOrd_pk(soiDb.getOrder_no()); // 销售订单主键
				p.setP_order_no(soiDb.getP_order_no());
				p.setContract_no(soiDb.getContract_no());
				p.setContract_line_no(soiDb.getContract_line_no());
				p.setContract_line_seq(soiDb.getContract_line_seq());
				p.setOrder_no(soiDb.getContract_no() + soiDb.getContract_line_seq() + soiDb.getOrder_seq());
				p.setOrder_seq(soiDb.getOrder_seq());
				p.setOrder_quantity(soiDb.getOrder_quantity());
				p.setQuantity_unit_name(soiDb.getQuantity_unit_name());
				p.setQuantity_unit_no(soiDb.getQuantity_unit_no());
				// 增加整卷发运标志 2018-11-13
				p.setWhole_coil(soiDb.getWhole_coil());
				p.setProcess(soiDb.getProcess());
				p.setChange_flag(soiDb.getChange_flag());
				// 重量数据转换
				p.setEstimate_weight(this.getBean(SlmBaseUnitConversionServiceImpl.class)
						.doUnitConversion(soiDb.getEstimate_weight(), soiDb.getEstimate_weight_unit_no(), "100305"));
				p.setEstimate_weight_unit_name("kg");
				p.setEstimate_weight_unit_no("100305");
				/*
				 * p.setEstimate_weight(soiDb.getEstimate_weight());
				 * p.setEstimate_weight_unit_name(soiDb.getEstimate_weight_unit_name());
				 * p.setEstimate_weight_unit_no(soiDb.getEstimate_weight_unit_no());
				 */

				p.setEnsu_total_len(soiDb.getEnsu_total_len());
				p.setReciver_address(soiDb.getReciver_address());
				p.setReciver_unit_name(soiDb.getReciver_unit_name());
				p.setReciver_unit_no(soiDb.getReciver_unit_no());
				p.setDeliver_date(soiDb.getDeliver_date());
				p.setSend_time(soiDb.getIssuer_time());
				p.setSend_man_name(soiDb.getIssuer_man_name());

				// 有且仅有一条，合同头信息
				SlmContractHeatInfo schi = new SlmContractHeatInfo();
				schi.setContract_no(soiDb.getContract_no());
				List<SlmContractHeatInfo> lschis = this.getMapper(SlmContractHeatInfoMapper.class).find(schi, 0, 0);
				p.setTxt_contract_no(lschis.get(0).getTxt_contract_no());
				p.setContract_type_no(lschis.get(0).getContract_type_no());
				p.setContract_type_name(lschis.get(0).getContract_type_name());
				p.setCustomer_no(lschis.get(0).getCustomer_no());
				p.setCustomer_name(lschis.get(0).getCustomer_name());

				// 合同行信息
				SlmContractLineInfo scli = new SlmContractLineInfo();
				scli.setContract_line_no(p.getContract_line_no());
				List<SlmContractLineInfo> lschi = this.getMapper(SlmContractLineInfoMapper.class).find(scli, 0, 0);

				p.setPk_ask_code(lschi.get(0).getPk_ask_code());
				p.setPk_ask_desc(lschi.get(0).getPk_ask_desc());
				
				// 订单估算重量 合同行最大重量/合同重量*订单重量=最大值 合同行最大重量/合同重量*订单重量=最小值
				DecimalFormat df = new DecimalFormat("#.00");
				// 得到两个值的比例
				double max = Double.parseDouble(df.format(lschi.get(0).getDelivery_error_max().doubleValue()
						/ lschi.get(0).getEstimate_weight().doubleValue()));
				double min = Double.parseDouble(df.format(lschi.get(0).getDelivery_error_min().doubleValue()
						/ lschi.get(0).getEstimate_weight().doubleValue()));

				p.setPsc(lschi.get(0).getPsc());
				p.setPsc_desc(lschi.get(0).getPsc_desc());
				// SLM_ORDER_INFO没有则找SLM_CONTRACT_LINE_INFO
				p.setMsc(soiDb.getMsc() == null ? lschi.get(0).getMsc() : soiDb.getMsc());
				p.setMsc_desc(soiDb.getMsc_desc() == null ? lschi.get(0).getMsc_desc() : soiDb.getMsc_desc());
				p.setMsc_type_no(
						soiDb.getMsc_type_no() == null ? lschi.get(0).getMsc_type_no() : soiDb.getMsc_type_no());
				p.setMsc_type_name(
						soiDb.getMsc_type_name() == null ? lschi.get(0).getMsc_type_name() : soiDb.getMsc_type_name());

				p.setUse_code(soiDb.getUse_code() == null ? lschi.get(0).getUse_code() : soiDb.getUse_code());
				p.setUse_desc(soiDb.getUse_desc() == null ? lschi.get(0).getUse_desc() : soiDb.getUse_desc());
				p.setProd_cls_no(
						soiDb.getProd_cls_no() == null ? lschi.get(0).getProd_cls_no() : soiDb.getProd_cls_no());
				p.setProd_cls_name(
						soiDb.getProd_cls_name() == null ? lschi.get(0).getProd_cls_name() : soiDb.getProd_cls_name());
				p.setProd_code(soiDb.getProd_code() == null ? lschi.get(0).getProd_code() : soiDb.getProd_code());
				p.setProd_name(soiDb.getProd_name() == null ? lschi.get(0).getProd_name() : soiDb.getProd_name());
				p.setStd_code(soiDb.getStd_code() == null ? lschi.get(0).getStd_code() : soiDb.getStd_code());
				p.setStd_name(soiDb.getStd_name() == null ? lschi.get(0).getStd_name() : soiDb.getStd_name());
				p.setSteel_code(soiDb.getSteel_code() == null ? lschi.get(0).getSteel_code() : soiDb.getSteel_code());
				p.setSteel_name(soiDb.getSteel_name() == null ? lschi.get(0).getSteel_name() : soiDb.getSteel_name());
				p.setStd_type_no(
						soiDb.getStd_type_no() == null ? lschi.get(0).getStd_type_no() : soiDb.getStd_type_no());
				p.setStd_type_name(
						soiDb.getStd_type_name() == null ? lschi.get(0).getStd_type_name() : soiDb.getStd_type_name());
				p.setProd_figure_no(soiDb.getProd_figure_no() == null ? lschi.get(0).getProd_figure_no()
						: soiDb.getProd_figure_no());
				p.setProd_figure_name(soiDb.getProd_figure_name() == null ? lschi.get(0).getProd_figure_name()
						: soiDb.getProd_figure_name());
				p.setOrder_nature(soiDb.getOrder_nature());

				p.setDelivery_weight_type(lschi.get(0).getDelivery_weight_type());
				p.setDelivery_error_max(p.getEstimate_weight().doubleValue() * max);
				p.setDelivery_error_min(p.getEstimate_weight().doubleValue() * min);
				p.setDelivery_unit_no("100305");
				p.setDelivery_unit_name("kg");
				p.setWeight_type_no(lschi.get(0).getWeight_type_no());
				p.setWeight_type_name(lschi.get(0).getWeight_type_name());
				// p.setSingle_weight( lschi.get(0).getSingle_weight());
				p.setSingle_weight(this.getBean(SlmBaseUnitConversionServiceImpl.class).doUnitConversion(
						lschi.get(0).getSingle_weight(), lschi.get(0).getSingle_weight_unit_no(), "100305"));
				p.setSingle_weight_max(this.getBean(SlmBaseUnitConversionServiceImpl.class).doUnitConversion(
						lschi.get(0).getSingle_weight_max(), lschi.get(0).getSingle_weight_unit_no(), "100305"));
				p.setSingle_weight_min(this.getBean(SlmBaseUnitConversionServiceImpl.class).doUnitConversion(
						lschi.get(0).getSingle_weight_min(), lschi.get(0).getSingle_weight_unit_no(), "100305"));
				p.setSingle_weight_unit_no("100305");
				p.setSingle_weight_unit_name("kg");

				p.setSingle_length(lschi.get(0).getSingle_length());
				p.setSingle_length_max(lschi.get(0).getSingle_length_max());
				p.setSingle_length_min(lschi.get(0).getSingle_length_min());
				p.setCnt_number(lschi.get(0).getCnt_number());
				p.setFixed_length_type_no(lschi.get(0).getFixed_length_type_no());
				p.setFixed_length_type_name(lschi.get(0).getFixed_length_type_name());

				p.setCut_edge_type_no(lschi.get(0).getCut_edge_type_no());
				p.setCut_edge_type_name(lschi.get(0).getCut_edge_type_name());

				p.setDiameter_inn(lschi.get(0).getDiameter_inn());
				p.setDiameter_inn_max(lschi.get(0).getDiameter_inn_max());
				p.setDiameter_inn_min(lschi.get(0).getDiameter_inn_min());
				p.setDiameter_inn_unit_no(lschi.get(0).getDiameter_inn_unit_no());
				p.setDiameter_inn_unit_name(lschi.get(0).getDiameter_inn_unit_name());

				p.setSpec_other(lschi.get(0).getSpec_other());

				p.setDiameter_out(lschi.get(0).getDiameter_out());
				p.setDiameter_out_max(lschi.get(0).getDiameter_out_max());
				p.setDiameter_out_min(lschi.get(0).getDiameter_out_min());
				p.setDiameter_out_unit_no(lschi.get(0).getDiameter_out_unit_no());
				p.setDiameter_out_unit_name(lschi.get(0).getDiameter_out_unit_name());

				p.setThick(this.getBean(SlmBaseUnitConversionServiceImpl.class)
						.doUnitConversion(lschi.get(0).getThick(), lschi.get(0).getThick_unit_no(), "100304 "));
				p.setThick_max(this.getBean(SlmBaseUnitConversionServiceImpl.class)
						.doUnitConversion(lschi.get(0).getThick_max(), lschi.get(0).getThick_unit_no(), "100304 "));
				p.setThick_min(this.getBean(SlmBaseUnitConversionServiceImpl.class)
						.doUnitConversion(lschi.get(0).getThick_min(), lschi.get(0).getThick_unit_no(), "100304 "));
				p.setThick_unit_no("100304");
				p.setThick_unit_name("mm");

				p.setDiam(lschi.get(0).getDiameter_inn());
				p.setDiam_up(lschi.get(0).getDiameter_inn_max());
				p.setDiam_down(lschi.get(0).getDiameter_inn_min());
				p.setDiam_unit_no(lschi.get(0).getDiameter_inn_unit_no());
				p.setDiam_unit_name(lschi.get(0).getDiameter_inn_unit_name());

				p.setWidth(this.getBean(SlmBaseUnitConversionServiceImpl.class)
						.doUnitConversion(lschi.get(0).getWidth(), lschi.get(0).getWidth_unit_no(), "100304 "));
				p.setWidth_max(this.getBean(SlmBaseUnitConversionServiceImpl.class)
						.doUnitConversion(lschi.get(0).getWidth_max(), lschi.get(0).getWidth_unit_no(), "100304 "));
				p.setWidth_min(this.getBean(SlmBaseUnitConversionServiceImpl.class)
						.doUnitConversion(lschi.get(0).getWidth_min(), lschi.get(0).getWidth_unit_no(), "100304 "));
				p.setWidth_unit_no("100304");
				p.setWidth_unit_name("mm");

				p.setLength(this.getBean(SlmBaseUnitConversionServiceImpl.class)
						.doUnitConversion(lschi.get(0).getLength(), lschi.get(0).getLengt_no(), "100304 "));
				p.setLength_max(this.getBean(SlmBaseUnitConversionServiceImpl.class)
						.doUnitConversion(lschi.get(0).getLength_max(), lschi.get(0).getLengt_no(), "100304 "));
				p.setLength_min(this.getBean(SlmBaseUnitConversionServiceImpl.class)
						.doUnitConversion(lschi.get(0).getLength_min(), lschi.get(0).getLengt_no(), "100304 "));
				p.setLength_unit_no("100304");
				p.setLength_unit_name("mm");

				p.setShort_ruler_ratio(lschi.get(0).getShort_ruler_ratio());
				p.setShort_ruler_length(lschi.get(0).getShort_ruler_length());
				p.setShort_ruler_unit_no(lschi.get(0).getShort_ruler_unit_no());
				p.setShort_ruler_unit_name(lschi.get(0).getShort_ruler_unit_name());
				p.setLong_ruler_ratio(lschi.get(0).getLong_ruler_ratio());
				p.setLong_ruler_length(lschi.get(0).getLong_ruler_length());
				p.setLong_ruler_unit_no(lschi.get(0).getLong_ruler_unit_no());
				p.setLong_ruler_unit_name(lschi.get(0).getLong_ruler_unit_name());
				p.setIs_together(lschi.get(0).getIs_together());
				p.setOut_average_length(lschi.get(0).getOut_average_length());
				p.setAverage_length_unit_no(lschi.get(0).getAverage_length_unit_no());
				p.setAverage_length_unit_name(lschi.get(0).getAverage_length_unit_name());
				p.setLong_and_short(lschi.get(0).getLong_and_short());
				p.setLas_unit_no(lschi.get(0).getLas_unit_no());
				p.setLas_unit_name(lschi.get(0).getLas_unit_name());
				p.setTolerance(lschi.get(0).getTolerance());
				p.setTolerance_unit_no(lschi.get(0).getTolerance_unit_no());
				p.setTolerance_unit_name(lschi.get(0).getTolerance_unit_name());
				p.setSingle_ruler_length(lschi.get(0).getSingle_ruler_length());
				p.setSrl_unit_no(lschi.get(0).getSrl_unit_no());
				p.setSrl_unit_name(lschi.get(0).getSrl_unit_name());
				p.setModel_code(lschi.get(0).getModel_code());
				p.setModel_name(lschi.get(0).getModel_name());
				p.setUser_no(lschi.get(0).getUser_no());
				p.setUser_name(lschi.get(0).getUser_name());
				p.setAdd_ask_no(lschi.get(0).getAdd_ask_no());
				p.setAdd_ask_desc(lschi.get(0).getAdd_ask_desc());
				p.setCustomer_alpha_no(lschi.get(0).getCustomer_alpha_no());
				p.setCustomer_alpha_desc(lschi.get(0).getCustomer_alpha_desc());
				p.setDelivery_state_code(lschi.get(0).getDelivery_state_code());
				p.setDelivery_state_desc(lschi.get(0).getDelivery_state_desc());
				p.setProduce_no("PN" + No + String.format("%05d", produceNo));

				p.setContract_memo(lschi.get(0).getMemo());
				p.setOrder_memo(soiDb.getMemo());
				// 20180417 采购合同号
				p.setPurchase_contract_no(soiDb.getPurchase_contract_no());

				SlmProcessPlan spp = new SlmProcessPlan();
				spp.setContract_no(soiDb.getContract_no());
				spp.setContract_line_seq(soiDb.getContract_line_seq());
				spp.setOrder_seq(soiDb.getOrder_seq());
				spp.setValid_flag("1");
				List<SlmProcessPlan> lspp = new ArrayList<>();
				// 整卷发运的订单可能有加工计划有的没有
				if (!"1".equals(soiDb.getOrder_nature()) && !"3".equals(soiDb.getOrder_nature())) {
					lspp = this.getMapper(SlmProcessPlanMapper.class).findWithCondition(spp, null, " cut_order_no ", 0,
							0);

					// 如果是2需加工，4冷轧，5酸洗订单的话，自动新增加工计划：20231006刘侣
					if(Utils.isEmpty(lspp)) {
						SlmProcessPlan sa = new SlmProcessPlan();
						sa.setPlan_no(soiDb.getOrder_no()); // 订单表的orderno
						sa.setContract_no(soiDb.getContract_no());
						sa.setContract_line_seq(soiDb.getContract_line_seq());
						sa.setOrder_seq(soiDb.getOrder_seq());
						sa.setContract_line_no(soiDb.getContract_line_no());
						sa.setSteel_code(soiDb.getSteel_code());
						sa.setSteel_name(soiDb.getSteel_name());
						sa.setSpec("" + p.getThick() + "*" + p.getWidth());
						sa.setCut_type("0");
						sa.setEstimate_weight(p.getEstimate_weight());
						sa.setEstimate_weight_unit_no(p.getEstimate_weight_unit_no());
						sa.setEstimate_weight_unit_name(p.getEstimate_weight_unit_name());
						sa.setValid_flag("1");
						sa.setCreate_man_no("admin");
						sa.setCreate_man_name("admin");
						sa.setCreate_time(new Date());
						sa.setCut_order_no(1L);
						sa.setOrder_no(soiDb.getOrder_no());
						sa.setThick(p.getThick());
						sa.setWidth(p.getWidth());
						sa.setCut_num(1L);
						sa.setMsc_desc(p.getMsc_desc());
						sa.setPlan_flag("103414");
						sa.setReview_man_name("admin");
						sa.setReview_man_no("admin");
						sa.setReview_time(new Date());
						this.getMapper(SlmProcessPlanMapper.class).insert(sa);
					}
					
					lspp = this.getMapper(SlmProcessPlanMapper.class).findWithCondition(spp, null, " cut_order_no ", 0,
							0);
					
					
					if(Utils.isNotEmpty(lspp)) {
						if (!"1".equals(p.getWhole_coil())) {
							List<SlmOrdDesignMscPl> msc_pline = new ArrayList<SlmOrdDesignMscPl>();
							// 选择design_key 以及制程产线确认,只有需加工订单才确认制程产线
							PlnProdorderExtinfo ppextinfo = new PlnProdorderExtinfo();
							ppextinfo.setProd_order_no(p.getProd_order_no());
							ppextinfo.setOrder_no(p.getOrder_no());
		
							// 如果只有一条加工计划并且是不切直接取一条工艺路径
							if (lspp.size() == 1 && lspp.get(0).getCut_type().equals("0")) {
								// 1、获取design_key
								SlmOrdDesignMsc som = new SlmOrdDesignMsc();
								som.setContract_line_no(lspp.get(0).getContract_no() + lspp.get(0).getOrder_seq()); // 通过加工计划号找design_key：planno就是订单表的orderno：这里得给：合同号 + 订单序号
								CommonPage<SlmOrdDesignMsc> sodm = new CommonPage<SlmOrdDesignMsc>();
								sodm.setObject(som);
								// 得到设计主表的design_key: 主键号；
								ResultModel result_DK = this.getBean(QmsApiServiceImpl.class).GetAllByDesignKey(sodm);
								if (!"200".equals(result_DK.getState())) {
									throw new Exception("自动确认制程产线失败!" + result_DK.getMsgInfo());
								}
								// 2、获取工艺路径：获取设计从表内的工艺路径
								List<SlmOrdDesignMsc> design_key = (List<SlmOrdDesignMsc>) result_DK.getData();
								ResultModel result_ZC = this.getBean(MesApiDesignInfoImpl.class)
										.GetMscByDesignKey(design_key.get(0).getDesign_key());
								if (!"200".equals(result_ZC.getState())) {
									throw new Exception("自动确认工艺路径失败!" + result_ZC.getMsgInfo());
								}
								msc_pline = (List<SlmOrdDesignMscPl>) result_ZC.getData();
								if (design_key.size() > 1 || msc_pline.size() > 1) {
									ppextinfo.setHas_multi_procedure(1l);
								} else {
									ppextinfo.setHas_multi_procedure(0l);
								}
								
								p.setDesign_key(design_key.get(0).getDesign_key());
								p.setMsc_pline(msc_pline.get(0).getMsc_pline());
								p.setWhole_process_codes(msc_pline.get(0).getStations_code());
								p.setWhole_process_names(msc_pline.get(0).getStations_desc());
								p.setWhole_process_seqs(msc_pline.get(0).getWarn_desc());

								// 获取道工艺路径后最好比对下订单内的工艺路径process：20230920刘侣
								if (soiDb.getProcess() == null) {
									throw new Exception("未找到订单的工艺路径：" + soiDb.getProcess());
								}
								String processQ = soiDb.getProcess().replaceAll("\\d", "");
								if (!processQ.equals(p.getWhole_process_names())) {
									throw new Exception("生产订单的工艺路径("+ p.getWhole_process_names() +")和订单的工艺路径("+ processQ +")不一致，请联系管理员");
								}
								// end
								
								this.getMapper(PlnProdorderExtinfoMapper.class).insert(ppextinfo);
							} else {
								// 2018-09-04 自动选择design_key 制程
								// plan : <design_key : 制程对象集合>
								List<Map<String, Map<String, List<SlmOrdDesignMscPl>>>> params = new ArrayList<>();
								SlmOrdDesignMscPl rst_path = new SlmOrdDesignMscPl();
								String rst_design_key = "";
								int i = 0;
								boolean flag_cross_cutting = false, flag_slitting = false;
								// 获取公共工艺路径
								for (SlmProcessPlan slm : lspp) {
									if (slm.getCut_type().equals("1")) {
										flag_cross_cutting = true;
									} else if (slm.getCut_type().equals("2")) {
										flag_slitting = true;
									} else if (slm.getCut_type().equals("3")) {
										flag_cross_cutting = true;
										flag_slitting = true;
									}
									Map<String, List<SlmOrdDesignMscPl>> map = new HashMap<String, List<SlmOrdDesignMscPl>>();
									Map<String, Map<String, List<SlmOrdDesignMscPl>>> plan_no = new HashMap<String, Map<String, List<SlmOrdDesignMscPl>>>();
									// 1、获取design_key
									SlmOrdDesignMsc som = new SlmOrdDesignMsc();
									som.setContract_line_no(lspp.get(0).getContract_no() + lspp.get(0).getOrder_seq()); // 通过加工计划号找design_key
									CommonPage<SlmOrdDesignMsc> sodm = new CommonPage<SlmOrdDesignMsc>();
									sodm.setObject(som);
									ResultModel result_DK = this.getBean(QmsApiServiceImpl.class).GetAllByDesignKey(sodm);
									if (!"200".equals(result_DK.getState())) {
										throw new Exception("自动确认制程产线失败!" + result_DK.getMsgInfo());
									}
									// 2、获取工艺路径
									List<SlmOrdDesignMsc> design_key = (List<SlmOrdDesignMsc>) result_DK.getData();
									for (SlmOrdDesignMsc design : design_key) {
										ResultModel result_ZC = this.getBean(MesApiDesignInfoImpl.class)
												.GetMscByDesignKey(design.getDesign_key());
										if (!"200".equals(result_ZC.getState())) {
											throw new Exception("自动确认工艺路径失败!" + result_ZC.getMsgInfo());
										}
										msc_pline = (List<SlmOrdDesignMscPl>) result_ZC.getData();
										map.put(design.getDesign_key(), msc_pline);
									}
									plan_no.put(slm.getPlan_no(), map);
									params.add(plan_no);
								}
								// design : 制程对象集合
								Map<String, List<SlmOrdDesignMscPl>> result = getCommonPath(params);
								if (Utils.isNotEmpty(result)) {
									if (result.size() > 1) {
										ppextinfo.setHas_multi_procedure(1l);
									} else {
										ppextinfo.setHas_multi_procedure(0l);
									}
									for (Entry<String, List<SlmOrdDesignMscPl>> map : result.entrySet()) {
										// 取第一个赋值
										if (i == 0) {
											rst_design_key = map.getKey();
											rst_path = map.getValue().get(0);
										}
										break;
									}
									if (Utils.isNotEmpty(rst_path.getStations_code())) {
										// 开平找不到加工计划报错
										if (rst_path.getStations_code().contains(processpoint.cross_cutting_code)
												&& !flag_cross_cutting) {
											throw new Exception("工艺路径中包含开平工序,但是不存在开平加工计划!请重新质量设计!");
										} else if (rst_path.getStations_code().contains(processpoint.slitting_code)
												&& !flag_slitting) {
											throw new Exception("工艺路径中包含分条工序,但是不存在分条加工计划!请重新质量设计!");
										}
		
									}
									p.setDesign_key(rst_design_key);
									p.setMsc_pline(rst_path.getMsc_pline());
									p.setWhole_process_codes(rst_path.getStations_code());
									p.setWhole_process_names(rst_path.getStations_desc());
									p.setWhole_process_seqs(rst_path.getWarn_desc());
									
									// 获取道工艺路径后最好比对下订单内的工艺路径process：20230920刘侣
									if (soiDb.getProcess() == null) {
										throw new Exception("未找到订单的工艺路径：" + soiDb.getProcess());
									}
									String processQ = soiDb.getProcess().replaceAll("\\d", "");
									if (!processQ.equals(p.getWhole_process_names())) {
										throw new Exception("生产订单的工艺路径("+ p.getWhole_process_names() +")和订单的工艺路径("+ processQ +")不一致，请联系管理员");
									}
									// end
									
									this.getMapper(PlnProdorderExtinfoMapper.class).insert(ppextinfo);
								}
							}
						}
					} else if (!"1".equals(p.getWhole_coil()) ) {
						throw new Exception("订单[" + soiDb.getOrder_no() + "]对应的加工计划信息未找到！");
					}
					// 2019-07-19 质量不维护次工艺参数取消验证
					// 如果存在轧制工序 ,判断厚度范围是否符合
//					if (p.getWhole_process_codes().contains(processpoint.rolling_code)) {
//						SlmOrdDesignMscPlSti sti = new SlmOrdDesignMscPlSti();
//						List<SlmOrdDesignMscTic> tics = new ArrayList<SlmOrdDesignMscTic>();
//						sti.setDesign_key(p.getDesign_key());
//						sti.setMsc_pline(p.getMsc_pline());
//						sti.setProcess_code(processpoint.rolling_code);
//						// 只查询工艺类工序点
//						sti.setProcess_point_type("403206");
//						List<SlmOrdDesignMscPlSti> stis = this.getBean(MesApiDesignInfoImpl.class).getQcmDesignInfo(sti);
//						if(Utils.isNotEmpty(stis)) {
//							for (SlmOrdDesignMscPlSti pl : stis) {
//								SlmOrdDesignMscTic tmp = new SlmOrdDesignMscTic();
//								BeanUtils.copyProperties(pl, tmp);
//								tmp.setPline_code("C016");
//								tmp.setMachine_code("M0008");
//								tics.add(tmp);
//							}
//							this.getBean(MesApiDesignInfoImpl.class).checkFirstProc(tics, p.getThick());
//							this.getBean(MesApiDesignInfoImpl.class).checkLastProc(tics, p.getThick());
//							this.getBean(MesApiDesignInfoImpl.class).comp_Proc_Std(tics);
//						}
//					}
				} else {
					// 20180417 从0417开始，销售的[原料卷]类型订单，不下发加工计划。 为了保持逻辑统一减少修改，生产接收时，自动生成一条加工计划。
					SlmProcessPlan sppc = new SlmProcessPlan();

					sppc.setPlan_no("0001");
					sppc.setPurchase_contract_no(p.getPurchase_contract_no());
					sppc.setSteel_code(p.getSteel_code());
					sppc.setSteel_name(p.getSteel_name());
					sppc.setSpec("" + p.getThick() + "*" + p.getWidth());
					sppc.setWidth(p.getWidth());
					sppc.setThick(p.getThick());
					sppc.setLen(p.getLength());
					sppc.setEstimate_weight(p.getEstimate_weight());
					sppc.setEstimate_weight_unit_no("100305");// 千克kg
					sppc.setCrosscut_stype("1");// 1：不横切
					sppc.setCut_type("0");// 0：不切
					sppc.setCut_num(1L);
					sppc.setMemo(p.getProcessMemo());
					sppc.setValid_flag("1");
					sppc.setCreate_man_name(userName);
					sppc.setCreate_time(new Date());
					lspp.add(sppc);
				}
				this.getMapper(PlnProdorderMapper.class).insert(p);
				// 将可能存在的订单号相同的数据设置为不可用
				PlnProcessPlan pppu = new PlnProcessPlan();
				pppu.setOrder_no(p.getOrder_no());
				pppu.setValid_flag("0");
				this.getMapper(PlnProcessPlanMapper.class).doUpdate(pppu);

				// 新建加工计划表[PLN_PROCESS_PLAN]记录：（一个订单对应多条记录，要全部从销售加工计划表复制过来）
				String sCutStyle = "";
				double width_total = 0;
				List<PlnProcessPlan> lppp = new ArrayList<PlnProcessPlan>();
				long cutOrdNo = 1;
				for (SlmProcessPlan sppc : lspp) {
					PlnProcessPlan ppp = new PlnProcessPlan();
					ppp.setProduce_no(p.getProduce_no());
					ppp.setPlan_no(sppc.getPlan_no());
					ppp.setCut_order_no(cutOrdNo++);
					ppp.setOrder_no(p.getOrder_no());
					ppp.setPurchase_contract_no(sppc.getPurchase_contract_no());
					ppp.setSteel_code(sppc.getSteel_code());
					ppp.setSteel_name(sppc.getSteel_name());
					ppp.setSpec(sppc.getSpec());
					ppp.setWidth(this.getBean(SlmBaseUnitConversionServiceImpl.class).doUnitConversion(sppc.getWidth(),
							lschi.get(0).getWidth_unit_no(), "100304 "));
					ppp.setThick(this.getBean(SlmBaseUnitConversionServiceImpl.class).doUnitConversion(sppc.getThick(),
							lschi.get(0).getThick_unit_no(), "100304 "));
					ppp.setLength(this.getBean(SlmBaseUnitConversionServiceImpl.class).doUnitConversion(sppc.getLen(),
							lschi.get(0).getLengt_no(), "100304 "));
					ppp.setEstimate_weight(this.getBean(SlmBaseUnitConversionServiceImpl.class)
							.doUnitConversion(sppc.getEstimate_weight(), sppc.getEstimate_weight_unit_no(), "100305"));
					if (Utils.isNotEmpty(lschi.get(0).getWidth())) {
						if (lschi.get(0).getWidth() <= 0) {
							throw new Exception("订单[" + soiDb.getOrder_no() + "]对应的加工计划[" + sppc.getPlan_no() + "]的宽度错误！");
						}
						ppp.setMat_width(this.getBean(SlmBaseUnitConversionServiceImpl.class)
								.doUnitConversion(lschi.get(0).getWidth(), lschi.get(0).getWidth_unit_no(), "100304 "));
						
					}
					if (Utils.isNotEmpty(lschi.get(0).getThick())) {
						if (lschi.get(0).getThick() <= 0) {
							throw new Exception("订单[" + soiDb.getOrder_no() + "]对应的加工计划[" + sppc.getPlan_no() + "]的厚度错误！");
						}
						ppp.setMat_thick(this.getBean(SlmBaseUnitConversionServiceImpl.class)
								.doUnitConversion(lschi.get(0).getThick(), lschi.get(0).getThick_unit_no(), "100304 "));
					}

					if (sppc.getCrosscut_stype() != null && !"".equals(sppc.getCrosscut_stype())) {
						try {
							int i = Integer.parseInt(sppc.getCrosscut_stype().trim());
							switch (i) {
							case 1:
							case 2:
							case 3:
							case 4:
							case 5:
							case 6:
							case 7:
							case 8:
								ppp.setCrosscut_style(sppc.getCrosscut_stype().trim());
								break;
							default:
								ppp.setCrosscut_style("1");
								break;
							}
						} catch (Exception ex) {
							throw new Exception(
									"订单[" + soiDb.getOrder_no() + "]对应的加工计划[" + sppc.getPlan_no() + "]的横切方式错误！");
						}
					}

					ppp.setCut_type(sppc.getCut_type());
					ppp.setCut_num(sppc.getCut_num());
					ppp.setRemark(sppc.getMemo());
					ppp.setValid_flag(sppc.getValid_flag());
					ppp.setCreate_man_name(userName);
					ppp.setCreate_time(new Date());

					ppp.setWall_thick(this.getBean(SlmBaseUnitConversionServiceImpl.class)
							.doUnitConversion(sppc.getWall_thick(), lschi.get(0).getThick_unit_no(), "100304 "));
					ppp.setMono_stack_max_weight(this.getBean(SlmBaseUnitConversionServiceImpl.class).doUnitConversion(
							sppc.getMono_stack_max_weight(), sppc.getEstimate_weight_unit_no(), "100305"));
					ppp.setMono_stack_min_weight(this.getBean(SlmBaseUnitConversionServiceImpl.class).doUnitConversion(
							sppc.getMono_stack_min_weight(), sppc.getEstimate_weight_unit_no(), "100305"));

					lppp.add(ppp);

					if (sppc.getCut_type() != null && "1".equals(sppc.getCut_type())) { // 横剪
						double weightupper = 0;
//					 读取基础配置 产线机组限制表
						ComDsnPltlmt cdp = new ComDsnPltlmt();
						cdp.setPlt("Y1");// 工厂
						cdp.setPlt_line("Y1");// 产线
						List<ComDsnPltlmt> lc = this.getMapper(ComDsnPltlmtMapper.class).find(cdp, 0, 0);
						if (lc == null || lc.size() == 0) {
							throw new Exception("未找到产线");
						}
//					 获取所有的限制条件
						ClRestrict MachineRestrict = new ClRestrict(lc);
						if (ppp.getMono_stack_max_weight() == null) {
							weightupper = MachineRestrict.lim_max_box_wgt;
						} else if (ppp.getMono_stack_max_weight() != null) {
							weightupper = ppp.getMono_stack_max_weight();
							if (ppp.getMono_stack_max_weight().doubleValue() - MachineRestrict.lim_max_box_wgt > 0) {
								throw new Exception("订单[" + soiDb.getOrder_no() + "]的加工计划中单剁重量上限(单位是吨)超出设备重量限制!");
							}
						}
						// 获取子堆垛总数和单堆垛块数
						// Double[] result =
						// this.getBean(MesApiCrCrossCuttingMServiceImpl.class).getBoxCount(ppp,MachineRestrict.lim_max_box_height);
						// 子板重量
						// double subweight
						// =this.getBean(MesApiCrCrossCuttingMServiceImpl.class).GetWeightBySize(ppp.getThick(),
						// ppp.getWidth(), ppp.getLength());
						if (ppp.getLength() != null) {
							sCutStyle += ppp.getLength().doubleValue() + "*"
									+ new BigDecimal(p.getEstimate_weight() / 1000)
											.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue()
									+ "T(" + new BigDecimal(weightupper / 1000).setScale(1, BigDecimal.ROUND_HALF_UP)
											.doubleValue()
									+ "T)+";
						}
					} else if (sppc.getCut_type() != null && "2".equals(sppc.getCut_type())) {// 纵剪
						sCutStyle += ppp.getWidth().doubleValue() + "*" + ppp.getCut_num().intValue() + "+";
						width_total += ppp.getWidth().doubleValue() * ppp.getCut_num().intValue();
					}
				}
				// 有不切的情况
				if (sCutStyle != null && !"".equals(sCutStyle)) {
					sCutStyle = sCutStyle.substring(0, sCutStyle.length() - 1);
				}
				for (PlnProcessPlan ppp : lppp) {
					if (lppp.size() >= 1) {
						ppp.setCut_style(sCutStyle);
						if (ppp.getCut_type() != null && "2".equals(ppp.getCut_type())) {
							ppp.setWidth_total(width_total);
						}
					}
					this.getMapper(PlnProcessPlanMapper.class).insert(ppp);
				}

				// 新建 订单进程表
				PlnOrderStatistic pos = new PlnOrderStatistic();
				pos.setSerial_no(++iPOSCount + "");
				pos.setOrder_no(p.getOrder_no());
				pos.setOrdered(p.getEstimate_weight());
				pos.setUnscheduled(p.getEstimate_weight());

				// 新建 生产订单进程表
				PlnProdorderStatistic pps = new PlnProdorderStatistic();
				pps.setOrder_no(p.getOrder_no());
				pps.setSerial_no(++iPPSCount + "");
				pps.setProd_order_no(p.getProd_order_no());
				pps.setProd_ordered(p.getEstimate_weight());
				pps.setUnscheduled(p.getEstimate_weight());

				// 订单最后一个需要坯料设计的工序 E0002为分条
				/*
				 * String WrkCode=this.getBean(QmsApiServiceImpl.class).GetWrkPlanCode("");
				 * if(processpoint.slitting_code.equals(WrkCode)){ //如果最后工序是分条，则填写：LW_UNDSN
				 * 欠分条设计_成品量=订单总量；LW_UNDSN_CNT 欠分条设计_成品数=订单总量
				 * pos.setLw_undsn(p.getEstimate_weight());
				 * pps.setLw_undsn(p.getEstimate_weight()); }
				 */

				// 验证生产订单表是否生成：20230413刘侣
				PlnProdorder pd = new PlnProdorder();
				pd.setProd_order_no(p.getProd_order_no());
				List<PlnProdorder> po = this.getMapper(PlnProdorderMapper.class).find(pd, 0, 0);
				if (po == null || po.size() == 0) {
					throw new Exception(p.getOrder_no() + " 未生成生产订单数据， 请联系管理员");
				}
				// end
				
				this.getMapper(PlnOrderStatisticMapper.class).insert(pos);
				this.getMapper(PlnProdorderStatisticMapper.class).insert(pps);

				// 修改订单状态为接收
				SlmOrderInfo soiu = new SlmOrderInfo();
				soiu.setOrder_no(soi.getOrder_no());
				soiu.setOrder_flag_no("103407");
				soiu.setOrder_flag_name("接收");
				this.getMapper(SlmOrderInfoMapper.class).update(soiu);
				rm.setState("200");
			}
		}
		return rm;
	}

	
	
	
	
	
	/**
	 * 订单回退
	 * 
	 * @throws Exception
	 */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doOrderBackWeb(CommonPage<PlnProdorder> sum) throws Exception {
		ResultModel rm = new ResultModel();

		List<PlnProdorder> lpc = sum.getObjectList();
		if (lpc == null || lpc.size() == 0) {
			rm.setState("500");
			rm.setMsgInfo("请传入参数！");
			return rm;
		}
		for (PlnProdorder p : lpc) {
			PlnProdorder pp = new PlnProdorder();
			// pp.setProd_order_no(p.getProd_order_no());
			pp.setOrder_no(p.getOrder_no());
			List<PlnProdorder> lpp = this.getMapper(PlnProdorderMapper.class).find(pp, 0, 0);
			if (lpp == null || lpp.size() == 0) {
				// 2018-11-29 防止多页面操作作此修改
//				continue;
				throw new Exception("未找到订单" + p.getOrder_no() + "信息！请刷新页面再操作!");
			}

			for (PlnProdorder ppc : lpp) {
				if (ppc.getStatus().compareTo("0PAA10") > 0) {
					throw new Exception("订单" + ppc.getProd_order_no() + "已下发生产，不能回退！");
				}
			}

			List<HashMap> list = this.getMapper(PlnProdorderStatisticMapper.class).doQuerySum(pp.getOrder_no());
			if (Integer.parseInt(list.get(0).get("UNSCHEDULED").toString()) < Integer
					.parseInt(list.get(0).get("ORDERED").toString())) {
				if (lpc.size() == 1) {
					//rm.setState("500");
					//rm.setMsgInfo("订单" + p.getProd_order_no() + "已部分排产或充当，不能回退！");
					//return rm;
				}
				//throw new Exception("订单" + p.getProd_order_no() + "已部分排产或充当，不能回退！");
			}
			
			// 存在只挂单出库，然后还能回退的情况，加上只要挂过单就不允许回退的限制：20230617刘侣
//			PlnMaterielDetail ispmd = new PlnMaterielDetail();
//			ispmd.setOrder_no(p.getOrder_no());
//			List<PlnMaterielDetail> islpmd = this.getMapper(PlnMaterielDetailMapper.class).find(ispmd, 0, 0);
//			if (islpmd.size() > 0) {
//				throw new Exception("订单" + p.getOrder_no() + "已经挂过单，不允许订单回退");
//			}
			
			// 修改逻辑，订单上没有卷且订单没有下过提单：20230824刘侣
			YdmProductDetail ypd = new YdmProductDetail();
			ypd.setOrderno(p.getOrder_no());
			// 且在库：20240822刘侣
			ypd.setState("0");
			
			int count1 = this.getMapper(YdmProductDetailMapper.class).count(ypd);
			if (count1 > 0) {
				throw new Exception("订单" + p.getOrder_no() + "存在未脱单的卷，不允许订单回退");
			}
			
			SlmLadingBillDetail sd = new SlmLadingBillDetail();
			sd.setOrder_no(p.getOrder_no());
			int count2 = this.getMapper(SlmLadingBillDetailMapper.class).count(sd);
			if (count2 > 0) {
				throw new Exception("订单" + p.getOrder_no() + "已经发过货，不允许订单回退");
			}
			// end
			
			String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);

			// 对订单所包括的所有虚拟坯料，新增虚拟坯料履历【0PAA09】

			PlnMaterielDetail pmd = new PlnMaterielDetail();
			pmd.setOrder_no(p.getOrder_no());
			List<PlnMaterielDetail> lpmd = this.getMapper(PlnMaterielDetailMapper.class).find(pmd, 0, 0);
			// 对订单所包括的所有虚拟坯料，新增虚拟坯料履历
			for (PlnMaterielDetail pmdc : lpmd) {
				this.getBean(MesApiServiceImpl.class).InsertMatVtProc(pmdc.getObject_no_vt(), "0PAA09", userName,
						new Date());
			}

			// 删除订单对应的虚拟物料表记录, delete from PLN_MATERIEL_DETAIL where ORDER_NO='xxxxxx'
			this.getMapper(PlnMaterielDetailMapper.class).doDelete(p.getOrder_no());
			// 删除订单对应的生产订单表记录, delete from PLN_PRODORDER where ORDER_NO='xxxxxx'
			this.getMapper(PlnProdorderMapper.class).doDelete(p.getOrder_no());
			// 删除订单对应的生产订单进程表记录, delete from PLN_PRODORDER_STATISTIC where ORDER_NO='xxxxxx'
			this.getMapper(PlnProdorderStatisticMapper.class).doDelete(p.getOrder_no());
			// 删除订单对应的订单进程表记录, delete from PLN_ORDER_STATISTIC where ORDER_NO='xxxxxx'
			this.getMapper(PlnOrderStatisticMapper.class).doDelete(p.getOrder_no());
			// 删除订单对应的加工计划表记录
			this.getMapper(PlnProcessPlanMapper.class).doDelete(p.getOrder_no());
			// 删除订单对应的生产订单附加信息表
			this.getMapper(PlnProdorderExtinfoMapper.class).doDelete(p.getOrder_no());

			// 修改订单状态为下发
			SlmOrderInfo soiu = new SlmOrderInfo();
			soiu.setOrder_no(p.getOrder_no());
			soiu.setOrder_flag_no("103406");
			soiu.setOrder_flag_name("下发");
			this.getMapper(SlmOrderInfoMapper.class).doUpdateFlag(soiu);
		}
		rm.setState("200");
		return rm;
	}

	/**
	 * 订单拆分
	 */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doOrderSplitWeb(CommonPage<PlnProdorder> sum) {
		ResultModel rm = new ResultModel();
		// 工序点信息
		List<ComBaseInfo> infoI = this.getMapper(ComBaseInfoMapper.class).findWithCondition(null,
				"sort_code = '2002' AND validflag = '1'", null, 0, 0);
		ProcessPoint processpoint = new ProcessPoint(infoI);
		PlnProdorder p = sum.getObject();
		// ---------------------------
		p.setEstimate_weight(p.getOrder_quantity());

		PlnProdorder pp = new PlnProdorder();
		pp.setProd_order_no(p.getProd_order_no());
		List<PlnProdorder> lp = this.getMapper(PlnProdorderMapper.class).find(pp, 0, 1);
		if (lp != null && lp.size() > 0) {
			if (!"0PAA10".equals(lp.get(0).getStatus())) {
				rm.setState("500");
				rm.setMsgInfo("只有未下发设计订单才能进行拆分!");
				return rm;
			}
			// 找生产订单进程表，生产订单总量
			PlnProdorderStatistic pps = new PlnProdorderStatistic();
			pps.setProd_order_no(p.getProd_order_no());
			List<PlnProdorderStatistic> lpps = this.getMapper(PlnProdorderStatisticMapper.class).find(pps, 0, 1);

			// 生产订单总量-输入量
			if ((lpps.get(0).getProd_ordered().doubleValue() - p.getEstimate_weight().doubleValue()) <= 0) {
				rm.setState("500");
				rm.setMsgInfo("无法拆分！拆分量不能等于生产订单总量");
				return rm;
			}

			if (p.getEstimate_weight().doubleValue() <= 0) {
				rm.setState("500");
				rm.setMsgInfo("无法拆分！拆分量不能<=0");
				return rm;
			}

			// 输入的量>生产订单未排产量
			if (p.getEstimate_weight() > lpps.get(0).getUnscheduled()) {
				rm.setState("500");
				rm.setMsgInfo("无法拆分！只能将未排产量拆分为新的生产订单。拆分量=" + p.getEstimate_weight() + "，未排产量="
						+ lpps.get(0).getUnscheduled());
				return rm;
			}

		} else {
			rm.setState("500");
			rm.setMsgInfo("未能找到订单信息!");
			return rm;
		}

		List<PlnProdorder> ppq = this.getMapper(PlnProdorderMapper.class).findWithCondition(null, "",
				" prod_order_no desc ", 0, 1);
		int maxId = 1;
		if (ppq != null && ppq.size() > 0) {
			maxId = Integer.parseInt(ppq.get(0).getSerial_no()) + 1;
		}

		String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		// 新建生产订单表
		String No = new SimpleDateFormat("yyMMdd").format(new Date());
		List<PlnProdorder> lpCount = this.getMapper(PlnProdorderMapper.class).findWithCondition(null,
				" substr(prod_order_no,1,6)='" + No + "' ", " to_number(serial_no) desc ", 0, 1);
		int iprodCount = 0;
		if (lpCount == null || lpCount.size() == 0) {
			iprodCount = 0;
		} else {
			iprodCount = Integer.parseInt(lpCount.get(0).getProd_order_no().substring(6, 13));
		}

		p.setSerial_no(maxId + "");// 自增id
		p.setProd_order_no(No + String.format("%07d", ++iprodCount));
		p.setStatus("0PAA10");
		// p.setMsc_pline("*******调用质量接口获取");
		p.setCreate_man_name(userName);
		p.setProduce_no(lp.get(0).getProduce_no());
		p.setCreate_time(new Date());
		p.setDelivery_error_max(
				(lp.get(0).getDelivery_error_max() / lp.get(0).getEstimate_weight()) * (p.getEstimate_weight()));
		p.setDelivery_error_min(
				(lp.get(0).getDelivery_error_min() / lp.get(0).getEstimate_weight()) * (p.getEstimate_weight()));
		this.getMapper(PlnProdorderMapper.class).insert(p);

		// 修改原生产订单数据
		PlnProdorder pu = new PlnProdorder();
		pu.setDelivery_error_max((lp.get(0).getDelivery_error_max() / lp.get(0).getEstimate_weight())
				* (lp.get(0).getEstimate_weight() - p.getEstimate_weight()));
		pu.setDelivery_error_min((lp.get(0).getDelivery_error_min() / lp.get(0).getEstimate_weight())
				* (lp.get(0).getEstimate_weight() - p.getEstimate_weight()));
		pu.setEstimate_weight((lp.get(0).getEstimate_weight() - p.getEstimate_weight()));
		pu.setSerial_no(lp.get(0).getSerial_no());
		this.getMapper(PlnProdorderMapper.class).update(pu);

		int iPPSCount = this.getMapper(PlnProdorderStatisticMapper.class).doQueryMaxNo();
		// 新建 生产订单进程表
		PlnProdorderStatistic pps = new PlnProdorderStatistic();
		pps.setSerial_no(++iPPSCount + "");
		pps.setOrder_no(lp.get(0).getOrder_no());
		pps.setProd_order_no(p.getProd_order_no());
		pps.setProd_ordered(p.getEstimate_weight());
		pps.setUnscheduled(p.getEstimate_weight());

		this.getMapper(PlnProdorderStatisticMapper.class).insert(pps);

		// 修改 原生产订单进程表
		PlnProdorderStatistic pos = new PlnProdorderStatistic();
		if ("0PAA10".compareTo(lp.get(0).getStatus()) < 0) {// lp.get(0).getStatus()状态大于等于0PAA10
			if (processpoint.slitting_code
					.equals(this.getBean(QmsApiServiceImpl.class).GetWrkPlanCode(lp.get(0).getOrder_no()))) {// 最后一道为分条
				pos.setLw_undsn(lp.get(0).getEstimate_weight() - p.getEstimate_weight());
			}
		}
		pos.setProd_order_no(lp.get(0).getProd_order_no());
		List<PlnProdorderStatistic> lpos = this.getMapper(PlnProdorderStatisticMapper.class).find(pos, 0, 0);
		pos.setProd_ordered(lp.get(0).getEstimate_weight() - p.getEstimate_weight());
		pos.setUnscheduled(lp.get(0).getEstimate_weight() - p.getEstimate_weight());
		pos.setSerial_no(lpos.get(0).getSerial_no());
		this.getMapper(PlnProdorderStatisticMapper.class).update(pos);

		rm.setState("200");
		return rm;
	}

	/**
	 * 订单合并 PlnProdorder数据为主数据最早一个生产订单 memo1中生产订单编号数据用,分隔 xx,xxx
	 */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doOrderMergeWeb(CommonPage<PlnProdorder> sum) {
		ResultModel rm = new ResultModel();

		PlnProdorder p = sum.getObject();
		PlnProdorder pp = new PlnProdorder();
		pp.setProd_order_no(p.getProd_order_no());
		List<PlnProdorder> lpp = this.getMapper(PlnProdorderMapper.class).find(pp, 0, 0);
		String contractLineNo = p.getContract_line_no();
		if (!"0PAA10".equals(lpp.get(0).getStatus())) {
			rm.setState("500");
			rm.setMsgInfo("只有未下发设计订单才能进行合并!");
			return rm;
		}
		pp.setSerial_no(lpp.get(0).getSerial_no());

		String sId = sum.getMemo1().replace(",", "','");
		List<PlnProdorder> lp = this.getMapper(PlnProdorderMapper.class).findWithCondition(null,
				" prod_order_no in('" + sId + "')", "", 0, 0);

		double Delivery_error_max = 0, Delivery_error_min = 0, Estimate_weight = 0;
		if (lp != null && lp.size() > 0) {
			for (PlnProdorder pc : lp) {
				if (!"0PAA10".equals(pc.getStatus())) {
					rm.setState("500");
					rm.setMsgInfo("只有未下发设计订单才能进行合并!");
					return rm;
				}
				if (!contractLineNo.equals(pc.getContract_line_no())) {
					rm.setState("500");
					rm.setMsgInfo("相同合同行才能进行合并!");
					return rm;
				}
				Delivery_error_max += pc.getDelivery_error_max();
				Delivery_error_min += pc.getDelivery_error_min();
				Estimate_weight += pc.getEstimate_weight();
			}
		} else {
			rm.setState("500");
			rm.setMsgInfo("未能找到订单信息!");
			return rm;
		}

		pp.setDelivery_error_max(lpp.get(0).getDelivery_error_max() + Delivery_error_max);
		pp.setDelivery_error_min(lpp.get(0).getDelivery_error_min() + Delivery_error_min);
		pp.setEstimate_weight(lpp.get(0).getEstimate_weight() + Estimate_weight);

		String serialNo = "";
		// 根据生产订单得到生产订单进程表
		List<PlnProdorderStatistic> lpps = this.getMapper(PlnProdorderStatisticMapper.class).findWithCondition(null,
				" prod_order_no in('" + sId + "','" + p.getProd_order_no() + "')", "", 0, 0);
		if (lpps != null && lpps.size() > 0) {
			for (PlnProdorderStatistic pc : lpps) {
				if (pc.getLw_dsn_cnt() != null && pc.getLw_dsn_cnt() > 0) {
					rm.setState("500");
					rm.setMsgInfo("生产订单[" + pc.getProd_order_no() + "]已经作了分条设计，无法合并!");
					return rm;
				}
				if (p.getProd_order_no().equals(pc.getProd_order_no())) {
					serialNo = pc.getSerial_no();
				}
			}
		} else {
			rm.setState("500");
			rm.setMsgInfo("未能找到生产订单进程信息!");
			return rm;
		}

		// 修改原生产订单数据
		this.getMapper(PlnProdorderMapper.class).update(pp);

		// 修改[First_ProdOrder]生产订单的生产订单进程表
		PlnProdorderStatistic ppsSum = this.getMapper(PlnProdorderStatisticMapper.class)
				.doSum(" prod_order_no in('" + sId + "','" + p.getProd_order_no() + "')");
		ppsSum.setSerial_no(serialNo);
		this.getMapper(PlnProdorderStatisticMapper.class).update(ppsSum);

		// 删除对应的生产订单表记录
		this.getMapper(PlnProdorderMapper.class).doDeleteProdOderNo(sId);

		// 删除对应的生产订单进程表记录
		this.getMapper(PlnProdorderStatisticMapper.class).doDeleteProdOderNo(sId);

		rm.setState("200");
		return rm;
	}

	/**
	 * 生产订单下发
	 * 
	 * @throws Exception
	 */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doOrderIssuedWeb(CommonPage<PlnProdorder> sum) throws Exception {
		ResultModel rm = new ResultModel();
		// 工序点信息
		List<ComBaseInfo> infoI = this.getMapper(ComBaseInfoMapper.class).findWithCondition(null,
				"sort_code = '2002' AND validflag = '1'", null, 0, 0);
		ProcessPoint processpoint = new ProcessPoint(infoI);
//		String [] path = null;
		// 计算所需原料卷数量
//		int db_cnt = 0;
//		ArrayList<String> result = new ArrayList<>();
		List<PlnProdorder> lpp = sum.getObjectList();
//		List<DesignInfo> infos = new ArrayList<>();
		boolean flag = false;
		for (PlnProdorder pp : lpp) {
			PlnProdorder pu = new PlnProdorder();
			pu.setSerial_no(pp.getSerial_no());
			PlnProdorder p = this.getMapper(PlnProdorderMapper.class).findById(pp.getSerial_no());
			String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			if (p == null) {
				throw new Exception("未找到生产订单" + pp.getProd_order_no() + "信息,请刷新页面再操作！");
//				db_cnt = (new BigDecimal(p.getEstimate_weight()).setScale(0, BigDecimal.ROUND_HALF_UP)).intValue() == 0 ? 1:(new BigDecimal(p.getEstimate_weight()).setScale(0, BigDecimal.ROUND_HALF_UP)).intValue();
			} else if (p != null) {
//				if (!"2".equals(p.getOrder_nature())) {
//					throw new Exception("生产订单" + p.getProd_order_no() + "无需进行加工操作， 请进行充当操作！");
//				}
				// 增加酸洗和冷轧订单类型防止以后在增加订单类型,直接判断不需要加工的订单(原料卷和非计划)
				if ("1".equals(p.getOrder_nature()) || "3".equals(p.getOrder_nature())) {
					throw new Exception("生产订单" + p.getProd_order_no() + "无需进行加工操作， 请进行充当操作！");
				}
				if (!"1".equals(p.getWhole_coil()) && (Utils.isEmpty(p.getDesign_key())
						|| Utils.isEmpty(p.getMsc_pline()) || Utils.isEmpty(p.getWhole_process_codes()))) {
					throw new Exception("生产订单" + pp.getProd_order_no() + "还未选制程,不能下发！");
				}
				if (p.getStatus() == null) {
					throw new Exception("生产订单" + p.getProd_order_no() + "状态无效！");
				} else if (p.getStatus().compareTo("0PAA10") < 0) {
					throw new Exception("生产订单" + p.getProd_order_no() + "订单无效！");
				} else if (p.getStatus().compareTo("0PAA10") == 0) {
					pu.setStatus("0PAA12");
					pu.setPline_code("");
					pu.setPline_name("");
					pu.setSend_time(new Date());
					pu.setSend_man_name(userName);
					this.getMapper(PlnProdorderMapper.class).update(pu);
//					PlnProcessPlan ppp = new PlnProcessPlan();
//					ppp.setProduce_no(p.getProduce_no());
//					ppp.setCut_order_no(1l);
//					ppp.setValid_flag("1");
//					List<PlnProcessPlan> pprocessp = this.getMapper(PlnProcessPlanMapper.class).find(ppp, 0, 1);
					// 修改生产订单进程表
					PlnProdorderStatistic pps = new PlnProdorderStatistic();
					pps.setProd_order_no(p.getProd_order_no());
					List<PlnProdorderStatistic> lpps = this.getMapper(PlnProdorderStatisticMapper.class).find(pps, 0,
							0);
					// 生产订单进程表.UNSCHEDULED
					double db = lpps.get(0).getUnscheduled().doubleValue();

					// 修改 订单进程表
					PlnOrderStatistic pos = new PlnOrderStatistic();
					pos.setOrder_no(p.getOrder_no());
					// 非整卷发运 (整卷发运不改变生产订单量)
					if (!"1".equals(p.getWhole_coil())) {
						// 分条
						if (p.getWhole_process_codes().contains(processpoint.slitting_code)) {
							pps.setLw_undsn(db);
//						pps.setLw_dsn(db);
//						pps.setMat_lw_dsn(db);
//						pps.setMat_lw_dsn_cnt(db_cnt);
							pps.setUnscheduled(-db);
//						this.getMapper(PlnProdorderStatisticMapper.class).doUpdatePlaned(pps);
							// 欠纵剪设计_成品量
							pos.setLw_undsn(db);
//						pos.setLw_dsn(db);
//						pos.setMat_lw_dsn(db);
//						pos.setMat_lw_dsn_cnt(db_cnt);
							pos.setUnscheduled(-db);
							this.getMapper(PlnOrderStatisticMapper.class).doUpdatePlaned(pos);
							flag = true;
						}
						// 开平
						if (p.getWhole_process_codes().contains(processpoint.cross_cutting_code)) {
							pps.setCl_undsn(db);
//						pps.setCl_dsn(db);
//						pps.setMat_cl_dsn(db);
//						pps.setMat_cl_dsn_cnt(db_cnt);
							pps.setUnscheduled(-db);
//						this.getMapper(PlnProdorderStatisticMapper.class).doUpdatePlaned(pps);
							// 欠横剪设计_成品量
							pos.setCl_undsn(db);
//						pos.setCl_dsn(db);
//						pos.setMat_cl_dsn(db);
//						pos.setMat_cl_dsn_cnt(db_cnt);
							if (!flag) {
								pos.setUnscheduled(-db);
							} else {
								pos.setUnscheduled(0d);
							}
							this.getMapper(PlnOrderStatisticMapper.class).doUpdateClPlaned(pos);
							flag = true;
						}
						// 罩退
						if (p.getWhole_process_codes().contains(processpoint.anneal_code)) {
							pps.setAn_undsn(db);
//						pps.setAn_dsn(db);
//						pps.setMat_an_dsn(db);
//						pps.setMat_an_dsn_cnt(db_cnt);
							pps.setUnscheduled(-db);
							// 欠罩退设计_成品量
							pos.setAn_undsn(db);
//						pos.setAn_dsn(db);
//						pos.setMat_an_dsn(db);
//						pos.setMat_an_dsn_cnt(db_cnt);
							if (!flag) {
								pos.setUnscheduled(-db);
							} else {
								pos.setUnscheduled(0d);
							}
							this.getMapper(PlnOrderStatisticMapper.class).doUpdateAnPlaned(pos);
							flag = true;
						}
						// 平整
						if (p.getWhole_process_codes().contains(processpoint.smooth_code)) {
							pps.setSr_undsn(db);
//						pps.setAn_dsn(db);
//						pps.setMat_an_dsn(db);
//						pps.setMat_an_dsn_cnt(db_cnt);
							pps.setUnscheduled(-db);
							// 欠罩退设计_成品量
							pos.setSr_undsn(db);
//						pos.setAn_dsn(db);
//						pos.setMat_an_dsn(db);
//						pos.setMat_an_dsn_cnt(db_cnt);
							if (!flag) {
								pos.setUnscheduled(-db);
							} else {
								pos.setUnscheduled(0d);
							}
							this.getMapper(PlnOrderStatisticMapper.class).doUpdateSrPlaned(pos);
						}
						// 轧制
						if (p.getWhole_process_codes().contains(processpoint.rolling_code)) {
							pps.setRl_undsn(db);
							pps.setUnscheduled(-db);
							// 欠轧制设计_成品量
							pos.setRl_undsn(db);
							if (!flag) {
								pos.setUnscheduled(-db);
							} else {
								pos.setUnscheduled(0d);
							}
							this.getMapper(PlnOrderStatisticMapper.class).doUpdateRlPlaned(pos);
						}
						// 酸洗
						if (p.getWhole_process_codes().contains(processpoint.pickle_code)) {
							pps.setPc_undsn(db);
							pps.setUnscheduled(-db);
							// 欠酸洗设计_成品量
							pos.setPc_undsn(db);
							if (!flag) {
								pos.setUnscheduled(-db);
							} else {
								pos.setUnscheduled(0d);
							}
							this.getMapper(PlnOrderStatisticMapper.class).doUpdatePcPlaned(pos);
						}
						this.getMapper(PlnProdorderStatisticMapper.class).doUpdatePlaned(pps);
					}

					// 修改销售订单状态 18.3.23---vir----
					SlmOrderInfo slm_order = new SlmOrderInfo();
					slm_order.setContract_no(p.getContract_no());
					slm_order.setContract_line_seq(p.getContract_line_seq());
					slm_order.setOrder_seq(p.getOrder_seq());
					List<SlmOrderInfo> orderList = this.getBean(SlmOrderInfoServiceImpl.class).doQuery(slm_order);
					boolean  in=true;
					if (orderList.size() ==1) {
						slm_order=orderList.get(0);
					}else if(orderList.size()>1){
						if(p.getOrd_pk()!=null){
							SlmOrderInfo pk_order=this.getMapper(SlmOrderInfoMapper.class).findById(p.getOrd_pk());
							if(pk_order!=null)	slm_order=pk_order;
						}
					}else{
						in=false;
					}
					if(in){
						slm_order.setP_order_flag_no(slm_order.getOrder_flag_no());
						slm_order.setP_order_flag_name(slm_order.getOrder_flag_name());
						slm_order.setOrder_flag_no("103408");
						slm_order.setOrder_flag_name("生产");
						this.getBean(SlmOrderInfoServiceImpl.class).doUpdate(slm_order);
					}
					// 修改销售订单状态 18.3.23---vir----
				}
			}

//			// 获取有意义的工艺路径
//			 path = p.getWhole_process_codes().split("-");
//			 result = Utils.getProcessPath(path);
//			// 通过工艺路径生成设计信息
//			 DesignInfo info = new DesignInfo();
//			 info.setProcess(result);
//			 info.setCurrentProcIndex(0);
//			 info.setObject_no_vt(null);
//			 info.setProd_order_no(p.getProd_order_no());
//			 infos.add(info);
//			 // 一个订单设计几个卷就循环几次
//			 for (int i = 0; i < db_cnt; i++) {
//				 ResultModel rmodel = this.getBean(MesApiDesignInfoImpl.class).Design_Plan_Info(infos);
//				 if (!"200".equals(rmodel.getState())) {
//					 throw new Exception(rmodel.getMsgInfo());
//				 }
//			 }
		}
		rm.setState("200");
		return rm;
	}

	/**
	 * 生产订单下发取消
	 * 
	 * @throws Exception
	 */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doOrderIssuedCancelWeb(CommonPage<PlnProdorder> sum) throws Exception {
		ResultModel rm = new ResultModel();
		// 工序点信息
		List<ComBaseInfo> infoI = this.getMapper(ComBaseInfoMapper.class).findWithCondition(null,
				"sort_code = '2002' AND validflag = '1'", null, 0, 0);
		ProcessPoint processpoint = new ProcessPoint(infoI);
		String userId = (String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		List<PlnProdorder> lpp = sum.getObjectList();
		boolean flag = false;
		for (PlnProdorder pp : lpp) {
			PlnProdorder pu = new PlnProdorder();
			pu.setSerial_no(pp.getSerial_no());
			PlnProdorder p = this.getMapper(PlnProdorderMapper.class).findById(pp.getSerial_no());
			if (p == null) {
				throw new Exception("未找到生产订单" + pp.getProd_order_no() + "信息,请刷新页面再操作！");
			} else if (p != null) {
				if (p.getStatus() == null) {
					throw new Exception("生产订单" + p.getProd_order_no() + "状态无效！");
				} else if (p.getStatus().compareTo("0PAA10") < 0) {
					throw new Exception("生产订单" + p.getProd_order_no() + "订单无效！");
				} else if (p.getStatus().compareTo("0PAA10") == 0) {
					// 跳过
				} else if (p.getStatus().compareTo("0PAA20") == 0) {
					throw new Exception("生产订单[" + p.getOrder_no() + "]已完成，不能回退！");
				} else {
					PlnProdorderStatistic ppsQ = new PlnProdorderStatistic();
					ppsQ.setOrder_no(p.getOrder_no());
					int icount = this.getMapper(PlnProdorderStatisticMapper.class).countWithCondition(ppsQ,
							" (LW_DSN>0 or AN_DSN>0 OR SR_DSN>0 OR CL_DSN>0 OR PC_DSN>0 OR RL_DSN>0) ");
					//暂时去掉这个限制：20240802刘侣
//					if (icount > 0) {
//						throw new Exception("生产订单[" + p.getOrder_no() + "]已设计，不能回退！");
//					}

					pu.setStatus("0PAA10");
					this.getMapper(PlnProdorderMapper.class).doOrderIssuedCancel(pu);

					if (!"1".equals(p.getWhole_coil())) {
						// 修改生产订单进程表
						PlnProdorderStatistic pps = new PlnProdorderStatistic();
						pps.setProd_order_no(p.getProd_order_no());
						List<PlnProdorderStatistic> lpps = this.getMapper(PlnProdorderStatisticMapper.class).find(pps,
								0, 0);
						// 修改 订单进程表
						PlnOrderStatistic pos = new PlnOrderStatistic();
						pos.setOrder_no(p.getOrder_no());
						if (p.getWhole_process_codes().contains(processpoint.slitting_code)) {
							// 生产订单进程表.Lw_undsn
							double db = lpps.get(0).getLw_undsn().doubleValue();
							// 计算所需原料卷数量
//							int db_cnt = (new BigDecimal(lpps.get(0).getLw_undsn()).setScale(0, BigDecimal.ROUND_HALF_UP)).intValue() == 0 ? 1:(new BigDecimal(lpps.get(0).getLw_undsn()).setScale(0, BigDecimal.ROUND_HALF_UP)).intValue();
							pps.setLw_undsn(-db);
//							pps.setLw_dsn(-db);
//							pps.setMat_lw_dsn(-db);
//							pps.setMat_lw_dsn_cnt(-db_cnt);
							pps.setUnscheduled(db);
//							this.getMapper(PlnProdorderStatisticMapper.class).doUpdatePlaned(pps);
							// 欠纵剪设计_成品量
							pos.setLw_undsn(-db);
//							pos.setLw_dsn(-db);
//							pos.setMat_lw_dsn(-db);
//							pos.setMat_lw_dsn_cnt(-db_cnt);
							pos.setUnscheduled(db);
							this.getMapper(PlnOrderStatisticMapper.class).doUpdatePlaned(pos);
							flag = true;
						}
						if (p.getWhole_process_codes().contains(processpoint.cross_cutting_code)) {
							// 生产订单进程表.Cl_undsn
							double db = lpps.get(0).getCl_undsn().doubleValue();
							// 计算所需原料卷数量
//							int db_cnt = (new BigDecimal(lpps.get(0).getCl_undsn()).setScale(0, BigDecimal.ROUND_HALF_UP)).intValue() == 0 ? 1:(new BigDecimal(lpps.get(0).getCl_undsn()).setScale(0, BigDecimal.ROUND_HALF_UP)).intValue();
							pps.setCl_undsn(-db);
//							pps.setCl_dsn(-db);
//							pps.setMat_cl_dsn(-db);
//							pps.setMat_cl_dsn_cnt(-db_cnt);
							pps.setUnscheduled(db);
//							this.getMapper(PlnProdorderStatisticMapper.class).doUpdatePlaned(pps);
							// 欠横剪设计_成品量
							pos.setCl_undsn(-db);
//							pos.setCl_dsn(-db);
//							pos.setMat_cl_dsn(-db);
//							pos.setMat_cl_dsn_cnt(-db_cnt);
							if (!flag) {
								pos.setUnscheduled(db);
							} else {
								pos.setUnscheduled(0d);
							}
							this.getMapper(PlnOrderStatisticMapper.class).doUpdateClPlaned(pos);
							flag = true;
						}
						if (p.getWhole_process_codes().contains(processpoint.anneal_code)) {
							// 生产订单进程表.An_undsn
							double db = lpps.get(0).getAn_undsn().doubleValue();
							// 计算所需原料卷数量
//							int db_cnt = (new BigDecimal(lpps.get(0).getAn_undsn()).setScale(0, BigDecimal.ROUND_HALF_UP)).intValue() == 0 ? 1:(new BigDecimal(lpps.get(0).getAn_undsn()).setScale(0, BigDecimal.ROUND_HALF_UP)).intValue();
							pps.setAn_undsn(-db);
//							pps.setAn_dsn(-db);
//							pps.setMat_an_dsn(-db);
//							pps.setMat_an_dsn_cnt(-db_cnt);
							pps.setUnscheduled(db);
							// 欠罩退设计_成品量
							pos.setAn_undsn(-db);
//							pos.setAn_dsn(-db);
//							pos.setMat_an_dsn(-db);
//							pos.setMat_an_dsn_cnt(-db_cnt);
							if (!flag) {
								pos.setUnscheduled(db);
							} else {
								pos.setUnscheduled(0d);
							}
							this.getMapper(PlnOrderStatisticMapper.class).doUpdateAnPlaned(pos);
							flag = true;
						}
						if (p.getWhole_process_codes().contains(processpoint.smooth_code)) {
							// 生产订单进程表.Sr_undsn
							double db = lpps.get(0).getSr_undsn().doubleValue();
							// 计算所需原料卷数量
//							int db_cnt = (new BigDecimal(lpps.get(0).getSr_undsn()).setScale(0, BigDecimal.ROUND_HALF_UP)).intValue() == 0 ? 1:(new BigDecimal(lpps.get(0).getAn_undsn()).setScale(0, BigDecimal.ROUND_HALF_UP)).intValue();
							pps.setSr_undsn(-db);
//							pps.setAn_dsn(-db);
//							pps.setMat_an_dsn(-db);
//							pps.setMat_an_dsn_cnt(-db_cnt);
							pps.setUnscheduled(db);
							// 欠罩退设计_成品量
							pos.setSr_undsn(-db);
//							pos.setSr_dsn(-db);
//							pos.setMat_an_dsn(-db);
//							pos.setMat_an_dsn_cnt(-db_cnt);
							if (!flag) {
								pos.setUnscheduled(db);
							} else {
								pos.setUnscheduled(0d);
							}
							this.getMapper(PlnOrderStatisticMapper.class).doUpdateSrPlaned(pos);
						}
						if (p.getWhole_process_codes().contains(processpoint.rolling_code)) {
							// 生产订单进程表.Rl_undsn
							double db = lpps.get(0).getRl_undsn().doubleValue();
							// 计算所需原料卷数量
//							int db_cnt = (new BigDecimal(lpps.get(0).getSr_undsn()).setScale(0, BigDecimal.ROUND_HALF_UP)).intValue() == 0 ? 1:(new BigDecimal(lpps.get(0).getAn_undsn()).setScale(0, BigDecimal.ROUND_HALF_UP)).intValue();
							pps.setRl_undsn(-db);
//							pps.setAn_dsn(-db);
//							pps.setMat_an_dsn(-db);
//							pps.setMat_an_dsn_cnt(-db_cnt);
							pps.setUnscheduled(db);
							// 欠轧制设计_成品量
							pos.setRl_undsn(-db);
//							pos.setSr_dsn(-db);
//							pos.setMat_an_dsn(-db);
//							pos.setMat_an_dsn_cnt(-db_cnt);
							if (!flag) {
								pos.setUnscheduled(db);
							} else {
								pos.setUnscheduled(0d);
							}
							this.getMapper(PlnOrderStatisticMapper.class).doUpdateRlPlaned(pos);
						}
						if (p.getWhole_process_codes().contains(processpoint.pickle_code)) {
							// 生产订单进程表.Rl_undsn
							double db = lpps.get(0).getPc_undsn().doubleValue();
							// 计算所需原料卷数量
//							int db_cnt = (new BigDecimal(lpps.get(0).getSr_undsn()).setScale(0, BigDecimal.ROUND_HALF_UP)).intValue() == 0 ? 1:(new BigDecimal(lpps.get(0).getAn_undsn()).setScale(0, BigDecimal.ROUND_HALF_UP)).intValue();
							pps.setPc_undsn(-db);
//							pps.setAn_dsn(-db);
//							pps.setMat_an_dsn(-db);
//							pps.setMat_an_dsn_cnt(-db_cnt);
							pps.setUnscheduled(db);
							// 欠轧制设计_成品量
							pos.setPc_undsn(-db);
//							pos.setSr_dsn(-db);
//							pos.setMat_an_dsn(-db);
//							pos.setMat_an_dsn_cnt(-db_cnt);
							if (!flag) {
								pos.setUnscheduled(db);
							} else {
								pos.setUnscheduled(0d);
							}
							this.getMapper(PlnOrderStatisticMapper.class).doUpdatePcPlaned(pos);
						}
						this.getMapper(PlnProdorderStatisticMapper.class).doUpdatePlaned(pps);
					}
					// 修改销售订单状态 18.3.23---vir----
					SlmOrderInfo slm_order = new SlmOrderInfo();
					slm_order.setContract_no(p.getContract_no());
					slm_order.setContract_line_seq(p.getContract_line_seq());
					slm_order.setOrder_seq(p.getOrder_seq());
					List<SlmOrderInfo> orderList = this.getBean(SlmOrderInfoServiceImpl.class).doQuery(slm_order);
					if (orderList.size() > 0) {
						orderList.get(0).setUpdate_man_no(userId);
						orderList.get(0).setUpdate_man_name(userName);
						orderList.get(0).setUpdate_time(new Date());
						orderList.get(0).setP_order_flag_no(orderList.get(0).getOrder_flag_no());
						orderList.get(0).setP_order_flag_name(orderList.get(0).getOrder_flag_name());
						orderList.get(0).setOrder_flag_no("103407");
						orderList.get(0).setOrder_flag_name("接收");
						this.getBean(SlmOrderInfoServiceImpl.class).doUpdate(orderList.get(0));
					}
					// 修改销售订单状态 18.3.23---vir----
				}
			}
		}

		rm.setState("200");
		return rm;
	}

	/**
	 * 分条充当 查询生产订单信息
	 */
	public ResultModel doLengthwiseQueryWeb(CommonPage<PlnProdorder> sum) {
		ResultModel rm = new ResultModel();
		try {
			String sWhere = " t2.lw_undsn>0 ";
			// 假如为1则为下发产生时间 为2交货时间
			if ("1".equals(sum.getMemo1())) {
				sWhere += " and t.send_time between to_date('" + sum.getStartTime()
						+ "','yyyy-MM-dd HH24:mi:ss') and to_date('" + sum.getEndTime() + "','yyyy-MM-dd HH24:mi:ss') ";
			} else if ("2".equals(sum.getMemo1())) {
				sWhere += " and t.deliver_date between to_date('" + sum.getStartTime().substring(0, 10)
						+ "','yyyy-MM-dd') and to_date('" + sum.getEndTime().substring(0, 10) + "','yyyy-MM-dd') ";
			}
			if (sum.getObject() != null) {
				if (sum.getObject().getDiameter_out_max() != null) {
					sWhere += " and t.diameter_out>=" + sum.getObject().getDiameter_inn_max();
					sum.getObject().setDiameter_inn_max(null);
				}
				if (sum.getObject().getDiameter_out_min() != null) {
					sWhere += " and t.diameter_out<=" + sum.getObject().getDiameter_inn_min();
					sum.getObject().setDiameter_inn_min(null);
				}

				if (sum.getObject().getContract_no() != null && !"".equals(sum.getObject().getContract_no().trim())) {
					sWhere += " and t.contract_no like '%" + sum.getObject().getContract_no().trim() + "%' ";
					sum.getObject().setContract_no(null);
				}
				if (sum.getObject().getOrder_no() != null && !"".equals(sum.getObject().getOrder_no().trim())) {
					sWhere += " and t.order_no like '%" + sum.getObject().getOrder_no().trim() + "%' ";
					sum.getObject().setOrder_no(null);
				}
				if (sum.getObject().getProd_order_no() != null
						&& !"".equals(sum.getObject().getProd_order_no().trim())) {
					sWhere += " and t.prod_order_no like '%" + sum.getObject().getProd_order_no().trim() + "%' ";
					sum.getObject().setProd_order_no(null);
				}
				if (sum.getObject().getSteel_name() != null && !"".equals(sum.getObject().getSteel_name().trim())) {
					sWhere += " and steel_name like '%" + sum.getObject().getSteel_name().trim() + "%' ";
					sum.getObject().setSteel_name(null);
				}
			}

			rm.setState("200");
			rm.setData(this.getMapper(PlnProdorderMapper.class).doLengthwiseQueryWeb(sum.getObject(), sWhere));
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("查询失败！");
			ex.printStackTrace();
			rm.setErrorInfo(ex.getMessage());
		}
		return rm;
	}

	/**
	 * 查询计划模块已接收过的且欠分条设计的生产订单 memo1 1则为下发产生时间 为2交货时间
	 */
	public ResultModel doQueryReceivedWeb(CommonPage<PlnProdorder> sum) {
		ResultModel rm = new ResultModel();
		try {
			PageModel<HashMap> pm = new PageModel<HashMap>(sum.getPageIndex(), sum.getPageSize());

			String sWhere = "";
			// 假如为1则为下发产生时间 为2交货时间
			if ("1".equals(sum.getMemo1())) {
				sWhere += " and t.send_time between to_date('" + sum.getStartTime()
						+ "','yyyy-MM-dd HH24:mi:ss') and to_date('" + sum.getEndTime() + "','yyyy-MM-dd HH24:mi:ss') ";
			} else if ("2".equals(sum.getMemo1())) {
				sWhere += " and t.deliver_date between to_date('" + sum.getStartTime().substring(0, 10)
						+ "','yyyy-MM-dd') and to_date('" + sum.getEndTime().substring(0, 10) + "','yyyy-MM-dd') ";
			}
			pm.setRows(this.getMapper(PlnProdorderMapper.class).doQueryStatistics(sum.getObject(), sWhere,
					(sum.getPageIndex() - 1) * sum.getPageSize(), sum.getPageIndex() * sum.getPageSize()));
			pm.setTotal(this.getMapper(PlnProdorderMapper.class).doQueryStatisticsCount(sum.getObject(), sWhere));
			rm.setData(pm);
			rm.setState("200");
			// rm.setData(this.getMapper(PlnProdorderMapper.class).doQueryStatistics(sum.getObject(),
			// sWhere,(sum.getPageIndex()-1)*sum.getPageSize(),sum.getPageIndex()*sum.getPageSize()));
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("查询失败！");
			ex.printStackTrace();
			rm.setErrorInfo(ex.getMessage());
		}
		return rm;
	}

	 
	/**
	 * 计划管理--生成订单进程查询 memo1 1则为接收时间 为2交货时间
	 */
	public ResultModel doQueryPlnStatisticsWeb2(CommonPage<PlnProdorder> sum) {
		ResultModel rm = new ResultModel();
		try {
			String sWhere = "";
			// 假如为1则为下发产生时间 为2交货时间
			if ("1".equals(sum.getMemo1())) {
				sWhere += " and t.create_time between to_date('" + sum.getStartTime()
						+ "','yyyy-MM-dd HH24:mi:ss') and to_date('" + sum.getEndTime() + "','yyyy-MM-dd HH24:mi:ss') ";
			} else if ("2".equals(sum.getMemo1())) {
				sWhere += " and t.deliver_date between to_date('" + sum.getStartTime().substring(0, 10)
						+ "','yyyy-MM-dd') and to_date('" + sum.getEndTime().substring(0, 10) + "','yyyy-MM-dd') ";
			}
			
			String status = sum.getObject().getStatus();			
			if (status!=null && !"".equals(status)) {
				// 改为使用生产订单状态去查询：20230908刘侣
//				status = status.replace("0PAA10", "103407");//接收
//				status = status.replace("0PAA12", "103406");//下发
//				status = status.replace("0PAA14", "103408");//投料
//				status = status.replace("0PAA15", "103408");//生产
//				status = status.replace("0PAA20", "103409");//缴库==生产完成
//				status = status.replace("0PAA50", "103410");//发货
//				status = status.replace("0PAA80", "103411");//结算
//				status = status.replace("0PAA99", "103412");//关闭
				
//				sWhere += " and soi.order_flag_no in ("+status+")";
				sWhere += " and t.status in ("+status+")";
				// end
			}
			//机台处理
			String machine_name = sum.getObject().getMachine_name();
			if ("M0001".equals(machine_name)) {//4mm
				sWhere += " and exists (select 1 from mes_cr_slitting_d d left join mes_cr_slitting_m m "
						+ "on d.process_no = m.process_no where d.order_no = t.order_no and m.machine_code = 'M0001')";
			}else if ("M0002".equals(machine_name)) {//12mm
				sWhere += " and exists (select 1 from mes_cr_slitting_d d left join mes_cr_slitting_m m "
						+ "on d.process_no = m.process_no where d.order_no = t.order_no and m.machine_code = 'M0002')";
			}else if ("M0003".equals(machine_name)) {//3mm
				sWhere += " and exists (select 1 from mes_cr_cross_cutting_d d where d.order_no = t.order_no)";
			}else if ("M000T".equals(machine_name)) {//退火
				sWhere += " and exists (select 1 from mes_cr_anneal_m d where d.order_no = t.order_no)";
			}else if ("M0007".equals(machine_name)) {//平整
				sWhere += " and exists (select 1 from mes_tpm_d d where d.order_no = t.order_no)";
			}else if ("M0008".equals(machine_name)) {//轧机
				sWhere += " and exists (select 1 from mes_rcm_d d where d.order_no = t.order_no)";
			}else if ("M0010".equals(machine_name)) {//酸洗
				sWhere += " and exists (select 1 from mes_plm_d d where d.order_no = t.order_no)";
			}
			rm.setData(this.getMapper(PlnProdorderMapper.class).doQueryPlnStatistics2(sum.getObject(), sWhere));
			rm.setState("200");
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("查询失败！");
			ex.printStackTrace();
			rm.setErrorInfo(ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 查询计划模块已接收过的未排产的生产订单 纵剪挂单使用 memo1 1则为下发产生时间 为2交货时间 memo2 1为勾选了满足一短短装量订单 memo3
	 * 1为勾选只显示首个工序为分条的
	 */
	public ResultModel doQueryWaitRelationOrderWeb(CommonPage<PlnProdorder> sum) {
		ResultModel rm = new ResultModel();

		try {
			String sWhere = "";
			// 假如为1则为下发产生时间 为2交货时间
			if ("1".equals(sum.getMemo1())) {
				sWhere += " and ((t1.status>='0PAA12' and t1.send_time between to_date('" + sum.getStartTime()
						+ "','yyyy-MM-dd HH24:mi:ss') and to_date('" + sum.getEndTime()
						+ "','yyyy-MM-dd HH24:mi:ss')) or (t1.status>='0PAA10' and t1.create_time between to_date('"
						+ sum.getStartTime() + "','yyyy-MM-dd HH24:mi:ss') and to_date('" + sum.getEndTime()
						+ "','yyyy-MM-dd HH24:mi:ss'))) ";
			} else if ("2".equals(sum.getMemo1())) {
				sWhere += " and t1.deliver_date between to_date('" + sum.getStartTime().substring(0, 10)
						+ "','yyyy-MM-dd') and to_date('" + sum.getEndTime().substring(0, 10) + "','yyyy-MM-dd') ";
			}

			
			if ("1".equals(sum.getMemo2())) {
				sWhere += " and nvl2(t1.delivery_error_min, case when ((t1.estimate_weight - t1.delivery_error_min) < (case when  t1.order_nature in ('1','3') or t1.whole_coil = '1' then t2.unscheduled else t2.lw_undsn end)) then 1 else 0 end, 1) = 1 ";
			} else {
//	TODO			sWhere+=" and (case when t1.status='0PAA10' then t2.unscheduled else t2.lw_undsn end)>0 ";
				sWhere += " and (case when t1.order_nature in ('1','3')  or t1.whole_coil = '1' then t2.unscheduled else t2.lw_undsn end) is not null ";
			}
			if (sum.getObject() != null) {
				if (sum.getObject().getContract_no() != null && !"".equals(sum.getObject().getContract_no().trim())) {
					sWhere += " and t1.contract_no like '%" + sum.getObject().getContract_no().trim() + "%' ";
					sum.getObject().setContract_no(null);
				}
				if (sum.getObject().getOrder_no() != null && !"".equals(sum.getObject().getOrder_no().trim())) {
					sWhere += " and t1.order_no like '%" + sum.getObject().getOrder_no().trim() + "%' ";
					sum.getObject().setOrder_no(null);
				}
				if (sum.getObject().getProd_order_no() != null
						&& !"".equals(sum.getObject().getProd_order_no().trim())) {
					sWhere += " and t1.prod_order_no like '%" + sum.getObject().getProd_order_no().trim() + "%' ";
					sum.getObject().setProd_order_no(null);
				}

				if (sum.getObject().getSteel_name() != null && !"".equals(sum.getObject().getSteel_name().trim())) {
					sWhere += " and t1.steel_name like '%" + sum.getObject().getSteel_name().trim() + "%' ";
					sum.getObject().setSteel_name(null);
				}
			}
			// 工序点信息
			List<ComBaseInfo> infoI = this.getMapper(ComBaseInfoMapper.class).findWithCondition(null,
					"sort_code = '2002' AND validflag = '1'", null, 0, 0);
			ProcessPoint processpoint = new ProcessPoint(infoI);

			List<HashMap> listHm = this.getMapper(PlnProdorderMapper.class).doQueryWaitRelationOrder(sum.getObject(),
					sWhere);
			Iterator<HashMap> it = listHm.iterator();
			while (it.hasNext()) {
				HashMap str = it.next();
				// 把不符合条件的数据remove
				if ("1".equals(sum.getMemo3()) && !"1".equals(str.get("ORDER_NATURE_TEMP")) && !"3".equals(str.get("ORDER_NATURE_TEMP"))) {
					// 获取有效的工艺路径
					String[] path = String.valueOf(str.get("WHOLE_PROCESS_CODES")).split("-");
					ArrayList<String> validpath = this.getBean(MesApiDesignInfoImpl.class).getProcessPath(path);
					if (Utils.isNotEmpty(validpath) && !processpoint.slitting_code.equals(validpath.get(0))) {
						it.remove();
						continue;
					}
				}
			}
			for (HashMap hashMap : listHm) {
				// 加工计划备注
				SlmProcessPlan plan = new SlmProcessPlan();
				plan.setContract_line_no((String) hashMap.get("CONTRACT_LINE_NO"));
				plan.setContract_line_seq((String) hashMap.get("CONTRACT_LINE_SEQ"));
				plan.setOrder_seq((String) hashMap.get("ORDER_SEQ"));
				plan.setValid_flag("1");
				List<SlmProcessPlan> planList = this.getMapper(SlmProcessPlanMapper.class).findWithCondition(plan, "",
						" cut_order_no", 0, 0);
				if (planList.size() > 0) {
					// 关联加工计划信息表SLM_PROCESS_PLAN查询加工计划备注
					hashMap.put("PROCESSMEMO", planList.get(0).getMemo());
				} else {
					hashMap.put("PROCESSMEMO", null);
				}
			}

			rm.setState("200");
			rm.setData(listHm);
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("查询失败！");
			ex.printStackTrace();
			rm.setErrorInfo(ex.getMessage());
		}

		return rm;
	}
	
	// -----------------------------------------2018-06-21 横剪----------------------------------------
	/**
	 * 开平充当 查询生产订单信息 2018-06-13
	 */
	public ResultModel doCuttoLengthQueryWeb(CommonPage<PlnProdorder> sum) {
		ResultModel rm = new ResultModel();
		try {
			String sWhere = " t2.cl_undsn>0 ";
			// 假如为1则为下发产生时间 为2交货时间
			if ("1".equals(sum.getMemo1())) {
				sWhere += " and t.send_time between to_date('" + sum.getStartTime()
						+ "','yyyy-MM-dd HH24:mi:ss') and to_date('" + sum.getEndTime() + "','yyyy-MM-dd HH24:mi:ss') ";
			} else if ("2".equals(sum.getMemo1())) {
				sWhere += " and t.deliver_date between to_date('" + sum.getStartTime().substring(0, 10)
						+ "','yyyy-MM-dd') and to_date('" + sum.getEndTime().substring(0, 10) + "','yyyy-MM-dd') ";
			}
			if (sum.getObject() != null) {
				if (sum.getObject().getDiameter_out_max() != null) {
					sWhere += " and t.diameter_out>=" + sum.getObject().getDiameter_inn_max();
					sum.getObject().setDiameter_inn_max(null);
				}
				if (sum.getObject().getDiameter_out_min() != null) {
					sWhere += " and t.diameter_out<=" + sum.getObject().getDiameter_inn_min();
					sum.getObject().setDiameter_inn_min(null);
				}

				if (sum.getObject().getContract_no() != null && !"".equals(sum.getObject().getContract_no().trim())) {
					sWhere += " and t.contract_no like '%" + sum.getObject().getContract_no().trim() + "%' ";
					sum.getObject().setContract_no(null);
				}
				if (sum.getObject().getOrder_no() != null && !"".equals(sum.getObject().getOrder_no().trim())) {
					sWhere += " and t.order_no like '%" + sum.getObject().getOrder_no().trim() + "%' ";
					sum.getObject().setOrder_no(null);
				}
				if (sum.getObject().getProd_order_no() != null
						&& !"".equals(sum.getObject().getProd_order_no().trim())) {
					sWhere += " and t.prod_order_no like '%" + sum.getObject().getProd_order_no().trim() + "%' ";
					sum.getObject().setProd_order_no(null);
				}
				if (sum.getObject().getSteel_name() != null && !"".equals(sum.getObject().getSteel_name().trim())) {
					sWhere += " and steel_name like '%" + sum.getObject().getSteel_name().trim() + "%' ";
					sum.getObject().setSteel_name(null);
				}
			}

			rm.setState("200");
			// TODO
			// rm.setData(this.getMapper(PlnProdorderMapper.class).doCuttoLengthQueryWeb(sum.getObject(),
			// sWhere));
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("查询失败！");
			ex.printStackTrace();
			rm.setErrorInfo(ex.getMessage());
		}
		return rm;
	}

	/**
	 * 查询计划模块已接收过的未排产的生产订单 横剪挂单使用 memo1 1则为下发产生时间 为2交货时间 memo2 1为勾选了满足溢短装量订单
	 */
	public ResultModel doQueryUnscheduledProdorder(CommonPage<PlnProdorder> sum) {
		ResultModel rm = new ResultModel("200", "");

		try {
			String sWhere = "";
			// 假如为1则为下发产生时间 为2交货时间
			if ("1".equals(sum.getMemo1())) {
				sWhere += " and ((t1.status>='0PAA12' and t1.send_time between to_date('" + sum.getStartTime()
						+ "','yyyy-MM-dd HH24:mi:ss') and to_date('" + sum.getEndTime()
						+ "','yyyy-MM-dd HH24:mi:ss')) or (t1.status>='0PAA10' and t1.create_time between to_date('"
						+ sum.getStartTime() + "','yyyy-MM-dd HH24:mi:ss') and to_date('" + sum.getEndTime()
						+ "','yyyy-MM-dd HH24:mi:ss'))) ";
			} else if ("2".equals(sum.getMemo1())) {
				sWhere += " and t1.deliver_date between to_date('" + sum.getStartTime().substring(0, 10)
						+ "','yyyy-MM-dd') and to_date('" + sum.getEndTime().substring(0, 10) + "','yyyy-MM-dd') ";
			}

			if ("1".equals(sum.getMemo2())) {
				sWhere += " and nvl2(t1.delivery_error_min, case when ((t1.estimate_weight - t1.delivery_error_min) < (case when  t1.order_nature in ('1','3') or t1.whole_coil = '1' then t2.unscheduled else t2.cl_undsn end)) then 1 else 0 end, 1) = 1 ";
			} else {
				sWhere += "  and (case when  t1.order_nature in ('1','3') or t1.whole_coil = '1' then t2.unscheduled else t2.cl_undsn end) is not null "; // 修复查看"不满足溢短装数据"
																																					// 包含非本工序的订单数据
			}

			if (sum.getObject() != null) {
				if (sum.getObject().getContract_no() != null && !"".equals(sum.getObject().getContract_no().trim())) {
					sWhere += " and t1.contract_no like '%" + sum.getObject().getContract_no().trim() + "%' ";
					sum.getObject().setContract_no(null);
				}
				if (sum.getObject().getOrder_no() != null && !"".equals(sum.getObject().getOrder_no().trim())) {
					sWhere += " and t1.order_no like '%" + sum.getObject().getOrder_no().trim() + "%' ";
					sum.getObject().setOrder_no(null);
				}
				if (sum.getObject().getProd_order_no() != null
						&& !"".equals(sum.getObject().getProd_order_no().trim())) {
					sWhere += " and t1.prod_order_no like '%" + sum.getObject().getProd_order_no().trim() + "%' ";
					sum.getObject().setProd_order_no(null);
				}

				if (sum.getObject().getSteel_name() != null && !"".equals(sum.getObject().getSteel_name().trim())) {
					sWhere += " and t1.steel_name like '%" + sum.getObject().getSteel_name().trim() + "%' ";
					sum.getObject().setSteel_name(null);
				}
			}
			// 工序点信息
			List<ComBaseInfo> infoI = this.getMapper(ComBaseInfoMapper.class).findWithCondition(null,
					"sort_code = '2002' AND validflag = '1'", null, 0, 0);
			ProcessPoint processpoint = new ProcessPoint(infoI);

			List<HashMap> listHm = this.getMapper(PlnProdorderMapper.class).doQueryUnscheduledProdorder(sum.getObject(),
					sWhere);
			Iterator<HashMap> it = listHm.iterator();
			while (it.hasNext()) {
				HashMap str = it.next();
				// 把不符合条件的数据remove
				if ("1".equals(sum.getMemo3()) && !"1".equals(str.get("ORDER_NATURE_TEMP")) && !"3".equals(str.get("ORDER_NATURE_TEMP"))) {
					// 获取有效的工艺路径
					String[] path = String.valueOf(str.get("WHOLE_PROCESS_CODES")).split("-");
					ArrayList<String> validpath = this.getBean(MesApiDesignInfoImpl.class).getProcessPath(path);
					if (Utils.isNotEmpty(validpath) && !processpoint.cross_cutting_code.equals(validpath.get(0))) {
						it.remove();
						continue;
					}
				}
			}
			for (HashMap hashMap : listHm) {
				// 加工计划备注
				SlmProcessPlan plan = new SlmProcessPlan();
				plan.setContract_line_no((String) hashMap.get("CONTRACT_LINE_NO"));
				plan.setContract_line_seq((String) hashMap.get("CONTRACT_LINE_SEQ"));
				plan.setOrder_seq((String) hashMap.get("ORDER_SEQ"));
				plan.setValid_flag("1");
				List<SlmProcessPlan> planList = this.getMapper(SlmProcessPlanMapper.class).findWithCondition(plan, "",
						" cut_order_no", 0, 0);
				if (planList.size() > 0) {
					// 关联加工计划信息表SLM_PROCESS_PLAN查询加工计划备注
					hashMap.put("PROCESSMEMO", planList.get(0).getMemo());
				} else {
					hashMap.put("PROCESSMEMO", null);
				}
			}
			rm.setState("200");
			rm.setData(listHm);
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("查询失败！");
			ex.printStackTrace();
			rm.setErrorInfo(ex.getMessage());
		}
		return rm;

	}

	/**
	 * 制程产线确认.
	 * 
	 * @param object 主键 prod_order_no 生产订单号 msc_pline 全程产线码 工艺路径
	 * @throws Exception
	 */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doPlineCheckWeb(CommonPage<PlnProdorder> sum) throws Exception {
		ResultModel rm = new ResultModel("200", "制程产线确认成功!");
		PlnProdorder pp = sum.getObject();
		if (pp == null || "".equals(pp)) {
			rm.setState("500");
			rm.setMsgInfo("请传入数据!");
			return rm;
		}
		if (pp.getProd_order_no() == null || "".equals(pp.getProd_order_no())) {
			rm.setState("500");
			rm.setMsgInfo("请传入生产订单号 !");
			return rm;
		}
		if (pp.getWhole_process_names() == null || "".equals(pp.getWhole_process_names())) {
			rm.setState("500");
			rm.setMsgInfo("请选择制程!");
			return rm;
		}
		List<PlnProdorder> ppd = this.getMapper(PlnProdorderMapper.class).findWithCondition(null,
				" prod_order_no = '" + pp.getProd_order_no() + "'", null, 0, 1);
		if (ppd == null || ppd.size() == 0) {
			rm.setState("500");
			rm.setMsgInfo("未找到[" + pp.getProd_order_no() + "]对应的生产订单信息 !");
			return rm;
		}
		if (ppd.get(0).getOrder_nature() == null || "".equals(ppd.get(0).getOrder_nature())
				|| "1".equals(ppd.get(0).getOrder_nature()) || "3".equals(ppd.get(0).getOrder_nature())) {
			rm.setState("500");
			rm.setMsgInfo("只有需要加工的订单才需制定制程产线 !");
			return rm;
		}
		List<PlnProdorderStatistic> lpps = this.getMapper(PlnProdorderStatisticMapper.class).findWithCondition(null,
				"prod_order_no = '" + pp.getProc_order_no() + "'", null, 0, 1);
		if (lpps != null && lpps.size() > 0) {
			for (PlnProdorderStatistic ppsc : lpps) {
				if (ppsc.getLw_dsn_cnt() > 0) {
					rm.setState("500");
					rm.setMsgInfo(ppsc.getOrder_no() + "已设计，不能设置制程！");
					return rm;
				}
			}
		}
		if (ppd.get(0).getStatus() != null && ppd.get(0).getStatus().compareTo("0PAA12") >= 0) {
			rm.setState("500");
			rm.setMsgInfo("生产订单[" + pp.getProd_order_no() + "]状态已改变,不能修改制程产线 !");
			return rm;
		}
		// 工序点信息
		List<ComBaseInfo> infoI = this.getMapper(ComBaseInfoMapper.class).findWithCondition(null,
				"sort_code = '2002' AND validflag = '1'", null, 0, 0);
		ProcessPoint processpoint = new ProcessPoint(infoI);
		List<PlnProcessPlan> ppp = this.getMapper(PlnProcessPlanMapper.class).findWithCondition(null,
				"produce_no = '" + ppd.get(0).getProduce_no() + "' and valid_flag = '1'", null, 0, 0);
		if (Utils.isNotEmpty(ppp)) {
			boolean flag_cross_cutting = false, flag_slitting = false;
			for (PlnProcessPlan slm : ppp) {
				if (slm.getCut_type().equals("1")) {
					flag_cross_cutting = true;
				} else if (slm.getCut_type().equals("2")) {
					flag_slitting = true;
				} else if (slm.getCut_type().equals("3")) {
					flag_cross_cutting = true;
					flag_slitting = true;
				}
			}
			if (Utils.isNotEmpty(pp.getWhole_process_codes())) {
				// 开平找不到加工计划报错
				if (pp.getWhole_process_codes().contains(processpoint.cross_cutting_code) && !flag_cross_cutting) {
					throw new Exception("工艺路径中包含开平工序,但是不存在开平加工计划!请重新质量设计!");
				} else if (pp.getWhole_process_codes().contains(processpoint.slitting_code) && !flag_slitting) {
					throw new Exception("工艺路径中包含分条工序,但是不存在分条加工计划!请重新质量设计!");
				}
			}
		}
		// 如果存在轧制工序 ,判断厚度范围是否符合
//		if (pp.getWhole_process_codes().contains(processpoint.rolling_code)) {
//			SlmOrdDesignMscPlSti sti = new SlmOrdDesignMscPlSti();
//			List<SlmOrdDesignMscTic> tics = new ArrayList<SlmOrdDesignMscTic>();
//			sti.setDesign_key(pp.getDesign_key());
//			sti.setMsc_pline(pp.getMsc_pline());
//			sti.setProcess_code(processpoint.rolling_code);
//			// 只查询工艺类工序点
//			sti.setProcess_point_type("403206");
//			List<SlmOrdDesignMscPlSti> stis = this.getBean(MesApiDesignInfoImpl.class).getQcmDesignInfo(sti);
//			for (SlmOrdDesignMscPlSti pl : stis) {
//				SlmOrdDesignMscTic tmp = new SlmOrdDesignMscTic();
//				BeanUtils.copyProperties(pl, tmp);
//				tmp.setPline_code("C016");
//				tmp.setMachine_code("M0008");
//				tics.add(tmp);
//			}
//			this.getBean(MesApiDesignInfoImpl.class).checkFirstProc(tics, ppd.get(0).getThick());
//			this.getBean(MesApiDesignInfoImpl.class).checkLastProc(tics, ppd.get(0).getThick());
//			this.getBean(MesApiDesignInfoImpl.class).comp_Proc_Std(tics);
//		}
		// 将全程产线码【MSC_PLINE】design_key_name、whole_process_names全工艺路径[WHOLE_PROCESS_CODES]design_key写入PLN_PRODORDER
		this.getMapper(PlnProdorderMapper.class).doUpdate(pp);
		return rm;
	}

	// -----------------------------------------2018-09-19 罩退----------------------------------------
	/**
	 * 查询计划模块已接收过的未排产的生产订单 罩退挂单使用 memo1 1则为下发产生时间 为2交货时间 memo2 1为勾选了满足溢短装量订单
	 */
	public ResultModel doQueryAnnealProdorderInfo(CommonPage<PlnProdorder> sum) {
		ResultModel rm = new ResultModel("200", "");

		try {
			String sWhere = "";
			// 假如为1则为下发产生时间 为2交货时间
			if ("1".equals(sum.getMemo1())) {
				sWhere += " and ((t1.status>='0PAA12' and t1.send_time between to_date('" + sum.getStartTime()
						+ "','yyyy-MM-dd HH24:mi:ss') and to_date('" + sum.getEndTime()
						+ "','yyyy-MM-dd HH24:mi:ss')) or (t1.status>='0PAA10' and t1.create_time between to_date('"
						+ sum.getStartTime() + "','yyyy-MM-dd HH24:mi:ss') and to_date('" + sum.getEndTime()
						+ "','yyyy-MM-dd HH24:mi:ss'))) ";
			} else if ("2".equals(sum.getMemo1())) {
				sWhere += " and t1.deliver_date between to_date('" + sum.getStartTime().substring(0, 10)
						+ "','yyyy-MM-dd') and to_date('" + sum.getEndTime().substring(0, 10) + "','yyyy-MM-dd') ";
			}

			if ("1".equals(sum.getMemo2())) {
				sWhere += " and nvl2(t1.delivery_error_min, case when ((t1.estimate_weight - t1.delivery_error_min) < (case when  t1.order_nature in ('1','3') or t1.whole_coil = '1' then t2.unscheduled else t2.an_undsn end)) then 1 else 0 end, 1) = 1 ";
			} else {
				sWhere += "  and (case when  t1.order_nature in ('1','3') or t1.whole_coil = '1' then t2.unscheduled else t2.an_undsn end) is not null "; // 修复查看"不满足溢短装数据"
																																					// 包含非本工序的订单数据
			}

			if (sum.getObject() != null) {
				if (sum.getObject().getContract_no() != null && !"".equals(sum.getObject().getContract_no().trim())) {
					sWhere += " and t1.contract_no like '%" + sum.getObject().getContract_no().trim() + "%' ";
					sum.getObject().setContract_no(null);
				}
				if (sum.getObject().getOrder_no() != null && !"".equals(sum.getObject().getOrder_no().trim())) {
					sWhere += " and t1.order_no like '%" + sum.getObject().getOrder_no().trim() + "%' ";
					sum.getObject().setOrder_no(null);
				}
				if (sum.getObject().getProd_order_no() != null
						&& !"".equals(sum.getObject().getProd_order_no().trim())) {
					sWhere += " and t1.prod_order_no like '%" + sum.getObject().getProd_order_no().trim() + "%' ";
					sum.getObject().setProd_order_no(null);
				}

				if (sum.getObject().getSteel_name() != null && !"".equals(sum.getObject().getSteel_name().trim())) {
					sWhere += " and t1.steel_name like '%" + sum.getObject().getSteel_name().trim() + "%' ";
					sum.getObject().setSteel_name(null);
				}
			}
			// 工序点信息
			List<ComBaseInfo> infoI = this.getMapper(ComBaseInfoMapper.class).findWithCondition(null,
					"sort_code = '2002' AND validflag = '1'", null, 0, 0);
			ProcessPoint processpoint = new ProcessPoint(infoI);

			List<HashMap> listHm = this.getMapper(PlnProdorderMapper.class).doQueryAnnealProdorderInfo(sum.getObject(),
					sWhere);
			Iterator<HashMap> it = listHm.iterator();
			while (it.hasNext()) {
				HashMap str = it.next();
				// 把不符合条件的数据remove
				if ("1".equals(sum.getMemo3()) && !"1".equals(str.get("ORDER_NATURE_TEMP")) && !"3".equals(str.get("ORDER_NATURE_TEMP"))) {
					// 获取有效的工艺路径
					String[] path = String.valueOf(str.get("WHOLE_PROCESS_CODES")).split("-");
					ArrayList<String> validpath = this.getBean(MesApiDesignInfoImpl.class).getProcessPath(path);
					if (Utils.isNotEmpty(validpath) && !processpoint.anneal_code.equals(validpath.get(0))) {
						it.remove();
						continue;
					}
				}
			}
			for (HashMap hashMap : listHm) {
				// 加工计划备注
				SlmProcessPlan plan = new SlmProcessPlan();
				plan.setContract_line_no((String) hashMap.get("CONTRACT_LINE_NO"));
				plan.setContract_line_seq((String) hashMap.get("CONTRACT_LINE_SEQ"));
				plan.setOrder_seq((String) hashMap.get("ORDER_SEQ"));
				plan.setValid_flag("1");
				List<SlmProcessPlan> planList = this.getMapper(SlmProcessPlanMapper.class).findWithCondition(plan, "",
						" cut_order_no", 0, 0);
				if (planList.size() > 0) {
					// 关联加工计划信息表SLM_PROCESS_PLAN查询加工计划备注
					hashMap.put("PROCESSMEMO", planList.get(0).getMemo());
				} else {
					hashMap.put("PROCESSMEMO", null);
				}
			}
			rm.setState("200");
			rm.setData(listHm);
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("查询失败！");
			ex.printStackTrace();
			rm.setErrorInfo(ex.getMessage());
		}
		return rm;
	}

	// -----------------------------------------2018-10-17 平整----------------------------------------

	/**
	 * 查询计划模块已接收过的未排产的生产订单 平整挂单使用 memo1 1则为下发产生时间 为2交货时间 memo2 1为勾选了满足溢短装量订单
	 */
	public ResultModel doQuerySrProdorderInfo(CommonPage<PlnProdorder> sum) {
		ResultModel rm = new ResultModel("200", "");

		try {
			String sWhere = "";
			// 假如为1则为下发产生时间 为2交货时间
			if ("1".equals(sum.getMemo1())) {
				sWhere += " and ((t1.status>='0PAA12' and t1.send_time between to_date('" + sum.getStartTime()
						+ "','yyyy-MM-dd HH24:mi:ss') and to_date('" + sum.getEndTime()
						+ "','yyyy-MM-dd HH24:mi:ss')) or (t1.status>='0PAA10' and t1.create_time between to_date('"
						+ sum.getStartTime() + "','yyyy-MM-dd HH24:mi:ss') and to_date('" + sum.getEndTime()
						+ "','yyyy-MM-dd HH24:mi:ss'))) ";
			} else if ("2".equals(sum.getMemo1())) {
				sWhere += " and t1.deliver_date between to_date('" + sum.getStartTime().substring(0, 10)
						+ "','yyyy-MM-dd') and to_date('" + sum.getEndTime().substring(0, 10) + "','yyyy-MM-dd') ";
			}

			if ("1".equals(sum.getMemo2())) {
				sWhere += " and nvl2(t1.delivery_error_min, case when ((t1.estimate_weight - t1.delivery_error_min) < (case when  t1.order_nature in ('1','3') or t1.whole_coil = '1' then t2.unscheduled else t2.sr_undsn end)) then 1 else 0 end, 1) = 1 ";
			} else {
				sWhere += "  and (case when  t1.order_nature in ('1','3') or t1.whole_coil = '1' then t2.unscheduled else t2.sr_undsn end) is not null "; // 修复查看"不满足溢短装数据"
																																					// 包含非本工序的订单数据
			}

			if (sum.getObject() != null) {
				if (sum.getObject().getContract_no() != null && !"".equals(sum.getObject().getContract_no().trim())) {
					sWhere += " and t1.contract_no like '%" + sum.getObject().getContract_no().trim() + "%' ";
					sum.getObject().setContract_no(null);
				}
				if (sum.getObject().getOrder_no() != null && !"".equals(sum.getObject().getOrder_no().trim())) {
					sWhere += " and t1.order_no like '%" + sum.getObject().getOrder_no().trim() + "%' ";
					sum.getObject().setOrder_no(null);
				}
				if (sum.getObject().getProd_order_no() != null
						&& !"".equals(sum.getObject().getProd_order_no().trim())) {
					sWhere += " and t1.prod_order_no like '%" + sum.getObject().getProd_order_no().trim() + "%' ";
					sum.getObject().setProd_order_no(null);
				}

				if (sum.getObject().getSteel_name() != null && !"".equals(sum.getObject().getSteel_name().trim())) {
					sWhere += " and t1.steel_name like '%" + sum.getObject().getSteel_name().trim() + "%' ";
					sum.getObject().setSteel_name(null);
				}
			}
			// 工序点信息
			List<ComBaseInfo> infoI = this.getMapper(ComBaseInfoMapper.class).findWithCondition(null,
					"sort_code = '2002' AND validflag = '1'", null, 0, 0);
			ProcessPoint processpoint = new ProcessPoint(infoI);

			List<HashMap> listHm = this.getMapper(PlnProdorderMapper.class).doQuerySrProdorderInfo(sum.getObject(),
					sWhere);
			Iterator<HashMap> it = listHm.iterator();
			while (it.hasNext()) {
				HashMap str = it.next();
				// 把不符合条件的数据remove
				if ("1".equals(sum.getMemo3()) && !"1".equals(str.get("ORDER_NATURE_TEMP")) && !"3".equals(str.get("ORDER_NATURE_TEMP"))) {
					// 获取有效的工艺路径
					String[] path = String.valueOf(str.get("WHOLE_PROCESS_CODES")).split("-");
					ArrayList<String> validpath = this.getBean(MesApiDesignInfoImpl.class).getProcessPath(path);
					if (Utils.isNotEmpty(validpath) && !processpoint.smooth_code.equals(validpath.get(0))) {
						it.remove();
						continue;
					}
				}
			}
			for (HashMap hashMap : listHm) {
				// 加工计划备注
				SlmProcessPlan plan = new SlmProcessPlan();
				plan.setContract_line_no((String) hashMap.get("CONTRACT_LINE_NO"));
				plan.setContract_line_seq((String) hashMap.get("CONTRACT_LINE_SEQ"));
				plan.setOrder_seq((String) hashMap.get("ORDER_SEQ"));
				plan.setValid_flag("1");
				List<SlmProcessPlan> planList = this.getMapper(SlmProcessPlanMapper.class).findWithCondition(plan, "",
						" cut_order_no", 0, 0);
				if (planList.size() > 0) {
					// 关联加工计划信息表SLM_PROCESS_PLAN查询加工计划备注
					hashMap.put("PROCESSMEMO", planList.get(0).getMemo());
				} else {
					hashMap.put("PROCESSMEMO", null);
				}
			}
			rm.setState("200");
			rm.setData(listHm);
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("查询失败！");
			ex.printStackTrace();
			rm.setErrorInfo(ex.getMessage());
		}
		return rm;
	}

	// -----------------------------------------2019-03-26 轧制----------------------------------------
	
	/**
	 * 查询计划模块已接收过的未排产的生产订单 轧制挂单使用 memo1 1则为下发产生时间 为2交货时间 memo2 1为勾选了满足溢短装量订单
	 */
	public ResultModel doQueryRollingProdorderInfo(CommonPage<PlnProdorder> sum) {
		ResultModel rm = new ResultModel("200", "");

		try {
			String sWhere = "";
			// 假如为1则为下发产生时间 为2交货时间
			if ("1".equals(sum.getMemo1())) {
				sWhere += " and ((t1.status>='0PAA12' and t1.send_time between to_date('" + sum.getStartTime()
						+ "','yyyy-MM-dd HH24:mi:ss') and to_date('" + sum.getEndTime()
						+ "','yyyy-MM-dd HH24:mi:ss')) or (t1.status>='0PAA10' and t1.create_time between to_date('"
						+ sum.getStartTime() + "','yyyy-MM-dd HH24:mi:ss') and to_date('" + sum.getEndTime()
						+ "','yyyy-MM-dd HH24:mi:ss'))) ";
			} else if ("2".equals(sum.getMemo1())) {
				sWhere += " and t1.deliver_date between to_date('" + sum.getStartTime().substring(0, 10)
						+ "','yyyy-MM-dd') and to_date('" + sum.getEndTime().substring(0, 10) + "','yyyy-MM-dd') ";
			}

			if ("1".equals(sum.getMemo2())) {
				sWhere += " and nvl2(t1.delivery_error_min, case when ((t1.estimate_weight - t1.delivery_error_min) < (case when  t1.order_nature in ('1','3') or t1.whole_coil = '1' then t2.unscheduled else t2.rl_undsn end)) then 1 else 0 end, 1) = 1 ";
			} else {
				sWhere += "  and (case when  t1.order_nature in ('1','3') or t1.whole_coil = '1' then t2.unscheduled else t2.rl_undsn end) is not null "; // 修复查看"不满足溢短装数据"
																																					// 包含非本工序的订单数据
			}

			if (sum.getObject() != null) {
				if (sum.getObject().getContract_no() != null && !"".equals(sum.getObject().getContract_no().trim())) {
					sWhere += " and t1.contract_no like '%" + sum.getObject().getContract_no().trim() + "%' ";
					sum.getObject().setContract_no(null);
				}
				if (sum.getObject().getOrder_no() != null && !"".equals(sum.getObject().getOrder_no().trim())) {
					sWhere += " and t1.order_no like '%" + sum.getObject().getOrder_no().trim() + "%' ";
					sum.getObject().setOrder_no(null);
				}
				if (sum.getObject().getProd_order_no() != null
						&& !"".equals(sum.getObject().getProd_order_no().trim())) {
					sWhere += " and t1.prod_order_no like '%" + sum.getObject().getProd_order_no().trim() + "%' ";
					sum.getObject().setProd_order_no(null);
				}

				if (sum.getObject().getSteel_name() != null && !"".equals(sum.getObject().getSteel_name().trim())) {
					sWhere += " and t1.steel_name like '%" + sum.getObject().getSteel_name().trim() + "%' ";
					sum.getObject().setSteel_name(null);
				}
			}
			// 工序点信息
			List<ComBaseInfo> infoI = this.getMapper(ComBaseInfoMapper.class).findWithCondition(null,
					"sort_code = '2002' AND validflag = '1'", null, 0, 0);
			ProcessPoint processpoint = new ProcessPoint(infoI);

			List<HashMap> listHm = this.getMapper(PlnProdorderMapper.class).doQueryRollingProdorderInfo(sum.getObject(),
					sWhere);
			Iterator<HashMap> it = listHm.iterator();
			while (it.hasNext()) {
				HashMap str = it.next();
				// 把不符合条件的数据remove
				if ("1".equals(sum.getMemo3()) && !"1".equals(str.get("ORDER_NATURE_TEMP")) && !"3".equals(str.get("ORDER_NATURE_TEMP"))) {
					// 获取有效的工艺路径
					String[] path = String.valueOf(str.get("WHOLE_PROCESS_CODES")).split("-");
					ArrayList<String> validpath = this.getBean(MesApiDesignInfoImpl.class).getProcessPath(path);
					if (Utils.isNotEmpty(validpath) && !processpoint.rolling_code.equals(validpath.get(0))) {
						it.remove();
						continue;
					}
				}
			}
//			for (HashMap hashMap : listHm) {
//				// 加工计划备注
//				SlmProcessPlan plan = new SlmProcessPlan();
//				plan.setContract_line_no((String) hashMap.get("CONTRACT_LINE_NO"));
//				plan.setContract_line_seq((String) hashMap.get("CONTRACT_LINE_SEQ"));
//				plan.setOrder_seq((String) hashMap.get("ORDER_SEQ"));
//				plan.setValid_flag("1");
//				List<SlmProcessPlan> planList = this.getMapper(SlmProcessPlanMapper.class).findWithCondition(plan, "",
//						" cut_order_no", 0, 0);
//				if (planList.size() > 0) {
//					// 关联加工计划信息表SLM_PROCESS_PLAN查询加工计划备注
//					hashMap.put("PROCESSMEMO", planList.get(0).getMemo());
//				} else {
//					hashMap.put("PROCESSMEMO", null);
//				}
//			}
			rm.setState("200");
			rm.setData(listHm);
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("查询失败！");
			ex.printStackTrace();
			rm.setErrorInfo(ex.getMessage());
		}
		return rm;
	}
	// -----------------------------------------2019-04-23 酸洗----------------------------------------
	
	/**
	 * 查询计划模块已接收过的未排产的生产订单 酸洗挂单使用 memo1 1则为下发产生时间 为2交货时间 memo2 1为勾选了满足溢短装量订单
	 */
	public ResultModel doQueryPickleProdorderInfo(CommonPage<PlnProdorder> sum) {
		ResultModel rm = new ResultModel("200", "");
		
		try {
			String sWhere = "";
			// 假如为1则为下发产生时间 为2交货时间
			if ("1".equals(sum.getMemo1())) {
				sWhere += " and ((t1.status>='0PAA12' and t1.send_time between to_date('" + sum.getStartTime()
				+ "','yyyy-MM-dd HH24:mi:ss') and to_date('" + sum.getEndTime()
				+ "','yyyy-MM-dd HH24:mi:ss')) or (t1.status>='0PAA10' and t1.create_time between to_date('"
				+ sum.getStartTime() + "','yyyy-MM-dd HH24:mi:ss') and to_date('" + sum.getEndTime()
				+ "','yyyy-MM-dd HH24:mi:ss'))) ";
			} else if ("2".equals(sum.getMemo1())) {
				sWhere += " and t1.deliver_date between to_date('" + sum.getStartTime().substring(0, 10)
						+ "','yyyy-MM-dd') and to_date('" + sum.getEndTime().substring(0, 10) + "','yyyy-MM-dd') ";
			}
			
			if ("1".equals(sum.getMemo2())) {
				sWhere += " and nvl2(t1.delivery_error_min, case when ((t1.estimate_weight - t1.delivery_error_min) < (case when  t1.order_nature in ('1','2','3') or t1.whole_coil = '1' then t2.unscheduled else t2.pc_undsn end)) then 1 else 0 end, 1) = 1 ";
			} else {
				sWhere += "  and (case when  t1.order_nature in ('1','2','3') or t1.whole_coil = '1' then t2.unscheduled else t2.pc_undsn end) is not null "; // 修复查看"不满足溢短装数据"
				// 包含非本工序的订单数据
			}
			
			if (sum.getObject() != null) {
				if (sum.getObject().getContract_no() != null && !"".equals(sum.getObject().getContract_no().trim())) {
					sWhere += " and t1.contract_no like '%" + sum.getObject().getContract_no().trim() + "%' ";
					sum.getObject().setContract_no(null);
				}
				if (sum.getObject().getOrder_no() != null && !"".equals(sum.getObject().getOrder_no().trim())) {
					sWhere += " and t1.order_no like '%" + sum.getObject().getOrder_no().trim() + "%' ";
					sum.getObject().setOrder_no(null);
				}
				if (sum.getObject().getProd_order_no() != null
						&& !"".equals(sum.getObject().getProd_order_no().trim())) {
					sWhere += " and t1.prod_order_no like '%" + sum.getObject().getProd_order_no().trim() + "%' ";
					sum.getObject().setProd_order_no(null);
				}
				
				if (sum.getObject().getSteel_name() != null && !"".equals(sum.getObject().getSteel_name().trim())) {
					sWhere += " and t1.steel_name like '%" + sum.getObject().getSteel_name().trim() + "%' ";
					sum.getObject().setSteel_name(null);
				}
			}
			// 工序点信息
			List<ComBaseInfo> infoI = this.getMapper(ComBaseInfoMapper.class).findWithCondition(null,
					"sort_code = '2002' AND validflag = '1'", null, 0, 0);
			ProcessPoint processpoint = new ProcessPoint(infoI);
			
			List<HashMap> listHm = this.getMapper(PlnProdorderMapper.class).doQueryPickleProdorderInfo(sum.getObject(),
					sWhere);
			Iterator<HashMap> it = listHm.iterator();
			while (it.hasNext()) {
				HashMap str = it.next();
				// 把不符合条件的数据remove
				if ("1".equals(sum.getMemo3()) && !"1".equals(str.get("ORDER_NATURE_TEMP")) && !"3".equals(str.get("ORDER_NATURE_TEMP"))) {
					// 获取有效的工艺路径
					String[] path = String.valueOf(str.get("WHOLE_PROCESS_CODES")).split("-");
					ArrayList<String> validpath = this.getBean(MesApiDesignInfoImpl.class).getProcessPath(path);
					if (Utils.isNotEmpty(validpath) && !processpoint.pickle_code.equals(validpath.get(0))) {
						it.remove();
						continue;
					}
				}
			}
			rm.setState("200");
			rm.setData(listHm);
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("查询失败！");
			ex.printStackTrace();
			rm.setErrorInfo(ex.getMessage());
		}
		return rm;
	}
	
	
	/**
	 * 查询计划模块已接收过的未排产的生产订单 
	 * 成品挂单使用 
	 * memo1 1则为下发产生时间 为2交货时间 memo2 1为勾选了满足溢短装量订单
	 */
	public ResultModel queOrdInfo(CommonPage<PlnProdorder> sum) {
		ResultModel rm = new ResultModel("200", "");

		try {
			String sWhere = "";
			// 假如为1则为下发产生时间 为2交货时间
			if ("1".equals(sum.getMemo1())) {
				sWhere += " and ((t1.status>='0PAA12' and t1.send_time between to_date('" + sum.getStartTime()
						+ "','yyyy-MM-dd HH24:mi:ss') and to_date('" + sum.getEndTime()
						+ "','yyyy-MM-dd HH24:mi:ss')) or (t1.status>='0PAA10' and t1.create_time between to_date('"
						+ sum.getStartTime() + "','yyyy-MM-dd HH24:mi:ss') and to_date('" + sum.getEndTime()
						+ "','yyyy-MM-dd HH24:mi:ss'))) ";
			} else if ("2".equals(sum.getMemo1())) {
				sWhere += " and t1.deliver_date between to_date('" + sum.getStartTime().substring(0, 10)
						+ "','yyyy-MM-dd') and to_date('" + sum.getEndTime().substring(0, 10) + "','yyyy-MM-dd') ";
			}

			if ("1".equals(sum.getMemo2())) {
				sWhere += " and nvl2(t1.delivery_error_min, case when ((t1.estimate_weight - t1.delivery_error_min) <"
						  + "coalesce(case when t2.lw_undsn = 0 then null else  t2.lw_undsn end ," + 
							"case when t2.cl_undsn = 0 then null else  t2.cl_undsn end,"+ 
							"case when t2.an_undsn = 0 then null else  t2.an_undsn end,"+ 
							"case when t2.pc_undsn = 0 then null else  t2.pc_undsn end,"+ 
							"case when t2.sr_undsn = 0 then null else  t2.sr_undsn end,"+ 
							"case when t2.rl_undsn = 0 then null else  t2.rl_undsn end )) then 1 else 0 end, 1) = 1 ";
			} /*else {
				sWhere += "and coalesce(case when t2.lw_undsn = 0 then null else  t2.lw_undsn end ," + 
							 " case when t2.cl_undsn = 0 then null else  t2.cl_undsn end ," + 
							 " case when t2.an_undsn = 0 then null else  t2.an_undsn end ," + 
							 " case when t2.pc_undsn = 0 then null else  t2.pc_undsn end ," + 
							 " case when t2.sr_undsn = 0 then null else  t2.sr_undsn end ," + 
							 " case when t2.rl_undsn = 0 then null else  t2.rl_undsn end ) is not null "; 
			}*/

			if (sum.getObject() != null) {
				if (sum.getObject().getContract_no() != null && !"".equals(sum.getObject().getContract_no().trim())) {
					sWhere += " and t1.contract_no like '%" + sum.getObject().getContract_no().trim() + "%' ";
					sum.getObject().setContract_no(null);
				}
				if (sum.getObject().getOrder_no() != null && !"".equals(sum.getObject().getOrder_no().trim())) {
					sWhere += " and t1.order_no like '%" + sum.getObject().getOrder_no().trim() + "%' ";
					sum.getObject().setOrder_no(null);
				}
				if (sum.getObject().getProd_order_no() != null
						&& !"".equals(sum.getObject().getProd_order_no().trim())) {
					sWhere += " and t1.prod_order_no like '%" + sum.getObject().getProd_order_no().trim() + "%' ";
					sum.getObject().setProd_order_no(null);
				}

				if (sum.getObject().getSteel_name() != null && !"".equals(sum.getObject().getSteel_name().trim())) {
					sWhere += " and t1.steel_name like '%" + sum.getObject().getSteel_name().trim() + "%' ";
					sum.getObject().setSteel_name(null);
				}
			}

			List<HashMap> listHm = this.getMapper(PlnProdorderMapper.class).queOrdInfo(sum.getObject(),sWhere);
			rm.setState("200");
			rm.setData(listHm);
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("查询失败！");
			ex.printStackTrace();
			rm.setErrorInfo(ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 获取公共的工艺路径
	 * 
	 * @param temp
	 * @return design_key : 工艺路径
	 */
	public static Map<String, List<SlmOrdDesignMscPl>> getCommonPath(
			List<Map<String, Map<String, List<SlmOrdDesignMscPl>>>> params) {
		List<ArrayList<String>> list = new ArrayList<ArrayList<String>>();
		List<SlmOrdDesignMscPl> path = new ArrayList<>();
		Map<String, List<SlmOrdDesignMscPl>> rst_map = new HashMap<>();
		// list <plan_no : map(design_key : 制程集合)> 集合
		for (Map<String, Map<String, List<SlmOrdDesignMscPl>>> temp : params) {
			// 一个加工计划对应的工艺路径集合
			ArrayList<String> str = new ArrayList<String>();
			// plan_no : map(design_key : 制程集合)
			for (Entry<String, Map<String, List<SlmOrdDesignMscPl>>> map : temp.entrySet()) {
				// design_key : 制程集合
				for (Entry<String, List<SlmOrdDesignMscPl>> entry : map.getValue().entrySet()) {
					// 制程对象
					for (SlmOrdDesignMscPl slm : entry.getValue()) {
						// 工艺路径
						str.add(slm.getStations_code());
					}
				}
			}
			list.add(str);
		}
		// 获取各加工计划公共的工艺路径
		ArrayList<String> result = Utils.getIntersection(list);
		if (Utils.isEmpty(result)) {
			return null;
		} else {
			// 根据公共的工艺路径反取 design : 制程对象集合
			// 取最后一个加工计划 map
			for (Entry<String, Map<String, List<SlmOrdDesignMscPl>>> msc : params.get(params.size() - 1).entrySet()) {
				// design_key map
				for (Entry<String, List<SlmOrdDesignMscPl>> str : msc.getValue().entrySet()) {
					// 制程对象
					for (SlmOrdDesignMscPl slm : str.getValue()) {
						// 包含公共工艺路径的对象提取
						result.contains(slm.getStations_code());
						path.add(slm);
					}
					rst_map.put(str.getKey(), path);
				}
			}
			return rst_map;
		}
	}

	/**
	 * 获取生产订单公共的工艺路径
	 * 
	 * @param prod_order_no 生产订单号
	 * @throws Exception
	 */
	public List<SlmOrdDesignMscPl> getOrderPath(String prod_order_no) throws Exception {
		if (Utils.isEmpty(prod_order_no)) {
			throw new Exception("请传入生产订单号(获取工艺路径)!");
		}
		List<PlnProdorder> ppo = this.getMapper(PlnProdorderMapper.class).findWithCondition(null,
				" prod_order_no = '" + prod_order_no + "'", null, 0, 1);
		if (Utils.isEmpty(ppo)) {
			throw new Exception("未找到生产订单[" + prod_order_no + "]信息!");
		}
		List<PlnProcessPlan> ppp = this.getMapper(PlnProcessPlanMapper.class).findWithCondition(null,
				" produce_no = '" + ppo.get(0).getProduce_no() + "' and valid_flag = '1'", null, 0, 0);
		if (Utils.isEmpty(ppp)) {
			throw new Exception("未找到加工计划[" + prod_order_no + "]信息!");
		}
		// plan : <design_key : 制程对象集合>
		List<Map<String, Map<String, List<SlmOrdDesignMscPl>>>> params = new ArrayList<>();
		List<ArrayList<String>> list = new ArrayList<ArrayList<String>>();
		List<SlmOrdDesignMscPl> path = new ArrayList<>();
		// 如果只有一条加工计划,并且是不切直接取一条工艺路径
		if (ppp.size() == 1 && ppp.get(0).getCut_type().equals("0")) {
			// 1、获取design_key
			SlmOrdDesignMsc som = new SlmOrdDesignMsc();
			som.setContract_line_no(ppp.get(0).getPlan_no()); // 通过加工计划号找design_key
			CommonPage<SlmOrdDesignMsc> sodm = new CommonPage<SlmOrdDesignMsc>();
			sodm.setObject(som);
			ResultModel result_DK = this.getBean(QmsApiServiceImpl.class).GetAllByDesignKey(sodm);
			if (!"200".equals(result_DK.getState())) {
				throw new Exception("自动确认制程产线失败!" + result_DK.getMsgInfo());
			}
			// 2、获取工艺路径
			List<SlmOrdDesignMsc> design_key = (List<SlmOrdDesignMsc>) result_DK.getData();
			for (SlmOrdDesignMsc design : design_key) {
				ResultModel result_ZC = this.getBean(MesApiDesignInfoImpl.class).GetMscByDesignKey(design.getDesign_key());
				if (!"200".equals(result_ZC.getState())) {
					throw new Exception("自动确认工艺路径失败!" + result_ZC.getMsgInfo());
				}
				List<SlmOrdDesignMscPl> msc_pline = (List<SlmOrdDesignMscPl>) result_ZC.getData();

				if (Utils.isEmpty(path) || !(path.size() == msc_pline.size() && path.containsAll(msc_pline))) {
					path.addAll(msc_pline);
				}
			}
		} else {
			for (PlnProcessPlan slm : ppp) {
				Map<String, List<SlmOrdDesignMscPl>> map = new HashMap<String, List<SlmOrdDesignMscPl>>();
				Map<String, Map<String, List<SlmOrdDesignMscPl>>> plan_no = new HashMap<String, Map<String, List<SlmOrdDesignMscPl>>>();
				// 1、获取design_key
				SlmOrdDesignMsc som = new SlmOrdDesignMsc();
				som.setContract_line_no(slm.getPlan_no()); // 通过加工计划号找design_key
				CommonPage<SlmOrdDesignMsc> sodm = new CommonPage<SlmOrdDesignMsc>();
				sodm.setObject(som);
				ResultModel result_DK = this.getBean(QmsApiServiceImpl.class).GetAllByDesignKey(sodm);
				if (!"200".equals(result_DK.getState())) {
					throw new Exception("获取制程产线失败!" + result_DK.getMsgInfo());
				}
				// 2、获取工艺路径
				List<SlmOrdDesignMsc> design_key = (List<SlmOrdDesignMsc>) result_DK.getData();
				for (SlmOrdDesignMsc design : design_key) {
					ResultModel result_ZC = this.getBean(MesApiDesignInfoImpl.class)
							.GetMscByDesignKey(design.getDesign_key());
					if (!"200".equals(result_ZC.getState())) {
						throw new Exception("获取确认工艺路径失败!" + result_ZC.getMsgInfo());
					}
					List<SlmOrdDesignMscPl> msc_pline = (List<SlmOrdDesignMscPl>) result_ZC.getData();
					map.put(design.getDesign_key(), msc_pline);
				}
				plan_no.put(slm.getPlan_no(), map);
				params.add(plan_no);
			}
			// list <plan_no : map(design_key : 制程集合)> 集合
			for (Map<String, Map<String, List<SlmOrdDesignMscPl>>> temp : params) {
				// 一个加工计划对应的工艺路径集合
				ArrayList<String> str = new ArrayList<String>();
				// plan_no : map(design_key : 制程集合)
				for (Entry<String, Map<String, List<SlmOrdDesignMscPl>>> map : temp.entrySet()) {
					// design_key : 制程集合
					for (Entry<String, List<SlmOrdDesignMscPl>> entry : map.getValue().entrySet()) {
						// 制程对象
						for (SlmOrdDesignMscPl slm : entry.getValue()) {
							// 工艺路径
							str.add(slm.getStations_code());
						}
					}
				}
				list.add(str);
			}
			// 获取各加工计划公共的工艺路径
			ArrayList<String> result = Utils.getIntersection(list);
			// 根据公共的工艺路径反取 design : 制程对象集合
			// 取最后一个加工计划 map
			for (Entry<String, Map<String, List<SlmOrdDesignMscPl>>> msc : params.get(params.size() - 1).entrySet()) {
				// design_key map
				for (Entry<String, List<SlmOrdDesignMscPl>> str : msc.getValue().entrySet()) {
					// 制程对象
					for (SlmOrdDesignMscPl slm : str.getValue()) {
						// 包含公共工艺路径的对象提取
						result.contains(slm.getStations_code());
						path.add(slm);
					}
				}
			}
		}
		return path;
	}
	
	/**
	 * 生产订单关闭和启用功能 20200212 zlz
	 * @param sum
	 * @return
	 * @throws Exception 
	 */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doUpdatePlnProdorderIsClosed(CommonPage<PlnProdorder> cp) throws Exception {
		ResultModel rm = new ResultModel();
		List<PlnProdorder> list = cp.getObjectList();
		String opr = cp.getMemo1();//memo1传递操作动作：1关闭   0开启
		if (list==null || list.size()<=0) {
			throw new Exception("请传入参数");
		}
		for (PlnProdorder pp : list) {
			this.getMapper(PlnProdorderMapper.class).doUpdatePlnProdorderIsClosed(pp.getProc_order_no(),opr);
		}
		rm.setState("200");
		rm.setMsgInfo("操作成功");
		return rm;
	}
	
}
