to: fix api
This commit is contained in:
parent
b4c10559d1
commit
545edb747b
|
@ -8,10 +8,10 @@ enum class BillType {
|
||||||
INCOME;
|
INCOME;
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun toType(n: Int): BillType = when (n) {
|
fun of(n: Int): BillType = when (n) {
|
||||||
0 -> CONSUME
|
0 -> CONSUME
|
||||||
1 -> INCOME
|
1 -> INCOME
|
||||||
else -> throw IllegalArgumentException("error type $n")
|
else -> throw IllegalArgumentException("error code $n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,17 @@ package cn.fadinglight.models
|
||||||
enum class LabelType {
|
enum class LabelType {
|
||||||
CLASS,
|
CLASS,
|
||||||
LABEL,
|
LABEL,
|
||||||
INCOME_CLASS,
|
INCOME_CLASS;
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun of(n: Int) = when (n) {
|
||||||
|
0 -> LabelType.CLASS
|
||||||
|
1 -> LabelType.LABEL
|
||||||
|
2 -> LabelType.INCOME_CLASS
|
||||||
|
else -> throw IllegalArgumentException("error code $n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data class Label(
|
data class Label(
|
||||||
|
|
|
@ -4,13 +4,18 @@ import cn.fadinglight.mapers.Bills
|
||||||
import cn.fadinglight.mapers.Labels
|
import cn.fadinglight.mapers.Labels
|
||||||
import cn.fadinglight.models.Bill
|
import cn.fadinglight.models.Bill
|
||||||
import cn.fadinglight.models.BillType
|
import cn.fadinglight.models.BillType
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.awaitAll
|
||||||
|
import kotlinx.coroutines.coroutineScope
|
||||||
import org.jetbrains.exposed.sql.*
|
import org.jetbrains.exposed.sql.*
|
||||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.like
|
import org.jetbrains.exposed.sql.SqlExpressionBuilder.like
|
||||||
|
import org.jetbrains.exposed.sql.transactions.experimental.suspendedTransactionAsync
|
||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
|
|
||||||
|
|
||||||
class BillServiceImpl : BillService {
|
class BillServiceImpl : BillService {
|
||||||
|
private val labelService = LabelServiceImpl()
|
||||||
private fun formatSingletonNumber(n: String) = if (n.length == 1) {
|
private fun formatSingletonNumber(n: String) = if (n.length == 1) {
|
||||||
"0$n"
|
"0$n"
|
||||||
} else {
|
} else {
|
||||||
|
@ -73,7 +78,8 @@ class BillServiceImpl : BillService {
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun addManyBills(bills: List<Bill>): Int = transaction {
|
override suspend fun addManyBills(bills: List<Bill>): Int = transaction {
|
||||||
Bills
|
|
||||||
|
val newBills = Bills
|
||||||
.batchInsert(bills) {
|
.batchInsert(bills) {
|
||||||
this[Bills.type] = it.type.name
|
this[Bills.type] = it.type.name
|
||||||
this[Bills.date] = it.date
|
this[Bills.date] = it.date
|
||||||
|
@ -82,7 +88,23 @@ class BillServiceImpl : BillService {
|
||||||
this[Bills.money] = it.money
|
this[Bills.money] = it.money
|
||||||
this[Bills.options] = it.options
|
this[Bills.options] = it.options
|
||||||
}
|
}
|
||||||
.count()
|
.map(::resultRowToBill)
|
||||||
|
newBills.forEach {
|
||||||
|
val classId = Labels
|
||||||
|
.select(Labels.name eq it.cls)
|
||||||
|
.map { it2 -> it2[Labels.id].value }
|
||||||
|
.single()
|
||||||
|
val labelId = Labels
|
||||||
|
.select(Labels.name eq it.label)
|
||||||
|
.map { it2 -> it2[Labels.id].value }
|
||||||
|
.single()
|
||||||
|
Labels.update({ (Labels.id eq labelId) or (Labels.id eq classId) }) {
|
||||||
|
with(SqlExpressionBuilder) {
|
||||||
|
it[count] = count + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newBills.count()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun updateManyBills(bills: List<Bill>): Int {
|
override suspend fun updateManyBills(bills: List<Bill>): Int {
|
||||||
|
|
|
@ -5,7 +5,6 @@ import cn.fadinglight.mapers.Labels
|
||||||
import cn.fadinglight.models.Label
|
import cn.fadinglight.models.Label
|
||||||
import cn.fadinglight.models.LabelType
|
import cn.fadinglight.models.LabelType
|
||||||
import cn.fadinglight.vo.LabelGroup
|
import cn.fadinglight.vo.LabelGroup
|
||||||
import cn.fadinglight.vo.LabelPost
|
|
||||||
import org.jetbrains.exposed.sql.*
|
import org.jetbrains.exposed.sql.*
|
||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
|
|
||||||
|
@ -34,15 +33,9 @@ class LabelServiceImpl : LabelService {
|
||||||
?: emptyList()
|
?: emptyList()
|
||||||
}
|
}
|
||||||
} ?: emptyList()
|
} ?: emptyList()
|
||||||
val incomeLabels = labelGroups[LabelType.CLASS]
|
val incomeLabels = labelGroups[LabelType.INCOME_CLASS]
|
||||||
?.map {
|
?.map(Label::vo) ?: emptyList()
|
||||||
it.vo().apply {
|
|
||||||
this.labels = labelGroups[LabelType.INCOME_CLASS]
|
|
||||||
?.filter { it2 -> it2.relativeId == it.id }
|
|
||||||
?.map(Label::vo)
|
|
||||||
?: emptyList()
|
|
||||||
}
|
|
||||||
} ?: emptyList()
|
|
||||||
return LabelGroup(income = incomeLabels, consume = consumeLabels)
|
return LabelGroup(income = incomeLabels, consume = consumeLabels)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import java.util.*
|
||||||
@Serializable
|
@Serializable
|
||||||
data class BillVO(
|
data class BillVO(
|
||||||
val id: Int? = null,
|
val id: Int? = null,
|
||||||
val type: BillType,
|
val type: Int,
|
||||||
val date: String,
|
val date: String,
|
||||||
val money: Float,
|
val money: Float,
|
||||||
val cls: String,
|
val cls: String,
|
||||||
|
@ -18,7 +18,7 @@ data class BillVO(
|
||||||
|
|
||||||
fun BillVO.bill() = Bill(
|
fun BillVO.bill() = Bill(
|
||||||
id = id,
|
id = id,
|
||||||
type = type,
|
type = BillType.of(type),
|
||||||
date = date,
|
date = date,
|
||||||
money = money,
|
money = money,
|
||||||
cls = cls,
|
cls = cls,
|
||||||
|
@ -28,7 +28,7 @@ fun BillVO.bill() = Bill(
|
||||||
|
|
||||||
fun Bill.vo() = BillVO(
|
fun Bill.vo() = BillVO(
|
||||||
id = id,
|
id = id,
|
||||||
type = type,
|
type = type.ordinal,
|
||||||
date = date,
|
date = date,
|
||||||
money = money,
|
money = money,
|
||||||
cls = cls,
|
cls = cls,
|
||||||
|
|
|
@ -7,14 +7,14 @@ import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class LabelPost(
|
data class LabelPost(
|
||||||
val type: LabelType,
|
val type: Int,
|
||||||
val name: String,
|
val name: String,
|
||||||
val relativeId: Int?,
|
val relativeId: Int?,
|
||||||
)
|
)
|
||||||
|
|
||||||
fun LabelPost.label() = Label(
|
fun LabelPost.label() = Label(
|
||||||
id = null,
|
id = null,
|
||||||
type = type,
|
type = LabelType.of(type),
|
||||||
name = name,
|
name = name,
|
||||||
count = 0,
|
count = 0,
|
||||||
relativeId = relativeId
|
relativeId = relativeId
|
||||||
|
|
Loading…
Reference in New Issue
Block a user