package cn.flightfeather.supervision.lightshare.service.impl
|
|
import cn.flightfeather.supervision.domain.ds1.entity.City
|
import cn.flightfeather.supervision.domain.ds1.mapper.CityMapper
|
import cn.flightfeather.supervision.lightshare.service.CityService
|
import cn.flightfeather.supervision.lightshare.vo.CityVo
|
import org.springframework.beans.BeanUtils
|
import org.springframework.stereotype.Service
|
|
@Service
|
class CityServiceImpl(val cityMapper: CityMapper) : CityService {
|
|
//根据ID查询
|
override fun findByID(id: String): CityVo {
|
val cityVo = CityVo()
|
//根据ID获取数据,ID是INT
|
val city = cityMapper.selectByPrimaryKey(id.toInt())
|
//转化
|
if (city != null)
|
BeanUtils.copyProperties(city, cityVo)
|
return cityVo
|
}
|
|
//获取全部
|
override fun findAll(): MutableList<CityVo> {
|
val cityVoList = mutableListOf<CityVo>()
|
//查询所有数据
|
val cityList = cityMapper.selectAll()
|
//有数据就循环转化
|
if (cityList.isNotEmpty()) {
|
cityList.forEach {
|
val cityVo = CityVo()
|
BeanUtils.copyProperties(it, cityVo)
|
//add to list
|
cityVoList.add(cityVo)
|
}
|
}
|
return cityVoList
|
}
|
|
override fun save(city: City): Int = cityMapper.insert(city)
|
|
override fun update(city: City): Int = cityMapper.updateByPrimaryKey(city)
|
|
override fun delete(id: String): Int = cityMapper.deleteByPrimaryKey(id.toInt())
|
}
|