package com.ejie.ab61.service.inicioOficioExp;

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.ab61.dao.inicioOficioExp.RelExpOriDesDao;
import com.ejie.ab61.model.inicioOficioExp.RelExpOriDes;
import com.ejie.x38.dto.JQGridRequestDto;
import com.ejie.x38.dto.JQGridResponseDto;
import com.ejie.x38.dto.JerarquiaDto;
import com.ejie.x38.dto.TableRowDto;

/**
 * RelExpOriDesServiceImpl  
 * 
 *  
 */

@Service(value = "relExpOriDesService")
public class RelExpOriDesServiceImpl implements RelExpOriDesService {

	@Autowired
	private RelExpOriDesDao relExpOriDesDao;

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

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

	/**
	 * Finds a single row in the RelExpOriDes table.
	 *
	 * @param relExpOriDes
	 *            RelExpOriDes
	 * @return RelExpOriDes
	 */
	public RelExpOriDes find(RelExpOriDes relExpOriDes) {
		return (RelExpOriDes) this.relExpOriDesDao.find(relExpOriDes);
	}

	/**
	 * Deletes a single row in the RelExpOriDes table.
	 *
	 * @param relExpOriDes
	 *            RelExpOriDes
	 */
	@Transactional(rollbackFor = Throwable.class)
	public void remove(RelExpOriDes relExpOriDes) {
		this.relExpOriDesDao.remove(relExpOriDes);
	}

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

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

	/*
	 * OPERACIONES RUP_TABLE
	 */

	/**
	 * Removes rows from the RelExpOriDes table.
	 *
	 * @param filterRelExpOriDes
	 *            RelExpOriDes
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 */
	public void removeMultiple(RelExpOriDes filterRelExpOriDes, JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		this.relExpOriDesDao.removeMultiple(filterRelExpOriDes, jqGridRequestDto, startsWith);
	}

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

	/**
	 * Searches rows in the RelExpOriDes table.
	 *
	 * @param filterRelExpOriDes
	 *            RelExpOriDes
	 * @param searchRelExpOriDes
	 *            RelExpOriDes
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return List<TableRowDto<RelExpOriDes>>
	 */
	public List<TableRowDto<RelExpOriDes>> search(RelExpOriDes filterRelExpOriDes, RelExpOriDes searchRelExpOriDes,
			JQGridRequestDto jqGridRequestDto, Boolean startsWith) {
		return this.relExpOriDesDao.search(filterRelExpOriDes, searchRelExpOriDes, jqGridRequestDto, startsWith);
	}

	/**
	 * Reorder the selection made in RelExpOriDes table.
	 *
	 * @param filterRelExpOriDes
	 *            RelExpOriDes
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return Object
	 */
	public Object reorderSelection(RelExpOriDes filterRelExpOriDes, JQGridRequestDto jqGridRequestDto,
			Boolean startsWith) {
		return this.relExpOriDesDao.reorderSelection(filterRelExpOriDes, jqGridRequestDto, startsWith);
	}

	/*
	 * OPERACIONES RUP_TABLE JERARQUIA
	 */

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

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

}
