/*
* Copyright 2021 E.J.I.E., S.A.
*
* Licencia con arreglo a la EUPL, Versión 1.1 exclusivamente (la «Licencia»);
* Solo podrá usarse esta obra si se respeta la Licencia.
* Puede obtenerse una copia de la Licencia en
*
* http://ec.europa.eu/idabc/eupl.html
*
* Salvo cuando lo exija la legislación aplicable o se acuerde por escrito,
* el programa distribuido con arreglo a la Licencia se distribuye «TAL CUAL»,
* SIN GARANT�?AS NI CONDICIONES DE NINGÚN TIPO, ni expresas ni implícitas.
* Véase la Licencia en el idioma concreto que rige los permisos y limitaciones
* que establece la Licencia.
*/
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.dao.comun.UtilDAO;
import com.ejie.ad74a.model.BandejaPapel0;
import com.ejie.ad74a.model.Expedientes;
import com.ejie.ad74a.util.UtilSQL;
import com.ejie.ad74a.util.constantes.Constantes;
import com.ejie.ad74a.util.constantes.ProcedimientosEnum;
import com.ejie.ad74a.util.constantes.TipoAportacionEnum;
import com.ejie.ad74a.util.constantes.Constantes.EstadosBandejaPapel0;
import com.ejie.ad74a.util.constantes.Constantes.NoAceptada;
import com.ejie.x38.dao.RowNumResultSetExtractor;
import com.ejie.x38.dto.TableManager;
import com.ejie.x38.dto.TableRequestDto;
import com.ejie.x38.dto.TableRowDto;

/**
 * BandejaPapel0DaoImpl generated by UDA, 19-abr-2023 10:08:13.
 * 
 * @author UDA
 */

@Repository
@Transactional
public class BandejaPapel0DaoImpl implements BandejaPapel0Dao {

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

	protected static final String[] ORDER_BY_WHITE_LIST = new String[] { "IDENTRADA12", "PROCEDUREID12", "FLECTURA12",
			"IDJMS12", "NUMREGISTRO12", "FREGISTRO12", "QRCODE12", "MENSAJE12", "ESTADO12", "BLOQUEO12", "TIPO12",
			"REMITENTE12", "NUMREGORIGINAL12", "FREGORIGINAL12", "USURESPONSABLE12", "NUMEXPEDIENTE12", "RESUMEN12",
			"URGENCIA12", "FALTA12", "USUALTA12", "FMODIF12", "USUMODIF12", "OBSERVACIONES12", "MOTIVOOCULTAR12" };

	private JdbcTemplate jdbcTemplate;

	public static final String SEQUENCE_BANDEJA_PAPEL0 = "SEQ_BANDEJA_PAPEL0";

	/*
	 * ROW_MAPPERS
	 */
	private RowMapper<BandejaPapel0> rwMap = new RowMapper<BandejaPapel0>() {
		public BandejaPapel0 mapRow(ResultSet resultSet, int rowNum) throws SQLException {
			BandejaPapel0 bandejaPapel0 = new BandejaPapel0(UtilSQL.getLong(resultSet, "IDENTRADA12"),
					resultSet.getString("PROCEDUREID12"), resultSet.getDate("FLECTURA12"),
					resultSet.getString("IDJMS12"), resultSet.getString("NUMREGISTRO12"),
					resultSet.getTimestamp("FREGISTRO12"), resultSet.getString("QRCODE12"),
					resultSet.getClob("MENSAJE12"), resultSet.getString("ESTADO12"),
					UtilSQL.getInt(resultSet, "BLOQUEO12"), resultSet.getString("TIPO12"),
					resultSet.getString("TIPOPROCESO12"), resultSet.getString("REMITENTE12"),
					resultSet.getString("NUMREGORIGINAL12"), resultSet.getTimestamp("FREGORIGINAL12"),
					resultSet.getString("USURESPONSABLE12"), resultSet.getString("NUMEXPEDIENTE12"),
					resultSet.getString("RESUMEN12"), UtilSQL.getInt(resultSet, "URGENCIA12"),
					resultSet.getDate("FALTA12"), resultSet.getString("USUALTA12"), resultSet.getDate("FMODIF12"),
					resultSet.getString("USUMODIF12"), resultSet.getString("OBSERVACIONES12"),
					resultSet.getString("MOTIVOOCULTAR12"));

			if (bandejaPapel0.getProcedureid12() != null) {
				bandejaPapel0.setProcedureid12_desc(ProcedimientosEnum.getDesc(bandejaPapel0.getProcedureid12()));
			}

			if (bandejaPapel0.getTipo12() != null) {
				bandejaPapel0.setTipo12_desc(
						TipoAportacionEnum.getDesc(bandejaPapel0.getTipo12().replaceAll("^0*", ""), null));

//				if (bandejaPapel0.getQrcode12() != null) {
//					bandejaPapel0
//							.setTipoProceso(TipoProcesoEnum.getTipoByQR(bandejaPapel0.getQrcode12().split(";")[0]));
//				}
			}
			if (bandejaPapel0.getTipoProceso12() != null) {
				bandejaPapel0.setTipoProceso12_desc(
						TipoAportacionEnum.getDesc(bandejaPapel0.getTipoProceso12().replaceAll("^0*", ""), null));

			}

			if (UtilDAO.hasColumn(resultSet, "NUMDOCUMENTOS") && null != resultSet.getObject("NUMDOCUMENTOS")) {
				bandejaPapel0.setNumDocumentos(UtilSQL.getInt(resultSet, "NUMDOCUMENTOS"));
			}

			if (UtilDAO.hasColumn(resultSet, "IDEXPEDIENTE00") && null != resultSet.getObject("IDEXPEDIENTE00")) {
				// Datos del expediente relacionado
				Expedientes expediente = new Expedientes();
				expediente.setIdExpediente00(UtilSQL.getLong(resultSet, "IDEXPEDIENTE00"));
				expediente.setNumExpediente00(resultSet.getString("NUMEXPEDIENTE12"));
			}

			return bandejaPapel0;
		}
	};
	private RowMapper<Expedientes> rwMapExpediente = new RowMapper<Expedientes>() {
		public Expedientes mapRow(ResultSet resultSet, int rowNum) throws SQLException {
			Expedientes exp = new Expedientes();
			exp.setIdTipoNot00(resultSet.getString("IDTIPONOT00"));
			exp.setCanalNot00(resultSet.getString("CANALNOT00"));
			exp.setTfnoNot00(resultSet.getString("TFNONOT00"));
			exp.setEmailNot00(resultSet.getString("EMAILNOT00"));
			exp.setIdiomaNot00(
					(resultSet.getString("IDIOMANOT") == null || resultSet.getString("IDIOMANOT").equals("0") ? "es"
							: "eu"));
			return exp;
		}
	};
	private RowMapper<BandejaPapel0> rwMapPK = new RowMapper<BandejaPapel0>() {
		public BandejaPapel0 mapRow(ResultSet resultSet, int rowNum) throws SQLException {
			return new BandejaPapel0(UtilSQL.getLong(resultSet, "IDENTRADA12"));
		}
	};

	/**
	 * 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 BandejaPapel0 table.
	 *
	 * @param bandejapapel0 BandejaPapel0
	 *
	 * @return BandejaPapel0
	 */
	public BandejaPapel0 add(BandejaPapel0 bandejapapel0) {

		GeneratedKeyHolder generatedKeyHolder = new GeneratedKeyHolder();

		String query = "INSERT INTO BANDEJA_PAPEL0 (ID_ENTRADA_12, PROCEDUREID_12, F_LECTURA_12, IDJMS_12, NUM_REGISTRO_12, F_REGISTRO_12, QRCODE_12, MENSAJE_12, ESTADO_12, BLOQUEO_12, TIPO_12, TIPO_PROCESO_12,  REMITENTE_12, NUM_REG_ORIGINAL_12, F_REG_ORIGINAL_12, USU_RESPONSABLE_12, NUM_EXPEDIENTE_12, RESUMEN_12, URGENCIA_12, F_ALTA_12, USU_ALTA_12, F_MODIF_12, USU_MODIF_12, OBSERVACIONES_12, MOTIVO_OCULTAR_12) "
				+ "VALUES (" + SEQUENCE_BANDEJA_PAPEL0
				+ ".NEXTVAL,:procedureId,:fLectura,:idjms,:numRegistro,:fRegistro,:qrCode,:mensaje,:estado,:bloqueo,:tipo,:tipoProceso,:remitente,:numRegOriginal,:fRegOriginal,:usuResponsable,:numExpediente,:resumen,:urgencia, :fAlta,:usuAlta,:fModif,:usuModif,:observaciones,:motivoOcultar)";

		MapSqlParameterSource parameters = new MapSqlParameterSource()
				.addValue("procedureId", bandejapapel0.getProcedureid12())
				.addValue("fLectura", bandejapapel0.getfLectura12())//
				.addValue("idjms", bandejapapel0.getIdjms12())//
				.addValue("numRegistro", bandejapapel0.getNumRegistro12())
				.addValue("fRegistro", bandejapapel0.getfRegistro12())//
				.addValue("qrCode", bandejapapel0.getQrcode12())//
				.addValue("mensaje", bandejapapel0.getMensaje12())//
				.addValue("estado", bandejapapel0.getEstado12())//
				.addValue("bloqueo", bandejapapel0.getBloqueo12())//
				.addValue("tipo", bandejapapel0.getTipo12())//
				.addValue("tipoProceso", bandejapapel0.getTipoProceso12())//
				.addValue("remitente", bandejapapel0.getRemitente12())
				.addValue("numRegOriginal", bandejapapel0.getNumRegOriginal12())
				.addValue("fRegOriginal", bandejapapel0.getfRegOriginal12())
				.addValue("usuResponsable", bandejapapel0.getUsuResponsable12())
				.addValue("numExpediente", bandejapapel0.getNumExpediente12())
				.addValue("resumen", bandejapapel0.getResumen12()).addValue("urgencia", bandejapapel0.getUrgencia12())
				.addValue("fAlta", bandejapapel0.getfAlta12()).addValue("usuAlta", bandejapapel0.getUsuAlta12())
				.addValue("fModif", bandejapapel0.getfModif12()).addValue("usuModif", bandejapapel0.getUsuModif12())
				.addValue("observaciones", bandejapapel0.getObservaciones12())
				.addValue("motivoOcultar", bandejapapel0.getMotivoOcultar12());

		NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
		namedParameterJdbcTemplate.update(query, parameters, generatedKeyHolder, new String[] { "ID_ENTRADA_12" });
		bandejapapel0.setIdEntrada12(generatedKeyHolder.getKey().longValue());

		return bandejapapel0;

	}

	/**
	 * Updates a single row in the BandejaPapel0 table.
	 *
	 * @param bandejapapel0 BandejaPapel0
	 *
	 * @return BandejaPapel0
	 */
	public BandejaPapel0 update(BandejaPapel0 bandejapapel0) {
		String query = "UPDATE BANDEJA_PAPEL0 SET PROCEDUREID_12=? F_LECTURA_12=?, IDJMS_12=?, NUM_REGISTRO_12=?, F_REGISTRO_12=?, QRCODE_12=?, MENSAJE_12=?, ESTADO_12=?, BLOQUEO_12=?, TIPO_12=?, TIPO_PROCESO_12=?,REMITENTE_12=?, NUM_REG_ORIGINAL_12=?, F_REG_ORIGINAL_12=?, USU_RESPONSABLE_12=?, NUM_EXPEDIENTE_12=?, RESUMEN_12=?, URGENCIA_12 = ?, F_ALTA_12=?, USU_ALTA_12=?, F_MODIF_12=?, USU_MODIF_12=?, OBSERVACIONES_12=?, MOTIVO_OCULTAR_12=? WHERE ID_ENTRADA_12=?";
		this.jdbcTemplate.update(query, bandejapapel0.getProcedureid12(), bandejapapel0.getfLectura12(),
				bandejapapel0.getIdjms12(), bandejapapel0.getNumRegistro12(), bandejapapel0.getfRegistro12(),
				bandejapapel0.getQrcode12(), bandejapapel0.getMensaje12(), bandejapapel0.getEstado12(),
				bandejapapel0.getBloqueo12(), bandejapapel0.getTipo12(), bandejapapel0.getTipoProceso12(),
				bandejapapel0.getRemitente12(), bandejapapel0.getNumRegOriginal12(), bandejapapel0.getfRegOriginal12(),
				bandejapapel0.getUsuResponsable12(), bandejapapel0.getNumExpediente12(), bandejapapel0.getResumen12(),
				bandejapapel0.getUrgencia12(), bandejapapel0.getfAlta12(), bandejapapel0.getUsuAlta12(),
				bandejapapel0.getfModif12(), bandejapapel0.getUsuModif12(), bandejapapel0.getObservaciones12(),
				bandejapapel0.getMotivoOcultar12(), bandejapapel0.getIdEntrada12());
		return bandejapapel0;
	}

	/**
	 * Finds a single row in the BandejaPapel0 table.
	 *
	 * @param bandejapapel0 BandejaPapel0
	 *
	 * @return BandejaPapel0
	 */
	@Transactional(readOnly = true)
	public BandejaPapel0 find(BandejaPapel0 bandejapapel0) {
		String query = "SELECT t1.ID_ENTRADA_12 IDENTRADA12, t1.PROCEDUREID_12 PROCEDUREID12, t1.F_LECTURA_12 FLECTURA12, t1.IDJMS_12 IDJMS12, t1.NUM_REGISTRO_12 NUMREGISTRO12, t1.F_REGISTRO_12 FREGISTRO12, t1.QRCODE_12 QRCODE12, t1.MENSAJE_12 MENSAJE12, t1.ESTADO_12 ESTADO12, t1.BLOQUEO_12 BLOQUEO12, t1.TIPO_12 TIPO12,t1.TIPO_PROCESO_12 TIPOPROCESO12, t1.REMITENTE_12 REMITENTE12, t1.NUM_REG_ORIGINAL_12 NUMREGORIGINAL12, t1.F_REG_ORIGINAL_12 FREGORIGINAL12, t1.USU_RESPONSABLE_12 USURESPONSABLE12, t1.NUM_EXPEDIENTE_12 NUMEXPEDIENTE12, t1.RESUMEN_12 RESUMEN12, t1.URGENCIA_12 URGENCIA12, t1.F_ALTA_12 FALTA12, t1.USU_ALTA_12 USUALTA12, t1.F_MODIF_12 FMODIF12, t1.USU_MODIF_12 USUMODIF12, t1.OBSERVACIONES_12 OBSERVACIONES12, t1.MOTIVO_OCULTAR_12 MOTIVOOCULTAR12 FROM BANDEJA_PAPEL0 t1  WHERE t1.ID_ENTRADA_12 = ?  ";

		List<BandejaPapel0> bandejapapel0List = this.jdbcTemplate.query(query, this.rwMap,
				bandejapapel0.getIdEntrada12());
		return DataAccessUtils.uniqueResult(bandejapapel0List);
	}

	/**
	 * Removes a single row in the BandejaPapel0 table.
	 *
	 * @param bandejapapel0 BandejaPapel0
	 */
	public void remove(BandejaPapel0 bandejapapel0) {
		String query = "DELETE FROM BANDEJA_PAPEL0 WHERE ID_ENTRADA_12=?";
		this.jdbcTemplate.update(query, bandejapapel0.getIdEntrada12());
	}

	public List<BandejaPapel0> getMultiple(BandejaPapel0 filterBandejaPapel0, TableRequestDto tableRequestDto,
			Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_ENTRADA_12 IDENTRADA12, t1.PROCEDUREID_12 PROCEDUREID12, t1.F_LECTURA_12 FLECTURA12, t1.IDJMS_12 IDJMS12, t1.NUM_REGISTRO_12 NUMREGISTRO12, t1.F_REGISTRO_12 FREGISTRO12, t1.QRCODE_12 QRCODE12, t1.MENSAJE_12 MENSAJE12, t1.ESTADO_12 ESTADO12, t1.BLOQUEO_12 BLOQUEO12, t1.TIPO_12 TIPO12,t1.TIPO_PROCESO_12 TIPOPROCESO12, t1.REMITENTE_12 REMITENTE12, t1.NUM_REG_ORIGINAL_12 NUMREGORIGINAL12, t1.F_REG_ORIGINAL_12 FREGORIGINAL12, t1.USU_RESPONSABLE_12 USURESPONSABLE12, t1.NUM_EXPEDIENTE_12 NUMEXPEDIENTE12, t1.RESUMEN_12 RESUMEN12, t1.URGENCIA_12 URGENCIA12, t1.F_ALTA_12 FALTA12, t1.USU_ALTA_12 USUALTA12, t1.F_MODIF_12 FMODIF12, t1.USU_MODIF_12 USUMODIF12, t1.OBSERVACIONES_12 OBSERVACIONES12, t1.MOTIVO_OCULTAR_12 MOTIVOOCULTAR12 ");
		// FROM
		query.append("FROM BANDEJA_PAPEL0 t1 ");
		// WHERE clause & Params
		Map<String, Object> mapaWhere = this.getWhereLikeMap(filterBandejaPapel0, startsWith);
		StringBuilder where = new StringBuilder(" WHERE 1=1 ");
		where.append(mapaWhere.get("query"));
		query.append(where);

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

		StringBuilder sbMultipleSQL = query.append(
				TableManager.getSelectMultipleQuery(tableRequestDto, BandejaPapel0.class, params, "id_entrada_12"));

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

	/**
	 * Finds a list of rows in the BandejaPapel0 table.
	 *
	 * @param bandejapapel0   BandejaPapel0
	 * @param tableRequestDto TableRequestDto
	 *
	 * @return List<BandejaPapel0>
	 */
	@Transactional(readOnly = true)
	public List<BandejaPapel0> findAll(BandejaPapel0 bandejapapel0, TableRequestDto tableRequestDto) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_ENTRADA_12 IDENTRADA12, t1.PROCEDUREID_12 PROCEDUREID12,t1.F_LECTURA_12 FLECTURA12,t1.IDJMS_12 IDJMS12,t1.NUM_REGISTRO_12 NUMREGISTRO12,t1.F_REGISTRO_12 FREGISTRO12,t1.QRCODE_12 QRCODE12,t1.MENSAJE_12 MENSAJE12,t1.ESTADO_12 ESTADO12,t1.BLOQUEO_12 BLOQUEO12,t1.TIPO_12 TIPO12,t1.TIPO_PROCESO_12 TIPOPROCESO12,t1.REMITENTE_12 REMITENTE12,t1.NUM_REG_ORIGINAL_12 NUMREGORIGINAL12,t1.F_REG_ORIGINAL_12 FREGORIGINAL12,t1.USU_RESPONSABLE_12 USURESPONSABLE12,t1.NUM_EXPEDIENTE_12 NUMEXPEDIENTE12, t1.RESUMEN_12 RESUMEN12, t1.URGENCIA_12 URGENCIA12, t1.F_ALTA_12 FALTA12, t1.USU_ALTA_12 USUALTA12, t1.F_MODIF_12 FMODIF12, t1.USU_MODIF_12 USUMODIF12, t1.OBSERVACIONES_12 OBSERVACIONES12 , t1.MOTIVO_OCULTAR_12 MOTIVOOCULTAR12 ");

		// FROM
		query.append("FROM BANDEJA_PAPEL0 t1 ");

		// WHERE clause & Params
		Map<String, ?> mapaWhere = this.getWhereMap(bandejapapel0);
		StringBuilder where = new StringBuilder(" WHERE 1=1 ");
		where.append(mapaWhere.get("query"));
		query.append(where);

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

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

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

	/**
	 * Finds rows in the BandejaPapel0 table using like.
	 *
	 * @param bandejapapel0   BandejaPapel0
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 *
	 * @return List<BandejaPapel0>
	 */
	@Transactional(readOnly = true)
	public List<BandejaPapel0> findAllLike(BandejaPapel0 bandejapapel0, TableRequestDto tableRequestDto,
			Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_ENTRADA_12 IDENTRADA12, t1.PROCEDUREID_12 PROCEDUREID12,t1.F_LECTURA_12 FLECTURA12,t1.IDJMS_12 IDJMS12,t1.NUM_REGISTRO_12 NUMREGISTRO12,t1.F_REGISTRO_12 FREGISTRO12,t1.QRCODE_12 QRCODE12,t1.MENSAJE_12 MENSAJE12,t1.ESTADO_12 ESTADO12,t1.BLOQUEO_12 BLOQUEO12,t1.TIPO_12 TIPO12,t1.TIPO_PROCESO_12 TIPOPROCESO12,t1.REMITENTE_12 REMITENTE12,t1.NUM_REG_ORIGINAL_12 NUMREGORIGINAL12,t1.F_REG_ORIGINAL_12 FREGORIGINAL12,t1.USU_RESPONSABLE_12 USURESPONSABLE12,t1.NUM_EXPEDIENTE_12 NUMEXPEDIENTE12, t1.RESUMEN_12 RESUMEN12, t1.URGENCIA_12 URGENCIA12, t1.F_ALTA_12 FALTA12, t1.USU_ALTA_12 USUALTA12, t1.F_MODIF_12 FMODIF12, t1.USU_MODIF_12 USUMODIF12, t1.OBSERVACIONES_12 OBSERVACIONES12, t1.MOTIVO_OCULTAR_12 MOTIVOOCULTAR12, ");

		query.append(
				" (SELECT COUNT(*) FROM DOCUMENTO_PAPEL0 t2 WHERE t2.ID_ENTRADA_13 = t1.ID_ENTRADA_12 ) NUMDOCUMENTOS ");

		// FROM
		query.append("FROM BANDEJA_PAPEL0 t1 ");

		// WHERE clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(bandejapapel0, startsWith);
		StringBuilder where = new StringBuilder(" WHERE 1=1 ");
		where.append(mapaWhere.get("query"));
		query.append(where);

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

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

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

	/*
	 * OPERACIONES RUP_TABLE
	 */

	/**
	 * Counts rows in the BandejaPapel0 table.
	 *
	 * @param bandejapapel0 BandejaPapel0
	 *
	 * @return Long
	 */
	@Transactional(readOnly = true)
	public Long findAllCount(BandejaPapel0 bandejapapel0) {
		// SELECT
		StringBuilder query = new StringBuilder("SELECT COUNT(1) FROM BANDEJA_PAPEL0 t1 ");

		// WHERE clause & Params
		Map<String, ?> mapaWhere = this.getWhereMap(bandejapapel0);
		StringBuilder where = new StringBuilder(" WHERE 1=1 ");
		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 BandejaPapel0 table using like.
	 *
	 * @param bandejapapel0 BandejaPapel0
	 * @param startsWith    Boolean
	 *
	 * @return Long
	 */
	@Transactional(readOnly = true)
	public Long findAllLikeCount(BandejaPapel0 bandejapapel0, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder("SELECT COUNT(1) FROM BANDEJA_PAPEL0 t1 ");

		// WHERE clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(bandejapapel0, startsWith);
		StringBuilder where = new StringBuilder(" WHERE 1=1 ");
		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 BandejaPapel0 selected for rup_table
	 *
	 * @param bandejapapel0   BandejaPapel0
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 *
	 * @return List<TableRowDto<BandejaPapel0>>
	 */
	@Override
	public List<TableRowDto<BandejaPapel0>> reorderSelection(BandejaPapel0 bandejapapel0,
			TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_ENTRADA_12 IDENTRADA12, t1.PROCEDUREID_12 PROCEDUREID12,t1.F_LECTURA_12 FLECTURA12,t1.IDJMS_12 IDJMS12,t1.NUM_REGISTRO_12 NUMREGISTRO12,t1.F_REGISTRO_12 FREGISTRO12,t1.QRCODE_12 QRCODE12,t1.MENSAJE_12 MENSAJE12,t1.ESTADO_12 ESTADO12,t1.BLOQUEO_12 BLOQUEO12,t1.TIPO_12 TIPO12,t1.REMITENTE_12 REMITENTE12,t1.NUM_REG_ORIGINAL_12 NUMREGORIGINAL12,t1.F_REG_ORIGINAL_12 FREGORIGINAL12,t1.USU_RESPONSABLE_12 USURESPONSABLE12,t1.NUM_EXPEDIENTE_12 NUMEXPEDIENTE12, t1.RESUMEN_12 RESUMEN12, t1.URGENCIA_12 URGENCIA12, t1.F_ALTA_12 FALTA12, t1.USU_ALTA_12 USUALTA12, t1.F_MODIF_12 FMODIF12, t1.USU_MODIF_12 USUMODIF12, t1.MOTIVO_OCULTAR12 MOTIVOOCULTAR12 ");
		// FROM
		query.append("FROM BANDEJA_PAPEL0 t1 ");
		// FILTRADO
		// WHERE clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(bandejapapel0, startsWith);
		StringBuilder where = new StringBuilder(" WHERE 1=1 ");
		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, BandejaPapel0.class,
				filterParamList, "identrada12");

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

	/**
	 * Search method for rup_table
	 *
	 * @param filterParams    BandejaPapel0
	 * @param searchParams    BandejaPapel0
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 *
	 * @return List<TableRowDto<BandejaPapel0>>
	 */
	@Override
	public List<TableRowDto<BandejaPapel0>> search(BandejaPapel0 filterParams, BandejaPapel0 searchParams,
			TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_ENTRADA_12 IDENTRADA12, t1.PROCEDUREID_12 PROCEDUREID12,t1.F_LECTURA_12 FLECTURA12,t1.IDJMS_12 IDJMS12,t1.NUM_REGISTRO_12 NUMREGISTRO12,t1.F_REGISTRO_12 FREGISTRO12,t1.QRCODE_12 QRCODE12,t1.MENSAJE_12 MENSAJE12,t1.ESTADO_12 ESTADO12,t1.BLOQUEO_12 BLOQUEO12,t1.TIPO_12 TIPO12,t1.REMITENTE_12 REMITENTE12,t1.NUM_REG_ORIGINAL_12 NUMREGORIGINAL12,t1.F_REG_ORIGINAL_12 FREGORIGINAL12,t1.USU_RESPONSABLE_12 USURESPONSABLE12,t1.NUM_EXPEDIENTE_12 NUMEXPEDIENTE12, t1.RESUMEN_12 RESUMEN12, t1.URGENCIA_12 URGENCIA12, t1.F_ALTA_12 FALTA12, t1.USU_ALTA_12 USUALTA12, t1.F_MODIF_12 FMODIF12, t1.USU_MODIF_12 USUMODIF12, t1.OBSERVACIONES_12 OBSERVACIONES12, t1.MOTIVO_OCULTAR_12 MOTIVOOCULTAR12 ");
		// FROM
		query.append("FROM BANDEJA_PAPEL0 t1 ");
		// TABLAS_ALIAS
		List<String> from_alias = new ArrayList<String>();
		from_alias.add(" t1 ");

		// FILTRADO
		Map<String, ?> mapaWhereFilter = this.getWhereLikeMap(filterParams, startsWith);
		StringBuilder where = new StringBuilder(" WHERE 1=1 ");
		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, BandejaPapel0.class,
				filterParamList, searchSQL, searchParamList, from_alias, "IDENTRADA12");

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

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

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

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

	/*
	 * MÃ‰TODOS PRIVADOS
	 */

	/**
	 * Returns a map with the needed value to create the conditions to filter by the
	 * BandejaPapel0 entity
	 *
	 * @param bandejapapel0 BandejaPapel0 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.
	 */
	private Map<String, ?> getWhereMap(BandejaPapel0 bandejapapel0) {
		StringBuilder where = new StringBuilder(BandejaPapel0DaoImpl.STRING_BUILDER_INIT);
		List<Object> params = new ArrayList<Object>();

		if (bandejapapel0 != null && bandejapapel0.getIdEntrada12() != null) {
			where.append(" AND t1.ID_ENTRADA_12 = ?");
			params.add(bandejapapel0.getIdEntrada12());
		}
		if (bandejapapel0 != null && bandejapapel0.getProcedureid12() != null) {
			where.append(" AND t1.PROCEDUREID_12 = ?");
			params.add(bandejapapel0.getProcedureid12());
		}
		if (bandejapapel0 != null && bandejapapel0.getfLectura12() != null) {
			where.append(" AND t1.F_LECTURA_12 = ?");
			params.add(bandejapapel0.getfLectura12());
		}
		if (bandejapapel0 != null && bandejapapel0.getIdjms12() != null) {
			where.append(" AND t1.IDJMS_12 = ?");
			params.add(bandejapapel0.getIdjms12());
		}
		if (bandejapapel0 != null && bandejapapel0.getNumRegistro12() != null) {
			where.append(" AND t1.NUM_REGISTRO_12 = ?");
			params.add(bandejapapel0.getNumRegistro12());
		}
		if (bandejapapel0 != null && bandejapapel0.getfRegistro12() != null) {
			where.append(" AND t1.F_REGISTRO_12 = ?");
			params.add(bandejapapel0.getfRegistro12());
		}
		if (bandejapapel0 != null && bandejapapel0.getQrcode12() != null) {
			where.append(" AND t1.QRCODE_12 = ?");
			params.add(bandejapapel0.getQrcode12());
		}
		if (bandejapapel0 != null && bandejapapel0.getEstado12() != null) {
			where.append(" AND t1.ESTADO_12 = ?");
			params.add(bandejapapel0.getEstado12());
		}
		if (bandejapapel0 != null && bandejapapel0.getBloqueo12() != null) {
			where.append(" AND t1.BLOQUEO_12 = ?");
			params.add(bandejapapel0.getBloqueo12());
		}
		if (bandejapapel0 != null && bandejapapel0.getTipo12() != null) {
			where.append(" AND t1.TIPO_12 = ?");
			params.add(bandejapapel0.getTipo12());
		}
		if (bandejapapel0 != null && bandejapapel0.getRemitente12() != null) {
			where.append(" AND t1.REMITENTE_12 = ?");
			params.add(bandejapapel0.getRemitente12());
		}
		if (bandejapapel0 != null && bandejapapel0.getNumRegOriginal12() != null) {
			where.append(" AND t1.NUM_REG_ORIGINAL_12 = ?");
			params.add(bandejapapel0.getNumRegOriginal12());
		}
		if (bandejapapel0 != null && bandejapapel0.getfRegOriginal12() != null) {
			where.append(" AND t1.F_REG_ORIGINAL_12 = ?");
			params.add(bandejapapel0.getfRegOriginal12());
		}
		if (bandejapapel0 != null && bandejapapel0.getUsuResponsable12() != null) {
			where.append(" AND t1.USU_RESPONSABLE_12 = ?");
			params.add(bandejapapel0.getUsuResponsable12());
		}
		if (bandejapapel0 != null && bandejapapel0.getNumExpediente12() != null) {
			where.append(" AND t1.NUM_EXPEDIENTE_12 = ?");
			params.add(bandejapapel0.getNumExpediente12());
		}
		if (bandejapapel0 != null && bandejapapel0.getResumen12() != null) {
			where.append(" AND t1.RESUMEN_12 = ?");
			params.add(bandejapapel0.getResumen12());
		}

		if (bandejapapel0 != null && bandejapapel0.getUrgencia12() != null) {
			where.append(" AND t1.URGENCIA_12 = ?");
			params.add(bandejapapel0.getUrgencia12());
		}

		if (bandejapapel0 != null && bandejapapel0.getUsuAlta12() != null) {
			where.append(" AND t1.USU_ALTA_12 = ?");
			params.add(bandejapapel0.getUsuAlta12());
		}
		if (bandejapapel0 != null && bandejapapel0.getfAlta12() != null) {
			where.append(" AND t1.F_ALTA_12 = ?");
			params.add(bandejapapel0.getfAlta12());
		}
		if (bandejapapel0 != null && bandejapapel0.getUsuModif12() != null) {
			where.append(" AND t1.USU_MODIF_12 = ?");
			params.add(bandejapapel0.getUsuModif12());
		}
		if (bandejapapel0 != null && bandejapapel0.getfModif12() != null) {
			where.append(" AND t1.F_MODIF_12 = ?");
			params.add(bandejapapel0.getfModif12());
		}
		if (bandejapapel0 != null && bandejapapel0.getObservaciones12() != null) {
			where.append(" AND t1.OBSERVACIONES_12 = ?");
			params.add(bandejapapel0.getObservaciones12());
		}
		if (bandejapapel0 != null && bandejapapel0.getMotivoOcultar12() != null) {
			where.append(" AND t1.MOTIVO_OCULTAR_12 = ?");
			params.add(bandejapapel0.getMotivoOcultar12());
		}
		if (bandejapapel0 != null && bandejapapel0.getNoAceptada() != null) {
			if (NoAceptada.ACEPTADA.equals(bandejapapel0.getNoAceptada())) {
				where.append(" AND t1.ESTADO_12 = ? ");
				params.add(EstadosBandejaPapel0.ACEPTADO);
			} else if (NoAceptada.NO_ACEPTADA.equals(bandejapapel0.getNoAceptada())) {
				where.append(" AND t1.ESTADO_12 != ? ");
				params.add(EstadosBandejaPapel0.ACEPTADO);
			}

		}

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

		return mapWhere;
	}

	/**
	 * Returns a map with the needed value to create the conditions to filter by the
	 * BandejaPapel0 entity
	 *
	 * @param bandejapapel0 BandejaPapel0 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.
	 */
	private Map<String, Object> getWhereLikeMap(BandejaPapel0 bandejapapel0, Boolean startsWith) {
		StringBuilder where = new StringBuilder(BandejaPapel0DaoImpl.STRING_BUILDER_INIT);
		List<Object> params = new ArrayList<Object>();

		if (bandejapapel0 != null && bandejapapel0.getIdEntrada12() != null) {
			where.append(" AND t1.ID_ENTRADA_12 = ?");
			params.add(bandejapapel0.getIdEntrada12());
		}
		if (bandejapapel0 != null && bandejapapel0.getProcedureid12() != null) {
			where.append(" AND UPPER(t1.PROCEDUREID_12) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(bandejapapel0.getProcedureid12().toUpperCase() + "%");
			} else {
				params.add("%" + bandejapapel0.getProcedureid12().toUpperCase() + "%");
			}
			where.append(" AND t1.PROCEDUREID_12 IS NOT NULL");
		}
		if (bandejapapel0 != null && bandejapapel0.getfLectura12() != null) {
			where.append(" AND t1.F_LECTURA_12 = ?");
			params.add(bandejapapel0.getfLectura12());
		}
		if (bandejapapel0 != null && bandejapapel0.getIdjms12() != null) {
			where.append(" AND UPPER(t1.IDJMS_12) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(bandejapapel0.getIdjms12().toUpperCase() + "%");
			} else {
				params.add("%" + bandejapapel0.getIdjms12().toUpperCase() + "%");
			}
			where.append(" AND t1.IDJMS_12 IS NOT NULL");
		}
		if (bandejapapel0 != null && bandejapapel0.getNumRegistro12() != null) {
			where.append(" AND UPPER(t1.NUM_REGISTRO_12) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(bandejapapel0.getNumRegistro12().toUpperCase() + "%");
			} else {
				params.add("%" + bandejapapel0.getNumRegistro12().toUpperCase() + "%");
			}
			where.append(" AND t1.NUM_REGISTRO_12 IS NOT NULL");
		}
		if (bandejapapel0 != null && bandejapapel0.getfRegistro12() != null) {
			where.append(" AND t1.F_REGISTRO_12 = ?");
			params.add(bandejapapel0.getfRegistro12());
		}
		if (bandejapapel0 != null && bandejapapel0.getQrcode12() != null) {
			where.append(" AND UPPER(t1.QRCODE_12) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(bandejapapel0.getQrcode12().toUpperCase() + "%");
			} else {
				params.add("%" + bandejapapel0.getQrcode12().toUpperCase() + "%");
			}
			where.append(" AND t1.QRCODE_12 IS NOT NULL");
		}
		if (bandejapapel0 != null && bandejapapel0.getEstado12() != null) {

			// Mostrar o no los ocultos
			if (bandejapapel0.getOcultos() != null) {

				where.append(" AND ( UPPER(t1.ESTADO_12) like ? ESCAPE  '\\'");
				if (startsWith) {
					params.add(bandejapapel0.getEstado12().toUpperCase() + "%");
				} else {
					params.add("%" + bandejapapel0.getEstado12().toUpperCase() + "%");
				}

				where.append(" OR UPPER(t1.ESTADO_12) like ? ESCAPE  '\\'");
				if (startsWith) {
					params.add(Constantes.EstadosBandejaPapel0.OCULTO + "%");
				} else {
					params.add("%" + Constantes.EstadosBandejaPapel0.OCULTO + "%");
				}

				where.append(") AND t1.ESTADO_12 IS NOT NULL");

			} else {
				where.append(" AND UPPER(t1.ESTADO_12) like ? ESCAPE  '\\'");
				if (startsWith) {
					params.add(bandejapapel0.getEstado12().toUpperCase() + "%");
				} else {
					params.add("%" + bandejapapel0.getEstado12().toUpperCase() + "%");
				}
				where.append(" AND t1.ESTADO_12 IS NOT NULL");
			}
		}
		if (bandejapapel0 != null && bandejapapel0.getBloqueo12() != null) {
			where.append(" AND t1.BLOQUEO_12 = ?");
			params.add(bandejapapel0.getBloqueo12());
		}
		if (bandejapapel0 != null && bandejapapel0.getTipo12() != null) {
			where.append(" AND UPPER(t1.TIPO_12) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(bandejapapel0.getTipo12().toUpperCase() + "%");
			} else {
				params.add("%" + bandejapapel0.getTipo12().toUpperCase() + "%");
			}
			where.append(" AND t1.TIPO_12 IS NOT NULL");
		}
		if (bandejapapel0 != null && bandejapapel0.getRemitente12() != null) {
			where.append(" AND UPPER(t1.REMITENTE_12) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(bandejapapel0.getRemitente12().toUpperCase() + "%");
			} else {
				params.add("%" + bandejapapel0.getRemitente12().toUpperCase() + "%");
			}
			where.append(" AND t1.REMITENTE_12 IS NOT NULL");
		}
		if (bandejapapel0 != null && bandejapapel0.getNumRegOriginal12() != null) {
			where.append(" AND UPPER(t1.NUM_REG_ORIGINAL_12) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(bandejapapel0.getNumRegOriginal12().toUpperCase() + "%");
			} else {
				params.add("%" + bandejapapel0.getNumRegOriginal12().toUpperCase() + "%");
			}
			where.append(" AND t1.NUM_REG_ORIGINAL_12 IS NOT NULL");
		}
		if (bandejapapel0 != null && bandejapapel0.getfRegOriginal12() != null) {
			where.append(" AND t1.F_REG_ORIGINAL_12 = ?");
			params.add(bandejapapel0.getfRegOriginal12());
		}
		if (bandejapapel0 != null && bandejapapel0.getUsuResponsable12() != null) {
			where.append(" AND UPPER(t1.USU_RESPONSABLE_12) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(bandejapapel0.getUsuResponsable12().toUpperCase() + "%");
			} else {
				params.add("%" + bandejapapel0.getUsuResponsable12().toUpperCase() + "%");
			}
			where.append(" AND t1.USU_RESPONSABLE_12 IS NOT NULL");
		}
		if (bandejapapel0 != null && bandejapapel0.getNumExpediente12() != null) {
			where.append(" AND UPPER(t1.NUM_EXPEDIENTE_12) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(bandejapapel0.getNumExpediente12().toUpperCase() + "%");
			} else {
				params.add("%" + bandejapapel0.getNumExpediente12().toUpperCase() + "%");
			}
			where.append(" AND t1.NUM_EXPEDIENTE_12 IS NOT NULL");
		}
		if (bandejapapel0 != null && bandejapapel0.getResumen12() != null) {
			where.append(" AND UPPER(t1.RESUMEN_12) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(bandejapapel0.getResumen12().toUpperCase() + "%");
			} else {
				params.add("%" + bandejapapel0.getResumen12().toUpperCase() + "%");
			}
			where.append(" AND t1.RESUMEN_12 IS NOT NULL");
		}

		if (bandejapapel0 != null && bandejapapel0.getUrgencia12() != null) {
			where.append(" AND t1.URGENCIA_12 = ?");
			params.add(bandejapapel0.getUrgencia12());
		}

		if (bandejapapel0 != null && bandejapapel0.getUsuAlta12() != null) {
			where.append(" AND UPPER(t1.USU_ALTA_12) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(bandejapapel0.getUsuAlta12().toUpperCase() + "%");
			} else {
				params.add("%" + bandejapapel0.getUsuAlta12().toUpperCase() + "%");
			}
			where.append(" AND t1.USU_ALTA_12 IS NOT NULL");
		}
		if (bandejapapel0 != null && bandejapapel0.getfAlta12() != null) {
			where.append(" AND t1.F_ALTA_12 = ?");
			params.add(bandejapapel0.getfAlta12());
		}
		if (bandejapapel0 != null && bandejapapel0.getUsuModif12() != null) {
			where.append(" AND UPPER(t1.USU_MODIF_12) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(bandejapapel0.getUsuModif12().toUpperCase() + "%");
			} else {
				params.add("%" + bandejapapel0.getUsuModif12().toUpperCase() + "%");
			}
			where.append(" AND t1.USU_MODIF_12 IS NOT NULL");
		}
		if (bandejapapel0 != null && bandejapapel0.getfModif12() != null) {
			where.append(" AND t1.F_MODIF_12 = ?");
			params.add(bandejapapel0.getfModif12());
		}
		if (bandejapapel0 != null && bandejapapel0.getObservaciones12() != null) {
			where.append(" AND UPPER(t1.OBSERVACIONES_12) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(bandejapapel0.getObservaciones12().toUpperCase() + "%");
			} else {
				params.add("%" + bandejapapel0.getObservaciones12().toUpperCase() + "%");
			}
			where.append(" AND t1.OBSERVACIONES_12 IS NOT NULL");
		}
		if (bandejapapel0 != null && bandejapapel0.getMotivoOcultar12() != null) {
			where.append(" AND UPPER(t1.MOTIVO_OCULTAR_12) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(bandejapapel0.getMotivoOcultar12().toUpperCase() + "%");
			} else {
				params.add("%" + bandejapapel0.getMotivoOcultar12().toUpperCase() + "%");
			}
			where.append(" AND t1.MOTIVO_OCULTAR_12 IS NOT NULL");
		}

		if (bandejapapel0 != null && bandejapapel0.getNoAceptada() != null) {
			if (NoAceptada.ACEPTADA.equals(bandejapapel0.getNoAceptada())) {
				where.append(" AND t1.ESTADO_12 = ? ");
				params.add(EstadosBandejaPapel0.ACEPTADO);
			} else if (NoAceptada.NO_ACEPTADA.equals(bandejapapel0.getNoAceptada())) {
				where.append(" AND t1.ESTADO_12 != ? ");
				params.add(EstadosBandejaPapel0.ACEPTADO);
			}

		}

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

		return mapWhere;
	}

	/**
	 * Existe MSGID en papel0
	 * 
	 * @param idjms12 String
	 * @return boolean
	 */
	@Override
	public boolean existeMsgIDPapelCero(String jmsidP1) {
		String query = "SELECT COUNT(1) FROM BANDEJA_PAPEL0 WHERE IDJMS_12 = '" + jmsidP1 + "'";

		Long count = this.jdbcTemplate.queryForObject(query.toString(), Long.class);
		return count > 0;
	}

	/**
	 * Existe numero de registro en papel0
	 * 
	 * @param numRegistro12 String
	 * @return boolean
	 */
	@Override
	public boolean existeNumRegPapelCero(String numeroRegistro) {
		String query = "SELECT COUNT(1) FROM BANDEJA_PAPEL0 WHERE NUM_REGISTRO_12 = '" + numeroRegistro + "'";

		Long count = this.jdbcTemplate.queryForObject(query.toString(), Long.class);
		return count > 0;
	}

	/**
	 * Búsqueda en bandeja papel 0 join con expedientes
	 * 
	 * @param filterBandejaPapel0
	 * @return
	 */
	@Override
	@Transactional(readOnly = true)
	public List<BandejaPapel0> getBandejaPapel0Complete(BandejaPapel0 filterBandejaPapel0) {

		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_ENTRADA_12 IDENTRADA12, t1.PROCEDUREID_12 PROCEDUREID12,t1.F_LECTURA_12 FLECTURA12,t1.IDJMS_12 IDJMS12,t1.NUM_REGISTRO_12 NUMREGISTRO12,t1.F_REGISTRO_12 FREGISTRO12,t1.QRCODE_12 QRCODE12,t1.MENSAJE_12 MENSAJE12,t1.ESTADO_12 ESTADO12,t1.BLOQUEO_12 BLOQUEO12,t1.TIPO_12 TIPO12,t1.TIPO_PROCESO_12 TIPOPROCESO12,t1.REMITENTE_12 REMITENTE12,t1.NUM_REG_ORIGINAL_12 NUMREGORIGINAL12,t1.F_REG_ORIGINAL_12 FREGORIGINAL12,t1.USU_RESPONSABLE_12 USURESPONSABLE12,t1.NUM_EXPEDIENTE_12 NUMEXPEDIENTE12, t1.RESUMEN_12 RESUMEN12, t1.F_ALTA_12 FALTA12, t1.USU_ALTA_12 USUALTA12, t1.F_MODIF_12 FMODIF12, t1.USU_MODIF_12 USUMODIF12, t1.OBSERVACIONES_12 OBSERVACIONES12, t1.URGENCIA_12 URGENCIA12, t1.MOTIVO_OCULTAR_12 MOTIVOOCULTAR12, ");

		query.append(" t2.ID_EXPEDIENTE_00 IDEXPEDIENTE00 ");

		// FROM
		query.append("FROM BANDEJA_PAPEL0 t1 ");
		query.append(" LEFT JOIN EXPEDIENTES t2 ON (t1.NUM_EXPEDIENTE_12 = t2.NUM_EXPEDIENTE_00) ");

		// WHERE clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(filterBandejaPapel0, false);
		StringBuilder where = new StringBuilder(" WHERE 1=1 ");
		where.append(mapaWhere.get("query"));
		query.append(where);

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

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

	/**
	 * Actualiza el ocultar de la entrada
	 * 
	 * @param BandejaPapel0
	 */
	public void updateOculto(BandejaPapel0 bandejaPapel0) {
		String query = "UPDATE BANDEJA_PAPEL0 SET ESTADO_12=?, F_MODIF_12=SYSDATE, USU_MODIF_12=?, MOTIVO_OCULTAR_12=? WHERE ID_ENTRADA_12=?";
		this.jdbcTemplate.update(query, bandejaPapel0.getEstado12(), bandejaPapel0.getUsuModif12(),
				bandejaPapel0.getMotivoOcultar12(), bandejaPapel0.getIdEntrada12());
	}

	/**
	 * Actualiza el estado de la entrada
	 * 
	 * @param BandejaPapel0
	 */
	public void updateEstado(BandejaPapel0 bandejaPapel0) {
		String query = "UPDATE BANDEJA_PAPEL0 SET ESTADO_12=?, F_MODIF_12=SYSDATE, USU_MODIF_12=? WHERE ID_ENTRADA_12=?";
		this.jdbcTemplate.update(query, bandejaPapel0.getEstado12(), bandejaPapel0.getUsuModif12(),
				bandejaPapel0.getIdEntrada12());
	}

	/**
	 * Actualiza el bloqueo de la entrada
	 * 
	 * @param BandejaPapel0
	 */
	public void updateBloqueo(BandejaPapel0 bandejaPapel0) {
		String query = "UPDATE BANDEJA_PAPEL0 SET BLOQUEO_12=?, USU_RESPONSABLE_12=? WHERE ID_ENTRADA_12=?";
		this.jdbcTemplate.update(query, bandejaPapel0.getBloqueo12(), bandejaPapel0.getUsuResponsable12(),
				bandejaPapel0.getIdEntrada12());
	}

	/**
	 * Actualiza el expediente de la entrada
	 * 
	 * @param BandejaPapel0
	 */
	public void updateExpediente(BandejaPapel0 bandejaPapel0) {
		String query = "UPDATE BANDEJA_PAPEL0 SET NUM_EXPEDIENTE_12=?, F_MODIF_12=SYSDATE, USU_MODIF_12=? WHERE ID_ENTRADA_12=?";
		this.jdbcTemplate.update(query, bandejaPapel0.getNumExpediente12(), bandejaPapel0.getUsuModif12(),
				bandejaPapel0.getIdEntrada12());
	}

	/**
	 * Actualiza las observaciones de la entrada
	 * 
	 * @param BandejaPapel0
	 */
	public void updateObservaciones(BandejaPapel0 bandejaPapel0) {
		String query = "UPDATE BANDEJA_PAPEL0 SET OBSERVACIONES_12=?, F_MODIF_12=SYSDATE, USU_MODIF_12=? WHERE ID_ENTRADA_12=?";
		this.jdbcTemplate.update(query, bandejaPapel0.getObservaciones12(), bandejaPapel0.getUsuModif12(),
				bandejaPapel0.getIdEntrada12());
	}

	/**
	 * Actualiza la urgencia de la entrada
	 * 
	 * @param BandejaPapel0
	 */
	public void updateUrgencia(BandejaPapel0 bandejaPapel0) {
		String query = "UPDATE BANDEJA_PAPEL0 SET URGENCIA_12=?, F_MODIF_12=SYSDATE, USU_MODIF_12=? WHERE ID_ENTRADA_12=?";
		this.jdbcTemplate.update(query, bandejaPapel0.getUrgencia12(), bandejaPapel0.getUsuModif12(),
				bandejaPapel0.getIdEntrada12());
	}

	/**
	 * Actualiza la urgencia de la entrada a traves del id expediente
	 * 
	 * @param BandejaPapel0
	 */
	public void updateUrgenciabyNumRegis(BandejaPapel0 bandejaPapel0) {
		String query = "UPDATE BANDEJA_PAPEL0 SET URGENCIA_12=?, F_MODIF_12=SYSDATE, USU_MODIF_12=? WHERE NUM_REGISTRO_12 =?";
		this.jdbcTemplate.update(query, bandejaPapel0.getUrgencia12(), bandejaPapel0.getUsuModif12(),
				bandejaPapel0.getExpediente().getNumRegistro00());
	}

	@Override
	public Expedientes obtenerAvisoSolicitanteUltimoExp(String idSolicitante) {
		StringBuilder query = new StringBuilder(
				"SELECT ID_TIPO_NOT_00 IDTIPONOT00,CANAL_NOT_00 CANALNOT00,EMAIL_NOT_00 EMAILNOT00,TFNO_NOT_00 TFNONOT00, idioma_not_00 IDIOMANOT FROM EXPEDIENTES WHERE ID_SOLICITANTE_00 = ? ORDER BY  F_RESOLUCION_00 DESC");
		List<Expedientes> expedientesList = this.jdbcTemplate.query(query.toString(), this.rwMapExpediente,
				idSolicitante);

		if (!expedientesList.isEmpty()) {
			return expedientesList.get(0);
		}

		return null;

	}

	@Override
	public BandejaPapel0 updateProcesarEntradaBandeja(BandejaPapel0 bandejaPapel0) {
		String query = "UPDATE BANDEJA_PAPEL0 SET URGENCIA_12=?, ESTADO_12=?, NUM_EXPEDIENTE_12=?, OBSERVACIONES_12=?,  F_MODIF_12=SYSDATE, USU_MODIF_12=? WHERE ID_ENTRADA_12=?";
		this.jdbcTemplate.update(query, bandejaPapel0.getUrgencia12(), bandejaPapel0.getEstado12(),
				bandejaPapel0.getNumExpediente12(), bandejaPapel0.getObservaciones12(), bandejaPapel0.getUsuModif12(),
				bandejaPapel0.getIdEntrada12());
		return bandejaPapel0;
	}

	@Override
	public BandejaPapel0 updateTipoProceso(BandejaPapel0 bandejaPapel0) {
		String query = "UPDATE BANDEJA_PAPEL0 SET TIPO_PROCESO_12=?, F_MODIF_12=SYSDATE, USU_MODIF_12=? WHERE ID_ENTRADA_12=?";
		this.jdbcTemplate.update(query, bandejaPapel0.getTipoProceso12(), bandejaPapel0.getUsuModif12(),
				bandejaPapel0.getIdEntrada12());
		return bandejaPapel0;
	}

}
