package com.tzy.common.dto.invoice;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.tzy.common.constant.Constants;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.teasoft.bee.osql.annotation.Entity;
import org.teasoft.bee.osql.annotation.Ignore;

import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * @author by po'yi
 * @Classname SimpleOrderDTO
 * @Description TODO
 * @Date 2022/8/9 14:05
 */
@Entity("card_group_order_info")
@Data
public class SimpleOrderDTO implements Serializable {
	private Long id;
	private String orderNo;
	/**付款金额*/
	private BigDecimal actualPayment;
	/**退款金额*/
	private BigDecimal refundFee;
	/**开票金额*/
	@Ignore
	private BigDecimal invoiceAmount;
	/**关联发票记录id*/
	private Integer invoiceId;
	@JsonIgnore
	private Long point;
	@JsonIgnore
	private String pointType;

	public BigDecimal getInvoiceAmount() {
		if (invoiceAmount != null) {
			return invoiceAmount;
		}
		BigDecimal orderAmount = actualPayment;
		refundFee = refundFee != null ? refundFee : BigDecimal.ZERO;
		if (StringUtils.isNotEmpty(pointType)) {
			orderAmount = BigDecimal.valueOf(point).divide(Constants.HUNDRED, 2, RoundingMode.HALF_UP);
			refundFee = refundFee.divide(Constants.HUNDRED, 2, RoundingMode.HALF_UP);
		}
		invoiceAmount = orderAmount.subtract(refundFee);
		return invoiceAmount;
	}
}
