修复企业管理员角色无法红冲的问题;修复操作列按钮高低不齐的问题

This commit is contained in:
BBIT-Kai
2026-05-27 09:29:06 +08:00
parent 9fd80980e7
commit a716c481da
10 changed files with 118 additions and 22 deletions
@@ -6,6 +6,10 @@ import kotlinx.serialization.Serializable
data class RedCreateRequest(
val historyId: String,
/**
* 平台数电账号 ID。企业管理员发起冲红时用于指定开票员。
*/
val digitalAccountId: String? = null,
/**
* 冲红原因
*
@@ -222,12 +222,28 @@ object OpenInvoiceTaskService {
.where { accountScope(user) }
.associateBy { it[PtDigitalAccountTable.id] }
val total = OpenInvoiceTaskTable.selectAll().where { where }.count()
val items = OpenInvoiceTaskTable.selectAll()
val taskRows = OpenInvoiceTaskTable.selectAll()
.where { where }
.orderBy(OpenInvoiceTaskTable.createdAt, SortOrder.DESC)
.limit(pageSize)
.offset(((page - 1).coerceAtLeast(0) * pageSize).toLong())
.map { it.toTaskItem(accountRows[it[OpenInvoiceTaskTable.digitalAccountId]]?.get(PtDigitalAccountTable.account)) }
.toList()
val historyMessages = taskRows
.map { it[OpenInvoiceTaskTable.invoiceReqSerialNo] }
.distinct()
.takeIf { it.isNotEmpty() }
?.let { serialNos ->
HistoryInvoiceBasicTable.selectAll()
.where { HistoryInvoiceBasicTable.invoiceReqSerialNo inList serialNos }
.associate { it[HistoryInvoiceBasicTable.invoiceReqSerialNo] to it[HistoryInvoiceBasicTable.msg] }
}
?: emptyMap()
val items = taskRows.map {
it.toTaskItem(
accountRows[it[OpenInvoiceTaskTable.digitalAccountId]]?.get(PtDigitalAccountTable.account),
historyMessages[it[OpenInvoiceTaskTable.invoiceReqSerialNo]],
)
}
PageResult(items, page, pageSize, total)
}
@@ -302,9 +318,9 @@ object OpenInvoiceTaskService {
val runMode = task[OpenInvoiceTaskTable.runMode]
val invoiceReqSerialNo = task[OpenInvoiceTaskTable.invoiceReqSerialNo]
try {
val code = if (runMode == MODE_SIMULATED) {
val (code, message) = if (runMode == MODE_SIMULATED) {
delay(2000)
simulatedQueryCode(invoiceReqSerialNo, task[OpenInvoiceTaskTable.pollCount])
simulatedQueryCode(invoiceReqSerialNo, task[OpenInvoiceTaskTable.pollCount]) to null
} else {
val res = PTApi.queryInvoiceInfo(
QueryInvoiceRequest(
@@ -320,9 +336,9 @@ object OpenInvoiceTaskService {
task[OpenInvoiceTaskTable.digitalAccountId],
)
}
res.code
res.code to res.msg
}
handleQueryCode(task, code)
handleQueryCode(task, code, message)
} catch (e: PTException) {
retryOrFail(task, e.code, e.message)
} catch (e: Exception) {
@@ -365,23 +381,23 @@ object OpenInvoiceTaskService {
}
}
private suspend fun handleQueryCode(task: ResultRow, code: String) {
private suspend fun handleQueryCode(task: ResultRow, code: String, message: String?) {
when (code) {
"0000" -> finishQueryTask(task, STATUS_SUCCESS, code, null)
"9999" -> finishQueryTask(task, STATUS_FAILED, code, "开票失败")
"9999" -> finishQueryTask(task, STATUS_FAILED, code, message?.takeIf { it.isNotBlank() } ?: "开票失败")
AUTH_REQUIRED_CODE -> {
val message = "需要登录/风险认证"
val authMessage = message?.takeIf { it.isNotBlank() } ?: "需要登录/风险认证"
dbQuery {
OpenInvoiceTaskTable.update({ OpenInvoiceTaskTable.id eq task[OpenInvoiceTaskTable.id] }) {
it[status] = STATUS_WAITING_AUTH
it[ptCode] = code
it[errorMessage] = message
it[errorMessage] = authMessage
it[updatedAt] = OffsetDateTime.now()
it[lockedBy] = null
it[lockedAt] = null
}
}
pauseApiKey(task[OpenInvoiceTaskTable.apiKey], code, message)
pauseApiKey(task[OpenInvoiceTaskTable.apiKey], code, authMessage)
}
"7777", "6666" -> requeueQueryTask(task, code)
else -> requeueQueryTask(task, code)
@@ -693,7 +709,7 @@ object OpenInvoiceTaskService {
runMode = this[OpenInvoiceTaskTable.runMode],
)
private fun ResultRow.toTaskItem(account: String?): OpenInvoiceTaskItem =
private fun ResultRow.toTaskItem(account: String?, historyMessage: String?): OpenInvoiceTaskItem =
OpenInvoiceTaskItem(
id = this[OpenInvoiceTaskTable.id].toString(),
digitalAccountId = this[OpenInvoiceTaskTable.digitalAccountId].toString(),
@@ -706,7 +722,8 @@ object OpenInvoiceTaskService {
batchNo = this[OpenInvoiceTaskTable.batchNo],
status = this[OpenInvoiceTaskTable.status],
ptCode = this[OpenInvoiceTaskTable.ptCode],
errorMessage = this[OpenInvoiceTaskTable.errorMessage],
errorMessage = this[OpenInvoiceTaskTable.errorMessage]
?: historyMessage?.takeIf { this[OpenInvoiceTaskTable.status] == STATUS_FAILED },
attemptCount = this[OpenInvoiceTaskTable.attemptCount],
maxAttemptCount = this[OpenInvoiceTaskTable.maxAttemptCount],
pollCount = this[OpenInvoiceTaskTable.pollCount],
@@ -28,7 +28,7 @@ object PTRedService {
* 红票接口调用 2.10
*/
suspend fun invoiceRed(user: CurrentUser, req: RedCreateRequest): String {
val account = PTConfigService.requireDigitalAccountForAction(user, null)
val account = PTConfigService.requireDigitalAccountForAction(user, req.digitalAccountId)
val invoiceReqSerialNo = PTClient.ptDate()
val historyId = Uuid.parse(req.historyId)
val his = dbQuery {