From 9de446b0b83610055437fbc5172d216bb374900f Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期四, 21 十一月 2024 09:22:19 +0800
Subject: [PATCH] 1. 2024.11.21 修复部分bug

---
 src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ProblemlistServiceImpl.kt |  378 +++++++++++++++++++++++++++++++++++------------------
 1 files changed, 248 insertions(+), 130 deletions(-)

diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ProblemlistServiceImpl.kt b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ProblemlistServiceImpl.kt
index f2a1191..02d7b7c 100644
--- a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ProblemlistServiceImpl.kt
+++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ProblemlistServiceImpl.kt
@@ -1,19 +1,25 @@
 package cn.flightfeather.supervision.lightshare.service.impl
 
-import cn.flightfeather.supervision.domain.ds1.entity.Problemlist
-import cn.flightfeather.supervision.domain.ds1.entity.Scense
+import cn.flightfeather.supervision.common.exception.BizException
+import cn.flightfeather.supervision.common.log.BizLog
+import cn.flightfeather.supervision.common.log.WorkStreamLogInfo
 import cn.flightfeather.supervision.common.utils.Constant
 import cn.flightfeather.supervision.common.utils.FileUtil
 import cn.flightfeather.supervision.common.utils.UUIDGenerator
-import cn.flightfeather.supervision.domain.ds1.entity.Mediafile
+import cn.flightfeather.supervision.domain.ds1.entity.*
 import cn.flightfeather.supervision.domain.ds1.mapper.*
+import cn.flightfeather.supervision.domain.ds1.repository.ProblemRep
+import cn.flightfeather.supervision.domain.ds1.repository.SubTaskRep
+import cn.flightfeather.supervision.domain.ds1.repository.TaskRep
 import cn.flightfeather.supervision.lightshare.service.MediafileService
 import cn.flightfeather.supervision.lightshare.service.ProblemlistService
 import cn.flightfeather.supervision.lightshare.service.TaskService
 import cn.flightfeather.supervision.lightshare.vo.*
 import com.fasterxml.jackson.core.type.TypeReference
 import com.fasterxml.jackson.databind.ObjectMapper
+import com.github.pagehelper.PageHelper
 import org.springframework.beans.BeanUtils
+import org.springframework.beans.factory.annotation.Value
 import org.springframework.stereotype.Service
 import org.springframework.web.multipart.MultipartFile
 import tk.mybatis.mapper.entity.Example
@@ -21,7 +27,9 @@
 import java.text.SimpleDateFormat
 import javax.annotation.Resource
 import java.math.BigDecimal
+import java.time.LocalDate
 import java.time.LocalDateTime
+import java.time.ZoneId
 import java.time.format.DateTimeFormatter
 import java.util.*
 
@@ -30,43 +38,53 @@
 class ProblemlistServiceImpl(
     val problemlistMapper: ProblemlistMapper,
     val inspectionMapper: InspectionMapper,
-    val mediafileMapper: MediafileMapper
+    val mediafileMapper: MediafileMapper,
+    private val taskRep: TaskRep,
+    private val subTaskRep: SubTaskRep,
+    private val problemRep: ProblemRep,
+    private val bizLog: BizLog,
+    @Value("\${filePath}") var filePath: String,
+    @Value("\${imgPath}") var imgPath: String,
 ) : ProblemlistService {
 
     @Resource
     lateinit var scenseMapper: ScenseMapper
+
     @Resource
     lateinit var problemtypeMapper: ProblemtypeMapper
+
     @Resource
     lateinit var taskMapper: TaskMapper
+
     @Resource
     lateinit var taskService: TaskService
+
     @Resource
     lateinit var mediafileService: MediafileService
 
-    override fun getByTopTask(tguid: String): List<ProblemlistVo> {
+    override fun getByTopTask(tguid: String): List<ProblemListVo> {
         TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
     }
 
     //鏍规嵁鍦烘櫙id鍜屾椂闂磋幏鍙栧搴旈《灞備换鍔′笅鐨勬墍鏈夐棶棰�
-    override fun getProblemByScene(sceneId: String, date: String): List<ProblemlistVo> {
+    override fun getProblemByScene(sceneId: String, date: String): List<ProblemListVo> {
         val simpleDateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
         val date1 = simpleDateFormat.parse(date)
         val scene = scenseMapper.selectByPrimaryKey(sceneId)
         val district = scene.districtcode
         val taskVolist = taskService.getByDistrictCode(district!!, date1)
-        val problemlistVolistTemp1 = mutableListOf<ProblemlistVo>()
+        val problemListVolistTemp1 = mutableListOf<ProblemListVo>()
         if (!taskVolist.isEmpty()) {
             val problemlists = (problemlistMapper.getProblemByScene(sceneId, taskVolist[0].tguid!!))
             problemlists.forEach {
                 // 闄愬埗浼佷笟鏌ョ湅鏈鏍哥殑闂
                 if (it.extension3 != Constant.PROBLEM_UNCHECKED && it.extension3 != Constant.PROBLEM_CHECK_FAIL) {
-                    val problemVo = ProblemlistVo();
+                    val problemVo = ProblemListVo();
                     BeanUtils.copyProperties(it, problemVo)
-                    problemlistVolistTemp1.add(problemVo)
+                    problemListVolistTemp1.add(problemVo)
                 }
             }
-            problemlistVolistTemp1.forEach {
+            problemListVolistTemp1.forEach {
                 if (it.ptguid != null) {
                     val tmp1 = problemtypeMapper.selectByPrimaryKey(it.ptguid)
                     if (tmp1 != null) {
@@ -84,7 +102,7 @@
                 }
             }
         }
-        return problemlistVolistTemp1
+        return problemListVolistTemp1
     }
 
     //鑾峰彇鏌愰《灞備换鍔′笅锛屾煇涓満鏅笅鐨勯棶棰樻暣鏀规儏鍐�
@@ -112,28 +130,11 @@
 
     //鏍规嵁鍖哄幙銆佸満鏅被鍨嬨�佹椂闂磋幏鍙栧悇涓棶棰樻暟閲�
     override fun getStatisticalResult(areaVo: AreaVo): List<StatisticsVo> {
-        val districtcode = areaVo.districtcode
-        val sceneType = areaVo.scensetypeid
-        val startTime = areaVo.starttime
-        val endTime = areaVo.endtime
-        val maps = problemlistMapper.getStatisticalResult(districtcode,startTime, endTime, sceneType)
-        val statisticsVos = mutableListOf<StatisticsVo>()
-        maps.forEach {
-            if (!it.isEmpty() && it.get("name") != null) {
-                val statisticsVo = StatisticsVo()
-                statisticsVo.name = it.get("name").toString()
-                try {
-                    statisticsVo.count = it.get("count").toString().toInt()
-                } catch (e: Exception) {
-                }
-                try {
-                    statisticsVo.changeCount = it.get("changeCount").toString().toInt()
-                } catch (e: Exception) {
-                }
-                statisticsVos.add(statisticsVo)
-            }
-        }
-        return statisticsVos
+//        val districtcode = areaVo.districtcode
+//        val sceneType = areaVo.scensetypeid
+//        val startTime = areaVo.starttime?.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
+//        val endTime = areaVo.endtime?.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
+        return problemlistMapper.getStatisticalResult(areaVo)
     }
 
     override fun getChargeResult(areaVo: AreaVo): ChargeInfoVo {
@@ -144,7 +145,12 @@
 //                .andGreaterThanOrEqualTo("endtime", areaVo.endtime)
 //                .andEqualTo("districtcode", areaVo.districtcode)
         val chargeInfoVo = ChargeInfoVo()
-        val sql = "select T_GUID, T_Name from tm_t_task where TS_GUID IS NULL and T_StartTime <= '" + areaVo.starttime + "' and T_EndTime >= '" + areaVo.endtime + "' and T_DistrictCode = '" + areaVo.districtcode +"'"
+        val sTime = areaVo.starttime?.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
+        val eTime = areaVo.endtime?.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
+        val sql =
+            "select T_GUID, T_Name from tm_t_task where TS_GUID IS NULL and T_StartTime <= '" + sTime + "' and T_EndTime" +
+                    " >= '" + eTime + "' and T_DistrictCode = '" + areaVo.districtcode + "'"
+
         val maps1 = taskMapper.selectSE(sql)
         var topTaskId = String()
         var topTaskName = String()
@@ -165,7 +171,7 @@
             } catch (e: Exception) {
             }
             try {
-                sceneInfo.changeCount  =it.get("changeCount").toString().toInt()
+                sceneInfo.changeCount = it.get("changeCount").toString().toInt()
             } catch (e: Exception) {
             }
             chargeInfoVo.sceneInfos.add(sceneInfo)
@@ -184,16 +190,16 @@
                 var curScore = -1
                 if (it.get("scoreAft") != null) {
                     curScore = it.get("scoreAft").toString().toInt()
-                }else if (it.get("scoreBef") != null) {
+                } else if (it.get("scoreBef") != null) {
                     curScore = it.get("scoreBef").toString().toInt()
                 }
                 if (curScore >= 100) {
                     scoreInfo1.count++
-                }else if (curScore >= 78 && curScore < 100) {
+                } else if (curScore >= 78 && curScore < 100) {
                     scoreInfo2.count++
-                }else if (curScore >= 54 && curScore < 78) {
+                } else if (curScore >= 54 && curScore < 78) {
                     scoreInfo3.count++
-                }else if (curScore < 54 && curScore >= 0) {
+                } else if (curScore < 54 && curScore >= 0) {
                     scoreInfo4.count++
                 }
             }
@@ -207,8 +213,8 @@
     }
 
     //鏍规嵁鍦板煙鑾峰彇闂
-    override fun getByArea(areaVo: AreaVo):List<ProblemlistVo> {
-        val problemlist = mutableListOf<ProblemlistVo>()
+    override fun getByArea(areaVo: AreaVo): List<ProblemListVo> {
+        val problemlist = mutableListOf<ProblemListVo>()
 //        val tmpproblemlsit = mutableListOf<Problemlist>()
         val example = Example(Scense::class.java)
         val criteria = example.createCriteria()
@@ -223,8 +229,8 @@
             criteria.andEqualTo("towncode", areaVo.towncode)
         criteria.andEqualTo("typeid", areaVo.scensetypeid)
         val result1 = scenseMapper.selectByExample(example)
-        if (result1.isNotEmpty()){
-            result1.forEach{
+        if (result1.isNotEmpty()) {
+            result1.forEach {
                 val tmpexample = Example(Problemlist::class.java)
                 val tmpcriteria = tmpexample.createCriteria()
                 //瀵逛簬纭畾鐨勬瘡涓満鏅紝鏍规嵁鏃堕棿鏌ヨ闂
@@ -232,7 +238,7 @@
                 tmpcriteria.andBetween("time", areaVo.starttime, areaVo.endtime)
                 val tmp = problemlistMapper.selectByExample(tmpexample)
                 tmp.forEach {
-                    val problem = ProblemlistVo();
+                    val problem = ProblemListVo();
                     BeanUtils.copyProperties(it, problem)
                     problemlist.add(problem)
                 }
@@ -252,47 +258,47 @@
     }
 
     //鏍规嵁宸℃煡ID鑾峰彇闂
-    override fun findByInspectionID(inspectionID: String): List<ProblemlistVo> {
-        val problemlistVoList = mutableListOf<ProblemlistVo>()
+    override fun findByInspectionID(inspectionID: String): List<ProblemListVo> {
+        val problemListVoList = mutableListOf<ProblemListVo>()
         val problemlist = Problemlist()
         problemlist.iguid = inspectionID
         val problemlists = problemlistMapper.select(problemlist)
         problemlists.forEach {
-            val problemlistVo = ProblemlistVo()
+            val problemlistVo = ProblemListVo()
             if (it.remark != Constant.PROBLEM_DELETED) {
                 BeanUtils.copyProperties(it, problemlistVo)
-                problemlistVoList.add(problemlistVo)
+                problemListVoList.add(problemlistVo)
             }
         }
         //鎺掑簭
-        problemlistVoList.sortBy { it.time }
-        return problemlistVoList
+        problemListVoList.sortBy { it.time }
+        return problemListVoList
     }
 
     //鏂板涓�涓棶棰�
-    override fun addProblem(problemlistVo: ProblemlistVo) {
+    override fun addProblem(problemlistVo: ProblemListVo) {
         val probemlist = Problemlist()
         BeanUtils.copyProperties(problemlistVo, probemlist)
         problemlistMapper.insert(probemlist)
     }
 
     //鏍规嵁瀛愪换鍔D鏌ヨ闂
-    override fun findBySubtaskId(subTaskID: String): List<ProblemlistVo> {
-        val problemlistVoList = mutableListOf<ProblemlistVo>()
+    override fun findBySubtaskId(subTaskID: String): List<ProblemListVo> {
+        val problemListVoList = mutableListOf<ProblemListVo>()
         val problemlist = Problemlist()
         problemlist.stguid = subTaskID
         val problemlists = problemlistMapper.select(problemlist)
         problemlists.forEach {
-            val problemlistVo = ProblemlistVo()
+            val problemlistVo = ProblemListVo()
             BeanUtils.copyProperties(it, problemlistVo)
-            problemlistVoList.add(problemlistVo)
+            problemListVoList.add(problemlistVo)
         }
-        return problemlistVoList
+        return problemListVoList
     }
 
     //鏍规嵁闂ID鑾峰彇涓�涓棶棰�
-    override fun findByID(id: String): ProblemlistVo {
-        val problemlistVo = ProblemlistVo()
+    override fun findByID(id: String): ProblemListVo {
+        val problemlistVo = ProblemListVo()
         val problemlist = problemlistMapper.selectByPrimaryKey(id)
         if (problemlist != null) {
             BeanUtils.copyProperties(problemlist, problemlistVo)
@@ -321,6 +327,12 @@
                 mediafileMapper.deleteByExample(Example(Mediafile::class.java).apply {
                     createCriteria().andEqualTo("businessguid", id)
                 })
+                //鏇存柊宸℃煡淇℃伅涓殑闂鏁伴噺
+                val inspection = inspectionMapper.selectByPrimaryKey(p.iguid)
+                if (inspection.problemcount != null && inspection.problemcount!! > 0) {
+                    inspection.problemcount = inspection.problemcount!! - 1
+                    inspectionMapper.updateByPrimaryKey(inspection)
+                }
                 BaseResponse(true, "闂鍒犻櫎鎴愬姛", data = i)
             }
         }
@@ -332,74 +344,99 @@
 
     override fun findMonthProblemById(taskId: String, sceneId: Int?): List<MonthProblemVo> {
         val monthProblemlistVoList = mutableListOf<MonthProblemVo>()
-        var map = problemlistMapper.findMonthProblemById(taskId,sceneId)
+        var map = problemlistMapper.findMonthProblemById(taskId, sceneId)
         map.forEach { m ->
             val monthProblemVo = MonthProblemVo()
-            monthProblemVo.townCode =if(m.get("towncode")!= null) BigDecimal(m.get("towncode").toString()).toString() else null
+            monthProblemVo.townCode =
+                if (m.get("towncode") != null) BigDecimal(m.get("towncode").toString()).toString() else null
             monthProblemVo.townName = if (m.get("townname") != null) m.get("townname").toString() else null
-            monthProblemVo.scenetype =if (m.get("scenetype") != null) m.get("scenetype").toString().toInt()else null
-            monthProblemVo.scenetypename =if(m.get("scenetypename") != null)m.get("scenetypename").toString()else null
-            monthProblemVo.totalscenecount =if(m.get("totalscenecount") != null)m.get("totalscenecount").toString().toInt()else null
-            monthProblemVo.problemscenes =if(m.get("problemscenes") != null)m.get("problemscenes").toString().toInt()else null
-            monthProblemVo.totalproblems =if(m.get("totalproblems") != null)m.get("totalproblems").toString().toInt()else null
-            monthProblemVo.changedproblems =if(m.get("changedproblems") != null)m.get("changedproblems").toString().toInt()else null
+            monthProblemVo.scenetype = if (m.get("scenetype") != null) m.get("scenetype").toString().toInt() else null
+            monthProblemVo.scenetypename =
+                if (m.get("scenetypename") != null) m.get("scenetypename").toString() else null
+            monthProblemVo.totalscenecount =
+                if (m.get("totalscenecount") != null) m.get("totalscenecount").toString().toInt() else null
+            monthProblemVo.problemscenes =
+                if (m.get("problemscenes") != null) m.get("problemscenes").toString().toInt() else null
+            monthProblemVo.totalproblems =
+                if (m.get("totalproblems") != null) m.get("totalproblems").toString().toInt() else null
+            monthProblemVo.changedproblems =
+                if (m.get("changedproblems") != null) m.get("changedproblems").toString().toInt() else null
             monthProblemlistVoList.add(monthProblemVo)
         }
         return monthProblemlistVoList;
     }
 
-    override fun check(pId: String, action: Byte, remark: String, userId: String, userName: String): BaseResponse<String> {
+    override fun check(
+        pId: String,
+        action: Byte,
+        remark: String,
+        userId: String,
+        userName: String,
+    ): BaseResponse<String> {
         if (action !in 0..3) {
             return BaseResponse(false, "闈炴硶鐨勬搷浣滄寚浠�")
         }
         val p = problemlistMapper.selectByPrimaryKey(pId) ?: return BaseResponse(false, "闂涓嶅瓨鍦�")
+        val subtask = p.stguid?.let { subTaskRep.findOne(it) }
         val response = BaseResponse<String>(true)
+        var event = ""
 
         p.apply {
             this.remark = userName
             if (extension3 == Constant.PROBLEM_UNCHECKED) {
+                event = "鍦�${subtask?.scensename}瀹℃牳浜嗕竴涓棶棰�"
                 when (action) {
-                    0.toByte() -> extension3 = Constant.PROBLEM_CHECK_PASS
-                    1.toByte() -> extension3 = Constant.PROBLEM_CHECK_FAIL
+                    0.toByte() -> {
+                        extension3 = Constant.PROBLEM_CHECK_PASS
+                    }
+                    1.toByte() -> {
+                        extension3 = Constant.PROBLEM_CHECK_FAIL
+                    }
                     2.toByte(),
-                    3.toByte() -> {
+                    3.toByte(),
+                    -> {
                         response.success = false
                         response.message = "闂鎻愪氦杩樻湭瀹℃牳锛屾棤娉曡繘琛屾暣鏀瑰鏍革紒"
                     }
                 }
-            }else if (extension3 == Constant.PROBLEM_CHECK_PASS || extension3 == Constant.PROBLEM_CHECK_FAIL) {
+            } else if (extension3 == Constant.PROBLEM_CHECK_PASS || extension3 == Constant.PROBLEM_CHECK_FAIL) {
                 when (action) {
                     0.toByte() -> extension3 = Constant.PROBLEM_CHECK_PASS
                     1.toByte() -> extension3 = Constant.PROBLEM_CHECK_FAIL
                     2.toByte(),
-                    3.toByte() -> {
+                    3.toByte(),
+                    -> {
                         if (ischanged == true && extension3 == Constant.PROBLEM_CHECK_PASS) {
                             response.success = true
                             extension3 = if (action == 2.toByte()) {
                                 Constant.CHANGE_CHECK_PASS
-                            }else{
+                            } else {
                                 Constant.CHANGE_CHECK_FAIL
                             }
+                            event = "鍦�${subtask?.scensename}瀹℃牳浜嗕竴涓暣鏀�"
                         } else {
                             response.success = false
                             response.message = "闂杩樻湭鏁存敼锛屾棤娉曡繘琛屾暣鏀瑰鏍革紒鎿嶄綔鏃犳晥"
                         }
                     }
                 }
-            }else if (extension3 == Constant.CHANGE_UNCHECKED) {
+            } else if (extension3 == Constant.CHANGE_UNCHECKED) {
+                event = "鍦�${subtask?.scensename}瀹℃牳浜嗕竴涓暣鏀�"
                 when (action) {
                     0.toByte(),
-                    1.toByte() -> {
+                    1.toByte(),
+                    -> {
                         response.success = false
                         response.message = "闂鎻愪氦宸插鏍革紝骞朵笖宸茶鏁存敼銆傛搷浣滄棤鏁�"
                     }
                     2.toByte() -> extension3 = Constant.CHANGE_CHECK_PASS
                     3.toByte() -> extension3 = Constant.CHANGE_CHECK_FAIL
                 }
-            }else if (extension3 == Constant.CHANGE_CHECK_PASS || extension3 == Constant.CHANGE_CHECK_FAIL) {
+            } else if (extension3 == Constant.CHANGE_CHECK_PASS || extension3 == Constant.CHANGE_CHECK_FAIL) {
                 when (action) {
                     0.toByte(),
-                    1.toByte() -> {
+                    1.toByte(),
+                    -> {
                         response.success = false
                         response.message = "闂鎻愪氦宸插鏍革紝骞朵笖宸茶鏁存敼銆傛搷浣滄棤鏁�"
                     }
@@ -414,76 +451,157 @@
             if (r != 1) {
                 response.success = false
                 response.message = "闂鏇存柊澶辫触锛�"
+            } else {
+                bizLog.info(WorkStreamLogInfo(userId, userName, event))
             }
         }
         return response
     }
 
     override fun newProblem(problem: String, files: Array<MultipartFile>): BaseResponse<String> {
-        val mapper = ObjectMapper()
-
         //json杞琽bject
-        val problemVo = mapper.readValue(problem, object : TypeReference<ProblemVo>() {})
+        val problemVo = ObjectMapper().readValue(problem, object : TypeReference<ProblemVo>() {})
 
-        // 淇濆瓨闂
         val inspection = inspectionMapper.selectByPrimaryKey(problemVo.insGuid) ?: return BaseResponse(false, "宸℃煡璁板綍涓嶅瓨鍦�")
         val scene = scenseMapper.selectByPrimaryKey(inspection.sguid) ?: return BaseResponse(false, "宸℃煡璁板綍瀵瑰簲鍦烘櫙涓嶅瓨鍦�")
-
-        val problemlist = Problemlist().apply {
-            guid = UUIDGenerator.generate16ShortUUID()
-            iguid = inspection.guid
-            stguid = inspection.stguid
-            sguid = inspection.sguid
-            sensename = inspection.scensename
-            senseaddress = inspection.scenseaddress
-            ptguid = problemVo.ptGuid
-            problemname = problemVo.proName
-            longitude = problemVo.longitude ?: scene.longitude
-            latitude = problemVo.latitude ?: scene.latitude
-            locationid = problemVo.locationId
-            location = problemVo.location
-            time = Date()
-            isrechecked = false
-            ischanged = false
-            advise = problemVo.advice
-            extension3 = Constant.PROBLEM_UNCHECKED
-        }
+        // 淇濆瓨闂
+        val problemlist = ProblemListVo.newPro(inspection, problemVo, scene)
         problemlistMapper.insert(problemlist)
 
         // 淇濆瓨鍥剧墖
-        val now = LocalDateTime.now()
-        for (image in files) {
-            val mediaFile = Mediafile().apply {
-                guid = UUIDGenerator.generate16ShortUUID()
-                iguid = inspection.guid
-                businessguid = problemlist.guid
-                longitude = problemlist.longitude
-                latitude = problemlist.latitude
-                address = problemlist.senseaddress
-                filetype = 1
-                businesstype = "闂"
-                businesstypeid = 1
-                path = "FlightFeather/Photo/" + scene.districtname + "/" + now.year + "骞�" + now.monthValue + "鏈�/" + now.monthValue + "鏈�" + now.dayOfMonth + "鏃�/" + scene.name + "/"
-                description = problemlist.problemname + " " + problemlist.location + " " + UUIDGenerator.generateUUID(4) + ".jpg"
-                savetime = Date()
-                ischanged = false
-                extension1 = scene.citycode + "/" + scene.districtcode + "/" + now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + "/" + scene.guid + "/"
-                remark = "宸蹭笂浼�"
-            }
-            mediafileMapper.insert(mediaFile)
+        mediafileService.saveMediaFile(files) { MediaFileVo.newProFile(inspection, problemlist, scene) }
 
-            val path = mediaFile.extension1
-            val fileName = mediaFile.guid + ".jpg"
-//            val filePath = "E:\\work\\绗笁鏂圭洃绠pp\\鑷姩璇勫垎\\椁愰ギ\\"
-            val filePath = "${Constant.DEFAULT_FILE_PATH}/images/$path/"
-            try {
-                //璋冪敤鏂囦欢淇濆瓨鏂规硶
-                FileUtil().uploadFile(image.bytes, filePath, fileName)
-            } catch (e: Exception) {
-                // TODO: handle exception
+        //鏇存柊宸℃煡淇℃伅鐨勯棶棰樻暟
+        if (inspection.problemcount != null) {
+            inspection.problemcount = inspection.problemcount!! + 1
+            inspectionMapper.updateByPrimaryKey(inspection)
+        }
+
+        problemlist.stguid?.let {
+            val subtask = subTaskRep.findOne(it)
+            val event = "鍦�${subtask?.scensename}鏂板涓�涓棶棰�"
+            bizLog.info(WorkStreamLogInfo(subtask?.executorguids, subtask?.executorrealtimes, event))
+        }
+
+        return BaseResponse(true)
+    }
+
+    override fun updateProblem(problem: ProblemListVo, deleteImg: List<String>, files: Array<MultipartFile>): String {
+        problemRep.findOne(problem.guid) ?: throw BizException("璇ラ棶棰樹笉瀛樺湪")
+        problemRep.update(problem)
+        val inspection = inspectionMapper.selectByPrimaryKey(problem.iguid) ?: throw BizException("宸℃煡璁板綍涓嶅瓨鍦�")
+        val scene = scenseMapper.selectByPrimaryKey(inspection.sguid) ?: throw BizException("宸℃煡璁板綍瀵瑰簲鍦烘櫙涓嶅瓨鍦�")
+        mediafileService.saveMediaFile(files) { MediaFileVo.newProFile(inspection, problem, scene) }
+        mediafileService.deleteList(deleteImg)
+        return "success"
+    }
+
+    override fun changeProblem(problemId: String, files: Array<MultipartFile>): BaseResponse<String> {
+        // 闂鍜岄棶棰樺浘鐗囧悎娉曟�ф鏌�
+        val p = problemlistMapper.selectByPrimaryKey(problemId) ?: return BaseResponse(false, "闂涓嶅瓨鍦�")
+        val mediaFiles = mediafileMapper.selectByExample(Example(Mediafile::class.java).apply {
+            createCriteria().andEqualTo("businessguid", p.guid)
+                .andEqualTo("businesstypeid", 1)
+                .andEqualTo("ischanged", false)
+        })
+        if (mediaFiles.isEmpty()) return BaseResponse(false, "闂涓嶅瓨鍦ㄦ垨宸叉暣鏀癸紝鏃犳硶閲嶅鏁存敼")
+
+        // 鏇存柊闂
+        p.apply {
+            ischanged = true
+            changedtime = Date()
+            extension3 = Constant.CHANGE_UNCHECKED
+            val today = LocalDate.now()
+            val pTime = LocalDateTime.ofInstant(time?.toInstant(), ZoneId.systemDefault()).toLocalDate()
+            changecatalog = if (p.extension1 != null) {
+                if (today.isAfter(pTime)) {
+                    Constant.PROMISE_CHANGE
+                } else {
+                    Constant.LOCAL_CHANGE
+                }
+            } else {
+                Constant.UN_PROMISE_CHANGE
+            }
+        }
+        problemlistMapper.updateByPrimaryKey(p)
+
+        // 淇濆瓨鏁存敼鍥剧墖
+        val m = mediaFiles[0]
+        m.path = m.path + "鏁存敼/"
+        m.savetime = Date()
+        m.ischanged = true
+        mediafileService.saveMediaFile(files) {
+            m.apply {
+                guid = UUIDGenerator.generate16ShortUUID()
+                description = p.problemname + " " + p.location + " 鏁存敼 " + UUIDGenerator.generateUUID(4) + ".jpg"
             }
         }
 
         return BaseResponse(true)
     }
+
+    override fun updateChange(problemId: String, deleteImg: List<String>, files: Array<MultipartFile>): String {
+        val p = problemRep.findOne(problemId) ?: throw BizException("璇ラ棶棰樹笉瀛樺湪")
+        val mediaFiles = mediafileMapper.selectByExample(Example(Mediafile::class.java).apply {
+            createCriteria().andEqualTo("businessguid", problemId)
+                .andEqualTo("businesstypeid", 1)
+                .andEqualTo("ischanged", true)
+        })
+        if (mediaFiles.isEmpty()) throw BizException("闂杩樻湭鏁存敼锛屾棤娉曚慨鏀规暣鏀�")
+
+        // 淇濆瓨鏂扮殑鏁存敼鍥剧墖
+        val m = mediaFiles[0]
+        m.savetime = Date()
+        mediafileService.saveMediaFile(files) {
+            m.apply {
+                guid = UUIDGenerator.generate16ShortUUID()
+                description = p.problemname + " " + p.location + " 鏁存敼 " + UUIDGenerator.generateUUID(4) + ".jpg"
+            }
+        }
+        mediafileService.deleteList(deleteImg)
+        return "success"
+    }
+
+    override fun getBySubTask(stGuid: String, all: Boolean?): List<ProblemListVo> {
+        //鏍规嵁瀛愪换鍔D鑾峰彇闂鍒楄〃
+        val problemListVo = mutableListOf<ProblemListVo>()
+        if (all == false) {
+            //鍘婚櫎鏈鏍镐互鍙婂鏍镐笉閫氳繃鐨勯棶棰�
+            findBySubtaskId(stGuid).forEach {
+                if (it.extension3 != Constant.PROBLEM_UNCHECKED && it.extension3 != Constant.PROBLEM_CHECK_FAIL) {
+                    problemListVo.add(it)
+                }
+            }
+        } else {
+            problemListVo.addAll(findBySubtaskId(stGuid))
+        }
+        //鏍规嵁姣忎釜闂,鑾峰彇濯掍綋鏂囦欢
+        problemListVo.forEach {
+            val mediafileVo = mediafileService.findByBusinessGUID(it.guid!!)
+            //鍒ゆ柇鏄惁鏈夊獟浣撹祫鏂�
+            if (mediafileVo.isNotEmpty()) {
+                //璧嬪��
+                it.mediafileList = mediafileVo
+            }
+        }
+        return problemListVo
+    }
+
+    override fun getSceneByProType(areaVo: AreaVo, pType: String): List<Subtask?> {
+        areaVo.scensetypeid ?: throw BizException("缂哄皯鍦烘櫙绫诲瀷鍙傛暟")
+        val task = taskRep.findOneTask(areaVo) ?: throw BizException("鏈壘鍒板搴旂殑宸℃煡鎬讳换鍔�")
+        return subTaskRep.findSubtasks(task.tguid!!, areaVo.scensetypeid!!, pType)
+    }
+
+    override fun getSceneProSummary(
+        areaVo: AreaVo,
+        page: Int,
+        per_page: Int,
+    ): Pair<DataHead?, List<SceneProblemSummary>?> {
+//        areaVo.scensetypeid ?: throw BizException("缂哄皯鍦烘櫙绫诲瀷鍙傛暟")
+//        val task = taskRep.findOneTask(areaVo) ?: throw BizException("鏈壘鍒板搴旂殑宸℃煡鎬讳换鍔�")
+        val p = PageHelper.startPage<SceneProblemSummary>(page, per_page)
+        val res = problemRep.selectSceneProSummary(areaVo)
+        return DataHead(p.pageNum, p.pages, p.total) to res
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3