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.GrupoDao;
import com.ejie.ab63.model.Grupo;
import com.ejie.x38.dto.JQGridRequestDto;
import com.ejie.x38.dto.JQGridResponseDto;
import com.ejie.x38.dto.JerarquiaDto;
import com.ejie.x38.dto.TableRowDto;

/**
 * Ab6312s00ServiceImpl  
 * 
 *  
 */

@Service(value = "grupoService")
public class GrupoServiceImpl implements GrupoService {

	@Autowired
	private GrupoDao ab6312s00Dao;

	/**
	 * Inserts a single row in the Ab6312s00 table.
	 *
	 * @param ab6312s00
	 *            Ab6312s00
	 * @return Ab6312s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public Grupo add(Grupo ab6312s00) {
		return this.ab6312s00Dao.add(ab6312s00);
	}

	/**
	 * Updates a single row in the Ab6312s00 table.
	 *
	 * @param ab6312s00
	 *            Ab6312s00
	 * @return Ab6312s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public Grupo update(Grupo ab6312s00) {
		return this.ab6312s00Dao.update(ab6312s00);
	}

	/**
	 * Finds a single row in the Ab6312s00 table.
	 *
	 * @param ab6312s00
	 *            Ab6312s00
	 * @return Ab6312s00
	 */
	public Grupo find(Grupo ab6312s00) {
		return (Grupo) this.ab6312s00Dao.find(ab6312s00);
	}

	/**
	 * Deletes a single row in the Ab6312s00 table.
	 *
	 * @param ab6312s00
	 *            Ab6312s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public void remove(Grupo ab6312s00) {
		this.ab6312s00Dao.remove(ab6312s00);
	}

	/**
	 * Finds a list of rows in the Ab6312s00 table.
	 *
	 * @param ab6312s00
	 *            Ab6312s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @return List<Ab6312s00>
	 */
	public List<Grupo> findAll(Grupo ab6312s00, JQGridRequestDto jqGridRequestDto) {
		return (List<Grupo>) this.ab6312s00Dao.findAll(ab6312s00, jqGridRequestDto);
	}

	/**
	 * Finds rows in the Ab6312s00 table using like.
	 *
	 * @param ab6312s00
	 *            Ab6312s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return List<Ab6312s00>
	 */
	public List<Grupo> findAllLike(Grupo ab6312s00, JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		return (List<Grupo>) this.ab6312s00Dao.findAllLike(ab6312s00, jqGridRequestDto, startsWith);
	}

	/*
	 * OPERACIONES RUP_TABLE
	 */

	/**
	 * Removes rows from the Ab6312s00 table.
	 *
	 * @param filterAb6312s00
	 *            Ab6312s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 */
	public void removeMultiple(Grupo filterAb6312s00, JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		this.ab6312s00Dao.removeMultiple(filterAb6312s00, jqGridRequestDto, startsWith);
	}

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

	/**
	 * Searches rows in the Ab6312s00 table.
	 *
	 * @param filterAb6312s00
	 *            Ab6312s00
	 * @param searchAb6312s00
	 *            Ab6312s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return List<TableRowDto<Ab6312s00>>
	 */
	public List<TableRowDto<Grupo>> search(Grupo filterAb6312s00, Grupo searchAb6312s00,
			JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		return this.ab6312s00Dao.search(filterAb6312s00, searchAb6312s00, jqGridRequestDto, startsWith);
	}

	/**
	 * Reorder the selection made in Ab6312s00 table.
	 *
	 * @param filterAb6312s00
	 *            Ab6312s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return Object
	 */
	public Object reorderSelection(Grupo filterAb6312s00, JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		return this.ab6312s00Dao.reorderSelection(filterAb6312s00, jqGridRequestDto, startsWith);
	}

	/*
	 * OPERACIONES RUP_TABLE JERARQUIA
	 */

	/**
	 * Finder method in the hierarchical the Ab6312s00 table.
	 *
	 * @param filterAb6312s00
	 *            Ab6312s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return JQGridResponseDto<JerarquiaDto<Ab6312s00>>
	 */
	public JQGridResponseDto<JerarquiaDto<Grupo>> jerarquia(Grupo filterAb6312s00, JQGridRequestDto jqGridRequestDto,
			Boolean startsWith) {
		List<JerarquiaDto<Grupo>> listaAb6312s00 = this.ab6312s00Dao.findAllLikeJerarquia(filterAb6312s00,
				jqGridRequestDto);
		Long recordNum = this.ab6312s00Dao.findAllLikeCountJerarquia(filterAb6312s00, jqGridRequestDto);
		return new JQGridResponseDto<JerarquiaDto<Grupo>>(jqGridRequestDto, recordNum, listaAb6312s00);
	}

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

}
