|
@@ -17,6 +17,7 @@ import com.dragoninfo.dcuc.common.http.HttpUtil;
|
|
|
import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
|
|
|
import com.dragonsoft.duceap.base.enums.BooleanEnum;
|
|
|
import com.dragonsoft.duceap.commons.util.collections.CollectionUtils;
|
|
|
+import com.dragonsoft.duceap.commons.util.string.StringUtils;
|
|
|
import org.apache.http.Header;
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
import org.apache.http.message.BasicHeader;
|
|
@@ -24,6 +25,7 @@ import org.apache.http.util.EntityUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.server.PathContainer;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import java.io.IOException;
|
|
|
import java.text.SimpleDateFormat;
|
|
@@ -83,7 +85,7 @@ public class ResourceBusiness implements IResourceBusiness {
|
|
|
ResourceTypeEnum appEnum = ResourceTypeEnum.TJ_APP;
|
|
|
ResourceSyncDTO syncDTO = new ResourceSyncDTO(appEnum.getResourceId()
|
|
|
, appEnum.getResourceType(), appEnum.getResouProvider());
|
|
|
- AppInfoAcceptDTO appAcceptDTO = acceptDTO.getTAppSystem();
|
|
|
+ AppInfoAcceptDTO appAcceptDTO = acceptDTO.getTappSystem();
|
|
|
syncDTO.setAppCode(appAcceptDTO.getYyxtbh());
|
|
|
syncDTO.setAppName(appAcceptDTO.getYyxtmc());
|
|
|
syncDTO.setExtId(appAcceptDTO.getId());
|
|
@@ -105,7 +107,7 @@ public class ResourceBusiness implements IResourceBusiness {
|
|
|
* @return
|
|
|
*/
|
|
|
private AppResourceDTO convertToAppDTO(AppResourceAcceptDTO acceptDTO) {
|
|
|
- AppInfoAcceptDTO appResourceDTO = acceptDTO.getTAppSystem();
|
|
|
+ AppInfoAcceptDTO appResourceDTO = acceptDTO.getTappSystem();
|
|
|
AppResourceDTO dto = new AppResourceDTO();
|
|
|
dto.setAppCode(appResourceDTO.getYyxtbh());
|
|
|
dto.setAppName(appResourceDTO.getYyxtmc());
|
|
@@ -126,7 +128,7 @@ public class ResourceBusiness implements IResourceBusiness {
|
|
|
dto.setApplyCategory(appResourceDTO.getYyxtfldm());
|
|
|
dto.setPoliceSpecies(appResourceDTO.getGajzfldm());
|
|
|
//设置菜单资源
|
|
|
- List<MenuResourceAcceptDTO> tAppFunctionList = acceptDTO.getTAppFunctionList();
|
|
|
+ List<MenuResourceAcceptDTO> tAppFunctionList = acceptDTO.getTappFunctionList();
|
|
|
List<MenuResourceDTO> menusDTOs = new ArrayList<>();
|
|
|
for (MenuResourceAcceptDTO mADTO : tAppFunctionList) {
|
|
|
MenuResourceDTO menuDTO = new MenuResourceDTO();
|
|
@@ -195,7 +197,7 @@ public class ResourceBusiness implements IResourceBusiness {
|
|
|
//暂时手动输入currentPage
|
|
|
//没有就从第一页开始获获取
|
|
|
if (null == currentPageNo) {
|
|
|
- currentPageNo = 0;
|
|
|
+ currentPageNo = 1;
|
|
|
}
|
|
|
ResourceRequestResultDTO listingInfo = getAllResourceListing(currentPageNo, pageSize, resourceEnum);
|
|
|
pageInfos.add(listingInfo);
|
|
@@ -291,25 +293,27 @@ public class ResourceBusiness implements IResourceBusiness {
|
|
|
|
|
|
@Override
|
|
|
public void run() {
|
|
|
+ logger.info("get menu resource start");
|
|
|
ArrayList<ResourceSyncDTO> list = new ArrayList<>();
|
|
|
try {
|
|
|
for (String appId : appIds) {
|
|
|
String menuStr = getAppMenuFromRemote(appId);
|
|
|
- JSONObject menuJSON = JSON.parseObject(menuStr);
|
|
|
- JSONObject appInfo = menuJSON.getJSONObject("tAppSystem");
|
|
|
+ AppResourceAcceptDTO resourceAcceptDTO = JSON.parseObject(menuStr, AppResourceAcceptDTO.class);
|
|
|
+ AppInfoAcceptDTO appInfo = resourceAcceptDTO.getTappSystem();
|
|
|
ResourceSyncDTO dto = new ResourceSyncDTO();
|
|
|
dto.setResourceId(ResourceTypeEnum.TJ_APP_MENU.getResourceId());
|
|
|
dto.setResourceType(ResourceTypeEnum.TJ_APP_MENU.getResourceType());
|
|
|
dto.setResourceProvider(ResourceTypeEnum.TJ_APP_MENU.getResouProvider());
|
|
|
dto.setSync(BooleanEnum.FALSE.getValue());
|
|
|
dto.setExtId(appId);
|
|
|
- dto.setAppCode(appInfo.getString("yyxtbh"));
|
|
|
- dto.setAppName(appInfo.getString("yyxtmc"));
|
|
|
- dto.setContent(menuJSON.getJSONArray("tAppFunctionList").toJSONString());
|
|
|
+ dto.setAppCode(appInfo.getYyxtbh());
|
|
|
+ dto.setAppName(appInfo.getYyxtmc());
|
|
|
+ dto.setContent(JSON.toJSONString(resourceAcceptDTO.getTappFunctionList()));
|
|
|
list.add(dto);
|
|
|
}
|
|
|
syncService.batchInsertResourceSync(list);
|
|
|
- }catch (Exception e){
|
|
|
+ } catch (Exception e){
|
|
|
+ logger.info("get MenuResource wrong in appIds:{}",JSON.toJSONString(appIds));
|
|
|
logger.error("get MenuResource exception.",e);
|
|
|
}
|
|
|
}
|
|
@@ -319,7 +323,7 @@ public class ResourceBusiness implements IResourceBusiness {
|
|
|
String busServiceId = resourceConfig.getMenuResource().getBusServiceId();
|
|
|
String busServiceFunc = resourceConfig.getMenuResource().getBusServiceFunc();
|
|
|
List<Header> heards = getHeaders(busSraId,busServiceId,busServiceFunc);
|
|
|
- String url = resourceConfig.getResourceUrl() + appId;
|
|
|
+ String url = resourceConfig.getResourceUrl()+ "/" + appId;
|
|
|
CloseableHttpResponse response = HttpUtil.get(url,null,heards);
|
|
|
return EntityUtils.toString(response.getEntity());
|
|
|
}
|
|
@@ -341,7 +345,7 @@ public class ResourceBusiness implements IResourceBusiness {
|
|
|
resultMap.put("pageNo", pageNo);
|
|
|
resultMap.put("pageSize", pageSize);
|
|
|
resultMap.put("resourceId", resouceId);
|
|
|
- return Result.fail("400", "get remote resource error", resultMap);
|
|
|
+ return Result.fail(ResponseStatus.FAIL_CODE, "get remote resource error", resultMap);
|
|
|
}
|
|
|
if (!ResponseStatus.SUCCESS_CODE.equals(resultFromRemote.getCode())) {
|
|
|
logger.info("get remote resource error from pageNo:{},pageSize:{},resourceId:{}", pageNo, pageSize, resouceId);
|
|
@@ -349,14 +353,17 @@ public class ResourceBusiness implements IResourceBusiness {
|
|
|
resultMap.put("pageNo", pageNo);
|
|
|
resultMap.put("pageSize", pageSize);
|
|
|
resultMap.put("resourceId", resouceId);
|
|
|
- return Result.fail("400", "get remote resource failed", resultMap);
|
|
|
+ return Result.fail(ResponseStatus.FAIL_CODE, "get remote resource failed", resultMap);
|
|
|
}
|
|
|
JSONArray records = resultFromRemote.getRecords();
|
|
|
//插入资源数据同步表
|
|
|
- List<ResourceSyncDTO> dtos = insertRemoteResourceSync(resourceEnum, records);
|
|
|
- if(resourceConfig.getMenuResource().isMenuEnabled() && ResourceTypeEnum.TJ_APP.equals(resourceEnum)){
|
|
|
- List<String> ids = dtos.stream().map(item -> item.getExtId()).collect(Collectors.toList());
|
|
|
- if(CollectionUtils.isNotEmpty(ids)){
|
|
|
+ if(CollectionUtils.isNotEmpty(records)){
|
|
|
+ List<ResourceSyncDTO> dtos = insertRemoteResourceSync(resourceEnum, records);
|
|
|
+ if(resourceConfig.getMenuResource().isMenuEnabled() && ResourceTypeEnum.TJ_APP.equals(resourceEnum)){
|
|
|
+ List<String> ids = dtos.stream()
|
|
|
+ .filter(item-> StringUtils.isNotBlank(item.getExtId()))
|
|
|
+ .map(item -> item.getExtId())
|
|
|
+ .collect(Collectors.toList());
|
|
|
getAppMenus(ids);
|
|
|
}
|
|
|
}
|
|
@@ -376,18 +383,24 @@ public class ResourceBusiness implements IResourceBusiness {
|
|
|
* @return
|
|
|
*/
|
|
|
private HttpResult getResourceFromRemote(ResourceTypeEnum resourceTypeEnum, Integer pageNo, Integer pageSize) throws IOException {
|
|
|
- HttpResult httpResult = new HttpResult();
|
|
|
+ HttpResult httpResult;
|
|
|
String url = resourceConfig.getResourceUrl();
|
|
|
//获取应用资源
|
|
|
if(ResourceTypeEnum.TJ_APP.equals(resourceTypeEnum)){
|
|
|
- getAppResource(pageNo, pageSize, httpResult, url);
|
|
|
+ httpResult = getAppResource(pageNo, pageSize, url);
|
|
|
}else if(ResourceTypeEnum.TJ_SERVICE.equals(resourceTypeEnum)){
|
|
|
- getServiceResource(pageNo, httpResult, url);
|
|
|
+ httpResult = getServiceResource(pageNo, pageSize, url);
|
|
|
+ }else {
|
|
|
+ httpResult = new HttpResult();
|
|
|
+ httpResult.setCode(ResponseStatus.SUCCESS_CODE);
|
|
|
+ httpResult.setPages(pageNo);
|
|
|
+ httpResult.setTotals(0);
|
|
|
}
|
|
|
return httpResult;
|
|
|
}
|
|
|
|
|
|
- private void getServiceResource(Integer pageNo, HttpResult httpResult, String url) {
|
|
|
+ private HttpResult getServiceResource(Integer pageNo, Integer pageSize,String url) {
|
|
|
+ HttpResult httpResult = new HttpResult();
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
map.put("page",String.valueOf(pageNo));
|
|
|
String param = JSON.toJSONString(map);
|
|
@@ -408,11 +421,14 @@ public class ResourceBusiness implements IResourceBusiness {
|
|
|
httpResult.setPages(data.getInteger("totalPages"));
|
|
|
httpResult.setTotals(data.getInteger("totalElements"));
|
|
|
}
|
|
|
+ return httpResult;
|
|
|
}
|
|
|
|
|
|
- private void getAppResource(Integer pageNo, Integer pageSize, HttpResult httpResult, String url) {
|
|
|
+ private HttpResult getAppResource(Integer pageNo, Integer pageSize, String url) {
|
|
|
+ HttpResult httpResult = new HttpResult();
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
- map.put("page",pageNo);
|
|
|
+ //应用目录从0页开始查
|
|
|
+ map.put("page",pageNo-1);
|
|
|
map.put("size",pageSize);
|
|
|
String param = JSON.toJSONString(map);
|
|
|
String busSraId = resourceConfig.getAppResource().getBusSraId();
|
|
@@ -429,6 +445,7 @@ public class ResourceBusiness implements IResourceBusiness {
|
|
|
httpResult.setTotals(parse.getInteger("total"));
|
|
|
httpResult.setRecords(parse.getJSONArray("content"));
|
|
|
}
|
|
|
+ return httpResult;
|
|
|
}
|
|
|
|
|
|
private List<Header> getHeaders(String busSraId,String busServiceId,String busServiceFunc) {
|