|
|
@@ -19,14 +19,16 @@ import kotlin.time.measureTimedValue
|
|
|
|
|
|
val temporaryPrepareCallTransactionCallTo: MutableMap<String, Map<String, Any?>?> = mutableMapOf()
|
|
|
val temporaryPrepareCallTransactionCallFrom: MutableMap<String, String?> = mutableMapOf()
|
|
|
+var temporaryHlrData: MutableMap<String, Map<String, Any?>?> = mutableMapOf()
|
|
|
|
|
|
|
|
|
@Service
|
|
|
class FinalizedDataService(
|
|
|
private val cpDecrypt: CpDecrypt,
|
|
|
private val passwordEncoder: PasswordEncoder,
|
|
|
- private val apiService: ApiService,
|
|
|
- private val insertDataService: InsertDataService
|
|
|
+ val apiService: ApiService,
|
|
|
+ private val insertDataService: InsertDataService,
|
|
|
+ private val migrationSettingService: MigrationSettingService
|
|
|
) {
|
|
|
|
|
|
private val logger = SimpleLogger.getLogger(this::class.java)
|
|
|
@@ -318,22 +320,28 @@ class FinalizedDataService(
|
|
|
if (temporaryDataByCode.any { a -> a.key == keyCode }) {
|
|
|
temporaryDataByCode[keyCode]
|
|
|
} else {
|
|
|
- try {
|
|
|
- val fd =
|
|
|
- if (table == "trunk") " AND (subscribed_no != 'new trunk' OR subscribed_no IS NULL) " else " "
|
|
|
+ var dataUid = try {
|
|
|
+ val fd = if (table == "trunk") " AND (subscribed_no != 'new trunk' OR subscribed_no IS NULL) " else " "
|
|
|
apiService.transaction { em ->
|
|
|
val result = em.createNativeQuery("SELECT $select FROM $tableName WHERE $field = :$field $fd")
|
|
|
.setParameter(field, value.toString())
|
|
|
.resultList
|
|
|
.first() as String?
|
|
|
- temporaryDataByCode[keyCode] = result
|
|
|
result
|
|
|
}
|
|
|
} catch (e: Exception) {
|
|
|
- temporaryDataByCode[keyCode] = null
|
|
|
logger.info("failed find uid $tableName $field $value")
|
|
|
null
|
|
|
}
|
|
|
+ if (tableName == "corcos" && dataUid == null && migrationSettingService.autoCreateCorcos) {
|
|
|
+ dataUid = insertDataService.insertDataWithNativeQuery(tableName, "command", mutableMapOf(
|
|
|
+ "command" to value,
|
|
|
+ "name" to value,
|
|
|
+ "description" to "auto create corcos"
|
|
|
+ ))
|
|
|
+ }
|
|
|
+ temporaryDataByCode[keyCode] = dataUid
|
|
|
+ dataUid
|
|
|
}
|
|
|
// temporaryDataByCode["$tableName;$select;$value"] ?: run {
|
|
|
// try {
|
|
|
@@ -457,8 +465,8 @@ class FinalizedDataService(
|
|
|
?.mapNotNull { findUidByCode("pbx", it) } ?: listOf()
|
|
|
if (pbxId.isBlank() && pbxGroup.isEmpty()) {
|
|
|
finalizer["pbx__default"]?.toString()?.let { pbx ->
|
|
|
- if (pbx.isNotBlank()) {
|
|
|
- phoneUserPbxIds.add(pbx)
|
|
|
+ findUidByCode("pbx", pbx)?.let { pbxDefault ->
|
|
|
+ phoneUserPbxIds.add(pbxDefault)
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
@@ -545,7 +553,7 @@ class FinalizedDataService(
|
|
|
|
|
|
1
|
|
|
} catch (e: Exception) {
|
|
|
- println(Util.mapper.writeValueAsString(map))
|
|
|
+// println(Util.mapper.writeValueAsString(map))
|
|
|
logger.error("failed insert data $table", e)
|
|
|
0
|
|
|
}
|
|
|
@@ -617,7 +625,7 @@ class FinalizedDataService(
|
|
|
val rawData = buildRawData.joinToString(",")
|
|
|
|
|
|
data["rawData"] = rawData
|
|
|
-// getCallTo(buildRawData[12].toString())?.forEach { (t, u) -> data[t] = u }
|
|
|
+ getCallTo(buildRawData[12].toString())?.forEach { (t, u) -> data[t] = u }
|
|
|
//
|
|
|
// data["area_uid"]?.toString()?.let { area ->
|
|
|
// val domainFrom = getCallFrom(area, buildRawData[10]?.toString(), buildRawData[1]?.toString())
|
|
|
@@ -639,31 +647,23 @@ class FinalizedDataService(
|
|
|
return if (temporaryPrepareCallTransactionCallTo.any { a -> a.key == keyCode })
|
|
|
temporaryPrepareCallTransactionCallTo[keyCode]
|
|
|
else {
|
|
|
- try {
|
|
|
- apiService.transaction { em ->
|
|
|
- val hlr = em.createNativeQuery(
|
|
|
- "SELECT TOP 1 prefix, provider_uid, area_uid, phone_type, zone_uid, domain \n" +
|
|
|
- "FROM hlr\n" +
|
|
|
-// "WHERE '$number' LIKE prefix + '%'\n" +
|
|
|
- "WHERE '$number' LIKE prefix + '%'\n" +
|
|
|
- "ORDER BY LEN(prefix) DESC"
|
|
|
- ).singleResult as Array<Any?>
|
|
|
- val result = mapOf(
|
|
|
- "prefix" to hlr[0].toString(),
|
|
|
- "provider_to_uid" to hlr[1].toString(),
|
|
|
- "area_uid" to hlr[2].toString(),
|
|
|
- "phone_type" to hlr[3].toString(),
|
|
|
- "zone_uid" to hlr[4].toString(),
|
|
|
- "domain" to hlr[5].toString()
|
|
|
- )
|
|
|
- temporaryPrepareCallTransactionCallTo[keyCode] = result
|
|
|
- result
|
|
|
- }
|
|
|
- } catch (e: Exception) {
|
|
|
- temporaryPrepareCallTransactionCallTo[keyCode] = null
|
|
|
- logger.info("failed get call to attribute number $number")
|
|
|
- null
|
|
|
+ val matchedPrefix = temporaryHlrData.entries
|
|
|
+ .filter { number.startsWith(it.key) }
|
|
|
+ .maxByOrNull { it.key.length }
|
|
|
+ ?.value
|
|
|
+
|
|
|
+ val result = matchedPrefix?.let {
|
|
|
+ mapOf(
|
|
|
+ "prefix" to it["prefix"]?.toString(),
|
|
|
+ "provider_to_uid" to it["provider.uid"]?.toString(),
|
|
|
+ "area_uid" to it["area.uid"]?.toString(),
|
|
|
+ "phone_type" to it["phoneType"]?.let { i -> (i as PhoneType).ordinal },
|
|
|
+ "zone_uid" to it["zone.uid"]?.toString(),
|
|
|
+ "domain" to it["domain"]?.toString()
|
|
|
+ )
|
|
|
}
|
|
|
+ temporaryPrepareCallTransactionCallTo[keyCode] = result
|
|
|
+ result
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -719,6 +719,12 @@ class FinalizedDataService(
|
|
|
val keyCode = "account;uid;${it["code"] ?: "#"}"
|
|
|
temporaryDataByCode[keyCode] = it["uid"]?.toString()
|
|
|
}
|
|
|
+
|
|
|
+ // hlr-data
|
|
|
+ temporaryHlrData = apiService.findListAll(
|
|
|
+ Hlr::class.java,
|
|
|
+ select = listOf("prefix", "provider.uid", "area.uid", "phoneType", "zone.uid", "domain")
|
|
|
+ ).distinctBy { it["prefix"] }.associateBy { it["prefix"].toString() }.toMutableMap()
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -774,7 +780,7 @@ class InsertDataService(
|
|
|
}
|
|
|
|
|
|
val fieldKey = fieldUnique?.split(";")?.mapNotNull { m -> mapData[m]?.toString() }?.joinToString(";")
|
|
|
- val uidFromDb = temporaryDataEntity["$table;$fieldKey"]?.get("uid")?.toString()
|
|
|
+ val uidFromDb = temporaryDataByCode["$table;uid;$fieldKey"]
|
|
|
val uid = uidFromDb ?: ULID.random()
|
|
|
val isUpdate = uidFromDb != null
|
|
|
|
|
|
@@ -782,13 +788,6 @@ class InsertDataService(
|
|
|
finalMap.remove("uid")
|
|
|
}
|
|
|
|
|
|
-// val structure = finalMap["parent_id"]?.toString()?.let {
|
|
|
-// fields.add("structure")
|
|
|
-// val parentUid = EntityUtility(
|
|
|
-// apiService, General.clazzEntity(className.camelCase())!!
|
|
|
-// ).parentStructure(it)
|
|
|
-// "$parentUid|$uid"
|
|
|
-// }
|
|
|
val structure = finalMap["parent_id"]?.let {
|
|
|
findParentStructure(table, it)?.let { parentUid ->
|
|
|
fields.add("structure")
|
|
|
@@ -796,7 +795,11 @@ class InsertDataService(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- val query = if (table == "calltransaction") "INSERT INTO $table (${fields.joinToString() { it.camelToSnake() }}) " +
|
|
|
+ if (isUpdate) {
|
|
|
+ fields.remove("uid")
|
|
|
+ }
|
|
|
+ val query =
|
|
|
+ if (table == "calltransaction") "INSERT INTO $table (${fields.joinToString() { it.camelToSnake() }}) " +
|
|
|
"VALUES (${fields.joinToString() { ":$it" }})"
|
|
|
else {
|
|
|
fieldUnique?.let { fu ->
|
|
|
@@ -828,7 +831,7 @@ class InsertDataService(
|
|
|
finalMap.forEach { (t, u) -> sqlNative.setParameter(t.replace("_id", "_uid"), u) }
|
|
|
sqlNative.executeUpdate()
|
|
|
|
|
|
-// functionAfter?.invoke(uid, isUpdate)
|
|
|
+ functionAfter?.invoke(uid, isUpdate)
|
|
|
|
|
|
return uid
|
|
|
}
|