feiyu02
2025-09-18 baf2cc2ce3dfd1235c012a3750132769fcd9ad2f
src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/TownServiceImpl.kt
@@ -1,12 +1,15 @@
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) : TownService {
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()
@@ -16,4 +19,16 @@
    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
    }
}