package com.jjt.biz.vo;

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

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.util.Random;

/**
 * 生产趋势视图
 *
 * @author ruoyi
 * @date 2024-12-30
 */
@ApiModel(value = "YrProdEfficiencyVO", description = "印染生产效率")
@Data
@NoArgsConstructor
public class YrProdEfficiencyVO {
    @ApiModelProperty("产线,如果为0就表示全部")
    private Integer line;
    @ApiModelProperty("产线开机数")
    private Integer open;
    @ApiModelProperty("产线总设备数")
    private Integer total;
    @ApiModelProperty("单位能耗")
    private BigDecimal energy;
    @ApiModelProperty("开机率")
    private BigDecimal ratio;
    @ApiModelProperty("米长")
    private BigDecimal length;
    @ApiModelProperty("重量")
    private BigDecimal weight;
    @ApiModelProperty("A班开机时间")
    private BigDecimal timeA;
    @ApiModelProperty("B班开机时间")
    private BigDecimal timeB;
    @ApiModelProperty("A班米长")
    private BigDecimal lengthA;
    @ApiModelProperty("B班米长")
    private BigDecimal lengthB;
    @ApiModelProperty("A班重量")
    private BigDecimal weightA;
    @ApiModelProperty("B班重量")
    private BigDecimal weightB;
    @ApiModelProperty("A班稼动率")
    private BigDecimal effA;
    @ApiModelProperty("B班稼动率")
    private BigDecimal effB;

    public YrProdEfficiencyVO(Integer line) {
        this.line = line;
        if (line == 0) {
            this.total = 267;
            this.open = 187;
            this.energy = BigDecimal.valueOf(2.6d);
            this.ratio = BigDecimal.valueOf(this.open * 100).divide(BigDecimal.valueOf(this.total), 2, RoundingMode.HALF_UP);
            this.lengthA = BigDecimal.ZERO;
            this.lengthB = BigDecimal.ZERO;
            this.timeA = BigDecimal.ZERO;
            this.timeB = BigDecimal.ZERO;
            this.effA = BigDecimal.ZERO;
            this.effB = BigDecimal.ZERO;
            this.weightA = BigDecimal.ZERO;
            this.weightB = BigDecimal.ZERO;
            this.length = BigDecimal.ZERO;
            this.weight = BigDecimal.ZERO;

        }
    }

    public void mock() {
        Integer[] total = {267, 38, 36, 35, 35, 30, 31, 32, 30};
        Integer[] open = {187, 28, 26, 25, 25, 20, 21, 22, 20};
        Random random = new Random();
        LocalDateTime ldt = LocalDateTime.now().plusHours(-7);
        this.total = total[line];
        this.open = open[line];
        this.energy = BigDecimal.valueOf(2.6d);
        this.ratio = BigDecimal.valueOf(this.open * 100).divide(BigDecimal.valueOf(this.total), 2, RoundingMode.HALF_UP);
        this.lengthA = BigDecimal.valueOf(5500 + 2000 * random.nextDouble()).multiply(BigDecimal.valueOf(ldt.getHour() / 12f)).setScale(2, RoundingMode.HALF_UP);
        this.weightA = lengthA.divide(BigDecimal.valueOf(1000), 2, RoundingMode.HALF_UP);
        int hour = ldt.getHour() + 1;
        if (hour > 12) {
            this.timeA = BigDecimal.valueOf(12).subtract(BigDecimal.valueOf(hour * 0.25 * random.nextFloat())).setScale(1, RoundingMode.HALF_UP);
            this.effA = timeA.divide(BigDecimal.valueOf(12), 4, RoundingMode.HALF_UP);
            this.lengthB = BigDecimal.valueOf(5500 + 2000 * random.nextDouble()).multiply(BigDecimal.valueOf((hour - 12) / 12f)).setScale(2, RoundingMode.HALF_UP);
            this.weightB = lengthB.divide(BigDecimal.valueOf(1000), 2, RoundingMode.HALF_UP);
            this.timeB = BigDecimal.valueOf(hour - 12).subtract(BigDecimal.valueOf((hour - 12) * 0.25 * random.nextFloat())).setScale(1, RoundingMode.HALF_UP);
            this.effB = timeB.divide(BigDecimal.valueOf(hour - 12), 4, RoundingMode.HALF_UP);
        } else {
            this.timeA = BigDecimal.valueOf(hour).subtract(BigDecimal.valueOf(hour * 0.25 * random.nextFloat())).setScale(1, RoundingMode.HALF_UP);
            this.effA = timeA.divide(BigDecimal.valueOf(hour), 4, RoundingMode.HALF_UP);
            this.timeB = BigDecimal.ZERO;
            this.lengthB = BigDecimal.ZERO;
            this.weightB = BigDecimal.ZERO;
            this.effB = BigDecimal.ZERO;
        }
        this.length = this.lengthA.add(this.lengthB);
        this.weight = this.weightA.add(this.weightB);
    }
}
