package cn.iocoder.yudao.module.smartfactory.controller.admin.screendata.factory.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.text.DecimalFormat;

/**
 * 功能描述
 *
 * @author: yj
 * @date: 2024年03月05日 13:55
 */
@Schema(description = "大屏数据 - 工厂运营数据 Response VO")
@Data
public class OperateDataRespVO {

    /**今日 **/
    @Schema(description = "今日出库", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
    private Integer outboundTotal;

    @Schema(description = "今日入库（打包数-破损）", requiredMode = Schema.RequiredMode.REQUIRED, example = "200")
    private Integer warehouseTotal ;

    @Schema(description = "今日破损", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
    private Integer wornTotal ;

    @Schema(description = "优等品", requiredMode = Schema.RequiredMode.REQUIRED, example = "100 （优等品，即使打包线打包数量）")
    private Integer ydpTotal ;

    @Schema(description = "一级品", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
    private Integer yjpTotal ;

    @Schema(description = "合格品", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
    private Integer hgpTotal ;

    /**昨日 **/
    @Schema(description = "昨日出库", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
    private Integer outboundTotalYesterday;

    @Schema(description = "昨日入库", requiredMode = Schema.RequiredMode.REQUIRED, example = "200")
    private Integer warehouseTotalYesterday ;

    @Schema(description = "昨日破损", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
    private Integer wornTotalYesterday ;

    @Schema(description = "优等品", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
    private Integer ydpTotalYesterday ;

    @Schema(description = "一级品", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
    private Integer yjpTotalYesterday ;

    @Schema(description = "合格品", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
    private Integer hgpTotalYesterday ;

    /**本周 **/
    @Schema(description = "本周出库", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
    private Integer outboundTotalWeek;

    @Schema(description = "本周入库", requiredMode = Schema.RequiredMode.REQUIRED, example = "200")
    private Integer warehouseTotalWeek ;

    @Schema(description = "本周分检数", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
    private Integer sortingTotalWeek ;

    @Schema(description = "本周破损", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
    private Integer wornTotalWeek ;

    @Schema(description = "优等品", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
    private Integer ydpTotalWeek ;

    @Schema(description = "一级品", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
    private Integer yjpTotalWeek ;

    @Schema(description = "合格品", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
    private Integer hgpTotalWeek ;

    /**本月 **/
    @Schema(description = "本月出库", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
    private Integer outboundTotalMonth;

    @Schema(description = "本月入库", requiredMode = Schema.RequiredMode.REQUIRED, example = "200")
    private Integer warehouseTotalMonth ;

    @Schema(description = "本月分检数", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
    private Integer sortingTotalMonth ;

    @Schema(description = "本月破损", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
    private Integer wornTotalMonth ;

    @Schema(description = "优等品", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
    private Integer ydpTotalMonth ;

    @Schema(description = "一级品", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
    private Integer yjpTotalMonth ;

    @Schema(description = "合格品", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
    private Integer hgpTotalMonth ;

    /**
     * 公式：(今日破损 - 昨日破损) / 昨日破损 * 100% = 环比%
     */
    @Schema(description = "破损环比增长/下降", requiredMode = Schema.RequiredMode.REQUIRED, example = "-12.22%")
    private String wornQOQ;


    DecimalFormat df = new DecimalFormat("#0.00");

    public String setWornQOQ() {
        double a = getWornTotal() ;
        double b = getWornTotalYesterday() ;
        double i = ((a - b) /  b ) * 100;
        this.wornQOQ = df.format(i) ;
        return wornQOQ;
    }

    @Schema(description = "优等率", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
    private String ydl;
    @Schema(description = "昨日优等率", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
    private String ydlYesterday;
    @Schema(description = "本周优等率", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
    private String ydlWeek;
    @Schema(description = "本月优等率", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
    private String ydlMonth;


    /**
     * 根据type类型, 计划今日，昨日，本周，本月
     * @param type  1= 今日  2= 昨日 3= 本周  4本月
     * @param ydpTotal 合格品
     * @param yjpTotal 一级品
     * @param hgpTotal 合格品
     */
    public void setYdl(Integer type, Integer ydpTotal, Integer yjpTotal, Integer hgpTotal) {
        double a = ydpTotal ;
        double b = ydpTotal + yjpTotal + hgpTotal ;
        double i = (a / b ) * 100 ;
        String c = df.format(i) ;
        switch ( type ) {
            case 1:
                this.ydl = c ;
                break ;
            case 2:
                this.ydlYesterday = c ;
                break ;
            case 3:
                this.ydlWeek = c ;
                break ;
            case 4:
                this.ydlMonth = c ;
                break ;
        }
    }

//    public static void main(String[] args) {
//        OperateDataRespVO a = new OperateDataRespVO() ;
//
//        a.setYdl(4, 100, 20,30);
//
//        System.out.println(a.getYdl());
//        System.out.println(a.getYdlYesterday());
//        System.out.println(a.getYdlWeek());
//        System.out.println(a.getYdlMonth());
//    }
}
