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
47
48
49
50
51
52
53
54
55
56
57
package cn.flightfeather.supervision.lightshare.service.Impl
 
import cn.flightfeather.supervision.domain.entity.PracticalOperation
import cn.flightfeather.supervision.domain.entity.PracticalOperationRecord
import cn.flightfeather.supervision.domain.mapper.PracticalOperationRecordMapper
import cn.flightfeather.supervision.domain.repository.PracticalOperationRep
import cn.flightfeather.supervision.domain.repository.UserConfigRep
import cn.flightfeather.supervision.lightshare.service.OperationService
import cn.flightfeather.supervision.lightshare.vo.PracticalOperationVo
import org.springframework.stereotype.Service
 
@Service
class OperationServiceImpl(
    private val userConfigRep: UserConfigRep,
    private val practicalOperationRep: PracticalOperationRep,
) : OperationService {
 
    override fun getOperations(userId: String): List<PracticalOperation?> {
        val res = mutableListOf<PracticalOperation?>()
        // 先查询是否有特定属于该用户的事务
        val r = practicalOperationRep.getOperation(userId)
        res.addAll(r)
        // 如果用户没有特定为其定制的事务,则使用通用的事务
        if (res.isEmpty()) {
            val configIds = mutableListOf<Int>()
            userConfigRep.getUserConfig(userId).forEach { it?.let { configIds.add(it.ucId) } }
            val r1 = practicalOperationRep.getOperation(configIds)
            res.addAll(r1)
        }
        return res
    }
 
    override fun executeOperation(
        userId: String,
        operationId: Int,
        stateId: String,
    ): PracticalOperationRecord? {
        return practicalOperationRep.executeOperation(userId, operationId, stateId)
    }
 
    override fun getOperationRecord(userId: String): List<PracticalOperationVo?> {
        val result = mutableListOf<PracticalOperationVo>()
        val operations = getOperations(userId)
        operations.forEach {
            it?.let {
                val vo = PracticalOperationVo()
                vo.operation = it
                val records = practicalOperationRep.getRecords(userId, it.poId, perPage = 1)
                if (records.isNotEmpty()) {
                    vo.record = records[0]
                }
                result.add(vo)
            }
        }
        return result
    }
}