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

/**
 * Ab6319s00ServiceImpl  
 * 
 *  
 */

@Service(value = "factorCompensatorioService")
public class FactorCompensatorioServiceImpl implements FactorCompensatorioService {

	@Autowired
	private FactorCompensatorioDao ab6319s00Dao;

	/**
	 * Inserts a single row in the Ab6319s00 table.
	 *
	 * @param ab6319s00
	 *            Ab6319s00
	 * @return Ab6319s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public FactorCompensatorio add(FactorCompensatorio ab6319s00) {
		return this.ab6319s00Dao.add(ab6319s00);
	}

	/**
	 * Updates a single row in the Ab6319s00 table.
	 *
	 * @param ab6319s00
	 *            Ab6319s00
	 * @return Ab6319s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public FactorCompensatorio update(FactorCompensatorio ab6319s00) {
		return this.ab6319s00Dao.update(ab6319s00);
	}

	/**
	 * Finds a single row in the Ab6319s00 table.
	 *
	 * @param ab6319s00
	 *            Ab6319s00
	 * @return Ab6319s00
	 */
	public FactorCompensatorio find(FactorCompensatorio ab6319s00) {
		return (FactorCompensatorio) this.ab6319s00Dao.find(ab6319s00);
	}

	/**
	 * Deletes a single row in the Ab6319s00 table.
	 *
	 * @param ab6319s00
	 *            Ab6319s00
	 */
	@Transactional(rollbackFor = Throwable.class)
	public void remove(FactorCompensatorio ab6319s00) {
		this.ab6319s00Dao.remove(ab6319s00);
	}

	/**
	 * Finds a list of rows in the Ab6319s00 table.
	 *
	 * @param ab6319s00
	 *            Ab6319s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @return List<Ab6319s00>
	 */
	public List<FactorCompensatorio> findAll(FactorCompensatorio ab6319s00, TableRequestDto tableRequestDto) {
		return (List<FactorCompensatorio>) this.ab6319s00Dao.findAll(ab6319s00, tableRequestDto);
	}

	/**
	 * Finds rows in the Ab6319s00 table using like.
	 *
	 * @param ab6319s00
	 *            Ab6319s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return List<Ab6319s00>
	 */
	public List<FactorCompensatorio> findAllLike(FactorCompensatorio ab6319s00, TableRequestDto tableRequestDto,
			Boolean startsWith) {
		return (List<FactorCompensatorio>) this.ab6319s00Dao.findAllLike(ab6319s00, tableRequestDto, startsWith);
	}

	/*
	 * OPERACIONES RUP_TABLE
	 */

	/**
	 * Removes rows from the Ab6319s00 table.
	 *
	 * @param filterAb6319s00
	 *            Ab6319s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 */
	public void removeMultiple(FactorCompensatorio filterAb6319s00, TableRequestDto tableRequestDto,
			Boolean startsWith) {
		this.ab6319s00Dao.removeMultiple(filterAb6319s00, tableRequestDto, startsWith);
	}

	/**
	 * Filter method in the Ab6319s00 table.
	 *
	 * @param filterAb6319s00
	 *            Ab6319s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return JQGridResponseDto<Ab6319s00>
	 */
	public TableResponseDto<FactorCompensatorio> filter(FactorCompensatorio filterAb6319s00,
			TableRequestDto tableRequestDto, Boolean startsWith) {

		List<FactorCompensatorio> listaAb6319s00 = this.ab6319s00Dao.findAllLike(filterAb6319s00, tableRequestDto,
				false);

		/*
		 * for (FactorCompensatorio factorCompensatorio : listaAb6319s00) {
		 * 
		 * /*if (null != factorCompensatorio.getTipoFactorCompensatorio() &&
		 * !"".equals(factorCompensatorio.getTipoFactorCompensatorio().
		 * getIdTipoFactorCompensatorio())) {
		 * 
		 * if (LocaleContextHolder.getLocale().getLanguage().equalsIgnoreCase(
		 * Constantes.CASTELLANO)) {
		 * factorCompensatorio.setDescTipoFactorCompensatorio(
		 * factorCompensatorio.getTipoFactorCompensatorio().getDescTipoEs ()); }
		 * else { factorCompensatorio.setDescTipoFactorCompensatorio(
		 * factorCompensatorio.getTipoFactorCompensatorio().getDescTipoEu ()); }
		 * }
		 * 
		 * }
		 */
		Long recordNum = this.ab6319s00Dao
				.findAllLikeCount(filterAb6319s00 != null ? filterAb6319s00 : new FactorCompensatorio(), false);
		if (tableRequestDto.getMultiselection().getSelectedIds() != null) {
			List<TableRowDto<FactorCompensatorio>> reorderSelection = this.ab6319s00Dao
					.reorderSelection(filterAb6319s00, tableRequestDto, startsWith);
			return new TableResponseDto<FactorCompensatorio>(tableRequestDto, recordNum, listaAb6319s00,
					reorderSelection);
		}
		return new TableResponseDto<FactorCompensatorio>(tableRequestDto, recordNum, listaAb6319s00);
	}

	/**
	 * Searches rows in the Ab6319s00 table.
	 *
	 * @param filterAb6319s00
	 *            Ab6319s00
	 * @param searchAb6319s00
	 *            Ab6319s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return List<TableRowDto<Ab6319s00>>
	 */
	public List<TableRowDto<FactorCompensatorio>> search(FactorCompensatorio filterAb6319s00,
			FactorCompensatorio searchAb6319s00, TableRequestDto tableRequestDto, Boolean startsWith) {
		return this.ab6319s00Dao.search(filterAb6319s00, searchAb6319s00, tableRequestDto, startsWith);
	}

	/**
	 * Reorder the selection made in Ab6319s00 table.
	 *
	 * @param filterAb6319s00
	 *            Ab6319s00
	 * @param jqGridRequestDto
	 *            JQGridRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return Object
	 */
	public Object reorderSelection(FactorCompensatorio filterAb6319s00, TableRequestDto tableRequestDto,
			Boolean startsWith) {
		return this.ab6319s00Dao.reorderSelection(filterAb6319s00, tableRequestDto, startsWith);
	}

	@Override
	@Transactional(rollbackFor = Throwable.class)
	public FactorCompensatorio save(FactorCompensatorio ab6319s00) {
		if (null != ab6319s00.getIdFactorComp() && ab6319s00.getIdFactorComp() > 0) {
			return this.update(ab6319s00);
		} else {
			return this.add(ab6319s00);
		}
	}

}
