diff --git a/maku-boot-module/maku-module-generator/pom.xml b/maku-boot-module/maku-module-generator/pom.xml
index 7bea687..12ca026 100644
--- a/maku-boot-module/maku-module-generator/pom.xml
+++ b/maku-boot-module/maku-module-generator/pom.xml
@@ -12,8 +12,8 @@
net.maku
- maku-generator-boot-starter
- 3.1.0
+ maku-generator-pro-boot-starter
+ 1.0.1
diff --git a/maku-boot-module/maku-module-generator/src/main/resources/template/config.json b/maku-boot-module/maku-module-generator/src/main/resources/template/config.json
index dc5e03d..accf551 100644
--- a/maku-boot-module/maku-module-generator/src/main/resources/template/config.json
+++ b/maku-boot-module/maku-module-generator/src/main/resources/template/config.json
@@ -3,9 +3,9 @@
"packageName": "net.maku",
"version": "1.0.0",
"backendPath": "D:\\generator\\maku-boot\\maku-server",
- "frontendPath": "D:\\generator\\maku-admin"
- },
- "developer": {
+ "frontendPath": "D:\\generator\\maku-admin",
+ "tablePrefix": "tb_",
+ "moduleName": "business",
"author": "阿沐",
"email": "babamu@126.com"
},
@@ -35,6 +35,10 @@
"generatorPath": "${backendPath}/src/main/java/${packagePath}/${moduleName}/vo/${ClassName}VO.java"
},
{
+ "templateName": "java/Excel.java.ftl",
+ "generatorPath": "${backendPath}/src/main/java/${packagePath}/${moduleName}/vo/${ClassName}ExcelVO.java"
+ },
+ {
"templateName": "java/Convert.java.ftl",
"generatorPath": "${backendPath}/src/main/java/${packagePath}/${moduleName}/convert/${ClassName}Convert.java"
},
@@ -62,5 +66,27 @@
"templateName": "vue/add-or-update.vue.ftl",
"generatorPath": "${frontendPath}/src/views/${moduleName}/${functionName}/add-or-update.vue"
}
+ ],
+ "subTemplates": [
+ {
+ "templateName": "java/Entity.java.ftl",
+ "generatorPath": "${backendPath}/src/main/java/${packagePath}/${moduleName}/entity/${ClassName}Entity.java"
+ },
+ {
+ "templateName": "java/Dao.java.ftl",
+ "generatorPath": "${backendPath}/src/main/java/${packagePath}/${moduleName}/dao/${ClassName}Dao.java"
+ },
+ {
+ "templateName": "java/VO.java.ftl",
+ "generatorPath": "${backendPath}/src/main/java/${packagePath}/${moduleName}/vo/${ClassName}VO.java"
+ },
+ {
+ "templateName": "java/Convert.java.ftl",
+ "generatorPath": "${backendPath}/src/main/java/${packagePath}/${moduleName}/convert/${ClassName}Convert.java"
+ },
+ {
+ "templateName": "vue/sub-add-or-update.vue.ftl",
+ "generatorPath": "${frontendPath}/src/views/${moduleName}/${functionName}/${className}.vue"
+ }
]
}
\ No newline at end of file
diff --git a/maku-boot-module/maku-module-generator/src/main/resources/template/java/Controller.java.ftl b/maku-boot-module/maku-module-generator/src/main/resources/template/java/Controller.java.ftl
index 7c6f2c0..079ba8c 100644
--- a/maku-boot-module/maku-module-generator/src/main/resources/template/java/Controller.java.ftl
+++ b/maku-boot-module/maku-module-generator/src/main/resources/template/java/Controller.java.ftl
@@ -5,26 +5,28 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import ${package}.framework.common.utils.PageResult;
import ${package}.framework.common.utils.Result;
-import ${package}.${moduleName}.convert.${ClassName}Convert;
-import ${package}.${moduleName}.entity.${ClassName}Entity;
+import ${package}.framework.operatelog.annotations.OperateLog;
+import ${package}.framework.operatelog.enums.OperateTypeEnum;
import ${package}.${moduleName}.service.${ClassName}Service;
import ${package}.${moduleName}.query.${ClassName}Query;
import ${package}.${moduleName}.vo.${ClassName}VO;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
-
+<#if tableOperation?seq_contains('import')>
+import org.springframework.web.multipart.MultipartFile;
+#if>
import jakarta.validation.Valid;
import java.util.List;
/**
-* ${tableComment}
-*
-* @author ${author} ${email}
-* @since ${version} ${date}
-*/
+ * ${tableComment!}
+ *
+ * @author ${author} ${email!}
+ * MAKU
+ */
@RestController
-@RequestMapping("${moduleName}/${functionName}")
+@RequestMapping("${requestUrl}")
@Tag(name="${tableComment}")
@AllArgsConstructor
public class ${ClassName}Controller {
@@ -32,46 +34,91 @@ public class ${ClassName}Controller {
@GetMapping("page")
@Operation(summary = "分页")
- @PreAuthorize("hasAuthority('${moduleName}:${functionName}:page')")
+ @PreAuthorize("hasAuthority('${authority}<#if authLevel==1>:page#if>')")
public Result> page(@ParameterObject @Valid ${ClassName}Query query){
PageResult<${ClassName}VO> page = ${className}Service.page(query);
return Result.ok(page);
}
+ <#if hasTree>
+ @GetMapping("list")
+ @Operation(summary = "列表")
+ @PreAuthorize("hasAuthority('${authority}<#if authLevel==1>:page#if>')")
+ public Result> list(Long ${treePid}) {
+ List<${ClassName}VO> list = ${className}Service.list(${treePid});
+
+ return Result.ok(list);
+ }
+ #if>
+
@GetMapping("{id}")
@Operation(summary = "信息")
- @PreAuthorize("hasAuthority('${moduleName}:${functionName}:info')")
+ @PreAuthorize("hasAuthority('${authority}<#if authLevel==1>:info#if>')")
public Result<${ClassName}VO> get(@PathVariable("id") Long id){
- ${ClassName}Entity entity = ${className}Service.getById(id);
+ ${ClassName}VO data = ${className}Service.get(id);
- return Result.ok(${ClassName}Convert.INSTANCE.convert(entity));
+ return Result.ok(data);
}
+ <#if tableOperation?seq_contains('insert')>
@PostMapping
@Operation(summary = "保存")
- @PreAuthorize("hasAuthority('${moduleName}:${functionName}:save')")
+ @OperateLog(type = OperateTypeEnum.INSERT)
+ @PreAuthorize("hasAuthority('${authority}<#if authLevel==1>:save#if>')")
public Result save(@RequestBody ${ClassName}VO vo){
${className}Service.save(vo);
return Result.ok();
}
+ #if>
+ <#if tableOperation?seq_contains('update')>
@PutMapping
@Operation(summary = "修改")
- @PreAuthorize("hasAuthority('${moduleName}:${functionName}:update')")
+ @OperateLog(type = OperateTypeEnum.UPDATE)
+ @PreAuthorize("hasAuthority('${authority}<#if authLevel==1>:update#if>')")
public Result update(@RequestBody @Valid ${ClassName}VO vo){
${className}Service.update(vo);
return Result.ok();
}
+ #if>
+ <#if tableOperation?seq_contains('delete')>
@DeleteMapping
@Operation(summary = "删除")
- @PreAuthorize("hasAuthority('${moduleName}:${functionName}:delete')")
+ @OperateLog(type = OperateTypeEnum.DELETE)
+ @PreAuthorize("hasAuthority('${authority}<#if authLevel==1>:delete#if>')")
public Result delete(@RequestBody List idList){
${className}Service.delete(idList);
return Result.ok();
}
+ #if>
+
+ <#if tableOperation?seq_contains('import')>
+ @PostMapping("import")
+ @Operation(summary = "导入")
+ @OperateLog(type = OperateTypeEnum.IMPORT)
+ @PreAuthorize("hasAuthority('${authority}<#if authLevel==1>:import#if>')")
+ public Result importExcel(@RequestParam("file") MultipartFile file) {
+ if (file.isEmpty()) {
+ return Result.error("请选择需要上传的文件");
+ }
+ ${className}Service.importByExcel(file);
+
+ return Result.ok();
+ }
+ #if>
+
+ <#if tableOperation?seq_contains('export')>
+ @GetMapping("export")
+ @Operation(summary = "导出")
+ @OperateLog(type = OperateTypeEnum.EXPORT)
+ @PreAuthorize("hasAuthority('${authority}<#if authLevel==1>:export#if>')")
+ public void export() {
+ ${className}Service.export();
+ }
+ #if>
}
\ No newline at end of file
diff --git a/maku-boot-module/maku-module-generator/src/main/resources/template/java/Convert.java.ftl b/maku-boot-module/maku-module-generator/src/main/resources/template/java/Convert.java.ftl
index 2953197..69b4448 100644
--- a/maku-boot-module/maku-module-generator/src/main/resources/template/java/Convert.java.ftl
+++ b/maku-boot-module/maku-module-generator/src/main/resources/template/java/Convert.java.ftl
@@ -2,17 +2,20 @@ package ${package}.${moduleName}.convert;
import ${package}.${moduleName}.entity.${ClassName}Entity;
import ${package}.${moduleName}.vo.${ClassName}VO;
+<#if tableOperation?seq_contains('import') || tableOperation?seq_contains('export')>
+import ${package}.${moduleName}.vo.${ClassName}ExcelVO;
+#if>
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
-* ${tableComment}
-*
-* @author ${author} ${email}
-* @since ${version} ${date}
-*/
+ * ${tableComment}
+ *
+ * @author ${author} ${email!}
+ * MAKU
+ */
@Mapper
public interface ${ClassName}Convert {
${ClassName}Convert INSTANCE = Mappers.getMapper(${ClassName}Convert.class);
@@ -23,4 +26,11 @@ public interface ${ClassName}Convert {
List<${ClassName}VO> convertList(List<${ClassName}Entity> list);
+ List<${ClassName}Entity> convertList2(List<${ClassName}VO> list);
+
+ <#if tableOperation?seq_contains('import') || tableOperation?seq_contains('export')>
+ List<${ClassName}ExcelVO> convertExcelList(List<${ClassName}Entity> list);
+
+ List<${ClassName}Entity> convertExcelList2(List<${ClassName}ExcelVO> list);
+ #if>
}
\ No newline at end of file
diff --git a/maku-boot-module/maku-module-generator/src/main/resources/template/java/Dao.java.ftl b/maku-boot-module/maku-module-generator/src/main/resources/template/java/Dao.java.ftl
index ebf94e9..b615951 100644
--- a/maku-boot-module/maku-module-generator/src/main/resources/template/java/Dao.java.ftl
+++ b/maku-boot-module/maku-module-generator/src/main/resources/template/java/Dao.java.ftl
@@ -5,12 +5,12 @@ import ${package}.${moduleName}.entity.${ClassName}Entity;
import org.apache.ibatis.annotations.Mapper;
/**
-* ${tableComment}
-*
-* @author ${author} ${email}
-* @since ${version} ${date}
-*/
+ * ${tableComment}
+ *
+ * @author ${author} ${email!}
+ * MAKU
+ */
@Mapper
public interface ${ClassName}Dao extends BaseDao<${ClassName}Entity> {
-
+
}
\ No newline at end of file
diff --git a/maku-boot-module/maku-module-generator/src/main/resources/template/java/Entity.java.ftl b/maku-boot-module/maku-module-generator/src/main/resources/template/java/Entity.java.ftl
index 2a47341..382f274 100644
--- a/maku-boot-module/maku-module-generator/src/main/resources/template/java/Entity.java.ftl
+++ b/maku-boot-module/maku-module-generator/src/main/resources/template/java/Entity.java.ftl
@@ -13,8 +13,8 @@ import ${baseClass.packageName}.${baseClass.code};
/**
* ${tableComment}
*
- * @author ${author} ${email}
- * @since ${version} ${date}
+ * @author ${author} ${email!}
+ * MAKU
*/
<#if baseClass??>@EqualsAndHashCode(callSuper=false)#if>
@Data
@@ -27,18 +27,20 @@ public class ${ClassName}Entity<#if baseClass??> extends ${baseClass.code}#if>
* ${field.fieldComment}
*/
#if>
- <#if field.autoFill == "INSERT">
- @TableField(fill = FieldFill.INSERT)
- #if>
- <#if field.autoFill == "INSERT_UPDATE">
- @TableField(fill = FieldFill.INSERT_UPDATE)
- #if>
- <#if field.autoFill == "UPDATE">
- @TableField(fill = FieldFill.UPDATE)
- #if>
- <#if field.primaryPk>
+ <#if field.primaryPk>
@TableId
#if>
+ <#if field.autoFill == "INSERT">
+ @TableField(value = "${field.fieldName}", fill = FieldFill.INSERT)
+ <#elseif field.autoFill == "INSERT_UPDATE">
+ @TableField(value = "${field.fieldName}", fill = FieldFill.INSERT_UPDATE)
+ <#elseif field.autoFill == "UPDATE">
+ @TableField(value = "${field.fieldName}", fill = FieldFill.UPDATE)
+ <#elseif hasTree && field.fieldName == treePid>
+ @TableField(value = "${field.fieldName}", updateStrategy = FieldStrategy.ALWAYS)
+ <#else>
+ @TableField(value = "${field.fieldName}")
+ #if>
private ${field.attrType} ${field.attrName};
#if>
diff --git a/maku-boot-module/maku-module-generator/src/main/resources/template/java/Excel.java.ftl b/maku-boot-module/maku-module-generator/src/main/resources/template/java/Excel.java.ftl
new file mode 100644
index 0000000..1df7939
--- /dev/null
+++ b/maku-boot-module/maku-module-generator/src/main/resources/template/java/Excel.java.ftl
@@ -0,0 +1,40 @@
+package ${package}.${moduleName}.vo;
+
+import lombok.Data;
+import com.alibaba.excel.annotation.ExcelIgnore;
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.fhs.core.trans.vo.TransPojo;
+<#list importList as i>
+import ${i!};
+#list>
+
+/**
+ * ${tableComment}
+ *
+ * @author ${author} ${email!}
+ * MAKU
+ */
+@Data
+public class ${ClassName}ExcelVO implements TransPojo {
+ @ExcelIgnore
+ private ${primaryType} ${primaryName};
+
+<#list gridList as field>
+ <#if field.fieldComment!?length gt 0>
+ @ExcelProperty("${field.fieldComment}")
+ #if>
+ <#if field.attrType == 'LocalDateTime'>
+ @ExcelProperty(value = "${field.fieldComment}", converter = LocalDateTimeConverter.class)
+ #if>
+ <#if field.formDict??>
+ private String ${field.attrName}Label;
+
+ @ExcelIgnore
+ @Trans(type = TransType.DICTIONARY, key = "${field.formDict}", ref = "${field.attrName}Label")
+ private ${field.attrType} ${field.attrName};
+ <#else>
+ private ${field.attrType} ${field.attrName};
+ #if>
+
+#list>
+}
\ No newline at end of file
diff --git a/maku-boot-module/maku-module-generator/src/main/resources/template/java/Query.java.ftl b/maku-boot-module/maku-module-generator/src/main/resources/template/java/Query.java.ftl
index bdb205b..350c690 100644
--- a/maku-boot-module/maku-module-generator/src/main/resources/template/java/Query.java.ftl
+++ b/maku-boot-module/maku-module-generator/src/main/resources/template/java/Query.java.ftl
@@ -11,11 +11,11 @@ import ${i!};
#list>
/**
-* ${tableComment}查询
-*
-* @author ${author} ${email}
-* @since ${version} ${date}
-*/
+ * ${tableComment}查询
+ *
+ * @author ${author} ${email!}
+ * MAKU
+ */
@Data
@EqualsAndHashCode(callSuper = false)
@Schema(description = "${tableComment}查询")
@@ -24,10 +24,12 @@ public class ${ClassName}Query extends Query {
<#if field.fieldComment!?length gt 0>
@Schema(description = "${field.fieldComment}")
#if>
- <#if field.attrType == 'Date'>
- @DateTimeFormat(pattern = DateUtils.DATE_TIME_PATTERN)
+ <#if field.queryFormType == 'date'>
+ @DateTimeFormat(pattern="yyyy-MM-dd")
+ <#elseif field.queryFormType == 'datetime'>
+ @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
#if>
- private ${field.attrType} ${field.attrName};
+ private ${field.attrType}<#if field.queryFormType == 'date' || field.queryFormType == 'datetime'>[]#if> ${field.attrName};
#list>
}
\ No newline at end of file
diff --git a/maku-boot-module/maku-module-generator/src/main/resources/template/java/Service.java.ftl b/maku-boot-module/maku-module-generator/src/main/resources/template/java/Service.java.ftl
index 736759d..5770367 100644
--- a/maku-boot-module/maku-module-generator/src/main/resources/template/java/Service.java.ftl
+++ b/maku-boot-module/maku-module-generator/src/main/resources/template/java/Service.java.ftl
@@ -5,22 +5,44 @@ import ${package}.framework.mybatis.service.BaseService;
import ${package}.${moduleName}.vo.${ClassName}VO;
import ${package}.${moduleName}.query.${ClassName}Query;
import ${package}.${moduleName}.entity.${ClassName}Entity;
-
+<#if tableOperation?seq_contains('import')>
+import org.springframework.web.multipart.MultipartFile;
+#if>
import java.util.List;
/**
* ${tableComment}
*
- * @author ${author} ${email}
- * @since ${version} ${date}
+ * @author ${author} ${email!}
+ * MAKU
*/
public interface ${ClassName}Service extends BaseService<${ClassName}Entity> {
PageResult<${ClassName}VO> page(${ClassName}Query query);
+ ${ClassName}VO get(Long id);
+
+ <#if hasTree>
+ List<${ClassName}VO> list(Long ${treePid});
+ #if>
+
+ <#if tableOperation?seq_contains('insert')>
void save(${ClassName}VO vo);
+ #if>
+ <#if tableOperation?seq_contains('update')>
void update(${ClassName}VO vo);
+ #if>
+ <#if tableOperation?seq_contains('delete')>
void delete(List idList);
+ #if>
+
+ <#if tableOperation?seq_contains('import')>
+ void importByExcel(MultipartFile file);
+ #if>
+
+ <#if tableOperation?seq_contains('export')>
+ void export();
+ #if>
}
\ No newline at end of file
diff --git a/maku-boot-module/maku-module-generator/src/main/resources/template/java/ServiceImpl.java.ftl b/maku-boot-module/maku-module-generator/src/main/resources/template/java/ServiceImpl.java.ftl
index 4f61914..4930faa 100644
--- a/maku-boot-module/maku-module-generator/src/main/resources/template/java/ServiceImpl.java.ftl
+++ b/maku-boot-module/maku-module-generator/src/main/resources/template/java/ServiceImpl.java.ftl
@@ -12,6 +12,19 @@ import ${package}.${moduleName}.query.${ClassName}Query;
import ${package}.${moduleName}.vo.${ClassName}VO;
import ${package}.${moduleName}.dao.${ClassName}Dao;
import ${package}.${moduleName}.service.${ClassName}Service;
+<#list subs as sub>
+import ${package}.${moduleName}.convert.${sub.ClassName}Convert;
+import ${package}.${moduleName}.entity.${sub.ClassName}Entity;
+import ${package}.${moduleName}.dao.${sub.ClassName}Dao;
+#list>
+<#if tableOperation?seq_contains('import') || tableOperation?seq_contains('export')>
+import com.fhs.trans.service.impl.TransService;
+import ${package}.framework.common.utils.ExcelUtils;
+import ${package}.${moduleName}.vo.${ClassName}ExcelVO;
+import ${package}.framework.common.excel.ExcelFinishCallBack;
+import org.springframework.web.multipart.MultipartFile;
+#if>
+import cn.hutool.core.util.ObjectUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -20,44 +33,206 @@ import java.util.List;
/**
* ${tableComment}
*
- * @author ${author} ${email}
- * @since ${version} ${date}
+ * @author ${author} ${email!}
+ * MAKU
*/
@Service
@AllArgsConstructor
public class ${ClassName}ServiceImpl extends BaseServiceImpl<${ClassName}Dao, ${ClassName}Entity> implements ${ClassName}Service {
+<#if tableOperation?seq_contains('import') || tableOperation?seq_contains('export')>
+ private final TransService transService;
+#if>
+<#list subs as sub>
+ private final ${sub.ClassName}Dao ${sub.className}Dao;
+#list>
@Override
public PageResult<${ClassName}VO> page(${ClassName}Query query) {
IPage<${ClassName}Entity> page = baseMapper.selectPage(getPage(query), getWrapper(query));
+ <#if hasTree>
+ return new PageResult<>(getHasChild(page.getRecords()), page.getTotal());
+ <#else>
return new PageResult<>(${ClassName}Convert.INSTANCE.convertList(page.getRecords()), page.getTotal());
+ #if>
}
+ <#if hasTree>
+ @Override
+ public List<${ClassName}VO> list(Long ${treePid}) {
+ LambdaQueryWrapper<${ClassName}Entity> wrapper = Wrappers.lambdaQuery();
+ wrapper.eq(${treePid} != null, ${ClassName}Entity::get${treePid?cap_first}, ${treePid});
+
+ List<${ClassName}Entity> list = baseMapper.selectList(wrapper);
+
+ <#if hasTree>
+ return getHasChild(list);
+ <#else>
+ return ${ClassName}Convert.INSTANCE.convertList(list);
+ #if>
+ }
+ #if>
+
private LambdaQueryWrapper<${ClassName}Entity> getWrapper(${ClassName}Query query){
LambdaQueryWrapper<${ClassName}Entity> wrapper = Wrappers.lambdaQuery();
+ <#if hasTree>
+ wrapper.isNull(${ClassName}Entity::get${treePid?cap_first});
+ #if>
+ <#list queryList as field>
+ <#if field.queryFormType == 'date' || field.queryFormType == 'datetime'>
+ wrapper.between(ObjectUtil.isNotEmpty(query.get${field.attrName?cap_first}()), ${ClassName}Entity::get${field.attrName?cap_first}, ArrayUtils.isNotEmpty(query.get${field.attrName?cap_first}()) ? query.get${field.attrName?cap_first}()[0] : null, ArrayUtils.isNotEmpty(query.get${field.attrName?cap_first}()) ? query.get${field.attrName?cap_first}()[1] : null);
+ <#elseif field.queryType == '='>
+ wrapper.eq(ObjectUtil.isNotEmpty(query.get${field.attrName?cap_first}()), ${ClassName}Entity::get${field.attrName?cap_first}, query.get${field.attrName?cap_first}());
+ <#elseif field.queryType == '!='>
+ wrapper.ne(ObjectUtil.isNotEmpty(query.get${field.attrName?cap_first}()), ${ClassName}Entity::get${field.attrName?cap_first}, query.get${field.attrName?cap_first}());
+ <#elseif field.queryType == '>'>
+ wrapper.gt(ObjectUtil.isNotEmpty(query.get${field.attrName?cap_first}()), ${ClassName}Entity::get${field.attrName?cap_first}, query.get${field.attrName?cap_first}());
+ <#elseif field.queryType == '>='>
+ wrapper.ge(ObjectUtil.isNotEmpty(query.get${field.attrName?cap_first}()), ${ClassName}Entity::get${field.attrName?cap_first}, query.get${field.attrName?cap_first}());
+ <#elseif field.queryType == '<'>
+ wrapper.lt(ObjectUtil.isNotEmpty(query.get${field.attrName?cap_first}()), ${ClassName}Entity::get${field.attrName?cap_first}, query.get${field.attrName?cap_first}());
+ <#elseif field.queryType == '<='>
+ wrapper.le(ObjectUtil.isNotEmpty(query.get${field.attrName?cap_first}()), ${ClassName}Entity::get${field.attrName?cap_first}, query.get${field.attrName?cap_first}());
+ <#elseif field.queryType == 'like'>
+ wrapper.like(ObjectUtil.isNotEmpty(query.get${field.attrName?cap_first}()), ${ClassName}Entity::get${field.attrName?cap_first}, query.get${field.attrName?cap_first}());
+ <#elseif field.queryType == 'left like'>
+ wrapper.likeLeft(ObjectUtil.isNotEmpty(query.get${field.attrName?cap_first}()), ${ClassName}Entity::get${field.attrName?cap_first}, query.get${field.attrName?cap_first}());
+ <#elseif field.queryType == 'right like'>
+ wrapper.likeRight(ObjectUtil.isNotEmpty(query.get${field.attrName?cap_first}()), ${ClassName}Entity::get${field.attrName?cap_first}, query.get${field.attrName?cap_first}());
+ #if>
+ #list>
return wrapper;
}
+ <#if hasTree>
+ private List<${ClassName}VO> getHasChild(List<${ClassName}Entity> entityList) {
+ List<${ClassName}VO> list = ${ClassName}Convert.INSTANCE.convertList(entityList);
+ list.forEach(vo -> {
+ Long count = baseMapper.selectCount(new LambdaQueryWrapper<${ClassName}Entity>().eq(${ClassName}Entity::get${treePid?cap_first}, vo.get${treeId?cap_first}()));
+ vo.setHasChild(count > 0);
+ });
+
+ return list;
+ }
+ #if>
+
@Override
+ public ${ClassName}VO get(Long id) {
+ ${ClassName}Entity entity = baseMapper.selectById(id);
+ ${ClassName}VO vo = ${ClassName}Convert.INSTANCE.convert(entity);
+
+ <#list subs as sub>
+ <#if sub.mainRelation ==1>
+ ${sub.ClassName}Entity ${sub.className}Entity = ${sub.className}Dao.selectOne(Wrappers.lambdaQuery(${sub.ClassName}Entity.class).eq(${sub.ClassName}Entity::get${sub.ForeignKey}, id));
+ vo.set${sub.ClassName}(${sub.ClassName}Convert.INSTANCE.convert(${sub.className}Entity));
+ #if>
+ <#if sub.mainRelation ==2>
+ List<${sub.ClassName}Entity> ${sub.className}List = ${sub.className}Dao.selectList(Wrappers.lambdaQuery(${sub.ClassName}Entity.class).eq(${sub.ClassName}Entity::get${sub.ForeignKey}, id));
+ vo.set${sub.ClassName}(${sub.ClassName}Convert.INSTANCE.convertList(${sub.className}List));
+ #if>
+
+ #list>
+ return vo;
+ }
+
+ <#if tableOperation?seq_contains('insert')>
+ @Override
+ @Transactional(rollbackFor = Exception.class)
public void save(${ClassName}VO vo) {
${ClassName}Entity entity = ${ClassName}Convert.INSTANCE.convert(vo);
baseMapper.insert(entity);
- }
+ <#list subs as sub>
+ ${sub.className}Dao.delete(Wrappers.lambdaQuery(${sub.ClassName}Entity.class).eq(${sub.ClassName}Entity::get${sub.ForeignKey}, entity.getId()));
+ #list>
+
+ <#list subs as sub>
+ <#if sub.mainRelation ==1>
+ ${sub.ClassName}Entity ${sub.className}Entity = ${sub.ClassName}Convert.INSTANCE.convert(vo.get${sub.ClassName}());
+ ${sub.className}Entity.set${sub.ForeignKey}(entity.getId());
+ ${sub.className}Dao.insert(${sub.className}Entity);
+ #if>
+ <#if sub.mainRelation ==2>
+ List<${sub.ClassName}Entity> ${sub.className}List = ${sub.ClassName}Convert.INSTANCE.convertList2(vo.get${sub.ClassName}());
+ ${sub.className}List.forEach(${sub.className}Entity -> {
+ ${sub.className}Entity.set${sub.ForeignKey}(entity.getId());
+ ${sub.className}Dao.insert(${sub.className}Entity);
+ });
+ #if>
+
+ #list>
+ }
+ #if>
+
+ <#if tableOperation?seq_contains('update')>
@Override
+ @Transactional(rollbackFor = Exception.class)
public void update(${ClassName}VO vo) {
${ClassName}Entity entity = ${ClassName}Convert.INSTANCE.convert(vo);
updateById(entity);
- }
+ <#list subs as sub>
+ ${sub.className}Dao.delete(Wrappers.lambdaQuery(${sub.ClassName}Entity.class).eq(${sub.ClassName}Entity::get${sub.ForeignKey}, entity.getId()));
+ #list>
+
+ <#list subs as sub>
+ <#if sub.mainRelation ==1>
+ ${sub.ClassName}Entity ${sub.className}Entity = ${sub.ClassName}Convert.INSTANCE.convert(vo.get${sub.ClassName}());
+ ${sub.className}Entity.set${sub.ForeignKey}(entity.getId());
+ ${sub.className}Dao.insert(${sub.className}Entity);
+ #if>
+ <#if sub.mainRelation ==2>
+ List<${sub.ClassName}Entity> ${sub.className}List = ${sub.ClassName}Convert.INSTANCE.convertList2(vo.get${sub.ClassName}());
+ ${sub.className}List.forEach(${sub.className}Entity -> {
+ ${sub.className}Entity.set${sub.ForeignKey}(entity.getId());
+ ${sub.className}Dao.insert(${sub.className}Entity);
+ });
+ #if>
+
+ #list>
+ }
+ #if>
+
+ <#if tableOperation?seq_contains('delete')>
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(List idList) {
removeByIds(idList);
+
+ <#if subs?size gt 0>
+ // 删除子表数据
+ idList.forEach(id -> {
+ <#list subs as sub>
+ ${sub.className}Dao.delete(Wrappers.lambdaQuery(${sub.ClassName}Entity.class).eq(${sub.ClassName}Entity::get${sub.ForeignKey}, id));
+ #list>
+ });
+ #if>
}
+ #if>
+
+ <#if tableOperation?seq_contains('import')>
+ @Override
+ public void importByExcel(MultipartFile file) {
+ ExcelUtils.readAnalysis(file, ${ClassName}ExcelVO.class, new ExcelFinishCallBack<>() {
+ @Override
+ public void doSaveBatch(List<${ClassName}ExcelVO> resultList) {
+ ExcelUtils.parseDict(resultList);
+ saveBatch(${ClassName}Convert.INSTANCE.convertExcelList2(resultList));
+ }
+ });
+ }
+ #if>
+
+ <#if tableOperation?seq_contains('export')>
+ @Override
+ public void export() {
+ List<${ClassName}ExcelVO> excelList = ${ClassName}Convert.INSTANCE.convertExcelList(list());
+ transService.transBatch(excelList);
+ ExcelUtils.excelExport(${ClassName}ExcelVO.class, "${tableComment}", null, excelList);
+ }
+ #if>
}
\ No newline at end of file
diff --git a/maku-boot-module/maku-module-generator/src/main/resources/template/java/VO.java.ftl b/maku-boot-module/maku-module-generator/src/main/resources/template/java/VO.java.ftl
index 1e89511..37f79ce 100644
--- a/maku-boot-module/maku-module-generator/src/main/resources/template/java/VO.java.ftl
+++ b/maku-boot-module/maku-module-generator/src/main/resources/template/java/VO.java.ftl
@@ -2,6 +2,7 @@ package ${package}.${moduleName}.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import com.fasterxml.jackson.annotation.JsonFormat;
+import java.util.List;
import lombok.Data;
import java.io.Serializable;
import ${package}.framework.common.utils.DateUtils;
@@ -10,11 +11,11 @@ import ${i!};
#list>
/**
-* ${tableComment}
-*
-* @author ${author} ${email}
-* @since ${version} ${date}
-*/
+ * ${tableComment}
+ *
+ * @author ${author} ${email!}
+ * MAKU
+ */
@Data
@Schema(description = "${tableComment}")
public class ${ClassName}VO implements Serializable {
@@ -24,11 +25,23 @@ public class ${ClassName}VO implements Serializable {
<#if field.fieldComment!?length gt 0>
@Schema(description = "${field.fieldComment}")
#if>
- <#if field.attrType == 'Date'>
+ <#if field.attrType == 'LocalDateTime'>
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
#if>
private ${field.attrType} ${field.attrName};
#list>
+<#list subs as sub>
+ @Schema(description = "${sub.tableTitle}")
+ <#if sub.mainRelation ==1>
+ private ${sub.ClassName}VO ${sub.className};
+ <#else>
+ private List<${sub.ClassName}VO> ${sub.className};
+ #if>
+#list>
+ <#if hasTree>
+ @Schema(description = "是否有子节点")
+ private Boolean hasChild;
+ #if>
}
\ No newline at end of file
diff --git a/maku-boot-module/maku-module-generator/src/main/resources/template/sql/menu.sql.ftl b/maku-boot-module/maku-module-generator/src/main/resources/template/sql/menu.sql.ftl
index d16769e..3b6c896 100644
--- a/maku-boot-module/maku-module-generator/src/main/resources/template/sql/menu.sql.ftl
+++ b/maku-boot-module/maku-module-generator/src/main/resources/template/sql/menu.sql.ftl
@@ -4,9 +4,30 @@
#if>
-- 初始化菜单
-INSERT INTO sys_menu (pid, name, url, authority, type, open_style, icon, sort, version, deleted, creator, create_time, updater, update_time) VALUES (1, '${tableComment!}', '${moduleName}/${functionName}/index', NULL, 0, 0, 'icon-menu', 0, 0, 0, 10000, ${dbTime}, 10000, ${dbTime});
+INSERT INTO sys_menu (pid, name, url, authority, type, open_style, icon, sort, version, deleted, creator, create_time, updater, update_time) VALUES (1, '${tableComment!}', '${moduleName}/${functionName}/index', <#if authLevel==0>'${authority}'<#else>NULL#if>, 0, 0, 'icon-menu', 0, 0, 0, 10000, ${dbTime}, 10000, ${dbTime});
-INSERT INTO sys_menu (pid, name, url, authority, type, open_style, icon, sort, version, deleted, creator, create_time, updater, update_time) VALUES ((SELECT max(id) from sys_menu where name = '${tableComment!}'), '查看', '', '${moduleName}:${functionName}:page', 1, 0, '', 0, 0, 0, 10000, ${dbTime}, 10000, ${dbTime});
-INSERT INTO sys_menu (pid, name, url, authority, type, open_style, icon, sort, version, deleted, creator, create_time, updater, update_time) VALUES ((SELECT max(id) from sys_menu where name = '${tableComment!}'), '新增', '', '${moduleName}:${functionName}:save', 1, 0, '', 1, 0, 0, 10000, ${dbTime}, 10000, ${dbTime});
-INSERT INTO sys_menu (pid, name, url, authority, type, open_style, icon, sort, version, deleted, creator, create_time, updater, update_time) VALUES ((SELECT max(id) from sys_menu where name = '${tableComment!}'), '修改', '', '${moduleName}:${functionName}:update,${moduleName}:${functionName}:info', 1, 0, '', 2, 0, 0, 10000, ${dbTime}, 10000, ${dbTime});
-INSERT INTO sys_menu (pid, name, url, authority, type, open_style, icon, sort, version, deleted, creator, create_time, updater, update_time) VALUES ((SELECT max(id) from sys_menu where name = '${tableComment!}'), '删除', '', '${moduleName}:${functionName}:delete', 1, 0, '', 3, 0, 0, 10000, ${dbTime}, 10000, ${dbTime});
+<#if authLevel==1>
+
+<#assign pid = "(SELECT max(id) from sys_menu where name = '${tableComment!}')">
+<#if dbType=="MySQL">
+set @menuId = @@identity;
+<#assign pid = "(SELECT @menuId)">
+#if>
+
+INSERT INTO sys_menu (pid, name, url, authority, type, open_style, icon, sort, version, deleted, creator, create_time, updater, update_time) VALUES (${pid}, '查看', '', '${authority}:page', 1, 0, '', 0, 0, 0, 10000, ${dbTime}, 10000, ${dbTime});
+<#if tableOperation?seq_contains('insert')>
+INSERT INTO sys_menu (pid, name, url, authority, type, open_style, icon, sort, version, deleted, creator, create_time, updater, update_time) VALUES (${pid}, '新增', '', '${authority}:save', 1, 0, '', 1, 0, 0, 10000, ${dbTime}, 10000, ${dbTime});
+#if>
+<#if tableOperation?seq_contains('update')>
+INSERT INTO sys_menu (pid, name, url, authority, type, open_style, icon, sort, version, deleted, creator, create_time, updater, update_time) VALUES (${pid}, '修改', '', '${authority}:update,${authority}:info', 1, 0, '', 2, 0, 0, 10000, ${dbTime}, 10000, ${dbTime});
+#if>
+<#if tableOperation?seq_contains('delete')>
+INSERT INTO sys_menu (pid, name, url, authority, type, open_style, icon, sort, version, deleted, creator, create_time, updater, update_time) VALUES (${pid}, '删除', '', '${authority}:delete', 1, 0, '', 3, 0, 0, 10000, ${dbTime}, 10000, ${dbTime});
+#if>
+<#if tableOperation?seq_contains('import')>
+INSERT INTO sys_menu (pid, name, url, authority, type, open_style, icon, sort, version, deleted, creator, create_time, updater, update_time) VALUES (${pid}, '导入', '', '${authority}:import', 1, 0, '', 3, 0, 0, 10000, ${dbTime}, 10000, ${dbTime});
+#if>
+<#if tableOperation?seq_contains('export')>
+INSERT INTO sys_menu (pid, name, url, authority, type, open_style, icon, sort, version, deleted, creator, create_time, updater, update_time) VALUES (${pid}, '导出', '', '${authority}:export', 1, 0, '', 3, 0, 0, 10000, ${dbTime}, 10000, ${dbTime});
+#if>
+#if>
\ No newline at end of file
diff --git a/maku-boot-module/maku-module-generator/src/main/resources/template/vue/add-or-update.vue.ftl b/maku-boot-module/maku-module-generator/src/main/resources/template/vue/add-or-update.vue.ftl
index 4156892..206d120 100644
--- a/maku-boot-module/maku-module-generator/src/main/resources/template/vue/add-or-update.vue.ftl
+++ b/maku-boot-module/maku-module-generator/src/main/resources/template/vue/add-or-update.vue.ftl
@@ -1,98 +1,64 @@
+<#import "/vue/form.vue.ftl" as form>
-
-
- <#list formList as field>
- <#if field.formType == 'text'>
-
-
-
- <#elseif field.formType == 'textarea'>
-
-
-
- <#elseif field.formType == 'editor'>
-
-
-
- <#elseif field.formType == 'select'>
- <#if field.formDict??>
-
-
-
- <#else>
-
-
-
-
-
- #if>
- <#elseif field.formType == 'radio'>
- <#if field.formDict??>
-
-
-
- <#else>
-
-
- 启用
- 禁用
-
-
- #if>
- <#elseif field.formType == 'checkbox'>
-
-
-
-
-
-
- <#elseif field.formType == 'date'>
-
-
-
- <#elseif field.formType == 'datetime'>
-
-
-
- <#else>
-
-
-
- #if>
- #list>
-
+ <#if openType==0>
+
+ <#else>
+
+ #if>
+ <@form.maForm>@form.maForm>
+ <#if subs?size gt 0>
+
+ <#list subs as sub>
+
+ <${sub.ClassName} ref="${sub.className}Ref" :value="dataForm.${sub.className}"/>
+
+ #list>
+
+ #if>
取消
确定
+ <#if openType==0>
+ <#else>
+
+ #if>
diff --git a/maku-boot-module/maku-module-generator/src/main/resources/template/vue/sub-add-or-update.vue.ftl b/maku-boot-module/maku-module-generator/src/main/resources/template/vue/sub-add-or-update.vue.ftl
new file mode 100644
index 0000000..2ab3c2f
--- /dev/null
+++ b/maku-boot-module/maku-module-generator/src/main/resources/template/vue/sub-add-or-update.vue.ftl
@@ -0,0 +1,183 @@
+<#import "/vue/form.vue.ftl" as form>
+
+ <#if mainRelation == 1>
+ <@form.maForm>@form.maForm>
+ #if>
+ <#if mainRelation == 2>
+ 新增
+ 删除
+
+
+ <#list formList as field>
+
+ #list>
+
+
+
+
+
+
+
+
+ <@form.maForm>@form.maForm>
+
+ 取消
+ 确定
+
+
+ #if>
+
+
+
diff --git a/maku-boot-module/maku-module-generator/src/main/resources/template/xml/Dao.xml.ftl b/maku-boot-module/maku-module-generator/src/main/resources/template/xml/Dao.xml.ftl
index 2b895c7..5344b46 100644
--- a/maku-boot-module/maku-module-generator/src/main/resources/template/xml/Dao.xml.ftl
+++ b/maku-boot-module/maku-module-generator/src/main/resources/template/xml/Dao.xml.ftl
@@ -3,10 +3,4 @@
-
- <#list fieldList as field>
-
- #list>
-
-
\ No newline at end of file