/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2018-01-30
 * 描述            ：质量设计-交付标准
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
***********************************************************/
package market.Qms.slmord.impl;
import java.util.ArrayList;
import java.util.List;

import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Qms.slmord.mapper.SlmOrdDesignAdditionalMapper;
import market.Qms.slmord.mapper.SlmOrdDesignStdCicMapper;
import market.Qms.slmord.mapper.SlmOrdDesignStdDicMapper;
import market.Qms.slmord.mapper.SlmOrdDesignStdMapper;
import market.Qms.slmord.mapper.SlmOrdDesignStdPicMapper;
import market.Qms.slmord.mapper.SlmOrdDesignStdSicMapper;
import market.Qms.slmord.service.SlmOrdDesignStdService;
import market.Qms.slmord.vo.SlmOrdDesignAdditional;
import market.Qms.slmord.vo.SlmOrdDesignStd;
import market.Qms.slmord.vo.SlmOrdDesignStdCic;
import market.Qms.slmord.vo.SlmOrdDesignStdDic;
import market.Qms.slmord.vo.SlmOrdDesignStdPic;
import market.Qms.slmord.vo.SlmOrdDesignStdSic;

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

@RemoteService(path="SlmOrdDesignStdService")
public class SlmOrdDesignStdServiceImpl extends BaseServiceImpl<SlmOrdDesignStd,Object> implements SlmOrdDesignStdService {
	 /**
	    * 获取公差标准结果集
	    * @param sum
	    * DESIGN_KEY,PSC
	    * PSC
	    * @return
	    */
		public ResultModel GetSlmOrdDesignStdSic (CommonPage<SlmOrdDesignStd> sum){
		   ResultModel rm=new ResultModel();
		   SlmOrdDesignStd sod=sum.getObject();
		   List<SlmOrdDesignStdSic> listsic=new ArrayList<>();
		   try {
			 SlmOrdDesignStd s = this.getMapper(SlmOrdDesignStdMapper.class).findById(sod.getDesign_key(),sod.getPsc());
			 //判断sic_k是否存在
			 if (s!=null) {
			 if (s.getSic_k()==null||s.getSic_k().equals("")) {
				 SlmOrdDesignStdSic sc=new SlmOrdDesignStdSic();
				 sc.setDesign_key(s.getDesign_key());
				 sc.setSic(s.getSic());
				 listsic = this.getMapper(SlmOrdDesignStdSicMapper.class).find(sc, 0, 0);
				rm.setData(listsic);
			}else {
				//如果sic_k存在，这取sic与sic_k两套结果的并集，以sic_k为准
				 List<SlmOrdDesignStdSic> listSic = this.getMapper(SlmOrdDesignStdSicMapper.class).findWithCondition(null, "DESIGN_KEY='"+s.getDesign_key()+"' and sic='"+s.getSic()+"'", null, 0, 0);
				 List<SlmOrdDesignStdSic> listsick = this.getMapper(SlmOrdDesignStdSicMapper.class).findWithCondition(null, "DESIGN_KEY='"+s.getDesign_key()+"' and sic='"+s.getSic_k()+"'", null, 0, 0);
				   for (SlmOrdDesignStdSic e : listSic) {
					   listsic.add(e);
				}
				   for (SlmOrdDesignStdSic slmOrdDesignStdSic : listsick) {
					   listsic.add(slmOrdDesignStdSic);
				}
				 for (SlmOrdDesignStdSic sic : listSic) {
					for (SlmOrdDesignStdSic sick : listsick) {
						if (sic.getBias_code().equals(sick.getBias_code())) {
							listsic.remove(sic);
						}
					}
					
				}
				  rm.setData(listsic);
			}
			}
			 rm.setState("200");
		} catch (Exception e) {
			// TODO: handle exception
			rm.setState("500");
			rm.setMsgInfo("查询公差标准失败");
			rm.setErrorInfo(e.getMessage());
		}
		   return rm;
	   }
		 /**
		    * 获取成分标准结果集
		    * @param sum
		    * DESIGN_KEY,PSC
		    * PSC
		    * @return
		    */
			public ResultModel GetSlmOrdDesignStdCic (CommonPage<SlmOrdDesignStd> sum){
			   ResultModel rm=new ResultModel();
			   SlmOrdDesignStd sod=sum.getObject();
			   List<SlmOrdDesignStdCic> listcic=new ArrayList<>();
			   try {
				 SlmOrdDesignStd s = this.getMapper(SlmOrdDesignStdMapper.class).findById(sod.getDesign_key(),sod.getPsc());
				 if (s!=null) {
				 //判断cic_k是否存在
				 if (s.getCic_k()==null||s.getCic_k().equals("")) {
					 SlmOrdDesignStdCic sc=new SlmOrdDesignStdCic();
					 sc.setDesign_key(s.getDesign_key());
					 sc.setCic(s.getCic());
					 listcic = this.getMapper(SlmOrdDesignStdCicMapper.class).find(sc, 0, 0);
					rm.setData(listcic);
				}else {
					//如果cic_k存在，这取cic与cic_k两套结果的并集，以cic_k为准
					 List<SlmOrdDesignStdCic> listCic = this.getMapper(SlmOrdDesignStdCicMapper.class).findWithCondition(null, "DESIGN_KEY='"+s.getDesign_key()+"' and cic='"+s.getCic()+"'", null, 0, 0);
					 List<SlmOrdDesignStdCic> listcick = this.getMapper(SlmOrdDesignStdCicMapper.class).findWithCondition(null, "DESIGN_KEY='"+s.getDesign_key()+"' and cic='"+s.getCic_k()+"'", null, 0, 0);
					  for (SlmOrdDesignStdCic e : listCic) {
						  listcic.add(e);
					}
					  for (SlmOrdDesignStdCic slmOrdDesignStdCic : listcick) {
						  listcic.add(slmOrdDesignStdCic);
					}
					  for (SlmOrdDesignStdCic cic : listCic) {
							for (SlmOrdDesignStdCic cick : listcick) {
								if (cic.getChem_code().equals(cick.getChem_code())) {
									listcic.remove(cic);
								}
							}
						}
					 
						}
				 }
					  rm.setData(listcic);
				 rm.setState("200");
			} catch (Exception e) {
				// TODO: handle exception
				rm.setState("500");
				rm.setMsgInfo("查询成分标准失败");
				rm.setErrorInfo(e.getMessage());
			}
			   return rm;
		   }
			 /**
			    * 获取材质标准结果集
			    * @param sum
			    * DESIGN_KEY,PSC
			    * PSC
			    * @return
			    */
				public ResultModel GetSlmOrdDesignStdPic (CommonPage<SlmOrdDesignStd> sum){
				   ResultModel rm=new ResultModel();
				   SlmOrdDesignStd sod=sum.getObject();
				   List<SlmOrdDesignStdPic> listpic=new ArrayList<>();
				   try {
					 SlmOrdDesignStd s = this.getMapper(SlmOrdDesignStdMapper.class).findById(sod.getDesign_key(),sod.getPsc());
					 //判断pic_k是否存在
					 if (s!=null) {
					 if (s.getPic_k()==null||s.getPic_k().equals("")) {
						 SlmOrdDesignStdPic sc=new SlmOrdDesignStdPic();
						 sc.setDesign_key(s.getDesign_key());
						 sc.setPic(s.getPic());
						 listpic = this.getMapper(SlmOrdDesignStdPicMapper.class).find(sc, 0, 0);
						rm.setData(listpic);
					}else {
						//如果pic_k存在，这取pic与pic_k两套结果的并集，以pic_k为准
						 List<SlmOrdDesignStdPic> listPic = this.getMapper(SlmOrdDesignStdPicMapper.class).findWithCondition(null, "DESIGN_KEY='"+s.getDesign_key()+"' and pic='"+s.getPic()+"'", null, 0, 0);
						 List<SlmOrdDesignStdPic> listpick = this.getMapper(SlmOrdDesignStdPicMapper.class).findWithCondition(null, "DESIGN_KEY='"+s.getDesign_key()+"' and pic='"+s.getPic_k()+"'", null, 0, 0);
						 for (SlmOrdDesignStdPic a : listPic) {
							 listpic.add(a);
						}
						 for (SlmOrdDesignStdPic slmOrdDesignStdPic : listpick) {
							 listpic.add(slmOrdDesignStdPic);
						}
						 for (SlmOrdDesignStdPic pic : listPic) {
							for (SlmOrdDesignStdPic pick : listpick) {
								String PicStr=pic.getPhy_code_l()+pic.getPhy_code_m()+pic.getPhy_code_s()+pic.getItem_code_d()+pic.getItem_code_t()+pic.getItem_code_s();
								String pickStr=pick.getPhy_code_l()+pick.getPhy_code_m()+pick.getPhy_code_s()+pick.getItem_code_d()+pick.getItem_code_t()+pick.getItem_code_s();
								if (PicStr.equals(pickStr)) {
									listpic.remove(pic);
								}
							}
							
						}
						  
						  
					}
						  rm.setData(listpic);
						
					}
					 rm.setState("200");
				} catch (Exception e) {
					// TODO: handle exception
					rm.setState("500");
					rm.setMsgInfo("查询材质标准失败");
					rm.setErrorInfo(e.getMessage());
				}
				   return rm;
			   }
				/**
				    * 获取探伤标准结果集
				    * @param sum
				    * DESIGN_KEY,PSC
				    * PSC
				    * @return
				    */
					public ResultModel GetSlmOrdDesignStdDic (CommonPage<SlmOrdDesignStd> sum){
					   ResultModel rm=new ResultModel();
					   SlmOrdDesignStd sod=sum.getObject();
					   List<SlmOrdDesignStdDic> listdic=new ArrayList<>();
					   try {
						 SlmOrdDesignStd s = this.getMapper(SlmOrdDesignStdMapper.class).findById(sod.getDesign_key(),sod.getPsc());
						 if (s!=null) {
						 //判断dic_k是否存在
						 if (s.getDic_k()==null||s.getDic_k().equals("")) {
							 SlmOrdDesignStdDic sc=new SlmOrdDesignStdDic();
							 sc.setDesign_key(s.getDesign_key());
							 sc.setDic(s.getDic());
							 listdic = this.getMapper(SlmOrdDesignStdDicMapper.class).find(sc, 0, 0);
							rm.setData(listdic);
						}else {
							//如果Dic_k存在，这取dic与dic_k两套结果的并集，以dic_k为准
							 List<SlmOrdDesignStdDic> listDic = this.getMapper(SlmOrdDesignStdDicMapper.class).findWithCondition(null, "DESIGN_KEY='"+s.getDesign_key()+"' and dic='"+s.getDic()+"'", null, 0, 0);
							 List<SlmOrdDesignStdDic> listdick = this.getMapper(SlmOrdDesignStdDicMapper.class).findWithCondition(null, "DESIGN_KEY='"+s.getDesign_key()+"' and dic='"+s.getDic_k()+"'", null, 0, 0);
							  for (SlmOrdDesignStdDic e : listDic) {
								  listdic.add(e);
							}
							  for (SlmOrdDesignStdDic slmOrdDesignStdDic : listdick) {
								  listdic.add(slmOrdDesignStdDic);
							}
							 for (SlmOrdDesignStdDic dic : listDic) {
								for (SlmOrdDesignStdDic dick : listdick) {
									String DicStr=dic.getPosition_code()+dic.getStd_desc()+dic.getLv_code();
									String DickStr=dick.getPosition_code()+dick.getStd_desc()+dick.getLv_code();
									if (DicStr.equals(DickStr)) {
										listdic.remove(dic);
									}
								}
								
							}
							  rm.setData(listdic);
							
						}
						 }
						 rm.setState("200");
					} catch (Exception e) {
						// TODO: handle exception
						rm.setState("500");
						rm.setMsgInfo("查询探伤标准失败");
						rm.setErrorInfo(e.getMessage());
					}
					   return rm;
				   }
	     /**
	      * 获取订单关联的留样宽度、长度，切割要求附加信息				
	      * @param design_key
	      * @return
	      */
		 public ResultModel GetSlmOrdDesignAdditional(String design_key){
			 ResultModel rm=new ResultModel();
			 try {
				 List<SlmOrdDesignAdditional> listadd = this.getMapper(SlmOrdDesignAdditionalMapper.class).findWithCondition(null, "design_key='"+design_key+"' and ask_sub_itme in ('12100628','12100626','12100627')", null, 0, 0);
			     rm.setData(listadd);
			     rm.setState("200");
			  } catch (Exception e) {
				// TODO: handle exception
				  rm.setState("500");
				  rm.setErrorInfo(e.getMessage());
			}
			 return rm;
		 }
		
}
