Serial number management
This article introduces the application of sequence number (Sequence) in crudapi through product code and order serial number.
Overview
serial number
MySQL database does not have a separate Sequence, only supports increment (increment) primary key, but you cannot set the step size, start index, format, etc. The most important thing is that a table can only be incremented by one field, but sometimes we need Multiple fields need to support the serial number function or need to support complex formats. MySQL itself cannot achieve this. Therefore, crudapi encapsulates complex serial numbers, supports strings and numbers, customizes the format, and can also be set as a timestamp. Can be used in scenarios such as product coding, order serial number, etc.!
Configuration serial number
product code
The product code adopts a character string, the format is: PROD_%09d, which means that the length is 9, the width is not enough to be filled with 0, the minimum value starts from 1, the maximum value is 999999999, the next value is 1, and the step size is 1.
Sales order serial number
The product code adopts time stamp, the format is:'SO'yyyyMMddHHmmssSSS, SO means prefix, accurate to year, month, day, hour, minute, second, millisecond
Table definition configuration serial number attributes
product code
Product table configuration serial number field
Sales order serial number
Sales order form configuration serial number field
Verify serial number function
product
Create a product through ui. Because the serial number is set in the code field, leave it blank, so that the code will be automatically generated in the background. If the code field is manually entered, the manually entered value shall prevail.
The generated code is PROD_000000001, which is consistent with expectations.
Sales order
Create sales order through Postman
ui view the order list, the serial number found that SO20210212110955912 was successfully generated
advanced
Serial Number API
The serial number provides an API for obtaining the next value function, which is suitable for UI customization scenarios. It is more intuitive to display the value on the ui explicitly, but if the user does not click the save or the save fails, the value may be wasted. View the swagger documentation:
https://demo.crudapi.cn/swagger-ui.html
verification
Get the next value PROD_000000002 through Postman
summary
This article realizes the automatic assignment function of specific fields by configuring the serial number, without coding, and supports secondary development. At present, there is a bit of imperfection. Products and sales orders are isolated single tables. Follow-up will introduce how to configure table relationships to achieve one-to-many, one-to-one, and many-to-many master and sub-tables.
Attached demo
This system belongs to a product-level zero-code platform. It is different from an automatic code generator. It does not need to generate Controller, Service, Repository, Entity and other business codes. The program can be used after running. The real zero code can cover basic and business-independent CRUD RESTful API.
Official website address:https://crudapi.cn
test address:https://demo.crudapi.cn/crudapi/login