From 5670e4a15fba292ef5f8fb90e96072de976bb621 Mon Sep 17 00:00:00 2001 From: feiyu02 <risaku@163.com> Date: 星期二, 28 六月 2022 14:00:22 +0800 Subject: [PATCH] 1. 中小企业守法自助相关接口更新 --- src/main/kotlin/cn/flightfeather/supervision/lightshare/service/Impl/EvaluationServiceImpl.kt | 366 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 349 insertions(+), 17 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 d527077..f7007b5 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 @@ -1,18 +1,18 @@ package cn.flightfeather.supervision.lightshare.service.Impl import cn.flightfeather.supervision.common.score.AutoScore -import cn.flightfeather.supervision.domain.entity.Company -import cn.flightfeather.supervision.domain.entity.Evaluation -import cn.flightfeather.supervision.domain.entity.Evaluationrule -import cn.flightfeather.supervision.domain.entity.OverallEvaluation +import cn.flightfeather.supervision.domain.entity.* import cn.flightfeather.supervision.domain.enumeration.AssessmentRuleType import cn.flightfeather.supervision.domain.enumeration.SceneType import cn.flightfeather.supervision.domain.mapper.* import cn.flightfeather.supervision.infrastructure.utils.DateUtil +import cn.flightfeather.supervision.infrastructure.utils.UUIDGenerator import cn.flightfeather.supervision.lightshare.service.EvaluationService +import cn.flightfeather.supervision.lightshare.service.ItemevaluationService import cn.flightfeather.supervision.lightshare.vo.AssessmentGradeVo import cn.flightfeather.supervision.lightshare.vo.AssessmentSearchCondition import cn.flightfeather.supervision.lightshare.vo.CreditInfoVo +import cn.flightfeather.supervision.lightshare.vo.GradeDetailVo import com.github.pagehelper.PageHelper import org.springframework.stereotype.Service import tk.mybatis.mapper.entity.Example @@ -23,11 +23,13 @@ class EvaluationServiceImpl( val evaluationMapper: EvaluationMapper, val evaluationruleMapper: EvaluationruleMapper, + val evaluationsubruleMapper: EvaluationsubruleMapper, val userinfoMapper: UserinfoMapper, val baseInfoMapper: BaseInfoMapper, val companyMapper: CompanyMapper, val overallEvaluationMapper: OverallEvaluationMapper, - val autoScore: AutoScore + val autoScore: AutoScore, + val itemevaluationService: ItemevaluationService ) : EvaluationService { override fun findOne(id: String): Evaluation = evaluationMapper.selectByPrimaryKey(id) @@ -75,13 +77,39 @@ override fun getHistoryPoint(userId: String, page: Int, per_page: Int, response: HttpServletResponse): List<AssessmentGradeVo> { val userInfo = userinfoMapper.selectByPrimaryKey(userId) ?: return emptyList() + + //璇勫垎瑙勫垯涓嬬殑鍒嗙骇銆佺瓑绾ч鑹插強绛夌骇璇勮 + 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) + .andEqualTo("ruletype", "0") + }) + if (rule.isNotEmpty()) { + val r = rule[0] + r.extension1?.split("#")?.forEach { + val pStr = it.split(",") + pointLevel.add(Pair(pStr[0].toInt(), pStr[1].toInt())) + } + r.extension2?.split("#")?.forEach { + evaluateLevel.add(it) + } + r.extension3?.split("#")?.forEach { + creditTexts.add(it) + } + r.remark?.split(";")?.forEach { + levelColors.add(it) + } + } val example = Example(Evaluation::class.java).apply { createCriteria().andEqualTo("iguid", userId) .andEqualTo("ertype", AssessmentRuleType.Total.value.toByte()) //鏍规嵁璇勪及浜虹殑绫诲瀷杩涜绛涢�夛紝鑷瘎鍜屽畼鏂硅瘎鍒嗗垎寮�鎺掑悕 and(createCriteria().orIsNull("evaluatorrealname") .orEqualTo("evaluatorrealname", 0)) - orderBy("updatedate").desc() + orderBy("createdate").desc() } val counts = evaluationMapper.selectCountByExample(example) val totalPage = Math.ceil(counts.toDouble() / per_page.toDouble()).toInt() @@ -100,9 +128,13 @@ tPGuid = it.guid tPRuleGuid = it.stguid totalPoint = it.resultscorebef?.toInt() ?: 0 - level = getEvaluationLevel(tPRuleGuid, totalPoint) + val l = getEvaluationLevel(totalPoint, pointLevel, evaluateLevel, creditTexts, levelColors) + level = l["evaluateLevel"] + color = l["color"] + creditText = l["creditText"] rank = it.promissednum ?: 1 - updateDate = it.updatedate + updateDate = it.createdate + period = it.scensename }) } @@ -202,7 +234,7 @@ tPGuid = it["tPGuid"] as String? tPRuleGuid = it["tPRuleGuid"] as String? totalPoint = (it["totalPoint"] as String?)?.toIntOrNull() ?: 0 - level = getEvaluationLevel(tPRuleGuid, totalPoint) + level = getEvaluationLevel(totalPoint)["evaluateLevel"] rank = (it["rank"] as Int?) ?: -1 updateDate = it["updateDate"] as Date? }) @@ -220,18 +252,317 @@ return response } + override fun uploadScore(userId: String, period: String, ruleId: String?, itemList: List<Pair<String, String>>): Boolean { + val userinfo = userinfoMapper.selectByPrimaryKey(userId) ?: return false + + //璇ュ満鏅被鍨嬩笅鐨勬�诲緱鍒嗚鍒� + val tRule = evaluationruleMapper.selectByExample(Example(Evaluationrule::class.java).apply { + createCriteria().andEqualTo("scensetypeid", userinfo.extension2) + .andEqualTo("ruletype", AssessmentRuleType.Total.value) + .andIsNull("tasktypeid") + }).takeIf { it.isNotEmpty() }?.get(0) + + var totalPoint = 0 + var tEvaluation = Evaluation() + + //涓婁紶鐨勫緱鍒嗚鍒� +// var rule = Evaluationrule() +// val subRules:List<Evaluationsubrule> = if (ruleId != null) { +// rule = evaluationruleMapper.selectByPrimaryKey(ruleId) +// evaluationsubruleMapper.selectByExample(Example(Evaluationsubrule::class.java).apply { +// createCriteria().andEqualTo("erguid", ruleId) +// }) +// } + + val ruleList = evaluationruleMapper.selectByExample(Example(Evaluationrule::class.java).apply { + createCriteria().andEqualTo("scensetypeid", userinfo.extension2) + .andNotEqualTo("ruletype", AssessmentRuleType.Total.value) + .andIsNull("tasktypeid") + }).forEach {rule-> + val subRules = evaluationsubruleMapper.selectByExample(Example(Evaluationsubrule::class.java).apply { + createCriteria().andEqualTo("erguid", rule.guid) + }) + if (subRules.isEmpty()) return@forEach + //鎬诲垎璁板綍 + val evaluation = Evaluation().apply { guid = UUIDGenerator.generate16ShortUUID() } + //鍏蜂綋椤瑰緱鍒嗚褰� + val itemEvaluationList = mutableListOf<Itemevaluation>() + //鎬诲緱鍒� + var totalScore = 0 + + itemList.forEach { + for (s in subRules) { + if (s.guid == it.first) { + var fatherId: String? + var subRule = s + var score = it.second + do { + val result = calculateScore(rule, evaluation.guid!!, userId, subRule, score, itemEvaluationList) + fatherId = result.first + for (s in subRules) { + if (s.guid == fatherId) { + subRule = s + score = result.second ?: "0" + break + } + } + } while (fatherId?.isNotBlank() == true) + + totalScore += it.second.toInt() + break + } + } + } + + //鎬诲垎 + var maxScore = 0 + subRules.forEach subRules@{s -> + if (s.ertype == 2) { + maxScore += s.maxscore ?: 0 + } + //瑙勫垯宸茬粡鎵撳垎瀹屾瘯锛屽垯璺宠繃 + itemEvaluationList.forEach {i -> + if (i.esrguid == s.guid) { + return@subRules + } + } + //鍚﹀垯鏂板涓�鏉℃湭鎵e垎鐨勮褰� + itemEvaluationList.add(Itemevaluation().apply { + ieguid = UUIDGenerator.generate16ShortUUID() + iguid = userId + sguid = evaluation.guid + erguid = rule.guid + rulename = rule.rulename + ruletype = rule.ruletype?.toInt() + ertype = s.ertype + esrguid = s.guid + name = s.itemname + value = "0" + extension1 = "false" + }) + } + //璁$畻鎬诲垎 + evaluation.apply { + iguid = userId + stguid = rule.guid + scensetypeid = userinfo.extension2?.toByte() + ertype = rule.ruletype?.toByte() + scensename = period + evaluatorguid = userId + evaluatorusername = userinfo.acountname + evaluatorrealname = "0" + resultscorebef = (maxScore + totalScore).toString() + createdate = Date() + updatedate = Date() + } + save(evaluation) + itemevaluationService.savelist(itemEvaluationList) + tEvaluation = evaluation + + totalPoint += evaluation.resultscorebef?.toInt() ?: 0 + } + + //璁$畻鎵�鏈夎〃鐨勬�诲垎 + tRule?.let { + tEvaluation.apply { + guid = UUIDGenerator.generate16ShortUUID() + stguid = it.guid + ertype = it.ruletype?.toByte() + resultscorebef = totalPoint.toString() + } + save(tEvaluation) + } + return true + } + + override fun getDetail(userId: String, period: String): GradeDetailVo { + val result = GradeDetailVo() + + val userinfo = userinfoMapper.selectByPrimaryKey(userId) ?: return result + + //璇ュ満鏅被鍨嬩笅鐨勬墍鏈夊緱鍒嗚鍒� + 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 + //寰楀垎瑙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) + } + + 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 +// 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 -> + val subRules = evaluationsubruleMapper.selectByExample(Example(Evaluationsubrule::class.java).apply { + createCriteria().andEqualTo("erguid", it.guid) + }) + val itemEvaluations = itemevaluationService.getItemEvaluationList(e.guid!!) + + itemEvaluations.forEach {item -> + when (item.ertype) { + //鍒嗙被鍒殑寰楀垎 + 2 -> { + for (s in subRules) { + if (s.guid == item.esrguid) { + val score = if ((item.value?.toInt() ?: 0) <= 0) { + s.maxscore?.plus(item.value?.toInt() ?: 0) + } else { + item.value?.toInt() ?: 0 + } + result.classScore.add(Triple(item.name ?: "", s.maxscore?.toString()?:"0", score.toString())) + 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" + } else { + (item.value?.toInt() ?: 0).minus(s.maxscore ?: 0).toString() + }, + s.remark ?: "" + ) + ) + } + } + } + } + } + } + } + } + + return result + } + + /** + * 鏍规嵁涓婁紶鐨勫瓙瑙勫垯鎵e垎鎯呭喌锛岀敓浜у瓙椤瑰緱鍒嗚褰� + * @param rule 鎬昏鍒� + * @param eGuid 鎬诲垎璁板綍id + * @param userId 鐢ㄦ埛id + * @param subRule 鎵e垎鐨勮鍒� + * @param score 鎵e垎 + * @param itemEvaluationList 寰楀垎璁板綍琛� + * @return 璇勫垎椤圭殑鐖秈d鍜屽緱鍒� + */ + private fun calculateScore(rule:Evaluationrule, eGuid: String, userId: String, subRule: Evaluationsubrule, score: String, itemEvaluationList: MutableList<Itemevaluation>): Pair<String?, String?> { + var result: Pair<String?, String?> = Pair(null, null) + var exist = false + for (i in itemEvaluationList) { + //璁板綍宸插瓨鍦紝璇存槑鏄埗椤圭殑璇勫垎瑙勫垯涓嬬殑鏌愪釜瀛愰」鐨勪竴閮ㄥ垎鎵e垎锛屾墸鍒嗙疮鍔� + if (subRule.guid == i.esrguid) { + i.value = i.value?.toInt()?.plus(score.toInt())?.toString() + result = Pair(subRule.fatherid, i.value) + exist = true + break + } + } + //璁板綍涓嶅瓨鍦ㄦ椂锛岃鏄庢槸瀛愰」绗竴娆℃墸鍒嗭紝鏂板涓�鏉¤褰� + if (!exist) { + itemEvaluationList.add(Itemevaluation().apply { + ieguid = UUIDGenerator.generate16ShortUUID() + iguid = userId + sguid = eGuid + erguid = rule.guid + rulename = rule.rulename + ruletype = rule.ruletype?.toInt() + ertype = subRule.ertype + esrguid = subRule.guid + name = subRule.itemname + value = score + extension1 = "true" + }) + result = Pair(subRule.fatherid, score) + } + return result + } + /** * 鏍规嵁鍒嗘暟鑾峰彇绛夌骇 */ - private fun getEvaluationLevel(ruleId:String?, score: Int): String { - return when (score) { - in 0..40 -> "鏋佸樊" - in 41..64 -> "杈冨樊" - in 65..79 -> "涓�鑸�" - in 80..94 -> "鑹ソ" - in 95..Int.MAX_VALUE -> "浼樼" - else -> "鏋佸樊" + private fun getEvaluationLevel( + score: Int, + pointLevel: MutableList<Pair<Int, Int>> = mutableListOf(), + evaluateLevel: MutableList<String> = mutableListOf(), + creditTexts: MutableList<String> = mutableListOf(), + levelColors: MutableList<String> = mutableListOf() + ): Map<String, String> { + val result = mutableMapOf<String, String>() + if (pointLevel.isEmpty() || evaluateLevel.isEmpty() || creditTexts.isEmpty() || levelColors.isEmpty()) { + result["evaluateLevel"] = when (score) { + in 0..40 -> "鏋佸樊" + in 41..64 -> "杈冨樊" + in 65..79 -> "涓�鑸�" + in 80..94 -> "鑹ソ" + in 95..Int.MAX_VALUE -> "浼樼" + else -> "鏋佸樊" + } + } else { + for (i in pointLevel.indices) { + if (score in pointLevel[i].first..pointLevel[i].second) { + result["color"] = levelColors[i % levelColors.size] + result["creditText"] = creditTexts[i % creditTexts.size] + result["evaluateLevel"] = evaluateLevel[i % evaluateLevel.size] + } + } } + return result + } private fun updateRank(evaluation: Evaluation, isInsert: Boolean) { @@ -239,6 +570,7 @@ val eList = evaluationMapper.selectByExample(Example(Evaluation::class.java).apply { createCriteria().andEqualTo("scensename", evaluation.scensename) .andIsNotNull("scensename") + .andEqualTo("ertype", AssessmentRuleType.Total.value) //鏍规嵁璇勪及浜虹殑绫诲瀷杩涜绛涢�夛紝鑷瘎鍜屽畼鏂硅瘎鍒嗗皝闈㈠紑鎺掑悕 if (evaluation.evaluatorrealname == null || evaluation.evaluatorrealname == "0") { and(createCriteria().orIsNull("evaluatorrealname") -- Gitblit v1.9.3