case class ConversationId(value: UUID)
case class CustomerRequestId(uuid: UUID)
class CustomerRequestReceiverController{
def createCustomerRequest(req: Request, optConversationId: Option[ConversationId] = None): Task[Response] = {
val NONE_REVISION = 0
val customerRequestId = CustomerRequestId(RandomUUID.randomUUID)
val result: Task[Response] = for {
form <- req.as(jsonOf[CreateCustomerRequestFormInternalApiV2])
_ = println(s"Conversation Id ${form.conversationId.getOrElse(ConversationId(RandomUUID.randomUUID))}")
_ = appLogger.info(s"creating CustomerRequest ${form.customerId.value} with Conversation ${optConversationId.getOrElse(form.conversationId.getOrElse(RandomUUID.randomUUID))}")
_ = logger.info(s"creating CustomerRequest ${form.customerId.value} with Conversation ${optConversationId.getOrElse(form.conversationId.getOrElse(RandomUUID.randomUUID))}")
createCommand <- Task.delay(CreateCustomerRequest(
customerRequestId = customerRequestId,
communication = Communication.Chat(optConversationId.getOrElse(form.conversationId.getOrElse(ConversationId(RandomUUID.randomUUID)))),
commandResult <- Task.delay(createCommandHandler.handle(createCommand))
response <- responseFormat(commandResult)
} yield response
result.handleWith(invalidRequestBody)
}
}
我希望UUID.randomUUID()的值输出是相同的UUID,但实际输出是不同的值
答案 0 :(得分:0)
替换行
customerRequestId = customerRequestId,
与
customerRequestId = CustomerRequestId(RandomUUID.randomUUID)
现在您只生成一次CustomerRequestId,并在每次迭代中使用它