class ApiExtController {

    @RequestMapping(value = "/checkAll")
    public ServiceResult<String> checkAll(@RequestParam("appid") String appid, @CurrentUser LoginUser user, HttpServletRequest request) {
        String baseurl = DasEnv.getBaseUrl(request);
        String addmsg = "明细请查看 http://" + baseurl + "/das/#/api?appid=" + appid;
        try {
            if (null == appid) {
                return ServiceResult.fail("ApiExtController.checkByAppid appid " + addmsg);
            }
            Project project = projectDao.getProjectByAppId(appid);
            //项目校验
            ConfigCkeckResult<List<ConfigDataResponse>> cr = projectService.getCheckData(user, project);
            if (cr.getCode() == ConfigCkeckResult.ERROR) {
                return ServiceResult.fail("projectService.getCheckData appid " + addmsg);
            }
            List<ConfigDataResponse> configDataResponses = cr.getItem();
            ConfigCkeckResult<ConfigCheckItem> configCkeckResult = ConfigCheckBase.checkData(configDataResponses);
            if (configCkeckResult.getCode() == ConfigCkeckResult.ERROR) {
                return ServiceResult.fail("项目配置校验不通过，" + configCkeckResult.getMsg() + addmsg);
            }
            //逻辑库校验
            List<DatabaseSet> dbsets = databaseSetDao.getAllDatabaseSetByGroupId(project.getDal_group_id());
            if (CollectionUtils.isEmpty(dbsets)) {
                return ServiceResult.fail("逻辑库配置校验不通过，" + configCkeckResult.getMsg() + addmsg);
            }
            List<ConfigDataResponse> configCheckResponses = databaseSetService.getAllCheckData(user, project.getDal_group_id(), dbsets.get(0));
            configCkeckResult = ConfigCheckBase.checkData(configCheckResponses);
            //物理库校验
            if (configCkeckResult.getCode() != ConfigCkeckResult.ERROR) {
                List<DataBaseInfo> list = dataBaseDao.getAllDbByAppId(appid);
                for (DataBaseInfo dataBaseInfo : list) {
                    cr = databaseService.getCheckData(user, dataBaseInfo);
                    if (cr.getCode() == ConfigCkeckResult.SUCCESS) {
                        return ServiceResult.fail("物理库校验不通过，" + configCkeckResult.getMsg() + addmsg);
                    }
                    configCkeckResult = ConfigCheckBase.checkData(cr.getItem());
                    if (configCkeckResult.getCode() == ConfigCkeckResult.ERROR) {
                        return ServiceResult.fail("物理库校验不通过，" + configCkeckResult.getMsg() + addmsg);
                    }
                }
                return ServiceResult.success();
            }
        } catch (Exception e) {
            return ServiceResult.fail("ApiExtController.checkByAppid appid : " + appid + "   " + StringUtil.getMessage(e));
        }
        return ServiceResult.fail("物理库校验不通过, 明细请查看 http://" + baseurl + "/das/#/api?appid=" + appid);
    }

}