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

import market.Com.mapper.ComBaseInfoMapper;
import market.Com.vo.ComBaseInfo;
import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Qms.common.DataHelper;
import market.Qms.slmord.mapper.SlmOrdDesignStdDicMapper;
import market.Qms.slmord.mapper.SlmOrdDesignStdMapper;
import market.Qms.slmord.service.SlmOrdDesignStdDicService;
import market.Qms.slmord.vo.SlmOrdDesignStd;
import market.Qms.slmord.vo.SlmOrdDesignStdDic;

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

@RemoteService(path="SlmOrdDesignStdDicService")
public class SlmOrdDesignStdDicServiceImpl extends BaseServiceImpl<SlmOrdDesignStdDic,Object> implements SlmOrdDesignStdDicService {

	
	
	/**
	 * 查询
	 * @param cp
	 * @return
	 */
	public ResultModel GetOrdDesignStdDic(CommonPage<SlmOrdDesignStd> cp) {
		ResultModel rm = new ResultModel();
		try {
			SlmOrdDesignStd _designStd=this.getMapper(SlmOrdDesignStdMapper.class).findById(cp.getObject().getDesign_key(),cp.getObject().getPsc());
			if(DataHelper.IsNullOrSpace(_designStd.getDic())){
				rm.setState("403");
				//rm.setMsgInfo("探伤索引号不能为空");
				return rm;
			}
			
			String condition=DataHelper.CreateSqlCondition(_designStd.getDic().split(";"),"dic")+" and  DESIGN_KEY='"+DataHelper.TrimSqlDangerMark(cp.getObject().getDesign_key())+"'";
			List<SlmOrdDesignStdDic> listStdDic=this.getMapper(SlmOrdDesignStdDicMapper.class).findWithCondition(null, condition, null, 0, 0);
			List<String> listBaseCode=new ArrayList<>();
			for (SlmOrdDesignStdDic stdDic : listStdDic) {
				if(!DataHelper.IsNullOrSpace(stdDic.getStd_desc())){
					listBaseCode.add(stdDic.getStd_desc());
				}
				if(!DataHelper.IsNullOrSpace(stdDic.getGroove_dir())){
					listBaseCode.add(stdDic.getGroove_dir());
				}
				if(!DataHelper.IsNullOrSpace(stdDic.getGroove_pos())){
					listBaseCode.add(stdDic.getGroove_pos());
				}
			}
			condition=DataHelper.CreateSqlCondition(listBaseCode, "base_code");
			List<ComBaseInfo> listBaseInfo=this.getMapper(ComBaseInfoMapper.class).findWithCondition(null, condition, null, 0, 0);
			for (SlmOrdDesignStdDic stdDic : listStdDic) {
				for (ComBaseInfo comBaseInfo : listBaseInfo) {
					if(!DataHelper.IsNullOrSpace(stdDic.getStd_desc())&&comBaseInfo.getBase_code().equals(stdDic.getStd_desc())){
						stdDic.setStd_desc(comBaseInfo.getBase_name());
					}
					if(!DataHelper.IsNullOrSpace(stdDic.getGroove_dir())&&comBaseInfo.getBase_code().equals(stdDic.getGroove_dir())){
						stdDic.setGroove_dir_desc(comBaseInfo.getBase_name());
					}
					if(!DataHelper.IsNullOrSpace(stdDic.getGroove_pos())&&comBaseInfo.getBase_code().equals(stdDic.getGroove_pos())){
						stdDic.setGroove_pos_desc(comBaseInfo.getBase_name());
					}
				}
			}
			rm.setState("200");
			rm.setData(listStdDic);
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("查询失败："+e.getMessage());
		}
		return rm;
	}
	
	
	/**
	 * 获取探伤内控信息
	 * @param dic
	 * @param designKey
	 * @return
	 */
	public ResultModel GetOrdDesignStdDicByDic(String dic,String designKey) {
		ResultModel rm = new ResultModel();
		try {
			if(DataHelper.IsNullOrSpace(dic)){
				rm.setState("404");
				rm.setMsgInfo("探伤索引不能为空");
				return rm;
			}
			String condition=DataHelper.CreateSqlCondition(dic, "dic",",")+" and design_key='"+DataHelper.TrimSqlDangerMark(designKey)+"'";
			List<SlmOrdDesignStdDic> listStdDic=this.getMapper(SlmOrdDesignStdDicMapper.class).findWithCondition(null, condition, "dic", 0, 0);
			rm.setState("200");
			rm.setData(listStdDic);
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("查询失败："+e.getMessage());
		}
		return rm;
	}
	
	
}
