package com.tofly.feesapi.sfgl.entity.vo;

import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.tofly.feesapi.common.MoneySerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

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

@Data
@ApiModel("应收统计报表VO")
public class YstjbbVo {

    @ApiModelProperty(value = "财务日期")
    private String cwrq;

    @ApiModelProperty(value = "用水项目")
    private String ysxm;

    @ApiModelProperty(value = "水价")
    private BigDecimal sj;

    @ApiModelProperty(value = "水量")
    private BigDecimal sl;

    @ApiModelProperty(value = "水费")
    @JsonSerialize(using = MoneySerializer.class)
    private BigDecimal sf;

    @ApiModelProperty(value = "污水费")
    @JsonSerialize(using = MoneySerializer.class)
    private BigDecimal wsf;

    @ApiModelProperty(value = "水资源费")
    @JsonSerialize(using = MoneySerializer.class)
    private BigDecimal szyf;

    @ApiModelProperty(value = "二次加压费")
    @JsonSerialize(using = MoneySerializer.class)
    private BigDecimal ecjyf;

    @ApiModelProperty(value = "附加费")
    @JsonSerialize(using = MoneySerializer.class)
    private BigDecimal fjf;

    @ApiModelProperty(value = "其他费(消防栓费)")
    @JsonSerialize(using = MoneySerializer.class)
    private BigDecimal qtf;

    @ApiModelProperty(value = "合计")
    @JsonSerialize(using = MoneySerializer.class)
    private BigDecimal hj;

    public static YstjbbVo tjhj(List<YstjbbVo> xjhjlist, String ysxm) {
        YstjbbVo hj = new YstjbbVo();
        hj.setCwrq(StrUtil.EMPTY);
        hj.setYsxm(ysxm);
        hj.setSj(BigDecimal.ZERO);

        hj.setSl(xjhjlist.stream().filter(o -> ObjUtil.isNotNull(o.getSl()))
                .map(YstjbbVo::getSl).reduce(BigDecimal.ZERO, BigDecimal::add));
        hj.setSf(xjhjlist.stream().filter(o -> ObjUtil.isNotNull(o.getSf()))
                .map(YstjbbVo::getSf).reduce(BigDecimal.ZERO, BigDecimal::add));
        hj.setWsf(xjhjlist.stream().filter(o -> ObjUtil.isNotNull(o.getWsf()))
                .map(YstjbbVo::getWsf).reduce(BigDecimal.ZERO, BigDecimal::add));
        hj.setSzyf(xjhjlist.stream().filter(o -> ObjUtil.isNotNull(o.getSzyf()))
                .map(YstjbbVo::getSzyf).reduce(BigDecimal.ZERO, BigDecimal::add));
        hj.setEcjyf(xjhjlist.stream().filter(o -> ObjUtil.isNotNull(o.getEcjyf()))
                .map(YstjbbVo::getEcjyf).reduce(BigDecimal.ZERO, BigDecimal::add));
        hj.setFjf(xjhjlist.stream().filter(o -> ObjUtil.isNotNull(o.getFjf()))
                .map(YstjbbVo::getFjf).reduce(BigDecimal.ZERO, BigDecimal::add));
        hj.setQtf(xjhjlist.stream().filter(o -> ObjUtil.isNotNull(o.getQtf()))
                .map(YstjbbVo::getQtf).reduce(BigDecimal.ZERO, BigDecimal::add));
        hj.setHj(xjhjlist.stream().filter(o -> ObjUtil.isNotNull(o.getHj()))
                .map(YstjbbVo::getHj).reduce(BigDecimal.ZERO, BigDecimal::add));

        return hj;
    }

    public void mxhjjs() {
        this.hj = BigDecimal.ZERO;

        if (NumberUtil.isGreater(sf, BigDecimal.ZERO)) {
            this.hj = hj.add(sf);
        }
        if (NumberUtil.isGreater(wsf, BigDecimal.ZERO)) {
            hj = hj.add(wsf);
        }
        if (NumberUtil.isGreater(szyf, BigDecimal.ZERO)) {
            hj = hj.add(szyf);
        }
        if (NumberUtil.isGreater(ecjyf, BigDecimal.ZERO)) {
            hj = hj.add(ecjyf);
        }
        if (NumberUtil.isGreater(fjf, BigDecimal.ZERO)) {
            hj = hj.add(fjf);
        }
        if (NumberUtil.isGreater(qtf, BigDecimal.ZERO)) {
            hj = hj.add(qtf);
        }
    }

}
