package com.dxhy.vo.custom;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dxhy.api.model.config.Business;
import com.dxhy.vo.CommonDTO;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

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

/**
 * 功能描述
 *
 * @author 陈刚扬
 * @date 2020/10/28
 * @return
 */
@EqualsAndHashCode(callSuper = true)
@SuppressWarnings({"AlibabaUndefineMagicConstant", "rawtypes", "DuplicatedCode"})
@Data
public class BaseCustomsVO extends CommonDTO {

    private List<String> gfTaxNo;
    /**
     * 购方税号，唯一
     */
    private String gfsh;
    /**
     * 缴款书号码
     */
    private String customsCode;

    private String buyerName;

    /**
     * 默认去年上月第一天
     */
    private String fillInDateStart;
    /**
     * 默认当前日期
     *
     * @author 陈刚扬
     * @date 2020/10/30
     * @param null
     * @return
     */
    private String fillInDateEnd;
    /**
     * 所属期开始
     */
    private String belongDateStart;
    /**
     * 所属期结束
     */
    private String belongDateEnd;
    /**
     * 税款金额开始
     */
    private String taxAmountStart;
    /**
     * 税款金额结束
     */
    private String taxAmountEnd;
    /**
     * 签收状态
     *
     * @author 陈刚扬
     * @date 2020/10/30
     * @param null
     * @return
     */
    private String signStatus;

    /**
     * 签收日期开始
     *
     * @author 陈刚扬
     * @date 2020/10/30
     * @param null
     * @return
     */
    private String signDateStart;
    /**
     * 签收日期结束
     *
     * @author 陈刚扬
     * @date 2020/10/30
     * @param null
     * @return
     */
    private String signDateEnd;

    /**
     * 所属期
     *
     * @author 陈刚扬
     * @date 2020/10/30
     * @param null
     * @return
     */
    private String belongDate;
    /**
     * 认证时间
     *
     * @author 陈刚扬
     * @date 2020/10/30
     * @param null
     * @return
     */
    private String rzhDate;
    /**
     * 管理状态
     *
     * @author 陈刚扬
     * @date 2020/10/30
     * @param null
     * @return
     */
    private String manageStatus;
    /**
     * 认证状态
     *
     * @author 陈刚扬
     * @date 2020/10/30
     * @param null
     * @return
     */
    private String confirmStatus;
    /**
     * 认证处理状态
     *
     * @author 陈刚扬
     * @date 2020/10/30
     * @param null
     * @return
     */
    private String authStatus;
    /**
     * 认证人
     *
     * @author 陈刚扬
     * @date 2020/10/30
     * @param null
     * @return
     */
    private String confirmUser;

    /**
     * 认证日期开始
     *
     * @author 陈刚扬
     * @date 2020/10/30
     * @param null
     * @return
     */
    private String rzhDateStart;
    /**
     * 认证日期结束
     *
     * @author 陈刚扬
     * @date 2020/10/30
     * @param null
     * @return
     */
    private String rzhDateEnd;

    private List<Long> idList;

    private List<String> ids;

    private String dataList;

    private String glzt;

    private String dataSources;

    private String entryDiscrepancy;

    private String rzhBelongDate;

    private String qsFlag;

    private String businessCode;

    private List<Business> business;


    public void setParam(Page page) throws Exception {

        if ("99".equals(gfsh)) {
            this.gfsh = null;
        }
        if ("99".equals(signStatus)) {
            this.signStatus = null;
        }
        if ("99".equals(authStatus)) {
            this.authStatus = null;
        }
        if ("99".equals(manageStatus)) {
            this.manageStatus = null;
        }
        if ("99".equals(confirmStatus)) {
            this.confirmStatus = null;
        }

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

        if (StringUtils.isEmpty(signStatus) || !"1".equals(signStatus)) {
            signDateStart = null;
            signDateEnd = null;
            businessCode = "99";
            // 签收为已签收时条件生效
        }

        if ("1".equals(qsFlag)) {
            signStatus = qsFlag;
        }

        if (StringUtils.isNotEmpty(belongDate) && "-".contains(belongDate)) {
            Date date = new SimpleDateFormat("yyyy-MM").parse(belongDate);
            belongDate = new SimpleDateFormat("yyyyMM").format(date);
        }
        if (this.getGfTaxNo() != null && this.getGfTaxNo().size() > 0) {
            for (String str : this.getGfTaxNo()) {
                if (this.isAll(str)) {
                    this.gfTaxNo = null;
                    break;
                }
            }
        }
        this.setPage(page);
    }


}
