package com.ejie.ab63.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ejie.ab63.dao.DireccionEstablecimientoDao;
import com.ejie.ab63.model.DireccionEstablecimiento;
import com.ejie.x38.dto.JQGridRequestDto;
import com.ejie.x38.dto.JQGridResponseDto;
import com.ejie.x38.dto.JerarquiaDto;
import com.ejie.x38.dto.TableRowDto;

/**
 * Ab6340s00ServiceImpl  
 * 
 *  
 */

@Service(value = "direccionEstablecimientoService")
public class DireccionEstablecimientoServiceImpl implements DireccionEstablecimientoService {

	@Autowired
	private DireccionEstablecimientoDao ab6340s00Dao;

	/**
	 * Inserts a single row in the Ab6340s00 table.
	 *
	 * @param ab6340s00
	 *            Ab6340s00
	 * @return Ab6340s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public DireccionEstablecimiento add(DireccionEstablecimiento ab6340s00) {
		return this.ab6340s00Dao.add(ab6340s00);
	}

	/**
	 * Updates a single row in the Ab6340s00 table.
	 *
	 * @param ab6340s00
	 *            Ab6340s00
	 * @return Ab6340s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public DireccionEstablecimiento update(DireccionEstablecimiento ab6340s00) {
		return this.ab6340s00Dao.update(ab6340s00);
	}

	/**
	 * Finds a single row in the Ab6340s00 table.
	 *
	 * @param ab6340s00
	 *            Ab6340s00
	 * @return Ab6340s00
	 */
	public DireccionEstablecimiento find(DireccionEstablecimiento ab6340s00) {
		return (DireccionEstablecimiento) this.ab6340s00Dao.find(ab6340s00);
	}

	/**
	 * Deletes a single row in the Ab6340s00 table.
	 *
	 * @param ab6340s00
	 *            Ab6340s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public void remove(DireccionEstablecimiento ab6340s00) {
		this.ab6340s00Dao.remove(ab6340s00);
	}

	/**
	 * Finds a list of rows in the Ab6340s00 table.
	 *
	 * @param ab6340s00
	 *            Ab6340s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @return List<Ab6340s00>
	 */
	public List<DireccionEstablecimiento> findAll(DireccionEstablecimiento ab6340s00,
			JQGridRequestDto jqGridRequestDto) {
		return (List<DireccionEstablecimiento>) this.ab6340s00Dao.findAll(ab6340s00, jqGridRequestDto);
	}

	/**
	 * Finds rows in the Ab6340s00 table using like.
	 *
	 * @param ab6340s00
	 *            Ab6340s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return List<Ab6340s00>
	 */
	public List<DireccionEstablecimiento> findAllLike(DireccionEstablecimiento ab6340s00,
			JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		return (List<DireccionEstablecimiento>) this.ab6340s00Dao.findAllLike(ab6340s00, jqGridRequestDto, startsWith);
	}

	/*
	 * OPERACIONES RUP_TABLE
	 */

	/**
	 * Removes rows from the Ab6340s00 table.
	 *
	 * @param filterAb6340s00
	 *            Ab6340s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 */
	public void removeMultiple(DireccionEstablecimiento filterAb6340s00, JQGridRequestDto jqGridRequestDto,
			Boolean startsWith) {
		this.ab6340s00Dao.removeMultiple(filterAb6340s00, jqGridRequestDto, startsWith);
	}

	/**
	 * Filter method in the Ab6340s00 table.
	 *
	 * @param filterAb6340s00
	 *            Ab6340s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return JQGridResponseDto<Ab6340s00>
	 */
	public JQGridResponseDto<DireccionEstablecimiento> filter(DireccionEstablecimiento filterAb6340s00,
			JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		List<DireccionEstablecimiento> listaAb6340s00 = this.ab6340s00Dao.findAllLike(filterAb6340s00, jqGridRequestDto,
				false);
		Long recordNum = this.ab6340s00Dao
				.findAllLikeCount(filterAb6340s00 != null ? filterAb6340s00 : new DireccionEstablecimiento(), false);
		if (jqGridRequestDto.getMultiselection().getSelectedIds() != null) {
			List<TableRowDto<DireccionEstablecimiento>> reorderSelection = this.ab6340s00Dao
					.reorderSelection(filterAb6340s00, jqGridRequestDto, startsWith);
			return new JQGridResponseDto<DireccionEstablecimiento>(jqGridRequestDto, recordNum, listaAb6340s00,
					reorderSelection);
		}
		return new JQGridResponseDto<DireccionEstablecimiento>(jqGridRequestDto, recordNum, listaAb6340s00);
	}

	/**
	 * Searches rows in the Ab6340s00 table.
	 *
	 * @param filterAb6340s00
	 *            Ab6340s00
	 * @param searchAb6340s00
	 *            Ab6340s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return List<TableRowDto<Ab6340s00>>
	 */
	public List<TableRowDto<DireccionEstablecimiento>> search(DireccionEstablecimiento filterAb6340s00,
			DireccionEstablecimiento searchAb6340s00, JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		return this.ab6340s00Dao.search(filterAb6340s00, searchAb6340s00, jqGridRequestDto, startsWith);
	}

	/**
	 * Reorder the selection made in Ab6340s00 table.
	 *
	 * @param filterAb6340s00
	 *            Ab6340s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return Object
	 */
	public Object reorderSelection(DireccionEstablecimiento filterAb6340s00, JQGridRequestDto jqGridRequestDto,
			Boolean startsWith) {
		return this.ab6340s00Dao.reorderSelection(filterAb6340s00, jqGridRequestDto, startsWith);
	}

	/*
	 * OPERACIONES RUP_TABLE JERARQUIA
	 */

	/**
	 * Finder method in the hierarchical the Ab6340s00 table.
	 *
	 * @param filterAb6340s00
	 *            Ab6340s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return JQGridResponseDto<JerarquiaDto<Ab6340s00>>
	 */
	public JQGridResponseDto<JerarquiaDto<DireccionEstablecimiento>> jerarquia(DireccionEstablecimiento filterAb6340s00,
			JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		List<JerarquiaDto<DireccionEstablecimiento>> listaAb6340s00 = this.ab6340s00Dao
				.findAllLikeJerarquia(filterAb6340s00, jqGridRequestDto);
		Long recordNum = this.ab6340s00Dao.findAllLikeCountJerarquia(filterAb6340s00, jqGridRequestDto);
		return new JQGridResponseDto<JerarquiaDto<DireccionEstablecimiento>>(jqGridRequestDto, recordNum,
				listaAb6340s00);
	}

	/**
	 * Finder method for siblings rows in the hierarchical the Ab6340s00 table.
	 *
	 * @param filterAb6340s00
	 *            Ab6340s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @return JQGridResponseDto<JerarquiaDto<Ab6340s00>>
	 */
	public JQGridResponseDto<JerarquiaDto<DireccionEstablecimiento>> jerarquiaChildren(
			DireccionEstablecimiento filterAb6340s00, JQGridRequestDto jqGridRequestDto) {
		JQGridResponseDto<JerarquiaDto<DireccionEstablecimiento>> jqGridResponseDto = new JQGridResponseDto<JerarquiaDto<DireccionEstablecimiento>>();
		jqGridResponseDto.addAdditionalParam(JQGridResponseDto.CHILDREN,
				this.ab6340s00Dao.findAllChild(filterAb6340s00, jqGridRequestDto));
		return jqGridResponseDto;
	}

}
