From 23bd719cebe5feeff4e48fde925b0b39755eea93 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期二, 15 十一月 2022 10:59:50 +0800
Subject: [PATCH] 2022.11.15

---
 src/main/kotlin/cn/flightfeather/supervision/lightshare/service/Impl/EvaluationServiceImpl.kt |  268 +++++++++++++++++++++++++++++++++++------------------
 1 files changed, 175 insertions(+), 93 deletions(-)

diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/Impl/EvaluationServiceImpl.kt b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/Impl/EvaluationServiceImpl.kt
index f7007b5..a37458b 100644
--- a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/Impl/EvaluationServiceImpl.kt
+++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/Impl/EvaluationServiceImpl.kt
@@ -16,6 +16,7 @@
 import com.github.pagehelper.PageHelper
 import org.springframework.stereotype.Service
 import tk.mybatis.mapper.entity.Example
+import java.time.LocalDateTime
 import java.util.*
 import javax.servlet.http.HttpServletResponse
 
@@ -51,8 +52,8 @@
     override fun getTotalPoints(userId: String, evaluatorType: Int, startTime: String, endTime: String, sceneTypeId: Int?, erGuid: String?, eId: String?): List<Evaluation> {
         val example = Example(Evaluation::class.java)
         val criteria = example.createCriteria()
-        val startDate = DateUtil().StringToDate(startTime)
-        val endDate = DateUtil().StringToDate(endTime)
+        val startDate = DateUtil.StringToDate(startTime)
+        val endDate = DateUtil.StringToDate(endTime)
         criteria.andEqualTo("iguid", userId)
                 .andBetween("createdate", startDate, endDate)
         example.and(example.createCriteria().apply {
@@ -75,16 +76,20 @@
         return evaluationMapper.selectByExample(example)
     }
 
-    override fun getHistoryPoint(userId: String, page: Int, per_page: Int, response: HttpServletResponse): List<AssessmentGradeVo> {
+    override fun getHistoryPoint(userId: String, page: Int, per_page: Int, platform:String?, response: HttpServletResponse): List<AssessmentGradeVo> {
         val userInfo = userinfoMapper.selectByPrimaryKey(userId) ?: return emptyList()
-
+        // FIXME: 2022/11/8 涓存椂娣诲姞杩囧害鍔熻兘锛屾彁渚涘井淇″皬绋嬪簭鍓嶇姹戒慨绫诲瀷鐨勫満鏅崟鐙殑璇勪及娓呭崟 锛屽満鏅被鍨嬩负 -7
+        var sceneType = userInfo.extension2
+        if (platform == "weixin" && sceneType == SceneType.VehicleRepair.value.toString()) {
+            sceneType = "-7"
+        }
         //璇勫垎瑙勫垯涓嬬殑鍒嗙骇銆佺瓑绾ч鑹插強绛夌骇璇勮
         val pointLevel = mutableListOf<Pair<Int, Int>>()
         val evaluateLevel = mutableListOf<String>()
         val creditTexts = mutableListOf<String>()
         val levelColors = mutableListOf<String>()
         val rule = evaluationruleMapper.selectByExample(Example(Evaluationrule::class.java).apply {
-            createCriteria().andEqualTo("scensetypeid", userInfo.extension2)
+            createCriteria().andEqualTo("scensetypeid", sceneType)
                 .andEqualTo("ruletype", "0")
         })
         if (rule.isNotEmpty()) {
@@ -124,7 +129,7 @@
             resultList.add(AssessmentGradeVo().apply {
                 this.userId = userId
                 userRealName = userInfo.realname
-                sceneType = userInfo.extension2?.toIntOrNull() ?: SceneType.NoType.value
+                this.sceneType = userInfo.extension2?.toIntOrNull() ?: SceneType.NoType.value
                 tPGuid = it.guid
                 tPRuleGuid = it.stguid
                 totalPoint = it.resultscorebef?.toInt() ?: 0
@@ -144,20 +149,22 @@
     override fun getCreditInfo(userId: String): CreditInfoVo {
         val userinfo = userinfoMapper.selectByPrimaryKey(userId)
         val baseInfo = baseInfoMapper.selectByPrimaryKey(userId)
+            ?: return CreditInfoVo(
+                userId, userinfo.realname,userinfo.extension2?.toIntOrNull() ?: SceneType.NoType.value)
         val company = companyMapper.selectByPrimaryKey(baseInfo.ciGuid)
 
 
         val result = CreditInfoVo(
                 userId,
-                baseInfo.biName,
+                baseInfo?.biName,
                 userinfo.extension2?.toIntOrNull() ?: SceneType.NoType.value,
-                baseInfo.ciName,
-                baseInfo.biManagementCompany,
-                baseInfo.biContact,
-                baseInfo.biTelephone,
-                baseInfo.biAddress,
-                district = company.ciDistrictName,
-                town = company.ciTownName
+                baseInfo?.ciName,
+                baseInfo?.biManagementCompany,
+                baseInfo?.biContact,
+                baseInfo?.biTelephone,
+                baseInfo?.biAddress,
+                district = company?.ciDistrictName,
+                town = company?.ciTownName
         )
 
         val rule = evaluationruleMapper.selectByExample(Example(Evaluationrule::class.java).apply {
@@ -169,7 +176,7 @@
         }).takeIf { it.isNotEmpty() }?.get(0) ?: return result
 
         val overallEvaluation = overallEvaluationMapper.selectByExample(Example(OverallEvaluation::class.java).apply {
-            createCriteria().andEqualTo("biGuid", baseInfo.biGuid)
+            createCriteria().andEqualTo("biGuid", baseInfo?.biGuid)
             orderBy("oePublishTime").desc()
         }).takeIf { it.isNotEmpty() }?.get(0) ?: return result
 
@@ -206,8 +213,8 @@
                 else -> null
             }
 
-        result.publishTime = DateUtil().DateToString(overallEvaluation.oePublishTime, "YYYY骞碝M鏈�")
-        result.updateTime = DateUtil().DateToString(overallEvaluation.oeUpdateTime, "YYYY骞碝M鏈�")
+        result.publishTime = DateUtil.DateToString(overallEvaluation.oePublishTime, "YYYY骞碝M鏈�")
+        result.updateTime = DateUtil.DateToString(overallEvaluation.oeUpdateTime, "YYYY骞碝M鏈�")
         result.creditLevel = creditLevel
         result.creditLevelDes = creditLevelDes
         result.codeLevel = codeLevel
@@ -254,10 +261,16 @@
 
     override fun uploadScore(userId: String, period: String, ruleId: String?, itemList: List<Pair<String, String>>): Boolean {
         val userinfo = userinfoMapper.selectByPrimaryKey(userId) ?: return false
+        var sceneType = userinfo.extension2
+
+        // FIXME: 2022/11/8 涓存椂娣诲姞杩囧害鍔熻兘锛屾彁渚涘井淇″皬绋嬪簭鍓嶇姹戒慨绫诲瀷鐨勫満鏅崟鐙殑璇勪及娓呭崟 锛屽満鏅被鍨嬩负 -7
+        if (sceneType == SceneType.VehicleRepair.value.toString()) {
+            sceneType = "-7"
+        }
 
         //璇ュ満鏅被鍨嬩笅鐨勬�诲緱鍒嗚鍒�
         val tRule = evaluationruleMapper.selectByExample(Example(Evaluationrule::class.java).apply {
-            createCriteria().andEqualTo("scensetypeid", userinfo.extension2)
+            createCriteria().andEqualTo("scensetypeid", sceneType)
                 .andEqualTo("ruletype", AssessmentRuleType.Total.value)
                 .andIsNull("tasktypeid")
         }).takeIf { it.isNotEmpty() }?.get(0)
@@ -275,7 +288,7 @@
 //        }
 
         val ruleList = evaluationruleMapper.selectByExample(Example(Evaluationrule::class.java).apply {
-            createCriteria().andEqualTo("scensetypeid", userinfo.extension2)
+            createCriteria().andEqualTo("scensetypeid", sceneType)
                     .andNotEqualTo("ruletype", AssessmentRuleType.Total.value)
                 .andIsNull("tasktypeid")
         }).forEach {rule->
@@ -290,6 +303,7 @@
             //鎬诲緱鍒�
             var totalScore = 0
 
+            //鏍规嵁涓婁紶鐨勯�夋嫨鐨勬潯鐩紝鐢熸垚瀵瑰簲鐨勮瘎鍒嗚褰�
             itemList.forEach {
                 for (s in subRules) {
                     if (s.guid == it.first) {
@@ -307,8 +321,6 @@
                                 }
                             }
                         } while (fatherId?.isNotBlank() == true)
-
-                        totalScore += it.second.toInt()
                         break
                     }
                 }
@@ -317,16 +329,21 @@
             //鎬诲垎
             var maxScore = 0
             subRules.forEach subRules@{s ->
-                if (s.ertype == 2) {
+                //璁$畻搴斿緱鎬诲垎锛宐asic_score锛氳〃绀哄熀纭�鍒嗭紝璁$畻鍦ㄥ簲寰楁�诲垎鍐咃紱addition_score琛ㄧず鍔犲垎锛屼笉璁$畻鍦ㄥ唴
+                if (s.ertype == 2 && s.extension1 != "addition_score") {
                     maxScore += s.maxscore ?: 0
                 }
                 //瑙勫垯宸茬粡鎵撳垎瀹屾瘯锛屽垯璺宠繃
                 itemEvaluationList.forEach {i ->
                     if (i.esrguid == s.guid) {
+                        //濡傛灉鏄渶澶х殑2绾ц瘎浼拌鍒欙紝璁$畻宸茶幏寰楃殑鎬诲垎
+                        if (s.ertype == 2) {
+                            totalScore += i.value?.toInt() ?: 0
+                        }
                         return@subRules
                     }
                 }
-                //鍚﹀垯鏂板涓�鏉℃湭鎵e垎鐨勮褰�
+                //鍚﹀垯濡傛灉鍓嶇鍏佽涓嶇敤鍏ㄩ儴璇勫垎锛屾柊澧炰竴鏉℃湭璇勫垎鐨勮褰�
                 itemEvaluationList.add(Itemevaluation().apply {
                     ieguid = UUIDGenerator.generate16ShortUUID()
                     iguid = userId
@@ -376,80 +393,94 @@
     }
 
     override fun getDetail(userId: String, period: String): GradeDetailVo {
+        val list = period.split("-")
+        val endM = list[1].toInt()
+        val list2 = list[0].split("/")
+        val year = list2[0].toInt()
+        val startM = list2[1].toInt()
+        val st = LocalDateTime.of(year, startM, 1, 0, 0, 0, 0)
+        val et = LocalDateTime.of(year, endM, 1, 0, 0, 0, 0).plusMonths(1)
+
         val result = GradeDetailVo()
 
         val userinfo = userinfoMapper.selectByPrimaryKey(userId) ?: return result
+        var sceneType = userinfo.extension2
+        // FIXME: 2022/11/8 涓存椂娣诲姞杩囧害鍔熻兘锛屾彁渚涘井淇″皬绋嬪簭鍓嶇姹戒慨绫诲瀷鐨勫満鏅崟鐙殑璇勪及娓呭崟 锛屽満鏅被鍨嬩负 -7
+        if (sceneType == SceneType.VehicleRepair.value.toString()) {
+            sceneType = "-7"
+        }
 
         //璇ュ満鏅被鍨嬩笅鐨勬墍鏈夊緱鍒嗚鍒�
-        var rule0: Evaluationrule? = null
-        val rule1List = mutableListOf<Evaluationrule>()
-        evaluationruleMapper.selectByExample(Example(Evaluationrule::class.java).apply {
-            createCriteria().andEqualTo("scensetypeid", userinfo.extension2)
-                and(createCriteria().orIsNull("tasktypeid").orNotEqualTo("tasktypeid", 1))
-        }).forEach {
-            if (it.ruletype == AssessmentRuleType.Total.value.toString()) {
-                rule0 = it
-            } else {
-                rule1List.add(it)
-            }
-        }
-        if (rule0 == null) return result
+//        var rule0: Evaluationrule? = null
+//        val rule1List = mutableListOf<Evaluationrule>()
+//        evaluationruleMapper.selectByExample(Example(Evaluationrule::class.java).apply {
+//            createCriteria().andEqualTo("scensetypeid", sceneType)
+//                and(createCriteria().orIsNull("tasktypeid").orNotEqualTo("tasktypeid", 1))
+//        }).forEach {
+//            if (it.ruletype == AssessmentRuleType.Total.value.toString()) {
+//                rule0 = it
+//            } else {
+//                rule1List.add(it)
+//            }
+//        }
+//        if (rule0 == null) return result
         //寰楀垎瑙h鍜屽緱鍒嗚鎯�
         evaluationMapper.selectByExample(Example(Evaluation::class.java).apply {
             createCriteria().andEqualTo("iguid", userId)
-                    .andEqualTo("ertype", AssessmentRuleType.Total.value.toByte())
-                    .andEqualTo("scensename", period)
-        }).takeIf { it.isNotEmpty() }?.get(0)?.let {
-            rule0?.apply {
-                val pointLevel = mutableListOf<Pair<Int, Int>>()
-                val evaluateLevel = mutableListOf<String>()
-                val creditTexts = mutableListOf<String>()
-                val levelColors = mutableListOf<String>()
-                extension1?.split("#")?.forEach {
-                    val pStr = it.split(",")
-                    pointLevel.add(Pair(pStr[0].toInt(), pStr[1].toInt()))
-                }
-                extension2?.split("#")?.forEach {
-                    evaluateLevel.add(it)
-                }
-                extension3?.split("#")?.forEach {
-                    creditTexts.add(it)
-                }
-                remark?.split(";")?.forEach {
-                    levelColors.add(it)
-                }
+//                    .andEqualTo("ertype", AssessmentRuleType.Total.value.toByte())
+            and(
+                    createCriteria().orEqualTo("scensename", period)
+                            .orBetween("createdate", st, et)
+            )
+        }).forEach {e ->
+            val rule = evaluationruleMapper.selectByPrimaryKey(e.stguid)
+            //鎬诲垎瑙勫垯锛岀敓鎴愭�讳綋璇勪环
+            if (rule.ruletype == AssessmentRuleType.Total.value.toString()) {
+                rule?.apply {
+                    val pointLevel = mutableListOf<Pair<Int, Int>>()
+                    val evaluateLevel = mutableListOf<String>()
+                    val creditTexts = mutableListOf<String>()
+                    val levelColors = mutableListOf<String>()
+                    extension1?.split("#")?.forEach {
+                        val pStr = it.split(",")
+                        pointLevel.add(Pair(pStr[0].toInt(), pStr[1].toInt()))
+                    }
+                    extension2?.split("#")?.forEach {
+                        evaluateLevel.add(it)
+                    }
+                    extension3?.split("#")?.forEach {
+                        creditTexts.add(it)
+                    }
+                    remark?.split(";")?.forEach {
+                        levelColors.add(it)
+                    }
 
-                val l = getEvaluationLevel(it.resultscorebef?.toInt()
-                        ?: 0, pointLevel, evaluateLevel, creditTexts, levelColors)
-                result.apply {
-                    creditText = l["creditText"]
-
-                    score = it.resultscorebef?.toInt() ?: 0
-                    rank = it.promissednum
-                    level = l["evaluateLevel"]
-                    this.period = it.scensename
-                    time = it.createdate
+                    val l = getEvaluationLevel(e.resultscorebef?.toInt()
+                            ?: 0, pointLevel, evaluateLevel, creditTexts, levelColors)
+                    result.apply {
+                        creditText = l["creditText"]
+                        score = e.resultscorebef?.toInt() ?: 0
+                        rank = e.promissednum
+                        level = l["evaluateLevel"]
+                        this.period = period
+                        time = e.createdate
 //                    color = l["color"]
+                    }
                 }
             }
-        }
-
-        //鍒嗙被鍒殑寰楀垎(姣忎釜璇勫垎琛ㄧ殑璇勫垎澶ч」鐨勫緱鍒�)鍜屽け鍒嗘潯鐩�
-        rule1List.forEach {
-            val evaluation = evaluationMapper.selectByExample(Example(Evaluation::class.java).apply {
-                createCriteria().andEqualTo("iguid", userId)
-                        .andEqualTo("ertype", it.ruletype)
-                        .andEqualTo("scensename", period)
-            }).takeIf { it.isNotEmpty() }?.get(0)?.let {e ->
+            //鍏蜂綋璇勪及琛�
+            else {
                 val subRules = evaluationsubruleMapper.selectByExample(Example(Evaluationsubrule::class.java).apply {
-                    createCriteria().andEqualTo("erguid", it.guid)
+                    createCriteria().andEqualTo("erguid", rule.guid)
                 })
                 val itemEvaluations = itemevaluationService.getItemEvaluationList(e.guid!!)
-
-                itemEvaluations.forEach {item ->
+                val ruleMap = result.loseScore
+                //鍒嗙被鍒殑寰楀垎(姣忎釜璇勫垎琛ㄧ殑璇勫垎澶ч」鐨勫緱鍒�)鍜屽け鍒嗘潯鐩�
+                itemEvaluations.sortedBy { it.ertype }.forEach {item ->
                     when (item.ertype) {
                         //鍒嗙被鍒殑寰楀垎
                         2 -> {
+                            ruleMap[item.name] = mutableMapOf()
                             for (s in subRules) {
                                 if (s.guid == item.esrguid) {
                                     val score = if ((item.value?.toInt() ?: 0) <= 0) {
@@ -462,22 +493,52 @@
                                 }
                             }
                         }
+                        3 -> {
+                            if ((item.value?.toInt() ?: 0) != 0 && item.extension1 == "true") {
+                                for (s in subRules) {
+                                    if (s.guid == item.esrguid) {
+                                        if (!ruleMap.containsKey(s.fathername)) {
+                                            ruleMap[s.fathername] = mutableMapOf()
+                                        }
+                                        ruleMap[s.fathername]?.put(item.name, mutableListOf())
+                                        break
+                                    }
+                                }
+                            }
+                        }
                         //澶卞垎鏉$洰
                         4 -> {
                             if ((item.value?.toInt() ?: 0) != 0 && item.extension1 == "true") {
                                 for (s in subRules) {
                                     if (s.guid == item.esrguid) {
-                                        result.loseScore.add(
-                                            Triple(
-                                                item.name ?: "",
-                                                if ((item.value?.toInt() ?: 0) < 0) {
-                                                    item . value ?: "0"
+                                        val d =
+                                                Triple(
+                                                        item.name ?: "",
+//                                                if ((item.value?.toInt() ?: 0) < 0) {
+//                                                    item.value ?: "0"
+//                                                } else {
+//                                                    (item.value?.toInt() ?: 0).minus(s.maxscore ?: 0).toString()
+//                                                },
+                                                        item.value ?: "0",
+                                                        s.remark ?: ""
+                                                )
+                                        val rule3Name = s.fathername
+                                        for (s1 in subRules) {
+                                            if (s1.itemname == rule3Name) {
+                                                val rule2Name =
+                                                //鐖秈d涓虹┖锛岃鏄庢4绾ц瘎浼伴」鐩存帴闄勫睘浜�2绾ц瘎浼伴」
+                                                if (s1.fathername.isNullOrBlank()) {
+                                                    ruleMap[rule3Name]?.put(rule3Name, mutableListOf())
+                                                    rule3Name
                                                 } else {
-                                                    (item.value?.toInt() ?: 0).minus(s.maxscore ?: 0).toString()
-                                                },
-                                                s.remark ?: ""
-                                            )
-                                        )
+                                                    s1.fathername
+                                                }
+                                                ruleMap[rule2Name]?.get(rule3Name)?.add(d)
+                                                break
+                                            }
+                                        }
+
+                                        break
                                     }
                                 }
                             }
@@ -485,13 +546,15 @@
                     }
                 }
             }
+
         }
+
 
         return result
     }
 
     /**
-     * 鏍规嵁涓婁紶鐨勫瓙瑙勫垯鎵e垎鎯呭喌锛岀敓浜у瓙椤瑰緱鍒嗚褰�
+     * 鏍规嵁涓婁紶鐨勫瓙瑙勫垯鎵e垎鎯呭喌锛岀敓鎴愬瓙椤瑰緱鍒嗚褰�
      * @param rule 鎬昏鍒�
      * @param eGuid 鎬诲垎璁板綍id
      * @param userId 鐢ㄦ埛id
@@ -504,9 +567,27 @@
         var result: Pair<String?, String?> = Pair(null, null)
         var exist = false
         for (i in itemEvaluationList) {
-            //璁板綍宸插瓨鍦紝璇存槑鏄埗椤圭殑璇勫垎瑙勫垯涓嬬殑鏌愪釜瀛愰」鐨勪竴閮ㄥ垎鎵e垎锛屾墸鍒嗙疮鍔�
+            //璁板綍宸插瓨鍦紝璇存槑鏄埗椤圭殑璇勫垎瑙勫垯涓嬬殑鏌愪釜瀛愰」鐨勪竴閮ㄥ垎鎵e垎锛屾墸鍒嗙疮鍔�,骞朵笖涓嶈兘瓒呰繃鐖堕」鐨勪笂闄�
             if (subRule.guid == i.esrguid) {
-                i.value = i.value?.toInt()?.plus(score.toInt())?.toString()
+                val s = i.value?.toInt()?.plus(score.toInt()) ?: 0
+                //鍔犲垎妯″紡
+                if (subRule.extension2 == "add_mode") {
+                    if (s > (subRule.maxscore ?: 0)) {
+                        i.value = subRule.maxscore?.toString() ?: "0"
+                    } else {
+                        i.value = s.toString()
+                    }
+                }
+                //榛樿鎯呭喌涓哄噺鍒嗘ā寮�
+                else {
+                    //鍏佽鎵i櫎鐨勫垎鏁版渶灏忓�硷紙璐熸暟锛�
+                    val min = subRule.minscore?.minus(subRule.maxscore ?: 0) ?: 0
+                    if (s < min) {
+                        i.value = min.toString()
+                    } else {
+                        i.value = s.toString()
+                    }
+                }
                 result = Pair(subRule.fatherid, i.value)
                 exist = true
                 break
@@ -554,7 +635,8 @@
             }
         } else {
             for (i in pointLevel.indices) {
-                if (score in pointLevel[i].first..pointLevel[i].second) {
+                if (score in pointLevel[i].first..pointLevel[i].second ||
+                        (i == pointLevel.size - 1 && score > pointLevel[i].second)) {
                     result["color"] = levelColors[i % levelColors.size]
                     result["creditText"] = creditTexts[i % creditTexts.size]
                     result["evaluateLevel"] = evaluateLevel[i % evaluateLevel.size]

--
Gitblit v1.9.3