/*
* 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 com.ejie.x38.dao.RowNumResultSetExtractor;
import com.ejie.x38.dto.TableManager;
import com.ejie.x38.dto.TableRequestDto;
import com.ejie.x38.dto.TableRowDto;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.sql.DataSource;
import org.springframework.dao.support.DataAccessUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.ejie.ad74a.model.MaestroNivSoporte;
import com.ejie.ad74a.model.Tarifas;
import com.ejie.ad74a.util.UtilSQL;

/**
 * TarifasDaoImpl generated by UDA, 28-sep-2023 11:01:18.
 * 
 * @author UDA
 */

@Repository
@Transactional
public class TarifasDaoImpl implements TarifasDao {

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

	protected static final String[] ORDER_BY_WHITE_LIST = new String[] { "IDTARIFANIVSOP76", "FVIGENCIADESDE76",
			"FVIGENCIAHASTA76", "IDNIVELSOPORTE76", "TARIFA76", "FALTA76", "USUALTA76", "FMODIF76", "USUMODIF76" };

	private JdbcTemplate jdbcTemplate;

	public static final String SEQUENCE_TARIFAS = "SEQ_TARIFAS";

	/*
	 * ROW_MAPPERS
	 */
	private RowMapper<Tarifas> rwMap = new RowMapper<Tarifas>() {
		public Tarifas mapRow(ResultSet resultSet, int rowNum) throws SQLException {
			return new Tarifas(UtilSQL.getLong(resultSet, "IDTARIFANIVSOP76"), resultSet.getDate("FVIGENCIADESDE76"),
					resultSet.getDate("FVIGENCIAHASTA76"),
					new MaestroNivSoporte(UtilSQL.getLong(resultSet, "IDNIVELSOPORTE76")),
					resultSet.getBigDecimal("TARIFA76"), resultSet.getDate("FALTA76"), resultSet.getString("USUALTA76"),
					resultSet.getDate("FMODIF76"), resultSet.getString("USUMODIF76"));
		}
	};

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

	private RowMapper<Tarifas> rwMapTarifasNivelSoporte = new RowMapper<Tarifas>() {
		public Tarifas mapRow(ResultSet resultSet, int rowNum) throws SQLException {
			Tarifas tarifa = new Tarifas(UtilSQL.getLong(resultSet, "IDTARIFANIVSOP76"));
			tarifa.setTarifa76(resultSet.getBigDecimal("TARIFA76"));
			tarifa.setfVigenciaDesde76(resultSet.getDate("FVIGENCIADESDE76"));
			tarifa.setfVigenciaHasta76(resultSet.getDate("FVIGENCIAHASTA76"));

			MaestroNivSoporte maestroNivSoporte = new MaestroNivSoporte(UtilSQL.getLong(resultSet, "IDNIVELSOPORTE76"));
			maestroNivSoporte.setDescEs58(resultSet.getString("DESCES58"));
			maestroNivSoporte.setDescEu58(resultSet.getString("DESCEU58"));
			tarifa.setMaestroNivSoporte(maestroNivSoporte);

			return tarifa;
		}
	};

	/**
	 * 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 Tarifas table.
	 *
	 * @param tarifas Tarifas
	 *
	 * @return Tarifas
	 */
	public Tarifas add(Tarifas tarifas) {
		GeneratedKeyHolder generatedKeyHolder = new GeneratedKeyHolder();

		String query = "INSERT INTO TARIFAS (ID_TARIFA_NIV_SOP_76, F_VIGENCIA_DESDE_76, F_VIGENCIA_HASTA_76, ID_NIVEL_SOPORTE_76, TARIFA_76, F_ALTA_76, USU_ALTA_76, F_MODIF_76, USU_MODIF_76) "
				+ "VALUES (" + SEQUENCE_TARIFAS
				+ ".NEXTVAL,:fVigenciaDesde,:fVigenciaHasta,:idNivelSoporte,:tarifa,:fAlta,:usuAlta,:fModif,:usuModif)";

		Object getNivSoporteIdNivelSoporte = null;
		if (tarifas.getMaestroNivSoporte() != null && tarifas.getMaestroNivSoporte().getIdNivelSoporte58() != null) {
			getNivSoporteIdNivelSoporte = tarifas.getMaestroNivSoporte().getIdNivelSoporte58();
		}

		MapSqlParameterSource parameters = new MapSqlParameterSource()
				.addValue("fVigenciaDesde", tarifas.getfVigenciaDesde76())
				.addValue("fVigenciaHasta", tarifas.getfVigenciaHasta76())
				.addValue("idNivelSoporte", getNivSoporteIdNivelSoporte).addValue("tarifa", tarifas.getTarifa76())
				.addValue("fAlta", tarifas.getfAlta76()).addValue("usuAlta", tarifas.getUsuAlta76())
				.addValue("fModif", tarifas.getfModif76()).addValue("usuModif", tarifas.getUsuModif76());

		NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
		namedParameterJdbcTemplate.update(query, parameters, generatedKeyHolder,
				new String[] { "ID_TARIFA_NIV_SOP_76" });
		tarifas.setIdTarifaNivSop76(generatedKeyHolder.getKey().longValue());

		return tarifas;
	}

	/**
	 * Updates a single row in the Tarifas table.
	 *
	 * @param tarifas Tarifas
	 *
	 * @return Tarifas
	 */
	public Tarifas update(Tarifas tarifas) {
		String query = "UPDATE TARIFAS SET F_VIGENCIA_DESDE_76=?, F_VIGENCIA_HASTA_76=?, ID_NIVEL_SOPORTE_76=?, TARIFA_76=?, F_MODIF_76=?, USU_MODIF_76=? WHERE ID_TARIFA_NIV_SOP_76=?";

		Object getNivSoporteIdNivelSoporte = null;
		if (tarifas.getMaestroNivSoporte() != null && tarifas.getMaestroNivSoporte().getIdNivelSoporte58() != null) {
			getNivSoporteIdNivelSoporte = tarifas.getMaestroNivSoporte().getIdNivelSoporte58();
		}

		this.jdbcTemplate.update(query, tarifas.getfVigenciaDesde76(), tarifas.getfVigenciaHasta76(),
				getNivSoporteIdNivelSoporte, tarifas.getTarifa76(), tarifas.getfModif76(), tarifas.getUsuModif76(),
				tarifas.getIdTarifaNivSop76());
		return tarifas;
	}

	/**
	 * Finds a single row in the Tarifas table.
	 *
	 * @param tarifas Tarifas
	 *
	 * @return Tarifas
	 */
	@Transactional(readOnly = true)
	public Tarifas find(Tarifas tarifas) {
		String query = "SELECT t1.ID_TARIFA_NIV_SOP_76 IDTARIFANIVSOP76, t1.F_VIGENCIA_DESDE_76 FVIGENCIADESDE76, t1.F_VIGENCIA_HASTA_76 FVIGENCIAHASTA76, t1.ID_NIVEL_SOPORTE_76 IDNIVELSOPORTE76, t1.TARIFA_76 TARIFA76, t1.F_ALTA_76 FALTA76, t1.USU_ALTA_76 USUALTA76, t1.F_MODIF_76 FMODIF76, t1.USU_MODIF_76 USUMODIF76 FROM TARIFAS t1  WHERE t1.ID_TARIFA_NIV_SOP_76 = ?  ";

		List<Tarifas> tarifasList = this.jdbcTemplate.query(query, this.rwMap, tarifas.getIdTarifaNivSop76());
		return DataAccessUtils.uniqueResult(tarifasList);
	}

	/**
	 * Removes a single row in the Tarifas table.
	 *
	 * @param tarifas Tarifas
	 */
	public void remove(Tarifas tarifas) {
		String query = "DELETE FROM TARIFAS WHERE ID_TARIFA_NIV_SOP_76=?";
		this.jdbcTemplate.update(query, tarifas.getIdTarifaNivSop76());
	}

	public List<Tarifas> getMultiple(Tarifas filterTarifas, TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_TARIFA_NIV_SOP_76 IDTARIFANIVSOP76, t1.F_VIGENCIA_DESDE_76 FVIGENCIADESDE76, t1.F_VIGENCIA_HASTA_76 FVIGENCIAHASTA76, t1.ID_NIVEL_SOPORTE_76 IDNIVELSOPORTE76, t1.TARIFA_76 TARIFA76, t1.F_ALTA_76 FALTA76, t1.USU_ALTA_76 USUALTA76, t1.F_MODIF_76 FMODIF76, t1.USU_MODIF_76 USUMODIF76 ");
		// FROM
		query.append("FROM TARIFAS t1 ");
		// WHERE clause & Params
		Map<String, Object> mapaWhere = this.getWhereLikeMap(filterTarifas, 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, Tarifas.class, params, "id_tarifa_niv_sop_76"));

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

	/**
	 * Finds a list of rows in the Tarifas table.
	 *
	 * @param tarifas         Tarifas
	 * @param tableRequestDto TableRequestDto
	 *
	 * @return List<Tarifas>
	 */
	@Transactional(readOnly = true)
	public List<Tarifas> findAll(Tarifas tarifas, TableRequestDto tableRequestDto) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_TARIFA_NIV_SOP_76 IDTARIFANIVSOP76,t1.F_VIGENCIA_DESDE_76 FVIGENCIADESDE76,t1.F_VIGENCIA_HASTA_76 FVIGENCIAHASTA76,t1.ID_NIVEL_SOPORTE_76 IDNIVELSOPORTE76,t1.TARIFA_76 TARIFA76,t1.F_ALTA_76 FALTA76,t1.USU_ALTA_76 USUALTA76,t1.F_MODIF_76 FMODIF76,t1.USU_MODIF_76 USUMODIF76 ");

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

		// WHERE clause & Params
		Map<String, ?> mapaWhere = this.getWhereMap(tarifas);
		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, TarifasDaoImpl.ORDER_BY_WHITE_LIST);
		}

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

	/**
	 * Finds rows in the Tarifas table using like.
	 *
	 * @param tarifas         Tarifas
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 *
	 * @return List<Tarifas>
	 */
	@Transactional(readOnly = true)
	public List<Tarifas> findAllLike(Tarifas tarifas, TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_TARIFA_NIV_SOP_76 IDTARIFANIVSOP76,t1.F_VIGENCIA_DESDE_76 FVIGENCIADESDE76,t1.F_VIGENCIA_HASTA_76 FVIGENCIAHASTA76,t1.ID_NIVEL_SOPORTE_76 IDNIVELSOPORTE76,t1.TARIFA_76 TARIFA76,t1.F_ALTA_76 FALTA76,t1.USU_ALTA_76 USUALTA76,t1.F_MODIF_76 FMODIF76,t1.USU_MODIF_76 USUMODIF76 ");

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

		// WHERE clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(tarifas, 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, TarifasDaoImpl.ORDER_BY_WHITE_LIST);
		}

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

	/*
	 * OPERACIONES RUP_TABLE
	 */

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

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

		// WHERE clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(tarifas, 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 Tarifas selected for rup_table
	 *
	 * @param tarifas         Tarifas
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 *
	 * @return List<TableRowDto<Tarifas>>
	 */
	@Override
	public List<TableRowDto<Tarifas>> reorderSelection(Tarifas tarifas, TableRequestDto tableRequestDto,
			Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_TARIFA_NIV_SOP_76 IDTARIFANIVSOP76,t1.F_VIGENCIA_DESDE_76 FVIGENCIADESDE76,t1.F_VIGENCIA_HASTA_76 FVIGENCIAHASTA76,t1.ID_NIVEL_SOPORTE_76 IDNIVELSOPORTE76,t1.TARIFA_76 TARIFA76,t1.F_ALTA_76 FALTA76,t1.USU_ALTA_76 USUALTA76,t1.F_MODIF_76 FMODIF76,t1.USU_MODIF_76 USUMODIF76 ");
		// FROM
		query.append("FROM TARIFAS t1 ");
		// FILTRADO
		// WHERE clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(tarifas, 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, Tarifas.class,
				filterParamList, "idtarifanivsop76");

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

	/**
	 * Search method for rup_table
	 *
	 * @param filterParams    Tarifas
	 * @param searchParams    Tarifas
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 *
	 * @return List<TableRowDto<Tarifas>>
	 */
	@Override
	public List<TableRowDto<Tarifas>> search(Tarifas filterParams, Tarifas searchParams,
			TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_TARIFA_NIV_SOP_76 IDTARIFANIVSOP76,t1.F_VIGENCIA_DESDE_76 FVIGENCIADESDE76,t1.F_VIGENCIA_HASTA_76 FVIGENCIAHASTA76,t1.ID_NIVEL_SOPORTE_76 IDNIVELSOPORTE76,t1.TARIFA_76 TARIFA76,t1.F_ALTA_76 FALTA76,t1.USU_ALTA_76 USUALTA76,t1.F_MODIF_76 FMODIF76,t1.USU_MODIF_76 USUMODIF76 ");
		// FROM
		query.append("FROM TARIFAS 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, Tarifas.class,
				filterParamList, searchSQL, searchParamList, from_alias, "IDTARIFANIVSOP76");

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

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

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

	/**
	 * Busca las tarifas por nivel soporte entre fechas.
	 * 
	 * @param fechaIniCalculoPantalla Date
	 * @param fechaFinCalculoPantalla Date
	 * @return List<Tarifas>
	 */
	@Transactional(readOnly = true)
	public List<Tarifas> findTarifasPorNivelSoporteEntreFechas(Date fechaIniCalculoPantalla,
			Date fechaFinCalculoPantalla) {
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_TARIFA_NIV_SOP_76 IDTARIFANIVSOP76, t1.ID_NIVEL_SOPORTE_76 IDNIVELSOPORTE76, t1.TARIFA_76 TARIFA76, t1.F_VIGENCIA_DESDE_76 FVIGENCIADESDE76, ");
		query.append(
				" CASE WHEN t1.F_VIGENCIA_HASTA_76 > ? OR t1.F_VIGENCIA_HASTA_76 IS NULL THEN ? ELSE t1.F_VIGENCIA_HASTA_76 END AS FVIGENCIAHASTA76,");
		query.append(" t2.DESC_ES_58 DESCES58, t2.DESC_EU_58 DESCEU58");
		query.append(" FROM TARIFAS t1");
		query.append(" LEFT JOIN MAESTRO_NIV_SOPORTE t2 ON (t1.ID_NIVEL_SOPORTE_76 = t2.ID_NIVEL_SOPORTE_58)");
		query.append(" WHERE (F_VIGENCIA_HASTA_76 >= ? OR F_VIGENCIA_HASTA_76 IS NULL) ");
		query.append(" AND F_VIGENCIA_DESDE_76 <= ? ");
		query.append(" ORDER BY t1.ID_NIVEL_SOPORTE_76, t1.F_VIGENCIA_DESDE_76 ");

		return this.jdbcTemplate.query(query.toString(), this.rwMapTarifasNivelSoporte, fechaFinCalculoPantalla,
				fechaFinCalculoPantalla, fechaIniCalculoPantalla, fechaFinCalculoPantalla);
	}

	/*
	 * MÉTODOS PRIVADOS
	 */

	/**
	 * Returns a map with the needed value to create the conditions to filter by the
	 * Tarifas entity
	 *
	 * @param tarifas Tarifas 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(Tarifas tarifas) {
		StringBuilder where = new StringBuilder(TarifasDaoImpl.STRING_BUILDER_INIT);
		List<Object> params = new ArrayList<Object>();

		if (tarifas != null && tarifas.getIdTarifaNivSop76() != null) {
			where.append(" AND t1.ID_TARIFA_NIV_SOP_76 = ?");
			params.add(tarifas.getIdTarifaNivSop76());
		}
		if (tarifas != null && tarifas.getfVigenciaDesde76() != null) {
			where.append(" AND t1.F_VIGENCIA_DESDE_76 = ?");
			params.add(tarifas.getfVigenciaDesde76());
		}
		if (tarifas != null && tarifas.getfVigenciaHasta76() != null) {
			where.append(" AND t1.F_VIGENCIA_HASTA_76 = ?");
			params.add(tarifas.getfVigenciaHasta76());
		}
		if (tarifas != null && tarifas.getMaestroNivSoporte() != null
				&& tarifas.getMaestroNivSoporte().getIdNivelSoporte58() != null) {
			where.append(" AND t1.ID_NIVEL_SOPORTE_76 = ?");
			params.add(tarifas.getMaestroNivSoporte().getIdNivelSoporte58());
		}
		if (tarifas != null && tarifas.getTarifa76() != null) {
			where.append(" AND t1.TARIFA_76 = ?");
			params.add(tarifas.getTarifa76());
		}
		if (tarifas != null && tarifas.getfAlta76() != null) {
			where.append(" AND t1.F_ALTA_76 = ?");
			params.add(tarifas.getfAlta76());
		}
		if (tarifas != null && tarifas.getUsuAlta76() != null) {
			where.append(" AND t1.USU_ALTA_76 = ?");
			params.add(tarifas.getUsuAlta76());
		}
		if (tarifas != null && tarifas.getfModif76() != null) {
			where.append(" AND t1.F_MODIF_76 = ?");
			params.add(tarifas.getfModif76());
		}
		if (tarifas != null && tarifas.getUsuModif76() != null) {
			where.append(" AND t1.USU_MODIF_76 = ?");
			params.add(tarifas.getUsuModif76());
		}

		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
	 * Tarifas entity
	 *
	 * @param tarifas    Tarifas 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(Tarifas tarifas, Boolean startsWith) {
		StringBuilder where = new StringBuilder(TarifasDaoImpl.STRING_BUILDER_INIT);
		List<Object> params = new ArrayList<Object>();

		if (tarifas != null && tarifas.getIdTarifaNivSop76() != null) {
			where.append(" AND t1.ID_TARIFA_NIV_SOP_76 = ?");
			params.add(tarifas.getIdTarifaNivSop76());
		}
		if (tarifas != null && tarifas.getfVigenciaDesde76() != null) {
			where.append(" AND t1.F_VIGENCIA_DESDE_76 = ?");
			params.add(tarifas.getfVigenciaDesde76());
		}
		if (tarifas != null && tarifas.getfVigenciaHasta76() != null) {
			where.append(" AND t1.F_VIGENCIA_HASTA_76 = ?");
			params.add(tarifas.getfVigenciaHasta76());
		}
		if (tarifas != null && tarifas.getMaestroNivSoporte() != null
				&& tarifas.getMaestroNivSoporte().getIdNivelSoporte58() != null) {
			where.append(" AND t1.ID_NIVEL_SOPORTE_76 = ?");
			params.add(tarifas.getMaestroNivSoporte().getIdNivelSoporte58());
		}
		if (tarifas != null && tarifas.getTarifa76() != null) {
			where.append(" AND t1.TARIFA_76 = ?");
			params.add(tarifas.getTarifa76());
		}
		if (tarifas != null && tarifas.getfAlta76() != null) {
			where.append(" AND t1.F_ALTA_76 = ?");
			params.add(tarifas.getfAlta76());
		}
		if (tarifas != null && tarifas.getUsuAlta76() != null) {
			where.append(" AND UPPER(t1.USU_ALTA_76) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(tarifas.getUsuAlta76().toUpperCase() + "%");
			} else {
				params.add("%" + tarifas.getUsuAlta76().toUpperCase() + "%");
			}
			where.append(" AND t1.USU_ALTA_76 IS NOT NULL");
		}
		if (tarifas != null && tarifas.getfModif76() != null) {
			where.append(" AND t1.F_MODIF_76 = ?");
			params.add(tarifas.getfModif76());
		}
		if (tarifas != null && tarifas.getUsuModif76() != null) {
			where.append(" AND UPPER(t1.USU_MODIF_76) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(tarifas.getUsuModif76().toUpperCase() + "%");
			} else {
				params.add("%" + tarifas.getUsuModif76().toUpperCase() + "%");
			}
			where.append(" AND t1.USU_MODIF_76 IS NOT NULL");
		}

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

		return mapWhere;
	}
}
