package com.jwipc.contract.model.query;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.google.common.collect.Lists;
import com.jwipc.query.BasePageQuery;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 *     合同付款申请主表列表查询实体类
 * </p>
 *
 * @author 邓京术
 * @version 1.0
 * @since 2025/12/10
 */
@Data
public class ContractPaymentApplyHeadQuery extends BasePageQuery implements Serializable {
    private String sort;
    private String order;

    /**
     * 申请单号
     */
    private String applyNo;
    /**
     * 数据状态 1:暂存 2:待推送OA 3:OA审批中 4:OA审批不通过 5:已支付
     */
    private Integer status;
    /**
     * 更多状态查询 系统待办查询使用
     */
    private String moreStatus;
    /**
     * 公司代码
     */
    private String companyCode;
    private List<String> companyCodes;
    /**
     * 工厂代码
     */
    private String factoryCode;
    /**
     * 供应商编码或名称
     */
    private String supCodeOrName;
    /**
     * 币种代码
     */
    private String currencyCode;
    /**
     * OA审批流程号
     */
    private String oaProcessCode;
    /**
     * 推送OA员工姓名
     */
    private String pushOaUserName;
    /**
     * 采购订单号(预付申请单查询专用)
     */
    private String poCode;

    /**
     * 采购订单行
     */
    private String poItemNo;
    /**
     * 创建时间(起)
     */
    private String createTimeStart;
    /**
     * 创建时间(至)
     */
    private String createTimeEnd;
    /**
     * 创建人ID
     */
    private Long createUserId;
    /**
     * 数据权限 当前登录人ID
     */
    private Long userId;
    /**
     * 数据权限 供应商编码
     */
    private String supplierCode;

    private String createUserName;
    /**
     * 付款金额起
     */
    private BigDecimal oaBorrowMoneyBegin;
    /**
     * 付款金额止
     */
    private BigDecimal oaBorrowMoneyEnd;

    /**
     * 本次申请金额
     */
    private BigDecimal taxAmount;

    private String oaType;

    private String contractCode;

    private String isOa;

    private String oaSubName;

    private String companyType;

    private String syncState;

    private String accountingDocument;

    private String oaProcessId;

    /**
     * 开票申请号
     */
    private String invoiceNo;

    private String dataType;

    private String orderCode;


    public String getApplyNoLike(){
        return StringUtils.isEmpty(this.applyNo) ? null : StringPool.PERCENT + this.applyNo + StringPool.PERCENT;
    }


    public String getSupCodeOrNameLike(){
        return StringUtils.isEmpty(this.supCodeOrName) ? null : StringPool.PERCENT + this.supCodeOrName + StringPool.PERCENT;
    }

    public String getOaProcessCodeLike(){
        return StringUtils.isEmpty(this.oaProcessCode) ? null : StringPool.PERCENT + this.oaProcessCode + StringPool.PERCENT;
    }

    public String getPushOaUserNameLike(){
        return StringUtils.isEmpty(this.pushOaUserName) ? null : StringPool.PERCENT + this.pushOaUserName + StringPool.PERCENT;
    }

    public List<Integer> getMoreStatusList(){
        if(StringUtils.isNotEmpty(this.moreStatus)) {
            final String[] msArray = StringUtils.split(this.moreStatus, ",");
            List<Integer> list = Lists.newArrayList();
            for (String ms: msArray) {
                list.add(Integer.parseInt(ms));
            }

            return list;
        }
        return Lists.newArrayList();
    }


    public String getCreateTimeStart(){
        if(StringUtils.isNotEmpty(this.createTimeStart)){
            return this.createTimeStart + " 00:00:00";
        }
        return "";
    }

    public String getCreateTimeEnd(){
        if(StringUtils.isNotEmpty(this.createTimeEnd)){
            return this.createTimeEnd + " 23:59:59";
        }
        return "";
    }

    public String getSort(){
        if(StringUtils.isNotEmpty(this.sort)){
            return StrUtil.toUnderlineCase(this.sort);
        }
        return "";
    }
}
