Преглед на файлове

提交人:江天明
提交内容:优化

江天明 преди 9 месеца
родител
ревизия
bf8b99c718
променени са 1 файла, в които са добавени 13 реда и са изтрити 1 реда
  1. 13 1
      BusinessStep/src/main/java/com/develop/step/details/CookDetailViewModel.kt

+ 13 - 1
BusinessStep/src/main/java/com/develop/step/details/CookDetailViewModel.kt

@@ -14,6 +14,7 @@ import com.develop.food.base.http.observeStatus
 import com.develop.food.base.repo.CURRENT_USER_ID
 import com.develop.food.base.repo.FoodDataProvider
 import com.develop.food.base.repo.entity.DevAccessory
+import com.develop.food.base.repo.entity.DevRecipeCategory
 import com.develop.food.base.repo.entity.DevRecipePortionSize
 import com.develop.food.base.repo.entity.UserOnLineRecipes
 import com.develop.food.base.utils.DownloadUtil
@@ -193,11 +194,22 @@ class CookDetailViewModel(application: Application) : AndroidViewModel(applicati
                 }
                 return
             }
-            val jsonContent = FileKit.readFileToString(jsonFile)
+            val jsonContent = FileKit.readFileToStringB(jsonFile)
             val contentData = Gson().fromJson(jsonContent, RecipeDataConfig::class.java)
             //contentData.resetAllCodes()
             FoodDataProvider.getDatabase().runInTransaction {
                 FoodDataProvider.getDatabase().recipeDao().apply {
+                    val categorys = queryAllCategory()
+                    val categoryMap = HashMap<String, DevRecipeCategory>()
+                    for (category in categorys) {
+                        categoryMap[category.number + ":" + category.lang] = category
+                    }
+                    for (devRecipeCategory in contentData.devRecipeCategorys) {
+                        if (categoryMap.containsKey(devRecipeCategory.number + ":" + devRecipeCategory.lang)) {
+                            devRecipeCategory.code =
+                                categoryMap[devRecipeCategory.number + ":" + devRecipeCategory.lang]?.code.toString()
+                        }
+                    }
                     insertDevAccessorys(contentData.devAccessorys)
                     insertHotTags(contentData.devHotTags)
                     insertDevPortraits(contentData.devPortraits)