package com.flightfeather.grid.service.impl
|
|
import com.flightfeather.grid.domain.ds1.entity.GridInfo
|
import com.flightfeather.grid.domain.ds1.mapper.GridInfoMapper
|
import com.flightfeather.grid.service.GridInfoService
|
import com.flightfeather.grid.vo.BaseResponse
|
import org.springframework.stereotype.Service
|
import tk.mybatis.mapper.entity.Example
|
import java.util.*
|
|
@Service
|
class GridInfoServiceImpl(val gridInfoMapper: GridInfoMapper) : GridInfoService {
|
|
override fun createGrid(gridInfo: GridInfo): BaseResponse<GridInfo?> {
|
gridInfoMapper.selectByExample(Example(GridInfo::class.java).apply {
|
createCriteria().andEqualTo("gsId", gridInfo.gsId)
|
.andEqualTo("giName", gridInfo.giName)
|
}).takeIf { it.isNotEmpty() }?.run { return BaseResponse(false, "网格名称在方案已存在") }
|
|
gridInfo.giUid = UUID.randomUUID().toString()
|
gridInfo.giDelete = false
|
gridInfo.giCreateTime = Date()
|
val res = gridInfoMapper.insert(gridInfo)
|
return if (res == 1) {
|
BaseResponse(true, "网格创建成功", data = gridInfo)
|
} else {
|
BaseResponse(false, "数据库插入失败")
|
}
|
}
|
|
override fun getGridList(schemeId: String): BaseResponse<List<GridInfo?>> {
|
val res = gridInfoMapper.selectByExample(Example(GridInfo::class.java).apply {
|
createCriteria().andEqualTo("gsId", schemeId)
|
.andEqualTo("giDelete", false)
|
orderBy("giCreateTime").desc()
|
})
|
return BaseResponse(true, data = res)
|
}
|
|
override fun updateGrid(gridInfo: GridInfo): BaseResponse<Boolean> {
|
val res = gridInfoMapper.updateByPrimaryKeySelective(gridInfo)
|
return if (res == 1) {
|
BaseResponse(true, "网格更新成功")
|
} else {
|
BaseResponse(false, "数据库更新失败")
|
}
|
}
|
|
override fun deleteGrid(id: String): BaseResponse<Boolean> {
|
val grid = gridInfoMapper.selectByPrimaryKey(id) ?: return BaseResponse(false, "网格不存在")
|
grid.giDelete = true
|
val res = gridInfoMapper.updateByPrimaryKeySelective(grid)
|
return if (res == 1) {
|
BaseResponse(true, "网格删除成功")
|
} else {
|
BaseResponse(false, "数据库更新失败")
|
}
|
}
|
}
|