package com.ejie.ad74a.dao;

import java.rmi.UnmarshalException;
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.dao.comun.UtilDAO;
import com.ejie.ad74a.exceptions.ManagerErrors;
import com.ejie.ad74a.model.Avisos;
import com.ejie.ad74a.model.Ayuntamientos;
import com.ejie.ad74a.model.Direcciones;
import com.ejie.ad74a.model.Informes;
import com.ejie.ad74a.model.MaestroActores;
import com.ejie.ad74a.model.MaestroSubtiposAviso;
import com.ejie.ad74a.model.MaestroTiposAviso;
import com.ejie.ad74a.model.Solicitantes;
import com.ejie.ad74a.model.Usuarios;
import com.ejie.ad74a.model.avisos.AvisosAnularBaja;
import com.ejie.ad74a.model.avisos.AvisosBajaBenef;
import com.ejie.ad74a.model.avisos.AvisosCambioDomic;
import com.ejie.ad74a.model.avisos.AvisosQueja;
import com.ejie.ad74a.util.UtilSQL;
import com.ejie.ad74a.util.comun.Utilidades;
import com.ejie.ad74a.util.comun.UtilidadesXML;
import com.ejie.ad74a.util.constantes.ActoresEnum;
import com.ejie.ad74a.util.constantes.SubTipoAvisoEnum;
import com.ejie.ad74a.util.constantes.TipoAvisoEnum;
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;

/**
 * AvisosDaoImpl generated by UDA, 12-may-2023 11:16:38.
 * 
 * @author UDA
 */

@Repository
@Transactional
public class AvisosDaoImpl implements AvisosDao {

	public static final String[] ORDER_BY_WHITE_LIST = new String[] { "IDAVISO20", "FALTA20", "FPROCESADO20",
			"IDSOLICITANTE20", "OBSERVACIONES20", "USUALTA20", "USUPROCESADO20", "DATOSAVISO20", "MTACTORESIDACT42",
			"MTACTDESCES42", "MTACTDESCEU42", "MTACTESDESCSORT42", "MTACTORESIDACT42", "MTACTDESCES42", "MTACTDESCEU42",
			"MTACTESDESCSORT42", "MTSUBTAVISOIDSUBT41", "MTSUBTAVISOIDTIPO41", "MTSUBTAVISODESCES41",
			"MTSUBTAVISODESCEU41", "MTROSUBTAVISOFBAJA41", "MTTIPOSAVISOIDTIPO40", "MTTIPOSAVISODESCES40",
			"MTTIPOSAVISODESCEU40", "MTTIPOSAVISOFBAJA40", "IDACTORIGEN42", "IDACTDEST42", "DESCSORTACTORIGEN42",
			"DESCSORTACTDEST42" };

	private JdbcTemplate jdbcTemplate;

	public static final String SEQUENCE_AVISOS = "SEQ_AVISOS";

	/*
	 * ROW_MAPPERS
	 */
	private RowMapper<Avisos> rwMap = new RowMapper<Avisos>() {
		public Avisos mapRow(ResultSet resultSet, int rowNum) throws SQLException {
			Avisos avisos = new Avisos(UtilSQL.getLong(resultSet, "IDAVISO20"), resultSet.getDate("FALTA20"),
					resultSet.getDate("FPROCESADO20"), UtilSQL.getLong(resultSet, "IDSOLICITANTE20"),
					resultSet.getString("OBSERVACIONES20"), resultSet.getString("USUALTA20"),
					resultSet.getString("USUPROCESADO20"), resultSet.getClob("DATOSAVISO20"),
					new MaestroActores(UtilSQL.getLong(resultSet, "IDACTDEST42"),
							resultSet.getString("DESCESACTDEST42"), resultSet.getString("DESCEUACTDEST42"),
							resultSet.getString("DESCSORTACTDEST42")),
					new MaestroActores(UtilSQL.getLong(resultSet, "IDACTORIGEN42"),
							resultSet.getString("DESCESACTORIGEN42"), resultSet.getString("DESCEUACTORIGEN42"),
							resultSet.getString("DESCSORTACTORIGEN42")),
					new MaestroSubtiposAviso(UtilSQL.getLong(resultSet, "MTSUBTAVISOIDSUBT41"),
							new MaestroTiposAviso(UtilSQL.getLong(resultSet, "MTSUBTAVISOIDTIPO41")),
							resultSet.getString("MTSUBTAVISODESCES41"), resultSet.getString("MTSUBTAVISODESCEU41"),
							resultSet.getDate("MTROSUBTAVISOFBAJA41"), resultSet.getString("MENSAJEES41"),
							resultSet.getString("MENSAJEEU41")),
					new MaestroTiposAviso(UtilSQL.getLong(resultSet, "MTTIPOSAVISOIDTIPO40"),
							resultSet.getString("MTTIPOSAVISODESCES40"), resultSet.getString("MTTIPOSAVISODESCEU40"),
							resultSet.getDate("MTTIPOSAVISOFBAJA40")));

			String datosAvisosXml = avisos.getDatosAvisoStr();
			if (!Utilidades.esBlancoNulo(datosAvisosXml)) {
				Long tipo = avisos.getMaestroTiposAviso().getIdTipoAviso40();
				Long subTipo = avisos.getMaestroSubtiposAviso().getIdSubTipoAviso41();
				if (tipo.toString().equalsIgnoreCase(TipoAvisoEnum.ACTUAL.getId())
						&& (subTipo.toString().equalsIgnoreCase(SubTipoAvisoEnum.BAJA.getId()))
						|| subTipo.toString().equalsIgnoreCase(SubTipoAvisoEnum.BAJAYALTA.getId())) {
					// baja
					try {
						AvisosBajaBenef avisoBaja = (AvisosBajaBenef) UtilidadesXML.unmarshallerObject(datosAvisosXml,
								AvisosBajaBenef.class);
						avisos.setAvisosBajaBenef(avisoBaja);
					} catch (UnmarshalException e) {
						ManagerErrors.manageException(e, "Error al parsear el CLOB del aviso de baja");
					}

				} else if (tipo.toString().equalsIgnoreCase(TipoAvisoEnum.ACTUAL.getId())
						&& (subTipo.toString().equalsIgnoreCase(SubTipoAvisoEnum.ANULARBAJA.getId()))) {
					// baja
					try {
						AvisosAnularBaja avisosAnularBaja = (AvisosAnularBaja) UtilidadesXML
								.unmarshallerObject(datosAvisosXml, AvisosAnularBaja.class);
						avisos.setAvisosAnularBaja(avisosAnularBaja);
					} catch (UnmarshalException e) {
						ManagerErrors.manageException(e, "Error al parsear el CLOB del aviso de anular baja");
					}

				} else if (tipo.toString().equalsIgnoreCase(TipoAvisoEnum.ACTUAL.getId())
						&& subTipo.toString().equalsIgnoreCase(SubTipoAvisoEnum.CAMBIODOM.getId())) {
					// cambio de domicilio
					try {
						Direcciones direcciones = (Direcciones) UtilidadesXML.unmarshallerObject(datosAvisosXml,
								Direcciones.class);
						avisos.setDirecciones(direcciones);
					} catch (UnmarshalException e) {
						ManagerErrors.manageException(e, "Error al parsear el CLOB del aviso");
					}
				} else if (tipo.toString().equalsIgnoreCase(TipoAvisoEnum.QUEJREC.getId())) {
					// quejas y reclamaciones
					try {
						AvisosQueja avisoQueja = (AvisosQueja) UtilidadesXML.unmarshallerObject(datosAvisosXml,
								AvisosQueja.class);
						avisos.setAvisosQueja(avisoQueja);
					} catch (UnmarshalException e) {
						ManagerErrors.manageException(e, "Error al parsear el CLOB del aviso de quejas");
					}
				}
			}

			if (UtilDAO.hasColumn(resultSet, "IDENTIFICADOR01") && null != resultSet.getString("IDENTIFICADOR01")) {
				Solicitantes solicitante = new Solicitantes();
				solicitante.setIdentificador01(resultSet.getString("IDENTIFICADOR01"));
				solicitante.setNombre01(resultSet.getString("NOMBRE01"));
				solicitante.setApellido101(resultSet.getString("APELLIDO101"));
				solicitante.setApellido201(resultSet.getString("APELLIDO201"));
				solicitante.setBeneficiario01(UtilSQL.getInt(resultSet, "BENEFICIARIO01"));
				avisos.setSolicitantes(solicitante);
			}
			if (UtilDAO.hasColumn(resultSet, "URGENCIA20") && null != resultSet.getString("URGENCIA20")) {
				avisos.setUrgencia20(resultSet.getBoolean("URGENCIA20"));
			}
			avisos.setIdInforme20(resultSet.getLong("IDINFORME20"));
			avisos.setIdexpedienteAsociado(resultSet.getLong("IDEXPEDIENTE16"));
			avisos.setNumExpedienteAsociado(resultSet.getString("NUMEXPEDIENTE00"));
			return avisos;

		}
	};

	private RowMapper<Avisos> rwMapDetalle = new RowMapper<Avisos>() {
		public Avisos mapRow(ResultSet resultSet, int rowNum) throws SQLException {
			Avisos avisos = new Avisos(UtilSQL.getLong(resultSet, "IDAVISO20"), resultSet.getDate("FALTA20"),
					resultSet.getDate("FPROCESADO20"), UtilSQL.getLong(resultSet, "IDSOLICITANTE20"),
					resultSet.getString("OBSERVACIONES20"), resultSet.getString("USUALTA20"),
					resultSet.getString("USUPROCESADO20"), resultSet.getClob("DATOSAVISO20"),
					new MaestroActores(UtilSQL.getLong(resultSet, "IDACTDEST42"),
							resultSet.getString("DESCESACTDEST42"), resultSet.getString("DESCEUACTDEST42"),
							resultSet.getString("DESCSORTACTDEST42")),
					new MaestroActores(UtilSQL.getLong(resultSet, "IDACTORIGEN42"),
							resultSet.getString("DESCESACTORIGEN42"), resultSet.getString("DESCEUACTORIGEN42"),
							resultSet.getString("DESCSORTACTORIGEN42")),
					new MaestroSubtiposAviso(UtilSQL.getLong(resultSet, "MTSUBTAVISOIDSUBT41"),
							new MaestroTiposAviso(UtilSQL.getLong(resultSet, "MTSUBTAVISOIDTIPO41")),
							resultSet.getString("MTSUBTAVISODESCES41"), resultSet.getString("MTSUBTAVISODESCEU41"),
							resultSet.getDate("MTROSUBTAVISOFBAJA41"), resultSet.getString("MENSAJEES41"),
							resultSet.getString("MENSAJEEU41")),
					new MaestroTiposAviso(UtilSQL.getLong(resultSet, "MTTIPOSAVISOIDTIPO40"),
							resultSet.getString("MTTIPOSAVISODESCES40"), resultSet.getString("MTTIPOSAVISODESCEU40"),
							resultSet.getDate("MTTIPOSAVISOFBAJA40")));

			String datosAvisosXml = avisos.getDatosAvisoStr();

			if (!Utilidades.esBlancoNulo(datosAvisosXml)) {
				Long tipo = avisos.getMaestroTiposAviso().getIdTipoAviso40();
				Long subTipo = avisos.getMaestroSubtiposAviso().getIdSubTipoAviso41();
				if (tipo.toString().equalsIgnoreCase(TipoAvisoEnum.ACTUAL.getId())
						&& (subTipo.toString().equalsIgnoreCase(SubTipoAvisoEnum.BAJA.getId()))
						|| subTipo.toString().equalsIgnoreCase(SubTipoAvisoEnum.BAJAYALTA.getId())) {
					// baja
					try {
						AvisosBajaBenef avisoBaja = (AvisosBajaBenef) UtilidadesXML.unmarshallerObject(datosAvisosXml,
								AvisosBajaBenef.class);
						avisos.setAvisosBajaBenef(avisoBaja);
					} catch (UnmarshalException e) {
						ManagerErrors.manageException(e, "Error al parsear el CLOB del aviso de baja");
					}

				} else if (tipo.toString().equalsIgnoreCase(TipoAvisoEnum.ACTUAL.getId())
						&& (subTipo.toString().equalsIgnoreCase(SubTipoAvisoEnum.ANULARBAJA.getId()))) {
					// baja
					try {
						AvisosAnularBaja avisosAnularBaja = (AvisosAnularBaja) UtilidadesXML
								.unmarshallerObject(datosAvisosXml, AvisosAnularBaja.class);
						avisos.setAvisosAnularBaja(avisosAnularBaja);
					} catch (UnmarshalException e) {
						ManagerErrors.manageException(e, "Error al parsear el CLOB del aviso de anular baja");
					}

				} else if (tipo.toString().equalsIgnoreCase(TipoAvisoEnum.ACTUAL.getId())
						&& subTipo.toString().equalsIgnoreCase(SubTipoAvisoEnum.CAMBIODOM.getId())) {
					// cambio de domicilio
					try {
						Direcciones direcciones = (Direcciones) UtilidadesXML.unmarshallerObject(datosAvisosXml,
								Direcciones.class);
						avisos.setDirecciones(direcciones);
					} catch (UnmarshalException e) {
						ManagerErrors.manageException(e, "Error al parsear el CLOB del aviso");
					}
				} else if (tipo.toString().equalsIgnoreCase(TipoAvisoEnum.QUEJREC.getId())) {
					// quejas y reclamaciones
					try {
						AvisosQueja avisoQueja = (AvisosQueja) UtilidadesXML.unmarshallerObject(datosAvisosXml,
								AvisosQueja.class);
						avisos.setAvisosQueja(avisoQueja);
					} catch (UnmarshalException e) {
						ManagerErrors.manageException(e, "Error al parsear el CLOB del aviso de quejas");
					}
				}
			}

			if (UtilDAO.hasColumn(resultSet, "IDENTIFICADOR01") && null != resultSet.getString("IDENTIFICADOR01")) {
				Solicitantes solicitante = new Solicitantes();
				solicitante.setIdentificador01(resultSet.getString("IDENTIFICADOR01"));
				solicitante.setNombre01(resultSet.getString("NOMBRE01"));
				solicitante.setApellido101(resultSet.getString("APELLIDO101"));
				solicitante.setApellido201(resultSet.getString("APELLIDO201"));
				solicitante.setBeneficiario01(UtilSQL.getInt(resultSet, "BENEFICIARIO01"));
				avisos.setSolicitantes(solicitante);
			}
			if (UtilDAO.hasColumn(resultSet, "URGENCIA20") && null != resultSet.getString("URGENCIA20")) {
				avisos.setUrgencia20(resultSet.getBoolean("URGENCIA20"));
			}
			avisos.setIdInforme20(resultSet.getLong("IDINFORME20"));
			avisos.setIdexpedienteAsociado(resultSet.getLong("IDEXPEDIENTE16"));
			avisos.setNumExpedienteAsociado(resultSet.getString("NUMEXPEDIENTE00"));
			Usuarios usuario = new Usuarios(UtilSQL.getLong(resultSet, "IDUSUARIO80"),
					resultSet.getString("IDENTIFICADOR80"), resultSet.getString("NOMBRE80"),
					resultSet.getString("APELLIDOS80"), resultSet.getString("USUXLNETS80"),
					resultSet.getString("EMAIL80"), resultSet.getString("TLFNO80"), resultSet.getString("PUESTO80"),
					resultSet.getDate("FBAJA80"), resultSet.getDate("FALTA80"), resultSet.getString("USUALTA80"),
					resultSet.getDate("FMODIF80"), resultSet.getString("USUMODIF80"));

			Ayuntamientos ayuntamiento = new Ayuntamientos();
			ayuntamiento.setDescEs31(resultSet.getString("DESCES31"));
			ayuntamiento.setDescEu31(resultSet.getString("DESCEU31"));
			usuario.setAyuntamiento(ayuntamiento);
			avisos.setUsuario(usuario);

			avisos.setEmail20(resultSet.getString("EMAIL16"));
			avisos.setTelefono20(resultSet.getString("TELEFONO16"));

			return avisos;

		}
	};

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

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

			Avisos avisos = new Avisos(UtilSQL.getLong(resultSet, "IDAVISO20"), resultSet.getDate("FALTA20"),
					resultSet.getDate("FPROCESADO20"), UtilSQL.getLong(resultSet, "IDSOLICITANTE20"),
					resultSet.getString("OBSERVACIONES20"), resultSet.getString("USUALTA20"),
					resultSet.getString("USUPROCESADO20"), resultSet.getClob("DATOSAVISO20"),
					new MaestroActores(UtilSQL.getLong(resultSet, "MTACTORESIDACT42"),
							resultSet.getString("MTACTDESCES42"), resultSet.getString("MTACTDESCEU42"),
							resultSet.getString("MTACTESDESCSORT42")),
					new MaestroActores(UtilSQL.getLong(resultSet, "MTACTORESIDACT42"),
							resultSet.getString("MTACTDESCES42"), resultSet.getString("MTACTDESCEU42"),
							resultSet.getString("MTACTESDESCSORT42")),
					new MaestroSubtiposAviso(UtilSQL.getLong(resultSet, "MTSUBTAVISOIDSUBT41"),
							new MaestroTiposAviso(UtilSQL.getLong(resultSet, "MTSUBTAVISOIDTIPO41")),
							resultSet.getString("MTSUBTAVISODESCES41"), resultSet.getString("MTSUBTAVISODESCEU41"),
							resultSet.getDate("MTROSUBTAVISOFBAJA41"), resultSet.getString("MENSAJEES41"),
							resultSet.getString("MENSAJEEU41")),
					new MaestroTiposAviso(UtilSQL.getLong(resultSet, "MTTIPOSAVISOIDTIPO40"),
							resultSet.getString("MTTIPOSAVISODESCES40"), resultSet.getString("MTTIPOSAVISODESCEU40"),
							resultSet.getDate("MTTIPOSAVISOFBAJA40")));

			avisos.setIdInforme20(resultSet.getLong("IDINFORME20"));
			JerarquiaDto<Avisos> jerarquia = new JerarquiaDto<Avisos>();
			jerarquia.setModel(avisos);
			jerarquia.setLevel((int) UtilSQL.getInt(resultSet, "LEVEL"));
			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 Avisos table.
	 *
	 * @param avisos Avisos
	 * @return Avisos
	 */
	public Avisos add(Avisos avisos) {

		GeneratedKeyHolder generatedKeyHolder = new GeneratedKeyHolder();

		String query = "INSERT INTO AVISOS (ID_AVISO_20, DESTINO_20, ORIGEN_20, ID_SUB_TIPO_AVISO_20, ID_TIPO_AVISO_20, F_ALTA_20, F_PROCESADO_20, ID_SOLICITANTE_20, OBSERVACIONES_20, USU_ALTA_20, USU_PROCESADO_20, DATOS_AVISO_20, URGENCIA_20, ID_INFORME_20) "
				+ "VALUES (" + SEQUENCE_AVISOS
				+ ".NEXTVAL,:destino,:origen,:idSubTipoAviso,:idTipoAviso,sysdate,:fProcesado,:idSolicitante,:observaciones, :usuAlta, :usuProcesado, :datosAviso, :urgencia, :idInforme)";
		Object getMaestroActoresByDestino20IdActor42Aux = null;
		if (avisos.getMaestroActoresByDestino20() != null
				&& avisos.getMaestroActoresByDestino20().getIdActor42() != null) {
			getMaestroActoresByDestino20IdActor42Aux = avisos.getMaestroActoresByDestino20().getIdActor42();
		}
		Object getMaestroActoresByOrigen20IdActor42Aux = null;
		if (avisos.getMaestroActoresByOrigen20() != null
				&& avisos.getMaestroActoresByOrigen20().getIdActor42() != null) {
			getMaestroActoresByOrigen20IdActor42Aux = avisos.getMaestroActoresByOrigen20().getIdActor42();
		}
		Object getMTSUBTAVISOIDSUBT41Aux = null;
		if (avisos.getMaestroSubtiposAviso() != null
				&& avisos.getMaestroSubtiposAviso().getIdSubTipoAviso41() != null) {
			getMTSUBTAVISOIDSUBT41Aux = avisos.getMaestroSubtiposAviso().getIdSubTipoAviso41();
		}
		Object getMTTIPOSAVISOIDTIPO40Aux = null;
		if (avisos.getMaestroTiposAviso() != null && avisos.getMaestroTiposAviso().getIdTipoAviso40() != null) {
			getMTTIPOSAVISOIDTIPO40Aux = avisos.getMaestroTiposAviso().getIdTipoAviso40();
		}

		String avisoExtra = null;
		if (null != avisos.getAvisosBajaBenef()) {
			try {
				avisoExtra = UtilidadesXML.marshalObjectWS(avisos.getAvisosBajaBenef());
				avisos.setDatosAviso20(avisoExtra);
			} catch (Exception e) {
				ManagerErrors.manageException(e, "Error al cargar el CLOB de datos de aviso");
			}
		} else if (null != avisos.getAvisosQueja()) {
			try {
				avisoExtra = UtilidadesXML.marshalObjectWS(avisos.getAvisosQueja());
				avisos.setDatosAviso20(avisoExtra);
			} catch (Exception e) {
				ManagerErrors.manageException(e, "Error al cargar el CLOB de datos de aviso");
			}
		} else if (null != avisos.getAvisosAnularBaja()) {
			try {
				avisoExtra = UtilidadesXML.marshalObjectWS(avisos.getAvisosAnularBaja());
				avisos.setDatosAviso20(avisoExtra);
			} catch (Exception e) {
				ManagerErrors.manageException(e, "Error al cargar el CLOB de datos de aviso");
			}
		} else if (null != avisos.getDirecciones()) {
			try {
				avisoExtra = UtilidadesXML.marshalObjectWS(avisos.getDirecciones());
				avisos.setDatosAviso20(avisoExtra);
			} catch (Exception e) {
				ManagerErrors.manageException(e, "Error al cargar el CLOB de datos de aviso");

			}
		}

		MapSqlParameterSource parameters = new MapSqlParameterSource()
				.addValue("destino", getMaestroActoresByDestino20IdActor42Aux)
				.addValue("origen", getMaestroActoresByOrigen20IdActor42Aux)
				.addValue("idSubTipoAviso", getMTSUBTAVISOIDSUBT41Aux)
				.addValue("idTipoAviso", getMTTIPOSAVISOIDTIPO40Aux).addValue("fProcesado", avisos.getfProcesado20())
				.addValue("idSolicitante", avisos.getIdSolicitante20())
				.addValue("observaciones", avisos.getObservaciones20()).addValue("usuAlta", avisos.getUsuAlta20())
				.addValue("usuProcesado", avisos.getUsuProcesado20()).addValue("urgencia", avisos.getUrgencia20())
				.addValue("usuProcesado", avisos.getUsuProcesado20())
				.addValue("datosAviso", UtilSQL.clobToString(avisos.getDatosAviso20()))
				.addValue("urgencia", avisos.getUrgencia20() != null && avisos.getUrgencia20())
				.addValue("idInforme", avisos.getIdInforme20());

		NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
		namedParameterJdbcTemplate.update(query, parameters, generatedKeyHolder, new String[] { "ID_AVISO_20" });

		avisos.setIdAviso20(generatedKeyHolder.getKey().longValue());
		return avisos;
	}

	public Avisos procesarAvisos(Avisos avisos) {
		String query = "UPDATE AVISOS SET F_PROCESADO_20 = SYSDATE, USU_PROCESADO_20 = ? WHERE ID_AVISO_20 = ?";

		this.jdbcTemplate.update(query, avisos.getUsuProcesado20(), avisos.getIdAviso20());
		return avisos;
	}

	/**
	 * Updates a single row in the Avisos table.
	 *
	 * @param avisos Avisos
	 * @return Avisos
	 */
	public Avisos update(Avisos avisos) {
		String query = "UPDATE AVISOS SET DESTINO_20=?, ORIGEN_20=?, ID_SUB_TIPO_AVISO_20=?, ID_TIPO_AVISO_20=?, F_ALTA_20=?, F_PROCESADO_20=?, ID_SOLICITANTE_20=?, OBSERVACIONES_20=?, USU_PROCESADO_20 =?, DATOS_AVISO_20 = ? WHERE ID_AVISO_20=?";
		Object getMaestroActoresByDestino20IdActor42Aux = null;
		if (avisos.getMaestroActoresByDestino20() != null
				&& avisos.getMaestroActoresByDestino20().getIdActor42() != null) {
			getMaestroActoresByDestino20IdActor42Aux = avisos.getMaestroActoresByDestino20().getIdActor42();
		}
		Object getMaestroActoresByOrigen20IdActor42Aux = null;
		if (avisos.getMaestroActoresByOrigen20() != null
				&& avisos.getMaestroActoresByOrigen20().getIdActor42() != null) {
			getMaestroActoresByOrigen20IdActor42Aux = avisos.getMaestroActoresByOrigen20().getIdActor42();
		}
		Object getMTSUBTAVISOIDSUBT41Aux = null;
		if (avisos.getMaestroSubtiposAviso() != null
				&& avisos.getMaestroSubtiposAviso().getIdSubTipoAviso41() != null) {
			getMTSUBTAVISOIDSUBT41Aux = avisos.getMaestroSubtiposAviso().getIdSubTipoAviso41();
		}

		Object getMTTIPOSAVISOIDTIPO40Aux = null;
		if (avisos.getMaestroTiposAviso() != null && avisos.getMaestroTiposAviso().getIdTipoAviso40() != null) {
			getMTTIPOSAVISOIDTIPO40Aux = avisos.getMaestroTiposAviso().getIdTipoAviso40();
		}

		String avisoExtra = null;
		if (avisos.getMaestroSubtiposAviso().getIdSubTipoAviso41() == 2 && null != avisos.getAvisosBajaBenef()) {
			try {
				avisoExtra = UtilidadesXML.marshalObjectWS(avisos.getAvisosBajaBenef());
				avisos.setDatosAviso20(avisoExtra);
			} catch (Exception e) {
				ManagerErrors.manageException(e, "Error al cargar el CLOB de datos de aviso");
			}
		} else if (avisos.getMaestroTiposAviso().getIdTipoAviso40() == 7 && null != avisos.getAvisosQueja()) {
			try {
				avisoExtra = UtilidadesXML.marshalObjectWS(avisos.getAvisosQueja());
				avisos.setDatosAviso20(avisoExtra);
			} catch (Exception e) {
				ManagerErrors.manageException(e, "Error al cargar el CLOB de datos de aviso");
			}
		} else if (avisos.getMaestroSubtiposAviso().getIdSubTipoAviso41() == 1
				&& null != avisos.getAvisosAnularBaja()) {
			try {
				avisoExtra = UtilidadesXML.marshalObjectWS(avisos.getAvisosAnularBaja());
				avisos.setDatosAviso20(avisoExtra);
			} catch (Exception e) {
				ManagerErrors.manageException(e, "Error al cargar el CLOB de datos de aviso");
			}
		} else if (avisos.getMaestroSubtiposAviso().getIdSubTipoAviso41() == 5 && null != avisos.getDirecciones()) {
			try {
				avisoExtra = UtilidadesXML.marshalObjectWS(avisos.getDirecciones());
				avisos.setDatosAviso20(avisoExtra);
			} catch (Exception e) {
				ManagerErrors.manageException(e, "Error al cargar el CLOB de datos de aviso");
			}
		}
		this.jdbcTemplate.update(query, getMaestroActoresByDestino20IdActor42Aux,
				getMaestroActoresByOrigen20IdActor42Aux, getMTSUBTAVISOIDSUBT41Aux, getMTTIPOSAVISOIDTIPO40Aux,
				avisos.getfAlta20(), avisos.getfProcesado20() != null ? avisos.getfProcesado20() : null,
				avisos.getIdSolicitante20(), avisos.getObservaciones20(), avisos.getUsuProcesado20(),
				UtilSQL.clobToString(avisos.getDatosAviso20()), avisos.getIdAviso20());
		return avisos;
	}

	public Avisos updateProcesado(Avisos avisos) {
		String query = "UPDATE AVISOS SET F_PROCESADO_20=sysdate, USU_PROCESADO_20 =? WHERE ID_AVISO_20=?";

		this.jdbcTemplate.update(query, avisos.getUsuProcesado20(), avisos.getIdAviso20());
		return avisos;
	}

	/**
	 * Finds a single row in the Avisos table.
	 *
	 * @param avisos Avisos
	 * @return Avisos
	 */
	@Transactional(readOnly = true)
	public Avisos find(Avisos avisos) {
		String query = "SELECT  t1.ID_AVISO_20 IDAVISO20,t1.F_ALTA_20 FALTA20,t1.F_PROCESADO_20 FPROCESADO20,"
				+ "t1.ID_SOLICITANTE_20 IDSOLICITANTE20,t1.OBSERVACIONES_20 OBSERVACIONES20, t1.USU_ALTA_20 USUALTA20, t1.USU_PROCESADO_20 USUPROCESADO20, t1.DATOS_AVISO_20 DATOSAVISO20, t1.URGENCIA_20 URGENCIA20, t1.ID_INFORME_20 IDINFORME20,"
				+ "(select ID_ACTOR_42 from MAESTRO_ACTORES where id_actor_42 = t1.ORIGEN_20) IDACTORIGEN42,(select DESC_ES_42 from MAESTRO_ACTORES where id_actor_42=t1.ORIGEN_20) DESCESACTORIGEN42,(select DESC_EU_42 from MAESTRO_ACTORES where id_actor_42=t1.ORIGEN_20) DESCEUACTORIGEN42,"
				+ "(select DESC_SORT_42 from MAESTRO_ACTORES where id_actor_42=t1.ORIGEN_20) DESCSORTACTORIGEN42,(select ID_ACTOR_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) IDACTDEST42,(select DESC_ES_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) DESCESACTDEST42,"
				+ "(select DESC_EU_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) DESCEUACTDEST42,(select DESC_SORT_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) DESCSORTACTDEST42,t3.IDENTIFICADOR_01 IDENTIFICADOR01, t3.NOMBRE_01 NOMBRE01, t3.APELLIDO1_01 APELLIDO101, t3.APELLIDO2_01 APELLIDO201, t3.BENEFICIARIO_01 BENEFICIARIO01,t4.ID_SUB_TIPO_AVISO_41 MTSUBTAVISOIDSUBT41,"
				+ "t4.ID_TIPO_AVISO_41 MTSUBTAVISOIDTIPO41,t4.DESC_ES_41 MTSUBTAVISODESCES41,t4.DESC_EU_41 MTSUBTAVISODESCEU41,"
				+ "t4.F_BAJA_41 MTROSUBTAVISOFBAJA41,t4.MENSAJE_ES_41 MENSAJEES41, t4.MENSAJE_EU_41 MENSAJEEU41,t5.ID_TIPO_AVISO_40 MTTIPOSAVISOIDTIPO40,t5.DESC_ES_40 MTTIPOSAVISODESCES40,"
				+ "t5.DESC_EU_40 MTTIPOSAVISODESCEU40,t5.F_BAJA_40 MTTIPOSAVISOFBAJA40, t6.ID_EXPEDIENTE_16 IDEXPEDIENTE16, t6.EMAIL_16 EMAIL16, t6.TELEFONO_16 TELEFONO16, t7.NUM_EXPEDIENTE_00 NUMEXPEDIENTE00, "
				+ "t8.ID_USUARIO_80 IDUSUARIO80,t8.NOMBRE_80 NOMBRE80,t8.APELLIDOS_80 APELLIDOS80, t8.USU_XLNETS_80 USUXLNETS80, t8.EMAIL_80 EMAIL80, t8.TLFNO_80 TLFNO80, t8.PUESTO_80 PUESTO80, "
				+ "t8.F_BAJA_80 FBAJA80, t8.IDENTIFICADOR_80 IDENTIFICADOR80,t8.F_ALTA_80 FALTA80,t8.USU_ALTA_80 USUALTA80, t8.F_MODIF_80 FMODIF80,t8.USU_MODIF_80 USUMODIF80,  t10.DESC_ES_31 DESCES31,t10.DESC_EU_31 DESCEU31  "

				+ " FROM AVISOS t1 ,MAESTRO_ACTORES t2, SOLICITANTES t3 ,MAESTRO_SUBTIPOS_AVISO t4 ,MAESTRO_TIPOS_AVISO t5, INFORMES t6, EXPEDIENTES t7, USUARIOS t8, AYUNTAMIENTOS t10"
				+ "  WHERE 1=1 AND t1.DESTINO_20= t2.ID_ACTOR_42(+) AND t1.ORIGEN_20= t2.ID_ACTOR_42(+) AND t1.ID_SUB_TIPO_AVISO_20= t4.ID_SUB_TIPO_AVISO_41(+) AND t1.ID_TIPO_AVISO_20= t5.ID_TIPO_AVISO_40(+) AND t1.id_solicitante_20 = t3.id_solicitante_01 AND t1.ID_INFORME_20 = t6.ID_INFORME_16 (+) AND t6.ID_EXPEDIENTE_16 = t7.ID_EXPEDIENTE_00 (+) AND t6.ID_USUARIO_16= t8.ID_USUARIO_80(+) AND t6.ID_AYUNTAMIENTO_16 = t10.ID_AYUNTAMIENTO_31(+) "
				+ " AND t1.ID_AVISO_20 = ?";

		List<Avisos> avisosList = this.jdbcTemplate.query(query, this.rwMapDetalle, avisos.getIdAviso20());
		return (Avisos) DataAccessUtils.uniqueResult(avisosList);
	}

	/**
	 * Removes a single row in the Avisos table.
	 *
	 * @param avisos Avisos
	 * @return
	 */
	public void remove(Avisos avisos) {
		String query = "DELETE FROM AVISOS WHERE ID_AVISO_20=?";
		this.jdbcTemplate.update(query, avisos.getIdAviso20());
	}

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

		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_AVISO_20 IDAVISO20,t1.F_ALTA_20 FALTA20,t1.F_PROCESADO_20 FPROCESADO20, "
						+ "t1.ID_SOLICITANTE_20 IDSOLICITANTE20,t1.OBSERVACIONES_20 OBSERVACIONES20, t1.USU_ALTA_20 USUALTA20, t1.USU_PROCESADO_20 USUPROCESADO20, t1.DATOS_AVISO_20 DATOSAVISO20, t1.URGENCIA_20 URGENCIA20, t1.ID_INFORME_20 IDINFORME20, "
						+ "(select ID_ACTOR_42 from MAESTRO_ACTORES where id_actor_42 = t1.ORIGEN_20) IDACTORIGEN42,(select DESC_ES_42 from MAESTRO_ACTORES where id_actor_42=t1.ORIGEN_20) DESCESACTORIGEN42,(select DESC_EU_42 from MAESTRO_ACTORES where id_actor_42=t1.ORIGEN_20) DESCEUACTORIGEN42,"
						+ "(select DESC_SORT_42 from MAESTRO_ACTORES where id_actor_42=t1.ORIGEN_20) DESCSORTACTORIGEN42,(select ID_ACTOR_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) IDACTDEST42,(select DESC_ES_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) DESCESACTDEST42, "
						+ "(select DESC_EU_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) DESCEUACTDEST42,(select DESC_SORT_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) DESCSORTACTDEST42,t3.IDENTIFICADOR_01 IDENTIFICADOR01, t3.NOMBRE_01 NOMBRE01, t3.APELLIDO1_01 APELLIDO101, t3.APELLIDO2_01 APELLIDO201, t3.BENEFICIARIO_01 BENEFICIARIO01,t4.ID_SUB_TIPO_AVISO_41 MTSUBTAVISOIDSUBT41, "
						+ "t4.ID_TIPO_AVISO_41 MTSUBTAVISOIDTIPO41,t4.DESC_ES_41 MTSUBTAVISODESCES41,t4.DESC_EU_41 MTSUBTAVISODESCEU41, "
						+ "t4.F_BAJA_41 MTROSUBTAVISOFBAJA41,t4.MENSAJE_ES_41 MENSAJEES41, t4.MENSAJE_EU_41 MENSAJEEU41,t5.ID_TIPO_AVISO_40 MTTIPOSAVISOIDTIPO40,t5.DESC_ES_40 MTTIPOSAVISODESCES40, "
						+ "t5.DESC_EU_40 MTTIPOSAVISODESCEU40,t5.F_BAJA_40 MTTIPOSAVISOFBAJA40, t6.ID_EXPEDIENTE_16 IDEXPEDIENTE16, t7.NUM_EXPEDIENTE_00 NUMEXPEDIENTE00 ");
		query.append(
				" FROM AVISOS t1 ,MAESTRO_ACTORES t2, SOLICITANTES t3 ,MAESTRO_SUBTIPOS_AVISO t4 ,MAESTRO_TIPOS_AVISO t5, INFORMES t6, EXPEDIENTES t7 ");
		// Where clause & Params
		Map<String, Object> mapaWhere = this.getWhereLikeMap(filterAvisos, startsWith);
		StringBuilder where = new StringBuilder(query
				+ " WHERE 1=1 AND t1.DESTINO_20= t2.ID_ACTOR_42(+) AND t1.ORIGEN_20= t2.ID_ACTOR_42(+) AND t1.ID_SUB_TIPO_AVISO_20= t4.ID_SUB_TIPO_AVISO_41(+) AND t1.ID_TIPO_AVISO_20= t5.ID_TIPO_AVISO_40(+) AND t1.id_solicitante_20 = t3.id_solicitante_01 AND t1.ID_INFORME_20 = t6.ID_INFORME_16 (+) AND t6.ID_EXPEDIENTE_16 = t7.ID_EXPEDIENTE_00 (+)");
		where.append(mapaWhere.get("query"));

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

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

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

	/**
	 * Finds a list of rows in the Avisos table.
	 *
	 * @param avisos          Avisos
	 * @param tableRequestDto TableRequestDto
	 * @return List<Avisos>
	 */
	@Transactional(readOnly = true)
	public List<Avisos> findAll(Avisos avisos, TableRequestDto tableRequestDto) {
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_AVISO_20 IDAVISO20,t1.F_ALTA_20 FALTA20,t1.F_PROCESADO_20 FPROCESADO20,"
						+ "t1.ID_SOLICITANTE_20 IDSOLICITANTE20,t1.OBSERVACIONES_20 OBSERVACIONES20, t1.USU_ALTA_20 USUALTA20, t1.USU_PROCESADO_20 USUPROCESADO20, t1.DATOS_AVISO_20 DATOSAVISO20, t1.URGENCIA_20 URGENCIA20, t1.ID_INFORME_20 IDINFORME20,"
						+ "(select ID_ACTOR_42 from MAESTRO_ACTORES where id_actor_42 = t1.ORIGEN_20) IDACTORIGEN42,(select DESC_ES_42 from MAESTRO_ACTORES where id_actor_42=t1.ORIGEN_20) DESCESACTORIGEN42,(select DESC_EU_42 from MAESTRO_ACTORES where id_actor_42=t1.ORIGEN_20) DESCEUACTORIGEN42,"
						+ "(select DESC_SORT_42 from MAESTRO_ACTORES where id_actor_42=t1.ORIGEN_20) DESCSORTACTORIGEN42,(select ID_ACTOR_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) IDACTDEST42,(select DESC_ES_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) DESCESACTDEST42,"
						+ "(select DESC_EU_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) DESCEUACTDEST42,(select DESC_SORT_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) DESCSORTACTDEST42,t3.IDENTIFICADOR_01 IDENTIFICADOR01, t3.NOMBRE_01 NOMBRE01, t3.APELLIDO1_01 APELLIDO101, t3.APELLIDO2_01 APELLIDO201, t3.BENEFICIARIO_01 BENEFICIARIO01,t4.ID_SUB_TIPO_AVISO_41 MTSUBTAVISOIDSUBT41,"
						+ "t4.ID_TIPO_AVISO_41 MTSUBTAVISOIDTIPO41,t4.DESC_ES_41 MTSUBTAVISODESCES41,t4.DESC_EU_41 MTSUBTAVISODESCEU41,"
						+ "t4.F_BAJA_41 MTROSUBTAVISOFBAJA41,t4.MENSAJE_ES_41 MENSAJEES41, t4.MENSAJE_EU_41 MENSAJEEU41,t5.ID_TIPO_AVISO_40 MTTIPOSAVISOIDTIPO40,t5.DESC_ES_40 MTTIPOSAVISODESCES40,"
						+ "t5.DESC_EU_40 MTTIPOSAVISODESCEU40,t5.F_BAJA_40 MTTIPOSAVISOFBAJA40, t6.ID_EXPEDIENTE_16 IDEXPEDIENTE16, t7.NUM_EXPEDIENTE_00 NUMEXPEDIENTE00 ");
		query.append(
				"FROM AVISOS t1 ,MAESTRO_ACTORES t2, SOLICITANTES t3 ,MAESTRO_SUBTIPOS_AVISO t4 ,MAESTRO_TIPOS_AVISO t5, INFORMES t6, EXPEDIENTES t7 ");

		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereMap(avisos);
		StringBuilder where = new StringBuilder(
				" WHERE 1=1 AND t1.DESTINO_20= t2.ID_ACTOR_42(+) AND t1.ORIGEN_20= t2.ID_ACTOR_42(+) AND t1.ID_SUB_TIPO_AVISO_20= t4.ID_SUB_TIPO_AVISO_41(+) AND t1.ID_TIPO_AVISO_20= t5.ID_TIPO_AVISO_40(+) AND t1.id_solicitante_20 = t3.id_solicitante_01 AND t1.ID_INFORME_20 = t6.ID_INFORME_16 (+) AND t6.ID_EXPEDIENTE_16 = t7.ID_EXPEDIENTE_00 (+) ");
		where.append(mapaWhere.get("query"));
		query.append(where);

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

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

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

	/**
	 * Finds rows in the Avisos table using like.
	 *
	 * @param avisos          Avisos
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 * @return List<Avisos>
	 */
	@Transactional(readOnly = true)
	public List<Avisos> findAllLike(Avisos avisos, TableRequestDto tableRequestDto, Boolean startsWith) {
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_AVISO_20 IDAVISO20,t1.F_ALTA_20 FALTA20,t1.F_PROCESADO_20 FPROCESADO20, "
						+ "t1.ID_SOLICITANTE_20 IDSOLICITANTE20,t1.OBSERVACIONES_20 OBSERVACIONES20, t1.USU_ALTA_20 USUALTA20, t1.USU_PROCESADO_20 USUPROCESADO20, t1.DATOS_AVISO_20 DATOSAVISO20, t1.URGENCIA_20 URGENCIA20, t1.ID_INFORME_20 IDINFORME20, "
						+ "(select ID_ACTOR_42 from MAESTRO_ACTORES where id_actor_42 = t1.ORIGEN_20) IDACTORIGEN42,(select DESC_ES_42 from MAESTRO_ACTORES where id_actor_42=t1.ORIGEN_20) DESCESACTORIGEN42,(select DESC_EU_42 from MAESTRO_ACTORES where id_actor_42=t1.ORIGEN_20) DESCEUACTORIGEN42,"
						+ "(select DESC_SORT_42 from MAESTRO_ACTORES where id_actor_42=t1.ORIGEN_20) DESCSORTACTORIGEN42,(select ID_ACTOR_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) IDACTDEST42,(select DESC_ES_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) DESCESACTDEST42, "
						+ "(select DESC_EU_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) DESCEUACTDEST42,(select DESC_SORT_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) DESCSORTACTDEST42,t3.IDENTIFICADOR_01 IDENTIFICADOR01, t3.NOMBRE_01 NOMBRE01, t3.APELLIDO1_01 APELLIDO101, t3.APELLIDO2_01 APELLIDO201, t3.BENEFICIARIO_01 BENEFICIARIO01,t4.ID_SUB_TIPO_AVISO_41 MTSUBTAVISOIDSUBT41, "
						+ "t4.ID_TIPO_AVISO_41 MTSUBTAVISOIDTIPO41,t4.DESC_ES_41 MTSUBTAVISODESCES41,t4.DESC_EU_41 MTSUBTAVISODESCEU41, "
						+ "t4.F_BAJA_41 MTROSUBTAVISOFBAJA41,t4.MENSAJE_ES_41 MENSAJEES41, t4.MENSAJE_EU_41 MENSAJEEU41,t5.ID_TIPO_AVISO_40 MTTIPOSAVISOIDTIPO40,t5.DESC_ES_40 MTTIPOSAVISODESCES40, "
						+ "t5.DESC_EU_40 MTTIPOSAVISODESCEU40,t5.F_BAJA_40 MTTIPOSAVISOFBAJA40, t6.ID_EXPEDIENTE_16 IDEXPEDIENTE16, t7.NUM_EXPEDIENTE_00 NUMEXPEDIENTE00 ");
		query.append(
				" FROM AVISOS t1 ,MAESTRO_ACTORES t2, SOLICITANTES t3 ,MAESTRO_SUBTIPOS_AVISO t4 ,MAESTRO_TIPOS_AVISO t5, INFORMES t6, EXPEDIENTES t7");

		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(avisos, startsWith);
		StringBuilder where = new StringBuilder(
				" WHERE 1=1 AND t1.DESTINO_20= t2.ID_ACTOR_42(+) AND t1.ORIGEN_20= t2.ID_ACTOR_42(+) AND t1.ID_SUB_TIPO_AVISO_20= t4.ID_SUB_TIPO_AVISO_41(+) AND t1.ID_TIPO_AVISO_20= t5.ID_TIPO_AVISO_40(+) AND t1.id_solicitante_20 = t3.id_solicitante_01 AND t1.ID_INFORME_20 = t6.ID_INFORME_16 (+) AND t6.ID_EXPEDIENTE_16 = t7.ID_EXPEDIENTE_00 (+)");
		where.append(mapaWhere.get("query"));
		query.append(where);

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

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

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

	@Transactional(readOnly = true)
	public List<Avisos> findAllLikeConUsuario(Avisos avisos, TableRequestDto tableRequestDto, Boolean startsWith,
			Integer usuario) {
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_AVISO_20 IDAVISO20,t1.F_ALTA_20 FALTA20,t1.F_PROCESADO_20 FPROCESADO20, "
						+ "t1.ID_SOLICITANTE_20 IDSOLICITANTE20,t1.OBSERVACIONES_20 OBSERVACIONES20, t1.USU_ALTA_20 USUALTA20, t1.USU_PROCESADO_20 USUPROCESADO20, t1.DATOS_AVISO_20 DATOSAVISO20, t1.URGENCIA_20 URGENCIA20, t1.ID_INFORME_20 IDINFORME20, "
						+ "(select ID_ACTOR_42 from MAESTRO_ACTORES where id_actor_42 = t1.ORIGEN_20) IDACTORIGEN42,(select DESC_ES_42 from MAESTRO_ACTORES where id_actor_42=t1.ORIGEN_20) DESCESACTORIGEN42,(select DESC_EU_42 from MAESTRO_ACTORES where id_actor_42=t1.ORIGEN_20) DESCEUACTORIGEN42, "
						+ "(select DESC_SORT_42 from MAESTRO_ACTORES where id_actor_42=t1.ORIGEN_20) DESCSORTACTORIGEN42,(select ID_ACTOR_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) IDACTDEST42,(select DESC_ES_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) DESCESACTDEST42, "
						+ "(select DESC_EU_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) DESCEUACTDEST42,(select DESC_SORT_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) DESCSORTACTDEST42,t3.IDENTIFICADOR_01 IDENTIFICADOR01, t3.NOMBRE_01 NOMBRE01, t3.APELLIDO1_01 APELLIDO101, t3.APELLIDO2_01 APELLIDO201, t3.BENEFICIARIO_01 BENEFICIARIO01,t4.ID_SUB_TIPO_AVISO_41 MTSUBTAVISOIDSUBT41, "
						+ "t4.ID_TIPO_AVISO_41 MTSUBTAVISOIDTIPO41,t4.DESC_ES_41 MTSUBTAVISODESCES41,t4.DESC_EU_41 MTSUBTAVISODESCEU41, "
						+ "t4.F_BAJA_41 MTROSUBTAVISOFBAJA41,t4.MENSAJE_ES_41 MENSAJEES41, t4.MENSAJE_EU_41 MENSAJEEU41,t5.ID_TIPO_AVISO_40 MTTIPOSAVISOIDTIPO40,t5.DESC_ES_40 MTTIPOSAVISODESCES40, "
						+ "t5.DESC_EU_40 MTTIPOSAVISODESCEU40,t5.F_BAJA_40 MTTIPOSAVISOFBAJA40, t6.ID_EXPEDIENTE_16 IDEXPEDIENTE16, t7.NUM_EXPEDIENTE_00 NUMEXPEDIENTE00 ");
		query.append(
				" FROM AVISOS t1 ,MAESTRO_ACTORES t2, SOLICITANTES t3 ,MAESTRO_SUBTIPOS_AVISO t4 ,MAESTRO_TIPOS_AVISO t5, INFORMES t6, EXPEDIENTES t7");

		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(avisos, startsWith);
		StringBuilder where = new StringBuilder(
				" WHERE 1=1 AND t1.DESTINO_20= t2.ID_ACTOR_42(+) AND t1.ORIGEN_20= t2.ID_ACTOR_42(+) AND t1.ID_SUB_TIPO_AVISO_20= t4.ID_SUB_TIPO_AVISO_41(+) AND t1.ID_TIPO_AVISO_20= t5.ID_TIPO_AVISO_40(+) AND t1.id_solicitante_20 = t3.id_solicitante_01 AND t1.ID_INFORME_20 = t6.ID_INFORME_16 (+) AND t6.ID_EXPEDIENTE_16 = t7.ID_EXPEDIENTE_00 (+)");
		where.append(mapaWhere.get("query"));

		if (null != usuario && usuario != ActoresEnum.ADMIN.getId().intValue())
			where.append(" AND (t1.ORIGEN_20=" + usuario + " OR t1.DESTINO_20=" + usuario + ")");

		query.append(where);

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

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

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

	/*
	 * OPERACIONES RUP_TABLE
	 */

	/**
	 * Counts rows in the Avisos table.
	 *
	 * @param avisos Avisos
	 * @return Long
	 */
	@Transactional(readOnly = true)
	public Long findAllCount(Avisos avisos) {
		StringBuilder query = new StringBuilder(
				"SELECT COUNT(1) FROM AVISOS t1 ,MAESTRO_ACTORES t2, SOLICITANTES t3 ,MAESTRO_SUBTIPOS_AVISO t4 ,MAESTRO_TIPOS_AVISO t5, INFORMES t6, EXPEDIENTES t7 ");

		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereMap(avisos);
		StringBuilder where = new StringBuilder(
				" WHERE 1=1 AND t1.DESTINO_20= t2.ID_ACTOR_42(+) AND t1.ORIGEN_20= t2.ID_ACTOR_42(+) AND t1.ID_SUB_TIPO_AVISO_20= t4.ID_SUB_TIPO_AVISO_41(+) AND t1.ID_TIPO_AVISO_20= t5.ID_TIPO_AVISO_40(+) AND t1.id_solicitante_20 = t3.id_solicitante_01 AND t1.ID_INFORME_20 = t6.ID_INFORME_16 (+) AND t6.ID_EXPEDIENTE_16 = t7.ID_EXPEDIENTE_00 (+) ");
		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 Avisos table using like.
	 *
	 * @param avisos     Avisos
	 * @param startsWith Boolean
	 * @return Long
	 */
	@Transactional(readOnly = true)
	public Long findAllLikeCount(Avisos avisos, Boolean startsWith) {
		StringBuilder query = new StringBuilder(
				"SELECT COUNT(1) FROM AVISOS t1 ,MAESTRO_ACTORES t2, SOLICITANTES t3 ,MAESTRO_SUBTIPOS_AVISO t4 ,MAESTRO_TIPOS_AVISO t5, INFORMES t6, EXPEDIENTES t7 ");

		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(avisos, startsWith);
		StringBuilder where = new StringBuilder(
				" WHERE 1=1 AND t1.DESTINO_20= t2.ID_ACTOR_42(+) AND t1.ORIGEN_20= t2.ID_ACTOR_42(+) AND t1.ID_SUB_TIPO_AVISO_20= t4.ID_SUB_TIPO_AVISO_41(+) AND t1.ID_TIPO_AVISO_20= t5.ID_TIPO_AVISO_40(+) AND t1.id_solicitante_20 = t3.id_solicitante_01 AND t1.ID_INFORME_20 = t6.ID_INFORME_16 (+) AND t6.ID_EXPEDIENTE_16 = t7.ID_EXPEDIENTE_00 (+) ");
		where.append(mapaWhere.get("query"));
		query.append(where);

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

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

	@Transactional(readOnly = true)
	public Long findAllLikeCountConUsuario(Avisos avisos, Boolean startsWith, Integer usuario) {
		StringBuilder query = new StringBuilder(
				"SELECT COUNT(1) FROM AVISOS t1 ,MAESTRO_ACTORES t2, SOLICITANTES t3 ,MAESTRO_SUBTIPOS_AVISO t4 ,MAESTRO_TIPOS_AVISO t5, INFORMES t6, EXPEDIENTES t7 ");

		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(avisos, startsWith);
		StringBuilder where = new StringBuilder(
				" WHERE 1=1 AND t1.DESTINO_20= t2.ID_ACTOR_42(+) AND t1.ORIGEN_20= t2.ID_ACTOR_42(+) AND t1.ID_SUB_TIPO_AVISO_20= t4.ID_SUB_TIPO_AVISO_41(+) AND t1.ID_TIPO_AVISO_20= t5.ID_TIPO_AVISO_40(+) AND t1.id_solicitante_20 = t3.id_solicitante_01 AND t1.ID_INFORME_20 = t6.ID_INFORME_16 (+) AND t6.ID_EXPEDIENTE_16 = t7.ID_EXPEDIENTE_00 (+) ");
		where.append(mapaWhere.get("query"));

		if (null != usuario && usuario != 4)
			where.append(" AND (t1.ORIGEN_20=" + usuario + " OR t1.DESTINO_20=" + usuario + ")");

		query.append(where);

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

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

	/**
	 * Reorder the data list of Avisos selected for rup_table
	 *
	 * @param avisos          Avisos
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 * @return List<TableRowDto<Avisos>>
	 */
	@Override
	public List<TableRowDto<Avisos>> reorderSelection(Avisos avisos, TableRequestDto tableRequestDto,
			Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_AVISO_20 IDAVISO20,t1.F_ALTA_20 FALTA20,t1.F_PROCESADO_20 FPROCESADO20,"
						+ "t1.ID_SOLICITANTE_20 IDSOLICITANTE20,t1.OBSERVACIONES_20 OBSERVACIONES20, t1.USU_ALTA_20 USUALTA20, t1.USU_PROCESADO_20 USUPROCESADO20, t1.DATOS_AVISO_20 DATOSAVISO20, t1.URGENCIA_20 URGENCIA20, t1.ID_INFORME_20 IDINFORME20,"
						+ "(select ID_ACTOR_42 from MAESTRO_ACTORES where id_actor_42 = t1.ORIGEN_20) IDACTORIGEN42,(select DESC_ES_42 from MAESTRO_ACTORES where id_actor_42=t1.ORIGEN_20) DESCESACTORIGEN42,(select DESC_EU_42 from MAESTRO_ACTORES where id_actor_42=t1.ORIGEN_20) DESCEUACTORIGEN42,"
						+ "(select DESC_SORT_42 from MAESTRO_ACTORES where id_actor_42=t1.ORIGEN_20) DESCSORTACTORIGEN42,(select ID_ACTOR_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) IDACTDEST42,(select DESC_ES_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) DESCESACTDEST42,"
						+ "(select DESC_EU_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) DESCEUACTDEST42,(select DESC_SORT_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) DESCSORTACTDEST42,t3.IDENTIFICADOR_01 IDENTIFICADOR01, t3.NOMBRE_01 NOMBRE01, t3.APELLIDO1_01 APELLIDO101, t3.APELLIDO2_01 APELLIDO201, t3.BENEFICIARIO_01 BENEFICIARIO01,t4.ID_SUB_TIPO_AVISO_41 MTSUBTAVISOIDSUBT41,"
						+ "t4.ID_TIPO_AVISO_41 MTSUBTAVISOIDTIPO41,t4.DESC_ES_41 MTSUBTAVISODESCES41,t4.DESC_EU_41 MTSUBTAVISODESCEU41,"
						+ "t4.F_BAJA_41 MTROSUBTAVISOFBAJA41,t4.MENSAJE_ES_41 MENSAJEES41, t4.MENSAJE_EU_41 MENSAJEEU41,t5.ID_TIPO_AVISO_40 MTTIPOSAVISOIDTIPO40,t5.DESC_ES_40 MTTIPOSAVISODESCES40,"
						+ "t5.DESC_EU_40 MTTIPOSAVISODESCEU40,t5.F_BAJA_40 MTTIPOSAVISOFBAJA40, t6.ID_EXPEDIENTE_16 IDEXPEDIENTE16, t7.NUM_EXPEDIENTE_00 NUMEXPEDIENTE00 ");
		// FROM
		query.append(
				" FROM AVISOS t1 ,MAESTRO_ACTORES t2, SOLICITANTES t3 ,MAESTRO_SUBTIPOS_AVISO t4 ,MAESTRO_TIPOS_AVISO t5, INFORMES t6, EXPEDIENTES t7 ");
		// FILTRADO
		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(avisos, startsWith);
		StringBuilder where = new StringBuilder(
				" WHERE 1=1 AND t1.DESTINO_20= t2.ID_ACTOR_42(+) AND t1.ORIGEN_20= t2.ID_ACTOR_42(+) AND t1.ID_SUB_TIPO_AVISO_20= t4.ID_SUB_TIPO_AVISO_41(+) AND t1.ID_TIPO_AVISO_20= t5.ID_TIPO_AVISO_40(+) AND t1.id_solicitante_20 = t3.id_solicitante_01 AND t1.ID_INFORME_20 = t6.ID_INFORME_16 (+) AND t6.ID_EXPEDIENTE_16 = t7.ID_EXPEDIENTE_00 (+) ");
		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, Avisos.class,
				filterParamList, "IDAVISO20");

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

	/**
	 * Search method for rup_table
	 *
	 * @param filterParams    Avisos
	 * @param searchParams    Avisos
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 * @return List<TableRowDto<Avisos>>
	 */
	@Override
	public List<TableRowDto<Avisos>> search(Avisos filterParams, Avisos searchParams, TableRequestDto tableRequestDto,
			Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_AVISO_20 IDAVISO20,t1.F_ALTA_20 FALTA20,t1.F_PROCESADO_20 FPROCESADO20,"
						+ "t1.ID_SOLICITANTE_20 IDSOLICITANTE20,t1.OBSERVACIONES_20 OBSERVACIONES20, t1.USU_ALTA_20 USUALTA20, t1.USU_PROCESADO_20 USUPROCESADO20, t1.DATOS_AVISO_20 DATOSAVISO20, t1.URGENCIA_20 URGENCIA20, t1.ID_INFORME_20 IDINFORME20,"
						+ "(select ID_ACTOR_42 from MAESTRO_ACTORES where id_actor_42 = t1.ORIGEN_20) IDACTORIGEN42,(select DESC_ES_42 from MAESTRO_ACTORES where id_actor_42=t1.ORIGEN_20) DESCESACTORIGEN42,(select DESC_EU_42 from MAESTRO_ACTORES where id_actor_42=t1.ORIGEN_20) DESCEUACTORIGEN42,\\\"\\r\\n"
						+ "(select DESC_SORT_42 from MAESTRO_ACTORES where id_actor_42=t1.ORIGEN_20) DESCSORTACTORIGEN42,(select ID_ACTOR_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) IDACTDEST42,(select DESC_ES_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) DESCESACTDEST42,"
						+ "(select DESC_EU_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) DESCEUACTDEST42,(select DESC_SORT_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) DESCSORTACTDEST42,t3.IDENTIFICADOR_01 IDENTIFICADOR01, t3.NOMBRE_01 NOMBRE01, t3.APELLIDO1_01 APELLIDO101, t3.APELLIDO2_01 APELLIDO201, t3.BENEFICIARIO_01 BENEFICIARIO01,t4.ID_SUB_TIPO_AVISO_41 MTSUBTAVISOIDSUBT41,"
						+ "t4.ID_TIPO_AVISO_41 MTSUBTAVISOIDTIPO41,t4.DESC_ES_41 MTSUBTAVISODESCES41,t4.DESC_EU_41 MTSUBTAVISODESCEU41,"
						+ "t4.F_BAJA_41 MTROSUBTAVISOFBAJA41,t4.MENSAJE_ES_41 MENSAJEES41, t4.MENSAJE_EU_41 MENSAJEEU41,t5.ID_TIPO_AVISO_40 MTTIPOSAVISOIDTIPO40,t5.DESC_ES_40 MTTIPOSAVISODESCES40,"
						+ "t5.DESC_EU_40 MTTIPOSAVISODESCEU40,t5.F_BAJA_40 MTTIPOSAVISOFBAJA40, t6.ID_EXPEDIENTE_16 IDEXPEDIENTE16, t7.NUM_EXPEDIENTE_00 NUMEXPEDIENTE00 ");
		// FROM
		query.append(
				"FROM AVISOS t1 ,MAESTRO_ACTORES t2, SOLICITANTES t3 ,MAESTRO_SUBTIPOS_AVISO t4 ,MAESTRO_TIPOS_AVISO t5, INFORMES t6, EXPEDIENTES t7 ");
		// TABLAS_ALIAS
		List<String> from_alias = new ArrayList<String>();
		from_alias.add(" t1 ");
		from_alias.add(" t2 ");
		from_alias.add(" t3 ");
		from_alias.add(" t4 ");
		from_alias.add(" t5 ");
		from_alias.add(" t6 ");
		from_alias.add(" t7 ");

		// FILTRADO
		Map<String, ?> mapaWhereFilter = this.getWhereLikeMap(filterParams, startsWith);
		StringBuilder where = new StringBuilder(
				" WHERE 1=1 AND t1.DESTINO_20= t2.ID_ACTOR_42(+) AND t1.ORIGEN_20= t2.ID_ACTOR_42(+) AND t1.ID_SUB_TIPO_AVISO_20= t4.ID_SUB_TIPO_AVISO_41(+) AND t1.ID_TIPO_AVISO_20= t5.ID_TIPO_AVISO_40(+) AND t1.id_solicitante_20 = t3.id_solicitante_01 AND t1.ID_INFORME_20 = t6.ID_INFORME_16 (+) AND t6.ID_EXPEDIENTE_16 = t7.ID_EXPEDIENTE_00 (+) ");
		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, Avisos.class,
				filterParamList, searchSQL, searchParamList, from_alias, "IDAVISO20");

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

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

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

	/**
	 * Filter in the hierarchical Avisos table.
	 *
	 * @param filterAvisos    Avisos
	 * @param tableRequestDto TableRequestDto
	 * @return List<JerarquiaDto<Avisos>>
	 */
	@Override
	public List<JerarquiaDto<Avisos>> findAllLikeJerarquia(Avisos filterAvisos, TableRequestDto tableRequestDto) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_AVISO_20 IDAVISO20,t1.F_ALTA_20 FALTA20,t1.F_PROCESADO_20 FPROCESADO20,t1.ID_SOLICITANTE_20 IDSOLICITANTE20,t1.OBSERVACIONES_20 OBSERVACIONES20,t1.USU_ALTA_20 USUALTA20, t1.USU_PROCESADO_20 USUPROCESADO20,t1.DATOS_AVISO_20 DATOSAVISO20, "
						+ "t2.ID_ACTOR_42 IDACTDEST42, t2.DESC_ES_42 DESCESACTDEST42, t2.DESC_EU_42 DESCEUACTDEST42, t2.DESC_SORT_42 DESCSORTACTDEST42, "
						+ "t3.ID_ACTOR_42 IDACTORIGEN42, t3.DESC_ES_42 DESCESACTORIGEN42, t3.DESC_EU_42 DESCEUACTORIGEN42, t3.DESC_SORT_42 DESCSORTACTORIGEN42, "
						+ "t4.ID_SUB_TIPO_AVISO_41 MTSUBTAVISOIDSUBT41,t4.ID_TIPO_AVISO_41 MTSUBTAVISOIDTIPO41,t4.DESC_ES_41 MTSUBTAVISODESCES41,t4.DESC_EU_41 MTSUBTAVISODESCEU41,t4.F_BAJA_41 MTROSUBTAVISOFBAJA41,t5.ID_TIPO_AVISO_40 MTTIPOSAVISOIDTIPO40,t5.DESC_ES_40 MTTIPOSAVISODESCES40,t5.DESC_EU_40 MTTIPOSAVISODESCEU40,t5.F_BAJA_40 MTTIPOSAVISOFBAJA40 ");
		// FROM
		// StringBuilder from = new StringBuilder("FROM AVISOS t1 ,MAESTRO_ACTORES t2
		// ,MAESTRO_ACTORES t2 ,MAESTRO_SUBTIPOS_AVISO t4 ,MAESTRO_TIPOS_AVISO t5 ");
		List<String> from = new ArrayList<String>();
		from.add("AVISOS");
		from.add("MAESTRO_ACTORES");
		from.add("MAESTRO_SUBTIPOS_AVISO");
		from.add("MAESTRO_TIPOS_AVISO");
		// TABLAS_ALIAS
		List<String> from_alias = new ArrayList<String>();
		from_alias.add(" t1 ");
		from_alias.add(" t2 ");
		from_alias.add(" t4 ");
		from_alias.add(" t5 ");

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

		// JERARQUIA
		// Especificar la columna padre correspondiente en lugar de la generada por
		// defecto (ID_PADRE)
		query = TableManagerJerarquia.getQuery(tableRequestDto, query, mapaWhere, "IDAVISO20", "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, AvisosDaoImpl.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 filterAvisos    Avisos
	 * @param tableRequestDto TableRequestDto
	 * @return Long
	 */
	@Override
	public Long findAllLikeCountJerarquia(Avisos filterAvisos, TableRequestDto tableRequestDto) {
		// FROM
		// StringBuilder from = new StringBuilder("FROM AVISOS t1 ,MAESTRO_ACTORES t2
		// ,MAESTRO_ACTORES t3 ,MAESTRO_SUBTIPOS_AVISO t4 ,MAESTRO_TIPOS_AVISO t5 ");
		List<String> from = new ArrayList<String>();
		from.add("AVISOS");
		from.add("MAESTRO_ACTORES");
		from.add("MAESTRO_ACTORES");
		from.add("MAESTRO_SUBTIPOS_AVISO");
		from.add("MAESTRO_TIPOS_AVISO");

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

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

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

		// FROM
		// StringBuilder from = new StringBuilder("FROM AVISOS t1 ,MAESTRO_ACTORES t2
		// ,MAESTRO_ACTORES t3 ,MAESTRO_SUBTIPOS_AVISO t4 ,MAESTRO_TIPOS_AVISO t5 ");
		List<String> from = new ArrayList<String>();
		from.add("AVISOS");
		from.add("MAESTRO_ACTORES");
		from.add("MAESTRO_ACTORES");
		from.add("MAESTRO_SUBTIPOS_AVISO");
		from.add("MAESTRO_TIPOS_AVISO");

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

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

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

	/*
	 * MÉTODOS PRIVADOS
	 */

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

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

		if (avisos != null && avisos.getIdAviso20() != null) {
			where.append(" AND t1.ID_AVISO_20 = ?");
			params.add(avisos.getIdAviso20());
		}
		if (avisos != null && avisos.getMaestroActoresByDestino20() != null
				&& avisos.getMaestroActoresByDestino20().getIdActor42() != null) {
			where.append(" AND t2.ID_ACTOR_42 = ?");
			params.add(avisos.getMaestroActoresByDestino20().getIdActor42());
		}
		if (avisos != null && avisos.getMaestroActoresByDestino20() != null
				&& avisos.getMaestroActoresByDestino20().getDescEs42() != null) {
			where.append(" AND t2.DESC_ES_42 = ?");
			params.add(avisos.getMaestroActoresByDestino20().getDescEs42());
		}
		if (avisos != null && avisos.getMaestroActoresByDestino20() != null
				&& avisos.getMaestroActoresByDestino20().getDescEu42() != null) {
			where.append(" AND t2.DESC_EU_42 = ?");
			params.add(avisos.getMaestroActoresByDestino20().getDescEu42());
		}
		if (avisos != null && avisos.getMaestroActoresByDestino20() != null
				&& avisos.getMaestroActoresByDestino20().getDescSort42() != null) {
			where.append(" AND t2.DESC_SORT_42 = ?");
			params.add(avisos.getMaestroActoresByDestino20().getDescSort42());
		}
		if (avisos != null && avisos.getMaestroActoresByOrigen20() != null
				&& avisos.getMaestroActoresByOrigen20().getIdActor42() != null) {
			where.append(" AND t3.ID_ACTOR_42 = ?");
			params.add(avisos.getMaestroActoresByOrigen20().getIdActor42());
		}
		if (avisos != null && avisos.getMaestroActoresByOrigen20() != null
				&& avisos.getMaestroActoresByOrigen20().getDescEs42() != null) {
			where.append(" AND t3.DESC_ES_42 = ?");
			params.add(avisos.getMaestroActoresByOrigen20().getDescEs42());
		}
		if (avisos != null && avisos.getMaestroActoresByOrigen20() != null
				&& avisos.getMaestroActoresByOrigen20().getDescEu42() != null) {
			where.append(" AND t3.DESC_EU_42 = ?");
			params.add(avisos.getMaestroActoresByOrigen20().getDescEu42());
		}
		if (avisos != null && avisos.getMaestroActoresByOrigen20() != null
				&& avisos.getMaestroActoresByOrigen20().getDescSort42() != null) {
			where.append(" AND t3.DESC_SORT_42 = ?");
			params.add(avisos.getMaestroActoresByOrigen20().getDescSort42());
		}
		if (avisos != null && avisos.getMaestroSubtiposAviso() != null
				&& avisos.getMaestroSubtiposAviso().getIdSubTipoAviso41() != null) {
			where.append(" AND t4.ID_SUB_TIPO_AVISO_41 = ?");
			params.add(avisos.getMaestroSubtiposAviso().getIdSubTipoAviso41());
		}
		if (avisos != null && avisos.getMaestroSubtiposAviso() != null
				&& avisos.getMaestroSubtiposAviso().getMaestroTiposAviso() != null
				&& avisos.getMaestroSubtiposAviso().getMaestroTiposAviso().getIdTipoAviso40() != null) {
			where.append(" AND t4.ID_TIPO_AVISO_41 = ?");
			params.add(avisos.getMaestroSubtiposAviso().getMaestroTiposAviso().getIdTipoAviso40());
		}
		if (avisos != null && avisos.getMaestroSubtiposAviso() != null
				&& avisos.getMaestroSubtiposAviso().getDescEs41() != null) {
			where.append(" AND t4.DESC_ES_41 = ?");
			params.add(avisos.getMaestroSubtiposAviso().getDescEs41());
		}
		if (avisos != null && avisos.getMaestroSubtiposAviso() != null
				&& avisos.getMaestroSubtiposAviso().getDescEu41() != null) {
			where.append(" AND t4.DESC_EU_41 = ?");
			params.add(avisos.getMaestroSubtiposAviso().getDescEu41());
		}
		if (avisos != null && avisos.getMaestroSubtiposAviso() != null
				&& avisos.getMaestroSubtiposAviso().getfBaja41() != null) {
			where.append(" AND t4.F_BAJA_41 = ?");
			params.add(avisos.getMaestroSubtiposAviso().getfBaja41());
		}
		if (avisos != null && avisos.getMaestroTiposAviso() != null
				&& avisos.getMaestroTiposAviso().getIdTipoAviso40() != null) {
			where.append(" AND t5.ID_TIPO_AVISO_40 = ?");
			params.add(avisos.getMaestroTiposAviso().getIdTipoAviso40());
		}
		if (avisos != null && avisos.getMaestroTiposAviso() != null
				&& avisos.getMaestroTiposAviso().getDescEs40() != null) {
			where.append(" AND t5.DESC_ES_40 = ?");
			params.add(avisos.getMaestroTiposAviso().getDescEs40());
		}
		if (avisos != null && avisos.getMaestroTiposAviso() != null
				&& avisos.getMaestroTiposAviso().getDescEu40() != null) {
			where.append(" AND t5.DESC_EU_40 = ?");
			params.add(avisos.getMaestroTiposAviso().getDescEu40());
		}
		if (avisos != null && avisos.getMaestroTiposAviso() != null
				&& avisos.getMaestroTiposAviso().getfBaja40() != null) {
			where.append(" AND t5.F_BAJA_40 = ?");
			params.add(avisos.getMaestroTiposAviso().getfBaja40());
		}
		if (avisos != null && avisos.getfAlta20() != null) {
			where.append(" AND t1.F_ALTA_20 = ?");
			params.add(avisos.getfAlta20());
		}
		if (avisos != null && avisos.getfProcesado20() != null) {
			where.append(" AND t1.F_PROCESADO_20 = ?");
			params.add(avisos.getfProcesado20());
		}
		if (avisos != null && avisos.getIdSolicitante20() != null) {
			where.append(" AND t1.ID_SOLICITANTE_20 = ?");
			params.add(avisos.getIdSolicitante20());
		}
		if (avisos != null && avisos.getObservaciones20() != null) {
			where.append(" AND t1.OBSERVACIONES_20 = ?");
			params.add(avisos.getObservaciones20());
		}
		if (avisos != null && avisos.getUsuAlta20() != null) {
			where.append(" AND t1.USU_ALTA_20 = ?");
			params.add(avisos.getUsuAlta20());
		}
		if (avisos != null && avisos.getUsuProcesado20() != null) {
			where.append(" AND t1.USU_PROCESADO_20 = ?");
			params.add(avisos.getUsuProcesado20());
		}

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

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

		if (avisos != null && avisos.getIdAviso20() != null) {
			where.append(" AND t1.ID_AVISO_20 = ?");
			params.add(avisos.getIdAviso20());
		}
		if (avisos != null && avisos.getMaestroActoresByDestino20() != null
				&& avisos.getMaestroActoresByDestino20().getIdActor42() != null) {
			where.append(" AND t1.DESTINO_20 = ?");
			params.add(avisos.getMaestroActoresByDestino20().getIdActor42());
		}
		if (avisos != null && avisos.getUrgencia20() != null && avisos.getUrgencia20() == false) {
			where.append(" AND t1.URGENCIA_20 = 1");
		}
		if (avisos != null && avisos.getUrgencia20() != null && avisos.getUrgencia20() == true) {
			where.append(" AND t1.URGENCIA_20 = 0");
		}

		if (avisos != null && avisos.getMaestroActoresByOrigen20() != null
				&& avisos.getMaestroActoresByOrigen20().getIdActor42() != null) {
			where.append(" AND t1.ORIGEN_20 = ?");
			params.add(avisos.getMaestroActoresByOrigen20().getIdActor42());
		}
		if (avisos != null && avisos.getOcultarProcesados() != null) {
			where.append(" AND t1.F_PROCESADO_20 IS NULL");
		}

		if (avisos != null && avisos.getMaestroSubtiposAviso() != null
				&& avisos.getMaestroSubtiposAviso().getIdSubTipoAviso41() != null) {
			where.append(" AND t4.ID_SUB_TIPO_AVISO_41 = ?");
			params.add(avisos.getMaestroSubtiposAviso().getIdSubTipoAviso41());
		}
		if (avisos != null && avisos.getMaestroSubtiposAviso() != null
				&& avisos.getMaestroSubtiposAviso().getMaestroTiposAviso() != null
				&& avisos.getMaestroSubtiposAviso().getMaestroTiposAviso().getIdTipoAviso40() != null) {
			where.append(" AND t4.ID_TIPO_AVISO_41 = ?");
			params.add(avisos.getMaestroSubtiposAviso().getMaestroTiposAviso().getIdTipoAviso40());
		}
		if (avisos != null && avisos.getMaestroSubtiposAviso() != null
				&& avisos.getMaestroSubtiposAviso().getDescEs41() != null) {
			where.append(" AND UPPER(t4.DESC_ES_41) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(avisos.getMaestroSubtiposAviso().getDescEs41().toUpperCase() + "%");
			} else {
				params.add("%" + avisos.getMaestroSubtiposAviso().getDescEs41().toUpperCase() + "%");
			}
			where.append(" AND t4.DESC_ES_41 IS NOT NULL");
		}
		if (avisos != null && avisos.getMaestroSubtiposAviso() != null
				&& avisos.getMaestroSubtiposAviso().getDescEu41() != null) {
			where.append(" AND UPPER(t4.DESC_EU_41) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(avisos.getMaestroSubtiposAviso().getDescEu41().toUpperCase() + "%");
			} else {
				params.add("%" + avisos.getMaestroSubtiposAviso().getDescEu41().toUpperCase() + "%");
			}
			where.append(" AND t4.DESC_EU_41 IS NOT NULL");
		}
		if (avisos != null && avisos.getMaestroSubtiposAviso() != null
				&& avisos.getMaestroSubtiposAviso().getfBaja41() != null) {
			where.append(" AND t4.F_BAJA_41 = ?");
			params.add(avisos.getMaestroSubtiposAviso().getfBaja41());
		}
		if (avisos != null && avisos.getMaestroTiposAviso() != null
				&& avisos.getMaestroTiposAviso().getIdTipoAviso40() != null) {
			where.append(" AND t5.ID_TIPO_AVISO_40 = ?");
			params.add(avisos.getMaestroTiposAviso().getIdTipoAviso40());
		}
		if (avisos != null && avisos.getMaestroTiposAviso() != null
				&& avisos.getMaestroTiposAviso().getDescEs40() != null) {
			where.append(" AND UPPER(t5.DESC_ES_40) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(avisos.getMaestroTiposAviso().getDescEs40().toUpperCase() + "%");
			} else {
				params.add("%" + avisos.getMaestroTiposAviso().getDescEs40().toUpperCase() + "%");
			}
			where.append(" AND t5.DESC_ES_40 IS NOT NULL");
		}
		if (avisos != null && avisos.getMaestroTiposAviso() != null
				&& avisos.getMaestroTiposAviso().getDescEu40() != null) {
			where.append(" AND UPPER(t5.DESC_EU_40) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(avisos.getMaestroTiposAviso().getDescEu40().toUpperCase() + "%");
			} else {
				params.add("%" + avisos.getMaestroTiposAviso().getDescEu40().toUpperCase() + "%");
			}
			where.append(" AND t5.DESC_EU_40 IS NOT NULL");
		}
		if (avisos != null && avisos.getMaestroTiposAviso() != null
				&& avisos.getMaestroTiposAviso().getfBaja40() != null) {
			where.append(" AND t5.F_BAJA_40 = ?");
			params.add(avisos.getMaestroTiposAviso().getfBaja40());
		}
		if (avisos != null && avisos.getfAlta20() != null) {
			where.append(" AND t1.F_ALTA_20 = ?");
			params.add(avisos.getfAlta20());
		}
		if (avisos != null && avisos.getFecAlta20desde() != null) {
			where.append(" AND t1.F_ALTA_20 > ?");
			params.add(avisos.getFecAlta20desde());
		}
		if (avisos != null && avisos.getFecAlta20hasta() != null) {
			where.append(" AND TRUNC(t1.f_alta_20) <= ?");
			params.add(avisos.getFecAlta20hasta());
		}
		if (avisos != null && avisos.getfProcesado20() != null) {
			where.append(" AND t1.F_PROCESADO_20 = ?");
			params.add(avisos.getfProcesado20());
		}
		if (avisos != null && avisos.getIdSolicitante20() != null) {
			where.append(" AND t1.ID_SOLICITANTE_20 = ?");
			params.add(avisos.getIdSolicitante20());
		}
		if (avisos != null && avisos.getObservaciones20() != null) {
			where.append(" AND UPPER(t1.OBSERVACIONES_20) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(avisos.getObservaciones20().toUpperCase() + "%");
			} else {
				params.add("%" + avisos.getObservaciones20().toUpperCase() + "%");
			}
			where.append(" AND t1.OBSERVACIONES_20 IS NOT NULL");
		}
		if (avisos != null && avisos.getUsuAlta20() != null) {
			where.append(" AND UPPER(t1.USU_ALTA_20) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(avisos.getUsuAlta20().toUpperCase() + "%");
			} else {
				params.add("%" + avisos.getUsuAlta20().toUpperCase() + "%");
			}
			where.append(" AND t1.USU_ALTA_20 IS NOT NULL");
		}
		if (avisos != null && avisos.getUsuProcesado20() != null) {
			where.append(" AND UPPER(t1.USU_PROCESADO_20) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(avisos.getUsuProcesado20().toUpperCase() + "%");
			} else {
				params.add("%" + avisos.getUsuProcesado20().toUpperCase() + "%");
			}
			where.append(" AND t1.USU_PROCESADO_20 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
	 */

	@Override
	@Transactional(readOnly = true)
	public List<Avisos> filterComplete(Avisos filterAvisos, TableRequestDto tableRequestDto) {

		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_AVISO_20 IDAVISO20,t1.F_ALTA_20 FALTA20,t1.F_PROCESADO_20 FPROCESADO20, "
						+ "t1.ID_SOLICITANTE_20 IDSOLICITANTE20,t1.OBSERVACIONES_20 OBSERVACIONES20, t1.USU_ALTA_20 USUALTA20, t1.USU_PROCESADO_20 USUPROCESADO20, t1.DATOS_AVISO_20 DATOSAVISO20, t1.URGENCIA_20 URGENCIA20, t1.ID_INFORME_20 IDINFORME20, "
						+ "(select ID_ACTOR_42 from MAESTRO_ACTORES where id_actor_42 = t1.ORIGEN_20) IDACTORIGEN42,(select DESC_ES_42 from MAESTRO_ACTORES where id_actor_42=t1.ORIGEN_20) DESCESACTORIGEN42,(select DESC_EU_42 from MAESTRO_ACTORES where id_actor_42=t1.ORIGEN_20) DESCEUACTORIGEN42,"
						+ "(select DESC_SORT_42 from MAESTRO_ACTORES where id_actor_42=t1.ORIGEN_20) DESCSORTACTORIGEN42,(select ID_ACTOR_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) IDACTDEST42,(select DESC_ES_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) DESCESACTDEST42, "
						+ "(select DESC_EU_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) DESCEUACTDEST42,(select DESC_SORT_42 from MAESTRO_ACTORES where id_actor_42=t1.DESTINO_20) DESCSORTACTDEST42,t3.IDENTIFICADOR_01 IDENTIFICADOR01, t3.NOMBRE_01 NOMBRE01, t3.APELLIDO1_01 APELLIDO101, t3.APELLIDO2_01 APELLIDO201, t3.BENEFICIARIO_01 BENEFICIARIO01,t4.ID_SUB_TIPO_AVISO_41 MTSUBTAVISOIDSUBT41, "
						+ "t4.ID_TIPO_AVISO_41 MTSUBTAVISOIDTIPO41,t4.DESC_ES_41 MTSUBTAVISODESCES41,t4.DESC_EU_41 MTSUBTAVISODESCEU41, "
						+ "t4.F_BAJA_41 MTROSUBTAVISOFBAJA41,t4.MENSAJE_ES_41 MENSAJEES41, t4.MENSAJE_EU_41 MENSAJEEU41,t5.ID_TIPO_AVISO_40 MTTIPOSAVISOIDTIPO40,t5.DESC_ES_40 MTTIPOSAVISODESCES40, "
						+ "t5.DESC_EU_40 MTTIPOSAVISODESCEU40,t5.F_BAJA_40 MTTIPOSAVISOFBAJA40, t6.ID_EXPEDIENTE_16 IDEXPEDIENTE16, t6.EMAIL_16 EMAIL16, t6.TELEFONO_16 TELEFONO16, t7.NUM_EXPEDIENTE_00 NUMEXPEDIENTE00, "
						+ "t8.ID_USUARIO_16 IDUSUARIO16, t9.ID_USUARIO_80 IDUSUARIO80,t9.NOMBRE_80 NOMBRE80,t9.APELLIDOS_80 APELLIDOS80, t9.USU_XLNETS_80 USUXLNETS80, t9.EMAIL_80 EMAIL80, t9.TLFNO_80 TLFNO80, t9.PUESTO_80 PUESTO80, "
						+ "t9.F_BAJA_80 FBAJA80, t9.IDENTIFICADOR_80 IDENTIFICADOR80,t9.F_ALTA_80 FALTA80,t9.USU_ALTA_80 USUALTA80, t9.F_MODIF_80 FMODIF80,t9.USU_MODIF_80 USUMODIF80, t10.DESC_ES_31 DESCES31,t10.DESC_EU_31 DESCEU31 ");

		query.append(
				" FROM AVISOS t1 ,MAESTRO_ACTORES t2, SOLICITANTES t3 ,MAESTRO_SUBTIPOS_AVISO t4 ,MAESTRO_TIPOS_AVISO t5, INFORMES t6, EXPEDIENTES t7, INFORMES t8, USUARIOS t9, AYUNTAMIENTOS t10 ");
		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(filterAvisos, false);
		StringBuilder where = new StringBuilder(
				" WHERE 1=1 AND t1.DESTINO_20= t2.ID_ACTOR_42(+) AND t1.ORIGEN_20= t2.ID_ACTOR_42(+) AND t1.ID_SUB_TIPO_AVISO_20= t4.ID_SUB_TIPO_AVISO_41(+) AND t1.ID_TIPO_AVISO_20= t5.ID_TIPO_AVISO_40(+) AND t1.id_solicitante_20 = t3.id_solicitante_01 AND t1.ID_INFORME_20 = t6.ID_INFORME_16 (+) AND t6.ID_EXPEDIENTE_16 = t7.ID_EXPEDIENTE_00 (+) AND t8.ID_INFORME_16(+) = t1.ID_INFORME_20 AND t9.ID_USUARIO_80(+)=t8.ID_USUARIO_16  AND t8.ID_AYUNTAMIENTO_16 = t10.ID_AYUNTAMIENTO_31(+)");
		where.append(mapaWhere.get("query"));
		query.append(where);

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

		if (tableRequestDto != null) {
			query = TableManager.getPaginationQuery(tableRequestDto, query, AvisosDaoImpl.ORDER_BY_WHITE_LIST);
		}
		return this.jdbcTemplate.query(query.toString(), this.rwMapDetalle, params.toArray());
	}

	@Override
	@Transactional(readOnly = true)
	public Avisos aportarExpediente(Avisos avisos) {

		String query = "UPDATE INFORMES SET ESTADO_16 = 9, ID_EXPEDIENTE_16 = ? WHERE ID_INFORME_16 = ?";

		this.jdbcTemplate.update(query, avisos.getIdexpedienteAsociado(), avisos.getIdInforme20());
		return avisos;
	}

	@Override
	@Transactional(readOnly = true)
	public Avisos solicitarPS(Avisos aviso) {

		String query = "UPDATE INFORMES SET ESTADO_16 = 4 WHERE ID_INFORME_16 = ?";

		this.jdbcTemplate.update(query, aviso.getIdInforme20());

		return aviso;
	}

	public static final int STRING_BUILDER_INIT = 4096;
}
