feiyu02
2022-07-28 e844ef2fdab88508e7dff4bb9e7b1632fcce15b2
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
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())
}