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 org.apache.poi.ss.usermodel.CellStyle;

import java.util.Map;

/**
 * 送经量
 *
 * @author wukai
 * @date 2024/5/8 15:50
 */
@ApiModel(value = "WarpRunIn", description = "送经量数据")
@Data
@NoArgsConstructor
public class WarpRunIn {
    @ApiModelProperty("设备信息")
    private String device;
    @ApiModelProperty("L1梳栉送经量")
    private String l1;
    @ApiModelProperty("L2梳栉送经量")
    private String l2;
    @ApiModelProperty("L3梳栉送经量")
    private String l3;
    @ApiModelProperty("L4梳栉送经量")
    private String l4;
    @ApiModelProperty("L5梳栉送经量")
    private String l5;
    @ApiModelProperty("牵拉密度")
    private Float density;
    @ApiModelProperty("卷曲张力系数")
    private Float coefficient;

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

    }

    private void setSmall(Map<String, Object> map) {
        this.l1 = (int) map.get("Formula_data_19") + "";
        this.l2 = (int) map.get("Formula_data_20") + "";
        this.l3 = (int) map.get("Formula_data_21") + "";
        this.l4 = (int) map.get("Formula_data_22") + "";
        this.l5 = (int) map.get("Formula_data_23") + "";
        this.density = (float) map.get("Formula_data_24");
        this.coefficient = (float) map.get("Formula_data_25");
    }

    private void setBig(Map<String, Object> map) {
        this.l1 = String.format("%d,%d",
                ((Number) map.get("Formula_data_1")).intValue(),
                ((Number) map.get("Formula_data_2")).intValue());
        this.l2 = String.format("%d,%d",
                ((Number) map.get("Formula_data_3")).intValue(),
                ((Number) map.get("Formula_data_4")).intValue());
        this.l3 = String.format("%d,%d",
                ((Number) map.get("Formula_data_5")).intValue(),
                ((Number) map.get("Formula_data_6")).intValue());
        this.l4 = String.format("%d,%d",
                ((Number) map.get("Formula_data_7")).intValue(),
                ((Number) map.get("Formula_data_8")).intValue());
        this.l5 = String.format("%d,%d",
                ((Number) map.get("Formula_data_9")).intValue(),
                ((Number) map.get("Formula_data_10")).intValue());
        this.density = (float) map.get("Capacity_data_112");
    }

    public void setCells(Cell[] cells, CellStyle style) {
        cells[0].setCellValue(device);
        cells[1].setCellValue(l1);
        cells[2].setCellValue(l2);
        cells[3].setCellValue(l3);
        cells[4].setCellValue(l4);
        cells[5].setCellValue(l5);
        cells[6].setCellValue(density);
        cells[6].setCellStyle(style);
        if (coefficient != null) {
            cells[7].setCellValue(coefficient);
            cells[7].setCellStyle(style);
        }
    }
}
