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.Ab6343s00Dao;
import com.ejie.ab63.model.Ab6343s00;
import com.ejie.x38.dto.JerarquiaDto;
import com.ejie.x38.dto.TableRequestDto;
import com.ejie.x38.dto.TableResponseDto;
import com.ejie.x38.dto.TableRowDto;

/**
 * Ab6343s00ServiceImpl  
 *  
 */

@Service(value = "ab6343s00Service")
public class Ab6343s00ServiceImpl implements Ab6343s00Service {

	@Autowired
	private Ab6343s00Dao ab6343s00Dao;

	/**
	 * Inserts a single row in the Ab6343s00 table.
	 *
	 * @param ab6343s00 Ab6343s00
	 * @return Ab6343s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public Ab6343s00 add(Ab6343s00 ab6343s00) {
		return this.ab6343s00Dao.add(ab6343s00);
	}

	/**
	 * Updates a single row in the Ab6343s00 table.
	 *
	 * @param ab6343s00 Ab6343s00
	 * @return Ab6343s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public Ab6343s00 update(Ab6343s00 ab6343s00) {
		return this.ab6343s00Dao.update(ab6343s00);
	 }

	/**
	 * Finds a single row in the Ab6343s00 table.
	 *
	 * @param ab6343s00 Ab6343s00
	 * @return Ab6343s00
	 */
	public Ab6343s00 find(Ab6343s00 ab6343s00) {
		return (Ab6343s00) this.ab6343s00Dao.find(ab6343s00);
	}
	
	/**
	 * Deletes a single row in the Ab6343s00 table.
	 *
	 * @param ab6343s00 Ab6343s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public void remove(Ab6343s00 ab6343s00) {
		this.ab6343s00Dao.remove(ab6343s00);
	}

	/**
	 * Finds a list of rows in the Ab6343s00 table.
	 *
	 * @param ab6343s00 Ab6343s00
	 * @param tableRequestDto TableRequestDto
	 * @return List<Ab6343s00>
	 */
	public List<Ab6343s00> findAll(Ab6343s00 ab6343s00, TableRequestDto tableRequestDto){
		return (List<Ab6343s00>) this.ab6343s00Dao.findAll(ab6343s00, tableRequestDto);
	}
    
	/**
	 * Finds rows in the Ab6343s00 table using like.
	 *
	 * @param ab6343s00 Ab6343s00
	 * @param tableRequestDto TableRequestDto
     * @param startsWith Boolean	 
	 * @return List<Ab6343s00>
	 */
	public List<Ab6343s00> findAllLike(Ab6343s00 ab6343s00, TableRequestDto tableRequestDto, Boolean startsWith){
		return (List<Ab6343s00>) this.ab6343s00Dao.findAllLike(ab6343s00, tableRequestDto, startsWith);
	}

	/*
	 * OPERACIONES RUP_TABLE
	 */
	 
	/**
	 * Removes rows from the Ab6343s00 table.
	 *
	 * @param filterAb6343s00 Ab6343s00
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith Boolean
	 */	
	public void removeMultiple(Ab6343s00 filterAb6343s00, TableRequestDto tableRequestDto,  Boolean startsWith){
		this.ab6343s00Dao.removeMultiple(filterAb6343s00, tableRequestDto, startsWith);
	}
        
	/**
	 * Filter method in the Ab6343s00 table.
	 *
	 * @param filterAb6343s00 Ab6343s00
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith Boolean
	 * @return TableResponseDto<Ab6343s00>
	 */	
	public TableResponseDto< Ab6343s00> filter(Ab6343s00 filterAb6343s00, TableRequestDto tableRequestDto,  Boolean startsWith){
		List<Ab6343s00> listaAb6343s00 =  this.ab6343s00Dao.findAllLike(filterAb6343s00, tableRequestDto, false);
		Long recordNum =  this.ab6343s00Dao.findAllLikeCount(filterAb6343s00 != null ? filterAb6343s00: new Ab6343s00 (),false);
		
		TableResponseDto<Ab6343s00> usuarioDto = new TableResponseDto<Ab6343s00>(tableRequestDto, recordNum, listaAb6343s00);
		
		if (tableRequestDto.getMultiselection().getSelectedIds()!=null){
			List< TableRowDto< Ab6343s00>> reorderSelection = this.ab6343s00Dao.reorderSelection(filterAb6343s00, tableRequestDto, startsWith);
			usuarioDto.setReorderedSelection(reorderSelection);
			usuarioDto.addAdditionalParam("reorderedSelection", reorderSelection);
			usuarioDto.addAdditionalParam("selectedAll", tableRequestDto.getMultiselection().getSelectedAll());
		}
		if (tableRequestDto.getSeeker().getSelectedIds()!=null){
			tableRequestDto.setMultiselection(tableRequestDto.getSeeker());
			List< TableRowDto< Ab6343s00>> reorderSeeker = this.ab6343s00Dao.reorderSelection(filterAb6343s00, tableRequestDto, startsWith);
			usuarioDto.setReorderedSeeker(reorderSeeker);
			usuarioDto.addAdditionalParam("reorderedSeeker", reorderSeeker);
		}
		return usuarioDto;   
	}
    /**
	 * Searches rows in the Ab6343s00 table.
	 *
	 * @param filterAb6343s00 Ab6343s00
	 * @param searchAb6343s00 Ab6343s00
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith Boolean
	 * @return List<TableRowDto<Ab6343s00>>
	 */	
    public List< TableRowDto< Ab6343s00>> search(Ab6343s00 filterAb6343s00, Ab6343s00 searchAb6343s00, TableRequestDto tableRequestDto, Boolean startsWith){
		return this.ab6343s00Dao.search(filterAb6343s00, searchAb6343s00, tableRequestDto, startsWith);
	}
    
    /**
	 * Reorder the selection made in Ab6343s00 table.
	 *
	 * @param filterAb6343s00 Ab6343s00
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith Boolean
	 * @return Object
	 */	
    public Object reorderSelection(Ab6343s00 filterAb6343s00, TableRequestDto tableRequestDto, Boolean startsWith){
		return this.ab6343s00Dao.reorderSelection(filterAb6343s00, tableRequestDto, startsWith);
	}
    
    /*
	 * OPERACIONES RUP_TABLE JERARQUIA
	 */
	 
	/**
	 * Finder method in the hierarchical the Ab6343s00 table.
	 *
	 * @param filterAb6343s00 Ab6343s00
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith Boolean
	 * @return TableResponseDto<JerarquiaDto<Ab6343s00>>
	 */	
	public TableResponseDto<JerarquiaDto<Ab6343s00>> jerarquia(Ab6343s00 filterAb6343s00, TableRequestDto tableRequestDto, Boolean startsWith){
		List<JerarquiaDto<Ab6343s00>> listaAb6343s00 =  this.ab6343s00Dao.findAllLikeJerarquia(filterAb6343s00, tableRequestDto);
		Long recordNum = this.ab6343s00Dao.findAllLikeCountJerarquia(filterAb6343s00, tableRequestDto);
		return new TableResponseDto<JerarquiaDto<Ab6343s00>>(tableRequestDto, recordNum, listaAb6343s00);
	}
	
	/**
	 * Finder method for siblings rows in the hierarchical the Ab6343s00 table.
	 *
	 * @param filterAb6343s00 Ab6343s00
	 * @param tableRequestDto TableRequestDto
	 * @return TableResponseDto<JerarquiaDto<Ab6343s00>>
	 */	
	public TableResponseDto<JerarquiaDto<Ab6343s00>> jerarquiaChildren(Ab6343s00 filterAb6343s00, TableRequestDto tableRequestDto){
		TableResponseDto<JerarquiaDto<Ab6343s00>> tableResponseDto = new TableResponseDto<JerarquiaDto<Ab6343s00>>();
		tableResponseDto.addAdditionalParam(TableResponseDto.CHILDREN, this.ab6343s00Dao.findAllChild(filterAb6343s00, tableRequestDto));
		return tableResponseDto;
	}
	
	/**
    * Exporta Datos al clipBoard
    *
    */
    public List<Ab6343s00> getMultiple(Ab6343s00 filterAb6343s00, TableRequestDto tableRequestDto,  Boolean startsWith){
		return this.ab6343s00Dao.getMultiple(filterAb6343s00, tableRequestDto, startsWith);
	}
      
	
	
}

