package com.dxhy.domestic.model.dto;

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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dxhy.common.util.UserInfoUtil;
import com.dxhy.common.utils.DateUtils;
import com.dxhy.common.vo.UserInfo;
import com.github.pagehelper.util.StringUtil;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author dxhy
 */
@SuppressWarnings("AlibabaUndefineMagicConstant")
@Data
@EqualsAndHashCode(callSuper = false)
public class TdxExportCustomsModelDTO extends CommonDTO {
    private Long id;
    private List<String> ids;
    private List<String> gfTaxNo;
    private String gfsh;
    private String customsCode;
    private String fillInDateStart;
    private String fillInDateEnd;
    private String exportNo;
    private String exportTaxAmount;
    private String exportTaxAmountMin;
    private String exportTaxAmountMax;
    private String sfDkStatus;
    private String glzt;
    private String rzhYesorno;
    private String confirmUser;
    private String authStatus;
    private String rzhDateStart;
    private String rzhDateEnd;
    private String rzhBelongDate;
    private String bdkStatus;

    private String auditStatus;
    private String applyCheck;

    private String rzlx;
    private String rzhType;
    private String cxrzType;
    private String entryDiscrepancy;
    private String bzdh;
    private String inAccountStatus;
    private String snVoucherNumber;
    private String imageNumber;
    private String postingTime;
    private String accountStatus;

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

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

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

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

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

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

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

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

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

        if (StringUtil.isNotEmpty(rzhBelongDate) && rzhBelongDate.contains("-")) {
            Date date = new SimpleDateFormat("yyyy-MM").parse(rzhBelongDate);
            rzhBelongDate = new SimpleDateFormat("yyyyMM").format(date);
        }

        if (StringUtil.isNotEmpty(fillInDateStart)) {
            fillInDateStart = DateUtils.getMorning(new SimpleDateFormat("yyyy-MM-dd").parse(fillInDateStart));
        }
        if (StringUtil.isNotEmpty(fillInDateEnd)) {
            fillInDateEnd = DateUtils.getNight(new SimpleDateFormat("yyyy-MM-dd").parse(fillInDateEnd));
        }

        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));
        }

        this.setPage(page);
    }
}
