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

/**
 * Ab6300s00ServiceImpl  
 * 
 *  
 */

@Service(value = "recursoService")
public class RecursoServiceImpl implements RecursoService {

	@Autowired
	private RecursoDao ab6300s00Dao;

	/**
	 * Inserts a single row in the Ab6300s00 table.
	 *
	 * @param ab6300s00
	 *            Ab6300s00
	 * @return Ab6300s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public Recurso add(Recurso ab6300s00) {
		return this.ab6300s00Dao.add(ab6300s00);
	}

	/**
	 * Updates a single row in the Ab6300s00 table.
	 *
	 * @param ab6300s00
	 *            Ab6300s00
	 * @return Ab6300s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public Recurso update(Recurso ab6300s00) {
		return this.ab6300s00Dao.update(ab6300s00);
	}

	/**
	 * Finds a single row in the Ab6300s00 table.
	 *
	 * @param ab6300s00
	 *            Ab6300s00
	 * @return Ab6300s00
	 */
	public Recurso find(Recurso ab6300s00) {
		return (Recurso) this.ab6300s00Dao.find(ab6300s00);
	}

	/**
	 * Deletes a single row in the Ab6300s00 table.
	 *
	 * @param ab6300s00
	 *            Ab6300s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public void remove(Recurso ab6300s00) {
		this.ab6300s00Dao.remove(ab6300s00);
	}

	/**
	 * Finds a list of rows in the Ab6300s00 table.
	 *
	 * @param ab6300s00
	 *            Ab6300s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @return List<Ab6300s00>
	 */
	public List<Recurso> findAll(Recurso ab6300s00, JQGridRequestDto jqGridRequestDto) {
		return (List<Recurso>) this.ab6300s00Dao.findAll(ab6300s00, jqGridRequestDto);
	}

	/**
	 * Finds rows in the Ab6300s00 table using like.
	 *
	 * @param ab6300s00
	 *            Ab6300s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return List<Ab6300s00>
	 */
	public List<Recurso> findAllLike(Recurso ab6300s00, JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		return (List<Recurso>) this.ab6300s00Dao.findAllLike(ab6300s00, jqGridRequestDto, startsWith);
	}

	/*
	 * OPERACIONES RUP_TABLE
	 */

	/**
	 * Removes rows from the Ab6300s00 table.
	 *
	 * @param filterAb6300s00
	 *            Ab6300s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 */
	public void removeMultiple(Recurso filterAb6300s00, JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		this.ab6300s00Dao.removeMultiple(filterAb6300s00, jqGridRequestDto, startsWith);
	}

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

	/**
	 * Searches rows in the Ab6300s00 table.
	 *
	 * @param filterAb6300s00
	 *            Ab6300s00
	 * @param searchAb6300s00
	 *            Ab6300s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return List<TableRowDto<Ab6300s00>>
	 */
	public List<TableRowDto<Recurso>> search(Recurso filterAb6300s00, Recurso searchAb6300s00,
			JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		return this.ab6300s00Dao.search(filterAb6300s00, searchAb6300s00, jqGridRequestDto, startsWith);
	}

	/**
	 * Reorder the selection made in Ab6300s00 table.
	 *
	 * @param filterAb6300s00
	 *            Ab6300s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return Object
	 */
	public Object reorderSelection(Recurso filterAb6300s00, JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		return this.ab6300s00Dao.reorderSelection(filterAb6300s00, jqGridRequestDto, startsWith);
	}

	/*
	 * OPERACIONES RUP_TABLE JERARQUIA
	 */

	/**
	 * Finder method in the hierarchical the Ab6300s00 table.
	 *
	 * @param filterAb6300s00
	 *            Ab6300s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return JQGridResponseDto<JerarquiaDto<Ab6300s00>>
	 */
	public JQGridResponseDto<JerarquiaDto<Recurso>> jerarquia(Recurso filterAb6300s00,
			JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		List<JerarquiaDto<Recurso>> listaAb6300s00 = this.ab6300s00Dao.findAllLikeJerarquia(filterAb6300s00,
				jqGridRequestDto);
		Long recordNum = this.ab6300s00Dao.findAllLikeCountJerarquia(filterAb6300s00, jqGridRequestDto);
		return new JQGridResponseDto<JerarquiaDto<Recurso>>(jqGridRequestDto, recordNum, listaAb6300s00);
	}

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

}
