mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 15:55:18 +08:00
代码生成优化
This commit is contained in:
@@ -14,9 +14,11 @@ import cn.lihongjie.coal.base.mapper.CommonEntityMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonMapper;
|
||||
import cn.lihongjie.coal.base.service.BaseService;
|
||||
import cn.lihongjie.coal.common.ArchiveUtils;
|
||||
import cn.lihongjie.coal.common.DictCode;
|
||||
import cn.lihongjie.coal.common.TreeUtils;
|
||||
import cn.lihongjie.coal.dbFunctions.DbFunctionService;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
import cn.lihongjie.coal.pojoProcessor.DictTranslate;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
import com.google.googlejavaformat.java.Formatter;
|
||||
@@ -145,26 +147,7 @@ public class Codegen {
|
||||
.build())
|
||||
.initializer("$S", "0")
|
||||
.build())
|
||||
.addField(
|
||||
FieldSpec.builder(
|
||||
String.class,
|
||||
"archiveStatusName",
|
||||
Modifier.PRIVATE)
|
||||
.addAnnotation(
|
||||
AnnotationSpec.builder(
|
||||
org.hibernate.annotations
|
||||
.Formula.class)
|
||||
.addMember(
|
||||
"value",
|
||||
"$S",
|
||||
"(select i.name\n"
|
||||
+ "from t_dictionary d,\n"
|
||||
+ " t_dictionary_item i\n"
|
||||
+ "where d.id = i.dictionary_id\n"
|
||||
+ " and d.code = 'archiveStatus'\n"
|
||||
+ " and i.code = archive_status)")
|
||||
.build())
|
||||
.build())
|
||||
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -224,6 +207,11 @@ public class Codegen {
|
||||
String.class,
|
||||
"archiveStatusName",
|
||||
Modifier.PRIVATE)
|
||||
.addAnnotation(
|
||||
AnnotationSpec.builder(
|
||||
DictTranslate.class)
|
||||
.addMember("dictKey", "$T.$N", ClassName.get(DictCode.class), "ARCHIVESTATUS" )
|
||||
.build())
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
@@ -313,6 +301,27 @@ public class Codegen {
|
||||
ParameterizedTypeName.get(
|
||||
ClassName.get(BaseRepository.class),
|
||||
ClassName.get(entityPackage, entity.name)))
|
||||
.addMethod(
|
||||
MethodSpec.methodBuilder("isLinked")
|
||||
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
|
||||
.returns(boolean.class)
|
||||
.addAnnotation(
|
||||
AnnotationSpec.builder(
|
||||
org.springframework.data.jpa.repository
|
||||
.Query.class)
|
||||
.addMember(
|
||||
"value",
|
||||
"$S",
|
||||
"select false")
|
||||
.build())
|
||||
.addParameter(
|
||||
ParameterSpec.builder(
|
||||
ParameterizedTypeName.get(
|
||||
ClassName.get(List.class),
|
||||
ClassName.get(String.class)),
|
||||
"ids")
|
||||
.build())
|
||||
.build())
|
||||
.build();
|
||||
|
||||
saveFile(repoPackage, repository);
|
||||
@@ -439,6 +448,12 @@ public class Codegen {
|
||||
.addParameter(ClassName.get(IdRequest.class), "request")
|
||||
.addStatement(
|
||||
"""
|
||||
boolean linked = this.repository.isLinked(request.getIds());
|
||||
|
||||
if (linked) {
|
||||
throw new BizException("数据已被关联,无法删除");
|
||||
}
|
||||
|
||||
this.repository.deleteAllById(request.getIds())
|
||||
""")
|
||||
.build();
|
||||
@@ -459,6 +474,11 @@ public class Codegen {
|
||||
(e, actual, expected) -> {
|
||||
throw new $T("数据 " + "已归档,无法删除");
|
||||
});
|
||||
boolean linked = this.repository.isLinked(request.getIds());
|
||||
|
||||
if (linked) {
|
||||
throw new BizException("数据已被关联,无法删除");
|
||||
}
|
||||
this.repository.deleteAllById(request.getIds())
|
||||
""",
|
||||
ClassName.get(ArchiveUtils.class),
|
||||
|
||||
Reference in New Issue
Block a user