package cn.flightfeather.supervision.lightshare.service.impl
|
|
import cn.flightfeather.supervision.business.AutoScore2
|
import cn.flightfeather.supervision.domain.ds1.entity.Domainitem
|
import cn.flightfeather.supervision.domain.ds1.entity.Evaluation
|
import cn.flightfeather.supervision.domain.ds1.entity.Subtask
|
import cn.flightfeather.supervision.domain.ds1.mapper.DomainitemMapper
|
import cn.flightfeather.supervision.domain.ds1.mapper.EvaluationMapper
|
import cn.flightfeather.supervision.domain.ds1.mapper.SubtaskMapper
|
import cn.flightfeather.supervision.common.utils.Constant
|
import cn.flightfeather.supervision.common.utils.DateUtil
|
import cn.flightfeather.supervision.common.utils.Domain
|
import cn.flightfeather.supervision.lightshare.service.EvaluationService
|
import cn.flightfeather.supervision.lightshare.service.SubtaskService
|
import cn.flightfeather.supervision.lightshare.vo.AreaVo
|
import cn.flightfeather.supervision.lightshare.vo.SubtaskVo
|
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.stereotype.Service
|
import tk.mybatis.mapper.entity.Example
|
import java.util.*
|
import kotlin.Comparator
|
|
@Service
|
class EvaluationServiceImpl(val evaluationMapper: EvaluationMapper) : EvaluationService {
|
|
@Autowired
|
lateinit var subtaskService: SubtaskService
|
@Autowired
|
lateinit var domainitemMapper: DomainitemMapper
|
@Autowired
|
lateinit var subtaskMapper: SubtaskMapper
|
|
//获取某顶层任务下某个场景的街道评分排名
|
override fun getRankOfTown(tguid: String, scensetypeid: String?): List<AreaVo> {
|
val evaluationlist = getRankInfo(tguid, scensetypeid, null)
|
var areaVolist = mutableListOf<AreaVo>()
|
//考核类型是规范考核
|
if (evaluationlist.isNotEmpty() &&
|
Objects.equals(evaluationlist.get(0).ertype, Constant.RuleType.STANDARD.value)) {
|
//获取规范考核的考核界限(问题数量)
|
val example = Example(Domainitem::class.java)
|
val criteria = example.createCriteria()
|
criteria.andEqualTo("dcguid", Domain.STANDARDLEVEL.value)
|
val standardlevel:String? = domainitemMapper.selectByExample(example).get(0).value
|
//按街镇计算严重不规范场景数量并按百分比排序
|
while (evaluationlist.isNotEmpty()) {
|
val tmplist = mutableListOf<Evaluation>()
|
tmplist.addAll(evaluationlist)
|
val iterator: MutableIterator<Evaluation> = tmplist.iterator()
|
|
val evaluation = evaluationlist.get(0)//获取一种街镇
|
var areaVo = AreaVo()
|
areaVo = transform(areaVo, evaluation)
|
while (iterator.hasNext()){
|
val tmp = iterator.next()
|
if (Objects.equals(tmp.towncode, evaluation.towncode)){
|
if (tmp.resultscorebef!!.toInt() >= standardlevel!!.toInt())
|
areaVo.notstandardnum++
|
areaVo.allsensenum++
|
evaluationlist.remove(tmp)
|
}
|
}
|
areaVolist.add(areaVo)
|
}
|
areaVolist = sort(areaVolist)
|
return areaVolist
|
}
|
//考核类型是评分考核
|
else if (evaluationlist.isNotEmpty() &&
|
Objects.equals(evaluationlist.get(0).ertype, Constant.RuleType.SCORE.value)){
|
//获取评分考核的评分界限
|
val example = Example(Domainitem::class.java)
|
val criteria = example.createCriteria()
|
criteria.andEqualTo("dcguid", Domain.SCORELEVEL.value)
|
example.orderBy("index")
|
val scorelevellist = domainitemMapper.selectByExample(example)
|
//按街镇计算严重不规范场景数量并按百分比排序
|
while (evaluationlist.isNotEmpty()) {
|
val tmplist = mutableListOf<Evaluation>()
|
tmplist.addAll(evaluationlist)
|
val iterator: MutableIterator<Evaluation> = tmplist.iterator()
|
|
val evaluation = evaluationlist.get(0)//获取一种街镇
|
var areaVo = AreaVo()
|
areaVo = transform(areaVo, evaluation)
|
while (iterator.hasNext()){
|
val tmp = iterator.next()
|
if (Objects.equals(tmp.towncode, evaluation.towncode)) {
|
if (tmp.resultscorebef!!.toInt() < scorelevellist.get(scorelevellist.size - 1).text!!.toInt())
|
areaVo.notstandardnum++
|
areaVo.allsensenum++
|
evaluationlist.remove(tmp)
|
}
|
}
|
areaVolist.add(areaVo)
|
}
|
areaVolist = sort(areaVolist)
|
return areaVolist
|
}
|
|
return areaVolist
|
}
|
|
//获取某顶层任务下某个场景的综合评分排名
|
override fun getRankOfSense(tguid: String, scensetypeid: String?, ruletypeid: ByteArray?): List<Evaluation> {
|
val evaluationlist = getRankInfo(tguid, scensetypeid, ruletypeid)
|
evaluationlist.sortWith(Comparator { o1, o2 -> o2!!.resultscorebef!!.toInt() - o1!!.resultscorebef!!.toInt() })
|
return evaluationlist
|
}
|
|
override fun findOne(id: String): Evaluation = evaluationMapper.selectByPrimaryKey(id)
|
|
override fun findAll(): MutableList<Evaluation> = evaluationMapper.selectAll()
|
|
override fun save(evaluation: Evaluation): Int = evaluationMapper.insert(evaluation)
|
|
override fun update(evaluation: Evaluation): Int = evaluationMapper.updateByPrimaryKey(evaluation)
|
|
override fun delete(id: String): Int = evaluationMapper.deleteByPrimaryKey(id)
|
|
//获取指定区域(顶层任务)指定场景的评分信息
|
fun getRankInfo(tguid: String, scensetypeid: String?, ruletypeid: ByteArray?):MutableList<Evaluation>{
|
val evaluationlist = mutableListOf<Evaluation>()
|
val subtaskVolist = subtaskService.findByTaskID(tguid)
|
subtaskVolist.forEach {
|
val example = Example(Evaluation::class.java)
|
val criteria = example.createCriteria()
|
|
criteria.andEqualTo("stguid", it.stguid)//子任务id
|
if (scensetypeid != null)//场景类别
|
criteria.andEqualTo("scensetypeid", scensetypeid)
|
if (ruletypeid != null)//评分类型
|
criteria.andEqualTo("ertype", ruletypeid)
|
else{
|
criteria.andEqualTo("ertype", Constant.RuleType.STANDARD.value)
|
val result = evaluationMapper.selectByExample(example)//查询是否有规范性评分表
|
//没有规范表就查询评分表
|
if (result.isEmpty()){
|
val example1 = Example(Evaluation::class.java)
|
val criteria1 = example1.createCriteria()
|
criteria1.andEqualTo("stguid", it.stguid)//子任务id
|
if (scensetypeid != null)//场景类别
|
criteria1.andEqualTo("scensetypeid", scensetypeid)
|
criteria1.andEqualTo("ertype", Constant.RuleType.SCORE.value)
|
val result1 = evaluationMapper.selectByExample(example1)
|
if (result1.size == 1)
|
evaluationlist.add(result1.get(0))
|
}
|
else
|
if (result.size == 1)
|
evaluationlist.add(result.get(0))
|
}
|
}
|
return evaluationlist
|
}
|
|
//Evaluation传递数据给AreaVo
|
fun transform(areaVo: AreaVo, evaluation: Evaluation):AreaVo{
|
areaVo.provincecode = evaluation.provincecode
|
areaVo.provincename = evaluation.provincename
|
areaVo.citycode = evaluation.citycode
|
areaVo.cityname = evaluation.cityname
|
areaVo.districtcode = evaluation.districtcode
|
areaVo.districtname = evaluation.districtname
|
areaVo.towncode = evaluation.towncode
|
areaVo.townname = evaluation.townname
|
return areaVo
|
}
|
|
//按街道严重不规范场景百分比排序
|
fun sort(areaVolist: MutableList<AreaVo>):MutableList<AreaVo>{
|
Collections.sort(areaVolist, object : Comparator<AreaVo>{
|
override fun compare(o1: AreaVo?, o2: AreaVo?): Int {
|
var num1 = 0.0
|
if (o1!!.allsensenum != 0)
|
num1 = (o1.notstandardnum/o1.allsensenum).toDouble()
|
var num2 = 0.0
|
if (o2!!.allsensenum != 0)
|
num2 = (o2.notstandardnum/o2.allsensenum).toDouble()
|
return compareValues(num1, num2)
|
}
|
})
|
return areaVolist
|
}
|
|
override fun getTopTaskByScene(sceneId: String?): String? {
|
val example = Example(Evaluation::class.java)
|
val criteria = example.createCriteria()
|
criteria.andEqualTo("sguid", sceneId)
|
example.orderBy("evaluatetime").desc()
|
val evaluationlist = evaluationMapper.selectByExample(example)
|
var subtask = SubtaskVo()
|
if (evaluationlist.isNotEmpty()) {
|
val stguid = evaluationlist[0].stguid
|
if (stguid != null)
|
subtask = subtaskService.findByID(stguid)
|
}
|
return subtask.tguid
|
}
|
|
override fun autoScore(districtCode: String, time: String): List<String> {
|
val resultList = mutableListOf<String>()
|
|
val example = Example(Subtask::class.java)
|
val criteria = example.createCriteria()
|
criteria.andEqualTo("districtcode", districtCode)
|
val date = DateUtil().StringToDate(time)
|
criteria.andGreaterThanOrEqualTo("planstarttime", time)
|
val subTaskList = subtaskMapper.selectByExample(example)
|
subTaskList.forEach {
|
val example1 = Example(Evaluation::class.java)
|
val criteria1 = example1.createCriteria()
|
criteria1.andEqualTo("stguid", it.stguid)
|
val result = evaluationMapper.selectByExample(example1)
|
if (result.isEmpty()) {
|
val autoScore = AutoScore2()
|
autoScore.subtask = it
|
autoScore.calculateScore()
|
resultList.add(it.stguid ?: "")
|
}
|
}
|
return resultList
|
}
|
|
override fun autoScore2(subTaskId: String): List<String> {
|
val resultList = mutableListOf<String>()
|
|
val example = Example(Subtask::class.java)
|
val criteria = example.createCriteria()
|
criteria.andEqualTo("stguid", subTaskId)
|
val subTaskList = subtaskMapper.selectByExample(example)
|
subTaskList.forEach {
|
val example1 = Example(Evaluation::class.java)
|
val criteria1 = example1.createCriteria()
|
criteria1.andEqualTo("stguid", it.stguid)
|
val result = evaluationMapper.selectByExample(example1)
|
if (result.isEmpty()) {
|
val autoScore = AutoScore2()
|
autoScore.subtask = it
|
autoScore.calculateScore()
|
resultList.add(it.stguid ?: "")
|
}
|
}
|
return resultList
|
}
|
|
override fun findByInspectionId(inspectionId: String): List<Evaluation> {
|
return evaluationMapper.selectByExample(Example(Evaluation::class.java).apply {
|
createCriteria().andEqualTo("iguid", inspectionId)
|
})
|
}
|
}
|