/***文档注释***********************************************
 * 作者               :                   易鑫
 * 创建日期      :                   2017.11.21
 * 描述               :        			分条子卷实绩
 * 注意事项      :                   无
 * 遗留BUG :                   无
 * 修改日期      :                   
 * 修改人员      :                   
 * 修改内容      :                   
 ***********************************************************/

package market.Mes.Lengthwise.Performance.impl;

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

import market.Api.Lms.impl.LmsApiServiceImpl;
import market.Api.Mes.impl.MesApi12mmPdiPdoImpl;
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.Api.Qms.vo.JudgeResult;
import market.Com.impl.ComBaseMachineServiceImpl;
import market.Com.impl.PbModelDbServiceImpl;
import market.Com.mapper.ComBaseInfoMapper;
import market.Com.mapper.ComBaseMachineMapper;
import market.Com.mapper.ComBasePlineMapper;
import market.Com.mapper.ComBaseSteelMapper;
import market.Com.pb.DoubleUtil;
import market.Com.vo.ComBaseInfo;
import market.Com.vo.ComBaseMachine;
import market.Com.vo.ComBasePline;
import market.Com.vo.ComBaseSteel;
import market.Com.vo.CommonPage;
import market.Com.vo.PbModelDb;
import market.Com.vo.ResultModel;
import market.Lms.Warehouse.mapper.YdmProductDetailMapper;
import market.Lms.Warehouse.vo.YdmProductDetail;
import market.Mes.Lengthwise.Performance.mapper.IfSlit01LogMapper;
import market.Mes.Lengthwise.Performance.mapper.MesCrSlittingDMapper;
import market.Mes.Lengthwise.Performance.mapper.MesCrSlittingMMapper;
import market.Mes.Lengthwise.Performance.mapper.MesCrSlittingTrcMapper;
import market.Mes.Lengthwise.Performance.mapper.MesCrSlittingWgtMapper;
import market.Mes.Lengthwise.Performance.service.MesCrSlittingDService;
import market.Mes.Lengthwise.Performance.vo.MesCrSlittingD;
import market.Mes.Lengthwise.Performance.vo.MesCrSlittingDSum;
import market.Mes.Lengthwise.Performance.vo.MesCrSlittingM;
import market.Mes.Lengthwise.Performance.vo.MesCrSlittingSum;
import market.Mes.Lengthwise.Performance.vo.MesCrSlittingTrc;
import market.Mes.Lengthwise.Performance.vo.MesCrSlittingWgt;
import market.Mes.Lengthwise.Performance.vo.PlnLengthwisePlanDetailAndMesCrSlittingD;
import market.Mes.Lengthwise.Plan.mapper.PlnLengthwisePlanDetailMapper;
import market.Mes.Lengthwise.Plan.mapper.PlnLengthwisePlanMapper;
import market.Mes.Lengthwise.Plan.mapper.PlnMaterielDetailMapper;
import market.Mes.Lengthwise.Plan.mapper.PlnProcessPlanMapper;
import market.Mes.Lengthwise.Plan.vo.PlnLengthwisePlan;
import market.Mes.Lengthwise.Plan.vo.PlnLengthwisePlanDetail;
import market.Mes.Lengthwise.Plan.vo.PlnLengthwisePlanSum;
import market.Mes.Lengthwise.Plan.vo.PlnMaterielDetail;
import market.Mes.Lengthwise.Plan.vo.PlnMaterielDetailSum;
import market.Mes.Lengthwise.Plan.vo.PlnProcessPlan;
import market.Mes.MaterielTrack.vo.PrcMaterielRelation;
import market.Mes.Opr.mapper.MesOprLogMapper;
import market.Mes.Opr.vo.MesOprLog;
import market.Mes.OrderManager.Plan.impl.PlnProdorderStatisticServiceImpl;
import market.Mes.OrderManager.Plan.mapper.PlnProdorderMapper;
import market.Mes.OrderManager.Plan.vo.PlnProdorder;
import market.Mes.Packing.Result.mapper.MesOprInfoMapper;
import market.Mes.Packing.Result.vo.MesOprInfo;
import market.Mes.Shift.mapper.MesShiftMMapper;
import market.Mes.Shift.vo.MesShiftM;
import market.Mes.Tpm.mapper.MesTpmPrintLogMapper;
import market.Mes.Tpm.vo.MesTpmPrintLog;
import market.Mes.anneal.mapper.MesCrAnnealMMapper;
import market.Mes.util.MesUtil;
import market.Qms.qcm.service.impl.QcmJhySampleConsignDItemServiceImpl;
import market.Qms.qcm.vo.QcmJhySampleFromPlan;
import market.Slm.FundManagement.impl.SlmFundFirstDetailServiceImpl;
import market.Slm.OrderManagement.mapper.SlmOrderInfoMapper;

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

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

@RemoteService(path="MesCrSlittingDService")
public class MesCrSlittingDServiceImpl extends BaseServiceImpl<MesCrSlittingD,Object> implements MesCrSlittingDService {
	
	/**
	 * 作业实绩数据查询
	 * */
	public ResultModel doQueryWeb(CommonPage<MesCrSlittingM> oci){
		ResultModel rm=new ResultModel();
		try{
			rm.setState("200");
			rm.setData(this.getMapper(MesCrSlittingDMapper.class).doQuery(oci.getObject()));
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 作业称重页面
	 * 作业实绩数据查询
	 * */
	public ResultModel doQueryWeb2(CommonPage<MesCrSlittingM> oci){
		ResultModel rm=new ResultModel();
		try{
			rm.setState("200");
			List<MesCrSlittingDSum> list=this.getMapper(MesCrSlittingDMapper.class).doQuery_wgt(oci.getObject());
			double thr=0,act=0;
			for(MesCrSlittingDSum sum:list){
				if(sum.getCoil_thr_wgt()!=null){
					thr+=sum.getCoil_thr_wgt();
				}
				if(sum.getCoil_act_wgt()!=null){
					act+=sum.getCoil_act_wgt();
				}
			}
			if(Math.abs((thr-act)/thr)>0.003){
				for(MesCrSlittingDSum sum:list){
					sum.setColor("1");
				}
			}
			rm.setData(list);
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	}

	/**
	 * 批量新增子卷           
	 * */
	@SuppressWarnings("unused")
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doAddsWeb(CommonPage<MesCrSlittingSum> oci) throws Exception{
		ResultModel rm=new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		PlnLengthwisePlanSum pps=oci.getObject().getSum();

		Integer v_cnt=null;
		//验证选中的作业计划主表记录存在
		PlnLengthwisePlan pp=new PlnLengthwisePlan();
		pp.setMachine_code(pps.getMachine_code());
		pp.setLw_plan_no(pps.getLw_plan_no());
		int icount=this.getMapper(PlnLengthwisePlanMapper.class).count(pp);
		if(icount==0){
			rm.setState("500");
			rm.setMsgInfo("作业计划主表记录不存在");
			return rm;
		}
		
		//验证选中的作业计划明细表记录存在
		PlnLengthwisePlanDetail ppd=new PlnLengthwisePlanDetail();
		ppd.setMachine_code(pps.getMachine_code());
		ppd.setLw_plan_no(pps.getLw_plan_no());
		ppd.setObject_no_vt(pps.getObject_no_vt());
		ppd.setObject_no(pps.getMaterial_no());
		List<PlnLengthwisePlanDetail> lppd=this.getMapper(PlnLengthwisePlanDetailMapper.class).find(ppd, 0, 0);
		if(lppd==null || lppd.size()==0){
			rm.setState("500");
			rm.setMsgInfo("作业计划明细记录不存在");
			return rm;
		}

		//验证选中的作业计划对应的分条主实绩存在，且为未交工状态
		MesCrSlittingM mcsm=new MesCrSlittingM();
		mcsm.setMachine_code(pps.getMachine_code());
		mcsm.setSchedule_no(pps.getLw_plan_no());
		mcsm.setMaterial_no_vt(pps.getObject_no_vt());
		mcsm.setMaterial_no(pps.getMaterial_no());
		List<MesCrSlittingM> lmcsm=this.getMapper(MesCrSlittingMMapper.class).find(mcsm, 0, 0);

		if(lmcsm==null||lmcsm.size()==0){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no_vt()+"]分条主实绩不存在！");
			return rm;
		}
		if(!"0".equals(lmcsm.get(0).getHand_over_status())
				&&lmcsm.get(0).getHand_over_status()!=null){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no_vt()+"]分条已生产交工！");
			return rm;
		}
		
		//删除现有所有子卷实绩（DELETE FROM MES_CR_SLITTING_D T WHERE T.PROCESS_NO = 找到的此卷生产主实绩记录的生产处理号）
		MesCrSlittingD mcsd=new MesCrSlittingD();
		mcsd.setProcess_no(lmcsm.get(0).getProcess_no());
		this.getMapper(MesCrSlittingDMapper.class).doDelete(mcsd);

		PlnMaterielDetail pmd=new PlnMaterielDetail();
		pmd.setMat_object_no_vt(pps.getObject_no_vt());
		List<PlnMaterielDetail> lpmd=this.getMapper(PlnMaterielDetailMapper.class).findWithCondition(pmd, ""," serial_no ",0,0);
		//***********************F01后续需根据机器的编码找到机器的代号然后 String.format("%02d",代号)
		//ComBaseMachine cbm=this.getMapper(ComBaseMachineMapper.class).findById(pps.getMachine_code());
		//cbm.getMachine_mark()
	    //验证机台基础信息存在
		v_cnt = this.getMapper(ComBaseMachineMapper.class).countWithCondition(null,"machine_code='"+pps.getMachine_code()+"'");
		if(v_cnt<=0){
			throw new Exception("机台代码{"+pps.getMachine_code()+"} 机台基础信息不存在！");
		}
		//获取机台基础信息表中，配置的机台设备代号（设备编号，如1,2,3）
		List<ComBaseMachine> lcbm = this.getMapper(ComBaseMachineMapper.class).findWithCondition(null,
				"machine_code='"+pps.getMachine_code()+"'", null, 0, 0);
		String v_machine_mark=lcbm.get(0).getMachine_mark();
		if(v_machine_mark==null){
			throw new Exception("机台代码{"+pps.getMachine_code()+"} 设备编号未配置，无法创建作业记录号！");
		}
		String sNo=pps.getMaterial_no().substring(0,8)+"F"+lpad(v_machine_mark,2,"0");
		
		List<MesCrSlittingD> lm=this.getMapper(MesCrSlittingDMapper.class).findWithCondition(null, " coil_no like '"+sNo+"%' and substr(coil_no, -1) <> 'B' and substr(coil_no, -1) <> 'H' ", "coil_no", 0, 0);
		//icount=this.getMapper(MesCrSlittingDMapper.class).doQueryMaxCount(mcc);
		//由于最大为99，且中间可能有删除数据的情况，导致只能循环而非一次获取最大
		ArrayList<Integer> ai=new ArrayList<Integer>();
		if(lm!=null&&lm.size()>0){
			for(MesCrSlittingD md:lm){
				ai.add(Integer.parseInt(md.getCoil_no().substring(md.getCoil_no().length()-2, md.getCoil_no().length())));
			}
		}
		//原料卷已切割生成的子卷数大于等于99
		if(lpmd.size()+ai.size()>99){
			throw new Exception("原料卷已切割生成的子卷数加当前生成的子卷数大于99!");
		}


		icount=1;
		//ai不为空
		boolean aiIsNoEpt=ai.size()==0?false:true;
		boolean flag=false;
		for(PlnMaterielDetail pmdc:lpmd){
			MesCrSlittingD mc=new MesCrSlittingD();			
			if(aiIsNoEpt){//不为空则有的号已使用则需验证
				flag=false;
				for(int i:ai){
					if(!ai.contains(icount)){
						flag=true;
						break;
					}else{
						icount++;
					}
				}
				if(flag){//补号码
					ai.add(icount);
				}
			}
			
			//根据机器编号查询机器信息
			mc.setCoil_no(sNo+String.format("%02d", icount));
			mc.setProcess_no(lmcsm.get(0).getProcess_no());
			mc.setWrk_date(lmcsm.get(0).getWrk_date());
			mc.setWrk_grp(lmcsm.get(0).getWrk_grp());
			mc.setWrk_ord(lmcsm.get(0).getWrk_ord());
			mc.setSteel_code(pmdc.getSteel_code());//牌号
			mc.setProd_order_no(pmdc.getProd_order_no());//生产订单号
			mc.setOrder_no(pmdc.getOrder_no());//订单号
			mc.setAim_inn_dia(pmdc.getDiameter_inn());//目标内径
			mc.setAct_inn_dia(pmdc.getDiameter_inn());//子卷内径
			mc.setAim_len(pmdc.getLength());
			mc.setAct_len(pmdc.getLength());
			mc.setAim_out_dia(pmdc.getDiameter_out());
			mc.setAct_out_dia(pmdc.getDiameter_out());
			mc.setAim_thk(pmdc.getThick());
			//2018-08-19
			mc.setAct_thk(lmcsm.get(0).getMtr_thk());//原料卷厚度
			mc.setAim_wdt(pmdc.getWidth());
			mc.setAct_wdt(pmdc.getWidth());
			mc.setCoil_thr_wgt(pmdc.getSingle_weight());
			mc.setReceive_opr(username);
			mc.setReceive_time(now);
			mc.setProduce_time(now);
			mc.setCreate_opr(username);
			// 2019-09-23 增加包装要求以便后续称重作业页面修改 panbin
			mc.setPk_ask_code(pmdc.getPk_ask_code());
			mc.setPk_ask_desc(pmdc.getPk_ask_desc());
			this.getMapper(MesCrSlittingDMapper.class).insert(mc);
			icount++;
		}

		// 获取所有子卷不包括边丝
		MesCrSlittingD mcsdqq=new MesCrSlittingD();
		mcsdqq.setProcess_no(lmcsm.get(0).getProcess_no());
		List<MesCrSlittingD> lmMsd=this.getMapper(MesCrSlittingDMapper.class).findWithCondition(mcsdqq, " coil_no like '"+sNo+"%' and substr(coil_no, -1) <> 'B' and substr(coil_no, -1) <> 'H' ", " coil_no ", 0, 0);
		
		if(lmMsd==null || lmMsd.size()==0){
			throw new Exception("找不到子卷信息");
		}

		String v_coil_no=null;
		List<MesCrSlittingD> lm_biansi=this.getMapper(MesCrSlittingDMapper.class).findWithCondition
				(null, " coil_no like '"+sNo+"%' and substr(coil_no, -1) = 'B' ", "coil_no", 0, 0);
		if(lm_biansi==null||lm_biansi.size()==0){
			v_cnt=0;
			v_coil_no=sNo+v_cnt+"B";
		}else{
			int i=0;
			for(MesCrSlittingD msbe:lm_biansi){
				int m=Integer.parseInt(msbe.getCoil_no().substring(msbe.getCoil_no().length()-2,msbe.getCoil_no().length()-1));
				if(i!=m){
					v_coil_no=sNo+i+"B";
					break;
				}
				i++;
				if(i>9){
					throw new Exception("边丝物料编号超出规则范围，流水号超出最大值9！");
				}
			}
			if(i>=lm_biansi.size()){
				v_coil_no=sNo+i+"B";
			}
		} 
	     
		MesCrSlittingD mc=new MesCrSlittingD();
		//边丝编码	
		//mc.setCoil_no(sNo+"0B");
		mc.setCoil_no(v_coil_no);
		mc.setProcess_no(lmcsm.get(0).getProcess_no());
		mc.setWrk_date(lmcsm.get(0).getWrk_date());
		mc.setWrk_grp(lmcsm.get(0).getWrk_grp());
		mc.setWrk_ord(lmcsm.get(0).getWrk_ord());
		mc.setSteel_code(lpmd.get(0).getSteel_code());//牌号
		mc.setProd_order_no(lpmd.get(0).getProd_order_no());//生产订单号
		mc.setOrder_no(lpmd.get(0).getOrder_no());//订单号
		mc.setAim_inn_dia(lpmd.get(0).getDiameter_inn());//目标内径
		mc.setAim_len(lpmd.get(0).getLength());
		mc.setAim_out_dia(lpmd.get(0).getDiameter_out());
		mc.setAim_thk(lpmd.get(0).getThick());
		mc.setAim_wdt(lpmd.get(0).getWidth());
		mc.setReceive_opr(username);
		mc.setReceive_time(now);
		mc.setProduce_time(now);
		mc.setCreate_opr(username);
		this.getMapper(MesCrSlittingDMapper.class).insert(mc);
		icount++;

		//后台在原有逻辑的基础上，加入【重量分配】的相关逻辑，修改各个子卷的理重（边丝0B不能参与分配），
		//实重设置为0（具体逻辑规则见修改后的重量分配逻辑);

		//总重量
		double sumWeight=Double.parseDouble(oci.getMemo1()==null?"0":oci.getMemo1());
		double lastWgt=0;
		String x1=lmcsm.get(0).getCrs_cut_mode();
		if(x1==null || "".equals(x1)){
			//横切方式（CRS_CUT_MODE）：通过生产订单号为条件，关联 pln_process_plan 表获取 CROSSCUT_STYLE 字段，详细截图；
			List<PlnProcessPlan> lppp=this.getMapper(PlnLengthwisePlanDetailMapper.class).doQueryCrs(oci.getObject().getSum().getObject_no_vt());
			if(lppp!=null && lppp.size()>0){
				x1 = lppp.get(0).getCrosscut_style();
			}
		}
		//分条计划总宽度
		//分条计划总宽度值verify
		double sumPwidth=0;
		// 记录子卷条数
		int j = 0;
		PlnMaterielDetail mcsmqq=new PlnMaterielDetail();
		mcsmqq.setLw_plan_no(oci.getObject().getSum().getLw_plan_no());
		mcsmqq.setMat_object_no_vt(oci.getObject().getSum().getObject_no_vt());
		List<PlnMaterielDetailSum> lpds = this.getMapper(PlnMaterielDetailMapper.class).doQuery(mcsmqq);
		for(PlnMaterielDetailSum pmd2 : lpds){
			if(pmd2.getWidth()!=null && !"".equals(pmd2.getWidth())){
				//不横切。获取分条计划中所有宽度
				if("1".equals(x1)){
					sumPwidth+=Double.parseDouble(pmd2.getWidth());
				}else if("2".equals(x1)){
					//一切二。获取分条计划中前一半宽度
					if(j++<lpds.size()/2){
						sumPwidth+=Double.parseDouble(pmd2.getWidth());
					}
				}else if("3".equals(x1)){
					//一切三。获取分条计划中前三分之一宽度
					if(j++<lpds.size()/3){
						sumPwidth+=Double.parseDouble(pmd2.getWidth());
					}
				}else if("4".equals(x1)){
					//一切四。获取分条计划中前四分之一宽度
					if(j++<lpds.size()/4){
						sumPwidth+=Double.parseDouble(pmd2.getWidth());
					}
				}else if("5".equals(x1)){
					//一切五。获取分条计划中前五分之一宽度
					if(j++<lpds.size()/5){
						sumPwidth+=Double.parseDouble(pmd2.getWidth());
					}
				}
			}
		}
		if(oci.getObject().getSum().getCrs_cut_len1()==null){
			oci.getObject().getSum().setCrs_cut_len1(0d);
		}
		if(oci.getObject().getSum().getCrs_cut_len2()==null){
			oci.getObject().getSum().setCrs_cut_len2(0d);
		}
		if(oci.getObject().getSum().getCrs_cut_len3()==null){
			oci.getObject().getSum().setCrs_cut_len3(0d);
		}
		if(oci.getObject().getSum().getCrs_cut_len4()==null){
			oci.getObject().getSum().setCrs_cut_len4(0d);
		}
		if(oci.getObject().getSum().getCrs_cut_len5()==null){
			oci.getObject().getSum().setCrs_cut_len5(0d);
		}
		
		if((!"1".equals(x1)) && (!"2".equals(x1)) && (!"3".equals(x1)) && (!"4".equals(x1)) && (!"5".equals(x1))){
			throw new Exception("横切方式不存在!");
		}
		if(("2".equals(x1)) &&  
				(oci.getObject().getSum().getCrs_cut_len1()<=0 || oci.getObject().getSum().getCrs_cut_len2()<=0 ) ){
			throw new Exception("一切二方式中，两次的长度比例不全!");
		}
		if("2".equals(x1)){
			double len12=oci.getObject().getSum().getCrs_cut_len1()+oci.getObject().getSum().getCrs_cut_len2();
			if(len12!=100){//100.0==100
				throw new Exception("一切二方式中，两次的长度比例不正确");
			}
		}
		if(("3".equals(x1)) &&  
				(oci.getObject().getSum().getCrs_cut_len1()<=0 || oci.getObject().getSum().getCrs_cut_len2()<=0  
				|| oci.getObject().getSum().getCrs_cut_len3()<=0 )){
			throw new Exception("一切三方式中，三次的长度比例不全!");
		}
		if("3".equals(x1)){
			double len123=oci.getObject().getSum().getCrs_cut_len1()+oci.getObject().getSum().getCrs_cut_len2()+
					oci.getObject().getSum().getCrs_cut_len3();
			if(len123!=100){
				throw new Exception("一切三方式中，三次的长度比例不正确");
			}
		}
		if(("4".equals(x1)) &&  
				(oci.getObject().getSum().getCrs_cut_len1()<=0 || oci.getObject().getSum().getCrs_cut_len2()<=0  
				|| oci.getObject().getSum().getCrs_cut_len3()<=0 || oci.getObject().getSum().getCrs_cut_len4()<=0)){
			throw new Exception("一切四方式中，四次的长度比例不全!");
		}
		if("4".equals(x1)){
			double len1234=oci.getObject().getSum().getCrs_cut_len1()+oci.getObject().getSum().getCrs_cut_len2()+
					oci.getObject().getSum().getCrs_cut_len3()+oci.getObject().getSum().getCrs_cut_len4();
			if(len1234!=100){
				throw new Exception("一切四方式中，四次的长度比例不正确");
			}
		}
		if(("5".equals(x1)) &&  
				(oci.getObject().getSum().getCrs_cut_len1()<=0 || oci.getObject().getSum().getCrs_cut_len2()<=0  
				|| oci.getObject().getSum().getCrs_cut_len3()<=0 || oci.getObject().getSum().getCrs_cut_len4()<=0
					|| oci.getObject().getSum().getCrs_cut_len5()<=0
						)){
			throw new Exception("一切五方式中，五次的长度比例不全!");
		}
		if("5".equals(x1)){
			double len12345=oci.getObject().getSum().getCrs_cut_len1()+oci.getObject().getSum().getCrs_cut_len2()+
					oci.getObject().getSum().getCrs_cut_len3()+oci.getObject().getSum().getCrs_cut_len4()+
					oci.getObject().getSum().getCrs_cut_len5();
			if(len12345!=100){
				throw new Exception("一切五方式中，五次的长度比例不正确");
			}
		}
		
		//同步中断长度
		MesCrSlittingM mcsmcur = lmcsm.get(0);
		mcsmcur.setCrs_cut_len1(oci.getObject().getSum().getCrs_cut_len1());
		mcsmcur.setCrs_cut_len2(oci.getObject().getSum().getCrs_cut_len2());
		mcsmcur.setCrs_cut_len3(oci.getObject().getSum().getCrs_cut_len3());
		mcsmcur.setCrs_cut_len4(oci.getObject().getSum().getCrs_cut_len4());
		mcsmcur.setCrs_cut_len5(oci.getObject().getSum().getCrs_cut_len5());
		//mcsmcur.setCrs_cut_len6(oci.getObject().getSum().getCrs_cut_len6());
		this.getMapper(MesCrSlittingMMapper.class).update(mcsmcur);
		
		
		int icountTwo=0;
		String dt=new SimpleDateFormat("yyMMdd").format(new Date());
		List<MesCrSlittingWgt> lmcw=this.getMapper(MesCrSlittingWgtMapper.class).findWithCondition(null, " substr(serial_no,1,6)='"+dt+"'", " serial_no desc", 0, 1);
		if(lmcw==null||lmcw.size()==0){
			icountTwo=1;
		}else{
			icountTwo=Integer.parseInt(lmcw.get(0).getSerial_no().substring(6,11))+1;
		}

		int i=1,k=0,p=0,s=0;
		for(MesCrSlittingD mcsttd:lmMsd){
			if("1".equals(x1)){
				//根据前端传入的子卷卷号集合，按各子卷的宽度占勾选的所有子卷的宽度和的比例，对重量进行分摊，
				//当做勾选的当个子卷的重量，同时，将上面创建的记录称重编号写入子卷实绩，方便信息反查
				//四舍五入
				BigDecimal b= new BigDecimal((mcsttd.getAct_wdt()/sumPwidth)*sumWeight);  
				double f1 = b.setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
				if(i==lmMsd.size()){
					f1=sumWeight-lastWgt;//最后一卷取值
				}else{
					lastWgt+=f1;
				}
				MesCrSlittingD mcsdu=new MesCrSlittingD();
				mcsdu.setCoil_no(mcsttd.getCoil_no());
				mcsdu.setCoil_act_wgt(0.0);
				mcsdu.setCoil_wgt_serial_no(dt+String.format("%05d", icountTwo++));
				mcsdu.setCoil_thr_wgt(f1);
				//mcsdu.setCoil_wgt_time(new Date());
				this.getMapper(MesCrSlittingDMapper.class).update(mcsdu);
				i++;
			}else if("2".equals(x1)){
				if(oci.getObject().getSum().getCrs_cut_len1()>0 && 
						oci.getObject().getSum().getCrs_cut_len2()>0){
					//根据前端传入的子卷卷号集合，按各子卷的宽度占勾选的所有子卷的宽度和的比例，对重量进行分摊，
					//当做勾选的当个子卷的重量，同时，将上面创建的记录称重编号写入子卷实绩，方便信息反查
					//四舍五入
					//宽度比例
					double wid_prop=0;
					if (k++<lmMsd.size()/2){
						//wid_prop=oci.getObject().getMain().getCrs_cut_len1().doubleValue()/100;
						Double v2=100.0;
						BigDecimal b1 = new BigDecimal(oci.getObject().getSum().getCrs_cut_len1().toString());    
						BigDecimal b2 = new BigDecimal(v2.toString());  
						wid_prop= new Double(b1.divide(b2, 15, BigDecimal.ROUND_HALF_UP).doubleValue());
					}else{
						//wid_prop=oci.getObject().getMain().getCrs_cut_len2().doubleValue()/100;
						Double v2=100.0;
						BigDecimal b1 = new BigDecimal(oci.getObject().getSum().getCrs_cut_len2().toString());    
						BigDecimal b2 = new BigDecimal(v2.toString());  
						wid_prop= new Double(b1.divide(b2, 15, BigDecimal.ROUND_HALF_UP).doubleValue());
					}
					BigDecimal b= new BigDecimal((mcsttd.getAct_wdt()/sumPwidth)*sumWeight*wid_prop);  
					double f1 = b.setScale(0,   BigDecimal.ROUND_HALF_UP).doubleValue();
					if(i==lmMsd.size()){
						f1=sumWeight-lastWgt;
					}else{
						lastWgt+=f1;
					}
					MesCrSlittingD mcsdu=new MesCrSlittingD();
					mcsdu.setCoil_no(mcsttd.getCoil_no());
					mcsdu.setCoil_act_wgt(0.0);
					mcsdu.setCoil_wgt_serial_no(dt+String.format("%05d", icountTwo++));
					mcsdu.setCoil_thr_wgt(f1);
					//mcsdu.setCoil_wgt_time(new Date());
					this.getMapper(MesCrSlittingDMapper.class).update(mcsdu);
					i++;
				}
			}else if("3".equals(x1)){
				if(oci.getObject().getSum().getCrs_cut_len1()>0 && 
						oci.getObject().getSum().getCrs_cut_len2()>0 && oci.getObject().getSum().getCrs_cut_len3()>0 ){
					//根据前端传入的子卷卷号集合，按各子卷的宽度占勾选的所有子卷的宽度和的比例，对重量进行分摊，
					//当做勾选的当个子卷的重量，同时，将上面创建的记录称重编号写入子卷实绩，方便信息反查
					//四舍五入
					//宽度比例
					double wid_prop=0;
					p++;
					if(p<=lmMsd.size()/3){
						//wid_prop=oci.getObject().getSum().getCrs_cut_len1()/100;
						Double v2=100.0;
						BigDecimal b1 = new BigDecimal(oci.getObject().getSum().getCrs_cut_len1().toString());    
						BigDecimal b2 = new BigDecimal(v2.toString());  
						wid_prop= new Double(b1.divide(b2, 15, BigDecimal.ROUND_HALF_UP).doubleValue());
					}else if(p<=(lmMsd.size()/3*2)){
						//wid_prop=oci.getObject().getSum().getCrs_cut_len2()/100;
						Double v2=100.0;
						BigDecimal b1 = new BigDecimal(oci.getObject().getSum().getCrs_cut_len2().toString());    
						BigDecimal b2 = new BigDecimal(v2.toString());  
						wid_prop= new Double(b1.divide(b2, 15, BigDecimal.ROUND_HALF_UP).doubleValue());
					}else{
						//wid_prop=oci.getObject().getSum().getCrs_cut_len3()/100;
						Double v2=100.0;
						BigDecimal b1 = new BigDecimal(oci.getObject().getSum().getCrs_cut_len3().toString());    
						BigDecimal b2 = new BigDecimal(v2.toString());  
						wid_prop= new Double(b1.divide(b2, 15, BigDecimal.ROUND_HALF_UP).doubleValue());
					}
					BigDecimal b= new BigDecimal((mcsttd.getAct_wdt()/sumPwidth)*sumWeight*wid_prop);  
					double f1 = b.setScale(0,   BigDecimal.ROUND_HALF_UP).doubleValue();
					if(i==lmMsd.size()){
						f1=sumWeight-lastWgt;
					}else{
						lastWgt+=f1;
					}
					MesCrSlittingD mcsdu=new MesCrSlittingD();
					mcsdu.setCoil_no(mcsttd.getCoil_no());
					mcsdu.setCoil_act_wgt(0.0);
					mcsdu.setCoil_wgt_serial_no(dt+String.format("%05d", icountTwo++));
					mcsdu.setCoil_thr_wgt(f1);
					//mcsdu.setCoil_wgt_time(new Date());
					this.getMapper(MesCrSlittingDMapper.class).update(mcsdu);
					i++;
				}
			}else if("4".equals(x1)){
				if(oci.getObject().getSum().getCrs_cut_len1()>0 && 
						oci.getObject().getSum().getCrs_cut_len2()>0 && oci.getObject().getSum().getCrs_cut_len3()>0 
						 && oci.getObject().getSum().getCrs_cut_len4()>0){
					//根据前端传入的子卷卷号集合，按各子卷的宽度占勾选的所有子卷的宽度和的比例，对重量进行分摊，
					//当做勾选的当个子卷的重量，同时，将上面创建的记录称重编号写入子卷实绩，方便信息反查
					//四舍五入
					//宽度比例
					double wid_prop=0;
					s++;
					if(s<=lmMsd.size()/4){
						//wid_prop=oci.getObject().getSum().getCrs_cut_len1()/100;
						Double v2=100.0;
						BigDecimal b1 = new BigDecimal(oci.getObject().getSum().getCrs_cut_len1().toString());    
						BigDecimal b2 = new BigDecimal(v2.toString());  
						wid_prop= new Double(b1.divide(b2, 15, BigDecimal.ROUND_HALF_UP).doubleValue());
					}else if(s<=(lmMsd.size()/4*2)){
						//wid_prop=oci.getObject().getSum().getCrs_cut_len2()/100;
						Double v2=100.0;
						BigDecimal b1 = new BigDecimal(oci.getObject().getSum().getCrs_cut_len2().toString());    
						BigDecimal b2 = new BigDecimal(v2.toString());  
						wid_prop= new Double(b1.divide(b2, 15, BigDecimal.ROUND_HALF_UP).doubleValue());
					}else if(s<=(lmMsd.size()/4*3)){
						//wid_prop=oci.getObject().getSum().getCrs_cut_len2()/100;
						Double v2=100.0;
						BigDecimal b1 = new BigDecimal(oci.getObject().getSum().getCrs_cut_len3().toString());    
						BigDecimal b2 = new BigDecimal(v2.toString());  
						wid_prop= new Double(b1.divide(b2, 15, BigDecimal.ROUND_HALF_UP).doubleValue());
					}else{
						//wid_prop=oci.getObject().getSum().getCrs_cut_len3()/100;
						Double v2=100.0;
						BigDecimal b1 = new BigDecimal(oci.getObject().getSum().getCrs_cut_len4().toString());    
						BigDecimal b2 = new BigDecimal(v2.toString());  
						wid_prop= new Double(b1.divide(b2, 15, BigDecimal.ROUND_HALF_UP).doubleValue());
					}
					BigDecimal b= new BigDecimal((mcsttd.getAct_wdt()/sumPwidth)*sumWeight*wid_prop);  
					double f1 = b.setScale(0,   BigDecimal.ROUND_HALF_UP).doubleValue();
					if(i==lmMsd.size()){
						f1=sumWeight-lastWgt;
					}else{
						lastWgt+=f1;
					}
					MesCrSlittingD mcsdu=new MesCrSlittingD();
					mcsdu.setCoil_no(mcsttd.getCoil_no());
					mcsdu.setCoil_act_wgt(0.0);
					mcsdu.setCoil_wgt_serial_no(dt+String.format("%05d", icountTwo++));
					mcsdu.setCoil_thr_wgt(f1);
					//mcsdu.setCoil_wgt_time(new Date());
					this.getMapper(MesCrSlittingDMapper.class).update(mcsdu);
					i++;
				}
			}else if("5".equals(x1)){
				if(oci.getObject().getSum().getCrs_cut_len1()>0 && 
						oci.getObject().getSum().getCrs_cut_len2()>0 && oci.getObject().getSum().getCrs_cut_len3()>0 
						 && oci.getObject().getSum().getCrs_cut_len4()>0 && oci.getObject().getSum().getCrs_cut_len5()>0){
					//根据前端传入的子卷卷号集合，按各子卷的宽度占勾选的所有子卷的宽度和的比例，对重量进行分摊，
					//当做勾选的当个子卷的重量，同时，将上面创建的记录称重编号写入子卷实绩，方便信息反查
					//四舍五入
					//宽度比例
					double wid_prop=0;
					s++;
					if(s<=lmMsd.size()/5){
						//wid_prop=oci.getObject().getSum().getCrs_cut_len1()/100;
						Double v2=100.0;
						BigDecimal b1 = new BigDecimal(oci.getObject().getSum().getCrs_cut_len1().toString());    
						BigDecimal b2 = new BigDecimal(v2.toString());  
						wid_prop= new Double(b1.divide(b2, 15, BigDecimal.ROUND_HALF_UP).doubleValue());
					}else if(s<=(lmMsd.size()/5*2)){
						//wid_prop=oci.getObject().getSum().getCrs_cut_len2()/100;
						Double v2=100.0;
						BigDecimal b1 = new BigDecimal(oci.getObject().getSum().getCrs_cut_len2().toString());    
						BigDecimal b2 = new BigDecimal(v2.toString());  
						wid_prop= new Double(b1.divide(b2, 15, BigDecimal.ROUND_HALF_UP).doubleValue());
					}else if(s<=(lmMsd.size()/5*3)){
						//wid_prop=oci.getObject().getSum().getCrs_cut_len2()/100;
						Double v2=100.0;
						BigDecimal b1 = new BigDecimal(oci.getObject().getSum().getCrs_cut_len3().toString());    
						BigDecimal b2 = new BigDecimal(v2.toString());  
						wid_prop= new Double(b1.divide(b2, 15, BigDecimal.ROUND_HALF_UP).doubleValue());
					}else if(s<=(lmMsd.size()/5*4)){
						//wid_prop=oci.getObject().getSum().getCrs_cut_len2()/100;
						Double v2=100.0;
						BigDecimal b1 = new BigDecimal(oci.getObject().getSum().getCrs_cut_len4().toString());    
						BigDecimal b2 = new BigDecimal(v2.toString());  
						wid_prop= new Double(b1.divide(b2, 15, BigDecimal.ROUND_HALF_UP).doubleValue());
					}else{
						//wid_prop=oci.getObject().getSum().getCrs_cut_len3()/100;
						Double v2=100.0;
						BigDecimal b1 = new BigDecimal(oci.getObject().getSum().getCrs_cut_len5().toString());    
						BigDecimal b2 = new BigDecimal(v2.toString());  
						wid_prop= new Double(b1.divide(b2, 15, BigDecimal.ROUND_HALF_UP).doubleValue());
					}
					BigDecimal b= new BigDecimal((mcsttd.getAct_wdt()/sumPwidth)*sumWeight*wid_prop);  
					double f1 = b.setScale(0,   BigDecimal.ROUND_HALF_UP).doubleValue();
					if(i==lmMsd.size()){
						f1=sumWeight-lastWgt;
					}else{
						lastWgt+=f1;
					}
					MesCrSlittingD mcsdu=new MesCrSlittingD();
					mcsdu.setCoil_no(mcsttd.getCoil_no());
					mcsdu.setCoil_act_wgt(0.0);
					mcsdu.setCoil_wgt_serial_no(dt+String.format("%05d", icountTwo++));
					mcsdu.setCoil_thr_wgt(f1);
					//mcsdu.setCoil_wgt_time(new Date());
					this.getMapper(MesCrSlittingDMapper.class).update(mcsdu);
					//日志
					MesOprLog mol = new MesOprLog("车间MES", pps.getMachine_name()+"作业管理", "按计划批量新增子卷", username, opr_time, mcsttd.getCoil_no(), null, null, null, "投料卷号："+pps.getMaterial_no());
					this.getMapper(MesOprLogMapper.class).insert(mol);
					rm.setState("200");
									
					i++;
				}
			}						
		}
		return rm;	
	}

	
	/**
	 * 新增头尾卷
	 * 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doAddWeb_H(CommonPage<MesCrSlittingSum> oci) throws Exception{
		ResultModel rm=new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		PlnLengthwisePlanSum pps=oci.getObject().getSum();

		//验证选中的作业计划主表记录存在
		PlnLengthwisePlan pp=new PlnLengthwisePlan();
		pp.setMachine_code(pps.getMachine_code());
		pp.setLw_plan_no(pps.getLw_plan_no());
		int icount=this.getMapper(PlnLengthwisePlanMapper.class).count(pp);
		if(icount==0){
			rm.setState("500");
			rm.setMsgInfo("作业计划主表记录不存在");
			return rm;
		}
		//验证选中的作业计划明细表记录存在
		PlnLengthwisePlanDetail ppd=new PlnLengthwisePlanDetail();
		ppd.setMachine_code(pps.getMachine_code());
		ppd.setLw_plan_no(pps.getLw_plan_no());
		ppd.setObject_no_vt(pps.getObject_no_vt());
		ppd.setObject_no(pps.getMaterial_no());
		List<PlnLengthwisePlanDetail> lppd=this.getMapper(PlnLengthwisePlanDetailMapper.class).find(ppd, 0, 0);
		if(lppd==null || lppd.size()==0){
			rm.setState("500");
			rm.setMsgInfo("作业计划明细记录不存在");
			return rm;
		}

		//验证选中的作业计划对应的分条主实绩存在，且为未交工状态
		MesCrSlittingM mcsm=new MesCrSlittingM();
		mcsm.setMachine_code(pps.getMachine_code());
		mcsm.setSchedule_no(pps.getLw_plan_no());
		mcsm.setMaterial_no_vt(pps.getObject_no_vt());
		mcsm.setMaterial_no(pps.getMaterial_no());
		List<MesCrSlittingM> lmcsm=this.getMapper(MesCrSlittingMMapper.class).find(mcsm, 0, 0);

		if(lmcsm==null||lmcsm.size()==0){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条主实绩不存在！");
			return rm;
		}
		if(!"0".equals(lmcsm.get(0).getHand_over_status())
				&&lmcsm.get(0).getHand_over_status()!=null){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条已生产交工！");
			return rm;
		}
		ComBaseMachine cbm=this.getBean(ComBaseMachineServiceImpl.class).doGetMark(pps.getMachine_code());
		if(cbm==null||cbm.getMachine_mark()==null){
			rm.setState("500");
			rm.setMsgInfo("机台代号获取失败！");
			return rm;
		}
		
		String sNo=pps.getMaterial_no().substring(0,8)+"F"+lpad(cbm.getMachine_mark(),2,"0");
		Integer v_cnt;
		String v_coil_no=null;
		List<MesCrSlittingD> lm_biansi=this.getMapper(MesCrSlittingDMapper.class).findWithCondition
				(null, " coil_no like '"+sNo+"%' and substr(coil_no, -1) = 'H' ", "coil_no", 0, 0);
		if(lm_biansi==null||lm_biansi.size()==0){
			v_cnt=0;
			v_coil_no=sNo+v_cnt+"H";
		}else{
			int i=0;
			for(MesCrSlittingD msbe:lm_biansi){
				int m=Integer.parseInt(msbe.getCoil_no().substring(msbe.getCoil_no().length()-2,msbe.getCoil_no().length()-1));
				if(i!=m){
					v_coil_no=sNo+i+"H";
					break;
				}
				i++;
				if(i>9){
					throw new Exception("头尾卷编号超出规则范围，流水号超出最大值9！");
				}
			}
			if(i>=lm_biansi.size()){
				v_coil_no=sNo+i+"H";
			}
		} 
	     
		//头尾卷
		//插入子卷实绩表
		MesCrSlittingD mm=oci.getObject().getChild();//修改了
		MesCrSlittingD mc=new MesCrSlittingD();//修改了
		mc.setAct_wdt(mm.getAct_wdt());//修改了
		mc.setCoil_no(v_coil_no);
		mc.setProcess_no(lmcsm.get(0).getProcess_no());
		mc.setWrk_date(lmcsm.get(0).getWrk_date());
		mc.setWrk_grp(lmcsm.get(0).getWrk_grp());
		mc.setWrk_ord(lmcsm.get(0).getWrk_ord());
		mc.setSteel_code(lmcsm.get(0).getSteel_code());//牌号
		mc.setAct_len(null);
		//2018-08-19
		mc.setAct_thk(lmcsm.get(0).getMtr_thk());	
		mc.setReceive_opr(username);
		mc.setReceive_time(now);
		mc.setProduce_time(now);
		mc.setCreate_opr(username);

		//---------------2018-03-12增加-----------------
		PlnMaterielDetail pmd=new PlnMaterielDetail();
		pmd.setMat_object_no_vt(pps.getObject_no_vt());
		List<PlnMaterielDetail> lpmd=this.getMapper(PlnMaterielDetailMapper.class).findWithCondition(pmd, ""," serial_no ",0,0);
		if(lpmd!=null&&lpmd.size()>0){
			mc.setProd_order_no(lpmd.get(0).getProd_order_no());//生产订单号
			mc.setOrder_no(lpmd.get(0).getOrder_no());//订单号
			//2018-09-10
			mc.setAim_inn_dia(lpmd.get(0).getDiameter_inn());//目标内径
			mc.setAim_len(lpmd.get(0).getLength());
			mc.setAim_out_dia(lpmd.get(0).getDiameter_out());
			mc.setAim_thk(lpmd.get(0).getThick());
			mc.setAim_wdt(lpmd.get(0).getWidth());
		}
		//----------------------------------------------

		this.getMapper(MesCrSlittingDMapper.class).insert(mc);
		//日志
		MesOprLog mol = new MesOprLog("车间MES", pps.getMachine_name()+"作业管理", "新增头尾卷", username, opr_time, mc.getCoil_no(), null, null, null, "投料卷号："+pps.getMaterial_no());
		this.getMapper(MesOprLogMapper.class).insert(mol);
		rm.setState("200");
		return rm;
	}
	

	/**
	 * 新增子卷
	 * */
	@SuppressWarnings("unused")
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doAddWeb(CommonPage<MesCrSlittingSum> oci) throws Exception{
		ResultModel rm=new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		PlnLengthwisePlanSum pps=oci.getObject().getSum();

		//验证选中的作业计划主表记录存在
		PlnLengthwisePlan pp=new PlnLengthwisePlan();
		pp.setMachine_code(pps.getMachine_code());
		pp.setLw_plan_no(pps.getLw_plan_no());
		int icount=this.getMapper(PlnLengthwisePlanMapper.class).count(pp);
		if(icount==0){
			rm.setState("500");
			rm.setMsgInfo("作业计划主表记录不存在");
			return rm;
		}

		//验证选中的作业计划明细表记录存在
		PlnLengthwisePlanDetail ppd=new PlnLengthwisePlanDetail();
		ppd.setMachine_code(pps.getMachine_code());
		ppd.setLw_plan_no(pps.getLw_plan_no());
		ppd.setObject_no_vt(pps.getObject_no_vt());
		ppd.setObject_no(pps.getMaterial_no());
		List<PlnLengthwisePlanDetail> lppd=this.getMapper(PlnLengthwisePlanDetailMapper.class).find(ppd, 0, 0);
		if(lppd==null || lppd.size()==0){
			rm.setState("500");
			rm.setMsgInfo("作业计划明细记录不存在");
			return rm;
		}
		

		//验证选中的作业计划对应的分条主实绩存在，且为未交工状态
		MesCrSlittingM mcsm=new MesCrSlittingM();
		mcsm.setMachine_code(pps.getMachine_code());
		mcsm.setSchedule_no(pps.getLw_plan_no());
		mcsm.setMaterial_no_vt(pps.getObject_no_vt());
		mcsm.setMaterial_no(pps.getMaterial_no());
		List<MesCrSlittingM> lmcsm=this.getMapper(MesCrSlittingMMapper.class).find(mcsm, 0, 0);
		if(CollectionUtils.isEmpty(lmcsm)){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条主实绩不存在！");
			return rm;
		}
		if(!"0".equals(lmcsm.get(0).getHand_over_status())
				&&lmcsm.get(0).getHand_over_status()!=null){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条已生产交工！");
			return rm;
		}
		ComBaseMachine cbm=this.getBean(ComBaseMachineServiceImpl.class).doGetMark(pps.getMachine_code());
		if(cbm==null||cbm.getMachine_mark()==null){
			rm.setState("500");
			rm.setMsgInfo("机台代号获取失败！");
			return rm;
		}

		String sNo=pps.getMaterial_no().substring(0,8)+"F"+lpad(cbm.getMachine_mark(),2,"0");
		
		List<MesCrSlittingD> lm=this.getMapper(MesCrSlittingDMapper.class).findWithCondition(null, " coil_no like '"+sNo+"%' and substr(coil_no, -1) <> 'B' and substr(coil_no, -1) <> 'H' ", " coil_no ", 0, 0);
		//由于最大为99，且中间可能有删除数据的情况，导致只能循环而非一次获取最大
		ArrayList<Integer> ai=new ArrayList<Integer>();
		if(lm!=null&&lm.size()>0){
			for(MesCrSlittingD md:lm){
				ai.add(Integer.parseInt(md.getCoil_no().substring(md.getCoil_no().length()-2, md.getCoil_no().length())));
			}
		}
		//原料卷已切割生成的子卷数大于等于99
		if(1+ai.size()>99){
			rm.setState("500");
			rm.setMsgInfo("原料卷已切割生成的子卷数加当前生成的子卷数大于99!");
			return rm;
		}

		boolean aiIsNoEpt=ai.size()==0?false:true;
		icount=1;
		if(aiIsNoEpt){//不为空则有的号已使用则需验证
			for (Integer i : ai) {
				if(!ai.contains(icount)){
					break;
				}else{
					icount++;
				}
			}
		}
		
		//插入子卷实绩表
		MesCrSlittingD mm=oci.getObject().getChild();//修改了
		MesCrSlittingD mc=new MesCrSlittingD();//修改了
		mc.setAct_wdt(mm.getAct_wdt());//修改了
		mc.setCoil_no(sNo+String.format("%02d", icount));
		mc.setProcess_no(lmcsm.get(0).getProcess_no());
		mc.setWrk_date(lmcsm.get(0).getWrk_date());
		mc.setWrk_grp(lmcsm.get(0).getWrk_grp());
		mc.setWrk_ord(lmcsm.get(0).getWrk_ord());
		mc.setSteel_code(lmcsm.get(0).getSteel_code());//牌号
		mc.setAct_len(null);
		//2018-08-19
		mc.setAct_thk(lmcsm.get(0).getMtr_thk());	
		mc.setReceive_opr(username);
		mc.setReceive_time(now);
		mc.setProduce_time(now);
		mc.setCreate_opr(username);

		//---------------2018-03-12增加-----------------
		PlnMaterielDetail pmd=new PlnMaterielDetail();
		pmd.setMat_object_no_vt(pps.getObject_no_vt());
		List<PlnMaterielDetail> lpmd=this.getMapper(PlnMaterielDetailMapper.class).findWithCondition(pmd, ""," serial_no ",0,0);
		if(lpmd!=null&&lpmd.size()>0){
			mc.setProd_order_no(lpmd.get(0).getProd_order_no());//生产订单号
			mc.setOrder_no(lpmd.get(0).getOrder_no());//订单号
			//厚度2018-09-10
			mc.setAim_inn_dia(lpmd.get(0).getDiameter_inn());//目标内径
			mc.setAim_len(lpmd.get(0).getLength());
			mc.setAim_out_dia(lpmd.get(0).getDiameter_out());
			mc.setAim_thk(lpmd.get(0).getThick());
			mc.setAim_wdt(lpmd.get(0).getWidth());
			mc.setPk_ask_code(lpmd.get(0).getPk_ask_code());
			mc.setPk_ask_desc(lpmd.get(0).getPk_ask_desc());
		}
		this.getMapper(MesCrSlittingDMapper.class).insert(mc);
		//日志
		MesOprLog mol = new MesOprLog("车间MES", pps.getMachine_name()+"作业管理", "新增子卷", username, opr_time, mc.getCoil_no(), null, null, null, "投料卷号："+pps.getMaterial_no()+mc.getMachine_code() + " ,宽度：" + mm.getAct_wdt());
		this.getMapper(MesOprLogMapper.class).insert(mol);		
		rm.setState("200");
		return rm;
	}

	/**
	 * 修改宽度
	 * @param oci
	 * @return
	 * @throws Exception
	 */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doUpdateWeb(CommonPage<MesCrSlittingSum> oci) throws Exception{
		ResultModel rm=new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		PlnLengthwisePlanSum pps=oci.getObject().getSum();

		//验证选中的作业计划主表记录存在
		PlnLengthwisePlan pp=new PlnLengthwisePlan();
		pp.setMachine_code(pps.getMachine_code());
		pp.setLw_plan_no(pps.getLw_plan_no());
		int icount=this.getMapper(PlnLengthwisePlanMapper.class).count(pp);
		if(icount==0){
			rm.setState("500");
			rm.setMsgInfo("作业计划主表记录不存在");
			return rm;
		}
		//验证选中的作业计划明细表记录存在
		PlnLengthwisePlanDetail ppd=new PlnLengthwisePlanDetail();
		ppd.setMachine_code(pps.getMachine_code());
		ppd.setLw_plan_no(pps.getLw_plan_no());
		ppd.setObject_no_vt(pps.getObject_no_vt());
		ppd.setObject_no(pps.getMaterial_no());
		List<PlnLengthwisePlanDetail> lppd=this.getMapper(PlnLengthwisePlanDetailMapper.class).find(ppd, 0, 0);
		if(lppd==null || lppd.size()==0){
			rm.setState("500");
			rm.setMsgInfo("作业计划明细记录不存在");
			return rm;
		}

		//验证选中的作业计划对应的分条主实绩存在，且为未交工状态
		MesCrSlittingM mcsm=new MesCrSlittingM();
		mcsm.setMachine_code(pps.getMachine_code());
		mcsm.setSchedule_no(pps.getLw_plan_no());
		mcsm.setMaterial_no_vt(pps.getObject_no_vt());
		mcsm.setMaterial_no(pps.getMaterial_no());
		List<MesCrSlittingM> lmcsm=this.getMapper(MesCrSlittingMMapper.class).find(mcsm, 0, 0);
		if(lmcsm==null||lmcsm.size()==0){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条主实绩不存在！");
			return rm;
		}
		if(!"0".equals(lmcsm.get(0).getHand_over_status())
				&&lmcsm.get(0).getHand_over_status()!=null){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条已生产交工！");
			return rm;
		}

		//验证选中的子卷实绩记录存在
		MesCrSlittingD mcd=this.getMapper(MesCrSlittingDMapper.class).findById(oci.getObject().getChild().getCoil_no());
		if(mcd!=null&&mcd.getCoil_no()!=null){
			//开始事务
			//修改子卷实绩表 2018 6 -27  只修改act_wdt
			MesCrSlittingD mm=oci.getObject().getChild();
			mm.setUpdate_opr(username);
			mm.setUpdate_time(now);
			mm.setAct_wdt(oci.getObject().getChild().getAct_wdt());
			this.getMapper(MesCrSlittingDMapper.class).update(mm);
			//日志
			MesOprLog mol = new MesOprLog("车间MES", pps.getMachine_name()+"作业管理", "修改宽度", username, opr_time, mm.getCoil_no(), null, null, null, "投料卷号："+pps.getMaterial_no()+mm.getMachine_code());
			this.getMapper(MesOprLogMapper.class).insert(mol);
		}else{
			throw new Exception("子卷实绩记录不存在!");
		}
		rm.setState("200");
		return rm;
	}

	/**
	 * 删除子卷
	 * @param oci
	 * @return
	 * @throws Exception
	 */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doDeleteWeb(CommonPage<MesCrSlittingSum> oci) throws Exception{
		ResultModel rm=new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		PlnLengthwisePlanSum pps=oci.getObject().getSum();

		//验证选中的作业计划主表记录存在
		PlnLengthwisePlan pp=new PlnLengthwisePlan();
		pp.setMachine_code(pps.getMachine_code());
		pp.setLw_plan_no(pps.getLw_plan_no());
		int icount=this.getMapper(PlnLengthwisePlanMapper.class).count(pp);
		if(icount==0){
			rm.setState("500");
			rm.setMsgInfo("作业计划主表记录不存在");
			return rm;
		}

		//验证选中的作业计划明细表记录存在
		PlnLengthwisePlanDetail ppd=new PlnLengthwisePlanDetail();
		ppd.setMachine_code(pps.getMachine_code());
		ppd.setLw_plan_no(pps.getLw_plan_no());
		ppd.setObject_no_vt(pps.getObject_no_vt());
		ppd.setObject_no(pps.getMaterial_no());
		List<PlnLengthwisePlanDetail> lppd=this.getMapper(PlnLengthwisePlanDetailMapper.class).find(ppd, 0, 0);
		if(lppd==null || lppd.size()==0){
			rm.setState("500");
			rm.setMsgInfo("作业计划明细记录不存在");
			return rm;
		}

		//验证选中的作业计划对应的分条主实绩存在，且为未交工状态
		MesCrSlittingM mcsm=new MesCrSlittingM();
		mcsm.setMachine_code(pps.getMachine_code());
		mcsm.setSchedule_no(pps.getLw_plan_no());
		mcsm.setMaterial_no_vt(pps.getObject_no_vt());
		mcsm.setMaterial_no(pps.getMaterial_no());
		List<MesCrSlittingM> lmcsm=this.getMapper(MesCrSlittingMMapper.class).find(mcsm, 0, 0);
		if(lmcsm==null||lmcsm.size()==0){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条主实绩不存在！");
			return rm;
		}
		if(!"0".equals(lmcsm.get(0).getHand_over_status())
				&&lmcsm.get(0).getHand_over_status()!=null){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条已生产交工！");
			return rm;
		}
		if("B".equals(oci.getObject().getChild().getCoil_no().substring(oci.getObject().getChild().getCoil_no().length()-1))){
			rm.setState("500");
			rm.setMsgInfo("["+oci.getObject().getChild().getCoil_no()+"]边丝不可删除！");
			return rm;
		}
		MesCrSlittingD mcsxx = this.getMapper(MesCrSlittingDMapper.class).findById(oci.getObject().getChild().getCoil_no());
		if(mcsxx==null || mcsxx.getCoil_no()==null){
			rm.setState("500");
			rm.setMsgInfo("卷号["+oci.getObject().getChild().getCoil_no()+"]不存在");
			return rm;
		}
		
		//删除子卷实绩表
		this.getMapper(MesCrSlittingDMapper.class).delete(oci.getObject().getChild().getCoil_no());
		//日志
		MesOprLog mol = new MesOprLog("车间MES", pps.getMachine_name()+"作业管理", "删除子卷", username, opr_time, oci.getObject().getChild().getCoil_no(), null, null, null, "投料卷号："+pps.getMaterial_no());
		this.getMapper(MesOprLogMapper.class).insert(mol);
		
		rm.setState("200");
		return rm;
	}

	/**
	 * 删除所有子卷
	 * @param oci
	 * @return
	 */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doDeleteAllWeb(CommonPage<MesCrSlittingSum> oci){
		ResultModel rm=new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		PlnLengthwisePlanSum pps=oci.getObject().getSum();

		//验证选中的作业计划主表记录存在
		PlnLengthwisePlan pp=new PlnLengthwisePlan();
		pp.setMachine_code(pps.getMachine_code());
		pp.setLw_plan_no(pps.getLw_plan_no());
		int icount=this.getMapper(PlnLengthwisePlanMapper.class).count(pp);
		if(icount==0){
			rm.setState("500");
			rm.setMsgInfo("作业计划主表记录不存在");
			return rm;
		}

		//验证选中的作业计划明细表记录存在
		PlnLengthwisePlanDetail ppd=new PlnLengthwisePlanDetail();
		ppd.setMachine_code(pps.getMachine_code());
		ppd.setLw_plan_no(pps.getLw_plan_no());
		ppd.setObject_no_vt(pps.getObject_no_vt());
		ppd.setObject_no(pps.getMaterial_no());
		List<PlnLengthwisePlanDetail> lppd=this.getMapper(PlnLengthwisePlanDetailMapper.class).find(ppd, 0, 0);
		if(lppd==null || lppd.size()==0){
			rm.setState("500");
			rm.setMsgInfo("作业计划明细记录不存在");
			return rm;
		}

		//验证选中的作业计划对应的分条主实绩存在，且为未交工状态
		MesCrSlittingM mcsm=new MesCrSlittingM();
		mcsm.setMachine_code(pps.getMachine_code());
		mcsm.setSchedule_no(pps.getLw_plan_no());
		mcsm.setMaterial_no_vt(pps.getObject_no_vt());
		mcsm.setMaterial_no(pps.getMaterial_no());
		List<MesCrSlittingM> lmcsm=this.getMapper(MesCrSlittingMMapper.class).find(mcsm, 0, 0);
		if(lmcsm==null||lmcsm.size()==0){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条主实绩不存在！");
			return rm;
		}
		if(!"0".equals(lmcsm.get(0).getHand_over_status())
				&&lmcsm.get(0).getHand_over_status()!=null){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条已生产交工！");
			return rm;
		}

		//验证作业计划原料卷存在子卷实绩
		MesCrSlittingD m=new MesCrSlittingD();
		m.setProcess_no(lmcsm.get(0).getProcess_no());
		List<MesCrSlittingD> lmcsd=this.getMapper(MesCrSlittingDMapper.class).find(m, 0, 0);
		if(lmcsd==null||lmcsd.size()==0){
			rm.setState("500");
			rm.setMsgInfo("作业计划原料卷不存在子卷实绩!");
			return rm;
		}

		//删除子卷实绩表
		for(MesCrSlittingD md:lmcsd){
			this.getMapper(MesCrSlittingDMapper.class).delete(md.getCoil_no());
			//日志
			MesOprLog mol = new MesOprLog("车间MES", pps.getMachine_name()+"作业管理", "删除所有子卷", username, opr_time, md.getCoil_no(), null, null, null, "投料卷号："+pps.getMaterial_no()+md.getMachine_code());
			this.getMapper(MesOprLogMapper.class).insert(mol);
		}	
		rm.setState("200");
		return rm;
	}

	/**
	 * 交工:4mm
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doHandoverWorkWeb(CommonPage<MesCrSlittingSum> oci) throws Exception{
		ResultModel rm=new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		String work_date = oci.getMemo3();//交工时间 (String) this.getSession().getAttribute(HomeService.SESSION_WORK_TIME);
		String work_ord = oci.getMemo4();//班次(String) this.getSession().getAttribute(HomeService.SESSION_WORK_ORD);
		String work_grp = oci.getMemo5();//班组(String) this.getSession().getAttribute(HomeService.SESSION_WORK_GRP);
		PlnLengthwisePlanSum pps=oci.getObject().getSum();
		
		String nextP = ""; // 下道工序，日志界面追踪用：
		
		//验证选中的作业计划主表记录存在
		PlnLengthwisePlan pp=new PlnLengthwisePlan();
		pp.setMachine_code(pps.getMachine_code());
		pp.setLw_plan_no(pps.getLw_plan_no());
		int icount=this.getMapper(PlnLengthwisePlanMapper.class).count(pp);
		if(icount==0){
			rm.setState("500");
			rm.setMsgInfo("作业计划主表记录不存在");
			return rm;
		}

		//-------------------2018-03-15------------------
		/*
		 定义变量dUpper，dLower（数值型，实数），分别从基础信息表（COM_BASE_INFO）获取编号（BASE_CODE）=“386101”、“386102”的值（MEMO）并验证，
		 只有当记录存在，且值（MEMO）为有效数值时，对应进行赋值：其中dUpper对应381601、dLower对应386102；当381601的值无效时
		 （无此记录或为空或不是有效数值），dUpper = 5（缺省值）；，当381602的值无效时（无此记录或为空或不是有效数值），dLower = -5（缺省值）；
		 */
		double dUpper=0,dLower=0;
		ResultModel rmDb=this.getBean(PbModelDbServiceImpl.class).findMesProductWidthCmbDb();
		if("200".equals(rmDb.getState())){
			if(rmDb.getData()!=null){
				dUpper=5;
				dLower=-5;
				try{
					@SuppressWarnings("unchecked")
					List<PbModelDb> lpmd=(List<PbModelDb>)rmDb.getData();
					for(PbModelDb pmd:lpmd){
						if("386101".equals(pmd.getId())){
							dUpper=Double.parseDouble(pmd.getRegionkey());
						}else if("386102".equals(pmd.getId())){
							dLower=Double.parseDouble(pmd.getRegionkey());
						}
					}
				}catch(Exception e){}
			}
		}
		//验证选中的作业计划明细表记录存在
		PlnLengthwisePlanDetail ppd=new PlnLengthwisePlanDetail();
		ppd.setMachine_code(pps.getMachine_code());
		ppd.setLw_plan_no(pps.getLw_plan_no());
		ppd.setObject_no_vt(pps.getObject_no_vt());
		ppd.setObject_no(pps.getMaterial_no());
		List<PlnLengthwisePlanDetail> lppd=this.getMapper(PlnLengthwisePlanDetailMapper.class).find(ppd, 0, 0);
		if(lppd==null || lppd.size()==0){
			rm.setState("500");
			rm.setMsgInfo("作业计划明细记录不存在");
			return rm;
		}

		//验证选中的作业计划对应的分条主实绩存在，且为未交工状态
		MesCrSlittingM mcsm=new MesCrSlittingM();
		mcsm.setMachine_code(pps.getMachine_code());
		mcsm.setSchedule_no(pps.getLw_plan_no());
		mcsm.setMaterial_no_vt(pps.getObject_no_vt());
		mcsm.setMaterial_no(pps.getMaterial_no());
		List<MesCrSlittingM> lmcsm=this.getMapper(MesCrSlittingMMapper.class).find(mcsm, 0, 0);
		if(lmcsm==null||lmcsm.size()==0){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条主实绩不存在！");
			return rm;
		}
				
		//2018-09-05
		MesCrSlittingM mesCrSlittingM =lmcsm.get(0);
		if(mesCrSlittingM.getBld_set_gap()==null || "".equals(mesCrSlittingM.getBld_set_gap())){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条主实绩的"+"排刀间隙量（mm）为空，请输入排刀间隙量（mm），并点击保存按钮，再进行此操作！");
			return rm;
		}
		if(mesCrSlittingM.getBld_set_overlay()==null || "".equals(mesCrSlittingM.getBld_set_overlay())){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条主实绩的"+"排刀重叠量（mm）为空，请输入排刀重叠量（mm），并点击保存按钮，再进行此操作！");
			return rm;
		}
		if(mesCrSlittingM.getPlt_tension()==null || "".equals(mesCrSlittingM.getPlt_tension())){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条主实绩的"+"张力台张力（kg）为空，请输入张力台张力（kg），并点击保存按钮，再进行此操作！");
			return rm;
		}
		if(mesCrSlittingM.getPrm_rcd_opr()==null || "".equals(mesCrSlittingM.getPrm_rcd_opr())){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条主实绩的"+"记录人为空，请输入记录人，并点击保存按钮，再进行此操作！");
			return rm;
		}
		if(mesCrSlittingM.getPrm_chk_opr()==null || "".equals(mesCrSlittingM.getPrm_chk_opr())){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条主实绩的"+"检查人为空，请输入检查人，并点击保存按钮，再进行此操作！");
			return rm;
		}		
		
		if(!"0".equals(lmcsm.get(0).getHand_over_status())
				&&lmcsm.get(0).getHand_over_status()!=null){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条已生产交工！");
			return rm;
		}

		//验证作业计划原料卷存在子卷实绩
		MesCrSlittingD m=new MesCrSlittingD();
		m.setProcess_no(lmcsm.get(0).getProcess_no());
		List<MesCrSlittingD> lmcsd=this.getMapper(MesCrSlittingDMapper.class).findWithCondition(m, "coil_no not like '%B'", " coil_no ", 0, 0);
		if(lmcsd==null||lmcsd.size()==0){
			rm.setState("500");
			rm.setMsgInfo("作业计划原料卷不存在子卷实绩!");
			return rm;
		}
		
		for (MesCrSlittingD mcsd : lmcsd) {
			// 2021-07-10  zlz 增加校验质量判定结果,空则不允许交工 
			ResultModel tmp_rst = 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);
			try {
				tmp_rst = this.getBean(MesApiServiceImpl.class).hasJudegeResult(mcsd.getCoil_no(),mcsd.getProd_order_no(),processpoint.slitting_code);
			} catch(Exception ex) {
				// 暂时先注释：2019101 刘侣
//				throw new Exception("获取质量判定信息接口报错!"+ ex.getMessage());
			}
			if(!"200".equals(tmp_rst.getState())){
				// 暂时先注释：2019101 刘侣
//				throw new Exception(tmp_rst.getData().toString());
			}
		}
			
		MesCrSlittingM mmm=new MesCrSlittingM();
  		mmm.setProcess_no(lmcsm.get(0).getProcess_no());
  		mmm.setWrk_grp(work_grp);
  		mmm.setWrk_ord(work_ord);
  		mmm.setWrk_date(work_date);
  		this.getMapper(MesCrSlittingMMapper.class).update(mmm);
  				
		//更新子表班组
		MesCrSlittingD mdd=new MesCrSlittingD();
		mdd.setProcess_no(lmcsm.get(0).getProcess_no());
		List<MesCrSlittingD> lmddq=this.getMapper(MesCrSlittingDMapper.class).findWithCondition(mdd, "", " coil_no ", 0, 0);
		for(MesCrSlittingD mc : lmddq){
			MesCrSlittingD mcsd=new MesCrSlittingD();
  			mcsd.setCoil_no(mc.getCoil_no());
  			mcsd.setWrk_grp(work_grp);
  			mcsd.setWrk_ord(work_ord);
  			mcsd.setWrk_date(work_date);
  			this.getMapper(MesCrSlittingDMapper.class).update(mcsd);
		}

		PlnMaterielDetail pmd=new PlnMaterielDetail();
		pmd.setMat_object_no_vt(pps.getObject_no_vt());
		List<PlnMaterielDetail> lpmd=this.getMapper(PlnMaterielDetailMapper.class).findWithCondition(pmd, "", " serial_no ", 0, 0);
		int k=0,n=lpmd.size()-1;
		//开始事务
		for(MesCrSlittingD mcsdc:lmcsd){
			//子卷的规格、重量都不为空值，重量大于0
			if(mcsdc.getAct_thk()==null){
				throw new Exception("子卷["+mcsdc.getCoil_no()+"]厚度为空");
			}
			if(mcsdc.getAct_wdt()==null){
				throw new Exception("子卷["+mcsdc.getCoil_no()+"]宽度为空");
			}
			if(mcsdc.getCoil_act_wgt()==null||mcsdc.getCoil_act_wgt()<=0){
				throw new Exception("子卷["+mcsdc.getCoil_no()+"]重量需大于0");
			}

			//调用物流模块（仓库管理）接口，验证产生的吊销卷号 在库存信息中不存在
			YdmProductDetail ypd = this.getMapper(YdmProductDetailMapper.class).doFind(mcsdc.getCoil_no(), null);
			if(ypd !=null){
				throw new Exception("子卷号["+mcsdc.getCoil_no()+"]已经存在，不能重复");
			}

			//---------------2018-03-15----------------------
			if(k<=n){
				MesCrSlittingD mcd=new MesCrSlittingD();
				mcd.setCoil_no(mcsdc.getCoil_no());

				//如果【(子卷实绩厚度 == 计划厚度) AND (子卷实绩宽度 - 计划宽度) <= dUpper AND (子卷实绩宽度 - 计划宽度) >= dLower】
				//2018-08-22 如果【(子卷实绩厚度 >0) AND (子卷实绩宽度 - 计划宽度) <= dUpper AND (子卷实绩宽度 - 计划宽度) >= dLower】
				if(mcsdc.getAct_thk()!=null && mcsdc.getAct_thk()>0
						&&(mcsdc.getAct_wdt().doubleValue()-lpmd.get(k).getWidth().doubleValue()<=dUpper)
						&&(mcsdc.getAct_wdt().doubleValue()-lpmd.get(k).getWidth().doubleValue()>=dLower)){
					//则SET 实绩.COIL_NO_VT = 计划.OBJECT_NO_VT, 实绩.PROD_ORDER_NO = 计划.PROD_ORDER_NO, 实绩.ORDER_NO = 计划.ORDER_NO；
					mcd.setCoil_no_vt(lpmd.get(k).getObject_no_vt());
					mcd.setOrder_no(lpmd.get(k).getOrder_no());
					mcd.setProd_order_no(lpmd.get(k).getProd_order_no());
					this.getMapper(MesCrSlittingDMapper.class).update(mcd);
				}else{
					//否则SET 实绩.COIL_NO_VT = NULL, 实绩.PROD_ORDER_NO = NULL, 实绩.ORDER_NO = NULL
					this.getMapper(MesCrSlittingDMapper.class).doUpdateNulls(mcd);
				}
			}
			//------------------------------------------------------
			k++;
		}
		
		//2019-02-21
  		/*
  		检验批分批规则：
  			同炉次号向下相同牌号、相同尺寸（厚度、宽度）的物料集合生成一个检验批号
  			检验批号编码规则：炉次号+两位流水号，示例：2619000401） 
  		 */
		try{
			Map<String, List<MesCrSlittingD>> mc_list =new HashMap<String, List<MesCrSlittingD>>();
	  		if(mesCrSlittingM.getSchedule_no()!=null && !"".equals(mesCrSlittingM.getSchedule_no())){
	  			List<MesCrSlittingM> v_rec_baf_mList = this.getMapper(MesCrSlittingMMapper.class).findWithCondition(null,"schedule_no='"+mesCrSlittingM.getSchedule_no()+"'", null, 0, 0);
	  			List<MesCrSlittingD> mcdlist=new ArrayList<MesCrSlittingD>();
	  			for(MesCrSlittingM mcsttlim:v_rec_baf_mList){
	  				List<MesCrSlittingD> lll = this.getMapper(MesCrSlittingDMapper.class).findWithCondition(null, "process_no='"+mcsttlim.getProcess_no()+"' and coil_no not like '%B'", null, 0, 0);
	  				for(MesCrSlittingD mccc:lll){
	  					mcdlist.add(mccc);	
	  				}
	  			}
	  			if(v_rec_baf_mList!=null && v_rec_baf_mList.size()>0 && mcdlist.size()>0){
	  						mc_list = groupBillingDataByExcpBatchCode(mcdlist,mesCrSlittingM.getSchedule_no());
	  						
	  			}
	  		}
	  		if(mc_list!=null && mc_list.size()>0){
				for(Map.Entry<String, List<MesCrSlittingD>> grouplist :mc_list.entrySet()){
					List<MesCrSlittingD> listCes = grouplist.getValue();
					for(MesCrSlittingD mcam:listCes){
							MesCrSlittingD mCrossleo = new MesCrSlittingD();
							mCrossleo.setCoil_no(mcam.getCoil_no());
							mCrossleo.setInspection_lot(mcam.getInspection_lot());
							this.getMapper(MesCrSlittingDMapper.class).update(mCrossleo);
						}
					}
			}
			
		}catch(Exception e){
			e.printStackTrace();
		}
	    		
		//循环分条子卷实绩（MES_CR_SLITTING_D，此时，子卷已完成匹配虚拟子卷号，需要重新获取子卷实绩集合
		MesCrSlittingD mc=new MesCrSlittingD();
		mc.setProcess_no(lmcsm.get(0).getProcess_no());
		List<MesCrSlittingD> lmcsq=this.getMapper(MesCrSlittingDMapper.class).find(mc, 0, 0);
		for(MesCrSlittingD mcsq:lmcsq){
			
			//20201215 毛重交货：交工过程中边丝重量=钢卷理重-所有分条小卷重量-头尾卷重量（如果有），
			//且边丝每卷最多只有一个，打印的重量为交工的重量(毛重)
			if ("B".equals(mcsq.getCoil_no().substring(mcsq.getCoil_no().length()-1))) {
				String condition = "contract_no||contract_line_seq||order_seq = '"+lmddq.get(0).getOrder_no()+"' "
						+ "and nvl(change_flag,'0') <> '1' and weight_type_no = '102302'";
				int soiCount = this.getMapper(SlmOrderInfoMapper.class).countWithCondition(null, condition);
				if (soiCount > 0) { //
					//投料重量					
					Double sumWeight = this.getMapper(MesCrSlittingDMapper.class).doQuerySumWeight(mcsq.getProcess_no());
					BigDecimal b= new BigDecimal(mesCrSlittingM.getMtr_act_wgt() - sumWeight);  
					double weightB = b.setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
					mcsq.setCoil_act_wgt(weightB);
					mcsq.setUpdate_opr(userName);
					mcsq.setUpdate_time(now);
					mcsq.setMemo("4mm毛重边丝自动计算重量");
					this.getMapper(MesCrSlittingDMapper.class).update(mcsq);
				}
			}
					
			//异重交工特有功能20191114
			if ("1".equals(oci.getMemo1())) {
				MesOprInfo moi = new MesOprInfo();
				moi.setOpr_id(mcsq.getCoil_no()+new SimpleDateFormat("yyyyMMddHHmmss").format(now));
				moi.setCoil_no(mcsq.getCoil_no());
				moi.setMat_coil_no(mcsm.getMaterial_no());//投料卷号
				moi.setOpr_desc("交工重量差异超过0.3%且不超过200KG时,进行异重交工");
				moi.setOpr_type("异重交工");
				moi.setMemo(oci.getMemo2());//异重交工的原因
				moi.setCreate_man(userName);
				moi.setCreate_time(now);
				this.getMapper(MesOprInfoMapper.class).insert(moi);
			}			
			
			//重量异常控制的
			if (mcsq.getCoil_no() !=null && "B".equals(mcsq.getCoil_no().substring(mcsq.getCoil_no().length()-1))) {
				if (mcsq.getCoil_act_wgt()==null || mcsq.getCoil_act_wgt().intValue()<=0) {
					continue;
				}
			}
			if(mcsq.getCoil_act_wgt()==null || mcsq.getCoil_act_wgt().intValue()<=0){
				throw new Exception("子卷["+mcsq.getCoil_no()+"]实重异常！");
			}
			
			if(!"B".equals(mcsq.getCoil_no().substring(mcsq.getCoil_no().length()-1))){
				if(mcsq.getCoil_no_vt()==null||"".equals(mcsq.getCoil_no_vt())){
					MesCrSlittingD mcd=new MesCrSlittingD();
					mcd.setCoil_no(mcsq.getCoil_no());
					mcd.setUpdate_opr(userName);
					mcd.setUpdate_time(now);
					this.getMapper(MesCrSlittingDMapper.class).update(mcd);
				}
			}
			
			CommonPage<MesCrSlittingD> cp=new CommonPage<MesCrSlittingD>();
			MesCrSlittingD mcsd=new MesCrSlittingD();
			mcsd.setCoil_no(mcsq.getCoil_no());
			mcsd.setCoil_no_vt(mcsq.getCoil_no_vt());
			cp.setObject(mcsd);
			//调用物流模块（仓库管理）接口，逐一将分条子卷实绩各子卷，插入库存记录（待入库状态）；	
			try{
				//下道工序不为空，入库仓库为中间品库，为空（最后一道工序了），就如成品库  
				String nextProcessCode = this.getBean(MesApiDesignInfoImpl.class).getNextProcessCode("1", pps.getObject_no_vt());
				nextP = nextProcessCode;
				if(nextProcessCode==null || "".equals(nextProcessCode)){
					cp.setMemo1("500203");//成品库					
					 //生产订单统计 统计量并修改生产订单状态
				    try{
//				    	this.getBean(PlnProdorderStatisticServiceImpl.class).prod_Stats(mcsq.getCoil_no(),1,true);
				    }catch(Exception e){
				    	System.out.println("生产订单统计 统计量并修改生产订单状态出错");
				    	e.printStackTrace();
				    }
				}else{
					cp.setMemo1("500202");//在制品库
				}
			}catch(Exception ex){
				throw new Exception("获取下道工序异常！");
			}
			
			try{				
				//2019-02-21修改
				PlnMaterielDetail pmd_21=new PlnMaterielDetail();
				pmd_21.setObject_no_vt(pps.getObject_no_vt());
				List<PlnMaterielDetail> list_pmd = this.getMapper(PlnMaterielDetailMapper.class).find(pmd_21, 0, 0);
				boolean flag_Ct = false;
				if(list_pmd!=null && list_pmd.size()>0){
					flag_Ct=this.getBean(MesApiDesignInfoImpl.class).getContractType(list_pmd.get(0).getProd_order_no());
				}
				if(flag_Ct && !"B".equals(mcsq.getCoil_no().substring(mcsq.getCoil_no().length()-1))){
					cp.setMemo3("507101");//物料属性，优特钢带
				}											
				ResultModel rmValid = this.getBean(LmsApiServiceImpl.class).doMesIn(cp);
				if(!"200".equals(rmValid.getState())){
					throw new Exception(rmValid.getMsgInfo());
				}
				
				
				// 写入库存表后去更新生产订单状态：20230909刘侣；
				YdmProductDetail ypdQ = this.getMapper(YdmProductDetailMapper.class).doFind(mcsq.getCoil_no(), null);
				if (ypdQ != null && "500203".equals(ypdQ.getStorageattr())) {
					this.getBean(PlnProdorderStatisticServiceImpl.class).prod_Stats(ypdQ.getCoilno(),1,true);
					
				}
				// end
				
				// 检验委托：如果是最后一道工序才需要送样，去做检验委托：
				// 待判信息发送：如果是最后一道工序（进成品库），那么就给isfinal ： 1， 否则就是：0；
				if (ypdQ != null && "500203".equals(ypdQ.getStorageattr())) {
					
					// 发送检验委托信息：20230909刘侣：最后一道工序才送样
					if (mcsq.getCoil_no() != null && ("B".equals(mcsq.getCoil_no().substring(mcsq.getCoil_no().length()-1))
							 || "H".equals(mcsq.getCoil_no().substring(mcsq.getCoil_no().length()-1)))) {
						
						this.getBean(SlmFundFirstDetailServiceImpl.class).sendToPD(mcsq.getCoil_no(), true, "1");
					} else {
						this.getBean(SlmFundFirstDetailServiceImpl.class).sendToPD(mcsq.getCoil_no(), false, "1");
					}
					
					// 只有以6开头的订单才去发送检验委托：
					if (ypdQ.getOrderno() != null) {
						ResultModel rmwt = this.getBean(SlmFundFirstDetailServiceImpl.class).sendToJYWT(mcsq.getCoil_no(), true);
  						if ("500".equals(rmwt.getState())) {
  							throw new Exception(rmwt.getMsgInfo());
  						}
					}
					
					// end
				} else {
					// 非最后一道：
					if (mcsq.getCoil_no() != null && ("B".equals(mcsq.getCoil_no().substring(mcsq.getCoil_no().length()-1))
							 || "H".equals(mcsq.getCoil_no().substring(mcsq.getCoil_no().length()-1)))) {
						
						this.getBean(SlmFundFirstDetailServiceImpl.class).sendToPD(mcsq.getCoil_no(), true, "0");
					} else {
						this.getBean(SlmFundFirstDetailServiceImpl.class).sendToPD(mcsq.getCoil_no(), false, "0");
					}
				}
				// end
				
				
			}catch(Exception ex){
				throw new Exception("物流入库接口出错!"+ ex.getMessage());
			}
			
			
			try{
				ResultModel rmxx = this.getBean(QmsApiServiceImpl.class).doQueryJudegeResult(mcsq.getCoil_no());
				if(rmxx!=null && rmxx.getData()!=null && (rmxx.getData() instanceof JudgeResult)){
					JudgeResult jr=(JudgeResult)rmxx.getData();
					YdmProductDetail ypd=new YdmProductDetail();
					ypd.setCoilno(mcsq.getCoil_no());
					boolean falgggg=false;
					if(jr.getMarginal_result()!=null){
						ypd.setMarginal_result(jr.getMarginal_result());
						falgggg=true;
					}
					if(jr.getMarginal_result_id()!=null){
						ypd.setMarginal_result_id(jr.getMarginal_result_id());
						falgggg=true;
					}
					if(jr.getMeasure_result()!=null){
						ypd.setMeasure_result(jr.getMeasure_result());
						falgggg=true;
					}
					if(jr.getMeasure_result_id()!=null){
						ypd.setMeasure_result_id(jr.getMeasure_result_id());
						falgggg=true;
					}
					if(jr.getSfd_is_lock()!=null){
						ypd.setSfd_is_lock(jr.getSfd_is_lock());
						falgggg=true;
					}
					if(jr.getSfe_is_lock()!=null){
						ypd.setSfe_is_lock(jr.getSfe_is_lock());
						falgggg=true;
					}
					if(jr.getSfu_is_lock()!=null){
						ypd.setSfu_is_lock(jr.getSfu_is_lock());
						falgggg=true;
					}
					if(jr.getSic_is_lock()!=null){
						ypd.setSic_is_lock(jr.getSic_is_lock());
						falgggg=true;
					}
					if(jr.getSizeResult()!=null){
						ypd.setSizeresult(jr.getSizeResult());
						falgggg=true;
					}
					if(jr.getUd_surface_result()!=null){
						ypd.setUd_surface_result(jr.getUd_surface_result());
						falgggg=true;
					}
					if(jr.getUd_surface_result_id()!=null){
						ypd.setUd_surface_result_id(jr.getUd_surface_result_id());
						falgggg=true;
					}
					if(jr.getUp_surface_result()!=null){
						ypd.setUp_surface_result(jr.getUp_surface_result());
						falgggg=true;
					}
					if(jr.getUp_surface_result_id()!=null){
						ypd.setUp_surface_result_id(jr.getUp_surface_result_id());
						falgggg=true;
					}
					if(jr.getUp_surface_flaw() != null) {
						ypd.setUp_surface_flaw(jr.getUp_surface_flaw());
						falgggg= true;
					}
					if(jr.getUd_surface_flaw() != null) {
						ypd.setUd_surface_flaw(jr.getUd_surface_flaw());
						falgggg= true;
					}
					if(jr.getMarginal_flaw()!= null) {
						ypd.setMarginal_flaw(jr.getMarginal_flaw());
						falgggg= true;
					}
					if(falgggg){
//						this.getMapper(YdmProductDetailMapper.class).update(ypd);
					}
					
				}
			}catch(Exception e){
				System.out.println("调用质量接口报错");
				e.printStackTrace();
			}
					
			//循环分条子卷实绩（MES_CR_SLITTING_D，此时，子卷已完成匹配虚拟子卷号，需要重新获取子卷实绩集合
			//如果此子卷的虚拟子卷号不为空（COIL_NO_VT，即满足切割计划）
			try{
				if(mcsq.getCoil_no_vt()!=null && !"".equals(mcsq.getCoil_no_vt())){
					//则调用生产管理的【分条完成——虚拟子卷 挂料接口】
					PlnMaterielDetail pmdq=new PlnMaterielDetail();
					pmdq.setObject_no(mcsq.getCoil_no());
					pmdq.setObject_no_vt(mcsq.getCoil_no_vt());
					pmdq.setMaterial_no(pps.getMaterial_no());//投料卷号 material_no   由页面交工按钮传入
					pmdq.setSub_object_no(mcsq.getCoil_no());//目的是为了PrcMaterielRelation的sub_object_no(pmdq.getSub_object_no());
					pmdq.setCreate_time(now);// 传入操作时间 2018-06-19
					this.getBean(MesApiServiceImpl.class).LengthwiseFinsh_Relation(pmdq,dUpper,dLower);
				}else if (mcsq.getCoil_no() != null && ("B".equals(mcsq.getCoil_no().substring(mcsq.getCoil_no().length()-1))
	 					 || "H".equals(mcsq.getCoil_no().substring(mcsq.getCoil_no().length()-1))
	 					)){
					//则调用生产管理的【分条完成——实物 生成接口】 2018-06-22
					PrcMaterielRelation pmr=new PrcMaterielRelation();
					pmr.setObject_no(pps.getMaterial_no());//投料卷号 material_no   由页面交工按钮传入
					pmr.setSub_object_no(mcsq.getCoil_no());//MES_CR_SLITTING_D表的子卷号
					pmr.setRelation_seq(3);
					this.getBean(MesApiServiceImpl.class).LengthwiseFinsh_PrcMatRelAdd(pmr);//有insert插入prc_materiel_relation的操作
				}else{//如果此子卷的虚拟子卷号为空（COIL_NO_VT，即为非计划）	
					// --------------2018-06-22 改为调用分条完成——虚拟子卷 挂料接口非计划接口-------------------
					PlnMaterielDetail pmdq=new PlnMaterielDetail();
					pmdq.setObject_no(pps.getMaterial_no());
					pmdq.setMaterial_no(pps.getMaterial_no());//投料卷号 material_no   由页面交工按钮传入
					pmdq.setSub_object_no(mcsq.getCoil_no());//MES_CR_SLITTING_D表的子卷号
					// 传入操作时间 2018-06-22
					pmdq.setCreate_time(now);
					this.getBean(MesApiServiceImpl.class).LengthwiseFinsh_No_Plan(pmdq);//有insert插入PLN_MATERIEL_DETAIL的操作
					// --------------2018-06-22 改为调用分条完成——虚拟子卷 挂料接口非计划接口-------------------
				}
			}catch(Exception ex){
				throw new Exception("计划接口出错!"+ ex.getMessage());
			}
			
			//===============2019-03-12========质量检验委托开始=============================
		    if(mesCrSlittingM.getSchedule_no()!=null && !"".equals(mesCrSlittingM.getSchedule_no())){//作业计划号不为空
		    	try{
					QcmJhySampleFromPlan ajsfp=new QcmJhySampleFromPlan();
					PlnMaterielDetail pmdq=new PlnMaterielDetail();
					pmdq.setObject_no_vt(pps.getObject_no_vt());
					List<PlnMaterielDetail> lpmdq22=this.getMapper(PlnMaterielDetailMapper.class).find(pmdq, 0, 1);
					String prod_order_no=lpmdq22.get(0).getProd_order_no();
					List<PlnProdorder> lpp = this.getMapper(PlnProdorderMapper.class).findWithCondition(null, "prod_order_no='"+prod_order_no+"'", null, 0, 0);
					if(lpp!=null && lpp.size()>0){
						int judge_Contain_Qcm = this.getBean(MesApiDesignInfoImpl.class).Judge_Contain_Qcm(pps.getObject_no_vt(), "E");
						// 获取工艺路径包含成分或者材质类
						if(judge_Contain_Qcm!=-1){
							ajsfp.setPline_seq((long)judge_Contain_Qcm);
							ajsfp.setInspection_lot(mcsq.getInspection_lot());
							ajsfp.setBatch_no(mesCrSlittingM.getSchedule_no());//轧批号    炉次号
							List<PlnProcessPlan> list_plnP = this.getMapper(PlnProcessPlanMapper.class).findWithCondition(null, "produce_no='"+lpp.get(0).getProduce_no()+"' and cut_order_no = 1", "", 0, 0);
							if(list_plnP!=null && list_plnP.size()>0){
								ajsfp.setContract_line_no(list_plnP.get(0).getPlan_no());//合同行信息  销售的订单的加工计划号
							}
							ajsfp.setDesign_key(lpp.get(0).getDesign_key());//design_key的集合  
							ajsfp.setJudge("0");//用于判断是改判还是原判 0：原判；1：改判  no
							ajsfp.setMaterial_no(mcsq.getCoil_no());//取样材料号   
							ajsfp.setMsc_pline(lpp.get(0).getMsc_pline());//全程产线号  制成号
							ajsfp.setOrder_no(lpp.get(0).getOrder_no());//销售订单号(合同号+订单行号，示例:YT-66G66001)
							ajsfp.setBoard_no(mesCrSlittingM.getMaterial_no());
							
							ComBaseMachine cbm = this.getMapper(ComBaseMachineMapper.class).findById(mesCrSlittingM.getMachine_code());
							ComBasePline cbp = this.getMapper(ComBasePlineMapper.class).findById(cbm.getPline_code());
							ajsfp.setPline_code(cbm.getPline_code());//产线代码
							ajsfp.setPline_name(cbp.getPline_name());// 产线名称
							//后期需要修改
							ajsfp.setProcess_code("E");//工序代码    com_base_process表
							ajsfp.setPsc(lpp.get(0).getPsc());//物料编码，
							List<QcmJhySampleFromPlan> lqsfp=new ArrayList<>();
							lqsfp.add(ajsfp);
							CommonPage<QcmJhySampleFromPlan>  cpqjsfp=new CommonPage<QcmJhySampleFromPlan>();
							cpqjsfp.setObjectList(lqsfp);
							ResultModel reModel = this.getBean(QcmJhySampleConsignDItemServiceImpl.class).AutoGenerationSampleInfo(cpqjsfp);
							if(reModel!=null){
								System.out.println(reModel.getState());
								System.out.println(reModel.getMsgInfo());
							}
						}
					}
				}catch(Exception e){
					e.printStackTrace();
				}
		    }
		}

		//如果分条产生了吊销的原料卷，则调用物流模块（仓库管理）接口，将新产生的吊销卷信息，插入库存记录（待入库状态，除卷号、理重、实重、长度外，其它相关信息可复制库存中原始原料卷相关信息）；																																							
		if("1".equals(lmcsm.get(0).getPartial_rejected())){
			YdmProductDetail ypd=new YdmProductDetail();
			ypd.setCoilno(lmcsm.get(0).getRejected_coil_no());
			ypd.setTheoryweight(lmcsm.get(0).getRejected_coil_thr_wgt());
			ypd.setFactweight(lmcsm.get(0).getRejected_coil_act_wgt());
			ypd.setLength(lmcsm.get(0).getRejected_coil_len());
			ypd.setDiameter_inn(lmcsm.get(0).getMtr_inn_dia());
			ypd.setDiameter_out(lmcsm.get(0).getMtr_out_dia());
            //2018-09-26 机台代码，机台名称
			ypd.setMachine_code(lmcsm.get(0).getMachine_code());
			List<ComBaseMachine> listcom=this.getMapper(ComBaseMachineMapper.class).findWithCondition(null, "machine_code='"+lmcsm.get(0).getMachine_code()+"'", null, 0, 0);
			if(listcom!=null && listcom.size()>0){
				ypd.setMachine_name(listcom.get(0).getMachine_name());
			}
			ResultModel rmValid = this.getBean(LmsApiServiceImpl.class).doInsertRevoke(pps.getMaterial_no(),ypd);
			if(!"200".equals(rmValid.getState())){
				throw new Exception(rmValid.getMsgInfo());
			}
		}
		
		PlnMaterielDetail pmdq=new PlnMaterielDetail();
		pmdq.setObject_no_vt(pps.getObject_no_vt());
		List<PlnMaterielDetail> lpmdq=this.getMapper(PlnMaterielDetailMapper.class).find(pmdq, 0, 1);
		try{
			this.getBean(MesApiServiceImpl.class).LengthwiseFinsh_Sum(lpmdq.get(0));
		}catch(Exception ex){
			throw new Exception("计划接口出错!"+ ex.getMessage());
		}
		

		//修改分条主实绩的交工状态为已交工状态
		MesCrSlittingM mcsmu=new MesCrSlittingM();
		mcsmu.setProcess_no(lmcsm.get(0).getProcess_no());
		//“交工”的这个处理转移到“上料”按钮中
		mcsmu.setHand_over_status("1");
		mcsmu.setUpdate_opr(userName);
		mcsmu.setUpdate_time(now);
		mcsmu.setHand_over_opr(userName);
		mcsmu.setHand_over_time(new Date());
		this.getMapper(MesCrSlittingMMapper.class).update(mcsmu);		

		for (MesCrSlittingD msd : lmcsd) {
			
			MesOprLog mol = new MesOprLog("车间MES", "4mm分条机作业管理", "交工", userName, opr_time, msd.getCoil_no(), null, null, null, "投料卷号："+pps.getMaterial_no() + "；下道工序为：" + nextP);
			this.getMapper(MesOprLogMapper.class).insert(mol);
		}
		rm.setState("200");
		return rm;
	}

	/**
	 * 12mm交工
	 * @param oci
	 * @return
	 * @throws Exception
	 */	 	 
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doHandoverWorkWeb_12mm(CommonPage<MesCrSlittingSum> oci) throws Exception{
		ResultModel rm=new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		String work_date = oci.getMemo3();//交工时间 (String) this.getSession().getAttribute(HomeService.SESSION_WORK_TIME);
		String work_ord = oci.getMemo4();//班次(String) this.getSession().getAttribute(HomeService.SESSION_WORK_ORD);
		String work_grp = oci.getMemo5();//班组(String) this.getSession().getAttribute(HomeService.SESSION_WORK_GRP);
		PlnLengthwisePlanSum pps=oci.getObject().getSum();
		
		String nextP = "";
		
		//验证选中的作业计划主表记录存在
		PlnLengthwisePlan pp=new PlnLengthwisePlan();
		pp.setMachine_code(pps.getMachine_code());
		pp.setLw_plan_no(pps.getLw_plan_no());
		int icount=this.getMapper(PlnLengthwisePlanMapper.class).count(pp);
		if(icount==0){
			rm.setState("500");
			rm.setMsgInfo("作业计划主表记录不存在");
			return rm;
		}

		//-------------------2018-03-15------------------
		/*
		 定义变量dUpper，dLower（数值型，实数），分别从基础信息表（COM_BASE_INFO）获取编号（BASE_CODE）=“386101”、“386102”的值（MEMO）并验证，
		 只有当记录存在，且值（MEMO）为有效数值时，对应进行赋值：其中dUpper对应381601、dLower对应386102；当381601的值无效时
		 （无此记录或为空或不是有效数值），dUpper = 5（缺省值）；，当381602的值无效时（无此记录或为空或不是有效数值），dLower = -5（缺省值）；
		 */
		double dUpper=0,dLower=0;
		ResultModel rmDb=this.getBean(PbModelDbServiceImpl.class).findMesProductWidthCmbDb();
		if("200".equals(rmDb.getState())){
			if(rmDb.getData()!=null){
				dUpper=5;
				dLower=-5;
				try{
					@SuppressWarnings("unchecked")
					List<PbModelDb> lpmd=(List<PbModelDb>)rmDb.getData();
					for(PbModelDb pmd:lpmd){
						if("386101".equals(pmd.getId())){
							dUpper=Double.parseDouble(pmd.getRegionkey());
						}else if("386102".equals(pmd.getId())){
							dLower=Double.parseDouble(pmd.getRegionkey());
						}
					}
				}catch(Exception e){}
			}
		}
		//验证选中的作业计划明细表记录存在
		PlnLengthwisePlanDetail ppd=new PlnLengthwisePlanDetail();
		ppd.setMachine_code(pps.getMachine_code());
		ppd.setLw_plan_no(pps.getLw_plan_no());
		ppd.setObject_no_vt(pps.getObject_no_vt());
		ppd.setObject_no(pps.getMaterial_no());
		List<PlnLengthwisePlanDetail> lppd=this.getMapper(PlnLengthwisePlanDetailMapper.class).find(ppd, 0, 0);
		if(lppd==null || lppd.size()==0){
			rm.setState("500");
			rm.setMsgInfo("作业计划明细记录不存在");
			return rm;
		}

		//验证选中的作业计划对应的分条主实绩存在，且为未交工状态
		MesCrSlittingM mcsm=new MesCrSlittingM();
		mcsm.setMachine_code(pps.getMachine_code());
		mcsm.setSchedule_no(pps.getLw_plan_no());
		mcsm.setMaterial_no_vt(pps.getObject_no_vt());
		mcsm.setMaterial_no(pps.getMaterial_no());
		List<MesCrSlittingM> lmcsm=this.getMapper(MesCrSlittingMMapper.class).find(mcsm, 0, 0);
		if(lmcsm==null||lmcsm.size()==0){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条主实绩不存在！");
			return rm;
		}
		
		//2018-09-05
		MesCrSlittingM mesCrSlittingM =lmcsm.get(0);
		if(mesCrSlittingM.getBld_set_gap()==null || "".equals(mesCrSlittingM.getBld_set_gap())){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条主实绩的"+"排刀间隙量（mm）为空，请输入排刀间隙量（mm），并点击保存按钮，再进行此操作！");
			return rm;
		}
		if(mesCrSlittingM.getBld_set_overlay()==null || "".equals(mesCrSlittingM.getBld_set_overlay())){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条主实绩的"+"排刀重叠量（mm）为空，请输入排刀重叠量（mm），并点击保存按钮，再进行此操作！");
			return rm;
		}
		if(mesCrSlittingM.getPlt_tension()==null || "".equals(mesCrSlittingM.getPlt_tension())){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条主实绩的"+"张力台张力（kg）为空，请输入张力台张力（kg），并点击保存按钮，再进行此操作！");
			return rm;
		}
		if(mesCrSlittingM.getPrm_rcd_opr()==null || "".equals(mesCrSlittingM.getPrm_rcd_opr())){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条主实绩的"+"记录人为空，请输入记录人，并点击保存按钮，再进行此操作！");
			return rm;
		}
		if(mesCrSlittingM.getPrm_chk_opr()==null || "".equals(mesCrSlittingM.getPrm_chk_opr())){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条主实绩的"+"检查人为空，请输入检查人，并点击保存按钮，再进行此操作！");
			return rm;
		}
		if(mesCrSlittingM.getWire_wdt()==null){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条主实绩的"+"边丝宽度为空，请输入边丝宽度，并点击保存按钮，再进行此操作！");
			return rm;
		}		
		if(!"0".equals(lmcsm.get(0).getHand_over_status())
				&&lmcsm.get(0).getHand_over_status()!=null){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条已生产交工！");
			return rm;
		}

		//验证作业计划原料卷存在子卷实绩
		MesCrSlittingD m=new MesCrSlittingD();
		m.setProcess_no(lmcsm.get(0).getProcess_no());
		List<MesCrSlittingD> lmcsd=this.getMapper(MesCrSlittingDMapper.class).findWithCondition(m, "coil_no not like '%B'", " coil_no ", 0, 0);
		if(lmcsd==null||lmcsd.size()==0){
			rm.setState("500");
			rm.setMsgInfo("作业计划原料卷不存在子卷实绩!");
			return rm;
		}
		
		for (MesCrSlittingD mcsd : lmcsd) {
			// 2021-07-10  zlz 增加校验质量判定结果,空则不允许交工 
			ResultModel tmp_rst = 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);
			try {
				tmp_rst = this.getBean(MesApiServiceImpl.class).hasJudegeResult(mcsd.getCoil_no(),mcsd.getProd_order_no(),processpoint.slitting_code);
			} catch(Exception ex) {
				// 暂时先注释：2019101 刘侣
//				throw new Exception("获取质量判定信息接口报错!"+ ex.getMessage());
			}
			if(!"200".equals(tmp_rst.getState())){
				// 暂时先注释：2019101 刘侣
//				throw new Exception(tmp_rst.getData().toString());
			}
		}
		
		MesCrSlittingM mmm=new MesCrSlittingM();
  		mmm.setProcess_no(lmcsm.get(0).getProcess_no());
  		mmm.setWrk_grp(work_grp);
  		mmm.setWrk_ord(work_ord);
  		mmm.setWrk_date(work_date);
  		this.getMapper(MesCrSlittingMMapper.class).update(mmm); 		
		
		//更新子表班组
		MesCrSlittingD mdd=new MesCrSlittingD();
		mdd.setProcess_no(lmcsm.get(0).getProcess_no());
		List<MesCrSlittingD> lmddq=this.getMapper(MesCrSlittingDMapper.class).findWithCondition(mdd, "", " coil_no ", 0, 0);
		for(MesCrSlittingD mc : lmddq){
			MesCrSlittingD mcsd=new MesCrSlittingD();
  			mcsd.setCoil_no(mc.getCoil_no());
  			mcsd.setWrk_grp(work_grp);
  			mcsd.setWrk_ord(work_ord);
  			mcsd.setWrk_date(work_date);
  			this.getMapper(MesCrSlittingDMapper.class).update(mcsd);
		}		

		PlnMaterielDetail pmd=new PlnMaterielDetail();
		pmd.setMat_object_no_vt(pps.getObject_no_vt());
		List<PlnMaterielDetail> lpmd=this.getMapper(PlnMaterielDetailMapper.class).findWithCondition(pmd, "", " serial_no ", 0, 0);
		int k=0,n=lpmd.size()-1;
		//开始事务
		for(MesCrSlittingD mcsdc:lmcsd){
			//子卷的规格、重量都不为空值，重量大于0
			if(mcsdc.getAct_thk()==null){
				throw new Exception("子卷["+mcsdc.getCoil_no()+"]厚度为空");
			}

			if(mcsdc.getAct_wdt()==null){
				throw new Exception("子卷["+mcsdc.getCoil_no()+"]宽度为空");
			}
			if(mcsdc.getCoil_act_wgt()==null||mcsdc.getCoil_act_wgt()<=0){
				throw new Exception("子卷["+mcsdc.getCoil_no()+"]重量需大于0");
			}

			//调用物流模块（仓库管理）接口，验证产生的吊销卷号 在库存信息中不存在
			YdmProductDetail ypd=new YdmProductDetail();
			ypd.setCoilno(mcsdc.getCoil_no());
			List<YdmProductDetail> lypd=this.getMapper(YdmProductDetailMapper.class).find(ypd, 0, 0);
			if(lypd!=null&&lypd.size()>0){
				throw new Exception("钢卷号唯一，不能重复");
			}
			//---------------2018-03-15----------------------
			if(k<=n){
				MesCrSlittingD mcd=new MesCrSlittingD();
				mcd.setCoil_no(mcsdc.getCoil_no());

				//如果【(子卷实绩厚度 == 计划厚度) AND (子卷实绩宽度 - 计划宽度) <= dUpper AND (子卷实绩宽度 - 计划宽度) >= dLower】
				//2018-08-22 如果【(子卷实绩厚度 >0) AND (子卷实绩宽度 - 计划宽度) <= dUpper AND (子卷实绩宽度 - 计划宽度) >= dLower】
				if(mcsdc.getAct_thk()!=null && mcsdc.getAct_thk()>0
						&&(mcsdc.getAct_wdt().doubleValue()-lpmd.get(k).getWidth().doubleValue()<=dUpper)
						&&(mcsdc.getAct_wdt().doubleValue()-lpmd.get(k).getWidth().doubleValue()>=dLower)){
					//则SET 实绩.COIL_NO_VT = 计划.OBJECT_NO_VT, 实绩.PROD_ORDER_NO = 计划.PROD_ORDER_NO, 实绩.ORDER_NO = 计划.ORDER_NO；
					mcd.setCoil_no_vt(lpmd.get(k).getObject_no_vt());
					mcd.setOrder_no(lpmd.get(k).getOrder_no());
					mcd.setProd_order_no(lpmd.get(k).getProd_order_no());
					this.getMapper(MesCrSlittingDMapper.class).update(mcd);
				}else{
					//否则SET 实绩.COIL_NO_VT = NULL, 实绩.PROD_ORDER_NO = NULL, 实绩.ORDER_NO = NULL
					this.getMapper(MesCrSlittingDMapper.class).doUpdateNulls(mcd);
				}
			}
			//------------------------------------------------------
			k++;					
		}		
		
		//2019-02-21
  		/*
  		检验批分批规则：
  			同炉次号向下相同牌号、相同尺寸（厚度、宽度）的物料集合生成一个检验批号
  			检验批号编码规则：炉次号+两位流水号，示例：2619000401） 
  		 */
		try{
			Map<String, List<MesCrSlittingD>> mc_list =new HashMap<String, List<MesCrSlittingD>>();
	  		if(mesCrSlittingM.getSchedule_no()!=null && !"".equals(mesCrSlittingM.getSchedule_no())){
	  			List<MesCrSlittingM> v_rec_baf_mList = this.getMapper(MesCrSlittingMMapper.class).findWithCondition(null,"schedule_no='"+mesCrSlittingM.getSchedule_no()+"'", null, 0, 0);
	  			List<MesCrSlittingD> mcdlist=new ArrayList<MesCrSlittingD>();
	  			for(MesCrSlittingM mcsttlim:v_rec_baf_mList){
	  				List<MesCrSlittingD> lll = this.getMapper(MesCrSlittingDMapper.class).findWithCondition(null, "process_no='"+mcsttlim.getProcess_no()+"' and coil_no not like '%B'", null, 0, 0);
	  				for(MesCrSlittingD mccc:lll){
	  					mcdlist.add(mccc);	
	  				}
	  			}
	  			if(v_rec_baf_mList!=null && v_rec_baf_mList.size()>0 && mcdlist.size()>0){
	  						mc_list = groupBillingDataByExcpBatchCode(mcdlist,mesCrSlittingM.getSchedule_no());
	  						
	  			}
	  		}
	  		if(mc_list!=null && mc_list.size()>0){
				for(Map.Entry<String, List<MesCrSlittingD>> grouplist :mc_list.entrySet()){
					List<MesCrSlittingD> listCes = grouplist.getValue();
					for(MesCrSlittingD mcam:listCes){
							MesCrSlittingD mCrossleo = new MesCrSlittingD();
							mCrossleo.setCoil_no(mcam.getCoil_no());
							mCrossleo.setInspection_lot(mcam.getInspection_lot());
							this.getMapper(MesCrSlittingDMapper.class).update(mCrossleo);
						}
					}
			}		
		}catch(Exception e){
			e.printStackTrace();
		}		

		//循环分条子卷实绩（MES_CR_SLITTING_D，此时，子卷已完成匹配虚拟子卷号，需要重新获取子卷实绩集合
		MesCrSlittingD mc=new MesCrSlittingD();
		mc.setProcess_no(lmcsm.get(0).getProcess_no());
		List<MesCrSlittingD> lmcsq=this.getMapper(MesCrSlittingDMapper.class).find(mc, 0, 0);
		for(MesCrSlittingD mcsq:lmcsq){
			
			//20201215 毛重交货：交工过程中边丝重量=钢卷理重-所有分条小卷重量-头尾卷重量（如果有），
			//且边丝每卷最多只有一个，打印的重量为交工的重量(毛重)
			if ("B".equals(mcsq.getCoil_no().substring(mcsq.getCoil_no().length()-1))) {
				String condition = "contract_no||contract_line_seq||order_seq = '"+lmddq.get(0).getOrder_no()+"' "
						+ "and nvl(change_flag,'0') <> '1' and weight_type_no = '102302'";
				int soiCount = this.getMapper(SlmOrderInfoMapper.class).countWithCondition(null, condition);
				if (soiCount > 0) { //
					//投料重量
					Double sumWeight = this.getMapper(MesCrSlittingDMapper.class).doQuerySumWeight(mcsq.getProcess_no());
					BigDecimal b= new BigDecimal(mesCrSlittingM.getMtr_act_wgt() - sumWeight);  
					double weightB = b.setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
					mcsq.setCoil_act_wgt(weightB);
					mcsq.setUpdate_opr(userName);
					mcsq.setUpdate_time(now);
					mcsq.setMemo("12mm毛重边丝自动计算重量");
					this.getMapper(MesCrSlittingDMapper.class).update(mcsq);
				}
			}		
			
			//  2018-6-21 将下面注解的东西修改成上面的
			if (mcsq.getCoil_no() !=null && "B".equals(mcsq.getCoil_no().substring(mcsq.getCoil_no().length()-1))) {
				if (mcsq.getCoil_act_wgt()==null || mcsq.getCoil_act_wgt().intValue()<=0) {
					continue;
				}
			}
			if(mcsq.getCoil_act_wgt()==null || mcsq.getCoil_act_wgt().intValue()<=0){
				throw new Exception("子卷["+mcsq.getCoil_no()+"]实重异常！");
			}
			if(!"B".equals(mcsq.getCoil_no().substring(mcsq.getCoil_no().length()-1))){
				if(mcsq.getCoil_no_vt()==null||"".equals(mcsq.getCoil_no_vt())){
					MesCrSlittingD mcd=new MesCrSlittingD();
					mcd.setCoil_no(mcsq.getCoil_no());
					mcd.setUpdate_opr(userName);
					mcd.setUpdate_time(now);
					this.getMapper(MesCrSlittingDMapper.class).update(mcd);
				}
			}
			CommonPage<MesCrSlittingD> cp=new CommonPage<MesCrSlittingD>();
			MesCrSlittingD mcsd=new MesCrSlittingD();
			mcsd.setCoil_no(mcsq.getCoil_no());
			mcsd.setCoil_no_vt(mcsq.getCoil_no_vt());
			cp.setObject(mcsd);
			//调用物流模块（仓库管理）接口，逐一将分条子卷实绩各子卷，插入库存记录（待入库状态）；	
			try{
				String nextProcessCode = this.getBean(MesApiDesignInfoImpl.class).getNextProcessCode("1", pps.getObject_no_vt());
				nextP = nextProcessCode;
				if(nextProcessCode==null || "".equals(nextProcessCode)){
					cp.setMemo1("500203");//成品库					
					//生产订单统计 统计量并修改生产订单状态
				    try{
//				    	this.getBean(PlnProdorderStatisticServiceImpl.class).prod_Stats(mcsq.getCoil_no(),1,true);
				    }catch(Exception e){
				    	System.out.println("生产订单统计 统计量并修改生产订单状态出错");
				    	e.printStackTrace();
				    }					
				}else{
					cp.setMemo1("500202");//在制品库
				}
			}catch(Exception e){
				e.printStackTrace();
			}
			
			try{				
				//2019-02-21修改
				PlnMaterielDetail pmd_21=new PlnMaterielDetail();
				pmd_21.setObject_no_vt(pps.getObject_no_vt());
				List<PlnMaterielDetail> list_pmd = this.getMapper(PlnMaterielDetailMapper.class).find(pmd_21, 0, 0);
				boolean flag_Ct = false;
				if(list_pmd!=null && list_pmd.size()>0){
					flag_Ct=this.getBean(MesApiDesignInfoImpl.class).getContractType(list_pmd.get(0).getProd_order_no());
				}
				if(flag_Ct && !"B".equals(mcsq.getCoil_no().substring(mcsq.getCoil_no().length()-1))){
					cp.setMemo3("507101");//物料属性，优特钢带
				}
								
				ResultModel rmValid = this.getBean(LmsApiServiceImpl.class).doMesIn(cp);
				if(!"200".equals(rmValid.getState())){
					throw new Exception(rmValid.getMsgInfo());
				}
				
				// 写入库存表后去更新生产订单状态：20230909刘侣；
				YdmProductDetail ypdQ = this.getMapper(YdmProductDetailMapper.class).doFind(mcsq.getCoil_no(), null);
				if (ypdQ != null && "500203".equals(ypdQ.getStorageattr())) {
					this.getBean(PlnProdorderStatisticServiceImpl.class).prod_Stats(ypdQ.getCoilno(),1,true);
				}
				// end
				
				// 检验委托：如果是最后一道工序才需要送样，去做检验委托：
				// 待判信息发送：如果是最后一道工序（进成品库），那么就给isfinal ： 1， 否则就是：0；
				if (ypdQ != null && "500203".equals(ypdQ.getStorageattr())) {
					
					// 发送检验委托信息：20230909刘侣：最后一道工序才送样
					if (mcsq.getCoil_no() != null && ("B".equals(mcsq.getCoil_no().substring(mcsq.getCoil_no().length()-1))
							 || "H".equals(mcsq.getCoil_no().substring(mcsq.getCoil_no().length()-1)))) {
						
						this.getBean(SlmFundFirstDetailServiceImpl.class).sendToPD(mcsq.getCoil_no(), true, "1");
					} else {
						this.getBean(SlmFundFirstDetailServiceImpl.class).sendToPD(mcsq.getCoil_no(), false, "1");
					}
					
					// 只有以6开头的订单才去发送检验委托：
					if (ypdQ.getOrderno() != null) {
						ResultModel rmwt = this.getBean(SlmFundFirstDetailServiceImpl.class).sendToJYWT(mcsq.getCoil_no(), true);
  						if ("500".equals(rmwt.getState())) {
  							throw new Exception(rmwt.getMsgInfo());
  						}
					}
					
					// end
				} else {
					// 非最后一道：
					if (mcsq.getCoil_no() != null && ("B".equals(mcsq.getCoil_no().substring(mcsq.getCoil_no().length()-1))
							 || "H".equals(mcsq.getCoil_no().substring(mcsq.getCoil_no().length()-1)))) {
						
						this.getBean(SlmFundFirstDetailServiceImpl.class).sendToPD(mcsq.getCoil_no(), true, "0");
					} else {
						this.getBean(SlmFundFirstDetailServiceImpl.class).sendToPD(mcsq.getCoil_no(), false, "0");
					}
				}
				// end
				
			}catch(Exception ex){
				throw new Exception("物流入库接口出错!"+ ex.getMessage());
			}

			try{
				ResultModel rmxx = this.getBean(QmsApiServiceImpl.class).doQueryJudegeResult(mcsq.getCoil_no());
				if(rmxx!=null && rmxx.getData()!=null && (rmxx.getData() instanceof JudgeResult)){
					JudgeResult jr=(JudgeResult)rmxx.getData();
					YdmProductDetail ypd=new YdmProductDetail();
					ypd.setCoilno(mcsq.getCoil_no());
					boolean falgggg=false;
					if(jr.getMarginal_result()!=null){
						ypd.setMarginal_result(jr.getMarginal_result());
						falgggg=true;
					}
					if(jr.getMarginal_result_id()!=null){
						ypd.setMarginal_result_id(jr.getMarginal_result_id());
						falgggg=true;
					}
					if(jr.getMeasure_result()!=null){
						ypd.setMeasure_result(jr.getMeasure_result());
						falgggg=true;
					}
					if(jr.getMeasure_result_id()!=null){
						ypd.setMeasure_result_id(jr.getMeasure_result_id());
						falgggg=true;
					}
					if(jr.getSfd_is_lock()!=null){
						ypd.setSfd_is_lock(jr.getSfd_is_lock());
						falgggg=true;
					}
					if(jr.getSfe_is_lock()!=null){
						ypd.setSfe_is_lock(jr.getSfe_is_lock());
						falgggg=true;
					}
					if(jr.getSfu_is_lock()!=null){
						ypd.setSfu_is_lock(jr.getSfu_is_lock());
						falgggg=true;
					}
					if(jr.getSic_is_lock()!=null){
						ypd.setSic_is_lock(jr.getSic_is_lock());
						falgggg=true;
					}
					if(jr.getSizeResult()!=null){
						ypd.setSizeresult(jr.getSizeResult());
						falgggg=true;
					}
					if(jr.getUd_surface_result()!=null){
						ypd.setUd_surface_result(jr.getUd_surface_result());
						falgggg=true;
					}
					if(jr.getUd_surface_result_id()!=null){
						ypd.setUd_surface_result_id(jr.getUd_surface_result_id());
						falgggg=true;
					}
					if(jr.getUp_surface_result()!=null){
						ypd.setUp_surface_result(jr.getUp_surface_result());
						falgggg=true;
					}
					if(jr.getUp_surface_result_id()!=null){
						ypd.setUp_surface_result_id(jr.getUp_surface_result_id());
						falgggg=true;
					}
					if(jr.getUp_surface_flaw() != null) {
						ypd.setUp_surface_flaw(jr.getUp_surface_flaw());
						falgggg= true;
					}
					if(jr.getUd_surface_flaw() != null) {
						ypd.setUd_surface_flaw(jr.getUd_surface_flaw());
						falgggg= true;
					}
					if(jr.getMarginal_flaw()!= null) {
						ypd.setMarginal_flaw(jr.getMarginal_flaw());
						falgggg= true;
					}
					if(falgggg){
//						this.getMapper(YdmProductDetailMapper.class).update(ypd);
					}
				}
			}catch(Exception e){
				System.out.println("调用质量接口报错");
				e.printStackTrace();
			}
			
			try{
				//循环分条子卷实绩（MES_CR_SLITTING_D，此时，子卷已完成匹配虚拟子卷号，需要重新获取子卷实绩集合
				//如果此子卷的虚拟子卷号不为空（COIL_NO_VT，即满足切割计划）
				if(mcsq.getCoil_no_vt()!=null&&!"".equals(mcsq.getCoil_no_vt())){
					//则调用生产管理的【分条完成——虚拟子卷 挂料接口】
					PlnMaterielDetail pmdq=new PlnMaterielDetail();
					pmdq.setObject_no(mcsq.getCoil_no());
					pmdq.setObject_no_vt(mcsq.getCoil_no_vt());
					pmdq.setMaterial_no(pps.getMaterial_no());//投料卷号 material_no   由页面交工按钮传入
					pmdq.setSub_object_no(mcsq.getCoil_no());//目的是为了PrcMaterielRelation的sub_object_no(pmdq.getSub_object_no());
					// 传入操作时间 2018-06-19
					pmdq.setCreate_time(now);
					this.getBean(MesApiServiceImpl.class).LengthwiseFinsh_Relation(pmdq,dUpper,dLower);
				}else if (mcsq.getCoil_no() != null && ("B".equals(mcsq.getCoil_no().substring(mcsq.getCoil_no().length()-1))
	 					 || "H".equals(mcsq.getCoil_no().substring(mcsq.getCoil_no().length()-1))
	 					)){
					//则调用生产管理的【分条完成——实物 生成接口】 2018-06-22
					PrcMaterielRelation pmr=new PrcMaterielRelation();
					pmr.setObject_no(pps.getMaterial_no());//投料卷号 material_no   由页面交工按钮传入
					pmr.setSub_object_no(mcsq.getCoil_no());//MES_CR_SLITTING_D表的子卷号
					pmr.setRelation_seq(3);
					this.getBean(MesApiServiceImpl.class).LengthwiseFinsh_PrcMatRelAdd(pmr);//有insert插入prc_materiel_relation的操作
				}else{//如果此子卷的虚拟子卷号为空（COIL_NO_VT，即为非计划）				
					// --------------2018-06-22 改为调用分条完成——虚拟子卷 挂料接口非计划接口-------------------
					PlnMaterielDetail pmdq=new PlnMaterielDetail();
					pmdq.setObject_no(pps.getMaterial_no());
					pmdq.setMaterial_no(pps.getMaterial_no());//投料卷号 material_no   由页面交工按钮传入
					pmdq.setSub_object_no(mcsq.getCoil_no());//MES_CR_SLITTING_D表的子卷号
					// 传入操作时间 2018-06-22
					pmdq.setCreate_time(now);
					this.getBean(MesApiServiceImpl.class).LengthwiseFinsh_No_Plan(pmdq);//有insert插入PLN_MATERIEL_DETAIL的操作
					// --------------2018-06-22 改为调用分条完成——虚拟子卷 挂料接口非计划接口-------------------
				}
			}catch(Exception ex){
				throw new Exception("计划接口出错!"+ ex.getMessage());
			}
			//===============2019-03-12========质量检验委托开始=============================
		    if(mesCrSlittingM.getSchedule_no()!=null && !"".equals(mesCrSlittingM.getSchedule_no())){//作业计划号不为空
		    	try{
					QcmJhySampleFromPlan ajsfp=new QcmJhySampleFromPlan();
					PlnMaterielDetail pmdq=new PlnMaterielDetail();
					pmdq.setObject_no_vt(pps.getObject_no_vt());
					List<PlnMaterielDetail> lpmdq22=this.getMapper(PlnMaterielDetailMapper.class).find(pmdq, 0, 1);
					String prod_order_no=lpmdq22.get(0).getProd_order_no();
					List<PlnProdorder> lpp = this.getMapper(PlnProdorderMapper.class).findWithCondition(null, "prod_order_no='"+prod_order_no+"'", null, 0, 0);
					if(lpp!=null && lpp.size()>0){
						int judge_Contain_Qcm = this.getBean(MesApiDesignInfoImpl.class).Judge_Contain_Qcm(pps.getObject_no_vt(), "E");
						// 获取工艺路径包含成分或者材质类
						if(judge_Contain_Qcm!=-1){
							ajsfp.setPline_seq((long)judge_Contain_Qcm);
							ajsfp.setInspection_lot(mcsq.getInspection_lot());
							ajsfp.setBatch_no(mesCrSlittingM.getSchedule_no());//轧批号    炉次号
							//ajsfp.setContract_line_no(lpp.get(0).getContract_line_no());//合同行信息
							List<PlnProcessPlan> list_plnP = this.getMapper(PlnProcessPlanMapper.class).findWithCondition(null, "produce_no='"+lpp.get(0).getProduce_no()+"' and cut_order_no = 1", "", 0, 0);
							if(list_plnP!=null && list_plnP.size()>0){
								ajsfp.setContract_line_no(list_plnP.get(0).getPlan_no());//合同行信息  销售的订单的加工计划号
							}
							ajsfp.setDesign_key(lpp.get(0).getDesign_key());//design_key的集合   
							ajsfp.setJudge("0");//用于判断是改判还是原判 0：原判；1：改判  no
							ajsfp.setMaterial_no(mcsq.getCoil_no());//取样材料号   
							ajsfp.setMsc_pline(lpp.get(0).getMsc_pline());//全程产线号  制成号
							ajsfp.setOrder_no(lpp.get(0).getOrder_no());//销售订单号(合同号+订单行号，示例:YT-66G66001)
							ajsfp.setBoard_no(mesCrSlittingM.getMaterial_no());
							
							ComBaseMachine cbm = this.getMapper(ComBaseMachineMapper.class).findById(mesCrSlittingM.getMachine_code());
							ComBasePline cbp = this.getMapper(ComBasePlineMapper.class).findById(cbm.getPline_code());
							ajsfp.setPline_code(cbm.getPline_code());//产线代码
							ajsfp.setPline_name(cbp.getPline_name());// 产线名称
							//后期需要修改
							ajsfp.setProcess_code("E");//工序代码    com_base_process表
							ajsfp.setPsc(lpp.get(0).getPsc());//物料编码，
							List<QcmJhySampleFromPlan> lqsfp=new ArrayList<>();
							lqsfp.add(ajsfp);
							CommonPage<QcmJhySampleFromPlan>  cpqjsfp=new CommonPage<QcmJhySampleFromPlan>();
							cpqjsfp.setObjectList(lqsfp);
							ResultModel reModel = this.getBean(QcmJhySampleConsignDItemServiceImpl.class).AutoGenerationSampleInfo(cpqjsfp);
							if(reModel!=null){
								System.out.println(reModel.getState());
								System.out.println(reModel.getMsgInfo());
							}
						}
					}
				}catch(Exception e){
					e.printStackTrace();
				}
		    }
			//==========================质量检验委托结束==================================						
		}

		//如果分条产生了吊销的原料卷，则调用物流模块（仓库管理）接口，将新产生的吊销卷信息，插入库存记录（待入库状态，除卷号、理重、实重、长度外，其它相关信息可复制库存中原始原料卷相关信息）；																																							
		if("1".equals(lmcsm.get(0).getPartial_rejected())){
			YdmProductDetail ypd=new YdmProductDetail();
			ypd.setCoilno(lmcsm.get(0).getRejected_coil_no());
			ypd.setTheoryweight(lmcsm.get(0).getRejected_coil_thr_wgt());
			ypd.setFactweight(lmcsm.get(0).getRejected_coil_act_wgt());
			ypd.setLength(lmcsm.get(0).getRejected_coil_len());
			ypd.setDiameter_inn(lmcsm.get(0).getMtr_inn_dia());
			ypd.setDiameter_out(lmcsm.get(0).getMtr_out_dia());
			//2018-09-26 机台代码，机台名称
			ypd.setMachine_code(lmcsm.get(0).getMachine_code());
			List<ComBaseMachine> listcom=this.getMapper(ComBaseMachineMapper.class).findWithCondition(null, "machine_code='"+lmcsm.get(0).getMachine_code()+"'", null, 0, 0);
			if(listcom!=null && listcom.size()>0){
				ypd.setMachine_name(listcom.get(0).getMachine_name());
			}
			ResultModel rmValid = this.getBean(LmsApiServiceImpl.class).doInsertRevoke(pps.getMaterial_no(),ypd);
			if(!"200".equals(rmValid.getState())){
				throw new Exception(rmValid.getMsgInfo());
			}
		}
		
		PlnMaterielDetail pmdq=new PlnMaterielDetail();
		pmdq.setObject_no_vt(pps.getObject_no_vt());
		List<PlnMaterielDetail> lpmdq=this.getMapper(PlnMaterielDetailMapper.class).find(pmdq, 0, 1);
		try{
			this.getBean(MesApiServiceImpl.class).LengthwiseFinsh_Sum(lpmdq.get(0));
		}catch(Exception ex){
			throw new Exception("计划接口出错!"+ ex.getMessage());
		}
		

		//修改分条主实绩的交工状态为已交工状态
		MesCrSlittingM mcsmu=new MesCrSlittingM();
		mcsmu.setProcess_no(lmcsm.get(0).getProcess_no());
		mcsmu.setHand_over_status("1");
		mcsmu.setUpdate_opr(userName);
		mcsmu.setUpdate_time(now);
		mcsmu.setHand_over_opr(userName);
		mcsmu.setHand_over_time(now);
		
		//=========================================================
		//2018-12-11对大纵剪边丝的处理
		double mdcoil_sumwgt=0;//除边丝以外的子卷磅重之和
		if(lmcsm.get(0).getWire_wdt()!=null && lmcsm.get(0).getMtr_len()!=null){
			List<MesCrSlittingD> md_list = this.getMapper(MesCrSlittingDMapper.class).findWithCondition(null, "process_no='"+lmcsm.get(0).getProcess_no()+"'", null, 0, 0);
			if(md_list!=null && md_list.size()>0){
				for(MesCrSlittingD mcsd:md_list){
					if (mcsd.getCoil_no() !=null && "B".equals(mcsd.getCoil_no().substring(mcsd.getCoil_no().length()-1))) {
							continue;
					}
					if(mcsd.getCoil_act_wgt() == null){
						mdcoil_sumwgt=0;
						break;
					}
					mdcoil_sumwgt+= mcsd.getCoil_act_wgt() == null ? 0 : mcsd.getCoil_act_wgt();
				}
			}
			if(mdcoil_sumwgt>0){
				//边丝磅重                   主表的mtr_thr_wgt等于mtr_act_wgt
				mcsmu.setWire_act_wgt(DoubleUtil.round((lmcsm.get(0).getMtr_thr_wgt()==null?0:lmcsm.get(0).getMtr_thr_wgt())-mdcoil_sumwgt, 0));
				if(mcsmu.getWire_act_wgt()<0){
					mcsmu.setWire_act_wgt(0d);
				}
			}
			//计算边丝理重
			double dtemp=0;
			double wire_thr_wgt=0;
			if(lmcsm.get(0).getMtr_thk()!=null && lmcsm.get(0).getMtr_len()!=null){
				dtemp=7.85*(lmcsm.get(0).getMtr_thk())*(lmcsm.get(0).getWire_wdt()/1000)*(lmcsm.get(0).getMtr_len()/1000);
			}
			if(dtemp>0){
				wire_thr_wgt=DoubleUtil.round(dtemp, 0);
			}
			if(wire_thr_wgt>0){
				mcsmu.setWire_thr_wgt(wire_thr_wgt);
			}
		}
		//=============================================================	
		this.getMapper(MesCrSlittingMMapper.class).update(mcsmu);
		//日志
		for (MesCrSlittingD msd : lmcsd) {
			
			
			MesOprLog mol = new MesOprLog("车间MES", "12mm分条机作业管理", "交工", userName, opr_time, msd.getCoil_no(), null, null, null, "投料卷号："+pps.getMaterial_no() + "；下道工序为：" + nextP);
			this.getMapper(MesOprLogMapper.class).insert(mol);
		}
		rm.setState("200");
		return rm;
	}
	
	
	/**
	 * 取消交工
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doHandoverWorkCancelWeb(CommonPage<MesCrSlittingSum> oci) throws Exception{
		ResultModel rm=new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		PlnLengthwisePlanSum pps=oci.getObject().getSum();

		//验证选中的作业计划主表记录存在
		PlnLengthwisePlan pp=new PlnLengthwisePlan();
		pp.setMachine_code(pps.getMachine_code());
		pp.setLw_plan_no(pps.getLw_plan_no());
		int icount=this.getMapper(PlnLengthwisePlanMapper.class).count(pp);
		if(icount==0){
			rm.setState("500");
			rm.setMsgInfo("作业计划主表记录不存在");
			return rm;
		}

		//验证选中的作业计划明细表记录存在
		PlnLengthwisePlanDetail ppd = new PlnLengthwisePlanDetail();
		ppd.setMachine_code(pps.getMachine_code());
		ppd.setLw_plan_no(pps.getLw_plan_no());
		ppd.setObject_no_vt(pps.getObject_no_vt());
		ppd.setObject_no(pps.getMaterial_no());
		List<PlnLengthwisePlanDetail> lppd=this.getMapper(PlnLengthwisePlanDetailMapper.class).find(ppd, 0, 0);
		if(lppd==null || lppd.size()==0){
			rm.setState("500");
			rm.setMsgInfo("作业计划明细记录不存在");
			return rm;
		}

		//验证选中的作业计划对应的分条主实绩存在，且为未交工状态
		MesCrSlittingM mcsm=new MesCrSlittingM();
		mcsm.setMachine_code(pps.getMachine_code());
		mcsm.setSchedule_no(pps.getLw_plan_no());
		mcsm.setMaterial_no_vt(pps.getObject_no_vt());
		mcsm.setMaterial_no(pps.getMaterial_no());
		List<MesCrSlittingM> lmcsm=this.getMapper(MesCrSlittingMMapper.class).find(mcsm, 0, 0);
		if(lmcsm==null||lmcsm.size()==0){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条主实绩不存在！");
			return rm;
		}
		if(!"1".equals(lmcsm.get(0).getHand_over_status())
				&&lmcsm.get(0).getHand_over_status()!=null){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条还未生产交工！");
			return rm;
		}

		//验证作业计划原料卷存在子卷实绩
		MesCrSlittingD m=new MesCrSlittingD();
		m.setProcess_no(lmcsm.get(0).getProcess_no());
		List<MesCrSlittingD> lmcsd=this.getMapper(MesCrSlittingDMapper.class).find(m, 0, 0);
		if(lmcsd==null||lmcsd.size()==0){
			rm.setState("500");
			rm.setMsgInfo("作业计划原料卷不存在子卷实绩!");
			return rm;
		}
		for(MesCrSlittingD mcsq:lmcsd){
			try{
				// --------------------------------2018-06-22--------------------------------
				// 如果子卷是边丝或者虚拟物料号为空,则按非计划执行
				if (Utils.isNotEmpty(mcsq.getCoil_no())  && ("B".equals(mcsq.getCoil_no().substring(mcsq.getCoil_no().length()-1))
						|| "H".equals(mcsq.getCoil_no().substring(mcsq.getCoil_no().length()-1))
	  					)){
					if (Utils.isNotEmpty(mcsq.getCoil_act_wgt()) && mcsq.getCoil_act_wgt().intValue()>0) {
						//则调用生产管理的【分条完成——实物 生成接口】 2018-06-22
						PrcMaterielRelation pmr=new PrcMaterielRelation();
						pmr.setObject_no(pps.getMaterial_no());//投料卷号 material_no   由页面交工按钮传入
						pmr.setSub_object_no(mcsq.getCoil_no());//MES_CR_SLITTING_D表的子卷号
						this.getBean(MesApiServiceImpl.class).LengthwiseFinsh_PrcMatRelRemove(pmr);
					}
					//或者虚拟物料号为空,则按非计划执行
				}else if (Utils.isEmpty(mcsq.getCoil_no_vt())) {
					PrcMaterielRelation pmr=new PrcMaterielRelation();
					pmr.setObject_no(pps.getMaterial_no());//投料卷号 material_no   由页面交工按钮传入
					pmr.setSub_object_no(mcsq.getCoil_no());//MES_CR_SLITTING_D表的子卷号
					// 由于在交工的时候,生成对应的虚拟子卷信息取消的时候将其直接删除 2018-09-10
					PlnMaterielDetail pmddetele = new PlnMaterielDetail();
					pmddetele.setObject_no(mcsq.getCoil_no());
					pmddetele.setOrd_flg("2");
					this.getMapper(PlnMaterielDetailMapper.class).doDeleteByOrdflg(pmddetele);
					this.getBean(MesApiServiceImpl.class).LengthwiseFinsh_PrcMatRelRemove(pmr);
				}else {
					//则调用生产管理的【分条完成——虚拟子卷 挂料接口】按计划执行
					PlnMaterielDetail pmdq=new PlnMaterielDetail();
					pmdq.setObject_no(mcsq.getCoil_no());
					pmdq.setObject_no_vt(mcsq.getCoil_no_vt());
					this.getBean(MesApiServiceImpl.class).LengthwiseFinsh_RelationCancel(pmdq);
					
				}
			}catch(Exception ex){
				throw new Exception("计划接口出错!"+ ex.getMessage());
			}
			
			// --------------------------------2018-06-22--------------------------------			
			//清空所有子卷实绩的虚拟子卷号信息
			MesCrSlittingD mcsd=new MesCrSlittingD();
			mcsd.setUpdate_opr(userName);
			mcsd.setUpdate_time(new Date());
			mcsd.setCoil_no(mcsq.getCoil_no());
			this.getMapper(MesCrSlittingDMapper.class).doUpdate(mcsd);
									
			//===============2019-03-12========质量检验委托开始=============================
		    if(lmcsm.get(0).getSchedule_no()!=null && !"".equals(lmcsm.get(0).getSchedule_no())){//作业计划号不为空
		    	if (mcsq.getCoil_no() !=null && "B".equals(mcsq.getCoil_no().substring(mcsq.getCoil_no().length()-1))) {
					if (mcsq.getCoil_act_wgt()==null || mcsq.getCoil_act_wgt().intValue()<=0) {
						continue;
					}
				}
		    	try{
					QcmJhySampleFromPlan ajsfp=new QcmJhySampleFromPlan();
					PlnMaterielDetail pmdq=new PlnMaterielDetail();
					pmdq.setObject_no_vt(pps.getObject_no_vt());
					List<PlnMaterielDetail> lpmdq22=this.getMapper(PlnMaterielDetailMapper.class).find(pmdq, 0, 1);
					String prod_order_no=lpmdq22.get(0).getProd_order_no();
					List<PlnProdorder> lpp = this.getMapper(PlnProdorderMapper.class).findWithCondition(null, "prod_order_no='"+prod_order_no+"'", null, 0, 0);
					if(lpp!=null && lpp.size()>0){
						int judge_Contain_Qcm = this.getBean(MesApiDesignInfoImpl.class).Judge_Contain_Qcm(pps.getObject_no_vt(), "E");
						// 获取工艺路径包含成分或者材质类
						if(judge_Contain_Qcm!=-1){
							ajsfp.setPline_seq((long)judge_Contain_Qcm);
							ajsfp.setInspection_lot(mcsq.getInspection_lot());
							ajsfp.setBatch_no(lmcsm.get(0).getSchedule_no());//轧批号    炉次号
							//ajsfp.setContract_line_no(lpp.get(0).getContract_line_no());//合同行信息
							List<PlnProcessPlan> list_plnP = this.getMapper(PlnProcessPlanMapper.class).findWithCondition(null, "produce_no='"+lpp.get(0).getProduce_no()+"' and cut_order_no = 1", "", 0, 0);
							if(list_plnP!=null && list_plnP.size()>0){
								ajsfp.setContract_line_no(list_plnP.get(0).getPlan_no());//合同行信息  销售的订单的加工计划号
							}
							ajsfp.setDesign_key(lpp.get(0).getDesign_key());//design_key的集合   
							ajsfp.setJudge("0");//用于判断是改判还是原判 0：原判；1：改判  no
							ajsfp.setMaterial_no(mcsq.getCoil_no());//取样材料号   
							ajsfp.setMsc_pline(lpp.get(0).getMsc_pline());//全程产线号  制成号
							ajsfp.setOrder_no(lpp.get(0).getOrder_no());//销售订单号(合同号+订单行号，示例:YT-66G66001)
								
							ComBaseMachine cbm = this.getMapper(ComBaseMachineMapper.class).findById(lmcsm.get(0).getMachine_code());
							ComBasePline cbp = this.getMapper(ComBasePlineMapper.class).findById(cbm.getPline_code());
							ajsfp.setPline_code(cbm.getPline_code());//产线代码
							ajsfp.setPline_name(cbp.getPline_name());// 产线名称
							//后期需要修改
							ajsfp.setProcess_code("E");//工序代码    com_base_process表
							ajsfp.setPsc(lpp.get(0).getPsc());//物料编码，
							List<QcmJhySampleFromPlan> lqsfp=new ArrayList<>();
							lqsfp.add(ajsfp);
							CommonPage<QcmJhySampleFromPlan>  cpqjsfp=new CommonPage<QcmJhySampleFromPlan>();
							cpqjsfp.setObjectList(lqsfp);
							QcmJhySampleFromPlan qjsprem=new QcmJhySampleFromPlan();
							qjsprem.setDesign_key(lpp.get(0).getDesign_key());
							qjsprem.setInspection_lot(mcsq.getInspection_lot());
							CommonPage<QcmJhySampleFromPlan> sum22=new CommonPage<QcmJhySampleFromPlan>();
							sum22.setObject(qjsprem);
							this.getBean(QmsApiServiceImpl.class).removeInspection(sum22);
						}
					}
				}catch(Exception e){
					e.printStackTrace();
				}
		    }
			//==========================质量检验委托结束==================================
		    String nextProcessCode = this.getBean(MesApiDesignInfoImpl.class).getNextProcessCode("1", pps.getObject_no_vt());
			if(nextProcessCode==null || "".equals(nextProcessCode) || 
					(mcsq.getCoil_no() !=null && "B".equals(mcsq.getCoil_no().substring(mcsq.getCoil_no().length()-1)))){
				 //生产订单统计 统计量并修改生产订单状态
			    try{
//			    	this.getBean(PlnProdorderStatisticServiceImpl.class).prod_Stats(mcsq.getCoil_no(),1,false);
			    }catch(Exception e){
			    	System.out.println("生产订单统计 统计量并修改生产订单状态出错");
			    	e.printStackTrace();
			    }
			}			
		}

		for(MesCrSlittingD mcsd:lmcsd){
			// 排除实重<=0的边丝
			if (mcsd.getCoil_no() != null && "B".equals(mcsd.getCoil_no().substring(mcsd.getCoil_no().length()-1))){
				if (mcsd.getCoil_act_wgt()==null || mcsd.getCoil_act_wgt().intValue()<=0) {
					continue;
				}
			}
			//调用物流模块（仓库管理）接口，逐一验证各子卷都为待入库状态
			YdmProductDetail ypd=new YdmProductDetail();
			ypd.setCoilno(mcsd.getCoil_no());
			ypd.setState("-1");
			List<YdmProductDetail> lypd=this.getMapper(YdmProductDetailMapper.class).find(ypd, 0, 0);
			if(lypd==null||lypd.size()==0){
				throw new Exception("子卷["+mcsd.getCoil_no()+"]不为待入库状态");
			}else{
				
				// 写入库存表后去更新生产订单状态：20230909刘侣；
				YdmProductDetail ypdQ = this.getMapper(YdmProductDetailMapper.class).doFind(mcsd.getCoil_no(), null);
				if (ypdQ != null && "500203".equals(ypdQ.getStorageattr())) {
					this.getBean(PlnProdorderStatisticServiceImpl.class).prod_Stats(ypdQ.getCoilno(),1,false);
				}
				// end
				
				//开始事务
				//调用物流模块（仓库管理）接口，逐一删除分条子卷库存实绩；
				CommonPage<YdmProductDetail> cp=new CommonPage<YdmProductDetail>();
				YdmProductDetail ypdu=new YdmProductDetail();
				ypdu.setCoilno(mcsd.getCoil_no());
				cp.setObject(ypd);
				ResultModel rmValid = this.getBean(LmsApiServiceImpl.class).doDeleteFinishedRoll(cp);
				if(!"200".equals(rmValid.getState())){
					throw new Exception(rmValid.getMsgInfo());
				}
			}
		}

		//如果分条主实绩中，存在部分原料卷吊销信息
		if(lmcsm.get(0).getRejected_coil_no()!=null&&!"".equals(lmcsm.get(0).getRejected_coil_no())){
			//调用物流模块（仓库管理）接口，验证产生的吊销卷号为待入库状况
			//调用物流模块（仓库管理）接口，逐一验证各子卷都为待入库状态
			YdmProductDetail ypd=new YdmProductDetail();
			ypd.setCoilno(lmcsm.get(0).getRejected_coil_no());
			ypd.setState("0");
			List<YdmProductDetail> lypd=this.getMapper(YdmProductDetailMapper.class).find(ypd, 0, 0);
			if(lypd==null||lypd.size()==0){
				throw new Exception("吊销卷["+lmcsm.get(0).getRejected_coil_no()+"]不为待入库状态");
			}else{
				//开始事务
				//如果分条产生了吊销的原料卷，调用物流模块（仓库管理）接口，吊销卷撤销库存实绩
				ResultModel rmValid = this.getBean(LmsApiServiceImpl.class).doInsertRevokeCanl(lmcsm.get(0).getRejected_coil_no());
				if(!"200".equals(rmValid.getState())){
					throw new Exception(rmValid.getMsgInfo());
				}
			}
		}

		PlnMaterielDetail pmdq=new PlnMaterielDetail();
		pmdq.setObject_no_vt(pps.getObject_no_vt());
		List<PlnMaterielDetail> lpmdq=this.getMapper(PlnMaterielDetailMapper.class).find(pmdq, 0, 1);
		try{
			this.getBean(MesApiServiceImpl.class).LengthwiseFinsh_SumCancel(lpmdq.get(0));
		}catch(Exception ex){
			throw new Exception("计划接口出错!"+ ex.getMessage());
		}
		
		//修改分条主实绩的交工状态为已交工状态
		MesCrSlittingM mcsmu=new MesCrSlittingM();
		mcsmu.setProcess_no(lmcsm.get(0).getProcess_no());
		mcsmu.setHand_over_status("0");
		mcsmu.setUpdate_opr(userName);
		mcsmu.setUpdate_time(new Date());
		this.getMapper(MesCrSlittingMMapper.class).doUpdateNull(mcsmu);
		//日志
		MesOprLog mol = new MesOprLog("车间MES", pps.getMachine_name()+"作业管理", "取消交工", userName, opr_time, pps.getMaterial_no(), null, null, null, "投料卷号："+pps.getMaterial_no()+pps.getMachine_code());
		this.getMapper(MesOprLogMapper.class).insert(mol);
		
		rm.setState("200");
		return rm;
	}



	/**
	 * 打印标签
	 * @throws Exception 
	 * */
	public ResultModel doPrint(CommonPage<MesCrSlittingD> oci){
		ResultModel rm=new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		List<MesCrSlittingD> msdList = oci.getObjectList();
		try{
			List<MesCrSlittingD> lmcsd=new ArrayList<MesCrSlittingD>();
			for(MesCrSlittingD mcsd : msdList){
				MesCrSlittingD mcsdc=this.getMapper(MesCrSlittingDMapper.class).findById(mcsd.getCoil_no());
				if(mcsdc==null||mcsdc.getCoil_no()==null){
					rm.setState("500");
					rm.setMsgInfo("未找到卷["+mcsd.getCoil_no()+"]");
					return rm;
				}
				if(mcsdc.getCoil_act_wgt()==null||mcsdc.getCoil_act_wgt()<=0){
					rm.setState("500");
					rm.setMsgInfo("卷["+mcsd.getCoil_no()+"]必须要称重后，才能打印标牌");
					return rm;
				}
				//班组
				String wrk_grp=null;
				//班次
				String wrk_ord=null;
				if(mcsdc.getProcess_no()!=null){
					MesCrSlittingM mcs = this.getMapper(MesCrSlittingMMapper.class).findById(mcsdc.getProcess_no());
					MesShiftM msm=new MesShiftM();
					if(mcs.getWrk_date()!=null && mcs.getWrk_ord()!=null){
						msm.setWrk_date(mcs.getWrk_date());
						msm.setWrk_ord(mcs.getWrk_ord());
						msm.setMachine_code(mcs.getMachine_code());
						List<MesShiftM> lmsm = this.getMapper(MesShiftMMapper.class).findWithCondition(msm, null, "", 0, 0);
						if(lmsm!=null && lmsm.size()>0){
							wrk_grp=lmsm.get(0).getWrk_grp();
							wrk_ord=lmsm.get(0).getWrk_ord();
						}else{
							wrk_grp=mcs.getWrk_grp();
							wrk_ord=mcs.getWrk_ord();
						}
					}else{
						wrk_grp=mcs.getWrk_grp();
						wrk_ord=mcs.getWrk_ord();
					}
				}				

				PlnProdorder pp=new PlnProdorder();
				pp.setProd_order_no(mcsdc.getProd_order_no());
				List<PlnProdorder> lpp=this.getMapper(PlnProdorderMapper.class).doQueryPrint(pp);
				if(lpp!=null&&lpp.size()>0){
					mcsdc.setProd_name(lpp.get(0).getProd_name()+"（"+lpp.get(0).getCustomer_name()+"）");
					mcsdc.setStd_name(lpp.get(0).getStd_name());
				}else{
					mcsdc.setProd_name("");
					mcsdc.setStd_name("");
				}
				
				//20201218 易XP：毛重交货的边丝，标签打印时，重量为null
				if ("B".equals(mcsdc.getCoil_no().substring(mcsdc.getCoil_no().length()-1))) {
					String condition = "contract_no||contract_line_seq||order_seq = '"+mcsdc.getOrder_no()+"' "
							+ "and nvl(change_flag,'0') <> '1' and weight_type_no = '102302'";
					int soiCount = this.getMapper(SlmOrderInfoMapper.class).countWithCondition(null, condition);
					if (soiCount > 0) {
						mcsdc.setCoil_act_wgt(null);
						mcsdc.setCoil_thr_wgt(null);
					}
				}
							
				DecimalFormat df = new DecimalFormat("######0.00"); 
				ComBaseSteel cbs=this.getMapper(ComBaseSteelMapper.class).findById(mcsdc.getSteel_code());
				if(lpp!=null&&lpp.size()>0){
					mcsdc.setSteel_code(lpp.get(0).getSteel_name() == null ? cbs.getSteel_name() : lpp.get(0).getSteel_name());
				} else {
					mcsdc.setSteel_code(cbs.getSteel_name());
				}
				
				if(mcsd.getCoil_no() != null &&  !"B".equals(mcsd.getCoil_no().substring(mcsd.getCoil_no().length() - 1))){
					if(mcsdc.getAim_thk()!=null){
						// 统一使用卷实际规格：20240212 刘侣
						// 以前的，先注释掉：可能是厚度不符合 但是需要发运，恢复回来
						mcsdc.setSpec(df.format(mcsdc.getAim_thk())+"*"+mcsdc.getAct_wdt());//取子卷目标厚度（计划厚度）
						// 现在的：
//						mcsdc.setSpec(df.format(mcsdc.getAct_thk())+"*"+mcsdc.getAct_wdt());
						// end
					}else{
						mcsdc.setSpec(df.format(mcsdc.getAct_thk())+"*"+mcsdc.getAct_wdt());
					}					
				}
				String twoCode="CoilNo:"+mcsdc.getCoil_no();
				twoCode+=" Dimension:"+mcsdc.getSpec();
				twoCode+=" SteelGrade:"+mcsdc.getSteel_code();
				twoCode+=" Date:"+mcsdc.getWrk_date();
				twoCode+=" Weight:"+(mcsdc.getCoil_act_wgt()==null?"":mcsdc.getCoil_act_wgt().intValue());
				mcsdc.setTwoCode(twoCode);
				//----2018-03-27增加原料卷号---------
				mcsdc.setMemo(this.getMapper(MesCrSlittingDMapper.class).doMaterailcoilno(mcsd));//原料卷号
				//---------2018-05-02增加班次，班组------------------
				mcsdc.setWrk_grp(wrk_grp);
				mcsdc.setWrk_ord(wrk_ord);
				//---------2019-03-11增加炉号
				mcsdc.setHeatno(this.getMapper(MesCrSlittingDMapper.class).doHeatNo(mcsd));
				
				lmcsd.add(mcsdc);
			}
			// 保存打印记录
			for(MesCrSlittingD d:lmcsd){
				MesTpmPrintLog log=new MesTpmPrintLog();
				BeanUtils.copyProperties(d, log);
				log.setId(UUID.randomUUID().toString());
				String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
				log.setPrintname(userName);
				SimpleDateFormat dfm=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				log.setPrinttime(dfm.format(new Date()));
				this.getMapper(MesTpmPrintLogMapper.class).insert(log);
				
				//日志
				MesOprLog mol = new MesOprLog("车间MES", "作业管理", "打印标签预览", username, opr_time, d.getCoil_no(), null, null, null, null);
				this.getMapper(MesOprLogMapper.class).insert(mol);
			}
			rm.setState("200");
			rm.setData(lmcsd);
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("打印失败："+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 重量分配
	 * @param memo1 重量
	 * @param memo2 重量来源 （1：采集、2：人工）
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doWeightDistribution1(CommonPage<PlnLengthwisePlanDetailAndMesCrSlittingD> oci) throws Exception{
		ResultModel rm=new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		//验证选中的作业计划主表记录存在
		PlnLengthwisePlan plp=new PlnLengthwisePlan();
		plp.setMachine_code(oci.getObject().getMain().getMachine_code());
		plp.setLw_plan_no(oci.getObject().getMain().getLw_plan_no());
		List<PlnLengthwisePlan> lplp=this.getMapper(PlnLengthwisePlanMapper.class).find(plp, 0, 0);
		if(lplp==null||lplp.size()==0){
			rm.setState("500");
			rm.setMsgInfo("选中的作业计划记录不存在");
			return rm;
		}
		//验证选中的作业计划明细表记录存在
		PlnLengthwisePlanDetail plpd=new PlnLengthwisePlanDetail();
		plpd.setMachine_code(oci.getObject().getMain().getMachine_code());
		plpd.setLw_plan_no(oci.getObject().getMain().getLw_plan_no());
		plpd.setObject_no_vt(oci.getObject().getMain().getObject_no_vt());
		plpd.setObject_no(oci.getObject().getMain().getObject_no());
		List<PlnLengthwisePlanDetail> lplpd=this.getMapper(PlnLengthwisePlanDetailMapper.class).find(plpd, 0, 0);
		if(lplpd==null||lplpd.size()==0){
			rm.setState("500");
			rm.setMsgInfo("选中的作业计划明细记录不存在");
			return rm;
		}

		//验证选中的作业计划对应的分条主实绩存在
		MesCrSlittingM mcsm=new MesCrSlittingM();
		mcsm.setMachine_code(oci.getObject().getMain().getMachine_code());
		mcsm.setSchedule_no(oci.getObject().getMain().getLw_plan_no());
		mcsm.setMaterial_no_vt(oci.getObject().getMain().getObject_no_vt());
		mcsm.setMaterial_no(oci.getObject().getMain().getObject_no());

		List<MesCrSlittingM> lmcsm=this.getMapper(MesCrSlittingMMapper.class).find(mcsm, 0, 0);
		if(lmcsm==null||lmcsm.size()==0){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no_vt()+"]分条主实绩不存在！");
			return rm;
		}
		if(!"0".equals(lmcsm.get(0).getHand_over_status())
				&&lmcsm.get(0).getHand_over_status()!=null){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no_vt()+"]分条已生产交工！");
			return rm;
		}
		//验证作业计划原料卷存在子卷实绩
		MesCrSlittingD m=new MesCrSlittingD();
		m.setProcess_no(lmcsm.get(0).getProcess_no());
		List<MesCrSlittingD> lmcsdxxx=this.getMapper(MesCrSlittingDMapper.class).findWithCondition(m, "coil_no not like '%B'", " coil_no ", 0, 0);
		if(lmcsdxxx==null||lmcsdxxx.size()==0){
			rm.setState("500");
			rm.setMsgInfo("作业计划原料卷不存在子卷实绩!");
			return rm;
		}
		
		
		// 获取子卷信息排除边丝 ----------2018-06-29--------------
		ArrayList<MesCrSlittingD> childNoBs = new ArrayList<MesCrSlittingD>();
		if(lmcsm.get(0).getProcess_no()!=null){
			MesCrSlittingD  mcsd=new MesCrSlittingD();
			mcsd.setProcess_no(lmcsm.get(0).getProcess_no());
			List<MesCrSlittingD> lmcsd = this.getMapper(MesCrSlittingDMapper.class).find(mcsd, 0, 0);
			for (MesCrSlittingD child : lmcsd) {
				// 不包括边丝
				if (child.getCoil_no() != null && "B".equals(child.getCoil_no().substring(child.getCoil_no().length()-1))
						|| ( child.getCoil_no() != null && "H".equals(child.getCoil_no().substring(child.getCoil_no().length()-1)))
						) {
					continue;
				}
				String xhstr = child.getCoil_no().substring(child.getCoil_no().length()-2);
				child.setXh(Integer.parseInt(xhstr));
				childNoBs.add(child);
			}
		}
		
		//总重量
	    double sumWeight=Double.parseDouble(oci.getMemo1());
	    
	    int icount=0;
		String dt=new SimpleDateFormat("yyMMdd").format(new Date());
		List<MesCrSlittingWgt> lmcw=this.getMapper(MesCrSlittingWgtMapper.class).findWithCondition(null, " substr(serial_no,1,6)='"+dt+"'", " serial_no desc", 0, 1);
		if(lmcw==null||lmcw.size()==0){
			icount=1;
		}else{
			icount=Integer.parseInt(lmcw.get(0).getSerial_no().substring(6,11))+1;
		}

		String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		if(userName==null){
			userName="";
		}
		//开始事务：

		//创建分条子卷线上称重实绩记录，即将前端传入的重量信息插入一条记录到MES_CR_SLITTING_WGT表中
		MesCrSlittingWgt mcsw=new MesCrSlittingWgt();
		mcsw.setSerial_no(dt+String.format("%05d", icount++));
		mcsw.setDivide_flag("1");
		mcsw.setDivide_opr(userName);
		mcsw.setDivide_time(new Date());
		mcsw.setProcess_no(lmcsm.get(0).getProcess_no());
		mcsw.setWgt_source(oci.getMemo2());
		mcsw.setWgt_time(new Date());
		mcsw.setWgt_value(Double.parseDouble(oci.getMemo1()));
		this.getMapper(MesCrSlittingWgtMapper.class).insert(mcsw);
	    
		//横切方式x1
		String x1=lmcsm.get(0).getCrs_cut_mode();
		if(x1==null || "".equals(x1)){
			//横切方式（CRS_CUT_MODE）：通过生产订单号为条件，关联 pln_process_plan 表获取 CROSSCUT_STYLE 字段，详细截图；
			List<PlnProcessPlan> lppp=this.getMapper(PlnLengthwisePlanDetailMapper.class).doQueryCrs(oci.getObject().getMain().getObject_no_vt());
			if(lppp!=null && lppp.size()>0){
				x1 = lppp.get(0).getCrosscut_style();
			}
		}
		//不横切。
		if("1".equals(x1)){
			//sumPwidth+=Double.parseDouble(pmd.getWidth());
		}else if("2".equals(x1)){
			//一切二。
			if(childNoBs.size()%2!=0){
				double v_sum=0;//理重计算值
				for(MesCrSlittingD mexsd :childNoBs){
					v_sum+=(mexsd.getAct_wdt()==null?0:mexsd.getAct_wdt())*(mexsd.getAct_thk()==null?0:mexsd.getAct_thk());
				}
				MesUtil.sortIntMethod(childNoBs);
				int i=1;
				double lastWgt=0;
				for(MesCrSlittingD mexsd :childNoBs){
					// （10.1'）、前N-1个出口卷理重 = 原卷理重 * （宽度*长度*厚度）/ ∑（宽度*长度*厚度）
					//四舍五入
				   BigDecimal b=null;
				   double f1=0;
				   if(i<childNoBs.size()){
					   b= new BigDecimal(sumWeight*mexsd.getAct_wdt()*mexsd.getAct_thk()/v_sum);  
					   f1 = b.setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
					   lastWgt+=f1;
				   }else if(i==childNoBs.size()){
					   b= new BigDecimal(sumWeight-lastWgt);  
					   f1 = b.setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
				   }
				   MesCrSlittingD mccccd=new MesCrSlittingD();
				   mccccd.setCoil_no(mexsd.getCoil_no());
				   mccccd.setCoil_thr_wgt(f1);
				   this.getMapper(MesCrSlittingDMapper.class).update(mccccd);
				   i++;
				}
				rm.setState("200");
				return rm;
				
			}
		}else if("3".equals(x1)){
			//一切三。
			if(childNoBs.size()%3!=0){
				double v_sum=0;//理重计算值
				for(MesCrSlittingD mexsd :childNoBs){
					v_sum+=(mexsd.getAct_wdt()==null?0:mexsd.getAct_wdt())*(mexsd.getAct_thk()==null?0:mexsd.getAct_thk());
				}
				MesUtil.sortIntMethod(childNoBs);
				int i=1;
				double lastWgt=0;
				for(MesCrSlittingD mexsd :childNoBs){
					// （10.1'）、前N-1个出口卷理重 = 原卷理重 * （宽度*长度*厚度）/ ∑（宽度*长度*厚度）
					//四舍五入
				   BigDecimal b=null;
				   double f1=0;
				   if(i<childNoBs.size()){
					   b= new BigDecimal(sumWeight*mexsd.getAct_wdt()*mexsd.getAct_thk()/v_sum);  
					   f1 = b.setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
					   lastWgt+=f1;
				   }else if(i==childNoBs.size()){
					   b= new BigDecimal(sumWeight-lastWgt);  
					   f1 = b.setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
				   }
				   MesCrSlittingD mccccd=new MesCrSlittingD();
				   mccccd.setCoil_no(mexsd.getCoil_no());
				   mccccd.setCoil_thr_wgt(f1);
				   this.getMapper(MesCrSlittingDMapper.class).update(mccccd);
				   i++;
				}
				rm.setState("200");
				return rm;
				
			}
		}else if("4".equals(x1)){
			//一切四。
			if(childNoBs.size()%4!=0){
				double v_sum=0;//理重计算值
				for(MesCrSlittingD mexsd :childNoBs){
					v_sum+=(mexsd.getAct_wdt()==null?0:mexsd.getAct_wdt())*(mexsd.getAct_thk()==null?0:mexsd.getAct_thk());
				}
				MesUtil.sortIntMethod(childNoBs);
				int i=1;
				double lastWgt=0;
				for(MesCrSlittingD mexsd :childNoBs){
					// （10.1'）、前N-1个出口卷理重 = 原卷理重 * （宽度*长度*厚度）/ ∑（宽度*长度*厚度）
					//四舍五入
				   BigDecimal b=null;
				   double f1=0;
				   if(i<childNoBs.size()){
					   b= new BigDecimal(sumWeight*mexsd.getAct_wdt()*mexsd.getAct_thk()/v_sum);  
					   f1 = b.setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
					   lastWgt+=f1;
				   }else if(i==childNoBs.size()){
					   b= new BigDecimal(sumWeight-lastWgt);  
					   f1 = b.setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
				   }
				   MesCrSlittingD mccccd=new MesCrSlittingD();
				   mccccd.setCoil_no(mexsd.getCoil_no());
				   mccccd.setCoil_thr_wgt(f1);
				   this.getMapper(MesCrSlittingDMapper.class).update(mccccd);
				   i++;
				}
				rm.setState("200");
				return rm;
				
			}
		}else if("5".equals(x1)){
			//一切五。
			if(childNoBs.size()%5!=0){		
				double v_sum=0;//理重计算值
				for(MesCrSlittingD mexsd :childNoBs){
					v_sum+=(mexsd.getAct_wdt()==null?0:mexsd.getAct_wdt())*(mexsd.getAct_thk()==null?0:mexsd.getAct_thk());
				}
				MesUtil.sortIntMethod(childNoBs);
				int i=1;
				double lastWgt=0;
				for(MesCrSlittingD mexsd :childNoBs){
					// （10.1'）、前N-1个出口卷理重 = 原卷理重 * （宽度*长度*厚度）/ ∑（宽度*长度*厚度）
					//四舍五入
				   BigDecimal b=null;
				   double f1=0;
				   if(i<childNoBs.size()){
					   b= new BigDecimal(sumWeight*mexsd.getAct_wdt()*mexsd.getAct_thk()/v_sum);  
					   f1 = b.setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
					   lastWgt+=f1;
				   }else if(i==childNoBs.size()){
					   b= new BigDecimal(sumWeight-lastWgt);  
					   f1 = b.setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
				   }
				   MesCrSlittingD mccccd=new MesCrSlittingD();
				   mccccd.setCoil_no(mexsd.getCoil_no());
				   mccccd.setCoil_thr_wgt(f1);
				   this.getMapper(MesCrSlittingDMapper.class).update(mccccd);
				   i++;
				}
				rm.setState("200");
				return rm;
				
			}
		}
		
		//总宽度值
		double sumWidth=0d;
		String process_no=null;
		//验证作业计划原料卷当前勾选选中的子卷实绩都存在
		for(MesCrSlittingD mcsd:childNoBs){
			
			//只有一条
			MesCrSlittingD mcsdq=this.getMapper(MesCrSlittingDMapper.class).findById(mcsd.getCoil_no());
			if(mcsdq==null||mcsdq.getCoil_no()==null){
				rm.setState("500");
				rm.setMsgInfo("当前勾选选中的子卷["+mcsd.getCoil_no()+"]实绩不存在");
				return rm;
			}
			if(mcsdq.getAct_wdt()==null){
				mcsdq.setAct_wdt(0d);
			}
			//sumWidth:总宽度值
			sumWidth+=mcsdq.getAct_wdt();
			mcsd.setAct_wdt(mcsdq.getAct_wdt());
			process_no=mcsdq.getProcess_no();
		}

		MesCrSlittingM mesc=new MesCrSlittingM();
		mesc.setProcess_no(process_no);
		MesCrSlittingM ms3 = this.getMapper(MesCrSlittingMMapper.class).findById(mesc.getProcess_no());
		MesCrSlittingD mcsdqq=new MesCrSlittingD();
		mcsdqq.setProcess_no(process_no);
		//查询所有子卷实绩
		List<MesCrSlittingD> lmcsdq = this.getMapper(MesCrSlittingDMapper.class).findWithCondition(mcsdqq, " and substr(coil_no, -1) <> 'B' and substr(coil_no, -1) <> 'H' ", null, 0, 0);
		if(oci.getObject().getMain().getCrs_cut_len1()==null){
			oci.getObject().getMain().setCrs_cut_len1(0d);
		}
		if(oci.getObject().getMain().getCrs_cut_len2()==null){
			oci.getObject().getMain().setCrs_cut_len2(0d);
		}
		if(oci.getObject().getMain().getCrs_cut_len3()==null){
			oci.getObject().getMain().setCrs_cut_len3(0d);
		}
		if(oci.getObject().getMain().getCrs_cut_len4()==null){
			oci.getObject().getMain().setCrs_cut_len4(0d);
		}
		if(oci.getObject().getMain().getCrs_cut_len5()==null){
			oci.getObject().getMain().setCrs_cut_len5(0d);
		}
		double lastWgt=0;

		if((!"1".equals(x1)) && (!"2".equals(x1)) && (!"3".equals(x1)) && (!"4".equals(x1)) && (!"5".equals(x1))){
			rm.setState("500");
			rm.setMsgInfo("横切方式不存在!");
			//return rm;
			throw new Exception("横切方式不存在!");
		}
		if(("2".equals(x1)) &&  
				(oci.getObject().getMain().getCrs_cut_len1()<=0 || oci.getObject().getMain().getCrs_cut_len2()<=0 ) ){
			rm.setState("500");
			rm.setMsgInfo("一切二方式中，两次的长度比例不全!");
			//return rm;
			throw new Exception("一切二方式中，两次的长度比例不全!");
		}
		if("2".equals(x1)){
			double len12=oci.getObject().getMain().getCrs_cut_len1()+oci.getObject().getMain().getCrs_cut_len2();
			if(len12!=100){//100.0==100
				rm.setState("500");
				rm.setMsgInfo("一切二方式中，两次的长度比例不正确");
				//return rm;
				throw new Exception("一切二方式中，两次的长度比例不正确");
			}
		}
		if(("3".equals(x1)) &&  
				(oci.getObject().getMain().getCrs_cut_len1()<=0 || oci.getObject().getMain().getCrs_cut_len2()<=0  
				|| oci.getObject().getMain().getCrs_cut_len3()<=0 )){
			rm.setState("500");
			rm.setMsgInfo("一切三方式中，三次的长度比例不全!");
			throw new Exception("一切三方式中，三次的长度比例不全!");
		}
		if("3".equals(x1)){
			double len123=oci.getObject().getMain().getCrs_cut_len1()+oci.getObject().getMain().getCrs_cut_len2()+
					oci.getObject().getMain().getCrs_cut_len3();
			if(len123!=100){
				rm.setState("500");
				rm.setMsgInfo("一切三方式中，三次的长度比例不正确");
				throw new Exception("一切三方式中，三次的长度比例不正确");
			}
		}
		if(("4".equals(x1)) &&  
				(oci.getObject().getMain().getCrs_cut_len1()<=0 || oci.getObject().getMain().getCrs_cut_len2()<=0  
				|| oci.getObject().getMain().getCrs_cut_len3()<=0 || oci.getObject().getMain().getCrs_cut_len4()<=0)){
			rm.setState("500");
			rm.setMsgInfo("一切四方式中，四次的长度比例不全!");
			throw new Exception("一切四方式中，四次的长度比例不全!");
		}
		if("4".equals(x1)){
			double len1234=oci.getObject().getMain().getCrs_cut_len1()+oci.getObject().getMain().getCrs_cut_len2()+
					oci.getObject().getMain().getCrs_cut_len3()+oci.getObject().getMain().getCrs_cut_len4();
			if(len1234!=100){
				rm.setState("500");
				rm.setMsgInfo("一切四方式中，四次的长度比例不正确");
				throw new Exception("一切四方式中，四次的长度比例不正确");
			}
		}
		if("5".equals(x1)){
			double len12345=oci.getObject().getMain().getCrs_cut_len1()+oci.getObject().getMain().getCrs_cut_len2()+
					oci.getObject().getMain().getCrs_cut_len3()+oci.getObject().getMain().getCrs_cut_len4()+
					oci.getObject().getMain().getCrs_cut_len5();
			if(len12345!=100){
				rm.setState("500");
				rm.setMsgInfo("一切五方式中，五次的长度比例不正确");
				throw new Exception("一切五方式中，五次的长度比例不正确");
			}
		}
		
		MesUtil.sortIntMethod(childNoBs);  
		int i=1;
		double cut2_1=0;
		double cut2_2=0;
		double cut3_1=0;
		double cut3_2=0;
		double cut3_3=0;
		double cut4_1=0;
		double cut4_2=0;
		double cut4_3=0;
		double cut4_4=0;
		double cut5_1=0;
		double cut5_2=0;
		double cut5_3=0;
		double cut5_4=0;
		double cut5_5=0;
		
		
		//取各部分宽度之和
		for(MesCrSlittingD pmd:childNoBs){
			if(pmd.getAct_wdt()==null){
				pmd.setAct_wdt(0d);
			}
			//不横切。获取分条计划中所有宽度
			if("1".equals(x1)){
				
			}else if("2".equals(x1)){
				//一切二。 cut2_1:获取分条计划中前一半宽度    cut2_2:获取分条计划中后一半宽度 
				if(pmd.getXh()<=childNoBs.size()/2){
					cut2_1+=pmd.getAct_wdt();
				}else{
					cut2_2+=pmd.getAct_wdt();
				}
			}else if("3".equals(x1)){
				//一切三。获取分条计划中前三分之一宽度
				if(pmd.getXh()<=childNoBs.size()/3){
					cut3_1+=pmd.getAct_wdt();
				}else if(pmd.getXh()<=childNoBs.size()/3*2){
					cut3_2+=pmd.getAct_wdt();
				}else{
					cut3_3+=pmd.getAct_wdt();
				}
			}else if("4".equals(x1)){
				//一切四。获取分条计划中前四分之一宽度
				if(pmd.getXh()<=childNoBs.size()/4){
					cut4_1+=pmd.getAct_wdt();
				}else if(pmd.getXh()<=childNoBs.size()/4*2){
					cut4_2+=pmd.getAct_wdt();
				}else if(pmd.getXh()<=childNoBs.size()/4*3){
					cut4_3+=pmd.getAct_wdt();
				}else{
					cut4_4+=pmd.getAct_wdt();
				}
			}else if("5".equals(x1)){
				//一切五。获取分条计划中前五分之一宽度
				if(pmd.getXh()<=childNoBs.size()/5){
					cut5_1+=pmd.getAct_wdt();
				}else if(pmd.getXh()<=childNoBs.size()/5*2){
					cut5_2+=pmd.getAct_wdt();
				}else if(pmd.getXh()<=childNoBs.size()/5*3){
					cut5_3+=pmd.getAct_wdt();
				}else if(pmd.getXh()<=childNoBs.size()/5*4){
					cut5_4+=pmd.getAct_wdt();
				}else{
					cut5_5+=pmd.getAct_wdt();
				}
			}
		}
		
		for(MesCrSlittingD mcsd:childNoBs){
			if("1".equals(x1)){
				//根据前端传入的子卷卷号集合，按各子卷的宽度占勾选的所有子卷的宽度和的比例，对重量进行分摊，
				//当做勾选的当个子卷的重量，同时，将上面创建的记录称重编号写入子卷实绩，方便信息反查
				//四舍五入
				BigDecimal b= new BigDecimal((mcsd.getAct_wdt()/sumWidth)*sumWeight);  
				double f1 = b.setScale(0,   BigDecimal.ROUND_HALF_UP).doubleValue();
				if(i==childNoBs.size()){
					f1=sumWeight-lastWgt;
				}else{
					lastWgt+=f1;
				}
				MesCrSlittingD mcsdu=new MesCrSlittingD();
				mcsdu.setCoil_no(mcsd.getCoil_no());
				//mcsdu.setCoil_act_wgt(0d);
				mcsdu.setCoil_wgt_serial_no(mcsw.getSerial_no());
				mcsdu.setCoil_thr_wgt(f1);
				//mcsdu.setCoil_wgt_time(new Date());
				this.getMapper(MesCrSlittingDMapper.class).update(mcsdu);
				i++;
			}else if("2".equals(x1)){
				if(oci.getObject().getMain().getCrs_cut_len1()>0 && 
						oci.getObject().getMain().getCrs_cut_len2()>0){
					//根据前端传入的子卷卷号集合，按各子卷的宽度占勾选的所有子卷的宽度和的比例，对重量进行分摊，
					//当做勾选的当个子卷的重量，同时，将上面创建的记录称重编号写入子卷实绩，方便信息反查
					//四舍五入
					//宽度比例
					double wid_prop=0;
					BigDecimal b=null;
					if(mcsd.getXh()<=lmcsdq.size()/2){
						Double v2=100.0;
						BigDecimal b1 = new BigDecimal(oci.getObject().getMain().getCrs_cut_len1().toString());    
						BigDecimal b2 = new BigDecimal(v2.toString());  
						wid_prop= new Double(b1.divide(b2, 15, BigDecimal.ROUND_HALF_UP).doubleValue());
						b= new BigDecimal((mcsd.getAct_wdt()/cut2_1)*sumWeight*wid_prop);  
					}else{
						Double v2=100.0;
						BigDecimal b1 = new BigDecimal(oci.getObject().getMain().getCrs_cut_len2().toString());    
						BigDecimal b2 = new BigDecimal(v2.toString());  
						wid_prop= new Double(b1.divide(b2, 15, BigDecimal.ROUND_HALF_UP).doubleValue());
						b= new BigDecimal((mcsd.getAct_wdt()/cut2_2)*sumWeight*wid_prop); 
					}
					//BigDecimal b= new BigDecimal((mcsd.getAct_wdt()/sumWidth)*sumWeight*wid_prop);  
					double f1 = b.setScale(0,   BigDecimal.ROUND_HALF_UP).doubleValue();
					if(i==childNoBs.size()){
						f1=sumWeight-lastWgt;
					}else{
						lastWgt+=f1;
					}
					MesCrSlittingD mcsdu=new MesCrSlittingD();
					mcsdu.setCoil_no(mcsd.getCoil_no());
					//mcsdu.setCoil_act_wgt(0d);
					mcsdu.setCoil_wgt_serial_no(mcsw.getSerial_no());
					mcsdu.setCoil_thr_wgt(f1);
					//mcsdu.setCoil_wgt_time(new Date());
					this.getMapper(MesCrSlittingDMapper.class).update(mcsdu);
					i++;
					// 更新纵剪实绩主表字段 CRS_CUT_LEN1、CRS_CUT_LEN2
					ms3.setCrs_cut_len1(oci.getObject().getMain().getCrs_cut_len1().doubleValue());
					ms3.setCrs_cut_len2(oci.getObject().getMain().getCrs_cut_len2().doubleValue());
				}
			}else if("3".equals(x1)){
				if(oci.getObject().getMain().getCrs_cut_len1()>0 && 
						oci.getObject().getMain().getCrs_cut_len2()>0 && oci.getObject().getMain().getCrs_cut_len3()>0 ){
					//根据前端传入的子卷卷号集合，按各子卷的宽度占勾选的所有子卷的宽度和的比例，对重量进行分摊，
					//当做勾选的当个子卷的重量，同时，将上面创建的记录称重编号写入子卷实绩，方便信息反查
					//四舍五入
					//宽度比例
					double wid_prop=0;
					BigDecimal b=null;
					if(mcsd.getXh()<=lmcsdq.size()/3){
						//wid_prop=oci.getObject().getMain().getCrs_cut_len1()/100;
						Double v2=100.0;
						BigDecimal b1 = new BigDecimal(oci.getObject().getMain().getCrs_cut_len1().toString());    
						BigDecimal b2 = new BigDecimal(v2.toString());  
						wid_prop= new Double(b1.divide(b2, 15, BigDecimal.ROUND_HALF_UP).doubleValue());
						b= new BigDecimal((mcsd.getAct_wdt()/cut3_1)*sumWeight*wid_prop);  
					}else if(mcsd.getXh()<=(lmcsdq.size()/3*2)){
						//wid_prop=oci.getObject().getMain().getCrs_cut_len2()/100;
						Double v2=100.0;
						BigDecimal b1 = new BigDecimal(oci.getObject().getMain().getCrs_cut_len2().toString());    
						BigDecimal b2 = new BigDecimal(v2.toString());  
						wid_prop= new Double(b1.divide(b2, 15, BigDecimal.ROUND_HALF_UP).doubleValue());
						b= new BigDecimal((mcsd.getAct_wdt()/cut3_2)*sumWeight*wid_prop);  
					}else{
						//wid_prop=oci.getObject().getMain().getCrs_cut_len3()/100;
						Double v2=100.0;
						BigDecimal b1 = new BigDecimal(oci.getObject().getMain().getCrs_cut_len3().toString());    
						BigDecimal b2 = new BigDecimal(v2.toString());  
						wid_prop= new Double(b1.divide(b2, 15, BigDecimal.ROUND_HALF_UP).doubleValue());
						b= new BigDecimal((mcsd.getAct_wdt()/cut3_3)*sumWeight*wid_prop);  
					}
				    //b= new BigDecimal((mcsd.getAct_wdt()/sumWidth)*sumWeight*wid_prop);  
					double f1 = b.setScale(0,   BigDecimal.ROUND_HALF_UP).doubleValue();
					if(i==childNoBs.size()){
						f1=sumWeight-lastWgt;
					}else{
						lastWgt+=f1;
					}
					MesCrSlittingD mcsdu=new MesCrSlittingD();
					mcsdu.setCoil_no(mcsd.getCoil_no());
					//mcsdu.setCoil_act_wgt(0d);
					mcsdu.setCoil_wgt_serial_no(mcsw.getSerial_no());
					mcsdu.setCoil_thr_wgt(f1);
					//mcsdu.setCoil_wgt_time(new Date());
					this.getMapper(MesCrSlittingDMapper.class).update(mcsdu);
					i++;
					// 更新纵剪实绩主表字段 CRS_CUT_LEN1、CRS_CUT_LEN2、CRS_CUT_LEN3；
					ms3.setCrs_cut_len1(oci.getObject().getMain().getCrs_cut_len1());
					ms3.setCrs_cut_len2(oci.getObject().getMain().getCrs_cut_len2());
					ms3.setCrs_cut_len3(oci.getObject().getMain().getCrs_cut_len3());
				}

			}else if("4".equals(x1)){
				if(oci.getObject().getMain().getCrs_cut_len1()>0 && 
						oci.getObject().getMain().getCrs_cut_len2()>0 && oci.getObject().getMain().getCrs_cut_len3()>0 
						&& oci.getObject().getMain().getCrs_cut_len4()>0){
					//根据前端传入的子卷卷号集合，按各子卷的宽度占勾选的所有子卷的宽度和的比例，对重量进行分摊，
					//当做勾选的当个子卷的重量，同时，将上面创建的记录称重编号写入子卷实绩，方便信息反查
					//四舍五入
					//宽度比例
					double wid_prop=0;
					BigDecimal b=null;
					if(mcsd.getXh()<=lmcsdq.size()/4){
						//wid_prop=oci.getObject().getMain().getCrs_cut_len1()/100;
						Double v2=100.0;
						BigDecimal b1 = new BigDecimal(oci.getObject().getMain().getCrs_cut_len1().toString());    
						BigDecimal b2 = new BigDecimal(v2.toString());  
						wid_prop= new Double(b1.divide(b2, 15, BigDecimal.ROUND_HALF_UP).doubleValue());
						b= new BigDecimal((mcsd.getAct_wdt()/cut4_1)*sumWeight*wid_prop);  
					}else if(mcsd.getXh()<=(lmcsdq.size()/4*2)){
						//wid_prop=oci.getObject().getMain().getCrs_cut_len2()/100;
						Double v2=100.0;
						BigDecimal b1 = new BigDecimal(oci.getObject().getMain().getCrs_cut_len2().toString());    
						BigDecimal b2 = new BigDecimal(v2.toString());  
						wid_prop= new Double(b1.divide(b2, 15, BigDecimal.ROUND_HALF_UP).doubleValue());
						b= new BigDecimal((mcsd.getAct_wdt()/cut4_2)*sumWeight*wid_prop);  
					}else if(mcsd.getXh()<=(lmcsdq.size()/4*3)){
						//wid_prop=oci.getObject().getMain().getCrs_cut_len2()/100;
						Double v2=100.0;
						BigDecimal b1 = new BigDecimal(oci.getObject().getMain().getCrs_cut_len3().toString());    
						BigDecimal b2 = new BigDecimal(v2.toString());  
						wid_prop= new Double(b1.divide(b2, 15, BigDecimal.ROUND_HALF_UP).doubleValue());
						b= new BigDecimal((mcsd.getAct_wdt()/cut4_3)*sumWeight*wid_prop);  
					}else{
						//wid_prop=oci.getObject().getMain().getCrs_cut_len3()/100;
						Double v2=100.0;
						BigDecimal b1 = new BigDecimal(oci.getObject().getMain().getCrs_cut_len4().toString());    
						BigDecimal b2 = new BigDecimal(v2.toString());  
						wid_prop= new Double(b1.divide(b2, 15, BigDecimal.ROUND_HALF_UP).doubleValue());
						b= new BigDecimal((mcsd.getAct_wdt()/cut4_4)*sumWeight*wid_prop);  
					}
				    //b= new BigDecimal((mcsd.getAct_wdt()/sumWidth)*sumWeight*wid_prop);  
					double f1 = b.setScale(0,   BigDecimal.ROUND_HALF_UP).doubleValue();
					if(i==childNoBs.size()){
						f1=sumWeight-lastWgt;
					}else{
						lastWgt+=f1;
					}
					MesCrSlittingD mcsdu=new MesCrSlittingD();
					mcsdu.setCoil_no(mcsd.getCoil_no());
					//mcsdu.setCoil_act_wgt(0d);
					mcsdu.setCoil_wgt_serial_no(mcsw.getSerial_no());
					mcsdu.setCoil_thr_wgt(f1);
					//mcsdu.setCoil_wgt_time(new Date());
					this.getMapper(MesCrSlittingDMapper.class).update(mcsdu);
					i++;
					// 更新纵剪实绩主表字段 CRS_CUT_LEN1、CRS_CUT_LEN2、CRS_CUT_LEN3；
					ms3.setCrs_cut_len1(oci.getObject().getMain().getCrs_cut_len1());
					ms3.setCrs_cut_len2(oci.getObject().getMain().getCrs_cut_len2());
					ms3.setCrs_cut_len3(oci.getObject().getMain().getCrs_cut_len3());
					ms3.setCrs_cut_len4(oci.getObject().getMain().getCrs_cut_len4());
				}

			}else if("5".equals(x1)){
				if(oci.getObject().getMain().getCrs_cut_len1()>0 && 
						oci.getObject().getMain().getCrs_cut_len2()>0 && oci.getObject().getMain().getCrs_cut_len3()>0 
						&& oci.getObject().getMain().getCrs_cut_len4()>0 && oci.getObject().getMain().getCrs_cut_len5()>0){
					//根据前端传入的子卷卷号集合，按各子卷的宽度占勾选的所有子卷的宽度和的比例，对重量进行分摊，
					//当做勾选的当个子卷的重量，同时，将上面创建的记录称重编号写入子卷实绩，方便信息反查
					//四舍五入
					//宽度比例
					double wid_prop=0;
					BigDecimal b=null;
					if(mcsd.getXh()<=lmcsdq.size()/5){
						//wid_prop=oci.getObject().getMain().getCrs_cut_len1()/100;
						Double v2=100.0;
						BigDecimal b1 = new BigDecimal(oci.getObject().getMain().getCrs_cut_len1().toString());    
						BigDecimal b2 = new BigDecimal(v2.toString());  
						wid_prop= new Double(b1.divide(b2, 15, BigDecimal.ROUND_HALF_UP).doubleValue());
						b= new BigDecimal((mcsd.getAct_wdt()/cut5_1)*sumWeight*wid_prop);  
					}else if(mcsd.getXh()<=(lmcsdq.size()/5*2)){
						//wid_prop=oci.getObject().getMain().getCrs_cut_len2()/100;
						Double v2=100.0;
						BigDecimal b1 = new BigDecimal(oci.getObject().getMain().getCrs_cut_len2().toString());    
						BigDecimal b2 = new BigDecimal(v2.toString());  
						wid_prop= new Double(b1.divide(b2, 15, BigDecimal.ROUND_HALF_UP).doubleValue());
						b= new BigDecimal((mcsd.getAct_wdt()/cut5_2)*sumWeight*wid_prop);  
					}else if(mcsd.getXh()<=(lmcsdq.size()/5*3)){
						//wid_prop=oci.getObject().getMain().getCrs_cut_len2()/100;
						Double v2=100.0;
						BigDecimal b1 = new BigDecimal(oci.getObject().getMain().getCrs_cut_len3().toString());    
						BigDecimal b2 = new BigDecimal(v2.toString());  
						wid_prop= new Double(b1.divide(b2, 15, BigDecimal.ROUND_HALF_UP).doubleValue());
						b= new BigDecimal((mcsd.getAct_wdt()/cut5_3)*sumWeight*wid_prop);  
					}else if(mcsd.getXh()<=(lmcsdq.size()/5*4)){
						//wid_prop=oci.getObject().getMain().getCrs_cut_len2()/100;
						Double v2=100.0;
						BigDecimal b1 = new BigDecimal(oci.getObject().getMain().getCrs_cut_len4().toString());    
						BigDecimal b2 = new BigDecimal(v2.toString());  
						wid_prop= new Double(b1.divide(b2, 15, BigDecimal.ROUND_HALF_UP).doubleValue());
						b= new BigDecimal((mcsd.getAct_wdt()/cut5_4)*sumWeight*wid_prop);  
					}else{
						//wid_prop=oci.getObject().getMain().getCrs_cut_len3()/100;
						Double v2=100.0;
						BigDecimal b1 = new BigDecimal(oci.getObject().getMain().getCrs_cut_len5().toString());    
						BigDecimal b2 = new BigDecimal(v2.toString());  
						wid_prop= new Double(b1.divide(b2, 15, BigDecimal.ROUND_HALF_UP).doubleValue());
						b= new BigDecimal((mcsd.getAct_wdt()/cut5_5)*sumWeight*wid_prop);  
					}
				    //b= new BigDecimal((mcsd.getAct_wdt()/sumWidth)*sumWeight*wid_prop);  
					double f1 = b.setScale(0,   BigDecimal.ROUND_HALF_UP).doubleValue();
					if(i==childNoBs.size()){
						f1=sumWeight-lastWgt;
					}else{
						lastWgt+=f1;
					}
					MesCrSlittingD mcsdu=new MesCrSlittingD();
					mcsdu.setCoil_no(mcsd.getCoil_no());
					//mcsdu.setCoil_act_wgt(0d);
					mcsdu.setCoil_wgt_serial_no(mcsw.getSerial_no());
					mcsdu.setCoil_thr_wgt(f1);
					//mcsdu.setCoil_wgt_time(new Date());
					this.getMapper(MesCrSlittingDMapper.class).update(mcsdu);
					i++;
					// 更新纵剪实绩主表字段 CRS_CUT_LEN1、CRS_CUT_LEN2、CRS_CUT_LEN3；
					ms3.setCrs_cut_len1(oci.getObject().getMain().getCrs_cut_len1());
					ms3.setCrs_cut_len2(oci.getObject().getMain().getCrs_cut_len2());
					ms3.setCrs_cut_len3(oci.getObject().getMain().getCrs_cut_len3());
					ms3.setCrs_cut_len4(oci.getObject().getMain().getCrs_cut_len4());
					ms3.setCrs_cut_len5(oci.getObject().getMain().getCrs_cut_len5());
				}

			}						
		}
		ms3.setCrs_cut_mode(x1);
		ms3.setUpdate_opr(userName);
		ms3.setUpdate_time(new Date());
		this.getMapper(MesCrSlittingMMapper.class).update(ms3);	
		//日志
		MesOprLog mol = new MesOprLog("车间MES", "分条机作业管理", "重量分配", username, opr_time, ms3.getMaterial_no(), null, null, null, "投料卷号："+ms3.getMaterial_no()+ms3.getMachine_code());
		this.getMapper(MesOprLogMapper.class).insert(mol);
		
		rm.setState("200");
		return rm;
	}
	
	
	
	/**
	 * 动作处理_称重保存
	 * @param memo1 重量
	 * @param memo2 重量来源 （1：采集、2：人工）
	 * memo3       pk_ask_code
	 * memo4       pk_ask_desc
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doWeightSave(CommonPage<PlnLengthwisePlanDetailAndMesCrSlittingD> oci) throws Exception{
		ResultModel rm=new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		//验证选中的作业计划主表记录存在
		PlnLengthwisePlan plp=new PlnLengthwisePlan();
		plp.setMachine_code(oci.getObject().getMain().getMachine_code());
		plp.setLw_plan_no(oci.getObject().getMain().getLw_plan_no());
		List<PlnLengthwisePlan> lplp=this.getMapper(PlnLengthwisePlanMapper.class).find(plp, 0, 0);
		if(lplp==null||lplp.size()==0){
			rm.setState("500");
			rm.setMsgInfo("选中的作业计划记录不存在");
			return rm;
		}
		//验证选中的作业计划明细表记录存在
		PlnLengthwisePlanDetail plpd=new PlnLengthwisePlanDetail();
		plpd.setMachine_code(oci.getObject().getMain().getMachine_code());
		plpd.setLw_plan_no(oci.getObject().getMain().getLw_plan_no());
		plpd.setObject_no_vt(oci.getObject().getMain().getObject_no_vt());
		plpd.setObject_no(oci.getObject().getMain().getObject_no());
		List<PlnLengthwisePlanDetail> lplpd=this.getMapper(PlnLengthwisePlanDetailMapper.class).find(plpd, 0, 0);
		if(lplpd==null||lplpd.size()==0){
			rm.setState("500");
			rm.setMsgInfo("选中的作业计划明细记录不存在");
			return rm;
		}

		//验证选中的作业计划对应的分条主实绩存在
		MesCrSlittingM mcsm=new MesCrSlittingM();
		mcsm.setMachine_code(oci.getObject().getMain().getMachine_code());
		mcsm.setSchedule_no(oci.getObject().getMain().getLw_plan_no());
		mcsm.setMaterial_no_vt(oci.getObject().getMain().getObject_no_vt());
		mcsm.setMaterial_no(oci.getObject().getMain().getObject_no());

		List<MesCrSlittingM> lmcsm=this.getMapper(MesCrSlittingMMapper.class).find(mcsm, 0, 0);
		if(lmcsm==null||lmcsm.size()==0){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条主实绩不存在！");
			return rm;
		}
		if(!"0".equals(lmcsm.get(0).getHand_over_status())
				&&lmcsm.get(0).getHand_over_status()!=null){
			rm.setState("500");
			rm.setMsgInfo("["+mcsm.getMaterial_no_vt()+"]分条已生产交工！");
			return rm;
		}
		//验证作业计划原料卷存在子卷实绩
		MesCrSlittingD m=new MesCrSlittingD();
		m.setProcess_no(lmcsm.get(0).getProcess_no());
		List<MesCrSlittingD> lmcsdxxx=this.getMapper(MesCrSlittingDMapper.class).findWithCondition(m, "coil_no not like '%B'", " coil_no ", 0, 0);
		if(lmcsdxxx==null||lmcsdxxx.size()==0){
			rm.setState("500");
			rm.setMsgInfo("作业计划原料卷不存在子卷实绩!");
			return rm;
		}
		
		//重量
		double sumWeight=Double.parseDouble(oci.getMemo1());
		//验证作业计划原料卷当前勾选选中的子卷实绩都存在
		for(MesCrSlittingD mcsd:oci.getObject().getChild()){
			//只有一条
			MesCrSlittingD mcsdq=this.getMapper(MesCrSlittingDMapper.class).findById(mcsd.getCoil_no());
			if(mcsdq==null||mcsdq.getCoil_no()==null){
				rm.setState("500");
				rm.setMsgInfo("当前勾选选中的子卷["+mcsd.getCoil_no()+"]实绩不存在");
				return rm;
			}
		}
		int icount=0;
		String dt=new SimpleDateFormat("yyMMdd").format(new Date());
		List<MesCrSlittingWgt> lmcw=this.getMapper(MesCrSlittingWgtMapper.class).findWithCondition(null, " substr(serial_no,1,6)='"+dt+"'", " serial_no desc", 0, 1);
		if(lmcw==null||lmcw.size()==0){
			icount=1;
		}else{
			icount=Integer.parseInt(lmcw.get(0).getSerial_no().substring(6,11))+1;
		}
		String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		if(userName==null){
			userName="";
		}
		//开始事务：
		//创建分条子卷线上称重实绩记录，即将前端传入的重量信息插入一条记录到MES_CR_SLITTING_WGT表中
		MesCrSlittingWgt mcsw=new MesCrSlittingWgt();
		mcsw.setSerial_no(dt+String.format("%05d", icount++));
		mcsw.setDivide_flag("1");
		mcsw.setDivide_opr(userName);
		mcsw.setDivide_time(now);
		mcsw.setProcess_no(lmcsm.get(0).getProcess_no());
		mcsw.setWgt_source(oci.getMemo2());
		mcsw.setWgt_time(now);
		mcsw.setWgt_value(Double.parseDouble(oci.getMemo1()));		
		mcsw.setCoil_no(oci.getObject().getChild().get(0).getCoil_no());//20201215 保存子卷号
		this.getMapper(MesCrSlittingWgtMapper.class).insert(mcsw);

		MesCrSlittingD mcs=this.getMapper(MesCrSlittingDMapper.class).findById(oci.getObject().getChild().get(0).getCoil_no());
		mcs.setCoil_act_wgt(sumWeight);
		mcs.setUpdate_opr(userName);
		mcs.setUpdate_time(now);
		mcs.setCoil_wgt_time(now);//子卷称重时间
		mcs.setPk_ask_code(oci.getMemo3());
		mcs.setPk_ask_desc(oci.getMemo4());
		this.getMapper(MesCrSlittingDMapper.class).update(mcs);	
		//日志
		MesOprLog mol = new MesOprLog("车间MES", "分条机作业管理", "称重保存", username, opr_time, mcs.getCoil_no(), null, null, null, mcs.getMachine_code());
		this.getMapper(MesOprLogMapper.class).insert(mol);
		
		rm.setState("200");
		return rm;
	}

	/**
	 * 12mm 下发PDI
	 * objectlist中：
	 * lw_plan_no 作业计划号
	 * object_no_vt 虚拟卷号
	 * memo1:mch_code机台代码
	 * memo2:登录用户名
	 * @throws Exception 
	 * */
	public ResultModel doSend12mmPDI(CommonPage<PlnLengthwisePlan> sum) throws Exception{
		ResultModel rm=new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		if(sum.getMemo1()==null || "".equals(sum.getMemo1())){
			rm.setState("500");
			rm.setMsgInfo("参数错误：机台代码不能为空！");
			return rm;
		}
		if(sum.getObjectList()==null || sum.getObjectList().size()<=0){
			rm.setState("500");
			rm.setMsgInfo("请勾选需要下发PDI的原料卷！");
			return rm;
		}
		for(PlnLengthwisePlan plp: sum.getObjectList()){
			if("".equals(plp.getLw_plan_no()) || "".equals(plp.getObject_no_vt())){
				rm.setState("500");
				rm.setMsgInfo("参数错误：作业计划号、虚拟原料卷号个数不匹配！");
				return rm;
			}
		}
		
		List<String> list_v_message=new ArrayList<>();
		//   --(2)、循环参数 { 作业计划号、虚拟原料卷号 } 集合中各元素
		for(PlnLengthwisePlan plp: sum.getObjectList()){
			String v_message="";
			try{
				v_message=this.getBean(MesApi12mmPdiPdoImpl.class).Send12mmSlitPDI(sum.getMemo1(),plp.getLw_plan_no(),plp.getObject_no_vt(),
						username,v_message);
			}catch(Exception e){
				e.printStackTrace();
				if(e.getMessage()!=null && e.getMessage().length()>200){
					v_message="PDI电文发送失败！"+e.getMessage().substring(0,200);
				}else{
					v_message="PDI电文发送失败！"+e.getMessage();
				}
			}
			v_message="计划号{"+plp.getLw_plan_no()+"}"+"虚拟卷号{" +plp.getObject_no_vt()+"}"+v_message;	
			list_v_message.add(v_message);
		}
		StringBuilder sb=new StringBuilder();
		// --(3)、写接口日志：与业务处理分开，单独的事务
		for(String s:list_v_message){
			//第二种，假如insert出错，程序跳到catch中，然后继续for循环。
			try{
				this.getMapper(IfSlit01LogMapper.class).insertIf_slit01_log(now,"Send12mmSlitPDI","",s);
			}catch(Exception e){
				e.printStackTrace();
			}
			sb.append(s+"<br>");
		}
		
		for (PlnLengthwisePlan plp: sum.getObjectList()) {
			//日志
			MesOprLog mol = new MesOprLog("车间MES", "12mm分条机作业管理", "12mm下发PDI", username, opr_time, plp.getObject_no(), null, null, null, null);
			this.getMapper(MesOprLogMapper.class).insert(mol);
		}
		rm.setMsgInfo(sb.toString());
		rm.setState("200");
		return rm;
	}
	
	/**
	 * 纵剪生产跟踪表
	 * @return
	 */
	public ResultModel doQueryProductTrc(){
		ResultModel rm=new ResultModel();
		String machine_code="M0002";//大纵剪
		MesCrSlittingTrc mcst = this.getMapper(MesCrSlittingTrcMapper.class).findById(machine_code);
		rm.setState("200");
		rm.setData(mcst);
		return rm;
	}
	
	/**
	 *  同炉次号向下相同牌号、相同尺寸（厚度、宽度）的物料集合生成一个检验批号
		检验批号编码规则：炉次号+两位流水号，示例：2619000401）
	 * @param billingList
	 * @return
	 * @throws Exception
	 */
	private Map<String, List<MesCrSlittingD>> groupBillingDataByExcpBatchCode(List<MesCrSlittingD> billingList,String schedule) throws Exception{
		Map<String, List<MesCrSlittingD>> resultMap = new HashMap<String, List<MesCrSlittingD>>();
		try{
			int i=0;
			Integer max=this.getMapper(MesCrAnnealMMapper.class).findMaxIns4mm(schedule);
			if(max!=null){
				i=max;
			}
			for(MesCrSlittingD tmExcpNew : billingList){
				String key=tmExcpNew.getSteel_code()+"F"+tmExcpNew.getAct_thk()+"F"+tmExcpNew.getAct_wdt();
				if(resultMap.containsKey(key)){//map中异常批次已存在，将该数据存放到同一个key（key存放的是异常批次）的map中
					List<MesCrSlittingD> list = resultMap.get(key);
					if(list!=null && list.size()>0){
						tmExcpNew.setInspection_lot(list.get(0).getInspection_lot());
					}
					resultMap.get(key).add(tmExcpNew);
				}else{//map中不存在，新建key，用来存放数据
					i++;
					String inspection_lot=schedule+lpad(i+"", 2, "0");
					tmExcpNew.setInspection_lot(inspection_lot);
					List<MesCrSlittingD> tmpList = new ArrayList<MesCrSlittingD>();
					tmpList.add(tmExcpNew);
					resultMap.put(key, tmpList);
				}
 
			}
		}catch(Exception e){
			 System.out.println("炉次号向下相同牌号、相同尺寸（厚度、宽度）的物料集合生成一个检验批号进行分组时出现异常");
			 return resultMap;
		}
		return resultMap;
	}
	
	
	// 补零
	public static String lpad(String str, int num, String pad) {
		String n_str = str;
		if (str == null && "".equals(str))
			n_str = " ";
		for (int i = str.length(); i < num; i++) {
			n_str = pad + n_str;
		}
		return n_str;
	}
}
