package com.njcn.event.pojo.vo;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.Collator;
import java.util.Comparator;
import java.util.Locale;

/**
 * 区域统计
 *
 * @author : zhaojun
 * @version : 1.0.0
 * @date : 2022年07月08日 8:55
 */
@Data
public class AreaCalculationVO implements Serializable {
    
    private static final long serialVersionUID = 1289723908309235565L;
    
    @ApiModelProperty(name = "areaName", value = "区域名称")
    private String areaName;
    
    @ApiModelProperty(name = "monitoringPoints", value = "监测点数")
    private Integer monitoringPoints;
    
    @ApiModelProperty(name = "frequency", value = "暂降次数")
    private Long frequency;
    
    @ApiModelProperty(name = "sarfi90", value = "SARFI-90")
    private Double sarfi9;
    
    /**
     * 计算SARFI-90数值
     */
    public void computeSarfi90() {
        BigDecimal b1 = new BigDecimal(frequency);
        BigDecimal b2 = new BigDecimal(monitoringPoints);
        if (b1.compareTo(BigDecimal.ZERO) == 0) {
            this.sarfi9 = 0.00D;
            return;
        }
        this.sarfi9 = b1.divide(b2, 2, RoundingMode.HALF_UP).doubleValue();
    }
    
    public static Comparator<AreaCalculationVO> sortAscAreaName() {
        return (o1, o2) -> {
            Collator collator = Collator.getInstance(Locale.CHINA);
            return collator.compare(o1.getAreaName(), o2.getAreaName());
        };
    }
    
}
