| @@ -12,10 +12,12 @@ import com.ffii.fpsms.modules.jobOrder.web.model.PrintRequest | |||||
| import com.ffii.fpsms.modules.jobOrder.web.model.LaserRequest | import com.ffii.fpsms.modules.jobOrder.web.model.LaserRequest | ||||
| import com.ffii.fpsms.modules.jobOrder.web.model.NgpclPushResponse | import com.ffii.fpsms.modules.jobOrder.web.model.NgpclPushResponse | ||||
| import com.ffii.fpsms.modules.jobOrder.web.model.OnPackQrJobOrderRequest | import com.ffii.fpsms.modules.jobOrder.web.model.OnPackQrJobOrderRequest | ||||
| import com.ffii.fpsms.modules.master.service.ItemUomService | |||||
| import com.ffii.fpsms.modules.settings.service.SettingsService | import com.ffii.fpsms.modules.settings.service.SettingsService | ||||
| import com.ffii.fpsms.modules.stock.entity.StockInLineRepository | import com.ffii.fpsms.modules.stock.entity.StockInLineRepository | ||||
| import com.ffii.fpsms.py.PrintedQtyByChannel | import com.ffii.fpsms.py.PrintedQtyByChannel | ||||
| import com.ffii.fpsms.py.PyJobOrderListItem | import com.ffii.fpsms.py.PyJobOrderListItem | ||||
| import com.ffii.fpsms.py.PyJobOrderListMapper | |||||
| import com.ffii.fpsms.py.PyJobOrderPrintSubmitService | import com.ffii.fpsms.py.PyJobOrderPrintSubmitService | ||||
| import org.springframework.core.env.Environment | import org.springframework.core.env.Environment | ||||
| import org.springframework.stereotype.Service | import org.springframework.stereotype.Service | ||||
| @@ -70,6 +72,7 @@ class PlasticBagPrinterService( | |||||
| val jobOrderRepository: JobOrderRepository, | val jobOrderRepository: JobOrderRepository, | ||||
| private val jdbcDao: JdbcDao, | private val jdbcDao: JdbcDao, | ||||
| private val stockInLineRepository: StockInLineRepository, | private val stockInLineRepository: StockInLineRepository, | ||||
| private val itemUomService: ItemUomService, | |||||
| private val settingsService: SettingsService, | private val settingsService: SettingsService, | ||||
| private val pyJobOrderPrintSubmitService: PyJobOrderPrintSubmitService, | private val pyJobOrderPrintSubmitService: PyJobOrderPrintSubmitService, | ||||
| private val environment: Environment, | private val environment: Environment, | ||||
| @@ -171,7 +174,7 @@ class PlasticBagPrinterService( | |||||
| val ids = filtered.mapNotNull { it.id } | val ids = filtered.mapNotNull { it.id } | ||||
| val printed = pyJobOrderPrintSubmitService.sumPrintedQtyByJobOrderIds(ids) | val printed = pyJobOrderPrintSubmitService.sumPrintedQtyByJobOrderIds(ids) | ||||
| return filtered.map { jo -> | return filtered.map { jo -> | ||||
| toPyJobOrderListItem(jo, printed[jo.id!!]) | |||||
| PyJobOrderListMapper.toListItem(jo, printed[jo.id!!], stockInLineRepository, itemUomService) | |||||
| } | } | ||||
| } | } | ||||
| @@ -183,30 +186,6 @@ class PlasticBagPrinterService( | |||||
| .toSet() | .toSet() | ||||
| } | } | ||||
| private fun toPyJobOrderListItem(jo: JobOrder, printed: PrintedQtyByChannel?): PyJobOrderListItem { | |||||
| val itemCode = jo.bom?.item?.code ?: jo.bom?.code | |||||
| val itemName = jo.bom?.name ?: jo.bom?.item?.name | |||||
| val itemId = jo.bom?.item?.id | |||||
| val stockInLine = jo.id?.let { stockInLineRepository.findFirstByJobOrder_IdAndDeletedFalse(it) } | |||||
| val stockInLineId = stockInLine?.id | |||||
| val lotNo = stockInLine?.lotNo | |||||
| val p = printed ?: PrintedQtyByChannel() | |||||
| return PyJobOrderListItem( | |||||
| id = jo.id!!, | |||||
| code = jo.code, | |||||
| planStart = jo.planStart, | |||||
| itemCode = itemCode, | |||||
| itemName = itemName, | |||||
| reqQty = jo.reqQty, | |||||
| stockInLineId = stockInLineId, | |||||
| itemId = itemId, | |||||
| lotNo = lotNo, | |||||
| bagPrintedQty = p.bagPrintedQty, | |||||
| labelPrintedQty = p.labelPrintedQty, | |||||
| laserPrintedQty = p.laserPrintedQty, | |||||
| ) | |||||
| } | |||||
| /** | /** | ||||
| * Bag2.py [send_job_to_laser] / [send_job_to_laser_with_retry]: UTF-8 TCP payload and optional ack read. | * Bag2.py [send_job_to_laser] / [send_job_to_laser_with_retry]: UTF-8 TCP payload and optional ack read. | ||||
| */ | */ | ||||
| @@ -1,8 +1,8 @@ | |||||
| package com.ffii.fpsms.py | package com.ffii.fpsms.py | ||||
| import com.ffii.fpsms.modules.jobOrder.entity.JobOrder | |||||
| import com.ffii.fpsms.modules.jobOrder.entity.JobOrderRepository | import com.ffii.fpsms.modules.jobOrder.entity.JobOrderRepository | ||||
| import com.ffii.fpsms.modules.jobOrder.service.PlasticBagPrinterService | import com.ffii.fpsms.modules.jobOrder.service.PlasticBagPrinterService | ||||
| import com.ffii.fpsms.modules.master.service.ItemUomService | |||||
| import com.ffii.fpsms.modules.stock.entity.StockInLineRepository | import com.ffii.fpsms.modules.stock.entity.StockInLineRepository | ||||
| import org.springframework.format.annotation.DateTimeFormat | import org.springframework.format.annotation.DateTimeFormat | ||||
| import org.springframework.http.ResponseEntity | import org.springframework.http.ResponseEntity | ||||
| @@ -15,7 +15,6 @@ import org.springframework.web.bind.annotation.RestController | |||||
| import org.springframework.web.server.ResponseStatusException | import org.springframework.web.server.ResponseStatusException | ||||
| import org.springframework.http.HttpStatus | import org.springframework.http.HttpStatus | ||||
| import java.time.LocalDate | import java.time.LocalDate | ||||
| import java.time.LocalDateTime | |||||
| /** | /** | ||||
| * Public API for Python clients. No login required. | * Public API for Python clients. No login required. | ||||
| @@ -26,6 +25,7 @@ import java.time.LocalDateTime | |||||
| open class PyController( | open class PyController( | ||||
| private val jobOrderRepository: JobOrderRepository, | private val jobOrderRepository: JobOrderRepository, | ||||
| private val stockInLineRepository: StockInLineRepository, | private val stockInLineRepository: StockInLineRepository, | ||||
| private val itemUomService: ItemUomService, | |||||
| private val plasticBagPrinterService: PlasticBagPrinterService, | private val plasticBagPrinterService: PlasticBagPrinterService, | ||||
| private val pyJobOrderPrintSubmitService: PyJobOrderPrintSubmitService, | private val pyJobOrderPrintSubmitService: PyJobOrderPrintSubmitService, | ||||
| ) { | ) { | ||||
| @@ -54,7 +54,7 @@ open class PyController( | |||||
| val ids = orders.mapNotNull { it.id } | val ids = orders.mapNotNull { it.id } | ||||
| val printed = pyJobOrderPrintSubmitService.sumPrintedQtyByJobOrderIds(ids) | val printed = pyJobOrderPrintSubmitService.sumPrintedQtyByJobOrderIds(ids) | ||||
| val list = orders.map { jo -> | val list = orders.map { jo -> | ||||
| toListItem(jo, printed[jo.id!!]) | |||||
| PyJobOrderListMapper.toListItem(jo, printed[jo.id!!], stockInLineRepository, itemUomService) | |||||
| } | } | ||||
| return ResponseEntity.ok(list) | return ResponseEntity.ok(list) | ||||
| } | } | ||||
| @@ -90,28 +90,4 @@ open class PyController( | |||||
| val date = planStart ?: LocalDate.now() | val date = planStart ?: LocalDate.now() | ||||
| return ResponseEntity.ok(plasticBagPrinterService.listLaserPrintJobOrders(date)) | return ResponseEntity.ok(plasticBagPrinterService.listLaserPrintJobOrders(date)) | ||||
| } | } | ||||
| private fun toListItem(jo: JobOrder, printed: PrintedQtyByChannel?): PyJobOrderListItem { | |||||
| val itemCode = jo.bom?.item?.code ?: jo.bom?.code | |||||
| val itemName = jo.bom?.name ?: jo.bom?.item?.name | |||||
| val itemId = jo.bom?.item?.id | |||||
| val stockInLine = jo.id?.let { stockInLineRepository.findFirstByJobOrder_IdAndDeletedFalse(it) } | |||||
| val stockInLineId = stockInLine?.id | |||||
| val lotNo = stockInLine?.lotNo | |||||
| val p = printed ?: PrintedQtyByChannel() | |||||
| return PyJobOrderListItem( | |||||
| id = jo.id!!, | |||||
| code = jo.code, | |||||
| planStart = jo.planStart, | |||||
| itemCode = itemCode, | |||||
| itemName = itemName, | |||||
| reqQty = jo.reqQty, | |||||
| stockInLineId = stockInLineId, | |||||
| itemId = itemId, | |||||
| lotNo = lotNo, | |||||
| bagPrintedQty = p.bagPrintedQty, | |||||
| labelPrintedQty = p.labelPrintedQty, | |||||
| laserPrintedQty = p.laserPrintedQty, | |||||
| ) | |||||
| } | |||||
| } | } | ||||
| @@ -8,6 +8,7 @@ import java.time.LocalDateTime | |||||
| * No login required. | * No login required. | ||||
| * stockInLineId and itemId are for QR code: {"itemId": xxx, "stockInLineId": xxx} | * stockInLineId and itemId are for QR code: {"itemId": xxx, "stockInLineId": xxx} | ||||
| * lotNo replaces job order no. on the label display. | * lotNo replaces job order no. on the label display. | ||||
| * [itemName] is BOM/item display name plus stock UOM [udfudesc] in parentheses, e.g. "名稱(單位)". | |||||
| */ | */ | ||||
| data class PyJobOrderListItem( | data class PyJobOrderListItem( | ||||
| val id: Long, | val id: Long, | ||||
| @@ -0,0 +1,92 @@ | |||||
| package com.ffii.fpsms.py | |||||
| import com.ffii.fpsms.modules.jobOrder.entity.JobOrder | |||||
| import com.ffii.fpsms.modules.master.service.ItemUomService | |||||
| import com.ffii.fpsms.modules.stock.entity.StockInLineRepository | |||||
| object PyJobOrderListMapper { | |||||
| fun toListItem( | |||||
| jo: JobOrder, | |||||
| printed: PrintedQtyByChannel?, | |||||
| stockInLineRepository: StockInLineRepository, | |||||
| itemUomService: ItemUomService, | |||||
| ): PyJobOrderListItem { | |||||
| val itemCode = jo.bom?.item?.code ?: jo.bom?.code | |||||
| val baseName = jo.bom?.name ?: jo.bom?.item?.name | |||||
| val itemId = jo.bom?.item?.id | |||||
| val stockUnitDesc = itemId?.let { id -> | |||||
| itemUomService.findStockUnitByItemId(id)?.uom?.udfudesc | |||||
| }?.trim().orEmpty() | |||||
| val baseTrim = baseName?.trim().orEmpty() | |||||
| val itemName = when { | |||||
| stockUnitDesc.isEmpty() && baseTrim.isEmpty() -> null | |||||
| stockUnitDesc.isEmpty() -> baseTrim | |||||
| baseTrim.isEmpty() -> "($stockUnitDesc)" | |||||
| else -> "$baseTrim($stockUnitDesc)" | |||||
| } | |||||
| val stockInLine = jo.id?.let { stockInLineRepository.findFirstByJobOrder_IdAndDeletedFalse(it) } | |||||
| val stockInLineId = stockInLine?.id | |||||
| val lotNo = stockInLine?.lotNo | |||||
| val p = printed ?: PrintedQtyByChannel() | |||||
| return PyJobOrderListItem( | |||||
| id = jo.id!!, | |||||
| code = jo.code, | |||||
| planStart = jo.planStart, | |||||
| itemCode = itemCode, | |||||
| itemName = itemName, | |||||
| reqQty = jo.reqQty, | |||||
| stockInLineId = stockInLineId, | |||||
| itemId = itemId, | |||||
| lotNo = lotNo, | |||||
| bagPrintedQty = p.bagPrintedQty, | |||||
| labelPrintedQty = p.labelPrintedQty, | |||||
| laserPrintedQty = p.laserPrintedQty, | |||||
| ) | |||||
| } | |||||
| } | |||||