package com.cyksj.model.views;

import com.cyksj.model.entity.UserDistributeSubRewards;
import com.ejlchina.searcher.bean.DbField;
import com.ejlchina.searcher.bean.DbIgnore;
import com.ejlchina.searcher.bean.SearchBean;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;

/**
 * 项目名: yhlxj
 * 文件名: UserDistributeSubDetailView
 * 创建者: JavaZou
 * 创建时间:2024/3/29 11:12
 */
@Getter
@Setter
@SearchBean(tables = "user_distribute_sub_waiting uw",
		where = "uw.send_status in ('waiting','success') and sub_user_id = :sid:")
public class UserDistributeSubDetailView {

	@DbField("sum(money)")
	private BigDecimal totalMoney = BigDecimal.ZERO;

	@DbField("select level from user_distribute_sub_rewards ur where sub_user_id = :sid: and ur.level > max(uw.level) limit 1")
	private Integer nextLevel;

	@DbIgnore
	private String nextLevelDesc;

	public String getNextLevelDesc() {
		if (nextLevel != null) {
			return UserDistributeSubRewards.RewardLevel.values()[nextLevel].getMsg();
		}
		if (totalMoney.compareTo(BigDecimal.ZERO) == 0) {
			return UserDistributeSubRewards.RewardLevel.meteor.getMsg();
		}
		return null;
	}
}
