Auto-increment Number Sequence

Use function to set auto-increment encoding rules
Actual scenario: The logic of the self-incrementing number field is relatively complicated, and rules need to be set in the custom function.
Configuration method: When adding or editing a field of type <self-incrementing number>, set the rule to select <function code>.

Auto-increment number sequence template:

Groovy:

IncrementNumber rule = IncrementNumber. builder()
.counter('testCounter1') // The key of the counter, the incremental self-increment code needs to ensure that the key is unique. Similarly, the self-increment number can be recounted by replacing the counter
.condition('MONTH') // recalculated by year, month, day `YEAR` `MONTH` `DAY` `NONE`
.postfix('-postfix') // encoding postfix
.prefix('prefix-') // encoding prefix
.serialNumber(4) // auto-increment code digits
.initialValue(1) // The initial value of the number cannot be less than 0, and the default is 1
.steppingNumber(2) // The stepper defaults to 1 and cannot be less than 1
.buildRule()
log. info(rule)

Java:

import java.util.List;
import java.util.Map;

public class Increment implements IAutoNumberAction {

/**
 * The operation method of the self-increment number function
 */
@Override
public IncrementNumber execute(FunctionContext context, Map<String, Object> args) {
  IncrementNumber rule = IncrementNumber
    .builder()
    .counter("testCounter1")// The key of the counter, the incremental self-increment code needs to ensure that the key is unique, similarly, changing the counter can recount the self-increment number
    .condition("MONTH") // recalculated by year, month, day `YEAR` `MONTH` `DAY` `NONE`
    .postfix("-postfix") // encoding postfix
    .prefix("prefix-") // encoding prefix
    .serialNumber(4) // auto-increment code digits
    .initialValue(1) // The initial value of the number cannot be less than 0, and the default is 1
    .steppingNumber(2) // The stepper defaults to 1 and cannot be less than 1
    .buildRule();
  return rule;
}
}
2024-07-12
0 0