package com.trade.service.trade.exportrebate.domain;

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

import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.trade.common.core.domain.BaseEntity;
import com.trade.service.DictConstants;
import com.trade.service.thirdparty.xiaotu.dto.ProduceExportDetailsResponse;
import com.trade.service.thirdparty.xiaotu.dto.TradeExportAndPurchaseDetailsResponse;
import com.trade.service.trade.salesorder.vo.CustomsDeclarationGoodsBelongsVO;
import org.springframework.format.annotation.DateTimeFormat;

/**
 * 出口退税-出口明细表表实体类
 *
 * @author hlb
 * @since 2024-10-24 20:46:23
 */
public class TaxRebateExportDetails extends BaseEntity<TaxRebateExportDetails> {

    /**
     * 客户id
     */
    private Long customerUserId;
    /**
     * 代理公司统一社会信用代码/注册号
     */
    private String agencyCertNo;
    /**
     * 进口商统一社会信用代码/注册号
     */
    private String importerCertNo;
    /**
     * 销售订单号
     */
    private String salesOrderNo;
    /**
     * 销售合同id
     */
    private Long salesContractId;
    /**
     * 销售合同号
     */
    private String salesContractNo;
    /**
     * 申报年月（生产企业：所属期）（yyyyMM）
     */
    private String declarationMonthYear;
    /**
     * 申报批次
     */
    private String declarationBatch;
    /**
     * 申报序号
     */
    private String declarationSerialNo;
    /**
     * 关联号
     */
    private String correlationNo;
    /**
     * 海关报关单号（18位）
     */
    private String customsDeclarationNo;
    /**
     * 出口货物报关单号（21位）
     */
    private String exportCustomsDeclarationNo;
    /**
     * 代理出口货物证明号
     */
    private String agencyExportGoodsCertificateNo;
    /**
     * 出口发票号（形式发票号）
     */
    private String proformaInvoiceNo;
    /**
     * 退税额（生产企业：免抵退税额）
     */
    private BigDecimal taxRefundAmount;
    /**
     * 出口日期
     */
    private Date exportDate;
    /**
     * 商品HS编码
     */
    private String hsCode;
    /**
     * 出口商品代码
     */
    private String exportCommodityCode;
    /**
     * 出口商品名称
     */
    private String exportCommodityName;
    /**
     * 计量单位
     */
    private String measurementUnit;
    /**
     * 申报商品代码
     */
    private String declarationCommodityCode;
    /**
     * 申报商品名称
     */
    private String declarationCommodityName;
    /**
     * 出口数量
     */
    private BigDecimal exportQuantity;
    /**
     * 美元离岸价
     */
    private BigDecimal fobPriceUsd;
    /**
     * 退（免）税业务类型
     */
    private String taxRefundExemptionType;
    /**
     * 退（免）税业务类型名称
     */
    private String taxRefundExemptionTypeName;
    /**
     * 国内启运方式
     */
    private String domesticShippingMethod;
    /**
     * 国内启运方式名称
     */
    private String domesticShippingName;
    /**
     * 海关总署认证企业类型
     */
    private String cgaCertifiedEnterpriseType;
    /**
     * 海关总署认证企业类型名称
     */
    private String cgaCertifiedEnterpriseTypeName;
    /**
     * 备注
     */
    private String mark;
    /**
     * 审核标志
     */
    private String auditStatus;
    /**
     * 不予办理标志
     */
    private String notProcessFlag;
    /**
     * 不予退税标志
     */
    private String notTaxRefund;
    /**
     * 暂不办理标志
     */
    private String deferredProcessFlag;
    /**
     * 不予办理年月
     */
    private String notProcessMonthYear;
    /**
     * 不予退税年月
     */
    private String notRefundMonthYear;
    /**
     * 暂不办理年月
     */
    private String suspensionMonthYear;
    /**
     * 最终解除暂不办理准予年月
     */
    private String liftingSuspensionApprovalDate;
    /**
     * 单证不齐标志
     */
    private String missingDocsFlag;
    /**
     * 退税状态，枚举rebate_process_status
     */
    private String status;
    /**
     * 退税到账状态，枚举rebate_payment_status
     */
    private String paymentStatus;
    /**
     * 退税到账日期
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date paymentDate;

    public Long getCustomerUserId() {
        return customerUserId;
    }

    public void setCustomerUserId(Long customerUserId) {
        this.customerUserId = customerUserId;
    }

    public String getAgencyCertNo() {
        return agencyCertNo;
    }

    public void setAgencyCertNo(String agencyCertNo) {
        this.agencyCertNo = agencyCertNo;
    }

    public String getImporterCertNo() {
        return importerCertNo;
    }

    public void setImporterCertNo(String importerCertNo) {
        this.importerCertNo = importerCertNo;
    }

    public String getSalesOrderNo() {
        return salesOrderNo;
    }

    public void setSalesOrderNo(String salesOrderNo) {
        this.salesOrderNo = salesOrderNo;
    }

    public Long getSalesContractId() {
        return salesContractId;
    }

    public void setSalesContractId(Long salesContractId) {
        this.salesContractId = salesContractId;
    }

    public String getSalesContractNo() {
        return salesContractNo;
    }

    public void setSalesContractNo(String salesContractNo) {
        this.salesContractNo = salesContractNo;
    }

    public String getDeclarationMonthYear() {
        return declarationMonthYear;
    }

    public void setDeclarationMonthYear(String declarationMonthYear) {
        this.declarationMonthYear = declarationMonthYear;
    }

    public String getDeclarationBatch() {
        return declarationBatch;
    }

    public void setDeclarationBatch(String declarationBatch) {
        this.declarationBatch = declarationBatch;
    }

    public String getDeclarationSerialNo() {
        return declarationSerialNo;
    }

    public void setDeclarationSerialNo(String declarationSerialNo) {
        this.declarationSerialNo = declarationSerialNo;
    }

    public String getCorrelationNo() {
        return correlationNo;
    }

    public void setCorrelationNo(String correlationNo) {
        this.correlationNo = correlationNo;
    }

    public String getCustomsDeclarationNo() {
        return customsDeclarationNo;
    }

    public void setCustomsDeclarationNo(String customsDeclarationNo) {
        this.customsDeclarationNo = customsDeclarationNo;
    }

    public String getExportCustomsDeclarationNo() {
        return exportCustomsDeclarationNo;
    }

    public void setExportCustomsDeclarationNo(String exportCustomsDeclarationNo) {
        this.exportCustomsDeclarationNo = exportCustomsDeclarationNo;
    }

    public String getAgencyExportGoodsCertificateNo() {
        return agencyExportGoodsCertificateNo;
    }

    public void setAgencyExportGoodsCertificateNo(String agencyExportGoodsCertificateNo) {
        this.agencyExportGoodsCertificateNo = agencyExportGoodsCertificateNo;
    }

    public String getProformaInvoiceNo() {
        return proformaInvoiceNo;
    }

    public void setProformaInvoiceNo(String proformaInvoiceNo) {
        this.proformaInvoiceNo = proformaInvoiceNo;
    }

    public BigDecimal getTaxRefundAmount() {
        return taxRefundAmount;
    }

    public void setTaxRefundAmount(BigDecimal taxRefundAmount) {
        this.taxRefundAmount = taxRefundAmount;
    }

    public Date getExportDate() {
        return exportDate;
    }

    public void setExportDate(Date exportDate) {
        this.exportDate = exportDate;
    }

    public String getHsCode() {
        return hsCode;
    }

    public void setHsCode(String hsCode) {
        this.hsCode = hsCode;
    }

    public String getExportCommodityCode() {
        return exportCommodityCode;
    }

    public void setExportCommodityCode(String exportCommodityCode) {
        this.exportCommodityCode = exportCommodityCode;
    }

    public String getExportCommodityName() {
        return exportCommodityName;
    }

    public void setExportCommodityName(String exportCommodityName) {
        this.exportCommodityName = exportCommodityName;
    }

    public String getMeasurementUnit() {
        return measurementUnit;
    }

    public void setMeasurementUnit(String measurementUnit) {
        this.measurementUnit = measurementUnit;
    }

    public String getDeclarationCommodityCode() {
        return declarationCommodityCode;
    }

    public void setDeclarationCommodityCode(String declarationCommodityCode) {
        this.declarationCommodityCode = declarationCommodityCode;
    }

    public String getDeclarationCommodityName() {
        return declarationCommodityName;
    }

    public void setDeclarationCommodityName(String declarationCommodityName) {
        this.declarationCommodityName = declarationCommodityName;
    }

    public BigDecimal getExportQuantity() {
        return exportQuantity;
    }

    public void setExportQuantity(BigDecimal exportQuantity) {
        this.exportQuantity = exportQuantity;
    }

    public BigDecimal getFobPriceUsd() {
        return fobPriceUsd;
    }

    public void setFobPriceUsd(BigDecimal fobPriceUsd) {
        this.fobPriceUsd = fobPriceUsd;
    }

    public String getTaxRefundExemptionType() {
        return taxRefundExemptionType;
    }

    public void setTaxRefundExemptionType(String taxRefundExemptionType) {
        this.taxRefundExemptionType = taxRefundExemptionType;
    }

    public String getTaxRefundExemptionTypeName() {
        return taxRefundExemptionTypeName;
    }

    public void setTaxRefundExemptionTypeName(String taxRefundExemptionTypeName) {
        this.taxRefundExemptionTypeName = taxRefundExemptionTypeName;
    }

    public String getDomesticShippingMethod() {
        return domesticShippingMethod;
    }

    public void setDomesticShippingMethod(String domesticShippingMethod) {
        this.domesticShippingMethod = domesticShippingMethod;
    }

    public String getDomesticShippingName() {
        return domesticShippingName;
    }

    public void setDomesticShippingName(String domesticShippingName) {
        this.domesticShippingName = domesticShippingName;
    }

    public String getCgaCertifiedEnterpriseType() {
        return cgaCertifiedEnterpriseType;
    }

    public void setCgaCertifiedEnterpriseType(String cgaCertifiedEnterpriseType) {
        this.cgaCertifiedEnterpriseType = cgaCertifiedEnterpriseType;
    }

    public String getCgaCertifiedEnterpriseTypeName() {
        return cgaCertifiedEnterpriseTypeName;
    }

    public void setCgaCertifiedEnterpriseTypeName(String cgaCertifiedEnterpriseTypeName) {
        this.cgaCertifiedEnterpriseTypeName = cgaCertifiedEnterpriseTypeName;
    }

    public String getMark() {
        return mark;
    }

    public void setMark(String mark) {
        this.mark = mark;
    }

    public String getAuditStatus() {
        return auditStatus;
    }

    public void setAuditStatus(String auditStatus) {
        this.auditStatus = auditStatus;
    }

    public String getNotProcessFlag() {
        return notProcessFlag;
    }

    public void setNotProcessFlag(String notProcessFlag) {
        this.notProcessFlag = notProcessFlag;
    }

    public String getNotTaxRefund() {
        return notTaxRefund;
    }

    public void setNotTaxRefund(String notTaxRefund) {
        this.notTaxRefund = notTaxRefund;
    }

    public String getDeferredProcessFlag() {
        return deferredProcessFlag;
    }

    public void setDeferredProcessFlag(String deferredProcessFlag) {
        this.deferredProcessFlag = deferredProcessFlag;
    }

    public String getNotProcessMonthYear() {
        return notProcessMonthYear;
    }

    public void setNotProcessMonthYear(String notProcessMonthYear) {
        this.notProcessMonthYear = notProcessMonthYear;
    }

    public String getNotRefundMonthYear() {
        return notRefundMonthYear;
    }

    public void setNotRefundMonthYear(String notRefundMonthYear) {
        this.notRefundMonthYear = notRefundMonthYear;
    }

    public String getSuspensionMonthYear() {
        return suspensionMonthYear;
    }

    public void setSuspensionMonthYear(String suspensionMonthYear) {
        this.suspensionMonthYear = suspensionMonthYear;
    }

    public String getLiftingSuspensionApprovalDate() {
        return liftingSuspensionApprovalDate;
    }

    public void setLiftingSuspensionApprovalDate(String liftingSuspensionApprovalDate) {
        this.liftingSuspensionApprovalDate = liftingSuspensionApprovalDate;
    }

    public String getMissingDocsFlag() {
        return missingDocsFlag;
    }

    public void setMissingDocsFlag(String missingDocsFlag) {
        this.missingDocsFlag = missingDocsFlag;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getPaymentStatus() {
        return paymentStatus;
    }

    public void setPaymentStatus(String paymentStatus) {
        this.paymentStatus = paymentStatus;
    }

    public Date getPaymentDate() {
        return paymentDate;
    }

    public void setPaymentDate(Date paymentDate) {
        this.paymentDate = paymentDate;
    }

    public TaxRebateExportDetails(){
    }

    public TaxRebateExportDetails(TradeExportAndPurchaseDetailsResponse response,
            CustomsDeclarationGoodsBelongsVO goodsBelongs){
        this.customerUserId = goodsBelongs == null ? null : goodsBelongs.getCustomerUserId();
        this.agencyCertNo = goodsBelongs == null ? null : goodsBelongs.getAgencyCertNo();
        this.importerCertNo = goodsBelongs == null ? null : goodsBelongs.getImporterCertNo();
        this.salesOrderNo = goodsBelongs == null ? null : goodsBelongs.getSalesOrderNo();
        this.salesContractId = goodsBelongs == null ? null : goodsBelongs.getSalesContractId();
        this.salesContractNo = goodsBelongs == null ? null : goodsBelongs.getSalesContractNo();
        this.declarationMonthYear = response.getSsq();
        this.declarationBatch = response.getSbpc();
        this.declarationSerialNo = response.getSbxh();
        this.correlationNo = response.getGlh();
        this.customsDeclarationNo = goodsBelongs == null ? null : goodsBelongs.getBgdhgbh();
        this.exportCustomsDeclarationNo = response.getCkbgdh();
        this.agencyExportGoodsCertificateNo = response.getDlzmh();
        this.proformaInvoiceNo = response.getCkfph();
        this.taxRefundAmount = response.getTse();
        this.exportDate = response.getCkrq() == null ? null : new Date(response.getCkrq());
        this.hsCode = goodsBelongs == null ? null : goodsBelongs.getHgckspDm();
        this.exportCommodityCode = response.getCkspDm();
        this.exportCommodityName = response.getSbhgspmc();
        this.measurementUnit = response.getHgjldwmc();
        this.declarationCommodityCode = response.getSbspDm();
        this.declarationCommodityName = response.getSbspmc();
        this.exportQuantity = response.getCksl();
        this.fobPriceUsd = response.getMylaj();
        this.taxRefundExemptionType = response.getCktmsywlxdmjh();
        this.taxRefundExemptionTypeName = response.getCktmsywlxmcjh();
        this.domesticShippingMethod = response.getGnqyfsDm();
        this.domesticShippingName = response.getGnqyfsmc();
        this.cgaCertifiedEnterpriseType = response.getHgzsrzqylxDm();
        this.cgaCertifiedEnterpriseTypeName = response.getHgzsrzqylxmc();
        this.mark = response.getBz();
        this.auditStatus = response.getShbz();
        this.notProcessFlag = response.getByblbz();
        this.notTaxRefund = response.getBytsbz();
        this.deferredProcessFlag = response.getZbblbz();
        this.notProcessMonthYear = response.getByblny();
        this.notRefundMonthYear = response.getBytsny();
        this.suspensionMonthYear = response.getZbblny();
        this.liftingSuspensionApprovalDate = response.getZzjczbblzyny();
        this.missingDocsFlag = response.getDzbqbz();
        // 审核标志（shbz）为Y，且不予办理标志（byblbz）为N（或空），且不予退税标志（bytsbz）为N（或空），且暂不办理标志（zbblbz）为N（或空），则表示已退税
        this.status = DictConstants.SYS_YES.equals(response.getShbz())
                && (StrUtil.isBlank(response.getByblbz()) || DictConstants.SYS_NO.equals(response.getByblbz()))
                && (StrUtil.isBlank(response.getBytsbz()) || DictConstants.SYS_NO.equals(response.getBytsbz()))
                && (StrUtil.isBlank(response.getZbblbz()) || DictConstants.SYS_NO.equals(response.getZbblbz()))
                        ? DictConstants.REBATE_PROCESS_STATUS_DONE
                        : DictConstants.REBATE_PROCESS_STATUS_NOT_REBATE;
        if (DictConstants.REBATE_PROCESS_STATUS_DONE.equals(this.status)) {
            this.paymentStatus = DictConstants.REBATE_PAYMENT_STATUS_NOT_PAY;
        }
    }

    public TaxRebateExportDetails(ProduceExportDetailsResponse response, CustomsDeclarationGoodsBelongsVO goodsBelongs){
        this.customerUserId = goodsBelongs == null ? null : goodsBelongs.getCustomerUserId();
        this.agencyCertNo = goodsBelongs == null ? null : goodsBelongs.getAgencyCertNo();
        this.importerCertNo = goodsBelongs == null ? null : goodsBelongs.getImporterCertNo();
        this.salesOrderNo = goodsBelongs == null ? null : goodsBelongs.getSalesOrderNo();
        this.salesContractId = goodsBelongs == null ? null : goodsBelongs.getSalesContractId();
        this.salesContractNo = goodsBelongs == null ? null : goodsBelongs.getSalesContractNo();
        this.declarationMonthYear = response.getSsq();
        this.declarationSerialNo = response.getSbxh();
        this.correlationNo = response.getGlh();
        this.customsDeclarationNo = goodsBelongs == null ? null : goodsBelongs.getBgdhgbh();
        this.exportCustomsDeclarationNo = response.getCkbgdh();
        this.proformaInvoiceNo = response.getCkfph();
        this.taxRefundAmount = response.getMdtse();
        this.exportDate = response.getCkrq() == null ? null : new Date(response.getCkrq());
        this.hsCode = goodsBelongs == null ? null : goodsBelongs.getHgckspDm();
        this.exportCommodityCode = response.getCkspDm();
        this.exportCommodityName = response.getSbhgspmc();
        this.measurementUnit = response.getHgjldwmc();
        this.declarationCommodityCode = response.getSbspDm();
        this.declarationCommodityName = response.getSbspmc();
        this.exportQuantity = response.getCksl();
        this.fobPriceUsd = response.getMylaj();
        this.taxRefundExemptionType = response.getCktmsywlxdmjh();
        this.taxRefundExemptionTypeName = response.getCktmsywlxmcjh();
        this.domesticShippingMethod = response.getGnqyfsDm();
        this.domesticShippingName = response.getGnqyfsmc();
        this.cgaCertifiedEnterpriseType = response.getHgzsrzqylxDm();
        this.cgaCertifiedEnterpriseTypeName = response.getHgzsrzqylxmc();
        this.mark = response.getBz();
        this.auditStatus = response.getShbz();
        this.notProcessFlag = response.getByblbz();
        this.notTaxRefund = response.getBytsbz();
        this.deferredProcessFlag = response.getZbblbz();
        this.notProcessMonthYear = response.getByblny();
        this.notRefundMonthYear = response.getBytsny();
        this.suspensionMonthYear = response.getZbblny();
        this.liftingSuspensionApprovalDate = response.getZzjczbblzyny();
        this.missingDocsFlag = response.getDzbqbz();
        // 审核标志（shbz）为Y，且不予办理标志（byblbz）为N（或空），且不予退税标志（bytsbz）为N（或空），且暂不办理标志（zbblbz）为N（或空），则表示已退税
        this.status = DictConstants.SYS_YES.equals(response.getShbz())
                && (StrUtil.isBlank(response.getByblbz()) || DictConstants.SYS_NO.equals(response.getByblbz()))
                && (StrUtil.isBlank(response.getBytsbz()) || DictConstants.SYS_NO.equals(response.getBytsbz()))
                && (StrUtil.isBlank(response.getZbblbz()) || DictConstants.SYS_NO.equals(response.getZbblbz()))
                        ? DictConstants.REBATE_PROCESS_STATUS_DONE
                        : DictConstants.REBATE_PROCESS_STATUS_NOT_REBATE;
        if (DictConstants.REBATE_PROCESS_STATUS_DONE.equals(this.status)) {
            this.paymentStatus = DictConstants.REBATE_PAYMENT_STATUS_NOT_PAY;
        }
    }
}
