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
package cn.flightfeather.supervision.lightshare.service.Impl
 
import cn.flightfeather.supervision.domain.entity.HWFile
import cn.flightfeather.supervision.domain.entity.HWRecord
import cn.flightfeather.supervision.domain.mapper.BaseInfoMapper
import cn.flightfeather.supervision.domain.mapper.CompanyMapper
import cn.flightfeather.supervision.domain.mapper.HWFileMapper
import cn.flightfeather.supervision.domain.mapper.HWRecordMapper
import cn.flightfeather.supervision.lightshare.service.HazardousWasteService
import org.springframework.stereotype.Service
import tk.mybatis.mapper.entity.Example
 
@Service
class HazardousWasteServiceImpl(
        val hwFileMapper: HWFileMapper,
        val hwRecordMapper: HWRecordMapper,
        val companyMapper: CompanyMapper,
        val baseInfoMapper: BaseInfoMapper
) : HazardousWasteService {
 
    override fun getFile(userId: String): List<HWFile?> {
        val baseInfo = baseInfoMapper.selectByPrimaryKey(userId)
        val result = hwFileMapper.selectByExample(Example(HWFile::class.java).apply {
            createCriteria().andEqualTo("ciGuid", baseInfo.ciGuid)
            orderBy("hbTime").desc()
        })
        return result
    }
 
    override fun getRecord(userId: String, year: String?): List<HWRecord?> {
        val baseInfo = baseInfoMapper.selectByPrimaryKey(userId)
        val result = mutableListOf<HWRecord>()
        val r = hwRecordMapper.selectByExample(Example(HWRecord::class.java).apply {
            createCriteria().andEqualTo("ciGuid", baseInfo.ciGuid)
                    .apply {
                        year?.let { andEqualTo("hrTime", year) }
                    }
            orderBy("hrTime").desc()
        })
        if (r.isNotEmpty()) {
            val maxYear = r[0]?.hrTime
            r.forEach {
                it?.let {
                    if (it.hrTime == maxYear) {
                        result.add(it)
                    }
                }
            }
        }
        return result
    }
}