package com.xjrsoft.module.datalog.service.impl;

import java.util.List;

import javax.validation.Valid;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.google.api.client.util.Lists;
import com.pictc.utils.DataLogTools;
import com.xjrsoft.module.datalog.entity.DataChangeLog;
import com.xjrsoft.module.datalog.service.DatalogService;

@Service
public class DatalogServiceImpl implements DatalogService{

	@Transactional(rollbackFor = Exception.class)
	@Override
	public <T> T insert(T entity) {
		return DataLogTools.insert(entity);
	}
	
	@Transactional(rollbackFor = Exception.class)
	@Override
	public <T> List<T> insertBatch(List<T> entitys) {
		List<T> res = Lists.newArrayList();
		for (T entity : entitys) {
			res.add(DataLogTools.insert(entity));
		}
		return res;
	}
	
	@Transactional(rollbackFor = Exception.class)
	@Override
	public <T> boolean updateById(T entity) {
		DataLogTools.update(entity);
		return true;
	}

	@Transactional(rollbackFor = Exception.class)
	@Override
	public <T> T delete(T entity) {
		return DataLogTools.delete(entity);
	}

	@Transactional(rollbackFor = Exception.class)
	@Override
	public <T> T deleteById(Class<T> klazz, long id) {
		return DataLogTools.deleteById(klazz, id);
	}
	
	@Transactional(rollbackFor = Exception.class)
	@Override
	public <T> boolean deleteByIds(Class<T> class1, @Valid List<Long> ids) {
		return DataLogTools.deleteByIds(class1, ids);
	}
	
	@Transactional(readOnly = true)
	@Override
	public <T> List<DataChangeLog> findByEntityId(Class<T> klazz, long dataId) {
		return DataLogTools.findLogsByEntityId(klazz, dataId);
	}





}
