fix: 代码生成器 自定义模板 复制

This commit is contained in:
cuijiawang 2025-09-27 17:23:19 +08:00
parent 685cc3d92c
commit b51f113053

View File

@ -180,13 +180,13 @@ public class UserTemplateServiceImpl implements IUserTemplateService {
throw new RuntimeException("源模板不存在");
}
// 只能复制公开模板
if (sourceTemplate.getIsPublic() != 1) {
throw new RuntimeException("该模板不是公开模板,无法复制");
}
Long currentUserId = LoginHelper.getUserId();
// 权限检查只能复制自己的模板或公开模板
if (sourceTemplate.getIsPublic() != 1 && !currentUserId.equals(sourceTemplate.getUserId())) {
throw new RuntimeException("无权限复制此模板");
}
// 检查新模板名称是否存在
if (checkTemplateNameExists(currentUserId, newName, null)) {
throw new RuntimeException("模板名称已存在");
@ -199,6 +199,11 @@ public class UserTemplateServiceImpl implements IUserTemplateService {
newTemplate.setTemplateName(newName);
newTemplate.setIsPublic(0); // 复制的模板默认为私有
newTemplate.setUseCount(0);
// 清除时间字段让自动填充功能设置当前时间
newTemplate.setCreateTime(null);
newTemplate.setUpdateTime(null);
newTemplate.setCreateBy(null);
newTemplate.setUpdateBy(null);
return userTemplateMapper.insert(newTemplate) > 0;
}