|
@@ -19,13 +19,8 @@ import com.datacomsolusindo.cpx_shared_code.entity.Trunk
|
|
|
import com.datacomsolusindo.cpx_shared_code.entity.WebUser
|
|
import com.datacomsolusindo.cpx_shared_code.entity.WebUser
|
|
|
import com.datacomsolusindo.cpx_shared_code.service.ApiService
|
|
import com.datacomsolusindo.cpx_shared_code.service.ApiService
|
|
|
import com.datacomsolusindo.cpx_shared_code.service.CpDecrypt
|
|
import com.datacomsolusindo.cpx_shared_code.service.CpDecrypt
|
|
|
-import com.datacomsolusindo.cpx_shared_code.utility.BudgetUserType
|
|
|
|
|
-import com.datacomsolusindo.cpx_shared_code.utility.SimpleLogger
|
|
|
|
|
-import com.datacomsolusindo.cpx_shared_code.utility.ToolAes
|
|
|
|
|
-import com.datacomsolusindo.cpx_shared_code.utility.TransferType
|
|
|
|
|
-import com.datacomsolusindo.cpx_shared_code.utility.collectAllField
|
|
|
|
|
-import com.datacomsolusindo.cpx_shared_code.utility.findId
|
|
|
|
|
-import com.datacomsolusindo.cpx_shared_code.utility.value
|
|
|
|
|
|
|
+import com.datacomsolusindo.cpx_shared_code.utility.*
|
|
|
|
|
+import io.azam.ulidj.ULID
|
|
|
import io.github.semutkecil.simplecriteria.FilterData
|
|
import io.github.semutkecil.simplecriteria.FilterData
|
|
|
import org.springframework.beans.factory.annotation.Autowired
|
|
import org.springframework.beans.factory.annotation.Autowired
|
|
|
import org.springframework.context.annotation.Bean
|
|
import org.springframework.context.annotation.Bean
|
|
@@ -34,6 +29,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
|
|
|
import org.springframework.security.crypto.factory.PasswordEncoderFactories
|
|
import org.springframework.security.crypto.factory.PasswordEncoderFactories
|
|
|
import org.springframework.security.crypto.password.PasswordEncoder
|
|
import org.springframework.security.crypto.password.PasswordEncoder
|
|
|
import org.springframework.stereotype.Service
|
|
import org.springframework.stereotype.Service
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional
|
|
|
import java.io.File
|
|
import java.io.File
|
|
|
import java.nio.charset.StandardCharsets
|
|
import java.nio.charset.StandardCharsets
|
|
|
import java.util.UUID
|
|
import java.util.UUID
|
|
@@ -42,7 +38,7 @@ import kotlin.time.measureTimedValue
|
|
|
|
|
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
|
-class MigrationEntity(val passwordEncoder: PasswordEncoder) {
|
|
|
|
|
|
|
+class MigrationEntity(val passwordEncoder: PasswordEncoder, val queryNativeService: QueryNativeService) {
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
lateinit var apiService: ApiService
|
|
lateinit var apiService: ApiService
|
|
@@ -67,13 +63,33 @@ class MigrationEntity(val passwordEncoder: PasswordEncoder) {
|
|
|
val rootData = readQueryDataToMap(rootFile)
|
|
val rootData = readQueryDataToMap(rootFile)
|
|
|
val mapRootData = rootData.map { map ->
|
|
val mapRootData = rootData.map { map ->
|
|
|
val data: MutableMap<String, Any?> = mutableMapOf()
|
|
val data: MutableMap<String, Any?> = mutableMapOf()
|
|
|
- fields.forEach { (t, u) ->
|
|
|
|
|
- data[t] = when {
|
|
|
|
|
- u.startsWith("history.") -> getValueAnotherFile(fields, historyData, unique, data, t, u, "history")
|
|
|
|
|
- u.startsWith("group.") -> getValueAnotherFile(fields, groupData, unique, data, t, u, "group")
|
|
|
|
|
- else -> map[u]
|
|
|
|
|
|
|
+ val fieldRoots = fields.toList().filterNot { f -> f.second.contains(".") }
|
|
|
|
|
+ val joinRoots = fields.toList().filter { f -> f.second.contains(".") }
|
|
|
|
|
+
|
|
|
|
|
+ fieldRoots.forEach { f ->
|
|
|
|
|
+ data[f.first] = map[f.second]
|
|
|
|
|
+ }
|
|
|
|
|
+ joinRoots.sortedByDescending { it.second }.forEach { f ->
|
|
|
|
|
+ data[f.first] = when {
|
|
|
|
|
+ f.second.startsWith("history.") ->
|
|
|
|
|
+ getValueAnotherFile(fields, historyData, unique, data, f.first, f.second, "history")
|
|
|
|
|
+
|
|
|
|
|
+ f.second.toString().startsWith("group.") ->
|
|
|
|
|
+ getValueAnotherFile(fields, groupData, unique, data, f.first, f.second, "group")
|
|
|
|
|
+
|
|
|
|
|
+ else -> map[f.second]
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+// fields.forEach { (t, u) ->
|
|
|
|
|
+// data[t] = when {
|
|
|
|
|
+// u.startsWith("history.") ->
|
|
|
|
|
+// getValueAnotherFile(fields, historyData, unique, data, t, u, "history")
|
|
|
|
|
+//
|
|
|
|
|
+// u.startsWith("group.") -> getValueAnotherFile(fields, groupData, unique, data, t, u, "group")
|
|
|
|
|
+// else -> map[u]
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
data
|
|
data
|
|
|
}
|
|
}
|
|
|
mapRootData
|
|
mapRootData
|
|
@@ -95,6 +111,7 @@ class MigrationEntity(val passwordEncoder: PasswordEncoder) {
|
|
|
if (it.any { a -> a.key == fields[unique] }) unique else "id"
|
|
if (it.any { a -> a.key == fields[unique] }) unique else "id"
|
|
|
} ?: "id"
|
|
} ?: "id"
|
|
|
val fieldUnique = fields[uniqueField]!!.split(".").last()
|
|
val fieldUnique = fields[uniqueField]!!.split(".").last()
|
|
|
|
|
+
|
|
|
val value = dataFile?.firstOrNull { f ->
|
|
val value = dataFile?.firstOrNull { f ->
|
|
|
f[fieldUnique].toString() == rootData[uniqueField].toString()
|
|
f[fieldUnique].toString() == rootData[uniqueField].toString()
|
|
|
}?.get(valRoot.replace("${key}.", ""))
|
|
}?.get(valRoot.replace("${key}.", ""))
|
|
@@ -102,7 +119,7 @@ class MigrationEntity(val passwordEncoder: PasswordEncoder) {
|
|
|
return if (keyRoot.contains("_")) value?.let { id ->
|
|
return if (keyRoot.contains("_")) value?.let { id ->
|
|
|
dataFile.firstOrNull { f ->
|
|
dataFile.firstOrNull { f ->
|
|
|
f[fields["id"]!!.split(".").last()].toString() == id.toString()
|
|
f[fields["id"]!!.split(".").last()].toString() == id.toString()
|
|
|
- }?.get(fields["code"])
|
|
|
|
|
|
|
+ }?.get(fields["code"]) ?: value
|
|
|
} else value
|
|
} else value
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -188,19 +205,18 @@ class MigrationEntity(val passwordEncoder: PasswordEncoder) {
|
|
|
rootFile: File,
|
|
rootFile: File,
|
|
|
historyFile: File?,
|
|
historyFile: File?,
|
|
|
groupFile: File?
|
|
groupFile: File?
|
|
|
- ) {
|
|
|
|
|
- failed.clear()
|
|
|
|
|
|
|
+ ): List<MutableMap<String, Any?>> {
|
|
|
val data = dataToMap(clazz, fields, "code", rootFile, historyFile, groupFile)
|
|
val data = dataToMap(clazz, fields, "code", rootFile, historyFile, groupFile)
|
|
|
-
|
|
|
|
|
- val process = measureTime { insertData(clazz, data) }
|
|
|
|
|
-
|
|
|
|
|
- logger.info(
|
|
|
|
|
- "finished process migration ${clazz.simpleName} " +
|
|
|
|
|
- "data ${data.size} " +
|
|
|
|
|
- "success ${data.size - failed.size} " +
|
|
|
|
|
- "failed ${failed.size} " +
|
|
|
|
|
- "takes time ${process.inWholeMilliseconds}ms"
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ return data
|
|
|
|
|
+
|
|
|
|
|
+// val process = measureTime { insertData(clazz, data) }
|
|
|
|
|
+// logger.info(
|
|
|
|
|
+// "finished process migration ${clazz.simpleName} " +
|
|
|
|
|
+// "data ${data.size} " +
|
|
|
|
|
+// "success ${data.size - failed.size} " +
|
|
|
|
|
+// "failed ${failed.size} " +
|
|
|
|
|
+// "takes time ${process.inWholeMilliseconds}ms"
|
|
|
|
|
+// )
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fun clazzEntity(migrationTarget: String): Class<out BaseEntity>? {
|
|
fun clazzEntity(migrationTarget: String): Class<out BaseEntity>? {
|
|
@@ -222,7 +238,8 @@ class MigrationEntity(val passwordEncoder: PasswordEncoder) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private fun <T : BaseEntity> insertData(clazz: Class<T>, dataMap: List<MutableMap<String, Any?>>) {
|
|
|
|
|
|
|
+ fun <T : BaseEntity> insertData(clazz: Class<T>, dataMap: List<MutableMap<String, Any?>>): MutableList<Any> {
|
|
|
|
|
+ failed.clear()
|
|
|
val sortingData = if (dataMap.any { it.any { a -> a.key == "structure" } }) {
|
|
val sortingData = if (dataMap.any { it.any { a -> a.key == "structure" } }) {
|
|
|
dataMap.sortedBy { f -> f["structure"].toString().length }
|
|
dataMap.sortedBy { f -> f["structure"].toString().length }
|
|
|
} else dataMap
|
|
} else dataMap
|
|
@@ -235,7 +252,7 @@ class MigrationEntity(val passwordEncoder: PasswordEncoder) {
|
|
|
// phoneUserPbx
|
|
// phoneUserPbx
|
|
|
val phoneUserPbxIds: MutableList<Any> = mutableListOf()
|
|
val phoneUserPbxIds: MutableList<Any> = mutableListOf()
|
|
|
val data = if (clazz.simpleName == "PhoneUser") {
|
|
val data = if (clazz.simpleName == "PhoneUser") {
|
|
|
- finalizer["pbxList"]?.toString()?.let {
|
|
|
|
|
|
|
+ finalizer["pbx.list"]?.toString()?.let {
|
|
|
it.split(";").forEach { fi ->
|
|
it.split(";").forEach { fi ->
|
|
|
findId(Pbx::class.java, fi)?.let { id -> phoneUserPbxIds.add(id) }
|
|
findId(Pbx::class.java, fi)?.let { id -> phoneUserPbxIds.add(id) }
|
|
|
}
|
|
}
|
|
@@ -246,49 +263,70 @@ class MigrationEntity(val passwordEncoder: PasswordEncoder) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
val finalMap = finalizer.filterNot { fi ->
|
|
val finalMap = finalizer.filterNot { fi ->
|
|
|
- listOf("pbxList", "pbx_id", "extension", "pin").any { a -> a == fi.key }
|
|
|
|
|
|
|
+ listOf("pbx.list", "pbx_id", "extension", "pin").any { a -> a == fi.key }
|
|
|
} as MutableMap<String, Any?>
|
|
} as MutableMap<String, Any?>
|
|
|
- apiService.create(clazz, finalMap)
|
|
|
|
|
|
|
+ queryNativeService.insertDataWithNativeQuery(clazz, finalMap)
|
|
|
|
|
+// apiService.create(clazz, finalMap)
|
|
|
} else {
|
|
} else {
|
|
|
- apiService.create(clazz, finalizer)
|
|
|
|
|
|
|
+// apiService.create(clazz, finalizer)
|
|
|
|
|
+ queryNativeService.insertDataWithNativeQuery(clazz, finalizer)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// create budget
|
|
// create budget
|
|
|
if (BudgetUserType.entries.any { a -> a.name.snakeToCamel() == clazz.simpleName.camelCase() }) {
|
|
if (BudgetUserType.entries.any { a -> a.name.snakeToCamel() == clazz.simpleName.camelCase() }) {
|
|
|
- val id = clazz.collectAllField().findId().value(data)
|
|
|
|
|
- val res = apiService.findById(clazz, id!!, listOf("uid"))
|
|
|
|
|
- res?.get("uid")?.toString()?.let { uid ->
|
|
|
|
|
- apiService.create(
|
|
|
|
|
- Budget::class.java,
|
|
|
|
|
- mutableMapOf(
|
|
|
|
|
- "userType" to BudgetUserType.valueOf(
|
|
|
|
|
- clazz.simpleName.camelCase().camelToSnake().uppercase()
|
|
|
|
|
- ),
|
|
|
|
|
- "userUid" to uid,
|
|
|
|
|
- "type" to "FLAT"
|
|
|
|
|
- ),
|
|
|
|
|
|
|
+// val id = clazz.collectAllField().findId().value(data)
|
|
|
|
|
+// val res = apiService.findById(clazz, id!!, listOf("uid"))
|
|
|
|
|
+// res?.get("uid")?.toString()?.let { uid ->
|
|
|
|
|
+// apiService.create(
|
|
|
|
|
+// Budget::class.java,
|
|
|
|
|
+// mutableMapOf(
|
|
|
|
|
+// "userType" to BudgetUserType.valueOf(
|
|
|
|
|
+// clazz.simpleName.camelCase().camelToSnake().uppercase()
|
|
|
|
|
+// ),
|
|
|
|
|
+// "userUid" to data,
|
|
|
|
|
+// "type" to "FLAT"
|
|
|
|
|
+// ),
|
|
|
|
|
+// )
|
|
|
|
|
+
|
|
|
|
|
+ queryNativeService.insertDataWithNativeQuery(
|
|
|
|
|
+ Budget::class.java, mutableMapOf(
|
|
|
|
|
+ "userType" to BudgetUserType.valueOf(
|
|
|
|
|
+ clazz.simpleName.camelCase().camelToSnake().uppercase()
|
|
|
|
|
+ ).ordinal,
|
|
|
|
|
+ "userUid" to data,
|
|
|
|
|
+ "type" to BudgetType.FLAT.ordinal
|
|
|
)
|
|
)
|
|
|
-
|
|
|
|
|
- // create phoneUserPbx
|
|
|
|
|
- if (phoneUserPbxIds.isNotEmpty()) {
|
|
|
|
|
- phoneUserPbxIds.forEach { pbxId ->
|
|
|
|
|
- apiService.create(
|
|
|
|
|
- PhoneUserPbx::class.java, mutableMapOf(
|
|
|
|
|
- "pin" to phoneUserPin,
|
|
|
|
|
- "extension" to phoneUserExtension,
|
|
|
|
|
- "pbx_id" to pbxId,
|
|
|
|
|
- "phoneUser_id" to id,
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ // create phoneUserPbx
|
|
|
|
|
+ if (phoneUserPbxIds.isNotEmpty()) {
|
|
|
|
|
+ phoneUserPbxIds.forEach { pbxId ->
|
|
|
|
|
+ queryNativeService.insertDataWithNativeQuery(
|
|
|
|
|
+ PhoneUserPbx::class.java, mutableMapOf(
|
|
|
|
|
+ "pin" to phoneUserPin,
|
|
|
|
|
+ "extension" to phoneUserExtension,
|
|
|
|
|
+ "pbx_id" to pbxId,
|
|
|
|
|
+ "phoneUser_id" to data,
|
|
|
)
|
|
)
|
|
|
- }
|
|
|
|
|
|
|
+ )
|
|
|
|
|
+// apiService.create(
|
|
|
|
|
+// PhoneUserPbx::class.java, mutableMapOf(
|
|
|
|
|
+// "pin" to phoneUserPin,
|
|
|
|
|
+// "extension" to phoneUserExtension,
|
|
|
|
|
+// "pbx_id" to pbxId,
|
|
|
|
|
+// "phoneUser_id" to id,
|
|
|
|
|
+// )
|
|
|
|
|
+// )
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+// }
|
|
|
}
|
|
}
|
|
|
} catch (e: Exception) {
|
|
} catch (e: Exception) {
|
|
|
failed.add(map)
|
|
failed.add(map)
|
|
|
- logger.error("failed insert data migration", e)
|
|
|
|
|
|
|
+// logger.error("failed insert data migration", e)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ return failed
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private fun finalizeMap(className: String, map: MutableMap<String, Any?>): MutableMap<String, Any?> {
|
|
private fun finalizeMap(className: String, map: MutableMap<String, Any?>): MutableMap<String, Any?> {
|
|
@@ -305,14 +343,25 @@ class MigrationEntity(val passwordEncoder: PasswordEncoder) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
map["direction"]?.toString()?.let {
|
|
map["direction"]?.toString()?.let {
|
|
|
- map["direction"] = it.split("").mapNotNull { m ->
|
|
|
|
|
- when (m.trim()) {
|
|
|
|
|
- "C" -> "INCOMING"
|
|
|
|
|
- "G" -> "OUTGOING"
|
|
|
|
|
- "I" -> "INTERNAL"
|
|
|
|
|
- else -> null
|
|
|
|
|
- }
|
|
|
|
|
- }.joinToString(";")
|
|
|
|
|
|
|
+ map["direction"] = if (className == "transaction") {
|
|
|
|
|
+ it.split("").mapNotNull { m ->
|
|
|
|
|
+ when (m.trim()) {
|
|
|
|
|
+ "C" -> Direction.INCOMING.ordinal //"C"
|
|
|
|
|
+ "G" -> Direction.OUTGOING.ordinal //"G"
|
|
|
|
|
+ "I" -> Direction.INTERNAL.ordinal //"I"
|
|
|
|
|
+ else -> null
|
|
|
|
|
+ }
|
|
|
|
|
+ }.joinToString(";")
|
|
|
|
|
+ } else {
|
|
|
|
|
+ it.split("").mapNotNull { m ->
|
|
|
|
|
+ when (m.trim()) {
|
|
|
|
|
+ "C" -> "C"
|
|
|
|
|
+ "G" -> "G"
|
|
|
|
|
+ "I" -> "I"
|
|
|
|
|
+ else -> null
|
|
|
|
|
+ }
|
|
|
|
|
+ }.joinToString(";")
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
map.filterNot { it.key == "id" || it.key == "structure" }.forEach { (t, u) ->
|
|
map.filterNot { it.key == "id" || it.key == "structure" }.forEach { (t, u) ->
|
|
@@ -347,10 +396,10 @@ class MigrationEntity(val passwordEncoder: PasswordEncoder) {
|
|
|
val to = mapFinalize["extTransferTo"]?.toString() ?: ""
|
|
val to = mapFinalize["extTransferTo"]?.toString() ?: ""
|
|
|
val from = mapFinalize["extTransferFrom"]?.toString() ?: ""
|
|
val from = mapFinalize["extTransferFrom"]?.toString() ?: ""
|
|
|
mapFinalize["transferType"] = when {
|
|
mapFinalize["transferType"] = when {
|
|
|
- to.isBlank() && from.isBlank() -> TransferType.DIRECT
|
|
|
|
|
- to.isNotBlank() && from.isBlank() -> TransferType.TRANSFER_TO
|
|
|
|
|
- to.isBlank() && from.isNotBlank() -> TransferType.TRANSFER_FROM
|
|
|
|
|
- else -> TransferType.TRANSFER_FROM_AND_TRANSFER_TO
|
|
|
|
|
|
|
+ to.isBlank() && from.isBlank() -> TransferType.DIRECT.ordinal
|
|
|
|
|
+ to.isNotBlank() && from.isBlank() -> TransferType.TRANSFER_TO.ordinal
|
|
|
|
|
+ to.isBlank() && from.isNotBlank() -> TransferType.TRANSFER_FROM.ordinal
|
|
|
|
|
+ else -> TransferType.TRANSFER_FROM_AND_TRANSFER_TO.ordinal
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -368,9 +417,9 @@ class MigrationEntity(val passwordEncoder: PasswordEncoder) {
|
|
|
private val defaultProfile: Any? by lazy {
|
|
private val defaultProfile: Any? by lazy {
|
|
|
apiService.findListPage(
|
|
apiService.findListPage(
|
|
|
Rights::class.java,
|
|
Rights::class.java,
|
|
|
- listOf("id"),
|
|
|
|
|
|
|
+ listOf("uid"),
|
|
|
FilterData.filter("name", FilterData.FILTEROP.EQ, "Default")
|
|
FilterData.filter("name", FilterData.FILTEROP.EQ, "Default")
|
|
|
- ).firstOrNull()?.get("id")
|
|
|
|
|
|
|
+ ).firstOrNull()?.get("uid")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private fun toSnakeCase(input: String): String {
|
|
private fun toSnakeCase(input: String): String {
|
|
@@ -381,7 +430,7 @@ class MigrationEntity(val passwordEncoder: PasswordEncoder) {
|
|
|
|
|
|
|
|
private fun <T : BaseEntity> findId(clazz: Class<T>, value: Any): String? {
|
|
private fun <T : BaseEntity> findId(clazz: Class<T>, value: Any): String? {
|
|
|
return try {
|
|
return try {
|
|
|
- val query = "SELECT id FROM ${toSnakeCase(clazz.simpleName)} WHERE code = :code "
|
|
|
|
|
|
|
+ val query = "SELECT uid FROM ${toSnakeCase(clazz.simpleName)} WHERE code = :code "
|
|
|
val id = apiService.em.createNativeQuery(query, String::class.java)
|
|
val id = apiService.em.createNativeQuery(query, String::class.java)
|
|
|
.setParameter("code", value)
|
|
.setParameter("code", value)
|
|
|
.singleResult as String
|
|
.singleResult as String
|
|
@@ -432,4 +481,47 @@ class SecurityConfig {
|
|
|
@Bean
|
|
@Bean
|
|
|
fun passwordEncoder(): PasswordEncoder = PasswordEncoderFactories.createDelegatingPasswordEncoder()
|
|
fun passwordEncoder(): PasswordEncoder = PasswordEncoderFactories.createDelegatingPasswordEncoder()
|
|
|
|
|
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+@Service
|
|
|
|
|
+@Transactional
|
|
|
|
|
+class QueryNativeService(val apiService: ApiService) {
|
|
|
|
|
+
|
|
|
|
|
+ fun <T> insertDataWithNativeQuery(clazz: Class<T>, map: MutableMap<String, Any?>): String? {
|
|
|
|
|
+ val uid = ULID.random()
|
|
|
|
|
+ val fields = mutableListOf("uid")
|
|
|
|
|
+ map.keys.forEach {
|
|
|
|
|
+ val t = it.replace("_id", "_uid")
|
|
|
|
|
+ fields.add(t)
|
|
|
|
|
+ }
|
|
|
|
|
+ val structure = map["parent_id"]?.toString()?.let {
|
|
|
|
|
+ fields.add("structure")
|
|
|
|
|
+ "${EntityUtility(apiService, Organization::class.java).parentStructure(it)}|$uid"
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ val tableName = when (clazz.simpleName.lowercase()) {
|
|
|
|
|
+ "phoneuserpbx" -> "phoneuserpbx"
|
|
|
|
|
+ "transaction" -> {
|
|
|
|
|
+ fields.remove("uid")
|
|
|
|
|
+ "calltransaction"
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ else -> clazz.simpleName.camelToSnake().lowercase()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ val query = "INSERT INTO $tableName (${fields.joinToString() { it.camelToSnake() }}) " +
|
|
|
|
|
+ "VALUES (${fields.joinToString() { ":$it" }})"
|
|
|
|
|
+
|
|
|
|
|
+ val sqlNative = apiService.em.createNativeQuery(query)
|
|
|
|
|
+
|
|
|
|
|
+ if (clazz.simpleName.lowercase() != "transaction") {
|
|
|
|
|
+ sqlNative.setParameter("uid", uid)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ structure?.let { sqlNative.setParameter("structure", structure) }
|
|
|
|
|
+ map.forEach { (t, u) -> sqlNative.setParameter(t.replace("_id", "_uid"), u) }
|
|
|
|
|
+ sqlNative.executeUpdate()
|
|
|
|
|
+ return uid
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|