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

package nc.bs.cm.meascostcontrast.process;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
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.MeasCostQueryConditionVO;
import nc.vo.cm.meascostcontrast.MeasCostQueryResultVO;
import nc.vo.pub.lang.UFDouble;
import org.apache.commons.lang3.StringUtils;

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

    public void saveItem(List<MeasCostQueryResultVO> factorList, MeasCostItemVO itemVO) {
        if (!CMValidateUtil.isEmpty(factorList)) {
            MeasCostQueryResultVO resultVO = (MeasCostQueryResultVO)factorList.get(0);
            UFDouble nnumTemp = UFDouble.ZERO_DBL;
            UFDouble nsumTemp = UFDouble.ZERO_DBL;
            UFDouble nstdcostNsumTemp = UFDouble.ZERO_DBL;
            UFDouble nnumdiffNsum = UFDouble.ZERO_DBL;
            UFDouble npricediffNsum = UFDouble.ZERO_DBL;
            if (StringUtils.equals(String.valueOf(MeasCostQueryConditionVO.NO_COSTCENTER_VALUE), ((MeasCostQueryResultVO)factorList.get(0)).getIsSumCccode())) {
                Map<String, UFDouble> cccodeMap = new HashMap();

                for(MeasCostQueryResultVO measCostQueryResultVO : factorList) {
                    if (!cccodeMap.containsKey(measCostQueryResultVO.getCccode())) {
                        nnumTemp = nnumTemp.add(measCostQueryResultVO.getNnum() == null ? UFDouble.ZERO_DBL : measCostQueryResultVO.getNnum());
                        nsumTemp = nsumTemp.add(measCostQueryResultVO.getNsum() == null ? UFDouble.ZERO_DBL : measCostQueryResultVO.getNsum());
                        nstdcostNsumTemp = nstdcostNsumTemp.add(resultVO.getNstdcostNsum() == null ? UFDouble.ZERO_DBL : resultVO.getNstdcostNsum());
                        nnumdiffNsum = nnumdiffNsum.add(resultVO.getNnumdiffNsum() == null ? UFDouble.ZERO_DBL : resultVO.getNnumdiffNsum());
                        npricediffNsum = npricediffNsum.add(resultVO.getNpricediffNsum() == null ? UFDouble.ZERO_DBL : resultVO.getNpricediffNsum());
                        cccodeMap.put(measCostQueryResultVO.getCccode(), UFDouble.ZERO_DBL);
                    }

                    measCostQueryResultVO.setCcname("");
                    measCostQueryResultVO.setCccode("");
                }

                resultVO.setNnum(nnumTemp);
                resultVO.setNsum(nsumTemp);
                resultVO.setNstdcostNmeascost(nstdcostNsumTemp);
                resultVO.setNnumdiffNsum(nnumdiffNsum);
                resultVO.setNpricediffNsum(npricediffNsum);
            }

            itemVO.setBookname(resultVO.getBookname());
            itemVO.setProfitcentername(resultVO.getProfitcentername());
            itemVO.setOrgname(resultVO.getOrgname());
            itemVO.setCccode(resultVO.getCccode());
            itemVO.setCcname(resultVO.getCcname());
            itemVO.setVcostobjcode(resultVO.getVcostobjcode());
            itemVO.setVcostobjname(resultVO.getVcostobjname());
            itemVO.setMaterialspec(resultVO.getMaterialspec());
            itemVO.setMaterialtype(resultVO.getMaterialtype());
            itemVO.setMeasdocname(resultVO.getMeasdocname());
            itemVO.setBitnumber(resultVO.getBitnumber());
            itemVO.setNnum(resultVO.getNnum());
            itemVO.setProjectcode(resultVO.getProjectcode());
            itemVO.setProjectname(resultVO.getProjectname());
            itemVO.setAttrbuteByRule("nmeascost", "ncost", CMNumberUtil2.div(resultVO.getNsum(), new UFDouble[]{resultVO.getNnum()}));
            itemVO.setAttrbuteByRule("nmeascost", "nstdcost", CMNumberUtil2.div(resultVO.getNstdcostNsum(), new UFDouble[]{resultVO.getNnum()}));
            itemVO.setAttrbuteByRule("nmeascost", "nnumdiff", CMNumberUtil2.div(resultVO.getNnumdiffNsum(), new UFDouble[]{resultVO.getNnum()}));
            itemVO.setAttrbuteByRule("nmeascost", "npricediff", CMNumberUtil2.div(resultVO.getNpricediffNsum(), new UFDouble[]{resultVO.getNnum()}));
            itemVO.setAttrbuteByRule("nsum", "ncost", resultVO.getNsum());
            itemVO.setAttrbuteByRule("nsum", "nstdcost", resultVO.getNstdcostNsum());
            itemVO.setAttrbuteByRule("nsum", "nnumdiff", resultVO.getNnumdiffNsum());
            itemVO.setAttrbuteByRule("nsum", "npricediff", resultVO.getNpricediffNsum());
        }
    }

    public void saveFactor(List<MeasCostQueryResultVO> factorList, MeasCostItemVO itemVO) {
        if (!CMValidateUtil.isEmpty(factorList)) {
            MeasCostQueryResultVO resultVO = (MeasCostQueryResultVO)factorList.get(0);
            UFDouble factorNsum = UFDouble.ZERO_DBL;
            UFDouble nstdcostFactor = UFDouble.ZERO_DBL;
            UFDouble nnumdiffFactor = UFDouble.ZERO_DBL;
            UFDouble npricediffFactor = UFDouble.ZERO_DBL;

            for(MeasCostQueryResultVO vo : factorList) {
                factorNsum = CMNumberUtil2.add(new UFDouble[]{factorNsum, vo.getFactorNsum()});
                nstdcostFactor = CMNumberUtil2.add(new UFDouble[]{nstdcostFactor, vo.getNstdcostFactor()});
                nnumdiffFactor = CMNumberUtil2.add(new UFDouble[]{nnumdiffFactor, vo.getNnumdiffFactor()});
                npricediffFactor = CMNumberUtil2.add(new UFDouble[]{npricediffFactor, vo.getNpricediffFactor()});
            }

            String factorcode = resultVO.getFactorcode();
            itemVO.setAttrbuteByRule(factorcode, "ncost", factorNsum);
            itemVO.setAttrbuteByRule(factorcode, "nstdcost", nstdcostFactor);
            itemVO.setAttrbuteByRule(factorcode, "nnumdiff", nnumdiffFactor);
            itemVO.setAttrbuteByRule(factorcode, "npricediff", npricediffFactor);
        }
    }
}
