-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor package structure, remove unused files, and add dark theme s…
…tyles
- Loading branch information
1 parent
ee67ccc
commit fc5b81d
Showing
18 changed files
with
602 additions
and
549 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
src/main/java/com/zpl/zpl/application/ZplFileGenerator.java
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
src/main/java/com/zpl/zpl/application/usecase/LabelGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.zpl.zpl.application.usecase; | ||
|
||
import com.zpl.zpl.domain.service.ZplFormatService; | ||
import com.zpl.zpl.domain.service.ZplValidationService; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class LabelGenerator { | ||
private final ZplFormatService zplFormatService; | ||
private final ZplValidationService zplValidationService; | ||
|
||
public LabelGenerator() { | ||
this.zplFormatService = new ZplFormatService(); | ||
this.zplValidationService = new ZplValidationService(); | ||
} | ||
|
||
public String generateZpl(List<Map<String, Object>> eansAndSkus, String labelFormat, String labelType, int labelWidth, int labelHeight, int columns, int rows) { | ||
zplValidationService.validateData(eansAndSkus); | ||
return zplFormatService.generateZpl(eansAndSkus, labelFormat, labelType, labelWidth, labelHeight, columns, rows); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...om/zpl/zpl/usecase/SpreadsheetReader.java → ...pplication/usecase/SpreadsheetReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
src/main/java/com/zpl/zpl/domain/service/ZplFormatService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package com.zpl.zpl.domain.service; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class ZplFormatService { | ||
|
||
public String generateZpl(List<Map<String, Object>> eansAndSkus, String labelFormat, String labelType, int labelWidth, int labelHeight, int columns, int rows) { | ||
switch (labelFormat) { | ||
case "2-Colunas": | ||
return generateZpl2Columns(eansAndSkus, labelType, labelWidth, labelHeight, columns); | ||
case "1-Coluna": | ||
return generateZpl1Column(eansAndSkus, labelType, labelWidth, labelHeight); | ||
case "4-etiquetas por página": | ||
return generateZpl4LabelsPerPage(eansAndSkus, labelType, labelWidth, labelHeight, columns, rows); | ||
default: | ||
throw new IllegalArgumentException("Formato de etiqueta desconhecido."); | ||
} | ||
} | ||
|
||
private String generateZpl2Columns(List<Map<String, Object>> eansAndSkus, String labelType, int labelWidth, int labelHeight, int columns) { | ||
StringBuilder zpl = new StringBuilder("^XA^CI28\n"); | ||
int xOffset = 0; | ||
int yOffset = 0; | ||
int columnCount = 0; | ||
|
||
for (Map<String, Object> item : eansAndSkus) { | ||
String ean = item.get("EAN").toString(); | ||
String sku = item.get("SKU").toString(); | ||
int quantity = Integer.parseInt(item.get("Quantidade").toString()); | ||
for (int i = 0; i < quantity; i++) { | ||
zpl.append(generateLabelContent(labelType, xOffset, yOffset, ean, sku)); | ||
columnCount++; | ||
xOffset += labelWidth; | ||
|
||
if (columnCount == columns) { | ||
xOffset = 0; | ||
yOffset += labelHeight; | ||
columnCount = 0; | ||
} | ||
} | ||
} | ||
|
||
zpl.append("^XZ"); | ||
return zpl.toString(); | ||
} | ||
|
||
private String generateZpl1Column(List<Map<String, Object>> eansAndSkus, String labelType, int labelWidth, int labelHeight) { | ||
StringBuilder zpl = new StringBuilder("^XA^CI28\n"); | ||
int yOffset = 0; | ||
|
||
for (Map<String, Object> item : eansAndSkus) { | ||
String ean = item.get("EAN").toString(); | ||
String sku = item.get("SKU").toString(); | ||
int quantity = Integer.parseInt(item.get("Quantidade").toString()); | ||
for (int i = 0; i < quantity; i++) { | ||
zpl.append(generateLabelContent(labelType, 0, yOffset, ean, sku)); | ||
yOffset += labelHeight; | ||
} | ||
} | ||
|
||
zpl.append("^XZ"); | ||
return zpl.toString(); | ||
} | ||
|
||
private String generateZpl4LabelsPerPage(List<Map<String, Object>> eansAndSkus, String labelType, int labelWidth, int labelHeight, int columns, int rows) { | ||
StringBuilder zpl = new StringBuilder("^XA^CI28\n"); | ||
int xOffset = 0; | ||
int yOffset = 0; | ||
int columnCount = 0; | ||
int rowCount = 0; | ||
|
||
for (Map<String, Object> item : eansAndSkus) { | ||
String ean = item.get("EAN").toString(); | ||
String sku = item.get("SKU").toString(); | ||
int quantity = Integer.parseInt(item.get("Quantidade").toString()); | ||
for (int i = 0; i < quantity; i++) { | ||
zpl.append(generateLabelContent(labelType, xOffset, yOffset, ean, sku)); | ||
columnCount++; | ||
xOffset += labelWidth; | ||
|
||
if (columnCount == columns) { | ||
xOffset = 0; | ||
yOffset += labelHeight; | ||
columnCount = 0; | ||
rowCount++; | ||
} | ||
|
||
if (rowCount == rows) { | ||
xOffset = 0; | ||
yOffset = 0; | ||
rowCount = 0; | ||
} | ||
} | ||
} | ||
|
||
zpl.append("^XZ"); | ||
return zpl.toString(); | ||
} | ||
|
||
private String generateLabelContent(String labelType, int xOffset, int yOffset, String ean, String sku) { | ||
switch (labelType) { | ||
case "Code128": | ||
return String.format( | ||
"^LH%d,%d\n^FO65,18^BY2,,0^BCN,54,N,N^FD%s^FS\n^FO145,80^A0N,20,25^FH^FD%s^FS\n^FO146,80^A0N,20,25^FH^FD%s^FS\n", | ||
xOffset, yOffset, ean, sku, sku | ||
); | ||
case "QRCode": | ||
return String.format( | ||
"^LH%d,%d\n^FO50,50^BQN,2,10^FDQA,%s^FS\n", xOffset, yOffset, ean | ||
); | ||
default: | ||
throw new IllegalArgumentException("Tipo de etiqueta desconhecido."); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/zpl/zpl/domain/service/ZplValidationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.zpl.zpl.domain.service; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class ZplValidationService { | ||
|
||
public void validateData(List<Map<String, Object>> eansAndSkus) { | ||
for (Map<String, Object> item : eansAndSkus) { | ||
if (!item.containsKey("EAN") || !item.containsKey("SKU") || !item.containsKey("Quantidade")) { | ||
throw new IllegalArgumentException("Dados inválidos: EAN, SKU e Quantidade são obrigatórios."); | ||
} | ||
if (!item.get("EAN").toString().matches("\\d+")) { | ||
throw new IllegalArgumentException("EAN deve conter apenas números."); | ||
} | ||
try { | ||
Integer.parseInt(item.get("Quantidade").toString()); | ||
} catch (NumberFormatException e) { | ||
throw new IllegalArgumentException("Quantidade deve ser um número inteiro."); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.