package com.dxhy.domestic.model.dto;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dxhy.api.model.config.UserInfo;
import com.dxhy.common.util.UserInfoUtil;
import com.dxhy.common.utils.DateUtils;
import com.dxhy.vo.CommonDTO;
import com.github.pagehelper.util.StringUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.List;

/**
 * @author dxhy
 */
@SuppressWarnings("AlibabaUndefineMagicConstant")
@Data
@EqualsAndHashCode(callSuper = false)
public class TdxExportInvoiceModelDTO extends CommonDTO {
    private Long id;
    private List<String> ids;
    private List<String> gfTaxNo;
    private String xfName;
    private String invoiceDateStart;
    private String invoiceDateEnd;
    private String invoiceNo;
    /**
     * 数电号码
     **/
    private String eleInvoiceNo;
    private String exportNo;
    private String invoiceStatus;
    private String invoiceType;
    private String invoiceSource;
    private String gfsh;
    private String sfDkStatus;
    private String rzhYesorno;
    private String bdkStatus;
    private String authStatus;
    private String rzhDateStart;
    private String rzhDateEnd;
    private String rzhBelongDate;
    private String confirmUser;
    private String minPrice;
    private String maxPrice;

    private String rzlx;
    private String rzhType;
    private String cxrzType;

    /**
     *不抵扣原因 1-用于非应税项目2-用于免税项目3-用于集体福利或者个人消费4-遭受非正常损失5-其他
     **/
    private String bdkMessage;
    /**
     * bdk_message是5时，保存具体原因
     **/
    private String bdkYy;

    public void setParam(Page page, UserInfo userInfo) throws Exception {

        if ("99".equals(invoiceType)) {
            this.invoiceType = null;
        }

        if ("99".equals(invoiceSource)) {
            this.invoiceSource = null;
        }

        if ("99".equals(invoiceStatus)) {
            this.invoiceStatus = null;
        }

        if ("99".equals(bdkStatus)) {
            this.bdkStatus = null;
        }
        if ("99".equals(rzlx)) {
            this.rzlx = null;
        }
        if ("99".equals(authStatus)) {
            this.authStatus = null;
        }
        if (!"1".equals(rzhYesorno) && !"2".equals(rzhYesorno)) {
            if ("99".equals(rzhYesorno)) {
                this.rzhYesorno = null;
            }
            rzhBelongDate = null;
            rzhDateEnd = null;
            rzhDateStart = null;
        }

        if (StringUtil.isNotEmpty(invoiceDateStart)) {
            invoiceDateStart = DateUtils.getMorning(new SimpleDateFormat("yyyy-MM-dd").parse(invoiceDateStart));
        }
        if (StringUtil.isNotEmpty(invoiceDateEnd)) {
            invoiceDateEnd = DateUtils.getNight(new SimpleDateFormat("yyyy-MM-dd").parse(invoiceDateEnd));
        }
        if (StringUtil.isNotEmpty(rzhDateStart)) {
            rzhDateStart = DateUtils.getMorning(new SimpleDateFormat("yyyy-MM-dd").parse(rzhDateStart));
        }
        if (StringUtil.isNotEmpty(rzhDateEnd)) {
            rzhDateEnd = DateUtils.getNight(new SimpleDateFormat("yyyy-MM-dd").parse(rzhDateEnd));
        }

        if (!Arrays.asList("1", "2").contains(rzhYesorno)) {
            // 认证为1-已认证抵扣2-已认证不抵扣时，有值，其它清空认证相关查询条件
            rzhDateStart = null;
            rzhDateEnd = null;
            rzhBelongDate = null;
        }

        if ("99".equals(gfsh)) {
            this.gfsh = null;
            gfTaxNo = UserInfoUtil.getGfshAll(userInfo.getOrg());
        }
        this.setPage(page);
    }
}
