package com.ejie.ad74a.dao;

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.MaestroTramites;
import com.ejie.ad74a.model.TareasTramite;
import com.ejie.ad74a.model.TramitesExpediente;
import com.ejie.ad74a.util.UtilSQL;
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;

/**
 * TramitesExpedienteDaoImpl generated by UDA, 22-mar-2023 17:10:15.
 * 
 * @author UDA
 */

@Repository
@Transactional
public class TramitesExpedienteDaoImpl implements TramitesExpedienteDao {

	public static final String[] ORDER_BY_WHITE_LIST = new String[] { "IDTRAMITEEXP10", "IDEXPEDIENTE10", "IDESTADO10",
			"FINICIO10", "FREALIZACION10", "OBSERVACIONES10", "FALTA10", "USUALTA10", "FMODIF10", "USUMODIF10",
			"MATRAIDTRAMITE37", "MATRADESCES37", "MATRADESCEU37", "TIPOESTUDIODOC10" };

	private JdbcTemplate jdbcTemplate;

	public static final String SEQUENCE_TRAMITES_EXP = "SEQ_TRAMITES_EXP";

	/*
	 * ROW_MAPPERS
	 */
	private RowMapper<TramitesExpediente> rwMap = new RowMapper<TramitesExpediente>() {
		public TramitesExpediente mapRow(ResultSet resultSet, int rowNum) throws SQLException {
			TramitesExpediente tramitesExpediente = new TramitesExpediente(UtilSQL.getLong(resultSet, "IDTRAMITEEXP10"),
					UtilSQL.getLong(resultSet, "IDEXPEDIENTE10"), resultSet.getString("IDESTADO10"),
					resultSet.getTimestamp("FINICIO10"), resultSet.getTimestamp("FREALIZACION10"),
					resultSet.getString("OBSERVACIONES10"), resultSet.getTimestamp("FALTA10"),
					resultSet.getString("USUALTA10"), resultSet.getTimestamp("FMODIF10"),
					resultSet.getString("USUMODIF10"),
					new MaestroTramites(UtilSQL.getLong(resultSet, "MATRAIDTRAMITE37"),
							resultSet.getString("MATRADESCES37"), resultSet.getString("MATRADESCEU37")),
					UtilSQL.getLong(resultSet, "TIPOESTUDIODOC10"));
			tramitesExpediente.setTareaTramite(new TareasTramite(UtilSQL.getLong(resultSet, "IDTAREATRAM11")));
			return tramitesExpediente;
		}
	};

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

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

			TramitesExpediente tramitesexpediente = new TramitesExpediente(UtilSQL.getLong(resultSet, "IDTRAMITEEXP10"),
					UtilSQL.getLong(resultSet, "IDEXPEDIENTE10"), resultSet.getString("IDESTADO10"),
					resultSet.getTimestamp("FINICIO10"), resultSet.getTimestamp("FREALIZACION10"),
					resultSet.getString("OBSERVACIONES10"), resultSet.getTimestamp("FALTA10"),
					resultSet.getString("USUALTA10"), resultSet.getTimestamp("FMODIF10"),
					resultSet.getString("USUMODIF10"),
					new MaestroTramites(UtilSQL.getLong(resultSet, "MATRAIDTRAMITE37"),
							resultSet.getString("MATRADESCES37"), resultSet.getString("MATRADESCEU37")),
					UtilSQL.getLong(resultSet, "TIPOESTUDIODOC10"));

			JerarquiaDto<TramitesExpediente> jerarquia = new JerarquiaDto<TramitesExpediente>();
			jerarquia.setModel(tramitesexpediente);
			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 TramitesExpediente table.
	 *
	 * @param tramitesexpediente TramitesExpediente
	 * @return TramitesExpediente
	 */
	public TramitesExpediente add(TramitesExpediente tramitesexpediente) {

		GeneratedKeyHolder generatedKeyHolder = new GeneratedKeyHolder();

		String query = "INSERT INTO TRAMITES_EXPEDIENTE (ID_TRAMITE_EXP_10, ID_TRAMITE_10, ID_EXPEDIENTE_10, ID_ESTADO_10, F_INICIO_10, F_REALIZACION_10, OBSERVACIONES_10, F_ALTA_10, USU_ALTA_10, F_MODIF_10, USU_MODIF_10,TIPO_ESTUDIO_DOC_10 ) "
				+ "VALUES (" + SEQUENCE_TRAMITES_EXP
				+ ".NEXTVAL,:idTramite,:idExpediente,:idEstado,:fInicio,:fRealizacion,:observaciones,sysdate,:usuAlta,sysdate,:usuModif,:tipoEstudioDoc10)";
		Object getMaestroTramitesIdTramite37Aux = null;
		if (tramitesexpediente.getMaestroTramites() != null
				&& tramitesexpediente.getMaestroTramites().getIdTramite37() != null) {
			getMaestroTramitesIdTramite37Aux = tramitesexpediente.getMaestroTramites().getIdTramite37();
		}
		MapSqlParameterSource parameters = new MapSqlParameterSource()
				.addValue("idTramite", getMaestroTramitesIdTramite37Aux)
				.addValue("idExpediente", tramitesexpediente.getIdExpediente10())
				.addValue("idEstado", tramitesexpediente.getIdEstado10())
				.addValue("fInicio", tramitesexpediente.getfInicio10())
				.addValue("fRealizacion", tramitesexpediente.getfRealizacion10())
				.addValue("observaciones", tramitesexpediente.getObservaciones10())
				.addValue("usuAlta", tramitesexpediente.getUsuAlta10())
				.addValue("tipoEstudioDoc10", tramitesexpediente.getTipoEstudioDoc10())
				.addValue("usuModif", tramitesexpediente.getUsuModif10());

		NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
		namedParameterJdbcTemplate.update(query, parameters, generatedKeyHolder, new String[] { "ID_TRAMITE_EXP_10" });
		tramitesexpediente.setIdTramiteExp10(generatedKeyHolder.getKey().longValue());

		return tramitesexpediente;
	}

	/**
	 * Updates a single row in the TramitesExpediente table.
	 *
	 * @param tramitesexpediente TramitesExpediente
	 * @return TramitesExpediente
	 */
	public TramitesExpediente update(TramitesExpediente tramitesexpediente) {
		String query = "UPDATE TRAMITES_EXPEDIENTE SET ID_TRAMITE_10=?, ID_EXPEDIENTE_10=?, ID_ESTADO_10=?, F_INICIO_10=?, F_REALIZACION_10=?, OBSERVACIONES_10=?, F_ALTA_10=?, USU_ALTA_10=?, F_MODIF_10=?, USU_MODIF_10=?, TIPO_ESTUDIO_DOC_10 = ? WHERE ID_TRAMITE_EXP_10=?";
		Object getMaestroTramitesIdTramite37Aux = null;
		if (tramitesexpediente.getMaestroTramites() != null
				&& tramitesexpediente.getMaestroTramites().getIdTramite37() != null) {
			getMaestroTramitesIdTramite37Aux = tramitesexpediente.getMaestroTramites().getIdTramite37();
		}
		this.jdbcTemplate.update(query, getMaestroTramitesIdTramite37Aux, tramitesexpediente.getIdExpediente10(),
				tramitesexpediente.getIdEstado10(), tramitesexpediente.getfInicio10(),
				tramitesexpediente.getfRealizacion10(), tramitesexpediente.getObservaciones10(),
				tramitesexpediente.getfAlta10(), tramitesexpediente.getUsuAlta10(), tramitesexpediente.getfModif10(),
				tramitesexpediente.getUsuModif10(), tramitesexpediente.getTipoEstudioDoc10(),
				tramitesexpediente.getIdTramiteExp10());
		return tramitesexpediente;
	}

	/**
	 * Finds a single row in the TramitesExpediente table.
	 *
	 * @param tramitesexpediente TramitesExpediente
	 * @return TramitesExpediente
	 */
	@Transactional(readOnly = true)
	public TramitesExpediente find(TramitesExpediente tramitesexpediente) {
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_TRAMITE_EXP_10 IDTRAMITEEXP10, t1.ID_EXPEDIENTE_10 IDEXPEDIENTE10, t1.ID_ESTADO_10 IDESTADO10, t1.F_INICIO_10 FINICIO10, t1.F_REALIZACION_10 FREALIZACION10, t1.OBSERVACIONES_10 OBSERVACIONES10, t1.F_ALTA_10 FALTA10, t1.USU_ALTA_10 USUALTA10, t1.F_MODIF_10 FMODIF10, t1.USU_MODIF_10 USUMODIF10,t1.TIPO_ESTUDIO_DOC_10 TIPOESTUDIODOC10, t2.ID_TRAMITE_37 MATRAIDTRAMITE37, t2.DESC_ES_37 MATRADESCES37, t2.DESC_EU_37 MATRADESCEU37 ");
		query.append(
				",(select tt.ID_TAREA_TRAM_11 from TAREAS_TRAMITE tt where tt.ID_TRAMITE_EXP_11 =  t1.id_tramite_exp_10 and tt.f_fin_11 is null and tt.ID_ESTADO_11 = 1) IDTAREATRAM11 ");
		query.append(
				" FROM TRAMITES_EXPEDIENTE t1 , MAESTRO_TRAMITES t2  WHERE t1.ID_TRAMITE_EXP_10 = ?   AND t1.ID_TRAMITE_10= t2.ID_TRAMITE_37(+) ");

		List<TramitesExpediente> tramitesexpedienteList = this.jdbcTemplate.query(query.toString(), this.rwMap,
				tramitesexpediente.getIdTramiteExp10());
		return (TramitesExpediente) DataAccessUtils.uniqueResult(tramitesexpedienteList);
	}

	@Transactional(readOnly = true)
	public TramitesExpediente findTramiteByTaskGUID(TramitesExpediente tramitesexpediente) {
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_TRAMITE_EXP_10 IDTRAMITEEXP10, t1.ID_EXPEDIENTE_10 IDEXPEDIENTE10, t1.ID_ESTADO_10 IDESTADO10, t1.F_INICIO_10 FINICIO10, t1.F_REALIZACION_10 FREALIZACION10, t1.OBSERVACIONES_10 OBSERVACIONES10, t1.F_ALTA_10 FALTA10, t1.USU_ALTA_10 USUALTA10, t1.F_MODIF_10 FMODIF10, t1.USU_MODIF_10 USUMODIF10,t1.TIPO_ESTUDIO_DOC_10 TIPOESTUDIODOC10, t2.ID_TRAMITE_37 MATRAIDTRAMITE37, t2.DESC_ES_37 MATRADESCES37, t2.DESC_EU_37 MATRADESCEU37 ");
		query.append(",null IDTAREATRAM11 ");
		query.append(
				" FROM TRAMITES_EXPEDIENTE t1 LEFT JOIN  MAESTRO_TRAMITES t2 ON (t1.ID_TRAMITE_10= t2.ID_TRAMITE_37) LEFT JOIN TAREAS_TRAMITE t3 ON (t3.ID_TRAMITE_EXP_11 = t1.ID_TRAMITE_EXP_10)  WHERE t3.TASKGUID_11 = ?   AND t1.TIPO_ESTUDIO_DOC_10=0");

		String taskGUID = null;
		if (tramitesexpediente != null && tramitesexpediente.getTareaTramite() != null) {
			taskGUID = tramitesexpediente.getTareaTramite().getTaskguid11();
		}

		List<TramitesExpediente> tramitesexpedienteList = this.jdbcTemplate.query(query.toString(), this.rwMap,
				taskGUID);
		return (TramitesExpediente) DataAccessUtils.uniqueResult(tramitesexpedienteList);
	}

	/**
	 * Removes a single row in the TramitesExpediente table.
	 *
	 * @param tramitesexpediente TramitesExpediente
	 * @return
	 */
	public void remove(TramitesExpediente tramitesexpediente) {
		String query = "DELETE FROM TRAMITES_EXPEDIENTE WHERE ID_TRAMITE_EXP_10=?";
		this.jdbcTemplate.update(query, tramitesexpediente.getIdTramiteExp10());
	}

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

		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_TRAMITE_EXP_10 IDTRAMITEEXP10, t1.ID_EXPEDIENTE_10 IDEXPEDIENTE10, t1.ID_ESTADO_10 IDESTADO10, t1.F_INICIO_10 FINICIO10, t1.F_REALIZACION_10 FREALIZACION10, t1.OBSERVACIONES_10 OBSERVACIONES10, t1.F_ALTA_10 FALTA10, t1.USU_ALTA_10 USUALTA10, t1.F_MODIF_10 FMODIF10, t1.USU_MODIF_10 USUMODIF10,t1.TIPO_ESTUDIO_DOC_10 TIPOESTUDIODOC10, t2.ID_TRAMITE_37 MATRAIDTRAMITE37, t2.DESC_ES_37 MATRADESCES37, t2.DESC_EU_37 MATRADESCEU37");
		query.append(
				",(select tt.ID_TAREA_TRAM_11 from TAREAS_TRAMITE tt where tt.ID_TRAMITE_EXP_11 =  t1.id_tramite_exp_10 and tt.f_fin_11 is null and tt.ID_ESTADO_11 = 1) IDTAREATRAM11 ");
		query.append(" FROM TRAMITES_EXPEDIENTE t1 , MAESTRO_TRAMITES t2  ");
		// Where clause & Params
		Map<String, Object> mapaWhere = this.getWhereLikeMap(filterTramitesExpediente, startsWith);
		StringBuilder where = new StringBuilder(query + " WHERE 1=1 ");
		where.append(mapaWhere.get("query"));

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

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

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

	/**
	 * Finds a list of rows in the TramitesExpediente table.
	 *
	 * @param tramitesexpediente TramitesExpediente
	 * @param tableRequestDto    TableRequestDto
	 * @return List<TramitesExpediente>
	 */
	@Transactional(readOnly = true)
	public List<TramitesExpediente> findAll(TramitesExpediente tramitesexpediente, TableRequestDto tableRequestDto) {
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_TRAMITE_EXP_10 IDTRAMITEEXP10,t1.ID_EXPEDIENTE_10 IDEXPEDIENTE10,t1.ID_ESTADO_10 IDESTADO10,t1.F_INICIO_10 FINICIO10,t1.F_REALIZACION_10 FREALIZACION10,t1.OBSERVACIONES_10 OBSERVACIONES10,t1.F_ALTA_10 FALTA10,t1.USU_ALTA_10 USUALTA10,t1.F_MODIF_10 FMODIF10,t1.USU_MODIF_10 USUMODIF10,t1.TIPO_ESTUDIO_DOC_10 TIPOESTUDIODOC10,t2.ID_TRAMITE_37 MATRAIDTRAMITE37,t2.DESC_ES_37 MATRADESCES37,t2.DESC_EU_37 MATRADESCEU37 ");
		query.append(
				",(select tt.ID_TAREA_TRAM_11 from TAREAS_TRAMITE tt where tt.ID_TRAMITE_EXP_11 =  t1.id_tramite_exp_10 and tt.f_fin_11 is null and tt.ID_ESTADO_11 = 1) IDTAREATRAM11 ");
		query.append("FROM TRAMITES_EXPEDIENTE t1 ,MAESTRO_TRAMITES t2 ");

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

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

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

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

	/**
	 * Finds rows in the TramitesExpediente table using like.
	 *
	 * @param tramitesexpediente TramitesExpediente
	 * @param tableRequestDto    TableRequestDto
	 * @param startsWith         Boolean
	 * @return List<TramitesExpediente>
	 */
	@Transactional(readOnly = true)
	public List<TramitesExpediente> findAllLike(TramitesExpediente tramitesexpediente, TableRequestDto tableRequestDto,
			Boolean startsWith) {
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_TRAMITE_EXP_10 IDTRAMITEEXP10,t1.ID_EXPEDIENTE_10 IDEXPEDIENTE10,t1.ID_ESTADO_10 IDESTADO10,t1.F_INICIO_10 FINICIO10,t1.F_REALIZACION_10 FREALIZACION10,t1.OBSERVACIONES_10 OBSERVACIONES10,t1.F_ALTA_10 FALTA10,t1.USU_ALTA_10 USUALTA10,t1.F_MODIF_10 FMODIF10,t1.USU_MODIF_10 USUMODIF10,t1.TIPO_ESTUDIO_DOC_10 TIPOESTUDIODOC10,t2.ID_TRAMITE_37 MATRAIDTRAMITE37,t2.DESC_ES_37 MATRADESCES37,t2.DESC_EU_37 MATRADESCEU37 ");
		query.append(
				",(select tt.ID_TAREA_TRAM_11 from TAREAS_TRAMITE tt where tt.ID_TRAMITE_EXP_11 =  t1.id_tramite_exp_10 and tt.f_fin_11 is null and tt.ID_ESTADO_11 = 1) IDTAREATRAM11 ");
		query.append("FROM TRAMITES_EXPEDIENTE t1 ,MAESTRO_TRAMITES t2 ");

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

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

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

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

	/*
	 * OPERACIONES RUP_TABLE
	 */

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

		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereMap(tramitesexpediente);
		StringBuilder where = new StringBuilder(" WHERE 1=1 AND t1.ID_TRAMITE_10= t2.ID_TRAMITE_37(+) ");
		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 TramitesExpediente table using like.
	 *
	 * @param tramitesexpediente TramitesExpediente
	 * @param startsWith         Boolean
	 * @return Long
	 */
	@Transactional(readOnly = true)
	public Long findAllLikeCount(TramitesExpediente tramitesexpediente, Boolean startsWith) {
		StringBuilder query = new StringBuilder("SELECT COUNT(1) FROM TRAMITES_EXPEDIENTE t1 ,MAESTRO_TRAMITES t2 ");

		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(tramitesexpediente, startsWith);
		StringBuilder where = new StringBuilder(" WHERE 1=1 AND t1.ID_TRAMITE_10= t2.ID_TRAMITE_37(+) ");
		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 TramitesExpediente selected for rup_table
	 *
	 * @param tramitesexpediente TramitesExpediente
	 * @param tableRequestDto    TableRequestDto
	 * @param startsWith         Boolean
	 * @return List<TableRowDto<TramitesExpediente>>
	 */
	@Override
	public List<TableRowDto<TramitesExpediente>> reorderSelection(TramitesExpediente tramitesexpediente,
			TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_TRAMITE_EXP_10 IDTRAMITEEXP10,t1.ID_EXPEDIENTE_10 IDEXPEDIENTE10,t1.ID_ESTADO_10 IDESTADO10,t1.F_INICIO_10 FINICIO10,t1.F_REALIZACION_10 FREALIZACION10,t1.OBSERVACIONES_10 OBSERVACIONES10,t1.F_ALTA_10 FALTA10,t1.USU_ALTA_10 USUALTA10,t1.F_MODIF_10 FMODIF10,t1.USU_MODIF_10 USUMODIF10,t2.ID_TRAMITE_37 MATRAIDTRAMITE37,t2.DESC_ES_37 MATRADESCES37,t2.DESC_EU_37 MATRADESCEU37 ");
		// FROM
		query.append("FROM TRAMITES_EXPEDIENTE t1 ,MAESTRO_TRAMITES t2 ");
		// FILTRADO
		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(tramitesexpediente, startsWith);
		StringBuilder where = new StringBuilder(" WHERE 1=1 AND t1.ID_TRAMITE_10= t2.ID_TRAMITE_37(+) ");
		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,
				TramitesExpediente.class, filterParamList, "IDTRAMITEEXP10");

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

	/**
	 * Search method for rup_table
	 *
	 * @param filterParams    TramitesExpediente
	 * @param searchParams    TramitesExpediente
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 * @return List<TableRowDto<TramitesExpediente>>
	 */
	@Override
	public List<TableRowDto<TramitesExpediente>> search(TramitesExpediente filterParams,
			TramitesExpediente searchParams, TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_TRAMITE_EXP_10 IDTRAMITEEXP10,t1.ID_EXPEDIENTE_10 IDEXPEDIENTE10,t1.ID_ESTADO_10 IDESTADO10,t1.F_INICIO_10 FINICIO10,t1.F_REALIZACION_10 FREALIZACION10,t1.OBSERVACIONES_10 OBSERVACIONES10,t1.F_ALTA_10 FALTA10,t1.USU_ALTA_10 USUALTA10,t1.F_MODIF_10 FMODIF10,t1.USU_MODIF_10 USUMODIF10,t2.ID_TRAMITE_37 MATRAIDTRAMITE37,t2.DESC_ES_37 MATRADESCES37,t2.DESC_EU_37 MATRADESCEU37 ");
		// FROM
		query.append("FROM TRAMITES_EXPEDIENTE t1 ,MAESTRO_TRAMITES 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 AND t1.ID_TRAMITE_10= t2.ID_TRAMITE_37(+) ");
		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,
				TramitesExpediente.class, filterParamList, searchSQL, searchParamList, from_alias, "IDTRAMITEEXP10");

		return this.jdbcTemplate.query(sbReorderSelectionSQL.toString(),
				new RowNumResultSetExtractor<TramitesExpediente>(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,
				TramitesExpediente.class, "TRAMITES_EXPEDIENTE", new String[] { "IDTRAMITEEXP10" });

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

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

	/**
	 * Filter in the hierarchical TramitesExpediente table.
	 *
	 * @param filterTramitesExpediente TramitesExpediente
	 * @param tableRequestDto          TableRequestDto
	 * @return List<JerarquiaDto<TramitesExpediente>>
	 */
	@Override
	public List<JerarquiaDto<TramitesExpediente>> findAllLikeJerarquia(TramitesExpediente filterTramitesExpediente,
			TableRequestDto tableRequestDto) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_TRAMITE_EXP_10 IDTRAMITEEXP10,t1.ID_EXPEDIENTE_10 IDEXPEDIENTE10,t1.ID_ESTADO_10 IDESTADO10,t1.F_INICIO_10 FINICIO10,t1.F_REALIZACION_10 FREALIZACION10,t1.OBSERVACIONES_10 OBSERVACIONES10,t1.F_ALTA_10 FALTA10,t1.USU_ALTA_10 USUALTA10,t1.F_MODIF_10 FMODIF10,t1.USU_MODIF_10 USUMODIF10,t1.TIPO_ESTUDIO_DOC_10 TIPOESTUDIODOC10,t2.ID_TRAMITE_37 MATRAIDTRAMITE37,t2.DESC_ES_37 MATRADESCES37,t2.DESC_EU_37 MATRADESCEU37 ");
		// FROM
		// StringBuilder from = new StringBuilder("FROM TRAMITES_EXPEDIENTE t1
		// ,MAESTRO_TRAMITES t2 ");
		List<String> from = new ArrayList<String>();
		from.add("TRAMITES_EXPEDIENTE");
		from.add("MAESTRO_TRAMITES");
		// TABLAS_ALIAS
		List<String> from_alias = new ArrayList<String>();
		from_alias.add(" t1 ");
		from_alias.add(" t2 ");

		// 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(filterTramitesExpediente, false);

		// JERARQUIA
		// Especificar la columna padre correspondiente en lugar de la generada por
		// defecto (ID_PADRE)
		query = TableManagerJerarquia.getQuery(tableRequestDto, query, mapaWhere, "IDTRAMITEEXP10", "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,
					TramitesExpedienteDaoImpl.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 filterTramitesExpediente TramitesExpediente
	 * @param tableRequestDto          TableRequestDto
	 * @return Long
	 */
	@Override
	public Long findAllLikeCountJerarquia(TramitesExpediente filterTramitesExpediente,
			TableRequestDto tableRequestDto) {
		// FROM
		// StringBuilder from = new StringBuilder("FROM TRAMITES_EXPEDIENTE t1
		// ,MAESTRO_TRAMITES t2 ");
		List<String> from = new ArrayList<String>();
		from.add("TRAMITES_EXPEDIENTE");
		from.add("MAESTRO_TRAMITES");

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

		// 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(filterTramitesExpediente, false);

		// JERARQUIA
		// Especificar la columna padre correspondiente en lugar de la generada por
		// defecto (ID_PADRE)
		StringBuilder query = TableManagerJerarquia.getQueryCount(tableRequestDto, mapaWhere, "IDTRAMITEEXP10",
				"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 filterTramitesExpediente TramitesExpediente
	 * @param tableRequestDto          TableRequestDto
	 * @return List<TableRowDto<TramitesExpediente>>
	 */
	@Override
	public List<TableRowDto<TramitesExpediente>> findAllChild(TramitesExpediente filterTramitesExpediente,
			TableRequestDto tableRequestDto) {

		// FROM
		// StringBuilder from = new StringBuilder("FROM TRAMITES_EXPEDIENTE t1
		// ,MAESTRO_TRAMITES t2 ");
		List<String> from = new ArrayList<String>();
		from.add("TRAMITES_EXPEDIENTE");
		from.add("MAESTRO_TRAMITES");

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

		// 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(filterTramitesExpediente, false);

		// MULTISELECCION
		// Especificar la columna padre correspondiente en lugar de la generada por
		// defecto (ID_PADRE)
		StringBuilder query = TableManagerJerarquia.getQueryChildren(tableRequestDto, mapaWhere, "IDTRAMITEEXP10",
				"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<TramitesExpediente>(this.rwMapPK, "IDTRAMITEEXP10"), params.toArray());
	}

	/*
	 * MÉTODOS PRIVADOS
	 */

	/**
	 * Returns a map with the needed value to create the conditions to filter by the
	 * TramitesExpediente entity
	 *
	 * @param tramitesexpediente TramitesExpediente 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(TramitesExpediente tramitesexpediente) {

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

		if (tramitesexpediente != null && tramitesexpediente.getIdTramiteExp10() != null) {
			where.append(" AND t1.ID_TRAMITE_EXP_10 = ?");
			params.add(tramitesexpediente.getIdTramiteExp10());
		}
		if (tramitesexpediente != null && tramitesexpediente.getMaestroTramites() != null
				&& tramitesexpediente.getMaestroTramites().getIdTramite37() != null) {
			where.append(" AND t2.ID_TRAMITE_37 = ?");
			params.add(tramitesexpediente.getMaestroTramites().getIdTramite37());
		}
		if (tramitesexpediente != null && tramitesexpediente.getMaestroTramites() != null
				&& tramitesexpediente.getMaestroTramites().getDescEs37() != null) {
			where.append(" AND t2.DESC_ES_37 = ?");
			params.add(tramitesexpediente.getMaestroTramites().getDescEs37());
		}
		if (tramitesexpediente != null && tramitesexpediente.getMaestroTramites() != null
				&& tramitesexpediente.getMaestroTramites().getDescEu37() != null) {
			where.append(" AND t2.DESC_EU_37 = ?");
			params.add(tramitesexpediente.getMaestroTramites().getDescEu37());
		}
		if (tramitesexpediente != null && tramitesexpediente.getIdExpediente10() != null) {
			where.append(" AND t1.ID_EXPEDIENTE_10 = ?");
			params.add(tramitesexpediente.getIdExpediente10());
		}
		if (tramitesexpediente != null && tramitesexpediente.getIdEstado10() != null) {
			where.append(" AND t1.ID_ESTADO_10 = ?");
			params.add(tramitesexpediente.getIdEstado10());
		}
		if (tramitesexpediente != null && tramitesexpediente.getfInicio10() != null) {
			where.append(" AND t1.F_INICIO_10 = ?");
			params.add(tramitesexpediente.getfInicio10());
		}
		if (tramitesexpediente != null && tramitesexpediente.getfRealizacion10() != null) {
			where.append(" AND t1.F_REALIZACION_10 = ?");
			params.add(tramitesexpediente.getfRealizacion10());
		}
		if (tramitesexpediente != null && tramitesexpediente.getObservaciones10() != null) {
			where.append(" AND t1.OBSERVACIONES_10 = ?");
			params.add(tramitesexpediente.getObservaciones10());
		}
		if (tramitesexpediente != null && tramitesexpediente.getfAlta10() != null) {
			where.append(" AND t1.F_ALTA_10 = ?");
			params.add(tramitesexpediente.getfAlta10());
		}
		if (tramitesexpediente != null && tramitesexpediente.getUsuAlta10() != null) {
			where.append(" AND t1.USU_ALTA_10 = ?");
			params.add(tramitesexpediente.getUsuAlta10());
		}
		if (tramitesexpediente != null && tramitesexpediente.getfModif10() != null) {
			where.append(" AND t1.F_MODIF_10 = ?");
			params.add(tramitesexpediente.getfModif10());
		}
		if (tramitesexpediente != null && tramitesexpediente.getUsuModif10() != null) {
			where.append(" AND t1.USU_MODIF_10 = ?");
			params.add(tramitesexpediente.getUsuModif10());
		}

		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
	 * TramitesExpediente entity
	 *
	 * @param tramitesexpediente TramitesExpediente 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(TramitesExpediente tramitesexpediente, Boolean startsWith) {

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

		if (tramitesexpediente != null && tramitesexpediente.getIdTramiteExp10() != null) {
			where.append(" AND t1.ID_TRAMITE_EXP_10 = ?");
			params.add(tramitesexpediente.getIdTramiteExp10());
		}
		if (tramitesexpediente != null && tramitesexpediente.getMaestroTramites() != null
				&& tramitesexpediente.getMaestroTramites().getIdTramite37() != null) {
			where.append(" AND t2.ID_TRAMITE_37 = ?");
			params.add(tramitesexpediente.getMaestroTramites().getIdTramite37());
		}
		if (tramitesexpediente != null && tramitesexpediente.getMaestroTramites() != null
				&& tramitesexpediente.getMaestroTramites().getDescEs37() != null) {
			where.append(" AND UPPER(t2.DESC_ES_37) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(tramitesexpediente.getMaestroTramites().getDescEs37().toUpperCase() + "%");
			} else {
				params.add("%" + tramitesexpediente.getMaestroTramites().getDescEs37().toUpperCase() + "%");
			}
			where.append(" AND t2.DESC_ES_37 IS NOT NULL");
		}
		if (tramitesexpediente != null && tramitesexpediente.getMaestroTramites() != null
				&& tramitesexpediente.getMaestroTramites().getDescEu37() != null) {
			where.append(" AND UPPER(t2.DESC_EU_37) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(tramitesexpediente.getMaestroTramites().getDescEu37().toUpperCase() + "%");
			} else {
				params.add("%" + tramitesexpediente.getMaestroTramites().getDescEu37().toUpperCase() + "%");
			}
			where.append(" AND t2.DESC_EU_37 IS NOT NULL");
		}
		if (tramitesexpediente != null && tramitesexpediente.getIdExpediente10() != null) {
			where.append(" AND t1.ID_EXPEDIENTE_10 = ?");
			params.add(tramitesexpediente.getIdExpediente10());
		}
		if (tramitesexpediente != null && tramitesexpediente.getIdEstado10() != null) {
			where.append(" AND t1.ID_ESTADO_10 = ?");
			params.add(tramitesexpediente.getIdEstado10());
		}
		if (tramitesexpediente != null && tramitesexpediente.getfInicio10() != null) {
			where.append(" AND t1.F_INICIO_10 = ?");
			params.add(tramitesexpediente.getfInicio10());
		}
		if (tramitesexpediente != null && tramitesexpediente.getfRealizacion10() != null) {
			where.append(" AND t1.F_REALIZACION_10 = ?");
			params.add(tramitesexpediente.getfRealizacion10());
		}
		if (tramitesexpediente != null && tramitesexpediente.getObservaciones10() != null) {
			where.append(" AND UPPER(t1.OBSERVACIONES_10) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(tramitesexpediente.getObservaciones10().toUpperCase() + "%");
			} else {
				params.add("%" + tramitesexpediente.getObservaciones10().toUpperCase() + "%");
			}
			where.append(" AND t1.OBSERVACIONES_10 IS NOT NULL");
		}
		if (tramitesexpediente != null && tramitesexpediente.getfAlta10() != null) {
			where.append(" AND t1.F_ALTA_10 = ?");
			params.add(tramitesexpediente.getfAlta10());
		}
		if (tramitesexpediente != null && tramitesexpediente.getUsuAlta10() != null) {
			where.append(" AND UPPER(t1.USU_ALTA_10) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(tramitesexpediente.getUsuAlta10().toUpperCase() + "%");
			} else {
				params.add("%" + tramitesexpediente.getUsuAlta10().toUpperCase() + "%");
			}
			where.append(" AND t1.USU_ALTA_10 IS NOT NULL");
		}
		if (tramitesexpediente != null && tramitesexpediente.getfModif10() != null) {
			where.append(" AND t1.F_MODIF_10 = ?");
			params.add(tramitesexpediente.getfModif10());
		}
		if (tramitesexpediente != null && tramitesexpediente.getUsuModif10() != null) {
			where.append(" AND UPPER(t1.USU_MODIF_10) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(tramitesexpediente.getUsuModif10().toUpperCase() + "%");
			} else {
				params.add("%" + tramitesexpediente.getUsuModif10().toUpperCase() + "%");
			}
			where.append(" AND t1.USU_MODIF_10 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;

	/**
	 * Recupera el tramite por codigo de tarea
	 *
	 * @param tramitesexpediente TramitesExpediente
	 * @param tableRequestDto    TableRequestDto
	 * @param startsWith         Boolean
	 * @return List<TableRowDto<TramitesExpediente>>
	 */
	@Override
	public List<TramitesExpediente> getTramiteByCodTarea(TramitesExpediente tramitesexpediente) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_TRAMITE_EXP_10 IDTRAMITEEXP10, t1.ID_EXPEDIENTE_10 IDEXPEDIENTE10, t1.ID_ESTADO_10 IDESTADO10, t1.F_INICIO_10 FINICIO10, t1.F_REALIZACION_10 FREALIZACION10, t1.OBSERVACIONES_10 OBSERVACIONES10, t1.F_ALTA_10 FALTA10, t1.USU_ALTA_10 USUALTA10, t1.F_MODIF_10 FMODIF10, t1.USU_MODIF_10 USUMODIF10,t1.TIPO_ESTUDIO_DOC_10 TIPOESTUDIODOC10, t2.ID_TRAMITE_37 MATRAIDTRAMITE37, t2.DESC_ES_37 MATRADESCES37, t2.DESC_EU_37 MATRADESCEU37 ");
		query.append(
				",(select tt.ID_TAREA_TRAM_11 from TAREAS_TRAMITE tt where tt.ID_TRAMITE_EXP_11 =  t1.id_tramite_exp_10 and tt.f_fin_11 is null and tt.ID_ESTADO_11 = 1) IDTAREATRAM11 ");
		// FROM
		query.append("FROM TRAMITES_EXPEDIENTE t1 , MAESTRO_TRAMITES t2, TAREAS_TRAMITE t3 ");

		// WHERE clause & Params
		StringBuilder where = new StringBuilder(
				" WHERE 1=1 AND t1.ID_TRAMITE_10= t2.ID_TRAMITE_37(+) AND ID_TRAMITE_EXP_10 = ID_TRAMITE_EXP_11 AND ID_TAREA_TRAM_11 = ? ");

		query.append(where);

		List<Integer> params = new ArrayList<Integer>();
		params.add(new Integer(tramitesexpediente.getTareasTramites().get(0).getIdTareaTram11().intValue()));

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

}
