feiyu02
2024-07-19 4e20a1aaaba1bb843820fca844c20055a33febce
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
package cn.flightfeather.supervision.lightshare.service.impl
 
import cn.flightfeather.supervision.domain.ds1.entity.District
import cn.flightfeather.supervision.domain.ds1.entity.Town
import cn.flightfeather.supervision.domain.ds1.mapper.DistrictMapper
import cn.flightfeather.supervision.domain.ds1.mapper.TownMapper
import cn.flightfeather.supervision.lightshare.service.TownService
import org.springframework.stereotype.Service
import tk.mybatis.mapper.entity.Example
 
@Service
class TownServiceImpl(val townMapper: TownMapper, private val districtMapper: DistrictMapper) : TownService {
    override fun findOne(id: String): Town = townMapper.selectByPrimaryKey(id)
 
    override fun findAll(): MutableList<Town> = townMapper.selectAll()
 
    override fun save(town: Town): Int = townMapper.insert(town)
 
    override fun update(town: Town): Int = townMapper.updateByPrimaryKey(town)
 
    override fun delete(id: String): Int = townMapper.deleteByPrimaryKey(id)
 
    override fun getByDistrict(districtCode: String): List<Town> {
        var result = mutableListOf<Town>()
        districtMapper.selectByExample(Example(District::class.java).apply {
            createCriteria().andEqualTo("districtcode", districtCode)
        })?.takeIf { it.isNotEmpty() }?.get(0)?.let {
            result = townMapper.selectByExample(Example(Town::class.java).apply {
                createCriteria().andEqualTo("districtid", it.districtid)
            })
        }
        return result
    }
}