|
@@ -154,7 +154,9 @@ class MigrationEntity(val passwordEncoder: PasswordEncoder, val queryNativeServi
|
|
|
|
|
|
|
|
// --- Create Indexes (O(n)) ---
|
|
// --- Create Indexes (O(n)) ---
|
|
|
val historyIndex = historyData?.groupBy { it[uniqueField] }?.mapValues { (_, items) ->
|
|
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() }
|
|
//?.associateBy { it[uniqueField]?.toString() }
|
|
|
val groupIndex = groupData?.associateBy { it[uniqueFieldId ?: 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()
|
|
val tempFindId: MutableMap<String, String?> = mutableMapOf()
|
|
|
|
|
|
|
|
private fun <T : BaseEntity> findId(clazz: Class<T>, value: Any): String? {
|
|
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()
|
|
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
|
|
@Service
|
|
|
@Transactional
|
|
@Transactional
|
|
|
class QueryNativeService(val apiService: ApiService) {
|
|
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 uid = ULID.random()
|
|
|
|
|
+ val cpId = mapData["cpid"]
|
|
|
val fields = mutableListOf("uid")
|
|
val fields = mutableListOf("uid")
|
|
|
- map.keys.forEach {
|
|
|
|
|
|
|
+ val finalMap = mapData.filterNot { it.key == "cpid" }
|
|
|
|
|
+ finalMap.keys.forEach {
|
|
|
val t = it.replace("_id", "_uid")
|
|
val t = it.replace("_id", "_uid")
|
|
|
fields.add(t)
|
|
fields.add(t)
|
|
|
}
|
|
}
|
|
|
- val structure = map["parent_id"]?.toString()?.let {
|
|
|
|
|
|
|
+ val structure = finalMap["parent_id"]?.toString()?.let {
|
|
|
fields.add("structure")
|
|
fields.add("structure")
|
|
|
"${EntityUtility(apiService, Organization::class.java).parentStructure(it)}|$uid"
|
|
"${EntityUtility(apiService, Organization::class.java).parentStructure(it)}|$uid"
|
|
|
}
|
|
}
|
|
@@ -686,7 +695,9 @@ class QueryNativeService(val apiService: ApiService) {
|
|
|
else -> clazz.simpleName.camelToSnake().lowercase()
|
|
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" }})"
|
|
"VALUES (${fields.joinToString() { ":$it" }})"
|
|
|
|
|
|
|
|
val sqlNative = apiService.em.createNativeQuery(query)
|
|
val sqlNative = apiService.em.createNativeQuery(query)
|
|
@@ -696,8 +707,14 @@ class QueryNativeService(val apiService: ApiService) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
structure?.let { sqlNative.setParameter("structure", structure) }
|
|
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()
|
|
sqlNative.executeUpdate()
|
|
|
|
|
+ finalMap["code"]?.let {
|
|
|
|
|
+ tempDataUid["${clazz.simpleName}_$it"] = uid
|
|
|
|
|
+ }
|
|
|
|
|
+ cpId?.let {
|
|
|
|
|
+ tempDataUid["${clazz.simpleName}_$it"] = uid
|
|
|
|
|
+ }
|
|
|
return uid
|
|
return uid
|
|
|
}
|
|
}
|
|
|
|
|
|