package com.tofly.xrtygis.custom.util;

import com.tofly.xrtygis.custom.entity.ImportDto.*;
import com.tofly.xrtygis.custom.entity.dto.WaterInfoDto;
import com.tofly.xrtygis.entity.*;

import java.math.BigDecimal;

/**
 * @author 20126
 */
public class ImportWaterMaking {

    private static final Double W = 10000D;
    private static final Double K = 1000D;
    private static final Double TEN = 10D;

    /**
     * 计算水量计划
     */
    public static Costbgwater calTbgWater(WaterPlanDto dto) {
        Costbgwater water = new Costbgwater();
        water.setMonth(dto.getYear() + "-" + dto.getMonth());
        water.setGslOne(dto.getGslOne());
        water.setGslTwo(dto.getGslTwo());
        water.setGslTotal(add(dto.getGslOne(), dto.getGslTwo()));
        water.setGslQbj(dto.getGslQbj());
        water.setZslOne(dto.getZslOne());
        water.setZslTwo(dto.getZslTwo());
        water.setZslTotal(add(dto.getZslOne(), dto.getZslTwo()));
        water.setZslHqsk(dto.getZslHqsk());
        water.setSslTotal(dto.getSslTotal());
        water.setZyslOne(subtract(dto.getZslOne(), dto.getGslOne()));
        water.setZyslTwo(subtract(dto.getZslTwo(), dto.getGslTwo()));
        water.setZyslTotal(add(subtract(dto.getZslOne(), dto.getGslOne()), subtract(dto.getZslTwo(), dto.getGslTwo())));
        water.setWspsl(dto.getWspsl());

        Double cxc = divide(subtract(add(water.getGslTotal(), water.getGslQbj()), dto.getSslTotal()), add(water.getGslTotal(), water.getGslQbj()));
        Double lsl = divide(subtract(subtract(add(water.getGslTotal(), water.getGslQbj()), dto.getSslTotal()), dto.getWspsl()), add(water.getGslTotal(), water.getGslQbj()));

        water.setZysllOne(multiply(divide(water.getZyslOne(), dto.getZslOne()), 100D));
        water.setZysllTwo(multiply(divide(water.getZyslTwo(), dto.getZslTwo()), 100D));
        water.setZysllTotal(multiply(divide(water.getZyslTotal(), water.getZslTotal()), 100D));
        water.setCxc(cxc != null ? cxc * 100 : null);
        water.setLsl(lsl != null ? lsl * 100 : null);

        return water;
    }

    /**
     * 计算预算指标
     */
    public static Costbgindex calTbgIndex(UnitPlanDto udto, Costbgwater water, IndexPlanDto idto) {
        Costbgindex index = new Costbgindex();

        index.setMonth(water.getMonth());

        index.setPam(idto.getPam());
        index.setFt(idto.getFt());
        index.setCn(idto.getCn());
        index.setGmsjfhy(idto.getGmsjfhy());
        index.setPamWn(idto.getPamWn());
        index.setBcs(idto.getBcs());
        index.setWnzl(idto.getWnzl());
        index.setOther(idto.getOther());

        index.setPacOne(multiply(udto.getPacdhOne(), multiply(water.getZslOne(), TEN)));
        index.setPacTwo(multiply(udto.getPacdhTwo(), multiply(water.getZslTwo(), TEN)));
        index.setSyOne(multiply(udto.getSydhOne(), multiply(water.getZslOne(), TEN)));
        index.setYlTwo(multiply(udto.getYldhTwo(), multiply(water.getZslTwo(), TEN)));
        index.setDldlOne(multiply(udto.getDhOne(), multiply(water.getZslOne(), TEN)));
        index.setDldlTwo(multiply(udto.getDhTwo(), multiply(water.getZslTwo(), TEN)));
        index.setDldlTotal(add(index.getDldlOne(), index.getDldlTwo()));

        return index;
    }

    /**
     * 计算预算单耗
     */
    public static Costbgunit calTbgUnit(Costbgwater water, UnitPlanDto dto) {
        Costbgunit unit = new Costbgunit();
        unit.setMonth(water.getMonth());

        unit.setPacdhOne(dto.getPacdhOne());
        unit.setPacdhTwo(dto.getPacdhTwo());
        unit.setSydhOne(dto.getSydhOne());
        unit.setYldhTwo(dto.getYldhTwo());
        unit.setDhOne(dto.getDhOne());
        unit.setDhTwo(dto.getDhTwo());

        //总制水单位电耗 = （制水单位电耗（一厂）*制水量(一厂) + 制水单位电耗（二厂）*制水量(二厂) ）/ (制水量(一厂) +制水量(二厂))
        unit.setDhTotal(divide(add(multiply(dto.getDhOne(), multiply(water.getZslOne(), TEN)), multiply(dto.getDhTwo(), multiply(water.getZslTwo(), TEN))), multiply(add(water.getZslOne(), water.getZslTwo()), TEN)));

        return unit;
    }

    /**
     * 计算预算单变
     */
    public static Costbgfixed calTbgFixed(Costbgwater water, Costbgprice price, Costbgindex index, Double jbdfOne, Double jbdfTwo) {
        Costbgfixed fixed = new Costbgfixed();

        fixed.setMouth(water.getMonth());

        Double otherzfy = multiply(price.getOtherdj(), divide(index.getOther(), K));
        Double paczfyOne = multiply(price.getPacdj(), divide(index.getPacOne(), K));
        Double paczfyTwo = multiply(price.getPacdj(), divide(index.getPacTwo(), K));
        Double syzfyOne = multiply(price.getSydj(), divide(index.getSyOne(), K));
        Double ylzfyTwo = multiply(price.getYldj(), divide(index.getYlTwo(), K));
        Double pamzszfy = multiply(price.getPamZsdj(), index.getPam());
        Double ftzfy = multiply(price.getFtdj(), divide(index.getFt(), K));
        Double cnzfy = multiply(price.getCndj(), divide(index.getCn(), K));
        Double gmsjfhyzfy = multiply(price.getGmsjfhydj(), divide(index.getGmsjfhy(), K));
        Double pamwnzfy = multiply(price.getPamWndj(), index.getPamWn());
        Double bcszfy = multiply(price.getBcsdj(), index.getBcs());
        Double wnzyzfy = multiply(price.getWnzydj(), divide(index.getWnzl(), K));
        Double dldfOne = multiply(price.getDlddjOne(), index.getDldlOne());
        Double dldfTwo = multiply(price.getDlddjTwo(), index.getDldlTwo());


        fixed.setJbdfOne(jbdfOne);
        fixed.setJbdfTwo(jbdfTwo);
        fixed.setJbdfTotal(add(jbdfOne, jbdfTwo));
        fixed.setOtherzfy(otherzfy == null ? null : otherzfy / W);
        fixed.setPaczfyOne(paczfyOne == null ? null : paczfyOne / W);
        fixed.setPaczfyTwo(paczfyTwo == null ? null : paczfyTwo / W);
        fixed.setSyzfyOne(syzfyOne == null ? null : syzfyOne / W);
        fixed.setYlzfyTwo(ylzfyTwo == null ? null : ylzfyTwo / W);
        fixed.setPamzszfy(pamzszfy == null ? null : pamzszfy / W);
        fixed.setFtzfy(ftzfy == null ? null : ftzfy / W);
        fixed.setCnzfy(cnzfy == null ? null : cnzfy / W);
        fixed.setGmsjfhyzfy(gmsjfhyzfy == null ? null : gmsjfhyzfy / W);
        fixed.setPamwnzfy(pamwnzfy == null ? null : pamwnzfy / W);
        fixed.setBcszfy(bcszfy == null ? null : bcszfy / W);
        fixed.setDldfOne(dldfOne == null ? null : dldfOne / W);
        fixed.setDldfTwo(dldfTwo == null ? null : dldfTwo / W);
        fixed.setDldfTotal(add(fixed.getDldfOne(), fixed.getDldfTwo()));
        fixed.setWnzyf(wnzyzfy == null ? null : wnzyzfy / W);

        fixed.setYsf(divide(multiply(water.getZslHqsk(), price.getYsfdj()), W));
        fixed.setSzysfOne(divide(multiply(water.getZslOne(), price.getSzysdj()), W));
        fixed.setSzysfTwo(divide(multiply(water.getZslTwo(), price.getSzysdj()), W));
        fixed.setSzysfTotal(divide(multiply(water.getZslTotal(), price.getSzysdj()), W));
        fixed.setZzsclfyOne(add(fixed.getOtherzfy(),add(add(fixed.getPaczfyOne(), fixed.getSyzfyOne()), add(fixed.getBcszfy(), fixed.getCnzfy()))));
        fixed.setZzsclfyTwo(add(add(add(add(fixed.getPaczfyTwo(), fixed.getYlzfyTwo()), add(fixed.getPamzszfy(), fixed.getFtzfy())), add(fixed.getGmsjfhyzfy(), fixed.getPamwnzfy())), fixed.getWnzyf()));
        fixed.setZfyOne(add(add(add(fixed.getJbdfOne(), fixed.getDldfOne()), add(fixed.getZzsclfyOne(), fixed.getYsf())), fixed.getSzysfOne()));
        fixed.setZfyTwo(add(add(fixed.getJbdfTwo(), fixed.getDldfTwo()), add(fixed.getZzsclfyTwo(), fixed.getSzysfTwo())));
        fixed.setZfy(add(fixed.getZfyOne(), fixed.getZfyTwo()));
        //一厂电费单位成本变动
        fixed.setDfcbOne(multiply(divide(add(fixed.getJbdfOne(), fixed.getDldfOne()), water.getGslOne()), K));
        fixed.setDfcbTwo(multiply(divide(add(fixed.getJbdfTwo(), fixed.getDldfTwo()), water.getGslTwo()), K));
        fixed.setDfcbTotal(multiply(divide(add(fixed.getJbdfTotal(), fixed.getDldfTotal()), water.getGslTotal()), K));
        //一厂制水材料单项成本
        fixed.setPaccbOne(multiply(divide(fixed.getPaczfyOne(), water.getGslOne()), K));
        fixed.setSycbOne(multiply(divide(fixed.getSyzfyOne(), water.getGslOne()), K));
        fixed.setCncbOne(multiply(divide(fixed.getCnzfy(), water.getGslOne()), K));
        fixed.setBcscbOne(multiply(divide(fixed.getBcszfy(), water.getGslOne()), K));
        //总制水材料成本一厂
        fixed.setZsclcbOne(multiply(divide(fixed.getZzsclfyOne(), water.getGslOne()), K));
        //二厂各项制水材料成本
        fixed.setPaccbTwo(multiply(divide(fixed.getPaczfyTwo(), water.getGslTwo()), K));
        fixed.setYlcbTwo(multiply(divide(fixed.getYlzfyTwo(), water.getGslTwo()), K));
        fixed.setPamzscbTwo(multiply(divide(fixed.getPamzszfy(), water.getGslTwo()), K));
        fixed.setFtcbTwo(multiply(divide(fixed.getFtzfy(), water.getGslTwo()), K));
        fixed.setGmsjfhycbTwo(multiply(divide(fixed.getGmsjfhyzfy(), water.getGslTwo()), K));
        fixed.setPamwncbTwo(multiply(divide(fixed.getPamwnzfy(), water.getGslTwo()), K));
        fixed.setWnzycbTwo(multiply(divide(fixed.getWnzyf(), water.getGslTwo()), K));
        //二厂总制水材料成本
        fixed.setZsclcbTwo(multiply(divide(fixed.getZzsclfyTwo(), water.getGslTwo()), K));
        //总制水材料成本
        fixed.setZsclcbTotal(multiply(divide(add(fixed.getZzsclfyOne(), fixed.getZzsclfyTwo()), water.getGslTotal()), K));
        //原水费成本
        fixed.setYsfcb(multiply(divide(fixed.getYsf(), water.getGslTotal()), K));
        //水资源税费成本
        fixed.setSzysfcbOne(multiply(divide(fixed.getSzysfOne(), water.getGslOne()), K));
        fixed.setSzysfcbTwo(multiply(divide(fixed.getSzysfTwo(), water.getGslTwo()), K));
        fixed.setSzysfcbTotal(multiply(divide(fixed.getSzysfTotal(), water.getGslTotal()), K));

        //单位变动成本
        fixed.setDwcbOne(multiply(divide(fixed.getZfyOne(), water.getGslTotal()), K));
        fixed.setDwcbTwo(multiply(divide(fixed.getZfyTwo(), water.getGslTotal()), K));
        fixed.setDwcbTotal(multiply(divide(fixed.getZfy(), water.getGslTotal()), K));

        return fixed;
    }

    /**
     * 计算实际制水总量
     */
    public static Costrlwater calTrlWater(WaterDto dto) {

        Costrlwater water = new Costrlwater();
        water.setMark("0");

        water.setUpDate(dto.getUpDate());

        water.setOther(dto.getOther());
        water.setGslOne(dto.getGslOne());
        water.setGslTwo(dto.getGslTwo());
        water.setGslQbj(dto.getGslQbj());
        water.setGslTotal(add(dto.getGslOne(), dto.getGslTwo()));
        water.setZslOne(dto.getZslOne());
        water.setZslTwo(dto.getZslTwo());
        water.setZslHqsk(dto.getZslHqsk());
        water.setZslTotal(add(dto.getZslOne(), dto.getZslTwo()));
        water.setSslTotal(dto.getSslTotal());
        water.setWspsl(dto.getWspsl());
        water.setPacOne(dto.getPacOne());
        water.setPacTwo(dto.getPacTwo());
        water.setSyOne(dto.getSyOne());
        water.setYlTwo(dto.getYlTwo());
        water.setPam(dto.getPam());
        water.setFt(dto.getFt());
        water.setCn(dto.getFt());
        water.setGmsjfhy(dto.getGmsjfhy());
        water.setPamWy(dto.getPamWy());
        water.setBcs(dto.getBcs());
        water.setWnzl(dto.getWnzl());
        water.setDldlOne(dto.getDldlOne());
        water.setDldlTwo(dto.getDldlTwo());
        water.setDldlTotal(add(dto.getDldlTwo(), dto.getDldlOne()));
        water.setJbdlOne(dto.getJbdlOne());
        water.setJbdlTwo(dto.getJbdlTwo());
        water.setJbdlTotal(add(dto.getJbdlOne(), dto.getJbdlTwo()));

        water.setZyslOne(subtract(dto.getZslOne(), dto.getGslOne()));
        water.setZyslTwo(subtract(dto.getZslTwo(), dto.getGslTwo()));
        water.setZyslTotal(add(subtract(dto.getZslOne(), dto.getGslOne()), subtract(dto.getZslTwo(), dto.getGslTwo())));

        Double cxc = divide(subtract(add(water.getGslTotal(), water.getGslQbj()), dto.getSslTotal()), add(water.getGslTotal(), water.getGslQbj()));
        Double lsl = divide(subtract(subtract(add(water.getGslTotal(), water.getGslQbj()), dto.getSslTotal()), dto.getWspsl()), add(water.getGslTotal(), water.getGslQbj()));

        water.setZysllOne(multiply(divide(water.getZyslOne(), dto.getZslOne()), 100D));
        water.setZysllTwo(multiply(divide(water.getZyslTwo(), dto.getZslTwo()), 100D));
        water.setZysllTotal(multiply(divide(water.getZyslTotal(), water.getZslTotal()), 100D));
        water.setCxc(cxc != null ? cxc * 100 : null);
        water.setLsl(lsl != null ? lsl * 100 : null);

        return water;
    }

    /**
     * 计算制水单耗
     */
    public static Costrlunit calTrlUnit(Costrlwater water) {

        Costrlunit unit = new Costrlunit();

        unit.setUpDate(water.getUpDate());

        unit.setPacdhOne(divide(water.getPacOne(), multiply(water.getZslOne(), TEN)));
        unit.setPacdhTwo(divide(water.getPacTwo(), multiply(water.getZslTwo(), TEN)));
        unit.setSydhOne(divide(water.getSyOne(), multiply(water.getZslOne(), TEN)));
        unit.setYldhTwo(divide(water.getYlTwo(), multiply(water.getZslTwo(), TEN)));
        unit.setDhOne(divide(water.getDldlOne(), multiply(water.getZslOne(), TEN)));
        unit.setDhTwo(divide(water.getDldlTwo(), multiply(water.getZslTwo(), TEN)));
        unit.setDhTotal(divide(water.getDldlTotal(), multiply(water.getZslTotal(), TEN)));

        unit.setCndh(divide(water.getCn(), multiply(water.getZslOne(), TEN)));
        unit.setGmsjfhydh(divide(water.getGmsjfhy(), multiply(water.getZslTwo(), TEN)));
        unit.setPamdh(divide(water.getPam(), multiply(water.getZslTwo(), TEN)));
        unit.setPamWydh(divide(water.getPamWy(), multiply(water.getZslTwo(), TEN)));
        unit.setWnzldh(divide(water.getWnzl(), multiply(water.getZslTwo(), TEN)));
        unit.setFtdh(divide(water.getFt(), multiply(water.getZslTwo(), TEN)));
        unit.setBcsdh(divide(water.getBcs(), multiply(water.getZslOne(), TEN)));
        unit.setOtherdh(divide(water.getOther(), multiply(water.getZslTotal(), TEN)));

        return unit;
    }

    /**
     * 计算制水总量信息
     */
    public static Costrlwater calWaterInfo(FixedDto dto, WaterInfoDto info, Costrlprice price) {

        Costrlwater water = new Costrlwater();

        water.setUpDate(dto.getUpDate());

        //冰醋酸  元/kg
        water.setBcs(divide(multiply(dto.getBcszfy(), W), price.getBcsdj()));
        //次钠   元/吨
        water.setCn(divide(multiply(dto.getCnzfy(), TEN), price.getCndj()));
        //粉碳   元/吨
        water.setFt(divide(multiply(dto.getFtzfy(), TEN), price.getFtdj()));
        //高锰酸钾  元/吨
        water.setGmsjfhy(divide(multiply(dto.getGmsjfhyzfy(), TEN), price.getGmsjfhydj()));
        //碱铝  元/吨
        water.setPacOne(divide(multiply(dto.getPaczfyOne(), TEN), price.getPacdj()));
        water.setPacTwo(divide(multiply(dto.getPaczfyTwo(), TEN), price.getPacdj()));

        if (info != null) {
            water.setGslOne(info.getGslOne());
            water.setGslTwo(info.getGslOne());
            water.setSslTotal(info.getSsl());
            water.setGslTotal(info.getGslTotal());
            water.setGslQbj(info.getGslQbj());
            water.setWspsl(info.getWspsl());
            water.setJbdlOne(info.getJbdlOne());
            water.setJbdlTwo(info.getJbdlTwo());
            water.setJbdlTotal(info.getJbdlTotal());
        }


        water.setDldlOne(divide(subtract(multiply(dto.getDfOneTotal(), W), multiply(water.getJbdlOne(), price.getJbdldjOne())), price.getDlddjOne()));
        water.setDldlTwo(divide(subtract(multiply(dto.getDfTwoTotal(), W), multiply(water.getJbdlTwo(), price.getJbdldjTwo())), price.getDlddjTwo()));
        water.setDldlTotal(add(water.getDldlOne(), water.getDldlTwo()));

        water.setZslHqsk(divide(dto.getYsf(), price.getYsfdj()));
        water.setZslOne(divide(dto.getSzysfOne(), price.getSzysdj()));
        water.setZslTwo(divide(dto.getSzysfTwo(), price.getSzysdj()));
        water.setPam(divide(multiply(dto.getPamzszfy(), W), price.getPamZsdj()));
        water.setPamWy(divide(multiply(dto.getPamwnzfy(), W), price.getPamWndj()));
        water.setSyOne(divide(multiply(dto.getSyzfyOne(), TEN), price.getSydj()));
        water.setWnzl(divide(multiply(dto.getWnzyf(), TEN), price.getWnzydj()));
        water.setYlTwo(divide(multiply(dto.getYlzfyTwo(), TEN), price.getYldj()));
        water.setOther(divide(multiply(dto.getOtherzfy(), TEN), price.getOtherdj()));

        CommonMethod.calWater(water);
        water.setMark("1");
        return water;
    }

    /**
     * 计算单变信息
     */
    public static Costrlfixed calFixedInfo(FixedDto dto, Costrlprice price, Costrlwater water) {
        Costrlfixed fixed = new Costrlfixed();

        fixed.setMark("1");
        fixed.setUpDate(dto.getUpDate());

        fixed.setPaczfyOne(dto.getPaczfyOne());
        fixed.setPaczfyTwo(dto.getPaczfyTwo());
        fixed.setSyzfyOne(dto.getSyzfyOne());
        fixed.setYlzfyTwo(dto.getYlzfyTwo());
        fixed.setCnzfy(dto.getCnzfy());
        fixed.setFtzfy(dto.getFtzfy());
        fixed.setGmsjfhyzfy(dto.getGmsjfhyzfy());
        fixed.setPamzszfy(dto.getPamzszfy());
        fixed.setBcszfy(dto.getBcszfy());
        fixed.setPamwnzfy(dto.getPamwnzfy());
        fixed.setWnzyf(dto.getWnzyf());
        fixed.setSzysfOne(dto.getSzysfOne());
        fixed.setSzysfTwo(dto.getSzysfTwo());
        fixed.setYsf(dto.getYsf());
        fixed.setOtherzfy(dto.getOtherzfy());

        fixed.setJbdfOne(divide(multiply(water.getJbdlOne(), price.getJbdldjOne()), W));
        fixed.setJbdfTwo(divide(multiply(water.getJbdlTwo(), price.getJbdldjTwo()), W));
        fixed.setJbdfTotal(add(fixed.getJbdfOne(), fixed.getJbdfTwo()));
        fixed.setDldfOne(divide(multiply(water.getDldlOne(), price.getDlddjOne()), W));
        fixed.setDldfTwo(divide(multiply(water.getDldlTwo(), price.getDlddjTwo()), W));
        fixed.setDldfTotal(add(fixed.getDldfOne(), fixed.getDldfTwo()));

        //一厂电费单位成本变动
        fixed.setDfcbOne(multiply(divide(add(fixed.getJbdfOne(), fixed.getDldfOne()), water.getGslOne()), K));
        fixed.setDfcbTwo(multiply(divide(add(fixed.getJbdfTwo(), fixed.getDldfTwo()), water.getGslTwo()), K));
        fixed.setDfcbTotal(multiply(divide(add(fixed.getJbdfTotal(), fixed.getDldfTotal()), water.getGslTotal()), K));
        //一厂制水材料单项成本
        fixed.setPaccbOne(multiply(divide(fixed.getPaczfyOne(), water.getGslOne()), K));
        fixed.setSycbOne(multiply(divide(fixed.getSyzfyOne(), water.getGslOne()), K));
        fixed.setCncbOne(multiply(divide(fixed.getCnzfy(), water.getGslOne()), K));
        fixed.setBcscbOne(multiply(divide(fixed.getBcszfy(), water.getGslOne()), K));
        //总制水材料成本一厂
        fixed.setZsclcbOne(multiply(divide(fixed.getZzsclfyOne(), water.getGslOne()), K));
        //二厂各项制水材料成本
        fixed.setPaccbTwo(multiply(divide(fixed.getPaczfyTwo(), water.getGslTwo()), K));
        fixed.setYlcbTwo(multiply(divide(fixed.getYlzfyTwo(), water.getGslTwo()), K));
        fixed.setPamzscbTwo(multiply(divide(fixed.getPamzszfy(), water.getGslTwo()), K));
        fixed.setFtcbTwo(multiply(divide(fixed.getFtzfy(), water.getGslTwo()), K));
        fixed.setGmsjfhycbTwo(multiply(divide(fixed.getGmsjfhyzfy(), water.getGslTwo()), K));
        fixed.setPamwncbTwo(multiply(divide(fixed.getPamwnzfy(), water.getGslTwo()), K));
        fixed.setWnzycbTwo(multiply(divide(fixed.getWnzyf(), water.getGslTwo()), K));
        //二厂总制水材料成本
        fixed.setZsclcbTwo(multiply(divide(fixed.getZzsclfyTwo(), water.getGslTwo()), K));
        //总制水材料成本
        fixed.setZsclcbTotal(multiply(divide(add(fixed.getZzsclfyOne(), fixed.getZzsclfyTwo()), water.getGslTotal()), K));
        //原水费成本
        fixed.setYsfcb(multiply(divide(fixed.getYsf(), water.getGslTotal()), K));
        //水资源税费成本
        fixed.setSzysfcbOne(multiply(divide(fixed.getSzysfOne(), water.getGslOne()), K));
        fixed.setSzysfcbTwo(multiply(divide(fixed.getSzysfTwo(), water.getGslTwo()), K));
        fixed.setSzysfcbTotal(multiply(divide(fixed.getSzysfTotal(), water.getGslTotal()), K));

        //单位变动成本
        fixed.setDwcbOne(multiply(divide(fixed.getZfyOne(), water.getGslTotal()), K));
        fixed.setDwcbTwo(multiply(divide(fixed.getZfyTwo(), water.getGslTotal()), K));
        fixed.setDwcbTotal(multiply(divide(fixed.getZfy(), water.getGslTotal()), K));

        return fixed;
    }

    /**
     * 判断数据是否为空
     */
    public static boolean existParam(Double dou1, Double dou2) {
        return dou1 != null && dou2 != null;
    }

    /**
     * 两数相加
     */
    public static Double add(Double dou1, Double dou2) {
        if (existParam(dou1, dou2)) {
            return new BigDecimal(dou1.toString()).add(new BigDecimal(dou2.toString())).doubleValue();
        } else {
            return null;
        }
    }


    /**
     * 两数相减
     */
    public static Double subtract(Double dou1, Double dou2) {
        if (existParam(dou1, dou2)) {
            return new BigDecimal(dou1.toString()).subtract(new BigDecimal(dou2.toString())).doubleValue();
        } else {
            return null;
        }
    }


    /**
     * 两数相除
     */
    public static Double divide(Double dou1, Double dou2) {
        if (existParam(dou1, dou2) && dou2 != 0) {
            return new BigDecimal(dou1.toString()).divide(new BigDecimal(dou2.toString()), 6, BigDecimal.ROUND_DOWN).doubleValue();
        } else {
            return null;
        }
    }

    /**
     * 两数相乘
     */
    public static Double multiply(Double dou1, Double dou2) {
        if (existParam(dou1, dou2)) {
            return new BigDecimal(dou1.toString()).multiply(new BigDecimal(dou2.toString())).doubleValue();
        } else {
            return null;
        }
    }


}
