package cn.flightfeather.supervision.common.score
|
|
import cn.flightfeather.supervision.domain.entity.Evaluation
|
import cn.flightfeather.supervision.domain.entity.Evaluationrule
|
import cn.flightfeather.supervision.domain.entity.Evaluationsubrule
|
import cn.flightfeather.supervision.domain.entity.Itemevaluation
|
import cn.flightfeather.supervision.domain.enumeration.SceneType
|
import cn.flightfeather.supervision.domain.mapper.*
|
import cn.flightfeather.supervision.infrastructure.utils.DateUtil
|
import cn.flightfeather.supervision.infrastructure.utils.ExcelUtil
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook
|
import org.apache.poi.hssf.util.HSSFColor
|
import org.springframework.stereotype.Component
|
import tk.mybatis.mapper.entity.Example
|
import java.io.File
|
import java.io.FileOutputStream
|
import java.util.*
|
|
/**
|
* 自评得分导出
|
*/
|
@Component
|
class ScoreUtil(
|
private val evaluationruleMapper: EvaluationruleMapper,
|
private val evaluationsubruleMapper: EvaluationsubruleMapper,
|
private val evaluationMapper: EvaluationMapper,
|
private val itemevaluationMapper: ItemevaluationMapper,
|
private val userinfoMapper: UserinfoMapper
|
) {
|
|
var head3 = true
|
|
fun outPut() {
|
val scoreItem = getScoreItem()
|
val evaluations = getScoreResult()
|
val titles = genTitles(scoreItem.second, scoreItem.third)
|
val contents = genContents(evaluations, scoreItem.second, scoreItem.third)
|
titles.addAll(contents)
|
toFile(titles, SceneType.VehicleRepair)
|
}
|
|
/**
|
* 获取评分规则
|
*/
|
fun getScoreItem(sceneType: Int = -7, districtCode: String = "310104")
|
: Triple<MutableList<Evaluationrule>,
|
MutableList<Evaluationsubrule>,
|
MutableList<Pair<Evaluationsubrule, MutableList<Evaluationsubrule>>>> {
|
val subRules = mutableListOf<Pair<Evaluationsubrule, MutableList<Evaluationsubrule>>>()
|
val baseRules = mutableListOf<Evaluationrule>()
|
val topItems = mutableListOf<Evaluationsubrule>()
|
|
val rule = evaluationruleMapper.selectByExample(Example(Evaluationrule::class.java).apply {
|
createCriteria()
|
// .andEqualTo("tasktypeid", 1)
|
.andEqualTo("scensetypeid", sceneType.toByte())
|
.andEqualTo("districtcode", districtCode)
|
})
|
if (rule.isNotEmpty()) {
|
baseRules.addAll(rule)
|
|
val ruleId = rule[0].guid
|
val rules = evaluationsubruleMapper.selectByExample(Example(Evaluationsubrule::class.java).apply {
|
createCriteria().andEqualTo("erguid", ruleId)
|
})
|
rules.forEach {
|
if (it.ertype == 2) {
|
topItems.add(it)
|
}
|
}
|
topItems.sortBy { it.displayid }
|
|
var t = 0
|
topItems.forEach {
|
t += it.maxscore ?: 0
|
val tempRules = mutableListOf<Evaluationsubrule>()
|
for (i in rules) {
|
if (i.fatherid == it.guid && i.ertype == 3) {
|
tempRules.add(i)
|
}
|
}
|
//评分大项如果没有找到评分小项,则说明其直接对应最小评分项,其本身变成评分项
|
if (tempRules.isEmpty()) {
|
tempRules.add(it)
|
}
|
tempRules.sortBy { t -> t.displayid }
|
tempRules.forEach { temp ->
|
val tempSubRules = mutableListOf<Evaluationsubrule>()
|
for (i in rules) {
|
if (i.fatherid == temp.guid && i.ertype == 4) {
|
tempSubRules.add(i)
|
}
|
}
|
tempSubRules.sortBy { ts -> ts.displayid }
|
subRules.add(Pair(temp, tempSubRules))
|
}
|
}
|
}
|
|
return Triple(baseRules, topItems, subRules)
|
}
|
|
fun getScoreResult(): List<Evaluation> {
|
return evaluationMapper.selectByExample(Example(Evaluation::class.java).apply {
|
createCriteria().andEqualTo("stguid", "3RNqhxpCe8lQoPss")
|
})
|
}
|
|
fun genTitles(topItems: List<Evaluationsubrule>, rules: List<Pair<Evaluationsubrule,
|
MutableList<Evaluationsubrule>>>): MutableList<Array<Any>> {
|
val contents = mutableListOf<Array<Any>>()
|
val h1 = mutableListOf<ExcelUtil.MyCell>()
|
h1.add(ExcelUtil.MyCell(""))
|
val h2 = mutableListOf<ExcelUtil.MyCell>()
|
h2.add(ExcelUtil.MyCell(""))
|
val h3 = mutableListOf<String>()
|
h3.add("")
|
topItems.forEach {
|
h1.add(ExcelUtil.MyCell(it.itemname ?: "", 1, 0))
|
for (r in rules) {
|
if (r.first.fatherid == it.guid || r.first.guid == it.guid) {
|
h2.add(ExcelUtil.MyCell(r.first.itemname ?: "", 1, 0))
|
// FIXME: 2021/4/25 决定是否写h3
|
if (head3) {
|
r.second.forEach { s ->
|
h3.add(s.itemname ?: "")
|
h2.last().colSpan++
|
h1.last().colSpan++
|
}
|
} else {
|
h2.last().colSpan++
|
h1.last().colSpan++
|
}
|
}
|
}
|
}
|
// FIXME: 2021/4/25 决定是否写h3
|
if (head3) {
|
h1.add(ExcelUtil.MyCell("总分", 3, 1))
|
h1.add(ExcelUtil.MyCell("环信码", 3, 1))
|
h1.add(ExcelUtil.MyCell("周期", 3, 1))
|
} else {
|
h1.add(ExcelUtil.MyCell("总分", 2, 1))
|
h1.add(ExcelUtil.MyCell("环信码", 2, 1))
|
h1.add(ExcelUtil.MyCell("周期", 2, 1))
|
}
|
contents.add(h1.toTypedArray())
|
contents.add(h2.toTypedArray())
|
// FIXME: 2021/4/25 决定是否写h3
|
if (head3) contents.add(h3.toTypedArray())
|
|
return contents
|
}
|
|
fun genContents(
|
evaluations: List<Evaluation>, topItems: MutableList<Evaluationsubrule>,
|
rules: MutableList<Pair<Evaluationsubrule, MutableList<Evaluationsubrule>>>
|
): List<Array<Any>> {
|
val contents = mutableListOf<Array<Any>>()
|
evaluations.forEach {
|
val cList = mutableListOf<Any>()
|
val user = userinfoMapper.selectByPrimaryKey(it.evaluatorguid)
|
cList.add("${user?.realname}")
|
val itemevaluations = itemevaluationMapper.selectByExample(Example(Itemevaluation::class.java).apply {
|
createCriteria().andEqualTo("sguid", it.guid)
|
})
|
//每一项具体得分
|
topItems.forEach {sr ->
|
for (r in rules) {
|
if (r.first.fatherid == sr.guid || r.first.guid == sr.guid) {
|
// FIXME: 2021/4/25 决定是否写h3
|
if (head3) {
|
r.second.forEach { s ->
|
val score = getScore(s.guid, itemevaluations)
|
cList.add(score)
|
}
|
} else {
|
val score = getScore(r.first.guid, itemevaluations)
|
cList.add(score)
|
}
|
}
|
}
|
}
|
|
//总分和环信码
|
cList.add(it.resultscorebef?.toDoubleOrNull() ?: -99.0)
|
val code = when (it.resultscorebef?.toIntOrNull() ?: 0) {
|
in 0..59 -> ExcelUtil.MyCell("红码", fontColor = HSSFColor.HSSFColorPredefined.RED.index)
|
in 60..89 -> ExcelUtil.MyCell("黄码", fontColor = HSSFColor.HSSFColorPredefined.GOLD.index)
|
in 90..120 -> ExcelUtil.MyCell("绿码", fontColor = HSSFColor.HSSFColorPredefined.BRIGHT_GREEN.index)
|
else -> ExcelUtil.MyCell("超出范围:${it.resultscoreaft}", fontColor = HSSFColor.HSSFColorPredefined.BLACK.index)
|
}
|
cList.add(code)
|
cList.add(it.scensename ?: "")
|
|
contents.add(cList.toTypedArray())
|
}
|
return contents
|
}
|
|
private fun getScore(subRuleId: String?, scoreList: List<Itemevaluation>): String{
|
val s = scoreList.find {
|
it.esrguid == subRuleId
|
}
|
return if (s?.extension1 == "true") s.value ?: "" else ""
|
}
|
|
fun toFile(contents: MutableList<Array<Any>>, sceneType: SceneType) {
|
// 写入文档
|
val workbook = HSSFWorkbook()
|
val fileName = "${sceneType.des}评分-${DateUtil.DateToString(Date(), "yyyy-MM-ddhhmmss")}.xls"
|
// val filePath = "E:\\工作\\开发\\飞羽环境app\\自动评分\\${SCENE_TYPE.des}\\$fileName"
|
val filePath = "C:\\work\\工作\\第三方监管\\用户自评\\${sceneType.des}\\$fileName"
|
val file = File(filePath)
|
if (!file.parentFile.exists()) {
|
file.parentFile.mkdirs()
|
}
|
val out = FileOutputStream(file)
|
|
ExcelUtil.write2(emptyList(), contents, workbook)
|
workbook.write(out)
|
workbook.close()
|
out.flush()
|
out.close()
|
}
|
}
|