瀏覽代碼

adding auth, update printer testing service

master
[email protected] 3 週之前
父節點
當前提交
b63fb45215
共有 3 個檔案被更改,包括 59 行新增39 行删除
  1. +44
    -39
      src/main/java/com/ffii/fpsms/modules/jobOrder/service/PlasticBagPrinterService.kt
  2. +9
    -0
      src/main/resources/db/changelog/changes/20260110_fai/01_insert_auth.sql
  3. +6
    -0
      src/main/resources/db/changelog/changes/20260110_fai/02_insert_auth_for_2fi.sql

+ 44
- 39
src/main/java/com/ffii/fpsms/modules/jobOrder/service/PlasticBagPrinterService.kt 查看文件

@@ -105,34 +105,29 @@ open class PlasticBagPrinterService(
}
fun sendDataFlexJob(request: PrintRequest) {
try {
// 1. Establish Socket Connection
val socket = Socket(request.printerIp, request.printerPort)
socket.soTimeout = 5000 // 5 seconds timeout
val writer = PrintWriter(socket.getOutputStream(), true)

// 2. Format the command for DataFlex 6330
// Note: This format depends on your specific label design in CLARiSOFT.
// Many DataFlex printers use the "Job Select" or "Set Variable" protocol.
val command = """
^SVAR1|${request.itemCode}
^SVAR2|${request.itemName}
^SVAR3|${request.lotNo}
^SVAR4|${request.expiryDate}
^PRNT1
""".trimIndent()

// 3. Send and Close
writer.print(command)
writer.flush()
socket.close()
println("Successfully sent command to DataFlex at ${request.printerIp}")
} catch (e: Exception) {
throw RuntimeException("Failed to communicate with DataFlex printer: ${e.message}")
Socket().use { socket ->
try {
socket.connect(InetSocketAddress(request.printerIp, request.printerPort), 3000)
val writer = PrintWriter(socket.getOutputStream(), true)

// Videojet/DataFlex ASCII protocol
// We assign the Lot number to both the text variable and the barcode variable
val command = """
^SVAR1|${request.itemCode}
^SVAR2|${request.itemName}
^SVAR3|${request.lotNo}
^SVAR4|${request.expiryDate}
^SVAR_QR|${request.lotNo}
^PRNT1
""".trimIndent()

writer.println(command)
writer.flush()
println("DataFlex: Print job with QR data sent to ${request.printerIp}")
} catch (e: Exception) {
throw RuntimeException("DataFlex Error: ${e.message}")
}
}
}

@@ -191,28 +186,38 @@ open class PlasticBagPrinterService(
socket.connect(InetSocketAddress(request.printerIp, request.printerPort), 3000)
val out = DataOutputStream(socket.getOutputStream())

// Construct TSPL commands
// Note: Coordinates (x,y) are in dots.
// For 203 DPI: 8 dots = 1mm.
// 203 DPI: 8 dots = 1mm
val tspl = StringBuilder()
.append("SIZE 100 mm, 50 mm\n") // Adjust to your label size
.append("SIZE 100 mm, 50 mm\n")
.append("GAP 3 mm, 0 mm\n")
.append("DIRECTION 1\n")
.append("CLS\n") // Clear buffer
// Text commands: TEXT x, y, "font", rotation, x-multi, y-multi, "content"
.append("TEXT 50,50,\"ROMAN.TTF\",0,1,1,\"ITEM: ${request.itemCode}\"\n")
.append("TEXT 50,100,\"ROMAN.TTF\",0,1,1,\"NAME: ${request.itemName}\"\n")
.append("TEXT 50,150,\"ROMAN.TTF\",0,1,1,\"LOT: ${request.lotNo}\"\n")
.append("TEXT 50,200,\"ROMAN.TTF\",0,1,1,\"EXP: ${request.expiryDate}\"\n")
.append("CLS\n")
// --- Text Content ---
.append("TEXT 50,40,\"ROMAN.TTF\",0,1,1,\"ITEM: ${request.itemCode}\"\n")
.append("TEXT 50,80,\"ROMAN.TTF\",0,1,1,\"NAME: ${request.itemName}\"\n")
.append("TEXT 50,120,\"ROMAN.TTF\",0,1,1,\"EXP: ${request.expiryDate}\"\n")
.append("TEXT 50,160,\"ROMAN.TTF\",0,1,1,\"LOT: ${request.lotNo}\"\n")

// --- QR Code for Lot Number ---
// Syntax: QRCODE x, y, ECC, cell_width, mode, rotation, "content"
// ECC Level M (Standard), Cell width 4 (size), Auto mode, 0 rotation
.append("QRCODE 450,40,M,4,A,0,\"${request.lotNo}\"\n")
// Optional: Label for the QR Code
.append("TEXT 450,180,\"ROMAN.TTF\",0,1,1,\"SCAN LOT\"\n")

.append("PRINT 1,1\n")
.toString()

// TSC printers usually expect encoding in Windows-1252 or Thai (TIS-620)
// Use TIS-620 for Thai support or Windows-1252 for English
val bytes = tspl.toByteArray(Charset.forName("TIS-620"))
out.write(bytes)
out.flush()
println("TSC: Print job with QR code sent to ${request.printerIp}")
} catch (e: Exception) {
println("TSC Error: ${e.message}")
throw RuntimeException("TSC Printer Error: ${e.message}")
}
}


+ 9
- 0
src/main/resources/db/changelog/changes/20260110_fai/01_insert_auth.sql 查看文件

@@ -0,0 +1,9 @@
--liquibase formatted sql
--changeset author:add_auth

INSERT INTO `fpsmsdb`.`authority` (`authority`, `name`) VALUES ('TESTING', 'Testing');
INSERT INTO `fpsmsdb`.`authority` (`authority`, `name`) VALUES ('PROD', '出品');
INSERT INTO `fpsmsdb`.`authority` (`authority`, `name`) VALUES ('ADMIN', '行政');
INSERT INTO `fpsmsdb`.`authority` (`authority`, `name`) VALUES ('STOCK', '倉務');
INSERT INTO `fpsmsdb`.`authority` (`authority`, `name`) VALUES ('Driver', '物流');
INSERT INTO `fpsmsdb`.`authority` (`authority`, `name`) VALUES ('PACK', '包裝');

+ 6
- 0
src/main/resources/db/changelog/changes/20260110_fai/02_insert_auth_for_2fi.sql 查看文件

@@ -0,0 +1,6 @@
--liquibase formatted sql
--changeset author:add_auth_for_2fi

INSERT INTO `fpsmsdb`.`user_authority` (`userId`, `authId`) VALUES ('1', '13');
INSERT INTO `fpsmsdb`.`user_authority` (`userId`, `authId`) VALUES ('1', '15');


Loading…
取消
儲存