/***文档注释***********************************************
 * 作者               :                   龙文航
 * 创建日期      :                   2017.11.21
 * 描述               :                   仓库管理-成品库管理-调拨单管理
 * 注意事项      :                   无
 * 遗留BUG :                   无
 * 修改日期      :                   
 * 修改人员      :                   
 * 修改内容      :                   
***********************************************************/

package market.Lms.Warehouse.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.regex.Pattern;

import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Lms.Warehouse.mapper.YdmProductButtresslistMapper;
import market.Lms.Warehouse.mapper.YdmProductDetailMapper;
import market.Lms.Warehouse.mapper.YdmProductInlistMapper;
import market.Lms.Warehouse.mapper.YdmProductMoveMapper;
import market.Lms.Warehouse.mapper.YdmProductOutlistMapper;
import market.Lms.Warehouse.service.YdmProductMoveService;
import market.Lms.Warehouse.vo.YdmAllotMain;
import market.Lms.Warehouse.vo.YdmProductButtresslist;
import market.Lms.Warehouse.vo.YdmProductDetail;
import market.Lms.Warehouse.vo.YdmProductInlist;
import market.Lms.Warehouse.vo.YdmProductMove;
import market.Lms.Warehouse.vo.YdmProductOutlist;
import market.Mes.MaterielTrack.vo.PrcMaterielProcess;
import market.Mes.Opr.mapper.MesOprLogMapper;
import market.Mes.Opr.vo.MesOprLog;

import org.springframework.transaction.annotation.Transactional;

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


@RemoteService(path="YdmProductMoveService")
public class YdmProductMoveServiceImpl extends BaseServiceImpl<YdmProductMove,Object> implements YdmProductMoveService {
	/**
	 * 根据调拨单主表的调拨单号查询调拨单明细
	 * */
	public ResultModel doQueryDetailWeb(CommonPage<YdmAllotMain> cp) {
		ResultModel rm=new ResultModel();
		int pageIndex=cp.getPageIndex();
		int pageSize=cp.getPageSize();
		PageModel<YdmProductMove> pm=new PageModel<YdmProductMove>(pageIndex, pageSize);
		try {
			if (cp.getObject()!=null && cp.getObject().getAllot_no()!=null 
					&&!"".equals(cp.getObject().getAllot_no())) {
				YdmProductMove ypm=new YdmProductMove();
				ypm.setAllot_no(cp.getObject().getAllot_no());
				pm.setRows(this.getMapper(YdmProductMoveMapper.class).find(ypm,(pageIndex-1)*pageSize,pageSize));
				pm.setTotal(this.getMapper(YdmProductMoveMapper.class).count(ypm));
				rm.setData(pm);
				rm.setState("200");				
			}
		}
		catch(Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 生成主键
	 * @return
	 * @throws Exception 
	 */
	@SuppressWarnings("rawtypes")
	public String createMOVEBILLNO() throws Exception {
		try {
			String movebillno="";
			List<HashMap> list = this.getMapper(YdmProductMoveMapper.class).getMoveBillNo("MV"+(new SimpleDateFormat("yyyyMMdd").format(new Date())));
			movebillno = (String) list.get(0).get("MAXNO");
			return movebillno;
		} 
		catch (Exception ex) {
			throw (ex);
		}
	}
	
	/**
	 * 生成装车单号
	 * @return
	 * @throws Exception 
	 */
	@SuppressWarnings("rawtypes")
	public String createBILLNO() throws Exception {
		try  {
			String billno="";
			List<HashMap> list = this.getMapper(YdmProductMoveMapper.class).getBillNo("BL"+(new SimpleDateFormat("yyyyMMdd").format(new Date())));
			billno = (String) list.get(0).get("MAXNO");
			return billno;
		} 
		catch (Exception ex) {
			throw (ex);
		}
	}
	
	/**
	 * 移送管理  分组显示(已移送+总)
	 * */
	public ResultModel doQueryWebBySQL(CommonPage<YdmProductMove> cp) {
		ResultModel rm=new ResultModel();
		int pageSize=cp.getPageSize();
		int pageIndex=cp.getPageIndex();
		PageModel<YdmProductMove> pm=new PageModel<YdmProductMove>(pageIndex, pageSize);
		try {
			String regex = "^(\\d+\\.?\\d*)$";	
			boolean isMatch = true;
			Object hmin="",hmax="",wmin="",wmax="";
			if (cp.getMemo1() != null && cp.getMemo1() != "") {
				isMatch = Pattern.matches(regex, cp.getMemo1().trim());
				if (!isMatch) {
					rm.setState("500");
					rm.setMsgInfo("请输入正确的厚度和宽度!");
					return rm;
				}
				hmin = Double.valueOf(cp.getMemo1()).doubleValue();
			}
			if (cp.getMemo2() != null && cp.getMemo2() != "") {
				isMatch = Pattern.matches(regex, cp.getMemo2().trim());
				if (!isMatch) {
					rm.setState("500");
					rm.setMsgInfo("请输入正确的厚度和宽度!");
					return rm;
				}
				hmax = Double.valueOf(cp.getMemo2()).doubleValue();
			}
			if (cp.getMemo3() != null && cp.getMemo3() != "") {
				isMatch = Pattern.matches(regex, cp.getMemo3().trim());
				if (!isMatch) {
					rm.setState("500");
					rm.setMsgInfo("请输入正确的厚度和宽度!");
					return rm;
				}
				wmin = Double.valueOf(cp.getMemo3()).doubleValue();
			}
			if (cp.getMemo4() != null && cp.getMemo4() != "") {
				isMatch = Pattern.matches(regex, cp.getMemo4().trim());
				if (!isMatch) {
					rm.setState("500");
					rm.setMsgInfo("请输入正确的厚度和宽度!");
					return rm;
				}
				wmax = Double.valueOf(cp.getMemo4()).doubleValue();
			}
			pm.setRows(this.getMapper(YdmProductMoveMapper.class).doQueryWebBySQL
					((pageIndex-1)*pageSize, (pageIndex-1)*pageSize+pageSize, cp.getStartTime(), cp.getEndTime(), cp.getObject().getCoilno(), cp.getObject().getSteelcode(),hmin,hmax,wmin,wmax,cp.getObject().getStorageattr(),cp.getObject().getIsaccept(),cp.getObject().getMaterailcoilno()));
			pm.setTotal(this.getMapper(YdmProductMoveMapper.class).doQueryWebBySQLCount
					(cp.getStartTime(), cp.getEndTime(), cp.getObject().getCoilno(), cp.getObject().getSteelcode(),hmin,hmax,wmin,wmax,cp.getObject().getStorageattr(),cp.getObject().getIsaccept()));
			rm.setData(pm);
			rm.setState("200");
		} 
		catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	
	/**
	 * 移送管理  分组显示(待接收+总)
	 * */
	public ResultModel doQueryWebBySQLR(CommonPage<YdmProductMove> cp) {
		ResultModel rm=new ResultModel();
		int pageSize=cp.getPageSize();
		int pageIndex=cp.getPageIndex();
		PageModel<YdmProductMove> pm=new PageModel<YdmProductMove>(pageIndex, pageSize);
		try {
			String regex = "^(\\d+\\.?\\d*)$";	
			boolean isMatch = true;
			Object hmin="",hmax="",wmin="",wmax="";
			if (cp.getMemo1() != null && cp.getMemo1() != "") {
				isMatch = Pattern.matches(regex, cp.getMemo1().trim());
				if (!isMatch) {
					rm.setState("500");
					rm.setMsgInfo("请输入正确的厚度和宽度!");
					return rm;
				}
				hmin = Double.valueOf(cp.getMemo1()).doubleValue();
			}
			if (cp.getMemo2() != null && cp.getMemo2() != "") {
				isMatch = Pattern.matches(regex, cp.getMemo2().trim());
				if (!isMatch) {
					rm.setState("500");
					rm.setMsgInfo("请输入正确的厚度和宽度!");
					return rm;
				}
				hmax = Double.valueOf(cp.getMemo2()).doubleValue();
			}
			if (cp.getMemo3() != null && cp.getMemo3() != "") {
				isMatch = Pattern.matches(regex, cp.getMemo3().trim());
				if (!isMatch) {
					rm.setState("500");
					rm.setMsgInfo("请输入正确的厚度和宽度!");
					return rm;
				}
				wmin = Double.valueOf(cp.getMemo3()).doubleValue();
			}
			if (cp.getMemo4() != null && cp.getMemo4() != "") {
				isMatch = Pattern.matches(regex, cp.getMemo4().trim());
				if (!isMatch) {
					rm.setState("500");
					rm.setMsgInfo("请输入正确的厚度和宽度!");
					return rm;
				}
				wmax = Double.valueOf(cp.getMemo4()).doubleValue();
			}
			pm.setRows(this.getMapper(YdmProductMoveMapper.class).doQueryWebBySQLR
					((pageIndex-1)*pageSize, (pageIndex-1)*pageSize+pageSize, cp.getStartTime(), cp.getEndTime(), cp.getObject().getCoilno(), cp.getObject().getSteelcode(),hmin,hmax,wmin,wmax,cp.getObject().getStorageattr(),cp.getObject().getIsaccept()));
			pm.setTotal(this.getMapper(YdmProductMoveMapper.class).doQueryWebBySQLRCount
					(cp.getStartTime(), cp.getEndTime(), cp.getObject().getCoilno(), cp.getObject().getSteelcode(),hmin,hmax,wmin,wmax,cp.getObject().getStorageattr(),cp.getObject().getIsaccept()));
			rm.setData(pm);
			rm.setState("200");
		} 
		catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 移送管理  分组显示(已接收)
	 * */
	public ResultModel doQueryWebBySQLA(CommonPage<YdmProductMove> cp) {
		ResultModel rm=new ResultModel();
		int pageSize=cp.getPageSize();
		int pageIndex=cp.getPageIndex();
		PageModel<YdmProductMove> pm=new PageModel<YdmProductMove>(pageIndex, pageSize);
		try  {
			String regex = "^(\\d+\\.?\\d*)$";	
			boolean isMatch = true;
			Object hmin="",hmax="",wmin="",wmax="";
			if (cp.getMemo1() != null && cp.getMemo1() != "") {
				isMatch = Pattern.matches(regex, cp.getMemo1().trim());
				if (!isMatch) {
					rm.setState("500");
					rm.setMsgInfo("请输入正确的厚度和宽度!");
					return rm;
				}
				hmin = Double.valueOf(cp.getMemo1()).doubleValue();
			}
			if (cp.getMemo2() != null && cp.getMemo2() != "") {
				isMatch = Pattern.matches(regex, cp.getMemo2().trim());
				if (!isMatch) {
					rm.setState("500");
					rm.setMsgInfo("请输入正确的厚度和宽度!");
					return rm;
				}
				hmax = Double.valueOf(cp.getMemo2()).doubleValue();
			}
			if (cp.getMemo3() != null && cp.getMemo3() != "") {
				isMatch = Pattern.matches(regex, cp.getMemo3().trim());
				if (!isMatch) {
					rm.setState("500");
					rm.setMsgInfo("请输入正确的厚度和宽度!");
					return rm;
				}
				wmin = Double.valueOf(cp.getMemo3()).doubleValue();
			}
			if (cp.getMemo4() != null && cp.getMemo4() != "") {
				isMatch = Pattern.matches(regex, cp.getMemo4().trim());
				if (!isMatch) {
					rm.setState("500");
					rm.setMsgInfo("请输入正确的厚度和宽度!");
					return rm;
				}
				wmax = Double.valueOf(cp.getMemo4()).doubleValue();
			}
			pm.setRows(this.getMapper(YdmProductMoveMapper.class).doQueryWebBySQLA
					((pageIndex-1)*pageSize, (pageIndex-1)*pageSize+pageSize, cp.getStartTime(), cp.getEndTime(), cp.getObject().getCoilno(), cp.getObject().getSteelcode(),hmin,hmax,wmin,wmax,cp.getObject().getStorageattr(),cp.getObject().getMaterailcoilno()));
			pm.setTotal(this.getMapper(YdmProductMoveMapper.class).doQueryWebBySQLACount
					(cp.getStartTime(), cp.getEndTime(), cp.getObject().getCoilno(), cp.getObject().getSteelcode(),hmin,hmax,wmin,wmax,cp.getObject().getStorageattr()));
			rm.setData(pm);
			rm.setState("200");
		} 
		catch (Exception ex) 
		{
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 移送管理  明细显示
	 * */
	public ResultModel doQueryWebBySQLDetail(CommonPage<YdmProductMove> cp) {
		ResultModel rm=new ResultModel();
		int pageSize=cp.getPageSize();
		int pageIndex=cp.getPageIndex();
		PageModel<YdmProductMove> pm=new PageModel<YdmProductMove>(pageIndex, pageSize);
		try {
			pm.setRows(this.getMapper(YdmProductMoveMapper.class).doQueryWebBySQLDetail
					((pageIndex-1)*pageSize, (pageIndex-1)*pageSize+pageSize,cp.getObject().getBillno(),cp.getObject().getIsaccept()));
			pm.setTotal(this.getMapper(YdmProductMoveMapper.class).doQueryWebBySQLDetailCount(cp.getObject().getBillno(),cp.getObject().getIsaccept()));
			rm.setData(pm);
			rm.setState("200");
		} 
		catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 移送管理 移库确认
	 * memo1-3分别传接收单位(id+text)/接收仓库的id,memo4传车号
	 * @throws Exception 
	 * */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doConfirm(CommonPage<YdmProductDetail> 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);
		String order=(String)this.getSession().getAttribute(HomeService.SESSION_WORK_ORD);
		String team=(String)this.getSession().getAttribute(HomeService.SESSION_WORK_GRP);
		try {
			List<YdmProductDetail> list=cp.getObjectList();
			String billno=this.createBILLNO();
			Date date=new Date();
			for(YdmProductDetail ypd:list) {
				if (ypd.getLength()==null||"".equals(ypd.getLength())) {
					ypd.setLength(0.0);
				}
				ypd.setCreater(username);
				if (ypd.getCreatedate()==null||"".equals(ypd.getCreatedate())) {
					ypd.setCreatedate(new Date());
				}
				ypd.setCoiltype("0");
				ypd.setSource("1");
				ypd.setState("0");
				if (ypd.getGrossweight()==null||"".equals(ypd.getGrossweight())) {
					ypd.setGrossweight(0.0);
				}
				if (ypd.getPackweight()==null||"".equals(ypd.getPackweight())) {
					ypd.setPackweight(0.0);
				}
				if(ypd.getIndate()==null||"".equals(ypd.getIndate())) {
					ypd.setIndate(new Date());
				}
				ypd.setInorder(order);
				ypd.setQuantity(0);
				if (ypd.getProd_code()==null||"".equals(ypd.getProd_code())) {
					ypd.setProd_code("0");
				}
				if (ypd.getCoilno()==null||"".equals(ypd.getCoilno())) {
					ypd.setCoilno("0");
				}
				if (ypd.getJudgesteelcode()==null||"".equals(ypd.getJudgesteelcode())) {
					ypd.setJudgesteelcode("0");
				}
				if (ypd.getAllot_no()==null||"".equals(ypd.getAllot_no())) {
					ypd.setAllot_no("0");
				}
				if (ypd.getLength()==null||"".equals(ypd.getLength())) {
					ypd.setLength(0.0);
				}
				if (ypd.getBatchno()==null||"".equals(ypd.getBatchno())) {
					ypd.setBatchno("0");
				}
				if (ypd.getMaterailtype()==null||"".equals(ypd.getMaterailtype())) {
					ypd.setMaterailtype("0");
				}
				if (ypd.getCoreweight()==null||"".equals(ypd.getCoreweight())) {
					ypd.setCoreweight(0.0);
				}
				if (ypd.getInorder()==null||"".equals(ypd.getInorder())) {
					ypd.setInorder("0");
				}
				if (ypd.getMaterailorderno()==null||"".equals(ypd.getMaterailorderno())) {
					ypd.setMaterailorderno("0");
				}
				if (ypd.getTheoryweight()==null||"".equals(ypd.getTheoryweight())) {
					ypd.setTheoryweight(0.0);
				}
				if (ypd.getIndate()==null||"".equals(ypd.getIndate())) {
					ypd.setIndate(new Date());
				}
				if (ypd.getMaterailsupplier()==null||"".equals(ypd.getMaterailsupplier())) {
					ypd.setMaterailsupplier("0");
				}
				if (ypd.getFactweight()==null||"".equals(ypd.getFactweight())) {
					ypd.setFactweight(0.0);
				}
				if (ypd.getMemo()==null||"".equals(ypd.getMemo())) {
					ypd.setMemo("无");
				}
				if (ypd.getSteelcode()==null||"".equals(ypd.getSteelcode())) {
					ypd.setSteelcode("0");
				}
				if (ypd.getStd_name()==null||"".equals(ypd.getStd_name())) {
					ypd.setStd_name(" ");
				}
				//插入出库信息
				YdmProductOutlist ypo=new YdmProductOutlist();
				ypo.setOuttype("500502");
				ypo.setOutoperator(username);
				ypo.setOutdate(date);
				ypo.setOutorder(order);
				ypo.setOutteam(team);
				ypo.setCreater(username);
				ypo.setCreatedate(date);
				ypo.setOutbillno(this.getBean(YdmProductOutlistServiceImpl.class).createOUTBILLNO());
				ypo.setCoilno(ypd.getCoilno());
				ypo.setCoiltype(ypd.getCoiltype());
				ypo.setMaterailtype(ypd.getMaterailtype());
				ypo.setSource(ypd.getSource());
				ypo.setMaterailsupplier(ypd.getMaterailsupplier());
				ypo.setIsbox(ypd.getIsbox());
				ypo.setBoxno(ypd.getBoxno());
				ypo.setDrawingno(ypd.getDrawingno());
				ypo.setBatchno(ypd.getBatchno());
				ypo.setHeatno(ypd.getBatchno());
				ypo.setSmpno(ypd.getSmpno());
				ypo.setManagementno(ypd.getManagementno());
				ypo.setStorageattr(ypd.getStorageattr());
				ypo.setProd_code(ypd.getProd_code());
				ypo.setProd_name(ypd.getProd_name());
				ypo.setStd_code(ypd.getStd_code());
				ypo.setStd_name(ypd.getStd_name());
				ypo.setUse_code(ypd.getUse_code());
				ypo.setUse_name(ypd.getUse_name());
				ypo.setPline_name(ypd.getPline_name());
				ypo.setPostid(ypd.getPostid());
				ypo.setThick(ypd.getThick());
				ypo.setWidth(ypd.getWidth());
				ypo.setLength(ypd.getLength());
				ypo.setDiameter_inn(ypd.getDiameter_inn());
				ypo.setDiameter_out(ypd.getDiameter_out());
				ypo.setQuantity(ypd.getQuantity());
				ypo.setTheoryweight(ypd.getTheoryweight());
				ypo.setCoreweight(ypd.getCoreweight());
				ypo.setGrossweight(ypd.getGrossweight());
				ypo.setPackweight(ypd.getPackweight());
				ypo.setFactweight(ypd.getFactweight());
				ypo.setCustomer_nm(ypd.getCustomer_nm());
				ypo.setCustomer_no(ypd.getCustomer_no());
				ypo.setReceiv_no(ypd.getReceiv_no());
				ypo.setReceiv_nm(ypd.getReceiv_nm());
				ypo.setOrderno(ypd.getOrderno());
				ypo.setProdorderno(ypd.getProdorderno());
				ypo.setSteelcode(ypd.getSteelcode());
				ypo.setJudgesteelcode(ypd.getJudgesteelcode());
				ypo.setPacking_group(ypd.getPacking_group());
				ypo.setChemresult(ypd.getChemresult());
				ypo.setSizeresult(ypd.getSizeresult());
				ypo.setSurfaceresult(ypd.getSurfaceresult());
				ypo.setWeightresult(ypd.getWeightresult());
				ypo.setJudgeresult(ypd.getJudgeresult());
				ypo.setPhysresult(ypd.getPhysresult());
				ypo.setSpyresult(ypd.getSpyresult());
				ypo.setProducedate(ypd.getProducedate());
				ypo.setProduceorder(ypd.getProduceorder());
				ypo.setProduceteam(ypd.getProduceteam());
				ypo.setIndate(ypd.getIndate());
				ypo.setInorder(ypd.getInorder());
				ypo.setInteam(ypd.getInteam());
				ypo.setButtressno(ypd.getButtressno());
				//4.24
				if(ypd.getLocality()!=null&&!ypd.getLocality().equals("")){
				     ypo.setLocality((long) Integer.valueOf(ypd.getLocality()).intValue());
				}
				ypo.setLayer(ypd.getLayer());
				
				// 加入物料属性：20230725刘侣
				ypo.setObj_attr_out(ypd.getObject_attr());
				// end
				
				//4.24
				this.getMapper(YdmProductOutlistMapper.class).insert(ypo);
				//插入移库信息
				YdmProductMove ypm=new YdmProductMove();
				ypm.setMovebillno(this.createMOVEBILLNO());
				ypm.setOutbillno(ypo.getOutbillno());
				ypm.setBillno(billno);
				ypm.setMovedate(date);
				ypm.setMoveoperator(username);
				ypm.setCreatedate(date);
				ypm.setCreater(username);
				ypm.setCarno(cp.getMemo4());
				ypm.setRemanagementno(cp.getMemo1());
				ypm.setRestorageattr(cp.getMemo3());
				ypm.setCoilno(ypd.getCoilno());
				ypm.setCoiltype(ypd.getCoiltype());
				ypm.setMaterailtype(ypd.getMaterailtype());
				ypm.setSource(ypd.getSource());
				ypm.setMaterailsupplier(ypd.getMaterailsupplier());
				ypm.setIsbox(ypd.getIsbox());
				ypm.setBoxno(ypd.getBoxno());
				ypm.setDrawingno(ypd.getDrawingno());
				ypm.setBatchno(ypd.getBatchno());
				ypm.setHeatno(ypd.getBatchno());
				ypm.setSmpno(ypd.getSmpno());
				ypm.setManagementno(ypd.getManagementno());
				ypm.setStorageattr(ypd.getStorageattr());
				ypm.setProd_code(ypd.getProd_code());
				ypm.setProd_name(ypd.getProd_name());
				ypm.setStd_code(ypd.getStd_code());
				ypm.setStd_name(ypd.getStd_name());
				ypm.setUse_code(ypd.getUse_code());
				ypm.setUse_name(ypd.getUse_name());
				ypm.setPline_name(ypd.getPline_name());
				ypm.setPostid(ypd.getPostid());
				ypm.setThick(ypd.getThick());
				ypm.setWidth(ypd.getWidth());
				ypm.setLength(ypd.getLength());
				ypm.setDiameter_inn(ypd.getDiameter_inn());
				ypm.setDiameter_out(ypd.getDiameter_out());
				ypm.setQuantity(ypd.getQuantity());
				ypm.setTheoryweight(ypd.getTheoryweight());
				ypm.setCoreweight(ypd.getCoreweight());
				ypm.setGrossweight(ypd.getGrossweight());
				ypm.setPackweight(ypd.getPackweight());
				ypm.setFactweight(ypd.getFactweight());
				ypm.setCustomer_nm(ypd.getCustomer_nm());
				ypm.setCustomer_no(ypd.getCustomer_no());
				ypm.setReceiv_no(ypd.getReceiv_no());
				ypm.setReceiv_nm(ypd.getReceiv_nm());
				ypm.setOrderno(ypd.getOrderno());
				ypm.setProdorderno(ypd.getProdorderno());
				ypm.setSteelcode(ypd.getSteelcode());
				ypm.setJudgesteelcode(ypd.getJudgesteelcode());
				ypm.setPacking_group(ypd.getPacking_group());
				ypm.setChemresult(ypd.getChemresult());
				ypm.setSizeresult(ypd.getSizeresult());
				ypm.setSurfaceresult(ypd.getSurfaceresult());
				ypm.setWeightresult(ypd.getWeightresult());
				ypm.setJudgeresult(ypd.getJudgeresult());
				ypm.setPhysresult(ypd.getPhysresult());
				ypm.setSpyresult(ypd.getSpyresult());
				ypm.setProducedate(ypd.getProducedate());
				ypm.setProduceorder(ypd.getProduceorder());
				ypm.setProduceteam(ypd.getProduceteam());
				ypm.setIndate(ypd.getIndate());
				ypm.setInorder(ypd.getInorder());
				ypm.setInteam(ypd.getInteam());
				ypm.setArea(ypd.getAreaname());//区域
				ypm.setButtressname(ypd.getButtressname());//垛位
				ypm.setLocation(ypd.getLocality());//位置
				this.getMapper(YdmProductMoveMapper.class).insert(ypm);
				//删除垛位信息
				if((ypd.getBoxno()!=null&&ypd.getBoxno()!="")||(ypd.getCoilno()!=null&&ypd.getCoilno()!=""))
					this.getMapper(YdmProductButtresslistMapper.class).doDelete(ypd.getCoilno(), ypd.getBoxno());
				//修改库存信息
				ypd.setState("1");
				ypd.setUpdater(username);
				ypd.setUpdatedate(date);
				this.getMapper(YdmProductDetailMapper.class).doUpdate(ypd);
				//调用生产计划模块物料跟踪接口
				PrcMaterielProcess pmp = new PrcMaterielProcess();
				pmp.setObject_no(ypd.getCoilno());
				pmp.setPrc_code("5BYS10");
				pmp.setCreate_time(now);
				pmp.setRemark("移送出库");
				pmp.setCreate_man_name(username);
				PrcMaterielProcess pmp1 = new PrcMaterielProcess();
				pmp1.setObject_no(ypd.getCoilno());
				pmp1.setPrc_code("5BYS03");
				pmp1.setCreate_time(now);
				pmp1.setRemark(""+opr_time);
				pmp1.setCreate_man_name(username);
				//日志
				MesOprLog mol = new MesOprLog("物流管理", "移送管理", "移送确认", username, opr_time, ypd.getCoilno(), null, null, null, "原料卷号："+ypd.getMaterailcoilno());
				this.getMapper(MesOprLogMapper.class).insert(mol);
			}
			rm.setState("200");
		}
		catch(Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("确认失败!");
			ex.printStackTrace();
			throw ex;
		}
		return rm;
	}
	
	/**
	 * 移送管理 撤销移库
	 * memo1-3分别放区域id/货位id/位置
	 * @throws Exception 
	 * */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doCancel(CommonPage<YdmProductMove> 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<YdmProductMove> list=cp.getObjectList();
		
		try {			
			for(YdmProductMove ydm:list) {
				//查询移送是否被接收
				YdmProductMove y= this.getMapper(YdmProductMoveMapper.class).findById(ydm.getMovebillno());
				String a=y.getIsaccept();
				if (a.equals("0")) {
					//删除出库信息
					this.getMapper(YdmProductOutlistMapper.class).doDelete(ydm.getOutbillno());
					//删除移库信息
					this.getMapper(YdmProductMoveMapper.class).doDelete(ydm.getMovebillno());
					//插入垛位信息
					YdmProductButtresslist ypb=new YdmProductButtresslist();
					ypb.setCreater(username);
					ypb.setCreatedate(new Date());
					if(cp.getMemo2()==null||cp.getMemo2().equals("")){
						throw new Exception("请传入堆放货位");
					}
					ypb.setButtressno(cp.getMemo2());
					if(cp.getMemo3()!=null&&cp.getMemo3()!=""){
						ypb.setLocality(Integer.valueOf(cp.getMemo3()).intValue());
					}else{
						throw new Exception("请传入堆放位置!");
					}
					
					// ydm.getRestorageattr()
				    // 需加工挂单重新入原料库的话，那么这次入成品库的卷的入库记录的仓库要为在制品库：这样才符合成本的逻辑，本道工序应体现为在制品：20230523刘侣
					// 采用最后一次入库记录的storageattr，所以这个逻辑废除：20230524刘侣
				    // 原仓库得是 在制品库或者成品库：
//				    if ("500202".equals(ydm.getStorageattr()) || "500203".equals(ydm.getStorageattr())) {
//				     List<YdmProductInlist> curYpiL = this.getMapper(YdmProductInlistMapper.class).findWithCondition(null, " COILNO = '"+ydm.getCoilno()+"'", "CREATEDATE", 0, 0);
//				        // 将第一条的仓库改成在制品库：
//				        YdmProductInlist ypiZZPK = curYpiL.get(0);
//				        ypiZZPK.setStorageattr(ydm.getStorageattr());
//				        this.getMapper(YdmProductInlistMapper.class).update(ypiZZPK);
//				    }
				    // end
					
					YdmProductButtresslist ydmcp = new YdmProductButtresslist();
					ydmcp.setButtressno(cp.getMemo2());
					ydmcp.setLocality(ypb.getLocality());
					int layer = this.getBean(YdmProductButtresslistMapper.class).getMaxlayerXy(ydmcp);
					ypb.setLayer(layer);
					//4.24
					ypb.setStorageattr(ydm.getStorageattr());
					ypb.setAreano(cp.getMemo1());
					ypb.setCoilno(ydm.getCoilno());
					ypb.setBoxno(ydm.getBoxno());
					this.getMapper(YdmProductButtresslistMapper.class).doInsert(ypb);
					//修改库存信息
					YdmProductDetail ypd=new YdmProductDetail();
					ypd.setState("0");
					ypd.setCoilno(ydm.getCoilno());
					ypd.setBoxno(ydm.getBoxno());
					ypd.setUpdater(username);
					ypd.setUpdatedate(new Date());
					this.getMapper(YdmProductDetailMapper.class).doUpdate(ypd);
					//调用生产计划模块物料跟踪撤销接口
					PrcMaterielProcess pmp =new PrcMaterielProcess();
					pmp.setObject_no(ypd.getCoilno());
					pmp.setPrc_code("5BYS10");
					pmp.setKeep_sametime_status(0);
					pmp.setRemark("移库出库撤销");
					//、日志
					MesOprLog mol = new MesOprLog("物流管理", "移送管理", "移送撤销", username, opr_time, ypd.getCoilno(), null, null, null, "原料卷号："+ypd.getMaterailcoilno());
					this.getMapper(MesOprLogMapper.class).insert(mol);			
					rm.setState("200");
				}else {
					rm.setState("500");
					rm.setMsgInfo("已经被接收无法撤销");
					throw new Exception("已经被接收无法撤销");
				}
			}			
		} catch(Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("确认失败!");
			ex.printStackTrace();
			throw ex;
		}
		return rm;
	}
	
	/**
	 * 移库管理 接收确认
	 * memo1-4存界面区域货位id，位置，备注
	 * */
	public ResultModel doRecConfirm(CommonPage<YdmProductMove> 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);
		try {
			List<YdmProductMove> list=cp.getObjectList();
			for(YdmProductMove ydm:list) {
				//插入入库信息
				YdmProductInlist ypi=new YdmProductInlist();
				ypi.setInbillno(this.getBean(YdmProductInlistServiceImpl.class).createINBILLNO());
				ypi.setCreater(username);
				ypi.setCreatedate(now);
				ypi.setIndate(now);
				ypi.setOperator(username);
				ypi.setIntype("500404");
				ypi.setMemo(cp.getMemo4());
				ypi.setButtressno(cp.getMemo2());
				//4.24
				if(cp.getMemo3()!=null&&cp.getMemo3()!=""){
					ypi.setPosition(cp.getMemo3());
				}else{
					throw new Exception("请传入堆放位置!");
				}
				
				// ydm.getRestorageattr()
				
				
				YdmProductButtresslist ydmcp = new YdmProductButtresslist();
				ydmcp.setButtressno(cp.getMemo2());
				//2018-05-05修改
				ydmcp.setLocality(Integer.valueOf(ypi.getPosition()).intValue());
				int layer = this.getBean(YdmProductButtresslistMapper.class).getMaxlayerXy(ydmcp);
				ypi.setLocality(String.valueOf(layer).toString());
				//4.24
				ypi.setCoilno(ydm.getCoilno());
				ypi.setCoiltype(ydm.getCoiltype());
				ypi.setMaterailtype(ydm.getMaterailtype());
				ypi.setSource(ydm.getSource());
				ypi.setMaterailsupplier(ydm.getMaterailsupplier());
				ypi.setIsbox(ydm.getIsbox());
				ypi.setBoxno(ydm.getBoxno());
				ypi.setDrawingno(ydm.getDrawingno());
				ypi.setBatchno(ydm.getBatchno());
				ypi.setHeatno(ydm.getBatchno());
				ypi.setSmpno(ydm.getSmpno());
				ypi.setManagementno(ydm.getManagementno());
				ypi.setStorageattr(ydm.getRestorageattr());
				ypi.setProd_code(ydm.getProd_code());
				ypi.setProd_name(ydm.getProd_name());
				ypi.setStd_code(ydm.getStd_code());
				ypi.setStd_name(ydm.getStd_name());
				ypi.setUse_code(ydm.getUse_code());
				ypi.setUse_name(ydm.getUse_name());
				ypi.setPline_name(ydm.getPline_name());
				ypi.setPostid(ydm.getPostid());
				ypi.setThick(ydm.getThick());
				ypi.setWidth(ydm.getWidth());
				ypi.setLength(ydm.getLength());
				ypi.setDiameter_inn(ydm.getDiameter_inn());
				ypi.setDiameter_out(ydm.getDiameter_out());
				ypi.setQuantity(ydm.getQuantity());
				ypi.setTheoryweight(ydm.getTheoryweight());
				ypi.setCoreweight(ydm.getCoreweight());
				ypi.setGrossweight(ydm.getGrossweight());
				ypi.setPackweight(ydm.getPackweight());
				ypi.setFactweight(ydm.getFactweight());
				ypi.setCustomer_nm(ydm.getCustomer_nm());
				ypi.setCustomer_no(ydm.getCustomer_no());
				ypi.setReceiv_no(ydm.getReceiv_no());
				ypi.setReceiv_nm(ydm.getReceiv_nm());
				ypi.setOrderno(ydm.getOrderno());
				ypi.setProdorderno(ydm.getProdorderno());
				ypi.setSteelcode(ydm.getSteelcode());
				ypi.setJudgesteelcode(ydm.getJudgesteelcode());
				ypi.setPacking_group(ydm.getPacking_group());
				ypi.setChemresult(ydm.getChemresult());
				ypi.setSizeresult(ydm.getSizeresult());
				ypi.setSurfaceresult(ydm.getSurfaceresult());
				ypi.setWeightresult(ydm.getWeightresult());
				ypi.setJudgeresult(ydm.getJudgeresult());
				ypi.setPhysresult(ydm.getPhysresult());
				ypi.setSpyresult(ydm.getSpyresult());
				ypi.setProducedate(ydm.getProducedate());
				ypi.setProduceorder(ydm.getProduceorder());
				ypi.setProduceteam(ydm.getProduceteam());
				ypi.setInorder(ydm.getInorder());
				ypi.setInteam(ydm.getInteam());
				
				
				// 加入物料属性：20230725刘侣
				YdmProductDetail yd= new YdmProductDetail();
			    yd.setCoilno(ydm.getCoilno());
			    //获取老卷号信息
			    List<YdmProductDetail> ago = this.getMapper(YdmProductDetailMapper.class).find(yd, 0, 1);
			    if (ago.size() > 0) {
			    	ypi.setObj_attr_in(ago.get(0).getObject_attr());
			    }
				// end
				
				this.getMapper(YdmProductInlistMapper.class).insert(ypi);
				//插入垛位信息
				YdmProductButtresslist ypb=new YdmProductButtresslist();
				ypb.setCreatedate(now);
				ypb.setCreater(username);
				ypb.setButtressno(cp.getMemo2());
				ypb.setLayer(layer);
				if(cp.getMemo3()!=null&&cp.getMemo3()!=""){
					ypb.setLocality(Integer.parseInt(cp.getMemo3()));
				}else{
					throw new Exception("请传入堆放位置!");
				}
				//判断现有垛位上是否存在物料
				String condition = " and buttressno = '"+ypb.getButtressno()+"' and layer = '"+ypb.getLayer()+"' and locality = '"+ypb.getLocality()+"'";
				int count = this.getMapper(YdmProductButtresslistMapper.class).countWithCondition(null, condition);
				if (count > 0) {
					throw new Exception("目标垛位已经存在物料信息，无法移送接收");
				}
				//4.24
				ypb.setStorageattr(ydm.getRestorageattr());
				ypb.setAreano(cp.getMemo1());
				ypb.setCoilno(ydm.getCoilno());
				ypb.setBoxno(ydm.getBoxno());
				this.getMapper(YdmProductButtresslistMapper.class).doInsert(ypb);
				//修改库存信息
				YdmProductDetail ypd=new YdmProductDetail();
				ypd.setStorageattr(ydm.getRestorageattr());
				ypd.setUpdater(username);
				ypd.setUpdatedate(now);
				ypd.setIndate(now);
				ypd.setCreater(username);
				ypd.setState("0");
				ypd.setMemo(cp.getMemo4());
				ypd.setCoilno(ydm.getCoilno());
				ypd.setBoxno(ydm.getBoxno());
				this.getMapper(YdmProductDetailMapper.class).doUpdate(ypd);
				//修改移库信息
				ydm.setInbillno(ypi.getInbillno());
				ydm.setAcceptdate(now);
				ydm.setAcceptoperator(username);
				ydm.setAcceptorder("2");      //暂时默认2,3
				ydm.setAcceptteam("3");
				ydm.setUpdater(username);
				ydm.setUpdatedate(now);
				ydm.setIndate(now);
				ydm.setIsaccept("1");
				ydm.setMemo(cp.getMemo4());
				this.getMapper(YdmProductMoveMapper.class).update(ydm);		
				//日志
				MesOprLog mol = new MesOprLog("物流管理", "移送接收管理", "接收确认", username, opr_time, ypd.getCoilno(), null, null, null, "原料卷号："+ypd.getMaterailcoilno());
				this.getMapper(MesOprLogMapper.class).insert(mol);
			}
			rm.setState("200");
		} catch(Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("确认失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 移库管理 接收撤销
	 * */
	public ResultModel doRecCancel(CommonPage<YdmProductMove> 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<YdmProductMove> list=cp.getObjectList();
		try {
			for(YdmProductMove ypm:list) {
				// 点撤销接收的时候判断是否是否在库：2022090401刘侣 start
				YdmProductDetail ypdOld = this.getMapper(YdmProductDetailMapper.class).findById(ypm.getCoilno());
				if (!"0".equals(ypdOld.getState()) || ypdOld == null) {
					rm.setState("500");
					rm.setMsgInfo("当前卷不在库，无法撤销接收!");
					return rm;
				}
				// end
				
				//删除入库信息
				if(ypm.getInbillno()!=null&&ypm.getInbillno()!="")
					this.getMapper(YdmProductInlistMapper.class).doDelete(ypm.getInbillno());
				//删除垛位信息
				if((ypm.getBoxno()!=null&&ypm.getBoxno()!="")||(ypm.getCoilno()!=null&&ypm.getCoilno()!=""))
					this.getMapper(YdmProductButtresslistMapper.class).doDelete(ypm.getCoilno(), ypm.getBoxno());
				//修改移库信息
				ypm.setIsaccept("0");
				ypm.setAcceptoperator(null);
				ypm.setAcceptorder(null);
				ypm.setAcceptteam(null);
				ypm.setAcceptdate(null);
				ypm.setInbillno(null);
				ypm.setUpdater(username);
				ypm.setUpdatedate(now);
				this.getMapper(YdmProductMoveMapper.class).update(ypm);
				//修改库存信息
				YdmProductDetail ypd=new YdmProductDetail();
				ypd.setUpdatedate(now);
				ypd.setUpdater(username);
				ypd.setState("1");
				ypd.setStorageattr(ypm.getStorageattr());
				ypd.setCoilno(ypm.getCoilno());
				ypd.setBoxno(ypm.getBoxno());
				this.getMapper(YdmProductDetailMapper.class).doUpdate(ypd);
				
				MesOprLog mol = new MesOprLog("物流管理", "移送接收管理", "接收撤销", username, opr_time, ypd.getCoilno(), null, null, null, "原料卷号："+ypd.getMaterailcoilno());
				this.getMapper(MesOprLogMapper.class).insert(mol);
			}
			rm.setState("200");
		}
		catch(Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("撤销失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
}
