feiyu02
2024-11-19 752e00503f672ddfe2066afb6c235721a3a912b5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package cn.flightfeather.supervision.domain.repository
 
import cn.flightfeather.supervision.domain.entity.LedgerRecord
import cn.flightfeather.supervision.domain.entity.LedgerSubType
import cn.flightfeather.supervision.domain.entity.Userinfo
import cn.flightfeather.supervision.domain.mapper.LedgerRecordMapper
import cn.flightfeather.supervision.domain.mapper.LedgerSubTypeMapper
import org.springframework.stereotype.Repository
import tk.mybatis.mapper.entity.Example
import java.time.LocalDateTime
import java.time.ZoneId
import java.util.*
 
@Repository
class LedgerRep(
    private val ledgerSubTypeMapper: LedgerSubTypeMapper,
    private val ledgerRecordMapper: LedgerRecordMapper,
) {
    fun selectLedger(ledgerSubTypeId: Int?): LedgerSubType? {
        return ledgerSubTypeMapper.selectByPrimaryKey(ledgerSubTypeId)
    }
 
    fun insertRecord(ledgerRecord: LedgerRecord?) {
        ledgerRecord?.let { ledgerRecordMapper.insert(it) }
    }
 
    fun updateRecord(ledgerRecord: LedgerRecord?) {
        ledgerRecord?.let { ledgerRecordMapper.updateByPrimaryKey(it) }
    }
 
    fun selectRecord(userId: String, ledgerSubTypeId: Int?, time: Date?): LedgerRecord? {
        val updateTime = LocalDateTime.ofInstant(time?.toInstant(), ZoneId.systemDefault())
        return selectRecord(userId, ledgerSubTypeId, updateTime)
    }
 
    fun selectRecord(userId: String, ledgerSubTypeId: Int?, time: LocalDateTime?): LedgerRecord? {
        val year = time?.year
        val month = time?.monthValue
        return ledgerRecordMapper.selectOne(LedgerRecord().apply {
            lsSubtypeid = ledgerSubTypeId
            year?.let { lrYear = it }
            month?.let { lrMonth = it.toByte() }
            lrSubmitid = userId
        })
    }
}