feiyu02
2022-07-20 39e208b6b0482a25c77e53590087c02d9d937563
src/main/kotlin/cn/flightfeather/supervision/business/report/DataSource.kt
@@ -4,10 +4,18 @@
import cn.flightfeather.supervision.common.utils.DateUtil
import cn.flightfeather.supervision.domain.ds1.entity.*
import cn.flightfeather.supervision.domain.ds1.mapper.*
import cn.flightfeather.supervision.domain.ds2.entity.LedgerRecord
import cn.flightfeather.supervision.domain.ds2.entity.LedgerSubType
import cn.flightfeather.supervision.domain.ds2.entity.UserMap
import cn.flightfeather.supervision.domain.ds2.mapper.LedgerRecordMapper
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
/**
@@ -20,6 +28,12 @@
    private val dateUtil = DateUtil()
    private val sourceList = mutableListOf<Subtask>()
    var year = 0
    var month = 0
    var area = ""
    val rowData = RowData()
@@ -36,6 +50,7 @@
    fun loop(callback: (index:Int, rowData: RowData) -> Unit) {
        reset()
        for (i in sourceList.indices) {
            rowData.index = i
            rowData.clear()
            rowData.subTask = sourceList[i]
            callback(i, rowData)
@@ -46,6 +61,7 @@
     * 重置
     */
    fun reset() {
        rowData.index = 0
        rowData.subTask = sourceList.first()
        rowData.clear()
    }
@@ -55,7 +71,7 @@
     */
    fun areaName(): String {
        val t = dbMapper.taskMapper.selectByPrimaryKey(config.topTaskGuid)
        return "${dateUtil.DateToString(t.starttime, DateUtil.DateStyle.YYYY_MM_CN)}${t.districtname}${Constant.ScenseType.getDes(config.sceneType)}"
        return "${dateUtil.DateToString(t.starttime, DateUtil.DateStyle.YYYY_MM_CN)}${t.districtname}${if (area != t.districtname) area else ""}${Constant.ScenseType.getDes(config.sceneType)}"
    }
    /**
@@ -65,6 +81,19 @@
        if (config.sceneType == null) return
        val result = mutableListOf<Subtask>()
        if (config.townCode != null) {
            dbMapper.townMapper.selectByExample(Example(Town::class.java).apply {
                createCriteria().andEqualTo("towncode", config.townCode)
            })?.takeIf { it.isNotEmpty() }?.get(0)?.let { area = it.townname ?: "" }
        }
        dbMapper.taskMapper.selectByPrimaryKey(config.topTaskGuid).let {
            val time = LocalDateTime.ofInstant(it.starttime?.toInstant(), ZoneId.systemDefault())
            this.year = time.year
            this.month = time.monthValue
            if (area.isBlank()) area = it.districtname ?: ""
        }
        //1. 查找特定的巡查任务或者所有的计划巡查任务
        var taskSceneIdList = listOf<String>()
@@ -109,6 +138,8 @@
    inner class RowData(){
        var index = 0
        var subTask: Subtask? = null
        //场景基本信息
@@ -263,6 +294,43 @@
            }
        private var _rules = mutableListOf<Pair<Evaluationsubrule2, MutableList<Evaluationsubrule2>>>()
        //必填台账数量
        val ledgerCount: Int
            get() {
                if (_ledgerCount == -1) {
                    val tzSceneType = Constant.ScenseType.typeMap(config.sceneType?.toByte())
                    _ledgerCount = dbMapper.ledgerSubTypeMapper.selectCountByExample(Example(LedgerSubType::class.java).apply {
                        createCriteria().andEqualTo("lScenetype", tzSceneType).andEqualTo("lNeedupdate", true)
                    })
                }
                return _ledgerCount
            }
        private var _ledgerCount = -1
        //用户实际提交台账数量
        val ledgerRecords: List<LedgerRecord>
            get() {
                if (_ledgerRecordNum == null) {
                    val userInfo = dbMapper.userinfoMapper.selectByExample(Example(Userinfo::class.java).apply {
                        createCriteria().andEqualTo("dGuid", subTask?.scenseid)
                    })?.takeIf { l -> l.isNotEmpty() }?.get(0)
                    val tzUserId = dbMapper.userMapMapper.selectByExample(Example(UserMap::class.java).apply {
                        createCriteria().andEqualTo("svUserId", userInfo?.guid)
                    })?.takeIf { m-> m.isNotEmpty() }?.get(0)?.tzUserId
                    if (tzUserId != null) {
                        _ledgerRecordNum = dbMapper.ledgerRecordMapper.selectByExample(Example(LedgerRecord::class.java).apply {
                            createCriteria().andEqualTo("lrYear", year)
                                    .andEqualTo("lrMonth", month)
                                    .andEqualTo("lrSubmitid", tzUserId)
                        })
                    }
                }
                return _ledgerRecordNum ?: emptyList()
            }
        private var _ledgerRecordNum: List<LedgerRecord>? = null
        /**
         * 清空当前处理的对象的相关数据源
         */
@@ -272,6 +340,7 @@
            _problems.clear()
            _evaluation = null
            _itemevaluationList.clear()
            _ledgerRecordNum = null
        }
        /**
@@ -295,5 +364,10 @@
    val evaluationruleMapper: EvaluationruleMapper,
    val evaluationsubruleMapper: EvaluationsubruleMapper2,
    val evaluationMapper: EvaluationMapper,
    val itemevaluationMapper: ItemevaluationMapper
    val itemevaluationMapper: ItemevaluationMapper,
    val ledgerSubTypeMapper: LedgerSubTypeMapper,
    val ledgerRecordMapper: LedgerRecordMapper,
    val userinfoMapper: UserinfoMapper,
    val userMapMapper: UserMapMapper,
    val townMapper: TownMapper,
)