道路线索应急巡查系统服务后台
feiyu02
2025-09-30 84569abda51ecf6c5549dec4cadee8d043422379
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package com.flightfeather.grid.service.impl
 
import com.flightfeather.grid.config.exception.BizException
import com.flightfeather.grid.constant.ConstantHttp
import com.flightfeather.grid.domain.ds1.entity.Clue
import com.flightfeather.grid.domain.ds1.entity.ClueConclusion
import com.flightfeather.grid.domain.ds1.entity.ClueInternal
import com.flightfeather.grid.domain.ds1.entity.ClueQuestion
import com.flightfeather.grid.domain.ds1.mapper.ClueConclusionMapper
import com.flightfeather.grid.domain.ds1.mapper.ClueInternalMapper
import com.flightfeather.grid.domain.ds1.mapper.ClueMapper
import com.flightfeather.grid.domain.ds1.mapper.ClueQuestionMapper
import com.flightfeather.grid.external.ClueHttpService
import com.flightfeather.grid.repository.ClueRepository
import com.flightfeather.grid.service.ClueService
import com.flightfeather.grid.utils.net.HttpMethod
import com.flightfeather.grid.vo.BaseResponse
import com.flightfeather.grid.vo.DataHead
import com.github.pagehelper.PageHelper
import org.springframework.stereotype.Service
import tk.mybatis.mapper.entity.Example
import java.util.*
 
@Service
class ClueServiceImpl(
    val clueMapper: ClueMapper,
    val clueConclusionMapper: ClueConclusionMapper,
    val clueQuestionMapper: ClueQuestionMapper,
    val clueRepository: ClueRepository,
    val clueHttpService: ClueHttpService,
) : ClueService {
 
    override fun getClue(sTime: String?, eTime: String?, pageNum: Int?, pageSize: Int?): Pair<DataHead, List<Clue?>> {
        val p = PageHelper.startPage<Clue>(pageNum ?: ConstantHttp.DEFAULT_PAGE_NUM,
            pageSize ?: ConstantHttp.DEFAULT_PAGE_SIZE)
        val res = clueMapper.getClue(sTime, eTime)
        return DataHead(p.pageNum, p.pages, p.total) to res
    }
 
    override fun searchClue(clue: Clue): List<Clue?> {
        return clueMapper.select(clue)
    }
 
    override fun fetchRemoteClue(updateTime: String): List<Clue?> {
        val res = clueHttpService.getClue(updateTime)
        val result = res.map {
            clueMapper.getClueById(it.id) ?: it.toEntity()
        }
        clueRepository.insertList(result)
        return result
    }
 
    override fun getClueFile(clueId: String): Pair<String, HttpMethod.MyResponse> {
        val clue = clueMapper.selectByPrimaryKey(clueId)
        val res = clueHttpService.getClueFile(clueId)
        return Pair(clue?.cClueName?.trimIndent() ?: "file", res)
    }
 
    override fun pushClue(clueId: String): Boolean {
        val clue = clueMapper.selectByPrimaryKey(clueId) ?: throw BizException("线索不存在")
        if (clue.cUploaded) throw BizException("线索已推送")
        clueConclusionMapper.selectByExample(Example(ClueConclusion::class.java).apply {
            createCriteria().andEqualTo("cId", clue.cId)
        }).run {
            if (this.isEmpty()) {
                throw BizException("线索结论缺失")
            } else if (this.size > 1) {
                throw BizException("线索拥有${this.size}个结论,数量错误,无法推送")
            } else {
                this[0]?.let { c ->
                    if (!clueHttpService.uploadConclusion(c)) throw BizException("推送结论失败,第三方接口失效!")
                }
            }
        }
        clueQuestionMapper.selectByExample(Example(ClueQuestion::class.java).apply {
            createCriteria().andEqualTo("cId", clue.cId)
        }).run {
            if (this.isEmpty()) {
                throw BizException("线索问题缺失")
            } else {
                this.forEach { q ->
                    q?.let {
                        if (!clueHttpService.uploadQuestion(q))
                            throw BizException("推送问题失败,第三方接口失效!")
                    }
                }
            }
        }
        clue.cUploaded = true
        clue.cUploadTime = Date()
        clueMapper.updateByPrimaryKey(clue)
 
        return true
    }
}