获取最大代号(暂时停用)
This commit is contained in:
@@ -19,4 +19,10 @@ public class CodeGeneratorController {
|
||||
public String genCode(@PathVariable String prefix) {
|
||||
return gen.nextCode(prefix);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/max/{prefix}")
|
||||
public Long maxCode(@PathVariable String prefix) {
|
||||
return gen.maxCode(prefix);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,6 @@ package com.ruoyi.oa.service;
|
||||
public interface CodeGeneratorService {
|
||||
|
||||
String nextCode(String prefix) ;
|
||||
|
||||
Long maxCode(String prefix);
|
||||
}
|
||||
|
||||
@@ -23,4 +23,14 @@ public class CodeGeneratorServiceImpl implements CodeGeneratorService {
|
||||
String padded = String.format("%07d", num);
|
||||
return prefix + "-" + padded; // e.g. TH-0000001
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public Long maxCode(String prefix) {
|
||||
mapper.upsertAndIncr(prefix); // 原子插/更
|
||||
long num = mapper.getLastSeq(); // 拿到新的序号
|
||||
return num-1L; //
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user