package com.sa.ibiz.demo.demo.service.dto;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sa.ibiz.demo.ibizutil.domain.ParentData;
import com.sa.ibiz.demo.demo.domain.XM;
import org.springframework.util.StringUtils;
import lombok.Data;
import java.util.Map;
import java.sql.Timestamp;
import com.sa.ibiz.demo.ibizutil.service.SearchFilterBase;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.sa.ibiz.demo.ibizutil.helper.DataGridCustomSearchHelper;
import com.alibaba.fastjson.JSONObject;
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class XMSearchFilter extends SearchFilterBase {

	private String query;
	private Page page;
	private QueryWrapper<XM> selectCond;
	private JSONObject customsearchval;
	public XMSearchFilter(){
		this.page =new Page<XM>(1,Short.MAX_VALUE);
		this.selectCond=new QueryWrapper<XM>();	
	}

	/**
	 * 设定自定义查询条件，在原有SQL基础上追加该SQL
	 */
	public void setCustomCond(String sql)
	{
		this.selectCond.apply(sql);
	}

	private String n_fzbmid_eq;

	public void setN_fzbmid_eq(String n_fzbmid_eq) {
        this.n_fzbmid_eq = n_fzbmid_eq;
        if(!StringUtils.isEmpty(this.n_fzbmid_eq)){
            this.selectCond.eq("fzbmid", n_fzbmid_eq);
        }
    }
	private String n_fzrid_eq;

	public void setN_fzrid_eq(String n_fzrid_eq) {
        this.n_fzrid_eq = n_fzrid_eq;
        if(!StringUtils.isEmpty(this.n_fzrid_eq)){
            this.selectCond.eq("fzrid", n_fzrid_eq);
        }
    }
	private String n_xmname_like;

	public void setN_xmname_like(String n_xmname_like) {
        this.n_xmname_like = n_xmname_like;
        if(!StringUtils.isEmpty(this.n_xmname_like)){
            this.selectCond.like("xmname", n_xmname_like);
        }
    }
	private String n_zxrid_eq;

	public void setN_zxrid_eq(String n_zxrid_eq) {
        this.n_zxrid_eq = n_zxrid_eq;
        if(!StringUtils.isEmpty(this.n_zxrid_eq)){
            this.selectCond.eq("zxrid", n_zxrid_eq);
        }
    }

	public void setSrfparentdata(Map<String, String> srfparentdata) {
		this.srfparentdata = srfparentdata;
		String strParentkey=this.getSrfparentdata().get("srfparentkey");
		if(this.srfparentdata.containsKey("srfparentmode")&& this.getSrfparentdata().get("srfparentmode").equals("DER1N_XM_ORGSECTOR_FZBMID"))
			if(StringUtils.isEmpty(strParentkey)){
				this.setN_fzbmid_eq("NA");
			}
			else{
				this.setN_fzbmid_eq(strParentkey);
			}
		if(this.srfparentdata.containsKey("srfparentmode")&& this.getSrfparentdata().get("srfparentmode").equals("DER1N_XM_ORGUSER_FZRID"))
			if(StringUtils.isEmpty(strParentkey)){
				this.setN_fzrid_eq("NA");
			}
			else{
				this.setN_fzrid_eq(strParentkey);
			}
		if(this.srfparentdata.containsKey("srfparentmode")&& this.getSrfparentdata().get("srfparentmode").equals("DER1N_XM_ORGUSER_ZXRID"))
			if(StringUtils.isEmpty(strParentkey)){
				this.setN_zxrid_eq("NA");
			}
			else{
				this.setN_zxrid_eq(strParentkey);
			}
	}

	/**
	 * 启用快速搜索
	 */
	public void setQuery(String query)
	{
		 this.query=query;
		 if(!StringUtils.isEmpty(query)){
			this.selectCond.or().like("xmname",query);
		 }
	}

	/**
	 * 自定义查询
	 * @param customsearchval
	 */
	public void setCustomsearchval(JSONObject customsearchval) {
		this.customsearchval = customsearchval;
		if(!StringUtils.isEmpty(customsearchval)){
			DataGridCustomSearchHelper customSearchHelper= DataGridCustomSearchHelper.getInstance();
			String customSql =customSearchHelper.parseCustomVal(customsearchval);
			this.selectCond.apply(customSql);
		}
	}

}