|
@@ -1,334 +1,333 @@
|
|
-package com.dragoninfo.dcuc.authweb.restcontroller.app;
|
|
|
|
-
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
|
-import com.dragoninfo.dcuc.app.dto.ResourceSyncDTO;
|
|
|
|
-import com.dragoninfo.dcuc.app.dto.ServiceAuthFlowDTO;
|
|
|
|
-import com.dragoninfo.dcuc.app.dto.ServiceResourceDTO;
|
|
|
|
-import com.dragoninfo.dcuc.app.enumresources.ResourceTypeEnum;
|
|
|
|
-import com.dragoninfo.dcuc.app.facade.IResourceFacade;
|
|
|
|
-import com.dragoninfo.dcuc.auth.auth.enumresources.YesNotEnum;
|
|
|
|
-import com.dragoninfo.dcuc.authweb.config.DcucAuthWebConfig;
|
|
|
|
-import com.dragoninfo.dcuc.authweb.restcontroller.api.v2.vo.*;
|
|
|
|
-import com.dragoninfo.dcuc.utils.huaweiapi.ApiGwUtils;
|
|
|
|
-import com.dragoninfo.duceap.core.response.Result;
|
|
|
|
-import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
|
|
|
|
-import com.dragonsoft.duceap.commons.util.string.StringUtils;
|
|
|
|
-import com.dragonsoft.duceap.core.entity.page.PageImpl;
|
|
|
|
-import com.dragonsoft.duceap.core.entity.page.PageRequest;
|
|
|
|
-import com.dragonsoft.duceap.core.search.Searchable;
|
|
|
|
-import org.apache.commons.collections.map.HashedMap;
|
|
|
|
-import org.slf4j.Logger;
|
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
-import org.springframework.data.domain.Page;
|
|
|
|
-import org.springframework.data.domain.Pageable;
|
|
|
|
-import org.springframework.http.MediaType;
|
|
|
|
-import org.springframework.stereotype.Controller;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
-import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
-
|
|
|
|
-import java.io.IOException;
|
|
|
|
-import java.io.InputStream;
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.Arrays;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * @author mazq
|
|
|
|
- * @Description 主动获取海联应用服务数据的接口
|
|
|
|
- * @create 2020-11-25 15:07
|
|
|
|
- */
|
|
|
|
-@Controller
|
|
|
|
-@RequestMapping("/applicationManagement/resource/")
|
|
|
|
-public class ResourceListingController {
|
|
|
|
-
|
|
|
|
- Logger logger = LoggerFactory.getLogger(ResourceListingController.class);
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- DcucAuthWebConfig dcucWebConfig;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private IResourceFacade iResourceFacade;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 获取应用和服务资源列表
|
|
|
|
- * 全量获取时,如果是第一页获取失败表示该资源列表都获取失败
|
|
|
|
- */
|
|
|
|
- @RequestMapping(value = "listing", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
- @ResponseBody
|
|
|
|
- public Result<List<ResourceListResult>> getResourceListing(@RequestBody ResourceRequestParam requestParam) {
|
|
|
|
- List<ResourceListResult> pageInfos = new ArrayList<>();
|
|
|
|
- Integer pageSize = requestParam.getPageSize();
|
|
|
|
- boolean listingAll = requestParam.isListingAll();
|
|
|
|
- pageSize = (pageSize == null ? 20 : pageSize);
|
|
|
|
- String tenantId = "";
|
|
|
|
- //全量获取
|
|
|
|
- //从currentPageNo页获取
|
|
|
|
- if (listingAll) {
|
|
|
|
- //全量默认20,便于下次同步
|
|
|
|
- pageSize = 20;
|
|
|
|
- Integer currentPageNo = requestParam.getCurrentPageNo();
|
|
|
|
- for (ResourceTypeEnum resourceEnum : ResourceTypeEnum.values()) {
|
|
|
|
- //若是增量获取currentPage = 数据库中上次同步的页数
|
|
|
|
- if (null == currentPageNo) {
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- ResourceListResult listingInfo = getAllResourceListing(currentPageNo, pageSize, tenantId, resourceEnum.getResourceId());
|
|
|
|
- pageInfos.add(listingInfo);
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- //根据页码获取
|
|
|
|
- List<ListingParam> listingParams = requestParam.getListingParams();
|
|
|
|
- for (ListingParam listingParam : listingParams) {
|
|
|
|
- ResourceListResult listingInfo = getPageNoResourceListing(pageSize, tenantId, listingParam);
|
|
|
|
- pageInfos.add(listingInfo);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- //是否需要保存已获取的页数,下次获取使用增量获取?
|
|
|
|
- return Result.success();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 资源同步表与应用、服务资源同步
|
|
|
|
- */
|
|
|
|
- @RequestMapping(value = "sync", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
- @ResponseBody
|
|
|
|
- public Result ResourceSync() {
|
|
|
|
- iResourceFacade.resourceSync();
|
|
|
|
- return Result.success();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 服务资源列表分页查询
|
|
|
|
- */
|
|
|
|
- @RequestMapping(value = "serviceResource/search", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
- @ResponseBody
|
|
|
|
- public Result<Page<ServiceResourceVo>> serviceResourcePage(Searchable searchable) {
|
|
|
|
- Page<ServiceResourceDTO> page = iResourceFacade.serviceResourcePage(searchable.toSearchDTO());
|
|
|
|
- List<ServiceResourceVo> vos = new ArrayList<>();
|
|
|
|
- List<ServiceResourceDTO> content = page.getContent();
|
|
|
|
- for (ServiceResourceDTO dto : content) {
|
|
|
|
- ServiceResourceVo vo = new ServiceResourceVo();
|
|
|
|
- BeanUtils.copyProperties(dto, vo);
|
|
|
|
- vos.add(vo);
|
|
|
|
- }
|
|
|
|
- Pageable newPageable = new PageRequest(page.getNumber(), page.getSize());
|
|
|
|
- PageImpl<ServiceResourceVo> pageResult = new PageImpl<>(vos, newPageable, page.getTotalElements());
|
|
|
|
- return Result.success();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 服务授权工单列表
|
|
|
|
- *
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- @RequestMapping(value = "serviceAuthFlow/search", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
- @ResponseBody
|
|
|
|
- public Result<Page<ServiceAuthFlowVo>> serviceAuthFlowPage(Searchable searchable) {
|
|
|
|
- Page<ServiceAuthFlowDTO> page = iResourceFacade.serviceAuthFlowPage(searchable.toSearchDTO());
|
|
|
|
- List<ServiceAuthFlowDTO> content = page.getContent();
|
|
|
|
- List<ServiceAuthFlowVo> vos = new ArrayList<>();
|
|
|
|
- for (ServiceAuthFlowDTO dto : content) {
|
|
|
|
- ServiceAuthFlowVo vo = new ServiceAuthFlowVo();
|
|
|
|
- BeanUtils.copyProperties(dto, vo, "serviceCodes", "serviceNames");
|
|
|
|
- String serviceCodes = dto.getServiceCodes();
|
|
|
|
- if (StringUtils.isNotBlank(serviceCodes)) {
|
|
|
|
- List<String> serviceCodesList = Arrays.asList(serviceCodes.split(","));
|
|
|
|
- vo.setServiceCodes(serviceCodesList);
|
|
|
|
- }
|
|
|
|
- String serviceNames = dto.getServiceNames();
|
|
|
|
- if (StringUtils.isNotBlank(serviceNames)) {
|
|
|
|
- List<String> serviceNamesList = Arrays.asList(serviceNames.split(","));
|
|
|
|
- vo.setServiceNames(serviceNamesList);
|
|
|
|
- }
|
|
|
|
- vos.add(vo);
|
|
|
|
- }
|
|
|
|
- Pageable newPageable = new PageRequest(page.getNumber(), page.getSize());
|
|
|
|
- PageImpl<ServiceAuthFlowVo> pageResult = new PageImpl<>(vos, newPageable, page.getTotalElements());
|
|
|
|
- return Result.success();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 根据页码获取资源列表
|
|
|
|
- *
|
|
|
|
- * @param pageSize
|
|
|
|
- * @param tenantId
|
|
|
|
- * @param listingParam
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- private ResourceListResult getPageNoResourceListing(Integer pageSize, String tenantId, ListingParam listingParam) {
|
|
|
|
- String resourceId = listingParam.getResourceId();
|
|
|
|
- List<Integer> pageNos = listingParam.getPageNo();
|
|
|
|
- ResourceListResult resourceListResult = new ResourceListResult(resourceId, new ArrayList<Integer>());
|
|
|
|
- for (Integer pageNo : pageNos) {
|
|
|
|
- Result<Map<String, Object>> result = getRemoteResource(resourceId, pageNo, pageSize, tenantId);
|
|
|
|
- //只收集未同步成功的资源id和页码
|
|
|
|
- if (!ResponseStatus.SUCCESS_CODE.equals(result.getResult())) {
|
|
|
|
- Map<String, Object> resultMap = result.getContent();
|
|
|
|
- Integer ePageNo = (Integer) resultMap.get("pageNo");
|
|
|
|
- resourceListResult.getPageNos().add(ePageNo);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- //不记录总页数,这里不是全量获取
|
|
|
|
- resourceListResult.setResourceId(resourceId);
|
|
|
|
- return resourceListResult;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 从currentPageNo页获取全量的资源列表
|
|
|
|
- * 第currentPageNo页获取失败表示该资源列表都获取失败
|
|
|
|
- *
|
|
|
|
- * @param pageSize
|
|
|
|
- * @param tenantId
|
|
|
|
- * @param resourceId
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- private ResourceListResult getAllResourceListing(Integer currentPageNo, Integer pageSize, String tenantId, String resourceId) {
|
|
|
|
- Integer pageNo = currentPageNo;
|
|
|
|
- Integer pages = currentPageNo;
|
|
|
|
- ResourceListResult resourceListResult = new ResourceListResult(resourceId, new ArrayList<Integer>());
|
|
|
|
- resourceListResult.setSuccess(YesNotEnum.YES.getValue());
|
|
|
|
- do {
|
|
|
|
- Result<Map<String, Object>> result = getRemoteResource(resourceId, pageNo, pageSize, tenantId);
|
|
|
|
- Map<String, Object> resultMap = result.getContent();
|
|
|
|
- //收集未同步成功的资源id和页码
|
|
|
|
- if (!ResponseStatus.SUCCESS_CODE.equals(result.getResult())) {
|
|
|
|
- Integer ePageNo = (Integer) resultMap.get("pageNo");
|
|
|
|
- resourceListResult.getPageNos().add(ePageNo);
|
|
|
|
- resourceListResult.setSuccess(YesNotEnum.NO.getValue());
|
|
|
|
- ++pageNo;
|
|
|
|
- }
|
|
|
|
- Integer allPages = (Integer) resultMap.get("pages");
|
|
|
|
- if (null != allPages) {
|
|
|
|
- pages = allPages;
|
|
|
|
- ++pageNo;
|
|
|
|
- }
|
|
|
|
- } while (pageNo <= pages);
|
|
|
|
- //收集获取列表的信息
|
|
|
|
- //这里是全量获取,记录资源获取的总页数,便于下次全量获取使用
|
|
|
|
- resourceListResult.setTotalPages(pages);
|
|
|
|
- resourceListResult.setResourceId(resourceId);
|
|
|
|
- return resourceListResult;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 从网关获取应用信息和服务信息,并录入数据
|
|
|
|
- */
|
|
|
|
- private Result<Map<String, Object>> getRemoteResource(String resouceId, Integer pageNo, Integer pageSize, String tenantId) {
|
|
|
|
- if (resouceId == null) {
|
|
|
|
- logger.info("资源类型不能为空", resouceId);
|
|
|
|
- }
|
|
|
|
- if (tenantId == null) {
|
|
|
|
- logger.info("资源类型不能为空", resouceId);
|
|
|
|
- }
|
|
|
|
- Map<String, Object> resultMap = new HashedMap();
|
|
|
|
- ResourceTypeEnum resourceEnum = ResourceTypeEnum.getByResourceId(resouceId);
|
|
|
|
- JSONObject resultFromRemote;
|
|
|
|
- try {
|
|
|
|
-// 测试
|
|
|
|
-// resultFromRemote = getResourceFromRemoteTest(tenantId,resourceEnum.getResourceType(),pageNo,pageSize);
|
|
|
|
- resultFromRemote = getResourceFromRemote(tenantId, resourceEnum.getResourceType(), pageNo, pageSize);
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- logger.info("get remote resource error from pageNo:{},pageSize:{},resourceId:{}", pageNo, pageSize, resouceId);
|
|
|
|
- logger.error("get remote resource error", e);
|
|
|
|
- resultMap.put("pageNo", pageNo);
|
|
|
|
- resultMap.put("pageSize", pageSize);
|
|
|
|
- resultMap.put("resourceId", resouceId);
|
|
|
|
- return Result.fail("400", "get remote resource error", resultMap);
|
|
|
|
- }
|
|
|
|
- if (!ResponseStatus.SUCCESS_CODE.equals(String.valueOf(resultFromRemote.get("code")))) {
|
|
|
|
- logger.info("get remote resource error from pageNo:{},pageSize:{},resourceId:{}", pageNo, pageSize, resouceId);
|
|
|
|
- logger.info("get remote resource error:{}", resultFromRemote.toJSONString());
|
|
|
|
- resultMap.put("pageNo", pageNo);
|
|
|
|
- resultMap.put("pageSize", pageSize);
|
|
|
|
- resultMap.put("resourceId", resouceId);
|
|
|
|
- return Result.fail("400", "get remote resource failed", resultMap);
|
|
|
|
- }
|
|
|
|
- JSONObject data = resultFromRemote.getJSONObject("data");
|
|
|
|
- JSONArray records = data.getJSONArray("records");
|
|
|
|
- //插入资源数据同步表
|
|
|
|
- insertRemoteResourceSync(resourceEnum, records);
|
|
|
|
- //返回总数量和总页数
|
|
|
|
- Integer total = data.getInteger("total");
|
|
|
|
- Integer pages = data.getInteger("pages");
|
|
|
|
- resultMap.put("pageNo", pageNo);
|
|
|
|
- resultMap.put("pageSize", pageSize);
|
|
|
|
- resultMap.put("resourceId", resouceId);
|
|
|
|
- resultMap.put("total", total);
|
|
|
|
- resultMap.put("pages", pages);
|
|
|
|
- return Result.success(resultMap);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 获取海联应用信息
|
|
|
|
- *
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- private JSONObject getResourceFromRemote(String tenantId, String resourceType, Integer pageNo, Integer pageSize) throws IOException {
|
|
|
|
- StringBuffer HlResourceUrl = new StringBuffer();
|
|
|
|
- String url = HlResourceUrl.append(tenantId)
|
|
|
|
- .append("?type=").append(resourceType)
|
|
|
|
- .append("&pageNo=").append(pageNo)
|
|
|
|
- .append("&pageSize=").append(pageSize)
|
|
|
|
- .toString();
|
|
|
|
- logger.info("get resource url:{}", url);
|
|
|
|
- String huaWeiUrl = "http://68.26.19.197:8343";
|
|
|
|
- String clientId = "bbd8ef1a30874d91bc759a6d9f692532";
|
|
|
|
- String clientSecret = "490d89dd10444585ac49231b22a44727";
|
|
|
|
- String accessToken = ApiGwUtils.getAccessToken(huaWeiUrl, clientId, clientSecret);
|
|
|
|
- return ApiGwUtils.requestServer(url, null, accessToken, "get");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- private JSONObject getResourceFromRemoteTest(String tenantId, String resourceType, Integer pageNo, Integer pageSize) throws IOException {
|
|
|
|
- InputStream stream;
|
|
|
|
- if ("05".equals(resourceType)) {
|
|
|
|
- stream = ClassLoader.getSystemResourceAsStream("AppPageJson.json");
|
|
|
|
- } else if ("02".equals(resourceType)) {
|
|
|
|
- stream = ClassLoader.getSystemResourceAsStream("ServicePageJson.json");
|
|
|
|
- } else {
|
|
|
|
- return new JSONObject();
|
|
|
|
- }
|
|
|
|
- int available = stream.available();
|
|
|
|
- byte[] bytes = new byte[available];
|
|
|
|
- int read = stream.read(bytes);
|
|
|
|
- String pageJson = new String(bytes);
|
|
|
|
- JSONArray array = JSONArray.parseArray(pageJson);
|
|
|
|
- JSONObject jsonObject = array.getJSONObject(pageNo - 1);
|
|
|
|
- return jsonObject;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- private void insertRemoteResourceSync(ResourceTypeEnum resourceEnum, JSONArray records) {
|
|
|
|
- List<ResourceSyncDTO> list = new ArrayList<>();
|
|
|
|
- for (Object record : records) {
|
|
|
|
- String jsonString = JSON.toJSONString(record);
|
|
|
|
- ResourceSyncDTO dto = new ResourceSyncDTO(resourceEnum.getResourceId(),
|
|
|
|
- resourceEnum.getResourceType(), resourceEnum.getResouProvider());
|
|
|
|
- dto.setContent(jsonString);
|
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(jsonString);
|
|
|
|
- String appCode = jsonObject.getString("appCode");
|
|
|
|
- String serviceCode = jsonObject.getString("serviceCode");
|
|
|
|
- String appName = jsonObject.getString("appName");
|
|
|
|
- String serviceName = jsonObject.getString("serviceName");
|
|
|
|
- dto.setAppCode(appCode);
|
|
|
|
- dto.setAppName(appName);
|
|
|
|
- dto.setServiceCode(serviceCode);
|
|
|
|
- dto.setServiceName(serviceName);
|
|
|
|
- dto.setSync(YesNotEnum.NO.getValue());
|
|
|
|
- list.add(dto);
|
|
|
|
- }
|
|
|
|
- iResourceFacade.batchInsertResourceSync(list);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
|
|
+//package com.dragoninfo.dcuc.authweb.restcontroller.app;
|
|
|
|
+//
|
|
|
|
+//import com.alibaba.fastjson.JSON;
|
|
|
|
+//import com.alibaba.fastjson.JSONArray;
|
|
|
|
+//import com.alibaba.fastjson.JSONObject;
|
|
|
|
+//import com.dragoninfo.dcuc.app.dto.ResourceSyncDTO;
|
|
|
|
+//import com.dragoninfo.dcuc.app.dto.ServiceAuthFlowDTO;
|
|
|
|
+//import com.dragoninfo.dcuc.app.dto.ServiceResourceDTO;
|
|
|
|
+//import com.dragoninfo.dcuc.app.enumresources.ResourceTypeEnum;
|
|
|
|
+//import com.dragoninfo.dcuc.app.facade.IResourceFacade;
|
|
|
|
+//import com.dragoninfo.dcuc.auth.auth.enumresources.YesNotEnum;
|
|
|
|
+//import com.dragoninfo.dcuc.authweb.config.DcucAuthWebConfig;
|
|
|
|
+//import com.dragoninfo.dcuc.authweb.restcontroller.api.v2.vo.*;
|
|
|
|
+//import com.dragoninfo.dcuc.utils.huaweiapi.ApiGwUtils;
|
|
|
|
+//import com.dragoninfo.duceap.core.response.Result;
|
|
|
|
+//import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
|
|
|
|
+//import com.dragonsoft.duceap.commons.util.string.StringUtils;
|
|
|
|
+//import com.dragonsoft.duceap.core.entity.page.PageImpl;
|
|
|
|
+//import com.dragonsoft.duceap.core.entity.page.PageRequest;
|
|
|
|
+//import com.dragonsoft.duceap.core.search.Searchable;
|
|
|
|
+//import org.apache.commons.collections.map.HashedMap;
|
|
|
|
+//import org.slf4j.Logger;
|
|
|
|
+//import org.slf4j.LoggerFactory;
|
|
|
|
+//import org.springframework.beans.BeanUtils;
|
|
|
|
+//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+//import org.springframework.data.domain.Page;
|
|
|
|
+//import org.springframework.data.domain.Pageable;
|
|
|
|
+//import org.springframework.http.MediaType;
|
|
|
|
+//import org.springframework.stereotype.Controller;
|
|
|
|
+//import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
+//import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+//import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
+//import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
+//
|
|
|
|
+//import java.io.IOException;
|
|
|
|
+//import java.io.InputStream;
|
|
|
|
+//import java.util.ArrayList;
|
|
|
|
+//import java.util.Arrays;
|
|
|
|
+//import java.util.List;
|
|
|
|
+//import java.util.Map;
|
|
|
|
+//
|
|
|
|
+///**
|
|
|
|
+// * @author mazq
|
|
|
|
+// * @Description 主动获取海联应用服务数据的接口
|
|
|
|
+// * @create 2020-11-25 15:07
|
|
|
|
+// */
|
|
|
|
+//@Controller
|
|
|
|
+//@RequestMapping("/applicationManagement/resource/")
|
|
|
|
+//public class ResourceListingController {
|
|
|
|
+//
|
|
|
|
+// Logger logger = LoggerFactory.getLogger(ResourceListingController.class);
|
|
|
|
+//
|
|
|
|
+// @Autowired
|
|
|
|
+// DcucAuthWebConfig dcucWebConfig;
|
|
|
|
+//
|
|
|
|
+// @Autowired
|
|
|
|
+// private IResourceFacade iResourceFacade;
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+// /**
|
|
|
|
+// * 获取应用和服务资源列表
|
|
|
|
+// * 全量获取时,如果是第一页获取失败表示该资源列表都获取失败
|
|
|
|
+// */
|
|
|
|
+// @RequestMapping(value = "listing", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
+// @ResponseBody
|
|
|
|
+// public Result<List<ResourceListResult>> getResourceListing(@RequestBody ResourceRequestParam requestParam) {
|
|
|
|
+// List<ResourceListResult> pageInfos = new ArrayList<>();
|
|
|
|
+// Integer pageSize = requestParam.getPageSize();
|
|
|
|
+// boolean listingAll = requestParam.isListingAll();
|
|
|
|
+// pageSize = (pageSize == null ? 20 : pageSize);
|
|
|
|
+// String tenantId = "";
|
|
|
|
+// //全量获取
|
|
|
|
+// //从currentPageNo页获取
|
|
|
|
+// if (listingAll) {
|
|
|
|
+// //全量默认20,便于下次同步
|
|
|
|
+// pageSize = 20;
|
|
|
|
+// Integer currentPageNo = requestParam.getCurrentPageNo();
|
|
|
|
+// for (ResourceTypeEnum resourceEnum : ResourceTypeEnum.values()) {
|
|
|
|
+// //若是增量获取currentPage = 数据库中上次同步的页数
|
|
|
|
+// if (null == currentPageNo) {
|
|
|
|
+//
|
|
|
|
+// }
|
|
|
|
+// ResourceListResult listingInfo = getAllResourceListing(currentPageNo, pageSize, tenantId, resourceEnum.getResourceId());
|
|
|
|
+// pageInfos.add(listingInfo);
|
|
|
|
+// }
|
|
|
|
+// } else {
|
|
|
|
+// //根据页码获取
|
|
|
|
+// List<ListingParam> listingParams = requestParam.getListingParams();
|
|
|
|
+// for (ListingParam listingParam : listingParams) {
|
|
|
|
+// ResourceListResult listingInfo = getPageNoResourceListing(pageSize, tenantId, listingParam);
|
|
|
|
+// pageInfos.add(listingInfo);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// //是否需要保存已获取的页数,下次获取使用增量获取?
|
|
|
|
+// return Result.success();
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// /**
|
|
|
|
+// * 资源同步表与应用、服务资源同步
|
|
|
|
+// */
|
|
|
|
+// @RequestMapping(value = "sync", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
+// @ResponseBody
|
|
|
|
+// public Result ResourceSync() {
|
|
|
|
+// iResourceFacade.resourceSync();
|
|
|
|
+// return Result.success();
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// /**
|
|
|
|
+// * 服务资源列表分页查询
|
|
|
|
+// */
|
|
|
|
+// @RequestMapping(value = "serviceResource/search", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
+// @ResponseBody
|
|
|
|
+// public Result<Page<ServiceResourceVo>> serviceResourcePage(Searchable searchable) {
|
|
|
|
+// Page<ServiceResourceDTO> page = iResourceFacade.serviceResourcePage(searchable.toSearchDTO());
|
|
|
|
+// List<ServiceResourceVo> vos = new ArrayList<>();
|
|
|
|
+// List<ServiceResourceDTO> content = page.getContent();
|
|
|
|
+// for (ServiceResourceDTO dto : content) {
|
|
|
|
+// ServiceResourceVo vo = new ServiceResourceVo();
|
|
|
|
+// BeanUtils.copyProperties(dto, vo);
|
|
|
|
+// vos.add(vo);
|
|
|
|
+// }
|
|
|
|
+// Pageable newPageable = new PageRequest(page.getNumber(), page.getSize());
|
|
|
|
+// PageImpl<ServiceResourceVo> pageResult = new PageImpl<>(vos, newPageable, page.getTotalElements());
|
|
|
|
+// return Result.success();
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// /**
|
|
|
|
+// * 服务授权工单列表
|
|
|
|
+// *
|
|
|
|
+// * @return
|
|
|
|
+// */
|
|
|
|
+// @RequestMapping(value = "serviceAuthFlow/search", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
+// @ResponseBody
|
|
|
|
+// public Result<Page<ServiceAuthFlowVo>> serviceAuthFlowPage(Searchable searchable) {
|
|
|
|
+// Page<ServiceAuthFlowDTO> page = iResourceFacade.serviceAuthFlowPage(searchable.toSearchDTO());
|
|
|
|
+// List<ServiceAuthFlowDTO> content = page.getContent();
|
|
|
|
+// List<ServiceAuthFlowVo> vos = new ArrayList<>();
|
|
|
|
+// for (ServiceAuthFlowDTO dto : content) {
|
|
|
|
+// ServiceAuthFlowVo vo = new ServiceAuthFlowVo();
|
|
|
|
+// BeanUtils.copyProperties(dto, vo, "serviceCodes", "serviceNames");
|
|
|
|
+// String serviceCodes = dto.getServiceCodes();
|
|
|
|
+// if (StringUtils.isNotBlank(serviceCodes)) {
|
|
|
|
+// List<String> serviceCodesList = Arrays.asList(serviceCodes.split(","));
|
|
|
|
+// vo.setServiceCodes(serviceCodesList);
|
|
|
|
+// }
|
|
|
|
+// String serviceNames = dto.getServiceNames();
|
|
|
|
+// if (StringUtils.isNotBlank(serviceNames)) {
|
|
|
|
+// List<String> serviceNamesList = Arrays.asList(serviceNames.split(","));
|
|
|
|
+// vo.setServiceNames(serviceNamesList);
|
|
|
|
+// }
|
|
|
|
+// vos.add(vo);
|
|
|
|
+// }
|
|
|
|
+// Pageable newPageable = new PageRequest(page.getNumber(), page.getSize());
|
|
|
|
+// PageImpl<ServiceAuthFlowVo> pageResult = new PageImpl<>(vos, newPageable, page.getTotalElements());
|
|
|
|
+// return Result.success();
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+// /**
|
|
|
|
+// * 根据页码获取资源列表
|
|
|
|
+// *
|
|
|
|
+// * @param pageSize
|
|
|
|
+// * @param tenantId
|
|
|
|
+// * @param listingParam
|
|
|
|
+// * @return
|
|
|
|
+// */
|
|
|
|
+// private ResourceListResult getPageNoResourceListing(Integer pageSize, String tenantId, ListingParam listingParam) {
|
|
|
|
+// String resourceId = listingParam.getResourceId();
|
|
|
|
+// List<Integer> pageNos = listingParam.getPageNo();
|
|
|
|
+// ResourceListResult resourceListResult = new ResourceListResult(resourceId, new ArrayList<Integer>());
|
|
|
|
+// for (Integer pageNo : pageNos) {
|
|
|
|
+// Result<Map<String, Object>> result = getRemoteResource(resourceId, pageNo, pageSize, tenantId);
|
|
|
|
+// //只收集未同步成功的资源id和页码
|
|
|
|
+// if (!ResponseStatus.SUCCESS_CODE.equals(result.getResult())) {
|
|
|
|
+// Map<String, Object> resultMap = result.getContent();
|
|
|
|
+// Integer ePageNo = (Integer) resultMap.get("pageNo");
|
|
|
|
+// resourceListResult.getPageNos().add(ePageNo);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// //不记录总页数,这里不是全量获取
|
|
|
|
+// resourceListResult.setResourceId(resourceId);
|
|
|
|
+// return resourceListResult;
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// /**
|
|
|
|
+// * 从currentPageNo页获取全量的资源列表
|
|
|
|
+// * 第currentPageNo页获取失败表示该资源列表都获取失败
|
|
|
|
+// *
|
|
|
|
+// * @param pageSize
|
|
|
|
+// * @param tenantId
|
|
|
|
+// * @param resourceId
|
|
|
|
+// * @return
|
|
|
|
+// */
|
|
|
|
+// private ResourceListResult getAllResourceListing(Integer currentPageNo, Integer pageSize, String tenantId, String resourceId) {
|
|
|
|
+// Integer pageNo = currentPageNo;
|
|
|
|
+// Integer pages = currentPageNo;
|
|
|
|
+// ResourceListResult resourceListResult = new ResourceListResult(resourceId, new ArrayList<Integer>());
|
|
|
|
+// resourceListResult.setSuccess(YesNotEnum.YES.getValue());
|
|
|
|
+// do {
|
|
|
|
+// Result<Map<String, Object>> result = getRemoteResource(resourceId, pageNo, pageSize, tenantId);
|
|
|
|
+// Map<String, Object> resultMap = result.getContent();
|
|
|
|
+// //收集未同步成功的资源id和页码
|
|
|
|
+// if (!ResponseStatus.SUCCESS_CODE.equals(result.getResult())) {
|
|
|
|
+// Integer ePageNo = (Integer) resultMap.get("pageNo");
|
|
|
|
+// resourceListResult.getPageNos().add(ePageNo);
|
|
|
|
+// resourceListResult.setSuccess(YesNotEnum.NO.getValue());
|
|
|
|
+// ++pageNo;
|
|
|
|
+// }
|
|
|
|
+// Integer allPages = (Integer) resultMap.get("pages");
|
|
|
|
+// if (null != allPages) {
|
|
|
|
+// pages = allPages;
|
|
|
|
+// ++pageNo;
|
|
|
|
+// }
|
|
|
|
+// } while (pageNo <= pages);
|
|
|
|
+// //收集获取列表的信息
|
|
|
|
+// //这里是全量获取,记录资源获取的总页数,便于下次全量获取使用
|
|
|
|
+// resourceListResult.setTotalPages(pages);
|
|
|
|
+// resourceListResult.setResourceId(resourceId);
|
|
|
|
+// return resourceListResult;
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+// /**
|
|
|
|
+// * 从网关获取应用信息和服务信息,并录入数据
|
|
|
|
+// */
|
|
|
|
+// private Result<Map<String, Object>> getRemoteResource(String resouceId, Integer pageNo, Integer pageSize, String tenantId) {
|
|
|
|
+// if (resouceId == null) {
|
|
|
|
+// logger.info("资源类型不能为空", resouceId);
|
|
|
|
+// }
|
|
|
|
+// if (tenantId == null) {
|
|
|
|
+// logger.info("资源类型不能为空", resouceId);
|
|
|
|
+// }
|
|
|
|
+// Map<String, Object> resultMap = new HashedMap();
|
|
|
|
+// ResourceTypeEnum resourceEnum = ResourceTypeEnum.getByResourceId(resouceId);
|
|
|
|
+// JSONObject resultFromRemote;
|
|
|
|
+// try {
|
|
|
|
+//// 测试
|
|
|
|
+//// resultFromRemote = getResourceFromRemoteTest(tenantId,resourceEnum.getResourceType(),pageNo,pageSize);
|
|
|
|
+// resultFromRemote = getResourceFromRemote(tenantId, resourceEnum.getResourceType(), pageNo, pageSize);
|
|
|
|
+// } catch (IOException e) {
|
|
|
|
+// logger.info("get remote resource error from pageNo:{},pageSize:{},resourceId:{}", pageNo, pageSize, resouceId);
|
|
|
|
+// logger.error("get remote resource error", e);
|
|
|
|
+// resultMap.put("pageNo", pageNo);
|
|
|
|
+// resultMap.put("pageSize", pageSize);
|
|
|
|
+// resultMap.put("resourceId", resouceId);
|
|
|
|
+// return Result.fail("400", "get remote resource error", resultMap);
|
|
|
|
+// }
|
|
|
|
+// if (!ResponseStatus.SUCCESS_CODE.equals(String.valueOf(resultFromRemote.get("code")))) {
|
|
|
|
+// logger.info("get remote resource error from pageNo:{},pageSize:{},resourceId:{}", pageNo, pageSize, resouceId);
|
|
|
|
+// logger.info("get remote resource error:{}", resultFromRemote.toJSONString());
|
|
|
|
+// resultMap.put("pageNo", pageNo);
|
|
|
|
+// resultMap.put("pageSize", pageSize);
|
|
|
|
+// resultMap.put("resourceId", resouceId);
|
|
|
|
+// return Result.fail("400", "get remote resource failed", resultMap);
|
|
|
|
+// }
|
|
|
|
+// JSONObject data = resultFromRemote.getJSONObject("data");
|
|
|
|
+// JSONArray records = data.getJSONArray("records");
|
|
|
|
+// //插入资源数据同步表
|
|
|
|
+// insertRemoteResourceSync(resourceEnum, records);
|
|
|
|
+// //返回总数量和总页数
|
|
|
|
+// Integer total = data.getInteger("total");
|
|
|
|
+// Integer pages = data.getInteger("pages");
|
|
|
|
+// resultMap.put("pageNo", pageNo);
|
|
|
|
+// resultMap.put("pageSize", pageSize);
|
|
|
|
+// resultMap.put("resourceId", resouceId);
|
|
|
|
+// resultMap.put("total", total);
|
|
|
|
+// resultMap.put("pages", pages);
|
|
|
|
+// return Result.success(resultMap);
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// /**
|
|
|
|
+// * 获取海联应用信息
|
|
|
|
+// *
|
|
|
|
+// * @return
|
|
|
|
+// */
|
|
|
|
+// private JSONObject getResourceFromRemote(String tenantId, String resourceType, Integer pageNo, Integer pageSize) throws IOException {
|
|
|
|
+// StringBuffer HlResourceUrl = new StringBuffer("");
|
|
|
|
+// String url = HlResourceUrl.append(tenantId)
|
|
|
|
+// .append("?type=").append(resourceType)
|
|
|
|
+// .append("&pageNo=").append(pageNo)
|
|
|
|
+// .append("&pageSize=").append(pageSize)
|
|
|
|
+// .toString();
|
|
|
|
+// logger.info("get resource url:{}", url);
|
|
|
|
+// String huaWeiUrl = "http://68.26.19.197:8343";
|
|
|
|
+// String clientId = "bbd8ef1a30874d91bc759a6d9f692532";
|
|
|
|
+// String clientSecret = "490d89dd10444585ac49231b22a44727";
|
|
|
|
+// String accessToken = ApiGwUtils.getAccessToken(huaWeiUrl, clientId, clientSecret);
|
|
|
|
+// return ApiGwUtils.requestServer(url, null, accessToken, "get");
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+// private JSONObject getResourceFromRemoteTest(String tenantId, String resourceType, Integer pageNo, Integer pageSize) throws IOException {
|
|
|
|
+// InputStream stream;
|
|
|
|
+// if ("05".equals(resourceType)) {
|
|
|
|
+// stream = ClassLoader.getSystemResourceAsStream("AppPageJson.json");
|
|
|
|
+// } else if ("02".equals(resourceType)) {
|
|
|
|
+// stream = ClassLoader.getSystemResourceAsStream("ServicePageJson.json");
|
|
|
|
+// } else {
|
|
|
|
+// return new JSONObject();
|
|
|
|
+// }
|
|
|
|
+// int available = stream.available();
|
|
|
|
+// byte[] bytes = new byte[available];
|
|
|
|
+// int read = stream.read(bytes);
|
|
|
|
+// String pageJson = new String(bytes);
|
|
|
|
+// JSONArray array = JSONArray.parseArray(pageJson);
|
|
|
|
+// JSONObject jsonObject = array.getJSONObject(pageNo - 1);
|
|
|
|
+// return jsonObject;
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+// private void insertRemoteResourceSync(ResourceTypeEnum resourceEnum, JSONArray records) {
|
|
|
|
+// List<ResourceSyncDTO> list = new ArrayList<>();
|
|
|
|
+// for (Object record : records) {
|
|
|
|
+// String jsonString = JSON.toJSONString(record);
|
|
|
|
+// ResourceSyncDTO dto = new ResourceSyncDTO(resourceEnum.getResourceId(),
|
|
|
|
+// resourceEnum.getResourceType(), resourceEnum.getResouProvider());
|
|
|
|
+// dto.setContent(jsonString);
|
|
|
|
+// JSONObject jsonObject = JSONObject.parseObject(jsonString);
|
|
|
|
+// String appCode = jsonObject.getString("appCode");
|
|
|
|
+// String serviceCode = jsonObject.getString("serviceCode");
|
|
|
|
+// String appName = jsonObject.getString("appName");
|
|
|
|
+// String serviceName = jsonObject.getString("serviceName");
|
|
|
|
+// dto.setAppCode(appCode);
|
|
|
|
+// dto.setAppName(appName);
|
|
|
|
+// dto.setServiceCode(serviceCode);
|
|
|
|
+// dto.setServiceName(serviceName);
|
|
|
|
+// dto.setSync(YesNotEnum.NO.getValue());
|
|
|
|
+// list.add(dto);
|
|
|
|
+// }
|
|
|
|
+// iResourceFacade.batchInsertResourceSync(list);
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+//}
|