Barcode Printing Utility Done

This commit is contained in:
2026-09-04 18:30:26 +05:30
parent 5e9b3f2122
commit 2c04a993f7
33 changed files with 8481 additions and 5 deletions

View File

@@ -0,0 +1,56 @@
package com.kifi.api.controller.barcode;
import com.kifi.api.entity.barcode.BarcodeLabelTemplate;
import com.kifi.api.service.barcode.BarcodeLabelTemplateService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@RestController
@RequestMapping("/api/kifi-v2/barcode-templates")
@RequiredArgsConstructor
public class BarcodeLabelTemplateController {
private final BarcodeLabelTemplateService templateService;
@GetMapping
public Flux<BarcodeLabelTemplate> getTemplates(Authentication authentication) {
Long userId = Long.valueOf(authentication.getDetails().toString());
return templateService.getActiveTemplates(userId);
}
@GetMapping("/{id}")
public Mono<BarcodeLabelTemplate> getTemplateById(
Authentication authentication,
@PathVariable Long id) {
Long userId = Long.valueOf(authentication.getDetails().toString());
return templateService.getTemplateById(userId, id);
}
@PostMapping
public Mono<BarcodeLabelTemplate> createTemplate(
Authentication authentication,
@RequestBody BarcodeLabelTemplate template) {
Long userId = Long.valueOf(authentication.getDetails().toString());
return templateService.createTemplate(userId, template);
}
@PutMapping("/{id}")
public Mono<BarcodeLabelTemplate> updateTemplate(
Authentication authentication,
@PathVariable Long id,
@RequestBody BarcodeLabelTemplate template) {
Long userId = Long.valueOf(authentication.getDetails().toString());
return templateService.updateTemplate(userId, id, template);
}
@DeleteMapping("/{id}")
public Mono<Void> deleteTemplate(
Authentication authentication,
@PathVariable Long id) {
Long userId = Long.valueOf(authentication.getDetails().toString());
return templateService.deleteTemplate(userId, id);
}
}

View File

@@ -0,0 +1,71 @@
package com.kifi.api.entity.barcode;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Column;
import org.springframework.data.relational.core.mapping.Table;
import java.time.LocalDateTime;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("barcode_label_templates")
public class BarcodeLabelTemplate {
@Id
private Long id;
@Column("user_id")
private Long userId;
@Column("template_name")
private String templateName;
private String description;
@Builder.Default
private String category = "PRODUCT";
@Builder.Default
private Integer version = 1;
@Column("label_width_mm")
@Builder.Default
private Double labelWidthMm = 50.0;
@Column("label_height_mm")
@Builder.Default
private Double labelHeightMm = 25.0;
@Column("measurement_unit")
@Builder.Default
private String measurementUnit = "mm";
@Column("printer_language")
@Builder.Default
private String printerLanguage = "ZPL";
@Builder.Default
private Integer dpi = 203;
@Column("configuration_json")
@Builder.Default
private String configurationJson = "{}";
@Column("template_json")
private String templateJson;
@Column("is_active")
@Builder.Default
private Boolean isActive = true;
@Column("created_at")
private LocalDateTime createdAt;
@Column("updated_at")
private LocalDateTime updatedAt;
}

View File

@@ -29,6 +29,7 @@ public class Product {
private String barcode;
private String hsnCode;
private String description;
private BigDecimal mrp;
private BigDecimal sellingPrice;
private BigDecimal gstRate;
private String dimensions;

View File

@@ -0,0 +1,15 @@
package com.kifi.api.repository.barcode;
import com.kifi.api.entity.barcode.BarcodeLabelTemplate;
import org.springframework.data.r2dbc.repository.Query;
import org.springframework.data.r2dbc.repository.R2dbcRepository;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
public interface BarcodeLabelTemplateRepository extends R2dbcRepository<BarcodeLabelTemplate, Long> {
Flux<BarcodeLabelTemplate> findByUserIdAndIsActiveTrueOrderByUpdatedAtDesc(Long userId);
Flux<BarcodeLabelTemplate> findByUserIdOrderByUpdatedAtDesc(Long userId);
Mono<BarcodeLabelTemplate> findByIdAndUserId(Long id, Long userId);
}

View File

@@ -0,0 +1,73 @@
package com.kifi.api.service.barcode;
import com.kifi.api.entity.barcode.BarcodeLabelTemplate;
import com.kifi.api.repository.barcode.BarcodeLabelTemplateRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import java.time.LocalDateTime;
@Service
@RequiredArgsConstructor
@Slf4j
public class BarcodeLabelTemplateService {
private final BarcodeLabelTemplateRepository templateRepository;
public Flux<BarcodeLabelTemplate> getActiveTemplates(Long userId) {
return templateRepository.findByUserIdAndIsActiveTrueOrderByUpdatedAtDesc(userId);
}
public Mono<BarcodeLabelTemplate> getTemplateById(Long userId, Long id) {
return templateRepository.findByIdAndUserId(id, userId);
}
public Mono<BarcodeLabelTemplate> createTemplate(Long userId, BarcodeLabelTemplate template) {
template.setId(null);
template.setUserId(userId);
template.setCreatedAt(LocalDateTime.now());
template.setUpdatedAt(LocalDateTime.now());
if (template.getIsActive() == null) {
template.setIsActive(true);
}
if (template.getVersion() == null) {
template.setVersion(1);
}
return templateRepository.save(template);
}
public Mono<BarcodeLabelTemplate> updateTemplate(Long userId, Long id, BarcodeLabelTemplate template) {
return templateRepository.findByIdAndUserId(id, userId)
.switchIfEmpty(Mono.error(new IllegalArgumentException("Template not found or access denied: " + id)))
.flatMap(existing -> {
if (template.getTemplateName() != null) existing.setTemplateName(template.getTemplateName());
if (template.getDescription() != null) existing.setDescription(template.getDescription());
if (template.getCategory() != null) existing.setCategory(template.getCategory());
if (template.getLabelWidthMm() != null) existing.setLabelWidthMm(template.getLabelWidthMm());
if (template.getLabelHeightMm() != null) existing.setLabelHeightMm(template.getLabelHeightMm());
if (template.getMeasurementUnit() != null) existing.setMeasurementUnit(template.getMeasurementUnit());
if (template.getPrinterLanguage() != null) existing.setPrinterLanguage(template.getPrinterLanguage());
if (template.getDpi() != null) existing.setDpi(template.getDpi());
if (template.getConfigurationJson() != null) existing.setConfigurationJson(template.getConfigurationJson());
if (template.getTemplateJson() != null) existing.setTemplateJson(template.getTemplateJson());
if (template.getIsActive() != null) existing.setIsActive(template.getIsActive());
existing.setVersion((existing.getVersion() != null ? existing.getVersion() : 1) + 1);
existing.setUpdatedAt(LocalDateTime.now());
return templateRepository.save(existing);
});
}
public Mono<Void> deleteTemplate(Long userId, Long id) {
return templateRepository.findByIdAndUserId(id, userId)
.flatMap(existing -> {
existing.setIsActive(false);
existing.setUpdatedAt(LocalDateTime.now());
return templateRepository.save(existing);
})
.then();
}
}

View File

@@ -96,6 +96,7 @@ public class ProductService {
existingProduct.setSku(updatedProduct.getSku());
existingProduct.setCategoryId(updatedProduct.getCategoryId());
existingProduct.setUomId(updatedProduct.getUomId());
existingProduct.setMrp(updatedProduct.getMrp());
existingProduct.setSellingPrice(updatedProduct.getSellingPrice());
existingProduct.setGstRate(updatedProduct.getGstRate());
existingProduct.setHsnCode(updatedProduct.getHsnCode());

View File

@@ -244,6 +244,7 @@ CREATE TABLE IF NOT EXISTS products (
barcode VARCHAR(100),
description TEXT,
purchase_price DECIMAL(15, 2),
mrp DECIMAL(15, 2),
selling_price DECIMAL(15, 2),
gst_rate DECIMAL(5, 2),
dimensions VARCHAR(100),
@@ -600,3 +601,25 @@ CREATE TABLE IF NOT EXISTS project_task_comments (
images TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS barcode_label_templates (
id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
template_name VARCHAR(150) NOT NULL,
description TEXT,
category VARCHAR(50) DEFAULT 'PRODUCT',
version INTEGER DEFAULT 1,
label_width_mm DOUBLE PRECISION NOT NULL DEFAULT 50.0,
label_height_mm DOUBLE PRECISION NOT NULL DEFAULT 25.0,
measurement_unit VARCHAR(10) DEFAULT 'mm',
printer_language VARCHAR(20) DEFAULT 'ZPL',
dpi INTEGER DEFAULT 203,
configuration_json TEXT NOT NULL DEFAULT '{}',
template_json TEXT NOT NULL,
is_active BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_barcode_templates_user ON barcode_label_templates(user_id);