Billing System using Spring Boot, Custom ID Generator for Employee, Customer, and Vendor

Billing System using Spring Boot, Custom ID Generator for Employee, Customer, and Vendor

Welcome back friends, in this story, I will be going to explain how I am using a Custom ID generator for Employee, Customer, and Vendor Data. I am not using any existing library for generating the ID. Just I am using my own logic to generate the ID for employee, Customer, and Vendor.

In my Billing System, there is a class called “CodeGenerator.java” it acts as a Component class, this class used generating unique “Code” for all of my Entity objects. I don’t have to rewrite the new method or class for different entity objects for unique code generation.
This class is having a method called newCode which accepts the code type which is tell that code for which entity object.
public String newCode(CodeType codeType) {
String code = “”;
AppEntityCode appEntityCode = null;
do {
String newCode = getCode(codeType.name());
appEntityCode = appEntityCodeRepository.findByCode(newCode);
if(appEntityCode == null) {
code = newCode;
}
}while(appEntityCode != null);
appEntityCode = new AppEntityCode();
appEntityCode.setCode(code);
appEntityCode.setCodeType(codeType);
appEntityCodeRepository.save(appEntityCode);
return appEntityCode.getCode();
}
The logic of this method is, The getCode() private method generates a code using Random class, and based on the type of code, it concatenates a three-letter digit to the newly generated code. Let say if the code type is employe code, it generates the code like below
“EMP3939”.
Once the code is generated, the “newCode()” method validates the code already exists in the app_entity_code table, if not exist, store the new code in the app_entity_code table with the respective code Type. Then this new code used in the new Employe record which created. So all unique codes are maintained in the app_entity_table. This is a common table unique code for all tables in the Billing System.
This is the generic method we can use any entity object for generating a new unique code. We don’t have to create separate logic for each entity object.
For better understanding, watch this full video
https://youtu.be/0Uoa2Wpnp-0
Download the latest source code from the following Github.
https://github.com/sureshstalin/billingsystem


Please follow our ITGARDEN YouTube channel for Billing System Project development work using Spring Boot. The Project source code absolutely free. This project is very good for who is looking for real-time project experience in Spring Boot. To understand the Billing System Project code, watch all Billing System related YouTube videos from this link. Click Here
Our YouTube Channel
https://www.youtube.com/channel/UChj5CeuWaHIFr4RkXoG3iJA?view_as=subscriber
Please follow me on Medium.com for all billing system related stories and Java-based technical Articles
https://suresh-stalin.medium.com/
Note: To find all billing System related stories find “billing system itgarden” in medium.com

Close Menu
×
×

Cart