package com.jjt.biz.vo;

import com.jjt.biz.domain.TwinDevice;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.poi.ss.usermodel.Cell;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Map;

/**
 * 平方米克重
 *
 * @author wukai
 * @date 2024/5/8 15:50
 */
@ApiModel(value = "GramMass", description = "平方米克重统计")
@Data
@NoArgsConstructor
public class GramMassDetail {
    @ApiModelProperty("设备信息")
    private String device;
    @ApiModelProperty("平方米克重")
    private Float gramMass;
    @ApiModelProperty("配方号")
    private Integer formula_data_1;
    @ApiModelProperty("机台号")
    private Integer formula_data_2;
    @ApiModelProperty("米克重")
    private Integer formula_data_3;
    @ApiModelProperty("L1、L5纱线规格D")
    private Integer formula_data_4;
    @ApiModelProperty("L2、L4纱线规格D")
    private Integer formula_data_5;
    @ApiModelProperty("L3纱线规格D")
    private Integer formula_data_6;
    @ApiModelProperty("L1、L5纱线规格F")
    private Integer formula_data_7;
    @ApiModelProperty("L2、L4纱线规格F")
    private Integer formula_data_8;
    @ApiModelProperty("L3纱线规格F")
    private Integer formula_data_9;
    @ApiModelProperty("L1、L5盘头根数")
    private Integer formula_data_10;
    @ApiModelProperty("L2、L4盘头根数")
    private Integer formula_data_11;
    @ApiModelProperty("L3盘头根数")
    private Integer formula_data_12;
    @ApiModelProperty("卷曲幅宽")
    private Float formula_data_13;
    @ApiModelProperty("下布长度")
    private Float formula_data_14;
    @ApiModelProperty("毛高")
    private Float formula_data_15;
    @ApiModelProperty("成品长")
    private Float formula_data_16;
    @ApiModelProperty("成品宽")
    private Float formula_data_17;
    @ApiModelProperty("成品重")
    private Float formula_data_18;
    @ApiModelProperty("GB1送经量")
    private String formula_data_19;
    @ApiModelProperty("GB2送经量")
    private String formula_data_20;
    @ApiModelProperty("GB3送经量")
    private String formula_data_21;
    @ApiModelProperty("GB4送经量")
    private String formula_data_22;
    @ApiModelProperty("GB5送经量")
    private String formula_data_23;
    @ApiModelProperty("牵拉密度")
    private Float formula_data_24;
    @ApiModelProperty("卷曲张力系数")
    private Float formula_data_25;

    public GramMassDetail(boolean isSmall, Map<String, Object> map) {
        TwinDevice twinDevice = (TwinDevice) map.get("device");
        this.device = twinDevice.getDeviceName();
        if (isSmall) {
            setSmall(map);
        } else {
            setBig(map);
        }

        //长
        BigDecimal length = BigDecimal.valueOf(this.formula_data_16);
        //宽
        BigDecimal width = BigDecimal.valueOf(this.formula_data_17);
        //面积
        BigDecimal area = length.multiply(width);
//       重量，单位kg，需要转换成克
        BigDecimal weight = BigDecimal.valueOf(this.formula_data_18 * 1000);
        //计算平方米克重 重量除以面积
        if (area.floatValue() != 0 && weight.floatValue() != 0) {
            this.gramMass = weight.divide(area, 2, RoundingMode.HALF_UP).floatValue();
        }else {
            this.gramMass = 0f;
        }
    }

    private void setSmall(Map<String, Object> map) {
        this.formula_data_1 = (int) map.get("Formula_data_1");
        this.formula_data_2 = (int) map.get("Formula_data_2");
        this.formula_data_3 = (int) map.get("Formula_data_3");
        this.formula_data_4 = (int) map.get("Formula_data_4");
        this.formula_data_5 = (int) map.get("Formula_data_5");
        this.formula_data_6 = (int) map.get("Formula_data_6");
        this.formula_data_7 = (int) map.get("Formula_data_7");
        this.formula_data_8 = (int) map.get("Formula_data_8");
        this.formula_data_9 = (int) map.get("Formula_data_9");
        this.formula_data_10 = (int) map.get("Formula_data_10");
        this.formula_data_11 = (int) map.get("Formula_data_11");
        this.formula_data_12 = (int) map.get("Formula_data_12");
        this.formula_data_13 = (float) map.get("Formula_data_13");
        this.formula_data_14 = (float) map.get("Formula_data_14");
        this.formula_data_15 = (float) map.get("Formula_data_15");
        this.formula_data_16 = (float) map.get("Formula_data_16");
        this.formula_data_17 = (float) map.get("Formula_data_17");
        this.formula_data_18 = (float) map.get("Formula_data_18");
        this.formula_data_19 = (int) map.get("Formula_data_19") + "";
        this.formula_data_20 = (int) map.get("Formula_data_20") + "";
        this.formula_data_21 = (int) map.get("Formula_data_21") + "";
        this.formula_data_22 = (int) map.get("Formula_data_22") + "";
        this.formula_data_23 = (int) map.get("Formula_data_23") + "";
        this.formula_data_24 = (float) map.get("Formula_data_24");
        this.formula_data_25 = (float) map.get("Formula_data_25");
        this.gramMass = 0f;
    }

    private void setBig(Map<String, Object> map) {
        this.formula_data_1 = (int) map.get("Formula_data_41");
        this.formula_data_2 = (int) map.get("Formula_data_42");
        this.formula_data_3 = (int) map.get("Formula_data_43");
        this.formula_data_4 = (int) map.get("Formula_data_44");
        this.formula_data_5 = (int) map.get("Formula_data_45");
        this.formula_data_6 = (int) map.get("Formula_data_46");
        this.formula_data_7 = (int) map.get("Formula_data_47");
        this.formula_data_8 = (int) map.get("Formula_data_48");
        this.formula_data_9 = (int) map.get("Formula_data_49");
        this.formula_data_10 = (int) map.get("Formula_data_50");
        this.formula_data_11 = (int) map.get("Formula_data_51");
        this.formula_data_12 = (int) map.get("Formula_data_52");
        this.formula_data_13 = (float) map.get("Formula_data_53");
        this.formula_data_14 = (float) map.get("Formula_data_54");
        this.formula_data_15 = (float) map.get("Formula_data_55");
        this.formula_data_16 = (float) map.get("Formula_data_56");
        this.formula_data_17 = (float) map.get("Formula_data_57");
        this.formula_data_18 = (float) map.get("Formula_data_58");
        this.formula_data_19 = String.format("%d,%d",
                ((Number) map.get("Formula_data_1")).intValue(),
                ((Number) map.get("Formula_data_2")).intValue());
        this.formula_data_20 = String.format("%d,%d",
                ((Number) map.get("Formula_data_3")).intValue(),
                ((Number) map.get("Formula_data_4")).intValue());
        this.formula_data_21 = String.format("%d,%d",
                ((Number) map.get("Formula_data_5")).intValue(),
                ((Number) map.get("Formula_data_6")).intValue());
        this.formula_data_22 = String.format("%d,%d",
                ((Number) map.get("Formula_data_7")).intValue(),
                ((Number) map.get("Formula_data_8")).intValue());
        this.formula_data_23 = String.format("%d,%d",
                ((Number) map.get("Formula_data_9")).intValue(),
                ((Number) map.get("Formula_data_10")).intValue());


        this.formula_data_24 = (float) map.get("Capacity_data_112");
    }

    public void setCells(Cell[] cells) {
        cells[0].setCellValue(this.device);
        cells[1].setCellValue(this.formula_data_2);
        cells[2].setCellValue(this.gramMass);
        cells[3].setCellValue(this.formula_data_19);
        cells[4].setCellValue(this.formula_data_20);
        cells[5].setCellValue(this.formula_data_21);
        cells[6].setCellValue(this.formula_data_22);
        cells[7].setCellValue(this.formula_data_23);
        cells[8].setCellValue(this.formula_data_4);
        cells[9].setCellValue(this.formula_data_5);
        cells[10].setCellValue(this.formula_data_6);
        cells[11].setCellValue(this.formula_data_7);
        cells[12].setCellValue(this.formula_data_8);
        cells[13].setCellValue(this.formula_data_9);
        cells[14].setCellValue(this.formula_data_10);
        cells[15].setCellValue(this.formula_data_11);
        cells[16].setCellValue(this.formula_data_12);
        cells[17].setCellValue(this.formula_data_13);
        cells[18].setCellValue(this.formula_data_14);
        cells[19].setCellValue(this.formula_data_16);
        cells[20].setCellValue(this.formula_data_17);
        cells[21].setCellValue(this.formula_data_18);
        cells[22].setCellValue(this.formula_data_24);
        if (this.formula_data_25 != null) {
            cells[23].setCellValue(this.formula_data_25);
        }
    }
}
