From 5a003a42d2b34e8362910ac1d3e5a8866768e5fe Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期六, 20 十二月 2025 16:50:28 +0800
Subject: [PATCH] 2025.12.20 巡查任务统计相关功能修改

---
 src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/SubtaskServiceImpl.kt |  132 ++++++++++++++++++++++++++++++++------------
 1 files changed, 96 insertions(+), 36 deletions(-)

diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/SubtaskServiceImpl.kt b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/SubtaskServiceImpl.kt
index f02a9e1..d264f3c 100644
--- a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/SubtaskServiceImpl.kt
+++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/SubtaskServiceImpl.kt
@@ -33,20 +33,28 @@
 
     @Autowired
     lateinit var taskService: TaskService
+
     @Autowired
     lateinit var taskMapper: TaskMapper
+
     @Autowired
     lateinit var evaluationMapper: EvaluationMapper
+
     @Autowired
     lateinit var problemlistMapper: ProblemlistMapper
+
     @Autowired
     lateinit var mediafileMapper: MediafileMapper
+
     @Autowired
     lateinit var scenseMapper: ScenseMapper
+
     @Autowired
     lateinit var inspectionMapper: InspectionMapper
+
     @Autowired
     lateinit var monitorobjectversionMapper: MonitorobjectversionMapper
+
     @Autowired
     lateinit var problemtypeMapper: ProblemtypeMapper
 
@@ -65,11 +73,11 @@
             criteria.andEqualTo("towncode", areaVo.towncode)
         criteria.andBetween("planstarttime", areaVo.starttime, areaVo.endtime)
         if (!Objects.equals(userGuid, Constant.UserType.ALL_USER.des))
-            criteria.andLike("executorguids","%"+userGuid+"%")
+            criteria.andLike("executorguids", "%" + userGuid + "%")
         var completecount = 0
         var subtasklist = subtaskMapper.selectByExample(example)
         subtasklist.forEach {
-            if (Objects.equals(it.status, Constant.TaskProgress.RUNINGSTATUS3.text)){
+            if (Objects.equals(it.status, Constant.TaskProgress.RUNINGSTATUS3.text)) {
                 completecount++
             }
         }
@@ -102,24 +110,26 @@
         criteria.andEqualTo("tsguid", dayTaskId)
         if (userType == "1") {
             example.and(
-                    example.createCriteria().orLike("executorguids", "%$userId%")
-                            .orLike("stAssessorguid", "%$userId%")
+                example.createCriteria().orLike("executorguids", "%$userId%")
+                    .orLike("stAssessorguid", "%$userId%")
             )
         }
         example.orderBy("name")
-        val result = subtaskMapper.selectByExample(example).apply{
+        val result = subtaskMapper.selectByExample(example).apply {
             forEach breaking@{
                 //宸插鏍告彁绀�
-                it.remark= Constant.PROBLEM_CHECK_PASS
+                it.remark = Constant.PROBLEM_CHECK_PASS
 
                 problemlistMapper.selectByExample(Example(Problemlist::class.java).apply {
                     createCriteria().andEqualTo("stguid", it.stguid)
-                    and(createCriteria().orIsNull("remark")
-                            .orNotEqualTo("remark", Constant.PROBLEM_DELETED))
-                }).forEach {problem ->
+                    and(
+                        createCriteria().orIsNull("remark")
+                            .orNotEqualTo("remark", Constant.PROBLEM_DELETED)
+                    )
+                }).forEach { problem ->
                     //瀛愪换鍔′腑鏈夐棶棰樻湭瀹℃牳鏃讹紝璁剧疆鏈鏍告彁绀�
                     if (problem.extension3 == Constant.PROBLEM_UNCHECKED) {
-                        it.remark= Constant.PROBLEM_UNCHECKED
+                        it.remark = Constant.PROBLEM_UNCHECKED
                         return@breaking
                     }
                 }
@@ -168,13 +178,13 @@
         } else {
             guid
         }
-        val userTypeId = if (userType == "涓荤閮ㄩ棬"){
+        val userTypeId = if (userType == "涓荤閮ㄩ棬") {
             "2"
-        }else if (userType == "椋炵窘鐢ㄦ埛") {
+        } else if (userType == "椋炵窘鐢ㄦ埛") {
             "1"
-        } else if(userType == "绠$悊鍛�"){
+        } else if (userType == "绠$悊鍛�") {
             "0"
-        }else if (userType == "鍦烘櫙") {
+        } else if (userType == "鍦烘櫙") {
             "3"
         } else {
             userType
@@ -197,16 +207,19 @@
                 two = dateString
                 three = DateUtil.addMonth(dateString, 1)
             }
+
             "Left" -> {
                 one = DateUtil.addMonth(dateString, 1)
                 two = DateUtil.addMonth(dateString, 2)
                 three = DateUtil.addMonth(dateString, 3)
             }
+
             "Right" -> {
                 one = DateUtil.addMonth(dateString, -1)
                 two = DateUtil.addMonth(dateString, -2)
                 three = DateUtil.addMonth(dateString, -3)
             }
+
             else -> {
                 //鍙傛暟涓嶆纭氨杩斿洖
                 return taskPackList
@@ -251,16 +264,19 @@
                 two = dateString
                 three = DateUtil.addMonth(dateString, 1)
             }
+
             "Left" -> {
                 one = DateUtil.addMonth(dateString, 1)
                 two = DateUtil.addMonth(dateString, 2)
                 three = DateUtil.addMonth(dateString, 3)
             }
+
             "Right" -> {
                 one = DateUtil.addMonth(dateString, -1)
                 two = DateUtil.addMonth(dateString, -2)
                 three = DateUtil.addMonth(dateString, -3)
             }
+
             else -> {
                 //鍙傛暟涓嶆纭氨杩斿洖
                 return taskPackList
@@ -422,21 +438,22 @@
             subtask.tsguid = daytaskVo.tguid
             //*锛堜慨鏀癸級*鏃ヤ换鍔℃鍦ㄦ墽琛岋紝瀛愪换鍔$粨鏉燂紝閬嶅巻鎵�鏈夊叾浣欏瓙浠诲姟锛岄兘鏄粨鏉熸椂鎵嶅皢鏃ヤ换鍔′慨鏀逛负缁撴潫****
             if (subtask.status == Constant.TaskProgress.RUNINGSTATUS3.text
-                && daytaskVo.runingstatus == Constant.TaskProgress.RUNINGSTATUS2.text){
+                && daytaskVo.runingstatus == Constant.TaskProgress.RUNINGSTATUS2.text
+            ) {
                 val subtaskVolist = findByDayTaskID(daytaskVo.tguid!!)
                 var bool = false
                 subtaskVolist.forEach {
-                    if (it.status != Constant.TaskProgress.RUNINGSTATUS3.text){
+                    if (it.status != Constant.TaskProgress.RUNINGSTATUS3.text) {
                         bool = true
                     }
                 }
-                if (!bool){
+                if (!bool) {
                     daytaskVo.runingstatus = Constant.TaskProgress.RUNINGSTATUS3.text
                 }
 
             }
             //涓よ�呯姸鎬佺浉鍚屾椂涓嶅仛淇敼锛屽叾浣欐儏鍐垫棩浠诲姟閮戒负姝e湪鎵ц
-            else if (subtask.status != daytaskVo.runingstatus){
+            else if (subtask.status != daytaskVo.runingstatus) {
                 daytaskVo.runingstatus = Constant.TaskProgress.RUNINGSTATUS2.text
             }
             val daytask = Task()
@@ -465,7 +482,7 @@
     }
 
     @Transactional
-    override fun delete(id: String): Int{
+    override fun delete(id: String): Int {
         val subtask = subtaskMapper.selectByPrimaryKey(id)
         val dayTaskId = subtask.tsguid
         subtaskMapper.deleteByPrimaryKey(id)
@@ -500,7 +517,15 @@
     }
 
 
-    override fun searchSubTask(token: String, sceneType: Int?, districtCode: String?, startTime: String?, endTime: String?, page: Int?, perPage: Int?): BaseSearchResultVo {
+    override fun searchSubTask(
+        token: String,
+        sceneType: Int?,
+        districtCode: String?,
+        startTime: String?,
+        endTime: String?,
+        page: Int?,
+        perPage: Int?,
+    ): BaseSearchResultVo {
         if (token != "jingan") {
             return BaseSearchResultVo().apply {
                 head = DataHead().apply {
@@ -543,7 +568,7 @@
 //        val  p = PageHelper.startPage<Subtask>(page ?: 1, perPage ?: 30)
         subtaskMapper.getSubtask2(null, null, _districtCode, _sceneType.toByte(), _startTime, _endTime).forEach {
             if (!subtaskMap.containsKey(it.subTaskId)) {
-                val vo =SubtaskSearchResultVo()
+                val vo = SubtaskSearchResultVo()
                 BeanUtils.copyProperties(it, vo)
                 subtaskMap[it.subTaskId] = vo
             }
@@ -553,7 +578,7 @@
                 problemMap[it.problemId] = problemDetail
                 subtaskMap[it.subTaskId]?.problemList?.add(problemDetail)
             }
-            val url = it.mExtension1 + it.mGuid+ ".jpg"
+            val url = it.mExtension1 + it.mGuid + ".jpg"
             if (it.isChanged == true) {
                 problemMap[it.problemId]?.rectificationPics?.add(url)
             } else {
@@ -647,8 +672,10 @@
                         .andNotEqualTo("extension3", Constant.CHANGE_CHECK_FAIL)
                         .andIsNotNull("extension3")
                     time?.let {
-                        and(createCriteria().orGreaterThan("time", it)
-                            .orGreaterThan("changedtime", it))
+                        and(
+                            createCriteria().orGreaterThan("time", it)
+                                .orGreaterThan("changedtime", it)
+                        )
                     }
                 }).forEach { p ->
                     val problem = ProblemDetail().apply {
@@ -743,7 +770,16 @@
         return BaseResponse(true, "璇锋眰鎴愬姛", data = result)
     }
 
-    override fun searchSubTask3(token: String, updateTime: String?, sceneType: Int?, districtCode: String?, startTime: String?, endTime: String?, page: Int?, perPage: Int?): BaseResponse<BaseSearchResultVo> {
+    override fun searchSubTask3(
+        token: String,
+        updateTime: String?,
+        sceneType: Int?,
+        districtCode: String?,
+        startTime: String?,
+        endTime: String?,
+        page: Int?,
+        perPage: Int?,
+    ): BaseResponse<BaseSearchResultVo> {
         if (token != "jinshan") {
             return BaseResponse(false, "璇锋眰token閿欒")
         }
@@ -798,8 +834,10 @@
                         .andNotEqualTo("extension3", Constant.CHANGE_CHECK_FAIL)
                         .andIsNotNull("extension3")
                     time?.let {
-                        and(createCriteria().orGreaterThan("time", it)
-                            .orGreaterThan("changedtime", it))
+                        and(
+                            createCriteria().orGreaterThan("time", it)
+                                .orGreaterThan("changedtime", it)
+                        )
                     }
                 }).forEach { p ->
                     val problem = ProblemDetail().apply {
@@ -868,7 +906,7 @@
 //            val p = PageHelper.startPage<Subtask>(page ?: 1, perPage ?: 30)
             subtaskMapper.getSubtask2(time, time2, _districtCode, _sceneType?.toByte(), null, null).forEach {
                 if (!subtaskMap.containsKey(it.subTaskId)) {
-                    val vo =SubtaskSearchResultVo()
+                    val vo = SubtaskSearchResultVo()
                     BeanUtils.copyProperties(it, vo)
                     subtaskMap[it.subTaskId] = vo
                 }
@@ -878,7 +916,7 @@
                     problemMap[it.problemId] = problemDetail
                     subtaskMap[it.subTaskId]?.problemList?.add(problemDetail)
                 }
-                val url = it.mExtension1 + it.mGuid+ ".jpg"
+                val url = it.mExtension1 + it.mGuid + ".jpg"
                 if (it.isChanged == true) {
                     problemMap[it.problemId]?.rectificationPics?.add(url)
                 } else {
@@ -899,15 +937,37 @@
         return BaseResponse(true, "璇锋眰鎴愬姛", data = result)
     }
 
-    override fun findByDate(date: String, userId: String): List<SubtaskVo> {
-        val time = DateUtil.StringToDate(date)
+    override fun findByDate(date: String?, userId: String?, sceneId: String?): List<SubtaskVo> {
+        val time = if (date == null) null else DateUtil.StringToDate(date)
 
         val resultList = mutableListOf<SubtaskVo>()
 
-        subtaskMapper.selectByExample(Example(Subtask::class.java).apply {
-            createCriteria().andLessThanOrEqualTo("planstarttime", time)
+        val subtasks = if (time != null) {
+            // 鑾峰彇鏌愪竴澶╃殑宸℃煡浠诲姟
+            subtaskMapper.selectByExample(Example(Subtask::class.java).apply {
+                createCriteria().andLessThanOrEqualTo("planstarttime", time)
                     .andGreaterThanOrEqualTo("planendtime", time)
-        }).forEach {
+                    .apply { sceneId?.let { andEqualTo("scenseid", it) } }
+            })
+        } else {
+            // 鑾峰彇鏈�杩戜竴涓湀鍐呯殑锛堟煇涓満鏅殑锛夋墍鏈夊贰鏌ヤ换鍔�
+            PageHelper.startPage<Subtask>(1, 1)
+            val lastOne = subtaskMapper.selectByExample(Example(Subtask::class.java).apply {
+                createCriteria().apply {
+                    sceneId?.let { andEqualTo("scenseid", it) }
+                }
+                orderBy("planstarttime").desc()
+            }).takeIf { it.isNotEmpty() }?.get(0)
+            if (lastOne == null) {
+                emptyList()
+            } else {
+                subtaskMapper.selectByExample(Example(Subtask::class.java).apply {
+                    createCriteria().andEqualTo("tguid", lastOne.tguid)
+                        .andEqualTo("scenseid", lastOne.scenseid)
+                })
+            }
+        }
+        subtasks.forEach {
             val vo = SubtaskVo()
             BeanUtils.copyProperties(it, vo)
             resultList.add(vo)
@@ -920,7 +980,7 @@
         topTaskId: String,
         startTime: String?,
         endTime: String?,
-        sceneTypeId: Int?
+        sceneTypeId: Int?,
     ): List<Subtask> {
 
         return subtaskMapper.selectByTopTask2(topTaskId, sceneTypeId)
@@ -933,7 +993,7 @@
     override fun getTaskProgressByArea(areaVo: AreaVo): List<TaskProgressVo> {
 //        areaVo.scensetypeid ?: throw BizException("缂哄皯鍦烘櫙绫诲瀷鍙傛暟")
         val res = mutableListOf<TaskProgressVo>()
-        taskRep.findTasks(areaVo).forEach {t->
+        taskRep.findTasks(areaVo).forEach { t ->
             if (t?.tguid == null) return@forEach
             val pro = TaskProgressVo().apply {
                 tguid = t.tguid

--
Gitblit v1.9.3