package com.nbclass.system.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.nbclass.exception.ParameterException;
import com.nbclass.system.mapper.SysLogMapper;
import com.nbclass.system.model.SysLog;
import com.nbclass.system.model.enums.SysLogType;
import com.nbclass.system.service.SysLogService;

/**
 *
 * @author Leon
 * @datetime 2020年6月3日 下午5:18:54
 */
@Service
public class SysLogServiceImpl implements SysLogService {

	@Resource
	private SysLogMapper mapper;

	@Override
	public void add(SysLog entity) {
		/*if(entity.getType() == null || entity.getType() < 1) {
			throw new ParameterException("type不能为空");
		}*/
		if(StringUtils.isBlank(entity.getDescription())) {
			throw new ParameterException("描述不能为空");
		}
		mapper.insertSelective(entity);
	}

	@Override
	public void delete(List<Long> ids) {
		if(ids == null || ids.isEmpty()){
			throw new ParameterException("id不能为空");
		}
		mapper.deleteByIds(ids);
	}

	@Override
	public List<SysLog> getList(SysLog entity) {
		List<SysLog> list = mapper.getList(entity);
		if(list!=null && !list.isEmpty()) {
			for (SysLog sysLog : list) {
				sysLog.setTypeName(SysLogType.getNameByCode(sysLog.getType()));
			}
		}
		return list;
	}

}
