/***文档注释***********************************************
 * 作者               :                   易鑫
 * 创建日期      :                   2017.11.21
 * 描述               :        			成品卷包装计量主实绩
 * 注意事项      :                   无
 * 遗留BUG :                   无
 * 修改日期      :                   
 * 修改人员      :                   
 * 修改内容      :                   
***********************************************************/

package market.Mes.Packing.Performance.impl;

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

import market.Api.Lms.impl.LmsApiServiceImpl;
import market.Com.mapper.ComBaseInfoMapper;
import market.Com.mapper.ComBaseMachineMapper;
import market.Com.vo.ComBaseInfo;
import market.Com.vo.ComBaseMachine;
import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Lms.Warehouse.mapper.YdmProductDetailMapper;
import market.Lms.Warehouse.vo.YdmProductDetail;
import market.Mes.Lengthwise.Plan.mapper.PlnMaterielDetailMapper;
import market.Mes.Lengthwise.Plan.vo.PlnMaterielDetail;
import market.Mes.Packing.Performance.mapper.MesCoilPackingDMapper;
import market.Mes.Packing.Performance.mapper.MesCoilPackingMMapper;
import market.Mes.Packing.Performance.service.MesCoilPackingMService;
import market.Mes.Packing.Performance.vo.MesCoilPackingD;
import market.Mes.Packing.Performance.vo.MesCoilPackingM;
import market.Mes.Packing.Plan.mapper.PlnPackingPlanDetailMapper;
import market.Mes.Packing.Plan.mapper.PlnPackingPlanMapper;
import market.Mes.Packing.Plan.vo.PlnPackingPlan;
import market.Mes.Packing.Plan.vo.PlnPackingPlanDetail;
import market.Mes.Packing.Plan.vo.PlnPackingPlanSum;

import org.springframework.transaction.annotation.Transactional;

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

@RemoteService(path="MesCoilPackingMService")
public class MesCoilPackingMServiceImpl extends BaseServiceImpl<MesCoilPackingM,Object> implements MesCoilPackingMService {
	/**
	 * ******车间MES********
	 * 查询包装实绩信息
	 * startTime 开始时间
	 * endTime 结束时间
	 * memo1 coil_no 包含卷号
	 * */
	public ResultModel doQueryWeb(CommonPage<MesCoilPackingM> oci){
		ResultModel rm=new ResultModel();
		try{
			String wrk_ord = (String) this.getSession().getAttribute(HomeService.SESSION_WORK_ORD);
			String wrk_grp = (String) this.getSession().getAttribute(HomeService.SESSION_WORK_GRP);
			String wrk_date = (String) this.getSession().getAttribute(HomeService.SESSION_WORK_TIME);
			oci.getObject().setWrk_ord(wrk_ord);
			oci.getObject().setWrk_grp(wrk_grp);
			oci.getObject().setWrk_date(wrk_date);
			
			rm.setData(this.getMapper(MesCoilPackingMMapper.class).doQuery(oci.getObject(),oci.getStartTime(),oci.getEndTime(),oci.getMemo1()));
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * ******车间MES********
	 * 刷新当班实绩信息
	 * startTime 开始时间
	 * endTime 结束时间
	 * memo1 coil_no 包含卷号
	 * */
	public ResultModel doQueryWrkWeb(CommonPage<MesCoilPackingM> oci){
		ResultModel rm=new ResultModel();
		try{
			String wrk_ord = (String) this.getSession().getAttribute(HomeService.SESSION_WORK_ORD);
			String wrk_grp = (String) this.getSession().getAttribute(HomeService.SESSION_WORK_GRP);
			String wrk_date = (String) this.getSession().getAttribute(HomeService.SESSION_WORK_TIME);
			oci.getObject().setWrk_ord(wrk_ord);
			oci.getObject().setWrk_grp(wrk_grp);
			oci.getObject().setWrk_date(wrk_date);
			
			rm.setData(this.getMapper(MesCoilPackingMMapper.class).doQueryWrk(oci.getObject()));
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	}
	/**
	 * 查询当班汇总信息
	 * */
	public ResultModel doQueryWrkSum(CommonPage<MesCoilPackingM> oci){
		ResultModel rm=new ResultModel();
		try{
			String wrk_ord = (String) this.getSession().getAttribute(HomeService.SESSION_WORK_ORD);
			String wrk_grp = (String) this.getSession().getAttribute(HomeService.SESSION_WORK_GRP);
			String wrk_date = (String) this.getSession().getAttribute(HomeService.SESSION_WORK_TIME);
			oci.getObject().setWrk_ord(wrk_ord);
			oci.getObject().setWrk_grp(wrk_grp);
			oci.getObject().setWrk_date(wrk_date);
			
			rm.setData(this.getMapper(MesCoilPackingMMapper.class).doQueryWrkSum(oci.getObject()));
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 新增包装实绩
	 * memo1 machine_code
	 * memo2 P1卷包号
	 * memo3 包装等级
	 * memo4 毛,皮,净重
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doAddWeb(CommonPage<PlnPackingPlanSum> oci) throws Exception{
		ResultModel rm=new ResultModel();
		ComBaseMachine cbm=this.getMapper(ComBaseMachineMapper.class).findById(oci.getMemo2());
		String P1=oci.getMemo2()==null?"":oci.getMemo2().trim();
		
		String wrk_ord = (String) this.getSession().getAttribute(HomeService.SESSION_WORK_ORD);
		String wrk_grp = (String) this.getSession().getAttribute(HomeService.SESSION_WORK_GRP);
		String wrk_date = (String) this.getSession().getAttribute(HomeService.SESSION_WORK_TIME);
		
		int maxNo=1;
		String p1Top="";
		if("".equals(P1)){
			//1位包装线编号（1、2）+ 1位固定字符'-' + 6位年月日（YYMMDD）+ 5位流水号（00001 - 99999），共 13 位字符串
			P1=cbm.getMachine_mark()+"-"+new SimpleDateFormat("yyMMdd").format(new Date());
			p1Top=P1;
			List<MesCoilPackingM> lmcpm=this.getMapper(MesCoilPackingMMapper.class).findWithCondition(null, " substr(packing_no,1,8)='"+P1+"' ", "", 0, 1);
			if(lmcpm!=null&&lmcpm.size()>0){
				maxNo=Integer.parseInt(lmcpm.get(0).getPacking_no().substring(9,13))+1;
			}
			P1+=String.format("%05d", maxNo);//取后5位
		}
		
		MesCoilPackingM mcpm=new MesCoilPackingM();
		List<MesCoilPackingD> lmcpd=new ArrayList<MesCoilPackingD>();
		//验证订单号
		String sOrder="";
		List<PlnPackingPlanSum> lppps=oci.getObjectList();
		List<PlnPackingPlanDetail> lpppdu=new ArrayList<PlnPackingPlanDetail>();
		
		for(PlnPackingPlanSum ppps:lppps){
			//逐一验证勾选的作业计划主表记录存在
			PlnPackingPlan ppp=new PlnPackingPlan();
			ppp.setMachine_code(oci.getMemo1());
			ppp.setPk_plan_no(ppps.getPk_plan_no());
			List<PlnPackingPlan> lppp=this.getMapper(PlnPackingPlanMapper.class).find(ppp, 0, 0);
			if(lppp==null||lppp.size()==0){
				rm.setState("500");
				rm.setMsgInfo("作业计划主表记录不存在！");
				return rm;
			}
			
			//逐一验证勾选的作业计划明细表记录存在
			PlnPackingPlanDetail pppd=new PlnPackingPlanDetail();
			pppd.setMachine_code(oci.getMemo1());
			pppd.setPk_plan_no(ppps.getPk_plan_no());
			pppd.setObject_no_vt(ppps.getObject_no_vt());
			pppd.setObject_no(ppps.getObject_no());
			pppd.setStatus("0PPK02");
			List<PlnPackingPlanDetail> lpppd=this.getMapper(PlnPackingPlanDetailMapper.class).find(pppd, 0, 0);
			if(lpppd==null||lpppd.size()==0){
				rm.setState("500");
				rm.setMsgInfo("作业计划明细表记录不存在！");
				return rm;
			}
			
			//逐一验证库存是否存在
			YdmProductDetail ypd=new YdmProductDetail();
			ypd.setCoilno(ppps.getObject_no());
			ypd.setState("0");
			List<YdmProductDetail> lypd=this.getMapper(YdmProductDetailMapper.class).findWithCondition(ypd, " packing_group is null ", "", 0, 0);
			if(lypd==null||lypd.size()==0){
				rm.setState("500");
				rm.setMsgInfo("钢卷库存明细记录不存在！");
				return rm;
			}
			
			//逐一验证选中的钢卷无包装实绩
			MesCoilPackingD mcpd=new MesCoilPackingD();
			//----------------主键值------------
			mcpd.setCoil_no(ppps.getObject_no());
			
			int icount=this.getMapper(MesCoilPackingDMapper.class).count(mcpd);
			if(icount>0){
				rm.setState("500");
				rm.setMsgInfo("钢卷已存在包装实绩！");
				return rm;
			}
			
			//逐一验证选中的钢卷都属于同一订单号
			if(!"".equals(sOrder)){
				if(!sOrder.equals(ppps.getOrder_no())){
					rm.setState("500");
					rm.setMsgInfo("同一订单的卷才能在一个包装内！");
					return rm;
				}
			}else{
				sOrder=ppps.getOrder_no();
			}
			
			PlnMaterielDetail pmd=new PlnMaterielDetail();
			pmd.setObject_no_vt(lppps.get(0).getObject_no_vt());
			List<PlnMaterielDetail> lpmd=this.getMapper(PlnMaterielDetailMapper.class).find(pmd, 0, 0);
			
			
			//有且只有一个包
			if(mcpm.getPacking_no()==null){
				//验证指定的卷包号在系统中
				if(oci.getMemo2()!=null&&!"".equals(oci.getMemo2())){
					MesCoilPackingM mcpmc=new MesCoilPackingM();
					mcpmc.setPacking_no(oci.getMemo2());
					icount=this.getMapper(MesCoilPackingMMapper.class).count(mcpmc);
					if(icount>0){
						rm.setState("500");
						rm.setMsgInfo("卷包号在系统中已存在！");
						return rm;
					}
					
					ypd.setState(null);
					ypd.setBoxno(oci.getMemo2());
					ypd.setCoilno(oci.getMemo2());
					icount=this.getMapper(YdmProductDetailMapper.class).count(ypd);
					if(icount>0){
						rm.setState("500");
						rm.setMsgInfo("验证卷包号在钢卷库存明细中已存在！");
						return rm;
					}
				}
				//验证指定的包装等级编码基础数据在系统中存在
				ComBaseInfo cbi=new ComBaseInfo();
				cbi.setBase_code(oci.getMemo3());
				icount=this.getMapper(ComBaseInfoMapper.class).count(cbi);
				if(icount==0){
					rm.setState("500");
					rm.setMsgInfo("包装等级编码基础数据在系统中不存在！");
					return rm;
				}
				//验证卷包号在钢卷库存明细中不存在（即不能重复）（YDM_PRODUCT_DETAIL 表中不存在 COILNO = P1 AND BOX_NO = P1 的记录）
				boolean flag=true;
				while(flag){
					ypd.setState(null);
					ypd.setBoxno(P1);
					ypd.setCoilno(P1);
					icount=this.getMapper(YdmProductDetailMapper.class).count(ypd);
					if(icount==0){
						flag=false;
					}else{
						maxNo+=1;//每次加1直到编号不存在为止
						P1=p1Top+String.format("%05d", maxNo);
					}
				}
				
				//构造卷包主数据
				mcpm.setPacking_no(P1);
				mcpm.setPacking_line_code(oci.getMemo1());
				mcpm.setPacking_line_name(cbm.getMachine_name());
				mcpm.setCoil_cnt(lppps.size());
				mcpm.setPacking_group(oci.getMemo3());
				
				mcpm.setOrd_thk(lpmd.get(0).getThick());
				mcpm.setOrd_wdt(lpmd.get(0).getWidth());
				mcpm.setOrd_len(lpmd.get(0).getLength());
				mcpm.setOrd_inn_dia(lpmd.get(0).getDiameter_inn());
				mcpm.setOrd_out_dia(lpmd.get(0).getDiameter_out());
				
				mcpm.setOrder_no(lppp.get(0).getOrder_no());
				mcpm.setProd_order_no(lppp.get(0).getProd_order_no());
				String[] sWgt= oci.getMemo4().split(",");
				if(sWgt.length!=3){
					rm.setState("500");
					rm.setMsgInfo("毛、皮、净参数传入错误！");
					return rm;
				}
				mcpm.setCoil_gross_wgt(Double.parseDouble(sWgt[0]));//毛
				mcpm.setCoil_tare_wgt(Double.parseDouble(sWgt[1]));//皮
				mcpm.setCoil_net_wgt(Double.parseDouble(sWgt[2]));//净
				mcpm.setPacking_time(new Date());
				mcpm.setStatus("0");
				
				mcpm.setWrk_date(wrk_date);
				mcpm.setWrk_ord(wrk_ord);
				mcpm.setWrk_grp(wrk_grp);
			}
			
			
			//子表数据新增
			mcpd.setOrd_thk(lpmd.get(0).getThick());
			mcpd.setOrd_wdt(lpmd.get(0).getWidth());
			mcpd.setOrd_len(lpmd.get(0).getLength());
			mcpd.setOrd_inn_dia(lpmd.get(0).getDiameter_inn());
			mcpd.setOrd_out_dia(lpmd.get(0).getDiameter_out());
			
			mcpd.setAct_len(lypd.get(0).getLength());
			mcpd.setAct_thk(lypd.get(0).getThick());
			mcpd.setAct_wdt(lypd.get(0).getWidth());
			mcpd.setAct_inn_dia(lypd.get(0).getDiameter_inn());
			mcpd.setAct_out_dia(lypd.get(0).getDiameter_out());
			mcpd.setProduce_time(lypd.get(0).getProducedate());
			mcpd.setCoil_thr_wgt(lypd.get(0).getTheoryweight());//理重
			mcpd.setCoil_act_wgt(lypd.get(0).getPackweight());//实重
			
			mcpd.setOrder_no(ppps.getOrder_no());
			mcpd.setProd_order_no(ppps.getProd_order_no());
			
			mcpd.setPacking_no(P1);
			mcpd.setSchedule_no(lppp.get(0).getPk_plan_no());//***********
			mcpd.setCoil_no_vt(lpmd.get(0).getObject_no_vt());//***********
			
			lmcpd.add(mcpd);
			
		
			//逐一修改包装作业计划明细记录状态为包装作业完成
			PlnPackingPlanDetail pppdu=new PlnPackingPlanDetail();
			pppdu.setSerial_no(lpppd.get(0).getSerial_no());
			pppdu.setStatus("0PPK10");
			lpppdu.add(pppdu);
		}
		
		//包装主数据插入
		this.getMapper(MesCoilPackingMMapper.class).insert(mcpm);
		//调用物流模块接口，将包装后的成品卷包进行插入库存  待入库状态
		CommonPage<YdmProductDetail> cpAdd=new CommonPage<YdmProductDetail>();
		YdmProductDetail ypdAdd=new YdmProductDetail();
		ypdAdd.setCoilno(mcpm.getPacking_no());
		cpAdd.setObject(ypdAdd);
		this.getBean(LmsApiServiceImpl.class).doFinishedIn(cpAdd);
		
		CommonPage<YdmProductDetail> cp=new CommonPage<YdmProductDetail>();
		List<YdmProductDetail> lypd=new ArrayList<YdmProductDetail>();
		
		for(MesCoilPackingD mcpd:lmcpd){
			//包装明细数据插入
			this.getMapper(MesCoilPackingDMapper.class).insert(mcpd);
			
			//调用物流模块接口，逐一修改库存明细的包装等级
			YdmProductDetail ypd=new YdmProductDetail();
			ypd.setCoilno(mcpd.getCoil_no());
			ypd.setPacking_group(mcpm.getPacking_group());
			lypd.add(ypd);
			
		}
		//调用物流模块接口，逐一修改库存明细的包装等级
		cp.setObjectList(lypd);
		this.getBean(LmsApiServiceImpl.class).doUpdatePackingGroup(cp);
		//调用物流模块接口,原始钢卷进行出库操作
		this.getBean(LmsApiServiceImpl.class).doRollOut(cp);
		
		
		
		//逐一修改包装作业计划明细记录状态为包装作业完成
		for(PlnPackingPlanDetail pppdu:lpppdu){
			this.getMapper(PlnPackingPlanDetailMapper.class).update(pppdu);
		}
		
		rm.setState("200");
		return rm;
	}
	
	
	/**
	 * 修改包装实绩
	 * memo1 包装等级
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doUpdateWeb(CommonPage<MesCoilPackingM> oci) throws Exception{
		ResultModel rm=new ResultModel();
		
		//验证选中的包装主实绩记录存在，且为未入库状态
		MesCoilPackingM mcpm=this.getMapper(MesCoilPackingMMapper.class).findById(oci.getObject().getPacking_no());
		if(mcpm==null||mcpm.getPacking_no()==null){
			rm.setState("500");
			rm.setMsgInfo("包装主实绩记录不存在！");
			return rm;
		}else{
			if(!"0".equals(mcpm.getStatus())){
				rm.setState("500");
				rm.setMsgInfo("包装主实绩已入库！");
				return rm;
			}
		}
		
		//验证指定的包装等级编码基础数据在系统中存在
		ComBaseInfo cbi=new ComBaseInfo();
		cbi.setBase_code(oci.getMemo1());
		int icount=this.getMapper(ComBaseInfoMapper.class).count(cbi);
		if(icount==0){
			rm.setState("500");
			rm.setMsgInfo("包装等级编码基础数据在系统中不存在！");
			return rm;
		}
		
		//调用物流模块接口，验证选中的包装后成品卷包库存明细记录存在，且为待入库状态，否则终止操作，返回错误信息并提示
		CommonPage<YdmProductDetail> cp=new CommonPage<YdmProductDetail>();
		YdmProductDetail ypd=new YdmProductDetail();
		ypd.setCoilno(mcpm.getPacking_no());
		cp.setObject(ypd);
		ResultModel rmValid = this.getBean(LmsApiServiceImpl.class).doConfirmWaitIn(cp);
		if(!"200".equals(rmValid.getState())){
			return rmValid;
		}
		
		
		//开始事务
		MesCoilPackingM mcm=new MesCoilPackingM();
		mcm.setPacking_no(mcpm.getPacking_no());
		mcm.setCoil_gross_wgt(mcpm.getCoil_gross_wgt());
		mcm.setCoil_tare_wgt(mcpm.getCoil_tare_wgt());
		mcm.setCoil_net_wgt(mcpm.getCoil_net_wgt());
		mcm.setPacking_group(oci.getMemo1());
		this.getMapper(MesCoilPackingMMapper.class).update(mcm);
		
		//调用物流模块接口，修改卷包库存明细记录
		ypd.setGrossweight(mcpm.getCoil_gross_wgt());
		ypd.setPackweight(mcpm.getCoil_tare_wgt());
		ypd.setFactweight(mcpm.getCoil_net_wgt());
		ypd.setCoilno(mcpm.getPacking_no());
		cp.setObject(ypd);
		rmValid = this.getBean(LmsApiServiceImpl.class).doUpdateDetail(cp);
		if(!"200".equals(rmValid.getState())){
			return rmValid;
		}
		
		rm.setState("200");
		return rm;
	}
	
	/**
	 * 删除包装实绩
	 * memo1 包装等级
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doDeleteWeb(CommonPage<MesCoilPackingM> oci) throws Exception{
		ResultModel rm=new ResultModel();
		
		//验证选中的包装主实绩记录存在，且为未入库状态
		MesCoilPackingM mcpm=this.getMapper(MesCoilPackingMMapper.class).findById(oci.getObject().getPacking_no());
		if(mcpm==null||mcpm.getPacking_no()==null){
			rm.setState("500");
			rm.setMsgInfo("包装主实绩记录不存在！");
			return rm;
		}else{
			if(!"0".equals(mcpm.getStatus())){
				rm.setState("500");
				rm.setMsgInfo("包装主实绩已入库！");
				return rm;
			}
		}
		
		CommonPage<YdmProductDetail> cp=new CommonPage<YdmProductDetail>();
		YdmProductDetail ypd=new YdmProductDetail();
		
		
		List<PlnPackingPlanDetail> lpppd=new ArrayList<PlnPackingPlanDetail>();
		for(MesCoilPackingD mcpd:oci.getObject().getChild()){
			//逐一验证选中的成品卷包对应的钢卷明细包装作业计划主记录存在
			PlnPackingPlan ppp=new PlnPackingPlan();
			ppp.setMachine_code(oci.getObject().getPacking_line_code());
			ppp.setPk_plan_no(mcpd.getSchedule_no());
			int icount=this.getMapper(PlnPackingPlanMapper.class).count(ppp);
			if(icount==0){
				rm.setState("500");
				rm.setMsgInfo("成品卷包对应的钢卷明细包装作业计划主记录不存在！");
				return rm;
			}
			//逐一验证选中的成品卷包对应的钢卷明细包装作业计划明细记录存在，且为包装作业完成状态
			PlnPackingPlanDetail pppd=new PlnPackingPlanDetail();
			pppd.setObject_no_vt(mcpd.getCoil_no_vt());
			pppd.setMachine_code(oci.getObject().getPacking_line_code());
			pppd.setObject_no(mcpd.getCoil_no());
			pppd.setStatus("0PPK10");
			List<PlnPackingPlanDetail> lpppdQ=this.getMapper(PlnPackingPlanDetailMapper.class).find(pppd,0,0);
			if(lpppdQ==null||lpppdQ.size()==0){
				rm.setState("500");
				rm.setMsgInfo("成品卷包对应的钢卷明细包装作业计划明细记录不存在！");
				return rm;
			}
			lpppd.add(lpppdQ.get(0));
			
			//调用物流模块接口，逐一验证选中的成品卷包对应的钢卷明细库存记录存在，且为包装出库状态，否则终止操作，返回错误信息并提示
			ypd.setCoilno(mcpd.getCoil_no());
			cp.setObject(ypd);
			ResultModel rmValid = this.getBean(LmsApiServiceImpl.class).doConfirmPackingOut(cp);
			if(!"200".equals(rmValid.getState())){
				return rmValid;
			}
			
		}
		
		//调用物流模块接口，验证选中的包装后成品卷包库存明细记录存在，且为待入库状态，否则终止操作，返回错误信息并提示
		ypd.setCoilno(mcpm.getPacking_no());
		cp.setObject(ypd);
		ResultModel rmValid = this.getBean(LmsApiServiceImpl.class).doConfirmWaitIn(cp);
		if(!"200".equals(rmValid.getState())){
			return rmValid;
		}
		
		//开始事务
		for(PlnPackingPlanDetail pppd:lpppd){
			//逐一修改成品卷包对应的钢卷明细包装作业计划明细记录状态为计划已下发
			PlnPackingPlanDetail pppdu=new PlnPackingPlanDetail();
			pppdu.setSerial_no(pppd.getSerial_no());
			pppdu.setStatus("0PPK02");
			this.getMapper(PlnPackingPlanDetailMapper.class).update(pppdu);
		}
		
		//调用物流模块接口，逐一将包装明细的原始钢卷进行撤销包装出库、并同时清空包装等级操作；
		CommonPage<YdmProductDetail> cpDelete=new CommonPage<YdmProductDetail>();
		List<YdmProductDetail> lypd=new ArrayList<YdmProductDetail>();
		
		for(MesCoilPackingD mcpd:oci.getObject().getChild()){
			//调用物流模块接口，逐一修改表格3中勾选的成品卷包进行撤销包装出库、并同时清空包装等级操作
			YdmProductDetail ypdDelete=new YdmProductDetail();
			ypdDelete.setCoilno(mcpd.getCoil_no());
			lypd.add(ypdDelete);
		}
		cpDelete.setObjectList(lypd);
		rmValid = this.getBean(LmsApiServiceImpl.class).doCancelPackingOut(cpDelete);
		if(!"200".equals(rmValid.getState())){
			throw new Exception(rmValid.getMsgInfo());
		}
		
		
		//调用物流模块接口，删除包装后的成品卷包库存信息；
		ypd.setCoilno(mcpm.getPacking_no());
		cp.setObject(ypd);
		rmValid = this.getBean(LmsApiServiceImpl.class).doDeleteFinishedRoll(cp);
		if(!"200".equals(rmValid.getState())){
			return rmValid;
		}
		
		//删除包装计量主实绩记录（DELETE MES_COIL_PACKING_M T WHERE T.PACKING_NO = 表格2中激活行的成品卷包号）；
		this.getMapper(MesCoilPackingMMapper.class).delete(mcpm.getPacking_no());
		//删除包装计量明细记录（DELETE MES_COIL_PACKING_D T WHERE T.PACKING_NO = 表格2中激活行的成品卷包号）；
		MesCoilPackingD mcpd=new MesCoilPackingD();
		mcpd.setPacking_no(mcpm.getPacking_no());
		this.getMapper(MesCoilPackingDMapper.class).doDelete(mcpd);
		
		rm.setState("200");
		return rm;
	}
	
	/**
	 * 调整班次班组
	 * memo1 班次
	 * memo2 班组
	 * memo3 作业日期
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doUpdateWrkWeb(CommonPage<MesCoilPackingM> oci) throws Exception{
		ResultModel rm=new ResultModel();
		List<MesCoilPackingM> lmcpm=oci.getObjectList();
		
		CommonPage<YdmProductDetail> cp=new CommonPage<YdmProductDetail>();
		YdmProductDetail ypd=new YdmProductDetail();
		
		for(MesCoilPackingM mcpm:lmcpm){
			//调用物流模块接口，验证选中的包装后成品卷包库存明细记录存在，且为待入库状
			ypd.setCoilno(mcpm.getPacking_no());
			cp.setObject(ypd);
			ResultModel rmValid = this.getBean(LmsApiServiceImpl.class).doConfirmWaitIn(cp);
			if(!"200".equals(rmValid.getState())){
				return rmValid;
			}
			
			//逐一验证选中的包装主实绩记录存在，且为未入库状态
			MesCoilPackingM mcpmQ=this.getMapper(MesCoilPackingMMapper.class).findById(mcpm.getPacking_no());
			if(mcpmQ==null||mcpmQ.getPacking_no()==null){
				rm.setState("500");
				rm.setMsgInfo("包装主实绩记录不存在！");
				return rm;
			}else{
				if(!"0".equals(mcpmQ.getStatus())){
					rm.setState("500");
					rm.setMsgInfo("包装主实绩已入库！");
					return rm;
				}
			}
		}
		
		List<YdmProductDetail> lypd=new ArrayList<YdmProductDetail>();
		
		for(MesCoilPackingM mcpm:lmcpm){
			//逐一修改包装计量主实绩记录的作业日期、班次、班组
			MesCoilPackingM mcpmU=new MesCoilPackingM();
			mcpmU.setPacking_no(mcpm.getPacking_no());
			mcpmU.setWrk_ord(oci.getMemo1());
			mcpmU.setWrk_grp(oci.getMemo2());
			mcpmU.setWrk_date(oci.getMemo3());
			this.getMapper(MesCoilPackingMMapper.class).update(mcpmU);
			
			//调用物流模块接口，逐一修改卷包库存明细记录的生产班次（PRODUCEORDER）、生产班组（PRODUCETEAM）
			YdmProductDetail ypdU=new YdmProductDetail();
			ypdU.setCoilno(mcpm.getPacking_no());
			ypdU.setProduceorder(oci.getMemo1());
			ypdU.setProduceteam(oci.getMemo2());
			lypd.add(ypdU);
		}
		
		cp.setObjectList(lypd);
		this.getBean(LmsApiServiceImpl.class).doUpdateOrderTeam(cp);
		
		rm.setState("200");
		return rm;
	}
}
