/*
* 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.ae01b;

import com.ejie.ad74a.model.ae01b.MotAnuCobro;
import com.ejie.ad74a.util.UtilSQL;
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;

/**
 * MotAnuCobroDaoImpl generated by UDA, 24-oct-2023 13:37:08.
 * 
 * @author UDA
 */

@Repository
@Transactional
public class MotAnuCobroDaoImpl implements MotAnuCobroDao {

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

	protected static final String[] ORDER_BY_WHITE_LIST = new String[] { "IDMOTANUCOBRO37", "CODANULACION37",
			"DESCRIPCIONES37", "DESCRIPCIONEU37", "INDCTAERRONEA37", "USUALTA37", "FALTA37", "USUMODIF37", "FMODIF37" };

	private JdbcTemplate jdbcTemplate;

	public static final String SEQUENCE_MOT_ANU_COBRO = "SEQ_MOT_ANU_COBRO";

	/*
	 * ROW_MAPPERS
	 */
	private RowMapper<MotAnuCobro> rwMap = new RowMapper<MotAnuCobro>() {
		public MotAnuCobro mapRow(ResultSet resultSet, int rowNum) throws SQLException {
			return new MotAnuCobro(UtilSQL.getLong(resultSet, "IDMOTANUCOBRO37"), resultSet.getString("CODANULACION37"),
					resultSet.getString("DESCRIPCIONES37"), resultSet.getString("DESCRIPCIONEU37"),
					UtilSQL.getInt(resultSet, "INDCTAERRONEA37"), resultSet.getString("USUALTA37"),
					resultSet.getDate("FALTA37"), resultSet.getString("USUMODIF37"), resultSet.getDate("FMODIF37"));
		}
	};

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

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

		String query = "INSERT INTO AE01B.MOT_ANU_COBRO (ID_MOT_ANU_COBRO_37, COD_ANULACION_37, DESCRIPCION_ES_37, DESCRIPCION_EU_37, IND_CTA_ERRONEA_37, USU_ALTA_37, F_ALTA_37, USU_MODIF_37, F_MODIF_37) "
				+ "VALUES (" + SEQUENCE_MOT_ANU_COBRO
				+ ".NEXTVAL, :codAnulacion, :descripcionEs, :descripcionEu, :indCtaErronea, :usuAlta, :fAlta, :usuModif, :fModif)";

		MapSqlParameterSource parameters = new MapSqlParameterSource()
				.addValue("codAnulacion", motanucobro.getCodAnulacion37())
				.addValue("descripcionEs", motanucobro.getDescripcionEs37())
				.addValue("descripcionEu", motanucobro.getDescripcionEu37())
				.addValue("indCtaErronea", motanucobro.getIndCtaErronea37())
				.addValue("usuAlta", motanucobro.getUsuAlta37()).addValue("fAlta", motanucobro.getfAlta37())
				.addValue("usuModif", motanucobro.getUsuModif37()).addValue("fModif", motanucobro.getfModif37());

		NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
		namedParameterJdbcTemplate.update(query, parameters, generatedKeyHolder,
				new String[] { "ID_MOT_ANU_COBRO_37" });
		motanucobro.setIdMotAnuCobro37(generatedKeyHolder.getKey().longValue());

		return motanucobro;
	}

	/**
	 * Updates a single row in the MotAnuCobro table.
	 *
	 * @param motanucobro MotAnuCobro
	 *
	 * @return MotAnuCobro
	 */
	public MotAnuCobro update(MotAnuCobro motanucobro) {
		String query = "UPDATE AE01B.MOT_ANU_COBRO SET COD_ANULACION_37=?, DESCRIPCION_ES_37=?, DESCRIPCION_EU_37=?, IND_CTA_ERRONEA_37=?, USU_MODIF_37=?, F_MODIF_37=? WHERE ID_MOT_ANU_COBRO_37=?";
		this.jdbcTemplate.update(query, motanucobro.getCodAnulacion37(), motanucobro.getDescripcionEs37(),
				motanucobro.getDescripcionEu37(), motanucobro.getIndCtaErronea37(), motanucobro.getUsuModif37(),
				motanucobro.getfModif37(), motanucobro.getIdMotAnuCobro37());
		return motanucobro;
	}

	/**
	 * Finds a single row in the MotAnuCobro table.
	 *
	 * @param motanucobro MotAnuCobro
	 *
	 * @return MotAnuCobro
	 */
	@Transactional(readOnly = true)
	public MotAnuCobro find(MotAnuCobro motanucobro) {
		String query = "SELECT t1.ID_MOT_ANU_COBRO_37 IDMOTANUCOBRO37, t1.COD_ANULACION_37 CODANULACION37, t1.DESCRIPCION_ES_37 DESCRIPCIONES37, t1.DESCRIPCION_EU_37 DESCRIPCIONEU37, t1.IND_CTA_ERRONEA_37 INDCTAERRONEA37, t1.USU_ALTA_37 USUALTA37, t1.F_ALTA_37 FALTA37, t1.USU_MODIF_37 USUMODIF37, t1.F_MODIF_37 FMODIF37 FROM AE01B.MOT_ANU_COBRO t1  WHERE t1.ID_MOT_ANU_COBRO_37 = ?  ";

		List<MotAnuCobro> motanucobroList = this.jdbcTemplate.query(query, this.rwMap,
				motanucobro.getIdMotAnuCobro37());
		return DataAccessUtils.uniqueResult(motanucobroList);
	}

	/**
	 * Removes a single row in the MotAnuCobro table.
	 *
	 * @param motanucobro MotAnuCobro
	 */
	public void remove(MotAnuCobro motanucobro) {
		String query = "DELETE FROM AE01B.MOT_ANU_COBRO WHERE ID_MOT_ANU_COBRO_37=?";
		this.jdbcTemplate.update(query, motanucobro.getIdMotAnuCobro37());
	}

	public List<MotAnuCobro> getMultiple(MotAnuCobro filterMotAnuCobro, TableRequestDto tableRequestDto,
			Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_MOT_ANU_COBRO_37 IDMOTANUCOBRO37, t1.COD_ANULACION_37 CODANULACION37, t1.DESCRIPCION_ES_37 DESCRIPCIONES37, t1.DESCRIPCION_EU_37 DESCRIPCIONEU37, t1.IND_CTA_ERRONEA_37 INDCTAERRONEA37, t1.USU_ALTA_37 USUALTA37, t1.F_ALTA_37 FALTA37, t1.USU_MODIF_37 USUMODIF37, t1.F_MODIF_37 FMODIF37 ");
		// FROM
		query.append("FROM AE01B.MOT_ANU_COBRO t1 ");
		// WHERE clause & Params
		Map<String, Object> mapaWhere = this.getWhereLikeMap(filterMotAnuCobro, 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, MotAnuCobro.class, params, "id_mot_anu_cobro_37"));

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

	/**
	 * Finds a list of rows in the MotAnuCobro table.
	 *
	 * @param motanucobro     MotAnuCobro
	 * @param tableRequestDto TableRequestDto
	 *
	 * @return List<MotAnuCobro>
	 */
	@Transactional(readOnly = true)
	public List<MotAnuCobro> findAll(MotAnuCobro motanucobro, TableRequestDto tableRequestDto) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_MOT_ANU_COBRO_37 IDMOTANUCOBRO37,t1.COD_ANULACION_37 CODANULACION37,t1.DESCRIPCION_ES_37 DESCRIPCIONES37,t1.DESCRIPCION_EU_37 DESCRIPCIONEU37, t1.IND_CTA_ERRONEA_37 INDCTAERRONEA37, t1.USU_ALTA_37 USUALTA37, t1.F_ALTA_37 FALTA37, t1.USU_MODIF_37 USUMODIF37, t1.F_MODIF_37 FMODIF37 ");

		// FROM
		query.append("FROM AE01B.MOT_ANU_COBRO t1 ");

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

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

	/**
	 * Finds rows in the MotAnuCobro table using like.
	 *
	 * @param motanucobro     MotAnuCobro
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 *
	 * @return List<MotAnuCobro>
	 */
	@Transactional(readOnly = true)
	public List<MotAnuCobro> findAllLike(MotAnuCobro motanucobro, TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_MOT_ANU_COBRO_37 IDMOTANUCOBRO37,t1.COD_ANULACION_37 CODANULACION37,t1.DESCRIPCION_ES_37 DESCRIPCIONES37,t1.DESCRIPCION_EU_37 DESCRIPCIONEU37, t1.IND_CTA_ERRONEA_37 INDCTAERRONEA37, t1.USU_ALTA_37 USUALTA37, t1.F_ALTA_37 FALTA37, t1.USU_MODIF_37 USUMODIF37, t1.F_MODIF_37 FMODIF37 ");

		// FROM
		query.append("FROM AE01B.MOT_ANU_COBRO t1 ");

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

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

	/*
	 * OPERACIONES RUP_TABLE
	 */

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

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

		// WHERE clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(motanucobro, 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 MotAnuCobro selected for rup_table
	 *
	 * @param motanucobro     MotAnuCobro
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 *
	 * @return List<TableRowDto<MotAnuCobro>>
	 */
	@Override
	public List<TableRowDto<MotAnuCobro>> reorderSelection(MotAnuCobro motanucobro, TableRequestDto tableRequestDto,
			Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_MOT_ANU_COBRO_37 IDMOTANUCOBRO37,t1.COD_ANULACION_37 CODANULACION37,t1.DESCRIPCION_ES_37 DESCRIPCIONES37,t1.DESCRIPCION_EU_37 DESCRIPCIONEU37, t1.IND_CTA_ERRONEA_37 INDCTAERRONEA37, t1.USU_ALTA_37 USUALTA37, t1.F_ALTA_37 FALTA37, t1.USU_MODIF_37 USUMODIF37, t1.F_MODIF_37 FMODIF37 ");
		// FROM
		query.append("FROM AE01B.MOT_ANU_COBRO t1 ");
		// FILTRADO
		// WHERE clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(motanucobro, 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, MotAnuCobro.class,
				filterParamList, "idmotanucobro37");

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

	/**
	 * Search method for rup_table
	 *
	 * @param filterParams    MotAnuCobro
	 * @param searchParams    MotAnuCobro
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 *
	 * @return List<TableRowDto<MotAnuCobro>>
	 */
	@Override
	public List<TableRowDto<MotAnuCobro>> search(MotAnuCobro filterParams, MotAnuCobro searchParams,
			TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_MOT_ANU_COBRO_37 IDMOTANUCOBRO37,t1.COD_ANULACION_37 CODANULACION37,t1.DESCRIPCION_ES37 DESCRIPCIONES37,t1.DESCRIPCION_EU_37 DESCRIPCIONEU37, t1.IND_CTA_ERRONEA_37 INDCTAERRONEA37, t1.USU_ALTA_37 USUALTA37, t1.F_ALTA_37 FALTA37, t1.USU_MODIF_37 USUMODIF37, t1.F_MODIF_37 FMODIF37 ");
		// FROM
		query.append("FROM AE01B.MOT_ANU_COBRO 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, MotAnuCobro.class,
				filterParamList, searchSQL, searchParamList, from_alias, "IDMOTANUCOBRO37");

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

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

		if (motanucobro != null && motanucobro.getIdMotAnuCobro37() != null) {
			where.append(" AND t1.ID_MOT_ANU_COBRO_37 = ?");
			params.add(motanucobro.getIdMotAnuCobro37());
		}
		if (motanucobro != null && motanucobro.getCodAnulacion37() != null) {
			where.append(" AND t1.COD_ANULACION_37 = ?");
			params.add(motanucobro.getCodAnulacion37());
		}
		if (motanucobro != null && motanucobro.getDescripcionEs37() != null) {
			where.append(" AND t1.DESCRIPCION_ES_37 = ?");
			params.add(motanucobro.getDescripcionEs37());
		}
		if (motanucobro != null && motanucobro.getDescripcionEu37() != null) {
			where.append(" AND t1.DESCRIPCION_EU_37 = ?");
			params.add(motanucobro.getDescripcionEu37());
		}
		if (motanucobro != null && motanucobro.getIndCtaErronea37() != null) {
			where.append(" AND t1.IND_CTA_ERRONEA_37 = ?");
			params.add(motanucobro.getIndCtaErronea37());
		}
		if (motanucobro != null && motanucobro.getUsuAlta37() != null) {
			where.append(" AND t1.USU_ALTA_37 = ?");
			params.add(motanucobro.getUsuAlta37());
		}
		if (motanucobro != null && motanucobro.getfAlta37() != null) {
			where.append(" AND t1.F_ALTA_37 = ?");
			params.add(motanucobro.getfAlta37());
		}
		if (motanucobro != null && motanucobro.getUsuModif37() != null) {
			where.append(" AND t1.USU_MODIF_37 = ?");
			params.add(motanucobro.getUsuModif37());
		}
		if (motanucobro != null && motanucobro.getfModif37() != null) {
			where.append(" AND t1.F_MODIF_37 = ?");
			params.add(motanucobro.getfModif37());
		}

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

		if (motanucobro != null && motanucobro.getIdMotAnuCobro37() != null) {
			where.append(" AND t1.ID_MOT_ANU_COBRO_37 = ?");
			params.add(motanucobro.getIdMotAnuCobro37());
		}
		if (motanucobro != null && motanucobro.getCodAnulacion37() != null) {
			where.append(" AND UPPER(t1.COD_ANULACION_37) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(motanucobro.getCodAnulacion37().toUpperCase() + "%");
			} else {
				params.add("%" + motanucobro.getCodAnulacion37().toUpperCase() + "%");
			}
			where.append(" AND t1.COD_ANULACION_37 IS NOT NULL");
		}
		if (motanucobro != null && motanucobro.getDescripcionEs37() != null) {
			where.append(" AND UPPER(t1.DESCRIPCION_ES_37) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(motanucobro.getDescripcionEs37().toUpperCase() + "%");
			} else {
				params.add("%" + motanucobro.getDescripcionEs37().toUpperCase() + "%");
			}
			where.append(" AND t1.DESCRIPCION_ES_37 IS NOT NULL");
		}
		if (motanucobro != null && motanucobro.getDescripcionEu37() != null) {
			where.append(" AND UPPER(t1.DESCRIPCION_EU_37) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(motanucobro.getDescripcionEu37().toUpperCase() + "%");
			} else {
				params.add("%" + motanucobro.getDescripcionEu37().toUpperCase() + "%");
			}
			where.append(" AND t1.DESCRIPCION_EU_37 IS NOT NULL");
		}
		if (motanucobro != null && motanucobro.getIndCtaErronea37() != null) {
			where.append(" AND t1.IND_CTA_ERRONEA_37 = ?");
			params.add(motanucobro.getIndCtaErronea37());
		}
		if (motanucobro != null && motanucobro.getUsuAlta37() != null) {
			where.append(" AND UPPER(t1.USU_ALTA_37) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(motanucobro.getUsuAlta37().toUpperCase() + "%");
			} else {
				params.add("%" + motanucobro.getUsuAlta37().toUpperCase() + "%");
			}
			where.append(" AND t1.USU_ALTA_37 IS NOT NULL");
		}
		if (motanucobro != null && motanucobro.getfAlta37() != null) {
			where.append(" AND t1.F_ALTA_37 = ?");
			params.add(motanucobro.getfAlta37());
		}
		if (motanucobro != null && motanucobro.getUsuModif37() != null) {
			where.append(" AND UPPER(t1.USU_MODIF_37) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(motanucobro.getUsuModif37().toUpperCase() + "%");
			} else {
				params.add("%" + motanucobro.getUsuModif37().toUpperCase() + "%");
			}
			where.append(" AND t1.USU_MODIF_37 IS NOT NULL");
		}
		if (motanucobro != null && motanucobro.getfModif37() != null) {
			where.append(" AND t1.F_MODIF_37 = ?");
			params.add(motanucobro.getfModif37());
		}

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

		return mapWhere;
	}
}
