package com.brilliance.isc.common.health;

import com.brilliance.isc.mda.dao.BchMapper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 用于Consul的健康检查类, 不可删除; 容器云平台的探针也配置这个url
 *
 
 */
@RefreshScope
@RestController
public class DbHealthController {

    @Value("${health.flag:true}")
    private String flag;
    @Resource
    private BchMapper bchMapper;

    @GetMapping("/isc/db/health")
    public String healthInfo() {
        if ("true".equalsIgnoreCase(flag)) {
            try {
                bchMapper.selectByBranch("3500");
            } catch (Exception exception) {
                return "DOWN";
            }
            return "APP and DB UP";
        } else {
            return "DOWN";
        }
    }
}
