package com.dxhy.customs.model;

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

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

/**
 * @author dxhy
 */
@SuppressWarnings("AlibabaUndefineMagicConstant")
@EqualsAndHashCode(callSuper = true)
@Data
public class TdxCustomsRecordModelDTO extends CommonDTO {
    private Long id;
    private List<String> ids;
    private List<String> gfTaxNo;
    private String customsCode;
    private String fillInDateStart;
    private String fillInDateEnd;
    private String taxAmount;
    private String taxAmountMax;
    private String taxAmountMin;
    private String qsStatus;
    private String qsDateStart;
    private String qsDateEnd;
    private String sfDkStatus;
    private String glzt;
    private String rzhYesorno;

    private String confirmUser;
    /**
     * 认证人列表
     **/
    private List<String> confirmUserList;
    private String rzhr;
    private String authStatus;

    private String rzhDateStart;
    private String rzhDateEnd;
    private String rzhBelongDate;
    private String gfsh;


    private String rzlx;
    private String rzhType;

    private String qsType;
    private String qsName;
    private String qsfs;
    private String businessCode;
    /**
     * bdk_message是5时，保存具体原因
     **/
    private String bdkYy;
    /**
     * 不抵扣类型，保存key。 1-用于非应税项目2-用于免税项目3-用于集体福利或者个人消费4-遭受非正常损失5-其他
     **/
    private String bdkMessage;
    private List<Business> business;

    public void setParam(Page page, UserInfo userInfo) throws Exception {
        business = userInfo.getBusiness();
        if ("99".equals(gfsh) || "".equals(gfsh)) {
            this.gfsh = null;
            gfTaxNo = UserInfoUtil.getGfshAll(userInfo.getOrg());

        }
        if ("99".equals(qsfs)) {
            this.qsfs = null;
        }
        if (!"1".equals(qsStatus)) {
            if ("99".equals(qsStatus)) {
                this.qsStatus = null;
            }
            this.qsDateStart = null;
            this.qsDateEnd = null;
            this.qsfs = null;
            this.businessCode = "99";
        }
        if ("99".equals(rzlx)) {
            this.rzlx = null;
        }

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

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

        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(qsDateStart)) {
            qsDateStart = DateUtils.getMorning(new SimpleDateFormat("yyyy-MM-dd").parse(qsDateStart));
        }
        if (StringUtil.isNotEmpty(qsDateEnd)) {
            qsDateEnd = DateUtils.getNight(new SimpleDateFormat("yyyy-MM-dd").parse(qsDateEnd));
        }

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