@@ -600,15 +600,7 @@ private AppBuilderAppDto createAppWithTemplate(AppBuilderAppCreateDto dto, AppBu
600600 AppBuilderFlowGraph flowGraph = templateApp .getFlowGraph ();
601601 flowGraph .setId (Entities .generateId ());
602602 Map <String , Object > appearance ;
603- try {
604- appearance = JSONObject .parseObject (flowGraph .getAppearance (), new TypeReference <Map <String , Object >>() {});
605- } catch (JSONException e ) {
606- log .error ("Import config failed, cause: {}" , e );
607- throw new AippException (AippErrCode .IMPORT_CONFIG_FIELD_ERROR , "flowGraph.appearance" );
608- }
609- appearance .computeIfPresent ("id" , (key , value ) -> flowGraph .getId ());
610- // 这里在创建应用时需要保证graph中的title+version唯一,否则在发布flow时会报错
611- appearance .put ("title" , flowGraph .getId ());
603+ appearance = this .resetGraphId (flowGraph );
612604 // 动态修改graph中的model为可选model的第一个
613605 flowGraph .setAppearance (JSONObject .toJSONString (appearance ));
614606 String version = this .buildVersion (templateApp , isUpgrade );
@@ -1282,24 +1274,25 @@ public void deleteTemplate(String templateId, OperationContext context) {
12821274 }
12831275
12841276 @ Override
1285- public List < PublishedAppResDto > recentPublished (AppQueryCondition cond , long offset , int limit , String appId ,
1286- OperationContext context ) {
1277+ public RangedResultSet < AppBuilderAppDto > recentPublished (AppQueryCondition cond , long offset , int limit ,
1278+ String appId , OperationContext context ) {
12871279 this .validateApp (appId );
12881280 try {
12891281 String aippId = MetaUtils .getAippIdByAppId (this .metaService , appId , context );
1290- List <Meta > allPublishedMeta = MetaUtils .getAllPublishedMeta (this .metaService , aippId , context )
1291- .stream ()
1292- .filter (meta -> !this .isAppBelong (appId , meta ))
1293- .collect (Collectors .toList ());
1282+ RangedResultSet <Meta > metaRangedResultSet =
1283+ MetaUtils .getPublishedMetaByPage (this .metaService , aippId , offset , limit , context );
1284+ List <Meta > allPublishedMeta = metaRangedResultSet .getResults ();
12941285 List <String > appIds = allPublishedMeta .stream ()
12951286 .map (meta -> String .valueOf (meta .getAttributes ().get (AippConst .ATTR_APP_ID_KEY )))
12961287 .collect (Collectors .toList ());
12971288 cond .setIds (appIds );
12981289 cond .setTenantId (context .getTenantId ());
12991290 List <AppBuilderApp > allPublishedApp = this .appRepository .selectWithCondition (cond );
1300- Map <String , AppBuilderApp > appIdKeyAppValueMap =
1301- allPublishedApp .stream ().collect (Collectors .toMap (AppBuilderApp ::getId , Function .identity ()));
1302- return this .buildPublishedAppResDtos (allPublishedMeta , appIdKeyAppValueMap );
1291+ Map <String , AppBuilderApp > appIdKeyAppValueMap = allPublishedApp .stream ()
1292+ .map (app -> appFactory .create (app .getId ()))
1293+ .collect (Collectors .toMap (AppBuilderApp ::getId , Function .identity ()));
1294+ return RangedResultSet .create (this .buildPublishedAppResDtos (allPublishedMeta , appIdKeyAppValueMap ),
1295+ metaRangedResultSet .getRange ());
13031296 } catch (AippTaskNotFoundException exception ) {
13041297 throw new AippException (QUERY_PUBLICATION_HISTORY_FAILED );
13051298 }
@@ -1315,30 +1308,57 @@ public List<CheckResult> checkAvailable(List<AppCheckDto> appCheckDtos, Operatio
13151308 return results .stream ().filter (result -> !result .isValid ()).collect (Collectors .toList ());
13161309 }
13171310
1311+ @ Override
1312+ @ Transactional
1313+ public AppBuilderAppDto recoverApp (String appId , String resetId , OperationContext context ) {
1314+ AppBuilderApp resetApp = this .appFactory .create (resetId );
1315+ AppBuilderApp currentApp = this .appFactory .create (appId );
1316+ List <AppBuilderFormProperty > resetFormProperties = resetApp .getFormProperties ();
1317+ List <AppBuilderFormProperty > currentFormProperties = currentApp .getFormProperties ();
1318+ Map <String , AppBuilderFormProperty > currentPropMap = currentFormProperties .stream ()
1319+ .collect (Collectors .toMap (AppBuilderFormProperty ::getName , Function .identity ()));
1320+ resetFormProperties .forEach (resetProp -> {
1321+ AppBuilderFormProperty currentProp = currentPropMap .get (resetProp .getName ());
1322+ if (currentProp != null ) {
1323+ currentProp .setDefaultValue (resetProp .getDefaultValue ());
1324+ }
1325+ });
1326+ currentApp .getFormPropertyRepository ().updateMany (currentFormProperties );
1327+
1328+ AppBuilderFlowGraph resetGraph = resetApp .getFlowGraph ();
1329+ AppBuilderFlowGraph currentGraph = currentApp .getFlowGraph ();
1330+ String currentGraphId = currentApp .getFlowGraphId ();
1331+ resetGraph .setId (currentGraphId );
1332+
1333+ Map <String , Object > appearance ;
1334+ appearance = this .resetGraphId (resetGraph );
1335+ currentGraph .setAppearance (JSONObject .toJSONString (appearance ));
1336+ currentApp .getFlowGraphRepository ().updateOne (currentGraph );
1337+
1338+ this .appFactory .update (currentApp );
1339+ return this .buildFullAppDto (currentApp );
1340+ }
1341+
13181342 private boolean isAppBelong (String appId , Meta meta ) {
13191343 return Objects .equals (String .valueOf (meta .getAttributes ().get (AippConst .ATTR_APP_ID_KEY )), appId );
13201344 }
13211345
1322- private List <PublishedAppResDto > buildPublishedAppResDtos (List <Meta > metas ,
1346+ private List <AppBuilderAppDto > buildPublishedAppResDtos (List <Meta > metas ,
13231347 Map <String , AppBuilderApp > appIdKeyAppValueMap ) {
13241348 return metas .stream ()
13251349 .map (meta -> this .buildPublishedAppResDto (meta , appIdKeyAppValueMap ))
13261350 .collect (Collectors .toList ());
13271351 }
13281352
1329- private PublishedAppResDto buildPublishedAppResDto (Meta meta , Map <String , AppBuilderApp > appIdKeyAppValueMap ) {
1353+ private AppBuilderAppDto buildPublishedAppResDto (Meta meta , Map <String , AppBuilderApp > appIdKeyAppValueMap ) {
13301354 String appId = String .valueOf (meta .getAttributes ().get (AippConst .ATTR_APP_ID_KEY ));
13311355 String publishedDescription = String .valueOf (meta .getAttributes ().get (AippConst .ATTR_PUBLISH_DESCRIPTION ));
13321356 String publishedUpdateLog = String .valueOf (meta .getAttributes ().get (AippConst .ATTR_PUBLISH_UPDATE_LOG ));
13331357 AppBuilderApp app = appIdKeyAppValueMap .get (appId );
1334- return PublishedAppResDto .builder ()
1335- .appId (appId )
1336- .appVersion (app .getVersion ())
1337- .publishedAt (meta .getCreationTime ())
1338- .publishedBy (meta .getCreator ())
1339- .publishedDescription (publishedDescription )
1340- .publishedUpdateLog (publishedUpdateLog )
1341- .build ();
1358+ AppBuilderAppDto dto = this .buildFullAppDto (app );
1359+ dto .setPublishedDescription (publishedDescription );
1360+ dto .setPublishedUpdateLog (publishedUpdateLog );
1361+ return dto ;
13421362 }
13431363
13441364 private static AppBuilderConfig resetConfig (List <AppBuilderFormProperty > formProperties , AppBuilderConfig config ) {
@@ -2036,4 +2056,18 @@ private String getAttribute(Map<String, Object> attributes, String name) {
20362056 Object value = attributes .get (name );
20372057 return value == null ? StringUtils .EMPTY : String .valueOf (value );
20382058 }
2059+
2060+ private Map <String , Object > resetGraphId (AppBuilderFlowGraph flowGraph ) {
2061+ Map <String , Object > appearance ;
2062+ try {
2063+ appearance = JSONObject .parseObject (flowGraph .getAppearance (), new TypeReference <Map <String , Object >>() {});
2064+ } catch (JSONException e ) {
2065+ log .error ("Import config failed, cause: {}" , e );
2066+ throw new AippException (AippErrCode .IMPORT_CONFIG_FIELD_ERROR , "flowGraph.appearance" );
2067+ }
2068+ appearance .computeIfPresent ("id" , (key , value ) -> flowGraph .getId ());
2069+ // 这里在创建应用时需要保证graph中的title+version唯一,否则在发布flow时会报错
2070+ appearance .put ("title" , flowGraph .getId ());
2071+ return appearance ;
2072+ }
20392073}
0 commit comments