Skip to content

Commit

Permalink
🎨 feat: 优化
Browse files Browse the repository at this point in the history
  • Loading branch information
cokie committed Jan 15, 2024
1 parent 7f3999e commit ac38217
Show file tree
Hide file tree
Showing 53 changed files with 187 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,8 @@ public Uni<R<PageDTO<QueryRobotDTO>>> getRobot(
@QueryParam("page") @DefaultValue("1") int page) {
RobotDO robotManager = robotManagerConverter.operateRobotDTO2RobotManager(operateRobotDTO);
return robotManagerService.getRobotList(robotManager, Pageable.of(page, size))
.map(it -> R.newInstance(
PageDTO.of(page, size, it.getSecond(),
it.getFirst()
.stream()
.map(robotDO -> robotManagerConverter.robotManager2QueryRobotDTO(robotDO))
.toList())
));
.map(it -> PageDTO.converter(it, robotManagerConverter::robotManager2QueryRobotDTO))
.map(R::newInstance);
}

@Operation(summary = "创建机器人")
Expand Down Expand Up @@ -89,7 +84,7 @@ public Uni<R<QueryRobotDTO>> modifyRobotInfo(
@Parameter(description = "机器人信息") @Valid @ConvertGroup(to = ValidGroup.Update.class) OperateRobotDTO operateRobotDTO) {
RobotDO robotDO = robotManagerConverter.operateRobotDTO2RobotManager(operateRobotDTO);
return robotManagerService.modifyRobotInfo(robotDO)
.map(robotManagerConverter::robotManager2QueryRobotDTO)
.map(dto -> robotManagerConverter.robotManager2QueryRobotDTO(dto))
.map(R::newInstance);
}

Expand Down
17 changes: 15 additions & 2 deletions tokisaki-api/src/main/java/io/micro/api/user/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import io.micro.api.user.dto.OperateUserDTO;
import io.micro.api.user.dto.QueryUserDTO;
import io.micro.core.annotation.InitAuthContext;
import io.micro.core.rest.PageDTO;
import io.micro.core.rest.Pageable;
import io.micro.core.rest.R;
import io.micro.server.auth.domain.service.AuthService;
import io.quarkus.security.Authenticated;
import io.smallrye.mutiny.Uni;
import jakarta.annotation.security.RolesAllowed;
import jakarta.inject.Inject;
import jakarta.validation.Valid;
import jakarta.ws.rs.PATCH;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.*;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.parameters.Parameter;
import org.eclipse.microprofile.openapi.annotations.tags.Tag;
Expand All @@ -27,11 +30,21 @@ public class UserController {
public UserConverter userConverter;

@Operation(summary = "修改用户信息")
@Authenticated
@PATCH
public Uni<R<QueryUserDTO>> modifyUserInfo(@Parameter(name = "用户信息") @Valid OperateUserDTO userDTO) {
return authService.updateUserById(userConverter.operateUserDTO2userDO(userDTO))
.map(userConverter::userDO2QueryUserDTO)
.map(R::newInstance);
}

@Operation(summary = "查询用户分页列表")
@RolesAllowed({"USER:ROOT"})
@GET
public Uni<R<PageDTO<QueryUserDTO>>> getUserInfo(@QueryParam("page") @DefaultValue("1") int page, @QueryParam("size") @DefaultValue("10") int size) {
return authService.getUserPage(Pageable.of(page, size))
.map(it -> PageDTO.converter(it, userConverter::userDO2QueryUserDTO))
.map(R::newInstance);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public Uni<ReplyMessageDTO> message(@Parameter(description = "普通文本信息
.transform(user -> {
ReplyMessageDTO replyMessageDTO = new ReplyMessageDTO();
replyMessageDTO.setFromUserName(wxMessageDTO.getToUserName());
replyMessageDTO.setToUserName(wxMessageDTO.getFromUserName());
replyMessageDTO.setCreateTime(String.valueOf(System.currentTimeMillis()));
replyMessageDTO.setMsgType("text");
replyMessageDTO.setContent("登陆成功," + user.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface RobotManagerConverter {
fun queryRobotDTO2RobotManager(dto: QueryRobotDTO): RobotDO

@InheritInverseConfiguration
fun robotManager2QueryRobotDTO(dto: RobotDO): QueryRobotDTO
fun robotManager2QueryRobotDTO(robotDO: RobotDO): QueryRobotDTO

@BeanMapping(unmappedTargetPolicy = ReportingPolicy.IGNORE)
fun operateFeatureFunctionDTO2FeatureFunction(featureFunctionDTO: OperateFeatureFunctionDTO): FeatureFunctionDO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ package io.micro.api.user.converter
import io.micro.api.user.dto.OperateUserDTO
import io.micro.api.user.dto.QueryUserDTO
import io.micro.server.auth.domain.model.entity.UserDO
import org.mapstruct.BeanMapping
import org.mapstruct.Mapper
import org.mapstruct.MappingConstants.ComponentModel
import org.mapstruct.ReportingPolicy

@Mapper(componentModel = ComponentModel.CDI)
interface UserConverter {

fun userDO2QueryUserDTO(userDO: UserDO): QueryUserDTO

@BeanMapping(unmappedTargetPolicy = ReportingPolicy.IGNORE)
fun operateUserDTO2userDO(queryUserDTO: OperateUserDTO): UserDO

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fun requireFalse(value: Boolean, detail: String? = null, code: CommonCode = Comm
if (value) {
fail(detail, code)
} else {
return value
return false
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.net.spcokie.common.exception
package io.micro.core.exception

import jakarta.validation.ConstraintViolationException

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.net.spcokie.common.exception
package io.micro.core.exception

/**
*@author Augenstern
Expand Down
29 changes: 29 additions & 0 deletions tokisaki-core/src/main/kotlin/io/micro/core/rest/PageDO.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.micro.core.rest

class PageDO<T> : Pageable() {

var total: Long = 0

var records: List<T> = listOf()

companion object {

@JvmStatic
fun <E> of(pageable: Pageable, total: Long, records: List<E>) = PageDO<E>().also {
it.current = pageable.current
it.limit = pageable.limit
it.records = records
it.total = total
}

@JvmStatic
fun <E> of(current: Int, limit: Int, total: Long, records: List<E>) = PageDO<E>().also {
it.current = current
it.limit = limit
it.records = records
it.total = total
}

}

}
8 changes: 8 additions & 0 deletions tokisaki-core/src/main/kotlin/io/micro/core/rest/PageDTO.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@ class PageDTO<T> : Pageable() {
var records: List<T> = listOf()

companion object {

@JvmStatic
fun <E> of(current: Int, limit: Int, total: Long, records: List<E>) = PageDTO<E>().also {
it.current = current
it.limit = limit
it.records = records
it.total = total
}

@JvmStatic
fun <E, R> converter(pageDO: PageDO<E>, converter: (E) -> R): PageDTO<R> {
val rs = pageDO.records.map { converter(it) }
return PageDTO.of(pageDO.current, pageDO.limit, pageDO.total, rs)
}

}

}
11 changes: 11 additions & 0 deletions tokisaki-core/src/main/kotlin/io/micro/core/util/Converter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.micro.core.util

fun <E, R> List<E>.converter(func: (E) -> R): List<R> = map(func)

@JvmName(name = "mutableConverter")
fun <E, R> MutableList<E>.converter(func: (E) -> R): List<R> = map(func)

fun <E, R> Set<E>.converter(func: (E) -> R): Set<R> = map(func).toSet()

@JvmName(name = "mutableConverter")
fun <E, R> MutableSet<E>.converter(func: (E) -> R): List<R> = map(func)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.micro.function.domain.image.model.entity
import io.micro.core.function.sdk.AbstractCmd
import io.micro.core.function.sdk.Cmd
import io.micro.function.domain.image.model.Image
import io.net.spcokie.types.QQFace
import io.micro.function.types.QQFace
import io.smallrye.mutiny.Uni

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.micro.function.domain.image.model.entity

import com.vdurmont.emoji.EmojiParser
import io.micro.core.exception.CmdException
import io.micro.core.function.sdk.AbstractCmd
import io.micro.core.function.sdk.ArgsMergeStrategy
import io.micro.core.function.sdk.Cmd
Expand All @@ -9,8 +10,7 @@ import io.micro.function.domain.image.model.valobj.EmojiCombination
import io.micro.function.domain.image.model.valobj.EmojiData
import io.micro.function.domain.image.model.valobj.EmojiMetadata
import io.micro.function.domain.image.model.valobj.GoogleRequestParam
import io.net.spcokie.common.exception.CmdException
import io.net.spcokie.types.QQFace
import io.micro.function.types.QQFace
import io.smallrye.mutiny.Uni

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.micro.function.domain.image.model.entity
import io.micro.core.function.sdk.AbstractCmd
import io.micro.core.function.sdk.Cmd
import io.micro.function.domain.image.model.Image
import io.net.spcokie.types.QQFace
import io.micro.function.types.QQFace
import io.smallrye.mutiny.Uni
import kotlin.random.Random
import kotlin.random.nextInt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import io.micro.core.function.sdk.ArgsMergeStrategy
import io.micro.core.function.sdk.Cmd
import io.micro.function.domain.image.model.Image
import io.micro.function.domain.image.model.valobj.MidjourneyConfig
import io.net.spcokie.types.QQFace
import io.micro.function.types.QQFace
import io.smallrye.mutiny.Uni

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.micro.function.domain.image.service.impl

import io.micro.core.annotation.CallCount
import io.micro.core.exception.CmdException
import io.micro.core.function.dto.MessageChain
import io.micro.core.function.sdk.CommandService
import io.micro.function.domain.image.adapter.ImageAdapter
import io.micro.function.domain.image.model.entity.AnimeCartoon
import io.micro.function.domain.image.repository.ImageRepository
import io.micro.function.domain.image.service.ImageTask
import io.net.spcokie.common.exception.CmdException
import io.quarkus.hibernate.reactive.panache.common.WithTransaction
import io.quarkus.logging.Log
import io.smallrye.faulttolerance.api.RateLimit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.micro.function.domain.image.service.impl

import io.micro.core.annotation.CallCount
import io.micro.core.exception.CmdException
import io.micro.core.function.dto.MessageChain
import io.micro.core.function.sdk.CommandService
import io.micro.function.domain.image.adapter.ImageAdapter
import io.micro.function.domain.image.model.entity.EmojiKitchen
import io.micro.function.domain.image.repository.ImageRepository
import io.net.spcokie.common.exception.CmdException
import io.quarkus.logging.Log
import io.quarkus.runtime.StartupEvent
import io.smallrye.faulttolerance.api.RateLimit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.micro.function.domain.image.service.impl

import io.micro.core.annotation.CallCount
import io.micro.core.exception.CmdException
import io.micro.core.function.dto.MessageChain
import io.micro.core.function.sdk.CommandService
import io.micro.function.domain.image.adapter.ImageAdapter
import io.micro.function.domain.image.model.entity.Girl
import io.micro.function.domain.image.repository.ImageRepository
import io.micro.function.domain.image.service.ImageTask
import io.net.spcokie.common.exception.CmdException
import io.quarkus.hibernate.reactive.panache.common.WithTransaction
import io.quarkus.logging.Log
import io.smallrye.faulttolerance.api.RateLimit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.micro.function.domain.image.service.impl

import io.micro.core.annotation.CallCount
import io.micro.core.exception.CmdException
import io.micro.core.function.dto.MessageChain
import io.micro.core.function.sdk.CommandService
import io.micro.function.domain.image.adapter.ImageAdapter
import io.micro.function.domain.image.model.entity.Midjourney
import io.micro.function.domain.image.model.valobj.MidjourneyConfig
import io.micro.function.domain.image.repository.ImageRepository
import io.net.spcokie.common.exception.CmdException
import io.smallrye.faulttolerance.api.RateLimit
import io.smallrye.faulttolerance.api.RateLimitException
import io.smallrye.faulttolerance.api.RateLimitType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.micro.function.domain.strategy

import com.vdurmont.emoji.EmojiParser
import io.micro.core.exception.CmdException
import io.micro.core.function.sdk.Cmd
import io.net.spcokie.common.exception.CmdException
import io.quarkus.arc.Arc
import io.quarkus.arc.Unremovable
import jakarta.enterprise.context.ApplicationScoped
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.micro.function.domain.strategy

import io.micro.core.context.AuthContext
import io.micro.core.exception.CmdException
import io.micro.core.function.ConfigHint
import io.micro.core.function.dto.Message
import io.micro.core.function.dto.MessageChain
import io.micro.core.function.sdk.Cmd
import io.micro.core.function.sdk.CommandService
import io.micro.function.domain.image.service.ImageTask
import io.net.spcokie.common.exception.CmdException
import io.quarkus.arc.All
import io.smallrye.mutiny.Uni
import jakarta.annotation.PostConstruct
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.net.spcokie.domain.text.model
package io.micro.function.domain.text.model

import io.micro.core.entity.BaseDomainEntity

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package io.micro.function.domain.text.model.entity
import io.micro.core.function.sdk.AbstractCmd
import io.micro.core.function.sdk.ArgsMergeStrategy
import io.micro.core.function.sdk.Cmd
import io.micro.function.domain.text.model.Text
import io.micro.function.domain.text.model.valobj.*
import io.net.spcokie.domain.text.model.Text
import io.net.spcokie.types.QQFace
import io.micro.function.types.QQFace
import io.smallrye.mutiny.Uni

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ data class ChatCompletionChoice(
var index: Int? = null,

/**
* The [ChatMessageRole.assistant] message or delta (when streaming) which was generated
* The [ChatMessageRole.ASSISTANT] message or delta (when streaming) which was generated
*/
var message: ChatMessage? = null,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ data class ChatCompletionRequest(

/**
* If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only [server-sent
* events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format) as they become available, with the stream terminated by a data: [DONE] message.
* events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format) as they become available, with the stream terminated by a data: message.
*/
var stream: Boolean? = null,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.micro.function.domain.text.service

import io.micro.core.annotation.CallCount
import io.micro.core.context.AuthContext
import io.micro.core.exception.CmdException
import io.micro.core.function.ConfigHint
import io.micro.core.function.dto.MessageChain
import io.micro.core.function.sdk.Cmd
Expand All @@ -10,7 +11,6 @@ import io.micro.function.domain.text.adapter.TextAdapter
import io.micro.function.domain.text.model.entity.Chat
import io.micro.function.domain.text.model.valobj.ChatConfig
import io.micro.function.domain.text.repository.TextRepository
import io.net.spcokie.common.exception.CmdException
import io.quarkus.hibernate.reactive.panache.common.WithTransaction
import io.smallrye.faulttolerance.api.RateLimit
import io.smallrye.faulttolerance.api.RateLimitException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.micro.function.infra.adapter

import io.micro.core.exception.CmdException
import io.micro.core.exception.RetryableException
import io.micro.function.domain.image.adapter.ImageAdapter
import io.micro.function.domain.image.model.entity.AnimeCartoon
import io.micro.function.domain.image.model.entity.EmojiKitchen
Expand All @@ -9,8 +11,6 @@ import io.micro.function.infra.adapter.dto.MidjourneyPromptDTO
import io.micro.function.infra.adapter.gateway.EmojiKitchenGateway
import io.micro.function.infra.adapter.gateway.MidjourneyGateway
import io.micro.function.infra.adapter.gateway.XyzImageGateway
import io.net.spcokie.common.exception.CmdException
import io.net.spcokie.common.exception.RetryableException
import io.quarkus.logging.Log
import io.smallrye.mutiny.Uni
import io.vertx.ext.web.client.WebClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import io.micro.function.domain.text.adapter.TextAdapter
import io.micro.function.domain.text.model.valobj.ChatCompletionRequest
import io.micro.function.domain.text.model.valobj.ChatCompletionResult
import io.micro.function.infra.adapter.gateway.ChatGateway
import io.net.spcokie.infra.converter.TextConverter
import io.micro.function.infra.converter.TextConverter
import io.quarkus.logging.Log
import io.smallrye.mutiny.Uni
import jakarta.enterprise.context.ApplicationScoped
Expand Down
Loading

0 comments on commit ac38217

Please sign in to comment.