@@ -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,58 @@ 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 resetApp (String appId , String resetId , OperationContext context ) {
1314+ AppBuilderApp resetApp = this .appFactory .create (resetId );
1315+ AppBuilderApp currentApp = this .appFactory .create (appId );
1316+ // 更新graph和form property,需更新form property的app id以及graph的id、title
1317+ List <AppBuilderFormProperty > resetFormProperties = resetApp .getFormProperties ();
1318+ List <AppBuilderFormProperty > currentFormProperties = currentApp .getFormProperties ();
1319+ Map <String , AppBuilderFormProperty > currentPropMap = currentFormProperties .stream ()
1320+ .collect (Collectors .toMap (AppBuilderFormProperty ::getName , Function .identity ()));
1321+ resetFormProperties .forEach (resetProp -> {
1322+ AppBuilderFormProperty currentProp = currentPropMap .get (resetProp .getName ());
1323+ if (currentProp != null ) {
1324+ currentProp .setDefaultValue (resetProp .getDefaultValue ());
1325+ }
1326+ });
1327+ currentApp .getFormPropertyRepository ().updateMany (currentFormProperties );
1328+
1329+ AppBuilderFlowGraph resetGraph = resetApp .getFlowGraph ();
1330+ AppBuilderFlowGraph currentGraph = currentApp .getFlowGraph ();
1331+ String currentGraphId = currentApp .getFlowGraphId ();
1332+ resetGraph .setId (currentGraphId );
1333+
1334+ Map <String , Object > appearance ;
1335+ appearance = this .resetGraphId (resetGraph );
1336+ currentGraph .setAppearance (JSONObject .toJSONString (appearance ));
1337+ currentApp .getFlowGraphRepository ().updateOne (currentGraph );
1338+
1339+ this .appFactory .update (currentApp );
1340+ return this .buildFullAppDto (currentApp );
1341+ }
1342+
13181343 private boolean isAppBelong (String appId , Meta meta ) {
13191344 return Objects .equals (String .valueOf (meta .getAttributes ().get (AippConst .ATTR_APP_ID_KEY )), appId );
13201345 }
13211346
1322- private List <PublishedAppResDto > buildPublishedAppResDtos (List <Meta > metas ,
1347+ private List <AppBuilderAppDto > buildPublishedAppResDtos (List <Meta > metas ,
13231348 Map <String , AppBuilderApp > appIdKeyAppValueMap ) {
13241349 return metas .stream ()
13251350 .map (meta -> this .buildPublishedAppResDto (meta , appIdKeyAppValueMap ))
13261351 .collect (Collectors .toList ());
13271352 }
13281353
1329- private PublishedAppResDto buildPublishedAppResDto (Meta meta , Map <String , AppBuilderApp > appIdKeyAppValueMap ) {
1354+ private AppBuilderAppDto buildPublishedAppResDto (Meta meta , Map <String , AppBuilderApp > appIdKeyAppValueMap ) {
13301355 String appId = String .valueOf (meta .getAttributes ().get (AippConst .ATTR_APP_ID_KEY ));
13311356 String publishedDescription = String .valueOf (meta .getAttributes ().get (AippConst .ATTR_PUBLISH_DESCRIPTION ));
13321357 String publishedUpdateLog = String .valueOf (meta .getAttributes ().get (AippConst .ATTR_PUBLISH_UPDATE_LOG ));
13331358 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 ();
1359+ AppBuilderAppDto dto = this .buildFullAppDto (app );
1360+ dto .setPublishedDescription (publishedDescription );
1361+ dto .setPublishedUpdateLog (publishedUpdateLog );
1362+ return dto ;
13421363 }
13431364
13441365 private static AppBuilderConfig resetConfig (List <AppBuilderFormProperty > formProperties , AppBuilderConfig config ) {
@@ -2036,4 +2057,18 @@ private String getAttribute(Map<String, Object> attributes, String name) {
20362057 Object value = attributes .get (name );
20372058 return value == null ? StringUtils .EMPTY : String .valueOf (value );
20382059 }
2060+
2061+ private Map <String , Object > resetGraphId (AppBuilderFlowGraph flowGraph ) {
2062+ Map <String , Object > appearance ;
2063+ try {
2064+ appearance = JSONObject .parseObject (flowGraph .getAppearance (), new TypeReference <Map <String , Object >>() {});
2065+ } catch (JSONException e ) {
2066+ log .error ("Import config failed, cause: {}" , e );
2067+ throw new AippException (AippErrCode .IMPORT_CONFIG_FIELD_ERROR , "flowGraph.appearance" );
2068+ }
2069+ appearance .computeIfPresent ("id" , (key , value ) -> flowGraph .getId ());
2070+ // 这里在创建应用时需要保证graph中的title+version唯一,否则在发布flow时会报错
2071+ appearance .put ("title" , flowGraph .getId ());
2072+ return appearance ;
2073+ }
20392074}
0 commit comments