| | |
| | | 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 javax.annotation.PostConstruct |
| | | import java.time.LocalDateTime |
| | | import java.time.ZoneId |
| | | |
| | | /** |
| | | * 报告所需源数据 |
| | |
| | | |
| | | 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() |
| | | // reset() |
| | | for (i in sourceList.indices) { |
| | | rowData.clear() |
| | | // rowData.recordLastScene() |
| | | rowData.index = i |
| | | rowData.subTask = sourceList[i] |
| | | rowData.clear() |
| | | callback(i, rowData) |
| | | } |
| | | } |
| | |
| | | * 重置 |
| | | */ |
| | | fun reset() { |
| | | rowData.index = 0 |
| | | rowData.subTask = sourceList.first() |
| | | rowData.clear() |
| | | } |
| | |
| | | */ |
| | | 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.SceneType.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>() |
| | |
| | | } |
| | | 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) |
| | |
| | | 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) |
| | |
| | | |
| | | |
| | | inner class RowData(){ |
| | | var index = 0 |
| | | |
| | | var subTask: Subtask? = null |
| | | |
| | | private var lastScene: Scense? = null |
| | | |
| | | //场景基本信息 |
| | | val scene: Scense? |
| | |
| | | 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 |
| | |
| | | } |
| | | private var _problems = mutableListOf<Problemlist>() |
| | | |
| | | //评估总分 |
| | | val evaluation: Evaluation? |
| | | get() { |
| | | if (_evaluation == null) { |
| | |
| | | } |
| | | private var _evaluation: Evaluation? = null |
| | | |
| | | //评估细则得分 |
| | | val itemevaluationList: MutableList<Itemevaluation> |
| | | get() { |
| | | if (_itemevaluationList.isEmpty()) { |
| | |
| | | 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) |
| | |
| | | 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 |
| | |
| | | } |
| | | private var _rules = mutableListOf<Pair<Evaluationsubrule2, MutableList<Evaluationsubrule2>>>() |
| | | |
| | | //必填台账数量 |
| | | val ledgerCount: Int |
| | | get() { |
| | | if (_ledgerCount == -1) { |
| | | val tzSceneType = Constant.SceneType.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 recordLastScene() { |
| | | lastScene = scene |
| | | } |
| | | |
| | | /** |
| | | * 清空当前处理的对象的相关数据源 |
| | | */ |
| | |
| | | _problems.clear() |
| | | _evaluation = null |
| | | _itemevaluationList.clear() |
| | | _ledgerRecordNum = null |
| | | if (lastScene != null && lastScene?.typeid != scene?.typeid) { |
| | | _problemTypes.clear() |
| | | _topItems.clear() |
| | | _rules.clear() |
| | | _ledgerCount = -1 |
| | | } |
| | | recordLastScene() |
| | | } |
| | | |
| | | /** |
| | |
| | | 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, |
| | | ) |