Bladeren bron

update temporary data

masarif 3 weken geleden
bovenliggende
commit
e3cfc3e2bf

+ 1 - 1
config/general-setting.yml

@@ -182,7 +182,7 @@ redirectUrl:
 - http://localhost:4200/oauth2redirect
 - https://cmpd.telmessenger.com/oauth2redirect
 - https://app.insomnia.rest/oauth/redirect
-dataKey: aY6tKotSoUoMIi7JiTBZq0KhtC4bslM0qvnU1EZgmMJ9rsAaBP8fCV3cugOaHB%2BO0rdqCT8BLvRpW3zZRMyaZN%2BOgLPchzBSS4WXWMJ2e%2BWfVKtx1U0WBWevGkoDU3IK
+dataKey: RMyvjTZXDMBnCr3jymw9oHGUUzIJTHCULv9x%2B6xE4De56nu2OlXjkTWuk5%2B3QLfyE5PJQUBl9SIAuZOGmpIJBTHvNBFOUN%2BtwT0FzDUIKfD%2BdOcU4lJzNzo9mc2cMilw
 
 #database: 
 #  type: sqlserver

+ 1 - 0
config/migration.yml

@@ -9,6 +9,7 @@ organization:
   structure: history.organization_id_structure
   appliedDate: history.app_datetime
   expiredDate: history.exp_datetime
+  cpid: history.organization_id
 costCenter:
   id: history.costcenter_id
   code: costcenter_code

+ 36 - 19
src/main/kotlin/com/datacomsolusindo/migration/MigrationEntity.kt

@@ -154,7 +154,9 @@ class MigrationEntity(val passwordEncoder: PasswordEncoder, val queryNativeServi
 
             // --- Create Indexes (O(n)) ---
             val historyIndex = historyData?.groupBy { it[uniqueField] }?.mapValues { (_, items) ->
-                items.maxByOrNull { it[uniqueFieldId!!.removePrefix("history.")].toString().toInt() }
+                items.maxByOrNull {
+                    it[uniqueFieldId!!.removePrefix("history.")].toString().toInt()
+                }
             }
             //?.associateBy { it[uniqueField]?.toString() }
             val groupIndex = groupData?.associateBy { it[uniqueFieldId ?: uniqueField]?.toString() }
@@ -571,19 +573,21 @@ class MigrationEntity(val passwordEncoder: PasswordEncoder, val queryNativeServi
     val tempFindId: MutableMap<String, String?> = mutableMapOf()
 
     private fun <T : BaseEntity> findId(clazz: Class<T>, value: Any): String? {
-        return tempFindId["$clazz-$value"] ?: run {
-            val id = try {
-                val query = "SELECT uid FROM ${toSnakeCase(clazz.simpleName)} WHERE code = :code "
-                val id = apiService.em.createNativeQuery(query, String::class.java)
-                    .setParameter("code", value)
-                    .singleResult as String
-                id
-            } catch (_: Exception) {
-                null
-            }
-            tempFindId["${clazz.simpleName}-$value"] = id
-            id
-        }
+        val id = tempDataUid["${clazz.simpleName}_${value}"]
+        return id
+//        return tempFindId["$clazz-$value"] ?: run {
+//            val id = try {
+//                val query = "SELECT uid FROM ${toSnakeCase(clazz.simpleName)} WHERE code = :code "
+//                val id = apiService.em.createNativeQuery(query, String::class.java)
+//                    .setParameter("code", value)
+//                    .singleResult as String
+//                id
+//            } catch (_: Exception) {
+//                null
+//            }
+//            tempFindId["${clazz.simpleName}-$value"] = id
+//            id
+//        }
     }
 
     val tempPhonePbxPin: MutableMap<String, Pair<String, String>?> = mutableMapOf()
@@ -660,18 +664,23 @@ class SecurityConfig {
 
 }
 
+val tempDataUid: MutableMap<String, String?> = mutableMapOf()
+val tempFieldColumn: MutableMap<String, String?> = mutableMapOf()
+
 @Service
 @Transactional
 class QueryNativeService(val apiService: ApiService) {
 
-    fun <T> insertDataWithNativeQuery(clazz: Class<T>, map: MutableMap<String, Any?>): String? {
+    fun <T> insertDataWithNativeQuery(clazz: Class<T>, mapData: MutableMap<String, Any?>): String? {
         val uid = ULID.random()
+        val cpId = mapData["cpid"]
         val fields = mutableListOf("uid")
-        map.keys.forEach {
+        val finalMap = mapData.filterNot { it.key == "cpid" }
+        finalMap.keys.forEach {
             val t = it.replace("_id", "_uid")
             fields.add(t)
         }
-        val structure = map["parent_id"]?.toString()?.let {
+        val structure = finalMap["parent_id"]?.toString()?.let {
             fields.add("structure")
             "${EntityUtility(apiService, Organization::class.java).parentStructure(it)}|$uid"
         }
@@ -686,7 +695,9 @@ class QueryNativeService(val apiService: ApiService) {
             else -> clazz.simpleName.camelToSnake().lowercase()
         }
 
-        val query = "INSERT INTO $tableName (${fields.joinToString() { it.camelToSnake() }}) " +
+        val tempField = fields.joinToString() { it.camelToSnake() }
+
+        val query = "INSERT INTO $tableName ($tempField) " +
                 "VALUES (${fields.joinToString() { ":$it" }})"
 
         val sqlNative = apiService.em.createNativeQuery(query)
@@ -696,8 +707,14 @@ class QueryNativeService(val apiService: ApiService) {
         }
 
         structure?.let { sqlNative.setParameter("structure", structure) }
-        map.forEach { (t, u) -> sqlNative.setParameter(t.replace("_id", "_uid"), u) }
+        finalMap.forEach { (t, u) -> sqlNative.setParameter(t.replace("_id", "_uid"), u) }
         sqlNative.executeUpdate()
+        finalMap["code"]?.let {
+            tempDataUid["${clazz.simpleName}_$it"] = uid
+        }
+        cpId?.let {
+            tempDataUid["${clazz.simpleName}_$it"] = uid
+        }
         return uid
     }
 

+ 5 - 0
src/main/resources/application.yml

@@ -3,6 +3,11 @@ spring:
   port: 4444
   application:
     name: migration
+  jpa:
+    properties:
+      hibernate:
+        jdbc:
+          batch_size: 1000
 logging:
   level:
     root: INFO