/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2018-01-30
 * 描述            ：质量设计-交付标准-公差标准
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
***********************************************************/
package market.Qms.slmord.impl;
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.SlmOrdDesignStdMapper;
import market.Qms.slmord.mapper.SlmOrdDesignStdSicMapper;
import market.Qms.slmord.service.SlmOrdDesignStdSicService;
import market.Qms.slmord.vo.SlmOrdDesignStd;
import market.Qms.slmord.vo.SlmOrdDesignStdSic;

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

@RemoteService(path="SlmOrdDesignStdSicService")
public class SlmOrdDesignStdSicServiceImpl extends BaseServiceImpl<SlmOrdDesignStdSic,Object> implements SlmOrdDesignStdSicService {
	
	
	/**
	 * 查询
	 * @param cp
	 * @return
	 */
	public ResultModel GetOrdDesignStdSic(CommonPage<SlmOrdDesignStd> cp) {
		ResultModel rm = new ResultModel();
		rm.setState("200");
		try {

			SlmOrdDesignStd _designStd=this.getMapper(SlmOrdDesignStdMapper.class).findById(cp.getObject().getDesign_key(),cp.getObject().getPsc());
			if(DataHelper.IsNullOrSpace(_designStd.getSic())){
				rm.setState("403");
				//rm.setMsgInfo("公差索引号不能为空");
				return rm;
			}
			String condition=DataHelper.CreateSqlCondition(_designStd.getSic().split(";"),"sic")+" And DESIGN_KEY='"+DataHelper.TrimSqlDangerMark(cp.getObject().getDesign_key())+"'";
			List<SlmOrdDesignStdSic> listStdSic=this.getMapper(SlmOrdDesignStdSicMapper.class).findWithCondition(null, condition, null, 0, 0);
			String[] addStd=new String[listStdSic.size()];//精度等级集
			for (int i = 0; i < listStdSic.size(); i++) {
				if(!DataHelper.IsNullOrSpace(listStdSic.get(i).getLvCode())){
					addStd[i]=listStdSic.get(i).getLvCode();
				}
			}
			condition=DataHelper.CreateSqlCondition(addStd, "base_code");
			List<ComBaseInfo> listBase=this.getMapper(ComBaseInfoMapper.class).findWithCondition(null, condition, null, 0, 0);
			//构造附加标准项信息
			for (SlmOrdDesignStdSic stdSic : listStdSic) {
				if(DataHelper.IsNullOrSpace(stdSic.getLvCode())){
					continue;
				}
				for (ComBaseInfo comBaseInfo : listBase) {
					if(comBaseInfo.getBase_code().equals(stdSic.getLvCode())){
						stdSic.setLvCode(comBaseInfo.getBase_name());
						break;
					}
				}
			}
			rm.setData(listStdSic);
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("查询失败："+e.getMessage());
		}
		return rm;
	}
	
	
	/**
	 * 获取成分内控信息
	 * @param sic
	 * @param designKey
	 * @return
	 */
	public ResultModel GetOrdDesignStdSicBySic(String sic,String designKey) {
		ResultModel rm = new ResultModel();
		try {
			if(DataHelper.IsNullOrSpace(sic)){
				rm.setState("404");
				rm.setMsgInfo("公差索引不能为空");
				return rm;
			}
			String condition=DataHelper.CreateSqlCondition(sic, "sic",",")+" and design_key='"+DataHelper.TrimSqlDangerMark(designKey)+"'";
			List<SlmOrdDesignStdSic> listStdCic=this.getMapper(SlmOrdDesignStdSicMapper.class).findWithCondition(null, condition, "sic", 0, 0);
			rm.setState("200");
			rm.setData(listStdCic);
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("查询失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}
	
	
}
