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
|
}
|
}
|