@Test public void addDalGroupDBTest() throws SQLException { LoginUser user = LoginUser.builder().id(1L).build(); DataBaseInfo groupDb = DataBaseInfo.builder().group_name("name").build(); Assert.assertTrue(databaseService.addDataBaseInfo(user, groupDb).getCode() == ServiceResult.SUCCESS); }
public ServiceResult<String> addDataBaseInfo(LoginUser user, DataBaseInfo dataBaseInfo) throws SQLException { if (dataBaseInfo.isAddToGroup()) { if (null == dataBaseInfo.getDal_group_id()) { List<UserGroup> list = userGroupDao.getUserGroupByUserId(user.getId()); if (CollectionUtils.isNotEmpty(list)) { dataBaseInfo.setDal_group_id(list.get(0).getGroup_id()); } } } String dbname = dataBaseInfo.getDbname().trim(); int maxlegnth = consts.dataBaseNameMaxLength; if (dbname.length() > maxlegnth) { return ServiceResult.fail(dbname + "物理库名称过长，不能大于" + maxlegnth + "个字符"); } dataBaseInfo.setDb_password(DasEnv.encdecConfiguration.encrypt(dataBaseInfo.getDb_password())); Long dbId = dataBaseDao.insertDataBaseInfo(dataBaseInfo); if (dbId <= 0) { return ServiceResult.fail(); } dataBaseInfo.setId(dbId); return genDefaultDbsetAndEntry(dataBaseInfo); }
DatabaseService { public ServiceResult<String> addDataBaseInfo(LoginUser user, DataBaseInfo dataBaseInfo) throws SQLException { if (dataBaseInfo.isAddToGroup()) { if (null == dataBaseInfo.getDal_group_id()) { List<UserGroup> list = userGroupDao.getUserGroupByUserId(user.getId()); if (CollectionUtils.isNotEmpty(list)) { dataBaseInfo.setDal_group_id(list.get(0).getGroup_id()); } } } String dbname = dataBaseInfo.getDbname().trim(); int maxlegnth = consts.dataBaseNameMaxLength; if (dbname.length() > maxlegnth) { return ServiceResult.fail(dbname + "物理库名称过长，不能大于" + maxlegnth + "个字符"); } dataBaseInfo.setDb_password(DasEnv.encdecConfiguration.encrypt(dataBaseInfo.getDb_password())); Long dbId = dataBaseDao.insertDataBaseInfo(dataBaseInfo); if (dbId <= 0) { return ServiceResult.fail(); } dataBaseInfo.setId(dbId); return genDefaultDbsetAndEntry(dataBaseInfo); } }
DatabaseService { public ServiceResult<String> addDataBaseInfo(LoginUser user, DataBaseInfo dataBaseInfo) throws SQLException { if (dataBaseInfo.isAddToGroup()) { if (null == dataBaseInfo.getDal_group_id()) { List<UserGroup> list = userGroupDao.getUserGroupByUserId(user.getId()); if (CollectionUtils.isNotEmpty(list)) { dataBaseInfo.setDal_group_id(list.get(0).getGroup_id()); } } } String dbname = dataBaseInfo.getDbname().trim(); int maxlegnth = consts.dataBaseNameMaxLength; if (dbname.length() > maxlegnth) { return ServiceResult.fail(dbname + "物理库名称过长，不能大于" + maxlegnth + "个字符"); } dataBaseInfo.setDb_password(DasEnv.encdecConfiguration.encrypt(dataBaseInfo.getDb_password())); Long dbId = dataBaseDao.insertDataBaseInfo(dataBaseInfo); if (dbId <= 0) { return ServiceResult.fail(); } dataBaseInfo.setId(dbId); return genDefaultDbsetAndEntry(dataBaseInfo); }  }
DatabaseService { public ServiceResult<String> addDataBaseInfo(LoginUser user, DataBaseInfo dataBaseInfo) throws SQLException { if (dataBaseInfo.isAddToGroup()) { if (null == dataBaseInfo.getDal_group_id()) { List<UserGroup> list = userGroupDao.getUserGroupByUserId(user.getId()); if (CollectionUtils.isNotEmpty(list)) { dataBaseInfo.setDal_group_id(list.get(0).getGroup_id()); } } } String dbname = dataBaseInfo.getDbname().trim(); int maxlegnth = consts.dataBaseNameMaxLength; if (dbname.length() > maxlegnth) { return ServiceResult.fail(dbname + "物理库名称过长，不能大于" + maxlegnth + "个字符"); } dataBaseInfo.setDb_password(DasEnv.encdecConfiguration.encrypt(dataBaseInfo.getDb_password())); Long dbId = dataBaseDao.insertDataBaseInfo(dataBaseInfo); if (dbId <= 0) { return ServiceResult.fail(); } dataBaseInfo.setId(dbId); return genDefaultDbsetAndEntry(dataBaseInfo); }  ValidatorChain validatePermision(LoginUser user, Errors errors); ServiceResult isExist(List<String> db_names); ServiceResult<String> addDataBaseInfo(LoginUser user, DataBaseInfo dataBaseInfo); ServiceResult<String> genDefaultDbsetAndEntry(DataBaseInfo dataBaseInfo); ServiceResult<String> genDefaultDbsetAndEntry(Long groupId, Long dbId, String dbname, Integer dbtype); boolean isNotExistByName(DataBaseInfo dataBaseInfo); ServiceResult<String> checkupdateDBInfo(DataBaseInfo dataBaseInfo); boolean updateDBInfo(DataBaseInfo dataBaseInfo); ListResult<DataBaseView> findDbPageList(Paging<DataBaseInfo> paging); ListResult<DataBaseView> findDbPageListByUserId(Paging<DataBaseInfo> paging, Long userId); ServiceResult encryptAndOptUser(LoginUser user, List<DataBaseInfo> dBList); ServiceResult<String> addDataBaseList(List<DataBaseInfo> dBList); ServiceResult<List<String>> getDBCatalogs(Long dbsetId); ServiceResult<List<String>> getDBCatalogsByDbId(Long dbid); ServiceResult connectionTest(ConnectionRequest connectionRequest); ServiceResult deleteCheck(Long dbId); ServiceResult<String> addDataCenter(LoginUser user, List<DataBaseInfo> list); ServiceResult<String> updateDataCenter(LoginUser user, DataBaseInfo dataBaseInfo); ServiceResult<String> deleteDataCenter(LoginUser user, DataBaseInfo dataBaseInfo); ServiceResult<String> syncDataCenter(LoginUser user, DataBaseInfo dataBaseInfo); ConfigCkeckResult<List<ConfigDataResponse>> getCheckData(LoginUser user, DataBaseInfo dataBaseInfo); ServiceResult getDataBaseButton(LoginUser user); }
DatabaseService { public ServiceResult<String> addDataBaseInfo(LoginUser user, DataBaseInfo dataBaseInfo) throws SQLException { if (dataBaseInfo.isAddToGroup()) { if (null == dataBaseInfo.getDal_group_id()) { List<UserGroup> list = userGroupDao.getUserGroupByUserId(user.getId()); if (CollectionUtils.isNotEmpty(list)) { dataBaseInfo.setDal_group_id(list.get(0).getGroup_id()); } } } String dbname = dataBaseInfo.getDbname().trim(); int maxlegnth = consts.dataBaseNameMaxLength; if (dbname.length() > maxlegnth) { return ServiceResult.fail(dbname + "物理库名称过长，不能大于" + maxlegnth + "个字符"); } dataBaseInfo.setDb_password(DasEnv.encdecConfiguration.encrypt(dataBaseInfo.getDb_password())); Long dbId = dataBaseDao.insertDataBaseInfo(dataBaseInfo); if (dbId <= 0) { return ServiceResult.fail(); } dataBaseInfo.setId(dbId); return genDefaultDbsetAndEntry(dataBaseInfo); }  ValidatorChain validatePermision(LoginUser user, Errors errors); ServiceResult isExist(List<String> db_names); ServiceResult<String> addDataBaseInfo(LoginUser user, DataBaseInfo dataBaseInfo); ServiceResult<String> genDefaultDbsetAndEntry(DataBaseInfo dataBaseInfo); ServiceResult<String> genDefaultDbsetAndEntry(Long groupId, Long dbId, String dbname, Integer dbtype); boolean isNotExistByName(DataBaseInfo dataBaseInfo); ServiceResult<String> checkupdateDBInfo(DataBaseInfo dataBaseInfo); boolean updateDBInfo(DataBaseInfo dataBaseInfo); ListResult<DataBaseView> findDbPageList(Paging<DataBaseInfo> paging); ListResult<DataBaseView> findDbPageListByUserId(Paging<DataBaseInfo> paging, Long userId); ServiceResult encryptAndOptUser(LoginUser user, List<DataBaseInfo> dBList); ServiceResult<String> addDataBaseList(List<DataBaseInfo> dBList); ServiceResult<List<String>> getDBCatalogs(Long dbsetId); ServiceResult<List<String>> getDBCatalogsByDbId(Long dbid); ServiceResult connectionTest(ConnectionRequest connectionRequest); ServiceResult deleteCheck(Long dbId); ServiceResult<String> addDataCenter(LoginUser user, List<DataBaseInfo> list); ServiceResult<String> updateDataCenter(LoginUser user, DataBaseInfo dataBaseInfo); ServiceResult<String> deleteDataCenter(LoginUser user, DataBaseInfo dataBaseInfo); ServiceResult<String> syncDataCenter(LoginUser user, DataBaseInfo dataBaseInfo); ConfigCkeckResult<List<ConfigDataResponse>> getCheckData(LoginUser user, DataBaseInfo dataBaseInfo); ServiceResult getDataBaseButton(LoginUser user);  }