package com.ejie.ad74a.dao;

import com.ejie.x38.dao.RowNumResultSetExtractor;
import com.ejie.x38.dto.JerarquiaDto;
import com.ejie.x38.dto.TableManager;
import com.ejie.x38.dto.TableManagerJerarquia;
import com.ejie.x38.dto.TableRequestDto;
import com.ejie.x38.dto.TableRowDto;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.sql.DataSource;
import org.springframework.dao.support.DataAccessUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.ejie.ad74a.model.DocuAvisos;
import com.ejie.ad74a.util.UtilSQL;

/**
 * DocuAvisosDaoImpl generated by UDA, 13-jul-2023 10:09:33.
 * 
 * @author UDA
 */

@Repository
@Transactional
public class DocuAvisosDaoImpl implements DocuAvisosDao {

	public static final String[] ORDER_BY_WHITE_LIST = new String[] { "IDDOCAVISO70", "IDAVISO70", "RUTA70",
			"NOMBREDOC70", "EXTENSION70", "FALTA70", "USUALTA70", "NOMBREDOCUMENTO", "tipoDocumentoDescEs" };

	private JdbcTemplate jdbcTemplate;

	public static final String SEQUENCE_DOCU_AVISOS = "SEQ_DOCU_AVISOS";

	/*
	 * ROW_MAPPERS
	 */
	private RowMapper<DocuAvisos> rwMap = new RowMapper<DocuAvisos>() {
		public DocuAvisos mapRow(ResultSet resultSet, int rowNum) throws SQLException {
			DocuAvisos docuAvisos = new DocuAvisos(UtilSQL.getLong(resultSet, "IDDOCAVISO70"),
					UtilSQL.getLong(resultSet, "IDAVISO70"), resultSet.getString("RUTA70"),
					resultSet.getString("NOMBREDOC70"), resultSet.getString("EXTENSION70"),
					resultSet.getDate("FALTA70"), resultSet.getString("USUALTA70"));
			docuAvisos.setIdTipoDoc70(resultSet.getLong("IDTIPODOC70"));
			docuAvisos.setTipoDocumentoEs(resultSet.getString("DESCES36"));
			docuAvisos.setTipoDocumentoEu(resultSet.getString("DESCEU36"));
			return docuAvisos;
		}
	};

	private RowMapper<DocuAvisos> rwMapPK = new RowMapper<DocuAvisos>() {
		public DocuAvisos mapRow(ResultSet resultSet, int rowNum) throws SQLException {
			return new DocuAvisos(resultSet.getLong("IDDOCAVISO70"));
		}
	};

	/**
	 * Rowmapper para Jerarquía
	 *
	 * @param dataSource DataSource
	 * @return
	 */
	private RowMapper<JerarquiaDto<DocuAvisos>> rwMapJerarquia = new RowMapper<JerarquiaDto<DocuAvisos>>() {
		public JerarquiaDto<DocuAvisos> mapRow(ResultSet resultSet, int rowNum) throws SQLException {

			DocuAvisos docuavisos = new DocuAvisos(UtilSQL.getLong(resultSet, "IDDOCAVISO70"),
					UtilSQL.getLong(resultSet, "IDAVISO70"), resultSet.getString("RUTA70"),
					resultSet.getString("NOMBREDOC70"), resultSet.getString("EXTENSION70"),
					resultSet.getDate("FALTA70"), resultSet.getString("USUALTA70"));

			JerarquiaDto<DocuAvisos> jerarquia = new JerarquiaDto<DocuAvisos>();
			jerarquia.setModel(docuavisos);
			jerarquia.setLevel(resultSet.getBigDecimal("LEVEL").intValue());
			jerarquia.setParentNodes(resultSet.getString("PARENTNODES"));
			jerarquia.setIsLeaf(Boolean.parseBoolean(resultSet.getString("ISLEAF")));
			jerarquia.setFilter(Boolean.parseBoolean(resultSet.getString("FILTER")));
			return jerarquia;
		}
	};

	/**
	 * Method use to set the datasource.
	 *
	 * @param dataSource DataSource
	 * @return
	 */
	@Resource
	public void setDataSource(DataSource dataSource) {
		this.jdbcTemplate = new JdbcTemplate(dataSource);
	}

	/*
	 * OPERACIONES CRUD
	 */

	/**
	 * Inserts a single row in the DocuAvisos table.
	 *
	 * @param docuavisos DocuAvisos
	 * @return DocuAvisos
	 */
	public DocuAvisos add(DocuAvisos docuavisos) {

		GeneratedKeyHolder generatedKeyHolder = new GeneratedKeyHolder();

		String query = "INSERT INTO DOCU_AVISOS (ID_DOC_AVISO_70, ID_AVISO_70, RUTA_70, NOMBRE_DOC_70, EXTENSION_70, F_ALTA_70, USU_ALTA_70, ID_TIPO_DOC_70) "
				+ "VALUES (" + SEQUENCE_DOCU_AVISOS
				+ ".NEXTVAL,:idAviso,:ruta,:nombreDoc,:extension,sysdate,:usuAlta,:idTipoDoc)";

		MapSqlParameterSource parameters = new MapSqlParameterSource().addValue("idAviso", docuavisos.getIdAviso70())
				.addValue("ruta", docuavisos.getRuta70()).addValue("nombreDoc", docuavisos.getNombreDoc70())
				.addValue("extension", docuavisos.getExtension70()).addValue("usuAlta", docuavisos.getUsuAlta70())
				.addValue("idTipoDoc", docuavisos.getIdTipoDoc70());

		NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
		namedParameterJdbcTemplate.update(query, parameters, generatedKeyHolder, new String[] { "ID_DOC_AVISO_70" });
		docuavisos.setIdAviso70(generatedKeyHolder.getKey().longValue());

		return docuavisos;
	}

	/**
	 * Updates a single row in the DocuAvisos table.
	 *
	 * @param docuavisos DocuAvisos
	 * @return DocuAvisos
	 */
	public DocuAvisos update(DocuAvisos docuavisos) {
		String query = "UPDATE DOCU_AVISOS SET ID_AVISO_70=?, RUTA_70=?, NOMBRE_DOC_70=?, EXTENSION_70=?, F_ALTA_70=?, USU_ALTA_70=?, t1.ID_TIPO_DOC_70=? WHERE ID_DOC_AVISO_70=?";
		this.jdbcTemplate.update(query, docuavisos.getIdAviso70(), docuavisos.getRuta70(), docuavisos.getNombreDoc70(),
				docuavisos.getExtension70(), docuavisos.getfecAlta70(), docuavisos.getUsuAlta70(),
				docuavisos.getIdTipoDoc70(), docuavisos.getIdDocAviso70());
		return docuavisos;
	}

	/**
	 * Finds a single row in the DocuAvisos table.
	 *
	 * @param docuavisos DocuAvisos
	 * @return DocuAvisos
	 */
	@Transactional(readOnly = true)
	public DocuAvisos find(DocuAvisos docuavisos) {
		String query = "SELECT t1.ID_DOC_AVISO_70 IDDOCAVISO70, t1.ID_AVISO_70 IDAVISO70, t1.RUTA_70 RUTA70, t1.NOMBRE_DOC_70 NOMBREDOC70, t1.EXTENSION_70 EXTENSION70, t1.F_ALTA_70 FALTA70, t1.USU_ALTA_70 USUALTA70, t1.ID_TIPO_DOC_70 IDTIPODOC70, t2.DESC_ES_36 DESCES36, t2.DESC_EU_36 DESCEU36 FROM DOCU_AVISOS t1, MAESTRO_TIPOS_DOC t2  WHERE t2.ID_TIPO_DOC_36 = t1.ID_TIPO_DOC_70 (+) AND t1.ID_DOC_AVISO_70 = ?  ";

		List<DocuAvisos> docuavisosList = this.jdbcTemplate.query(query, this.rwMap, docuavisos.getIdDocAviso70());
		return (DocuAvisos) DataAccessUtils.uniqueResult(docuavisosList);
	}

	/**
	 * Removes a single row in the DocuAvisos table.
	 *
	 * @param docuavisos DocuAvisos
	 * @return
	 */
	public void remove(DocuAvisos docuavisos) {
		String query = "DELETE FROM DOCU_AVISOS WHERE ID_DOC_AVISO_70=?";
		this.jdbcTemplate.update(query, docuavisos.getIdDocAviso70());
	}

	public void removeByIdAviso(DocuAvisos docuavisos) {
		String query = "DELETE FROM DOCU_AVISOS WHERE ID_AVISO_70=?";
		this.jdbcTemplate.update(query, docuavisos.getIdAviso70());
	}

	/**
	 * Removes a single row in the DocuAvisos table.
	 *
	 * @param docuavisos DocuAvisos
	 * @return
	 */
	public void removeByRuta(String oid) {
		String query = "DELETE FROM DOCU_AVISOS WHERE RUTA_70 = ?";
		this.jdbcTemplate.update(query, oid);
	}

	/**
	 * Exporta Datos al clipBoard
	 *
	 */
	public List<DocuAvisos> getMultiple(DocuAvisos filterDocuAvisos, TableRequestDto tableRequestDto,
			Boolean startsWith) {

		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_DOC_AVISO_70 IDDOCAVISO70, t1.ID_AVISO_70 IDAVISO70, t1.RUTA_70 RUTA70, t1.NOMBRE_DOC_70 NOMBREDOC70, t1.EXTENSION_70 EXTENSION70, t1.F_ALTA_70 FALTA70, t1.USU_ALTA_70 USUALTA70, t1.ID_TIPO_DOC_70 IDTIPODOC70, t2.DESC_ES_36 DESCES36, t2.DESC_EU_36 DESCEU36");
		query.append(" FROM DOCU_AVISOS t1, MAESTRO_TIPOS_DOC t2  ");
		// Where clause & Params
		Map<String, Object> mapaWhere = this.getWhereLikeMap(filterDocuAvisos, startsWith);
		StringBuilder where = new StringBuilder(query + " WHERE 1=1 ");
		where.append("AND t2.ID_TIPO_DOC_36 = t1.ID_TIPO_DOC_70 (+)");
		where.append(mapaWhere.get("query"));

		@SuppressWarnings("unchecked")
		List<Object> params = (List<Object>) mapaWhere.get("params");

		StringBuilder sbMultipleSQL = TableManager.getSelectMultipleQuery(tableRequestDto, DocuAvisos.class, params,
				"ID_DOC_AVISO_70");
		where.append(sbMultipleSQL);

		return this.jdbcTemplate.query(where.toString(), this.rwMap, params.toArray());
	}

	/**
	 * Finds a list of rows in the DocuAvisos table.
	 *
	 * @param docuavisos      DocuAvisos
	 * @param tableRequestDto TableRequestDto
	 * @return List<DocuAvisos>
	 */
	@Transactional(readOnly = true)
	public List<DocuAvisos> findAll(DocuAvisos docuavisos, TableRequestDto tableRequestDto) {
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_DOC_AVISO_70 IDDOCAVISO70,t1.ID_AVISO_70 IDAVISO70,t1.RUTA_70 RUTA70,t1.NOMBRE_DOC_70 NOMBREDOC70,t1.EXTENSION_70 EXTENSION70,t1.F_ALTA_70 FALTA70,t1.USU_ALTA_70 USUALTA70, t1.ID_TIPO_DOC_70 IDTIPODOC70, t2.DESC_ES_36 DESCES36, t2.DESC_EU_36 DESCEU36 ");
		query.append("FROM DOCU_AVISOS t1, MAESTRO_TIPOS_DOC t2 ");

		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereMap(docuavisos);
		StringBuilder where = new StringBuilder(" WHERE 1=1 ");
		where.append("AND t2.ID_TIPO_DOC_36 = t1.ID_TIPO_DOC_70 (+)");
		where.append(mapaWhere.get("query"));
		query.append(where);

		List<?> params = (List<?>) mapaWhere.get("params");

		if (tableRequestDto != null) {
			query = TableManager.getPaginationQuery(tableRequestDto, query, DocuAvisosDaoImpl.ORDER_BY_WHITE_LIST);
		}

		return (List<DocuAvisos>) this.jdbcTemplate.query(query.toString(), this.rwMap, params.toArray());
	}

	/**
	 * Finds rows in the DocuAvisos table using like.
	 *
	 * @param docuavisos      DocuAvisos
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 * @return List<DocuAvisos>
	 */
	@Transactional(readOnly = true)
	public List<DocuAvisos> findAllLike(DocuAvisos docuavisos, TableRequestDto tableRequestDto, Boolean startsWith) {
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_DOC_AVISO_70 IDDOCAVISO70,t1.ID_AVISO_70 IDAVISO70,t1.RUTA_70 RUTA70,t1.NOMBRE_DOC_70 NOMBREDOC70,t1.EXTENSION_70 EXTENSION70,t1.F_ALTA_70 FALTA70,t1.USU_ALTA_70 USUALTA70, t1.ID_TIPO_DOC_70 IDTIPODOC70, t2.DESC_ES_36 DESCES36, t2.DESC_EU_36 DESCEU36 ");
		query.append("FROM DOCU_AVISOS t1, MAESTRO_TIPOS_DOC t2 ");

		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(docuavisos, startsWith);
		StringBuilder where = new StringBuilder(" WHERE 1=1 ");
		where.append("AND t2.ID_TIPO_DOC_36 = t1.ID_TIPO_DOC_70 (+)");
		where.append(mapaWhere.get("query"));
		query.append(where);

		List<?> params = (List<?>) mapaWhere.get("params");

		if (tableRequestDto != null) {
			query = TableManager.getPaginationQuery(tableRequestDto, query, DocuAvisosDaoImpl.ORDER_BY_WHITE_LIST);
		}

		return (List<DocuAvisos>) this.jdbcTemplate.query(query.toString(), this.rwMap, params.toArray());
	}

	/*
	 * OPERACIONES RUP_TABLE
	 */

	/**
	 * Counts rows in the DocuAvisos table.
	 *
	 * @param docuavisos DocuAvisos
	 * @return Long
	 */
	@Transactional(readOnly = true)
	public Long findAllCount(DocuAvisos docuavisos) {
		StringBuilder query = new StringBuilder("SELECT COUNT(1) FROM DOCU_AVISOS t1, MAESTRO_TIPOS_DOC t2 ");

		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereMap(docuavisos);
		StringBuilder where = new StringBuilder(" WHERE 1=1 ");
		where.append("AND t2.ID_TIPO_DOC_36 = t1.ID_TIPO_DOC_70 (+)");
		where.append(mapaWhere.get("query"));
		query.append(where);

		List<?> params = (List<?>) mapaWhere.get("params");

		return this.jdbcTemplate.queryForObject(query.toString(), params.toArray(), Long.class);
	}

	/**
	 * Counts rows in the DocuAvisos table using like.
	 *
	 * @param docuavisos DocuAvisos
	 * @param startsWith Boolean
	 * @return Long
	 */
	@Transactional(readOnly = true)
	public Long findAllLikeCount(DocuAvisos docuavisos, Boolean startsWith) {
		StringBuilder query = new StringBuilder("SELECT COUNT(1) FROM DOCU_AVISOS t1, MAESTRO_TIPOS_DOC t2 ");

		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(docuavisos, startsWith);
		StringBuilder where = new StringBuilder(" WHERE 1=1 ");
		where.append("AND t2.ID_TIPO_DOC_36 = t1.ID_TIPO_DOC_70 (+)");
		where.append(mapaWhere.get("query"));
		query.append(where);

		List<?> params = (List<?>) mapaWhere.get("params");

		return this.jdbcTemplate.queryForObject(query.toString(), params.toArray(), Long.class);
	}

	/**
	 * Reorder the data list of DocuAvisos selected for rup_table
	 *
	 * @param docuavisos      DocuAvisos
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 * @return List<TableRowDto<DocuAvisos>>
	 */
	@Override
	public List<TableRowDto<DocuAvisos>> reorderSelection(DocuAvisos docuavisos, TableRequestDto tableRequestDto,
			Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_DOC_AVISO_70 IDDOCAVISO70,t1.ID_AVISO_70 IDAVISO70,t1.RUTA_70 RUTA70,t1.NOMBRE_DOC_70 NOMBREDOC70,t1.EXTENSION_70 EXTENSION70,t1.F_ALTA_70 FALTA70,t1.USU_ALTA_70 USUALTA70, t1.ID_TIPO_DOC_70 IDTIPODOC70, t2.DESC_ES_36 DESCES36, t2.DESC_EU_36 DESCEU36 ");
		// FROM
		query.append("FROM DOCU_AVISOS t1, MAESTRO_TIPOS_DOC t2 ");
		// FILTRADO
		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(docuavisos, startsWith);
		StringBuilder where = new StringBuilder(" WHERE 1=1 ");
		where.append("AND t2.ID_TIPO_DOC_36 = t1.ID_TIPO_DOC_70 (+)");
		where.append(mapaWhere.get("query"));
		query.append(where);

		// Parámetros de filtrado
		@SuppressWarnings("unchecked")
		List<Object> filterParamList = (List<Object>) mapaWhere.get("params");

		// SQL para la reordenación
		StringBuilder sbReorderSelectionSQL = TableManager.getReorderQuery(query, tableRequestDto, DocuAvisos.class,
				filterParamList, "IDDOCAVISO70");

		return this.jdbcTemplate.query(sbReorderSelectionSQL.toString(),
				new RowNumResultSetExtractor<DocuAvisos>(this.rwMapPK, tableRequestDto), filterParamList.toArray());
	}

	/**
	 * Search method for rup_table
	 *
	 * @param filterParams    DocuAvisos
	 * @param searchParams    DocuAvisos
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 * @return List<TableRowDto<DocuAvisos>>
	 */
	@Override
	public List<TableRowDto<DocuAvisos>> search(DocuAvisos filterParams, DocuAvisos searchParams,
			TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_DOC_AVISO_70 IDDOCAVISO70,t1.ID_AVISO_70 IDAVISO70,t1.RUTA_70 RUTA70,t1.NOMBRE_DOC_70 NOMBREDOC70,t1.EXTENSION_70 EXTENSION70,t1.F_ALTA_70 FALTA70,t1.USU_ALTA_70 USUALTA70, t1.ID_TIPO_DOC_70 IDTIPODOC70, t2.DESC_ES_36 DESCES36, t2.DESC_EU_36 DESCEU36 ");
		// FROM
		query.append("FROM DOCU_AVISOS t1, MAESTRO_TIPOS_DOC t2 ");
		// TABLAS_ALIAS
		List<String> from_alias = new ArrayList<String>();
		from_alias.add(" t1 ");
		from_alias.add(" t2 ");

		// FILTRADO
		Map<String, ?> mapaWhereFilter = this.getWhereLikeMap(filterParams, startsWith);
		StringBuilder where = new StringBuilder(" WHERE 1=1 ");
		where.append("AND t2.ID_TIPO_DOC_36 = t1.ID_TIPO_DOC_70 (+)");
		where.append(mapaWhereFilter.get("query"));
		query.append(where);
		// Filter params
		@SuppressWarnings("unchecked")
		List<Object> filterParamList = (List<Object>) mapaWhereFilter.get("params");

		// BUSQUEDA
		Map<String, Object> mapaWhereSearch = this.getWhereLikeMap(searchParams, startsWith);
		String searchSQL = ((StringBuilder) mapaWhereSearch.get("query")).toString();
		// Search params
		@SuppressWarnings("unchecked")
		List<Object> searchParamList = (List<Object>) mapaWhereSearch.get("params");

		// SQL
		StringBuilder sbReorderSelectionSQL = TableManager.getSearchQuery(query, tableRequestDto, DocuAvisos.class,
				filterParamList, searchSQL, searchParamList, from_alias, "IDDOCAVISO70");

		return this.jdbcTemplate.query(sbReorderSelectionSQL.toString(),
				new RowNumResultSetExtractor<DocuAvisos>(this.rwMapPK, tableRequestDto), filterParamList.toArray());
	}

	/**
	 * Remove multiple method for rup_table
	 *
	 * @param tableRequestDto TableRequestDto
	 */
	@Override
	public void removeMultiple(TableRequestDto tableRequestDto) {
		StringBuilder sbRemoveMultipleSQL = TableManager.getRemoveMultipleQuery(tableRequestDto, DocuAvisos.class,
				"DOCU_AVISOS", new String[] { "IDDOCAVISO70" });

		List<String> params = tableRequestDto.getMultiselection().getSelectedIds();

		this.jdbcTemplate.update(sbRemoveMultipleSQL.toString(), params.toArray());
	}

	/**
	 * Filter in the hierarchical DocuAvisos table.
	 *
	 * @param filterDocuAvisos DocuAvisos
	 * @param tableRequestDto  TableRequestDto
	 * @return List<JerarquiaDto<DocuAvisos>>
	 */
	@Override
	public List<JerarquiaDto<DocuAvisos>> findAllLikeJerarquia(DocuAvisos filterDocuAvisos,
			TableRequestDto tableRequestDto) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_DOC_AVISO_70 IDDOCAVISO70,t1.ID_AVISO_70 IDAVISO70,t1.RUTA_70 RUTA70,t1.NOMBRE_DOC_70 NOMBREDOC70,t1.EXTENSION_70 EXTENSION70,t1.F_ALTA_70 FALTA70,t1.USU_ALTA_70 USUALTA70 ");
		// FROM
		// StringBuilder from = new StringBuilder("FROM DOCU_AVISOS t1 ");
		List<String> from = new ArrayList<String>();
		from.add("DOCU_AVISOS");
		// TABLAS_ALIAS
		List<String> from_alias = new ArrayList<String>();
		from_alias.add(" t1 ");

		// JOINS TABLAS
		/*
		 * Ejemplo de como indicar joins entre las tablas de la query
		 */
		/*
		 * StringBuilder joins = new StringBuilder("");
		 * joins.append("AND T1.ID=T2.ID_T1");
		 */

		// CONDICIONES (negocio)
		/*
		 * Ejemplo de como incluir condiciones de negocio en la consulta de la jerarquía
		 */
		/*
		 * StringBuilder businessFilters = new StringBuilder(); List<Object>
		 * businessParams = new ArrayList<Object>();
		 * businessFilters.append("   AND t1.EJIE = ?  "); businessParams.add("1");
		 */

		// FILTRO
		Map<String, ?> mapaWhere = this.getWhereLikeMap(filterDocuAvisos, false);

		// JERARQUIA
		// Especificar la columna padre correspondiente en lugar de la generada por
		// defecto (ID_PADRE)
		query = TableManagerJerarquia.getQuery(tableRequestDto, query, mapaWhere, "IDDOCAVISO70", "ID_PADRE", "NOMBRE",
				from, from_alias);

		/*
		 * Ejemplo de llamada en caso de indicar joins entre tablas y condiciones de
		 * negocio
		 */
//		query = TableManagerJerarquia.getQuery(tableRequestDto, query, mapaWhere, "ID", "ID_PADRE", "NOMBRE", from, from_alias, joins, businessFilters, businessParams);

		// PAGINACION
		if (tableRequestDto != null) {
			query = TableManagerJerarquia.getPaginationQuery(tableRequestDto, query,
					DocuAvisosDaoImpl.ORDER_BY_WHITE_LIST);
		}

		List<?> params = (List<?>) mapaWhere.get("params");
		return this.jdbcTemplate.query(query.toString(), this.rwMapJerarquia, params.toArray());
	}

	/**
	 * Count rows in hierarchy
	 *
	 * @param filterDocuAvisos DocuAvisos
	 * @param tableRequestDto  TableRequestDto
	 * @return Long
	 */
	@Override
	public Long findAllLikeCountJerarquia(DocuAvisos filterDocuAvisos, TableRequestDto tableRequestDto) {
		// FROM
		// StringBuilder from = new StringBuilder("FROM DOCU_AVISOS t1 ");
		List<String> from = new ArrayList<String>();
		from.add("DOCU_AVISOS");

		// TABLAS_ALIAS
		List<String> from_alias = new ArrayList<String>();
		from_alias.add(" t1 ");

		// JOINS TABLAS
		/*
		 * Ejemplo de como indicar joins entre las tablas de la query
		 */
		/*
		 * StringBuilder joins = new StringBuilder("");
		 * joins.append("AND T1.ID=T2.ID_T1");
		 */

		// CONDICIONES (negocio)
		/*
		 * Ejemplo de como incluir condiciones de negocio en la consulta de la jerarquía
		 */
		/*
		 * StringBuilder businessFilters = new StringBuilder(); List<Object>
		 * businessParams = new ArrayList<Object>();
		 * businessFilters.append("   AND t1.EJIE = ?  "); businessParams.add("1");
		 */

		// FILTRO
		Map<String, ?> mapaWhere = this.getWhereLikeMap(filterDocuAvisos, false);

		// JERARQUIA
		// Especificar la columna padre correspondiente en lugar de la generada por
		// defecto (ID_PADRE)
		StringBuilder query = TableManagerJerarquia.getQueryCount(tableRequestDto, mapaWhere, "IDDOCAVISO70",
				"ID_PADRE", from, from_alias);

		/*
		 * Ejemplo de llamada en caso de indicar joins entre tablas y condiciones de
		 * negocio
		 */
//		StringBuilder query = TableManagerJerarquia.getQueryCount(tableRequestDto, mapaWhere, "ID", "ID_PADRE", from, from_alias, joins, businessFilters, businessParams);

		List<?> params = (List<?>) mapaWhere.get("params");
		return this.jdbcTemplate.queryForObject(query.toString(), params.toArray(), Long.class);
	}

	/**
	 * Find dependent hierarchical rows
	 *
	 * @param filterDocuAvisos DocuAvisos
	 * @param tableRequestDto  TableRequestDto
	 * @return List<TableRowDto<DocuAvisos>>
	 */
	@Override
	public List<TableRowDto<DocuAvisos>> findAllChild(DocuAvisos filterDocuAvisos, TableRequestDto tableRequestDto) {

		// FROM
		// StringBuilder from = new StringBuilder("FROM DOCU_AVISOS t1 ");
		List<String> from = new ArrayList<String>();
		from.add("DOCU_AVISOS");

		// TABLAS_ALIAS
		List<String> from_alias = new ArrayList<String>();
		from_alias.add(" t1 ");

		// JOINS TABLAS
		/*
		 * Ejemplo de como indicar joins entre las tablas de la query
		 */
		/*
		 * StringBuilder joins = new StringBuilder("");
		 * joins.append("AND T1.ID=T2.ID_T1");
		 */

		// CONDICIONES (negocio)
		/*
		 * Ejemplo de como incluir condiciones de negocio en la consulta de la jerarquía
		 */
		/*
		 * StringBuilder businessFilters = new StringBuilder(); List<Object>
		 * businessParams = new ArrayList<Object>();
		 * businessFilters.append("   AND t1.EJIE = ?  "); businessParams.add("1");
		 */

		// FILTRO
		Map<String, ?> mapaWhere = this.getWhereLikeMap(filterDocuAvisos, false);

		// MULTISELECCION
		// Especificar la columna padre correspondiente en lugar de la generada por
		// defecto (ID_PADRE)
		StringBuilder query = TableManagerJerarquia.getQueryChildren(tableRequestDto, mapaWhere, "IDDOCAVISO70",
				"ID_PADRE", from, from_alias);

		/*
		 * Ejemplo de llamada en caso de indicar joins entre tablas y condiciones de
		 * negocio
		 */
//		StringBuilder query = TableManagerJerarquia.getQueryChildren(tableRequestDto, mapaWhere, "ID", "ID_PADRE", from, from_alias, joins, businessFilters, businessParams);

		List<?> params = (List<?>) mapaWhere.get("params");

		return this.jdbcTemplate.query(query.toString(),
				new RowNumResultSetExtractor<DocuAvisos>(this.rwMapPK, "IDDOCAVISO70"), params.toArray());
	}

	/*
	 * MÉTODOS PRIVADOS
	 */

	/**
	 * Returns a map with the needed value to create the conditions to filter by the
	 * DocuAvisos entity
	 *
	 * @param docuavisos DocuAvisos Bean with the criteria values to filter by.
	 * @return Map created with two keys key query stores the sql query syntax key
	 *         params stores the parameter values to be used in the condition
	 *         sentence.
	 */
	// CHECKSTYLE:OFF CyclomaticComplexity - Generación de código de UDA
	private Map<String, ?> getWhereMap(DocuAvisos docuavisos) {

		StringBuilder where = new StringBuilder(DocuAvisosDaoImpl.STRING_BUILDER_INIT);
		List<Object> params = new ArrayList<Object>();

		if (docuavisos != null && docuavisos.getIdDocAviso70() != null) {
			where.append(" AND t1.ID_DOC_AVISO_70 = ?");
			params.add(docuavisos.getIdDocAviso70());
		}
		if (docuavisos != null && docuavisos.getIdAviso70() != null) {
			where.append(" AND t1.ID_AVISO_70 = ?");
			params.add(docuavisos.getIdAviso70());
		}
		if (docuavisos != null && docuavisos.getRuta70() != null) {
			where.append(" AND t1.RUTA_70 = ?");
			params.add(docuavisos.getRuta70());
		}
		if (docuavisos != null && docuavisos.getNombreDoc70() != null) {
			where.append(" AND t1.NOMBRE_DOC_70 = ?");
			params.add(docuavisos.getNombreDoc70());
		}
		if (docuavisos != null && docuavisos.getExtension70() != null) {
			where.append(" AND t1.EXTENSION_70 = ?");
			params.add(docuavisos.getExtension70());
		}
		if (docuavisos != null && docuavisos.getfecAlta70() != null) {
			where.append(" AND t1.F_ALTA_70 = ?");
			params.add(docuavisos.getfecAlta70());
		}
		if (docuavisos != null && docuavisos.getUsuAlta70() != null) {
			where.append(" AND t1.USU_ALTA_70 = ?");
			params.add(docuavisos.getUsuAlta70());
		}

		Map<String, Object> mapWhere = new HashMap<String, Object>();
		mapWhere.put("query", where);
		mapWhere.put("params", params);

		return mapWhere;
	}
	// CHECKSTYLE:ON CyclomaticComplexity - Generación de código de UDA

	/**
	 * Returns a map with the needed value to create the conditions to filter by the
	 * DocuAvisos entity
	 *
	 * @param docuavisos DocuAvisos Bean with the criteria values to filter by.
	 * @param startsWith Boolean
	 * @return Map created with two keys key query stores the sql query syntax key
	 *         params stores the parameter values to be used in the condition
	 *         sentence.
	 */
	// CHECKSTYLE:OFF CyclomaticComplexity - Generación de código de UDA
	private Map<String, Object> getWhereLikeMap(DocuAvisos docuavisos, Boolean startsWith) {

		StringBuilder where = new StringBuilder(DocuAvisosDaoImpl.STRING_BUILDER_INIT);
		List<Object> params = new ArrayList<Object>();

		if (docuavisos != null && docuavisos.getIdDocAviso70() != null) {
			where.append(" AND t1.ID_DOC_AVISO_70 = ?");
			params.add(docuavisos.getIdDocAviso70());
		}
		if (docuavisos != null && docuavisos.getIdAviso70() != null) {
			where.append(" AND t1.ID_AVISO_70 = ?");
			params.add(docuavisos.getIdAviso70());
		}
		if (docuavisos != null && docuavisos.getRuta70() != null) {
			where.append(" AND UPPER(t1.RUTA_70) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(docuavisos.getRuta70().toUpperCase() + "%");
			} else {
				params.add("%" + docuavisos.getRuta70().toUpperCase() + "%");
			}
			where.append(" AND t1.RUTA_70 IS NOT NULL");
		}
		if (docuavisos != null && docuavisos.getNombreDoc70() != null) {
			where.append(" AND UPPER(t1.NOMBRE_DOC_70) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(docuavisos.getNombreDoc70().toUpperCase() + "%");
			} else {
				params.add("%" + docuavisos.getNombreDoc70().toUpperCase() + "%");
			}
			where.append(" AND t1.NOMBRE_DOC_70 IS NOT NULL");
		}
		if (docuavisos != null && docuavisos.getExtension70() != null) {
			where.append(" AND UPPER(t1.EXTENSION_70) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(docuavisos.getExtension70().toUpperCase() + "%");
			} else {
				params.add("%" + docuavisos.getExtension70().toUpperCase() + "%");
			}
			where.append(" AND t1.EXTENSION_70 IS NOT NULL");
		}
		if (docuavisos != null && docuavisos.getfecAlta70() != null) {
			where.append(" AND t1.F_ALTA_70 = ?");
			params.add(docuavisos.getfecAlta70());
		}
		if (docuavisos != null && docuavisos.getUsuAlta70() != null) {
			where.append(" AND UPPER(t1.USU_ALTA_70) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(docuavisos.getUsuAlta70().toUpperCase() + "%");
			} else {
				params.add("%" + docuavisos.getUsuAlta70().toUpperCase() + "%");
			}
			where.append(" AND t1.USU_ALTA_70 IS NOT NULL");
		}

		Map<String, Object> mapWhere = new HashMap<String, Object>();
		mapWhere.put("query", where);
		mapWhere.put("params", params);

		return mapWhere;
	}
	// CHECKSTYLE:ON CyclomaticComplexity - Generación de código de UDA

	/**
	 * StringBuilder initilization value
	 */
	public static final int STRING_BUILDER_INIT = 4096;
}
