From 909fd8929d7906f1dca68acc05e36e29b0b9192c Mon Sep 17 00:00:00 2001 From: feiyu02 <risaku@163.com> Date: 星期二, 15 十一月 2022 10:57:30 +0800 Subject: [PATCH] 2022.11.15 --- src/main/kotlin/cn/flightfeather/supervision/business/report/DataSource.kt | 137 +++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 123 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/cn/flightfeather/supervision/business/report/DataSource.kt b/src/main/kotlin/cn/flightfeather/supervision/business/report/DataSource.kt index 77154e7..3d715f9 100644 --- a/src/main/kotlin/cn/flightfeather/supervision/business/report/DataSource.kt +++ b/src/main/kotlin/cn/flightfeather/supervision/business/report/DataSource.kt @@ -4,10 +4,19 @@ 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.Duration +import java.time.LocalDateTime +import java.time.ZoneId import javax.annotation.PostConstruct /** @@ -21,21 +30,28 @@ private val sourceList = mutableListOf<Subtask>() + var year = 0 + + var month = 0 + + var area = "" + 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() for (i in sourceList.indices) { + rowData.index = i rowData.clear() rowData.subTask = sourceList[i] callback(i, rowData) @@ -46,6 +62,7 @@ * 閲嶇疆 */ fun reset() { + rowData.index = 0 rowData.subTask = sourceList.first() rowData.clear() } @@ -55,16 +72,29 @@ */ 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)}" } /** - * 鑾峰彇鎶ュ憡鏁版嵁婧� + * 鑾峰彇鎶ュ憡鏁版嵁婧愶紙宸℃煡浠诲姟锛� */ private fun getSource(config: ExcelConfigVo) { - if (config.sceneType == null) return +// 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>() @@ -78,10 +108,12 @@ } 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) + taskSceneIdList = dbMapper.monitorobjectversionMapper.getSceneByType(config.topTaskGuid, config.sceneType, config.townCode) dbMapper.subtaskMapper.selectByExample(Example(Subtask::class.java).apply { createCriteria().andIn("scenseid", taskSceneIdList) .andEqualTo("tguid", config.topTaskGuid) @@ -109,7 +141,11 @@ inner class RowData(){ + var index = 0 + var subTask: Subtask? = null + + private var lastScene: Scense? = null //鍦烘櫙鍩烘湰淇℃伅 val scene: Scense? @@ -160,6 +196,7 @@ } private var _problems = mutableListOf<Problemlist>() + //璇勪及鎬诲垎 val evaluation: Evaluation? get() { if (_evaluation == null) { @@ -173,6 +210,7 @@ } private var _evaluation: Evaluation? = null + //璇勪及缁嗗垯寰楀垎 val itemevaluationList: MutableList<Itemevaluation> get() { if (_itemevaluationList.isEmpty()) { @@ -191,8 +229,8 @@ get() { if (_problemTypes.isEmpty()) { 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) @@ -208,7 +246,7 @@ 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 @@ -263,15 +301,81 @@ } private var _rules = mutableListOf<Pair<Evaluationsubrule2, MutableList<Evaluationsubrule2>>>() + //蹇呭~鍙拌处鏁伴噺 + val ledgerCount: Int + get() { + if (_ledgerCount == -1) { + val tzSceneType = Constant.ScenseType.typeMap(scene?.typeid) + _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 + + /** + * 鑾峰彇褰撳墠宸℃煡浠诲姟鐨勪笂鏈熷贰鏌ヨ褰� + */ + 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 clear() { + if (lastScene != null && lastScene?.typeid != _scene?.typeid) { + _problemTypes.clear() + _topItems.clear() + _rules.clear() + _ledgerCount = -1 + } else { + lastScene = _scene + } _scene = null _baseScene = null _problems.clear() _evaluation = null _itemevaluationList.clear() + _ledgerRecordNum = null } /** @@ -295,5 +399,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, ) -- Gitblit v1.9.3