package com.jjt.calc.domain;

import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.jjt.common.annotation.Excel;
import com.jjt.common.core.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

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

/**
 * 印花机日统计数据对象 TWIN_CALC_DAY_YHJ
 *
 * @author wukai
 * @date 2025-03-07
 */
@ApiModel(value = "TwinCalcDayYhj", description = "印花机日统计数据")
@Data
public class TwinCalcDayYhj extends BaseEntity {
    private static final long serialVersionUID = 1L;

    /**
     * ID
     */
    @ApiModelProperty("ID")
    @TableId
    private Long id;

    /**
     * 时间
     */
    @ApiModelProperty("时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date time;

    /**
     * 设备ID
     */
    @ApiModelProperty("设备ID")
    @Excel(name = "设备ID")
    private Integer deviceId;

    /**
     * 自然天统计长度
     */
    @ApiModelProperty("自然天统计长度")
    @Excel(name = "自然天统计长度")
    private Integer dayLength;

    /**
     * 自然天统计重量
     */
    @ApiModelProperty("自然天统计重量")
    @Excel(name = "自然天统计重量")
    private BigDecimal dayWeight;

    /**
     * 总米长
     */
    @ApiModelProperty("总米长")
    @Excel(name = "总米长")
    private Integer length;

    /**
     * 总重量
     */
    @ApiModelProperty("总重量")
    @Excel(name = "总重量")
    private BigDecimal weight;

    /**
     * A班米长
     */
    @ApiModelProperty("A班米长")
    @Excel(name = "A班米长")
    private Integer lengthA;

    /**
     * A班重量
     */
    @ApiModelProperty("A班重量")
    @Excel(name = "A班重量")
    private BigDecimal weightA;

    /**
     * B班米长
     */
    @ApiModelProperty("B班米长")
    @Excel(name = "B班米长")
    private Integer lengthB;

    /**
     * B班重量
     */
    @ApiModelProperty("B班重量")
    @Excel(name = "B班重量")
    private BigDecimal weightB;

    public void setLength(Integer lengthA, Integer lengthB) {
        this.lengthA = lengthA == null ? 0 : lengthA;
        this.weightA = BigDecimal.valueOf(this.lengthA).divide(BigDecimal.valueOf(1000), 2, RoundingMode.HALF_UP);
        this.lengthB = lengthB == null ? 0 : lengthB;
        this.weightB = BigDecimal.valueOf(this.lengthB).divide(BigDecimal.valueOf(1000), 2, RoundingMode.HALF_UP);
        this.length = this.lengthA + this.lengthB;
        this.weight = this.weightA.add(this.weightB);
    }

}
