/*
* 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.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.MaestroMotAnulacion;
import com.ejie.ad74a.util.UtilSQL;

/**
 * MaestroMotAnulacionDaoImpl generated by UDA, 15-ago-2023 8:18:24.
 * 
 * @author UDA
 */

@Repository
@Transactional
public class MaestroMotAnulacionDaoImpl implements MaestroMotAnulacionDao {

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

	protected static final String[] ORDER_BY_WHITE_LIST = new String[] { "IDMOTIVOANUL57", "CODANULACION57", "DESCES57",
			"DESCEU57", "CTAERRONEA57", "FALTA57", "USUALTA57", "FMODIF57", "USUMODIF57" };

	private JdbcTemplate jdbcTemplate;

	public static final String SEQUENCE_MAESTRO_MOT_ANULACION = "SEQ_MAESTRO_MOT_ANULACION";

	/*
	 * ROW_MAPPERS
	 */
	private RowMapper<MaestroMotAnulacion> rwMap = new RowMapper<MaestroMotAnulacion>() {
		public MaestroMotAnulacion mapRow(ResultSet resultSet, int rowNum) throws SQLException {
			return new MaestroMotAnulacion(UtilSQL.getLong(resultSet, "IDMOTIVOANUL57"),
					resultSet.getString("CODANULACION57"), resultSet.getString("DESCES57"),
					resultSet.getString("DESCEU57"), UtilSQL.getLong(resultSet, "CTAERRONEA57"),
					resultSet.getDate("FALTA57"), resultSet.getString("USUALTA57"), resultSet.getDate("FMODIF57"),
					resultSet.getString("USUMODIF57"));
		}
	};

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

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

		GeneratedKeyHolder generatedKeyHolder = new GeneratedKeyHolder();

		String query = "INSERT INTO MAESTRO_MOT_ANULACION (ID_MOTIVO_ANUL_57, COD_ANULACION_57, DESC_ES_57, DESC_EU_57, CTA_ERRONEA_57, F_ALTA_57, USU_ALTA_57, F_MODIF_57, USU_MODIF_57) "
				+ "VALUES (" + SEQUENCE_MAESTRO_MOT_ANULACION
				+ ".NEXTVAL,:codAnulacion,:descEs,:descEu,:ctaErronea,:fAlta,:usuAlta,:fModif,:usuModif)";

		MapSqlParameterSource parameters = new MapSqlParameterSource()
				.addValue("codAnulacion", maestromotanulacion.getCodAnulacion57())
				.addValue("descEs", maestromotanulacion.getDescEs57())
				.addValue("descEu", maestromotanulacion.getDescEu57())
				.addValue("ctaErronea", maestromotanulacion.getCtaErronea57())
				.addValue("fAlta", maestromotanulacion.getfAlta57())
				.addValue("usuAlta", maestromotanulacion.getUsuAlta57())
				.addValue("fModif", maestromotanulacion.getfModif57())
				.addValue("usuModif", maestromotanulacion.getUsuModif57());

		NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
		namedParameterJdbcTemplate.update(query, parameters, generatedKeyHolder, new String[] { "ID_MOTIVO_ANUL_57" });
		maestromotanulacion.setIdMotivoAnul57(generatedKeyHolder.getKey().longValue());

		return maestromotanulacion;
	}

	/**
	 * Updates a single row in the MaestroMotAnulacion table.
	 *
	 * @param maestromotanulacion MaestroMotAnulacion
	 *
	 * @return MaestroMotAnulacion
	 */
	public MaestroMotAnulacion update(MaestroMotAnulacion maestromotanulacion) {
		String query = "UPDATE MAESTRO_MOT_ANULACION SET COD_ANULACION_57=?, DESC_ES_57=?, DESC_EU_57=?, CTA_ERRONEA_57=?, F_MODIF_57=?, USU_MODIF_57=? WHERE ID_MOTIVO_ANUL_57=?";
		this.jdbcTemplate.update(query, maestromotanulacion.getCodAnulacion57(), maestromotanulacion.getDescEs57(),
				maestromotanulacion.getDescEu57(), maestromotanulacion.getCtaErronea57(),
				maestromotanulacion.getfModif57(), maestromotanulacion.getUsuModif57(),
				maestromotanulacion.getIdMotivoAnul57());
		return maestromotanulacion;
	}

	/**
	 * Finds a single row in the MaestroMotAnulacion table.
	 *
	 * @param maestromotanulacion MaestroMotAnulacion
	 *
	 * @return MaestroMotAnulacion
	 */
	@Transactional(readOnly = true)
	public MaestroMotAnulacion find(MaestroMotAnulacion maestromotanulacion) {
		String query = "SELECT t1.ID_MOTIVO_ANUL_57 IDMOTIVOANUL57, t1.COD_ANULACION_57 CODANULACION57, t1.DESC_ES_57 DESCES57, t1.DESC_EU_57 DESCEU57, t1.CTA_ERRONEA_57 CTAERRONEA57, t1.F_ALTA_57 FALTA57, t1.USU_ALTA_57 USUALTA57, t1.F_MODIF_57 FMODIF57, t1.USU_MODIF_57 USUMODIF57 FROM MAESTRO_MOT_ANULACION t1  WHERE t1.ID_MOTIVO_ANUL_57 = ?  ";

		List<MaestroMotAnulacion> maestromotanulacionList = this.jdbcTemplate.query(query, this.rwMap,
				maestromotanulacion.getIdMotivoAnul57());
		return DataAccessUtils.uniqueResult(maestromotanulacionList);
	}

	/**
	 * Removes a single row in the MaestroMotAnulacion table.
	 *
	 * @param maestromotanulacion MaestroMotAnulacion
	 */
	public void remove(MaestroMotAnulacion maestromotanulacion) {
		String query = "DELETE FROM MAESTRO_MOT_ANULACION WHERE ID_MOTIVO_ANUL_57=?";
		this.jdbcTemplate.update(query, maestromotanulacion.getIdMotivoAnul57());
	}

	public List<MaestroMotAnulacion> getMultiple(MaestroMotAnulacion filterMaestroMotAnulacion,
			TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_MOTIVO_ANUL_57 IDMOTIVOANUL57, t1.COD_ANULACION_57 CODANULACION57, t1.DESC_ES_57 DESCES57, t1.DESC_EU_57 DESCEU57, t1.CTA_ERRONEA_57 CTAERRONEA57, t1.F_ALTA_57 FALTA57, t1.USU_ALTA_57 USUALTA57, t1.F_MODIF_57 FMODIF57, t1.USU_MODIF_57 USUMODIF57 ");
		// FROM
		query.append("FROM MAESTRO_MOT_ANULACION t1 ");
		// WHERE clause & Params
		Map<String, Object> mapaWhere = this.getWhereLikeMap(filterMaestroMotAnulacion, 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,
				MaestroMotAnulacion.class, params, "id_motivo_anul_57"));

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

	/**
	 * Finds a list of rows in the MaestroMotAnulacion table.
	 *
	 * @param maestromotanulacion MaestroMotAnulacion
	 * @param tableRequestDto     TableRequestDto
	 *
	 * @return List<MaestroMotAnulacion>
	 */
	@Transactional(readOnly = true)
	public List<MaestroMotAnulacion> findAll(MaestroMotAnulacion maestromotanulacion, TableRequestDto tableRequestDto) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_MOTIVO_ANUL_57 IDMOTIVOANUL57,t1.COD_ANULACION_57 CODANULACION57,t1.DESC_ES_57 DESCES57,t1.DESC_EU_57 DESCEU57,t1.CTA_ERRONEA_57 CTAERRONEA57,t1.F_ALTA_57 FALTA57,t1.USU_ALTA_57 USUALTA57,t1.F_MODIF_57 FMODIF57,t1.USU_MODIF_57 USUMODIF57 ");

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

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

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

	/**
	 * Finds rows in the MaestroMotAnulacion table using like.
	 *
	 * @param maestromotanulacion MaestroMotAnulacion
	 * @param tableRequestDto     TableRequestDto
	 * @param startsWith          Boolean
	 *
	 * @return List<MaestroMotAnulacion>
	 */
	@Transactional(readOnly = true)
	public List<MaestroMotAnulacion> findAllLike(MaestroMotAnulacion maestromotanulacion,
			TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_MOTIVO_ANUL_57 IDMOTIVOANUL57,t1.COD_ANULACION_57 CODANULACION57,t1.DESC_ES_57 DESCES57,t1.DESC_EU_57 DESCEU57,t1.CTA_ERRONEA_57 CTAERRONEA57,t1.F_ALTA_57 FALTA57,t1.USU_ALTA_57 USUALTA57,t1.F_MODIF_57 FMODIF57,t1.USU_MODIF_57 USUMODIF57 ");

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

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

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

	/*
	 * OPERACIONES RUP_TABLE
	 */

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

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

		// WHERE clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(maestromotanulacion, 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 MaestroMotAnulacion selected for rup_table
	 *
	 * @param maestromotanulacion MaestroMotAnulacion
	 * @param tableRequestDto     TableRequestDto
	 * @param startsWith          Boolean
	 *
	 * @return List<TableRowDto<MaestroMotAnulacion>>
	 */
	@Override
	public List<TableRowDto<MaestroMotAnulacion>> reorderSelection(MaestroMotAnulacion maestromotanulacion,
			TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_MOTIVO_ANUL_57 IDMOTIVOANUL57,t1.COD_ANULACION_57 CODANULACION57,t1.DESC_ES_57 DESCES57,t1.DESC_EU_57 DESCEU57,t1.CTA_ERRONEA_57 CTAERRONEA57,t1.F_ALTA_57 FALTA57,t1.USU_ALTA_57 USUALTA57,t1.F_MODIF_57 FMODIF57,t1.USU_MODIF_57 USUMODIF57 ");
		// FROM
		query.append("FROM MAESTRO_MOT_ANULACION t1 ");
		// FILTRADO
		// WHERE clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(maestromotanulacion, 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,
				MaestroMotAnulacion.class, filterParamList, "idmotivoanul57");

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

	/**
	 * Search method for rup_table
	 *
	 * @param filterParams    MaestroMotAnulacion
	 * @param searchParams    MaestroMotAnulacion
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 *
	 * @return List<TableRowDto<MaestroMotAnulacion>>
	 */
	@Override
	public List<TableRowDto<MaestroMotAnulacion>> search(MaestroMotAnulacion filterParams,
			MaestroMotAnulacion searchParams, TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_MOTIVO_ANUL_57 IDMOTIVOANUL57,t1.COD_ANULACION_57 CODANULACION57,t1.DESC_ES_57 DESCES57,t1.DESC_EU_57 DESCEU57,t1.CTA_ERRONEA_57 CTAERRONEA57,t1.F_ALTA_57 FALTA57,t1.USU_ALTA_57 USUALTA57,t1.F_MODIF_57 FMODIF57,t1.USU_MODIF_57 USUMODIF57 ");
		// FROM
		query.append("FROM MAESTRO_MOT_ANULACION 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,
				MaestroMotAnulacion.class, filterParamList, searchSQL, searchParamList, from_alias, "IDMOTIVOANUL57");

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

		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
	 * MaestroMotAnulacion entity
	 *
	 * @param maestromotanulacion MaestroMotAnulacion 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(MaestroMotAnulacion maestromotanulacion) {
		StringBuilder where = new StringBuilder(MaestroMotAnulacionDaoImpl.STRING_BUILDER_INIT);
		List<Object> params = new ArrayList<Object>();

		if (maestromotanulacion != null && maestromotanulacion.getIdMotivoAnul57() != null) {
			where.append(" AND t1.ID_MOTIVO_ANUL_57 = ?");
			params.add(maestromotanulacion.getIdMotivoAnul57());
		}
		if (maestromotanulacion != null && maestromotanulacion.getCodAnulacion57() != null) {
			where.append(" AND t1.COD_ANULACION_57 = ?");
			params.add(maestromotanulacion.getCodAnulacion57());
		}
		if (maestromotanulacion != null && maestromotanulacion.getDescEs57() != null) {
			where.append(" AND t1.DESC_ES_57 = ?");
			params.add(maestromotanulacion.getDescEs57());
		}
		if (maestromotanulacion != null && maestromotanulacion.getDescEu57() != null) {
			where.append(" AND t1.DESC_EU_57 = ?");
			params.add(maestromotanulacion.getDescEu57());
		}
		if (maestromotanulacion != null && maestromotanulacion.getCtaErronea57() != null) {
			where.append(" AND t1.CTA_ERRONEA_57 = ?");
			params.add(maestromotanulacion.getCtaErronea57());
		}
		if (maestromotanulacion != null && maestromotanulacion.getfAlta57() != null) {
			where.append(" AND t1.F_ALTA_57 = ?");
			params.add(maestromotanulacion.getfAlta57());
		}
		if (maestromotanulacion != null && maestromotanulacion.getUsuAlta57() != null) {
			where.append(" AND t1.USU_ALTA_57 = ?");
			params.add(maestromotanulacion.getUsuAlta57());
		}
		if (maestromotanulacion != null && maestromotanulacion.getfModif57() != null) {
			where.append(" AND t1.F_MODIF_57 = ?");
			params.add(maestromotanulacion.getfModif57());
		}
		if (maestromotanulacion != null && maestromotanulacion.getUsuModif57() != null) {
			where.append(" AND t1.USU_MODIF_57 = ?");
			params.add(maestromotanulacion.getUsuModif57());
		}

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

		if (maestromotanulacion != null && maestromotanulacion.getIdMotivoAnul57() != null) {
			where.append(" AND t1.ID_MOTIVO_ANUL_57 = ?");
			params.add(maestromotanulacion.getIdMotivoAnul57());
		}
		if (maestromotanulacion != null && maestromotanulacion.getCodAnulacion57() != null) {
			where.append(" AND UPPER(t1.COD_ANULACION_57) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(maestromotanulacion.getCodAnulacion57().toUpperCase() + "%");
			} else {
				params.add("%" + maestromotanulacion.getCodAnulacion57().toUpperCase() + "%");
			}
			where.append(" AND t1.COD_ANULACION_57 IS NOT NULL");
		}
		if (maestromotanulacion != null && maestromotanulacion.getDescEs57() != null) {
			where.append(" AND UPPER(t1.DESC_ES_57) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(maestromotanulacion.getDescEs57().toUpperCase() + "%");
			} else {
				params.add("%" + maestromotanulacion.getDescEs57().toUpperCase() + "%");
			}
			where.append(" AND t1.DESC_ES_57 IS NOT NULL");
		}
		if (maestromotanulacion != null && maestromotanulacion.getDescEu57() != null) {
			where.append(" AND UPPER(t1.DESC_EU_57) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(maestromotanulacion.getDescEu57().toUpperCase() + "%");
			} else {
				params.add("%" + maestromotanulacion.getDescEu57().toUpperCase() + "%");
			}
			where.append(" AND t1.DESC_EU_57 IS NOT NULL");
		}
		if (maestromotanulacion != null && maestromotanulacion.getCtaErronea57() != null) {
			where.append(" AND t1.CTA_ERRONEA_57 = ?");
			params.add(maestromotanulacion.getCtaErronea57());
		}
		if (maestromotanulacion != null && maestromotanulacion.getfAlta57() != null) {
			where.append(" AND t1.F_ALTA_57 = ?");
			params.add(maestromotanulacion.getfAlta57());
		}
		if (maestromotanulacion != null && maestromotanulacion.getUsuAlta57() != null) {
			where.append(" AND UPPER(t1.USU_ALTA_57) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(maestromotanulacion.getUsuAlta57().toUpperCase() + "%");
			} else {
				params.add("%" + maestromotanulacion.getUsuAlta57().toUpperCase() + "%");
			}
			where.append(" AND t1.USU_ALTA_57 IS NOT NULL");
		}
		if (maestromotanulacion != null && maestromotanulacion.getfModif57() != null) {
			where.append(" AND t1.F_MODIF_57 = ?");
			params.add(maestromotanulacion.getfModif57());
		}
		if (maestromotanulacion != null && maestromotanulacion.getUsuModif57() != null) {
			where.append(" AND UPPER(t1.USU_MODIF_57) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(maestromotanulacion.getUsuModif57().toUpperCase() + "%");
			} else {
				params.add("%" + maestromotanulacion.getUsuModif57().toUpperCase() + "%");
			}
			where.append(" AND t1.USU_MODIF_57 IS NOT NULL");
		}

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

		return mapWhere;
	}
}
