//
// 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 MeasCostDefault implements IMeasCostStrategy {
    public MeasCostDefault() {
    }

    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;
            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());
                        nsumTemp = nsumTemp.add(measCostQueryResultVO.getNsum());
                        cccodeMap.put(measCostQueryResultVO.getCccode(), UFDouble.ZERO_DBL);
                    }

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

                resultVO.setNnum(nnumTemp);
                resultVO.setNsum(nsumTemp);
            }

            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("nsum", "ncost", resultVO.getNsum());
            itemVO.setAttrbuteByRule("nmeascost", "ncost", CMNumberUtil2.div(resultVO.getNsum(), new UFDouble[]{resultVO.getNnum()}));
        }
    }

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

            for(MeasCostQueryResultVO vo : factorList) {
                factorNsum = CMNumberUtil2.add(new UFDouble[]{factorNsum, vo.getFactorNsum()});
            }

            itemVO.setAttrbuteByRule(resultVO.getFactorcode(), "ncost", factorNsum);
        }
    }
}
