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

package market.Lms.Logistics.impl;

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

import market.Api.Slm.impl.SlmApiServiceImpl;
import market.Com.mapper.ComBaseInfoMapper;
import market.Com.mapper.ComBaseSteelMapper;
import market.Com.mapper.PbModelDbMapper;
import market.Com.pb.DoubleUtil;
import market.Com.vo.ComBaseInfo;
import market.Com.vo.ComBaseSteel;
import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
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.SpmDeliveryService;
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.mapper.YdmProductDetailMapper;
import market.Lms.Warehouse.vo.YdmProductDetail;
import market.Mes.Opr.mapper.MesOprLogMapper;
import market.Mes.Opr.vo.MesOprLog;
import market.Mes.OrderManager.Plan.mapper.PlnProdorderMapper;
import market.Mes.OrderManager.Plan.vo.PlnProdorder;
import market.Qms.qcm.mapper.QcmZbsBillMapper;
import market.Qms.qcm.service.impl.QcmZbsBillServiceImpl;
import market.Qms.qcm.vo.QcmZbsBill;
import market.Slm.ContractManagement.mapper.SlmContractIdenOrgMapper;
import market.Slm.ContractManagement.mapper.SlmContractLineInfoMapper;
import market.Slm.ContractManagement.vo.SlmContractIdenOrg;
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.mapper.SlmLadingBillLineMapper;
import market.Slm.DeliveryManagement.vo.SlmLadingBillDetail;
import market.Slm.DeliveryManagement.vo.SlmLadingBillHeat;
import market.Slm.DeliveryManagement.vo.SlmLadingBillLine;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

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

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
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="SpmDeliveryService")
public class SpmDeliveryServiceImpl extends BaseServiceImpl<SpmDelivery, Object> implements SpmDeliveryService {

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

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

	/**
	 * 理货单管理 提货单明细
	 * */
	public ResultModel doQueryWebBySQlDetail(CommonPage<SpmDeliveryDetail> cp) {
		ResultModel rm=new ResultModel();
		int pageSize=cp.getPageSize();
		int pageIndex=cp.getPageIndex();
		PageModel<SpmDeliveryDetail> pm = new PageModel<SpmDeliveryDetail>(pageIndex,pageSize);
		try {
			pm.setRows(this.getMapper(SpmDeliveryDetailMapper.class).doQueryWebBySQL
					((pageIndex-1)*pageSize, (pageIndex-1)*pageSize+pageSize,cp.getObject().getDeliveryno()));
			pm.setTotal(this.getMapper(SpmDeliveryDetailMapper.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 doQueryWebBySQLDelivery(CommonPage<SpmDelivery> cp) {
		ResultModel rm=new ResultModel();
		int pageSize=cp.getPageSize();
		int pageIndex=cp.getPageIndex();
		PageModel<YdmProductDetail> pm = new PageModel<YdmProductDetail>(pageIndex,pageSize);
		try {
			String deliveryno=cp.getObject().getDeliveryno();
			if(deliveryno!=null&&deliveryno!="") {
				//通过提货单号获取销售订单编号
				List<String> listorderno=this.getMapper(SpmDeliveryMapper.class).getOrderNoB(deliveryno);
				//查询库存信息
				pm.setRows(this.getMapper(YdmProductDetailMapper.class).doQueryWebBySQLDeliveryB
						((pageIndex-1)*pageSize, (pageIndex-1)*pageSize+pageSize,listorderno,cp.getObject().getStorageattr(),cp.getObject().getState(),deliveryno));
				pm.setTotal(this.getMapper(YdmProductDetailMapper.class).doQueryWebBySQLDeliveryCountB
						(listorderno,cp.getObject().getStorageattr(),cp.getObject().getState(),deliveryno));
				rm.setData(pm);
				rm.setState("200");
			}
			else {
				rm.setState("500");
				rm.setMsgInfo("传入参数为空!");
			}
		}
		catch(Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("库存查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 理货单管理 理货单编制
	 * startTime/endTime传提单开始/结束日期(精确到分秒)，memo1传车号，memo2传提货单号,memo3传仓库编码
	 * @throws Exception 
	 * */
	public ResultModel doWeave(CommonPage<YdmProductDetail> cp) throws Exception {
		ResultModel rm=new ResultModel();
		Date now = new Date();
		List<YdmProductDetail> list=cp.getObjectList();
		try {
			String username=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			double disfactweight=0;
			double distheoryweight=0;
			Integer distrbutequantity=list.size();
			String distrbuteno=this.createDistrbuteNO();
			SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			//修改提货单从表
			for(YdmProductDetail ypd:list) {
				if(ypd.getFactweight() ==null||"".equals(ypd.getFactweight())){
					ypd.setFactweight((double) 0);
				}
				if(ypd.getTheoryweight() ==null||"".equals(ypd.getTheoryweight())){
					ypd.setTheoryweight((double) 0);
				}
				disfactweight+=ypd.getFactweight();
				distheoryweight+=ypd.getTheoryweight();
				String lineno;
				if(cp.getMemo2()!=null&&cp.getMemo2()!=""&&ypd.getOrderno()!=null&&ypd.getOrderno()!=""){
					lineno=this.getMapper(SpmDeliveryMapper.class).getLineNo(cp.getMemo2(), ypd.getOrderno());
					if(lineno!=null&&lineno!=""){
						SpmDeliveryDetail sdd=new SpmDeliveryDetail();
						sdd=this.getMapper(SpmDeliveryDetailMapper.class).dofind(cp.getMemo2(), lineno);
						if(sdd!=null){
							sdd.setCreatedate(now);
							sdd.setCreater(username);
							if(cp.getStartTime()!=null&&cp.getStartTime()!="")
								sdd.setPlanStartTime(formatter.parse(cp.getStartTime()));
							if(cp.getEndTime()!=null&&cp.getEndTime()!="")
								sdd.setPlanEndTime(formatter.parse(cp.getEndTime()));
							sdd.setCarno(cp.getMemo1());
							if(sdd.getDistrbutequantity()==null)
								sdd.setDistrbutequantity(0);
							sdd.setDistrbutequantity(sdd.getDistrbutequantity()+1);
							if(sdd.getDisFactWeight()==null){
								sdd.setDisFactWeight(ypd.getFactweight());
							} else{
								sdd.setDisFactWeight(sdd.getDisFactWeight()+ypd.getFactweight());
							}
							
							if(sdd.getDisTheoryWeight()==null){
								sdd.setDisTheoryWeight(ypd.getTheoryweight());
							}
							else{
								sdd.setDisTheoryWeight(sdd.getDisTheoryWeight()+ypd.getTheoryweight());
							}
							this.getMapper(SpmDeliveryDetailMapper.class).doUpdateA(sdd);
						}
						//插入装车单从表
						if((ypd.getCoilno()!=null&&ypd.getCoilno()!="")||(ypd.getBoxno()!=null&&ypd.getBoxno()!="")){
							SpmTransportDetail std=new SpmTransportDetail();
							YdmProductDetail ypd1=this.getMapper(YdmProductDetailMapper.class).doFind(ypd.getCoilno(), ypd.getBoxno());
							if(ypd1!=null) {
								std.setCreatedate(now);
								std.setCreater(username);
								std.setState("0");
								std.setDistrbuteno(distrbuteno);
								std.setBillNo(cp.getMemo2());
								
								// lineno的值改成和 slmLadingBillDetail 表里的lineNo一致：20240105刘侣
								// 原来是：std.setLineNo(lineno);
								List<SlmLadingBillDetail> detailL = this.getMapper(SlmLadingBillDetailMapper.class).findWithCondition(null, " BILL_NO='"+std.getBillNo()+"' and COILNO='"+ypd.getCoilno()+"'", null, 0, 0);
								if (detailL.size() > 0) {
									std.setLineNo(detailL.get(0).getLine_no());
								}
								// end
								
								if (ypd1.getCoilno()!=null) {
									std.setObjectno(ypd1.getCoilno());
								}
								if (ypd1.getCoiltype()!=null) {
									std.setObjectnotype(ypd1.getCoiltype());
								}
								if (ypd1.getMaterailtype()!=null) {
									std.setMaterailtype(ypd1.getMaterailtype());
								}
								if (ypd1.getSource()!=null) {
									std.setSource(ypd1.getSource());
								}
								if (ypd1.getMaterailsupplier()!=null) {
									std.setMaterailsupplier(ypd1.getMaterailsupplier());
								}
								if (ypd1.getIsbox()!=null) {
									std.setIsbox(ypd1.getIsbox());
								}
								if (ypd1.getBoxno()!=null) {
									std.setBoxId(ypd1.getBoxno());
								}
								if (ypd1.getDrawingno()!=null) {
									std.setBoxDrawingNo(ypd1.getDrawingno());
								}
								if (ypd1.getBatchno()!=null) {
									std.setBatchno(ypd1.getBatchno());
								}
								if (ypd1.getBatchno()!=null) {
									std.setHeatno(ypd1.getBatchno());
								}
								if (ypd1.getSmpno()!=null) {
									std.setSmpNo(ypd1.getSmpno());
								}
								if (ypd1.getManagementno()!=null) {
									std.setManagementno(ypd1.getManagementno());
								}
								if (ypd1.getStorageattr()!=null) {
									std.setStorageattr(ypd1.getStorageattr());
								}
								if (ypd1.getProd_code()!=null) {
									std.setPrdCode(ypd1.getProd_code());
								}
								if (ypd1.getProd_name()!=null) {
									std.setPrdName(ypd1.getProd_name());
								}
								if (ypd1.getStd_code()!=null) {
									std.setStdCode(ypd1.getStd_code());
								}
								if (ypd1.getStd_name()!=null) {
									std.setStdName(ypd1.getStd_name());
								}
								if (ypd1.getUse_code()!=null) {
									std.setUsgCode(ypd1.getUse_code());
								}
								if (ypd1.getUse_name()!=null) {
									std.setUsgName(ypd1.getUse_name());
								}
								if (ypd1.getPostid()!=null) {
									std.setPostid(ypd1.getPostid());
								}
								if (ypd1.getThick()!=null) {
									std.setHeight(ypd1.getThick());
								}
								if (ypd1.getWidth()!=null) {
									std.setWidth(ypd1.getWidth());
								}
								if (ypd1.getLength()!=null) {
									std.setLength(ypd1.getLength());
								}
								if (ypd1.getDiameter_inn()!=null) {
									std.setInterdiameter(ypd1.getDiameter_inn());
								}
								if (ypd1.getDiameter_out()!=null) {
									std.setDiameter(ypd1.getDiameter_out());
								}
								if (ypd1.getQuantity()!=null) {
									std.setQuantity(ypd1.getQuantity());
								}
								if (ypd1.getTheoryweight()!=null) {
									std.setTheoryweight(ypd1.getTheoryweight());
								}
								if (ypd1.getCoreweight()!=null) {
									std.setCoreweight(ypd1.getCoreweight());
								}
								if (ypd1.getGrossweight()!=null) {
									std.setGrossweight(ypd1.getGrossweight());
								}
								if (ypd1.getPackweight()!=null) {
									std.setPackweight(ypd1.getPackweight());
								}
								if (ypd1.getFactweight()!=null) {
									std.setFactweight(ypd1.getFactweight());
								}
								if (ypd1.getCustomer_nm()!=null) {
									std.setCustomerNm(ypd1.getCustomer_nm());
								}
								if (ypd1.getCustomer_no()!=null) {
									std.setCustomerNo(ypd1.getCustomer_no());
								}
								if (ypd1.getReceiv_no()!=null) {
									std.setReceivNo(ypd1.getReceiv_no());
								}
								if (ypd1.getReceiv_nm()!=null) {
									std.setReceivNm(ypd1.getReceiv_nm());
								}
								if (ypd1.getOrderno()!=null) {
									std.setOrderno(ypd1.getOrderno());
								}
								if (ypd1.getProdorderno()!=null) {
									std.setProdorderno(ypd1.getProdorderno());
								}
								if (ypd1.getSteelcode()!=null) {
									std.setSteelcode(ypd1.getSteelcode());
								}
								if (ypd1.getJudgesteelcode()!=null) {
									std.setJudgesteelcode(ypd1.getJudgesteelcode());
								}
								if (ypd1.getPacking_group()!=null) {
									std.setPackingGroup(ypd1.getPacking_group());
								}
								if (ypd1.getChemresult()!=null) {
									std.setChemresult(ypd1.getChemresult());
								}
								if (ypd1.getSizeresult()!=null) {
									std.setSizeresult(ypd1.getSizeresult());
								}
								if (ypd1.getSurfaceresult()!=null) {
									std.setSurfaceresult(ypd1.getSurfaceresult());
								}
								if (ypd1.getWeightresult()!=null) {
									std.setWeightresult(ypd1.getWeightresult());
								}
								if (ypd1.getJudgeresult()!=null) {
									std.setJudgeresult(ypd1.getJudgeresult());
								}
								if (ypd1.getPhysresult()!=null) {
									std.setPhysresult(ypd1.getPhysresult());
								}
								if (ypd1.getSpyresult()!=null) {
									std.setSpyresult(ypd1.getSpyresult());
								}
								if (ypd1.getProducedate()!=null) {
									std.setProducedate(ypd1.getProducedate());
								}
								if (ypd1.getProduceorder()!=null) {
									std.setProduceorder(ypd1.getProduceorder());
								}
								if (ypd1.getProduceteam()!=null) {
									std.setProduceteam(ypd1.getProduceteam());
								}
								if (ypd1.getIndate()!=null) {
									std.setIndate(ypd1.getIndate());
								}
								if (ypd1.getInorder()!=null) {
									std.setInorder(ypd1.getInorder());
								}
								if (ypd1.getInteam()!=null) {
									std.setInteam(ypd1.getInteam());
								}
								this.getMapper(SpmTransportDetailMapper.class).doInsert(std);
								//修改库存信息
								ypd1.setUpdater(username);
								ypd1.setUpdatedate(now);
								ypd1.setState("2");
								this.getMapper(YdmProductDetailMapper.class).doUpdate(ypd1);
							}
						}
					}
				}	
			}
			//插入理货单主表
			SpmDistrbuteMain sdb=new SpmDistrbuteMain();
			sdb.setCreater(username);
			sdb.setCreatedate(now);
			sdb.setState("0");
			sdb.setDisFactWeight(disfactweight);
			sdb.setDisTheoryWeight(distheoryweight);
			sdb.setDistrbutequantity(distrbutequantity);
			sdb.setDistrbuteno(distrbuteno);
			sdb.setDeliveryno(cp.getMemo2());
			sdb.setCarno(cp.getMemo1());
			sdb.setLoadstore(cp.getMemo3());
			if(cp.getStartTime()!=null&&cp.getStartTime()!="")
				sdb.setPlanStartTime(formatter.parse(cp.getStartTime()));
			if(cp.getEndTime()!=null&&cp.getEndTime()!="")
				sdb.setPlanEndTime(formatter.parse(cp.getEndTime()));
			this.getMapper(SpmDistrbuteMainMapper.class).insert(sdb);
			//修改提货单表
			if(StringUtils.isNotEmpty(cp.getMemo2())) {
				SpmDelivery sd=this.getMapper(SpmDeliveryMapper.class).findById(cp.getMemo2());
				if(sd!=null) {
					sd.setUpdater(username);
					sd.setUpdatedate(now);
					if(cp.getStartTime()!=null&&cp.getStartTime()!="")
						sd.setPlanStartTime(formatter.parse(cp.getStartTime()));
					if(cp.getEndTime()!=null&&cp.getEndTime()!="")
						sd.setPlanEndTime(formatter.parse(cp.getEndTime()));
					if(sd.getDistrbutequantity()==null)
						sd.setDistrbutequantity(0);
					if(sd.getDistrbutequantity()==null) {
						sd.setDistrbutequantity(distrbutequantity);
					} else{
						sd.setDistrbutequantity(sd.getDistrbutequantity()+distrbutequantity);
					}
					
					if(sd.getDisFactWeight()==null) {
						sd.setDisFactWeight(disfactweight);
					} else {
						sd.setDisFactWeight(sd.getDisFactWeight()+disfactweight);
					}
					
					if(sd.getDisTheoryWeight()==null) {
						sd.setDisTheoryWeight(distheoryweight);
					} else {
						sd.setDisTheoryWeight(sd.getDisTheoryWeight()+distheoryweight);
					}
					if("1".equals(sd.getState()))
						sd.setState("2");
					this.getMapper(SpmDeliveryMapper.class).update(sd);
				}
			}
			rm.setState("200");
		} 
		catch (Exception ex) 
		{
			rm.setState("500");
			rm.setMsgInfo("服务端异常，编制失败!");
			ex.printStackTrace();
			throw ex;
		}
		return rm;
	}

	/**
	 * 废副品理货单管理 理货单编制
	 * startTime/endTime传提单开始/结束日期(精确到分秒)，memo1传车号，memo2传提货单号,memo3传仓库编码
	 * @throws Exception 
	 * */
	public ResultModel doWeaveF(CommonPage<YdmProductDetail> cp) throws Exception {
		ResultModel rm=new ResultModel();
		Date now = new Date();
		List<YdmProductDetail> list=cp.getObjectList();
		try {
			String username=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			double disfactweight=0;
			double distheoryweight=0;
			Integer distrbutequantity=1;
			String distrbuteno=this.createDistrbuteNO();
			SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			//修改提货单从表
			List<SlmLadingBillDetail> det = this.getMapper(SlmLadingBillDetailMapper.class).findWithCondition(null, " BILL_NO='"+cp.getMemo2()+"'", null, 0, 1);
			
			disfactweight+=(det.get(0).getFactweight() * 1000);
			distheoryweight+=(det.get(0).getTheoryweight() * 1000);
			String lineno;
			if(cp.getMemo2()!=null&&cp.getMemo2()!=""){
				lineno=this.getMapper(SpmDeliveryMapper.class).getLineNo(cp.getMemo2(), det.get(0).getOrder_no());
				if(lineno!=null&&lineno!=""){
					SpmDeliveryDetail sdd=new SpmDeliveryDetail();
					sdd=this.getMapper(SpmDeliveryDetailMapper.class).dofind(cp.getMemo2(), lineno);
					if(sdd!=null){
						sdd.setCreatedate(now);
						sdd.setCreater(username);
						if(cp.getStartTime()!=null&&cp.getStartTime()!="")
							sdd.setPlanStartTime(formatter.parse(cp.getStartTime()));
						if(cp.getEndTime()!=null&&cp.getEndTime()!="")
							sdd.setPlanEndTime(formatter.parse(cp.getEndTime()));
						sdd.setCarno(cp.getMemo1());
						if(sdd.getDistrbutequantity()==null)
							sdd.setDistrbutequantity(0);
						sdd.setDistrbutequantity(sdd.getDistrbutequantity()+1);
						if(sdd.getDisFactWeight()==null){
							sdd.setDisFactWeight(det.get(0).getFactweight()*1000);
						} else{
							sdd.setDisFactWeight(sdd.getDisFactWeight()+(det.get(0).getFactweight()*1000));
						}
						
						if(sdd.getDisTheoryWeight()==null){
							sdd.setDisTheoryWeight(det.get(0).getTheoryweight()*1000);
						}
						else{
							sdd.setDisTheoryWeight(sdd.getDisTheoryWeight()+(det.get(0).getTheoryweight()*1000));
						}
						this.getMapper(SpmDeliveryDetailMapper.class).doUpdateA(sdd);
					}
					//插入装车单从表
					
					SpmTransportDetail std=new SpmTransportDetail();
					
					
					std.setCreatedate(now);
					std.setCreater(username);
					std.setState("0");
					std.setDistrbuteno(distrbuteno);
					std.setBillNo(cp.getMemo2());
					
					// lineno的值改成和 slmLadingBillDetail 表里的lineNo一致：20240105刘侣
					// 原来是：std.setLineNo(lineno);
					if (det.size() > 0) {
						std.setLineNo(det.get(0).getLine_no());
					}
					// end
						
						
					std.setObjectno(det.get(0).getCoilno());
				
				
					std.setObjectnotype("2");
				
				
					std.setMaterailtype("5");
				
			
					std.setSource("0");
				
				
					std.setMaterailsupplier("");
				
				
					std.setIsbox("");
				
				
					std.setBoxId("");
				
				
					std.setBoxDrawingNo("");
				
				
					std.setBatchno("");
				
				
					std.setHeatno("");
				
				
					std.setSmpNo("");
				
				
					std.setManagementno("");
				
				
					std.setStorageattr("500210");
				
				
					std.setPrdCode(det.get(0).getProd_code());
				
				
					std.setPrdName(det.get(0).getProd_name());
				
				
					std.setStdCode(det.get(0).getStd_code());
				
				
					std.setStdName(det.get(0).getStd_name());
				
				
					std.setUsgCode("");
				
				
					std.setUsgName("");
				
				
					std.setPostid("");
				
				
					std.setHeight(det.get(0).getThick());
				
				
					std.setWidth(det.get(0).getWidth());
				
				
					std.setLength(det.get(0).getLen());
				
				
					std.setInterdiameter(0.00);
				
				
					std.setDiameter(0.00);
				
				
					std.setQuantity(1);
				
				
					std.setTheoryweight(det.get(0).getTheoryweight() * 1000);
				
				
					std.setCoreweight(0.00);
				
				
					std.setGrossweight(0.00);
				
				
					std.setPackweight(0.00);
				
			
					std.setFactweight(det.get(0).getFactweight() * 1000);
				
				
					std.setCustomerNm(det.get(0).getCustomer_name());
				
			
					std.setCustomerNo(det.get(0).getCustomer_no());
				
				
					std.setReceivNo(det.get(0).getReciver_unit_no());
				
				
					std.setReceivNm(det.get(0).getReciver_unit_name());
				
				
					std.setOrderno(det.get(0).getOrder_no());
				
				
					std.setProdorderno("");
				
				
					std.setSteelcode(det.get(0).getJudgesteelcode());
				
				
					std.setJudgesteelcode(det.get(0).getJudgesteelcode());
				
				
					std.setPackingGroup("");
				
				
					std.setChemresult("");
				
				
					std.setSizeresult("");
				
				
					std.setSurfaceresult("40740601");
				
				
					std.setWeightresult("");
				
				
					std.setJudgeresult("40740804");
				
				
					std.setPhysresult("");
				
				
					std.setSpyresult("");
				
				
					std.setProducedate(now);
				
					std.setProduceorder("");
				
					std.setProduceteam("");
				
					std.setIndate(now);
				
					std.setInorder("");
				
					std.setInteam("");
						
					this.getMapper(SpmTransportDetailMapper.class).doInsert(std);
					
			}
			
			//插入理货单主表
			SpmDistrbuteMain sdb=new SpmDistrbuteMain();
			sdb.setCreater(username);
			sdb.setCreatedate(now);
			sdb.setState("0");
			sdb.setDisFactWeight(disfactweight);
			sdb.setDisTheoryWeight(distheoryweight);
			sdb.setDistrbutequantity(distrbutequantity);
			sdb.setDistrbuteno(distrbuteno);
			sdb.setDeliveryno(cp.getMemo2());
			sdb.setCarno(cp.getMemo1());
			sdb.setLoadstore("500210");
			if(cp.getStartTime()!=null&&cp.getStartTime()!="")
				sdb.setPlanStartTime(formatter.parse(cp.getStartTime()));
			if(cp.getEndTime()!=null&&cp.getEndTime()!="")
				sdb.setPlanEndTime(formatter.parse(cp.getEndTime()));
			this.getMapper(SpmDistrbuteMainMapper.class).insert(sdb);
			//修改提货单表
			if(StringUtils.isNotEmpty(cp.getMemo2())) {
				SpmDelivery sd=this.getMapper(SpmDeliveryMapper.class).findById(cp.getMemo2());
				if(sd!=null) {
					sd.setUpdater(username);
					sd.setUpdatedate(now);
					if(cp.getStartTime()!=null&&cp.getStartTime()!="")
						sd.setPlanStartTime(formatter.parse(cp.getStartTime()));
					if(cp.getEndTime()!=null&&cp.getEndTime()!="")
						sd.setPlanEndTime(formatter.parse(cp.getEndTime()));
					if(sd.getDistrbutequantity()==null)
						sd.setDistrbutequantity(0);
					if(sd.getDistrbutequantity()==null) {
						sd.setDistrbutequantity(distrbutequantity);
					} else{
						sd.setDistrbutequantity(sd.getDistrbutequantity()+distrbutequantity);
					}
					
					if(sd.getDisFactWeight()==null) {
						sd.setDisFactWeight(disfactweight);
					} else {
						sd.setDisFactWeight(sd.getDisFactWeight()+disfactweight);
					}
					
					if(sd.getDisTheoryWeight()==null) {
						sd.setDisTheoryWeight(distheoryweight);
					} else {
						sd.setDisTheoryWeight(sd.getDisTheoryWeight()+distheoryweight);
					}
					if("1".equals(sd.getState()))
						sd.setState("2");
					this.getMapper(SpmDeliveryMapper.class).update(sd);
				}
			}
			rm.setState("200");
			}
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("废副品理货单编制失败!");
			ex.printStackTrace();
			throw ex;
		}
		return rm;
	}
	
	/**
	 * 理货单管理 理货单撤销
	 * */
	public ResultModel doCancel(CommonPage<SpmDistrbuteMain> cp) {
		ResultModel rm=new ResultModel();
		Date now = new Date();
		String username=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		List<SpmDistrbuteMain> list=cp.getObjectList();
		try {
			for(SpmDistrbuteMain spm:list) {
				if(spm.getDeliveryno()!=null&spm.getDeliveryno()!="") {
					//修改提货单主表
					SpmDelivery sd=this.getMapper(SpmDeliveryMapper.class).findById(spm.getDeliveryno());
					if(sd!=null) {
						if(sd.getDistrbutequantity()==null)
							sd.setDistrbutequantity(0);
						if(spm.getDistrbutequantity()==null)
							spm.setDistrbutequantity(0);
						sd.setDistrbutequantity(sd.getDistrbutequantity()-spm.getDistrbutequantity());
						if(sd.getDistrbutequantity()==0&&"2".equals(sd.getState()))
							sd.setState("1");
						sd.setDisFactWeight(sd.getDisFactWeight()-spm.getDisFactWeight());
						sd.setDisTheoryWeight(sd.getDisTheoryWeight()-spm.getDisTheoryWeight());
						sd.setUpdatedate(now);
						sd.setUpdater(username);
						this.getMapper(SpmDeliveryMapper.class).update(sd);
					}
					//修改提货单从表
					if(spm.getLineNo()!=""&&spm.getLineNo()!=null) {
						SpmDeliveryDetail sdd=this.getMapper(SpmDeliveryDetailMapper.class).dofind(spm.getDeliveryno(), spm.getLineNo());
						if(sdd!=null)
						{
							if(sdd.getDistrbutequantity()==null)
								sdd.setDistrbutequantity(0);
							if(spm.getDistrbutequantity()==null)
								spm.setDistrbutequantity(0);
							sdd.setDistrbutequantity(sdd.getDistrbutequantity()-spm.getDistrbutequantity());
							sdd.setDisFactWeight(sdd.getDisFactWeight()-spm.getDisFactWeight());
							sdd.setDisTheoryWeight(sdd.getDisTheoryWeight()-spm.getDisTheoryWeight());
							sdd.setUpdatedate(now);
							sdd.setUpdater(username);
							this.getMapper(SpmDeliveryDetailMapper.class).doUpdateA(sdd);
						}
					}		
				}
				//删除理货单主表
				if(spm.getDistrbuteno()!=null&&spm.getDistrbuteno()!="")
				{
					SpmDistrbuteMain sdm=this.getMapper(SpmDistrbuteMainMapper.class).findById(spm.getDistrbuteno());
					if(sdm!=null)
						this.getMapper(SpmDistrbuteMainMapper.class).doDelete(sdm.getDistrbuteno());
					//删除装车单从表
					SpmTransportDetail std=new SpmTransportDetail();
					std.setDistrbuteno(spm.getDistrbuteno());
					List<SpmTransportDetail> ls=this.getMapper(SpmTransportDetailMapper.class).find(std, 0, 0);
					if(ls!=null&&ls.size()>0)
					{
						this.getMapper(SpmTransportDetailMapper.class).doDelete(spm.getDistrbuteno());
						//修改库存信息
						for(SpmTransportDetail st:ls)
						{
							if((st.getObjectno()!=null&st.getObjectno()!="")||(st.getBoxId()!=null&&st.getBoxId()!=""))
							{
								YdmProductDetail ypd=this.getMapper(YdmProductDetailMapper.class).doFind(st.getObjectno(), st.getBoxId());
								ypd.setUpdater(username);
								ypd.setUpdatedate(now);
								if("2".equals(ypd.getState()))
									ypd.setState("0");
								this.getMapper(YdmProductDetailMapper.class).doUpdate(ypd);
							}
						}
					}
				}		
			}
			rm.setState("200");
		}
		catch(Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("服务端异常，撤销失败!");
			ex.printStackTrace();
		}
		return rm;
	}

	/**
	 * 理货单管理 修改理货单
	 * memo1传车号,开始/结束时间传进对象
	 * */
	public ResultModel doUpdate(CommonPage<SpmDistrbuteMain> cp) {
		ResultModel rm=new ResultModel();
		Date now = new Date();
		String username=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		List<SpmDistrbuteMain> list=cp.getObjectList();
		try
		{
			if(list!=null&&list.size()>0)
			{
				for(SpmDistrbuteMain sdm:list)
				{
					if(sdm.getDistrbuteno()!=null&&sdm.getDistrbuteno()!="")
					{					
						SpmDistrbuteMain sdm1=this.getMapper(SpmDistrbuteMainMapper.class).findById(sdm.getDistrbuteno());
						if(sdm1!=null&&"0".equals(sdm1.getState()))
						{
							sdm1.setUpdatedate(now);
							sdm1.setUpdater(username);
							sdm1.setPlanStartTime(sdm.getPlanStartTime());
							sdm1.setPlanEndTime(sdm.getPlanEndTime());
							sdm1.setCarno(cp.getMemo1());
							this.getMapper(SpmDistrbuteMainMapper.class).update(sdm1);
						}
					}
				}
			}
			rm.setState("200");
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("服务端异常，修改失败!");
			ex.printStackTrace();
		}
		return rm;
	}

	/**
	 * 理货单管理 增加物料
	 * memo1-2分别存选中理货单主表的理货单号，提货单号
	 **/
	public ResultModel doAdd(CommonPage<YdmProductDetail> cp) {
		ResultModel rm=new ResultModel();
		Date now = new Date();
		String username=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		List<YdmProductDetail> list=cp.getObjectList();
		try
		{
			Integer count=list.size();
			double theoryweight=0;
			double factweight=0;
			if(list!=null&&list.size()>0)
			{
				for(YdmProductDetail ypd1:list)
				{
					theoryweight+=ypd1.getTheoryweight();
					factweight+=ypd1.getFactweight();
					String lineno="";
					//插入装车单从表
					if((ypd1.getCoilno()!=null&ypd1.getCoilno()!="")||(ypd1.getBoxno()!=null&&ypd1.getBoxno()!=""))
					{
						SpmTransportDetail std=new SpmTransportDetail();
						YdmProductDetail ypd=this.getMapper(YdmProductDetailMapper.class).doFind(ypd1.getCoilno(), ypd1.getBoxno());
						if(ypd!=null)
						{
							if(cp.getMemo2()!=null&&cp.getMemo2()!=""&&ypd.getOrderno()!=""&&ypd.getOrderno()!=null)
								lineno=this.getMapper(SpmDeliveryMapper.class).getLineNo(cp.getMemo2(), ypd.getOrderno());
							std.setCreatedate(now);
							std.setCreater(username);
							std.setState("0");
							std.setDistrbuteno(cp.getMemo1());
							std.setBillNo(cp.getMemo2());
							std.setLineNo(lineno);
							if (ypd.getCoilno()!=null) {
								std.setObjectno(ypd.getCoilno());
							}
							if (ypd.getCoiltype()!=null) {
								std.setObjectnotype(ypd.getCoiltype());
							}
							if (ypd.getMaterailtype()!=null) {
								std.setMaterailtype(ypd.getMaterailtype());
							}
							if (ypd.getSource()!=null) {
								std.setSource(ypd.getSource());
							}
							if (ypd.getMaterailsupplier()!=null) {
								std.setMaterailsupplier(ypd.getMaterailsupplier());
							}
							if (ypd.getIsbox()!=null) {
								std.setIsbox(ypd.getIsbox());
							}
							if (ypd.getBoxno()!=null) {
								std.setBoxId(ypd.getBoxno());
							}
							if (ypd.getDrawingno()!=null) {
								std.setBoxDrawingNo(ypd.getDrawingno());
							}
							if (ypd.getBatchno()!=null) {
								std.setBatchno(ypd.getBatchno());
							}
							if (ypd.getHeatno()!=null) {
								std.setHeatno(ypd.getHeatno());
							}
							if (ypd.getSmpno()!=null) {
								std.setSmpNo(ypd.getSmpno());
							}
							if (ypd.getManagementno()!=null) {
								std.setManagementno(ypd.getManagementno());
							}
							if (ypd.getStorageattr()!=null) {
								std.setStorageattr(ypd.getStorageattr());
							}
							if (ypd.getProd_code()!=null) {
								std.setPrdCode(ypd.getProd_code());
							}
							if (ypd.getProd_name()!=null) {
								std.setPrdName(ypd.getProd_name());
							}
							if (ypd.getStd_code()!=null) {
								std.setStdCode(ypd.getStd_code());
							}
							if (ypd.getStd_name()!=null) {
								std.setStdName(ypd.getStd_name());
							}
							if (ypd.getUse_code()!=null) {
								std.setUsgCode(ypd.getUse_code());
							}
							if (ypd.getUse_name()!=null) {
								std.setUsgName(ypd.getUse_name());
							}
							if (ypd.getPostid()!=null) {
								std.setPostid(ypd.getPostid());
							}
							if (ypd.getThick()!=null) {
								std.setHeight(ypd.getThick());
							}
							if (ypd.getWidth()!=null) {
								std.setWidth(ypd.getWidth());
							}
							if (ypd.getLength()!=null) {
								std.setLength(ypd.getLength());
							}
							if (ypd.getDiameter_inn()!=null) {
								std.setInterdiameter(ypd.getDiameter_inn());
							}
							if (ypd.getDiameter_out()!=null) {
								std.setDiameter(ypd.getDiameter_out());
							}
							if (ypd.getQuantity()!=null) {
								std.setQuantity(ypd.getQuantity());
							}
							if (ypd.getTheoryweight()!=null) {
								std.setTheoryweight(ypd.getTheoryweight());
							}
							if (ypd.getCoreweight()!=null) {
								std.setCoreweight(ypd.getCoreweight());
							}
							if (ypd.getGrossweight()!=null) {
								std.setGrossweight(ypd.getGrossweight());
							}
							if (ypd.getPackweight()!=null) {
								std.setPackweight(ypd.getPackweight());
							}
							if (ypd.getFactweight()!=null) {
								std.setFactweight(ypd.getFactweight());
							}
							if (ypd.getCustomer_nm()!=null) {
								std.setCustomerNm(ypd.getCustomer_nm());
							}
							if (ypd.getCustomer_no()!=null) {
								std.setCustomerNo(ypd.getCustomer_no());
							}
							if (ypd.getReceiv_no()!=null) {
								std.setReceivNo(ypd.getReceiv_no());
							}
							if (ypd.getReceiv_nm()!=null) {
								std.setReceivNm(ypd.getReceiv_nm());
							}
							if (ypd.getOrderno()!=null) {
								std.setOrderno(ypd.getOrderno());
							}
							if (ypd.getProdorderno()!=null) {
								std.setProdorderno(ypd.getProdorderno());
							}
							if (ypd.getSteelcode()!=null) {
								std.setSteelcode(ypd.getSteelcode());
							}
							if (ypd.getJudgesteelcode()!=null) {
								std.setJudgesteelcode(ypd.getJudgesteelcode());
							}
							if (ypd.getPacking_group()!=null) {
								std.setPackingGroup(ypd.getPacking_group());
							}
							if (ypd.getChemresult()!=null) {
								std.setChemresult(ypd.getChemresult());
							}
							if (ypd.getSizeresult()!=null) {
								std.setSizeresult(ypd.getSizeresult());
							}
							if (ypd.getSurfaceresult()!=null) {
								std.setSurfaceresult(ypd.getSurfaceresult());
							}
							if (ypd.getWeightresult()!=null) {
								std.setWeightresult(ypd.getWeightresult());
							}
							if (ypd.getJudgeresult()!=null) {
								std.setJudgeresult(ypd.getJudgeresult());
							}
							if (ypd.getPhysresult()!=null) {
								std.setPhysresult(ypd.getPhysresult());
							}
							if (ypd.getSpyresult()!=null) {
								std.setSpyresult(ypd.getSpyresult());
							}
							if (ypd.getProducedate()!=null) {
								std.setProducedate(ypd.getProducedate());
							}
							if (ypd.getProduceorder()!=null) {
								std.setProduceorder(ypd.getProduceorder());
							}
							if (ypd.getProduceteam()!=null) {
								std.setProduceteam(ypd.getProduceteam());
							}
							if (ypd.getIndate()!=null) {
								std.setIndate(ypd.getIndate());
							}
							if (ypd.getInorder()!=null) {
								std.setInorder(ypd.getInorder());
							}
							if (ypd.getInteam()!=null) {
								std.setInteam(ypd.getInteam());
							}
							this.getMapper(SpmTransportDetailMapper.class).doInsert(std);
							//修改库存信息
							ypd.setUpdater(username);
							ypd.setUpdatedate(now);
							ypd.setState("2");
							this.getMapper(YdmProductDetailMapper.class).doUpdate(ypd);
							//修改提货单从表
							if(cp.getMemo2()!=null&&cp.getMemo2()!=""&&lineno!=null&&lineno!="")
							{
								SpmDeliveryDetail sdd=this.getMapper(SpmDeliveryDetailMapper.class).dofind(cp.getMemo2(), lineno);
								if(sdd!=null)
								{
									if(sdd.getDistrbutequantity()==null)
										sdd.setDistrbutequantity(0);
									sdd.setDistrbutequantity(sdd.getDistrbutequantity()+1);
									sdd.setDisFactWeight(sdd.getDisFactWeight()+ypd.getFactweight());
									sdd.setDisTheoryWeight(sdd.getDisTheoryWeight()+ypd.getTheoryweight());
									sdd.setUpdatedate(now);
									sdd.setUpdater(username);
									this.getMapper(SpmDeliveryDetailMapper.class).doUpdateA(sdd);
								}
							}
						}
					}
				}
				//修改理货单主表
				if(cp.getMemo1()!=null&&cp.getMemo1()!="")
				{
					SpmDistrbuteMain sdm=this.getMapper(SpmDistrbuteMainMapper.class).findById(cp.getMemo1());
					if(sdm!=null)
					{
						if(sdm.getDistrbutequantity()==null)
							sdm.setDistrbutequantity(0);
						sdm.setDistrbutequantity(sdm.getDistrbutequantity()+count);
						sdm.setDisFactWeight(sdm.getDisFactWeight()+factweight);
						sdm.setDisTheoryWeight(sdm.getDisTheoryWeight()+theoryweight);
						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)
					{
						if(sd.getDistrbutequantity()==null)
							sd.setDistrbutequantity(0);
						sd.setDistrbutequantity(sd.getDistrbutequantity()+count);
						sd.setDisFactWeight(sd.getDisFactWeight()+factweight);
						sd.setDisTheoryWeight(sd.getDisTheoryWeight()+theoryweight);
						sd.setUpdatedate(now);
						sd.setUpdater(username);
						this.getMapper(SpmDeliveryMapper.class).update(sd);
					}
				}
				rm.setState("200");
			}
			else
			{
				rm.setMsgInfo("传入数据为空");
			}
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("服务端异常，增加失败!");
			ex.printStackTrace();
		}
		return rm;
	}

	/**
	 * 理货单管理 撤销物料
	 * meme1-2传理货单号，提货单号
	 * */
	@Deprecated
	public ResultModel doCancelM(CommonPage<SpmTransportDetail> cp) {
		ResultModel rm=new ResultModel();
		Date now = new Date();
		String username=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		List<SpmTransportDetail> list=cp.getObjectList();
		try {
			Integer count=list.size();
			double theoryweight=0;
			double factweight=0;
			for(SpmTransportDetail std:list) {
				theoryweight+=std.getTheoryweight();
				factweight+=std.getFactweight();
				//删除装车单从表
				if((std.getObjectno()!=null&&std.getObjectno()!="")||(std.getBoxId()!=null&&std.getBoxId()!=""))
				{
					SpmTransportDetail std1=this.getMapper(SpmTransportDetailMapper.class).doFind(std.getObjectno(), std.getBoxId());
					if(std1!=null)
						this.getMapper(SpmTransportDetailMapper.class).doDeleteByNo(std1.getObjectno(), std1.getBoxId());
					//修改库存表
					YdmProductDetail ypd=this.getMapper(YdmProductDetailMapper.class).doFind(std.getObjectno(), std.getBoxId());
					if(ypd!=null&&"2".equals(ypd.getState()))		
					{
						ypd.setUpdater(username);
						ypd.setUpdatedate(now);
						ypd.setState("0");
						this.getMapper(YdmProductDetailMapper.class).doUpdate(ypd);
					}
				}
				//修改提货单从表
				if(std.getLineNo()!=""&&std.getLineNo()!=null&&cp.getMemo2()!=null&&cp.getMemo2()!="") {
					SpmDeliveryDetail sdd=this.getMapper(SpmDeliveryDetailMapper.class).dofind(cp.getMemo2(),std.getLineNo());
					if(sdd!=null) {
						sdd.setUpdatedate(now);
						sdd.setUpdater(username);
						if(sdd.getDistrbutequantity()==null)
							sdd.setDistrbutequantity(0);
						sdd.setDistrbutequantity(sdd.getDistrbutequantity()-1);
						sdd.setDisFactWeight(sdd.getDisFactWeight()-std.getFactweight());
						sdd.setDisTheoryWeight(sdd.getDisTheoryWeight()-std.getTheoryweight());
						this.getMapper(SpmDeliveryDetailMapper.class).doUpdateA(sdd);
					}
				}
			}
			//修改理货单主表
			if(cp.getMemo1()!=null&&cp.getMemo1()!="") {
				SpmDistrbuteMain sdm=this.getMapper(SpmDistrbuteMainMapper.class).findById(cp.getMemo1());
				if(sdm!=null) {
					sdm.setUpdatedate(now);
					sdm.setUpdater(username);
					if(sdm.getDistrbutequantity()==null)
						sdm.setDistrbutequantity(0);
					sdm.setDistrbutequantity(sdm.getDistrbutequantity()-count);
					if(sdm.getDistrbutequantity()==0) {
						this.getMapper(SpmDistrbuteMainMapper.class).doDelete(sdm.getDistrbuteno());
					}
					else {
						sdm.setDisFactWeight(sdm.getDisFactWeight()-factweight);
						sdm.setDisTheoryWeight(sdm.getDisTheoryWeight()-theoryweight);
						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);
					if(sd.getDistrbutequantity()==null)
						sd.setDistrbutequantity(0);
					sd.setDistrbutequantity(sd.getDistrbutequantity()-count);
					sd.setDisFactWeight(sd.getDisFactWeight()-factweight);
					sd.setDisTheoryWeight(sd.getDisTheoryWeight()-theoryweight);
					this.getMapper(SpmDeliveryMapper.class).update(sd);
				}
			}
			rm.setState("200");
		}
		catch(Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("服务端异常，撤销失败!");
			ex.printStackTrace();
		}
		return rm;
	}

	/**
	 * 理货单管理 理货单关闭(装车管理 理货单关闭)
	 * */
	public ResultModel doClose(CommonPage<SpmDistrbuteMain> cp) {
		ResultModel rm=new ResultModel();
		Date now = new Date();
		String username=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		try  {
			List<SpmDistrbuteMain> list=cp.getObjectList();
			for(SpmDistrbuteMain sdm:list) {
				if(sdm.getDeliveryno()!=null&&sdm.getDistrbuteno()!=null&&sdm.getDeliveryno()!=""&&sdm.getDistrbuteno()!="")
				{
					String lineno=this.getMapper(SpmTransportDetailMapper.class).getLineno(sdm.getDeliveryno(), sdm.getDistrbuteno());
					int count=this.getMapper(SpmTransportDetailMapper.class).doSumUnloadCount(sdm.getDistrbuteno(), sdm.getDeliveryno(), lineno);
					String factweight1=this.getMapper(SpmTransportDetailMapper.class).doSumUnloadFactWeight(sdm.getDistrbuteno(), sdm.getDeliveryno(),lineno);
					String theoryweight1=this.getMapper(SpmTransportDetailMapper.class).doSumUnloadTheoryWeight(sdm.getDistrbuteno(), sdm.getDeliveryno(), lineno);
					double factweight=0;
					double theoryweight=0;
					if (factweight1!=null) {
						factweight =Double.valueOf(factweight1).doubleValue(); 
					}
					if (theoryweight1!=null) {
						theoryweight =Double.valueOf(theoryweight1).doubleValue(); 
					}
					//修改提货单主表
					SpmDelivery sd=this.getMapper(SpmDeliveryMapper.class).findById(sdm.getDeliveryno());
					if(sd!=null) {
						sd.setUpdatedate(now);
						sd.setUpdater(username);
						if(sd.getDistrbutequantity()==null)
							sd.setDistrbutequantity(0);
						sd.setDistrbutequantity(sd.getDistrbutequantity()-count);
						sd.setDisFactWeight(sd.getDisFactWeight()-factweight);
						sd.setDisTheoryWeight(sd.getDisTheoryWeight()-theoryweight);
						sd.setCloser(username);
						sd.setClosetime(now);
						this.getMapper(SpmDeliveryMapper.class).update(sd);
					}
					//修改提货单从表
					SpmDeliveryDetail sdd=this.getMapper(SpmDeliveryDetailMapper.class).dofind(sdm.getDeliveryno(),lineno);
					if(sdd!=null) {
						sdd.setUpdatedate(now);
						sdd.setUpdater(username);
						if(sdd.getDistrbutequantity()==null)
							sdd.setDistrbutequantity(0);
						sdd.setDistrbutequantity(sdd.getDistrbutequantity()-count);
						sdd.setDisFactWeight(sdd.getDisFactWeight()-factweight);
						sdd.setDisTheoryWeight(sdd.getDisTheoryWeight()-theoryweight);
						sdd.setCloser(username);
						sdd.setClosetime(now);
						this.getMapper(SpmDeliveryDetailMapper.class).doUpdateA(sdd);
					}
					//修改理货单主表
					SpmDistrbuteMain sdm1=this.getMapper(SpmDistrbuteMainMapper.class).findById(sdm.getDistrbuteno());
					if(sdm1!=null) {
						sdm1.setUpdatedate(now);
						sdm1.setUpdater(username);
						if(sdm1.getDistrbutequantity()==null)
							sdm1.setDistrbutequantity(0);
						sdm1.setDistrbutequantity(sdm1.getDistrbutequantity()-count);
						sdm1.setDisFactWeight(sdm1.getDisFactWeight()-factweight);
						sdm1.setDisTheoryWeight(sdm1.getDisTheoryWeight()-theoryweight);
						sdm1.setState("2");
						sdm1.setCloser(username);
						sdm1.setClosetime(now);
						this.getMapper(SpmDistrbuteMainMapper.class).update(sdm1);
					}
					//修改库存信息
					List<SpmTransportDetail> ls=this.getMapper(SpmTransportDetailMapper.class).doFindByNo(sdm.getDistrbuteno(), sdm.getDeliveryno(),lineno);
					if(ls!=null&&ls.size()>0) {
						for(SpmTransportDetail std:ls) {
							if((std.getObjectno()!=null&std.getObjectno()!="")||(std.getBoxId()!=null&&std.getBoxId()!=""))
							{
								YdmProductDetail ypd=this.getMapper(YdmProductDetailMapper.class).doFind(std.getObjectno(), std.getBoxId());
								if(ypd!=null) {
									ypd.setUpdatedate(now);
									ypd.setUpdater(username);
									ypd.setState("0");
									this.getMapper(YdmProductDetailMapper.class).doUpdate(ypd);
								}
							}
						}
					}
					//删除装车单从表
					this.getMapper(SpmTransportDetailMapper.class).doDeleteUnload(sdm.getDistrbuteno(), sdm.getDeliveryno(),lineno);
				}
			}
			rm.setState("200");
		} 
		catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("服务端异常，关闭失败!");
			ex.printStackTrace();
		}
		return rm;
	}

	/**
	 * 理货单管理  撤销关闭
	 * */
	public ResultModel doCancelClose(CommonPage<SpmDistrbuteMain> cp) {
		ResultModel rm=new ResultModel();
		//String username=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		try {
			List<SpmDistrbuteMain> list=cp.getObjectList();
			for(SpmDistrbuteMain sdm:list) {
				SpmDistrbuteMain sdm1=this.getMapper(SpmDistrbuteMainMapper.class).findById(sdm.getDistrbuteno());
				if(sdm1!=null) {
					if (sdm1.getState().equals("2")) {
						if(sdm1.getQuantity()==null||"".equals(sdm1.getQuantity()))
						{
							sdm1.setQuantity(0);
						}

						if (sdm1.getQuantity()>0) {
							sdm1.setState("1");
						}else {
							sdm1.setState("0");
						}
						this.getMapper(SpmDistrbuteMainMapper.class).update(sdm1);
						rm.setState("200");
					}else {
						rm.setState("500");
						rm.setMsgInfo("理货单处于关闭状态才能撤销关闭");
					}

				}
			}
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("服务端异常，撤销关闭失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	/** 在途跟踪管理 提货单查询
     * 
     */
	public ResultModel doQueryWebBySQlSpm(CommonPage<SlmLadingBillHeat> cp) {
		ResultModel rm=new ResultModel();
		int pageSize=cp.getPageSize();
		int pageIndex=cp.getPageIndex();
		PageModel<SlmLadingBillHeat> pm = new PageModel<SlmLadingBillHeat>(pageIndex,pageSize); 
		try {
			List<SlmLadingBillHeat> lists = this.getMapper(SlmLadingBillHeatMapper.class).doQueryWebBySQlSpm
					((pageIndex-1)*pageSize, (pageIndex-1)*pageSize+pageSize,cp.getStartTime(),cp.getEndTime(),cp.getObject().getBill_no(),cp.getObject().getState(),cp.getObject().getCoilno(),cp.getObject().getMaterailcoilno(),cp.getObject().getContract_no());
			for (SlmLadingBillHeat slm : lists) {
				slm.setDis_theory_weight(DoubleUtil.round(slm.getDis_theory_weight(), 3));
				slm.setLoad_theory_weight(DoubleUtil.round(slm.getLoad_theory_weight(), 3));
			}
			pm.setRows(lists);
			pm.setTotal(this.getMapper(SlmLadingBillHeatMapper.class).doQueryWebBySQlSlmCount
					(cp.getStartTime(),cp.getEndTime(),cp.getObject().getBill_no(),cp.getObject().getState()));
			rm.setData(pm);
			rm.setState("200");
		} catch(Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("服务端异常，查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}

	/**
	 * 提货单管理 提货单查询
	 * */
	public ResultModel doQueryWebBySQlSlm(CommonPage<SlmLadingBillHeat> cp) {
		ResultModel rm=new ResultModel();
		int pageSize=cp.getPageSize();
		int pageIndex=cp.getPageIndex();
		PageModel<SlmLadingBillHeat> pm = new PageModel<SlmLadingBillHeat>(pageIndex,pageSize); 
		try {
			List<SlmLadingBillHeat> list = this.getMapper(SlmLadingBillHeatMapper.class).doQueryWebBySQlSlm
			((pageIndex-1)*pageSize, (pageIndex-1)*pageSize+pageSize,cp.getStartTime(),cp.getEndTime(),
					cp.getObject().getBill_no(),cp.getObject().getState(),cp.getObject().getCoilno(),
					cp.getObject().getMaterailcoilno(),cp.getObject().getContract_no(),cp.getObject().getStorageattr());
			for (SlmLadingBillHeat slm : list) {
				slm.setDis_theory_weight(DoubleUtil.round(slm.getDis_theory_weight(), 3));
				slm.setLoad_theory_weight(DoubleUtil.round(slm.getLoad_theory_weight(), 3));
			}
			pm.setRows(list);
			pm.setTotal(this.getMapper(SlmLadingBillHeatMapper.class).doQueryWebBySQlSlmCount
					(cp.getStartTime(),cp.getEndTime(),cp.getObject().getBill_no(),cp.getObject().getState()));
			rm.setData(pm);
			rm.setState("200");
		}
		catch(Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("服务端异常，查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}

	/**
	 * 废副品提货单管理 提货单查询：20241202 刘侣
	 * */
	public ResultModel doQueryWebBySQlSlmF(CommonPage<SlmLadingBillHeat> cp) {
		ResultModel rm=new ResultModel();
		int pageSize=cp.getPageSize();
		int pageIndex=cp.getPageIndex();
		PageModel<SlmLadingBillHeat> pm = new PageModel<SlmLadingBillHeat>(pageIndex,pageSize); 
		try {
			List<SlmLadingBillHeat> list = this.getMapper(SlmLadingBillHeatMapper.class).doQueryWebBySQlSlmF
			((pageIndex-1)*pageSize, (pageIndex-1)*pageSize+pageSize,cp.getStartTime(),cp.getEndTime(),
					cp.getObject().getBill_no(),cp.getObject().getState(),cp.getObject().getCoilno(),
					cp.getObject().getMaterailcoilno(),cp.getObject().getContract_no(),cp.getObject().getStorageattr());
			for (SlmLadingBillHeat slm : list) {
				slm.setDis_theory_weight(DoubleUtil.round(slm.getDis_theory_weight(), 3));
				slm.setLoad_theory_weight(DoubleUtil.round(slm.getLoad_theory_weight(), 3));
			}
			pm.setRows(list);
			pm.setTotal(this.getMapper(SlmLadingBillHeatMapper.class).doQueryWebBySQlSlmCountF
					(cp.getStartTime(),cp.getEndTime(),cp.getObject().getBill_no(),cp.getObject().getState()));
			rm.setData(pm);
			rm.setState("200");
		}
		catch(Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("服务端异常，查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 提货单管理 提货单明细
	 * */
	public ResultModel doQueryDetail(CommonPage<SpmDeliveryDetail> cp)
	{
		ResultModel rm=new ResultModel();
		int pageSize=cp.getPageSize();
		int pageIndex=cp.getPageIndex();
		PageModel<SlmLadingBillLine> pm = new PageModel<SlmLadingBillLine>(pageIndex,pageSize);
		try 
		{
			List<SlmLadingBillLine> list = this.getMapper(SlmLadingBillLineMapper.class).doQueryDetail
					((pageIndex-1)*pageSize, (pageIndex-1)*pageSize+pageSize,cp.getObject().getDeliveryno());
			/*for(int i=0;i<list.size();i++){
				String str = list.get(i).getMaterailcoilno();
				String[] arr=str.split(",");
				String string = "";
				for (int j=0; j<arr.length; j++) {    
			        if(!string.contains(arr[j])) {    
			            if(string.length()== 0){
			            	string = arr[j];
			            }else{
			            	string = string+","+String.valueOf(arr[j]);
			            }
			        }  
			    }
				list.get(i).setMaterailcoilno(string);
			}*/
			pm.setRows(list);
			pm.setTotal(this.getMapper(SlmLadingBillLineMapper.class).doQueryDetailCount
					(cp.getObject().getDeliveryno()));
			rm.setData(pm);
			rm.setState("200");
		} 
		catch (Exception ex) 
		{
			rm.setState("500");
			rm.setMsgInfo("明细查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 废副品提货单管理 提货单明细
	 * */
	public ResultModel doQueryDetailF(CommonPage<SpmDeliveryDetail> cp)
	{
		ResultModel rm=new ResultModel();
		int pageSize=cp.getPageSize();
		int pageIndex=cp.getPageIndex();
		PageModel<SlmLadingBillLine> pm = new PageModel<SlmLadingBillLine>(pageIndex,pageSize);
		try 
		{
			List<SlmLadingBillLine> list = this.getMapper(SlmLadingBillLineMapper.class).doQueryDetailF
					((pageIndex-1)*pageSize, (pageIndex-1)*pageSize+pageSize,cp.getObject().getDeliveryno());
			/*for(int i=0;i<list.size();i++){
				String str = list.get(i).getMaterailcoilno();
				String[] arr=str.split(",");
				String string = "";
				for (int j=0; j<arr.length; j++) {    
			        if(!string.contains(arr[j])) {    
			            if(string.length()== 0){
			            	string = arr[j];
			            }else{
			            	string = string+","+String.valueOf(arr[j]);
			            }
			        }  
			    }
				list.get(i).setMaterailcoilno(string);
			}*/
			pm.setRows(list);
			pm.setTotal(this.getMapper(SlmLadingBillLineMapper.class).doQueryDetailCount
					(cp.getObject().getDeliveryno()));
			rm.setData(pm);
			rm.setState("200");
		} 
		catch (Exception ex) 
		{
			rm.setState("500");
			rm.setMsgInfo("明细查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}

	/**
	 * 提货单管理 提货单接收
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doReceive(CommonPage<SpmDelivery> cp) throws Exception {
		ResultModel rm=new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		List<SpmDelivery> list=cp.getObjectList();
		
		if(CollectionUtils.isNotEmpty(list)) {
			for(SpmDelivery sd:list) {
				if (StringUtils.isEmpty(sd.getDeliveryno())) {
					throw new Exception("提货单编号为空，不能接受");
				}			
				SlmLadingBillHeat slbh = this.getMapper(SlmLadingBillHeatMapper.class).findById(sd.getDeliveryno());
				if (slbh==null || !"4".equals(slbh.getValid_status())) {
					throw new Exception("已下发的提货单才能进行提货单接收操作！");
				}
				//插入提货单主表信息
				sd.setState("1");
				sd.setReceiver(username);
				sd.setReceivetime(now);
				sd.setCreatedate(now);
				sd.setCreater(username);
				sd.setPlanStartTime(sd.getEffect_start_time());
				sd.setPlanEndTime(sd.getEffect_end_time());
				this.getMapper(SpmDeliveryMapper.class).insert(sd);
				//插入提货单从表信息
				List<String> llineno=this.getMapper(SlmLadingBillLineMapper.class).getLineNo(sd.getDeliveryno());
				if(CollectionUtils.isNotEmpty(llineno)) {
					for(String lineno:llineno) {
						SpmDeliveryDetail sdd=new SpmDeliveryDetail();
						sdd.setDeliveryno(sd.getDeliveryno());
						sdd.setLineNo(lineno);
						sdd.setCreatedate(now);
						sdd.setCreater(username);
						sdd.setReceiver(username);
						sdd.setReceivetime(now);
						sdd.setState("1");
						sdd.setQuantity(sd.getQuantity());
						sdd.setLoadFactWeight(sd.getLoadFactWeight());
						sdd.setLoadTheoryWeight(sd.getLoadTheoryWeight());
						sdd.setDistrbutequantity(sd.getDistrbutequantity());
						sdd.setDisFactWeight(sd.getDisFactWeight());
						sdd.setDisTheoryWeight(sd.getDisTheoryWeight());
						sdd.setLoadstore(sd.getStorageattr());
						this.getMapper(SpmDeliveryDetailMapper.class).insert(sdd);
					}
				}

				//生成理货单
				if("1".equals(cp.getMemo1())) {
					CommonPage<YdmProductDetail> cpy = new CommonPage<YdmProductDetail>();
					List<YdmProductDetail> pdd = this.getMapper(YdmProductDetailMapper.class).doQueryDetByLad(sd.getDeliveryno());
					String CarNo  = this.getMapper(YdmProductDetailMapper.class).doQueryCarByLad(sd.getDeliveryno());
					cpy.setObjectList(pdd);
					SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					cpy.setStartTime(formatter.format(now));
					Calendar c = Calendar.getInstance();
					c.setTime(now);
					c.add(Calendar.DATE, 2);
					Date d = c.getTime();
				       
					cpy.setEndTime(formatter.format(d));
					cpy.setMemo1(CarNo);
					cpy.setMemo2(sd.getDeliveryno());
					cpy.setMemo3(sd.getStorageattr());
					doWeave(cpy);
					//反写销售表
					CommonPage<SlmLadingBillHeat> sum=new CommonPage<SlmLadingBillHeat>();
					SlmLadingBillHeat heat=new SlmLadingBillHeat();
					heat.setBill_no(sd.getDeliveryno());
					sum.setObject(heat);
					this.getBean(SlmLadingBillHeatServiceImpl.class).doDeliverWeb(sum);
				}
				else {
					//反写销售表
					CommonPage<SlmLadingBillHeat> sum1=new CommonPage<SlmLadingBillHeat>();
					SlmLadingBillHeat heat1=new SlmLadingBillHeat();
					heat1.setBill_no(sd.getDeliveryno());
					sum1.setObject(heat1);
					this.getBean(SlmLadingBillHeatServiceImpl.class).doReceiveWeb(sum1);
				}
				//日志
				MesOprLog mol = new MesOprLog("物流管理", "提货单管理", "提货单接收", username, opr_time, null, null, sd.getDeliveryno(), null, null);
				this.getMapper(MesOprLogMapper.class).insert(mol);
			}			
		}
		else {
			rm.setMsgInfo("传入的数据为空!");
		}
		rm.setState("200");		
		return rm;
	}

	/**
	 * 提货单管理 撤销接收
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doCancelRec(CommonPage<SpmDelivery> cp) throws Exception {
		ResultModel rm=new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		List<SpmDelivery> list=cp.getObjectList();
		if (CollectionUtils.isEmpty(list)) {
			throw new Exception("请勾选提货单信息");
		}
		try {
			for(SpmDelivery sd:list) {
				if (StringUtils.isEmpty(sd.getDeliveryno())) {
					rm.setState("500");
					rm.setMsgInfo("提货单号为空，参数有误");
					return rm;
				}
				SpmDelivery sdy = 	this.getMapper(SpmDeliveryMapper.class).findById(sd.getDeliveryno());
				if(!"1".equals(sdy.getState()) && !"2".equals(sdy.getState())) {
					rm.setState("500");
					rm.setMsgInfo("提货单状态发生变化，请查询后在操作!");
					return rm;
				}
				//删除提货单主表				
				this.getMapper(SpmDeliveryMapper.class).doDelete(sd.getDeliveryno());
				
				//删除理货单
				SpmDistrbuteMain sdm = new SpmDistrbuteMain();
				sdm.setDeliveryno(sd.getDeliveryno());
				List<SpmDistrbuteMain> list1 = this.getMapper(SpmDistrbuteMainMapper.class).find(sdm, 0, 0);			
				if(CollectionUtils.isNotEmpty(list1)) {			
					this.getMapper(SpmDistrbuteMainMapper.class).doDelete(list1.get(0).getDistrbuteno());						
					this.getMapper(SpmTransportDetailMapper.class).doDelete(list1.get(0).getDistrbuteno());
				}
				//反写销售表
				CommonPage<SlmLadingBillHeat> sum=new CommonPage<SlmLadingBillHeat>();
				SlmLadingBillHeat heat=new SlmLadingBillHeat();
				heat.setBill_no(sd.getDeliveryno());
				sum.setObject(heat);
				this.getBean(SlmLadingBillHeatServiceImpl.class).doCancelReceiveWeb(sum);
				
				//删除提货单从表
				List<String> linenoList=this.getMapper(SlmLadingBillLineMapper.class).getLineNo(sd.getDeliveryno());
				if(CollectionUtils.isNotEmpty(linenoList)) {
					for(String lineno:linenoList) {
						this.getMapper(SpmDeliveryDetailMapper.class).doDelete(sd.getDeliveryno(), lineno);
					}
				}
				//日志
				MesOprLog mol = new MesOprLog("物流管理", "提货单管理", "撤销接收", username, opr_time, null, null, sd.getDeliveryno(), null, null);
				this.getMapper(MesOprLogMapper.class).insert(mol);
			}
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("服务端异常，虚单关闭失败!"+ex.getMessage());
			ex.printStackTrace();
			throw ex;
		}
		rm.setState("200");
		return rm;
	}

	/**
	 * 废副品提货单管理 撤销接收
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doCancelRecF(CommonPage<SpmDelivery> cp) throws Exception {
		ResultModel rm=new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		List<SpmDelivery> list=cp.getObjectList();
		if (CollectionUtils.isEmpty(list)) {
			throw new Exception("请勾选提货单信息");
		}
		try {
			for(SpmDelivery sd:list) {
				if (StringUtils.isEmpty(sd.getDeliveryno())) {
					rm.setState("500");
					rm.setMsgInfo("提货单号为空，参数有误");
					return rm;
				}
				SpmDelivery sdy = 	this.getMapper(SpmDeliveryMapper.class).findById(sd.getDeliveryno());
				if(!"1".equals(sdy.getState()) && !"2".equals(sdy.getState())) {
					rm.setState("500");
					rm.setMsgInfo("提货单状态发生变化，请查询后在操作!");
					return rm;
				}
				//删除提货单主表				
				this.getMapper(SpmDeliveryMapper.class).doDelete(sd.getDeliveryno());
				
				//删除理货单
				SpmDistrbuteMain sdm = new SpmDistrbuteMain();
				sdm.setDeliveryno(sd.getDeliveryno());
				List<SpmDistrbuteMain> list1 = this.getMapper(SpmDistrbuteMainMapper.class).find(sdm, 0, 0);			
				if(CollectionUtils.isNotEmpty(list1)) {			
					this.getMapper(SpmDistrbuteMainMapper.class).doDelete(list1.get(0).getDistrbuteno());						
					this.getMapper(SpmTransportDetailMapper.class).doDelete(list1.get(0).getDistrbuteno());
				}
				//反写销售表
				CommonPage<SlmLadingBillHeat> sum=new CommonPage<SlmLadingBillHeat>();
				SlmLadingBillHeat heat=new SlmLadingBillHeat();
				heat.setBill_no(sd.getDeliveryno());
				sum.setObject(heat);
				this.getBean(SlmLadingBillHeatServiceImpl.class).doCancelReceiveWeb(sum);
				
				//删除提货单从表
				List<String> linenoList=this.getMapper(SlmLadingBillLineMapper.class).getLineNo(sd.getDeliveryno());
				if(CollectionUtils.isNotEmpty(linenoList)) {
					for(String lineno:linenoList) {
						this.getMapper(SpmDeliveryDetailMapper.class).doDelete(sd.getDeliveryno(), lineno);
					}
				}
				//日志
				MesOprLog mol = new MesOprLog("物流管理", "废副品提货单管理", "废副品提单撤销接收", username, opr_time, null, null, sd.getDeliveryno(), null, null);
				this.getMapper(MesOprLogMapper.class).insert(mol);
			}
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("服务端异常，虚单关闭失败!"+ex.getMessage());
			ex.printStackTrace();
			throw ex;
		}
		rm.setState("200");
		return rm;
	}
	
	/**
	 * 废副品提货单管理 提货单接收
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doReceiveF(CommonPage<SpmDelivery> cp) throws Exception {
		ResultModel rm=new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		List<SpmDelivery> list=cp.getObjectList();
		
		if(CollectionUtils.isNotEmpty(list)) {
			for(SpmDelivery sd:list) {
				if (StringUtils.isEmpty(sd.getDeliveryno())) {
					throw new Exception("提货单编号为空，不能接收");
				}			
				SlmLadingBillHeat slbh = this.getMapper(SlmLadingBillHeatMapper.class).findById(sd.getDeliveryno());
				if (slbh==null || !"4".equals(slbh.getValid_status())) {
					throw new Exception("已下发的提货单才能进行提货单接收操作！");
				}
				//插入提货单主表信息
				sd.setState("1");
				sd.setReceiver(username);
				sd.setReceivetime(now);
				sd.setCreatedate(now);
				sd.setCreater(username);
				sd.setPlanStartTime(sd.getEffect_start_time());
				sd.setPlanEndTime(sd.getEffect_end_time());
				this.getMapper(SpmDeliveryMapper.class).insert(sd);
				//插入提货单从表信息
				List<String> llineno=this.getMapper(SlmLadingBillLineMapper.class).getLineNo(sd.getDeliveryno());
				if(CollectionUtils.isNotEmpty(llineno)) {
					for(String lineno:llineno) {
						SpmDeliveryDetail sdd=new SpmDeliveryDetail();
						sdd.setDeliveryno(sd.getDeliveryno());
						sdd.setLineNo(lineno);
						sdd.setCreatedate(now);
						sdd.setCreater(username);
						sdd.setReceiver(username);
						sdd.setReceivetime(now);
						sdd.setState("1");
						sdd.setQuantity(sd.getQuantity());
						sdd.setLoadFactWeight(sd.getLoadFactWeight());
						sdd.setLoadTheoryWeight(sd.getLoadTheoryWeight());
						sdd.setDistrbutequantity(sd.getDistrbutequantity());
						sdd.setDisFactWeight(sd.getDisFactWeight());
						sdd.setDisTheoryWeight(sd.getDisTheoryWeight());
						sdd.setLoadstore(sd.getStorageattr());
						this.getMapper(SpmDeliveryDetailMapper.class).insert(sdd);
					}
				}

				//生成理货单
				if("1".equals(cp.getMemo1())) {
					CommonPage<YdmProductDetail> cpy = new CommonPage<YdmProductDetail>();
					List<YdmProductDetail> pdd = this.getMapper(YdmProductDetailMapper.class).doQueryDetByLad(sd.getDeliveryno());
					String CarNo  = this.getMapper(YdmProductDetailMapper.class).doQueryCarByLad(sd.getDeliveryno());
					cpy.setObjectList(pdd);
					SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					cpy.setStartTime(formatter.format(now));
					Calendar c = Calendar.getInstance();
					c.setTime(now);
					c.add(Calendar.DATE, 2);
					Date d = c.getTime();
				       
					cpy.setEndTime(formatter.format(d));
					cpy.setMemo1(CarNo);
					cpy.setMemo2(sd.getDeliveryno());
					cpy.setMemo3("500210");
					doWeaveF(cpy);
					//反写销售表
					CommonPage<SlmLadingBillHeat> sum=new CommonPage<SlmLadingBillHeat>();
					SlmLadingBillHeat heat=new SlmLadingBillHeat();
					heat.setBill_no(sd.getDeliveryno());
					sum.setObject(heat);
					this.getBean(SlmLadingBillHeatServiceImpl.class).doDeliverWeb(sum);
				}
				else {
					//反写销售表
					CommonPage<SlmLadingBillHeat> sum1=new CommonPage<SlmLadingBillHeat>();
					SlmLadingBillHeat heat1=new SlmLadingBillHeat();
					heat1.setBill_no(sd.getDeliveryno());
					sum1.setObject(heat1);
					this.getBean(SlmLadingBillHeatServiceImpl.class).doReceiveWeb(sum1);
				}
				//日志
				MesOprLog mol = new MesOprLog("物流管理", "废副品提货单管理", "废副品提货单接收", username, opr_time, null, null, sd.getDeliveryno(), null, null);
				this.getMapper(MesOprLogMapper.class).insert(mol);
			}			
		}
		else {
			rm.setMsgInfo("传入的数据为空!");
		}
		rm.setState("200");		
		return rm;
	}
	
	/**
	 * 提货单管理 虚单关闭
	 * */
	@Deprecated
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doCloseVirtual(CommonPage<SpmDelivery> cp) {
		ResultModel rm=new ResultModel();
		Date now = new Date();
		String username=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		try {
			List<SpmDelivery> list=cp.getObjectList();
			if(list!=null&&list.size()>0) {
				for(SpmDelivery sd:list) {
					if(sd.getDeliveryno()!=null&&sd.getDeliveryno()!="") {						
						SpmDelivery sd1=this.getMapper(SpmDeliveryMapper.class).findById(sd.getDeliveryno());						
						if(sd1!=null&&"2".equals(sd1.getState())) {
							sd1.setUpdater(username);
							sd1.setUpdatedate(now);
							sd1.setCloser(username);
							sd1.setClosetime(now);
							sd1.setState("5");
							this.getMapper(SpmDeliveryMapper.class).update(sd1);
							//调用销售虚拟提货单关闭
							CommonPage<SlmLadingBillHeat> sum=new CommonPage<SlmLadingBillHeat>();
							SlmLadingBillHeat heat=new SlmLadingBillHeat();
							heat.setBill_no(sd.getDeliveryno());
							sum.setObject(heat);
							this.getBean(SlmLadingBillHeatServiceImpl.class).doCancelReceiveWeb(sum);
						}
						else {
							rm.setMsgInfo("提货单不存在或提货单状态不为'已理货'!");
						}
					}
				}
			}
			else {
				rm.setMsgInfo("传入的数据为空!");
			}
		} 
		catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("服务端异常，虚单关闭失败!");
			ex.printStackTrace();
		}
		rm.setState("200");
		return rm;
	}

	/**
	 * 提货单管理 虚单撤销关闭
	 * */
	@Deprecated
	public ResultModel doCancelCloseDetail(CommonPage<SpmDelivery> cp)
	{
		ResultModel rm=new ResultModel();
		Date now = new Date();
		String username=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		try
		{
			List<SpmDelivery> list=cp.getObjectList();
			if(list!=null&&list.size()>0)
			{
				for(SpmDelivery sd:list)
				{
					if(sd.getDeliveryno()!=null&&sd.getDeliveryno()!="")
					{
						SpmDelivery sd1=this.getMapper(SpmDeliveryMapper.class).findById(sd.getDeliveryno());
						if(sd1!=null&&"5".equals(sd1.getState()))
						{
							sd1.setUpdatedate(now);
							sd1.setUpdater(username);
							sd1.setState("2");
							sd1.setCloser(null);
							sd1.setClosetime(null);
							this.getMapper(SpmDeliveryMapper.class).update(sd1);

							//调用销售虚拟提货单
							CommonPage<SlmLadingBillHeat> sum=new CommonPage<SlmLadingBillHeat>();
							SlmLadingBillHeat heat=new SlmLadingBillHeat();
							heat.setBill_no(sd.getDeliveryno());
							sum.setObject(heat);
							this.getBean(SlmLadingBillHeatServiceImpl.class).doCancelCloseWeb(sum);
						}
					}
				}
			}
			else 
			{
				rm.setMsgInfo("传入的数据为空!");
			}
			rm.setState("200");
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("服务端异常，虚单撤销关闭失败!");
			ex.printStackTrace();
		}
		return rm;
	}

	/**
	 * 提货单管理 提货单关闭
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doCloseReal(CommonPage<SpmDelivery> cp) throws Exception{
		ResultModel rm = new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		List<SpmDelivery> list = cp.getObjectList();
		
		if (list==null || list.size()<=0) {
			rm.setMsgInfo("传入的数据为空!");
			return rm;
		}
		for (SpmDelivery sd : list) {
			if (sd.getDeliveryno()==null || "".equals(sd.getDeliveryno())) {
				continue;
			}
			SpmDelivery sd1 = this.getMapper(SpmDeliveryMapper.class).findById(sd.getDeliveryno());
			if (sd1 != null) {
				if (sd1.getCar_seq()==null || "".equals(sd1.getCar_seq())) {
					throw new Exception("提单号【"+sd1.getDeliveryno()+"】没有同车序号，请重新装车");
				}
				if (!("4".equals(sd1.getState())|| "3".equals(sd1.getState()))) {
					continue;//只有4和3状态才能进行装车操作
				}
				
				SpmDelivery sd1New=new SpmDelivery();
				sd1New.setDeliveryno(sd1.getDeliveryno());
				sd1New.setState("6");
				sd1New.setUpdatedate(now);
				sd1New.setUpdater(username);
				sd1New.setCloser(username);
				sd1New.setClosetime(now);
				this.getMapper(SpmDeliveryMapper.class).update(sd1New);
				// 调用销售提货单关闭
				CommonPage<SlmLadingBillHeat> sum = new CommonPage<SlmLadingBillHeat>();
				SlmLadingBillHeat heat = new SlmLadingBillHeat();
				heat.setBill_no(sd1.getDeliveryno());
				sum.setObject(heat);
				this.getBean(SlmLadingBillHeatServiceImpl.class).doActualCloseWeb(sum);						
				// 反写销售表发运数据
				String carno = null;
				SpmDeliveryDetail sdd = new SpmDeliveryDetail();
				sdd.setDeliveryno(sd.getDeliveryno());
				List<SpmDeliveryDetail> lisSp = this.getMapper(SpmDeliveryDetailMapper.class).find(sdd, 0,0);							
				if (lisSp != null && lisSp.size() > 0) {
					carno = lisSp.get(0).getCarno();
					for (SpmDeliveryDetail Spm : lisSp) {
						CommonPage<SlmLadingBillLine> sbl = new CommonPage<SlmLadingBillLine>();
						
						SlmLadingBillLine sbl1 = new SlmLadingBillLine();									
						sbl1.setLine_no(Spm.getLineNo());
						if (Spm.getQuantity() == null|| "".equals(Spm.getQuantity())) {
							sbl1.setActual_quantity((double) 0);
						} else {
							sbl1.setActual_quantity(Double.parseDouble(Spm.getQuantity().toString()));
						}
						//计重方式要取订单行的计重方式
						SlmLadingBillLine sbl2 = this.getMapper(SlmLadingBillLineMapper.class).doQuaryWeightTypeByLineno(Spm.getLineNo());
						if(sbl2.getWeight_type_no().equals("102301")) {//净重
							if (Spm.getLoadFactWeight() == null|| "".equals(Spm.getLoadFactWeight())) {
								sbl1.setActual_weight((double) 0);
							} else {
								sbl1.setActual_weight(Spm.getLoadFactWeight() / 1000);
							}
						}
						else {	//毛重
							if (Spm.getLoadTheoryWeight()==null||"".equals(Spm.getLoadTheoryWeight())) {
								sbl1.setActual_weight((double) 0);
							} else {
								sbl1.setActual_weight(Spm.getLoadTheoryWeight() / 1000);
							}
						}
						sbl.setObject(sbl1);
						this.getBean(SlmApiServiceImpl.class).doLadingWeb(sbl);//提单装车
					}
				}	 
				SlmLadingBillHeat SBH =this.getMapper(SlmLadingBillHeatMapper.class).findById(sd.getDeliveryno());
				if (SBH!=null) {
					if (SBH.getSolutions_name().contains("到优特")) {
						//脱单(不变库，不变状态)
						this.getMapper(YdmProductDetailMapper.class).doTuoDan(sd.getDeliveryno());
						//修改提货单实绩表SPM_DELIVERY，STATE ='4'已关闭，修改关闭时间、关闭人； 
						SpmDelivery sdNew=new SpmDelivery();
						sdNew.setDeliveryno(sd1.getDeliveryno());
						if ("1".equals(SBH.getBill_type())) {
							sdNew.setState("6");
						}else if ("2".equals(SBH.getBill_type())) {
							sdNew.setState("5");
						} 
						sdNew.setCloser(username);
						sdNew.setClosetime(now);
						this.getMapper(SpmDeliveryMapper.class).update(sdNew); 
					}
					// 调用销售模块提货单关闭接口；
					CommonPage<SlmLadingBillHeat> sum1 = new CommonPage<SlmLadingBillHeat>();
					SlmLadingBillHeat heat1 = new SlmLadingBillHeat();
					heat1.setBill_no(sd.getDeliveryno());
					sum1.setObject(heat1);
					this.getBean(SlmLadingBillHeatServiceImpl.class).doActualCloseWeb(sum1); 
				}
				
				//判断当前提货单的同车提单是否都已经关闭
				String condition ="car_seq = '"+sd1.getCar_seq()+"' and state in ('1','2','3','4')";
				int count = this.getMapper(SpmDeliveryMapper.class).countWithCondition(null, condition);							
				if (count==0) {
					//组装质量模块接口的参数
					List<QcmZbsBill> qzbList = new ArrayList<QcmZbsBill>();
					//如果同车的提货单都已经关闭，就生成质保书，(同车下的所有提货单)
					SpmDelivery sdNew = new SpmDelivery();
					sdNew.setCar_seq(sd1.getCar_seq());
					List<SpmDelivery> sdList = this.getMapper(SpmDeliveryMapper.class).find(sdNew, 0, 0);
					if (sdList!=null && sdList.size()>0) {
						for (SpmDelivery spmDelivery : sdList) {
							SlmLadingBillDetail slBd = new SlmLadingBillDetail();//提单明细
							slBd.setBill_no(spmDelivery.getDeliveryno());
							List<SlmLadingBillDetail> slbdList = this.getMapper(SlmLadingBillDetailMapper.class).find(slBd, 0, 0);
							if (slbdList!=null && slbdList.size()>0) {
								for (SlmLadingBillDetail slbd : slbdList) {
									YdmProductDetail ypd = this.getMapper(YdmProductDetailMapper.class).doFind(slbd.getCoilno(),null);
									String lastChar = ypd.getCoilno().substring(ypd.getCoilno().length()-1);
									if (!"B".equals(lastChar)&& !"H".equals(lastChar)) {
										//头尾卷和边丝不写数据
										QcmZbsBill qzb = new QcmZbsBill();
										qzb.setBill_no(sd1.getCar_seq());//发货单号==同车单号
										qzb.setBatch_no(ypd.getBatchno());
										qzb.setObject_no(ypd.getCoilno());
										qzb.setHeat_no(ypd.getHeatno());
										//处理牌号
										if (ypd.getJudgesteelcode()!=null && !"".equals(ypd.getJudgesteelcode())) {
											qzb.setSteel_code(ypd.getJudgesteelcode());
											ComBaseSteel cbs = this.getMapper(ComBaseSteelMapper.class).findById(ypd.getJudgesteelcode());
											if (cbs!=null) {
												qzb.setSteel_name(cbs.getSteel_name());
											}
										}						
										qzb.setProd_code(ypd.getProd_code());
										qzb.setProd_name(ypd.getProd_name());
										//qzb.setOrg_num(ypd.geto);//认证机构数目,(没找到数据来源)
										qzb.setStd_code(ypd.getStd_code());
										qzb.setStd_name(ypd.getStd_name());
										//获取切边方式和定尺方式
										qzb.setContract_no(slbd.getContract_no());
										if (slbd.getContract_line_no()!=null && !"".equals(slbd.getContract_line_no())) {
											qzb.setContract_line_no(slbd.getContract_line_no());
											SlmContractLineInfo scli = this.getMapper(SlmContractLineInfoMapper.class).findById(slbd.getContract_line_no());
											if (scli!=null) {
												qzb.setCut_edge_type_no(scli.getCut_edge_type_no());//切边方式
												qzb.setCut_edge_type_name(scli.getCut_edge_type_name());
												qzb.setFixed_length_type_no(scli.getFixed_length_type_no());//定尺方式
												qzb.setFixed_length_type_name(scli.getFixed_length_type_name());
												qzb.setDelivery_state_code(scli.getDelivery_state_code());//交货状态
												qzb.setDelivery_state_desc(scli.getDelivery_state_desc());
												/*qzb.setThick(scli.getThick()==null?"":String.valueOf(scli.getThick()));//厚宽长							
												qzb.setLength(scli.getLength()==null?"":String.valueOf(scli.getLength()));
												if ("0".equals(ypd.getCoiltype())) {//20190627宽度:原料卷取销售,产成品取实际规格
													qzb.setWidth(scli.getWidth()==null?"":String.valueOf(scli.getWidth()));
												}else {
													qzb.setWidth(ypd.getWidth()==null?"":String.valueOf(ypd.getWidth()));
												}*/
												//20210119 除【分条机组】取实际的规格，其它的都取订单的规格
												if ("M0001".equals(ypd.getMachine_code()) || "M0002".equals(ypd.getMachine_code())) {
													qzb.setThick(ypd.getThick()==null?"":String.valueOf(ypd.getThick()));
													qzb.setWidth(ypd.getWidth()==null?"":String.valueOf(ypd.getWidth()));
													qzb.setLength(ypd.getLength()==null?"":String.valueOf(ypd.getLength()));
												}else {
													qzb.setThick(scli.getThick()==null?"":String.valueOf(scli.getThick()));
													qzb.setWidth(scli.getWidth()==null?"":String.valueOf(scli.getWidth()));
													qzb.setLength(scli.getLength()==null?"":String.valueOf(scli.getLength()));
												}
											}
											SlmContractIdenOrg scio = new SlmContractIdenOrg();
											scio.setContract_line_no(slbd.getContract_line_no());
											List<SlmContractIdenOrg> scioList = this.getMapper(SlmContractIdenOrgMapper.class).find(null, 0, 0);
											if (scioList!=null && scioList.size()>0) {
												qzb.setOrg_code(scioList.get(0).getOrg_code());//认证机构代码
												qzb.setOrg_name(scioList.get(0).getOrg_name());
											}
										}
										qzb.setContract_line_no(slbd.getContract_line_no()+slbd.getContract_line_seq());
										//qzb.setContract_line_seq(slbd.getContract_line_seq());
										qzb.setOrder_seq(slbd.getOrder_seq());
										qzb.setOrder_unit_no(slbd.getCustomer_no());//订货单位
										qzb.setOrder_unit_name(slbd.getCustomer_name());
										qzb.setReciver_unit_no(slbd.getReciver_unit_no());
										qzb.setReciver_unit_name(slbd.getReciver_unit_name());
										qzb.setCar_no(carno);//车号
										qzb.setTheory_weight(ypd.getTheoryweight()==null?"":String.valueOf(ypd.getTheoryweight()));
										qzb.setFact_weight(ypd.getFactweight()==null?"":String.valueOf(ypd.getFactweight()));
										qzb.setQuantity(ypd.getQuantity()==null?"":String.valueOf(ypd.getQuantity()));
										qzb.setCreate_time(now);
										qzb.setCreate_name(username);
										qzb.setIs_create_book("0");//是否创建了质保书：1是，0否
										qzb.setData_sources("1");//虚拟发货0，实际发货1
										qzb.setDetail_date(slbd.getCreate_time());//明细创建日期
										qzb.setDic_std_code(null);//探伤标准代码
										qzb.setDic_std_desc(null);//探伤标准描述
										qzb.setDic_lv_code(null);//探伤等级代码
										qzb.setDic_lv_desc(null);//探伤等级描述
										if (ypd.getSpyresult()!=null && !"".equals(ypd.getSpyresult())){
											ComBaseInfo cbi = this.getMapper(ComBaseInfoMapper.class).findById(ypd.getSpyresult());
											if (cbi!=null && cbi.getBase_name()!=null) {														
												qzb.setDic_result_desc(cbi.getBase_name());//探伤检验结果描述												
											}
										}
										if (ypd.getChemresult()!=null && !"".equals(ypd.getChemresult())){
											ComBaseInfo cbi = this.getMapper(ComBaseInfoMapper.class).findById(ypd.getChemresult());
											if (cbi!=null && cbi.getBase_name()!=null) {														
												qzb.setCic_result_desc(cbi.getBase_name());//成分判定结果描述
											}
										}
										if (ypd.getPhysresult()!=null && !"".equals(ypd.getPhysresult())){
											ComBaseInfo cbi = this.getMapper(ComBaseInfoMapper.class).findById(ypd.getPhysresult());
											if (cbi!=null && cbi.getBase_name()!=null) {														
												qzb.setPic_result_desc(cbi.getBase_name());//材质判定结果描述
											}
										}
										if (ypd.getSizeresult()!=null && !"".equals(ypd.getSizeresult())){
											ComBaseInfo cbi = this.getMapper(ComBaseInfoMapper.class).findById(ypd.getSizeresult());
											if (cbi!=null && cbi.getBase_name()!=null) {														
												qzb.setSic_result_desc(cbi.getBase_name());//公差判定结果描述
											}
										}
										if (ypd.getUp_surface_result()!=null && !"".equals(ypd.getUp_surface_result())){
											ComBaseInfo cbi = this.getMapper(ComBaseInfoMapper.class).findById(ypd.getUp_surface_result());
											if (cbi!=null && cbi.getBase_name()!=null) {														
												qzb.setSfu_result_desc(cbi.getBase_name());//上表检验结果描述
											}
										}
										if (ypd.getUd_surface_result()!=null && !"".equals(ypd.getUd_surface_result())){
											ComBaseInfo cbi = this.getMapper(ComBaseInfoMapper.class).findById(ypd.getUd_surface_result());
											if (cbi!=null && cbi.getBase_name()!=null) {														
												qzb.setSfd_result_desc(cbi.getBase_name());//下表检验结果描述
											}
										}
										if (ypd.getProdorderno()!=null && !"".equals(ypd.getProdorderno())) {
											PlnProdorder ppo = new PlnProdorder();
											ppo.setProd_order_no(ypd.getProdorderno());
											List<PlnProdorder> ppoList = this.getMapper(PlnProdorderMapper.class).find(ppo, 0, 0);
											if (ppoList!=null && ppoList.size()>0) {
												qzb.setDesign_key(ppoList.get(0).getDesign_key());//DESIGN_KEY
												qzb.setPsc(ppoList.get(0).getPsc());//产品规范码
											}
										}
										//20190523质量模块要求新增字段1 //物料类型(0原料卷1中间卷2成品卷)
										if ("500201".equals(ypd.getStorageattr())) {
											qzb.setMat_type("0");
										}else if ("500202".equals(ypd.getStorageattr())) {
											qzb.setMat_type("1");
										}else if ("500203".equals(ypd.getStorageattr())) {
											qzb.setMat_type("2");
										}
										if ("HR".equals(qzb.getDelivery_state_desc())) {
											qzb.setMat_type("3");//物料类型 3:酸洗卷
										}
										qzb.setCic_id(ypd.getChemresult_id()==null?ypd.getMaterailcoilno():ypd.getChemresult_id());//成分判定记录号
										qzb.setPic_id(ypd.getPhysresult_id()==null?ypd.getSmpno():ypd.getPhysresult_id());//材质判断记录号
										if ("500201".equals(ypd.getStorageattr())||"500205".equals(ypd.getStorageattr())
												|| "HR".equals(qzb.getDelivery_state_desc())) {
											if (StringUtils.isEmpty(qzb.getCic_id())) {											
												qzb.setCic_id(ypd.getMaterailcoilno());//成分判定记录号==原料卷号
											}
											if (StringUtils.isEmpty(qzb.getPic_id())) {											
												qzb.setPic_id(ypd.getSmpno());//材质判断记录号
											}										
										}
										
										qzbList.add(qzb);
									}
								}
							}
						}
					}
					//2019-02-23 调用质量模块接口
					CommonPage<QcmZbsBill> cp2 =new CommonPage<QcmZbsBill>();
					cp2.setObjectList(qzbList);
					ResultModel rm2 = this.getBean(QcmZbsBillServiceImpl.class).doInsertBill(cp2);
					if (!"200".equals(rm2.getState())) {
						throw new Exception("调用质量模块接口出错");
					}
				}
				
				if ("0".equals(SBH.getTrans_type())) {
					// 这里只发送汽运提单：20231214刘侣
//					List<SlmLadingBillLine> lineL = this.getMapper(SlmLadingBillLineMapper.class).findWithCondition(null, " bill_no='"+sd.getDeliveryno()+"' and valid_flag='1'", null, 0, 0);
//					if (lineL != null && lineL.size() > 0) {
//						if (lineL.get(0).getOrder_no() != null) {
							// 在这里获取装车实绩从表，并发送装车实绩：
							// [{},{}]
							JSONArray ja = new JSONArray();
							List<SpmTransportDetail> ls=this.getMapper(SpmTransportDetailMapper.class).findWithCondition(null, " BILL_NO = '" + sd.getDeliveryno() + "'", null, 0, 0);
							for(SpmTransportDetail spd : ls) {
								JSONObject obj = new JSONObject();
								obj.put("transno", spd.getBillNo());
								
								SpmDistrbuteMain sdm=new SpmDistrbuteMain();
								sdm.setDeliveryno(spd.getBillNo());
								List<SpmDistrbuteMain> main=this.getMapper(SpmDistrbuteMainMapper.class).find(sdm, 0, 0);
								obj.put("carno", main.get(0).getCarno());
								obj.put("loaddate", new SimpleDateFormat("yyyy-MM-dd").format(spd.getLoaddate()));
								obj.put("loadtime", new SimpleDateFormat("HH:mm:ss").format(spd.getLoaddate()));
								obj.put("totalwgt", spd.getFactweight() != null ? (spd.getFactweight() / 1000) : spd.getFactweight());
								obj.put("pactno", spd.getOrderno().substring(0, spd.getOrderno().length() - 6));
								obj.put("orderno", spd.getOrderno().substring(0, spd.getOrderno().length() - 3));
								obj.put("labelno", spd.getObjectno());
								obj.put("quantity", spd.getQuantity() != null ? spd.getQuantity().toString() : "1");
								obj.put("wgt", spd.getTheoryweight() != null ? (spd.getTheoryweight() / 1000) : 0);
								obj.put("thick", spd.getHeight() != null ? spd.getHeight().toString() : "0");
								obj.put("width", spd.getWidth() != null ? spd.getWidth().toString() : "0");
								obj.put("length", spd.getLength() != null ? spd.getLength().toString() : "0");
								obj.put("transplanno", spd.getBillNo());

								ComBaseSteel cbs = this.getMapper(ComBaseSteelMapper.class).findById(spd.getSteelcode());
								if (cbs!=null) {
									obj.put("tradeno", cbs.getSteel_name());
								}
								
								YdmProductDetail ypdQQ = this.getMapper(YdmProductDetailMapper.class).doFind(spd.getObjectno(), null);
								if (ypdQQ != null) {
									obj.put("stoveno", ypdQQ.getHeatno());
								}
								
								obj.put("rollno", spd.getBatchno());
								
								
								String butname = this.getMapper(YdmProductDetailMapper.class).doQueryCButtressOne(spd.getObjectno());
								if (butname != null) {
									obj.put("buttress", butname);
								}
//								String prevcoil = spd.getObjectno();
								String prodline = ypdQQ.getCoilno().contains("S") ? "YTSX" : ypdQQ.getCoilno().contains("L") ? "YTZZ" : ypdQQ.getCoilno().contains("P") ? "YTPZ" : ypdQQ.getCoilno().contains("T") ? "YTTH" : ypdQQ.getCoilno().contains("K") ? "YTHJ" : ypdQQ.getCoilno().contains("F") ? "YTZJ" : "YT1";
								obj.put("prodline", prodline);
								
								ja.add(obj);
								
							}
							// http://172.16.0.169/CXZCXSMESIMPL/http/SENDGOODS
							// 用杨佳俊的接口：http://172.16.4.136:14008/il/ilApi/sendGoods
//							System.out.println("装车实绩参数：" + ja.toString());
							String result = Connecttt.postJsonParams("http://172.16.4.136:14008/il/ilApi/sendGoods", ja.toString());
							JsonObject resObj = new JsonParser().parse(result).getAsJsonObject();
//							System.out.println(resObj.get("code"));
							String code = resObj.get("code").toString();
							if (!"1000".equals(code)) {
								throw new Exception("提单装车实绩报错：" + resObj.get("message"));
							}
//						}
//					}
				}
				
				
				
				//日志
				MesOprLog mol = new MesOprLog("物流管理", "装车管理", "提货单关闭", username, opr_time, null, null, sd.getDeliveryno(), null, null);
				this.getMapper(MesOprLogMapper.class).insert(mol);		
			}						
		}

		rm.setState("200");
		return rm;
	}
	
	
	/**
	 * 废副品提货单管理 提货单关闭
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doCloseRealF(CommonPage<SpmDelivery> cp) throws Exception{
		ResultModel rm = new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		List<SpmDelivery> list = cp.getObjectList();
		String pline = cp.getMemo1();
		
		if (list==null || list.size()<=0) {
			rm.setMsgInfo("传入的数据为空!");
			return rm;
		}
		for (SpmDelivery sd : list) {
			if (sd.getDeliveryno()==null || "".equals(sd.getDeliveryno())) {
				continue;
			}
			SpmDelivery sd1 = this.getMapper(SpmDeliveryMapper.class).findById(sd.getDeliveryno());
			if (sd1 != null) {
				if (sd1.getCar_seq()==null || "".equals(sd1.getCar_seq())) {
					throw new Exception("提单号【"+sd1.getDeliveryno()+"】没有同车序号，请重新装车");
				}
				if (!("4".equals(sd1.getState())|| "3".equals(sd1.getState()))) {
					continue;//只有4和3状态才能进行装车操作
				}
				
				SpmDelivery sd1New=new SpmDelivery();
				sd1New.setDeliveryno(sd1.getDeliveryno());
				sd1New.setState("6");
				sd1New.setUpdatedate(now);
				sd1New.setUpdater(username);
				sd1New.setCloser(username);
				sd1New.setClosetime(now);
				this.getMapper(SpmDeliveryMapper.class).update(sd1New);
				// 调用销售提货单关闭
				CommonPage<SlmLadingBillHeat> sum = new CommonPage<SlmLadingBillHeat>();
				SlmLadingBillHeat heat = new SlmLadingBillHeat();
				heat.setBill_no(sd1.getDeliveryno());
				sum.setObject(heat);
				this.getBean(SlmLadingBillHeatServiceImpl.class).doActualCloseWeb(sum);						
				// 反写销售表发运数据
				String carno = null;
				SpmDeliveryDetail sdd = new SpmDeliveryDetail();
				sdd.setDeliveryno(sd.getDeliveryno());
				List<SpmDeliveryDetail> lisSp = this.getMapper(SpmDeliveryDetailMapper.class).find(sdd, 0,0);							
				if (lisSp != null && lisSp.size() > 0) {
					carno = lisSp.get(0).getCarno();
					for (SpmDeliveryDetail Spm : lisSp) {
						CommonPage<SlmLadingBillLine> sbl = new CommonPage<SlmLadingBillLine>();
						
						SlmLadingBillLine sbl1 = new SlmLadingBillLine();									
						sbl1.setLine_no(Spm.getLineNo());
						if (Spm.getQuantity() == null|| "".equals(Spm.getQuantity())) {
							sbl1.setActual_quantity((double) 0);
						} else {
							sbl1.setActual_quantity(Double.parseDouble(Spm.getQuantity().toString()));
						}
						//计重方式要取订单行的计重方式
						SlmLadingBillLine sbl2 = this.getMapper(SlmLadingBillLineMapper.class).doQuaryWeightTypeByLineno(Spm.getLineNo());
						if(sbl2.getWeight_type_no().equals("102301")) {//净重
							if (Spm.getLoadFactWeight() == null|| "".equals(Spm.getLoadFactWeight())) {
								sbl1.setActual_weight((double) 0);
							} else {
								sbl1.setActual_weight(Spm.getLoadFactWeight() / 1000);
							}
						}
						else {	//毛重
							if (Spm.getLoadTheoryWeight()==null||"".equals(Spm.getLoadTheoryWeight())) {
								sbl1.setActual_weight((double) 0);
							} else {
								sbl1.setActual_weight(Spm.getLoadTheoryWeight() / 1000);
							}
						}
						sbl.setObject(sbl1);
						this.getBean(SlmApiServiceImpl.class).doLadingWeb(sbl);//提单装车
					}
				}	 
				SlmLadingBillHeat SBH =this.getMapper(SlmLadingBillHeatMapper.class).findById(sd.getDeliveryno());
				if (SBH!=null) {
					
					// 调用销售模块提货单关闭接口；
					CommonPage<SlmLadingBillHeat> sum1 = new CommonPage<SlmLadingBillHeat>();
					SlmLadingBillHeat heat1 = new SlmLadingBillHeat();
					heat1.setBill_no(sd.getDeliveryno());
					sum1.setObject(heat1);
					this.getBean(SlmLadingBillHeatServiceImpl.class).doActualCloseWeb(sum1); 
				}
				
				
				if ("0".equals(SBH.getTrans_type())) {
					// 这里只发送汽运提单：20231214刘侣
					// 在这里获取装车实绩从表，并发送装车实绩：
					// [{},{}]
					JSONArray ja = new JSONArray();
					List<SpmTransportDetail> ls=this.getMapper(SpmTransportDetailMapper.class).findWithCondition(null, " BILL_NO = '" + sd.getDeliveryno() + "'", null, 0, 0);
					for(SpmTransportDetail spd : ls) {
						JSONObject obj = new JSONObject();
						obj.put("transno", spd.getBillNo());
						
						SpmDistrbuteMain sdm=new SpmDistrbuteMain();
						sdm.setDeliveryno(spd.getBillNo());
						List<SpmDistrbuteMain> main=this.getMapper(SpmDistrbuteMainMapper.class).find(sdm, 0, 0);
						obj.put("carno", main.get(0).getCarno());
						obj.put("loaddate", new SimpleDateFormat("yyyy-MM-dd").format(spd.getLoaddate()));
						obj.put("loadtime", new SimpleDateFormat("HH:mm:ss").format(spd.getLoaddate()));
						obj.put("totalwgt", spd.getFactweight() != null ? (spd.getFactweight() / 1000) : spd.getFactweight());
						obj.put("pactno", spd.getOrderno().substring(0, spd.getOrderno().length() - 6));
						obj.put("orderno", spd.getOrderno().substring(0, spd.getOrderno().length() - 3));
						obj.put("labelno", spd.getObjectno());
						obj.put("quantity", spd.getQuantity() != null ? spd.getQuantity().toString() : "1");
						obj.put("wgt", spd.getTheoryweight() != null ? (spd.getTheoryweight() / 1000) : 0);
						obj.put("thick", spd.getHeight() != null ? spd.getHeight().toString() : "0");
						obj.put("width", spd.getWidth() != null ? spd.getWidth().toString() : "0");
						obj.put("length", spd.getLength() != null ? spd.getLength().toString() : "0");
						obj.put("transplanno", spd.getBillNo());

						ComBaseSteel cbs = this.getMapper(ComBaseSteelMapper.class).findById(spd.getJudgesteelcode());
						if (cbs!=null) {
							obj.put("tradeno", cbs.getSteel_name());
						}
						obj.put("rollno", spd.getBatchno());
						obj.put("stoveno", "");
						obj.put("buttress", "");
						
						obj.put("prodline", pline);
						
						ja.add(obj);
						
					}
					
					// System.out.println("装车实绩参数：" + ja.toString());
					String result = Connecttt.postJsonParams("http://172.16.4.136:14008/il/ilApi/sendGoods", ja.toString());
					JsonObject resObj = new JsonParser().parse(result).getAsJsonObject();
//							System.out.println(resObj.get("code"));
					String code = resObj.get("code").toString();
					if (!"1000".equals(code)) {
						throw new Exception("废副品提单装车实绩发送报错：" + resObj.get("message"));
					}
					// end
				}
				
				//日志
				MesOprLog mol = new MesOprLog("物流管理", "废副品装车管理", "废副品提货单关闭", username, opr_time, null, null, sd.getDeliveryno(), null, null);
				this.getMapper(MesOprLogMapper.class).insert(mol);		
			}						
		}

		rm.setState("200");
		return rm;
	}
	
	
	/**
	 * 提货单管理 提货单关闭
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doCloseRealNew(CommonPage<SpmDelivery> cp) throws Exception{
		ResultModel rm = new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		List<SpmDelivery> list = cp.getObjectList();
		
		if (list==null || list.size()<=0) {
			rm.setMsgInfo("传入的数据为空!");
			return rm;
		}
		for (SpmDelivery sd : list) {
			if (sd.getDeliveryno()==null || "".equals(sd.getDeliveryno())) {
				continue;
			}
			SpmDelivery sd1 = this.getMapper(SpmDeliveryMapper.class).findById(sd.getDeliveryno());
			if (sd1 != null) {
				if (sd1.getCar_seq()==null || "".equals(sd1.getCar_seq())) {
					throw new Exception("提单号【"+sd1.getDeliveryno()+"】没有同车序号，请重新装车");
				}
				if (!("4".equals(sd1.getState())|| "3".equals(sd1.getState()))) {
					continue;//只有4和3状态才能进行装车操作
				}
				
				SpmDelivery sd1New=new SpmDelivery();
				sd1New.setDeliveryno(sd1.getDeliveryno());
				sd1New.setState("6");
				sd1New.setUpdatedate(now);
				sd1New.setUpdater(username);
				sd1New.setCloser(username);
				sd1New.setClosetime(now);
				this.getMapper(SpmDeliveryMapper.class).update(sd1New);
				// 调用销售提货单关闭
				CommonPage<SlmLadingBillHeat> sum = new CommonPage<SlmLadingBillHeat>();
				SlmLadingBillHeat heat = new SlmLadingBillHeat();
				heat.setBill_no(sd1.getDeliveryno());
				sum.setObject(heat);
				this.getBean(SlmLadingBillHeatServiceImpl.class).doActualCloseWeb(sum);						
				// 反写销售表发运数据
				String carno = null;
				SpmDeliveryDetail sdd = new SpmDeliveryDetail();
				sdd.setDeliveryno(sd.getDeliveryno());
				List<SpmDeliveryDetail> lisSp = this.getMapper(SpmDeliveryDetailMapper.class).find(sdd, 0,0);							
				if (lisSp != null && lisSp.size() > 0) {
					carno = lisSp.get(0).getCarno();
					for (SpmDeliveryDetail Spm : lisSp) {
						CommonPage<SlmLadingBillLine> sbl = new CommonPage<SlmLadingBillLine>();
						
						SlmLadingBillLine sbl1 = new SlmLadingBillLine();									
						sbl1.setLine_no(Spm.getLineNo());
						if (Spm.getQuantity() == null|| "".equals(Spm.getQuantity())) {
							sbl1.setActual_quantity((double) 0);
						} else {
							sbl1.setActual_quantity(Double.parseDouble(Spm.getQuantity().toString()));
						}
						//计重方式要取订单行的计重方式
						SlmLadingBillLine sbl2 = this.getMapper(SlmLadingBillLineMapper.class).doQuaryWeightTypeByLineno(Spm.getLineNo());
						if(sbl2.getWeight_type_no().equals("102301")) {//净重
							if (Spm.getLoadFactWeight() == null|| "".equals(Spm.getLoadFactWeight())) {
								sbl1.setActual_weight((double) 0);
							} else {
								sbl1.setActual_weight(Spm.getLoadFactWeight() / 1000);
							}
						}
						else {	//毛重
							if (Spm.getLoadTheoryWeight()==null||"".equals(Spm.getLoadTheoryWeight())) {
								sbl1.setActual_weight((double) 0);
							} else {
								sbl1.setActual_weight(Spm.getLoadTheoryWeight() / 1000);
							}
						}
						sbl.setObject(sbl1);
						this.getBean(SlmApiServiceImpl.class).doLadingWeb(sbl);//提单装车
					}
				}	 
				SlmLadingBillHeat SBH =this.getMapper(SlmLadingBillHeatMapper.class).findById(sd.getDeliveryno());
				if (SBH!=null) {
					if (SBH.getSolutions_name().contains("到优特")) {
						//脱单(不变库，不变状态)
						this.getMapper(YdmProductDetailMapper.class).doTuoDan(sd.getDeliveryno());
						//修改提货单实绩表SPM_DELIVERY，STATE ='4'已关闭，修改关闭时间、关闭人； 
						SpmDelivery sdNew=new SpmDelivery();
						sdNew.setDeliveryno(sd1.getDeliveryno());
						if ("1".equals(SBH.getBill_type())) {
							sdNew.setState("6");
						}else if ("2".equals(SBH.getBill_type())) {
							sdNew.setState("5");
						} 
						sdNew.setCloser(username);
						sdNew.setClosetime(now);
						this.getMapper(SpmDeliveryMapper.class).update(sdNew); 
					}
					// 调用销售模块提货单关闭接口；
					CommonPage<SlmLadingBillHeat> sum1 = new CommonPage<SlmLadingBillHeat>();
					SlmLadingBillHeat heat1 = new SlmLadingBillHeat();
					heat1.setBill_no(sd.getDeliveryno());
					sum1.setObject(heat1);
					this.getBean(SlmLadingBillHeatServiceImpl.class).doActualCloseWeb(sum1); 
				}
				
				//判断当前提货单的同车提单是否都已经关闭
				String condition ="car_seq = '"+sd1.getCar_seq()+"' and state in ('1','2','3','4')";
				int count = this.getMapper(SpmDeliveryMapper.class).countWithCondition(null, condition);							
				if (count==0) {
					//组装质量模块接口的参数
					List<QcmZbsBill> qzbList = new ArrayList<QcmZbsBill>();
					//如果同车的提货单都已经关闭，就生成质保书，(同车下的所有提货单)
					SpmDelivery sdNew = new SpmDelivery();
					sdNew.setCar_seq(sd1.getCar_seq());
					List<SpmDelivery> sdList = this.getMapper(SpmDeliveryMapper.class).find(sdNew, 0, 0);
					if (sdList!=null && sdList.size()>0) {
						for (SpmDelivery spmDelivery : sdList) {
							SlmLadingBillDetail slBd = new SlmLadingBillDetail();//提单明细
							slBd.setBill_no(spmDelivery.getDeliveryno());
							List<SlmLadingBillDetail> slbdList = this.getMapper(SlmLadingBillDetailMapper.class).find(slBd, 0, 0);
							if (slbdList!=null && slbdList.size()>0) {
								for (SlmLadingBillDetail slbd : slbdList) {
									YdmProductDetail ypd = this.getMapper(YdmProductDetailMapper.class).doFind(slbd.getCoilno(),null);
									String lastChar = ypd.getCoilno().substring(ypd.getCoilno().length()-1);
									if (!"B".equals(lastChar)&& !"H".equals(lastChar)) {
										//头尾卷和边丝不写数据
										QcmZbsBill qzb = new QcmZbsBill();
										qzb.setBill_no(sd1.getCar_seq());//发货单号==同车单号
										qzb.setBatch_no(ypd.getBatchno());
										qzb.setObject_no(ypd.getCoilno());
										qzb.setHeat_no(ypd.getHeatno());
										//处理牌号
										if (ypd.getJudgesteelcode()!=null && !"".equals(ypd.getJudgesteelcode())) {
											qzb.setSteel_code(ypd.getJudgesteelcode());
											ComBaseSteel cbs = this.getMapper(ComBaseSteelMapper.class).findById(ypd.getJudgesteelcode());
											if (cbs!=null) {
												qzb.setSteel_name(cbs.getSteel_name());
											}
										}						
										qzb.setProd_code(ypd.getProd_code());
										qzb.setProd_name(ypd.getProd_name());
										//qzb.setOrg_num(ypd.geto);//认证机构数目,(没找到数据来源)
										qzb.setStd_code(ypd.getStd_code());
										qzb.setStd_name(ypd.getStd_name());
										//获取切边方式和定尺方式
										qzb.setContract_no(slbd.getContract_no());
										if (slbd.getContract_line_no()!=null && !"".equals(slbd.getContract_line_no())) {
											qzb.setContract_line_no(slbd.getContract_line_no());
											SlmContractLineInfo scli = this.getMapper(SlmContractLineInfoMapper.class).findById(slbd.getContract_line_no());
											if (scli!=null) {
												qzb.setCut_edge_type_no(scli.getCut_edge_type_no());//切边方式
												qzb.setCut_edge_type_name(scli.getCut_edge_type_name());
												qzb.setFixed_length_type_no(scli.getFixed_length_type_no());//定尺方式
												qzb.setFixed_length_type_name(scli.getFixed_length_type_name());
												qzb.setDelivery_state_code(scli.getDelivery_state_code());//交货状态
												qzb.setDelivery_state_desc(scli.getDelivery_state_desc());
												/*qzb.setThick(scli.getThick()==null?"":String.valueOf(scli.getThick()));//厚宽长							
												qzb.setLength(scli.getLength()==null?"":String.valueOf(scli.getLength()));
												if ("0".equals(ypd.getCoiltype())) {//20190627宽度:原料卷取销售,产成品取实际规格
													qzb.setWidth(scli.getWidth()==null?"":String.valueOf(scli.getWidth()));
												}else {
													qzb.setWidth(ypd.getWidth()==null?"":String.valueOf(ypd.getWidth()));
												}*/
												//20210119 除【分条机组】取实际的规格，其它的都取订单的规格
												if ("M0001".equals(ypd.getMachine_code()) || "M0002".equals(ypd.getMachine_code())) {
													qzb.setThick(ypd.getThick()==null?"":String.valueOf(ypd.getThick()));
													qzb.setWidth(ypd.getWidth()==null?"":String.valueOf(ypd.getWidth()));
													qzb.setLength(ypd.getLength()==null?"":String.valueOf(ypd.getLength()));
												}else {
													qzb.setThick(scli.getThick()==null?"":String.valueOf(scli.getThick()));
													qzb.setWidth(scli.getWidth()==null?"":String.valueOf(scli.getWidth()));
													qzb.setLength(scli.getLength()==null?"":String.valueOf(scli.getLength()));
												}
											}
											SlmContractIdenOrg scio = new SlmContractIdenOrg();
											scio.setContract_line_no(slbd.getContract_line_no());
											List<SlmContractIdenOrg> scioList = this.getMapper(SlmContractIdenOrgMapper.class).find(null, 0, 0);
											if (scioList!=null && scioList.size()>0) {
												qzb.setOrg_code(scioList.get(0).getOrg_code());//认证机构代码
												qzb.setOrg_name(scioList.get(0).getOrg_name());
											}
										}
										qzb.setContract_line_no(slbd.getContract_line_no()+slbd.getContract_line_seq());
										//qzb.setContract_line_seq(slbd.getContract_line_seq());
										qzb.setOrder_seq(slbd.getOrder_seq());
										qzb.setOrder_unit_no(slbd.getCustomer_no());//订货单位
										qzb.setOrder_unit_name(slbd.getCustomer_name());
										qzb.setReciver_unit_no(slbd.getReciver_unit_no());
										qzb.setReciver_unit_name(slbd.getReciver_unit_name());
										qzb.setCar_no(carno);//车号
										qzb.setTheory_weight(ypd.getTheoryweight()==null?"":String.valueOf(ypd.getTheoryweight()));
										qzb.setFact_weight(ypd.getFactweight()==null?"":String.valueOf(ypd.getFactweight()));
										qzb.setQuantity(ypd.getQuantity()==null?"":String.valueOf(ypd.getQuantity()));
										qzb.setCreate_time(now);
										qzb.setCreate_name(username);
										qzb.setIs_create_book("0");//是否创建了质保书：1是，0否
										qzb.setData_sources("1");//虚拟发货0，实际发货1
										qzb.setDetail_date(slbd.getCreate_time());//明细创建日期
										qzb.setDic_std_code(null);//探伤标准代码
										qzb.setDic_std_desc(null);//探伤标准描述
										qzb.setDic_lv_code(null);//探伤等级代码
										qzb.setDic_lv_desc(null);//探伤等级描述
										if (ypd.getSpyresult()!=null && !"".equals(ypd.getSpyresult())){
											ComBaseInfo cbi = this.getMapper(ComBaseInfoMapper.class).findById(ypd.getSpyresult());
											if (cbi!=null && cbi.getBase_name()!=null) {														
												qzb.setDic_result_desc(cbi.getBase_name());//探伤检验结果描述												
											}
										}
										if (ypd.getChemresult()!=null && !"".equals(ypd.getChemresult())){
											ComBaseInfo cbi = this.getMapper(ComBaseInfoMapper.class).findById(ypd.getChemresult());
											if (cbi!=null && cbi.getBase_name()!=null) {														
												qzb.setCic_result_desc(cbi.getBase_name());//成分判定结果描述
											}
										}
										if (ypd.getPhysresult()!=null && !"".equals(ypd.getPhysresult())){
											ComBaseInfo cbi = this.getMapper(ComBaseInfoMapper.class).findById(ypd.getPhysresult());
											if (cbi!=null && cbi.getBase_name()!=null) {														
												qzb.setPic_result_desc(cbi.getBase_name());//材质判定结果描述
											}
										}
										if (ypd.getSizeresult()!=null && !"".equals(ypd.getSizeresult())){
											ComBaseInfo cbi = this.getMapper(ComBaseInfoMapper.class).findById(ypd.getSizeresult());
											if (cbi!=null && cbi.getBase_name()!=null) {														
												qzb.setSic_result_desc(cbi.getBase_name());//公差判定结果描述
											}
										}
										if (ypd.getUp_surface_result()!=null && !"".equals(ypd.getUp_surface_result())){
											ComBaseInfo cbi = this.getMapper(ComBaseInfoMapper.class).findById(ypd.getUp_surface_result());
											if (cbi!=null && cbi.getBase_name()!=null) {														
												qzb.setSfu_result_desc(cbi.getBase_name());//上表检验结果描述
											}
										}
										if (ypd.getUd_surface_result()!=null && !"".equals(ypd.getUd_surface_result())){
											ComBaseInfo cbi = this.getMapper(ComBaseInfoMapper.class).findById(ypd.getUd_surface_result());
											if (cbi!=null && cbi.getBase_name()!=null) {														
												qzb.setSfd_result_desc(cbi.getBase_name());//下表检验结果描述
											}
										}
										if (ypd.getProdorderno()!=null && !"".equals(ypd.getProdorderno())) {
											PlnProdorder ppo = new PlnProdorder();
											ppo.setProd_order_no(ypd.getProdorderno());
											List<PlnProdorder> ppoList = this.getMapper(PlnProdorderMapper.class).find(ppo, 0, 0);
											if (ppoList!=null && ppoList.size()>0) {
												qzb.setDesign_key(ppoList.get(0).getDesign_key());//DESIGN_KEY
												qzb.setPsc(ppoList.get(0).getPsc());//产品规范码
											}
										}
										//20190523质量模块要求新增字段1 //物料类型(0原料卷1中间卷2成品卷)
										if ("500201".equals(ypd.getStorageattr())) {
											qzb.setMat_type("0");
										}else if ("500202".equals(ypd.getStorageattr())) {
											qzb.setMat_type("1");
										}else if ("500203".equals(ypd.getStorageattr())) {
											qzb.setMat_type("2");
										}
										if ("HR".equals(qzb.getDelivery_state_desc())) {
											qzb.setMat_type("3");//物料类型 3:酸洗卷
										}
										qzb.setCic_id(ypd.getChemresult_id()==null?ypd.getMaterailcoilno():ypd.getChemresult_id());//成分判定记录号
										qzb.setPic_id(ypd.getPhysresult_id()==null?ypd.getSmpno():ypd.getPhysresult_id());//材质判断记录号
										if ("500201".equals(ypd.getStorageattr())||"500205".equals(ypd.getStorageattr())
												|| "HR".equals(qzb.getDelivery_state_desc())) {
											if (StringUtils.isEmpty(qzb.getCic_id())) {											
												qzb.setCic_id(ypd.getMaterailcoilno());//成分判定记录号==原料卷号
											}
											if (StringUtils.isEmpty(qzb.getPic_id())) {											
												qzb.setPic_id(ypd.getSmpno());//材质判断记录号
											}										
										}
										
										qzbList.add(qzb);
									}
								}
							}
						}
					}
					//2019-02-23 调用质量模块接口
					CommonPage<QcmZbsBill> cp2 =new CommonPage<QcmZbsBill>();
					cp2.setObjectList(qzbList);
					ResultModel rm2 = this.getBean(QcmZbsBillServiceImpl.class).doInsertBill(cp2);
					if (!"200".equals(rm2.getState())) {
						throw new Exception("调用质量模块接口出错");
					}
				}
				
				// 只有汽运提单才发送装车实绩，火运提单在修改火车号界面去发送装车实绩：20231110刘侣
				if ("0".equals(SBH.getTrans_type())) {
					// 在这里获取装车实绩从表，并发送装车实绩：
					// [{},{}]
					JSONArray ja = new JSONArray();
					SpmTransportDetail std=new SpmTransportDetail();
					std.setBill_no(sd.getDeliveryno());
					List<SpmTransportDetail> ls=this.getMapper(SpmTransportDetailMapper.class).find(std, 0, 0);
					for(SpmTransportDetail spd : ls) {
						JSONObject obj = new JSONObject();
						obj.put("transno", spd.getBillNo());
						
						SpmDistrbuteMain sdm=new SpmDistrbuteMain();
						sdm.setDeliveryno(spd.getBillNo());
						List<SpmDistrbuteMain> main=this.getMapper(SpmDistrbuteMainMapper.class).find(sdm, 0, 0);
						obj.put("carno", main.get(0).getCarno());
						obj.put("loaddate", new SimpleDateFormat("yyyy-MM-dd").format(spd.getLoaddate()));
						obj.put("loadtime", new SimpleDateFormat("HH:mm:ss").format(spd.getLoaddate()));
						obj.put("totalwgt", spd.getFactweight() != null ? spd.getFactweight() / 1000 : spd.getFactweight());
						obj.put("pactno", spd.getOrderno().substring(0, spd.getOrderno().length() - 6));
						obj.put("orderno", spd.getOrderno().substring(0, spd.getOrderno().length() - 6) + spd.getOrderno().substring(spd.getOrderno().length() - 3));
						obj.put("labelno", spd.getObjectno());
						obj.put("quantity", spd.getQuantity());
						obj.put("wgt", spd.getTheoryweight() != null ? spd.getTheoryweight() / 1000 : spd.getTheoryweight());
						obj.put("thick", spd.getHeight());
						obj.put("width", spd.getWidth());
						obj.put("length", spd.getLength());
						obj.put("transplanno", spd.getBillNo());

						ComBaseSteel cbs = this.getMapper(ComBaseSteelMapper.class).findById(spd.getSteelcode());
						if (cbs!=null) {
							obj.put("tradeno", cbs.getSteel_name());
						}
						
						YdmProductDetail ypdQQ = this.getMapper(YdmProductDetailMapper.class).doFind(spd.getObjectno(), null);
						if (ypdQQ != null) {
							obj.put("stoveno", ypdQQ.getHeatno());
						}
						
						obj.put("rollno", spd.getBatchno());
						
						
						String butname = this.getMapper(YdmProductDetailMapper.class).doQueryCButtressOne(spd.getObjectno());
						if (butname != null) {
							obj.put("buttress", butname);
						}
						String prevcoil = spd.getObjectno();
						String prodline = ypdQQ.getCoilno().contains("S") ? "YTSX" : ypdQQ.getCoilno().contains("L") ? "YTZZ" : ypdQQ.getCoilno().contains("P") ? "YTPZ" : ypdQQ.getCoilno().contains("T") ? "YTTH" : ypdQQ.getCoilno().contains("K") ? "YTHJ" : ypdQQ.getCoilno().contains("F") ? "YTZJ" : "YT1";
						obj.put("prodline", prodline);
						
						ja.add(obj);
						
					}
//					System.out.println("装车实绩参数：" + ja.toString());
					String result = Connecttt.postJsonParams("http://172.16.4.136:14008/il/ilApi/sendGoods", ja.toString());
					JsonObject resObj = new JsonParser().parse(result).getAsJsonObject();
//					System.out.println(resObj.get("code"));
					String code = resObj.get("code").toString();
					if (!"1000".equals(code)) {
						throw new Exception("提单装车实绩报错：" + resObj.get("message"));
					}
				}
				
				
				//日志
				MesOprLog mol = new MesOprLog("物流管理", "装车管理", "提货单关闭", username, opr_time, null, null, sd.getDeliveryno(), null, null);
				this.getMapper(MesOprLogMapper.class).insert(mol);		
			}						
		}

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

	/**
	 * 提货单管理 提货单撤销关闭
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doCancelCloseReal(CommonPage<SpmDelivery> cp)throws Exception {
		ResultModel rm = new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		List<SpmDelivery> list = cp.getObjectList();
		
		if (CollectionUtils.isEmpty(list)) {
			throw new Exception("请勾选提货单信息");
		}
		try {
			for (SpmDelivery sd : list) {
				if (StringUtils.isEmpty(sd.getDeliveryno())) {
					throw new Exception("提货单号为空，参数有误");
				}
				SpmDelivery sd1 = this.getMapper(SpmDeliveryMapper.class).findById(sd.getDeliveryno());
				if (sd1==null) {
					throw new Exception("未找到【"+sd.getDeliveryno()+"】对应的提货单信息");
				}
				if (!"5".equals(sd1.getState()) && !"6".equals(sd1.getState())) {
					throw new Exception("提货单【"+sd.getDeliveryno()+"】不是实际关闭状态，无法撤销关闭");
				}
				sd1.setState("4");
				sd1.setUpdatedate(now);
				sd1.setUpdater(username);
				sd1.setCloser(null);
				sd1.setClosetime(null);
				this.getMapper(SpmDeliveryMapper.class).update(sd1);
				// 调用销售提货单关闭
				CommonPage<SlmLadingBillHeat> sum = new CommonPage<SlmLadingBillHeat>();
				SlmLadingBillHeat heat = new SlmLadingBillHeat();
				heat.setBill_no(sd.getDeliveryno());
				sum.setObject(heat);
				this.getBean(SlmLadingBillHeatServiceImpl.class).doCancelCloseWeb(sum);
				//
				QcmZbsBill qzb = new QcmZbsBill();
				qzb.setBill_no(sd1.getCar_seq());//装车单号==同车序号
				int count = this.getMapper(QcmZbsBillMapper.class).count(qzb);
				if (count > 0) {
					//如果存在同车的质保书， 调用质量模块接口删除所有的质保书
					CommonPage<QcmZbsBill> cp2 =new CommonPage<QcmZbsBill>();
					cp2.setObject(qzb);
					ResultModel rm2 = this.getBean(QcmZbsBillServiceImpl.class).removeInsertBill(cp2);
					if (!"200".equals(rm2.getState())) {
						throw new Exception("调用质量模块接口出错："+rm2.getMsgInfo());
					}
				}

				
				//一次结算撤销：重新自动挂单
				SlmLadingBillHeat SBH =this.getMapper(SlmLadingBillHeatMapper.class).findById(sd.getDeliveryno());
				if (SBH!=null &&  SBH.getSolutions_name()!=null&&SBH.getSolutions_name().contains("到优特")) {
					// 如果是一次结算提单的撤销提货单关闭：那么就得校验是否这个提单内的卷都是在库状态：20230808刘侣
					// 一次结算提单的卷不出库，都是在库状态，如果不是在库状态，那么这个卷就可能进入下道工序或者发运出库了，得限制：
					String sql = "select count(1) from SLM_LADING_BILL_DETAIL t " 
						      +" left join YDM_PRODUCT_DETAIL ypd on t.COILNO = ypd.COILNO"
						      + " where t.BILL_NO = '"+ sd.getDeliveryno() +"' and ypd.STATE = '5'";
					int isCk = this.getMapper(PbModelDbMapper.class).doQueryCount(sql);
					if (isCk > 0) {
						throw new Exception("一次结算提单 " + sd.getDeliveryno() + " 内的卷存在出库状态的卷，请联系管理员");
					}
					// end
					
					// 如果卷信息里有订单号，不需要重新挂，如果没有订单，那就需要通过卷信息里的生产订单号获取到订单号补上去：20240719刘侣
					// 不能重新设置订单号：20240702刘侣
					this.getMapper(YdmProductDetailMapper.class).doGuaDan(sd.getDeliveryno());
				}	
				
				// 反写销售表发运数据
				SpmDeliveryDetail sdd = new SpmDeliveryDetail();
				sdd.setDeliveryno(sd.getDeliveryno());
				List<SpmDeliveryDetail> lisSp = this.getMapper(SpmDeliveryDetailMapper.class).find(sdd, 0,0);
				if (lisSp != null && lisSp.size() > 0) {
					for (SpmDeliveryDetail Spm : lisSp) {											
						this.getMapper(SlmLadingBillLineMapper.class).updateactualweight(Spm.getLineNo());																
					}
				}
				
				// 撤销装车实绩的话只能允许汽运提单撤销一体化实绩：20240702刘侣
				if ("0".equals(SBH.getTrans_type())) {
					// 一体化提单：撤销装车实绩 20231023刘侣
					List<SlmLadingBillLine> lineL = this.getMapper(SlmLadingBillLineMapper.class).findWithCondition(null, " bill_no='"+sd.getDeliveryno()+"' and valid_flag='1'", null, 0, 0);
					if (lineL != null && lineL.size() > 0) {
						if (lineL.get(0).getOrder_no() != null) {
							// 在这里获取装车实绩从表，并发送装车实绩：
							// ["1","2"] 格式json
							JSONArray ja = new JSONArray();
							ja.add(sd.getDeliveryno());
							// http://172.16.4.136:14008/il/ilApi/cancelYtSendGoods
//							System.out.println("装车实绩参数：" + ja.toString());
							String result = Connecttt.postJsonParams("http://172.16.4.136:14008/il/ilApi/cancelYtSendGoods", ja.toString());
							JsonObject resObj = new JsonParser().parse(result).getAsJsonObject();
//							System.out.println(resObj.get("code"));
							String code = resObj.get("code").toString();
							// 发送指令过去，但是区分报错信息：不抛错20231218刘侣
//							if (!"1000".equals(code)) {
//								throw new Exception("提单取消装车实绩报错：" + resObj.get("message"));
//							}
//							String str = resObj.get("message").getAsString();
						}
					}
					// end
				}
				
				
				//日志
				MesOprLog mol = new MesOprLog("物流管理", "提货单管理", "撤销关闭", username, opr_time, null, null, sd.getDeliveryno(), null, null);
				this.getMapper(MesOprLogMapper.class).insert(mol);
			}
			rm.setState("200");
		} catch (Exception ex) {
			// 20230808刘侣：
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			rm.setState("500");
			rm.setMsgInfo("服务端异常，提货单撤销关闭失败!");
			ex.printStackTrace();
			throw ex;
		}
		return rm;
	}
	 

	/**
	 * 废副品提货单管理 废副品提货单撤销关闭
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doCancelCloseRealF(CommonPage<SpmDelivery> cp)throws Exception {
		ResultModel rm = new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		List<SpmDelivery> list = cp.getObjectList();
		
		if (CollectionUtils.isEmpty(list)) {
			throw new Exception("请勾选提货单信息");
		}
		try {
			for (SpmDelivery sd : list) {
				if (StringUtils.isEmpty(sd.getDeliveryno())) {
					throw new Exception("提货单号为空，参数有误");
				}
				SpmDelivery sd1 = this.getMapper(SpmDeliveryMapper.class).findById(sd.getDeliveryno());
				if (sd1==null) {
					throw new Exception("未找到【"+sd.getDeliveryno()+"】对应的提货单信息");
				}
				if (!"5".equals(sd1.getState()) && !"6".equals(sd1.getState())) {
					throw new Exception("提货单【"+sd.getDeliveryno()+"】不是实际关闭状态，无法撤销关闭");
				}
				sd1.setState("4");
				sd1.setUpdatedate(now);
				sd1.setUpdater(username);
				sd1.setCloser(null);
				sd1.setClosetime(null);
				this.getMapper(SpmDeliveryMapper.class).update(sd1);
				// 调用销售提货单关闭
				CommonPage<SlmLadingBillHeat> sum = new CommonPage<SlmLadingBillHeat>();
				SlmLadingBillHeat heat = new SlmLadingBillHeat();
				heat.setBill_no(sd.getDeliveryno());
				sum.setObject(heat);
				this.getBean(SlmLadingBillHeatServiceImpl.class).doCancelCloseWeb(sum);
				//
				QcmZbsBill qzb = new QcmZbsBill();
				qzb.setBill_no(sd1.getCar_seq());//装车单号==同车序号
				
				//一次结算撤销：重新自动挂单
				SlmLadingBillHeat SBH =this.getMapper(SlmLadingBillHeatMapper.class).findById(sd.getDeliveryno());
				
				
				// 反写销售表发运数据
				SpmDeliveryDetail sdd = new SpmDeliveryDetail();
				sdd.setDeliveryno(sd.getDeliveryno());
				List<SpmDeliveryDetail> lisSp = this.getMapper(SpmDeliveryDetailMapper.class).find(sdd, 0,0);
				if (lisSp != null && lisSp.size() > 0) {
					for (SpmDeliveryDetail Spm : lisSp) {											
						this.getMapper(SlmLadingBillLineMapper.class).updateactualweight(Spm.getLineNo());																
					}
				}
				
				// 撤销装车实绩的话只能允许汽运提单撤销一体化实绩：20240702刘侣
				if ("0".equals(SBH.getTrans_type())) {
					// 一体化提单：撤销装车实绩 20231023刘侣
					List<SlmLadingBillLine> lineL = this.getMapper(SlmLadingBillLineMapper.class).findWithCondition(null, " bill_no='"+sd.getDeliveryno()+"' and valid_flag='1'", null, 0, 0);
					if (lineL != null && lineL.size() > 0) {
						if (lineL.get(0).getOrder_no() != null) {
							// 在这里获取装车实绩从表，并发送装车实绩：
							// ["1","2"] 格式json
							JSONArray ja = new JSONArray();
							ja.add(sd.getDeliveryno());
							// http://172.16.4.136:14008/il/ilApi/cancelYtSendGoods
//							System.out.println("装车实绩参数：" + ja.toString());
							String result = Connecttt.postJsonParams("http://172.16.4.136:14008/il/ilApi/cancelYtSendGoods", ja.toString());
							JsonObject resObj = new JsonParser().parse(result).getAsJsonObject();
//							System.out.println(resObj.get("code"));
							String code = resObj.get("code").toString();
							// 发送指令过去，但是区分报错信息：不抛错20231218刘侣
//							if (!"1000".equals(code)) {
//								throw new Exception("提单取消装车实绩报错：" + resObj.get("message"));
//							}
//							String str = resObj.get("message").getAsString();
						}
					}
					// end
				}
				
				
				//日志
				MesOprLog mol = new MesOprLog("物流管理", "废副品提货单管理", "撤销关闭", username, opr_time, null, null, sd.getDeliveryno(), null, null);
				this.getMapper(MesOprLogMapper.class).insert(mol);
			}
			rm.setState("200");
		} catch (Exception ex) {
			// 20230808刘侣：
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			rm.setState("500");
			rm.setMsgInfo("服务端异常，废副品提货单撤销关闭失败!");
			ex.printStackTrace();
			throw ex;
		}
		return rm;
	}
	
	/**
	 * 提货单管理 判断理货单是否结束
	 * */
	public ResultModel doJudgeEnd(CommonPage<SpmDelivery> cp) {
		ResultModel rm=new ResultModel();
		try {
			List<SpmDelivery> list=cp.getObjectList();
			boolean have=false;
			if(list!=null&&list.size()>0) {
				for(SpmDelivery sd:list) {
					if(sd.getDeliveryno()!=null&&sd.getDeliveryno()!="") {
						SpmDistrbuteMain sdm=new SpmDistrbuteMain();
						sdm.setDeliveryno(sd.getDeliveryno());
						List<SpmDistrbuteMain> ls=this.getMapper(SpmDistrbuteMainMapper.class).find(sdm, 0, 0);
						if(ls!=null&&ls.size()>0) {
							for(SpmDistrbuteMain sdb:ls) {
								if(!"2".equals(sdb.getState())) {
									have=true;						
								}
							}
						}
						else  {
							rm.setState("500");
							rm.setMsgInfo("没找到对应的理货单信息!");
						}
					}
				}
				if(!have)
					rm.setState("200");
				else  {
					rm.setState("500");
					rm.setMsgInfo("选择行的提货单下存在未结束的理货单!");
				}
			}
			else {
				rm.setState("500");
				rm.setMsgInfo("传入的数据为空!");
			}
		}
		catch(Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("服务端异常，判断理货单是否结束失败!");
			ex.printStackTrace();
		}
		return rm;
	}

	/**
	 * 判断是否全部为挂物料科
	 * @return
	 */
	public ResultModel doFindis_detail(CommonPage<SpmDelivery> cp) {
		ResultModel rm =new ResultModel();
		String bill_no=cp.getObject().getDeliveryno();
		List<String> isList =this.getMapper(SpmDeliveryMapper.class).doFindis_detail(bill_no);
		boolean b =true;
		if (isList!=null&&isList.size()>0) {
			for (String s : isList) {
				if (s!=null) {
					if (s=="1"||s.equals("1")) {
					}else {
						b=false;
						break;
					}
				}else {
					b=false;
					break;
				}
			}
		}else {
			b=false;
		}
		rm.setData(b);
		return rm;
	}
	
	/**
	 * 提货单同车
	 * @author 
	 */
    public ResultModel DoSameCarSeq(CommonPage<SpmDelivery> cp){
    	ResultModel rm = new ResultModel(); 
    	Date now = new Date();
    	String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
    	String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
    	List<SpmDelivery> list = cp.getObjectList();
    	
    	try{
	    	String max = this.getMapper(SpmDeliveryMapper.class).getCode(new SimpleDateFormat("yyyyMMdd").format(now));
	    	for(SpmDelivery sd : list){
	    		String Swhere = " 1=1 and deliveryno = '"+sd.getDeliveryno()+"'";
	    		List<SpmDelivery> lists = this.getMapper(SpmDeliveryMapper.class).findWithCondition(null, Swhere, null, 0, 0);
	    		if(lists.get(0).getCar_seq()!= null){
	    			rm.setState("500");
	    			rm.setMsgInfo("该'"+sd.getDeliveryno()+"'提货单已经同车,请取消同车再进行此操作！");
	    			return rm;
	    		}
	    		sd.setDeliveryno(sd.getDeliveryno());
	    		sd.setCar_seq(max);
	    		this.getMapper(SpmDeliveryMapper.class).update(sd);	    		
	    		//日志
	    		MesOprLog mol = new MesOprLog("物流管理", "装车管理", "同车", username, opr_time, null, null, sd.getDeliveryno(), null, "同车序号:"+max);
	    		this.getMapper(MesOprLogMapper.class).insert(mol);
	    	}   	
	    	rm.setState("200");
    	}catch(Exception ex){
    		rm.setData("500");
    		rm.setMsgInfo("同车失败！");
    		ex.printStackTrace();
    	}
    	return rm;
    }
    /**
     * 提货单取消同车
     * @author 
     */
    public ResultModel CancelSameCarSeq(CommonPage<SpmDelivery> cp){
    	ResultModel rm = new ResultModel();
    	Date now = new Date();
    	String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
    	String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
    	List<SpmDelivery> list = cp.getObjectList();
    	try{
    		for(SpmDelivery sd : list){
    			String Swhere = " 1=1 and deliveryno = '"+sd.getDeliveryno()+"'";
    			List<SpmDelivery> lists = this.getMapper(SpmDeliveryMapper.class).findWithCondition(null, Swhere, null, 0, 0);
    			if(("").equals(lists.get(0).getCar_seq())){
        			rm.setState("500");
        			rm.setMsgInfo("该'"+sd.getDeliveryno()+"'提货单没有同车,无需取消同车！");
        			return rm;
        		}
    			String car_seq = sd.getCar_seq();
        		sd.setDeliveryno(sd.getDeliveryno());
        		sd.setCar_seq("");
        		this.getMapper(SpmDeliveryMapper.class).update(sd);
        		//日志
        		MesOprLog mol = new MesOprLog("物流管理", "装车管理", "取消同车", username, opr_time, null, null, sd.getDeliveryno(), null, "前同车序号:"+car_seq);
        		this.getMapper(MesOprLogMapper.class).insert(mol);
    		}
    		rm.setState("200");
    	}
    	catch(Exception ex){
    		rm.setState("500");
    		rm.setMsgInfo("取消同车失败！");
    		ex.printStackTrace();
    	}
    	return rm;
    }
    /**
     * 签收
     * @author
     */
    @Deprecated
    public ResultModel Sign(CommonPage<SpmDelivery> cp){
    	ResultModel rm = new ResultModel();
    	Date now = new Date();
    	List<SpmDelivery> list = cp.getObjectList();
    	try{
    		SpmDelivery spd = new SpmDelivery();
    		String v_man = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
    		for(SpmDelivery sd : list){
    			String Swhere = " 1 = 1 and deliveryno = '"+sd.getDeliveryno()+"'";
    			List<SpmDelivery> lists = this.getMapper(SpmDeliveryMapper.class).findWithCondition(null, Swhere, null, 0, 0);
    			if(lists.get(0).getSign_state().equals("1")){
    				rm.setState("500");
    				rm.setMsgInfo("该【'"+sd.getDeliveryno()+"'】提货单已经签收,无需继续签收！");
    				return rm;
    			}
    			spd.setDeliveryno(sd.getDeliveryno());
    			spd.setSign_man(v_man);
    			spd.setSign_state("1");
    			spd.setSign_time(now);
    			this.getMapper(SpmDeliveryMapper.class).update(spd);
    		}
    		rm.setState("200");
    	}catch(Exception ex){
    		rm.setState("500");
    		rm.setMsgInfo("签收失败!");
    		rm.setErrorInfo(ex.getMessage());
    	}
    	return rm;
    }
    /**
     * 取消签收
     * @author
     */
    @Deprecated
    public ResultModel CancelSign(CommonPage<SpmDelivery> cp){
    	ResultModel rm = new ResultModel();
    	try{
    		List<SpmDelivery> list = cp.getObjectList();
    		for(SpmDelivery sd : list){
    			String Swhere = " 1=1 and deliveryno = '"+sd.getDeliveryno()+"'";
    			List<SpmDelivery> lists = this.getMapper(SpmDeliveryMapper.class).findWithCondition(null, Swhere, null, 0, 0);
    			if(lists.get(0).getSign_state().equals("0")){
    				rm.setState("500");
    				rm.setMsgInfo("该【'"+sd.getDeliveryno()+"'】提货单处于在途状态,无需取消签收！");
    				return rm;
    			}
    			this.getMapper(SpmDeliveryMapper.class).cancelsign(sd.getDeliveryno());
    		}
    		rm.setState("200");
    	}catch(Exception ex){
    		rm.setState("500");
    		rm.setMsgInfo("取消签收失败!");
    		rm.setErrorInfo(ex.getMessage());
    	}
    	return rm;
    }
    /**
     * 在途
     * @author
     */
    @Deprecated
    public ResultModel Locatetion(CommonPage<SpmDelivery> cp){
    	ResultModel rm = new ResultModel();
    	try{
    		List<SpmDelivery> list = cp.getObjectList();
    		SpmDelivery spd = new  SpmDelivery();
    		String v_man = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
    		for(SpmDelivery sd : list){
    			String Swhere = " 1=1 and deliveryno = '"+sd.getDeliveryno()+"'";
    			List<SpmDelivery> lists = this.getMapper(SpmDeliveryMapper.class).findWithCondition(null, Swhere, null, 0, 0);
    			if(lists.get(0).getSign_state().equals("1")){
    				rm.setState("500");
    				rm.setMsgInfo("该【'"+sd.getDeliveryno()+"'】提货单已被签收,不能更改在途信息！");
    				return rm;
    			}
    			spd.setDeliveryno(sd.getDeliveryno());
    			spd.setLocation(sd.getLocation());
    			spd.setLocation_person(v_man);
    			spd.setLocation_time(sd.getLocation_time());
    			this.getMapper(SpmDeliveryMapper.class).update(spd);
    		}
    		rm.setState("200");
    	}catch(Exception ex){
    		rm.setState("500");
    		rm.setMsgInfo("在途信息更新失败");
    		rm.setErrorInfo(ex.getMessage());
    	}
    	return rm;
    }
    /**
     * 取消在途信息
     */
    @Deprecated
    public ResultModel CancelLocation(CommonPage<SpmDelivery> cp){
    	ResultModel rm = new ResultModel();
    	try{
    		List<SpmDelivery> list = cp.getObjectList();
    		for(SpmDelivery sd : list){
    			String Swhere = " 1=1 and deliveryno = '"+sd.getDeliveryno()+"'";
    			List<SpmDelivery> lists = this.getMapper(SpmDeliveryMapper.class).findWithCondition(null, Swhere, null, 0, 0);
    			if(lists.get(0).getSign_state().equals("1")){
    				rm.setState("500");
    				rm.setMsgInfo("该【'"+sd.getDeliveryno()+"'】提货单已被签收,不能撤销在途信息！");
    				return rm;
    			}
    			this.getMapper(SpmDeliveryMapper.class).cancellocation(sd.getDeliveryno());
    		}
    		rm.setState("200");
    	}catch(Exception ex){
    		rm.setState("500");
    		rm.setMsgInfo("撤销在途失败");
    		rm.setErrorInfo(ex.getMessage());
    	}
    	return rm;
    }
    //2162
}