| | |
| | | import com.alibaba.nacos.api.naming.pojo.Instance; |
| | | import com.vci.ubcs.common.constant.LauncherConstant; |
| | | import com.vci.ubcs.omd.dto.BtmAndLinkTypeDdlDTO; |
| | | import com.vci.ubcs.omd.dto.TableAddColumnDTO; |
| | | import com.vci.ubcs.omd.dto.TableCheckDTO; |
| | | import com.vci.ubcs.omd.dto.TableCheckResultDTO; |
| | | import com.vci.ubcs.omd.vo.BtmTypeVO; |
| | | import com.vci.ubcs.omd.vo.DomainVO; |
| | | import com.vci.ubcs.omd.vo.LinkTypeVO; |
| | |
| | | import org.springblade.core.launch.constant.AppConstant; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.utils.BeanUtil; |
| | | import org.springblade.core.tool.utils.StringPool; |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | public static final String API_CHECK_DIFFERENT_REFLEX = API_PREFIX + StringPool.SLASH + "checkDifferentAndReflex"; |
| | | |
| | | /** |
| | | * 检查数据表是否有数据,没有按需求删除 |
| | | */ |
| | | public static final String API_CHECK_TABLE_HAS_DATA_THEN_DELETE = API_PREFIX + StringPool.SLASH + "checkTableHasDataThenDelete"; |
| | | |
| | | /** |
| | | * 数据表添加字段 |
| | | */ |
| | | public static final String API_TABLE_ADD_COLUMN = API_PREFIX + StringPool.SLASH + "addColumnForTable"; |
| | | |
| | | /** |
| | | * 用于构建静态服务类 |
| | | */ |
| | | public static DomainRepeater domainRepeater; |
| | |
| | | return R.fail(String.valueOf(responseEntity.getStatusCode().value())); |
| | | } |
| | | |
| | | /** |
| | | * 检查数据表是否存在数据,如果不存在则删除 |
| | | * @param checkList 需要检查的表集合 |
| | | * @return 检查结果 |
| | | * @throws NacosException 找不到服务的时候会抛出异常 |
| | | */ |
| | | public static R checkTableHasDataByTableNameThenDrop(List<TableCheckDTO> checkList) throws NacosException { |
| | | Map<String, List<TableCheckDTO>> serviceMap = checkList.stream().collect(Collectors.groupingBy(TableCheckDTO::getDomain)); |
| | | List<TableCheckResultDTO> result = new ArrayList<>(); |
| | | for (String key : serviceMap.keySet()) { |
| | | String url = getUrl(key, API_CHECK_TABLE_HAS_DATA_THEN_DELETE); |
| | | ResponseEntity<R> responseEntity = executePost(url, JSONObject.toJSONString(serviceMap.get(key)), new HashMap<>(16)); |
| | | if (responseEntity.getStatusCode().equals(HttpStatus.OK)) { |
| | | R r = responseEntity.getBody(); |
| | | if (r.getData() instanceof List){ |
| | | List dataList = (List) r.getData(); |
| | | dataList.forEach(data -> { |
| | | TableCheckResultDTO dto = BeanUtil.copy(JSON.parseObject(JSON.toJSONString(data)), TableCheckResultDTO.class); |
| | | result.add(dto); |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | return R.data(result); |
| | | } |
| | | |
| | | /** |
| | | * 为表添加字段 |
| | | * @param addColumnDTO 添加的对象 |
| | | * @param serviceName 服务名 |
| | | * @return 执行结果 |
| | | * @throws NacosException 找不到服务时抛出异常 |
| | | */ |
| | | public static R addColumnForTable(TableAddColumnDTO addColumnDTO, String serviceName) throws NacosException { |
| | | try { |
| | | String url = getUrl(serviceName,API_TABLE_ADD_COLUMN); |
| | | ResponseEntity<R> responseEntity = executePost(url, JSONObject.toJSONString(addColumnDTO), null); |
| | | if (responseEntity.getStatusCode().equals(HttpStatus.OK)) { |
| | | R body = Objects.requireNonNull(responseEntity.getBody()); |
| | | return body; |
| | | } |
| | | return R.fail(String.valueOf(responseEntity.getStatusCode().value())); |
| | | }catch (HttpClientErrorException e) { |
| | | if (HttpStatus.NOT_FOUND.equals(e.getStatusCode())) { |
| | | R fail = R.fail("调用服务失败"); |
| | | fail.setCode(HttpStatus.NOT_FOUND.value()); |
| | | return fail; |
| | | } |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | return R.fail("未知错误"); |
| | | } |
| | | |
| | | @PostConstruct |
| | | private void init() { |
| | | domainRepeater = this; |