/***文档注释***********************************************
 * 作者               :                   龙文航
 * 创建日期      :                   2017.12.6
 * 描述               :                   物流管理-理货单管理
 * 注意事项      :                   无
 * 遗留BUG :                   无
 * 修改日期      :                   
 * 修改人员      :                   
 * 修改内容      :                   
 ***********************************************************/
package market.Lms.Logistics.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;

import market.Api.Mes.impl.MesApiServiceImpl;
import market.Com.mapper.ComBaseInfoMapper;
import market.Com.mapper.ComBaseSteelMapper;
import market.Com.vo.ComBaseCbYdd;
import market.Com.vo.ComBaseSteel;
import market.Com.vo.CommonPage;
import market.Com.vo.PassportInfo;
import market.Com.vo.ResultModel;
import market.Lms.Logistics.mapper.LmsPassportinfoMapper;
import market.Lms.Logistics.mapper.SpmDeliveryDetailMapper;
import market.Lms.Logistics.mapper.SpmDeliveryMapper;
import market.Lms.Logistics.mapper.SpmDistrbuteMainMapper;
import market.Lms.Logistics.mapper.SpmTransportDetailMapper;
import market.Lms.Logistics.service.SpmDistrbuteMainService;
import market.Lms.Logistics.vo.SpmDelivery;
import market.Lms.Logistics.vo.SpmDeliveryDetail;
import market.Lms.Logistics.vo.SpmDistrbuteMain;
import market.Lms.Logistics.vo.SpmTransportDetail;
import market.Lms.Warehouse.impl.YdmProductOutlistServiceImpl;
import market.Lms.Warehouse.mapper.YdmBaseButtressconfigMapper;
import market.Lms.Warehouse.mapper.YdmProductButtresslistMapper;
import market.Lms.Warehouse.mapper.YdmProductDetailMapper;
import market.Lms.Warehouse.mapper.YdmProductOutlistMapper;
import market.Lms.Warehouse.service.YdmProductInlistService;
import market.Lms.Warehouse.vo.IfRawMtrCoilM;
import market.Lms.Warehouse.vo.YdmBaseButtressconfig;
import market.Lms.Warehouse.vo.YdmProductButtresslist;
import market.Lms.Warehouse.vo.YdmProductDetail;
import market.Lms.Warehouse.vo.YdmProductOutlist;
import market.Mes.MaterielTrack.vo.PrcMaterielProcess;
import market.Mes.Opr.mapper.MesOprLogMapper;
import market.Mes.Opr.vo.MesOprLog;
import market.Mes.OrderManager.Plan.impl.PlnProdorderStatisticServiceImpl;
import market.Mes.Packing.Result.mapper.MesPackResultMapper;
import market.Mes.Packing.Result.vo.MesPackResult;
import market.Qms.qcm.mapper.QcmJudgeSurfaceMapper;
import market.Qms.qcm.vo.QcmJudgeSurface;
import market.Slm.ContractManagement.mapper.SlmContractHeatInfoMapper;
import market.Slm.ContractManagement.mapper.SlmContractLineInfoMapper;
import market.Slm.ContractManagement.vo.SlmContractHeatInfo;
import market.Slm.ContractManagement.vo.SlmContractLineInfo;
import market.Slm.DeliveryManagement.impl.SlmLadingBillHeatServiceImpl;
import market.Slm.DeliveryManagement.mapper.SlmLadingBillDetailMapper;
import market.Slm.DeliveryManagement.mapper.SlmLadingBillHeatMapper;
import market.Slm.DeliveryManagement.vo.SlmLadingBillDetail;
import market.Slm.DeliveryManagement.vo.SlmLadingBillHeat;
import market.Slm.FundManagement.service.SlmFundFirstDetailService;
import market.Slm.OrderManagement.impl.IfSlmContractInfoServiceImpl;
import market.Slm.OrderManagement.mapper.IfSlmContractInfoMapper;
import market.Slm.OrderManagement.mapper.SlmOrderInfoMapper;
import market.Slm.OrderManagement.vo.Ctbl02CoilCommD;
import market.Slm.OrderManagement.vo.IfSlmContractInfo;
import market.Slm.OrderManagement.vo.IfTbl02CoilComm;
import market.Slm.OrderManagement.vo.SlmOrderInfo;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.transaction.annotation.Transactional;

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

@RemoteService(path = "SpmDistrbuteMainService")
public class SpmDistrbuteMainServiceImpl extends BaseServiceImpl<SpmDistrbuteMain, Object>
		implements SpmDistrbuteMainService {

	/**
	 * 物流管理 理货单管理 理货单查询
	 */
	public ResultModel doQueryWebBySQl(CommonPage<SpmDelivery> cp) {
		ResultModel rm = new ResultModel();
		int pageSize = cp.getPageSize();
		int pageIndex = cp.getPageIndex();
		PageModel<SpmDistrbuteMain> pm = new PageModel<SpmDistrbuteMain>(pageIndex, pageSize);
		try {
			pm.setRows(this.getMapper(SpmDistrbuteMainMapper.class).doQueryWebBySQL((pageIndex - 1) * pageSize,
					(pageIndex - 1) * pageSize + pageSize, cp.getObject().getDeliveryno()));
			pm.setTotal(
					this.getMapper(SpmDistrbuteMainMapper.class).doQueryWebBySQLCount(cp.getObject().getDeliveryno()));
			rm.setData(pm);
			rm.setState("200");
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}

	/**
	 * 理货单管理 理货单明细(装车管理 理货单明细)
	 */
	public ResultModel doQueryWebBySQlDetail(CommonPage<SpmDistrbuteMain> cp) {
		ResultModel rm = new ResultModel();
		int pageSize = cp.getPageSize();
		int pageIndex = cp.getPageIndex();
		String state =cp.getMemo1();
		PageModel<SpmTransportDetail> pm = new PageModel<SpmTransportDetail>(pageIndex, pageSize);
		try {
			pm.setRows(this.getMapper(SpmTransportDetailMapper.class).doQueryWebBySQL((pageIndex - 1) * pageSize,
					(pageIndex - 1) * pageSize + pageSize, cp.getObject().getDistrbuteno(),state));
			pm.setTotal(this.getMapper(SpmTransportDetailMapper.class)
					.doQueryWebBySQLCount(cp.getObject().getDistrbuteno(),state));
			rm.setData(pm);
			rm.setState("200");
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("明细查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}

	/**
	 * 理货单管理 理货单明细
	 */
	public ResultModel doQueryWebBySQlDetailB(CommonPage<SpmDistrbuteMain> cp) {
		ResultModel rm = new ResultModel();
		int pageSize = cp.getPageSize();
		int pageIndex = cp.getPageIndex();
		PageModel<SpmTransportDetail> pm = new PageModel<SpmTransportDetail>(pageIndex, pageSize);
		try {
			pm.setRows(this.getMapper(SpmTransportDetailMapper.class).doQueryWebBySQLbon((pageIndex - 1) * pageSize,
					(pageIndex - 1) * pageSize + pageSize, cp.getObject().getDistrbuteno()));
			pm.setTotal(this.getMapper(SpmTransportDetailMapper.class)
					.doQueryWebBySQLCount(cp.getObject().getDistrbuteno(),null));
			rm.setData(pm);
			rm.setState("200");
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("明细查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}

	/**
	 * 装车管理 理货单查询
	 */
	public ResultModel doQueryWebBySQlLoad(CommonPage<SpmDistrbuteMain> cp) {
		ResultModel rm = new ResultModel();
		int pageSize = cp.getPageSize();
		int pageIndex = cp.getPageIndex();
		PageModel<SpmDistrbuteMain> pm = new PageModel<SpmDistrbuteMain>(pageIndex, pageSize);
		try {
//			String sciCondition = " and ORDERNO = 'W60202205S302'";
//			List<IfRawMtrCoilM> sciList = this.getMapper(IfSlmContractInfoMapper.class).doQuaryIfSlmContractInfo2(sciCondition, 0, 1);
//			System.out.println(sciList);
			
			pm.setRows(this.getMapper(SpmDistrbuteMainMapper.class).doQueryWebBySQlLoad((pageIndex - 1) * pageSize,
					(pageIndex - 1) * pageSize + pageSize, cp.getStartTime(), cp.getEndTime(),
					cp.getObject().getDistrbuteno(), cp.getObject().getLoadstore(), cp.getObject().getCarno(),cp.getObject().getDeliveryno()));
			pm.setTotal(this.getMapper(SpmDistrbuteMainMapper.class).doQueryWebBySQlLoadCount(cp.getStartTime(),
					cp.getEndTime(), cp.getObject().getDistrbuteno(), cp.getObject().getLoadstore(),
					cp.getObject().getCarno(),cp.getObject().getDeliveryno()));
			rm.setData(pm);
			rm.setState("200");
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	
	/**
	 * 废副品装车管理 废副品理货单查询
	 */
	public ResultModel doQueryWebBySQlLoadF(CommonPage<SpmDistrbuteMain> cp) {
		ResultModel rm = new ResultModel();
		int pageSize = cp.getPageSize();
		int pageIndex = cp.getPageIndex();
		PageModel<SpmDistrbuteMain> pm = new PageModel<SpmDistrbuteMain>(pageIndex, pageSize);
		try {
//			String sciCondition = " and ORDERNO = 'W60202205S302'";
//			List<IfRawMtrCoilM> sciList = this.getMapper(IfSlmContractInfoMapper.class).doQuaryIfSlmContractInfo2(sciCondition, 0, 1);
//			System.out.println(sciList);
			
			pm.setRows(this.getMapper(SpmDistrbuteMainMapper.class).doQueryWebBySQlLoadF((pageIndex - 1) * pageSize,
					(pageIndex - 1) * pageSize + pageSize, cp.getStartTime(), cp.getEndTime(),
					cp.getObject().getDistrbuteno(), cp.getObject().getLoadstore(), cp.getObject().getCarno(),cp.getObject().getDeliveryno()));
			pm.setTotal(this.getMapper(SpmDistrbuteMainMapper.class).doQueryWebBySQlLoadCountF(cp.getStartTime(),
					cp.getEndTime(), cp.getObject().getDistrbuteno(), cp.getObject().getLoadstore(),
					cp.getObject().getCarno(),cp.getObject().getDeliveryno()));
			rm.setData(pm);
			rm.setState("200");
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}

//	@Transactional(value="tm", rollbackFor=Exception.class)
//	public ResultModel loadLinshi() throws Exception {
//		ResultModel rm = new ResultModel();
//		boolean isWt = true;
//		YdmProductDetail ypd = this.getMapper(YdmProductDetailMapper.class).findById("Y20B2609S0101");
//		if (isWt) {
//			//获取订单信息
//			String condition = "contract_no || contract_line_seq || order_seq = '"+ypd.getOrderno()+"' and nvl(change_flag,0) <> '1'";
//			List<SlmOrderInfo> soiList = this.getMapper(SlmOrderInfoMapper.class).findWithCondition(null, condition, "", 0, 0);
//			if (soiList==null || soiList.size()<=0) {
//				rm.setState("500");
//				rm.setMsgInfo("未找到订单信息");
//				return rm;
//			}
//			
////			SpmTransportDetail std1 = this.getMapper(SpmTransportDetailMapper.class).doFind(ypd.getCoilno(), null);
//			
//			//获取合同行信息
//			//获取合同头信息							
//			IfTbl02CoilComm it = new IfTbl02CoilComm();
//			it.setCoil_no(ypd.getCoilno().length()==8? (ypd.getCoilno()+"S0101") : ypd.getCoilno());
//			it.setOld_sampl_no(ypd.getCoilno().length()==8? (ypd.getCoilno()+"S0101") : ypd.getCoilno());//真实钢卷号（优特钢内部）
//			SlmContractLineInfo scli = this.getMapper(SlmContractLineInfoMapper.class).findById(soiList.get(0).getContract_line_no());
//			if (scli!=null) {								
//				it.setInstr_coil_thk(scli.getThick());//订单厚度
//				it.setInstr_coil_wth(scli.getWidth());
//				it.setInstr_coil_len(scli.getLength());
//			}
//			it.setDevlmt_dtime(new SimpleDateFormat("yyyyMMdd").format(soiList.get(0).getDeliver_date()));//交货期
//			it.setOrdcust_cd(null);//客户
//			it.setCoil_thk(ypd.getThick());
//			it.setCoil_wth(ypd.getWidth());
//			it.setCoil_len(ypd.getLength());
//			it.setAct_wgt(ypd.getFactweight());						
//			it.setOrd_no(ypd.getLzorderno());
//			it.setSlab_no(ypd.getHeatno());
//			it.setStl_grd(soiList.get(0).getSteel_name());//牌号
//			it.setSpec_stl_grd(soiList.get(0).getSteel_name());
//			
//			String sciCondition = " and ORDERNO = '"+ypd.getLzorderno()+"'";
//			List<IfRawMtrCoilM> sciList = this.getMapper(IfSlmContractInfoMapper.class).doQuaryIfSlmContractInfo2(sciCondition, 0, 1);
//			if (sciList!=null && sciList.size()>0) {								
//				it.setOrd_use_cd(sciList.get(0).getPrdCode());//订单用途代码  
//				it.setOrd_seq(sciList.get(0).getProdorderno());//订单序号
//			}
//									
//			String condition1 = " coilno = '"+ypd.getCoilno()+"'";
//			List<YdmProductButtresslist> ypbList = this.getMapper(YdmProductButtresslistMapper.class).findWithCondition(null, condition1, "createdate desc", 0, 1);
//			if (ypbList!=null && ypbList.size()>0) {
//				YdmBaseButtressconfig ybb = this.getMapper(YdmBaseButtressconfigMapper.class).findById(ypbList.get(0).getButtressno());
//				if (ybb!=null) {
//					it.setCur_load_loc(ybb.getButtressname());//垛位
//				}
//			}else {
//				it.setCur_load_loc("酸洗L");//垛位
//			}
//			it.setSpec_abbsym(ypd.getStd_name());//标准
//			it.setCur_prog_cd_dtime(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
//			//成分判定等级
//			if (ypd.getChemresult()!=null) {
//				if (ypd.getChemresult().endsWith("01")) {										
//					it.setIngr_dec_grd("1");//1 合格
//				}else {
//					it.setIngr_dec_grd("2");//2 不合格
//				}
//			}
//			//外观判定等级
//			if (ypd.getSurfaceresult()!=null) {
//				if (ypd.getSurfaceresult().endsWith("01")) {
//					it.setExtshape_dec_grd("1");
//				}else {
//					it.setExtshape_dec_grd("2");
//				}
//			}
//			//SIZE判定等级
//			if (ypd.getSizeresult()!=null) {
//				if (ypd.getSizeresult().endsWith("01")) {
//					it.setSize_dec_rst("1");
//				}else {
//					it.setSize_dec_rst("2");
//				}
//			}
//			//材质判定等级
//			if (ypd.getPhysresult()!=null) {
//				if (ypd.getPhysresult().endsWith("01")) {
//					it.setMatlqlty_dec_grd("1");
//				}else {
//					it.setMatlqlty_dec_grd("2");
//				}
//			}
//			//综合判定等级
//			if (ypd.getJudgeresult()!=null) {
//				if (ypd.getJudgeresult().endsWith("01")) {
//					it.setTot_dec_grd("1");
//				}else {
//					it.setTot_dec_grd("2");
//				}
//			}
//			
//			it.setMill_dtime(new SimpleDateFormat("yyyyMMddHHmmss").format(ypd.getCreatedate()));//轧钢时间
//			it.setSmp_no(ypd.getSmpno());//试样号
//			it.setH_coil_no1(ypd.getMaterailcoilno());//热轧卷号
//			
//			MesPackResult mpr = new MesPackResult();
//			mpr.setCoil_no(ypd.getCoilno());
//			String pk_ask_code = soiList.get(0).getPk_ask_code();
//			if(pk_ask_code!=null){
//				if("201101".equals(pk_ask_code)){//裸包
//					it.setPackage_level("1");//包装等级(1-不包;2-简包;3-普包;4-精包)
//					it.setPackage_fl("0");//是否包装(0-未包装;1-已包装)
//				}else if("201102".equals(pk_ask_code)){//简包
//					it.setPackage_level("2");//包装等级(1-不包;2-简包;3-普包;4-精包)
//					it.setPackage_fl("1");//是否包装(0-未包装;1-已包装)
//				}else if("201103".equals(pk_ask_code)){//普包
//					it.setPackage_level("3");//包装等级(1-不包;2-简包;3-普包;4-精包)	
//					it.setPackage_fl("1");//是否包装(0-未包装;1-已包装)
//				}else if("201104".equals(pk_ask_code)){//精包
//					it.setPackage_level("4");//包装等级(1-不包;2-简包;3-普包;4-精包)	
//					it.setPackage_fl("1");//是否包装(0-未包装;1-已包装)
//				}
//			}
//			
//			//组装【酸轧成品订单公共表】  
//			Ctbl02CoilCommD cc = new Ctbl02CoilCommD();
//			cc.setL_coil_no(it.getOld_sampl_no());
//			cc.setCut_seq("01");
//			if (sciList!=null && sciList.size()>0) {								
//				it.setOrd_use_cd(sciList.get(0).getPrdCode());//订单用途代码  
//				cc.setOrd_thk(Double.parseDouble(sciList.get(0).getInstr_coil_thk()));
//				cc.setOrd_wth(Double.parseDouble(sciList.get(0).getInstr_coil_wth()));
//				cc.setOrd_wgt_min(Double.parseDouble(sciList.get(0).getOrd_wgt()));
//				cc.setOrd_wgt_max(Double.parseDouble(sciList.get(0).getOrd_wgt()));
//				cc.setOrd_no(sciList.get(0).getOrderno());
//				cc.setOrd_seq(sciList.get(0).getProdorderno());
//			}
//			cc.setOrd_wgt(it.getAct_wgt());
//			cc.setOrd_fl("1");
//			
//			String condition2 = "material_no = '"+ypd.getCoilno()+"'";
//			List<QcmJudgeSurface> qcmList = this.getMapper(QcmJudgeSurfaceMapper.class).findWithCondition(null, condition2, "judge_time desc", 0, 1);
//			if (qcmList!=null && qcmList.size()>0) {									
//				it.setExtshape_quality(qcmList.get(0).getLevel_desc());//FA  FB外观质量等级
//			}
//			List<MesPackResult> mprList = this.getMapper(MesPackResultMapper.class).findWithCondition(mpr, null, "create_time desc", 0, 0);
//			if (mprList!=null && mprList.size()>0) {									
//				it.setPackage_reg(mprList.get(0).getCreate_man());//包装人
//				it.setPackage_dtime(new SimpleDateFormat("yyyy-MM-dd").format(mprList.get(0).getCreate_time()));//包装时间
//			}
//			it.setCur_prog_cd("DFA");
//			it.setOrd_fl("1");
//			//20200303 综合判定不合格的需要进行特殊处理
//			if (it.getTot_dec_grd()!=null && "2".equals(it.getTot_dec_grd())) {
//				//T.TOT_DEC_GRD='2',T.CUR_PROG_CD='CRC',T.ORD_FL='2',T.ORD_NO='',T.ORD_SEQ=''
//				it.setTot_dec_grd("2");
//				it.setCur_prog_cd("CRC");
//				it.setOrd_fl("2");
//				it.setOrd_no("");
//				it.setOrd_seq("");
//				it.setExtshape_quality("CP");//20200312综判不合格，外观等级直接给"CP"
//			} else if (it.getTot_dec_grd()!=null && "1".equals(it.getTot_dec_grd())) {
//				// 综判合格但是表面判定不合格的话，直接将表面判定置成最低合格登记FA：2022071201
//				if (it.getExtshape_quality() != null && "CP".equals(it.getExtshape_quality())) {
//					it.setExtshape_quality("FA");//FA  FB外观质量等级
//				}
//			}
//			
//			//20200629 处理轧制数据传到冷轧系统
//			if (ypd.getCoilno().contains("L01") && "M0008".equals(ypd.getMachine_code())) {
//				//t.ORD_FL='2',t.ORD_NO='',t.ORD_SEQ='',t.CUR_PROG_CD='CRC'
//				it.setOrd_fl("2");
//				it.setOrd_no("");
//				it.setOrd_seq("");
//				it.setCur_prog_cd("CRC");
//			}
//			
//			if ((ypd.getLzorderno().startsWith("WZ53") || ypd.getLzorderno().startsWith("WZ52") || ypd.getLzorderno().startsWith("WZ51"))) {
//				// 向冷轧厂返写：
//				ResultModel rmFX = this.getBean(IfSlmContractInfoServiceImpl.class).doUpdateC_TBL02_COIL_COMM_ROUTE(ypd.getMaterailcoilno(), "3");
//				if (rmFX.getState()==null || !"200".equals(rmFX.getState())) {
//					throw new Exception("装车失败，请联系系统维护人员route：3");
//				}
//				// 插入日志：
////				MesOprLog mol2 = new MesOprLog("物流管理", "装车管理", "装车", username, opr_time, ypd.getCoilno(), null, null, null, "冷轧厂加工委托卷子返写状态成功：3");
////				this.getMapper(MesOprLogMapper.class).insert(mol2);
//			} else {
//				//开始传送数据到冷轧系统
//				ResultModel rm1 = this.getBean(IfSlmContractInfoServiceImpl.class).doInsertIfCoil(it);
//				if (rm1.getState()==null || !"200".equals(rm1.getState())) {
//					rm.setState("500");
//					rm.setMsgInfo("装车失败:"+rm1.getMsgInfo());
//					return rm;
//				}
//				ResultModel rm2 = this.getBean(IfSlmContractInfoServiceImpl.class).doInsertIfCoilC(it);
//				if (rm2.getState()==null || !"200".equals(rm2.getState())) {
//					rm.setState("500");
//					rm.setMsgInfo("装车失败:"+rm2.getMsgInfo());
//					return rm;
//				}
//				//3.插入酸轧成品订单公共表
//				ResultModel rm3 = this.getBean(IfSlmContractInfoServiceImpl.class).doInsertCtbl02CoilCommD(cc);
//				if (rm3.getState()==null || !"200".equals(rm3.getState())) {
//					rm.setState("500");
//					rm.setMsgInfo("装车失败:"+rm3.getMsgInfo());
//					return rm;
//				}
//				//4.更新冷轧系统的原料表
//				ResultModel rm4 = this.getBean(IfSlmContractInfoServiceImpl.class).doUpdateC_tbk02_coil_comm(it);
//				if (rm4.getState()==null || !"200".equals(rm4.getState())) {
//					rm.setState("500");
//					rm.setMsgInfo("装车失败:"+rm4.getMsgInfo());
//					return rm;
//				}
//				//5.更新冷轧系统的原料表
//				ResultModel rm5 = this.getBean(IfSlmContractInfoServiceImpl.class).doUpdatec_tbk08_coil_yard(it);
//				if (rm5.getState()==null || !"200".equals(rm5.getState())) {
//					rm.setState("500");
//					rm.setMsgInfo("装车失败:"+rm5.getMsgInfo());
//					return rm;
//				}
//			}
//			
//			// 委托加工且运输方案：到冷轧；
////			if (cp.getSortField().contains("到冷轧")) {
////				//5.更新冷轧系统的库存表
////				ResultModel rm6 = this.getBean(IfSlmContractInfoServiceImpl.class).doUpdatec_tbk08_coil_yard(it);
////				if (rm6.getState()==null || !"200".equals(rm6.getState())) {
////					rm.setState("500");
////					rm.setMsgInfo("装车失败:"+rm6.getMsgInfo());
////					return rm;
////				}
////			}
//			
//			
//			
//		}
//		return rm;
//	}
	
	/**
	 * 装车管理 装车 memo1-3传理货单号，提货单号，提货单子编号，memo4传编辑区车号,sortField运输方式
	 * @throws Exception 
	 */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doLoad(CommonPage<SpmTransportDetail> cp) throws Exception {
		ResultModel rm = new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String userId = (String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		String order = (String) this.getSession().getAttribute(HomeService.WRK_ORD);
		String team = (String) this.getSession().getAttribute(HomeService.WRK_GRP);
		List<SpmTransportDetail> list = cp.getObjectList();
		String deliveryno = cp.getMemo2();//提货单号
		String solution = cp.getSortField();//运输方案
		String carno = cp.getMemo4();//车号
		
		if (StringUtils.isEmpty(solution)) {
			rm.setState("500");
			rm.setMsgInfo("运输方式不允许为空，请重新操作!");
			return rm;
		}		
		
		// 检验车辆是否是环保车辆：20250304ll
		// 只有汽运提单需要校验：TRANS_TYPE is '提单类型（0汽运，1火运）' 20250306ll
		SlmLadingBillHeat heat = this.getMapper(SlmLadingBillHeatMapper.class).findById(deliveryno);
		if ("0".equals(heat.getTrans_type())) {
			ResultModel res = this.getBean(SlmFundFirstDetailService.class).isECOCar(carno, cp.getMemo6());
			if ("500".equals(res.getState())) {
				throw new Exception(res.getMsgInfo());
			}
		}
		// end
		
		if (CollectionUtils.isNotEmpty(list)) {
			String outbillno = this.getBean(SpmTransportDetailServiceImpl.class).createOutBillNo();//装车单号
			Integer count = list.size();
			double loadtheoryweight = 0;
			double loadfactweight = 0;
			ArrayList<String> Strlist = new ArrayList<String>();
			//装车校验
			SpmDelivery spm = this.getMapper(SpmDeliveryMapper.class).findById(deliveryno);
			if (spm == null || (!"1".equals(spm.getState()) && !"2".equals(spm.getState()) && !"3".equals(spm.getState()))) {
				rm.setState("500");
				rm.setMsgInfo("提货单状态发生改变! 请重新查询后操作!");
				throw new Exception("提货单状态发生改变! 请重新查询后操作!");
			}
			String car_seq = spm.getCar_seq();//同车序号
			if(car_seq != null){
				String swhere = " 1=1 and car_seq = '"+car_seq+"'";
				List<SpmDelivery> spmdl = this.getMapper(SpmDeliveryMapper.class).findWithCondition(null, swhere, "state desc", 0, 0);
				List<SpmDistrbuteMain> spmds = this.getMapper(SpmDistrbuteMainMapper.class)._find(spmdl.get(0).getDeliveryno());
				if(spmds.size() > 0 && spmds.get(0).getCarno() !=null){
					if(!carno.equals(spmds.get(0).getCarno())){
						rm.setState("500");
						rm.setMsgInfo("同车提货单号不能输入不同车号!");
						throw new Exception("同车提货单号不能输入不同车号!");
					}
				}
			}
			
			for (SpmTransportDetail std : list) {
				if ((StringUtils.isNotEmpty(std.getObjectno()))|| (StringUtils.isNotEmpty(std.getBillNo()))) {
					Strlist.add(std.getObjectno());
					SpmTransportDetail std1 = this.getMapper(SpmTransportDetailMapper.class).doFind(std.getObjectno(), std.getBillNo());
					if (std1 != null) { 
						if ("1".equals(std1.getState())){
							rm.setState("500");
							rm.setMsgInfo("数据已装车， 请重新查询后操作!");
							throw  new Exception("数据已装车 请重新查询后操作!");
						}
						// 装车前判断卷是否已经点过包装：20230203刘侣 先注释
						// std1.getObjectno()
//						List<MesPackResult> packagedList = this.getMapper(MesPackResultMapper.class).findWithCondition(null, " COIL_NO = '"+std1.getObjectno()+"'", null, 0, 1);
//						if (packagedList.size() <= 0) {
//							throw  new Exception("卷：" + std1.getObjectno() + " 还未包装，请联系包装人员包装后再点击装车。");
//						}
						// end
						
						boolean isWt = false;
						//判断是否为委托加工合同  101607
						SlmContractHeatInfo schi = new SlmContractHeatInfo();
						schi.setValid_flag("1");
						schi.setContract_no(std1.getOrderno().substring(0,std1.getOrderno().length()-6));
						List<SlmContractHeatInfo> schiList = this.getMapper(SlmContractHeatInfoMapper.class).find(schi, 0, 0);
						if (schiList!=null && schiList.size()>0) {
							for (SlmContractHeatInfo sc : schiList) {
								if ("101607".equals(sc.getContract_type_no())) {
									isWt = true;
								}
							}
						}							

						loadtheoryweight += std1.getTheoryweight()==null?0:std1.getTheoryweight();
						loadfactweight += std1.getFactweight()==null?0:std1.getFactweight();
						// 插入出库信息
						YdmProductOutlist ypo = null;
						if(!cp.getSortField().contains("到优特")){
							ypo = new YdmProductOutlist();
							ypo.setOutbillno(this.getBean(YdmProductOutlistServiceImpl.class).createOUTBILLNO());
							ypo.setCreater(username);
							ypo.setCreatedate(now);
							ypo.setOutorder(order);
							ypo.setOutteam(team);
							ypo.setOutoperator(username);
							ypo.setOutdate(now);
							ypo.setOuttype("500505");
//							if (isWt) {
//								ypo.setOuttype("500514");//冷轧出库
//							}
							ypo.setButtressno(std.getButtressno());				
							ypo.setLayer((long) 1);
							ypo.setLocality(std.getLocality());
							ypo.setCoilno(std1.getObjectno());
							ypo.setCoiltype(std1.getObjectnotype());
							ypo.setMaterailtype(std1.getMaterailtype());
							ypo.setSource(std1.getSource());
							ypo.setMaterailsupplier(std1.getMaterailsupplier());
							ypo.setIsbox(std1.getIsbox());
							ypo.setBoxno(std1.getBoxId());							 
							ypo.setBatchno(std1.getBatchno());
							ypo.setDrawingno(std1.getBoxDrawingNo());							 
							ypo.setHeatno(std1.getBatchno());
							ypo.setSmpno(std1.getSmpNo());
							ypo.setManagementno(std1.getManagementno());
							ypo.setStorageattr(std1.getStorageattr());							 
							ypo.setProd_name(std1.getPrdName());
							ypo.setProd_code(std1.getPrdCode());
							ypo.setStd_code(std1.getStdCode());
							ypo.setStd_name(std1.getStdName());
							ypo.setUse_code(std1.getUsgCode());
							ypo.setUse_name(std1.getUsgName());
							ypo.setPostid(std1.getPostid());
							ypo.setThick(std1.getHeight());
							ypo.setWidth(std1.getWidth());
							ypo.setLength(std1.getLength());
							ypo.setDiameter_inn(std1.getInterdiameter());
							ypo.setDiameter_out(std1.getDiameter());
							ypo.setQuantity(std1.getQuantity());
							ypo.setTheoryweight(std1.getTheoryweight());
							ypo.setCoreweight(std1.getCoreweight());
							ypo.setGrossweight(std1.getGrossweight());
							ypo.setPackweight(std1.getPackweight());
							ypo.setFactweight(std1.getFactweight());
							ypo.setCustomer_nm(std1.getCustomerNm());
							ypo.setCustomer_no(std1.getCustomerNo());
							ypo.setReceiv_no(std1.getReceivNo());
							ypo.setReceiv_nm(std1.getReceivNm());
							ypo.setOrderno(std1.getOrderno());
							ypo.setProdorderno(std1.getProdorderno());
							ypo.setSteelcode(std1.getSteelcode());
							ypo.setJudgesteelcode(std1.getJudgesteelcode());
							ypo.setPacking_group(std1.getPackingGroup());
							ypo.setChemresult(std1.getChemresult());
							ypo.setSizeresult(std1.getSizeresult());
							ypo.setSurfaceresult(std1.getSurfaceresult());
							ypo.setWeightresult(std1.getWeightresult());
							ypo.setJudgeresult(std1.getJudgeresult());
							ypo.setPhysresult(std1.getPhysresult());
							ypo.setSpyresult(std1.getSpyresult());
							ypo.setProducedate(std1.getProducedate());
							ypo.setProduceorder(std1.getProduceorder());
							ypo.setProduceteam(std1.getProduceteam());
							ypo.setIndate(std1.getIndate());
							ypo.setInorder(std1.getInorder());
							ypo.setInteam(std1.getInteam());
							
							// 加入物料属性：20230725刘侣
							YdmProductDetail ypdago = this.getMapper(YdmProductDetailMapper.class).doFind(std1.getObjectno(), std1.getBoxId());
							if (ypdago != null) {
								ypo.setObj_attr_out(ypdago.getObject_attr());
							}
							
							// end
							
							this.getMapper(YdmProductOutlistMapper.class).insert(ypo); 
							//日志
							MesOprLog mol = new MesOprLog("物流管理", "装车管理", "装车出库", username, opr_time, ypo.getCoilno(), null, null, null, "车号:"+carno);
							this.getMapper(MesOprLogMapper.class).insert(mol);
						}
						// 修改库存信息
						YdmProductDetail ypd = this.getMapper(YdmProductDetailMapper.class).doFind(std1.getObjectno(), std1.getBoxId());
						if (ypd != null) {
							//20190508 综合判定为null不能装车(边丝不用判断)
							if (!ypd.getCoilno().endsWith("B") && ypd.getJudgeresult()==null) {
								rm.setState("500");
								rm.setMsgInfo("卷号【"+ypd.getCoilno()+"】综合判定为null,不能装车！");
								throw  new Exception("卷号【"+ypd.getCoilno()+"】综合判定为null,不能装车！");
							}
							ypd.setState("5");
							ypd.setUpdatedate(now);
							ypd.setUpdater(username);
							this.getMapper(YdmProductDetailMapper.class).doUpdate(ypd);
							//调用生产计划模块物料跟踪接口
							PrcMaterielProcess pmp = new PrcMaterielProcess();
							Date date =new  Date();
							pmp.setObject_no(ypd.getCoilno());
							pmp.setPrc_code("5BYS10");
							pmp.setCreate_time(date);
							pmp.setRemark("装车出库:"+cp.getMemo4());
							pmp.setCreate_man_name(username);
							PrcMaterielProcess pmp1 = new PrcMaterielProcess();
							pmp1.setObject_no(ypd.getCoilno());
							pmp1.setPrc_code("5BYZ10");
							pmp1.setCreate_time(date);
							pmp1.setRemark(""+opr_time);
							pmp1.setCreate_man_name(username);
							this.getBean(MesApiServiceImpl.class).INSERT_OBJ_PROCESS(pmp1);
							this.getBean(MesApiServiceImpl.class).INSERT_OBJ_PROCESS(pmp);
							// 成品   生产订单统计 统计量并修改生产订单状态
							try {
								if ("500203".equals(ypd.getStorageattr())) {
									this.getBean(PlnProdorderStatisticServiceImpl.class).prod_Stats(ypd.getCoilno(), 3, true);
								}
							} catch (Exception e) {
								throw new Exception("调用统计生产订单量接口出错");
							}
							
							String isOpen = this.getMapper(ComBaseInfoMapper.class).findById("9512").getMemo();
							if ("1".equals(isOpen)) {
							
								// 记录成本异动点：20230811刘侣
								ComBaseCbYdd cd = new ComBaseCbYdd();
								cd.setCoilStus("1"); // 综判前算半成品，综判入库后算成品
								cd.setInstDisp("01");
								cd.setDataTypeIdx("O");
								// 当前产线：
								String currentMachine = ypd.getCoilno().contains("S") ? "YTSX" : ypd.getCoilno().contains("L") ? "YTZZ" : ypd.getCoilno().contains("P") ? "YTPZ" : ypd.getCoilno().contains("T") ? "YTTH" : ypd.getCoilno().contains("K") ? "YTHJ" : ypd.getCoilno().contains("F") ? "YTZJ" : "YT1";
								cd.setLocNo(currentMachine); // 填当前产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
								cd.setInvQtyUnit("块");
								cd.setInvWidth(ypd.getWidth() != null ? String.valueOf(ypd.getWidth()) : "0");
								cd.setCreateId(userId);
								cd.setActivityId("69A");
								cd.setInvLength(ypd.getLength() != null ? String.valueOf(ypd.getLength()) : "0");
								cd.setManageip(currentMachine); // 填当前产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
								cd.setProdName(ypd.getProd_name());
								cd.setInvThick(ypd.getThick() != null ? String.valueOf(ypd.getThick()) : "0");
								
								String prevcoil = this.getBean(YdmProductInlistService.class).doQueryTl(ypd.getCoilno());
								// 上道产线：
								String prevMachine = prevcoil.contains("S") ? "YTSX" : prevcoil.contains("L") ? "YTZZ" : prevcoil.contains("P") ? "YTPZ" : prevcoil.contains("T") ? "YTTH" : prevcoil.contains("K") ? "YTHJ" : prevcoil.contains("F") ? "YTZJ" : "YT1";
								cd.setRefnoA(prevcoil); // 投料卷号
								cd.setSysId("IA");
								cd.setOrderItem(ypd.getOrderno());
								cd.setCrntMill(currentMachine); // 填当前产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
								cd.setBeTransUnit("t");
								cd.setExecJobFunc("N");
								ComBaseSteel cbs = this.getMapper(ComBaseSteelMapper.class).findById(ypd.getSteelcode());
								if (cbs != null) {
									cd.setAlloyNo(cbs.getSteel_name()); // 牌号
								}
								
								cd.setAcctDate(new SimpleDateFormat("yyyyMMdd").format(now));
								cd.setLastMill(prevMachine); // 填上道工序产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
								cd.setBeTransWgt(ypd.getFactweight() != null ? ypd.getFactweight() / 1000 : ypd.getFactweight());
								cd.setProdTypeNo("CTR");
								cd.setAppId("优特钢产出卷发货");
								cd.setInvId(ypd.getCoilno());
								cd.setInvQty("1");
								cd.setSrcFac("1");
								cd.setGrade("40740801".equals(ypd.getJudgeresult()) ? "1" : "1"); // 正品　1　协议　3　次品　5
								cd.setProdClassNo("H");
								
								String currentMName = ypd.getCoilno().contains("S") ? "酸洗" : ypd.getCoilno().contains("L") ? "冷轧" : ypd.getCoilno().contains("P") ? "平整" : ypd.getCoilno().contains("T") ? "退火" : ypd.getCoilno().contains("K") ? "横剪" : ypd.getCoilno().contains("F") ? "分条" : "原料";
								
								// setSrcFac根据卷的物料属性去判断：
								cd.setSrcFac("507101".equals(ypd.getObject_attr()) ? "1" : "3");
								
								// 去掉只有原料卷才需要增加综判异动点,zhouxubin：20231110刘侣
								// 优特钢带属性卷最后一道工序不合格发货时：卷综判判废给11az，其他结果给 11ac和69a:zhouxubin：20231110刘侣
								// 卷子质量系统判废就 给 11AZ xuli需求 20231227 刘侣
//								if (ypd.getCoilno().length() <= 8) {
									cd.setCoilStus("1"); // 综判前算半成品，综判入库后算成品
									cd.setActivityId("11AC");
									if ("40740804".equals(ypd.getJudgeresult())) {
										cd.setActivityId("11AZ");
										cd.setCoilStus("0"); // 综判前算半成品，综判入库后算成品
									}
									cd.setAppId("优特" + currentMName + "综判");
									cd.setProdTypeNo(ypd.getCoilno().length() > 8 ? "CTR" : ypd.getMaterailcoilno().startsWith("L") ? "CCR" : "HCR");
									cd.setCrntMill(currentMachine); // 填上道产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
									cd.setInvId(ypd.getCoilno().length() <= 8 ? ypd.getMaterailcoilno() : ypd.getCoilno());
									
									// 综判异动点发送：在最后一倒工序完成后发送，不再是发货时发送 20240425刘侣
//									this.getBean(SlmFundFirstDetailService.class).doCbDataIns(cd, cd.getActivityId(), ypd.getMaterailcoilno());
									// end 20240425刘侣
//								}
								// end
								
								// 存入表：1、上料一抛：原料转库（47）（原料上料准备生产时抛送）
								cd.setActivityId("69A");
								cd.setExecJobFunc("N");
								cd.setDataTypeIdx("O");
								cd.setInvId(ypd.getCoilno().length() <= 8 ? ypd.getMaterailcoilno() : ypd.getCoilno());
								cd.setProdTypeNo(ypd.getCoilno().length() > 8 ? "CTR" : ypd.getMaterailcoilno().startsWith("L") ? "CCR" : "HCR");
								cd.setCoilStus("1"); // 综判前算半成品0，综判入库后算成品1
								cd.setCrntMill(currentMachine); // 填上道产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
								cd.setManageip(currentMachine); // 填上道产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
								cd.setLocNo(currentMachine); // 填上道产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
//								String prevMName = prevcoil.contains("S") ? "酸洗" : prevcoil.contains("L") ? "冷轧" : prevcoil.contains("P") ? "平整" : prevcoil.contains("T") ? "退火" : prevcoil.contains("K") ? "开平" : prevcoil.contains("F") ? "分条" : "原料";
								cd.setAppId("优特" + currentMName + "发货");
								
								this.getBean(SlmFundFirstDetailService.class).doCbDataIns(cd, cd.getActivityId(), ypd.getMaterailcoilno());
							}
							
						}
						// 切换后不再需要向冷轧系统发送数据：20231116刘侣
						//委托加工合同，将数据写入销售
//						if (isWt) {
//							//获取订单信息
//							String condition = "contract_no || contract_line_seq || order_seq = '"+ypd.getOrderno()+"' and nvl(change_flag,0) <> '1'";
//							List<SlmOrderInfo> soiList = this.getMapper(SlmOrderInfoMapper.class).findWithCondition(null, condition, "", 0, 0);
//							if (soiList==null || soiList.size()<=0) {
//								rm.setState("500");
//								rm.setMsgInfo("未找到订单信息");
//								return rm;
//							}
//							
//							//获取合同行信息
//							//获取合同头信息							
//							IfTbl02CoilComm it = new IfTbl02CoilComm();
//							it.setCoil_no(ypd.getCoilno().length()==8? (ypd.getCoilno()+"S0101") : ypd.getCoilno());
//							it.setOld_sampl_no(std1.getObjectno().length()==8?(std1.getObjectno()+"S0101") : std1.getObjectno());//真实钢卷号（优特钢内部）
//							SlmContractLineInfo scli = this.getMapper(SlmContractLineInfoMapper.class).findById(soiList.get(0).getContract_line_no());
//							if (scli!=null) {								
//								it.setInstr_coil_thk(scli.getThick());//订单厚度
//								it.setInstr_coil_wth(scli.getWidth());
//								it.setInstr_coil_len(scli.getLength());
//							}
//							it.setDevlmt_dtime(new SimpleDateFormat("yyyyMMdd").format(soiList.get(0).getDeliver_date()));//交货期
//							it.setOrdcust_cd(null);//客户
//							it.setCoil_thk(ypd.getThick());
//							it.setCoil_wth(ypd.getWidth());
//							it.setCoil_len(ypd.getLength());
//							it.setAct_wgt(ypd.getFactweight());						
//							it.setOrd_no(ypd.getLzorderno());
//							it.setSlab_no(ypd.getHeatno());
//							it.setStl_grd(soiList.get(0).getSteel_name());//牌号
//							it.setSpec_stl_grd(soiList.get(0).getSteel_name());
//							
//							String sciCondition = " and ORDERNO = '"+ypd.getLzorderno()+"'";
//							List<IfRawMtrCoilM> sciList = this.getMapper(IfSlmContractInfoMapper.class).doQuaryIfSlmContractInfo2(sciCondition, 0, 1);
//							if (sciList!=null && sciList.size()>0) {								
//								it.setOrd_use_cd(sciList.get(0).getPrdCode());//订单用途代码  
//								it.setOrd_seq(sciList.get(0).getProdorderno());//订单序号
//							}
//													
//							String condition1 = " coilno = '"+ypd.getCoilno()+"'";
//							List<YdmProductButtresslist> ypbList = this.getMapper(YdmProductButtresslistMapper.class).findWithCondition(null, condition1, "createdate desc", 0, 1);
//							if (ypbList!=null && ypbList.size()>0) {
//								YdmBaseButtressconfig ybb = this.getMapper(YdmBaseButtressconfigMapper.class).findById(ypbList.get(0).getButtressno());
//								if (ybb!=null) {
//									it.setCur_load_loc(ybb.getButtressname());//垛位
//								}
//							}else {
//								it.setCur_load_loc("酸洗L");//垛位
//							}
//							it.setSpec_abbsym(ypd.getStd_name());//标准
//							it.setCur_prog_cd_dtime(new SimpleDateFormat("yyyyMMddHHmmss").format(now));
//							//成分判定等级
//							if (ypd.getChemresult()!=null) {
//								if (ypd.getChemresult().endsWith("01")) {										
//									it.setIngr_dec_grd("1");//1 合格
//								}else {
//									it.setIngr_dec_grd("2");//2 不合格
//								}
//							}
//							//外观判定等级
//							if (ypd.getSurfaceresult()!=null) {
//								if (ypd.getSurfaceresult().endsWith("01")) {
//									it.setExtshape_dec_grd("1");
//								}else {
//									it.setExtshape_dec_grd("2");
//								}
//							}
//							//SIZE判定等级
//							if (ypd.getSizeresult()!=null) {
//								if (ypd.getSizeresult().endsWith("01")) {
//									it.setSize_dec_rst("1");
//								}else {
//									it.setSize_dec_rst("2");
//								}
//							}
//							//材质判定等级
//							if (ypd.getPhysresult()!=null) {
//								if (ypd.getPhysresult().endsWith("01")) {
//									it.setMatlqlty_dec_grd("1");
//								}else {
//									it.setMatlqlty_dec_grd("2");
//								}
//							}
//							//综合判定等级
//							if (ypd.getJudgeresult()!=null) {
//								if (ypd.getJudgeresult().endsWith("01")) {
//									it.setTot_dec_grd("1");
//								}else {
//									it.setTot_dec_grd("2");
//								}
//							}
//							
//							it.setMill_dtime(new SimpleDateFormat("yyyyMMddHHmmss").format(ypd.getCreatedate()));//轧钢时间
//							it.setSmp_no(ypd.getSmpno());//试样号
//							it.setH_coil_no1(ypd.getMaterailcoilno());//热轧卷号
//							
//							MesPackResult mpr = new MesPackResult();
//							mpr.setCoil_no(ypd.getCoilno());
//							String pk_ask_code = soiList.get(0).getPk_ask_code();
//							if(pk_ask_code!=null){
//								if("201101".equals(pk_ask_code)){//裸包
//									it.setPackage_level("1");//包装等级(1-不包;2-简包;3-普包;4-精包)
//									it.setPackage_fl("0");//是否包装(0-未包装;1-已包装)
//								}else if("201102".equals(pk_ask_code)){//简包
//									it.setPackage_level("2");//包装等级(1-不包;2-简包;3-普包;4-精包)
//									it.setPackage_fl("1");//是否包装(0-未包装;1-已包装)
//								}else if("201103".equals(pk_ask_code)){//普包
//									it.setPackage_level("3");//包装等级(1-不包;2-简包;3-普包;4-精包)	
//									it.setPackage_fl("1");//是否包装(0-未包装;1-已包装)
//								}else if("201104".equals(pk_ask_code)){//精包
//									it.setPackage_level("4");//包装等级(1-不包;2-简包;3-普包;4-精包)	
//									it.setPackage_fl("1");//是否包装(0-未包装;1-已包装)
//								}
//							}
//							
//							//组装【酸轧成品订单公共表】  
//							Ctbl02CoilCommD cc = new Ctbl02CoilCommD();
//							cc.setL_coil_no(it.getOld_sampl_no());
//							cc.setCut_seq("01");
//							if (sciList!=null && sciList.size()>0) {								
//								it.setOrd_use_cd(sciList.get(0).getPrdCode());//订单用途代码  
//								cc.setOrd_thk(Double.parseDouble(sciList.get(0).getInstr_coil_thk()));
//								cc.setOrd_wth(Double.parseDouble(sciList.get(0).getInstr_coil_wth()));
//								cc.setOrd_wgt_min(Double.parseDouble(sciList.get(0).getOrd_wgt()));
//								cc.setOrd_wgt_max(Double.parseDouble(sciList.get(0).getOrd_wgt()));
//								cc.setOrd_no(sciList.get(0).getOrderno());
//								cc.setOrd_seq(sciList.get(0).getProdorderno());
//							}
//							cc.setOrd_wgt(it.getAct_wgt());
//							cc.setOrd_fl("1");
//							
//							String condition2 = "material_no = '"+ypd.getCoilno()+"'";
//							List<QcmJudgeSurface> qcmList = this.getMapper(QcmJudgeSurfaceMapper.class).findWithCondition(null, condition2, "judge_time desc", 0, 1);
//							if (qcmList!=null && qcmList.size()>0) {									
//								it.setExtshape_quality(qcmList.get(0).getLevel_desc());//FA  FB外观质量等级
//							}
//							List<MesPackResult> mprList = this.getMapper(MesPackResultMapper.class).findWithCondition(mpr, null, "create_time desc", 0, 0);
//							if (mprList!=null && mprList.size()>0) {									
//								it.setPackage_reg(mprList.get(0).getCreate_man());//包装人
//								it.setPackage_dtime(new SimpleDateFormat("yyyy-MM-dd").format(mprList.get(0).getCreate_time()));//包装时间
//							}
//							it.setCur_prog_cd("DFA");
//							it.setOrd_fl("1");
//							//20200303 综合判定不合格的需要进行特殊处理
//							if (it.getTot_dec_grd()!=null && "2".equals(it.getTot_dec_grd())) {
//								//T.TOT_DEC_GRD='2',T.CUR_PROG_CD='CRC',T.ORD_FL='2',T.ORD_NO='',T.ORD_SEQ=''
//								it.setTot_dec_grd("2");
//								it.setCur_prog_cd("CRC");
//								it.setOrd_fl("2");
//								it.setOrd_no("");
//								it.setOrd_seq("");
//								it.setExtshape_quality("CP");//20200312综判不合格，外观等级直接给"CP"
//							} else if (it.getTot_dec_grd()!=null && "1".equals(it.getTot_dec_grd())) {
//								// 综判合格但是表面判定不合格的话，直接将表面判定置成最低合格登记FA：2022071201
//								if (it.getExtshape_quality() != null && "CP".equals(it.getExtshape_quality())) {
//									it.setExtshape_quality("FA");//FA  FB外观质量等级
//								}
//							}
//							
//							//20200629 处理轧制数据传到冷轧系统
//							if (ypd.getCoilno().contains("L01") && "M0008".equals(ypd.getMachine_code())) {
//								//t.ORD_FL='2',t.ORD_NO='',t.ORD_SEQ='',t.CUR_PROG_CD='CRC'
//								it.setOrd_fl("2");
//								it.setOrd_no("");
//								it.setOrd_seq("");
//								it.setCur_prog_cd("CRC");
//							}
//							
//							if (ypd.getLzorderno() == null) {
//								// 这种就是外购入库的卷，不需要发送：
//							} else if ((ypd.getLzorderno().startsWith("WZ53") || ypd.getLzorderno().startsWith("WZ52") || ypd.getLzorderno().startsWith("WZ51"))) {
//								// 向冷轧厂返写：
//								ResultModel rmFX = this.getBean(IfSlmContractInfoServiceImpl.class).doUpdateC_TBL02_COIL_COMM_ROUTE(ypd.getMaterailcoilno(), "3");
//								if (rmFX.getState()==null || !"200".equals(rmFX.getState())) {
//									throw new Exception("装车失败，请联系系统维护人员route：3");
//								}
//								// 插入日志：
//								MesOprLog mol2 = new MesOprLog("物流管理", "装车管理", "装车", username, opr_time, ypd.getCoilno(), null, null, null, "冷轧厂加工委托卷子返写状态成功：3");
//								this.getMapper(MesOprLogMapper.class).insert(mol2);
//							} else {
//								//开始传送数据到冷轧系统
//								ResultModel rm1 = this.getBean(IfSlmContractInfoServiceImpl.class).doInsertIfCoil(it);
//								if (rm1.getState()==null || !"200".equals(rm1.getState())) {
//									rm.setState("500");
//									rm.setMsgInfo("装车失败:"+rm1.getMsgInfo());
//									return rm;
//								}
//								ResultModel rm2 = this.getBean(IfSlmContractInfoServiceImpl.class).doInsertIfCoilC(it);
//								if (rm2.getState()==null || !"200".equals(rm2.getState())) {
//									rm.setState("500");
//									rm.setMsgInfo("装车失败:"+rm2.getMsgInfo());
//									return rm;
//								}
//								//3.插入酸轧成品订单公共表
//								ResultModel rm3 = this.getBean(IfSlmContractInfoServiceImpl.class).doInsertCtbl02CoilCommD(cc);
//								if (rm3.getState()==null || !"200".equals(rm3.getState())) {
//									rm.setState("500");
//									rm.setMsgInfo("装车失败:"+rm3.getMsgInfo());
//									return rm;
//								}
//								//4.更新冷轧系统的原料表
//								ResultModel rm4 = this.getBean(IfSlmContractInfoServiceImpl.class).doUpdateC_tbk02_coil_comm(it);
//								if (rm4.getState()==null || !"200".equals(rm4.getState())) {
//									rm.setState("500");
//									rm.setMsgInfo("装车失败:"+rm4.getMsgInfo());
//									return rm;
//								}
//								//5.更新冷轧系统的原料表
//								ResultModel rm5 = this.getBean(IfSlmContractInfoServiceImpl.class).doUpdatec_tbk08_coil_yard(it);
//								if (rm5.getState()==null || !"200".equals(rm5.getState())) {
//									rm.setState("500");
//									rm.setMsgInfo("装车失败:"+rm5.getMsgInfo());
//									return rm;
//								}
//							}
//							
//							// 委托加工且运输方案：到冷轧；
////							if (cp.getSortField().contains("到冷轧")) {
////								//5.更新冷轧系统的库存表
////								ResultModel rm6 = this.getBean(IfSlmContractInfoServiceImpl.class).doUpdatec_tbk08_coil_yard(it);
////								if (rm6.getState()==null || !"200".equals(rm6.getState())) {
////									rm.setState("500");
////									rm.setMsgInfo("装车失败:"+rm6.getMsgInfo());
////									return rm;
////								}
////							}
//							
//							
//							
//						}
						
						// 修改装车单从表
						std1.setOutbillno(outbillno);
						std1.setState("1");
						std1.setLoadoperator(username);
						std1.setLoaddate(now);
						std1.setOutlistno(ypo==null?null:ypo.getOutbillno());
						std1.setUpdatedate(now);
						std1.setUpdater(username);
						
						this.getMapper(SpmTransportDetailMapper.class).doUpdate(std1);
						
						//判断 运输方案是否为“到优特”
						if (cp.getSortField().contains("到优特")) {
							//如果是则 修改库存数据的 YDM_PRODUCT_DETAIL.Object_Attr = '客户'；YDM_PRODUCT_DETAIL.state = 0；
							YdmProductDetail yd=new YdmProductDetail();
							yd.setCoilno(std1.getObjectno());
							yd.setObject_attr("507102");
							yd.setState("0");
							yd.setUpdatedate(now);
							yd.setUpdater(username);
							this.getMapper(YdmProductDetailMapper.class).update(yd);							 
						}else {
							//如果不是则 逐一删除垛位信息表 YDM_PRODUCT_BUTTRESSLIST中选择的相应数据  
							this.getMapper(YdmProductButtresslistMapper.class).doDelete(std1.getObjectno(),
									std1.getBoxId()); // 删除垛位信息
						}
					}
				} 
			}
			List<SpmTransportDetail> std = new ArrayList<SpmTransportDetail>();
			if (cp.getMemo1() != null && cp.getMemo1() != "") {
				// 修改理货单主表
				SpmDistrbuteMain sdm = this.getMapper(SpmDistrbuteMainMapper.class).findById(cp.getMemo1());
				if (sdm != null) {
					sdm.setStarttime(now);

					if (sdm.getLoadfactweight() == null) {
						sdm.setLoadfactweight(loadfactweight);
					} else {
						sdm.setLoadfactweight(sdm.getLoadfactweight() + loadfactweight);
					}
					if (sdm.getLoadtheoryweight() == null) {
						sdm.setLoadtheoryweight(loadtheoryweight);
					} else {
						sdm.setLoadtheoryweight(sdm.getLoadtheoryweight() + loadtheoryweight);
					}

					// sdm.setLoadfactweight(sdm.getLoadfactweight()+loadfactweight);
					// sdm.setLoadtheoryweight(sdm.getLoadtheoryweight()+loadtheoryweight);
					if (sdm.getQuantity() == null)
						sdm.setQuantity(0);
					sdm.setQuantity(sdm.getQuantity() + count);

					SpmTransportDetail std1 = new SpmTransportDetail();
					std1.setDistrbuteno(cp.getMemo1());
					std1.setState("0");
					std = this.getMapper(SpmTransportDetailMapper.class).find(std1, 0, 0);
					if (std == null || std.size() == 0) {
						sdm.setState("2");
					} else {
						sdm.setState("1");
					}
					sdm.setOutbillno(outbillno);
					sdm.setOvertime(now);
					sdm.setUpdatedate(now);
					sdm.setUpdater(username);
					if ((sdm.getCarno() == null || " ".equals(sdm.getCarno()) ||sdm.getCarno() == "") && cp.getMemo4() != null
							&& cp.getMemo4() != "")
						sdm.setCarno(cp.getMemo4());
					this.getMapper(SpmDistrbuteMainMapper.class).update(sdm);
				}
			}
			// 修改提货单主表
			if (cp.getMemo2() != null && cp.getMemo2() != "") {
				SpmDelivery sd = this.getMapper(SpmDeliveryMapper.class).findById(cp.getMemo2());
				if (sd != null) {
					sd.setUpdatedate(now);
					sd.setStarttime(now);
					sd.setUpdater(username);

					if (sd.getLoadFactWeight() == null) {
						sd.setLoadFactWeight(loadfactweight);
					} else {
						sd.setLoadFactWeight(sd.getLoadFactWeight() + loadfactweight);
					}
					if (sd.getLoadTheoryWeight() == null) {
						sd.setLoadTheoryWeight(loadtheoryweight);
					} else {
						sd.setLoadTheoryWeight(sd.getLoadTheoryWeight() + loadtheoryweight);
					}

					// sd.setLoadFactWeight(sd.getLoadFactWeight()+loadfactweight);
					// sd.setLoadTheoryWeight(sd.getLoadTheoryWeight()+loadtheoryweight);
					if (sd.getQuantity() == null)
						sd.setQuantity(0);
					sd.setQuantity(sd.getQuantity() + count);
					sd.setOvertime(now);
					if (std == null || std.size() == 0) {
						sd.setState("4");
					} else {
						sd.setState("3");
					}
					//同车序号
					String max = this.getMapper(SpmDeliveryMapper.class).getCode(new SimpleDateFormat("yyyyMMdd").format(now));
					if(sd.getCar_seq() == null){
						sd.setCar_seq(max);
					}
					this.getMapper(SpmDeliveryMapper.class).update(sd);
					
				}
				
					// 修改提货单从表 Strlist
					List<SpmDeliveryDetail> lisSdd = new ArrayList<SpmDeliveryDetail>();
					if (Strlist != null && Strlist.size() > 0) {
						lisSdd = this.getMapper(SpmDeliveryDetailMapper.class).dofindWeight(Strlist,"1");
					}
					if (lisSdd != null && lisSdd.size() > 0) {
						for (SpmDeliveryDetail add1 : lisSdd) {
							SpmDeliveryDetail sdd = new SpmDeliveryDetail();
							if(add1.getDeliveryno()!=null&&!"".equals(add1.getDeliveryno())&&add1.getLineNo()!=null&&!"".equals(add1.getLineNo()))
							{
							 sdd = this.getMapper(SpmDeliveryDetailMapper.class).dofind(add1.getDeliveryno(), add1.getLineNo());
							}
							if (sdd.getLineNo() != null&&!"".equals(sdd.getLineNo())) {
								sdd.setStarttime(now);
								if ((sdd.getCarno() == null || sdd.getCarno() == ""|| " ".equals(sdd.getCarno()) ) && cp.getMemo4() != null
										&& cp.getMemo4() != "")
									sdd.setCarno(cp.getMemo4());
								if (!"3".equals(sdd.getState()))
									sdd.setState("3");
								sdd.setUpdatedate(now);
								sdd.setUpdater(username);
								if (sdd.getLoadFactWeight() == null) {
									sdd.setLoadFactWeight(add1.getLoadFactWeight());
								} else {
									sdd.setLoadFactWeight(sdd.getLoadFactWeight() + add1.getLoadFactWeight());
								}
								if (sdd.getLoadTheoryWeight() == null) {
									sdd.setLoadTheoryWeight(add1.getLoadTheoryWeight());
								} else {
									sdd.setLoadTheoryWeight(sdd.getLoadTheoryWeight() + add1.getLoadTheoryWeight());
								}
								if (sdd.getQuantity() == null)
									sdd.setQuantity(0);
								sdd.setQuantity(sdd.getQuantity() + add1.getQuantity());
								sdd.setOvertime(now);
								this.getMapper(SpmDeliveryDetailMapper.class).update(sdd);
							}
						}
					} 
			}
			
			try {
				//装车车号不为8和9
				if (!cp.getSortField().contains("到优特") && !"8".equals(cp.getMemo4()) && !"9".equals(cp.getMemo4())) {
					int countS = this.getMapper(SlmLadingBillDetailMapper.class).doCountStorageByBillno(cp.getMemo2(),"500205");
					//判断提单对应的仓库是不是贸易库，如果有贸易库的卷子，则不需要发送门禁数据
					if (countS == 0) {					
						CommonPage<PassportInfo> cp1 = new CommonPage<PassportInfo>();
						cp1.setMemo1(cp.getMemo2());//提货单号
						cp1.setMemo2(cp.getMemo5());//草支垫重量 20201105
						cp1.setMemo6(cp.getMemo6());//车牌颜色
						ResultModel rm1 = this.getBean(LmsPassportinfoServiceImpl.class).doAddPassportInfo(cp1);
						if (!"200".equals(rm1.getState())) {
							throw new Exception(rm1.getMsgInfo());
						}
					}
				}
			} catch (Exception e) {
				throw new Exception(e.getMessage());
			}			 
		} else {
			rm.setMsgInfo("传入的数据为空!");
		}
		rm.setState("200");
		return rm;
	}
	

	/**
	 * 装车管理 装车 memo1-3传理货单号，提货单号，提货单子编号，memo4传编辑区车号,sortField运输方式
	 * @throws Exception 
	 */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doLoadNew(CommonPage<SpmTransportDetail> cp) throws Exception {
		ResultModel rm = new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String userId = (String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		String order = (String) this.getSession().getAttribute(HomeService.WRK_ORD);
		String team = (String) this.getSession().getAttribute(HomeService.WRK_GRP);
		List<SpmTransportDetail> list = cp.getObjectList();
		String deliveryno = cp.getMemo2();//提货单号
		cp.setSortField("正常发运");
		String solution = cp.getSortField();//运输方案
		String carno = cp.getMemo4();//车号
		
		if (StringUtils.isEmpty(solution)) {
			rm.setState("500");
			rm.setMsgInfo("运输方式不允许为空，请重新操作!");
			return rm;
		}		
		
		// 检验车辆是否是环保车辆：20250304ll
		ResultModel res = this.getBean(SlmFundFirstDetailService.class).isECOCar(carno, cp.getMemo6());
		if ("500".equals(res.getState())) {
			rm.setState("500");
			rm.setMsgInfo(res.getMsgInfo());
			return rm;
		}
		// end
		
		if (CollectionUtils.isNotEmpty(list)) {
			String outbillno = this.getBean(SpmTransportDetailServiceImpl.class).createOutBillNo();//装车单号
			Integer count = list.size();
			double loadtheoryweight = 0;
			double loadfactweight = 0;
			ArrayList<String> Strlist = new ArrayList<String>();
			//装车校验
			SpmDelivery spm = this.getMapper(SpmDeliveryMapper.class).findById(deliveryno);
			if (spm == null || (!"1".equals(spm.getState()) && !"2".equals(spm.getState()) && !"3".equals(spm.getState()))) {
				rm.setState("500");
				rm.setMsgInfo("提货单状态发生改变! 请重新查询后操作!");
				throw new Exception("提货单状态发生改变! 请重新查询后操作!");
			}
			String car_seq = spm.getCar_seq();//同车序号
			if(car_seq != null){
				String swhere = " 1=1 and car_seq = '"+car_seq+"'";
				List<SpmDelivery> spmdl = this.getMapper(SpmDeliveryMapper.class).findWithCondition(null, swhere, "state desc", 0, 0);
				List<SpmDistrbuteMain> spmds = this.getMapper(SpmDistrbuteMainMapper.class)._find(spmdl.get(0).getDeliveryno());
				if(spmds.size() > 0 && spmds.get(0).getCarno() !=null){
					if(!carno.equals(spmds.get(0).getCarno())){
						rm.setState("500");
						rm.setMsgInfo("同车提货单号不能输入不同车号!");
						throw new Exception("同车提货单号不能输入不同车号!");
					}
				}
			}
			
			for (SpmTransportDetail std : list) {
				if ((StringUtils.isNotEmpty(std.getObjectno()))|| (StringUtils.isNotEmpty(std.getBillNo()))) {
					Strlist.add(std.getObjectno());
					SpmTransportDetail std1 = this.getMapper(SpmTransportDetailMapper.class).doFind(std.getObjectno(), std.getBillNo());
					if (std1 != null) { 
						if ("1".equals(std1.getState())){
							rm.setState("500");
							rm.setMsgInfo("数据已装车， 请重新查询后操作!");
							throw  new Exception("数据已装车 请重新查询后操作!");
						}
						// 装车前判断卷是否已经点过包装：20230203刘侣 先注释
						// std1.getObjectno()
//						List<MesPackResult> packagedList = this.getMapper(MesPackResultMapper.class).findWithCondition(null, " COIL_NO = '"+std1.getObjectno()+"'", null, 0, 1);
//						if (packagedList.size() <= 0) {
//							throw  new Exception("卷：" + std1.getObjectno() + " 还未包装，请联系包装人员包装后再点击装车。");
//						}
						// end
						
						boolean isWt = false;
						//判断是否为委托加工合同  101607
						SlmContractHeatInfo schi = new SlmContractHeatInfo();
						schi.setValid_flag("1");
						schi.setContract_no(std1.getOrderno().substring(0,std1.getOrderno().length()-6));
						List<SlmContractHeatInfo> schiList = this.getMapper(SlmContractHeatInfoMapper.class).find(schi, 0, 0);
						if (schiList!=null && schiList.size()>0) {
							for (SlmContractHeatInfo sc : schiList) {
								if ("101607".equals(sc.getContract_type_no())) {
									isWt = true;
								}
							}
						}							

						loadtheoryweight += std1.getTheoryweight()==null?0:std1.getTheoryweight();
						loadfactweight += std1.getFactweight()==null?0:std1.getFactweight();
						// 插入出库信息
						YdmProductOutlist ypo = null;
						if(!cp.getSortField().contains("到优特")){
							ypo = new YdmProductOutlist();
							ypo.setOutbillno(this.getBean(YdmProductOutlistServiceImpl.class).createOUTBILLNO());
							ypo.setCreater(username);
							ypo.setCreatedate(now);
							ypo.setOutorder(order);
							ypo.setOutteam(team);
							ypo.setOutoperator(username);
							ypo.setOutdate(now);
							ypo.setOuttype("500505");
//							if (isWt) {
//								ypo.setOuttype("500514");//冷轧出库
//							}
							ypo.setButtressno(std.getButtressno());				
							ypo.setLayer((long) 1);
							ypo.setLocality(std.getLocality());
							ypo.setCoilno(std1.getObjectno());
							ypo.setCoiltype(std1.getObjectnotype());
							ypo.setMaterailtype(std1.getMaterailtype());
							ypo.setSource(std1.getSource());
							ypo.setMaterailsupplier(std1.getMaterailsupplier());
							ypo.setIsbox(std1.getIsbox());
							ypo.setBoxno(std1.getBoxId());							 
							ypo.setBatchno(std1.getBatchno());
							ypo.setDrawingno(std1.getBoxDrawingNo());							 
							ypo.setHeatno(std1.getBatchno());
							ypo.setSmpno(std1.getSmpNo());
							ypo.setManagementno(std1.getManagementno());
							ypo.setStorageattr(std1.getStorageattr());							 
							ypo.setProd_name(std1.getPrdName());
							ypo.setProd_code(std1.getPrdCode());
							ypo.setStd_code(std1.getStdCode());
							ypo.setStd_name(std1.getStdName());
							ypo.setUse_code(std1.getUsgCode());
							ypo.setUse_name(std1.getUsgName());
							ypo.setPostid(std1.getPostid());
							ypo.setThick(std1.getHeight());
							ypo.setWidth(std1.getWidth());
							ypo.setLength(std1.getLength());
							ypo.setDiameter_inn(std1.getInterdiameter());
							ypo.setDiameter_out(std1.getDiameter());
							ypo.setQuantity(std1.getQuantity());
							ypo.setTheoryweight(std1.getTheoryweight());
							ypo.setCoreweight(std1.getCoreweight());
							ypo.setGrossweight(std1.getGrossweight());
							ypo.setPackweight(std1.getPackweight());
							ypo.setFactweight(std1.getFactweight());
							ypo.setCustomer_nm(std1.getCustomerNm());
							ypo.setCustomer_no(std1.getCustomerNo());
							ypo.setReceiv_no(std1.getReceivNo());
							ypo.setReceiv_nm(std1.getReceivNm());
							ypo.setOrderno(std1.getOrderno());
							ypo.setProdorderno(std1.getProdorderno());
							ypo.setSteelcode(std1.getSteelcode());
							ypo.setJudgesteelcode(std1.getJudgesteelcode());
							ypo.setPacking_group(std1.getPackingGroup());
							ypo.setChemresult(std1.getChemresult());
							ypo.setSizeresult(std1.getSizeresult());
							ypo.setSurfaceresult(std1.getSurfaceresult());
							ypo.setWeightresult(std1.getWeightresult());
							ypo.setJudgeresult(std1.getJudgeresult());
							ypo.setPhysresult(std1.getPhysresult());
							ypo.setSpyresult(std1.getSpyresult());
							ypo.setProducedate(std1.getProducedate());
							ypo.setProduceorder(std1.getProduceorder());
							ypo.setProduceteam(std1.getProduceteam());
							ypo.setIndate(std1.getIndate());
							ypo.setInorder(std1.getInorder());
							ypo.setInteam(std1.getInteam());
							
							// 加入物料属性：20230725刘侣
							YdmProductDetail ypdago = this.getMapper(YdmProductDetailMapper.class).doFind(std1.getObjectno(), std1.getBoxId());
							if (ypdago != null) {
								ypo.setObj_attr_out(ypdago.getObject_attr());
							}
							
							// end
							
							this.getMapper(YdmProductOutlistMapper.class).insert(ypo); 
							//日志
							MesOprLog mol = new MesOprLog("物流管理", "装车管理", "装车出库", username, opr_time, ypo.getCoilno(), null, null, null, "车号:"+carno);
							this.getMapper(MesOprLogMapper.class).insert(mol);
						}
						// 修改库存信息
						YdmProductDetail ypd = this.getMapper(YdmProductDetailMapper.class).doFind(std1.getObjectno(), std1.getBoxId());
						if (ypd != null) {
							//20190508 综合判定为null不能装车(边丝不用判断)
							if (!ypd.getCoilno().endsWith("B") && ypd.getJudgeresult()==null) {
								rm.setState("500");
								rm.setMsgInfo("卷号【"+ypd.getCoilno()+"】综合判定为null,不能装车！");
								throw  new Exception("卷号【"+ypd.getCoilno()+"】综合判定为null,不能装车！");
							}
							ypd.setState("5");
							ypd.setUpdatedate(now);
							ypd.setUpdater(username);
							this.getMapper(YdmProductDetailMapper.class).doUpdate(ypd);
							//调用生产计划模块物料跟踪接口
							PrcMaterielProcess pmp = new PrcMaterielProcess();
							Date date =new  Date();
							pmp.setObject_no(ypd.getCoilno());
							pmp.setPrc_code("5BYS10");
							pmp.setCreate_time(date);
							pmp.setRemark("装车出库:"+cp.getMemo4());
							pmp.setCreate_man_name(username);
							PrcMaterielProcess pmp1 = new PrcMaterielProcess();
							pmp1.setObject_no(ypd.getCoilno());
							pmp1.setPrc_code("5BYZ10");
							pmp1.setCreate_time(date);
							pmp1.setRemark(""+opr_time);
							pmp1.setCreate_man_name(username);
							this.getBean(MesApiServiceImpl.class).INSERT_OBJ_PROCESS(pmp1);
							this.getBean(MesApiServiceImpl.class).INSERT_OBJ_PROCESS(pmp);
							// 成品   生产订单统计 统计量并修改生产订单状态
							try {
								if ("500203".equals(ypd.getStorageattr())) {
									this.getBean(PlnProdorderStatisticServiceImpl.class).prod_Stats(ypd.getCoilno(), 3, true);
								}
							} catch (Exception e) {
								throw new Exception("调用统计生产订单量接口出错");
							}
							
							String isOpen = this.getMapper(ComBaseInfoMapper.class).findById("9512").getMemo();
							if ("1".equals(isOpen)) {
								
								// 记录成本异动点：20230811刘侣
								ComBaseCbYdd cd = new ComBaseCbYdd();
								cd.setCoilStus("1"); // 综判前算半成品，综判入库后算成品
								cd.setInstDisp("01");
								cd.setDataTypeIdx("O");
								// 当前产线：
								String currentMachine = ypd.getCoilno().contains("S") ? "YTSX" : ypd.getCoilno().contains("L") ? "YTZZ" : ypd.getCoilno().contains("P") ? "YTPZ" : ypd.getCoilno().contains("T") ? "YTTH" : ypd.getCoilno().contains("K") ? "YTHJ" : ypd.getCoilno().contains("F") ? "YTZJ" : "YT1";
								cd.setLocNo(currentMachine); // 填当前产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
								cd.setInvQtyUnit("块");
								cd.setInvWidth(ypd.getWidth() != null ? String.valueOf(ypd.getWidth()) : "0");
								cd.setCreateId(userId);
								cd.setActivityId("69A");
								cd.setInvLength(ypd.getLength() != null ? String.valueOf(ypd.getLength()) : "0");
								cd.setManageip(currentMachine); // 填当前产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
								cd.setProdName(ypd.getProd_name());
								cd.setInvThick(ypd.getThick() != null ? String.valueOf(ypd.getThick()) : "0");
								
								String prevcoil = this.getBean(YdmProductInlistService.class).doQueryTl(ypd.getCoilno());
								// 上道产线：
								String prevMachine = prevcoil.contains("S") ? "YTSX" : prevcoil.contains("L") ? "YTZZ" : prevcoil.contains("P") ? "YTPZ" : prevcoil.contains("T") ? "YTTH" : prevcoil.contains("K") ? "YTHJ" : prevcoil.contains("F") ? "YTZJ" : "YT1";
								cd.setRefnoA(prevcoil); // 投料卷号
								cd.setSysId("IA");
								cd.setOrderItem(ypd.getOrderno());
								cd.setCrntMill(currentMachine); // 填当前产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
								cd.setBeTransUnit("t");
								cd.setExecJobFunc("N");
								ComBaseSteel cbs = this.getMapper(ComBaseSteelMapper.class).findById(ypd.getSteelcode());
								if (cbs != null) {
									cd.setAlloyNo(cbs.getSteel_name()); // 牌号
								}
								
								cd.setAcctDate(new SimpleDateFormat("yyyyMMdd").format(now));
								cd.setLastMill(prevMachine); // 填上道工序产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
								cd.setBeTransWgt(ypd.getFactweight() != null ? ypd.getFactweight() / 1000 : ypd.getFactweight());
								cd.setProdTypeNo("CTR");
								cd.setAppId("优特钢产出卷发货");
								cd.setInvId(ypd.getCoilno());
								cd.setInvQty("1");
								cd.setSrcFac("1");
								cd.setGrade("40740801".equals(ypd.getJudgeresult()) ? "1" : "1"); // 正品　1　协议　3　次品　5
								cd.setProdClassNo("H");
								
								String currentMName = ypd.getCoilno().contains("S") ? "酸洗" : ypd.getCoilno().contains("L") ? "冷轧" : ypd.getCoilno().contains("P") ? "平整" : ypd.getCoilno().contains("T") ? "退火" : ypd.getCoilno().contains("K") ? "横剪" : ypd.getCoilno().contains("F") ? "分条" : "原料";

								// setSrcFac根据卷的物料属性去判断：20231031刘侣
								cd.setSrcFac("507101".equals(ypd.getObject_attr()) ? "1" : "3");
								
								// 去掉只有原料卷才需要增加综判异动点,zhouxubin：20231110刘侣
//								if (ypd.getCoilno().length() <= 8) {
									cd.setCoilStus("1"); // 综判前算半成品，综判入库后算成品
									cd.setActivityId("11AC");
									// 优特钢带属性卷最后一道工序不合格发货时：卷综判判废给11az，其他结果给 11ac和69a:zhouxubin：20231110刘侣
									// 卷判废才给 11az  xuli 20231227
									if ("40740804".equals(ypd.getJudgeresult())) {
										cd.setActivityId("11AZ");
										cd.setCoilStus("0"); // 综判前算半成品，综判入库后算成品
									}
									// end
									cd.setAppId("优特" + currentMName + "综判");
									cd.setProdTypeNo(ypd.getCoilno().length() > 8 ? "CTR" : ypd.getMaterailcoilno().startsWith("L") ? "CCR" : "HCR");
									cd.setCrntMill(currentMachine); // 填上道产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
									cd.setInvId(ypd.getCoilno().length() <= 8 ? ypd.getMaterailcoilno() : ypd.getCoilno());
									
									// 综判异动点发送：在最后一倒工序完成后发送，不再是发货时发送 20240425刘侣
//									this.getBean(SlmFundFirstDetailService.class).doCbDataIns(cd, cd.getActivityId(), ypd.getMaterailcoilno());
									// end 20240425刘侣
//								}
								
								// 存入表：1、上料一抛：原料转库（47）（原料上料准备生产时抛送）
								cd.setActivityId("69A");
								cd.setExecJobFunc("N");
								cd.setDataTypeIdx("O");
								cd.setInvId(ypd.getCoilno().length() <= 8 ? ypd.getMaterailcoilno() : ypd.getCoilno());
								cd.setProdTypeNo(ypd.getCoilno().length() > 8 ? "CTR" : ypd.getMaterailcoilno().startsWith("L") ? "CCR" : "HCR");
								cd.setCoilStus("1"); // 综判前算半成品0，综判入库后算成品1
								cd.setCrntMill(currentMachine); // 填上道产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
								cd.setManageip(currentMachine); // 填上道产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
								cd.setLocNo(currentMachine); // 填上道产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
//								String prevMName = prevcoil.contains("S") ? "酸洗" : prevcoil.contains("L") ? "冷轧" : prevcoil.contains("P") ? "平整" : prevcoil.contains("T") ? "退火" : prevcoil.contains("K") ? "开平" : prevcoil.contains("F") ? "分条" : "原料";
								cd.setAppId("优特" + currentMName + "发货");
								
								this.getBean(SlmFundFirstDetailService.class).doCbDataIns(cd, cd.getActivityId(), ypd.getMaterailcoilno());
							}
							
						}
						
						// 切换后不再需要向冷轧系统发送数据：20231116刘侣
						//委托加工合同，将数据写入销售
//						if (isWt) {
//							//获取订单信息
//							String condition = "contract_no || contract_line_seq || order_seq = '"+ypd.getOrderno()+"' and nvl(change_flag,0) <> '1'";
//							List<SlmOrderInfo> soiList = this.getMapper(SlmOrderInfoMapper.class).findWithCondition(null, condition, "", 0, 0);
//							if (soiList==null || soiList.size()<=0) {
//								rm.setState("500");
//								rm.setMsgInfo("未找到订单信息");
//								return rm;
//							}
//							
//							//获取合同行信息
//							//获取合同头信息							
//							IfTbl02CoilComm it = new IfTbl02CoilComm();
//							it.setCoil_no(ypd.getCoilno().length()==8? (ypd.getCoilno()+"S0101") : ypd.getCoilno());
//							it.setOld_sampl_no(std1.getObjectno().length()==8?(std1.getObjectno()+"S0101") : std1.getObjectno());//真实钢卷号（优特钢内部）
//							SlmContractLineInfo scli = this.getMapper(SlmContractLineInfoMapper.class).findById(soiList.get(0).getContract_line_no());
//							if (scli!=null) {								
//								it.setInstr_coil_thk(scli.getThick());//订单厚度
//								it.setInstr_coil_wth(scli.getWidth());
//								it.setInstr_coil_len(scli.getLength());
//							}
//							it.setDevlmt_dtime(new SimpleDateFormat("yyyyMMdd").format(soiList.get(0).getDeliver_date()));//交货期
//							it.setOrdcust_cd(null);//客户
//							it.setCoil_thk(ypd.getThick());
//							it.setCoil_wth(ypd.getWidth());
//							it.setCoil_len(ypd.getLength());
//							it.setAct_wgt(ypd.getFactweight());						
//							it.setOrd_no(ypd.getLzorderno());
//							it.setSlab_no(ypd.getHeatno());
//							it.setStl_grd(soiList.get(0).getSteel_name());//牌号
//							it.setSpec_stl_grd(soiList.get(0).getSteel_name());
//							
//							String sciCondition = " and ORDERNO = '"+ypd.getLzorderno()+"'";
//							List<IfRawMtrCoilM> sciList = this.getMapper(IfSlmContractInfoMapper.class).doQuaryIfSlmContractInfo2(sciCondition, 0, 1);
//							if (sciList!=null && sciList.size()>0) {								
//								it.setOrd_use_cd(sciList.get(0).getPrdCode());//订单用途代码  
//								it.setOrd_seq(sciList.get(0).getProdorderno());//订单序号
//							}
//													
//							String condition1 = " coilno = '"+ypd.getCoilno()+"'";
//							List<YdmProductButtresslist> ypbList = this.getMapper(YdmProductButtresslistMapper.class).findWithCondition(null, condition1, "createdate desc", 0, 1);
//							if (ypbList!=null && ypbList.size()>0) {
//								YdmBaseButtressconfig ybb = this.getMapper(YdmBaseButtressconfigMapper.class).findById(ypbList.get(0).getButtressno());
//								if (ybb!=null) {
//									it.setCur_load_loc(ybb.getButtressname());//垛位
//								}
//							}else {
//								it.setCur_load_loc("酸洗L");//垛位
//							}
//							it.setSpec_abbsym(ypd.getStd_name());//标准
//							it.setCur_prog_cd_dtime(new SimpleDateFormat("yyyyMMddHHmmss").format(now));
//							//成分判定等级
//							if (ypd.getChemresult()!=null) {
//								if (ypd.getChemresult().endsWith("01")) {										
//									it.setIngr_dec_grd("1");//1 合格
//								}else {
//									it.setIngr_dec_grd("2");//2 不合格
//								}
//							}
//							//外观判定等级
//							if (ypd.getSurfaceresult()!=null) {
//								if (ypd.getSurfaceresult().endsWith("01")) {
//									it.setExtshape_dec_grd("1");
//								}else {
//									it.setExtshape_dec_grd("2");
//								}
//							}
//							//SIZE判定等级
//							if (ypd.getSizeresult()!=null) {
//								if (ypd.getSizeresult().endsWith("01")) {
//									it.setSize_dec_rst("1");
//								}else {
//									it.setSize_dec_rst("2");
//								}
//							}
//							//材质判定等级
//							if (ypd.getPhysresult()!=null) {
//								if (ypd.getPhysresult().endsWith("01")) {
//									it.setMatlqlty_dec_grd("1");
//								}else {
//									it.setMatlqlty_dec_grd("2");
//								}
//							}
//							//综合判定等级
//							if (ypd.getJudgeresult()!=null) {
//								if (ypd.getJudgeresult().endsWith("01")) {
//									it.setTot_dec_grd("1");
//								}else {
//									it.setTot_dec_grd("2");
//								}
//							}
//							
//							it.setMill_dtime(new SimpleDateFormat("yyyyMMddHHmmss").format(ypd.getCreatedate()));//轧钢时间
//							it.setSmp_no(ypd.getSmpno());//试样号
//							it.setH_coil_no1(ypd.getMaterailcoilno());//热轧卷号
//							
//							MesPackResult mpr = new MesPackResult();
//							mpr.setCoil_no(ypd.getCoilno());
//							String pk_ask_code = soiList.get(0).getPk_ask_code();
//							if(pk_ask_code!=null){
//								if("201101".equals(pk_ask_code)){//裸包
//									it.setPackage_level("1");//包装等级(1-不包;2-简包;3-普包;4-精包)
//									it.setPackage_fl("0");//是否包装(0-未包装;1-已包装)
//								}else if("201102".equals(pk_ask_code)){//简包
//									it.setPackage_level("2");//包装等级(1-不包;2-简包;3-普包;4-精包)
//									it.setPackage_fl("1");//是否包装(0-未包装;1-已包装)
//								}else if("201103".equals(pk_ask_code)){//普包
//									it.setPackage_level("3");//包装等级(1-不包;2-简包;3-普包;4-精包)	
//									it.setPackage_fl("1");//是否包装(0-未包装;1-已包装)
//								}else if("201104".equals(pk_ask_code)){//精包
//									it.setPackage_level("4");//包装等级(1-不包;2-简包;3-普包;4-精包)	
//									it.setPackage_fl("1");//是否包装(0-未包装;1-已包装)
//								}
//							}
//							
//							//组装【酸轧成品订单公共表】  
//							Ctbl02CoilCommD cc = new Ctbl02CoilCommD();
//							cc.setL_coil_no(it.getOld_sampl_no());
//							cc.setCut_seq("01");
//							if (sciList!=null && sciList.size()>0) {								
//								it.setOrd_use_cd(sciList.get(0).getPrdCode());//订单用途代码  
//								cc.setOrd_thk(Double.parseDouble(sciList.get(0).getInstr_coil_thk()));
//								cc.setOrd_wth(Double.parseDouble(sciList.get(0).getInstr_coil_wth()));
//								cc.setOrd_wgt_min(Double.parseDouble(sciList.get(0).getOrd_wgt()));
//								cc.setOrd_wgt_max(Double.parseDouble(sciList.get(0).getOrd_wgt()));
//								cc.setOrd_no(sciList.get(0).getOrderno());
//								cc.setOrd_seq(sciList.get(0).getProdorderno());
//							}
//							cc.setOrd_wgt(it.getAct_wgt());
//							cc.setOrd_fl("1");
//							
//							String condition2 = "material_no = '"+ypd.getCoilno()+"'";
//							List<QcmJudgeSurface> qcmList = this.getMapper(QcmJudgeSurfaceMapper.class).findWithCondition(null, condition2, "judge_time desc", 0, 1);
//							if (qcmList!=null && qcmList.size()>0) {									
//								it.setExtshape_quality(qcmList.get(0).getLevel_desc());//FA  FB外观质量等级
//							}
//							List<MesPackResult> mprList = this.getMapper(MesPackResultMapper.class).findWithCondition(mpr, null, "create_time desc", 0, 0);
//							if (mprList!=null && mprList.size()>0) {									
//								it.setPackage_reg(mprList.get(0).getCreate_man());//包装人
//								it.setPackage_dtime(new SimpleDateFormat("yyyy-MM-dd").format(mprList.get(0).getCreate_time()));//包装时间
//							}
//							it.setCur_prog_cd("DFA");
//							it.setOrd_fl("1");
//							//20200303 综合判定不合格的需要进行特殊处理
//							if (it.getTot_dec_grd()!=null && "2".equals(it.getTot_dec_grd())) {
//								//T.TOT_DEC_GRD='2',T.CUR_PROG_CD='CRC',T.ORD_FL='2',T.ORD_NO='',T.ORD_SEQ=''
//								it.setTot_dec_grd("2");
//								it.setCur_prog_cd("CRC");
//								it.setOrd_fl("2");
//								it.setOrd_no("");
//								it.setOrd_seq("");
//								it.setExtshape_quality("CP");//20200312综判不合格，外观等级直接给"CP"
//							} else if (it.getTot_dec_grd()!=null && "1".equals(it.getTot_dec_grd())) {
//								// 综判合格但是表面判定不合格的话，直接将表面判定置成最低合格登记FA：2022071201
//								if (it.getExtshape_quality() != null && "CP".equals(it.getExtshape_quality())) {
//									it.setExtshape_quality("FA");//FA  FB外观质量等级
//								}
//							}
//							
//							//20200629 处理轧制数据传到冷轧系统
//							if (ypd.getCoilno().contains("L01") && "M0008".equals(ypd.getMachine_code())) {
//								//t.ORD_FL='2',t.ORD_NO='',t.ORD_SEQ='',t.CUR_PROG_CD='CRC'
//								it.setOrd_fl("2");
//								it.setOrd_no("");
//								it.setOrd_seq("");
//								it.setCur_prog_cd("CRC");
//							}
//							
//							if ((ypd.getLzorderno().startsWith("WZ53") || ypd.getLzorderno().startsWith("WZ52") || ypd.getLzorderno().startsWith("WZ51"))) {
//								// 向冷轧厂返写：
//								ResultModel rmFX = this.getBean(IfSlmContractInfoServiceImpl.class).doUpdateC_TBL02_COIL_COMM_ROUTE(ypd.getMaterailcoilno(), "3");
//								if (rmFX.getState()==null || !"200".equals(rmFX.getState())) {
//									throw new Exception("装车失败，请联系系统维护人员route：3");
//								}
//								// 插入日志：
//								MesOprLog mol2 = new MesOprLog("物流管理", "装车管理", "装车", username, opr_time, ypd.getCoilno(), null, null, null, "冷轧厂加工委托卷子返写状态成功：3");
//								this.getMapper(MesOprLogMapper.class).insert(mol2);
//							} else {
//								//开始传送数据到冷轧系统
//								ResultModel rm1 = this.getBean(IfSlmContractInfoServiceImpl.class).doInsertIfCoil(it);
//								if (rm1.getState()==null || !"200".equals(rm1.getState())) {
//									rm.setState("500");
//									rm.setMsgInfo("装车失败:"+rm1.getMsgInfo());
//									return rm;
//								}
//								ResultModel rm2 = this.getBean(IfSlmContractInfoServiceImpl.class).doInsertIfCoilC(it);
//								if (rm2.getState()==null || !"200".equals(rm2.getState())) {
//									rm.setState("500");
//									rm.setMsgInfo("装车失败:"+rm2.getMsgInfo());
//									return rm;
//								}
//								//3.插入酸轧成品订单公共表
//								ResultModel rm3 = this.getBean(IfSlmContractInfoServiceImpl.class).doInsertCtbl02CoilCommD(cc);
//								if (rm3.getState()==null || !"200".equals(rm3.getState())) {
//									rm.setState("500");
//									rm.setMsgInfo("装车失败:"+rm3.getMsgInfo());
//									return rm;
//								}
//								//4.更新冷轧系统的原料表
//								ResultModel rm4 = this.getBean(IfSlmContractInfoServiceImpl.class).doUpdateC_tbk02_coil_comm(it);
//								if (rm4.getState()==null || !"200".equals(rm4.getState())) {
//									rm.setState("500");
//									rm.setMsgInfo("装车失败:"+rm4.getMsgInfo());
//									return rm;
//								}
//								//5.更新冷轧系统的原料表
//								ResultModel rm5 = this.getBean(IfSlmContractInfoServiceImpl.class).doUpdatec_tbk08_coil_yard(it);
//								if (rm5.getState()==null || !"200".equals(rm5.getState())) {
//									rm.setState("500");
//									rm.setMsgInfo("装车失败:"+rm5.getMsgInfo());
//									return rm;
//								}
//							}
//							
//							// 委托加工且运输方案：到冷轧；
////							if (cp.getSortField().contains("到冷轧")) {
////								//5.更新冷轧系统的库存表
////								ResultModel rm6 = this.getBean(IfSlmContractInfoServiceImpl.class).doUpdatec_tbk08_coil_yard(it);
////								if (rm6.getState()==null || !"200".equals(rm6.getState())) {
////									rm.setState("500");
////									rm.setMsgInfo("装车失败:"+rm6.getMsgInfo());
////									return rm;
////								}
////							}
//							
//							
//							
//						}
						
						// 修改装车单从表
						std1.setOutbillno(outbillno);
						std1.setState("1");
						std1.setLoadoperator(username);
						std1.setLoaddate(now);
						std1.setOutlistno(ypo==null?null:ypo.getOutbillno());
						std1.setUpdatedate(now);
						std1.setUpdater(username);
						
						this.getMapper(SpmTransportDetailMapper.class).doUpdate(std1);
						
						//判断 运输方案是否为“到优特”
						if (cp.getSortField().contains("到优特")) {
							//如果是则 修改库存数据的 YDM_PRODUCT_DETAIL.Object_Attr = '客户'；YDM_PRODUCT_DETAIL.state = 0；
							YdmProductDetail yd=new YdmProductDetail();
							yd.setCoilno(std1.getObjectno());
							yd.setObject_attr("507102");
							yd.setState("0");
							yd.setUpdatedate(now);
							yd.setUpdater(username);
							this.getMapper(YdmProductDetailMapper.class).update(yd);							 
						}else {
							//如果不是则 逐一删除垛位信息表 YDM_PRODUCT_BUTTRESSLIST中选择的相应数据  
							this.getMapper(YdmProductButtresslistMapper.class).doDelete(std1.getObjectno(),
									std1.getBoxId()); // 删除垛位信息
						}
					}
				} 
			}
			List<SpmTransportDetail> std = new ArrayList<SpmTransportDetail>();
			if (cp.getMemo1() != null && cp.getMemo1() != "") {
				// 修改理货单主表
				SpmDistrbuteMain sdm = this.getMapper(SpmDistrbuteMainMapper.class).findById(cp.getMemo1());
				if (sdm != null) {
					sdm.setStarttime(now);

					if (sdm.getLoadfactweight() == null) {
						sdm.setLoadfactweight(loadfactweight);
					} else {
						sdm.setLoadfactweight(sdm.getLoadfactweight() + loadfactweight);
					}
					if (sdm.getLoadtheoryweight() == null) {
						sdm.setLoadtheoryweight(loadtheoryweight);
					} else {
						sdm.setLoadtheoryweight(sdm.getLoadtheoryweight() + loadtheoryweight);
					}

					// sdm.setLoadfactweight(sdm.getLoadfactweight()+loadfactweight);
					// sdm.setLoadtheoryweight(sdm.getLoadtheoryweight()+loadtheoryweight);
					if (sdm.getQuantity() == null)
						sdm.setQuantity(0);
					sdm.setQuantity(sdm.getQuantity() + count);

					SpmTransportDetail std1 = new SpmTransportDetail();
					std1.setDistrbuteno(cp.getMemo1());
					std1.setState("0");
					std = this.getMapper(SpmTransportDetailMapper.class).find(std1, 0, 0);
					if (std == null || std.size() == 0) {
						sdm.setState("2");
					} else {
						sdm.setState("1");
					}
					sdm.setOutbillno(outbillno);
					sdm.setOvertime(now);
					sdm.setUpdatedate(now);
					sdm.setUpdater(username);
					if ((sdm.getCarno() == null || " ".equals(sdm.getCarno()) ||sdm.getCarno() == "") && cp.getMemo4() != null
							&& cp.getMemo4() != "")
						sdm.setCarno(cp.getMemo4());
					this.getMapper(SpmDistrbuteMainMapper.class).update(sdm);
				}
			}
			// 修改提货单主表
			if (cp.getMemo2() != null && cp.getMemo2() != "") {
				SpmDelivery sd = this.getMapper(SpmDeliveryMapper.class).findById(cp.getMemo2());
				if (sd != null) {
					sd.setUpdatedate(now);
					sd.setStarttime(now);
					sd.setUpdater(username);

					if (sd.getLoadFactWeight() == null) {
						sd.setLoadFactWeight(loadfactweight);
					} else {
						sd.setLoadFactWeight(sd.getLoadFactWeight() + loadfactweight);
					}
					if (sd.getLoadTheoryWeight() == null) {
						sd.setLoadTheoryWeight(loadtheoryweight);
					} else {
						sd.setLoadTheoryWeight(sd.getLoadTheoryWeight() + loadtheoryweight);
					}

					// sd.setLoadFactWeight(sd.getLoadFactWeight()+loadfactweight);
					// sd.setLoadTheoryWeight(sd.getLoadTheoryWeight()+loadtheoryweight);
					if (sd.getQuantity() == null)
						sd.setQuantity(0);
					sd.setQuantity(sd.getQuantity() + count);
					sd.setOvertime(now);
					if (std == null || std.size() == 0) {
						sd.setState("4");
					} else {
						sd.setState("3");
					}
					//同车序号
					String max = this.getMapper(SpmDeliveryMapper.class).getCode(new SimpleDateFormat("yyyyMMdd").format(now));
					if(sd.getCar_seq() == null){
						sd.setCar_seq(max);
					}
					this.getMapper(SpmDeliveryMapper.class).update(sd);
					
				}
				
					// 修改提货单从表 Strlist
					List<SpmDeliveryDetail> lisSdd = new ArrayList<SpmDeliveryDetail>();
					if (Strlist != null && Strlist.size() > 0) {
						lisSdd = this.getMapper(SpmDeliveryDetailMapper.class).dofindWeight(Strlist,"1");
					}
					if (lisSdd != null && lisSdd.size() > 0) {
						for (SpmDeliveryDetail add1 : lisSdd) {
							SpmDeliveryDetail sdd = new SpmDeliveryDetail();
							if(add1.getDeliveryno()!=null&&!"".equals(add1.getDeliveryno())&&add1.getLineNo()!=null&&!"".equals(add1.getLineNo()))
							{
							 sdd = this.getMapper(SpmDeliveryDetailMapper.class).dofind(add1.getDeliveryno(), add1.getLineNo());
							}
							if (sdd.getLineNo() != null&&!"".equals(sdd.getLineNo())) {
								sdd.setStarttime(now);
								if ((sdd.getCarno() == null || sdd.getCarno() == ""|| " ".equals(sdd.getCarno()) ) && cp.getMemo4() != null
										&& cp.getMemo4() != "")
									sdd.setCarno(cp.getMemo4());
								if (!"3".equals(sdd.getState()))
									sdd.setState("3");
								sdd.setUpdatedate(now);
								sdd.setUpdater(username);
								if (sdd.getLoadFactWeight() == null) {
									sdd.setLoadFactWeight(add1.getLoadFactWeight());
								} else {
									sdd.setLoadFactWeight(sdd.getLoadFactWeight() + add1.getLoadFactWeight());
								}
								if (sdd.getLoadTheoryWeight() == null) {
									sdd.setLoadTheoryWeight(add1.getLoadTheoryWeight());
								} else {
									sdd.setLoadTheoryWeight(sdd.getLoadTheoryWeight() + add1.getLoadTheoryWeight());
								}
								if (sdd.getQuantity() == null)
									sdd.setQuantity(0);
								sdd.setQuantity(sdd.getQuantity() + add1.getQuantity());
								sdd.setOvertime(now);
								this.getMapper(SpmDeliveryDetailMapper.class).update(sdd);
							}
						}
					} 
			}
			
			try {
				//装车车号不为8和9
				if (!cp.getSortField().contains("到优特") && !"8".equals(cp.getMemo4()) && !"9".equals(cp.getMemo4())) {
					int countS = this.getMapper(SlmLadingBillDetailMapper.class).doCountStorageByBillno(cp.getMemo2(),"500205");
					//判断提单对应的仓库是不是贸易库，如果有贸易库的卷子，则不需要发送门禁数据
					if (countS == 0) {					
						CommonPage<PassportInfo> cp1 = new CommonPage<PassportInfo>();
						cp1.setMemo1(cp.getMemo2());//提货单号
						cp1.setMemo2(cp.getMemo5());//草支垫重量 20201105
						cp1.setMemo6(cp.getMemo6());//车牌颜色
						ResultModel rm1 = this.getBean(LmsPassportinfoServiceImpl.class).doAddPassportInfo(cp1);
						if (!"200".equals(rm1.getState())) {
							throw new Exception(rm1.getMsgInfo());
						}
					}
				}
			} catch (Exception e) {
				throw new Exception(e.getMessage());
			}			 
		} else {
			rm.setMsgInfo("传入的数据为空!");
		}
		rm.setState("200");
		return rm;
	}
	
	
	/**
	 * 废副品装车管理 装车 memo1-3传理货单号，提货单号，提货单子编号，memo4传编辑区车号,sortField运输方式
	 * @throws Exception 
	 */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doLoadF(CommonPage<SpmTransportDetail> cp) throws Exception {
		ResultModel rm = new ResultModel();
		Date now = new Date();
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		List<SpmTransportDetail> list = cp.getObjectList();
		String deliveryno = cp.getMemo2();//提货单号
		String solution = cp.getSortField();//运输方案
		String carno = cp.getMemo4();//车号
		String weightStr = cp.getMemo7(); // 实际过磅重量
		
		if (StringUtils.isEmpty(weightStr)) {
			rm.setState("500");
			rm.setMsgInfo("请输入实际过磅重量!");
			return rm;
		}
		double factW = Double.parseDouble(weightStr);
		
		if (StringUtils.isEmpty(solution)) {
			rm.setState("500");
			rm.setMsgInfo("运输方式不允许为空，请重新操作!");
			return rm;
		}		
		if (CollectionUtils.isNotEmpty(list)) {
			String outbillno = this.getBean(SpmTransportDetailServiceImpl.class).createOutBillNo();//装车单号
			Integer count = list.size();
			double loadtheoryweight = 0;
			double loadfactweight = 0;
			ArrayList<String> Strlist = new ArrayList<String>();
			//装车校验
			SpmDelivery spm = this.getMapper(SpmDeliveryMapper.class).findById(deliveryno);
			if (spm == null || (!"1".equals(spm.getState()) && !"2".equals(spm.getState()) && !"3".equals(spm.getState()))) {
				rm.setState("500");
				rm.setMsgInfo("提货单状态发生改变! 请重新查询后操作!");
				throw new Exception("提货单状态发生改变! 请重新查询后操作!");
			}
			String car_seq = spm.getCar_seq();//同车序号
			if(car_seq != null){
				String swhere = " 1=1 and car_seq = '"+car_seq+"'";
				List<SpmDelivery> spmdl = this.getMapper(SpmDeliveryMapper.class).findWithCondition(null, swhere, "state desc", 0, 0);
				List<SpmDistrbuteMain> spmds = this.getMapper(SpmDistrbuteMainMapper.class)._find(spmdl.get(0).getDeliveryno());
				if(spmds.size() > 0 && spmds.get(0).getCarno() !=null){
					if(!carno.equals(spmds.get(0).getCarno())){
						rm.setState("500");
						rm.setMsgInfo("同车提货单号不能输入不同车号!");
						throw new Exception("同车提货单号不能输入不同车号!");
					}
				}
			}
			
			for (SpmTransportDetail std : list) {
				if ((StringUtils.isNotEmpty(std.getObjectno()))|| (StringUtils.isNotEmpty(std.getBillNo()))) {
					Strlist.add(std.getObjectno());
					SpmTransportDetail std1 = this.getMapper(SpmTransportDetailMapper.class).doFind(std.getObjectno(), std.getBillNo());
					if (std1 != null) { 
						if ("1".equals(std1.getState())){
							rm.setState("500");
							rm.setMsgInfo("数据已装车， 请重新查询后操作!");
							throw  new Exception("数据已装车 请重新查询后操作!");
						}
						
						// 修改transportdetail的重量：20250226刘侣
						std1.setFactweight(factW);
						this.getMapper(SpmTransportDetailMapper.class).spmTDetailU(factW, std1.getObjectno());
						std1 = this.getMapper(SpmTransportDetailMapper.class).doFind(std.getObjectno(), std.getBillNo());
						
						loadtheoryweight += std1.getTheoryweight()==null?0:std1.getTheoryweight();
						loadfactweight += factW;
						
						
						// 修改装车单从表
						std1.setOutbillno(outbillno);
						std1.setState("1");
						std1.setLoadoperator(username);
						std1.setLoaddate(now);
//						std1.setOutlistno(ypo==null?null:ypo.getOutbillno());
						std1.setUpdatedate(now);
						std1.setUpdater(username);
						
						this.getMapper(SpmTransportDetailMapper.class).doUpdate(std1);
						
						
					}
				} 
			}
			List<SpmTransportDetail> std = new ArrayList<SpmTransportDetail>();
			if (cp.getMemo1() != null && cp.getMemo1() != "") {
				// 修改理货单主表
				SpmDistrbuteMain sdm = this.getMapper(SpmDistrbuteMainMapper.class).findById(cp.getMemo1());
				if (sdm != null) {
					sdm.setStarttime(now);

					if (sdm.getLoadfactweight() == null) {
						sdm.setLoadfactweight(loadfactweight);
					} else {
						sdm.setLoadfactweight(sdm.getLoadfactweight() + loadfactweight);
					}
					if (sdm.getLoadtheoryweight() == null) {
						sdm.setLoadtheoryweight(loadtheoryweight);
					} else {
						sdm.setLoadtheoryweight(sdm.getLoadtheoryweight() + loadtheoryweight);
					}

					// sdm.setLoadfactweight(sdm.getLoadfactweight()+loadfactweight);
					// sdm.setLoadtheoryweight(sdm.getLoadtheoryweight()+loadtheoryweight);
					if (sdm.getQuantity() == null)
						sdm.setQuantity(0);
					sdm.setQuantity(sdm.getQuantity() + count);

					SpmTransportDetail std1 = new SpmTransportDetail();
					std1.setDistrbuteno(cp.getMemo1());
					std1.setState("0");
					std = this.getMapper(SpmTransportDetailMapper.class).find(std1, 0, 0);
					if (std == null || std.size() == 0) {
						sdm.setState("2");
					} else {
						sdm.setState("1");
					}
					sdm.setOutbillno(outbillno);
					sdm.setOvertime(now);
					sdm.setUpdatedate(now);
					sdm.setUpdater(username);
					if ((sdm.getCarno() == null || " ".equals(sdm.getCarno()) ||sdm.getCarno() == "") && cp.getMemo4() != null
							&& cp.getMemo4() != "")
						sdm.setCarno(cp.getMemo4());
					this.getMapper(SpmDistrbuteMainMapper.class).update(sdm);
				}
			}
			// 修改提货单主表
			if (cp.getMemo2() != null && cp.getMemo2() != "") {
				SpmDelivery sd = this.getMapper(SpmDeliveryMapper.class).findById(cp.getMemo2());
				if (sd != null) {
					sd.setUpdatedate(now);
					sd.setStarttime(now);
					sd.setUpdater(username);

					if (sd.getLoadFactWeight() == null) {
						sd.setLoadFactWeight(loadfactweight);
					} else {
						sd.setLoadFactWeight(sd.getLoadFactWeight() + loadfactweight);
					}
					if (sd.getLoadTheoryWeight() == null) {
						sd.setLoadTheoryWeight(loadtheoryweight);
					} else {
						sd.setLoadTheoryWeight(sd.getLoadTheoryWeight() + loadtheoryweight);
					}

					// sd.setLoadFactWeight(sd.getLoadFactWeight()+loadfactweight);
					// sd.setLoadTheoryWeight(sd.getLoadTheoryWeight()+loadtheoryweight);
					if (sd.getQuantity() == null)
						sd.setQuantity(0);
					sd.setQuantity(sd.getQuantity() + count);
					sd.setOvertime(now);
					if (std == null || std.size() == 0) {
						sd.setState("4");
					} else {
						sd.setState("3");
					}
					//同车序号
					String max = this.getMapper(SpmDeliveryMapper.class).getCode(new SimpleDateFormat("yyyyMMdd").format(now));
					if(sd.getCar_seq() == null){
						sd.setCar_seq(max);
					}
					this.getMapper(SpmDeliveryMapper.class).update(sd);
					
				}
				
				// 修改提货单从表 Strlist
				SpmDeliveryDetail sdd = new SpmDeliveryDetail();
				sdd.setDeliveryno(sd.getDeliveryno());
//				sdd.setLineNo();
				sdd.setStarttime(now);
				sdd.setCarno(cp.getMemo4());
				sdd.setState("3");
				sdd.setUpdatedate(now);
				sdd.setUpdater(username);
				sdd.setLoadFactWeight(sd.getLoadFactWeight());
				sdd.setLoadTheoryWeight(sd.getLoadTheoryWeight());
				sdd.setQuantity(1);
				sdd.setOvertime(now);
				sdd.setLoadstore("500210");
				
				this.getMapper(SpmDeliveryDetailMapper.class).doUpdateZCF(sdd);
				
			}
			
			try {
				//装车车号不为8和9
				if (!cp.getSortField().contains("到优特") && !"8".equals(cp.getMemo4()) && !"9".equals(cp.getMemo4())) {
									
					CommonPage<PassportInfo> cp1 = new CommonPage<PassportInfo>();
					cp1.setMemo1(cp.getMemo2());//提货单号
					cp1.setMemo2(cp.getMemo5());//草支垫重量 20201105
					cp1.setMemo6(cp.getMemo6());//车牌颜色
					ResultModel rm1 = this.getBean(LmsPassportinfoServiceImpl.class).doAddPassportInfoF(cp1);
					if (!"200".equals(rm1.getState())) {
						throw new Exception(rm1.getMsgInfo());
					}
					
				}
			} catch (Exception e) {
				throw new Exception(e.getMessage());
			}			 
		} else {
			rm.setMsgInfo("传入的数据为空!");
		}
		rm.setState("200");
		return rm;
	}
	
	
	/**
	 * 装车管理 撤销装车 记得传界面上的区域编码 memo1-3传理货单号，提货单号，提货单子编号,sortField运输方式
	 * @throws Exception 
	 */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doCancel(CommonPage<SpmTransportDetail> cp) throws Exception {
		ResultModel rm = new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String userId = (String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		List<SpmTransportDetail> list = cp.getObjectList();//理货单明细数据
		String deliveryno = cp.getMemo2();//提货单号
		
		ArrayList<String> Strlist = new ArrayList<String>();
		if (list != null && list.size() > 0) {
			Integer count = list.size();
			double loadtheoryweight = 0;
			double loadfactweight = 0;
			
			SpmDelivery spm = this.getMapper(SpmDeliveryMapper.class).findById(deliveryno);
			if (spm != null && !"4".equals(spm.getState()) && !"3".equals(spm.getState())) {
				rm.setState("500");
				rm.setMsgInfo("提货单状态发生改变! 请重新查询后操作!");
				throw  new Exception("提货单状态发生改变! 请重新查询后操作!");
			}
			//20210511 判断当前提单是否已经下发门禁
			PassportInfo ppi = this.getMapper(LmsPassportinfoMapper.class).findById("Y"+deliveryno);
			if (ppi!=null && "1".equals(ppi.getIs_send())) {
				rm.setState("500");
				rm.setMsgInfo("当前提单已经下发门禁，请先删除门禁！");
				throw  new Exception("当前提单已经下发门禁，请先删除门禁！");
			}
			for (SpmTransportDetail std : list) {
				if ((std.getObjectno() != null && std.getObjectno() != "")
						|| (std.getBillNo() != null && std.getBillNo() != "")) {
					//查出库表，判断是否投料出库。
					YdmProductOutlist ydd = new YdmProductOutlist();
					ydd.setCoilno(std.getObjectno());
					ydd.setOuttype("500501");
					List<YdmProductOutlist> outList = this.getMapper(YdmProductOutlistMapper.class).find(ydd, 0, 0);
					if (outList!=null&&outList.size()>0) {
						rm.setState("500");
						rm.setMsgInfo("原料已投料出库，禁止撤销虚拟装车!");
						throw new Exception("原料已投料出库，禁止撤销虚拟装车!");
					}
					SpmTransportDetail std1 = this.getMapper(SpmTransportDetailMapper.class)
							.doFind(std.getObjectno(), std.getBillNo());
					if (std1 != null) {
						Strlist.add(std.getObjectno());
						loadtheoryweight += std1.getTheoryweight()==null?0:std1.getTheoryweight();
						loadfactweight += std1.getFactweight()==null?0:std1.getFactweight();
						// 修改装车单从表
						std1.setUpdatedate(now);
						std1.setUpdater(username);
						
						if ("0".equals(std1.getState())) {
							rm.setState("500");
							rm.setMsgInfo("数据已被撤销 请重新查询后操作!");
							throw  new Exception("数据已被撤销 请重新查询后操作!");
						}
						
						if ("1".equals(std1.getState()))
							std1.setState("0"); 
							
						YdmProductOutlist ypo =null;
						this.getMapper(SpmTransportDetailMapper.class).doUpdate(std1);
						if (std1.getOutlistno() != null && std1.getOutlistno() != "") {
							ypo = this.getMapper(YdmProductOutlistMapper.class)
									.findById(std1.getOutlistno());
							if (ypo != null) { // 删除出库信息
								this.getMapper(YdmProductOutlistMapper.class).doDelete(std1.getOutlistno());
							}
						}
						
						if (cp.getSortField().contains("到优特")) {
							YdmProductDetail yd=new YdmProductDetail();
							yd.setCoilno(std1.getObjectno());
							yd.setObject_attr("507101");
							yd.setState("2");
							this.getMapper(YdmProductDetailMapper.class).update(yd);
							
							/*List<YdmProductInlist> yi=this.getMapper(YdmProductInlistMapper.class).findWithCondition(null, " COILNO = '"+std1.getObjectno()+"'", null, 0, 0);
							if (yi!=null && yi.size()>0) {
								for (YdmProductInlist ydmP : yi) {
									this.getMapper(YdmProductInlistMapper.class).delete(ydmP.getInbillno());
								} 
							}*/ 
						}else {
							YdmProductButtresslist yb=new YdmProductButtresslist();
							this.getMapper(YdmProductButtresslistMapper.class).insert(yb);
							// 插入垛位信息
							if (ypo!=null) {
								YdmProductButtresslist ypb = new YdmProductButtresslist();
								ypb.setCreatedate(now);
								ypb.setCreater(username);
								ypb.setLayer(ypo.getLayer().intValue());
								ypb.setLocality(ypo.getLocality().intValue());
								if (ypo.getButtressno() != null) {
									ypb.setButtressno(ypo.getButtressno());
								}
								if (ypo.getStorageattr() != null) {
									ypb.setStorageattr(ypo.getStorageattr());
								}
								if (std.getAreano() != null) {
									ypb.setAreano(std.getAreano());
								}
								if (std1.getObjectno() != null) {
									ypb.setCoilno(std1.getObjectno());
								}
								if (std1.getBoxId() != null) {
									ypb.setBoxno(std1.getBoxId());
								}
								this.getMapper(YdmProductButtresslistMapper.class).doInsert(ypb); 
							}
						}
						
					}
					// 修改库存信息
					YdmProductDetail ypd = this.getMapper(YdmProductDetailMapper.class).doFind(std.getObjectno(), std.getBoxId());
					if (ypd != null) {
						ypd.setUpdatedate(now);
						ypd.setUpdater(username);
						if (!"2".equals(ypd.getState()))
							ypd.setState("2");
						this.getMapper(YdmProductDetailMapper.class).doUpdate(ypd);
						//调用生产计划模块物料跟踪撤销接口
						PrcMaterielProcess pmp =new PrcMaterielProcess();
						pmp.setObject_no(ypd.getCoilno());
						pmp.setPrc_code("5BYS10");
						pmp.setKeep_sametime_status(0);
						pmp.setRemark("装车撤销");
						//this.getBean(MesApiServiceImpl.class).ARRAYLIST(pmp).getState();
						String tmp = this.getBean(MesApiServiceImpl.class).ARRAYLIST(pmp).getState();
						if(tmp=="-1"){
							throw new Exception("出现程序异常！撤销跟踪失败！");
						}else if(tmp=="-2"){
							//throw new Exception("状态不是最后状态，不允许回退删除！撤销跟踪失败");
						}else{
							
						}
						// 成品   生产订单统计 统计量并修改生产订单状态
						try {
							if ("500203".equals(ypd.getStorageattr())) {
								this.getBean(PlnProdorderStatisticServiceImpl.class).prod_Stats(ypd.getCoilno(), 3, false);
							}
						} catch (Exception e) {
							throw new Exception("调用统计生产订单量接口出错");
						}
						
						String isOpen = this.getMapper(ComBaseInfoMapper.class).findById("9512").getMemo();
						if ("1".equals(isOpen)) {
						
							// 记录成本异动点：20230811刘侣
							ComBaseCbYdd cd = new ComBaseCbYdd();
							cd.setCoilStus("1"); // 综判前算半成品，综判入库后算成品
							cd.setInstDisp("01");
							cd.setDataTypeIdx("O");
							// 当前产线：
							String currentMachine = ypd.getCoilno().contains("S") ? "YTSX" : ypd.getCoilno().contains("L") ? "YTZZ" : ypd.getCoilno().contains("P") ? "YTPZ" : ypd.getCoilno().contains("T") ? "YTTH" : ypd.getCoilno().contains("K") ? "YTHJ" : ypd.getCoilno().contains("F") ? "YTZJ" : "YT1";
							cd.setLocNo(currentMachine); // 填当前产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
							cd.setInvQtyUnit("块");
							cd.setInvWidth(ypd.getWidth() != null ? String.valueOf(ypd.getWidth()) : "0");
							cd.setCreateId(userId);
							cd.setActivityId("69A");
							cd.setInvLength(ypd.getLength() != null ? String.valueOf(ypd.getLength()) : "0");
							cd.setManageip(currentMachine); // 填当前产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
							cd.setProdName(ypd.getProd_name());
							cd.setInvThick(ypd.getThick() != null ? String.valueOf(ypd.getThick()) : "0");
							
							String prevcoil = this.getBean(YdmProductInlistService.class).doQueryTl(ypd.getCoilno());
							// 上道产线：
							String prevMachine = prevcoil.contains("S") ? "YTSX" : prevcoil.contains("L") ? "YTZZ" : prevcoil.contains("P") ? "YTPZ" : prevcoil.contains("T") ? "YTTH" : prevcoil.contains("K") ? "YTHJ" : prevcoil.contains("F") ? "YTZJ" : "YT1";
							cd.setRefnoA(prevcoil); // 投料卷号
							cd.setSysId("IA");
							cd.setOrderItem(ypd.getOrderno());
							cd.setCrntMill(currentMachine); // 填当前产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
							cd.setBeTransUnit("t");
							cd.setExecJobFunc("D");
							ComBaseSteel cbs = this.getMapper(ComBaseSteelMapper.class).findById(ypd.getSteelcode());
							if (cbs != null) {
								cd.setAlloyNo(cbs.getSteel_name()); // 牌号
							}
							
							cd.setAcctDate(new SimpleDateFormat("yyyyMMdd").format(now));
							cd.setLastMill(prevMachine); // 填上道工序产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
							cd.setBeTransWgt(ypd.getFactweight() != null ? ypd.getFactweight() / 1000 : ypd.getFactweight());
//							cd.setProdTypeNo("CTR");
//							cd.setAppId("优特钢产出卷取消发货");
							cd.setInvId(ypd.getCoilno());
							cd.setInvQty("1");
							cd.setSrcFac("1");
							cd.setGrade("40740801".equals(ypd.getJudgeresult()) ? "1" : "1"); // 正品　1　协议　3　次品　5
							cd.setProdClassNo("H");
							
							// 增加取消综判异动点：20231130刘侣
							cd.setCoilStus("1"); // 综判前算半成品，综判入库后算成品
							cd.setActivityId("11AC");
							if ("507101".equals(ypd.getObject_attr()) && "40740802".equals(ypd.getJudgeresult())) {
								cd.setActivityId("11AZ");
							}
							String currentMName = ypd.getCoilno().contains("S") ? "酸洗" : ypd.getCoilno().contains("L") ? "冷轧" : ypd.getCoilno().contains("P") ? "平整" : ypd.getCoilno().contains("T") ? "退火" : ypd.getCoilno().contains("K") ? "横剪" : ypd.getCoilno().contains("F") ? "分条" : "原料";
							cd.setAppId("优特" + currentMName + "取消综判");
							cd.setProdTypeNo(ypd.getCoilno().length() > 8 ? "CTR" : ypd.getMaterailcoilno().startsWith("L") ? "CCR" : "HCR");
							cd.setCrntMill(currentMachine); // 填上道产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
							cd.setInvId(ypd.getCoilno().length() <= 8 ? ypd.getMaterailcoilno() : ypd.getCoilno());
							
							// 综判异动点发送：在最后一倒工序完成后发送，不再是发货时发送 20240425刘侣
//							this.getBean(SlmFundFirstDetailService.class).doCbDataIns(cd, cd.getActivityId(), ypd.getMaterailcoilno());
							// end 20240425刘侣
							
							// 存入表：1、上料一抛：原料转库（47）（原料上料准备生产时抛送）
							cd.setActivityId("69A");
							cd.setExecJobFunc("D");
							cd.setDataTypeIdx("O");
							cd.setProdTypeNo(ypd.getCoilno().length() > 8 ? "CTR" : ypd.getMaterailcoilno().startsWith("L") ? "CCR" : "HCR");
							cd.setCoilStus("1"); // 综判前算半成品0，综判入库后算成品1
							cd.setCrntMill(currentMachine); // 填上道产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
							cd.setManageip(currentMachine); // 填上道产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
							cd.setLocNo(currentMachine); // 填上道产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
//							String currentMName = ypd.getCoilno().contains("S") ? "酸洗" : ypd.getCoilno().contains("L") ? "冷轧" : ypd.getCoilno().contains("P") ? "平整" : ypd.getCoilno().contains("T") ? "退火" : ypd.getCoilno().contains("K") ? "横剪" : ypd.getCoilno().contains("F") ? "分条" : "原料";
//							String prevMName = prevcoil.contains("S") ? "酸洗" : prevcoil.contains("L") ? "冷轧" : prevcoil.contains("P") ? "平整" : prevcoil.contains("T") ? "退火" : prevcoil.contains("K") ? "开平" : prevcoil.contains("F") ? "分条" : "原料";
							cd.setAppId("优特" + currentMName + "取消发货");
							
							if (ypd.getCoilno().length() <= 8) {
								cd.setInvId(ypd.getMaterailcoilno());
							}

							// setSrcFac根据卷的物料属性去判断：20231031刘侣
							cd.setSrcFac("507101".equals(ypd.getObject_attr()) ? "1" : "3");
							
							this.getBean(SlmFundFirstDetailService.class).doCbDataIns(cd, cd.getActivityId(), ypd.getMaterailcoilno());
						}
						
						// 切换后不再需要向冷轧系统发送数据：20231116刘侣
						// 移送优特钢标识0MES待移送 1已移送优特钢未接收 2优特钢已接收 3优特钢已返回MES未收
//						if ((ypd.getLzorderno().startsWith("WZ53") || ypd.getLzorderno().startsWith("WZ52") || ypd.getLzorderno().startsWith("WZ51"))) {
//							// 向冷轧厂返写：
//							ResultModel rmFX = this.getBean(IfSlmContractInfoServiceImpl.class).doUpdateC_TBL02_COIL_COMM_ROUTE(ypd.getMaterailcoilno(), "3");
//							if (rmFX.getState()==null || !"200".equals(rmFX.getState())) {
//								throw new Exception("撤销装车失败，请联系系统维护人员route：3");
//							}
//							// 插入日志：
//							MesOprLog mol2 = new MesOprLog("物流管理", "装车管理", "撤销装车", username, opr_time, ypd.getCoilno(), null, null, null, "冷轧厂加工委托卷子返写状态成功：3");
//							this.getMapper(MesOprLogMapper.class).insert(mol2);
//						}
					}
				}
			}
			if (cp.getMemo1() != null && cp.getMemo1() != "") {
				// 修改理货单主表
				SpmDistrbuteMain sdm = this.getMapper(SpmDistrbuteMainMapper.class).findById(cp.getMemo1());
				if (sdm != null) {
					sdm.setLoadfactweight(sdm.getLoadfactweight() - loadfactweight);
					sdm.setLoadtheoryweight(sdm.getLoadtheoryweight() - loadtheoryweight);
					if (sdm.getQuantity() == null)
						sdm.setQuantity(0);
					sdm.setQuantity(sdm.getQuantity() - count);

					if ("2".equals(sdm.getState()))
						sdm.setState("1");

					if (sdm.getQuantity() == 0 && ("1".equals(sdm.getState()) || "2".equals(sdm.getState()))) {
						sdm.setState("0");
						sdm.setCarno(null);
						this.getMapper(SpmDistrbuteMainMapper.class).doExitCarNo("",sdm.getDeliveryno());
					}
					sdm.setUpdatedate(now);
					sdm.setUpdater(username);
					this.getMapper(SpmDistrbuteMainMapper.class).update(sdm);
					
				}
			}
			// 修改提货单主表
			if (cp.getMemo2() != null && cp.getMemo2() != "") {
				SpmDelivery sd = this.getMapper(SpmDeliveryMapper.class).findById(cp.getMemo2());
				if (sd != null) {
					sd.setUpdatedate(now);
					sd.setUpdater(username);
					sd.setLoadFactWeight(sd.getLoadFactWeight() - loadfactweight);
					sd.setLoadTheoryWeight(sd.getLoadTheoryWeight() - loadtheoryweight);
					if (sd.getQuantity() == null)
						sd.setQuantity(0);
					sd.setQuantity(sd.getQuantity() - count);
					if (("4".equals(sd.getState())||"3".equals(sd.getState())) && sd.getQuantity() == 0){
						sd.setState("2");
					}
					else{    
						if(sd.getQuantity() == 0){
						    sd.setState("2");
					     }else{
					    	 sd.setState("3");
					     }
					}
					sd.setCar_seq("");
					this.getMapper(SpmDeliveryMapper.class).update(sd);
				}
				
				// 修改提货单从表		
				List<SpmDeliveryDetail> lisSdd = new ArrayList<SpmDeliveryDetail>();
				if (Strlist != null && Strlist.size() > 0) {
					lisSdd = this.getMapper(SpmDeliveryDetailMapper.class).dofindWeight(Strlist,"1");
				}
				if (lisSdd != null && lisSdd.size() > 0) {
					for (SpmDeliveryDetail add1 : lisSdd) {
						SpmDeliveryDetail sdd = new SpmDeliveryDetail();
						if(add1.getDeliveryno()!=null&&!"".equals(add1.getDeliveryno())&&add1.getLineNo()!=null&&!"".equals(add1.getLineNo())){
							sdd = this.getMapper(SpmDeliveryDetailMapper.class).dofind(add1.getDeliveryno(), add1.getLineNo());
						}
						if (sdd.getLineNo() != null&&!"".equals(sdd.getLineNo())) {
							sdd.setStarttime(now);
							if ((sdd.getCarno() == null || sdd.getCarno() == "" || " ".equals(sdd.getCarno())) && cp.getMemo4() != null
									&& cp.getMemo4() != "")
								sdd.setCarno(cp.getMemo4());
							if ("3".equals(sdd.getState()) && sdd.getQuantity() == 0)
								sdd.setState("2");
							sdd.setUpdatedate(now);
							sdd.setUpdater(username);
							if (sdd.getLoadFactWeight() == null) {
								sdd.setLoadFactWeight((double) 0);
							} else {
								sdd.setLoadFactWeight(sdd.getLoadFactWeight() - add1.getLoadFactWeight());
							}
							if (sdd.getLoadTheoryWeight() == null) {
								sdd.setLoadTheoryWeight((double) 0);
							} else {
								sdd.setLoadTheoryWeight(sdd.getLoadTheoryWeight() - add1.getLoadTheoryWeight());
							}
							if (sdd.getQuantity() == null)
								sdd.setQuantity(0);
							sdd.setQuantity(sdd.getQuantity() - add1.getQuantity());
							sdd.setOvertime(now);
							this.getMapper(SpmDeliveryDetailMapper.class).update(sdd);
						}
					}
				
					
				}
			}
			try {
				if (!cp.getSortField().contains("到优特") && !"9".equals(cp.getMemo5()) && !"8".equals(cp.getMemo5())) {
					int countS = this.getMapper(SlmLadingBillDetailMapper.class).doCountStorageByBillno(cp.getMemo2(),"500205");
					//判断提单对应的仓库是不是贸易库，如果有贸易库的卷子，则不需要发送门禁数据
					if (countS == 0) {							
						/*CommonPage<SpmDelivery> cp1 = new CommonPage<SpmDelivery>();
						cp1.setMemo1(cp.getMemo2());
						cp1.setMemo2(cp.getMemo4());//撤销装车的原因
						ResultModel rm1 = this.getBean(LmsPassportinfoServiceImpl.class).doDeletePassportInfo(cp1);
						if (!"200".equals(rm1.getState())) {
							throw new Exception(rm1.getMsgInfo());
						}*/
						this.getMapper(LmsPassportinfoMapper.class).delete("Y"+cp.getMemo2());
					}
				}
			} catch (Exception e) {
				throw new Exception("撤销门禁系统接口出错!"+ e.getMessage());
			}
			//日志
			MesOprLog mol = new MesOprLog("物流管理", "装车管理", "撤销装车", username, opr_time, null, null, cp.getMemo2(), null, null);
			this.getMapper(MesOprLogMapper.class).insert(mol);
		} else {
			rm.setMsgInfo("传入的数据为空!");
		}
		rm.setState("200");
		
		return rm;
	}

	
	/**
	 * 废副品装车管理 撤销装车 记得传界面上的区域编码 memo1-3传理货单号，提货单号，提货单子编号,sortField运输方式
	 * @throws Exception 
	 */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doCancelF(CommonPage<SpmTransportDetail> cp) throws Exception {
		ResultModel rm = new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String userId = (String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		List<SpmTransportDetail> list = cp.getObjectList();//理货单明细数据
		String deliveryno = cp.getMemo2();//提货单号
		
		ArrayList<String> Strlist = new ArrayList<String>();
		if (list != null && list.size() > 0) {
			Integer count = list.size();
			double loadtheoryweight = 0;
			double loadfactweight = 0;
			
			SpmDelivery spm = this.getMapper(SpmDeliveryMapper.class).findById(deliveryno);
			if (spm != null && !"4".equals(spm.getState()) && !"3".equals(spm.getState())) {
				rm.setState("500");
				rm.setMsgInfo("提货单状态发生改变! 请重新查询后操作!");
				throw  new Exception("提货单状态发生改变! 请重新查询后操作!");
			}
			//20210511 判断当前提单是否已经下发门禁
			PassportInfo ppi = this.getMapper(LmsPassportinfoMapper.class).findById("Y"+deliveryno);
			if (ppi!=null && "1".equals(ppi.getIs_send())) {
				rm.setState("500");
				rm.setMsgInfo("当前提单已经下发门禁，请先删除门禁！");
				throw  new Exception("当前提单已经下发门禁，请先删除门禁！");
			}
			for (SpmTransportDetail std : list) {
				if ((std.getObjectno() != null && std.getObjectno() != "")
						|| (std.getBillNo() != null && std.getBillNo() != "")) {
					
					SpmTransportDetail std1 = this.getMapper(SpmTransportDetailMapper.class)
							.doFind(std.getObjectno(), std.getBillNo());
					if (std1 != null) {
						Strlist.add(std.getObjectno());
						loadtheoryweight += std1.getTheoryweight()==null?0:std1.getTheoryweight();
						loadfactweight += std1.getFactweight()==null?0:std1.getFactweight();
						// 修改装车单从表
						std1.setUpdatedate(now);
						std1.setUpdater(username);
						
						if ("0".equals(std1.getState())) {
							rm.setState("500");
							rm.setMsgInfo("数据已被撤销 请重新查询后操作!");
							throw  new Exception("数据已被撤销 请重新查询后操作!");
						}
						
						if ("1".equals(std1.getState()))
							std1.setState("0"); 
							
						this.getMapper(SpmTransportDetailMapper.class).doUpdate(std1);
					
					}
					
//						
//						String isOpen = this.getMapper(ComBaseInfoMapper.class).findById("9512").getMemo();
//						if ("1".equals(isOpen)) {
//						
//							// 记录成本异动点：20230811刘侣
//							ComBaseCbYdd cd = new ComBaseCbYdd();
//							cd.setCoilStus("1"); // 综判前算半成品，综判入库后算成品
//							cd.setInstDisp("01");
//							cd.setDataTypeIdx("O");
//							// 当前产线：
//							String currentMachine = ypd.getCoilno().contains("S") ? "YTSX" : ypd.getCoilno().contains("L") ? "YTZZ" : ypd.getCoilno().contains("P") ? "YTPZ" : ypd.getCoilno().contains("T") ? "YTTH" : ypd.getCoilno().contains("K") ? "YTHJ" : ypd.getCoilno().contains("F") ? "YTZJ" : "YT1";
//							cd.setLocNo(currentMachine); // 填当前产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
//							cd.setInvQtyUnit("块");
//							cd.setInvWidth(ypd.getWidth() != null ? String.valueOf(ypd.getWidth()) : "0");
//							cd.setCreateId(userId);
//							cd.setActivityId("69A");
//							cd.setInvLength(ypd.getLength() != null ? String.valueOf(ypd.getLength()) : "0");
//							cd.setManageip(currentMachine); // 填当前产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
//							cd.setProdName(ypd.getProd_name());
//							cd.setInvThick(ypd.getThick() != null ? String.valueOf(ypd.getThick()) : "0");
//							
//							String prevcoil = this.getBean(YdmProductInlistService.class).doQueryTl(ypd.getCoilno());
//							// 上道产线：
//							String prevMachine = prevcoil.contains("S") ? "YTSX" : prevcoil.contains("L") ? "YTZZ" : prevcoil.contains("P") ? "YTPZ" : prevcoil.contains("T") ? "YTTH" : prevcoil.contains("K") ? "YTHJ" : prevcoil.contains("F") ? "YTZJ" : "YT1";
//							cd.setRefnoA(prevcoil); // 投料卷号
//							cd.setSysId("IA");
//							cd.setOrderItem(ypd.getOrderno());
//							cd.setCrntMill(currentMachine); // 填当前产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
//							cd.setBeTransUnit("t");
//							cd.setExecJobFunc("D");
//							ComBaseSteel cbs = this.getMapper(ComBaseSteelMapper.class).findById(ypd.getSteelcode());
//							if (cbs != null) {
//								cd.setAlloyNo(cbs.getSteel_name()); // 牌号
//							}
//							
//							cd.setAcctDate(new SimpleDateFormat("yyyyMMdd").format(now));
//							cd.setLastMill(prevMachine); // 填上道工序产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
//							cd.setBeTransWgt(ypd.getFactweight() != null ? ypd.getFactweight() / 1000 : ypd.getFactweight());
////							cd.setProdTypeNo("CTR");
////							cd.setAppId("优特钢产出卷取消发货");
//							cd.setInvId(ypd.getCoilno());
//							cd.setInvQty("1");
//							cd.setSrcFac("1");
//							cd.setGrade("40740801".equals(ypd.getJudgeresult()) ? "1" : "1"); // 正品　1　协议　3　次品　5
//							cd.setProdClassNo("H");
//							
//							// 增加取消综判异动点：20231130刘侣
//							cd.setCoilStus("1"); // 综判前算半成品，综判入库后算成品
//							cd.setActivityId("11AC");
//							if ("507101".equals(ypd.getObject_attr()) && "40740802".equals(ypd.getJudgeresult())) {
//								cd.setActivityId("11AZ");
//							}
//							String currentMName = ypd.getCoilno().contains("S") ? "酸洗" : ypd.getCoilno().contains("L") ? "冷轧" : ypd.getCoilno().contains("P") ? "平整" : ypd.getCoilno().contains("T") ? "退火" : ypd.getCoilno().contains("K") ? "横剪" : ypd.getCoilno().contains("F") ? "分条" : "原料";
//							cd.setAppId("优特" + currentMName + "取消综判");
//							cd.setProdTypeNo(ypd.getCoilno().length() > 8 ? "CTR" : ypd.getMaterailcoilno().startsWith("L") ? "CCR" : "HCR");
//							cd.setCrntMill(currentMachine); // 填上道产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
//							cd.setInvId(ypd.getCoilno().length() <= 8 ? ypd.getMaterailcoilno() : ypd.getCoilno());
//							
//							// 综判异动点发送：在最后一倒工序完成后发送，不再是发货时发送 20240425刘侣
////							this.getBean(SlmFundFirstDetailService.class).doCbDataIns(cd, cd.getActivityId(), ypd.getMaterailcoilno());
//							// end 20240425刘侣
//							
//							// 存入表：1、上料一抛：原料转库（47）（原料上料准备生产时抛送）
//							cd.setActivityId("69A");
//							cd.setExecJobFunc("D");
//							cd.setDataTypeIdx("O");
//							cd.setProdTypeNo(ypd.getCoilno().length() > 8 ? "CTR" : ypd.getMaterailcoilno().startsWith("L") ? "CCR" : "HCR");
//							cd.setCoilStus("1"); // 综判前算半成品0，综判入库后算成品1
//							cd.setCrntMill(currentMachine); // 填上道产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
//							cd.setManageip(currentMachine); // 填上道产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
//							cd.setLocNo(currentMachine); // 填上道产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
////							String currentMName = ypd.getCoilno().contains("S") ? "酸洗" : ypd.getCoilno().contains("L") ? "冷轧" : ypd.getCoilno().contains("P") ? "平整" : ypd.getCoilno().contains("T") ? "退火" : ypd.getCoilno().contains("K") ? "横剪" : ypd.getCoilno().contains("F") ? "分条" : "原料";
////							String prevMName = prevcoil.contains("S") ? "酸洗" : prevcoil.contains("L") ? "冷轧" : prevcoil.contains("P") ? "平整" : prevcoil.contains("T") ? "退火" : prevcoil.contains("K") ? "开平" : prevcoil.contains("F") ? "分条" : "原料";
//							cd.setAppId("优特" + currentMName + "取消发货");
//							
//							if (ypd.getCoilno().length() <= 8) {
//								cd.setInvId(ypd.getMaterailcoilno());
//							}
//
//							// setSrcFac根据卷的物料属性去判断：20231031刘侣
//							cd.setSrcFac("507101".equals(ypd.getObject_attr()) ? "1" : "3");
//							
//							this.getBean(SlmFundFirstDetailService.class).doCbDataIns(cd, cd.getActivityId(), ypd.getMaterailcoilno());
//						}
						
					
				}
			}
			if (cp.getMemo1() != null && cp.getMemo1() != "") {
				// 修改理货单主表
				SpmDistrbuteMain sdm = this.getMapper(SpmDistrbuteMainMapper.class).findById(cp.getMemo1());
				if (sdm != null) {
					sdm.setLoadfactweight(sdm.getLoadfactweight() - loadfactweight);
					sdm.setLoadtheoryweight(sdm.getLoadtheoryweight() - loadtheoryweight);
					if (sdm.getQuantity() == null)
						sdm.setQuantity(0);
					sdm.setQuantity(sdm.getQuantity() - count);

					if ("2".equals(sdm.getState()))
						sdm.setState("1");

					if (sdm.getQuantity() == 0 && ("1".equals(sdm.getState()) || "2".equals(sdm.getState()))) {
						sdm.setState("0");
						sdm.setCarno(null);
						this.getMapper(SpmDistrbuteMainMapper.class).doExitCarNo("",sdm.getDeliveryno());
					}
					sdm.setUpdatedate(now);
					sdm.setUpdater(username);
					this.getMapper(SpmDistrbuteMainMapper.class).update(sdm);
					
				}
			}
			// 修改提货单主表
			if (cp.getMemo2() != null && cp.getMemo2() != "") {
				SpmDelivery sd = this.getMapper(SpmDeliveryMapper.class).findById(cp.getMemo2());
				if (sd != null) {
					sd.setUpdatedate(now);
					sd.setUpdater(username);
					sd.setLoadFactWeight(sd.getLoadFactWeight() - loadfactweight);
					sd.setLoadTheoryWeight(sd.getLoadTheoryWeight() - loadtheoryweight);
					if (sd.getQuantity() == null)
						sd.setQuantity(0);
					sd.setQuantity(sd.getQuantity() - count);
					if (("4".equals(sd.getState())||"3".equals(sd.getState())) && sd.getQuantity() == 0){
						sd.setState("2");
					}
					else{    
						if(sd.getQuantity() == 0){
						    sd.setState("2");
					     }else{
					    	 sd.setState("3");
					     }
					}
					sd.setCar_seq("");
					this.getMapper(SpmDeliveryMapper.class).update(sd);
				}
				
				// 修改提货单从表	
				SpmDeliveryDetail sdd = new SpmDeliveryDetail();
				sdd.setStarttime(now);
				sdd.setCarno(cp.getMemo4());
				sdd.setState("2");
				sdd.setUpdatedate(now);
				sdd.setUpdater(username);
				sdd.setLoadFactWeight((double) 0);
				sdd.setLoadTheoryWeight((double) 0);
				sdd.setQuantity(0);
				sdd.setOvertime(now);
				
				this.getMapper(SpmDeliveryDetailMapper.class).doUpdateZCF(sdd);
			}
			try {
				if (!cp.getSortField().contains("到优特") && !"9".equals(cp.getMemo5()) && !"8".equals(cp.getMemo5())) {
				
					this.getMapper(LmsPassportinfoMapper.class).delete("Y"+cp.getMemo2());
					
				}
			} catch (Exception e) {
				throw new Exception("撤销门禁系统接口出错!"+ e.getMessage());
			}
			//日志
			MesOprLog mol = new MesOprLog("物流管理", "废副品装车管理", "撤销装车", username, opr_time, null, null, cp.getMemo2(), null, null);
			this.getMapper(MesOprLogMapper.class).insert(mol);
		} else {
			rm.setMsgInfo("传入的数据为空!");
		}
		rm.setState("200");
		
		return rm;
	}

	
	/**
	 * 打印发货单明细
	 */
	public CommonPage<SpmTransportDetail> doQueryWebByDy(CommonPage<SpmTransportDetail> cp) {
		CommonPage<SpmTransportDetail> commonPage = new CommonPage<SpmTransportDetail>();
		SpmTransportDetail spm = this.getMapper(SpmTransportDetailMapper.class)
				.GexXxXinXi(cp.getObject().getOutbillno());
		commonPage.setObject(spm);
		SpmTransportDetail spms = new SpmTransportDetail();
		spms.setOutbillno(cp.getObject().getOutbillno());
		List<SpmTransportDetail> spmList = this.getMapper(SpmTransportDetailMapper.class).find(spms, 0, 0);
		commonPage.setObjectList(spmList);
		return commonPage;

	}
	
	/**
	 * 修改车号
	 */

	public ResultModel doExitCarNo(CommonPage<SpmDistrbuteMain> cp) {
		ResultModel rm =new ResultModel();
		try {
			this.getMapper(SpmDistrbuteMainMapper.class).doExitCarNo(cp.getObject().getCarno(), cp.getObject().getDeliveryno());
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			e.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 查询"装车单号"所对应的车牌号，如果车牌号相同返回true,则false。
	 * @param str：“'装车单号1','装车单号2','装车单号3',...”
	 * @return 如果车牌号相同返回true,则false。
	 */
	public boolean doQueryCarno(String str){
		List<SpmDistrbuteMain> list = this.getMapper(SpmDistrbuteMainMapper.class).doQueryCarno(str);
		HashSet<String> ss = new  HashSet<>();
		for (SpmDistrbuteMain s : list) {
			if (s.getCarno()!=null&&!"".equals(s.getCarno())) {//说明s.getCarno()是一个有效的车牌号
				ss.add(s.getCarno());
			}else{
				return false;
			}
		}
		return ss.size()==1;
	}
	
	/**
	 * 编辑火车车皮号
	 * @param cp
	 * @return
	 * @throws Exception 
	 */
	public ResultModel doUpdateTrainNo(CommonPage<SpmDistrbuteMain> cp) throws Exception {
		ResultModel rm =new ResultModel();
		String train_no =cp.getMemo1();//火车车皮号
		List<SpmDistrbuteMain> list = cp.getObjectList();
		if (train_no==null || "".equals(train_no)) {
			throw new Exception("火车车皮号不能为空");
		}
		if (list==null || list.size()<=0) {
			throw new Exception("请传入参数");
		}
		for (SpmDistrbuteMain sdm : list) {
			SpmDistrbuteMain newSdm = new SpmDistrbuteMain();
			newSdm.setDistrbuteno(sdm.getDistrbuteno());
			newSdm.setTrain_no(train_no);
			this.getMapper(SpmDistrbuteMainMapper.class).update(newSdm);
		}
		rm.setState("200");
		rm.setMsgInfo("调整火车车皮号成功");
		return rm;
	}
	//1077
}