Skip to content

Commit

Permalink
refactor: remove some not-null assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
Handiwork committed Mar 3, 2024
1 parent 37f1afc commit acd2a76
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 25 deletions.
6 changes: 3 additions & 3 deletions src/main/kotlin/plus/maa/backend/common/aop/JsonSchemaAop.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import plus.maa.backend.controller.request.copilot.CopilotRatingReq
import plus.maa.backend.controller.response.MaaResultException
import java.io.IOException

private val log = KotlinLogging.logger { }
private val log = KotlinLogging.logger { }

/**
* @author LoMu
Expand Down Expand Up @@ -61,12 +61,12 @@ class JsonSchemaAop(
}
}
}
if (content == null) return
if (schemaJson == null || content == null) return


//获取json schema json路径并验证
try {
ClassPathResource(schemaJson!!).inputStream.use { inputStream ->
ClassPathResource(schemaJson).inputStream.use { inputStream ->
val json = JSONObject(content)
val jsonObject = JSONObject(JSONTokener(inputStream))
val schema = SchemaLoader.load(jsonObject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class CopilotController(
@ApiResponse(description = "删除作业结果")
@RequireJwt
@PostMapping("/delete")
fun deleteCopilot(@RequestBody request: CopilotCUDRequest?): MaaResult<Unit> {
copilotService.delete(helper.requireUserId(), request!!)
fun deleteCopilot(@RequestBody request: CopilotCUDRequest): MaaResult<Unit> {
copilotService.delete(helper.requireUserId(), request)
return success()
}

Expand Down
14 changes: 4 additions & 10 deletions src/main/kotlin/plus/maa/backend/service/ArkGameDataService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,11 @@ class ArkGameDataService(private val okHttpClient: OkHttpClient) {
}
val node = mapper.reader().readTree(body.string())
val characters = mapper.convertValue(node, object : TypeReference<Map<String, ArkCharacter>>() {})
characters.forEach { (id, c) -> c.id = id }
arkCharacterMap.clear()
characters.values.forEach { c ->
if (c.id.isNullOrBlank()) {
return@forEach
}
val ids = c.id!!.split("_")
if (ids.size != 3) {
// 不是干员
return@forEach
}
characters.forEach { (id, c) ->
val ids = id.split("_")
if (ids.size != 3) return@forEach
c.id = id
arkCharacterMap[ids[2]] = c
}
log.info { "[DATA]获取character数据成功, 共${arkCharacterMap.size}" }
Expand Down
19 changes: 9 additions & 10 deletions src/main/kotlin/plus/maa/backend/service/ArkLevelService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import java.time.ZoneId
import java.util.*
import java.util.concurrent.atomic.AtomicInteger

private val log = KotlinLogging.logger { }
private val log = KotlinLogging.logger { }

/**
* @author dragove
Expand Down Expand Up @@ -164,7 +164,8 @@ class ArkLevelService(
*/
fun updateActivitiesOpenStatus() {
log.info { "[ACTIVITIES-OPEN-STATUS]准备更新活动地图开放状态" }
val stages = githubRepo.getContents(githubToken, "resource").firstOrNull { content: GithubContent -> content.isFile && "stages.json" == content.name }
val stages = githubRepo.getContents(githubToken, "resource")
.firstOrNull { content: GithubContent -> content.isFile && "stages.json" == content.name }

if (stages == null) {
log.info { "[ACTIVITIES-OPEN-STATUS]活动地图开放状态数据不存在" }
Expand All @@ -186,14 +187,12 @@ class ArkLevelService(
okHttpClient
.newCall(Request.Builder().url(stages.downloadUrl).build())
.execute().use { response ->
if (!response.isSuccessful || response.body == null) {
val body = response.body?.byteStream()
if (!response.isSuccessful || body == null) {
log.error { "[ACTIVITIES-OPEN-STATUS]活动地图开放状态下载失败" }
return
}
val body = response.body!!.byteStream()
val stagesList: List<MaaArkStage> =
mapper.readValue(body, object : TypeReference<List<MaaArkStage>>() {
})
val stagesList = mapper.readValue(body, object : TypeReference<List<MaaArkStage>>() {})

val keyInfos = stagesList
.map { it.stageId } // 提取地图系列的唯一标识
Expand All @@ -210,7 +209,7 @@ class ArkLevelService(
val nowTime = LocalDateTime.now()

while (arkLevelPage.hasContent()) {
arkLevelPage.forEach{ arkLevel: ArkLevel ->
arkLevelPage.forEach { arkLevel: ArkLevel ->
// 只考虑地图系列的唯一标识
if (keyInfos.contains(ArkLevelUtil.getKeyInfoById(arkLevel.stageId))) {
arkLevel.isOpen = true
Expand Down Expand Up @@ -335,7 +334,7 @@ class ArkLevelService(
private val fail: AtomicInteger = AtomicInteger(0),
private val pass: AtomicInteger = AtomicInteger(0),
val total: Int = 0,
private val finishCallback: ((DownloadTask) -> Unit)? = null
private val finishCallback: ((DownloadTask) -> Unit)
) {
fun success() {
success.incrementAndGet()
Expand Down Expand Up @@ -365,7 +364,7 @@ class ArkLevelService(
if (success.get() + fail.get() + pass.get() != total) {
return
}
finishCallback!!.invoke(this)
finishCallback.invoke(this)
log.info { "[LEVEL]地图数据下载完成, 成功:${success.get()}, 失败:${fail.get()}, 跳过:${pass.get()} 总用时${duration}s" }
}
}
Expand Down

0 comments on commit acd2a76

Please sign in to comment.