package com.steering.mes.mcp.coup;

import java.util.ArrayList;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA06.CoreReturnSortObject;

import com.steering.comm.db.DBCommon;
import com.steering.mes.mcp.entity.PhosphateRD;
import com.steering.mes.mcp.entity.PhosphateResult;
import com.steering.mes.mcp.entity.ThreadingResult;

/**
 * 接箍磷化检测实绩
 * @author lzh520
 *
 */
public class PhosphateResultService extends DBCommon{

	 /**
     * 查询加工计划
     * @param planNO
     * @return
     */
    public CoreReturnObject getCoupProcessPlan(String  planNO){
    	Object[] pamar = new Object[]{ planNO};
    	CoreReturnObject core = new CoreReturnObject();
    	core = this.getDataBySqlID("PhosphateResultService.ProcessPlan.GetPhosphateResult", pamar);
    	CoreReturnSortObject ct = (CoreReturnSortObject) core.getResult();
    	if(ct.getResult().size()>0){
    		return this.getDataBySqlID(
    				"PhosphateResultService.ProcessPlan.GetPhosphateResultAndCoupPlan", pamar);
    	}else
    	{
    		return this.getDataBySqlID(
        			"PhosphateResultService.ProcessPlan.CoupProcessPlan",pamar);
    	}
    }
    
    
    /**
     * 新增或修改磷化检测实绩
     * @param result 磷化检测实绩
     * @return
     */
    public CoreReturnObject addPhosphateResult(PhosphateResult  result) {
    	CoreReturnObject core = new CoreReturnObject();
    	CoreReturnObject core2 = new CoreReturnObject();
    	Object[] pamar = new Object[]{ result.getMembranceThick(),
    			result.getAdhesion(),result.getAntiCorrosion(),
    			result.getReactionTime(),result.getSurfaceCondition(),
    			result.getProducer(),result.getProducerTime(),
    			result.getColShft(),result.getColGroup(),
    			result.getColUser(),result.getColTime(),
    			result.getPlineCode(),result.getPlanNo()};
    	
    	core = this.getPhosphateResult(result.getPlanNo());
    	CoreReturnSortObject ct = (CoreReturnSortObject) core.getResult();

		if(ct.getResult().size()>0){
			//修改
			core2 = this.setDataBySqlID("PhosphateResultService.ProcessPlan.UpdatePhosphateResult", pamar);
		}else{
			//新增
			core2 = this.setDataBySqlID("PhosphateResultService.ProcessPlan.AddPhosphateResult",pamar);
		}
		return core2;
    }
    
    /**
     * 保存接箍磷化检验结果表
     * @param list
     * @return
     */
    /*public CoreReturnObject savePhosphateRD(ArrayList<PhosphateRD> list){
    	CoreReturnObject core = new CoreReturnObject();
    	CoreReturnObject coreRD = new CoreReturnObject();
    	for (int i = 0; i < list.size(); i++) {
    		PhosphateRD prd = list.get(i);
    		Object[] params = new Object[]{prd.getItemNo(),prd.getTestResultF(),
    				prd.getTestResultT(),prd.getDosage(),prd.getTemperature(),
    				prd.getResultNo(),prd.getDetailNo()};
    		//coreRD = this.getPhosphateRD(planNO);
    		}
    	return core;
    }*/
    
    /**
     * 查询磷化检测实绩
     * @param planNO
     * @return
     */
    public CoreReturnObject getPhosphateResult(String  planNO){
    	return this.getDataBySqlID("PhosphateResultService.ProcessPlan.GetPhosphateResult",new Object[]{planNO} );
    }
    /**
     * 查询接箍磷化检测项配置表
     * @return
     */
    public CoreReturnObject getPhosphateItem(){
    	return this.getDataBySqlID("PhosphateResultService.ProcessPlan.CoupProcessItem");
    }
    /**
     * 查询接箍磷化检测结果表
     * @param planNO
     * @return
     */
    public CoreReturnObject getPhosphateRD(String  planNO){
    	return this.getDataBySqlID("PhosphateResultService.ProcessPlan.CoupProcessRD", new Object[] {planNO});
    }
    /**
     * 
     * @param planNO
     * @param detailNo
     * @return
     */
    public CoreReturnObject getPhosphateRDByDetailNo(String  planNO,String detailNo){
    	return this.getDataBySqlID("PhosphateResultService.ProcessPlan.CoupProcessRDByDetailNo", new Object[] {planNO,detailNo});
    }
}
