parent
ec2d69a09f
commit
7e327e2131
|
|
@ -1,5 +1,6 @@
|
|||
package org.dromara.pangu.application.service.impl;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
|
@ -44,9 +45,39 @@ public class PgApplicationServiceImpl implements IPgApplicationService {
|
|||
|
||||
@Override
|
||||
public int insert(PgApplication app) {
|
||||
// 自动生成应用编码:YY + 6位序号
|
||||
String appCode = generateAppCode();
|
||||
app.setAppCode(appCode);
|
||||
// 自动生成32位应用密钥
|
||||
app.setAppSecret(IdUtil.fastSimpleUUID());
|
||||
return baseMapper.insert(app);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成应用编码
|
||||
*/
|
||||
private String generateAppCode() {
|
||||
// 查询当前最大编码
|
||||
LambdaQueryWrapper<PgApplication> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.select(PgApplication::getAppCode);
|
||||
lqw.likeRight(PgApplication::getAppCode, "YY");
|
||||
lqw.orderByDesc(PgApplication::getAppCode);
|
||||
lqw.last("LIMIT 1");
|
||||
PgApplication lastApp = baseMapper.selectOne(lqw);
|
||||
|
||||
int nextNum = 1;
|
||||
if (lastApp != null && StrUtil.isNotBlank(lastApp.getAppCode())) {
|
||||
String lastCode = lastApp.getAppCode();
|
||||
if (lastCode.length() > 2) {
|
||||
try {
|
||||
nextNum = Integer.parseInt(lastCode.substring(2)) + 1;
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return String.format("YY%06d", nextNum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(PgApplication app) {
|
||||
return baseMapper.updateById(app);
|
||||
|
|
|
|||
Loading…
Reference in New Issue