-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
cokie
committed
Dec 19, 2023
1 parent
2d60dea
commit c7073f4
Showing
19 changed files
with
254 additions
and
17 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...rc/main/kotlin/io/micro/core/rest/Code.kt → ...-api/src/main/kotlin/io/micro/api/Code.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package io.micro.core.rest | ||
package io.micro.api | ||
|
||
/** | ||
*@author Augenstern | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
tokisaki-api/src/main/kotlin/io/micro/api/robot/converter/RobotManagerConverter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.micro.api.robot.converter | ||
|
||
import io.micro.api.robot.dto.RobotManagerDTO | ||
import io.micro.server.robot.domain.model.entity.RobotManager | ||
import org.mapstruct.BeanMapping | ||
import org.mapstruct.Mapper | ||
import org.mapstruct.MappingConstants.ComponentModel | ||
import org.mapstruct.ReportingPolicy | ||
|
||
@Mapper(componentModel = ComponentModel.CDI) | ||
interface RobotManagerConverter { | ||
|
||
@BeanMapping(unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
fun robotManagerDTO2RobotManager(dto: RobotManagerDTO): RobotManager | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
tokisaki-api/src/main/kotlin/io/micro/api/robot/dto/FeatureFunctionDTO.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.micro.api.robot.dto | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class FeatureFunctionDTO( | ||
var id: Long, | ||
var remark: String? = null, | ||
var enabled: Boolean = false | ||
) |
18 changes: 18 additions & 0 deletions
18
tokisaki-api/src/main/kotlin/io/micro/api/robot/dto/RobotManagerDTO.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.micro.api.robot.dto | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class RobotManagerDTO( | ||
var userId: Long, | ||
|
||
var name: String, | ||
|
||
var type: Int, | ||
|
||
var state: Int = 0, | ||
|
||
var remark: String? = null, | ||
|
||
val functions: MutableList<FeatureFunctionDTO> = mutableListOf() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
tokisaki-core/src/main/kotlin/io/micro/core/exception/BusinessException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package io.micro.core.exception | ||
|
||
class BusinessException(message: String? = null, cause: Throwable? = null) : RuntimeException(message, cause) |
34 changes: 34 additions & 0 deletions
34
tokisaki-core/src/main/kotlin/io/micro/core/exception/Throws.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.micro.core.exception | ||
|
||
import java.util.* | ||
|
||
object Throws { | ||
|
||
fun fail(msg: String): Nothing { | ||
throw BusinessException(msg) | ||
} | ||
|
||
fun failIfTure(block: () -> Boolean, msg: String) { | ||
if (block()) { | ||
fail(msg) | ||
} | ||
} | ||
|
||
fun failIfFalse(block: () -> Boolean, msg: String) { | ||
if (!block()) { | ||
fail(msg) | ||
} | ||
} | ||
|
||
fun <T> failIfNull(block: () -> T, msg: String) { | ||
if (Objects.isNull(block())) { | ||
fail(msg) | ||
} | ||
} | ||
|
||
fun <T> failIfNonNull(block: () -> T, msg: String) { | ||
if (!Objects.isNull(block())) { | ||
fail(msg) | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
tokisaki-server/src/main/kotlin/io/micro/server/robot/domain/model/entity/RobotManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package io.micro.server.robot.domain.model.entity | ||
|
||
import io.micro.core.entity.BaseDomainEntity | ||
import io.micro.core.exception.Throws | ||
import io.micro.server.robot.domain.model.valobj.FeatureFunction | ||
import kotlin.properties.Delegates | ||
|
||
class RobotManager : BaseDomainEntity() { | ||
|
||
var userId: Long by Delegates.notNull() | ||
|
||
lateinit var name: String | ||
|
||
var type: Int by Delegates.notNull() | ||
|
||
var state: Int = 0 | ||
|
||
var remark: String? = null | ||
|
||
val functions: MutableList<FeatureFunction> = mutableListOf() | ||
|
||
fun isValidType() = validTypeIds.contains(type) | ||
|
||
fun isValidState() = validStateIds.contains(state) | ||
|
||
fun verify() { | ||
Throws.failIfFalse(::isValidType, "非法的类型") | ||
Throws.failIfFalse(::isValidState, "非法的状态") | ||
} | ||
|
||
companion object { | ||
val validTypeIds = listOf(0) | ||
val validStateIds = listOf(0, 1, 2, 3, 4, 5, 6) | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
tokisaki-server/src/main/kotlin/io/micro/server/robot/domain/model/valobj/FeatureFunction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.micro.server.robot.domain.model.valobj | ||
|
||
data class FeatureFunction( | ||
var id: Long, | ||
var remark: String? = null, | ||
var enabled: Boolean = false | ||
) |
8 changes: 8 additions & 0 deletions
8
...server/src/main/kotlin/io/micro/server/robot/domain/repository/IRobotManagerRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.micro.server.robot.domain.repository | ||
|
||
import io.micro.server.robot.domain.model.entity.RobotManager | ||
import io.smallrye.mutiny.Uni | ||
|
||
interface IRobotManagerRepository { | ||
fun saveRobotWithUser(robotManager: RobotManager): Uni<Unit> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
tokisaki-server/src/main/kotlin/io/micro/server/robot/infra/converter/RobotConverter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.micro.server.robot.infra.converter | ||
|
||
import io.micro.server.robot.domain.model.entity.RobotManager | ||
import io.micro.server.robot.infra.po.Robot | ||
import org.mapstruct.BeanMapping | ||
import org.mapstruct.Mapper | ||
import org.mapstruct.MappingConstants.ComponentModel | ||
import org.mapstruct.ReportingPolicy | ||
|
||
@Mapper(componentModel = ComponentModel.CDI, uses = [RobotMapper::class]) | ||
interface RobotConverter { | ||
|
||
@BeanMapping(unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
fun robotManager2RobotPO(robotManager: RobotManager): Robot | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
tokisaki-server/src/main/kotlin/io/micro/server/robot/infra/converter/RobotMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.micro.server.robot.infra.converter | ||
|
||
import io.micro.server.function.infra.po.Function | ||
import io.micro.server.robot.domain.model.valobj.FeatureFunction | ||
import io.micro.server.robot.infra.po.Robot | ||
import io.micro.server.robot.infra.po.UseFunction | ||
import jakarta.inject.Singleton | ||
|
||
@Singleton | ||
class RobotMapper { | ||
|
||
fun number2Type(num: Int): Robot.Type { | ||
val entries = Robot.Type.entries | ||
if (num < entries.size) { | ||
return entries[num] | ||
} else { | ||
throw IllegalArgumentException() | ||
} | ||
} | ||
|
||
fun number2State(num: Int): Robot.State { | ||
val entries = Robot.State.entries | ||
if (num < entries.size) { | ||
return entries[num] | ||
} else { | ||
throw IllegalArgumentException() | ||
} | ||
} | ||
|
||
fun featureFunction2UseFunction(featureFunction: FeatureFunction): UseFunction { | ||
return UseFunction().apply { | ||
function = Function().apply { id = featureFunction.id } | ||
remark = featureFunction.remark | ||
enabled = featureFunction.enabled | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...i-server/src/main/kotlin/io/micro/server/robot/infra/repository/RobotManagerRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.micro.server.robot.infra.repository | ||
|
||
import io.micro.core.exception.Throws | ||
import io.micro.server.auth.infra.po.User | ||
import io.micro.server.robot.domain.model.entity.RobotManager | ||
import io.micro.server.robot.domain.repository.IRobotManagerRepository | ||
import io.micro.server.robot.infra.converter.RobotConverter | ||
import io.micro.server.robot.infra.po.Robot | ||
import io.quarkus.hibernate.reactive.panache.common.WithSession | ||
import io.smallrye.mutiny.Uni | ||
import io.smallrye.mutiny.replaceWithUnit | ||
import jakarta.enterprise.context.ApplicationScoped | ||
|
||
@ApplicationScoped | ||
class RobotManagerRepository(private val robotConverter: RobotConverter) : IRobotManagerRepository { | ||
|
||
@WithSession | ||
override fun saveRobotWithUser(robotManager: RobotManager): Uni<Unit> { | ||
return User.findById(robotManager.userId).flatMap { user -> | ||
Throws.failIfNull({ user }, "用户不存在") | ||
robotConverter.robotManager2RobotPO(robotManager) | ||
.apply { this.user = user } | ||
.persistAndFlush<Robot>() | ||
.replaceWithUnit() | ||
} | ||
} | ||
|
||
} |