|
|
@@ -157,13 +157,13 @@ class MigrationEntity(val passwordEncoder: PasswordEncoder, val queryNativeServi
|
|
|
items.maxByOrNull { it[uniqueFieldId!!.removePrefix("history.")].toString().toInt() }
|
|
|
}
|
|
|
//?.associateBy { it[uniqueField]?.toString() }
|
|
|
- val groupIndex = groupData?.associateBy { it[ uniqueFieldId ?: uniqueField]?.toString() }
|
|
|
+ val groupIndex = groupData?.associateBy { it[uniqueFieldId ?: uniqueField]?.toString() }
|
|
|
|
|
|
val fieldRoots = fields.filter { !it.value.contains(".") }
|
|
|
val joinRoots = fields.filter { it.value.contains(".") }
|
|
|
.toList().sortedByDescending { it.second }.toMap()
|
|
|
|
|
|
- rootData.mapIndexed { index, row->
|
|
|
+ rootData.mapIndexed { index, row ->
|
|
|
val data = mutableMapOf<String, Any?>()
|
|
|
|
|
|
// --- Direct Fields ---
|
|
|
@@ -568,42 +568,52 @@ class MigrationEntity(val passwordEncoder: PasswordEncoder, val queryNativeServi
|
|
|
.lowercase()
|
|
|
}
|
|
|
|
|
|
+ val tempFindId: MutableMap<String, String?> = mutableMapOf()
|
|
|
+
|
|
|
private fun <T : BaseEntity> findId(clazz: Class<T>, value: Any): String? {
|
|
|
- return 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
|
|
|
+ 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
|
|
|
- } catch (_: Exception) {
|
|
|
- null
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private fun findPin(phoneUserCode: String): Pair<String, String>? {
|
|
|
- return try {
|
|
|
+ val tempPhonePbxPin: MutableMap<String, Pair<String, String>?> = mutableMapOf()
|
|
|
|
|
|
- val query = """
|
|
|
+ private fun findPin(phoneUserCode: String): Pair<String, String>? {
|
|
|
+ return tempPhonePbxPin[phoneUserCode] ?: run {
|
|
|
+ val map = try {
|
|
|
+ val query = """
|
|
|
SELECT TOP 1 pin, pbx_uid
|
|
|
FROM phoneuserpbx
|
|
|
LEFT JOIN phone_user ph ON ph.uid = phoneuserpbx.phone_user_uid
|
|
|
WHERE ph.code = :code
|
|
|
""".trimIndent()
|
|
|
|
|
|
- val result = apiService.em
|
|
|
- .createNativeQuery(query)
|
|
|
- .setParameter("code", phoneUserCode)
|
|
|
- .singleResult as Array<*>
|
|
|
+ val result = apiService.em
|
|
|
+ .createNativeQuery(query)
|
|
|
+ .setParameter("code", phoneUserCode)
|
|
|
+ .singleResult as Array<*>
|
|
|
|
|
|
- val pin = result[0]?.toString()
|
|
|
- val pbxUid = result[1]?.toString()
|
|
|
+ val pin = result[0]?.toString()
|
|
|
+ val pbxUid = result[1]?.toString()
|
|
|
|
|
|
- if (pin != null && pbxUid != null) {
|
|
|
- Pair(pbxUid, pin)
|
|
|
- } else null
|
|
|
-
|
|
|
- } catch (_: Exception) {
|
|
|
- null
|
|
|
+ if (pin != null && pbxUid != null) {
|
|
|
+ Pair(pbxUid, pin)
|
|
|
+ } else null
|
|
|
+ } catch (_: Exception) {
|
|
|
+ null
|
|
|
+ }
|
|
|
+ tempPhonePbxPin[phoneUserCode] = map
|
|
|
+ map
|
|
|
}
|
|
|
}
|
|
|
|