package com.cyksj.model.views;

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;

/*
 *项目名: netflix
 *文件名: DistributeBusinessView
 *创建者: JavaZou
 *创建时间:2023/3/22 18:00
 */
@Getter
@Setter
@SearchBean(tables = "(select distinct business_id from user_distribute_business_rate) ur left join user_distribute_business_order_don_record ubr on ubr.business_id = ur.business_id and :time:" +
		" inner join cms_user cu on cu.id = ur.business_id",
		groupBy = "ur.business_id,cu.nickname,date_format(ubr.order_created_time,'%Y-%m')")
public class DistributeBusinessView {
	@DbField("ur.business_id")
	private Long businessId;

	@DbField("cu.nickname")
	private String businessName;

	/**
	 * 关联人数
	 */
	@DbIgnore
	private Integer numOfRelation;

	@DbField("count(if(ubr.order_type = 1 and ubr.status = 'success',1,NULL))")
	private Integer numOfFirstOrderThisMonth;

	@DbField("cast(sum(if(ubr.order_type = 1 and ubr.status = 'success',ubr.take_money,0))/100 as decimal(10,2))")
	private BigDecimal moneyOfFirstOrderThisMonth;

	@DbField("count(if(ubr.order_type = 2 and ubr.status = 'success',1,NULL))")
	private Integer numOfRenewOrderThisMonth;

	@DbField("cast(sum(if(ubr.order_type = 2 and ubr.status = 'success',ubr.take_money,0))/100 as decimal(10,2))")
	private BigDecimal moneyOfRenewOrderThisMonth;

	@DbField("cast(sum(if(ubr.status = 'success',ubr.take_money,0))/100 as decimal(10,2))")
	private BigDecimal takeMoney;

	@DbField("cast(sum(if(ubr.status = 'refund', ubr.take_money,0))/100 as decimal(10,2))")
	private BigDecimal refundMoney;

	@DbField("date_format(ubr.order_created_time,'%Y-%m')")
	private String monthDate;
}
