/***文档注释***********************************************
 * 作者               :                   宋燕辉
 * 创建日期      :                   2018.08.13
 * 描述               :                  罩退  pdipdo
 * 注意事项      :                   无
 * 遗留BUG :                   无
 * 修改日期      :                   
 * 修改人员      :                   
 * 修改内容      :                   
 ***********************************************************/
package market.Api.Mes.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import market.Api.Mes.service.MesApiPlmPdiPdoService;
import market.Com.pb.PropertiesUtils;
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.Performance.mapper.MesCrSlittingDMapper;
import market.Mes.Lengthwise.Performance.vo.MesCrSlittingD;
import market.Mes.Lengthwise.Plan.mapper.MesCrCrossCuttingDMapper;
import market.Mes.Lengthwise.Plan.vo.MesCrCrossCuttingD;
import market.Mes.Pickle.Performance.mapper.MesPlmMMapper;
import market.Mes.Tpm.mapper.IfTpm01L3PdiMapper;
import market.Mes.util.DateUtil;

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

@RemoteService(path = "MesApiPlmPdiPdoService")
public class MesApiPlmPdiPdoImpl extends BaseServiceImpl implements MesApiPlmPdiPdoService{
 
	public static String PLMPDI = PropertiesUtils.getPdioProperties().getProperty("PLMPDI");
	public static String PLMORDER = PropertiesUtils.getPdioProperties().getProperty("PLMORDER");
	public static String PLMDEL = PropertiesUtils.getPdioProperties().getProperty("PLMDEL");
    	
	//获取需要进行状态跟踪的钢卷信息
	public List<String> getPlmTrcCoils(){
		List<String> list=new ArrayList<>();		
		list=this.getMapper(MesPlmMMapper.class).doQueryWebMaterialno("M0010");
		return list;
	}		
	
	public void mesToLmsWrkDate(String start,String end) throws Exception{
		List<MesCrSlittingD> mescm = this.getMapper(MesCrSlittingDMapper.class).findWithCondition(null, "wrk_date>='"+start+"' and wrk_date<='"+end+"'", "", 0, 0);
		for(MesCrSlittingD mcm:mescm){
			List<YdmProductDetail> listypd = this.getMapper(YdmProductDetailMapper.class).findWithCondition(null, "coilno='"+mcm.getCoil_no()+"'", "", 0, 0);
			if(listypd!=null && listypd.size()>0){
				YdmProductDetail ypd=new YdmProductDetail();
				ypd.setCoilno(listypd.get(0).getCoilno());
				try{
					if(mcm.getWrk_date()!=null){
						ypd.setProducedate(DateUtil.formatString(mcm.getWrk_date(), "yyyy-MM-dd"));
						this.getMapper(YdmProductDetailMapper.class).update(ypd);
					}
				}catch(Exception ex){
					ex.printStackTrace();
				}
			}
		}
		List<MesCrCrossCuttingD> mescmxx = this.getMapper(MesCrCrossCuttingDMapper.class).findWithCondition(null, "wrk_date>='"+start+"' and wrk_date<='"+end+"'", "", 0, 0);
		for(MesCrCrossCuttingD mcm:mescmxx){
			List<YdmProductDetail> listypd = this.getMapper(YdmProductDetailMapper.class).findWithCondition(null, "coilno='"+mcm.getPacking_no()+"'", "", 0, 0);
			if(listypd!=null && listypd.size()>0){
				YdmProductDetail ypd=new YdmProductDetail();
				ypd.setCoilno(listypd.get(0).getCoilno());
				try{
					if(mcm.getWrk_date()!=null){
						ypd.setProducedate(DateUtil.formatString(mcm.getWrk_date(), "yyyy-MM-dd"));
						this.getMapper(YdmProductDetailMapper.class).update(ypd);
					}
				}catch(Exception ex){
					ex.printStackTrace();
				}
			}
		}
		
//		List<MesCrAnnealM> mescmxx1 = this.getMapper(MesCrAnnealMMapper.class).findWithCondition(null, "discharge_date>='"+start+"' and discharge_date<='"+end+"'", "", 0, 0);
//		for(MesCrAnnealM mcm:mescmxx1){
//			List<YdmProductDetail> listypd = this.getMapper(YdmProductDetailMapper.class).findWithCondition(null, "coilno='"+mcm.getCoil_no()+"'", "", 0, 0);
//			if(listypd!=null && listypd.size()>0){
//				YdmProductDetail ypd=new YdmProductDetail();
//				ypd.setCoilno(listypd.get(0).getCoilno());
//				ypd.setProducedate(DateUtil.formatString(mcm.getDischarge_date(), "yyyy-MM-dd"));
//				try{
//					if(mcm.getDischarge_date()!=null){
//						ypd.setProducedate(DateUtil.formatString(mcm.getDischarge_date(), "yyyy-MM-dd"));
//						this.getMapper(YdmProductDetailMapper.class).update(ypd);
//					}
//					this.getMapper(YdmProductDetailMapper.class).update(ypd);
//				}catch(Exception ex){
//					ex.printStackTrace();
//				}
//			}
//		}
//		
//		
//		List<MesTpmD> mescm12 = this.getMapper(MesTpmDMapper.class).findWithCondition(null, "wrk_date>='"+start+"' and wrk_date<='"+end+"'", "", 0, 0);
//		for(MesTpmD mcm:mescm12){
//			List<YdmProductDetail> listypd = this.getMapper(YdmProductDetailMapper.class).findWithCondition(null, "coilno='"+mcm.getCoil_no()+"'", "", 0, 0);
//			if(listypd!=null && listypd.size()>0){
//				YdmProductDetail ypd=new YdmProductDetail();
//				ypd.setCoilno(listypd.get(0).getCoilno());
//				try{
//					if(mcm.getWrk_date()!=null){
//						ypd.setProducedate(DateUtil.formatString(mcm.getWrk_date(), "yyyy-MM-dd"));
//						this.getMapper(YdmProductDetailMapper.class).update(ypd);
//					}
//				}catch(Exception ex){
//					ex.printStackTrace();
//				}
//			}
//		}
//		
//		
//		List<MesRcmD> mescm125 = this.getMapper(MesRcmDMapper.class).findWithCondition(null, "wrk_date>='"+start+"' and wrk_date<='"+end+"'", "", 0, 0);
//		for(MesRcmD mcm:mescm125){
//			List<YdmProductDetail> listypd = this.getMapper(YdmProductDetailMapper.class).findWithCondition(null, "coilno='"+mcm.getCoil_no()+"'", "", 0, 0);
//			if(listypd!=null && listypd.size()>0){
//				YdmProductDetail ypd=new YdmProductDetail();
//				ypd.setCoilno(listypd.get(0).getCoilno());
//				try{
//					if(mcm.getWrk_date()!=null){
//						ypd.setProducedate(DateUtil.formatString(mcm.getWrk_date(), "yyyy-MM-dd"));
//						this.getMapper(YdmProductDetailMapper.class).update(ypd);
//					}
//				}catch(Exception ex){
//					ex.printStackTrace();
//				}
//			}
//		}
		
	}
	
	
	
	
//	public static void main(String[] args){
//		IfPlm01L2Par v_rec_pdo_param=new IfPlm01L2Par();
//		v_rec_pdo_param.setBl_ds("Blsdfd");
//		v_rec_pdo_param.setFid("fidfid");
//		v_rec_pdo_param.setTen3("teens33");
//		v_rec_pdo_param.setCoil_no("YYYYYYsdfsdf");
//		MesPlmDPar mcae=new MesPlmDPar();
//		BeanUtils.copyProperties(v_rec_pdo_param, mcae);
//		System.out.println(mcae);
//	}
	
	
	
	// 补零
	public static String lpad(String str, int num, String pad) {
		String n_str = str;
		if (str == null && "".equals(str))
			n_str = " ";
		for (int i = str.length(); i < num; i++) {
			n_str = pad + n_str;
		}
		return n_str;
	}	
	
	/**
	 * 酸洗作业指示查询
	 * memo1:传机台代码   startTime:开始时间 endTime:结束时间
	 * @param oci
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public ResultModel doQueryPlmWeb(CommonPage<YdmProductDetail> oci){
		ResultModel rm=new ResultModel();
		if(oci.getMemo1()==null || "".equals(oci.getMemo1())){
			rm.setState("500");
			rm.setMsgInfo("请输入机台代码");
			return rm;
		}
		try{
			List<HashMap> lpav=this.getMapper(IfTpm01L3PdiMapper.class).doQueryPlmWeb(oci.getObject(),oci.getMemo1(),oci.getMemo2(),oci.getStartTime(),oci.getEndTime(),oci.getMemo3());
			rm.setData(lpav);
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	}
	


}
