package cn.flightfeather.supervision.lightshare.service.Impl
|
|
import cn.flightfeather.supervision.common.risk.DataSource
|
import cn.flightfeather.supervision.common.risk.DbMapper
|
import cn.flightfeather.supervision.common.risk.RiskAnalysis
|
import cn.flightfeather.supervision.domain.entity.Evaluation
|
import cn.flightfeather.supervision.domain.entity.RiskEvaluation
|
import cn.flightfeather.supervision.domain.mapper.RiskEvaluationMapper
|
import cn.flightfeather.supervision.domain.mapper.UserinfoMapper
|
import cn.flightfeather.supervision.domain.repository.UserConfigRep
|
import cn.flightfeather.supervision.lightshare.service.RiskService
|
import cn.flightfeather.supervision.lightshare.vo.*
|
import com.github.pagehelper.PageHelper
|
import org.springframework.stereotype.Service
|
import tk.mybatis.mapper.entity.Example
|
import java.util.*
|
import javax.servlet.http.HttpServletResponse
|
|
@Service
|
class RiskServiceImpl(
|
private val userinfoMapper: UserinfoMapper,
|
private val riskEvaluationMapper: RiskEvaluationMapper,
|
private val userConfigRep: UserConfigRep,
|
private val dbMapper: DbMapper,
|
) : RiskService {
|
|
override fun getRiskCount(userId: String, condition: UserSearchCondition): BaseResponse<CountVo> {
|
if (condition.sceneTypes.size != 1) return BaseResponse(false, "只支持单个场景类型的查询")
|
|
val config = userConfigRep.getUserConfigBySubType(userId)
|
val condition2 = UserSearchCondition.fromUserConfig(config, condition)
|
|
// 低风险
|
var level0 = 0
|
// 中风险
|
var level1 = 0
|
// 高风险
|
var level2 = 0
|
condition2.period = condition2.period
|
?: riskEvaluationMapper.getLatestPeriod(condition2)
|
?: return BaseResponse(false, "无记录")
|
|
riskEvaluationMapper.getRiskCount(condition2).forEach {
|
when (it.reRiskLevel?.toInt()) {
|
0 -> level0++
|
1 -> level1++
|
2 -> level2++
|
}
|
}
|
val result = CountVo().apply {
|
tag = condition2.period
|
countList.addAll(listOf(level0, level1, level2))
|
}
|
|
return BaseResponse(true, data = result)
|
}
|
|
override fun searchRiskList(
|
userId: String,
|
condition: UserSearchCondition,
|
page: Int,
|
perPage: Int,
|
): BaseResponse<List<CreditInfoVo>> {
|
if (condition.period == null) return BaseResponse(false, "必须选择周期")
|
if (condition.sceneTypes.size > 2) return BaseResponse(false, "场景类型只支持一种")
|
val config = userConfigRep.getUserConfigBySubType(userId)
|
val condition2 = UserSearchCondition.fromUserConfig(config, condition)
|
val p = PageHelper.startPage<Evaluation>(page, perPage)
|
val result = riskEvaluationMapper.searchRiskList(condition2)
|
return BaseResponse(true, head = DataHead(p.pageNum, p.pages, p.total), data = result)
|
}
|
|
override fun getRiskInfo(userId: String, period: String?): BaseResponse<RiskEvaluation> {
|
PageHelper.startPage<RiskEvaluation>(1, 1)
|
val result = riskEvaluationMapper.selectByExample(Example(RiskEvaluation::class.java).apply {
|
createCriteria().andEqualTo("biGuid", userId)
|
.apply {
|
period?.let {
|
andLessThanOrEqualTo("reStartTime", it)
|
andGreaterThanOrEqualTo("reEndTime", it)
|
}
|
}
|
orderBy("reStartTime").desc()
|
})
|
return if (result.isNotEmpty()) {
|
BaseResponse(true, data = result[0])
|
} else {
|
BaseResponse(false, "无综合风险记录")
|
}
|
}
|
|
override fun downloadRiskInfo(
|
district: String,
|
sceneType: String,
|
year: Int,
|
month: Int,
|
response: HttpServletResponse,
|
) {
|
val dataSource = DataSource(DataSource.Config(district, sceneType, year, month), dbMapper)
|
val riskAnalysis = RiskAnalysis(dataSource, toDatabase = false, toFile = true)
|
|
// val fName = Base64.getEncoder().encodeToString("risk.xlsx".toByteArray())
|
val fName = "${year}-${month} risk.xls"
|
response.apply {
|
setHeader("Content-Disposition", "attachment;filename=$fName")
|
setHeader("fileName", fName)
|
addHeader("Access-Control-Expose-Headers", "fileName")
|
contentType = "application/vnd.ms-excel;charset=UTF-8"
|
setHeader("Pragma", "no-cache")
|
setHeader("Cache-Control", "no-cache")
|
setDateHeader("Expires", 0)
|
}
|
riskAnalysis.executeToStream(response.outputStream)
|
|
return
|
}
|
}
|