package com.tofly.xrtygis.custom.util;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.xrtygis.custom.entity.dto.FixedDto;
import com.tofly.xrtygis.custom.entity.dto.WaterInfoDto;
import com.tofly.xrtygis.custom.entity.vo.CostVo;
import com.tofly.xrtygis.custom.entity.vo.MarkWaterVo;
import com.tofly.xrtygis.entity.*;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 提取的公共代码
 *
 * @author 陈浩
 */
public class CommonMethod {
    private final static Double W = 10000D;
    private final static Double K = 1000D;
    private final static Double TEN = 10D;

    /**
     * 计算制水费用
     */
    public static Costbgfixed calExpense(Costbgindex index, Costbgprice price, Costbgwater water, Double jbdfOne, Double jbdfTwo) {

        Costbgfixed fixed = new Costbgfixed();

        fixed.setMouth(index.getMonth());
        fixed.setJbdfOne(jbdfOne);
        fixed.setJbdfTwo(jbdfTwo);
        fixed.setJbdfTotal(add(jbdfOne, jbdfTwo));

        fixed.setOtherzfy(divide(multiply(price.getOtherdj(), divide(index.getOther(), K)), W));
        fixed.setOtherOneZfy(divide(multiply(price.getOtherOneDj(), divide(index.getOtherOne(), K)), W));
        fixed.setOtherTwoZfy(divide(multiply(price.getOtherTwoDj(), divide(index.getOtherTwo(), K)), W));
        fixed.setPaczfyOne(divide(multiply(price.getPacdj(), divide(index.getPacOne(), K)), W));
        fixed.setPaczfyTwo(divide(multiply(price.getPacdj(), divide(index.getPacTwo(), K)), W));
        fixed.setSyzfyOne(divide(multiply(price.getSydj(), divide(index.getSyOne(), K)), W));
        fixed.setYlzfyTwo(divide(multiply(price.getYldj(), divide(index.getYlTwo(), K)), W));
        fixed.setPamzszfy(divide(multiply(price.getPamZsdj(), index.getPam()), W));
        fixed.setFtzfy(divide(multiply(price.getFtdj(), divide(index.getFt(), K)), W));
        fixed.setCnzfy(divide(multiply(price.getCndj(), divide(index.getCn(), K)), W));
        fixed.setCnzfyTwo(divide(multiply(price.getCndj(), divide(index.getCnTwo(), K)), W));
        fixed.setGmsjfhyzfy(divide(multiply(price.getGmsjfhydj(), divide(index.getGmsjfhy(), K)), W));
        fixed.setPamwnzfy(divide(multiply(price.getPamWndj(), index.getPamWn()), W));
        fixed.setBcszfy(divide(multiply(price.getBcsdj(), index.getBcs()), W));
        fixed.setDldfOne(divide(multiply(price.getDlddjOne(), index.getDldlOne()), W));
        fixed.setDldfTwo(divide(multiply(price.getDlddjTwo(), index.getDldlTwo()), W));
        fixed.setDldfTotal(add(fixed.getDldfOne(), fixed.getDldfTwo()));
        fixed.setWnzyf(divide(multiply(price.getWnzydj(), multiply(index.getWnzl(), K)), W));
        if (null != water) {
            fixed.setYsf(multiply(water.getZslHqsk(), price.getYsfdj()));
            fixed.setSzysfOne(multiply(water.getZslOne(), price.getSzysdj()));
            fixed.setSzysfTwo(multiply(water.getZslTwo(), price.getSzysdj()));
            fixed.setSzysfTotal(multiply(water.getZslTotal(), price.getSzysdj()));
        }
        fixed.setZzsclfyOne(add(fixed.getOtherOneZfy(), add(fixed.getOtherzfy(), add(add(fixed.getPaczfyOne(), fixed.getSyzfyOne()), add(fixed.getBcszfy(), fixed.getCnzfy())))));
        fixed.setZzsclfyTwo(add(fixed.getOtherTwoZfy(), add(fixed.getCnzfyTwo(), 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.setUpdateTime(new Date());
        return fixed;
    }


    public static Costrlwater calWaterInfo(Costrlprice price, Costrlfixed fixed, WaterInfoDto dto) {

        Costrlwater water = new Costrlwater();

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

        water.setBcs(divide(multiply(fixed.getBcszfy(), W), price.getBcsdj()));
        water.setCn(divide(multiply(fixed.getCnzfy(), TEN), price.getCndj()));
        water.setCnTwo(divide(multiply(fixed.getCnzfyTwo(), TEN), price.getCndj()));
        water.setDldlOne(divide(multiply(fixed.getDldfOne(), W), price.getDlddjOne()));
        water.setDldlTwo(divide(multiply(fixed.getDldfTwo(), W), price.getDlddjTwo()));
        water.setFt(divide(multiply(fixed.getFtzfy(), TEN), price.getFtdj()));
        water.setGmsjfhy(divide(multiply(fixed.getGmsjfhyzfy(), TEN), price.getGmsjfhydj()));
        water.setPacOne(divide(multiply(fixed.getPaczfyOne(), TEN), price.getPacdj()));
        water.setPacTwo(divide(multiply(fixed.getPaczfyTwo(), TEN), price.getPacdj()));
        if (dto != null) {
            water.setGslOne(dto.getGslOne());
            water.setGslTwo(dto.getGslOne());
            water.setSslTotal(dto.getSsl());
            water.setGslTotal(dto.getGslTotal());
            water.setGslQbj(dto.getGslQbj());
            water.setWspsl(dto.getWspsl());
        }
        water.setZslHqsk(divide(fixed.getYsf(), price.getYsfdj()));
        water.setZslOne(divide(fixed.getSzysfOne(), price.getSzysdj()));
        water.setZslTwo(divide(fixed.getSzysfTwo(), price.getSzysdj()));
        water.setJbdlOne(divide(multiply(fixed.getJbdfOne(), W), price.getJbdldjOne()));
        water.setJbdlTwo(divide(multiply(fixed.getJbdfTwo(), W), price.getJbdldjTwo()));
        water.setPam(divide(multiply(fixed.getPamzszfy(), W), price.getPamZsdj()));
        water.setPamWy(divide(multiply(fixed.getPamwnzfy(), W), price.getPamWndj()));
        water.setSyOne(divide(multiply(fixed.getSyzfyOne(), TEN), price.getSydj()));
        water.setWnzl(divide(multiply(fixed.getWnzyf(), TEN), price.getWnzydj()));
        water.setYlTwo(divide(multiply(fixed.getYlzfyTwo(), TEN), price.getYldj()));
        water.setOther(divide(multiply(fixed.getOtherzfy(), TEN), price.getOtherdj()));
        water.setOtherOne(divide(multiply(fixed.getOtherOneZfy(), TEN), price.getOtherOneDj()));
        water.setOtherTwo(divide(multiply(fixed.getOtherTwoZfy(), TEN), price.getOtherTwoDj()));

        water.setUpdateTime(new Date());

        return calWater(water);
    }

    public static Costrlwater calWaterInfo(Costrlprice price, FixedDto fDto, WaterInfoDto dto) {

        Costrlwater water = new Costrlwater();

        water.setMark("1");
        water.setUpDate(fDto.getUpDate());

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

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

        water.setBcs(divide(multiply(fDto.getBcszfy(), W), price.getBcsdj()));
        water.setCn(divide(multiply(fDto.getCnzfy(), TEN), price.getCndj()));
        //（一厂总电费 -（基本电量*基本单价））/动力电单价

        water.setFt(divide(multiply(fDto.getFtzfy(), TEN), price.getFtdj()));
        water.setGmsjfhy(divide(multiply(fDto.getGmsjfhyzfy(), TEN), price.getGmsjfhydj()));
        water.setPacOne(divide(multiply(fDto.getPaczfyOne(), TEN), price.getPacdj()));
        water.setPacTwo(divide(multiply(fDto.getPaczfyTwo(), TEN), price.getPacdj()));

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

        return calWater(water);
    }

    public static Costrlfixed calExpense(Costrlprice price, Costrlwater water) {

        Costrlfixed fixed = new Costrlfixed();

        fixed.setUpDate(water.getUpDate());

        fixed.setOtherzfy(divide(multiply(price.getOtherdj(), divide(water.getOther(), K)), W));
        fixed.setOtherOneZfy(divide(multiply(price.getOtherOneDj(), divide(water.getOtherOne(), K)), W));
        fixed.setOtherTwoZfy(divide(multiply(price.getOtherTwoDj(), divide(water.getOtherTwo(), K)), W));
        fixed.setPaczfyOne(divide(multiply(price.getPacdj(), divide(water.getPacOne(), K)), W));
        fixed.setPaczfyTwo(divide(multiply(price.getPacdj(), divide(water.getPacTwo(), K)), W));
        fixed.setSyzfyOne(divide(multiply(price.getSydj(), divide(water.getSyOne(), K)), W));
        fixed.setYlzfyTwo(divide(multiply(price.getYldj(), divide(water.getYlTwo(), K)), W));
        fixed.setPamzszfy(divide(multiply(price.getPamZsdj(), water.getPam()), W));
        fixed.setFtzfy(divide(multiply(price.getFtdj(), divide(water.getFt(), K)), W));
        fixed.setCnzfy(divide(multiply(price.getCndj(), divide(water.getCn(), K)), W));
        fixed.setCnzfyTwo(divide(multiply(price.getCndj(), divide(water.getCnTwo(), K)), W));
        fixed.setGmsjfhyzfy(divide(multiply(price.getGmsjfhydj(), divide(water.getGmsjfhy(), K)), W));
        fixed.setPamwnzfy(divide(multiply(price.getPamWndj(), water.getPamWy()), W));
        fixed.setBcszfy(divide(multiply(price.getBcsdj(), water.getBcs()), W));
        fixed.setDldfOne(divide(multiply(price.getDlddjOne(), water.getDldlOne()), W));
        fixed.setDldfTwo(divide(multiply(price.getDlddjTwo(), water.getDldlTwo()), W));
        fixed.setDldfTotal(add(fixed.getDldfOne(), fixed.getDldfTwo()));
//        fixed.setWnzyf(divide(multiply(price.getWnzydj(), water.getWnzl()), TEN));
        fixed.setWnzyf(divide(multiply(price.getWnzydj(), multiply(water.getWnzl(), K)), W));
        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.setYsf(multiply(water.getZslHqsk(), price.getYsfdj()));
        fixed.setSzysfOne(multiply(water.getZslOne(), price.getSzysdj()));
        fixed.setSzysfTwo(multiply(water.getZslTwo(), price.getSzysdj()));
        fixed.setSzysfTotal(add(fixed.getSzysfOne(), fixed.getSzysfTwo()));

        fixed.setZzsclfyOne(add(fixed.getOtherOneZfy(), add(fixed.getOtherzfy(), add(add(fixed.getPaczfyOne(), fixed.getSyzfyOne()), add(fixed.getBcszfy(), fixed.getCnzfy())))));
        fixed.setZzsclfyTwo(add(fixed.getOtherTwoZfy(), add(fixed.getCnzfyTwo(), 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.setUpDate(new Date());

        return fixed;
    }

    public static Costrlfixed calExpense(Costrlfixed fixed, Costrlprice price, Costrlwater water) {

        fixed.setOtherzfy(divide(multiply(price.getOtherdj(), divide(water.getOther(), K)), W));
        fixed.setOtherOneZfy(divide(multiply(price.getOtherOneDj(), divide(water.getOtherOne(), K)), W));
        fixed.setOtherTwoZfy(divide(multiply(price.getOtherTwoDj(), divide(water.getOtherTwo(), K)), W));
        fixed.setPaczfyOne(divide(multiply(price.getPacdj(), divide(water.getPacOne(), K)), W));
        fixed.setPaczfyTwo(divide(multiply(price.getPacdj(), divide(water.getPacTwo(), K)), W));
        fixed.setSyzfyOne(divide(multiply(price.getSydj(), divide(water.getSyOne(), K)), W));
        fixed.setYlzfyTwo(divide(multiply(price.getYldj(), divide(water.getYlTwo(), K)), W));
        fixed.setPamzszfy(divide(multiply(price.getPamZsdj(), water.getPam()), W));
        fixed.setFtzfy(divide(multiply(price.getFtdj(), divide(water.getFt(), K)), W));
        fixed.setCnzfy(divide(multiply(price.getCndj(), divide(water.getCn(), K)), W));
        fixed.setCnzfy(divide(multiply(price.getCndj(), divide(water.getCnTwo(), K)), W));
        fixed.setGmsjfhyzfy(divide(multiply(price.getGmsjfhydj(), divide(water.getGmsjfhy(), K)), W));
        fixed.setPamwnzfy(divide(multiply(price.getPamWndj(), water.getPamWy()), W));
        fixed.setBcszfy(divide(multiply(price.getBcsdj(), water.getBcs()), W));
        fixed.setDldfOne(divide(multiply(price.getDlddjOne(), water.getDldlOne()), W));
        fixed.setDldfTwo(divide(multiply(price.getDlddjTwo(), water.getDldlTwo()), W));
        fixed.setDldfTotal(add(fixed.getDldfOne(), fixed.getDldfTwo()));
//        fixed.setWnzyf(divide(multiply(price.getWnzydj(), water.getWnzl()), TEN));
        fixed.setWnzyf(divide(multiply(price.getWnzydj(), multiply(water.getWnzl(), K)), W));
        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.setYsf(multiply(water.getZslHqsk(), price.getYsfdj()));
        fixed.setSzysfOne(multiply(water.getZslOne(), price.getSzysdj()));
        fixed.setSzysfTwo(multiply(water.getZslTwo(), price.getSzysdj()));
        fixed.setSzysfTotal(add(fixed.getSzysfOne(), fixed.getSzysfTwo()));

        fixed.setZzsclfyOne(add(fixed.getOtherOneZfy(), add(fixed.getOtherzfy(), add(add(fixed.getPaczfyOne(), fixed.getSyzfyOne()), add(fixed.getBcszfy(), fixed.getCnzfy())))));
        fixed.setZzsclfyTwo(add(fixed.getOtherTwoZfy(), add(fixed.getCnzfyTwo(), 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()));

        return fixed;
    }

    /**
     * 改动修改制水单变
     */
    public static Costbgfixed newCalFixedPlan(Costbgfixed fixed, Costbgwater water) {
        if (null != water && fixed != null) {
            fixed.setOthercb(divide(multiply(fixed.getOtherzfy(), K), water.getGslOne()));
            //一厂电费单位成本变动
            fixed.setDfcbOne(divide(multiply(add(fixed.getJbdfOne(), fixed.getDldfOne()), K), water.getGslOne()));
            fixed.setDfcbTwo(multiply(divide(add(fixed.getJbdfTwo(), fixed.getDldfTwo()), water.getGslTwo()), K));
            fixed.setDfcbTotal(divide(multiply(add(fixed.getJbdfTotal(), fixed.getDldfTotal()), K), water.getGslTotal()));
            fixed.setOtherOneCb(divide(multiply(fixed.getOtherOneZfy(), K), water.getGslOne()));
            //一厂制水材料单项成本
            fixed.setPaccbOne(divide(multiply(fixed.getPaczfyOne(), K), water.getGslOne()));
            fixed.setSycbOne(divide(multiply(fixed.getSyzfyOne(), K), water.getGslOne()));
            fixed.setCncbOne(divide(multiply(fixed.getCnzfy(), K), water.getGslOne()));
            fixed.setBcscbOne(divide(multiply(fixed.getBcszfy(), K), water.getGslOne()));
            //总制水材料成本一厂
            fixed.setZsclcbOne(multiply(divide(fixed.getZzsclfyOne(), water.getGslOne()), K));
            //二厂各项制水材料成本
            fixed.setPaccbTwo(divide(multiply(fixed.getPaczfyTwo(), K), water.getGslTwo()));
            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.setCncbTwo(divide(multiply(fixed.getCnzfyTwo(), K), water.getGslTwo()));
            fixed.setOtherTwoCb(divide(multiply(fixed.getOtherTwoZfy(), K), water.getGslTwo()));
            //二厂总制水材料成本
            fixed.setZsclcbTwo(multiply(divide(fixed.getZzsclfyTwo(), water.getGslTwo()), K));
            //总制水材料成本
            fixed.setZsclcbTotal(multiply(divide(add(fixed.getZzsclfyOne(), fixed.getZzsclfyTwo()), water.getGslTotal()), K));
            //原水费成本
//            fixed.setYsfcb(divide(multiply(fixed.getYsf(), water.getGslTotal()), K));
            fixed.setYsfcb(divide(multiply(fixed.getYsf(), W), multiply(water.getGslTotal(), TEN)));
            //水资源税费成本
            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.getGslOne()), K));
            fixed.setDwcbTwo(multiply(divide(fixed.getZfyTwo(), water.getGslTwo()), K));
            fixed.setDwcbTotal(multiply(divide(fixed.getZfy(), water.getGslTotal()), K));

            fixed.setUpdateTime(new Date());
        }
        return fixed;
    }

    public static Costrlfixed newCalFixed(Costrlfixed fixed, Costrlwater water) {
        fixed.setDldfTotal(add(fixed.getDldfOne(), fixed.getDldfTwo()));
        fixed.setJbdfTotal(add(fixed.getJbdfOne(), fixed.getJbdfTwo()));
        fixed.setSzysfTotal(add(fixed.getSzysfOne(), fixed.getSzysfTwo()));
        fixed.setZzsclfyOne(add(fixed.getOtherzfy(), add(add(fixed.getPaczfyOne(), fixed.getSyzfyOne()), add(fixed.getBcszfy(), fixed.getCnzfy()))));
        fixed.setZzsclfyTwo(add(fixed.getCnzfyTwo(), add(fixed.getPaczfyTwo(), add(fixed.getYlzfyTwo(), add(fixed.getPamzszfy(), add(fixed.getFtzfy(), add(fixed.getGmsjfhyzfy(), add(fixed.getWnzyf(), fixed.getPamwnzfy()))))))));
        fixed.setZfyOne(add(fixed.getJbdfOne(), add(fixed.getDldfOne(), add(fixed.getZzsclfyOne(), add(fixed.getYsf(), fixed.getSzysfOne())))));
        fixed.setZfyTwo(add(fixed.getJbdfTwo(), add(fixed.getDldfTwo(), add(fixed.getZzsclfyTwo(), fixed.getSzysfTwo()))));
        fixed.setZfy(add(fixed.getZfyOne(), fixed.getZfyTwo()));
        if (null != water) {
            //一厂电费单位成本变动
            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.setCncbTwo(multiply(divide(fixed.getCnzfyTwo(), 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(divide(multiply(fixed.getYsf(), water.getGslTotal()), K));
            fixed.setYsfcb(divide(multiply(fixed.getYsf(), W), multiply(water.getGslTotal(), TEN)));
            //水资源税费成本
            fixed.setSzysfcbOne(multiply(divide(fixed.getSzysfOne(), water.getGslOne()), K));
            fixed.setSzysfcbTwo(multiply(divide(fixed.getSzysfTwo(), water.getGslTwo()), K));
            fixed.setSzysfcbTotal(multiply(divide(add(fixed.getSzysfOne(), fixed.getSzysfTwo()), water.getGslTotal()), K));

            fixed.setOthercb(divide(multiply(fixed.getOtherzfy(), K), water.getGslOne()));
            fixed.setOtherOneCb(divide(multiply(fixed.getOtherOneZfy(), K), water.getGslOne()));
            fixed.setOtherTwoCb(divide(multiply(fixed.getOtherTwoZfy(), K), water.getGslTwo()));

            //单位变动成本
            fixed.setDwcbOne(multiply(divide(fixed.getZfyOne(), water.getGslOne()), K));
            fixed.setDwcbTwo(multiply(divide(fixed.getZfyTwo(), water.getGslTwo()), K));
            fixed.setDwcbTotal(multiply(divide(fixed.getZfy(), water.getGslTotal()), K));
        }
        fixed.setUpdateTime(new Date());
        return fixed;
    }

    public static Double newCalUnitPlan(Costbgunit unit, Costbgwater water) {
        //（制水单位电耗（一厂）*制水量(一厂) + 制水单位电耗（二厂）*制水量(二厂) ）/ (制水量(一厂) +制水量(二厂))
        return divide(add(multiply(unit.getDhOne(), multiply(water == null ? null : water.getZslOne(), TEN)), multiply(unit.getDhTwo(), multiply(water == null ? null : water.getZslTwo(), TEN))), multiply(add(water == null ? null : water.getZslOne(), water == null ? null : water.getZslTwo()), TEN));
    }

    /**
     * 改动修改指标
     */
    public static Costbgindex newCalIndexPlan(Costbgwater water, Costbgunit unit) {
        Costbgindex index = new Costbgindex();

        index.setMonth(water.getMonth());

        index.setPacOne(multiply(unit.getPacdhOne(), multiply(water.getZslOne(), TEN)));
        index.setSyOne(multiply(unit.getSydhOne(), multiply(water.getZslOne(), TEN)));
        index.setDldlOne(multiply(unit.getDhOne(), multiply(water.getZslOne(), TEN)));

//        index.setOther(multiply(unit.getOtherdh(), multiply(water.getZslOne(), TEN)));
        index.setOtherOne(multiply(unit.getOtherOneDh(), multiply(water.getZslOne(), TEN)));
        index.setOtherTwo(multiply(unit.getOtherTwoDh(), multiply(water.getZslTwo(), TEN)));

        index.setPacTwo(multiply(unit.getPacdhTwo(), multiply(water.getZslTwo(), TEN)));
        index.setYlTwo(multiply(unit.getYldhTwo(), multiply(water.getZslTwo(), TEN)));
        index.setDldlTwo(multiply(unit.getDhTwo(), multiply(water.getZslTwo(), TEN)));
        index.setCnTwo(multiply(unit.getCndhTwo(), multiply(water.getZslTwo(), TEN)));

        index.setDldlTotal(add(index.getDldlOne(), index.getDldlTwo()));

        index.setUpdateTime(new Date());

        return index;
    }

    public static Costbgindex newCalIndexPlan(Costbgindex index, Costbgwater water, Costbgunit unit) {

        if (index != null && water != null && unit != null) {
            index.setPacOne(multiply(unit.getPacdhOne(), multiply(water.getZslOne(), TEN)));
            index.setSyOne(multiply(unit.getSydhOne(), multiply(water.getZslOne(), TEN)));
            index.setDldlOne(multiply(unit.getDhOne(), multiply(water.getZslOne(), TEN)));

            index.setOther(multiply(unit.getOtherdh(), multiply(water.getZslOne(), TEN)));
//            index.setOtherOne(multiply(unit.getOtherOneDh(), multiply(water.getZslOne(), TEN)));
//            index.setOtherTwo(multiply(unit.getOtherTwoDh(), multiply(water.getZslTwo(), TEN)));

            index.setPacTwo(multiply(unit.getPacdhTwo(), multiply(water.getZslTwo(), TEN)));
            index.setYlTwo(multiply(unit.getYldhTwo(), multiply(water.getZslTwo(), TEN)));
            index.setDldlTwo(multiply(unit.getDhTwo(), multiply(water.getZslTwo(), TEN)));
            index.setCnTwo(multiply(unit.getCndhTwo(), multiply(water.getZslTwo(), TEN)));

            index.setDldlTotal(add(index.getDldlOne(), index.getDldlTwo()));

            index.setUpdateTime(new Date());
        }
        return index;
    }

    public static Costrlunit newCalUnit(Costrlwater water) {
        Costrlunit unit = new Costrlunit();

        unit.setUpDate(water.getUpDate());
        unit.setMark(water.getMark());

        unit.setBcsdh(divide(water.getBcs(), multiply(water.getZslOne(), TEN)));
        unit.setCndh(divide(water.getCn(), multiply(water.getZslOne(), TEN)));
        unit.setCndhTwo(divide(water.getCnTwo(), 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.setFtdh(divide(water.getFt(), multiply(water.getZslTwo(), TEN)));
        unit.setGmsjfhydh(divide(water.getGmsjfhy(), multiply(water.getZslTwo(), TEN)));
        unit.setOtherdh(divide(water.getOther(), multiply(water.getZslOne(), TEN)));
        unit.setOtherOneDh(divide(water.getOtherOne(), multiply(water.getZslOne(), TEN)));
        unit.setOtherTwoDh(divide(water.getOtherTwo(), multiply(water.getZslTwo(), TEN)));
        unit.setPacdhOne(divide(water.getPacOne(), multiply(water.getZslOne(), TEN)));
        unit.setPacdhTwo(divide(water.getPacTwo(), multiply(water.getZslTwo(), TEN)));
        unit.setPamdh(divide(water.getPam(), multiply(water.getZslTwo(), TEN)));
        unit.setPamWydh(divide(water.getPamWy(), multiply(water.getZslTwo(), TEN)));
        unit.setSydhOne(divide(water.getSyOne(), multiply(water.getZslOne(), TEN)));
        unit.setYldhTwo(divide(water.getYlTwo(), multiply(water.getZslTwo(), TEN)));
        unit.setWnzldh(divide(water.getWnzl(), multiply(water.getZslTwo(), TEN)));

        unit.setUpdateTime(new Date());

        return unit;
    }

    public static Costrlunit newCalUnit(Costrlunit unit, Costrlwater water) {
        if (water != null) {
            unit.setBcsdh(divide(water.getBcs(), multiply(water.getZslOne(), TEN)));
            unit.setCndh(divide(water.getCn(), multiply(water.getZslOne(), TEN)));
            unit.setCndhTwo(divide(water.getCnTwo(), 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.setFtdh(divide(water.getFt(), multiply(water.getZslTwo(), TEN)));
            unit.setGmsjfhydh(divide(water.getGmsjfhy(), multiply(water.getZslTwo(), TEN)));
            unit.setOtherdh(divide(water.getOther(), multiply(water.getZslOne(), TEN)));
            unit.setOtherOneDh(divide(water.getOtherOne(), multiply(water.getZslOne(), TEN)));
            unit.setOtherTwoDh(divide(water.getOtherTwo(), multiply(water.getZslTwo(), TEN)));
            unit.setPacdhOne(divide(water.getPacOne(), multiply(water.getZslOne(), TEN)));
            unit.setPacdhTwo(divide(water.getPacTwo(), multiply(water.getZslTwo(), TEN)));
            unit.setPamdh(divide(water.getPam(), multiply(water.getZslTwo(), TEN)));
            unit.setPamWydh(divide(water.getPamWy(), multiply(water.getZslTwo(), TEN)));
            unit.setSydhOne(divide(water.getSyOne(), multiply(water.getZslOne(), TEN)));
            unit.setYldhTwo(divide(water.getYlTwo(), multiply(water.getZslTwo(), TEN)));
            unit.setWnzldh(divide(water.getWnzl(), multiply(water.getZslTwo(), TEN)));
        }
        unit.setUpdateTime(new Date());

        return unit;
    }

    /**
     * 计算预算单变
     *
     * @param fixed 单变
     * @param index 指标
     * @param price 单价
     * @param water 水量
     * @return fixed
     */
    public static Costbgfixed calFixedPlan(Costbgfixed fixed, Costbgindex index, Costbgprice price, Costbgwater water) {
        if (fixed != null && price != null && index != null) {
            fixed.setOtherzfy(divide(multiply(price.getOtherdj(), divide(index.getOther(), K)), W));
            fixed.setOtherOneZfy(divide(multiply(price.getOtherOneDj(), divide(index.getOtherOne(), K)), W));
            fixed.setOtherTwoZfy(divide(multiply(price.getOtherTwoDj(), divide(index.getOtherTwo(), K)), W));
            fixed.setPaczfyOne(divide(multiply(price.getPacdj(), divide(index.getPacOne(), K)), W));
            fixed.setPaczfyTwo(divide(multiply(price.getPacdj(), divide(index.getPacTwo(), K)), W));
            fixed.setSyzfyOne(divide(multiply(price.getSydj(), divide(index.getSyOne(), K)), W));
            fixed.setYlzfyTwo(divide(multiply(price.getYldj(), divide(index.getYlTwo(), K)), W));
            fixed.setPamzszfy(divide(multiply(price.getPamZsdj(), index.getPam()), W));
            fixed.setFtzfy(divide(multiply(price.getFtdj(), divide(index.getFt(), K)), W));
            fixed.setCnzfy(divide(multiply(price.getCndj(), divide(index.getCn(), K)), W));
            fixed.setCnzfyTwo(divide(multiply(price.getCndj(), divide(index.getCnTwo(), K)), W));
            fixed.setGmsjfhyzfy(divide(multiply(price.getGmsjfhydj(), divide(index.getGmsjfhy(), K)), W));
            fixed.setPamwnzfy(divide(multiply(price.getPamWndj(), index.getPamWn()), W));
            fixed.setBcszfy(divide(multiply(price.getBcsdj(), index.getBcs()), W));
            fixed.setDldfOne(divide(multiply(price.getDlddjOne(), index.getDldlOne()), W));
            fixed.setDldfTwo(divide(multiply(price.getDlddjTwo(), index.getDldlTwo()), W));
            fixed.setDldfTotal(add(fixed.getDldfOne(), fixed.getDldfTwo()));
            fixed.setJbdfTotal(add(fixed.getJbdfOne(), fixed.getJbdfTwo()));
//            fixed.setWnzyf(divide(multiply(price.getWnzydj(), index.getWnzl()), TEN));
            fixed.setWnzyf(divide(multiply(price.getWnzydj(), multiply(index.getWnzl(), K)), W));
            if (null != water) {
                fixed.setYsf(multiply(water.getZslHqsk(), price.getYsfdj()));
                fixed.setSzysfOne(multiply(water.getZslOne(), price.getSzysdj()));
                fixed.setSzysfTwo(multiply(water.getZslTwo(), price.getSzysdj()));
                fixed.setSzysfTotal(multiply(water.getZslTotal(), price.getSzysdj()));
            }
            fixed.setZzsclfyOne(add(fixed.getOtherOneZfy(), add(fixed.getOtherzfy(), add(add(fixed.getPaczfyOne(), fixed.getSyzfyOne()), add(fixed.getBcszfy(), fixed.getCnzfy())))));
            fixed.setZzsclfyTwo(add(fixed.getOtherTwoZfy(), add(fixed.getCnzfyTwo(), 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()));

            if (null != water) {
                fixed.setOthercb(divide(multiply(fixed.getOtherzfy(), K), water.getGslOne()));
                fixed.setOtherOneCb(divide(multiply(fixed.getOtherOneZfy(), K), water.getGslOne()));
                fixed.setOtherTwoCb(divide(multiply(fixed.getOtherTwoZfy(), K), water.getGslTwo()));
                //一厂电费单位成本变动
                fixed.setDfcbOne(divide(multiply(add(fixed.getJbdfOne(), fixed.getDldfOne()), K), water.getGslOne()));
                fixed.setDfcbTwo(multiply(divide(add(fixed.getJbdfTwo(), fixed.getDldfTwo()), water.getGslTwo()), K));
                fixed.setDfcbTotal(divide(multiply(add(fixed.getJbdfTotal(), fixed.getDldfTotal()), K), water.getGslTotal()));
                //一厂制水材料单项成本
                fixed.setPaccbOne(divide(multiply(fixed.getPaczfyOne(), K), water.getGslOne()));
                fixed.setSycbOne(divide(multiply(fixed.getSyzfyOne(), K), water.getGslOne()));
                fixed.setCncbOne(divide(multiply(fixed.getCnzfy(), K), water.getGslOne()));
                fixed.setBcscbOne(divide(multiply(fixed.getBcszfy(), K), water.getGslOne()));
                //总制水材料成本一厂
                fixed.setZsclcbOne(multiply(divide(fixed.getZzsclfyOne(), water.getGslOne()), K));
                fixed.setZsclcbOne(multiply(divide(fixed.getZzsclfyOne(), water.getGslOne()), K));
                //二厂各项制水材料成本
                fixed.setPaccbTwo(divide(multiply(fixed.getPaczfyTwo(), K), water.getGslTwo()));
                fixed.setCncbTwo(divide(multiply(fixed.getCnzfyTwo(), K), water.getGslTwo()));
                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(divide(multiply(fixed.getYsf(), water.getGslTotal()), K));
                fixed.setYsfcb(divide(multiply(fixed.getYsf(), W), multiply(water.getGslTotal(), TEN)));
                //水资源税费成本
                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.getGslOne()), K));
                fixed.setDwcbTwo(multiply(divide(fixed.getZfyTwo(), water.getGslTwo()), K));
                fixed.setDwcbTotal(multiply(divide(fixed.getZfy(), water.getGslTotal()), K));
            }

            fixed.setUpdateTime(new Date());
        }

        return fixed;
    }

    /**
     * 计算实际制水指标
     *
     * @param tbg 指标信息
     * @return Costrlwater
     */
    public static Costrlwater calWater(Costrlwater tbg) {

        Double zysllOne = divide(subtract(tbg.getZslOne(), tbg.getGslOne()), tbg.getZslOne());
        Double zysllTwo = divide(subtract(tbg.getZslTwo(), tbg.getGslTwo()), tbg.getZslTwo());


        //总供水量
        tbg.setGslTotal(add(tbg.getGslOne(), tbg.getGslTwo()));
        //总制水量
        tbg.setZslTotal(add(tbg.getZslOne(), tbg.getZslTwo()));

        tbg.setJbdlTotal(add(tbg.getJbdlOne(), tbg.getJbdlTwo()));
        tbg.setDldlTotal(add(tbg.getDldlOne(), tbg.getDldlTwo()));
        //自用水量
        tbg.setZyslOne(subtract(tbg.getZslOne(), tbg.getGslOne()));
        tbg.setZyslTwo(subtract(tbg.getZslTwo(), tbg.getGslTwo()));
        tbg.setZyslTotal(subtract(tbg.getZslTotal(), tbg.getGslTotal()));
        //自用水率
        tbg.setZysllOne(zysllOne == null ? null : zysllOne * 100);
        tbg.setZysllTwo(zysllTwo == null ? null : zysllTwo * 100);

        Double zysllTotal = divide(subtract(tbg.getZslTotal(), tbg.getGslTotal()), tbg.getZslTotal());

        tbg.setZysllTotal(zysllTotal == null ? null : zysllTotal * 100);

        Double cxc = divide(subtract(add(tbg.getGslTotal(), tbg.getGslQbj()), tbg.getSslTotal()), add(tbg.getGslTotal(), tbg.getGslQbj()));
        Double lsl = divide(subtract(add(tbg.getGslTotal(), tbg.getGslQbj()), tbg.getSslTotal(), tbg.getWspsl()), add(tbg.getGslTotal(), tbg.getGslQbj()));
        //漏损率
        tbg.setLsl(lsl == null ? null : lsl * 100);
        //产销差
        tbg.setCxc(cxc == null ? null : cxc * 100);

        tbg.setUpdateTime(new Date());

        return tbg;
    }

    /**
     * 计算实际单变
     */
    public static Costrlfixed countFixed(Costrlfixed fixed, Costrlprice price, Costrlwater water) {


        if (null != water) {
            if (null != price) {
                //动力电量
                fixed.setDldfOne(judge(isNull(water.getDldlOne()) * isNull(price.getDlddjOne())));
                fixed.setDldfTwo(judge(isNull(water.getDldlTwo()) * isNull(price.getDlddjTwo())));
                fixed.setDldfTotal(fixed.getDldfOne() + fixed.getDldfTwo());

                //总污泥转运费
//                fixed.setWnzyf(judge(isNull(water.getWnzl()) * isNull(price.getWnzydj())));
                fixed.setWnzyf(divide(multiply(price.getWnzydj(), multiply(water.getWnzl(), K)), W));
            }
            //原水费
            fixed.setYsf(judge(isNull(water.getZslHqsk()) * 0.24));
            //水资源税费
            fixed.setSzysfOne(judge(isNull(water.getZslOne()) * 0.088));
            fixed.setSzysfOne(judge(isNull(water.getZslTwo()) * 0.088));
            fixed.setSzysfTotal(judge(isNull(water.getZslTotal()) * 0.088));
            //电费成本
            fixed.setDfcbOne(judge((fixed.getJbdfOne() + fixed.getDldfOne()) / isNull(water.getGslOne())));
            fixed.setDfcbTwo(multiply(divide(add(fixed.getJbdfTwo(), fixed.getDldfTwo()), water.getGslTwo()), K));
            fixed.setDfcbTotal(judge((fixed.getJbdfTotal() + fixed.getDldfTotal()) / isNull(water.getGslTotal())));
            //一厂制水材料各单项成本
            fixed.setPaccbOne(judge(isNull(fixed.getPaczfyOne()) / isNull(water.getGslOne())));
            fixed.setSycbOne(judge(isNull(fixed.getSyzfyOne()) / isNull(water.getGslOne())));
            fixed.setCncbOne(judge(isNull(fixed.getCnzfy()) / isNull(water.getGslOne())));
            fixed.setBcscbOne(judge(isNull(fixed.getBcszfy()) / isNull(water.getGslOne())));

            //二厂制水材料各单项成本
            fixed.setPaccbTwo(judge(isNull(fixed.getPaczfyTwo()) / isNull(water.getGslTwo())));
            fixed.setYlcbTwo(judge(isNull(fixed.getYlzfyTwo()) / isNull(water.getGslTwo())));
            fixed.setPamzscbTwo(judge(isNull(fixed.getPamzszfy()) / isNull(water.getGslTwo())));
            fixed.setFtcbTwo(judge(isNull(fixed.getFtzfy()) / isNull(water.getGslTwo())));
            fixed.setGmsjfhycbTwo(judge(isNull(fixed.getGmsjfhyzfy()) / isNull(water.getGslTwo())));
            fixed.setPamwncbTwo(judge(isNull(fixed.getPamwnzfy()) / isNull(water.getGslTwo())));
            fixed.setWnzycbTwo(judge(isNull(fixed.getWnzyf()) / isNull(water.getGslTwo())));

            //总制水材料成本
            fixed.setZsclcbOne(judge(isNull(fixed.getZzsclfyOne()) / isNull(water.getGslOne())));
            fixed.setZsclcbTwo(judge(isNull(fixed.getZzsclfyTwo()) / isNull(water.getGslTwo())));
            fixed.setZsclcbTotal(judge((isNull(fixed.getZzsclfyOne()) + isNull(fixed.getZzsclfyTwo())) / (isNull(water.getGslOne()) + isNull(water.getGslTwo()))));
            //原水费成本
            fixed.setYsfcb(judge(isNull(fixed.getYsf()) / (isNull(water.getGslOne()) + isNull(water.getGslTwo()))));
            //水资源税费成本
            fixed.setSzysfcbOne(judge(isNull(fixed.getSzysfOne()) / isNull(water.getGslOne())));
            fixed.setSzysfcbTwo(judge(isNull(fixed.getSzysfTwo()) / isNull(water.getGslTwo())));
            fixed.setSzysfcbTotal(judge((isNull(fixed.getSzysfOne()) + isNull(fixed.getSzysfTwo())) / (isNull(water.getGslOne()) + isNull(water.getGslTwo()))));
            //单位变动成本
            fixed.setDwcbOne(multiply(divide(fixed.getZfyOne(), water.getGslOne()), K));
            fixed.setDwcbTotal(multiply(divide(fixed.getZfyTwo(), water.getGslTwo()), K));
            fixed.setDwcbTotal(judge(isNull(fixed.getZfy()) / (isNull(water.getGslTwo()) + isNull(water.getGslOne()))));
        }


        //总制水材料费用
        fixed.setZzsclfyOne(add(fixed.getOtherzfy(), add(add(fixed.getPaczfyOne(), fixed.getSyzfyOne()), add(fixed.getBcszfy(), fixed.getCnzfy()))));
        fixed.setZzsclfyTwo(fixed.getPaczfyOne() + fixed.getYlzfyTwo() + fixed.getPamzszfy() + fixed.getFtzfy() + fixed.getGmsjfhyzfy() + fixed.getPamwnzfy() + fixed.getWnzyf());
        //总费用
        fixed.setZfyOne(fixed.getJbdfOne() + fixed.getDldfOne() + fixed.getZzsclfyOne() + fixed.getYsf() + fixed.getSzysfOne());
        fixed.setZfyTwo(fixed.getJbdfTwo() + fixed.getDldfTwo() + fixed.getZzsclfyTwo() + fixed.getSzysfTwo());
        fixed.setZfy(fixed.getZfyOne() + fixed.getZfyTwo());

        return fixed;
    }


    /**
     * 计算预算水量
     *
     * @param tbg tbg
     * @return Costbgwater
     */
    public static Costbgwater calWaterPlan(Costbgwater tbg) {
        Double zysllOne = divide(subtract(tbg.getZslOne(), tbg.getGslOne()), tbg.getZslOne());
        Double zysllTwo = divide(subtract(tbg.getZslTwo(), tbg.getGslTwo()), tbg.getZslTwo());


        //总供水量
        tbg.setGslTotal(add(tbg.getGslOne(), tbg.getGslTwo()));
        //总制水量
        tbg.setZslTotal(add(tbg.getZslOne(), tbg.getZslTwo()));
        //自用水量
        tbg.setZyslOne(subtract(tbg.getZslOne(), tbg.getGslOne()));
        tbg.setZyslTwo(subtract(tbg.getZslTwo(), tbg.getGslTwo()));
        tbg.setZyslTotal(subtract(tbg.getZslTotal(), tbg.getGslTotal()));
        //自用水率
        tbg.setZysllOne(zysllOne == null ? null : zysllOne * 100);
        tbg.setZysllTwo(zysllTwo == null ? null : zysllTwo * 100);

        Double zysllTotal = divide(subtract(tbg.getZslTotal(), tbg.getGslTotal()), tbg.getZslTotal());

        tbg.setZysllTotal(zysllTotal == null ? null : zysllTotal * 100);

        Double gsl = add(tbg.getGslTotal(), tbg.getGslQbj());

        Double cxc = divide(subtract(gsl, tbg.getSslTotal()), gsl);
        Double lsl = divide(subtract(gsl, tbg.getSslTotal(), tbg.getWspsl()), gsl);
        //漏损率
        tbg.setLsl(lsl == null ? null : lsl * 100);
        //产销差
        tbg.setCxc(cxc == null ? null : cxc * 100);

        tbg.setUpdateTime(new Date());

        return tbg;
    }


    /**
     * 计算完成率
     *
     * @param m1 实际值
     * @param m2 计划值
     * @return MarkWaterVo
     */
    public static MarkWaterVo calCompletionRate(MarkWaterVo m1, MarkWaterVo m2) {

        if (null == m1 || null == m2) {
            return null;
        }
        MarkWaterVo water = new MarkWaterVo();

        water.setGsl(calDivisor(m1.getGsl(), m2.getGsl()));
        water.setZsl(calDivisor(m1.getZsl(), m2.getZsl()));
        water.setZysl(calDivisor(m1.getZysl(), m2.getZysl()));
        water.setZysll(calDivisor(m1.getZysll(), m2.getZysll()));
        water.setPacdh(calDivisor(m1.getPacdh(), m2.getPacdh()));
        water.setSydh(calDivisor(m1.getSydh(), m2.getSydh()));
        water.setYldh(calDivisor(m1.getYldh(), m2.getYldh()));
        water.setDh(calDivisor(m1.getDh(), m2.getDh()));
        water.setPac(calDivisor(m1.getPac(), m2.getPac()));
        water.setSy(calDivisor(m1.getSy(), m2.getSy()));
        water.setYl(calDivisor(m1.getYl(), m2.getYl()));
        water.setPam(calDivisor(m1.getPam(), m2.getPam()));
        water.setFt(calDivisor(m1.getFt(), m2.getFt()));
        water.setCn(calDivisor(m1.getCn(), m2.getCn()));
        water.setGmsj(calDivisor(m1.getGmsj(), m2.getGmsj()));
        water.setPamwn(calDivisor(m1.getPamwn(), m2.getPamwn()));
        water.setBcs(calDivisor(m1.getBcs(), m2.getBcs()));
        water.setWnzl(calDivisor(m1.getWnzl(), m2.getWnzl()));
        water.setDldl(calDivisor(m1.getDldl(), m2.getDldl()));
        water.setOther(calDivisor(m1.getOther(), m2.getOther()));
        water.setOtherdh(calDivisor(m1.getOtherdh(), m2.getOtherdh()));
        water.setOtherOne(calDivisor(m1.getOtherOne(), m2.getOtherOne()));
        water.setOtherOneDh(calDivisor(m1.getOtherOneDh(), m2.getOtherOneDh()));
        water.setOtherTwo(calDivisor(m1.getOtherTwo(), m2.getOtherTwo()));
        water.setOtherTwoDh(calDivisor(m1.getOtherTwoDh(), m2.getOtherTwoDh()));
        water.setCnDh(calDivisor(m1.getCnDh(), m2.getCnDh()));
        return water;
    }

    public static Costbgwater newCalTbgWater(Costbgwater tbg) {

        if (tbg != null) {
            Double zysllOne = divide(subtract(tbg.getZslOne(), tbg.getGslOne()), tbg.getZslOne());
            Double zysllTwo = divide(subtract(tbg.getZslTwo(), tbg.getGslTwo()), tbg.getZslTwo());

            //总供水量
            tbg.setGslTotal(add(tbg.getGslOne(), tbg.getGslTwo()));
            //总制水量
            tbg.setZslTotal(add(tbg.getZslOne(), tbg.getZslTwo()));
            //自用水量
            tbg.setZyslOne(subtract(tbg.getZslOne(), tbg.getGslOne()));
            tbg.setZyslTwo(subtract(tbg.getZslTwo(), tbg.getGslTwo()));
            tbg.setZyslTotal(subtract(tbg.getZslTotal(), tbg.getGslTotal()));
            //自用水率
            tbg.setZysllOne(zysllOne == null ? null : zysllOne * 100);
            tbg.setZysllTwo(zysllTwo == null ? null : zysllTwo * 100);

            Double zysllTotal = divide(subtract(tbg.getZslTotal(), tbg.getGslTotal()), tbg.getZslTotal());

            tbg.setZysllTotal(zysllTotal == null ? null : zysllTotal * 100);

            Double cxc = divide(subtract(add(tbg.getGslTotal(), tbg.getGslQbj()), tbg.getSslTotal()), add(tbg.getGslTotal(), tbg.getGslQbj()));
            Double lsl = divide(subtract(add(tbg.getGslTotal(), tbg.getGslQbj()), tbg.getSslTotal(), tbg.getWspsl()), add(tbg.getGslTotal(), tbg.getGslQbj()));
            //漏损率
            tbg.setLsl(lsl == null ? null : lsl * 100);
            //产销差
            tbg.setCxc(cxc == null ? null : cxc * 100);

            tbg.setUpdateTime(new Date());
        }
        return tbg;
    }


    /**
     * 计算完成率
     *
     * @param c1 实际值
     * @param c2 计划值
     * @return MarkWaterVo
     */
    public static CostVo calCompletionRate(CostVo c1, CostVo c2) {

        if (null == c1 || null == c2) {
            return null;
        }

        CostVo cost = new CostVo();

        cost.setPacfy(calDivisor(c1.getPacfy(), c2.getPacfy()));
        cost.setSyfy(calDivisor(c1.getSyfy(), c2.getSyfy()));
        cost.setYlfy(calDivisor(c1.getYlfy(), c2.getYlfy()));
        cost.setPamzs(calDivisor(c1.getPamzs(), c2.getPamzs()));
        cost.setFtfy(calDivisor(c1.getFtfy(), c2.getFtfy()));
        cost.setCnfy(calDivisor(c1.getCnfy(), c2.getCnfy()));
        cost.setGmsjfy(calDivisor(c1.getGmsjfy(), c2.getGmsjfy()));
        cost.setPamwn(calDivisor(c1.getPamwn(), c2.getPamwn()));
        cost.setBcsfy(calDivisor(c1.getBcsfy(), c2.getBcsfy()));
        cost.setWnzyfy(calDivisor(c1.getWnzyfy(), c2.getWnzyfy()));
        cost.setWnzyfy(calDivisor(c1.getWnzyfy(), c2.getWnzyfy()));
        cost.setJbdf(calDivisor(c1.getJbdf(), c2.getJbdf()));
        cost.setDldf(calDivisor(c1.getDldf(), c2.getDldf()));
        cost.setYsf(calDivisor(c1.getYsf(), c2.getYsf()));
        cost.setSzysf(calDivisor(c1.getSzysf(), c2.getSzysf()));
        cost.setZsclzfy(calDivisor(c1.getZsclzfy(), c2.getZsclzfy()));
        cost.setZfy(calDivisor(c1.getZfy(), c2.getZfy()));
        cost.setDfcb(calDivisor(c1.getDfcb(), c2.getDfcb()));
        cost.setSydj(calDivisor(c1.getSydj(), c2.getSydj()));
        cost.setYldj(calDivisor(c1.getYldj(), c2.getYldj()));
        cost.setPamzsdj(calDivisor(c1.getPamzsdj(), c2.getPamzsdj()));
        cost.setGmsjdj(calDivisor(c1.getGmsjdj(), c2.getGmsjdj()));
        cost.setCndj(calDivisor(c1.getCndj(), c2.getCndj()));
        cost.setFtdj(calDivisor(c1.getFtdj(), c2.getFtdj()));
        cost.setPamwndj(calDivisor(c1.getPamwndj(), c2.getPamwndj()));
        cost.setWnzydj(calDivisor(c1.getWnzydj(), c2.getWnzydj()));
        cost.setBcsdj(calDivisor(c1.getBcsdj(), c2.getBcsdj()));
        cost.setZzsclcb(calDivisor(c1.getZzsclcb(), c2.getZzsclcb()));
        cost.setYsfcb(calDivisor(c1.getYsfcb(), c2.getYsfcb()));
        cost.setSzysfcb(calDivisor(c1.getSzysfcb(), c2.getSzysfcb()));
        cost.setDwbdcb(calDivisor(c1.getDwbdcb(), c2.getDwbdcb()));
        cost.setOtherdj(calDivisor(c1.getOtherdj(), c2.getOtherdj()));
        cost.setOtherzfy(calDivisor(c1.getOtherzfy(), c2.getOtherzfy()));
        cost.setOthercb(calDivisor(c1.getOthercb(), c2.getOthercb()));
        cost.setOtherOneDj(calDivisor(c1.getOtherOneDj(), c2.getOtherOneDj()));
        cost.setOtherOneZfy(calDivisor(c1.getOtherOneZfy(), c2.getOtherOneZfy()));
        cost.setOtherOneCb(calDivisor(c1.getOtherOneCb(), c2.getOtherOneCb()));
        cost.setOtherTwoDj(calDivisor(c1.getOtherTwoDj(), c2.getOtherTwoDj()));
        cost.setOtherTwoZfy(calDivisor(c1.getOtherTwoZfy(), c2.getOtherTwoZfy()));
        cost.setOtherTwoCb(calDivisor(c1.getOtherTwoCb(), c2.getOtherTwoCb()));
        return cost;
    }


    /**
     * 判断数据的类型
     *
     * @param mathematical 算式或值
     * @return 0 或 值
     */
    public static Double judge(Double mathematical) {
        double value;
        if (Double.isNaN(mathematical) || Double.isInfinite(mathematical)) {
            value = 0.0;
        } else {
            value = mathematical;
        }
        return value;
    }

    /**
     * 判断参数为空
     */
    public static Double isNull(Double param) {
        return null == param ? 0 : param;
    }

    /**
     * list 输出 page
     *
     * @param page     page
     * @param pageList list
     * @return page
     */
    public static Page listToPage(Page page, List pageList) {
        // 当前页第一条数据在List中的位置
        int start = (int) ((page.getCurrent() - 1) * page.getSize());
        // 当前页最后一条数据在List中的位置
        int end = (int) ((start + page.getSize()) > pageList.size() ? pageList.size() : (page.getSize() * page.getCurrent()));
        page.setRecords(new ArrayList<>());
        if (page.getSize() * (page.getCurrent() - 1) <= page.getTotal()) {
            // 分隔列表 当前页存在数据时 设置
            page.setRecords(pageList.subList(start, end));
        }
        page.setTotal(pageList.size());
        return page;
    }

    /**
     * 两数相除保留两位小数（百分比）
     *
     * @param d1 被除数
     * @param d2 除数
     * @return double
     */
    public static Double calDivisor(Double d1, Double d2) {
        if (paramIsNull(d1, d2) && d2 != 0) {
            return new BigDecimal(d1.toString()).divide(new BigDecimal(d2.toString()), 4).multiply(new BigDecimal("100")).doubleValue();
        } else {
            return null;
        }
    }


    public static boolean paramIsNull(Double dou1, Double dou2) {
        return null != dou1 && null != dou2;
    }

    public static boolean paramIsNull(Double dou1, Double dou2, Double dou3) {
        return null != dou1 && null != dou2 && null != dou3;
    }

    public static Double multiply(Double dou1, Double dou2) {
        if (paramIsNull(dou1, dou2)) {
            return new BigDecimal(dou1.toString()).multiply(new BigDecimal(dou2.toString())).doubleValue();
        } else {
            return null;
        }
    }

    public static Double divide(Double dou1, Double dou2) {
        if (paramIsNull(dou1, dou2) && dou2 != 0) {
            //return new BigDecimal(dou1.toString()).divide(new BigDecimal(dou2.toString()), BigDecimal.ROUND_DOWN).doubleValue();
            return dou1 / dou2;
        } else {
            return null;
        }
    }


    public static Double add(Double dou1, Double dou2) {
        if (paramIsNull(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 (paramIsNull(dou1, dou2)) {
            return new BigDecimal(dou1.toString()).subtract(new BigDecimal(dou2.toString())).doubleValue();
        } else {
            return null;
        }
    }

    public static Double subtract(Double dou1, Double dou2, Double dou3) {
        if (paramIsNull(dou1, dou2, dou3)) {
            return new BigDecimal(dou1.toString()).subtract(new BigDecimal(dou2.toString())).subtract(new BigDecimal(dou3.toString())).doubleValue();
        } else {
            return null;
        }
    }
}
