/**
 * Copyright 2018-2020 stylefeng & fengshuonan (sn93@qq.com)
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package com.inkasso.config;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.druid.support.http.StatViewServlet;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * 数据库连接池配置
 *
 * @author zc
 * @Date 2021-09-22
 */
@Configuration
@Slf4j
public class DruidViewConfig {


  /**
   * druid监控，配置StatViewServlet
   */
  @Bean
  public ServletRegistrationBean<StatViewServlet> druidServletRegistration() {

    // 随机生成druid账号和密码
    String account = "admin";
    String password = "admin";

    // 设置servelet的参数
    Map<String, String> statViewServletParams = new HashMap();
    statViewServletParams.put("resetEnable", "true");
    statViewServletParams.put("loginUsername", account);
    statViewServletParams.put("loginPassword", password);

    ServletRegistrationBean<StatViewServlet> registration = new ServletRegistrationBean<>(
        new StatViewServlet());
    registration.addUrlMappings("/druid/*");
    registration.setInitParameters(statViewServletParams);
    return registration;
  }

}
