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.CodeItem;
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 CodeItemSearchFilter extends SearchFilterBase {

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

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

	private String n_codeitemname_like;

	public void setN_codeitemname_like(String n_codeitemname_like) {
        this.n_codeitemname_like = n_codeitemname_like;
        if(!StringUtils.isEmpty(this.n_codeitemname_like)){
            this.selectCond.like("codeitemname", n_codeitemname_like);
        }
    }
	private String n_codelistid_eq;

	public void setN_codelistid_eq(String n_codelistid_eq) {
        this.n_codelistid_eq = n_codelistid_eq;
        if(!StringUtils.isEmpty(this.n_codelistid_eq)){
            this.selectCond.eq("codelistid", n_codelistid_eq);
        }
    }
	private String n_codelistname_eq;

	public void setN_codelistname_eq(String n_codelistname_eq) {
        this.n_codelistname_eq = n_codelistname_eq;
        if(!StringUtils.isEmpty(this.n_codelistname_eq)){
            this.selectCond.eq("codelistname", n_codelistname_eq);
        }
    }
	private String n_codelistname_like;

	public void setN_codelistname_like(String n_codelistname_like) {
        this.n_codelistname_like = n_codelistname_like;
        if(!StringUtils.isEmpty(this.n_codelistname_like)){
            this.selectCond.like("codelistname", n_codelistname_like);
        }
    }
	private String n_pcodeitemid_eq;

	public void setN_pcodeitemid_eq(String n_pcodeitemid_eq) {
        this.n_pcodeitemid_eq = n_pcodeitemid_eq;
        if(!StringUtils.isEmpty(this.n_pcodeitemid_eq)){
            this.selectCond.eq("pcodeitemid", n_pcodeitemid_eq);
        }
    }
	private String n_pcodeitemname_eq;

	public void setN_pcodeitemname_eq(String n_pcodeitemname_eq) {
        this.n_pcodeitemname_eq = n_pcodeitemname_eq;
        if(!StringUtils.isEmpty(this.n_pcodeitemname_eq)){
            this.selectCond.eq("pcodeitemname", n_pcodeitemname_eq);
        }
    }
	private String n_pcodeitemname_like;

	public void setN_pcodeitemname_like(String n_pcodeitemname_like) {
        this.n_pcodeitemname_like = n_pcodeitemname_like;
        if(!StringUtils.isEmpty(this.n_pcodeitemname_like)){
            this.selectCond.like("pcodeitemname", n_pcodeitemname_like);
        }
    }

	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_CODEITEM_CODELIST_CODELISTID"))
			if(StringUtils.isEmpty(strParentkey)){
				this.setN_codelistid_eq("NA");
			}
			else{
				this.setN_codelistid_eq(strParentkey);
			}
		if(this.srfparentdata.containsKey("srfparentmode")&& this.getSrfparentdata().get("srfparentmode").equals("DER1N_CODEITEM_CODEITEM_PCODEITEMID"))
			if(StringUtils.isEmpty(strParentkey)){
				this.setN_pcodeitemid_eq("NA");
			}
			else{
				this.setN_pcodeitemid_eq(strParentkey);
			}
	}

	/**
	 * 启用快速搜索
	 */
	public void setQuery(String query)
	{
		 this.query=query;
		 if(!StringUtils.isEmpty(query)){
			this.selectCond.or().like("codeitemname",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);
		}
	}

}