//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package nc.bs.cm.meascostcontrast.process;

import java.util.List;
import nc.bd.framework.base.CMNumberUtil2;
import nc.bs.cm.meascostcontrast.strategy.IMeasCostStrategy;
import nc.cmpub.framework.util.CMValidateUtil;
import nc.vo.cm.meascostcontrast.MeasCostItemVO;
import nc.vo.cm.meascostcontrast.MeasCostQueryResultVO;
import nc.vo.pub.lang.UFDouble;

public class MeasCostCenterfrom implements IMeasCostStrategy {
    public MeasCostCenterfrom() {
    }

    public void saveItem(List<MeasCostQueryResultVO> factorList, MeasCostItemVO itemVO) {
        if (!CMValidateUtil.isEmpty(factorList)) {
            itemVO.setBookname(((MeasCostQueryResultVO)factorList.get(0)).getBookname());
            itemVO.setProfitcentername(((MeasCostQueryResultVO)factorList.get(0)).getProfitcentername());
            itemVO.setOrgname(((MeasCostQueryResultVO)factorList.get(0)).getOrgname());
            itemVO.setCccode(((MeasCostQueryResultVO)factorList.get(0)).getCccode());
            itemVO.setCcname(((MeasCostQueryResultVO)factorList.get(0)).getCcname());
            itemVO.setVcostobjcode(((MeasCostQueryResultVO)factorList.get(0)).getVcostobjcode());
            itemVO.setVcostobjname(((MeasCostQueryResultVO)factorList.get(0)).getVcostobjname());
            itemVO.setNnum(((MeasCostQueryResultVO)factorList.get(0)).getNnum());
            itemVO.setMaterialspec(((MeasCostQueryResultVO)factorList.get(0)).getMaterialspec());
            itemVO.setMaterialtype(((MeasCostQueryResultVO)factorList.get(0)).getMaterialtype());
            itemVO.setMeasdocname(((MeasCostQueryResultVO)factorList.get(0)).getMeasdocname());
            itemVO.setBitnumber(((MeasCostQueryResultVO)factorList.get(0)).getBitnumber());
            itemVO.setProjectcode(((MeasCostQueryResultVO)factorList.get(0)).getProjectcode());
            itemVO.setProjectname(((MeasCostQueryResultVO)factorList.get(0)).getProjectname());
            UFDouble nmeascostN = UFDouble.ZERO_DBL;
            UFDouble nmeascostY = UFDouble.ZERO_DBL;
            UFDouble nsumN = UFDouble.ZERO_DBL;
            UFDouble nsumY = UFDouble.ZERO_DBL;

            for(MeasCostQueryResultVO resultVO : factorList) {
                String bfromcostcenter = resultVO.getBfromcostcenter();
                if ("N".equals(bfromcostcenter)) {
                    nsumN = resultVO.getNsum();
                    nmeascostN = CMNumberUtil2.div(nsumN, new UFDouble[]{((MeasCostQueryResultVO)factorList.get(0)).getNnum()});
                } else if ("Y".equals(bfromcostcenter)) {
                    nsumY = resultVO.getNsum();
                    nmeascostY = CMNumberUtil2.div(nsumY, new UFDouble[]{((MeasCostQueryResultVO)factorList.get(0)).getNnum()});
                }
            }

            itemVO.setAttrbuteByRule("nmeascost", "ncost", CMNumberUtil2.add(new UFDouble[]{nmeascostN, nmeascostY}));
            itemVO.setAttrbuteByRule("nmeascost", "thiscenter", nmeascostN);
            itemVO.setAttrbuteByRule("nmeascost", "othercenter", nmeascostY);
            itemVO.setAttrbuteByRule("nsum", "ncost", CMNumberUtil2.add(new UFDouble[]{nsumN, nsumY}));
            itemVO.setAttrbuteByRule("nsum", "thiscenter", nsumN);
            itemVO.setAttrbuteByRule("nsum", "othercenter", nsumY);
        }
    }

    public void saveFactor(List<MeasCostQueryResultVO> factorList, MeasCostItemVO itemVO) {
        if (!CMValidateUtil.isEmpty(factorList)) {
            String factorcode = ((MeasCostQueryResultVO)factorList.get(0)).getFactorcode();
            UFDouble factornsumN = UFDouble.ZERO_DBL;
            UFDouble factornsumY = UFDouble.ZERO_DBL;

            for(MeasCostQueryResultVO resultVO : factorList) {
                String bfromcostcenter = resultVO.getBfromcostcenter();
                if ("N".equals(bfromcostcenter)) {
                    factornsumN = CMNumberUtil2.add(new UFDouble[]{factornsumN, resultVO.getFactorNsum()});
                } else if ("Y".equals(bfromcostcenter)) {
                    factornsumY = CMNumberUtil2.add(new UFDouble[]{factornsumY, resultVO.getFactorNsum()});
                }
            }

            itemVO.setAttrbuteByRule(factorcode, "ncost", CMNumberUtil2.add(new UFDouble[]{factornsumN, factornsumY}));
            itemVO.setAttrbuteByRule(factorcode, "thiscenter", factornsumN);
            itemVO.setAttrbuteByRule(factorcode, "othercenter", factornsumY);
        }
    }
}
