Compare commits

..

No commits in common. "dd5b3724b13646792039dae507f7241afc65687d" and "0da5e307b6ed07743c9b0aff2dd3e919f9872596" have entirely different histories.

7 changed files with 91 additions and 121 deletions

View File

@ -361,7 +361,6 @@
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<finalName>ctp-service</finalName>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>

View File

@ -5,7 +5,6 @@ import com.utopiaindustries.dao.ctp.BundleWrapper;
import com.utopiaindustries.model.ctp.JobCardWrapper; import com.utopiaindustries.model.ctp.JobCardWrapper;
import com.utopiaindustries.service.*; import com.utopiaindustries.service.*;
import com.utopiaindustries.util.StringUtils; import com.utopiaindustries.util.StringUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -156,14 +155,7 @@ public class CuttingController {
redirectAttributes.addFlashAttribute("error", "Please Select At least One CheckBox." ); redirectAttributes.addFlashAttribute("error", "Please Select At least One CheckBox." );
return "redirect:/cutting/bundles"; return "redirect:/cutting/bundles";
} }
try { return barcodeService.generateBarcodes( Arrays.asList( ids ), artifactType );
barcodeService.generateBarcodes( Arrays.asList( ids ), artifactType );
redirectAttributes.addFlashAttribute( "success", "Barcode generated successfully" );
return "redirect:/cutting/bundles";
}catch (Exception e){
redirectAttributes.addFlashAttribute( "error", e );
return "redirect:/cutting/bundles";
}
} }
@PostMapping( "/generate-master-barcodes" ) @PostMapping( "/generate-master-barcodes" )
@ -173,13 +165,6 @@ public class CuttingController {
redirectAttributes.addFlashAttribute("error", "Please Select At least One CheckBox." ); redirectAttributes.addFlashAttribute("error", "Please Select At least One CheckBox." );
return "redirect:/cutting/master-bundles"; return "redirect:/cutting/master-bundles";
} }
try { return barcodeService.generateBarcodes( Arrays.asList( ids ), artifactType );
barcodeService.generateBarcodes( Arrays.asList( ids ), artifactType );
redirectAttributes.addFlashAttribute( "success", "Master barcode generated successfully" );
return "redirect:/cutting/master-bundles";
}catch (Exception e){
redirectAttributes.addFlashAttribute( "error", e );
return "redirect:/cutting/master-bundles";
}
} }
} }

View File

@ -5,7 +5,6 @@ import com.utopiaindustries.model.ctp.JobCard;
import com.utopiaindustries.model.ctp.StitchingOfflineItem; import com.utopiaindustries.model.ctp.StitchingOfflineItem;
import com.utopiaindustries.service.*; import com.utopiaindustries.service.*;
import com.utopiaindustries.util.StringUtils; import com.utopiaindustries.util.StringUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -131,18 +130,11 @@ public class StitchingController {
@PostMapping( "/generate-barcodes" ) @PostMapping( "/generate-barcodes" )
public Object generateBarcode(@RequestParam( name = "ids" ,required = false) Long[] ids, public Object generateBarcode(@RequestParam( name = "ids" ,required = false) Long[] ids,
@RequestParam( name = "artifactType" ) String artifactType, RedirectAttributes redirectAttributes ) throws Exception { @RequestParam( name = "artifactType" ) String artifactType, RedirectAttributes redirectAttributes ) throws Exception {
if (ids == null){ if (ids == null){
redirectAttributes.addFlashAttribute( "error", "Select At least One CheckBox" ); redirectAttributes.addFlashAttribute( "error", "Select At least One CheckBox" );
return "redirect:/stitching/stitching-offline-items"; return "redirect:/stitching/stitching-offline-items";
} }
try { return barcodeService.generateBarcodes( Arrays.asList( ids ), artifactType );
barcodeService.generateBarcodes( Arrays.asList( ids ), artifactType );
redirectAttributes.addFlashAttribute( "success", "Barcode generated successfully" );
return "redirect:/stitching/stitching-offline-items";
}catch (Exception e){
redirectAttributes.addFlashAttribute( "error", e );
return "redirect:/stitching/stitching-offline-items";
}
} }
} }

View File

@ -5,8 +5,7 @@ public enum BarcodeStickerSize {
SIZE_1_5_X_3( 3 * 72, 1.5f * 72, 10, 10, 6, 6, 50, 50, 125, 125, 14, 9, 7), SIZE_1_5_X_3( 3 * 72, 1.5f * 72, 10, 10, 6, 6, 50, 50, 125, 125, 14, 9, 7),
SIZE_2_X_3( 3 * 72, 2 * 72, 10, 10, 6, 6, 50, 50, 125, 125, 14, 9, 7), SIZE_2_X_3( 3 * 72, 2 * 72, 10, 10, 6, 6, 50, 50, 125, 125, 14, 9, 7),
SIZE_4_X_4( 4 * 72, 4 * 72, 8, 8, 8, 8, 200, 100, 250, 250, 14, 9, 7), SIZE_4_X_4( 4 * 72, 4 * 72, 8, 8, 8, 8, 200, 100, 250, 250, 14, 9, 7),
SIZE_1_75_X_3_5( 3.5f * 72, 1.75f * 72, 10, 10, 6, 6, 50, 50, 125, 125, 14, 9, 7), SIZE_1_75_X_3_5( 3.5f * 72, 1.75f * 72, 10, 10, 6, 6, 50, 50, 125, 125, 14, 9, 7);
SIZE_4_X_7( 7f * 72, 4f * 72, 10, 10, 6, 6, 50, 50, 125, 125, 14, 9, 7);
private final float width; private final float width;

View File

@ -1,6 +1,10 @@
package com.utopiaindustries.service; package com.utopiaindustries.service;
import com.google.zxing.BarcodeFormat; import com.google.zxing.BarcodeFormat;
import com.itextpdf.html2pdf.ConverterProperties;
import com.itextpdf.html2pdf.resolver.font.DefaultFontProvider;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.*;
import com.utopiaindustries.dao.ctp.BundleDAO; import com.utopiaindustries.dao.ctp.BundleDAO;
import com.utopiaindustries.dao.ctp.FinishedItemDAO; import com.utopiaindustries.dao.ctp.FinishedItemDAO;
import com.utopiaindustries.dao.ctp.MasterBundleDAO; import com.utopiaindustries.dao.ctp.MasterBundleDAO;
@ -8,18 +12,16 @@ import com.utopiaindustries.dao.ctp.StitchingOfflineItemDAO;
import com.utopiaindustries.model.ctp.*; import com.utopiaindustries.model.ctp.*;
import com.utopiaindustries.util.BarcodeUtils; import com.utopiaindustries.util.BarcodeUtils;
import com.utopiaindustries.util.StringUtils; import com.utopiaindustries.util.StringUtils;
import com.zebra.sdk.comm.Connection; import org.springframework.core.io.DefaultResourceLoader;
import com.zebra.sdk.comm.TcpConnection; import org.springframework.core.io.InputStreamResource;
import com.zebra.sdk.graphics.internal.ZebraImage; import org.springframework.core.io.ResourceLoader;
import com.zebra.sdk.printer.ZebraPrinter; import org.springframework.http.HttpHeaders;
import com.zebra.sdk.printer.ZebraPrinterFactory; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.Font;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -42,8 +44,8 @@ public class BarcodeService {
/* /*
* generate barcodes here * generate barcodes here
* */ * */
public void generateBarcodes(List<Long> ids, String artifactType) throws Exception { public ResponseEntity<InputStreamResource> generateBarcodes(List<Long> ids, String artifactType) throws Exception {
String size = BarcodeStickerSize.SIZE_4_X_7.name(); String size = BarcodeStickerSize.SIZE_1_75_X_3_5.name();
BarcodeStickerSize stickerSize = BarcodeStickerSize.getSize(size); BarcodeStickerSize stickerSize = BarcodeStickerSize.getSize(size);
List<? extends InventoryArtifact> list = new ArrayList<>(); List<? extends InventoryArtifact> list = new ArrayList<>();
@ -55,81 +57,89 @@ public class BarcodeService {
list = stitchingOfflineItemDAO.findByIds(ids); list = stitchingOfflineItemDAO.findByIds(ids);
} }
getBarcodeImages(list, stickerSize, artifactType); // get input stream
ByteArrayInputStream inputStream = null;
// get input stream
inputStream = getInputStream(list, stickerSize, artifactType);
String headerContentDispositionStr = String.format("%s; filename=%s.pdf", "attachment", artifactType);
// return response
return ResponseEntity
.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, headerContentDispositionStr)
.contentType(MediaType.APPLICATION_PDF)
.body(new InputStreamResource(inputStream));
} }
public void getBarcodeImages(List<? extends InventoryArtifact> artifacts, private ByteArrayInputStream getInputStream(List<? extends InventoryArtifact> artifacts,
BarcodeStickerSize stickerSize, BarcodeStickerSize stickerSize,
String artifactType) throws Exception { String artifactType) throws Exception {
// resource loader
ResourceLoader resourceLoader = new DefaultResourceLoader();
// output stream
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// converter properties
ConverterProperties properties = new ConverterProperties();
properties.setFontProvider(new DefaultFontProvider(false, false, true));
// generate pdf
Document document = new Document(new Rectangle(stickerSize.getWidth(), stickerSize.getHeight()), stickerSize.getMarginLeft(), stickerSize.getMarginRight(), stickerSize.getMarginTop(), stickerSize.getMarginBottom());
PdfWriter.getInstance(document, outputStream);
document.open();
for (InventoryArtifact artifact : artifacts) { for (InventoryArtifact artifact : artifacts) {
// Create a blank BufferedImage (an image with the size of the sticker) document.newPage();
BufferedImage stickerImage = new BufferedImage((int) stickerSize.getWidth()*2, (int) stickerSize.getHeight()*2, BufferedImage.TYPE_INT_ARGB); // add sku
Graphics2D g2d = stickerImage.createGraphics(); Paragraph skuPara = new Paragraph(artifact.getSku(), new Font(Font.FontFamily.HELVETICA, stickerSize.getTextSizeSmall(), Font.BOLD));
g2d.scale(2,2); skuPara.setAlignment(Element.ALIGN_CENTER);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); document.add(skuPara);
// Set background color (white for the sticker) // add barcode image
g2d.setColor(Color.WHITE); byte[] imgBytes = BarcodeUtils.getBarcodeImageByteArray(artifact.getBarcode(), BarcodeFormat.CODE_128, stickerSize.getImageWidthBarcode(), stickerSize.getImageHeightBarcode());
g2d.fillRect(0, 0, (int) stickerSize.getWidth(), (int) stickerSize.getHeight()); Image image = Image.getInstance(imgBytes);
image.setAlignment(Element.ALIGN_CENTER);
document.add(image);
// Set font for SKU and barcode Paragraph barcodePara = new Paragraph(artifact.getBarcode(), new Font(Font.FontFamily.HELVETICA, stickerSize.getTextSizeSmall(), Font.BOLD));
Font font = new Font("Helvetica", Font.BOLD, stickerSize.getTextSize()+10); barcodePara.setAlignment(Element.ALIGN_CENTER);
g2d.setFont(font); document.add(barcodePara);
// add Artifact mark B / M / F
if ( artifactType.equalsIgnoreCase( Bundle.class.getSimpleName()) ) {
Paragraph artifactPara = new Paragraph(String.format("%s : %d", artifact.getType(), artifact.getId() ), new Font(Font.FontFamily.HELVETICA, stickerSize.getTextSizeExtraSmall(), Font.NORMAL));
artifactPara.setAlignment(Element.ALIGN_CENTER);
// Add SKU to the image Paragraph type = new Paragraph(String.valueOf(artifactType.toCharArray()[0]), new Font(Font.FontFamily.HELVETICA, stickerSize.getTextSize(), Font.BOLD));
String sku = artifact.getSku(); type.setAlignment(Element.ALIGN_CENTER);
FontMetrics fontMetrics = g2d.getFontMetrics();
int textWidth = fontMetrics.stringWidth(sku);
int x = (int) ((stickerSize.getWidth() - textWidth) / 2);
g2d.setColor(Color.BLACK);
g2d.drawString(sku, x, stickerSize.getMarginTop() + fontMetrics.getAscent()+20);
// Create the barcode image // Create a table with 2 columns
byte[] imgBytes = BarcodeUtils.getBarcodeImageByteArray(artifact.getBarcode(), BarcodeFormat.CODE_128, stickerSize.getImageWidthBarcode()+500, stickerSize.getImageHeightBarcode()+30); PdfPTable table = new PdfPTable(2);
BufferedImage barcodeImage = ImageIO.read(new ByteArrayInputStream(imgBytes)); table.setWidthPercentage(100);
table.setWidths(new int[]{55, 45}); // Adjust column widths as needed
// Draw the barcode image on the sticker // Add cells to the table
int barcodeX =(int) (stickerSize.getWidth() - barcodeImage.getWidth()) / 2; PdfPCell artifactCell = new PdfPCell(artifactPara);
int barcodeY = stickerSize.getMarginTop() + fontMetrics.getAscent() + 30; // Add some margin artifactCell.setBorder(Rectangle.NO_BORDER);
g2d.drawImage(barcodeImage, barcodeX, barcodeY, null); artifactCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
artifactCell.setPaddingTop(5);
// Add the barcode value below the barcode image PdfPCell typeCell = new PdfPCell(type);
g2d.drawString(artifact.getBarcode(), (stickerSize.getWidth() - fontMetrics.stringWidth(artifact.getBarcode())) / 2, typeCell.setBorder(Rectangle.NO_BORDER);
barcodeY + barcodeImage.getHeight() + fontMetrics.getAscent()); typeCell.setHorizontalAlignment(Element.ALIGN_LEFT);
// If artifactType is Bundle, add additional info table.addCell(artifactCell);
if (artifactType.equalsIgnoreCase(Bundle.class.getSimpleName())) { table.addCell(typeCell);
String typeText = String.format("%s : %d", artifact.getType(), artifact.getId()); // Add the table to the document
g2d.drawString(typeText, (stickerSize.getWidth() - fontMetrics.stringWidth(typeText)) / 2, document.add(table);
barcodeY + barcodeImage.getHeight() + fontMetrics.getAscent() + 45);
g2d.setFont(new Font("Helvetica", Font.BOLD, stickerSize.getTextSize()+20));
g2d.drawString(String.valueOf(artifactType.toCharArray()[0]), (stickerSize.getWidth() - fontMetrics.stringWidth(String.valueOf(artifactType.toCharArray()[0]))) / 2,
barcodeY + barcodeImage.getHeight() + fontMetrics.getAscent() + 77);
} else { } else {
// Add first character of artifact type Paragraph type = new Paragraph(String.valueOf(artifactType.toCharArray()[0]), new Font(Font.FontFamily.HELVETICA, stickerSize.getTextSize(), Font.BOLD));
String type = String.valueOf(artifactType.charAt(0)); type.setAlignment(Element.ALIGN_CENTER);
g2d.setFont(new Font("Helvetica", Font.BOLD, stickerSize.getTextSize()+10)); document.add(type);
g2d.drawString(type, (stickerSize.getWidth() - fontMetrics.stringWidth(type)) / 2,
barcodeY + barcodeImage.getHeight() + fontMetrics.getAscent() + 45);
} }
// Finalize drawing
g2d.dispose();
printLabel(stickerImage);
} }
document.close();
// input stream
return new ByteArrayInputStream(outputStream.toByteArray());
} }
public void printLabel( BufferedImage bufferedImage ) throws Exception {
String ipAddr = "192.168.90.160";
int port = 9100;
Connection connection = new TcpConnection( ipAddr, port );
connection.open();
ZebraPrinter printer = ZebraPrinterFactory.getInstance( connection );
ZebraImage zebraImage = new ZebraImage( bufferedImage );
printer.printImage( zebraImage, 0, 0, 0, 0, false );
connection.close();
}
} }

View File

@ -14,11 +14,11 @@ spring:
enabled: true enabled: true
cache: cache:
period: 0 period: 0
static-locations: classpath:/static/ static-locations: file:./src/main/resources/static/
thymeleaf: thymeleaf:
check-template-location: true check-template-location: true
cache: false cache: false
prefix: classpath:/templates/ prefix: file:./src/main/resources/templates/
uinddatasource: uinddatasource:
jdbcUrl: jdbc:mysql://192.168.90.108:3306/uind_vms jdbcUrl: jdbc:mysql://192.168.90.108:3306/uind_vms
username: utopia username: utopia

View File

@ -6,29 +6,14 @@
<body> <body>
<!-- flash messages --> <!-- flash messages -->
<div th:fragment="page-notices"> <div th:fragment="page-notices">
<div id="error" class="collapse show alert alert-danger" th:if="${error}" > <div class="alert alert-danger" th:if="${error}" th:text="${error}"></div>
<div class="d-flex justify-content-between align-items-center" style="position: relative;">
<span th:text="${error}"></span>
<span class="btn font-lg" data-toggle="collapse" data-target="#error">&times;</span>
</div>
</div>
<div class="alert alert-danger" th:if="${errors != null && #lists.size(errors) > 0}"> <div class="alert alert-danger" th:if="${errors != null && #lists.size(errors) > 0}">
<ul class="mb-0"> <ul class="mb-0">
<li th:each="error: ${errors}" th:text="${error}"></li> <li th:each="error: ${errors}" th:text="${error}"></li>
</ul> </ul>
</div> </div>
<div id="success" class="collapse show alert alert-success" th:if="${success}" > <div class="alert alert-success" th:if="${success}" th:text="${success}"></div>
<div class="d-flex justify-content-between align-items-center" style="position: relative;"> <div class="alert alert-warning" th:if="${warning}" th:text="${warning}"></div>
<span th:text="${success}"></span>
<span class="btn font-lg" data-toggle="collapse" data-target="#success">&times;</span>
</div>
</div>
<div id="warning" class="collapse show alert alert-warning" th:if="${warning}" th:text="${warning}">
<div class="d-flex justify-content-between align-items-center" style="position: relative;">
<span th:text="${warning}"></span>
<span class="btn font-lg" data-toggle="collapse" data-target="#warning">&times;</span>
</div>
</div>
</div> </div>
</body> </body>
</html> </html>