道路线索应急巡查系统服务后台
feiyu02
2025-04-22 41548e262362faf603a71e066e01bd4ef46619d2
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
47
48
49
50
51
52
53
54
55
56
57
58
59
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, "数据库更新失败")
        }
    }
}