代码生成器模块,支持多表生成
This commit is contained in:
parent
717920b544
commit
b4377a1fe9
|
|
@ -12,8 +12,8 @@
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.maku</groupId>
|
<groupId>net.maku</groupId>
|
||||||
<artifactId>maku-generator-boot-starter</artifactId>
|
<artifactId>maku-generator-pro-boot-starter</artifactId>
|
||||||
<version>3.1.0</version>
|
<version>1.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@
|
||||||
"packageName": "net.maku",
|
"packageName": "net.maku",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"backendPath": "D:\\generator\\maku-boot\\maku-server",
|
"backendPath": "D:\\generator\\maku-boot\\maku-server",
|
||||||
"frontendPath": "D:\\generator\\maku-admin"
|
"frontendPath": "D:\\generator\\maku-admin",
|
||||||
},
|
"tablePrefix": "tb_",
|
||||||
"developer": {
|
"moduleName": "business",
|
||||||
"author": "阿沐",
|
"author": "阿沐",
|
||||||
"email": "babamu@126.com"
|
"email": "babamu@126.com"
|
||||||
},
|
},
|
||||||
|
|
@ -35,6 +35,10 @@
|
||||||
"generatorPath": "${backendPath}/src/main/java/${packagePath}/${moduleName}/vo/${ClassName}VO.java"
|
"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",
|
"templateName": "java/Convert.java.ftl",
|
||||||
"generatorPath": "${backendPath}/src/main/java/${packagePath}/${moduleName}/convert/${ClassName}Convert.java"
|
"generatorPath": "${backendPath}/src/main/java/${packagePath}/${moduleName}/convert/${ClassName}Convert.java"
|
||||||
},
|
},
|
||||||
|
|
@ -62,5 +66,27 @@
|
||||||
"templateName": "vue/add-or-update.vue.ftl",
|
"templateName": "vue/add-or-update.vue.ftl",
|
||||||
"generatorPath": "${frontendPath}/src/views/${moduleName}/${functionName}/add-or-update.vue"
|
"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"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
@ -5,26 +5,28 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import ${package}.framework.common.utils.PageResult;
|
import ${package}.framework.common.utils.PageResult;
|
||||||
import ${package}.framework.common.utils.Result;
|
import ${package}.framework.common.utils.Result;
|
||||||
import ${package}.${moduleName}.convert.${ClassName}Convert;
|
import ${package}.framework.operatelog.annotations.OperateLog;
|
||||||
import ${package}.${moduleName}.entity.${ClassName}Entity;
|
import ${package}.framework.operatelog.enums.OperateTypeEnum;
|
||||||
import ${package}.${moduleName}.service.${ClassName}Service;
|
import ${package}.${moduleName}.service.${ClassName}Service;
|
||||||
import ${package}.${moduleName}.query.${ClassName}Query;
|
import ${package}.${moduleName}.query.${ClassName}Query;
|
||||||
import ${package}.${moduleName}.vo.${ClassName}VO;
|
import ${package}.${moduleName}.vo.${ClassName}VO;
|
||||||
import org.springdoc.core.annotations.ParameterObject;
|
import org.springdoc.core.annotations.ParameterObject;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
<#if tableOperation?seq_contains('import')>
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
</#if>
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ${tableComment}
|
* ${tableComment!}
|
||||||
*
|
*
|
||||||
* @author ${author} ${email}
|
* @author ${author} ${email!}
|
||||||
* @since ${version} ${date}
|
* <a href="https://maku.net">MAKU</a>
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("${moduleName}/${functionName}")
|
@RequestMapping("${requestUrl}")
|
||||||
@Tag(name="${tableComment}")
|
@Tag(name="${tableComment}")
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ${ClassName}Controller {
|
public class ${ClassName}Controller {
|
||||||
|
|
@ -32,46 +34,91 @@ public class ${ClassName}Controller {
|
||||||
|
|
||||||
@GetMapping("page")
|
@GetMapping("page")
|
||||||
@Operation(summary = "分页")
|
@Operation(summary = "分页")
|
||||||
@PreAuthorize("hasAuthority('${moduleName}:${functionName}:page')")
|
@PreAuthorize("hasAuthority('${authority}<#if authLevel==1>:page</#if>')")
|
||||||
public Result<PageResult<${ClassName}VO>> page(@ParameterObject @Valid ${ClassName}Query query){
|
public Result<PageResult<${ClassName}VO>> page(@ParameterObject @Valid ${ClassName}Query query){
|
||||||
PageResult<${ClassName}VO> page = ${className}Service.page(query);
|
PageResult<${ClassName}VO> page = ${className}Service.page(query);
|
||||||
|
|
||||||
return Result.ok(page);
|
return Result.ok(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<#if hasTree>
|
||||||
|
@GetMapping("list")
|
||||||
|
@Operation(summary = "列表")
|
||||||
|
@PreAuthorize("hasAuthority('${authority}<#if authLevel==1>:page</#if>')")
|
||||||
|
public Result<List<${ClassName}VO>> list(Long ${treePid}) {
|
||||||
|
List<${ClassName}VO> list = ${className}Service.list(${treePid});
|
||||||
|
|
||||||
|
return Result.ok(list);
|
||||||
|
}
|
||||||
|
</#if>
|
||||||
|
|
||||||
@GetMapping("{id}")
|
@GetMapping("{id}")
|
||||||
@Operation(summary = "信息")
|
@Operation(summary = "信息")
|
||||||
@PreAuthorize("hasAuthority('${moduleName}:${functionName}:info')")
|
@PreAuthorize("hasAuthority('${authority}<#if authLevel==1>:info</#if>')")
|
||||||
public Result<${ClassName}VO> get(@PathVariable("id") Long id){
|
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
|
@PostMapping
|
||||||
@Operation(summary = "保存")
|
@Operation(summary = "保存")
|
||||||
@PreAuthorize("hasAuthority('${moduleName}:${functionName}:save')")
|
@OperateLog(type = OperateTypeEnum.INSERT)
|
||||||
|
@PreAuthorize("hasAuthority('${authority}<#if authLevel==1>:save</#if>')")
|
||||||
public Result<String> save(@RequestBody ${ClassName}VO vo){
|
public Result<String> save(@RequestBody ${ClassName}VO vo){
|
||||||
${className}Service.save(vo);
|
${className}Service.save(vo);
|
||||||
|
|
||||||
return Result.ok();
|
return Result.ok();
|
||||||
}
|
}
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<#if tableOperation?seq_contains('update')>
|
||||||
@PutMapping
|
@PutMapping
|
||||||
@Operation(summary = "修改")
|
@Operation(summary = "修改")
|
||||||
@PreAuthorize("hasAuthority('${moduleName}:${functionName}:update')")
|
@OperateLog(type = OperateTypeEnum.UPDATE)
|
||||||
|
@PreAuthorize("hasAuthority('${authority}<#if authLevel==1>:update</#if>')")
|
||||||
public Result<String> update(@RequestBody @Valid ${ClassName}VO vo){
|
public Result<String> update(@RequestBody @Valid ${ClassName}VO vo){
|
||||||
${className}Service.update(vo);
|
${className}Service.update(vo);
|
||||||
|
|
||||||
return Result.ok();
|
return Result.ok();
|
||||||
}
|
}
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<#if tableOperation?seq_contains('delete')>
|
||||||
@DeleteMapping
|
@DeleteMapping
|
||||||
@Operation(summary = "删除")
|
@Operation(summary = "删除")
|
||||||
@PreAuthorize("hasAuthority('${moduleName}:${functionName}:delete')")
|
@OperateLog(type = OperateTypeEnum.DELETE)
|
||||||
|
@PreAuthorize("hasAuthority('${authority}<#if authLevel==1>:delete</#if>')")
|
||||||
public Result<String> delete(@RequestBody List<Long> idList){
|
public Result<String> delete(@RequestBody List<Long> idList){
|
||||||
${className}Service.delete(idList);
|
${className}Service.delete(idList);
|
||||||
|
|
||||||
return Result.ok();
|
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<String> 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>
|
||||||
}
|
}
|
||||||
|
|
@ -2,17 +2,20 @@ package ${package}.${moduleName}.convert;
|
||||||
|
|
||||||
import ${package}.${moduleName}.entity.${ClassName}Entity;
|
import ${package}.${moduleName}.entity.${ClassName}Entity;
|
||||||
import ${package}.${moduleName}.vo.${ClassName}VO;
|
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.Mapper;
|
||||||
import org.mapstruct.factory.Mappers;
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ${tableComment}
|
* ${tableComment}
|
||||||
*
|
*
|
||||||
* @author ${author} ${email}
|
* @author ${author} ${email!}
|
||||||
* @since ${version} ${date}
|
* <a href="https://maku.net">MAKU</a>
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface ${ClassName}Convert {
|
public interface ${ClassName}Convert {
|
||||||
${ClassName}Convert INSTANCE = Mappers.getMapper(${ClassName}Convert.class);
|
${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}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>
|
||||||
}
|
}
|
||||||
|
|
@ -5,12 +5,12 @@ import ${package}.${moduleName}.entity.${ClassName}Entity;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ${tableComment}
|
* ${tableComment}
|
||||||
*
|
*
|
||||||
* @author ${author} ${email}
|
* @author ${author} ${email!}
|
||||||
* @since ${version} ${date}
|
* <a href="https://maku.net">MAKU</a>
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface ${ClassName}Dao extends BaseDao<${ClassName}Entity> {
|
public interface ${ClassName}Dao extends BaseDao<${ClassName}Entity> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -13,8 +13,8 @@ import ${baseClass.packageName}.${baseClass.code};
|
||||||
/**
|
/**
|
||||||
* ${tableComment}
|
* ${tableComment}
|
||||||
*
|
*
|
||||||
* @author ${author} ${email}
|
* @author ${author} ${email!}
|
||||||
* @since ${version} ${date}
|
* <a href="https://maku.net">MAKU</a>
|
||||||
*/
|
*/
|
||||||
<#if baseClass??>@EqualsAndHashCode(callSuper=false)</#if>
|
<#if baseClass??>@EqualsAndHashCode(callSuper=false)</#if>
|
||||||
@Data
|
@Data
|
||||||
|
|
@ -27,18 +27,20 @@ public class ${ClassName}Entity<#if baseClass??> extends ${baseClass.code}</#if>
|
||||||
* ${field.fieldComment}
|
* ${field.fieldComment}
|
||||||
*/
|
*/
|
||||||
</#if>
|
</#if>
|
||||||
<#if field.autoFill == "INSERT">
|
<#if field.primaryPk>
|
||||||
@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>
|
|
||||||
@TableId
|
@TableId
|
||||||
</#if>
|
</#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};
|
private ${field.attrType} ${field.attrName};
|
||||||
</#if>
|
</#if>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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!}
|
||||||
|
* <a href="https://maku.net">MAKU</a>
|
||||||
|
*/
|
||||||
|
@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>
|
||||||
|
}
|
||||||
|
|
@ -11,11 +11,11 @@ import ${i!};
|
||||||
</#list>
|
</#list>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ${tableComment}查询
|
* ${tableComment}查询
|
||||||
*
|
*
|
||||||
* @author ${author} ${email}
|
* @author ${author} ${email!}
|
||||||
* @since ${version} ${date}
|
* <a href="https://maku.net">MAKU</a>
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
@Schema(description = "${tableComment}查询")
|
@Schema(description = "${tableComment}查询")
|
||||||
|
|
@ -24,10 +24,12 @@ public class ${ClassName}Query extends Query {
|
||||||
<#if field.fieldComment!?length gt 0>
|
<#if field.fieldComment!?length gt 0>
|
||||||
@Schema(description = "${field.fieldComment}")
|
@Schema(description = "${field.fieldComment}")
|
||||||
</#if>
|
</#if>
|
||||||
<#if field.attrType == 'Date'>
|
<#if field.queryFormType == 'date'>
|
||||||
@DateTimeFormat(pattern = DateUtils.DATE_TIME_PATTERN)
|
@DateTimeFormat(pattern="yyyy-MM-dd")
|
||||||
|
<#elseif field.queryFormType == 'datetime'>
|
||||||
|
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||||
</#if>
|
</#if>
|
||||||
private ${field.attrType} ${field.attrName};
|
private ${field.attrType}<#if field.queryFormType == 'date' || field.queryFormType == 'datetime'>[]</#if> ${field.attrName};
|
||||||
|
|
||||||
</#list>
|
</#list>
|
||||||
}
|
}
|
||||||
|
|
@ -5,22 +5,44 @@ import ${package}.framework.mybatis.service.BaseService;
|
||||||
import ${package}.${moduleName}.vo.${ClassName}VO;
|
import ${package}.${moduleName}.vo.${ClassName}VO;
|
||||||
import ${package}.${moduleName}.query.${ClassName}Query;
|
import ${package}.${moduleName}.query.${ClassName}Query;
|
||||||
import ${package}.${moduleName}.entity.${ClassName}Entity;
|
import ${package}.${moduleName}.entity.${ClassName}Entity;
|
||||||
|
<#if tableOperation?seq_contains('import')>
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
</#if>
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ${tableComment}
|
* ${tableComment}
|
||||||
*
|
*
|
||||||
* @author ${author} ${email}
|
* @author ${author} ${email!}
|
||||||
* @since ${version} ${date}
|
* <a href="https://maku.net">MAKU</a>
|
||||||
*/
|
*/
|
||||||
public interface ${ClassName}Service extends BaseService<${ClassName}Entity> {
|
public interface ${ClassName}Service extends BaseService<${ClassName}Entity> {
|
||||||
|
|
||||||
PageResult<${ClassName}VO> page(${ClassName}Query query);
|
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);
|
void save(${ClassName}VO vo);
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<#if tableOperation?seq_contains('update')>
|
||||||
void update(${ClassName}VO vo);
|
void update(${ClassName}VO vo);
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<#if tableOperation?seq_contains('delete')>
|
||||||
void delete(List<Long> idList);
|
void delete(List<Long> idList);
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<#if tableOperation?seq_contains('import')>
|
||||||
|
void importByExcel(MultipartFile file);
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<#if tableOperation?seq_contains('export')>
|
||||||
|
void export();
|
||||||
|
</#if>
|
||||||
}
|
}
|
||||||
|
|
@ -12,6 +12,19 @@ import ${package}.${moduleName}.query.${ClassName}Query;
|
||||||
import ${package}.${moduleName}.vo.${ClassName}VO;
|
import ${package}.${moduleName}.vo.${ClassName}VO;
|
||||||
import ${package}.${moduleName}.dao.${ClassName}Dao;
|
import ${package}.${moduleName}.dao.${ClassName}Dao;
|
||||||
import ${package}.${moduleName}.service.${ClassName}Service;
|
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.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
|
@ -20,44 +33,206 @@ import java.util.List;
|
||||||
/**
|
/**
|
||||||
* ${tableComment}
|
* ${tableComment}
|
||||||
*
|
*
|
||||||
* @author ${author} ${email}
|
* @author ${author} ${email!}
|
||||||
* @since ${version} ${date}
|
* <a href="https://maku.net">MAKU</a>
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ${ClassName}ServiceImpl extends BaseServiceImpl<${ClassName}Dao, ${ClassName}Entity> implements ${ClassName}Service {
|
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
|
@Override
|
||||||
public PageResult<${ClassName}VO> page(${ClassName}Query query) {
|
public PageResult<${ClassName}VO> page(${ClassName}Query query) {
|
||||||
IPage<${ClassName}Entity> page = baseMapper.selectPage(getPage(query), getWrapper(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());
|
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){
|
private LambdaQueryWrapper<${ClassName}Entity> getWrapper(${ClassName}Query query){
|
||||||
LambdaQueryWrapper<${ClassName}Entity> wrapper = Wrappers.lambdaQuery();
|
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;
|
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
|
@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) {
|
public void save(${ClassName}VO vo) {
|
||||||
${ClassName}Entity entity = ${ClassName}Convert.INSTANCE.convert(vo);
|
${ClassName}Entity entity = ${ClassName}Convert.INSTANCE.convert(vo);
|
||||||
|
|
||||||
baseMapper.insert(entity);
|
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
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void update(${ClassName}VO vo) {
|
public void update(${ClassName}VO vo) {
|
||||||
${ClassName}Entity entity = ${ClassName}Convert.INSTANCE.convert(vo);
|
${ClassName}Entity entity = ${ClassName}Convert.INSTANCE.convert(vo);
|
||||||
|
|
||||||
updateById(entity);
|
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
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void delete(List<Long> idList) {
|
public void delete(List<Long> idList) {
|
||||||
removeByIds(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>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -2,6 +2,7 @@ package ${package}.${moduleName}.vo;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import java.util.List;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import ${package}.framework.common.utils.DateUtils;
|
import ${package}.framework.common.utils.DateUtils;
|
||||||
|
|
@ -10,11 +11,11 @@ import ${i!};
|
||||||
</#list>
|
</#list>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ${tableComment}
|
* ${tableComment}
|
||||||
*
|
*
|
||||||
* @author ${author} ${email}
|
* @author ${author} ${email!}
|
||||||
* @since ${version} ${date}
|
* <a href="https://maku.net">MAKU</a>
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Schema(description = "${tableComment}")
|
@Schema(description = "${tableComment}")
|
||||||
public class ${ClassName}VO implements Serializable {
|
public class ${ClassName}VO implements Serializable {
|
||||||
|
|
@ -24,11 +25,23 @@ public class ${ClassName}VO implements Serializable {
|
||||||
<#if field.fieldComment!?length gt 0>
|
<#if field.fieldComment!?length gt 0>
|
||||||
@Schema(description = "${field.fieldComment}")
|
@Schema(description = "${field.fieldComment}")
|
||||||
</#if>
|
</#if>
|
||||||
<#if field.attrType == 'Date'>
|
<#if field.attrType == 'LocalDateTime'>
|
||||||
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
|
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
|
||||||
</#if>
|
</#if>
|
||||||
private ${field.attrType} ${field.attrName};
|
private ${field.attrType} ${field.attrName};
|
||||||
|
|
||||||
</#list>
|
</#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>
|
||||||
}
|
}
|
||||||
|
|
@ -4,9 +4,30 @@
|
||||||
</#if>
|
</#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});
|
<#if authLevel==1>
|
||||||
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});
|
<#assign pid = "(SELECT max(id) from sys_menu where name = '${tableComment!}')">
|
||||||
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 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>
|
||||||
|
|
@ -1,98 +1,64 @@
|
||||||
|
<#import "/vue/form.vue.ftl" as form>
|
||||||
<template>
|
<template>
|
||||||
<el-dialog v-model="visible" :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false">
|
<#if openType==0>
|
||||||
<el-form ref="dataFormRef" :model="dataForm" :rules="dataRules" label-width="100px" @keyup.enter="submitHandle()">
|
<el-dialog v-model="visible" :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false" draggable>
|
||||||
<#list formList as field>
|
<#else>
|
||||||
<#if field.formType == 'text'>
|
<el-drawer v-model="visible" :title="!dataForm.id ? '新增' : '修改'" :size="1000">
|
||||||
<el-form-item label="${field.fieldComment!}" prop="${field.attrName}">
|
</#if>
|
||||||
<el-input v-model="dataForm.${field.attrName}" placeholder="${field.fieldComment!}"></el-input>
|
<@form.maForm></@form.maForm>
|
||||||
</el-form-item>
|
<#if subs?size gt 0>
|
||||||
<#elseif field.formType == 'textarea'>
|
<el-tabs v-model="activeName">
|
||||||
<el-form-item label="${field.fieldComment!}" prop="${field.attrName}">
|
<#list subs as sub>
|
||||||
<el-input type="textarea" v-model="dataForm.${field.attrName}"></el-input>
|
<el-tab-pane label="${sub.tableTitle}" name="${sub.className}">
|
||||||
</el-form-item>
|
<${sub.ClassName} ref="${sub.className}Ref" :value="dataForm.${sub.className}"/>
|
||||||
<#elseif field.formType == 'editor'>
|
</el-tab-pane>
|
||||||
<el-form-item label="${field.fieldComment!}" prop="${field.attrName}">
|
</#list>
|
||||||
<el-input type="textarea" v-model="dataForm.${field.attrName}"></el-input>
|
</el-tabs>
|
||||||
</el-form-item>
|
</#if>
|
||||||
<#elseif field.formType == 'select'>
|
|
||||||
<#if field.formDict??>
|
|
||||||
<el-form-item label="${field.fieldComment!}" prop="${field.attrName}">
|
|
||||||
<ma-dict-select v-model="dataForm.${field.attrName}" dict-type="${field.formDict}" placeholder="${field.fieldComment!}"></ma-dict-select>
|
|
||||||
</el-form-item>
|
|
||||||
<#else>
|
|
||||||
<el-form-item label="${field.fieldComment!}" prop="${field.attrName}">
|
|
||||||
<el-select v-model="dataForm.${field.attrName}" placeholder="请选择">
|
|
||||||
<el-option label="请选择" value="0"></el-option>
|
|
||||||
</el-select>
|
|
||||||
</el-form-item>
|
|
||||||
</#if>
|
|
||||||
<#elseif field.formType == 'radio'>
|
|
||||||
<#if field.formDict??>
|
|
||||||
<el-form-item label="${field.fieldComment!}" prop="${field.attrName}">
|
|
||||||
<ma-dict-radio v-model="dataForm.${field.attrName}" dict-type="${field.formDict}"></ma-dict-radio>
|
|
||||||
</el-form-item>
|
|
||||||
<#else>
|
|
||||||
<el-form-item label="${field.fieldComment!}" prop="${field.attrName}">
|
|
||||||
<el-radio-group v-model="dataForm.${field.attrName}">
|
|
||||||
<el-radio :label="0">启用</el-radio>
|
|
||||||
<el-radio :label="1">禁用</el-radio>
|
|
||||||
</el-radio-group>
|
|
||||||
</el-form-item>
|
|
||||||
</#if>
|
|
||||||
<#elseif field.formType == 'checkbox'>
|
|
||||||
<el-form-item label="${field.fieldComment!}" prop="${field.attrName}">
|
|
||||||
<el-checkbox-group v-model="dataForm.${field.attrName}">
|
|
||||||
<el-checkbox label="启用" name="type"></el-checkbox>
|
|
||||||
<el-checkbox label="禁用" name="type"></el-checkbox>
|
|
||||||
</el-checkbox-group>
|
|
||||||
</el-form-item>
|
|
||||||
<#elseif field.formType == 'date'>
|
|
||||||
<el-form-item label="${field.fieldComment!}" prop="${field.attrName}">
|
|
||||||
<el-date-picker type="date" placeholder="${field.fieldComment!}" v-model="dataForm.${field.attrName}"></el-date-picker>
|
|
||||||
</el-form-item>
|
|
||||||
<#elseif field.formType == 'datetime'>
|
|
||||||
<el-form-item label="${field.fieldComment!}" prop="${field.attrName}">
|
|
||||||
<el-date-picker type="datetime" placeholder="${field.fieldComment!}" v-model="dataForm.${field.attrName}"></el-date-picker>
|
|
||||||
</el-form-item>
|
|
||||||
<#else>
|
|
||||||
<el-form-item label="${field.fieldComment!}" prop="${field.attrName}">
|
|
||||||
<el-input v-model="dataForm.${field.attrName}" placeholder="${field.fieldComment!}"></el-input>
|
|
||||||
</el-form-item>
|
|
||||||
</#if>
|
|
||||||
</#list>
|
|
||||||
</el-form>
|
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<el-button @click="visible = false">取消</el-button>
|
<el-button @click="visible = false">取消</el-button>
|
||||||
<el-button type="primary" @click="submitHandle()">确定</el-button>
|
<el-button type="primary" @click="submitHandle()">确定</el-button>
|
||||||
</template>
|
</template>
|
||||||
|
<#if openType==0>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
|
<#else>
|
||||||
|
</el-drawer>
|
||||||
|
</#if>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { reactive, ref } from 'vue'
|
import { reactive, ref } from 'vue'
|
||||||
import { ElMessage } from 'element-plus/es'
|
import { ElMessage } from 'element-plus/es'
|
||||||
import { use${FunctionName}Api, use${FunctionName}SubmitApi } from '@/api/${moduleName}/${functionName}'
|
import { use${FunctionName}Api, use${FunctionName}SubmitApi } from '@/api/${moduleName}/${functionName}'
|
||||||
|
<#list subs as sub>
|
||||||
|
import ${sub.ClassName} from './${sub.className}.vue'
|
||||||
|
</#list>
|
||||||
|
|
||||||
const emit = defineEmits(['refreshDataList'])
|
const emit = defineEmits(['refreshDataList'])
|
||||||
|
|
||||||
const visible = ref(false)
|
const visible = defineModel<boolean>('visible')
|
||||||
const dataFormRef = ref()
|
const dataFormRef = ref()
|
||||||
|
<#if subs?size gt 0>
|
||||||
|
const activeName = ref("${subs[0].className}")
|
||||||
|
</#if>
|
||||||
|
<#list subs as sub>
|
||||||
|
const ${sub.className}Ref = ref()
|
||||||
|
</#list>
|
||||||
|
|
||||||
const dataForm = reactive({
|
const dataForm = reactive({
|
||||||
|
<#list subs as sub>
|
||||||
|
<#if sub.mainRelation == 1>
|
||||||
|
${sub.className}: {},
|
||||||
|
<#else>
|
||||||
|
${sub.className}: [],
|
||||||
|
</#if>
|
||||||
|
</#list>
|
||||||
<#list fieldList as field>
|
<#list fieldList as field>
|
||||||
${field.attrName}: ''<#sep>,
|
${field.attrName}: ''<#sep>,
|
||||||
</#list>
|
</#list>
|
||||||
})
|
})
|
||||||
|
|
||||||
const init = (id?: number) => {
|
const init = (id?: number) => {
|
||||||
visible.value = true
|
|
||||||
dataForm.id = ''
|
|
||||||
|
|
||||||
// 重置表单数据
|
|
||||||
if (dataFormRef.value) {
|
|
||||||
dataFormRef.value.resetFields()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (id) {
|
if (id) {
|
||||||
get${FunctionName}(id)
|
get${FunctionName}(id)
|
||||||
}
|
}
|
||||||
|
|
@ -114,11 +80,15 @@ const dataRules = ref({
|
||||||
|
|
||||||
// 表单提交
|
// 表单提交
|
||||||
const submitHandle = () => {
|
const submitHandle = () => {
|
||||||
dataFormRef.value.validate((valid: boolean) => {
|
dataFormRef.value.validate(async (valid: boolean) => {
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<#list subs as sub>
|
||||||
|
dataForm.${sub.className} = await ${sub.className}Ref.value.getData()
|
||||||
|
</#list>
|
||||||
|
|
||||||
use${FunctionName}SubmitApi(dataForm).then(() => {
|
use${FunctionName}SubmitApi(dataForm).then(() => {
|
||||||
ElMessage.success({
|
ElMessage.success({
|
||||||
message: '操作成功',
|
message: '操作成功',
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,19 @@
|
||||||
import service from '@/utils/request'
|
import service from '@/utils/request'
|
||||||
|
|
||||||
export const use${FunctionName}Api = (id: number) => {
|
export const use${FunctionName}Api = (id: number) => {
|
||||||
return service.get('/${moduleName}/${functionName}/' + id)
|
return service.get('${requestUrl}/' + id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<#if hasTree>
|
||||||
|
export const use${FunctionName}TreeLoadApi = (${treePid}: number) => {
|
||||||
|
return service.get('${requestUrl}/list?${treePid}=' + ${treePid})
|
||||||
|
}
|
||||||
|
|
||||||
|
</#if>
|
||||||
export const use${FunctionName}SubmitApi = (dataForm: any) => {
|
export const use${FunctionName}SubmitApi = (dataForm: any) => {
|
||||||
if (dataForm.id) {
|
if (dataForm.id) {
|
||||||
return service.put('/${moduleName}/${functionName}', dataForm)
|
return service.put('${requestUrl}', dataForm)
|
||||||
} else {
|
} else {
|
||||||
return service.post('/${moduleName}/${functionName}', dataForm)
|
return service.post('${requestUrl}', dataForm)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
<#macro maFormItem model field>
|
||||||
|
<el-form-item label="${field.fieldComment!}" prop="${field.attrName}">
|
||||||
|
<#if hasTree && field.fieldName == treePid>
|
||||||
|
<ma-data-tree-select
|
||||||
|
v-model="${model}.${field.attrName}"
|
||||||
|
url="${requestUrl}/list"
|
||||||
|
:props="{ label: '${treeLabel}', value: '${treeId}' }"
|
||||||
|
pplaceholder="${field.fieldComment!}" />
|
||||||
|
<#elseif field.formType == 'input'>
|
||||||
|
<el-input v-model="${model}.${field.attrName}" placeholder="${field.fieldComment!}"></el-input>
|
||||||
|
<#elseif field.formType == 'number'>
|
||||||
|
<el-input-number v-model="${model}.${field.attrName}" placeholder="${field.fieldComment!}"></el-input-number>
|
||||||
|
<#elseif field.formType == 'textarea'>
|
||||||
|
<el-input type="textarea" v-model="${model}.${field.attrName}" placeholder="${field.fieldComment!}"></el-input>
|
||||||
|
<#elseif field.formType == 'editor'>
|
||||||
|
<ma-editor v-model="${model}.${field.attrName}" placeholder="${field.fieldComment!}"></ma-editor>
|
||||||
|
<#elseif field.formType == 'select'>
|
||||||
|
<#if field.formDict??>
|
||||||
|
<ma-dict-select v-model="${model}.${field.attrName}" dict-type="${field.formDict}" placeholder="${field.fieldComment!}"></ma-dict-select>
|
||||||
|
<#else>
|
||||||
|
<el-select v-model="${model}.${field.attrName}" placeholder="${field.fieldComment!}">
|
||||||
|
<el-option label="请选择" :value="0"></el-option>
|
||||||
|
</el-select>
|
||||||
|
</#if>
|
||||||
|
<#elseif field.formType == 'radio'>
|
||||||
|
<#if field.formDict??>
|
||||||
|
<ma-dict-radio v-model="${model}.${field.attrName}" dict-type="${field.formDict}"></ma-dict-radio>
|
||||||
|
<#else>
|
||||||
|
<el-radio-group v-model="${model}.${field.attrName}">
|
||||||
|
<el-radio :value="0">启用</el-radio>
|
||||||
|
<el-radio :value="1">禁用</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
|
</#if>
|
||||||
|
<#elseif field.formType == 'checkbox'>
|
||||||
|
<el-checkbox-group v-model="${model}.${field.attrName}">
|
||||||
|
<el-checkbox :value="1">启用</el-checkbox>
|
||||||
|
<el-checkbox :value="0">禁用</el-checkbox>
|
||||||
|
</el-checkbox-group>
|
||||||
|
<#elseif field.formType == 'address'>
|
||||||
|
<ma-address v-model="${model}.${field.attrName}" placeholder="${field.fieldComment!}"></ma-address>
|
||||||
|
<#elseif field.formType == 'date'>
|
||||||
|
<el-date-picker type="date" placeholder="${field.fieldComment!}" v-model="${model}.${field.attrName}"></el-date-picker>
|
||||||
|
<#elseif field.formType == 'datetime'>
|
||||||
|
<el-date-picker type="datetime" placeholder="${field.fieldComment!}" v-model="${model}.${field.attrName}"></el-date-picker>
|
||||||
|
<#elseif field.formType == 'treeselect'>
|
||||||
|
<el-tree-select v-model="${model}.${field.attrName}" placeholder="${field.fieldComment!}"></el-tree-select>
|
||||||
|
<#elseif field.formType == 'user'>
|
||||||
|
<ma-user-input v-model="${model}.${field.attrName}" placeholder="${field.fieldComment!}"></ma-user-input>
|
||||||
|
<#elseif field.formType == 'org'>
|
||||||
|
<ma-org-select v-model="${model}.${field.attrName}" placeholder="${field.fieldComment!}"></ma-org-select>
|
||||||
|
<#elseif field.formType == 'post'>
|
||||||
|
<ma-post-input v-model="${model}.${field.attrName}" placeholder="${field.fieldComment!}"></ma-post-input>
|
||||||
|
<#else>
|
||||||
|
<el-input v-model="${model}.${field.attrName}" placeholder="${field.fieldComment!}"></el-input>
|
||||||
|
</#if>
|
||||||
|
</el-form-item>
|
||||||
|
</#macro>
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
<#import "/vue/form-item.vue.ftl" as formItem>
|
||||||
|
|
||||||
|
<#macro maForm>
|
||||||
|
<el-form ref="dataFormRef" :model="dataForm" :rules="dataRules" :label-width="100">
|
||||||
|
<#list formList as field>
|
||||||
|
<#if (formLayout > 1)>
|
||||||
|
<#if field_index % 2 == 0>
|
||||||
|
<el-row>
|
||||||
|
</#if>
|
||||||
|
<el-col :span="12">
|
||||||
|
<@formItem.maFormItem model='dataForm' field=field></@formItem.maFormItem>
|
||||||
|
</el-col><#nt>
|
||||||
|
<#if field_index % 2 != 0 || formList?size == field_index + 1>
|
||||||
|
</el-row>
|
||||||
|
</#if>
|
||||||
|
<#else>
|
||||||
|
<@formItem.maFormItem model='dataForm' field=field ></@formItem.maFormItem>
|
||||||
|
</#if>
|
||||||
|
</#list>
|
||||||
|
<#nested>
|
||||||
|
</el-form>
|
||||||
|
</#macro>
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
<template>
|
<template>
|
||||||
|
<#if tableOperation?seq_contains('query')>
|
||||||
<el-card class="layout-query">
|
<el-card class="layout-query">
|
||||||
<el-form ref="queryRef" :inline="true" :model="state.queryForm" @keyup.enter="getDataList()">
|
<el-form ref="queryRef" :inline="true" :model="state.queryForm" @keyup.enter="getDataList()">
|
||||||
<#list queryList as field>
|
<#list queryList as field>
|
||||||
<el-form-item prop="${field.attrName}">
|
<el-form-item prop="${field.attrName}">
|
||||||
<#if field.formType == 'text' || field.formType == 'textarea' || field.formType == 'editor'>
|
<#if field.queryFormType == 'text' || field.queryFormType == 'textarea' || field.queryFormType == 'editor'>
|
||||||
<el-input v-model="state.queryForm.${field.attrName}" placeholder="${field.fieldComment!}"></el-input>
|
<el-input v-model="state.queryForm.${field.attrName}" placeholder="${field.fieldComment!}"></el-input>
|
||||||
<#elseif field.queryFormType == 'select'>
|
<#elseif field.queryFormType == 'select'>
|
||||||
<#if field.queryDict??>
|
<#if field.queryDict??>
|
||||||
|
|
@ -46,17 +47,36 @@
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
</el-card>
|
</el-card>
|
||||||
|
</#if>
|
||||||
|
|
||||||
<el-card>
|
<el-card>
|
||||||
|
<#if tableOperation?seq_contains('insert') || tableOperation?seq_contains('import') || tableOperation?seq_contains('export') || tableOperation?seq_contains('delete')>
|
||||||
<el-space>
|
<el-space>
|
||||||
|
<#if tableOperation?seq_contains('insert')>
|
||||||
<el-space>
|
<el-space>
|
||||||
<el-button v-auth="'${moduleName}:${functionName}:save'" icon="Plus" type="primary" @click="addOrUpdateHandle()">新增</el-button>
|
<el-button <#if authLevel==1>v-auth="'${authority}:save'" </#if>icon="Plus" type="primary" @click="addOrUpdateHandle()">新增</el-button>
|
||||||
</el-space>
|
</el-space>
|
||||||
|
</#if>
|
||||||
|
<#if tableOperation?seq_contains('import')>
|
||||||
|
<el-space <#if authLevel==1>v-auth="'${authority}:import'"</#if>>
|
||||||
|
<ma-upload-file action="${requestUrl}/import">
|
||||||
|
<el-button plain icon="Upload">导入</el-button>
|
||||||
|
</ma-upload-file>
|
||||||
|
</el-space>
|
||||||
|
</#if>
|
||||||
|
<#if tableOperation?seq_contains('export')>
|
||||||
<el-space>
|
<el-space>
|
||||||
<el-button v-auth="'${moduleName}:${functionName}:delete'" icon="Delete" plain type="danger" @click="deleteBatchHandle()">批量删除</el-button>
|
<el-button <#if authLevel==1>v-auth="'${authority}:export'" </#if>plain icon="Download" @click="downloadHandle('${requestUrl}/export')">导出</el-button>
|
||||||
</el-space>
|
</el-space>
|
||||||
|
</#if>
|
||||||
|
<#if tableOperation?seq_contains('delete')>
|
||||||
|
<el-space>
|
||||||
|
<el-button <#if authLevel==1>v-auth="'${authority}:delete'" </#if>icon="Delete" plain type="danger" @click="deleteBatchHandle()">批量删除</el-button>
|
||||||
|
</el-space>
|
||||||
|
</#if>
|
||||||
</el-space>
|
</el-space>
|
||||||
<el-table v-loading="state.dataListLoading" :data="state.dataList" border class="layout-table" @selection-change="selectionChangeHandle">
|
</#if>
|
||||||
|
<el-table v-loading="state.dataListLoading" :data="state.dataList" border class="layout-table" show-overflow-tooltip @selection-change="selectionChangeHandle" <#if hasTree>row-key="id" lazy :load="load" :tree-props="{ hasChildren: 'hasChild' }"</#if>>
|
||||||
<el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
|
<el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
|
||||||
<#list gridList as field>
|
<#list gridList as field>
|
||||||
<#if field.formDict??>
|
<#if field.formDict??>
|
||||||
|
|
@ -65,12 +85,18 @@
|
||||||
<el-table-column prop="${field.attrName}" label="${field.fieldComment!}" header-align="center" align="center"></el-table-column>
|
<el-table-column prop="${field.attrName}" label="${field.fieldComment!}" header-align="center" align="center"></el-table-column>
|
||||||
</#if>
|
</#if>
|
||||||
</#list>
|
</#list>
|
||||||
|
<#if tableOperation?seq_contains('update') || tableOperation?seq_contains('delete')>
|
||||||
<el-table-column label="操作" fixed="right" header-align="center" align="center" width="150">
|
<el-table-column label="操作" fixed="right" header-align="center" align="center" width="150">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-button v-auth="'${moduleName}:${functionName}:update'" type="primary" link @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
|
<#if tableOperation?seq_contains('update')>
|
||||||
<el-button v-auth="'${moduleName}:${functionName}:delete'" type="primary" link @click="deleteBatchHandle(scope.row.id)">删除</el-button>
|
<el-button <#if authLevel==1>v-auth="'${authority}:update'" </#if>type="primary" link @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
|
||||||
|
</#if>
|
||||||
|
<#if tableOperation?seq_contains('delete')>
|
||||||
|
<el-button <#if authLevel==1>v-auth="'${authority}:delete'" </#if>type="primary" link @click="deleteBatchHandle(scope.row.id)">删除</el-button>
|
||||||
|
</#if>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
</#if>
|
||||||
</el-table>
|
</el-table>
|
||||||
<el-pagination
|
<el-pagination
|
||||||
:current-page="state.page"
|
:current-page="state.page"
|
||||||
|
|
@ -83,20 +109,27 @@
|
||||||
>
|
>
|
||||||
</el-pagination>
|
</el-pagination>
|
||||||
|
|
||||||
|
<#if tableOperation?seq_contains('insert') || tableOperation?seq_contains('update')>
|
||||||
<!-- 弹窗, 新增 / 修改 -->
|
<!-- 弹窗, 新增 / 修改 -->
|
||||||
<add-or-update ref="addOrUpdateRef" @refreshDataList="getDataList"></add-or-update>
|
<add-or-update v-if="addOrUpdateVisible" ref="addOrUpdateRef" v-model:visible="addOrUpdateVisible" @refreshDataList="getDataList"></add-or-update>
|
||||||
|
</#if>
|
||||||
</el-card>
|
</el-card>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts" name="${ModuleName}${FunctionName}Index">
|
<script setup lang="ts" name="${ModuleName}${FunctionName}Index">
|
||||||
import {useCrud} from '@/hooks'
|
import {useCrud} from '@/hooks'
|
||||||
import {reactive, ref} from 'vue'
|
import {reactive, nextTick, ref} from 'vue'
|
||||||
import {IHooksOptions} from '@/hooks/interface'
|
import {IHooksOptions} from '@/hooks/interface'
|
||||||
|
<#if tableOperation?seq_contains('insert') || tableOperation?seq_contains('update')>
|
||||||
import AddOrUpdate from './add-or-update.vue'
|
import AddOrUpdate from './add-or-update.vue'
|
||||||
|
</#if>
|
||||||
|
<#if hasTree>import { use${FunctionName}TreeLoadApi } from '@/api/${moduleName}/${functionName}'</#if>
|
||||||
|
|
||||||
const state: IHooksOptions = reactive({
|
const state: IHooksOptions = reactive({
|
||||||
dataListUrl: '/${moduleName}/${functionName}/page',
|
dataListUrl: '${requestUrl}/page',
|
||||||
deleteUrl: '/${moduleName}/${functionName}',
|
<#if tableOperation?seq_contains('query')>
|
||||||
|
deleteUrl: '${requestUrl}',
|
||||||
|
</#if>
|
||||||
queryForm: {
|
queryForm: {
|
||||||
<#list queryList as field>
|
<#list queryList as field>
|
||||||
<#if field.formType == 'date'>
|
<#if field.formType == 'date'>
|
||||||
|
|
@ -113,10 +146,23 @@
|
||||||
})
|
})
|
||||||
|
|
||||||
const queryRef = ref()
|
const queryRef = ref()
|
||||||
|
<#if tableOperation?seq_contains('insert') || tableOperation?seq_contains('update')>
|
||||||
|
const addOrUpdateVisible = ref(false)
|
||||||
const addOrUpdateRef = ref()
|
const addOrUpdateRef = ref()
|
||||||
const addOrUpdateHandle = (id?: number) => {
|
const addOrUpdateHandle = (id?: number) => {
|
||||||
addOrUpdateRef.value.init(id)
|
addOrUpdateVisible.value = true
|
||||||
|
nextTick(() => addOrUpdateRef.value.init(id))
|
||||||
}
|
}
|
||||||
|
</#if>
|
||||||
|
|
||||||
const { getDataList, selectionChangeHandle, sizeChangeHandle, currentChangeHandle, deleteBatchHandle, reset } = useCrud(state)
|
<#if hasTree>
|
||||||
|
// 树数据加载
|
||||||
|
const load = (tree: any, treeNode: unknown, resolve: (data: any[]) => void) => {
|
||||||
|
use${FunctionName}TreeLoadApi(tree.${treeId}).then((res: any) => {
|
||||||
|
resolve(res.data)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
const { getDataList, selectionChangeHandle, sizeChangeHandle, currentChangeHandle, deleteBatchHandle, downloadHandle, reset } = useCrud(state)
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,183 @@
|
||||||
|
<#import "/vue/form.vue.ftl" as form>
|
||||||
|
<template>
|
||||||
|
<#if mainRelation == 1>
|
||||||
|
<@form.maForm></@form.maForm>
|
||||||
|
</#if>
|
||||||
|
<#if mainRelation == 2>
|
||||||
|
<el-button type="primary" plain icon="Plus" @click="openDialog">新增</el-button>
|
||||||
|
<el-button type="danger" plain icon="Delete" @click="removeBatchEvent">删除</el-button>
|
||||||
|
<vxe-table ref="xTable" max-height="500" style="margin-top: 10px" :data="value">
|
||||||
|
<vxe-column type="checkbox" width="60"></vxe-column>
|
||||||
|
<#list formList as field>
|
||||||
|
<vxe-column field="${field.attrName}" title="${field.fieldComment!}"></vxe-column>
|
||||||
|
</#list>
|
||||||
|
<vxe-column title="操作" width="100" show-overflow>
|
||||||
|
<template #default="{ row }">
|
||||||
|
<vxe-button type="text" icon="vxe-icon-edit" @click="editEvent(row)"></vxe-button>
|
||||||
|
<vxe-button type="text" icon="vxe-icon-delete" @click="removeEvent(row)"></vxe-button>
|
||||||
|
</template>
|
||||||
|
</vxe-column>
|
||||||
|
</vxe-table>
|
||||||
|
<el-dialog v-model="visible" :title="!selectRow ? '新增' : '修改'" draggable @close="closeDialog">
|
||||||
|
<@form.maForm></@form.maForm>
|
||||||
|
<template #footer>
|
||||||
|
<el-button @click="closeDialog">取消</el-button>
|
||||||
|
<el-button type="primary" @click="submitEvent">确定</el-button>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</#if>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
<#if mainRelation == 1>
|
||||||
|
import { computed, PropType, ref } from 'vue'
|
||||||
|
<#else>
|
||||||
|
import { nextTick, reactive, ref } from 'vue'
|
||||||
|
import VXETable from 'vxe-table'
|
||||||
|
</#if>
|
||||||
|
import { ElMessage } from 'element-plus/es'
|
||||||
|
|
||||||
|
<#if mainRelation == 1>
|
||||||
|
const props = defineProps({
|
||||||
|
value: {
|
||||||
|
type: Object as PropType<any>,
|
||||||
|
default: () => ({})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const dataFormRef = ref()
|
||||||
|
const dataForm = computed(() => props.value)
|
||||||
|
|
||||||
|
const dataRules = ref({
|
||||||
|
<#list formList as field>
|
||||||
|
<#if field.formRequired>
|
||||||
|
${field.attrName}: [{ required: true, message: '必填项不能为空', trigger: 'blur' }]<#sep>,
|
||||||
|
</#if>
|
||||||
|
</#list>
|
||||||
|
})
|
||||||
|
|
||||||
|
const getData = async () => {
|
||||||
|
return await new Promise((resolve, reject) => {
|
||||||
|
dataFormRef.value
|
||||||
|
.validate()
|
||||||
|
.then((validate: boolean) => {
|
||||||
|
if (validate) {
|
||||||
|
resolve(dataForm)
|
||||||
|
} else {
|
||||||
|
ElMessage.error("表单效验失败")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error: Error) => {
|
||||||
|
reject(error)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
getData
|
||||||
|
})
|
||||||
|
<#else>
|
||||||
|
const props = defineProps({
|
||||||
|
value: {
|
||||||
|
type: Array,
|
||||||
|
default: () => []
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const dataFormRef = ref()
|
||||||
|
const visible = ref(false)
|
||||||
|
const xTable = ref()
|
||||||
|
const selectRow = ref()
|
||||||
|
|
||||||
|
const dataForm = reactive({
|
||||||
|
<#list fieldList as field>
|
||||||
|
${field.attrName}: ''<#sep>,
|
||||||
|
</#list>
|
||||||
|
})
|
||||||
|
|
||||||
|
const dataRules = ref({
|
||||||
|
<#list formList as field>
|
||||||
|
<#if field.formRequired>
|
||||||
|
${field.attrName}: [{ required: true, message: '必填项不能为空', trigger: 'blur' }]<#sep>,
|
||||||
|
</#if>
|
||||||
|
</#list>
|
||||||
|
})
|
||||||
|
|
||||||
|
const openDialog = () => {
|
||||||
|
dataForm.id = ''
|
||||||
|
visible.value = true
|
||||||
|
selectRow.value = null
|
||||||
|
|
||||||
|
dataFormRef.value?.resetFields()
|
||||||
|
}
|
||||||
|
|
||||||
|
const closeDialog = () => {
|
||||||
|
visible.value = false
|
||||||
|
dataFormRef.value?.resetFields()
|
||||||
|
}
|
||||||
|
|
||||||
|
const editEvent = (row: any) => {
|
||||||
|
visible.value = true
|
||||||
|
|
||||||
|
dataFormRef.value?.resetFields()
|
||||||
|
|
||||||
|
selectRow.value = row
|
||||||
|
nextTick(() => {
|
||||||
|
Object.assign(dataForm, { ...row })
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const removeEvent = async (row: any) => {
|
||||||
|
const type = await VXETable.modal.confirm("您确定要删除该数据?")
|
||||||
|
if (type === "confirm") {
|
||||||
|
const $table = xTable.value
|
||||||
|
if ($table) {
|
||||||
|
$table.remove(row)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const removeBatchEvent = () => {
|
||||||
|
const selectRecords = xTable.value.getCheckboxRecords()
|
||||||
|
if (selectRecords.length) {
|
||||||
|
xTable.value.removeCheckboxRow()
|
||||||
|
} else {
|
||||||
|
ElMessage.error("请至少选择一条数据")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const submitEvent = () => {
|
||||||
|
dataFormRef.value.validate(async (valid: boolean) => {
|
||||||
|
if (!valid) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectRow.value) {
|
||||||
|
Object.assign(selectRow.value, dataForm)
|
||||||
|
} else {
|
||||||
|
await xTable.value.insertAt({ ...dataForm }, -1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关闭对话框
|
||||||
|
closeDialog()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const getData = async () => {
|
||||||
|
const data = xTable.value.getTableData().tableData
|
||||||
|
|
||||||
|
// 删除自带的属性
|
||||||
|
data.map((e: any) => {
|
||||||
|
delete e._X_ROW_KEY
|
||||||
|
})
|
||||||
|
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
getData
|
||||||
|
})
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
@ -3,10 +3,4 @@
|
||||||
|
|
||||||
<mapper namespace="${package}.${moduleName}.dao.${ClassName}Dao">
|
<mapper namespace="${package}.${moduleName}.dao.${ClassName}Dao">
|
||||||
|
|
||||||
<resultMap type="${package}.${moduleName}.entity.${ClassName}Entity" id="${className}Map">
|
|
||||||
<#list fieldList as field>
|
|
||||||
<result property="${field.attrName}" column="${field.fieldName}"/>
|
|
||||||
</#list>
|
|
||||||
</resultMap>
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
Loading…
Reference in New Issue
Block a user