package market.Qms.slmord.impl;

import java.util.List;

import market.Qms.common.DataHelper;
import market.Qms.common.ReturnMsg;
import market.Qms.metallurgy.mapper.ComPscRMscMapper;
import market.Qms.metallurgy.vo.ComMsc;
import market.Qms.metallurgy.vo.ComPscRMsc;
import market.Qms.slmord.service.QualityDesignAbilityRequireService;
import market.Slm.OrderManagement.vo.SlmContractProcessPlan;
import market.Slm.OrderManagement.vo.SlmProcessPlan;

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

@RemoteService(serviceInterface=QualityDesignAbilityRequireService.class)
public class QualityDesignAbilityRequireServiceImpl extends BaseServiceImpl<Object,Object> implements QualityDesignAbilityRequireService {

	@Override
	public boolean checkCustSpecialAsk(ReturnMsg msg, ComMsc msc,SlmContractProcessPlan orderLine) {
		if(DataHelper.IsNullOrSpace(orderLine.getCustomer_alpha_no())||!DataHelper.IsNullOrSpace(orderLine.getMsc_n())){
			return true;
		}
		//客户有特殊要求则必须要求合同行有最终用户
		if(!DataHelper.IsNullOrSpace(orderLine.getCustomer_alpha_no())&&DataHelper.IsNullOrSpace(orderLine.getUser_no())){
			msg.setMessage("订单有技术要求却无最终用户，无法进行技术要求评审");
			return false;
		}

		ComPscRMsc _prMsc=new ComPscRMsc();
		_prMsc.setPsc(orderLine.getPsc());
		_prMsc.setValidflag("1");
		String condition="cust_alpha_no like '"+orderLine.getCustomer_alpha_no()+"'";
		List<ComPscRMsc> listPRMsc=this.getMapper(ComPscRMscMapper.class).findWithCondition(_prMsc, condition, null, 0, 0);
		if(listPRMsc.size()>0){
			//存在与客户alpha编号关联的产品码与冶金规范码说明以前已经评审通过了
			if(listPRMsc.size()==1){
				SlmProcessPlan plan=new SlmProcessPlan();
				/*plan.setMsc(listPRMsc.get(0).getMsc());
				plan.setMsc_desc(listPRMsc.get(0).getMsc_desc());
				plan.setPlan_no(orderLine.getContract_line_no());*/
				orderLine.setMsc_n(listPRMsc.get(0).getMsc());
				//this.getMapper(SlmProcessPlanMapper.class).update(plan);
			}else{
				msg.setMessage("找到了多条适用客户的的msc(n)，需要人工确认");
				return false;
			}
			return true;
		}
		msg.setMessage("订单存在技术要求,待人工进行确认！");
		return false;
	}
}
