package com.iformall.domain.po;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.iformall.common.SortColumn;
import com.iformall.domain.po.base.BaseEntity;
import com.iformall.enums.EnumPriceUnit;
import com.iformall.enums.EnumRentContractAdjustPeriod;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author gongbiao
 */
@TableName(value = "wx_rent_contract")
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class WxRentContract extends BaseEntity {

    protected Long id;


    @TableField(exist = false)
    @SortColumn(column = "shopNumber")
    private String shopNumber;

    @TableField(exist = false)
    private String building;

    @TableField(exist = false)
    private String floor;

    @TableField(exist = false)
    private String brandName;

    @TableField(exist = false)
    private String buildArea;

    @TableField(exist = false)
    private String priceStr;

    @TableField(exist = false)
    private String depositStr;

    @TableField(exist = false)
    @SortColumn(column = "allPeriod")
    private Integer allPeriod;

    @TableField(exist = false)
    @SortColumn(column = "period")
    private Integer period;

    @TableField(exist = false)
    @SortColumn(column = "needPay")
    private Integer needPay;

    @TableField(exist = false)
    @SortColumn(column = "receivePay")
    private Integer receivePay;

    @TableField(exist = false)
    @SortColumn(column = "owe")
    private Integer owe;

    @TableField(exist = false)
    private String receiveDate;

    @TableField(exist = false)
    @SortColumn(column = "latePayPrice")
    private Integer latePayPrice;

    @io.swagger.annotations.ApiModelProperty(value = "是否同时终止物业", name = "endProperty")
    @TableField(exist = false)
    private Integer endProperty;

    @io.swagger.annotations.ApiModelProperty(value = "商户", name = "merchantId")
    private Long merchantId;
    @io.swagger.annotations.ApiModelProperty(value = "月租金/分成(分)", name = "price")
    private Long price;
    @io.swagger.annotations.ApiModelProperty(value = "计租开始时间", name = "rentalStartDate")
    private Date rentalStartDate;
    @io.swagger.annotations.ApiModelProperty(value = "计租结束时间", name = "rentalEndDate")
    private Date rentalEndDate;
    @io.swagger.annotations.ApiModelProperty(value = "签定合同时间", name = "signDate")
    private Date signDate;
    @io.swagger.annotations.ApiModelProperty(value = "付款周期", name = "receivePeriod")
    private Integer receivePeriod;
    @io.swagger.annotations.ApiModelProperty(value = "租户ID", name = "tenantId")
    private String tenantId;
    @io.swagger.annotations.ApiModelProperty(value = "合同文件路径", name = "filepath")
    private String filepath;
    @io.swagger.annotations.ApiModelProperty(value = "合同进度状态1待签约2已签约未记租3计租中4提前终止5合同到期", name = "status")
    private Integer status;
    @io.swagger.annotations.ApiModelProperty(value = "合同编号", name = "contractNumber")
    private String contractNumber;
    @io.swagger.annotations.ApiModelProperty(value = "押金", name = "deposit")
    private Long deposit;

    @io.swagger.annotations.ApiModelProperty(value = "交租日 计租开始时间减去交租日的天数为基数 提前多少日交租", name = "payDate")
    @SortColumn(column = "payDate")
    private Integer payDate;
    @io.swagger.annotations.ApiModelProperty(value = "是否删除1是0否", name = "isDel")
    private Integer isDel;
    @io.swagger.annotations.ApiModelProperty(value = "商户名称", name = "merchantName")
    private String merchantName;
    @io.swagger.annotations.ApiModelProperty(value = "经营品牌", name = "brand")
    private Long brand;
    @io.swagger.annotations.ApiModelProperty(value = "经常业态ID", name = "businessId")
    private Integer businessId;
    @io.swagger.annotations.ApiModelProperty(value = "店铺类型", name = "shopType")
    private Integer shopType;
    @io.swagger.annotations.ApiModelProperty(value = "商铺ID", name = "shopId")
    private Long shopId;
    @io.swagger.annotations.ApiModelProperty(value = "更新时间", name = "updatetime")
    private Date updatetime;

    @io.swagger.annotations.ApiModelProperty(value = "创建时间", name = "createtime")
    private Date createtime;

    @io.swagger.annotations.ApiModelProperty(value = "计租面积", name = "rentArea")
    private String rentArea;

    @io.swagger.annotations.ApiModelProperty(value = "联系人", name = "linkPerson")
    private String linkPerson;

    @io.swagger.annotations.ApiModelProperty(value = "联系电话", name = "linkPhone")
    private String linkPhone;

    @io.swagger.annotations.ApiModelProperty(value = "付款账号", name = "payAccount")
    private String payAccount;

    @io.swagger.annotations.ApiModelProperty(value = "上传文件名", name = "filename")
    private String filename;

    @io.swagger.annotations.ApiModelProperty(value = "租期(月)", name = "lease")
    private Integer lease;

    @io.swagger.annotations.ApiModelProperty(value = "类型", name = "type")
    private Integer type;

    @io.swagger.annotations.ApiModelProperty(value = "调整比例", name = "adjustRatio")
    private String adjustRatio;

    @io.swagger.annotations.ApiModelProperty(value = "计租周期 1日2月", name = "adjustPeriod")
    private Integer adjustPeriod;

    @io.swagger.annotations.ApiModelProperty(value = "支付比例", name = "payRatio")
    private Integer payRatio;

    @io.swagger.annotations.ApiModelProperty(value = "营业额", name = "revenue")
    private Long revenue;

    @io.swagger.annotations.ApiModelProperty(value = "起租开始时间", name = "rentalStartDate")
    private Date startDate;

    @io.swagger.annotations.ApiModelProperty(value = "起租结束时间", name = "rentalEndDate")
    private Date endDate;

    //审核状态，0未审核 1审核中 2审核通过 3驳回
    @io.swagger.annotations.ApiModelProperty(value = "审核状态", name = "applyStatus")
    private Integer applyStatus;

    // 审批流1合同2账单3终止审批
    @io.swagger.annotations.ApiModelProperty(value = "审批流类型", name = "businessType")
    private Integer businessType;

    @io.swagger.annotations.ApiModelProperty(value = "开户行", name = "bankName")
    private String bankName;

    @io.swagger.annotations.ApiModelProperty(value = "租赁商铺类型", name = "rentShopType")
    private Integer rentShopType;

    @TableField(exist = false)
    @io.swagger.annotations.ApiModelProperty(value = "审批流参数", name = "flowParams")
    private Map<String, Object> flowParams;

    @io.swagger.annotations.ApiModelProperty(value = "装修期开始时间", name = "fixStartDate")
    private Date fixStartDate;

    @io.swagger.annotations.ApiModelProperty(value = "装修期结束时间", name = "fixEndDate")
    private Date fixEndDate;

    @TableField(exist = false)
    @io.swagger.annotations.ApiModelProperty(value = "租赁合同预账单列表", name = "previewBillRentList")
    private List<WxBillRent> previewBillRentList;

    @TableField(exist = false)
    @io.swagger.annotations.ApiModelProperty(value = "物业合同预账单列表", name = "reviewBillPropertyPList")
    private List<WxBillProperty> reviewBillPropertyPList;

    @io.swagger.annotations.ApiModelProperty(value = "租金信息", name = "rentInfo")
    private String rentInfo;

    @io.swagger.annotations.ApiModelProperty(value = "上传文件名", name = "fileNames")
    private String fileNames;

    @io.swagger.annotations.ApiModelProperty(value = "租金单位1日2月3年", name = "priceUnit")
    private Integer priceUnit;

    @io.swagger.annotations.ApiModelProperty(value = "多径租赁单价(其他放rentInfo)", name = "priceUnit")
    private String rentPrice;

    @io.swagger.annotations.ApiModelProperty(value = "主体名称", name = "subjectName")
    private String subjectName;

    @io.swagger.annotations.ApiModelProperty(value = "1按租赁日生产2按计租日生成账单", name = "rentStartType")
    private Integer rentStartType;

    @io.swagger.annotations.ApiModelProperty(value = "租金录入方式1合铺录入2分铺录入", name = "rent_input_way")
    private Integer rentInputWay;

    @io.swagger.annotations.ApiModelProperty(value = "年租金调整方式1按比例2按金额", name = "adjust_ratio_way")
    private Integer adjustRatioWay;

    @io.swagger.annotations.ApiModelProperty(value = "操作类型1区分租赁物业2合并租赁物业", name = "operationType")
    private Integer operationType;

    @io.swagger.annotations.ApiModelProperty(value = "滞纳金费率", name = "latePayRatio")
    private String latePayRatio;

    @io.swagger.annotations.ApiModelProperty(value = "n日后开始计算滞纳金", name = "latePayRatio")
    private Integer latePayDay;

    @io.swagger.annotations.ApiModelProperty(value = "联营扣点率", name = "busDiscountRatio")
    private String busDiscountRatio;

    @io.swagger.annotations.ApiModelProperty(value = "联营扣点-时间范围 1年2月3周期", name = "busDiscountTime")
    private Integer busDiscountTime;

    public void setAdjustPeriodHandle() {
        if(EnumPriceUnit.D.getCode().equals(this.getPriceUnit()) && EnumRentContractAdjustPeriod.ADJUST_PERIOD_MONTH.getCode().equals(adjustPeriod)){
            this.adjustPeriod = EnumRentContractAdjustPeriod.ADJUST_PERIOD_DAY.getCode();
        }
    }

    public void setRentPriceHandle() {
        if(StringUtils.isNotBlank(rentPrice)) {
            rentPrice = new BigDecimal(rentPrice).multiply(new BigDecimal(100)).toPlainString();
        } else {
            rentPrice = "0";
        }
    }




}

