package cn.flightfeather.supervision.lightshare.service.Impl
|
|
import cn.flightfeather.supervision.common.score.AutoScore
|
import cn.flightfeather.supervision.domain.entity.*
|
import cn.flightfeather.supervision.domain.enumeration.AssessmentRuleType
|
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.UUIDGenerator
|
import cn.flightfeather.supervision.lightshare.service.EvaluationService
|
import cn.flightfeather.supervision.lightshare.service.ItemevaluationService
|
import cn.flightfeather.supervision.lightshare.vo.AssessmentGradeVo
|
import cn.flightfeather.supervision.lightshare.vo.AssessmentSearchCondition
|
import cn.flightfeather.supervision.lightshare.vo.CreditInfoVo
|
import cn.flightfeather.supervision.lightshare.vo.GradeDetailVo
|
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 EvaluationServiceImpl(
|
val evaluationMapper: EvaluationMapper,
|
val evaluationruleMapper: EvaluationruleMapper,
|
val evaluationsubruleMapper: EvaluationsubruleMapper,
|
val userinfoMapper: UserinfoMapper,
|
val baseInfoMapper: BaseInfoMapper,
|
val companyMapper: CompanyMapper,
|
val overallEvaluationMapper: OverallEvaluationMapper,
|
val autoScore: AutoScore,
|
val itemevaluationService: ItemevaluationService
|
) : EvaluationService {
|
|
override fun findOne(id: String): Evaluation = evaluationMapper.selectByPrimaryKey(id)
|
|
override fun findAll(): MutableList<Evaluation> = evaluationMapper.selectAll()
|
|
override fun save(evaluation: Evaluation): Int {
|
updateRank(evaluation, true)
|
return evaluationMapper.insert(evaluation)
|
}
|
|
override fun update(evaluation: Evaluation): Int {
|
updateRank(evaluation, false)
|
return evaluationMapper.updateByPrimaryKey(evaluation)
|
}
|
|
override fun delete(id: String): Int = evaluationMapper.deleteByPrimaryKey(id)
|
|
override fun getTotalPoints(userId: String, evaluatorType: Int, startTime: String, endTime: String, sceneTypeId: Int?, erGuid: String?, eId: String?): List<Evaluation> {
|
val example = Example(Evaluation::class.java)
|
val criteria = example.createCriteria()
|
val startDate = DateUtil().StringToDate(startTime)
|
val endDate = DateUtil().StringToDate(endTime)
|
criteria.andEqualTo("iguid", userId)
|
.andBetween("createdate", startDate, endDate)
|
example.and(example.createCriteria().apply {
|
if (evaluatorType == 0) {
|
orEqualTo("evaluatorrealname", evaluatorType.toString())
|
.orIsNull("evaluatorrealname")
|
} else {
|
andEqualTo("evaluatorrealname", evaluatorType.toString())
|
}
|
})
|
erGuid?.let { criteria.andEqualTo("stguid", erGuid) }
|
eId?.let { criteria.andEqualTo("guid", eId) }
|
sceneTypeId?.let {
|
example.and(example.createCriteria()
|
.orEqualTo("scensetypeid", sceneTypeId.toByte())
|
.orIsNull("scensetypeid")
|
)
|
}
|
|
return evaluationMapper.selectByExample(example)
|
}
|
|
override fun getHistoryPoint(userId: String, page: Int, per_page: Int, response: HttpServletResponse): List<AssessmentGradeVo> {
|
val userInfo = userinfoMapper.selectByPrimaryKey(userId) ?: return emptyList()
|
|
//评分规则下的分级、等级颜色及等级评语
|
val pointLevel = mutableListOf<Pair<Int, Int>>()
|
val evaluateLevel = mutableListOf<String>()
|
val creditTexts = mutableListOf<String>()
|
val levelColors = mutableListOf<String>()
|
val rule = evaluationruleMapper.selectByExample(Example(Evaluationrule::class.java).apply {
|
createCriteria().andEqualTo("scensetypeid", userInfo.extension2)
|
.andEqualTo("ruletype", "0")
|
})
|
if (rule.isNotEmpty()) {
|
val r = rule[0]
|
r.extension1?.split("#")?.forEach {
|
val pStr = it.split(",")
|
pointLevel.add(Pair(pStr[0].toInt(), pStr[1].toInt()))
|
}
|
r.extension2?.split("#")?.forEach {
|
evaluateLevel.add(it)
|
}
|
r.extension3?.split("#")?.forEach {
|
creditTexts.add(it)
|
}
|
r.remark?.split(";")?.forEach {
|
levelColors.add(it)
|
}
|
}
|
val example = Example(Evaluation::class.java).apply {
|
createCriteria().andEqualTo("iguid", userId)
|
.andEqualTo("ertype", AssessmentRuleType.Total.value.toByte())
|
//根据评估人的类型进行筛选,自评和官方评分分开排名
|
and(createCriteria().orIsNull("evaluatorrealname")
|
.orEqualTo("evaluatorrealname", 0))
|
orderBy("createdate").desc()
|
}
|
val counts = evaluationMapper.selectCountByExample(example)
|
val totalPage = Math.ceil(counts.toDouble() / per_page.toDouble()).toInt()
|
response.setIntHeader("totalPage", totalPage)
|
response.setIntHeader("currentPage", page)
|
|
val offset = per_page.times(page - 1)
|
PageHelper.offsetPage<Evaluation>(offset, per_page)
|
|
val resultList = mutableListOf<AssessmentGradeVo>()
|
evaluationMapper.selectByExample(example).forEach {
|
resultList.add(AssessmentGradeVo().apply {
|
this.userId = userId
|
userRealName = userInfo.realname
|
sceneType = userInfo.extension2?.toIntOrNull() ?: SceneType.NoType.value
|
tPGuid = it.guid
|
tPRuleGuid = it.stguid
|
totalPoint = it.resultscorebef?.toInt() ?: 0
|
val l = getEvaluationLevel(totalPoint, pointLevel, evaluateLevel, creditTexts, levelColors)
|
level = l["evaluateLevel"]
|
color = l["color"]
|
creditText = l["creditText"]
|
rank = it.promissednum ?: 1
|
updateDate = it.createdate
|
period = it.scensename
|
})
|
}
|
|
return resultList
|
}
|
|
override fun getCreditInfo(userId: String): CreditInfoVo {
|
val userinfo = userinfoMapper.selectByPrimaryKey(userId)
|
val baseInfo = baseInfoMapper.selectByPrimaryKey(userId)
|
val company = companyMapper.selectByPrimaryKey(baseInfo.ciGuid)
|
|
|
val result = CreditInfoVo(
|
userId,
|
baseInfo.biName,
|
userinfo.extension2?.toIntOrNull() ?: SceneType.NoType.value,
|
baseInfo.ciName,
|
baseInfo.biManagementCompany,
|
baseInfo.biContact,
|
baseInfo.biTelephone,
|
baseInfo.biAddress,
|
district = company.ciDistrictName,
|
town = company.ciTownName
|
)
|
|
val rule = evaluationruleMapper.selectByExample(Example(Evaluationrule::class.java).apply {
|
val c = createCriteria()
|
userinfo.extension2?.toByteOrNull()?.let {
|
c.andEqualTo("scensetypeid", it)
|
.andEqualTo("ruletype", "0")
|
}
|
}).takeIf { it.isNotEmpty() }?.get(0) ?: return result
|
|
val overallEvaluation = overallEvaluationMapper.selectByExample(Example(OverallEvaluation::class.java).apply {
|
createCriteria().andEqualTo("biGuid", baseInfo.biGuid)
|
orderBy("oePublishTime").desc()
|
}).takeIf { it.isNotEmpty() }?.get(0) ?: return result
|
|
//评分记录对应 的打分周期 ,格式为 YYYY/M-M,某年某月至某月
|
val period = overallEvaluation.oePeriod
|
//评分等级分数界限,格式为 0,59#60,89#90,100,表示有三个分数段
|
val levels = rule.extension1?.split("#")?.asReversed()
|
//评分等级对应的描述,格式为 较差#一般#优秀,对应三个分数段的描述
|
val levelDes = rule.extension2?.split("#")?.asReversed()
|
|
var creditLevel: Int? = null
|
var creditLevelDes: String? = null
|
|
if (levels != null && levelDes != null && levels.size == levelDes.size) {
|
for (i in levels.indices) {
|
val list = levels[i].split(",")
|
if (list.size == 2) {
|
val min = list[0].toInt()
|
val max = list[1].toInt()
|
val score = overallEvaluation.oeScore
|
if (score in min..max) {
|
creditLevel = i
|
creditLevelDes = levelDes[i]
|
break
|
}
|
}
|
}
|
}
|
val codeLevel =
|
when (overallEvaluation.oeCodeLevel) {
|
0.toByte() -> "绿码"
|
1.toByte() -> "黄码"
|
2.toByte() -> "红码"
|
else -> null
|
}
|
|
result.publishTime = DateUtil().DateToString(overallEvaluation.oePublishTime, "YYYY年MM月")
|
result.updateTime = DateUtil().DateToString(overallEvaluation.oeUpdateTime, "YYYY年MM月")
|
result.creditLevel = creditLevel
|
result.creditLevelDes = creditLevelDes
|
result.codeLevel = codeLevel
|
result.score = overallEvaluation.oeScore?.toString()
|
|
return result
|
}
|
|
|
override fun getAssessments(userId: String, condition: AssessmentSearchCondition, page: Int, perPage: Int, response: HttpServletResponse): List<AssessmentGradeVo> {
|
val user = userinfoMapper.selectByPrimaryKey(userId)
|
val districtName = user.extension1
|
|
val p = PageHelper.startPage<Evaluation>(page, perPage)
|
|
val result = mutableListOf<AssessmentGradeVo>()
|
evaluationMapper.getAssessments(districtName?:"", condition.searchText, "", condition.sceneTypes).forEach {
|
//此处由于 PageHelper 的分页操作,会导致结果的数量强制为 perPage的值,包括null
|
if (it != null) {
|
result.add(AssessmentGradeVo().apply {
|
this.userId = it["userId"] as String?
|
userRealName = it["userRealName"] as String?
|
sceneType = (it["sceneType"] as String?)?.toIntOrNull() ?: SceneType.Restaurant.value
|
tPGuid = it["tPGuid"] as String?
|
tPRuleGuid = it["tPRuleGuid"] as String?
|
totalPoint = (it["totalPoint"] as String?)?.toIntOrNull() ?: 0
|
level = getEvaluationLevel(totalPoint)["evaluateLevel"]
|
rank = (it["rank"] as Int?) ?: -1
|
updateDate = it["updateDate"] as Date?
|
})
|
}
|
}
|
|
response.setIntHeader("totalPage", p.pages)
|
response.setIntHeader("currentPage", p.pageNum)
|
|
return result
|
}
|
|
override fun autoScore(year: Int, month: Int, sceneType: Int, response: HttpServletResponse): HttpServletResponse {
|
autoScore.go()
|
return response
|
}
|
|
override fun uploadScore(userId: String, period: String, ruleId: String?, itemList: List<Pair<String, String>>): Boolean {
|
val userinfo = userinfoMapper.selectByPrimaryKey(userId) ?: return false
|
|
//该场景类型下的总得分规则
|
val tRule = evaluationruleMapper.selectByExample(Example(Evaluationrule::class.java).apply {
|
createCriteria().andEqualTo("scensetypeid", userinfo.extension2)
|
.andEqualTo("ruletype", AssessmentRuleType.Total.value)
|
.andIsNull("tasktypeid")
|
}).takeIf { it.isNotEmpty() }?.get(0)
|
|
var totalPoint = 0
|
var tEvaluation = Evaluation()
|
|
//上传的得分规则
|
// var rule = Evaluationrule()
|
// val subRules:List<Evaluationsubrule> = if (ruleId != null) {
|
// rule = evaluationruleMapper.selectByPrimaryKey(ruleId)
|
// evaluationsubruleMapper.selectByExample(Example(Evaluationsubrule::class.java).apply {
|
// createCriteria().andEqualTo("erguid", ruleId)
|
// })
|
// }
|
|
val ruleList = evaluationruleMapper.selectByExample(Example(Evaluationrule::class.java).apply {
|
createCriteria().andEqualTo("scensetypeid", userinfo.extension2)
|
.andNotEqualTo("ruletype", AssessmentRuleType.Total.value)
|
.andIsNull("tasktypeid")
|
}).forEach {rule->
|
val subRules = evaluationsubruleMapper.selectByExample(Example(Evaluationsubrule::class.java).apply {
|
createCriteria().andEqualTo("erguid", rule.guid)
|
})
|
if (subRules.isEmpty()) return@forEach
|
//总分记录
|
val evaluation = Evaluation().apply { guid = UUIDGenerator.generate16ShortUUID() }
|
//具体项得分记录
|
val itemEvaluationList = mutableListOf<Itemevaluation>()
|
//总得分
|
var totalScore = 0
|
|
itemList.forEach {
|
for (s in subRules) {
|
if (s.guid == it.first) {
|
var fatherId: String?
|
var subRule = s
|
var score = it.second
|
do {
|
val result = calculateScore(rule, evaluation.guid!!, userId, subRule, score, itemEvaluationList)
|
fatherId = result.first
|
for (s in subRules) {
|
if (s.guid == fatherId) {
|
subRule = s
|
score = result.second ?: "0"
|
break
|
}
|
}
|
} while (fatherId?.isNotBlank() == true)
|
|
totalScore += it.second.toInt()
|
break
|
}
|
}
|
}
|
|
//总分
|
var maxScore = 0
|
subRules.forEach subRules@{s ->
|
if (s.ertype == 2) {
|
maxScore += s.maxscore ?: 0
|
}
|
//规则已经打分完毕,则跳过
|
itemEvaluationList.forEach {i ->
|
if (i.esrguid == s.guid) {
|
return@subRules
|
}
|
}
|
//否则新增一条未扣分的记录
|
itemEvaluationList.add(Itemevaluation().apply {
|
ieguid = UUIDGenerator.generate16ShortUUID()
|
iguid = userId
|
sguid = evaluation.guid
|
erguid = rule.guid
|
rulename = rule.rulename
|
ruletype = rule.ruletype?.toInt()
|
ertype = s.ertype
|
esrguid = s.guid
|
name = s.itemname
|
value = "0"
|
extension1 = "false"
|
})
|
}
|
//计算总分
|
evaluation.apply {
|
iguid = userId
|
stguid = rule.guid
|
scensetypeid = userinfo.extension2?.toByte()
|
ertype = rule.ruletype?.toByte()
|
scensename = period
|
evaluatorguid = userId
|
evaluatorusername = userinfo.acountname
|
evaluatorrealname = "0"
|
resultscorebef = (maxScore + totalScore).toString()
|
createdate = Date()
|
updatedate = Date()
|
}
|
save(evaluation)
|
itemevaluationService.savelist(itemEvaluationList)
|
tEvaluation = evaluation
|
|
totalPoint += evaluation.resultscorebef?.toInt() ?: 0
|
}
|
|
//计算所有表的总分
|
tRule?.let {
|
tEvaluation.apply {
|
guid = UUIDGenerator.generate16ShortUUID()
|
stguid = it.guid
|
ertype = it.ruletype?.toByte()
|
resultscorebef = totalPoint.toString()
|
}
|
save(tEvaluation)
|
}
|
return true
|
}
|
|
override fun getDetail(userId: String, period: String): GradeDetailVo {
|
val result = GradeDetailVo()
|
|
val userinfo = userinfoMapper.selectByPrimaryKey(userId) ?: return result
|
|
//该场景类型下的所有得分规则
|
var rule0: Evaluationrule? = null
|
val rule1List = mutableListOf<Evaluationrule>()
|
evaluationruleMapper.selectByExample(Example(Evaluationrule::class.java).apply {
|
createCriteria().andEqualTo("scensetypeid", userinfo.extension2)
|
and(createCriteria().orIsNull("tasktypeid").orNotEqualTo("tasktypeid", 1))
|
}).forEach {
|
if (it.ruletype == AssessmentRuleType.Total.value.toString()) {
|
rule0 = it
|
} else {
|
rule1List.add(it)
|
}
|
}
|
if (rule0 == null) return result
|
//得分解读和得分详情
|
evaluationMapper.selectByExample(Example(Evaluation::class.java).apply {
|
createCriteria().andEqualTo("iguid", userId)
|
.andEqualTo("ertype", AssessmentRuleType.Total.value.toByte())
|
.andEqualTo("scensename", period)
|
}).takeIf { it.isNotEmpty() }?.get(0)?.let {
|
rule0?.apply {
|
val pointLevel = mutableListOf<Pair<Int, Int>>()
|
val evaluateLevel = mutableListOf<String>()
|
val creditTexts = mutableListOf<String>()
|
val levelColors = mutableListOf<String>()
|
extension1?.split("#")?.forEach {
|
val pStr = it.split(",")
|
pointLevel.add(Pair(pStr[0].toInt(), pStr[1].toInt()))
|
}
|
extension2?.split("#")?.forEach {
|
evaluateLevel.add(it)
|
}
|
extension3?.split("#")?.forEach {
|
creditTexts.add(it)
|
}
|
remark?.split(";")?.forEach {
|
levelColors.add(it)
|
}
|
|
val l = getEvaluationLevel(it.resultscorebef?.toInt()
|
?: 0, pointLevel, evaluateLevel, creditTexts, levelColors)
|
result.apply {
|
creditText = l["creditText"]
|
|
score = it.resultscorebef?.toInt() ?: 0
|
rank = it.promissednum
|
level = l["evaluateLevel"]
|
this.period = it.scensename
|
time = it.createdate
|
// color = l["color"]
|
}
|
}
|
}
|
|
//分类别的得分(每个评分表的评分大项的得分)和失分条目
|
rule1List.forEach {
|
val evaluation = evaluationMapper.selectByExample(Example(Evaluation::class.java).apply {
|
createCriteria().andEqualTo("iguid", userId)
|
.andEqualTo("ertype", it.ruletype)
|
.andEqualTo("scensename", period)
|
}).takeIf { it.isNotEmpty() }?.get(0)?.let {e ->
|
val subRules = evaluationsubruleMapper.selectByExample(Example(Evaluationsubrule::class.java).apply {
|
createCriteria().andEqualTo("erguid", it.guid)
|
})
|
val itemEvaluations = itemevaluationService.getItemEvaluationList(e.guid!!)
|
|
itemEvaluations.forEach {item ->
|
when (item.ertype) {
|
//分类别的得分
|
2 -> {
|
for (s in subRules) {
|
if (s.guid == item.esrguid) {
|
val score = if ((item.value?.toInt() ?: 0) <= 0) {
|
s.maxscore?.plus(item.value?.toInt() ?: 0)
|
} else {
|
item.value?.toInt() ?: 0
|
}
|
result.classScore.add(Triple(item.name ?: "", s.maxscore?.toString()?:"0", score.toString()))
|
break
|
}
|
}
|
}
|
//失分条目
|
4 -> {
|
if ((item.value?.toInt() ?: 0) != 0 && item.extension1 == "true") {
|
for (s in subRules) {
|
if (s.guid == item.esrguid) {
|
result.loseScore.add(
|
Triple(
|
item.name ?: "",
|
if ((item.value?.toInt() ?: 0) < 0) {
|
item . value ?: "0"
|
} else {
|
(item.value?.toInt() ?: 0).minus(s.maxscore ?: 0).toString()
|
},
|
s.remark ?: ""
|
)
|
)
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
|
return result
|
}
|
|
/**
|
* 根据上传的子规则扣分情况,生产子项得分记录
|
* @param rule 总规则
|
* @param eGuid 总分记录id
|
* @param userId 用户id
|
* @param subRule 扣分的规则
|
* @param score 扣分
|
* @param itemEvaluationList 得分记录表
|
* @return 评分项的父id和得分
|
*/
|
private fun calculateScore(rule:Evaluationrule, eGuid: String, userId: String, subRule: Evaluationsubrule, score: String, itemEvaluationList: MutableList<Itemevaluation>): Pair<String?, String?> {
|
var result: Pair<String?, String?> = Pair(null, null)
|
var exist = false
|
for (i in itemEvaluationList) {
|
//记录已存在,说明是父项的评分规则下的某个子项的一部分扣分,扣分累加
|
if (subRule.guid == i.esrguid) {
|
i.value = i.value?.toInt()?.plus(score.toInt())?.toString()
|
result = Pair(subRule.fatherid, i.value)
|
exist = true
|
break
|
}
|
}
|
//记录不存在时,说明是子项第一次扣分,新增一条记录
|
if (!exist) {
|
itemEvaluationList.add(Itemevaluation().apply {
|
ieguid = UUIDGenerator.generate16ShortUUID()
|
iguid = userId
|
sguid = eGuid
|
erguid = rule.guid
|
rulename = rule.rulename
|
ruletype = rule.ruletype?.toInt()
|
ertype = subRule.ertype
|
esrguid = subRule.guid
|
name = subRule.itemname
|
value = score
|
extension1 = "true"
|
})
|
result = Pair(subRule.fatherid, score)
|
}
|
return result
|
}
|
|
/**
|
* 根据分数获取等级
|
*/
|
private fun getEvaluationLevel(
|
score: Int,
|
pointLevel: MutableList<Pair<Int, Int>> = mutableListOf(),
|
evaluateLevel: MutableList<String> = mutableListOf(),
|
creditTexts: MutableList<String> = mutableListOf(),
|
levelColors: MutableList<String> = mutableListOf()
|
): Map<String, String> {
|
val result = mutableMapOf<String, String>()
|
if (pointLevel.isEmpty() || evaluateLevel.isEmpty() || creditTexts.isEmpty() || levelColors.isEmpty()) {
|
result["evaluateLevel"] = when (score) {
|
in 0..40 -> "极差"
|
in 41..64 -> "较差"
|
in 65..79 -> "一般"
|
in 80..94 -> "良好"
|
in 95..Int.MAX_VALUE -> "优秀"
|
else -> "极差"
|
}
|
} else {
|
for (i in pointLevel.indices) {
|
if (score in pointLevel[i].first..pointLevel[i].second) {
|
result["color"] = levelColors[i % levelColors.size]
|
result["creditText"] = creditTexts[i % creditTexts.size]
|
result["evaluateLevel"] = evaluateLevel[i % evaluateLevel.size]
|
}
|
}
|
}
|
return result
|
|
}
|
|
private fun updateRank(evaluation: Evaluation, isInsert: Boolean) {
|
if (evaluation.ertype == AssessmentRuleType.Total.value.toByte()) {
|
val eList = evaluationMapper.selectByExample(Example(Evaluation::class.java).apply {
|
createCriteria().andEqualTo("scensename", evaluation.scensename)
|
.andIsNotNull("scensename")
|
.andEqualTo("ertype", AssessmentRuleType.Total.value)
|
//根据评估人的类型进行筛选,自评和官方评分封面开排名
|
if (evaluation.evaluatorrealname == null || evaluation.evaluatorrealname == "0") {
|
and(createCriteria().orIsNull("evaluatorrealname")
|
.orEqualTo("evaluatorrealname", evaluation.evaluatorrealname))
|
} else {
|
and(createCriteria().andEqualTo("evaluatorrealname", evaluation.evaluatorrealname))
|
}
|
})
|
if (isInsert) {
|
eList.add(evaluation)
|
} else {
|
for (i in eList.indices) {
|
if (evaluation.guid == eList[i].guid) {
|
eList[i].resultscorebef = evaluation.resultscorebef
|
break
|
}
|
}
|
}
|
eList.sortByDescending {
|
it.resultscorebef?.toInt() ?: 0
|
}
|
val updateList = mutableListOf<Evaluation>()
|
for (i in eList.indices) {
|
if (eList[i].guid == evaluation.guid){
|
evaluation.promissednum = i + 1
|
}
|
else if (eList[i].promissednum != i + 1) {
|
eList[i].promissednum = i + 1
|
updateList.add(eList[i])
|
}
|
}
|
updateList.forEach {
|
evaluationMapper.updateByPrimaryKey(it)
|
}
|
}
|
}
|
}
|