package com.zcxk.dto.ranking;

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

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @description
 * @auto lihui
 * @data 2021-04-01
 */
@ApiModel("排名实体类")
@Data
public class RankingDto implements Comparable<RankingDto>{

    private static final long serialVersionUID = -3866939316262264972L;

    @ApiModelProperty(value = "名字",hidden = true)
    private String name;

    @ApiModelProperty(value = "得分",hidden = true)
    private Double score;

    @Override
    public int compareTo(RankingDto o) {
        return o.getScore().compareTo(this.getScore());
    }

    public static void main(String[] args) {
        List<RankingDto> list = new ArrayList<>();
        RankingDto dto = new RankingDto();
        dto.setName("排名5");
        dto.setScore(55.333);
        list.add(dto);
        dto = new RankingDto();
        dto.setName("排名1");
        dto.setScore(100.333);
        list.add(dto);
        dto = new RankingDto();
        dto.setName("排名3");
        dto.setScore(91.333);
        list.add(dto);
        dto = new RankingDto();
        dto.setName("排名2");
        dto.setScore(92.333);
        list.add(dto);
        dto = new RankingDto();
        dto.setName("排名4");
        dto.setScore(66.333);
        list.add(dto);
        Collections.sort(list);
        for (RankingDto rankingDto : list){
            System.out.println(rankingDto.getName() +"=1=1=" + rankingDto.getScore());
        }
    }

}
