package market.Api.Qms.impl;

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

import market.Api.Qms.mapper.DesignResultMapper;
import market.Api.Qms.service.DesignResultService;
import market.Api.Qms.vo.SlmOrdDesignMsc;
import market.Com.mapper.ComPscMapper;
import market.Com.vo.ComPsc;
import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;

import com.hnshituo.basic.service.impl.BaseServiceImpl;
import com.hnshituo.basic.spring.remoting.annotation.RemoteService;
@RemoteService(path="DesignResultService")
public class DesignResultServiceImpl extends BaseServiceImpl implements DesignResultService{

	/**
	 * 通过合同行PK码获取对应所有附加要求信息
	 * 
	 * */
	
	public ResultModel findInfoByPk(CommonPage<SlmOrdDesignMsc> cp)
	{
//		if(param == null || "".equals(param)) return;
//return this.getMapper(DesignResultMapper.class).GetDetail(param);		
		
		ResultModel rm = new ResultModel();
		SlmOrdDesignMsc Org = new SlmOrdDesignMsc();
		try {
			Org=cp.getObject();
			if(Org != null){
             rm.setData(this.getMapper(DesignResultMapper.class).GetDetail(cp.getObject().getOrd_pk()));
				rm.setState("200");}
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
		}
		
		return rm;
		

		
		
	}
	public ResultModel  GetBlankComb(CommonPage<ComPsc> cp)
	{
		
		ResultModel rm = new ResultModel();
		ComPsc Org = new ComPsc();
		try {
			List<ComPsc> com = cp.getObjectList();
			if(com == null){
Org.setPsc(cp.getObject().getPsc());
rm.setData(this.getMapper(ComPscMapper.class).find(Org, 0, 0).get(0).getBlank_comb_max());
					
				}else {
					 ArrayList<ComPsc> list = new ArrayList<ComPsc>(); 
					for(ComPsc c:com)
					{
					Org.setPsc(c.getPsc());
					List<ComPsc> ls = this.getMapper(ComPscMapper.class).find(Org, 0, 0);
					double min = ls.get(0).getBlank_comb_max();
					ComPsc minObject = new ComPsc();
					for(ComPsc t:ls)
					{
						if(t.getBlank_comb_max()<min){
							min = t.getBlank_comb_max();
							minObject = t;
						}
					}
					list.add(minObject);
					}
					ComPsc minComPsc = new ComPsc();
					Double minnum = list.get(0).getBlank_comb_max();
					for(ComPsc t:list)
					{
						if(minnum<t.getBlank_comb_max())
						{
							minnum = t.getBlank_comb_max();
							minComPsc = t;
						}
					}
					rm.setData(minComPsc.getBlank_comb_max());
					
				}
				rm.setState("200");
		
			
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
		}
		
		return rm;
		

	}
	
}
