package com.xunhong.erp.turbo.datasource.handler;

import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.exceptions.TooManyResultsException;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author shenyifei
 */
@Slf4j
@RestControllerAdvice
@Order(3)
public class MybatisExceptionHandler {
	@ResponseBody
	@ExceptionHandler(TooManyResultsException.class)
	public Response handleTooManyResultsException(TooManyResultsException e) {
		log.error("********TooManyResultsException********: mybatis多查：{}", e.toString(), e);
		return SingleResponse.buildFailure(HttpStatus.BAD_REQUEST.value() + "", "mybatis多查");
	}

}
