package cn.flightfeather.supervision.common.risk
|
|
import cn.flightfeather.supervision.domain.entity.Userinfo
|
import cn.flightfeather.supervision.domain.enumeration.SceneType
|
import cn.flightfeather.supervision.lightshare.vo.LedgerSubTypeVo
|
import java.time.LocalDate
|
import java.time.format.DateTimeFormatter
|
|
/**
|
* 获取台账完成率
|
*/
|
open class RiskLedger {
|
|
open val summary = listOf(
|
"必填台账存在部分缺失项,\n",
|
"必填台账存在较多缺失项,\n",
|
"必填台账缺失严重,\n",
|
"必填台账全类别缺失,\n"
|
)
|
|
inner class Result() {
|
// 所有台账提交率
|
var rate1: Double = .0
|
// 必填台账提交率
|
var rate2: Double = .0
|
// 必填项中不涉及台账占比
|
var rate3: Double = .0
|
// 缺失台账
|
var unSubmitLedger = ""
|
// 不涉及台账
|
var notInvolvedLedger = ""
|
// 特殊情况判断结果
|
var specialResult = false
|
}
|
|
private val result = Result()
|
|
protected var config: DataSource.Config? = null
|
|
private fun reset(){
|
result.apply {
|
rate1 = .0
|
rate2 = .0
|
unSubmitLedger = ""
|
}
|
}
|
|
fun getResult(user: Userinfo, config: DataSource.Config, dbMapper: DbMapper): Result {
|
this.config = config
|
reset()
|
return getLedger(user, config, dbMapper)
|
}
|
|
/**
|
* 根据上传率,返回总结
|
*/
|
fun getSummary(): String {
|
return result.run {
|
when {
|
rate2 >= 1.0 -> ""
|
rate2 >= .8 -> summary[0]
|
rate2 >= .6 && rate2 < .8 -> summary[1]
|
rate2 > 0 && rate2 < .6 -> summary[2]
|
else -> summary[3]
|
}
|
}
|
}
|
|
/**
|
* 获取台账记录
|
*/
|
private fun getLedger(user: Userinfo, config: DataSource.Config, dbMapper: DbMapper): Result {
|
user.guid ?: return result
|
val time = LocalDate.of(config.year, config.month, 1).format(DateTimeFormatter.ofPattern("YYYY-MM-dd"))
|
val records = dbMapper.ledgerService.getUserLedgerSummary(user.guid!!, config.sceneType.toInt(), time)
|
return completionRate(records)
|
}
|
|
open fun isFit(ledgerSubTypeVo: LedgerSubTypeVo): Boolean {
|
return ledgerSubTypeVo.ledgerTypeId != -1
|
}
|
|
open fun specialCondition(records: List<LedgerSubTypeVo>): Boolean {
|
return when (this.config?.sceneType) {
|
// “危险废物转移联单、废机油产生量、废铅酸蓄电池产生量、危险废物贮存场所”有3类及以上不正常提交或为不涉及的;
|
SceneType.VehicleRepair.value.toString()->{
|
val ledgerTypeIds = listOf(2904, 2905, 2906, 2907)
|
val count = records.filter {
|
return@filter ledgerTypeIds.contains(it.ledgerSubTypeId) && (!it.ledgerFinished || !it.involved)
|
}.size
|
count >= 3
|
}
|
else -> false
|
}
|
}
|
|
/**
|
* 计算统计结果
|
*/
|
private fun completionRate(records: List<LedgerSubTypeVo>): Result {
|
// 所有台账计数
|
var total1 = 0
|
var finished1 = 0
|
// 必填台账计数
|
var total2 = 0
|
var finished2 = 0
|
// 缺失台账
|
val list = mutableListOf<String>()
|
// 不涉及台账
|
val list2 = mutableListOf<String>()
|
|
records.forEach {
|
if (!isFit(it)) return@forEach
|
//总数
|
total1++
|
//完成数
|
if (it.ledgerFinished) {
|
finished1++
|
}
|
//必填项
|
if (it.needUpdate) {
|
total2++
|
if (it.ledgerFinished) {
|
finished2++
|
} else {
|
it.ledgerName?.let { n -> list.add(n) }
|
}
|
// 不涉及项
|
if (!it.involved) {
|
it.ledgerName?.let { n -> list2.add(n) }
|
}
|
}
|
}
|
result.apply {
|
rate1 = finished1.toDouble().div(total1)
|
rate2 = finished2.toDouble().div(total2)
|
rate3 = list2.size.toDouble().div(total2)
|
unSubmitLedger = if (list.isNotEmpty()) {
|
"缺失:\"${list.joinToString("、")}\",总计${list.size}项"
|
} else {
|
"无缺失项"
|
}
|
notInvolvedLedger = if (list2.isNotEmpty()) {
|
"不涉及:\"${list2.joinToString("、")}\",总计${list2.size}项"
|
} else {
|
"无不涉及项"
|
}
|
this.specialResult = specialCondition(records)
|
}
|
|
return result
|
}
|
}
|