package nc.bs.mmpub.setanalysis.bp.rule;

import nc.bs.dao.BaseDAO;
import nc.impl.pubapp.pattern.rule.IRule;
import nc.vo.mmpub.setanalysis.entity.AggAnalysisVO;
import nc.vo.mmpub.setanalysis.entity.SaAnalysisVO;
import nc.vo.pub.BusinessException;

public class analysisAfterCheckRule implements IRule<AggAnalysisVO> {

	@Override
	public void process(AggAnalysisVO[] aggAnalysisVOS) {
		try {
			for (AggAnalysisVO vo : aggAnalysisVOS) {
				SaAnalysisVO saAnalysisVO = vo.getParentVO();
				String cdemandbillbid = saAnalysisVO.getCdemandbillbid();// 需求单据明细nsetsnum
				Object ntotaloutnumsObj = saAnalysisVO.getNsetsnum();// 齐套主数量ndemandnum
				String ntotaloutnums = (ntotaloutnumsObj != null) ? ntotaloutnumsObj.toString() : "";
				double ntotaloutnum = (ntotaloutnums.isEmpty()) ? 0 : Double.parseDouble(ntotaloutnums);// 齐套主数量
				Object ndemandnumObj = saAnalysisVO.getNdemandnum();// 分析主数量
				String ndemandnums = (ndemandnumObj != null) ? ndemandnumObj.toString() : "";
				double ndemandnum = (ndemandnums.isEmpty()) ? 0 : Double.parseDouble(ndemandnums);// 分析数量
				double vdef4 = 0;
				if (ndemandnum != 0) {
					vdef4 = ntotaloutnum / ndemandnum;
				}
				String update = " update mm_mo set vdef6=" + ntotaloutnum + ",vdef4=" + vdef4 + " where cmoid='"
						+ cdemandbillbid + "' ";
				updateSaleBSQty(update);
			}
		} catch (BusinessException e) {
			throw new RuntimeException(e);
		}
	}

	private int updateSaleBSQty(String sql) throws BusinessException {
		BaseDAO baseDAO = new BaseDAO();
		int succInt = baseDAO.executeUpdate(sql);
		return succInt;
	}

}
