-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add query by user email implementation
- Loading branch information
1 parent
5cb2434
commit 3e014d1
Showing
3 changed files
with
132 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
pluginManagement { repositories { gradlePluginPortal() } } | ||
|
||
rootProject.name = "pagopa-ecommerce-helpdesk-service" | ||
rootProject.name = "pagopa-ecommerce-helpdesk-service" |
65 changes: 65 additions & 0 deletions
65
src/main/kotlin/it/pagopa/ecommerce/helpdesk/services/PmQueries.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package it.pagopa.ecommerce.helpdesk.services | ||
|
||
fun buildTransactionByUserEmailQuery(userEmail: String) = | ||
""" | ||
SELECT pu.FISCAL_CODE , pu.NOTIFICATION_EMAIL , pu.SURNAME , pu.NAME , pu.USERNAME , pu.STATUS , | ||
pt.CREATION_DATE , pt.STATUS ,pt.ACCOUNTING_STATUS , pt.AMOUNT , pt.FEE , pt.GRAND_TOTAL ,pt.FK_PAYMENT , | ||
pp.ID ,pp.AMOUNT , pp.SUBJECT , pp.ORIGIN , | ||
ppd.IUV , ppd.CCP, ppd.ENTE_BENEFICIARIO , ppd.IMPORTO , ppd.ID_DOMINIO , | ||
pp2.ID_PSP , pp2.BUSINESS_NAME , pp2.ID_CHANNEL | ||
FROM AGID_USER.PP_USER pu | ||
left JOIN AGID_USER.PP_TRANSACTION pt ON pu.ID_USER =pt.FK_USER | ||
left JOIN AGID_USER.PP_PAYMENT pp ON pt.FK_PAYMENT = pp.ID | ||
left JOIN AGID_USER.PP_PAYMENT_DETAIL ppd ON pp.ID =ppd.PAYMENT_ID | ||
left JOIN AGID_USER.PP_PSP pp2 ON pt.FK_PSP = pp2.ID | ||
WHERE pu.NOTIFICATION_EMAIL ='$userEmail' | ||
AND PT.AMOUNT > 1 | ||
ORDER BY PT.CREATION_DATE DESC | ||
""" | ||
.trimIndent() | ||
|
||
fun buildTransactionByUserEmailCountQuery(userEmail: String) = | ||
""" | ||
SELECT COUNT(*) | ||
FROM AGID_USER.PP_USER pu | ||
left JOIN AGID_USER.PP_TRANSACTION pt ON pu.ID_USER =pt.FK_USER | ||
left JOIN AGID_USER.PP_PAYMENT pp ON pt.FK_PAYMENT = pp.ID | ||
left JOIN AGID_USER.PP_PAYMENT_DETAIL ppd ON pp.ID =ppd.PAYMENT_ID | ||
left JOIN AGID_USER.PP_PSP pp2 ON pt.FK_PSP = pp2.ID | ||
WHERE pu.NOTIFICATION_EMAIL ='$userEmail' | ||
AND PT.AMOUNT > 1 | ||
ORDER BY PT.CREATION_DATE DESC | ||
""" | ||
.trimIndent() | ||
|
||
fun buildTransactionByFiscalCodeQuery(fiscalCode: String) = | ||
""" | ||
SELECT pu.FISCAL_CODE , pu.NOTIFICATION_EMAIL , pu.SURNAME , pu.NAME , pu.USERNAME , | ||
pt.CREATION_DATE , pt.STATUS ,pt.ACCOUNTING_STATUS , pt.AMOUNT , pt.FEE , pt.GRAND_TOTAL ,pt.FK_PAYMENT , | ||
pp.ID ,pp.AMOUNT , pp.SUBJECT , pp.ORIGIN , | ||
ppd.IUV , ppd.CCP, ppd.ENTE_BENEFICIARIO , ppd.IMPORTO , ppd.ID_DOMINIO , | ||
pp2.ID_PSP , pp2.BUSINESS_NAME , pp2.ID_CHANNEL | ||
FROM AGID_USER.PP_USER pu | ||
left JOIN AGID_USER.PP_TRANSACTION pt ON pu.ID_USER =pt.FK_USER | ||
left JOIN AGID_USER.PP_PAYMENT pp ON pt.FK_PAYMENT = pp.ID | ||
left JOIN AGID_USER.PP_PAYMENT_DETAIL ppd ON pp.ID =ppd.PAYMENT_ID | ||
left JOIN AGID_USER.PP_PSP pp2 ON pt.FK_PSP = pp2.ID | ||
WHERE pu.FISCAL_CODE ='$fiscalCode' | ||
AND PT.AMOUNT > 1 | ||
AND pu.STATUS IN ('11', '12') | ||
""" | ||
.trimIndent() | ||
|
||
fun buildTransactionByFiscalCodeCountQuery(fiscalCode: String) = | ||
""" | ||
SELECT COUNT(*) | ||
FROM AGID_USER.PP_USER pu | ||
left JOIN AGID_USER.PP_TRANSACTION pt ON pu.ID_USER =pt.FK_USER | ||
left JOIN AGID_USER.PP_PAYMENT pp ON pt.FK_PAYMENT = pp.ID | ||
left JOIN AGID_USER.PP_PAYMENT_DETAIL ppd ON pp.ID =ppd.PAYMENT_ID | ||
left JOIN AGID_USER.PP_PSP pp2 ON pt.FK_PSP = pp2.ID | ||
WHERE pu.FISCAL_CODE ='$fiscalCode' | ||
AND PT.AMOUNT > 1 | ||
AND pu.STATUS IN ('11', '12') | ||
""" | ||
.trimIndent() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,13 @@ package it.pagopa.ecommerce.helpdesk.services | |
import io.r2dbc.spi.ConnectionFactory | ||
import it.pagopa.generated.ecommerce.helpdesk.model.* | ||
import java.time.OffsetDateTime | ||
import java.util.stream.IntStream | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.stereotype.Service | ||
import reactor.core.publisher.Flux | ||
import reactor.core.publisher.Mono | ||
import reactor.kotlin.core.publisher.toMono | ||
|
||
@Service | ||
class PmService(@Autowired val connectionFactory: ConnectionFactory) { | ||
|
@@ -23,23 +25,83 @@ class PmService(@Autowired val connectionFactory: ConnectionFactory) { | |
|
||
return pmSearchTransactionRequestDto | ||
.doOnNext { logger.info("Search type: ${it.type}") } | ||
.flatMapMany { | ||
.flatMap { | ||
Flux.usingWhen( | ||
connectionFactory.create(), | ||
{ connection -> | ||
Flux.from( | ||
connection | ||
.createStatement( | ||
buildTransactionByUserEmailCountQuery( | ||
"[email protected]" | ||
) | ||
) | ||
.execute() | ||
) | ||
.flatMap { result -> | ||
result.map { row -> row[0, Integer::class.java] } | ||
} | ||
.toMono() | ||
.flatMapMany { totalCount -> | ||
logger.info("Total records found: $totalCount") | ||
Flux.from( | ||
connection | ||
.createStatement( | ||
buildTransactionByUserEmailQuery( | ||
"[email protected]" | ||
) | ||
) | ||
.execute() | ||
) | ||
.flatMap { result -> | ||
result.map { row -> | ||
val stringBuilder = StringBuilder() | ||
IntStream.range(0, 22).forEach { | ||
stringBuilder.append( | ||
"Column $it, value ${row[it, String::class.java]}\n" | ||
) | ||
} | ||
stringBuilder | ||
} | ||
} | ||
.doOnNext { logger.info("Row read from DB: $it") } | ||
} | ||
}, | ||
{ it.close() } | ||
) | ||
.toMono() | ||
} | ||
.flatMapMany { totalCount -> | ||
logger.info("Total records found: $totalCount") | ||
Flux.usingWhen( | ||
connectionFactory.create(), | ||
{ connection -> | ||
Flux.from( | ||
connection | ||
.createStatement("SELECT 'Hello, Oracle' FROM sys.dual") | ||
.createStatement( | ||
buildTransactionByUserEmailQuery("[email protected]") | ||
) | ||
.execute() | ||
) | ||
.flatMap { result -> result.map { row -> row[0, String::class.java] } } | ||
.doOnNext { logger.info("Read from DB: $it") } | ||
.flatMap { result -> | ||
result.map { row -> | ||
val stringBuilder = StringBuilder() | ||
IntStream.range(0, 22).forEach { | ||
stringBuilder.append( | ||
"Column $it, value ${row[it, String::class.java]}\n" | ||
) | ||
} | ||
stringBuilder | ||
} | ||
} | ||
.doOnNext { logger.info("Row read from DB: $it") } | ||
}, | ||
{ it.close() } | ||
) | ||
} | ||
.collectList() | ||
.map { | ||
logger.info("all rows $it") | ||
SearchTransactionResponseDto() | ||
.page(PageInfoDto().current(0).results(3).total(1)) | ||
.transactions( | ||
|