src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/EvaluationServiceImpl.kt
@@ -1,11 +1,16 @@
package cn.flightfeather.supervision.lightshare.service.impl
import cn.flightfeather.supervision.business.AutoScore2
import cn.flightfeather.supervision.business.autooutput.AopTaskCtrl
import cn.flightfeather.supervision.business.bgtask.AopTaskCtrl
import cn.flightfeather.supervision.business.autooutput.score.AopEvaluation
import cn.flightfeather.supervision.common.executor.BackgroundTaskCtrl
import cn.flightfeather.supervision.business.bgtask.ReportTaskCtrl
import cn.flightfeather.supervision.business.report.DataSource
import cn.flightfeather.supervision.business.report.DbMapper
import cn.flightfeather.supervision.business.report.file.ReportOne
import cn.flightfeather.supervision.business.report.file.ReportThree
import cn.flightfeather.supervision.business.report.file.ReportTwo
import cn.flightfeather.supervision.common.exception.ResponseErrorException
import cn.flightfeather.supervision.common.executor.BgTaskStatus
import cn.flightfeather.supervision.common.executor.BgTaskType
import cn.flightfeather.supervision.domain.ds1.entity.Domainitem
import cn.flightfeather.supervision.domain.ds1.entity.Evaluation
import cn.flightfeather.supervision.domain.ds1.entity.Subtask
@@ -18,15 +23,17 @@
import cn.flightfeather.supervision.domain.ds1.repository.EvaluationRep
import cn.flightfeather.supervision.domain.ds1.repository.TaskRep
import cn.flightfeather.supervision.lightshare.service.EvaluationService
import cn.flightfeather.supervision.lightshare.service.SearchService
import cn.flightfeather.supervision.lightshare.service.SubtaskService
import cn.flightfeather.supervision.lightshare.vo.AreaVo
import cn.flightfeather.supervision.lightshare.vo.AutoScoreResultVo
import cn.flightfeather.supervision.lightshare.vo.BaseResponse
import cn.flightfeather.supervision.lightshare.vo.EvaluateResVo
import cn.flightfeather.supervision.lightshare.vo.*
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Service
import tk.mybatis.mapper.entity.Example
import java.io.File
import java.net.URLEncoder
import java.util.*
import javax.servlet.http.HttpServletResponse
import kotlin.Comparator
@Service
@@ -35,14 +42,21 @@
    private val evaluationRep: EvaluationRep,
    private val taskRep: TaskRep,
    private val aopTaskCtrl: AopTaskCtrl,
    private val searchService: SearchService,
    private val dbMapper: DbMapper,
    @Value("\${filePath}") private val filePath: String,
    private val reportTaskCtrl: ReportTaskCtrl,
) : EvaluationService {
    @Autowired
    lateinit var subtaskService: SubtaskService
    @Autowired
    lateinit var domainitemMapper: DomainitemMapper
    @Autowired
    lateinit var subtaskMapper: SubtaskMapper
    @Autowired
    lateinit var aopEvaluation: AopEvaluation
    private var isAutoScoreRunning = false
@@ -53,7 +67,8 @@
        var areaVolist = mutableListOf<EvaluateResVo>()
        //考核类型是规范考核
        if (evaluationlist.isNotEmpty() &&
                Objects.equals(evaluationlist.get(0).ertype, Constant.RuleType.STANDARD.value)) {
            Objects.equals(evaluationlist.get(0).ertype, Constant.RuleType.STANDARD.value)
        ) {
            //获取规范考核的考核界限(问题数量)
            val example = Example(Domainitem::class.java)
            val criteria = example.createCriteria()
@@ -84,7 +99,8 @@
        }
        //考核类型是评分考核
        else if (evaluationlist.isNotEmpty() &&
                Objects.equals(evaluationlist.get(0).ertype, Constant.RuleType.SCORE.value)){
            Objects.equals(evaluationlist.get(0).ertype, Constant.RuleType.SCORE.value)
        ) {
            //获取评分考核的评分界限
            val example = Example(Domainitem::class.java)
            val criteria = example.createCriteria()
@@ -162,8 +178,7 @@
                    val result1 = evaluationMapper.selectByExample(example1)
                    if (result1.size == 1)
                        evaluationlist.add(result1.get(0))
                }
                else
                } else
                    if (result.size == 1)
                        evaluationlist.add(result.get(0))
            }
@@ -270,8 +285,47 @@
    override fun findAutoEvaluation(areaVo: AreaVo): List<AutoScoreResultVo?>? {
        //1. 查找历史记录,查看评估是否已存在
        areaVo.scensetypeid ?: throw IllegalStateException("查询时必须选择一个场景类型")
        val task = taskRep.findOneTask(areaVo) ?: throw IllegalStateException("查询时必须选择一个场景类型")
//        areaVo.scensetypeid ?: throw ResponseErrorException("查询时必须选择一个场景类型")
//        val task = taskRep.findOneTask(areaVo) ?: throw ResponseErrorException("查询时必须选择一个场景类型")
        return evaluationRep.findAutoScore(areaVo)
    }
    override fun downloadAutoEvaluation(areaVo: AreaVo, response: HttpServletResponse): Boolean {
        areaVo.scensetypeid ?: throw ResponseErrorException("必须选择一个场景类型")
        val topTask = taskRep.findOneTask(areaVo) ?: throw ResponseErrorException("未找到符合条件的顶层任务")
        val config = ExcelConfigVo(
            topTask.tguid ?: "",
            topTask.starttime,
            topTask.endtime,
            topTask.provincecode,
            topTask.citycode,
            topTask.districtcode,
            topTask.towncode,
            areaVo.scensetypeid?.toInt()
        )
        val dataSource = DataSource(config, dbMapper)
        val t = ReportTwo(dataSource)
        val fileName = t.getReportName()
        val p = "$filePath/autoscore/"
        val file = File(p + fileName)
        if (config.forceUpdate || !file.exists()) {
            val downloadUrl = "/autoscore/${fileName}"
            reportTaskCtrl.startTask(t, downloadUrl)
            return false
        } else {
            val fName = Base64.getEncoder().encodeToString(fileName.toByteArray())
            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)
            }
            response.outputStream.write(file.readBytes())
            return true
        }
    }
}