package ${packageName}.admin.api.${moduleName};

import java.util.List;

import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.iotechn.unimall.core.exception.ServiceException;
import com.iotechn.unimall.data.util.ExcelUtil;
import ${packageName}.data.mapper.${moduleName}.${ClassName}Mapper;
import ${packageName}.data.domain.${moduleName}.${ClassName};
import ${packageName}.admin.api.${moduleName}.${ClassName}Service;

/**
 * ${functionName}Service业务层处理
 * 
 * @author ${author}
 * @date ${datetime}
 */
@Service
public class ${ClassName}ServiceImpl implements ${ClassName}Service{
	@Autowired
	private ${ClassName}Mapper ${className}Mapper;
	
	@Override
	public Boolean add(${ClassName} ${className}) throws ServiceException {
		return ${className}Mapper.insert(${className})>0;
	}

	@Override
	public Page<${ClassName}> list(#foreach ($column in $columns)#if($column.isQuery==1)$column.javaType $column.javaField,#end#end Integer page, Integer limit)throws ServiceException {
		Wrapper<${ClassName}> wrapper = new EntityWrapper<${ClassName}>();
		#foreach ($column in $columns)
			#if($column.isQuery==1)
				if (!StringUtils.isEmpty($column.javaField)) {
					wrapper.eq("$column.columnName", $column.javaField);
				}
			#end
		#end 
		List<${ClassName}> list = ${className}Mapper.selectPage(new RowBounds((page - 1) * limit, limit), wrapper);
		Integer count = ${className}Mapper.selectCount(wrapper);
		return new Page<${ClassName}>(list, page, limit, count);
	}

	@Override
	public Boolean delete(${pkColumn.javaField}s)) throws ServiceException {
		String[] ids=${pkColumn.javaField}.split(",");
		Wrapper<${ClassName}> wrapper = new EntityWrapper<${ClassName}>();
		wrapper.in("${pkColumn.columnName}", ids);
		return ${className}Mapper.delete(wrapper)>0;
	}

	@Override
	public Boolean update(${ClassName} ${className}) throws ServiceException {
		return ${className}Mapper.updateById(${className})>0;
	}

	@Override
	public ${ClassName} get(${pkColumn.javaType} ${pkColumn.javaField}) throws ServiceException {
		return ${className}Mapper.selectById(${pkColumn.javaField});
	}
	
	@Override
	public String export(#foreach ($column in $columns)#if($column.isQuery==1)$column.javaType $column.javaField,#end#end Integer page, Integer limit)throws ServiceException {
		Wrapper<${ClassName}> wrapper = new EntityWrapper<${ClassName}>();
		#foreach ($column in $columns)
			#if($column.isQuery==1)
				if (!StringUtils.isEmpty($column.javaField)) {
					wrapper.eq("$column.columnName", $column.javaField);
				}
			#end
		#end 
		List<${ClassName}> list = ${className}Mapper.selectList(wrapper);
		ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class);
		return util.exportExcel(list, "操作日志");
	}
}
