Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ class ReceiptPrinter(

@Throws(IOException::class)
fun print() {
Socket(ipOrHost, port).use { socket ->
Socket().apply {
soTimeout = 5000 // 5秒でタイムアウト
connect(java.net.InetSocketAddress(ipOrHost, port), 5000) // 接続タイムアウト5秒
}.use { socket ->
socket.getOutputStream().use {
it.write(command.build())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ class ItemApiController {
],
)
fun findByBarcode(
@Parameter(description = "Item barcode (4+ digits)", required = true, example = "1234567890")
@Parameter(description = "Item barcode (format: A01XXXXXXA)", required = true, example = "A01000001A")
@PathVariable barcode: String,
): ResponseEntity<ItemResponse> {
logger.info("Fetching item with barcode: {}", barcode)

// Validate barcode format
if (!barcode.matches(Regex("^[0-9]{4,}$"))) {
// Validate barcode format (A + 種別(2桁) + ID(6桁) + A)
if (!barcode.matches(Regex("^A(00|01|02)\\d{6}A$"))) {
throw InvalidBarcodeException(barcode)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import info.nukoneko.kidspos.server.service.mapper.SaleMapper
import jakarta.validation.Valid
import org.slf4j.LoggerFactory
import org.springframework.http.ResponseEntity
import org.springframework.scheduling.annotation.Async
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.*
import java.util.concurrent.CompletableFuture

/**
* 販売APIコントローラー
Expand Down Expand Up @@ -50,12 +52,18 @@ class SaleApiController(
)
when (val result = saleProcessingService.processSaleWithValidation(saleBean, items)) {
is SaleResult.Success -> {
// Print receipt
receiptService.printReceipt(
request.storeId,
items,
request.deposit,
)
// Print receipt asynchronously (non-blocking)
CompletableFuture.runAsync {
try {
receiptService.printReceipt(
request.storeId,
items,
request.deposit,
)
} catch (e: Exception) {
logger.error("Failed to print receipt asynchronously", e)
}
}

val sale = result.sale
val response =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import java.util.*
* @property quantity 数量
* @property amount 売上げ金額
* @property deposit 預かり金
* @property changeAmount お釣り
* @property createdAt 作成日時
*/
@Entity
Expand All @@ -23,6 +24,7 @@ data class SaleEntity(
val storeId: Int, // 店舗ID
val quantity: Int, // 数量
val amount: Int, // 売り上げ
val deposit: Int,
val deposit: Int, // 預かり金
val changeAmount: Int, // お釣り
val createdAt: Date,
)
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class SalePersistenceService(
val saleId = idGenerationService.generateNextId(saleRepository)
val totalAmount = saleCalculationService.calculateSaleAmount(items)
val quantity = saleCalculationService.calculateQuantity(items)
val changeAmount = saleCalculationService.calculateChange(saleBean.deposit, totalAmount)

val sale =
SaleEntity(
Expand All @@ -44,6 +45,7 @@ class SalePersistenceService(
quantity = quantity,
amount = totalAmount,
deposit = saleBean.deposit,
changeAmount = changeAmount,
createdAt = Date(),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,16 @@ class SaleService(
items.forEach {
logger.debug("Item - ID: {}, Name: {}, Price: {}", it.id, it.name, it.price)
}
val totalAmount = items.sumOf { it.price }
val changeAmount = saleBean.deposit - totalAmount
val sale =
SaleEntity(
id,
saleBean.storeId,
items.size,
items.sumOf { it.price },
totalAmount,
saleBean.deposit,
changeAmount,
Date(),
)

Expand Down
Loading