feiyu02
2024-04-25 0392c333ed3d987cb2ab3dac4e1a972cff405f21
src/main/kotlin/cn/flightfeather/supervision/business/report/DataSource.kt
@@ -11,12 +11,10 @@
import cn.flightfeather.supervision.domain.ds2.mapper.LedgerSubTypeMapper
import cn.flightfeather.supervision.domain.ds2.mapper.UserMapMapper
import cn.flightfeather.supervision.lightshare.vo.ExcelConfigVo
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component
import tk.mybatis.mapper.entity.Example
import java.time.LocalDateTime
import java.time.ZoneId
import javax.annotation.PostConstruct
/**
 * 报告所需源数据
@@ -38,21 +36,22 @@
    val rowData = RowData()
    init {
        if (config.districtCode == null) {
            throw IllegalStateException("参数缺少区县编码:[districtCode]")
        }
        if (config.sceneType == null) {
            throw IllegalStateException("参数缺少场景类型:[sceneType]")
        }
//        if (config.districtCode == null) {
//            throw IllegalStateException("参数缺少区县编码:[districtCode]")
//        }
//        if (config.sceneType == null) {
//            throw IllegalStateException("参数缺少场景类型:[sceneType]")
//        }
        getSource(config)
    }
    fun loop(callback: (index:Int, rowData: RowData) -> Unit) {
        reset()
//        reset()
        for (i in sourceList.indices) {
//            rowData.recordLastScene()
            rowData.index = i
            rowData.clear()
            rowData.subTask = sourceList[i]
            rowData.clear()
            callback(i, rowData)
        }
    }
@@ -71,14 +70,14 @@
     */
    fun areaName(): String {
        val t = dbMapper.taskMapper.selectByPrimaryKey(config.topTaskGuid)
        return "${dateUtil.DateToString(t.starttime, DateUtil.DateStyle.YYYY_MM_CN)}${t.districtname}${if (area != t.districtname) area else ""}${Constant.ScenseType.getDes(config.sceneType)}"
        return "${dateUtil.DateToString(t.starttime, DateUtil.DateStyle.YYYY_MM_CN)}${t.districtname}${if (area != t.districtname) area else ""}${Constant.SceneType.getDes(config.sceneType)}"
    }
    /**
     * 获取报告数据源
     * 获取报告数据源(巡查任务)
     */
    private fun getSource(config: ExcelConfigVo) {
        if (config.sceneType == null) return
//        if (config.sceneType == null) return
        val result = mutableListOf<Subtask>()
@@ -107,10 +106,13 @@
                    }
                    config.startTime?.let { andGreaterThanOrEqualTo("planstarttime", it) }
                    config.endTime?.let { andLessThanOrEqualTo("planendtime", it) }
                    config.districtCode?.let { andEqualTo("districtcode", it) }
//                    andEqualTo("tguid", config.topTaskGuid)
                }
            })
        } else {
            taskSceneIdList = dbMapper.monitorobjectversionMapper.getSceneByType(config.topTaskGuid, config.sceneType, config.townCode)
            taskSceneIdList = dbMapper.scenseMapper.getSceneByType(config.topTaskGuid, config
                .sceneType, config.townCode).map { it.guid ?: "" }
            dbMapper.subtaskMapper.selectByExample(Example(Subtask::class.java).apply {
                createCriteria().andIn("scenseid", taskSceneIdList)
                    .andEqualTo("tguid", config.topTaskGuid)
@@ -123,11 +125,12 @@
                for (s in subTaskList) {
                    if (s.scenseid == it) {
                        subtask = s
                        break
                        result.add(s)
                    }
                }
                if (subtask == null) subtask = Subtask().apply { scenseid = it }
                result.add(subtask)
                if (subtask == null) {
                    result.add(Subtask().apply { scenseid = it })
                }
            }
        } else {
            result.addAll(subTaskList)
@@ -141,6 +144,8 @@
        var index = 0
        var subTask: Subtask? = null
        private var lastScene: Scense? = null
        //场景基本信息
        val scene: Scense?
@@ -157,16 +162,16 @@
            get() {
                if (_baseScene == null) {
                    _baseScene = when (this.scene?.typeid.toString()) {
                        Constant.ScenseType.TYPE1.value -> {
                        Constant.SceneType.TYPE1.value -> {
                            dbMapper.sceneConstructionSiteMapper.selectByPrimaryKey(scene?.guid)
                        }
                        Constant.ScenseType.TYPE2.value -> {
                        Constant.SceneType.TYPE2.value -> {
                            dbMapper.sceneWharfMapper.selectByPrimaryKey(scene?.guid)
                        }
                        Constant.ScenseType.TYPE3.value -> {
                        Constant.SceneType.TYPE3.value -> {
                            dbMapper.sceneMixingPlantMapper.selectByPrimaryKey(scene?.guid)
                        }
                        Constant.ScenseType.TYPE14.value -> {
                        Constant.SceneType.TYPE14.value -> {
                            dbMapper.sceneStorageYardMapper.selectByPrimaryKey(scene?.guid)
                        }
                        else -> null
@@ -177,20 +182,21 @@
        private var _baseScene: BaseScene? = null
        //具体的问题
        val problems: MutableList<Problemlist>
        val problems: List<Problemlist>
            get() {
                if (noRecord()) return mutableListOf()
                if (_problems.isEmpty()) {
                if (_problems == null) {
                    val r = dbMapper.problemlistMapper.selectByExample(Example(Problemlist::class.java).apply {
                        createCriteria().andEqualTo("stguid", subTask?.stguid)
                    })
                    _problems.addAll(r)
                    _problems = r
                }
                return _problems
                return _problems ?: emptyList()
            }
        private var _problems = mutableListOf<Problemlist>()
        private var _problems: List<Problemlist>? = null
        //评估总分
        val evaluation: Evaluation?
            get() {
                if (_evaluation == null) {
@@ -204,42 +210,45 @@
            }
        private var _evaluation: Evaluation? = null
        val itemevaluationList: MutableList<Itemevaluation>
        //评估细则得分
        val itemevaluationList: List<Itemevaluation>
            get() {
                if (_itemevaluationList.isEmpty()) {
                if (_itemevaluationList == null) {
                    val r = dbMapper.itemevaluationMapper.selectByExample(Example(Itemevaluation::class.java).apply {
                        createCriteria().andEqualTo("stguid", subTask?.stguid)
                    })
                    _itemevaluationList.addAll(r)
                    _itemevaluationList = r
                    println("-------------------itemevaluationList--------------------------------")
                }
                return _itemevaluationList
                return _itemevaluationList ?: emptyList()
            }
        private var _itemevaluationList = mutableListOf<Itemevaluation>()
        private var _itemevaluationList: List<Itemevaluation>? = null
        //问题类型
        val problemTypes: MutableList<Problemtype>
        val problemTypes: List<Problemtype>
            get() {
                if (_problemTypes.isEmpty()) {
                if (_problemTypes == null) {
                    val r = dbMapper.problemtypeMapper.selectByExample(Example(Problemtype::class.java).apply {
                        createCriteria().andEqualTo("scensetypeid", config.sceneType)
                            .andEqualTo("districtcode", config.districtCode)
                        createCriteria().andEqualTo("scensetypeid", scene?.typeid)
                            .andEqualTo("districtcode", scene?.districtcode)
                        orderBy("extension1")
                    })
                    _problemTypes.addAll(r)
                    _problemTypes = r
                }
                return _problemTypes
                return _problemTypes ?: emptyList()
            }
        private var _problemTypes = mutableListOf<Problemtype>()
        private var _problemTypes: List<Problemtype>? = null
        //自动评分规则一级分类
        val topItems: MutableList<Evaluationsubrule2>
        val topItems: List<Evaluationsubrule2>
            get() {
                if (_topItems.isEmpty()) {
                if (_topItems == null) {
                    val tempTopItems = mutableListOf<Evaluationsubrule2>()
                    val secRules = mutableListOf<Pair<Evaluationsubrule2, MutableList<Evaluationsubrule2>>>()
                    val rule = dbMapper.evaluationruleMapper.selectByExample(Example(Evaluationrule::class.java).apply {
                        createCriteria()
                            .andEqualTo("tasktypeid", 99)
                            .andEqualTo("scensetypeid", config.sceneType)
                            .andEqualTo("scensetypeid", scene?.typeid)
                    })
                    if (rule.isNotEmpty()) {
                        val ruleId = rule[0].guid
@@ -248,13 +257,13 @@
                        })
                        rules.forEach {
                            if (it.ertype == 2) {
                                _topItems.add(it)
                                tempTopItems.add(it)
                            }
                        }
                        _topItems.sortBy { it.displayid }
                        tempTopItems.sortBy { it.displayid }
                        var t = 0
                        _topItems.forEach {
                        tempTopItems.forEach {
                            t += it.maxscore ?: 0
                            val tempRules = mutableListOf<Evaluationsubrule2>()
                            for (i in rules) {
@@ -275,30 +284,32 @@
                                    }
                                }
                                tempSubRules.sortBy { ts -> ts.displayid }
                                this._rules.add(Pair(temp, tempSubRules))
                                secRules.add(Pair(temp, tempSubRules))
                            }
                        }
                    }
                    this._rules = secRules
                    _topItems = tempTopItems
                }
                return _topItems
                return _topItems ?: emptyList()
            }
        private var _topItems = mutableListOf<Evaluationsubrule2>()
        private var _topItems: List<Evaluationsubrule2>? = null
        //自动评分规则二级和三级分类
        val rules: MutableList<Pair<Evaluationsubrule2, MutableList<Evaluationsubrule2>>>
        val rules: List<Pair<Evaluationsubrule2, MutableList<Evaluationsubrule2>>>
            get() {
                if (_rules.isEmpty()) {
                if (_rules == null) {
                    this.topItems
                }
                return _rules
                return _rules ?: emptyList()
            }
        private var _rules = mutableListOf<Pair<Evaluationsubrule2, MutableList<Evaluationsubrule2>>>()
        private var _rules: List<Pair<Evaluationsubrule2, MutableList<Evaluationsubrule2>>>? = null
        //必填台账数量
        val ledgerCount: Int
            get() {
                if (_ledgerCount == -1) {
                    val tzSceneType = Constant.ScenseType.typeMap(config.sceneType?.toByte())
                    val tzSceneType = Constant.SceneType.typeMap(scene?.typeid)
                    _ledgerCount = dbMapper.ledgerSubTypeMapper.selectCountByExample(Example(LedgerSubType::class.java).apply {
                        createCriteria().andEqualTo("lScenetype", tzSceneType).andEqualTo("lNeedupdate", true)
                    })
@@ -332,15 +343,49 @@
        private var _ledgerRecordNum: List<LedgerRecord>? = null
        /**
         * 获取当前巡查任务的上期巡查记录
         */
        fun lastOne(): RowData {
            val last = RowData()
            val r = dbMapper.subtaskMapper.selectByExample(Example(Subtask::class.java).apply {
                createCriteria().andEqualTo("scenseid", subTask?.scenseid)
                    .andLessThan("planstarttime", subTask?.planstarttime)
                orderBy("planstarttime").desc()
            })
            if (r.isNotEmpty()) {
                val thisMonth = LocalDateTime.ofInstant(subTask?.planstarttime?.toInstant(), ZoneId.systemDefault()).withDayOfMonth(1).toLocalDate()
                val lastMonth = LocalDateTime.ofInstant(r[0]?.planstarttime?.toInstant(), ZoneId.systemDefault()).withDayOfMonth(1).toLocalDate()
                if (lastMonth.plusMonths(1).isEqual(thisMonth)) {
                    last.subTask = r[0]
                }
            }
            return last
        }
        /**
         * 记录上一个场景
         */
        fun recordLastScene() {
            lastScene = scene
        }
        /**
         * 清空当前处理的对象的相关数据源
         */
        fun clear() {
            _scene = null
            _baseScene = null
            _problems.clear()
            _problems = null
            _evaluation = null
            _itemevaluationList.clear()
            _itemevaluationList = null
            _ledgerRecordNum = null
            if (lastScene != null && lastScene?.typeid != scene?.typeid) {
                _problemTypes = null
                _topItems = null
                _rules = null
                _ledgerCount = -1
            }
            recordLastScene()
        }
        /**
@@ -350,6 +395,7 @@
    }
}
@Component
data class DbMapper(
    val scenseMapper: ScenseMapper,
    val problemlistMapper: ProblemlistMapper,