修补生成代码的bug
This commit is contained in:
parent
8994098662
commit
eb31cb786a
@ -94,6 +94,7 @@ public class BpmTaskCandidateInvoker {
|
|||||||
Set<Long> userIds = null;
|
Set<Long> userIds = null;
|
||||||
Integer strategy = BpmnModelUtils.parseCandidateStrategy(execution.getCurrentFlowElement());
|
Integer strategy = BpmnModelUtils.parseCandidateStrategy(execution.getCurrentFlowElement());
|
||||||
String range = BpmnModelUtils.parseCandidateRange(execution.getCurrentFlowElement());
|
String range = BpmnModelUtils.parseCandidateRange(execution.getCurrentFlowElement());
|
||||||
|
String itemType = BpmnModelUtils.parseItemType(execution.getCurrentFlowElement());
|
||||||
String param = BpmnModelUtils.parseCandidateParam(execution.getCurrentFlowElement());
|
String param = BpmnModelUtils.parseCandidateParam(execution.getCurrentFlowElement());
|
||||||
// 1.1 计算任务的候选人 审批人范围为:本部门或本公司
|
// 1.1 计算任务的候选人 审批人范围为:本部门或本公司
|
||||||
if ((range != null) && (range.equals("1") || range.equals("2")) ){
|
if ((range != null) && (range.equals("1") || range.equals("2")) ){
|
||||||
|
@ -23,6 +23,8 @@ public interface BpmnModelConstants {
|
|||||||
* BPMN UserTask 的扩展属性,用于标审批人范围
|
* BPMN UserTask 的扩展属性,用于标审批人范围
|
||||||
*/
|
*/
|
||||||
String USER_TASK_CANDIDATE_RANGE = "candidateRange";
|
String USER_TASK_CANDIDATE_RANGE = "candidateRange";
|
||||||
|
|
||||||
|
String USER_TASK_ITEM_TYPE = "itemType";
|
||||||
/**
|
/**
|
||||||
* BPMN UserTask 的扩展属性,用于标记候选人参数
|
* BPMN UserTask 的扩展属性,用于标记候选人参数
|
||||||
*/
|
*/
|
||||||
|
@ -30,6 +30,11 @@ public class BpmnModelUtils {
|
|||||||
return userTask.getAttributeValue(
|
return userTask.getAttributeValue(
|
||||||
BpmnModelConstants.NAMESPACE, BpmnModelConstants.USER_TASK_CANDIDATE_RANGE);
|
BpmnModelConstants.NAMESPACE, BpmnModelConstants.USER_TASK_CANDIDATE_RANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String parseItemType(FlowElement userTask) {
|
||||||
|
return userTask.getAttributeValue(
|
||||||
|
BpmnModelConstants.NAMESPACE, BpmnModelConstants.USER_TASK_ITEM_TYPE);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 根据节点,获取入口连线
|
* 根据节点,获取入口连线
|
||||||
*
|
*
|
||||||
|
@ -0,0 +1,234 @@
|
|||||||
|
package ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName};
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import ${jakartaPackage}.annotation.Resource;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
#if ($sceneEnum.scene == 1)import org.springframework.security.access.prepost.PreAuthorize;#end
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
|
||||||
|
import ${jakartaPackage}.validation.constraints.*;
|
||||||
|
import ${jakartaPackage}.validation.*;
|
||||||
|
import ${jakartaPackage}.servlet.http.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import ${PageParamClassName};
|
||||||
|
import ${PageResultClassName};
|
||||||
|
import ${CommonResultClassName};
|
||||||
|
import ${BeanUtils};
|
||||||
|
import static ${CommonResultClassName}.success;
|
||||||
|
|
||||||
|
import ${ExcelUtilsClassName};
|
||||||
|
|
||||||
|
import ${ApiAccessLogClassName};
|
||||||
|
import static ${OperateTypeEnumClassName}.*;
|
||||||
|
|
||||||
|
import ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo.*;
|
||||||
|
import ${basePackage}.module.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO;
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
import ${basePackage}.module.${subTable.moduleName}.dal.dataobject.${subTable.businessName}.${subTable.className}DO;
|
||||||
|
#end
|
||||||
|
import ${basePackage}.module.${table.moduleName}.service.${table.businessName}.${table.className}Service;
|
||||||
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||||
|
|
||||||
|
@Tag(name = "${sceneEnum.name} - ${table.classComment}")
|
||||||
|
@RestController
|
||||||
|
##二级的 businessName 暂时不算在 HTTP 路径上,可以根据需要写
|
||||||
|
@RequestMapping("/${table.moduleName}/${simpleClassName_strikeCase}")
|
||||||
|
@Validated
|
||||||
|
public class ${sceneEnum.prefixClass}${table.className}Controller {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ${table.className}Service ${classNameVar}Service;
|
||||||
|
|
||||||
|
@PostMapping("/create")
|
||||||
|
@Operation(summary = "创建${table.classComment}")
|
||||||
|
#if ($sceneEnum.scene == 1)
|
||||||
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:create')")
|
||||||
|
#end
|
||||||
|
public CommonResult<${primaryColumn.javaType}> create${simpleClassName}(@Valid @RequestBody ${sceneEnum.prefixClass}${table.className}SaveReqVO createReqVO) {
|
||||||
|
return success(${classNameVar}Service.create${simpleClassName}(getLoginUserId(),createReqVO));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/update")
|
||||||
|
@Operation(summary = "更新${table.classComment}")
|
||||||
|
#if ($sceneEnum.scene == 1)
|
||||||
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:update')")
|
||||||
|
#end
|
||||||
|
public CommonResult<Boolean> update${simpleClassName}(@Valid @RequestBody ${sceneEnum.prefixClass}${table.className}SaveReqVO updateReqVO) {
|
||||||
|
${classNameVar}Service.update${simpleClassName}(updateReqVO);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/delete")
|
||||||
|
@Operation(summary = "删除${table.classComment}")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true)
|
||||||
|
#if ($sceneEnum.scene == 1)
|
||||||
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')")
|
||||||
|
#end
|
||||||
|
public CommonResult<Boolean> delete${simpleClassName}(@RequestParam("id") ${primaryColumn.javaType} id) {
|
||||||
|
${classNameVar}Service.delete${simpleClassName}(id);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get")
|
||||||
|
@Operation(summary = "获得${table.classComment}")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||||
|
#if ($sceneEnum.scene == 1)
|
||||||
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
|
||||||
|
#end
|
||||||
|
public CommonResult<${sceneEnum.prefixClass}${table.className}RespVO> get${simpleClassName}(@RequestParam("id") ${primaryColumn.javaType} id) {
|
||||||
|
${table.className}DO ${classNameVar} = ${classNameVar}Service.get${simpleClassName}(id);
|
||||||
|
return success(BeanUtils.toBean(${classNameVar}, ${sceneEnum.prefixClass}${table.className}RespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
#if ( $table.templateType != 2 )
|
||||||
|
@GetMapping("/page")
|
||||||
|
@Operation(summary = "获得${table.classComment}分页")
|
||||||
|
#if ($sceneEnum.scene == 1)
|
||||||
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
|
||||||
|
#end
|
||||||
|
public CommonResult<PageResult<${sceneEnum.prefixClass}${table.className}RespVO>> get${simpleClassName}Page(@Valid ${sceneEnum.prefixClass}${table.className}PageReqVO pageReqVO) {
|
||||||
|
PageResult<${table.className}DO> pageResult = ${classNameVar}Service.get${simpleClassName}Page(pageReqVO);
|
||||||
|
return success(BeanUtils.toBean(pageResult, ${sceneEnum.prefixClass}${table.className}RespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||||
|
#else
|
||||||
|
@GetMapping("/list")
|
||||||
|
@Operation(summary = "获得${table.classComment}列表")
|
||||||
|
#if ($sceneEnum.scene == 1)
|
||||||
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
|
||||||
|
#end
|
||||||
|
public CommonResult<List<${sceneEnum.prefixClass}${table.className}RespVO>> get${simpleClassName}List(@Valid ${sceneEnum.prefixClass}${table.className}ListReqVO listReqVO) {
|
||||||
|
List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}List(listReqVO);
|
||||||
|
return success(BeanUtils.toBean(list, ${sceneEnum.prefixClass}${table.className}RespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
#end
|
||||||
|
@GetMapping("/export-excel")
|
||||||
|
@Operation(summary = "导出${table.classComment} Excel")
|
||||||
|
#if ($sceneEnum.scene == 1)
|
||||||
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:export')")
|
||||||
|
#end
|
||||||
|
@ApiAccessLog(operateType = EXPORT)
|
||||||
|
#if ( $table.templateType != 2 )
|
||||||
|
public void export${simpleClassName}Excel(@Valid ${sceneEnum.prefixClass}${table.className}PageReqVO pageReqVO,
|
||||||
|
HttpServletResponse response) throws IOException {
|
||||||
|
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||||
|
List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}Page(pageReqVO).getList();
|
||||||
|
// 导出 Excel
|
||||||
|
ExcelUtils.write(response, "${table.classComment}.xls", "数据", ${sceneEnum.prefixClass}${table.className}RespVO.class,
|
||||||
|
BeanUtils.toBean(list, ${sceneEnum.prefixClass}${table.className}RespVO.class));
|
||||||
|
}
|
||||||
|
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||||
|
#else
|
||||||
|
public void export${simpleClassName}Excel(@Valid ${sceneEnum.prefixClass}${table.className}ListReqVO listReqVO,
|
||||||
|
HttpServletResponse response) throws IOException {
|
||||||
|
List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}List(listReqVO);
|
||||||
|
// 导出 Excel
|
||||||
|
ExcelUtils.write(response, "${table.classComment}.xls", "数据", ${table.className}RespVO.class,
|
||||||
|
BeanUtils.toBean(list, ${table.className}RespVO.class));
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
#set ($subPrimaryColumn = $subPrimaryColumns.get($index))##当前 primary 字段
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
|
||||||
|
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||||
|
#set ($subSimpleClassName_strikeCase = $subSimpleClassName_strikeCases.get($index))
|
||||||
|
#set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||||
|
// ==================== 子表($subTable.classComment) ====================
|
||||||
|
|
||||||
|
## 情况一:MASTER_ERP 时,需要分查询页子表
|
||||||
|
#if ( $table.templateType == 11 )
|
||||||
|
@GetMapping("/${subSimpleClassName_strikeCase}/page")
|
||||||
|
@Operation(summary = "获得${subTable.classComment}分页")
|
||||||
|
@Parameter(name = "${subJoinColumn.javaField}", description = "${subJoinColumn.columnComment}")
|
||||||
|
#if ($sceneEnum.scene == 1)
|
||||||
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
|
||||||
|
#end
|
||||||
|
public CommonResult<PageResult<${subTable.className}DO>> get${subSimpleClassName}Page(PageParam pageReqVO,
|
||||||
|
@RequestParam("${subJoinColumn.javaField}") ${subJoinColumn.javaType} ${subJoinColumn.javaField}) {
|
||||||
|
return success(${classNameVar}Service.get${subSimpleClassName}Page(pageReqVO, ${subJoinColumn.javaField}));
|
||||||
|
}
|
||||||
|
|
||||||
|
## 情况二:非 MASTER_ERP 时,需要列表查询子表
|
||||||
|
#else
|
||||||
|
#if ( $subTable.subJoinMany )
|
||||||
|
@GetMapping("/${subSimpleClassName_strikeCase}/list-by-${subJoinColumn_strikeCase}")
|
||||||
|
@Operation(summary = "获得${subTable.classComment}列表")
|
||||||
|
@Parameter(name = "${subJoinColumn.javaField}", description = "${subJoinColumn.columnComment}")
|
||||||
|
#if ($sceneEnum.scene == 1)
|
||||||
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
|
||||||
|
#end
|
||||||
|
public CommonResult<List<${subTable.className}DO>> get${subSimpleClassName}ListBy${SubJoinColumnName}(@RequestParam("${subJoinColumn.javaField}") ${subJoinColumn.javaType} ${subJoinColumn.javaField}) {
|
||||||
|
return success(${classNameVar}Service.get${subSimpleClassName}ListBy${SubJoinColumnName}(${subJoinColumn.javaField}));
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@GetMapping("/${subSimpleClassName_strikeCase}/get-by-${subJoinColumn_strikeCase}")
|
||||||
|
@Operation(summary = "获得${subTable.classComment}")
|
||||||
|
@Parameter(name = "${subJoinColumn.javaField}", description = "${subJoinColumn.columnComment}")
|
||||||
|
#if ($sceneEnum.scene == 1)
|
||||||
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
|
||||||
|
#end
|
||||||
|
public CommonResult<${subTable.className}DO> get${subSimpleClassName}By${SubJoinColumnName}(@RequestParam("${subJoinColumn.javaField}") ${subJoinColumn.javaType} ${subJoinColumn.javaField}) {
|
||||||
|
return success(${classNameVar}Service.get${subSimpleClassName}By${SubJoinColumnName}(${subJoinColumn.javaField}));
|
||||||
|
}
|
||||||
|
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
## 特殊:MASTER_ERP 时,支持单个的新增、修改、删除操作
|
||||||
|
#if ( $table.templateType == 11 )
|
||||||
|
@PostMapping("/${subSimpleClassName_strikeCase}/create")
|
||||||
|
@Operation(summary = "创建${subTable.classComment}")
|
||||||
|
#if ($sceneEnum.scene == 1)
|
||||||
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:create')")
|
||||||
|
#end
|
||||||
|
public CommonResult<${subPrimaryColumn.javaType}> create${subSimpleClassName}(@Valid @RequestBody ${subTable.className}DO ${subClassNameVar}) {
|
||||||
|
return success(${classNameVar}Service.create${subSimpleClassName}(${subClassNameVar}));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/${subSimpleClassName_strikeCase}/update")
|
||||||
|
@Operation(summary = "更新${subTable.classComment}")
|
||||||
|
#if ($sceneEnum.scene == 1)
|
||||||
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:update')")
|
||||||
|
#end
|
||||||
|
public CommonResult<Boolean> update${subSimpleClassName}(@Valid @RequestBody ${subTable.className}DO ${subClassNameVar}) {
|
||||||
|
${classNameVar}Service.update${subSimpleClassName}(${subClassNameVar});
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/${subSimpleClassName_strikeCase}/delete")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true)
|
||||||
|
@Operation(summary = "删除${subTable.classComment}")
|
||||||
|
#if ($sceneEnum.scene == 1)
|
||||||
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')")
|
||||||
|
#end
|
||||||
|
public CommonResult<Boolean> delete${subSimpleClassName}(@RequestParam("id") ${subPrimaryColumn.javaType} id) {
|
||||||
|
${classNameVar}Service.delete${subSimpleClassName}(id);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/${subSimpleClassName_strikeCase}/get")
|
||||||
|
@Operation(summary = "获得${subTable.classComment}")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true)
|
||||||
|
#if ($sceneEnum.scene == 1)
|
||||||
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
|
||||||
|
#end
|
||||||
|
public CommonResult<${subTable.className}DO> get${subSimpleClassName}(@RequestParam("id") ${subPrimaryColumn.javaType} id) {
|
||||||
|
return success(${classNameVar}Service.get${subSimpleClassName}(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import ${PageParamClassName};
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (${column.javaType} == "BigDecimal")
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
#break
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
## 处理 LocalDateTime 字段的引入
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (${column.listOperationCondition} && ${column.javaType} == "LocalDateTime")
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import static ${DateUtilsClassName}.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||||
|
#break
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
## 字段模板
|
||||||
|
#macro(columnTpl $prefix $prefixStr)
|
||||||
|
@Schema(description = "${prefixStr}${column.columnComment}"#if ("$!column.example" != ""), example = "${column.example}"#end)
|
||||||
|
private ${column.javaType}#if ("$!prefix" != "") ${prefix}${JavaField}#else ${column.javaField}#end;
|
||||||
|
#end
|
||||||
|
|
||||||
|
@Schema(description = "${sceneEnum.name} - ${table.classComment}分页 Request VO")
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
public class ${sceneEnum.prefixClass}${table.className}PageReqVO extends PageParam {
|
||||||
|
//1.去掉 userId、processInstanceId、deptId的字段定义
|
||||||
|
//2.检查必要定义字段title、userName、deptName、status,六个字段定义
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (${column.listOperation})##查询操作
|
||||||
|
#if (${column.listOperationCondition} == "BETWEEN")## 情况一,Between 的时候
|
||||||
|
@Schema(description = "${column.columnComment}"#if ("$!column.example" != ""), example = "${column.example}"#end)
|
||||||
|
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||||
|
private ${column.javaType}[] ${column.javaField};
|
||||||
|
#else##情况二,非 Between 的时间
|
||||||
|
#columnTpl('', '')
|
||||||
|
#end
|
||||||
|
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
package ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
## 处理 BigDecimal 字段的引入
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (${column.javaType} == "BigDecimal")
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
#break
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
## 处理 LocalDateTime 字段的引入
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (${column.listOperationResult} && ${column.javaType} == "LocalDateTime")
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
#break
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
## 处理 Excel 导出
|
||||||
|
import com.alibaba.excel.annotation.*;
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if ("$!column.dictType" != "")## 有设置数据字典
|
||||||
|
import ${DictFormatClassName};
|
||||||
|
import ${DictConvertClassName};
|
||||||
|
#break
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
|
||||||
|
@Schema(description = "${sceneEnum.name} - ${table.classComment} Response VO")
|
||||||
|
@Data
|
||||||
|
@ExcelIgnoreUnannotated
|
||||||
|
public class ${sceneEnum.prefixClass}${table.className}RespVO {
|
||||||
|
//1.去掉 userId的字段定义
|
||||||
|
//2.检查必要定义字段title、userName、deptId、deptName、processInstanceId、status,六个字段定义
|
||||||
|
## 逐个处理字段
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (${column.listOperationResult})
|
||||||
|
## 1. 处理 Swagger 注解
|
||||||
|
@Schema(description = "${column.columnComment}"#if (!${column.nullable}), requiredMode = Schema.RequiredMode.REQUIRED#end#if ("$!column.example" != ""), example = "${column.example}"#end)
|
||||||
|
## 2. 处理 Excel 导出
|
||||||
|
#if ("$!column.dictType" != "")##处理枚举值
|
||||||
|
@ExcelProperty(value = "${column.columnComment}", converter = DictConvert.class)
|
||||||
|
@DictFormat("${column.dictType}") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
|
||||||
|
#else
|
||||||
|
@ExcelProperty("${column.columnComment}")
|
||||||
|
#end
|
||||||
|
## 3. 处理字段定义
|
||||||
|
private ${column.javaType} ${column.javaField};
|
||||||
|
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
@ -0,0 +1,74 @@
|
|||||||
|
package ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import ${jakartaPackage}.validation.constraints.*;
|
||||||
|
## 处理 BigDecimal 字段的引入
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (${column.javaType} == "BigDecimal")
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
#break
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
## 处理 LocalDateTime 字段的引入
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if ((${column.createOperation} || ${column.updateOperation}) && ${column.javaType} == "LocalDateTime")
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
#break
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
import ${basePackage}.module.${subTable.moduleName}.dal.dataobject.${subTable.businessName}.${subTable.className}DO;
|
||||||
|
#end
|
||||||
|
|
||||||
|
@Schema(description = "${sceneEnum.name} - ${table.classComment}新增/修改 Request VO")
|
||||||
|
@Data
|
||||||
|
public class ${sceneEnum.prefixClass}${table.className}SaveReqVO {
|
||||||
|
|
||||||
|
//1.去掉 userId的字段定义
|
||||||
|
//2.检查必要定义字段title、userName、deptId、deptName、processInstanceId、status,六个字段定义
|
||||||
|
## 逐个处理字段
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (${column.createOperation} || ${column.updateOperation})
|
||||||
|
## 1. 处理 Swagger 注解
|
||||||
|
@Schema(description = "${column.columnComment}"#if (!${column.nullable}), requiredMode = Schema.RequiredMode.REQUIRED#end#if ("$!column.example" != ""), example = "${column.example}"#end)
|
||||||
|
## 2. 处理 Validator 参数校验
|
||||||
|
#if (!${column.nullable} && !${column.primaryKey})
|
||||||
|
#if (${column.javaType} == 'String')
|
||||||
|
@NotEmpty(message = "${column.columnComment}不能为空")
|
||||||
|
#else
|
||||||
|
@NotNull(message = "${column.columnComment}不能为空")
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
## 3. 处理字段定义
|
||||||
|
private ${column.javaType} ${column.javaField};
|
||||||
|
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
## 特殊:主子表专属逻辑(非 ERP 模式)
|
||||||
|
#if ( $subTables && $subTables.size() > 0 && $table.templateType != 11 )
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#if ( $subTable.subJoinMany)
|
||||||
|
@Schema(description = "${subTable.classComment}列表")
|
||||||
|
private List<${subTable.className}DO> ${subClassNameVars.get($index)}s;
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Schema(description = "${subTable.classComment}")
|
||||||
|
private ${subTable.className}DO ${subClassNameVars.get($index)};
|
||||||
|
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
@Schema(description = "发起人自选审批人 Map", example = "{taskKey1: [1, 2]}")
|
||||||
|
private Map<String, List<Long>> startUserSelectAssignees;
|
||||||
|
|
||||||
|
@Schema(description = "流程定义key")
|
||||||
|
private String processDefinitionKey;
|
||||||
|
|
||||||
|
@Schema(description = "当前创建路径")
|
||||||
|
private String curfullpath;
|
||||||
|
}
|
@ -0,0 +1,89 @@
|
|||||||
|
package ${basePackage}.module.${table.moduleName}.dal.mysql.${table.businessName};
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import ${PageResultClassName};
|
||||||
|
import ${QueryWrapperClassName};
|
||||||
|
import ${BaseMapperClassName};
|
||||||
|
import ${basePackage}.module.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo.*;
|
||||||
|
|
||||||
|
## 字段模板
|
||||||
|
#macro(listCondition)
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (${column.listOperation})
|
||||||
|
#set ($JavaField = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})##首字母大写
|
||||||
|
#if (${column.listOperationCondition} == "=")##情况一,= 的时候
|
||||||
|
.eqIfPresent(${table.className}DO::get${JavaField}, reqVO.get${JavaField}())
|
||||||
|
#end
|
||||||
|
#if (${column.listOperationCondition} == "!=")##情况二,!= 的时候
|
||||||
|
.neIfPresent(${table.className}DO::get${JavaField}, reqVO.get${JavaField}())
|
||||||
|
#end
|
||||||
|
#if (${column.listOperationCondition} == ">")##情况三,> 的时候
|
||||||
|
.gtIfPresent(${table.className}DO::get${JavaField}, reqVO.get${JavaField}())
|
||||||
|
#end
|
||||||
|
#if (${column.listOperationCondition} == ">=")##情况四,>= 的时候
|
||||||
|
.geIfPresent(${table.className}DO::get${JavaField}, reqVO.get${JavaField}())
|
||||||
|
#end
|
||||||
|
#if (${column.listOperationCondition} == "<")##情况五,< 的时候
|
||||||
|
.ltIfPresent(${table.className}DO::get${JavaField}, reqVO.get${JavaField}())
|
||||||
|
#end
|
||||||
|
#if (${column.listOperationCondition} == "<=")##情况五,<= 的时候
|
||||||
|
.leIfPresent(${table.className}DO::get${JavaField}, reqVO.get${JavaField}())
|
||||||
|
#end
|
||||||
|
#if (${column.listOperationCondition} == "LIKE")##情况七,Like 的时候
|
||||||
|
.likeIfPresent(${table.className}DO::get${JavaField}, reqVO.get${JavaField}())
|
||||||
|
#end
|
||||||
|
#if (${column.listOperationCondition} == "BETWEEN")##情况八,Between 的时候
|
||||||
|
.betweenIfPresent(${table.className}DO::get${JavaField}, reqVO.get${JavaField}())
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
/**
|
||||||
|
* ${table.classComment} Mapper
|
||||||
|
*
|
||||||
|
* @author ${table.author}
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface ${table.className}Mapper extends BaseMapperX<${table.className}DO> {
|
||||||
|
|
||||||
|
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||||
|
#if ( $table.templateType != 2 )
|
||||||
|
default PageResult<${table.className}DO> selectPage(${sceneEnum.prefixClass}${table.className}PageReqVO reqVO) {
|
||||||
|
return selectPage(reqVO, new LambdaQueryWrapperX<${table.className}DO>()
|
||||||
|
#listCondition()
|
||||||
|
.orderByDesc(${table.className}DO::getId));## 大多数情况下,id 倒序
|
||||||
|
|
||||||
|
}
|
||||||
|
//由于传入参数userId,因此替换掉这一行:.eqIfPresent(${table.className}DO::getUserId, userId)
|
||||||
|
default PageResult<${table.className}DO> selectPage(long userId,${sceneEnum.prefixClass}${table.className}PageReqVO reqVO) {
|
||||||
|
return selectPage(reqVO, new LambdaQueryWrapperX<${table.className}DO>()
|
||||||
|
#listCondition()
|
||||||
|
.orderByDesc(${table.className}DO::getId));## 大多数情况下,id 倒序
|
||||||
|
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
default List<${table.className}DO> selectList(${sceneEnum.prefixClass}${table.className}ListReqVO reqVO) {
|
||||||
|
return selectList(new LambdaQueryWrapperX<${table.className}DO>()
|
||||||
|
#listCondition()
|
||||||
|
.orderByDesc(${table.className}DO::getId));## 大多数情况下,id 倒序
|
||||||
|
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
#set ($TreeParentJavaField = $treeParentColumn.javaField.substring(0,1).toUpperCase() + ${treeParentColumn.javaField.substring(1)})##首字母大写
|
||||||
|
#set ($TreeNameJavaField = $treeNameColumn.javaField.substring(0,1).toUpperCase() + ${treeNameColumn.javaField.substring(1)})##首字母大写
|
||||||
|
default ${table.className}DO selectBy${TreeParentJavaField}And${TreeNameJavaField}(Long ${treeParentColumn.javaField}, String ${treeNameColumn.javaField}) {
|
||||||
|
return selectOne(${table.className}DO::get${TreeParentJavaField}, ${treeParentColumn.javaField}, ${table.className}DO::get${TreeNameJavaField}, ${treeNameColumn.javaField});
|
||||||
|
}
|
||||||
|
|
||||||
|
default Long selectCountBy${TreeParentJavaField}(${treeParentColumn.javaType} ${treeParentColumn.javaField}) {
|
||||||
|
return selectCount(${table.className}DO::get${TreeParentJavaField}, ${treeParentColumn.javaField});
|
||||||
|
}
|
||||||
|
|
||||||
|
#end
|
||||||
|
}
|
@ -0,0 +1,151 @@
|
|||||||
|
package ${basePackage}.module.${table.moduleName}.service.${table.businessName};
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import ${jakartaPackage}.validation.*;
|
||||||
|
import ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo.*;
|
||||||
|
import ${basePackage}.module.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO;
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
import ${basePackage}.module.${subTable.moduleName}.dal.dataobject.${subTable.businessName}.${subTable.className}DO;
|
||||||
|
#end
|
||||||
|
import ${PageResultClassName};
|
||||||
|
import ${PageParamClassName};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${table.classComment} Service 接口
|
||||||
|
*
|
||||||
|
* @author ${table.author}
|
||||||
|
*/
|
||||||
|
public interface ${table.className}Service {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建${table.classComment}
|
||||||
|
*
|
||||||
|
* @param createReqVO 创建信息
|
||||||
|
* @return 编号
|
||||||
|
*/
|
||||||
|
${primaryColumn.javaType} create${simpleClassName}(Long userId,@Valid ${sceneEnum.prefixClass}${table.className}SaveReqVO createReqVO);
|
||||||
|
/**
|
||||||
|
* 更新${table.classComment}
|
||||||
|
*
|
||||||
|
* @param updateReqVO 更新信息
|
||||||
|
*/
|
||||||
|
void update${simpleClassName}(@Valid ${sceneEnum.prefixClass}${table.className}SaveReqVO updateReqVO);
|
||||||
|
/**
|
||||||
|
* 更新流程的状态
|
||||||
|
*
|
||||||
|
* @param id ${simpleClassName}S的id,status ${simpleClassName}S的状态
|
||||||
|
*/
|
||||||
|
void update${simpleClassName}Status(Long id, Integer status);
|
||||||
|
/**
|
||||||
|
* 删除${table.classComment}
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
*/
|
||||||
|
void delete${simpleClassName}(${primaryColumn.javaType} id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得${table.classComment}
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
* @return ${table.classComment}
|
||||||
|
*/
|
||||||
|
${table.className}DO get${simpleClassName}(${primaryColumn.javaType} id);
|
||||||
|
|
||||||
|
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||||
|
#if ( $table.templateType != 2 )
|
||||||
|
/**
|
||||||
|
* 获得${table.classComment}分页
|
||||||
|
*
|
||||||
|
* @param pageReqVO 分页查询
|
||||||
|
* @return ${table.classComment}分页
|
||||||
|
*/
|
||||||
|
PageResult<${table.className}DO> get${simpleClassName}Page(${sceneEnum.prefixClass}${table.className}PageReqVO pageReqVO);
|
||||||
|
#else
|
||||||
|
/**
|
||||||
|
* 获得${table.classComment}列表
|
||||||
|
*
|
||||||
|
* @param listReqVO 查询条件
|
||||||
|
* @return ${table.classComment}列表
|
||||||
|
*/
|
||||||
|
List<${table.className}DO> get${simpleClassName}List(${sceneEnum.prefixClass}${table.className}ListReqVO listReqVO);
|
||||||
|
#end
|
||||||
|
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
#set ($subPrimaryColumn = $subPrimaryColumns.get($index))##当前 primary 字段
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
|
||||||
|
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||||
|
// ==================== 子表($subTable.classComment) ====================
|
||||||
|
|
||||||
|
## 情况一:MASTER_ERP 时,需要分查询页子表
|
||||||
|
#if ( $table.templateType == 11 )
|
||||||
|
/**
|
||||||
|
* 获得${subTable.classComment}分页
|
||||||
|
*
|
||||||
|
* @param pageReqVO 分页查询
|
||||||
|
* @param ${subJoinColumn.javaField} ${subJoinColumn.columnComment}
|
||||||
|
* @return ${subTable.classComment}分页
|
||||||
|
*/
|
||||||
|
PageResult<${subTable.className}DO> get${subSimpleClassName}Page(PageParam pageReqVO, ${subJoinColumn.javaType} ${subJoinColumn.javaField});
|
||||||
|
|
||||||
|
## 情况二:非 MASTER_ERP 时,需要列表查询子表
|
||||||
|
#else
|
||||||
|
#if ( $subTable.subJoinMany )
|
||||||
|
/**
|
||||||
|
* 获得${subTable.classComment}列表
|
||||||
|
*
|
||||||
|
* @param ${subJoinColumn.javaField} ${subJoinColumn.columnComment}
|
||||||
|
* @return ${subTable.classComment}列表
|
||||||
|
*/
|
||||||
|
List<${subTable.className}DO> get${subSimpleClassName}ListBy${SubJoinColumnName}(${subJoinColumn.javaType} ${subJoinColumn.javaField});
|
||||||
|
|
||||||
|
#else
|
||||||
|
/**
|
||||||
|
* 获得${subTable.classComment}
|
||||||
|
*
|
||||||
|
* @param ${subJoinColumn.javaField} ${subJoinColumn.columnComment}
|
||||||
|
* @return ${subTable.classComment}
|
||||||
|
*/
|
||||||
|
${subTable.className}DO get${subSimpleClassName}By${SubJoinColumnName}(${subJoinColumn.javaType} ${subJoinColumn.javaField});
|
||||||
|
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
## 特殊:MASTER_ERP 时,支持单个的新增、修改、删除操作
|
||||||
|
#if ( $table.templateType == 11 )
|
||||||
|
/**
|
||||||
|
* 创建${subTable.classComment}
|
||||||
|
*
|
||||||
|
* @param ${subClassNameVar} 创建信息
|
||||||
|
* @return 编号
|
||||||
|
*/
|
||||||
|
${subPrimaryColumn.javaType} create${subSimpleClassName}(@Valid ${subTable.className}DO ${subClassNameVar});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新${subTable.classComment}
|
||||||
|
*
|
||||||
|
* @param ${subClassNameVar} 更新信息
|
||||||
|
*/
|
||||||
|
void update${subSimpleClassName}(@Valid ${subTable.className}DO ${subClassNameVar});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除${subTable.classComment}
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
*/
|
||||||
|
void delete${subSimpleClassName}(${subPrimaryColumn.javaType} id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得${subTable.classComment}
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
* @return ${subTable.classComment}
|
||||||
|
*/
|
||||||
|
${subTable.className}DO get${subSimpleClassName}(${subPrimaryColumn.javaType} id);
|
||||||
|
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
@ -0,0 +1,387 @@
|
|||||||
|
package ${basePackage}.module.${table.moduleName}.service.${table.businessName};
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ${jakartaPackage}.annotation.Resource;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo.*;
|
||||||
|
import ${basePackage}.module.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO;
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
import ${basePackage}.module.${subTable.moduleName}.dal.dataobject.${subTable.businessName}.${subTable.className}DO;
|
||||||
|
#end
|
||||||
|
import ${PageResultClassName};
|
||||||
|
import ${PageParamClassName};
|
||||||
|
import ${BeanUtils};
|
||||||
|
|
||||||
|
import ${basePackage}.module.${table.moduleName}.dal.mysql.${table.businessName}.${table.className}Mapper;
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
import ${basePackage}.module.${subTable.moduleName}.dal.mysql.${subTable.businessName}.${subTable.className}Mapper;
|
||||||
|
#end
|
||||||
|
import ${basePackage}.module.bpm.api.task.BpmProcessInstanceApi;
|
||||||
|
import ${basePackage}.module.bpm.service.processinstancetodo.ProcessInstanceTodoService;
|
||||||
|
import ${basePackage}.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO;
|
||||||
|
import ${basePackage}.module.bpm.enums.task.BpmTaskStatusEnum;
|
||||||
|
|
||||||
|
import static ${ServiceExceptionUtilClassName}.exception;
|
||||||
|
import static ${basePackage}.module.${table.moduleName}.enums.ErrorCodeConstants.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${table.classComment} Service 实现类
|
||||||
|
*
|
||||||
|
* @author ${table.author}
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Validated
|
||||||
|
public class ${table.className}ServiceImpl implements ${table.className}Service {
|
||||||
|
|
||||||
|
public static String PROCESS_KEY = "";
|
||||||
|
public static String processInstanceId ="";
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private BpmProcessInstanceApi processInstanceApi;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ProcessInstanceTodoService processInstanceTodoService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ${table.className}Mapper ${classNameVar}Mapper;
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
@Resource
|
||||||
|
private ${subTable.className}Mapper ${subClassNameVars.get($index)}Mapper;
|
||||||
|
#end
|
||||||
|
|
||||||
|
@Override
|
||||||
|
## 特殊:主子表专属逻辑(非 ERP 模式)
|
||||||
|
#if ( $subTables && $subTables.size() > 0 && $table.templateType != 11 )
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
#end
|
||||||
|
public ${primaryColumn.javaType} create${simpleClassName}(Long userId,${sceneEnum.prefixClass}${table.className}SaveReqVO createReqVO) {
|
||||||
|
PROCESS_KEY = createReqVO.getProcessDefinitionKey();
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
#set ($TreeParentJavaField = $treeParentColumn.javaField.substring(0,1).toUpperCase() + ${treeParentColumn.javaField.substring(1)})##首字母大写
|
||||||
|
#set ($TreeNameJavaField = $treeNameColumn.javaField.substring(0,1).toUpperCase() + ${treeNameColumn.javaField.substring(1)})##首字母大写
|
||||||
|
// 校验${treeParentColumn.columnComment}的有效性
|
||||||
|
validateParent${simpleClassName}(null, createReqVO.get${TreeParentJavaField}());
|
||||||
|
// 校验${treeNameColumn.columnComment}的唯一性
|
||||||
|
validate${simpleClassName}${TreeNameJavaField}Unique(null, createReqVO.get${TreeParentJavaField}(), createReqVO.get${TreeNameJavaField}());
|
||||||
|
|
||||||
|
#end
|
||||||
|
// 插入
|
||||||
|
${table.className}DO ${classNameVar} = BeanUtils.toBean(createReqVO, ${table.className}DO.class)
|
||||||
|
.setUserId(userId).setStatus(BpmTaskStatusEnum.RUNNING.getStatus());
|
||||||
|
${classNameVar}Mapper.insert(${classNameVar});
|
||||||
|
## 特殊:主子表专属逻辑(非 ERP 模式)
|
||||||
|
#if ( $subTables && $subTables.size() > 0 && $table.templateType != 11 )
|
||||||
|
|
||||||
|
// 插入子表
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
|
||||||
|
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||||
|
#if ( $subTable.subJoinMany)
|
||||||
|
create${subSimpleClassName}List(${classNameVar}.getId(), createReqVO.get${subSimpleClassNames.get($index)}s());
|
||||||
|
#else
|
||||||
|
create${subSimpleClassName}(${classNameVar}.getId(), createReqVO.get${subSimpleClassNames.get($index)}());
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
// 发起 BPM 流程
|
||||||
|
Map<String, Object> processInstanceVariables = new HashMap<>();
|
||||||
|
processInstanceId = processInstanceApi.createProcessInstance(userId,
|
||||||
|
new BpmProcessInstanceCreateReqDTO().setProcessDefinitionKey(PROCESS_KEY)
|
||||||
|
.setVariables(processInstanceVariables).setBusinessKey(String.valueOf(${classNameVar}.getId()))
|
||||||
|
.setStartUserSelectAssignees(createReqVO.getStartUserSelectAssignees()));
|
||||||
|
|
||||||
|
// 将工作流的编号,更新到 OA 请假单中
|
||||||
|
${classNameVar}Mapper.updateById(new ${table.className}DO().setId(${classNameVar}.getId()).setProcessInstanceId(processInstanceId));
|
||||||
|
//同步更新流程待办库
|
||||||
|
processInstanceTodoService.oaCreateProcessInstanceTodo(
|
||||||
|
createReqVO.getTitle(),
|
||||||
|
PROCESS_KEY,
|
||||||
|
processInstanceId,
|
||||||
|
createReqVO.getCurfullpath()
|
||||||
|
);
|
||||||
|
// 返回
|
||||||
|
return ${classNameVar}.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
## 特殊:主子表专属逻辑(非 ERP 模式)
|
||||||
|
#if ( $subTables && $subTables.size() > 0 && $table.templateType != 11 )
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
#end
|
||||||
|
public void update${simpleClassName}(${sceneEnum.prefixClass}${table.className}SaveReqVO updateReqVO) {
|
||||||
|
// 校验存在
|
||||||
|
validate${simpleClassName}Exists(updateReqVO.getId());
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
#set ($TreeParentJavaField = $treeParentColumn.javaField.substring(0,1).toUpperCase() + ${treeParentColumn.javaField.substring(1)})##首字母大写
|
||||||
|
#set ($TreeNameJavaField = $treeNameColumn.javaField.substring(0,1).toUpperCase() + ${treeNameColumn.javaField.substring(1)})##首字母大写
|
||||||
|
// 校验${treeParentColumn.columnComment}的有效性
|
||||||
|
validateParent${simpleClassName}(updateReqVO.getId(), updateReqVO.get${TreeParentJavaField}());
|
||||||
|
// 校验${treeNameColumn.columnComment}的唯一性
|
||||||
|
validate${simpleClassName}${TreeNameJavaField}Unique(updateReqVO.getId(), updateReqVO.get${TreeParentJavaField}(), updateReqVO.get${TreeNameJavaField}());
|
||||||
|
|
||||||
|
#end
|
||||||
|
// 更新
|
||||||
|
${table.className}DO updateObj = BeanUtils.toBean(updateReqVO, ${table.className}DO.class);
|
||||||
|
${classNameVar}Mapper.updateById(updateObj);
|
||||||
|
## 特殊:主子表专属逻辑(非 ERP 模式)
|
||||||
|
#if ( $subTables && $subTables.size() > 0 && $table.templateType != 11)
|
||||||
|
|
||||||
|
// 更新子表
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
|
||||||
|
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||||
|
#if ( $subTable.subJoinMany)
|
||||||
|
update${subSimpleClassName}List(updateReqVO.getId(), updateReqVO.get${subSimpleClassNames.get($index)}s());
|
||||||
|
#else
|
||||||
|
update${subSimpleClassName}(updateReqVO.getId(), updateReqVO.get${subSimpleClassNames.get($index)}());
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update${simpleClassName}Status(Long id, Integer status) {
|
||||||
|
// 校验存在
|
||||||
|
validate${simpleClassName}Exists(id);
|
||||||
|
${classNameVar}Mapper.updateById( new ${simpleClassName}DO().setId(id).setStatus(status) );
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $subTables && $subTables.size() > 0)
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
#end
|
||||||
|
public void delete${simpleClassName}(${primaryColumn.javaType} id) {
|
||||||
|
// 校验存在
|
||||||
|
validate${simpleClassName}Exists(id);
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
#set ($ParentJavaField = $treeParentColumn.javaField.substring(0,1).toUpperCase() + ${treeParentColumn.javaField.substring(1)})##首字母大写
|
||||||
|
// 校验是否有子${table.classComment}
|
||||||
|
if (${classNameVar}Mapper.selectCountBy${ParentJavaField}(id) > 0) {
|
||||||
|
throw exception(${simpleClassName_underlineCase.toUpperCase()}_EXITS_CHILDREN);
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
// 删除
|
||||||
|
${classNameVar}Mapper.deleteById(id);
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $subTables && $subTables.size() > 0)
|
||||||
|
|
||||||
|
// 删除子表
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
|
||||||
|
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||||
|
delete${subSimpleClassName}By${SubJoinColumnName}(id);
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validate${simpleClassName}Exists(${primaryColumn.javaType} id) {
|
||||||
|
if (${classNameVar}Mapper.selectById(id) == null) {
|
||||||
|
throw exception(${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
#set ($TreeParentJavaField = $treeParentColumn.javaField.substring(0,1).toUpperCase() + ${treeParentColumn.javaField.substring(1)})##首字母大写
|
||||||
|
#set ($TreeNameJavaField = $treeNameColumn.javaField.substring(0,1).toUpperCase() + ${treeNameColumn.javaField.substring(1)})##首字母大写
|
||||||
|
private void validateParent${simpleClassName}(Long id, Long ${treeParentColumn.javaField}) {
|
||||||
|
if (${treeParentColumn.javaField} == null || ${simpleClassName}DO.${treeParentColumn_javaField_underlineCase.toUpperCase()}_ROOT.equals(${treeParentColumn.javaField})) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 1. 不能设置自己为父${table.classComment}
|
||||||
|
if (Objects.equals(id, ${treeParentColumn.javaField})) {
|
||||||
|
throw exception(${simpleClassName_underlineCase.toUpperCase()}_PARENT_ERROR);
|
||||||
|
}
|
||||||
|
// 2. 父${table.classComment}不存在
|
||||||
|
${simpleClassName}DO parent${simpleClassName} = ${classNameVar}Mapper.selectById(${treeParentColumn.javaField});
|
||||||
|
if (parent${simpleClassName} == null) {
|
||||||
|
throw exception(${simpleClassName_underlineCase.toUpperCase()}_PARENT_NOT_EXITS);
|
||||||
|
}
|
||||||
|
// 3. 递归校验父${table.classComment},如果父${table.classComment}是自己的子${table.classComment},则报错,避免形成环路
|
||||||
|
if (id == null) { // id 为空,说明新增,不需要考虑环路
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < Short.MAX_VALUE; i++) {
|
||||||
|
// 3.1 校验环路
|
||||||
|
${treeParentColumn.javaField} = parent${simpleClassName}.get${TreeParentJavaField}();
|
||||||
|
if (Objects.equals(id, ${treeParentColumn.javaField})) {
|
||||||
|
throw exception(${simpleClassName_underlineCase.toUpperCase()}_PARENT_IS_CHILD);
|
||||||
|
}
|
||||||
|
// 3.2 继续递归下一级父${table.classComment}
|
||||||
|
if (${treeParentColumn.javaField} == null || ${simpleClassName}DO.${treeParentColumn_javaField_underlineCase.toUpperCase()}_ROOT.equals(${treeParentColumn.javaField})) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
parent${simpleClassName} = ${classNameVar}Mapper.selectById(${treeParentColumn.javaField});
|
||||||
|
if (parent${simpleClassName} == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validate${simpleClassName}${TreeNameJavaField}Unique(Long id, Long ${treeParentColumn.javaField}, String ${treeNameColumn.javaField}) {
|
||||||
|
${simpleClassName}DO ${classNameVar} = ${classNameVar}Mapper.selectBy${TreeParentJavaField}And${TreeNameJavaField}(${treeParentColumn.javaField}, ${treeNameColumn.javaField});
|
||||||
|
if (${classNameVar} == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 如果 id 为空,说明不用比较是否为相同 id 的${table.classComment}
|
||||||
|
if (id == null) {
|
||||||
|
throw exception(${simpleClassName_underlineCase.toUpperCase()}_${treeNameColumn_javaField_underlineCase.toUpperCase()}_DUPLICATE);
|
||||||
|
}
|
||||||
|
if (!Objects.equals(${classNameVar}.getId(), id)) {
|
||||||
|
throw exception(${simpleClassName_underlineCase.toUpperCase()}_${treeNameColumn_javaField_underlineCase.toUpperCase()}_DUPLICATE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#end
|
||||||
|
@Override
|
||||||
|
public ${table.className}DO get${simpleClassName}(${primaryColumn.javaType} id) {
|
||||||
|
return ${classNameVar}Mapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||||
|
#if ( $table.templateType != 2 )
|
||||||
|
@Override
|
||||||
|
public PageResult<${table.className}DO> get${simpleClassName}Page(${sceneEnum.prefixClass}${table.className}PageReqVO pageReqVO) {
|
||||||
|
return ${classNameVar}Mapper.selectPage(pageReqVO);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public List<${table.className}DO> get${simpleClassName}List(${sceneEnum.prefixClass}${table.className}ListReqVO listReqVO) {
|
||||||
|
return ${classNameVar}Mapper.selectList(listReqVO);
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
#set ($simpleClassNameUnderlineCase = $simpleClassNameUnderlineCases.get($index))
|
||||||
|
#set ($subPrimaryColumn = $subPrimaryColumns.get($index))##当前 primary 字段
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
|
||||||
|
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||||
|
// ==================== 子表($subTable.classComment) ====================
|
||||||
|
|
||||||
|
## 情况一:MASTER_ERP 时,需要分查询页子表
|
||||||
|
#if ( $table.templateType == 11 )
|
||||||
|
@Override
|
||||||
|
public PageResult<${subTable.className}DO> get${subSimpleClassName}Page(PageParam pageReqVO, ${subJoinColumn.javaType} ${subJoinColumn.javaField}) {
|
||||||
|
return ${subClassNameVars.get($index)}Mapper.selectPage(pageReqVO, ${subJoinColumn.javaField});
|
||||||
|
}
|
||||||
|
|
||||||
|
## 情况二:非 MASTER_ERP 时,需要列表查询子表
|
||||||
|
#else
|
||||||
|
#if ( $subTable.subJoinMany )
|
||||||
|
@Override
|
||||||
|
public List<${subTable.className}DO> get${subSimpleClassName}ListBy${SubJoinColumnName}(${subJoinColumn.javaType} ${subJoinColumn.javaField}) {
|
||||||
|
return ${subClassNameVars.get($index)}Mapper.selectListBy${SubJoinColumnName}(${subJoinColumn.javaField});
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public ${subTable.className}DO get${subSimpleClassName}By${SubJoinColumnName}(${subJoinColumn.javaType} ${subJoinColumn.javaField}) {
|
||||||
|
return ${subClassNameVars.get($index)}Mapper.selectBy${SubJoinColumnName}(${subJoinColumn.javaField});
|
||||||
|
}
|
||||||
|
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
## 情况一:MASTER_ERP 时,支持单个的新增、修改、删除操作
|
||||||
|
#if ( $table.templateType == 11 )
|
||||||
|
@Override
|
||||||
|
public ${subPrimaryColumn.javaType} create${subSimpleClassName}(${subTable.className}DO ${subClassNameVar}) {
|
||||||
|
## 特殊:一对一时,需要保证只有一条,不能重复插入
|
||||||
|
#if ( !$subTable.subJoinMany)
|
||||||
|
// 校验是否已经存在
|
||||||
|
if (${subClassNameVars.get($index)}Mapper.selectBy${SubJoinColumnName}(${subClassNameVar}.get${SubJoinColumnName}()) != null) {
|
||||||
|
throw exception(${simpleClassNameUnderlineCase.toUpperCase()}_EXISTS);
|
||||||
|
}
|
||||||
|
// 插入
|
||||||
|
#end
|
||||||
|
${subClassNameVars.get($index)}Mapper.insert(${subClassNameVar});
|
||||||
|
return ${subClassNameVar}.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update${subSimpleClassName}(${subTable.className}DO ${subClassNameVar}) {
|
||||||
|
// 校验存在
|
||||||
|
validate${subSimpleClassName}Exists(${subClassNameVar}.getId());
|
||||||
|
// 更新
|
||||||
|
${subClassNameVars.get($index)}Mapper.updateById(${subClassNameVar});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete${subSimpleClassName}(${subPrimaryColumn.javaType} id) {
|
||||||
|
// 校验存在
|
||||||
|
validate${subSimpleClassName}Exists(id);
|
||||||
|
// 删除
|
||||||
|
${subClassNameVars.get($index)}Mapper.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ${subTable.className}DO get${subSimpleClassName}(${subPrimaryColumn.javaType} id) {
|
||||||
|
return ${subClassNameVars.get($index)}Mapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validate${subSimpleClassName}Exists(${subPrimaryColumn.javaType} id) {
|
||||||
|
if (${subClassNameVar}Mapper.selectById(id) == null) {
|
||||||
|
throw exception(${simpleClassNameUnderlineCase.toUpperCase()}_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
## 情况二:非 MASTER_ERP 时,支持批量的新增、修改操作
|
||||||
|
#else
|
||||||
|
#if ( $subTable.subJoinMany)
|
||||||
|
private void create${subSimpleClassName}List(${primaryColumn.javaType} ${subJoinColumn.javaField}, List<${subTable.className}DO> list) {
|
||||||
|
list.forEach(o -> o.set$SubJoinColumnName(${subJoinColumn.javaField}));
|
||||||
|
${subClassNameVars.get($index)}Mapper.insertBatch(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void update${subSimpleClassName}List(${primaryColumn.javaType} ${subJoinColumn.javaField}, List<${subTable.className}DO> list) {
|
||||||
|
delete${subSimpleClassName}By${SubJoinColumnName}(${subJoinColumn.javaField});
|
||||||
|
list.forEach(o -> o.setId(null).setUpdater(null).setUpdateTime(null)); // 解决更新情况下:1)id 冲突;2)updateTime 不更新
|
||||||
|
create${subSimpleClassName}List(${subJoinColumn.javaField}, list);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
private void create${subSimpleClassName}(${primaryColumn.javaType} ${subJoinColumn.javaField}, ${subTable.className}DO ${subClassNameVar}) {
|
||||||
|
if (${subClassNameVar} == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
${subClassNameVar}.set$SubJoinColumnName(${subJoinColumn.javaField});
|
||||||
|
${subClassNameVars.get($index)}Mapper.insert(${subClassNameVar});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void update${subSimpleClassName}(${primaryColumn.javaType} ${subJoinColumn.javaField}, ${subTable.className}DO ${subClassNameVar}) {
|
||||||
|
if (${subClassNameVar} == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
${subClassNameVar}.set$SubJoinColumnName(${subJoinColumn.javaField});
|
||||||
|
${subClassNameVar}.setUpdater(null).setUpdateTime(null); // 解决更新情况下:updateTime 不更新
|
||||||
|
${subClassNameVars.get($index)}Mapper.insertOrUpdate(${subClassNameVar});
|
||||||
|
}
|
||||||
|
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
private void delete${subSimpleClassName}By${SubJoinColumnName}(${primaryColumn.javaType} ${subJoinColumn.javaField}) {
|
||||||
|
${subClassNameVars.get($index)}Mapper.deleteBy${SubJoinColumnName}(${subJoinColumn.javaField});
|
||||||
|
}
|
||||||
|
|
||||||
|
#end
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package ${basePackage}.module.${table.moduleName}.service.${table.businessName}.listener;
|
||||||
|
|
||||||
|
import ${basePackage}.module.${table.moduleName}.service.${table.businessName}.${table.className}Service;
|
||||||
|
import ${basePackage}.module.${table.moduleName}.service.${table.businessName}.${table.className}ServiceImpl;
|
||||||
|
import ${basePackage}.module.bpm.event.BpmProcessInstanceStatusEvent;
|
||||||
|
import ${basePackage}.module.bpm.event.BpmProcessInstanceStatusEventListener;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${table.classComment} 结束的监听器实现类
|
||||||
|
*
|
||||||
|
* @author ${table.author}
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class ${table.className}StatusListener extends BpmProcessInstanceStatusEventListener {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ${table.className}Service ${table.businessName}Service;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getProcessDefinitionKey() {
|
||||||
|
return ${table.className}ServiceImpl.PROCESS_KEY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getProcessInstanceId() {
|
||||||
|
return ${table.className}ServiceImpl.processInstanceId;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected void onEvent(BpmProcessInstanceStatusEvent event) {
|
||||||
|
${table.businessName}Service.update${table.className}Status(Long.parseLong(event.getBusinessKey()), event.getStatus());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,118 @@
|
|||||||
|
import request from '@/config/axios'
|
||||||
|
#set ($baseURL = "/${table.moduleName}/${simpleClassName_strikeCase}")
|
||||||
|
|
||||||
|
// ${table.classComment} VO
|
||||||
|
export interface ${simpleClassName}VO {
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer" || ${column.javaType.toLowerCase()} == "short" || ${column.javaType.toLowerCase()} == "double" || ${column.javaType.toLowerCase()} == "bigdecimal")
|
||||||
|
${column.javaField}: number // ${column.columnComment}
|
||||||
|
#elseif(${column.javaType.toLowerCase()} == "date" || ${column.javaType.toLowerCase()} == "localdate" || ${column.javaType.toLowerCase()} == "localdatetime")
|
||||||
|
${column.javaField}: Date // ${column.columnComment}
|
||||||
|
#else
|
||||||
|
${column.javaField}: ${column.javaType.toLowerCase()} // ${column.columnComment}
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
startUserSelectAssignees:string //启动用户选择的用户信息
|
||||||
|
curfullpath:string // 当前表单路径
|
||||||
|
processDefinitionKey:string //流程定义的key
|
||||||
|
}
|
||||||
|
|
||||||
|
// ${table.classComment} API
|
||||||
|
export const ${simpleClassName}Api = {
|
||||||
|
#if ( $table.templateType != 2 )
|
||||||
|
// 查询${table.classComment}分页
|
||||||
|
get${simpleClassName}Page: async (params: any) => {
|
||||||
|
return await request.get({ url: `${baseURL}/page`, params })
|
||||||
|
},
|
||||||
|
#else
|
||||||
|
// 查询${table.classComment}列表
|
||||||
|
get${simpleClassName}List: async (params) => {
|
||||||
|
return await request.get({ url: `${baseURL}/list`, params })
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
|
||||||
|
// 查询${table.classComment}详情
|
||||||
|
get${simpleClassName}: async (id: number) => {
|
||||||
|
return await request.get({ url: `${baseURL}/get?id=` + id })
|
||||||
|
},
|
||||||
|
|
||||||
|
// 新增${table.classComment}
|
||||||
|
create${simpleClassName}: async (data: ${simpleClassName}VO) => {
|
||||||
|
return await request.post({ url: `${baseURL}/create`, data })
|
||||||
|
},
|
||||||
|
|
||||||
|
// 修改${table.classComment}
|
||||||
|
update${simpleClassName}: async (data: ${simpleClassName}VO) => {
|
||||||
|
return await request.put({ url: `${baseURL}/update`, data })
|
||||||
|
},
|
||||||
|
|
||||||
|
// 删除${table.classComment}
|
||||||
|
delete${simpleClassName}: async (id: number) => {
|
||||||
|
return await request.delete({ url: `${baseURL}/delete?id=` + id })
|
||||||
|
},
|
||||||
|
|
||||||
|
// 导出${table.classComment} Excel
|
||||||
|
export${simpleClassName}: async (params) => {
|
||||||
|
return await request.download({ url: `${baseURL}/export-excel`, params })
|
||||||
|
},
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
#set ($subPrimaryColumn = $subPrimaryColumns.get($index))##当前 primary 字段
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
|
||||||
|
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||||
|
#set ($subSimpleClassName_strikeCase = $subSimpleClassName_strikeCases.get($index))
|
||||||
|
#set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||||
|
|
||||||
|
// ==================== 子表($subTable.classComment) ====================
|
||||||
|
## 情况一:MASTER_ERP 时,需要分查询页子表
|
||||||
|
#if ( $table.templateType == 11 )
|
||||||
|
|
||||||
|
// 获得${subTable.classComment}分页
|
||||||
|
get${subSimpleClassName}Page: async (params) => {
|
||||||
|
return await request.get({ url: `${baseURL}/${subSimpleClassName_strikeCase}/page`, params })
|
||||||
|
},
|
||||||
|
## 情况二:非 MASTER_ERP 时,需要列表查询子表
|
||||||
|
#else
|
||||||
|
#if ( $subTable.subJoinMany )
|
||||||
|
|
||||||
|
// 获得${subTable.classComment}列表
|
||||||
|
get${subSimpleClassName}ListBy${SubJoinColumnName}: async (${subJoinColumn.javaField}) => {
|
||||||
|
return await request.get({ url: `${baseURL}/${subSimpleClassName_strikeCase}/list-by-${subJoinColumn_strikeCase}?${subJoinColumn.javaField}=` + ${subJoinColumn.javaField} })
|
||||||
|
},
|
||||||
|
#else
|
||||||
|
|
||||||
|
// 获得${subTable.classComment}
|
||||||
|
get${subSimpleClassName}By${SubJoinColumnName}: async (${subJoinColumn.javaField}) => {
|
||||||
|
return await request.get({ url: `${baseURL}/${subSimpleClassName_strikeCase}/get-by-${subJoinColumn_strikeCase}?${subJoinColumn.javaField}=` + ${subJoinColumn.javaField} })
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
## 特殊:MASTER_ERP 时,支持单个的新增、修改、删除操作
|
||||||
|
#if ( $table.templateType == 11 )
|
||||||
|
// 新增${subTable.classComment}
|
||||||
|
create${subSimpleClassName}: async (data) => {
|
||||||
|
return await request.post({ url: `${baseURL}/${subSimpleClassName_strikeCase}/create`, data })
|
||||||
|
},
|
||||||
|
|
||||||
|
// 修改${subTable.classComment}
|
||||||
|
update${subSimpleClassName}: async (data) => {
|
||||||
|
return await request.put({ url: `${baseURL}/${subSimpleClassName_strikeCase}/update`, data })
|
||||||
|
},
|
||||||
|
|
||||||
|
// 删除${subTable.classComment}
|
||||||
|
delete${subSimpleClassName}: async (id: number) => {
|
||||||
|
return await request.delete({ url: `${baseURL}/${subSimpleClassName_strikeCase}/delete?id=` + id })
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获得${subTable.classComment}
|
||||||
|
get${subSimpleClassName}: async (id: number) => {
|
||||||
|
return await request.get({ url: `${baseURL}/${subSimpleClassName_strikeCase}/get?id=` + id })
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
@ -0,0 +1,268 @@
|
|||||||
|
<template>
|
||||||
|
<el-form
|
||||||
|
ref="formRef"
|
||||||
|
:model="formData"
|
||||||
|
:rules="formRules"
|
||||||
|
label-width="100px"
|
||||||
|
v-loading="formLoading"
|
||||||
|
>
|
||||||
|
#foreach($column in $columns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#set ($dictType = $column.dictType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($javaType = $column.javaType)
|
||||||
|
#set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
#set ($comment = $column.columnComment)
|
||||||
|
#set ($dictMethod = "getDictOptions")## 计算使用哪个 dict 字典方法
|
||||||
|
#if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short")
|
||||||
|
#set ($dictMethod = "getIntDictOptions")
|
||||||
|
#elseif ($javaType == "String")
|
||||||
|
#set ($dictMethod = "getStrDictOptions")
|
||||||
|
#elseif ($javaType == "Boolean")
|
||||||
|
#set ($dictMethod = "getBoolDictOptions")
|
||||||
|
#end
|
||||||
|
#if ( $table.templateType == 2 && $column.id == $treeParentColumn.id )
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-tree-select
|
||||||
|
v-model="formData.${javaField}"
|
||||||
|
:data="${classNameVar}Tree"
|
||||||
|
#if ($treeNameColumn.javaField == "name")
|
||||||
|
:props="defaultProps"
|
||||||
|
#else
|
||||||
|
:props="{...defaultProps, label: '$treeNameColumn.javaField'}"
|
||||||
|
#end
|
||||||
|
check-strictly
|
||||||
|
default-expand-all
|
||||||
|
placeholder="请选择${comment}"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-input v-model="formData.${javaField}" placeholder="请输入${comment}" disabled />
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "imageUpload")## 图片上传
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<UploadImg v-model="formData.${javaField}" disabled />
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "fileUpload")## 文件上传
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<UploadFile v-model="formData.${javaField}" disabled />
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "editor")## 文本编辑器
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<Editor v-model="formData.${javaField}" height="150px" disabled />
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "select")## 下拉框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-select v-model="formData.${javaField}" placeholder="请选择${comment}" disabled>
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<el-option
|
||||||
|
v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.label"
|
||||||
|
:value="dict.value"
|
||||||
|
/>
|
||||||
|
#else##没数据字典
|
||||||
|
<el-option label="请选择字典生成" value="" />
|
||||||
|
#end
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "checkbox")## 多选框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-checkbox-group v-model="formData.${javaField}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<el-checkbox
|
||||||
|
v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.value"
|
||||||
|
>
|
||||||
|
{{ dict.label }}
|
||||||
|
</el-checkbox>
|
||||||
|
#else##没数据字典
|
||||||
|
<el-checkbox>请选择字典生成</el-checkbox>
|
||||||
|
#end
|
||||||
|
</el-checkbox-group>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "radio")## 单选框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-radio-group v-model="formData.${javaField}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<el-radio
|
||||||
|
v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.value"
|
||||||
|
>
|
||||||
|
{{ dict.label }}
|
||||||
|
</el-radio>
|
||||||
|
#else##没数据字典
|
||||||
|
<el-radio label="1">请选择字典生成</el-radio>
|
||||||
|
#end
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "datetime")## 时间框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-date-picker
|
||||||
|
v-model="formData.${javaField}"
|
||||||
|
type="date"
|
||||||
|
value-format="x"
|
||||||
|
placeholder="选择${comment}"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "textarea")## 文本框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-input v-model="formData.${javaField}" type="textarea" placeholder="请输入${comment}" disabled />
|
||||||
|
</el-form-item>
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
</el-form>
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||||
|
<!-- 子表的表单 -->
|
||||||
|
<el-tabs v-model="subTabsName">
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
#set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
|
||||||
|
<el-tab-pane label="${subTable.classComment}" name="$subClassNameVar">
|
||||||
|
<${subSimpleClassName}Form ref="${subClassNameVar}FormRef" :${subJoinColumn_strikeCase}="formData.id" />
|
||||||
|
</el-tab-pane>
|
||||||
|
#end
|
||||||
|
</el-tabs>
|
||||||
|
#end
|
||||||
|
## <template #footer>
|
||||||
|
## <el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
|
||||||
|
## <el-button @click="dialogVisible = false">取 消</el-button>
|
||||||
|
## </template>
|
||||||
|
</template>
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict'
|
||||||
|
import { propTypes } from '@/utils/propTypes'
|
||||||
|
import { ${simpleClassName}Api, ${simpleClassName}VO } from '@/api/${table.moduleName}/${table.businessName}'
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
import { defaultProps, handleTree } from '@/utils/tree'
|
||||||
|
#end
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||||
|
#foreach ($subSimpleClassName in $subSimpleClassNames)
|
||||||
|
import ${subSimpleClassName}Form from './components/${subSimpleClassName}Form.vue'
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
|
||||||
|
/** ${table.classComment} 表单 */
|
||||||
|
defineOptions({ name: '${simpleClassName}Form' })
|
||||||
|
|
||||||
|
const { t } = useI18n() // 国际化
|
||||||
|
const message = useMessage() // 消息弹窗
|
||||||
|
const { query } = useRoute() // 查询参数
|
||||||
|
const queryId = query.id as unknown as number // 从 URL 传递过来的 id 编号 添加
|
||||||
|
|
||||||
|
const dialogVisible = ref(false) // 弹窗的是否展示
|
||||||
|
// const dialogTitle = ref('') // 弹窗的标题
|
||||||
|
// const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||||
|
const props = defineProps({
|
||||||
|
id: propTypes.number.def(undefined)
|
||||||
|
})
|
||||||
|
const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
||||||
|
const formData = ref({
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#if ($column.htmlType == "checkbox")
|
||||||
|
$column.javaField: [],
|
||||||
|
#else
|
||||||
|
$column.javaField: undefined,
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
})
|
||||||
|
const formRules = reactive({
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键
|
||||||
|
#set($comment=$column.columnComment)
|
||||||
|
$column.javaField: [{ required: true, message: '${comment}不能为空', trigger: #if($column.htmlType == 'select')'change'#else'blur'#end }],
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
})
|
||||||
|
const formRef = ref() // 表单 Ref
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
const ${classNameVar}Tree = ref() // 树形结构
|
||||||
|
#end
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||||
|
#if ( $subTables && $subTables.size() > 0 )
|
||||||
|
|
||||||
|
/** 子表的表单 */
|
||||||
|
const subTabsName = ref('$subClassNameVars.get(0)')
|
||||||
|
#foreach ($subClassNameVar in $subClassNameVars)
|
||||||
|
const ${subClassNameVar}FormRef = ref()
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
|
||||||
|
/** 打开弹窗 */
|
||||||
|
## const open = async (type: string, id?: number) => {
|
||||||
|
## dialogVisible.value = true
|
||||||
|
## dialogTitle.value = t('action.' + type)
|
||||||
|
## formType.value = type
|
||||||
|
## resetForm()
|
||||||
|
## // 修改时,设置数据
|
||||||
|
## if (id) {
|
||||||
|
## formLoading.value = true
|
||||||
|
## try {
|
||||||
|
## formData.value = await ${simpleClassName}Api.get${simpleClassName}(id)
|
||||||
|
## } finally {
|
||||||
|
## formLoading.value = false
|
||||||
|
## }
|
||||||
|
## }
|
||||||
|
## ## 特殊:树表专属逻辑
|
||||||
|
## #if ( $table.templateType == 2 )
|
||||||
|
## await get${simpleClassName}Tree()
|
||||||
|
## #end
|
||||||
|
## }
|
||||||
|
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
||||||
|
|
||||||
|
/** 提交表单 */
|
||||||
|
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
||||||
|
|
||||||
|
|
||||||
|
/** 重置表单 */
|
||||||
|
const resetForm = () => {
|
||||||
|
formData.value = {
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#if ($column.htmlType == "checkbox")
|
||||||
|
$column.javaField: [],
|
||||||
|
#else
|
||||||
|
$column.javaField: undefined,
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
formRef.value?.resetFields()
|
||||||
|
}
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
|
||||||
|
/** 获得${table.classComment}树 */
|
||||||
|
const get${simpleClassName}Tree = async () => {
|
||||||
|
${classNameVar}Tree.value = []
|
||||||
|
const data = await ${simpleClassName}Api.get${simpleClassName}List()
|
||||||
|
const root: Tree = { id: 0, name: '顶级${table.classComment}', children: [] }
|
||||||
|
root.children = handleTree(data, 'id', '${treeParentColumn.javaField}')
|
||||||
|
${classNameVar}Tree.value.push(root)
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
onMounted(async () => {
|
||||||
|
const id = props.id || queryId
|
||||||
|
//console.log("id",id)
|
||||||
|
if (id) {
|
||||||
|
try {
|
||||||
|
formData.value = await ${simpleClassName}Api.get${simpleClassName}(id)
|
||||||
|
} finally {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
@ -0,0 +1,364 @@
|
|||||||
|
<template>
|
||||||
|
<el-card shadow="never" >
|
||||||
|
<template #header>
|
||||||
|
<span style="font-size: 16px">创建请假管理流程</span>
|
||||||
|
</template>
|
||||||
|
<el-form
|
||||||
|
ref="formRef"
|
||||||
|
:model="formData"
|
||||||
|
:rules="formRules"
|
||||||
|
label-width="100px"
|
||||||
|
v-loading="formLoading"
|
||||||
|
>
|
||||||
|
#foreach($column in $columns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#set ($dictType = $column.dictType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($javaType = $column.javaType)
|
||||||
|
#set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
#set ($comment = $column.columnComment)
|
||||||
|
#set ($dictMethod = "getDictOptions")## 计算使用哪个 dict 字典方法
|
||||||
|
#if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short")
|
||||||
|
#set ($dictMethod = "getIntDictOptions")
|
||||||
|
#elseif ($javaType == "String")
|
||||||
|
#set ($dictMethod = "getStrDictOptions")
|
||||||
|
#elseif ($javaType == "Boolean")
|
||||||
|
#set ($dictMethod = "getBoolDictOptions")
|
||||||
|
#end
|
||||||
|
#if ( $table.templateType == 2 && $column.id == $treeParentColumn.id )
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-tree-select
|
||||||
|
v-model="formData.${javaField}"
|
||||||
|
:data="${classNameVar}Tree"
|
||||||
|
#if ($treeNameColumn.javaField == "name")
|
||||||
|
:props="defaultProps"
|
||||||
|
#else
|
||||||
|
:props="{...defaultProps, label: '$treeNameColumn.javaField'}"
|
||||||
|
#end
|
||||||
|
check-strictly
|
||||||
|
default-expand-all
|
||||||
|
placeholder="请选择${comment}"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-input v-model="formData.${javaField}" placeholder="请输入${comment}" />
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "imageUpload")## 图片上传
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<UploadImg v-model="formData.${javaField}" />
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "fileUpload")## 文件上传
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<UploadFile v-model="formData.${javaField}" />
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "editor")## 文本编辑器
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<Editor v-model="formData.${javaField}" height="150px" />
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "select")## 下拉框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-select v-model="formData.${javaField}" placeholder="请选择${comment}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<el-option
|
||||||
|
v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.label"
|
||||||
|
:value="dict.value"
|
||||||
|
/>
|
||||||
|
#else##没数据字典
|
||||||
|
<el-option label="请选择字典生成" value="" />
|
||||||
|
#end
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "checkbox")## 多选框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-checkbox-group v-model="formData.${javaField}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<el-checkbox
|
||||||
|
v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.value"
|
||||||
|
>
|
||||||
|
{{ dict.label }}
|
||||||
|
</el-checkbox>
|
||||||
|
#else##没数据字典
|
||||||
|
<el-checkbox>请选择字典生成</el-checkbox>
|
||||||
|
#end
|
||||||
|
</el-checkbox-group>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "radio")## 单选框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-radio-group v-model="formData.${javaField}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<el-radio
|
||||||
|
v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.value"
|
||||||
|
>
|
||||||
|
{{ dict.label }}
|
||||||
|
</el-radio>
|
||||||
|
#else##没数据字典
|
||||||
|
<el-radio label="1">请选择字典生成</el-radio>
|
||||||
|
#end
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "datetime")## 时间框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-date-picker
|
||||||
|
v-model="formData.${javaField}"
|
||||||
|
type="date"
|
||||||
|
value-format="x"
|
||||||
|
placeholder="选择${comment}"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "textarea")## 文本框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-input v-model="formData.${javaField}" type="textarea" placeholder="请输入${comment}" />
|
||||||
|
</el-form-item>
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
</el-form>
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||||
|
<!-- 子表的表单 -->
|
||||||
|
<el-tabs v-model="subTabsName">
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
#set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
|
||||||
|
<el-tab-pane label="${subTable.classComment}" name="$subClassNameVar">
|
||||||
|
<${subSimpleClassName}Form ref="${subClassNameVar}FormRef" :${subJoinColumn_strikeCase}="formData.id" />
|
||||||
|
</el-tab-pane>
|
||||||
|
#end
|
||||||
|
</el-tabs>
|
||||||
|
#end
|
||||||
|
<template #footer>
|
||||||
|
<el-row justify="end">
|
||||||
|
<el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
|
||||||
|
</el-row>
|
||||||
|
</template>
|
||||||
|
</el-card>
|
||||||
|
</template>
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict'
|
||||||
|
import { ${simpleClassName}Api, ${simpleClassName}VO } from '@/api/${table.moduleName}/${table.businessName}'
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
import { defaultProps, handleTree } from '@/utils/tree'
|
||||||
|
#end
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||||
|
#foreach ($subSimpleClassName in $subSimpleClassNames)
|
||||||
|
import ${subSimpleClassName}Form from './components/${subSimpleClassName}Form.vue'
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
import * as DefinitionApi from '@/api/bpm/definition'
|
||||||
|
import * as UserApi from '@/api/system/user'
|
||||||
|
import {useTagsViewStore} from "@/store/modules/tagsView";
|
||||||
|
import {getUserProfile, ProfileVO} from "@/api/system/user/profile";
|
||||||
|
import {FormProcessMappingApi} from "@/api/bpm/formprocessmapping";
|
||||||
|
|
||||||
|
/** ${table.classComment} 表单 */
|
||||||
|
defineOptions({ name: '${simpleClassName}Form' })
|
||||||
|
|
||||||
|
const { t } = useI18n() // 国际化
|
||||||
|
const message = useMessage() // 消息弹窗
|
||||||
|
const { delView } = useTagsViewStore() // 视图操作
|
||||||
|
const { push, currentRoute } = useRouter() // 路由
|
||||||
|
// const dialogVisible = ref(false) // 弹窗的是否展示
|
||||||
|
// const dialogTitle = ref('') // 弹窗的标题
|
||||||
|
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||||
|
const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
||||||
|
const formData = ref({
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#if ($column.htmlType == "checkbox")
|
||||||
|
$column.javaField: [],
|
||||||
|
#else
|
||||||
|
$column.javaField: undefined,
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
})
|
||||||
|
const formRules = reactive({
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键
|
||||||
|
#set($comment=$column.columnComment)
|
||||||
|
$column.javaField: [{ required: true, message: '${comment}不能为空', trigger: #if($column.htmlType == 'select')'change'#else'blur'#end }],
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
})
|
||||||
|
const formRef = ref() // 表单 Ref
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
const ${classNameVar}Tree = ref() // 树形结构
|
||||||
|
#end
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||||
|
#if ( $subTables && $subTables.size() > 0 )
|
||||||
|
|
||||||
|
/** 子表的表单 */
|
||||||
|
const subTabsName = ref('$subClassNameVars.get(0)')
|
||||||
|
#foreach ($subClassNameVar in $subClassNameVars)
|
||||||
|
const ${subClassNameVar}FormRef = ref()
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
const userInfo = ref('')
|
||||||
|
const deptInfo = ref('')
|
||||||
|
|
||||||
|
const getUserInfo = async () => {
|
||||||
|
const users = await getUserProfile()
|
||||||
|
if (formData.value.deptId == '' || formData.value.deptId == undefined) {
|
||||||
|
formData.value.deptId = users.dept.id
|
||||||
|
}
|
||||||
|
if (formData.value.deptName == '' || formData.value.deptName == undefined) {
|
||||||
|
formData.value.deptName = users.dept.name
|
||||||
|
}
|
||||||
|
|
||||||
|
if (formData.value.userName == '' || formData.value.userName == undefined) {
|
||||||
|
formData.value.userName = users.nickname
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 指定审批人
|
||||||
|
const startUserSelectTasks = ref([]) // 发起人需要选择审批人的用户任务列表
|
||||||
|
const startUserSelectAssignees = ref({}) // 发起人选择审批人的数据
|
||||||
|
const startUserSelectAssigneesFormRef = ref() // 发起人选择审批人的表单 Ref
|
||||||
|
const startUserSelectAssigneesFormRules = ref({}) // 发起人选择审批人的表单 Rules
|
||||||
|
//const userList = ref<any[]>([]) // 用户列表
|
||||||
|
/** 提交表单 */
|
||||||
|
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
||||||
|
const submitForm = async () => {
|
||||||
|
// 校验表单
|
||||||
|
await formRef.value.validate()
|
||||||
|
// 校验指定审批人++
|
||||||
|
if (startUserSelectTasks.value?.length > 0) {
|
||||||
|
await startUserSelectAssigneesFormRef.value.validate()
|
||||||
|
}
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||||
|
#if ( $subTables && $subTables.size() > 0 )
|
||||||
|
// 校验子表单
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||||
|
try {
|
||||||
|
await ${subClassNameVar}FormRef.value.validate()
|
||||||
|
} catch (e) {
|
||||||
|
subTabsName.value = '${subClassNameVar}'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
// 提交请求
|
||||||
|
formLoading.value = true
|
||||||
|
try {
|
||||||
|
const data = formData.value as unknown as ${simpleClassName}VO
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||||
|
#if ( $subTables && $subTables.size() > 0 )
|
||||||
|
// 拼接子表的数据
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||||
|
data.${subClassNameVar}#if ( $subTable.subJoinMany)s#end = ${subClassNameVar}FormRef.value.getData()
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
|
||||||
|
// 设置指定审批人++
|
||||||
|
if (startUserSelectTasks.value?.length > 0) {
|
||||||
|
data.startUserSelectAssignees = startUserSelectAssignees.value
|
||||||
|
}
|
||||||
|
|
||||||
|
const curFullPath = currentRoute.value.fullPath
|
||||||
|
if( curFullPath ) {
|
||||||
|
data.curfullpath = curFullPath
|
||||||
|
}
|
||||||
|
const processKey = await FormProcessMappingApi.selectProcessKey( curFullPath )
|
||||||
|
if ( processKey) {
|
||||||
|
data.processDefinitionKey = processKey
|
||||||
|
}
|
||||||
|
|
||||||
|
await ${simpleClassName}Api.create${simpleClassName}(data)
|
||||||
|
message.success(t('common.createFlow'))
|
||||||
|
// 关闭当前 Tab
|
||||||
|
delView(unref(currentRoute))
|
||||||
|
await push({ name: '${simpleClassName}' })
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
formLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 重置表单 */
|
||||||
|
const resetForm = () => {
|
||||||
|
formData.value = {
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#if ($column.htmlType == "checkbox")
|
||||||
|
$column.javaField: [],
|
||||||
|
#else
|
||||||
|
$column.javaField: undefined,
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
formRef.value?.resetFields()
|
||||||
|
}
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
|
||||||
|
/** 获得${table.classComment}树 */
|
||||||
|
const get${simpleClassName}Tree = async () => {
|
||||||
|
${classNameVar}Tree.value = []
|
||||||
|
const data = await ${simpleClassName}Api.get${simpleClassName}List()
|
||||||
|
const root: Tree = { id: 0, name: '顶级${table.classComment}', children: [] }
|
||||||
|
root.children = handleTree(data, 'id', '${treeParentColumn.javaField}')
|
||||||
|
${classNameVar}Tree.value.push(root)
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
/** 打开弹窗 */
|
||||||
|
onMounted(async () => {
|
||||||
|
await getUserInfo()
|
||||||
|
const curFullPath = currentRoute.value.fullPath
|
||||||
|
const processKey = await FormProcessMappingApi.selectProcessKey( curFullPath )
|
||||||
|
|
||||||
|
if ( !processKey ) {
|
||||||
|
message.error('流程对应表单模型未配置,请检查!')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const processDefinitionDetail = await DefinitionApi.getProcessDefinition(
|
||||||
|
undefined,
|
||||||
|
processKey
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!processDefinitionDetail) {
|
||||||
|
message.error('OA 请假的流程模型未配置,请检查!')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
startUserSelectTasks.value = processDefinitionDetail.startUserSelectTasks
|
||||||
|
// console.log(startUserSelectTasks.value?.length ,"length")
|
||||||
|
// console.log(startUserSelectTasks.value ,"startUserSelectTasks.value")
|
||||||
|
// 设置指定审批人
|
||||||
|
if (startUserSelectTasks.value?.length > 0) {
|
||||||
|
// 设置校验规则
|
||||||
|
for (const userTask of startUserSelectTasks.value) {
|
||||||
|
startUserSelectAssignees.value[userTask.id] = []
|
||||||
|
startUserSelectAssigneesFormRules.value[userTask.id] = [
|
||||||
|
{ required: true, message: '请选择审批人', trigger: 'blur' }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加载用户列表
|
||||||
|
userList.value = await UserApi.getSimpleUserList()
|
||||||
|
console.log(userList.value ,"userList.value")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
@ -0,0 +1,406 @@
|
|||||||
|
<template>
|
||||||
|
<ContentWrap>
|
||||||
|
<!-- 搜索工作栏 -->
|
||||||
|
<el-form
|
||||||
|
class="-mb-15px"
|
||||||
|
:model="queryParams"
|
||||||
|
ref="queryFormRef"
|
||||||
|
:inline="true"
|
||||||
|
label-width="68px"
|
||||||
|
>
|
||||||
|
#foreach($column in $columns)
|
||||||
|
#if ($column.listOperation)
|
||||||
|
#set ($dictType = $column.dictType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($javaType = $column.javaType)
|
||||||
|
#set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
#set ($comment = $column.columnComment)
|
||||||
|
#set ($dictMethod = "getDictOptions")## 计算使用哪个 dict 字典方法
|
||||||
|
#if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short")
|
||||||
|
#set ($dictMethod = "getIntDictOptions")
|
||||||
|
#elseif ($javaType == "String")
|
||||||
|
#set ($dictMethod = "getStrDictOptions")
|
||||||
|
#elseif ($javaType == "Boolean")
|
||||||
|
#set ($dictMethod = "getBoolDictOptions")
|
||||||
|
#end
|
||||||
|
#if ($column.htmlType == "input")
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-input
|
||||||
|
v-model="queryParams.${javaField}"
|
||||||
|
placeholder="请输入${comment}"
|
||||||
|
clearable
|
||||||
|
@keyup.enter="handleQuery"
|
||||||
|
class="!w-240px"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif ($column.htmlType == "select" || $column.htmlType == "radio")
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-select
|
||||||
|
v-model="queryParams.${javaField}"
|
||||||
|
placeholder="请选择${comment}"
|
||||||
|
clearable
|
||||||
|
class="!w-240px"
|
||||||
|
>
|
||||||
|
#if ("" != $dictType)## 设置了 dictType 数据字典的情况
|
||||||
|
<el-option
|
||||||
|
v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.label"
|
||||||
|
:value="dict.value"
|
||||||
|
/>
|
||||||
|
#else## 未设置 dictType 数据字典的情况
|
||||||
|
<el-option label="请选择字典生成" value="" />
|
||||||
|
#end
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "datetime")
|
||||||
|
#if ($column.listOperationCondition != "BETWEEN")## 非范围
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-date-picker
|
||||||
|
v-model="queryParams.${javaField}"
|
||||||
|
value-format="YYYY-MM-DD"
|
||||||
|
type="date"
|
||||||
|
placeholder="选择${comment}"
|
||||||
|
clearable
|
||||||
|
class="!w-240px"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
#else## 范围
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-date-picker
|
||||||
|
v-model="queryParams.${javaField}"
|
||||||
|
value-format="YYYY-MM-DD HH:mm:ss"
|
||||||
|
type="daterange"
|
||||||
|
start-placeholder="开始日期"
|
||||||
|
end-placeholder="结束日期"
|
||||||
|
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
|
||||||
|
class="!w-240px"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
<el-form-item>
|
||||||
|
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
|
||||||
|
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
|
||||||
|
<el-button
|
||||||
|
type="primary"
|
||||||
|
plain
|
||||||
|
@click="handleCreate()"
|
||||||
|
v-hasPermi="['${permissionPrefix}:create']"
|
||||||
|
>
|
||||||
|
<Icon icon="ep:plus" class="mr-5px" /> 发起流程
|
||||||
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
type="success"
|
||||||
|
plain
|
||||||
|
@click="handleExport"
|
||||||
|
:loading="exportLoading"
|
||||||
|
v-hasPermi="['${permissionPrefix}:export']"
|
||||||
|
>
|
||||||
|
<Icon icon="ep:download" class="mr-5px" /> 导出
|
||||||
|
</el-button>
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
<el-button type="danger" plain @click="toggleExpandAll">
|
||||||
|
<Icon icon="ep:sort" class="mr-5px" /> 展开/折叠
|
||||||
|
</el-button>
|
||||||
|
#end
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
</ContentWrap>
|
||||||
|
|
||||||
|
<!-- 列表 -->
|
||||||
|
<ContentWrap>
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 )
|
||||||
|
<el-table
|
||||||
|
v-loading="loading"
|
||||||
|
:data="list"
|
||||||
|
:stripe="true"
|
||||||
|
:show-overflow-tooltip="true"
|
||||||
|
highlight-current-row
|
||||||
|
@current-change="handleCurrentChange"
|
||||||
|
>
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#elseif ( $table.templateType == 2 )
|
||||||
|
<el-table
|
||||||
|
v-loading="loading"
|
||||||
|
:data="list"
|
||||||
|
:stripe="true"
|
||||||
|
:show-overflow-tooltip="true"
|
||||||
|
row-key="id"
|
||||||
|
:default-expand-all="isExpandAll"
|
||||||
|
v-if="refreshTable"
|
||||||
|
>
|
||||||
|
#else
|
||||||
|
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
|
||||||
|
#end
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 12 && $subTables && $subTables.size() > 0 )
|
||||||
|
<!-- 子表的列表 -->
|
||||||
|
<el-table-column type="expand">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-tabs model-value="$subClassNameVars.get(0)">
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
#set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
|
||||||
|
<el-tab-pane label="${subTable.classComment}" name="$subClassNameVar">
|
||||||
|
<${subSimpleClassName}List :${subJoinColumn_strikeCase}="scope.row.id" />
|
||||||
|
</el-tab-pane>
|
||||||
|
#end
|
||||||
|
</el-tabs>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#end
|
||||||
|
#foreach($column in $columns)
|
||||||
|
#if ($column.listOperationResult)
|
||||||
|
#set ($dictType=$column.dictType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
#set ($comment=$column.columnComment)
|
||||||
|
#if ($column.javaType == "LocalDateTime")## 时间类型
|
||||||
|
<el-table-column
|
||||||
|
label="${comment}"
|
||||||
|
align="center"
|
||||||
|
prop="${javaField}"
|
||||||
|
:formatter="dateFormatter"
|
||||||
|
width="180px"
|
||||||
|
/>
|
||||||
|
#elseif($column.dictType && "" != $column.dictType)## 数据字典
|
||||||
|
<el-table-column label="${comment}" align="center" prop="${javaField}">
|
||||||
|
<template #default="scope">
|
||||||
|
<dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.${column.javaField}" />
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#else
|
||||||
|
<el-table-column label="${comment}" align="center" prop="${javaField}" />
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
<el-table-column label="操作" align="center">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-button
|
||||||
|
link
|
||||||
|
type="primary"
|
||||||
|
@click="handleDetail(scope.row)"
|
||||||
|
v-hasPermi="['${permissionPrefix}:update']"
|
||||||
|
>
|
||||||
|
详情
|
||||||
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
link
|
||||||
|
type="danger"
|
||||||
|
@click="handleProcessDetail(scope.row)"
|
||||||
|
v-hasPermi="['${permissionPrefix}:delete']"
|
||||||
|
>
|
||||||
|
进度
|
||||||
|
</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
<!-- 分页 -->
|
||||||
|
<Pagination
|
||||||
|
:total="total"
|
||||||
|
v-model:page="queryParams.pageNo"
|
||||||
|
v-model:limit="queryParams.pageSize"
|
||||||
|
@pagination="getList"
|
||||||
|
/>
|
||||||
|
</ContentWrap>
|
||||||
|
|
||||||
|
<!-- 表单弹窗:添加/修改 -->
|
||||||
|
## <${simpleClassName}Form ref="formRef" @success="getList" />
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 )
|
||||||
|
<!-- 子表的列表 -->
|
||||||
|
<ContentWrap>
|
||||||
|
<el-tabs model-value="$subClassNameVars.get(0)">
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
#set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
|
||||||
|
<el-tab-pane label="${subTable.classComment}" name="$subClassNameVar">
|
||||||
|
<${subSimpleClassName}List :${subJoinColumn_strikeCase}="currentRow.id" />
|
||||||
|
</el-tab-pane>
|
||||||
|
#end
|
||||||
|
</el-tabs>
|
||||||
|
</ContentWrap>
|
||||||
|
#end
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict'
|
||||||
|
import { dateFormatter } from '@/utils/formatTime'
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
import { handleTree } from '@/utils/tree'
|
||||||
|
#end
|
||||||
|
import download from '@/utils/download'
|
||||||
|
import { ${simpleClassName}Api, ${simpleClassName}VO } from '@/api/${table.moduleName}/${table.businessName}'
|
||||||
|
import ${simpleClassName}Form from './${simpleClassName}Form.vue'
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType != 10 )
|
||||||
|
#foreach ($subSimpleClassName in $subSimpleClassNames)
|
||||||
|
import ${subSimpleClassName}List from './components/${subSimpleClassName}List.vue'
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
|
||||||
|
/** ${table.classComment} 列表 */
|
||||||
|
defineOptions({ name: '${table.className}' })
|
||||||
|
const router = useRouter() // 路由
|
||||||
|
const message = useMessage() // 消息弹窗
|
||||||
|
const { t } = useI18n() // 国际化
|
||||||
|
|
||||||
|
const loading = ref(true) // 列表的加载中
|
||||||
|
const list = ref<${simpleClassName}VO[]>([]) // 列表的数据
|
||||||
|
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||||
|
#if ( $table.templateType != 2 )
|
||||||
|
const total = ref(0) // 列表的总页数
|
||||||
|
#end
|
||||||
|
const queryParams = reactive({
|
||||||
|
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||||
|
#if ( $table.templateType != 2 )
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
#end
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if ($column.listOperation)
|
||||||
|
#if ($column.listOperationCondition != 'BETWEEN')
|
||||||
|
$column.javaField: undefined,
|
||||||
|
#end
|
||||||
|
#if ($column.htmlType == "datetime" || $column.listOperationCondition == "BETWEEN")
|
||||||
|
$column.javaField: [],
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
})
|
||||||
|
const queryFormRef = ref() // 搜索的表单
|
||||||
|
const exportLoading = ref(false) // 导出的加载中
|
||||||
|
|
||||||
|
/** 查询列表 */
|
||||||
|
const getList = async () => {
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
const data = await ${simpleClassName}Api.get${simpleClassName}List(queryParams)
|
||||||
|
list.value = handleTree(data, 'id', '${treeParentColumn.javaField}')
|
||||||
|
#else
|
||||||
|
const data = await ${simpleClassName}Api.get${simpleClassName}Page(queryParams)
|
||||||
|
list.value = data.list
|
||||||
|
total.value = data.total
|
||||||
|
#end
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 搜索按钮操作 */
|
||||||
|
const handleQuery = () => {
|
||||||
|
queryParams.pageNo = 1
|
||||||
|
getList()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 重置按钮操作 */
|
||||||
|
const resetQuery = () => {
|
||||||
|
queryFormRef.value.resetFields()
|
||||||
|
handleQuery()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 添加/修改操作 */
|
||||||
|
const formRef = ref()
|
||||||
|
const openForm = (type: string, id?: number) => {
|
||||||
|
formRef.value.open(type, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除按钮操作 */
|
||||||
|
const handleDelete = async (id: number) => {
|
||||||
|
try {
|
||||||
|
// 删除的二次确认
|
||||||
|
await message.delConfirm()
|
||||||
|
// 发起删除
|
||||||
|
await ${simpleClassName}Api.delete${simpleClassName}(id)
|
||||||
|
message.success(t('common.delSuccess'))
|
||||||
|
// 刷新列表
|
||||||
|
await getList()
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
// flowBegin++++++++++++++++++
|
||||||
|
/** 添加操作 */
|
||||||
|
const handleCreate = () => {
|
||||||
|
router.push({ name: '${simpleClassName}Form' })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 详情操作 */
|
||||||
|
const handleDetail = (row: ${simpleClassName}Api.${simpleClassName}VO) => {
|
||||||
|
router.push({
|
||||||
|
name: '${simpleClassName}Detail',
|
||||||
|
query: {
|
||||||
|
id: row.id
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/** 审批进度 */
|
||||||
|
const handleProcessDetail = (row) => {
|
||||||
|
router.push({
|
||||||
|
name: 'BpmProcessInstanceDetail',
|
||||||
|
query: {
|
||||||
|
id: row.processInstanceId
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// fix: 列表不刷新的问题。
|
||||||
|
watch(
|
||||||
|
() => router.currentRoute.value,
|
||||||
|
() => {
|
||||||
|
getList()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
// flowOver++++++++++++++++++
|
||||||
|
/** 导出按钮操作 */
|
||||||
|
const handleExport = async () => {
|
||||||
|
try {
|
||||||
|
// 导出的二次确认
|
||||||
|
await message.exportConfirm()
|
||||||
|
// 发起导出
|
||||||
|
exportLoading.value = true
|
||||||
|
const data = await ${simpleClassName}Api.export${simpleClassName}(queryParams)
|
||||||
|
download.excel(data, '${table.classComment}.xls')
|
||||||
|
} catch {
|
||||||
|
} finally {
|
||||||
|
exportLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 11 )
|
||||||
|
|
||||||
|
/** 选中行操作 */
|
||||||
|
const currentRow = ref({}) // 选中行
|
||||||
|
const handleCurrentChange = (row) => {
|
||||||
|
currentRow.value = row
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
|
||||||
|
/** 展开/折叠操作 */
|
||||||
|
const isExpandAll = ref(true) // 是否展开,默认全部展开
|
||||||
|
const refreshTable = ref(true) // 重新渲染表格状态
|
||||||
|
const toggleExpandAll = async () => {
|
||||||
|
refreshTable.value = false
|
||||||
|
isExpandAll.value = !isExpandAll.value
|
||||||
|
await nextTick()
|
||||||
|
refreshTable.value = true
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
|
||||||
|
/** 初始化 **/
|
||||||
|
onMounted(() => {
|
||||||
|
getList()
|
||||||
|
})
|
||||||
|
</script>
|
@ -0,0 +1,233 @@
|
|||||||
|
package ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName};
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import ${jakartaPackage}.annotation.Resource;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
#if ($sceneEnum.scene == 1)import org.springframework.security.access.prepost.PreAuthorize;#end
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
|
||||||
|
import ${jakartaPackage}.validation.constraints.*;
|
||||||
|
import ${jakartaPackage}.validation.*;
|
||||||
|
import ${jakartaPackage}.servlet.http.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import ${PageParamClassName};
|
||||||
|
import ${PageResultClassName};
|
||||||
|
import ${CommonResultClassName};
|
||||||
|
import ${BeanUtils};
|
||||||
|
import static ${CommonResultClassName}.success;
|
||||||
|
|
||||||
|
import ${ExcelUtilsClassName};
|
||||||
|
|
||||||
|
import ${ApiAccessLogClassName};
|
||||||
|
import static ${OperateTypeEnumClassName}.*;
|
||||||
|
|
||||||
|
import ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo.*;
|
||||||
|
import ${basePackage}.module.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO;
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
import ${basePackage}.module.${subTable.moduleName}.dal.dataobject.${subTable.businessName}.${subTable.className}DO;
|
||||||
|
#end
|
||||||
|
import ${basePackage}.module.${table.moduleName}.service.${table.businessName}.${table.className}Service;
|
||||||
|
|
||||||
|
@Tag(name = "${sceneEnum.name} - ${table.classComment}")
|
||||||
|
@RestController
|
||||||
|
##二级的 businessName 暂时不算在 HTTP 路径上,可以根据需要写
|
||||||
|
@RequestMapping("/${table.moduleName}/${simpleClassName_strikeCase}")
|
||||||
|
@Validated
|
||||||
|
public class ${sceneEnum.prefixClass}${table.className}Controller {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ${table.className}Service ${classNameVar}Service;
|
||||||
|
|
||||||
|
@PostMapping("/create")
|
||||||
|
@Operation(summary = "创建${table.classComment}")
|
||||||
|
#if ($sceneEnum.scene == 1)
|
||||||
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:create')")
|
||||||
|
#end
|
||||||
|
public CommonResult<${primaryColumn.javaType}> create${simpleClassName}(@Valid @RequestBody ${sceneEnum.prefixClass}${table.className}SaveReqVO createReqVO) {
|
||||||
|
return success(${classNameVar}Service.create${simpleClassName}(createReqVO));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/update")
|
||||||
|
@Operation(summary = "更新${table.classComment}")
|
||||||
|
#if ($sceneEnum.scene == 1)
|
||||||
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:update')")
|
||||||
|
#end
|
||||||
|
public CommonResult<Boolean> update${simpleClassName}(@Valid @RequestBody ${sceneEnum.prefixClass}${table.className}SaveReqVO updateReqVO) {
|
||||||
|
${classNameVar}Service.update${simpleClassName}(updateReqVO);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/delete")
|
||||||
|
@Operation(summary = "删除${table.classComment}")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true)
|
||||||
|
#if ($sceneEnum.scene == 1)
|
||||||
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')")
|
||||||
|
#end
|
||||||
|
public CommonResult<Boolean> delete${simpleClassName}(@RequestParam("id") ${primaryColumn.javaType} id) {
|
||||||
|
${classNameVar}Service.delete${simpleClassName}(id);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get")
|
||||||
|
@Operation(summary = "获得${table.classComment}")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||||
|
#if ($sceneEnum.scene == 1)
|
||||||
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
|
||||||
|
#end
|
||||||
|
public CommonResult<${sceneEnum.prefixClass}${table.className}RespVO> get${simpleClassName}(@RequestParam("id") ${primaryColumn.javaType} id) {
|
||||||
|
${table.className}DO ${classNameVar} = ${classNameVar}Service.get${simpleClassName}(id);
|
||||||
|
return success(BeanUtils.toBean(${classNameVar}, ${sceneEnum.prefixClass}${table.className}RespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
#if ( $table.templateType != 2 )
|
||||||
|
@GetMapping("/page")
|
||||||
|
@Operation(summary = "获得${table.classComment}分页")
|
||||||
|
#if ($sceneEnum.scene == 1)
|
||||||
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
|
||||||
|
#end
|
||||||
|
public CommonResult<PageResult<${sceneEnum.prefixClass}${table.className}RespVO>> get${simpleClassName}Page(@Valid ${sceneEnum.prefixClass}${table.className}PageReqVO pageReqVO) {
|
||||||
|
PageResult<${table.className}DO> pageResult = ${classNameVar}Service.get${simpleClassName}Page(pageReqVO);
|
||||||
|
return success(BeanUtils.toBean(pageResult, ${sceneEnum.prefixClass}${table.className}RespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||||
|
#else
|
||||||
|
@GetMapping("/list")
|
||||||
|
@Operation(summary = "获得${table.classComment}列表")
|
||||||
|
#if ($sceneEnum.scene == 1)
|
||||||
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
|
||||||
|
#end
|
||||||
|
public CommonResult<List<${sceneEnum.prefixClass}${table.className}RespVO>> get${simpleClassName}List(@Valid ${sceneEnum.prefixClass}${table.className}ListReqVO listReqVO) {
|
||||||
|
List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}List(listReqVO);
|
||||||
|
return success(BeanUtils.toBean(list, ${sceneEnum.prefixClass}${table.className}RespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
#end
|
||||||
|
@GetMapping("/export-excel")
|
||||||
|
@Operation(summary = "导出${table.classComment} Excel")
|
||||||
|
#if ($sceneEnum.scene == 1)
|
||||||
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:export')")
|
||||||
|
#end
|
||||||
|
@ApiAccessLog(operateType = EXPORT)
|
||||||
|
#if ( $table.templateType != 2 )
|
||||||
|
public void export${simpleClassName}Excel(@Valid ${sceneEnum.prefixClass}${table.className}PageReqVO pageReqVO,
|
||||||
|
HttpServletResponse response) throws IOException {
|
||||||
|
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||||
|
List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}Page(pageReqVO).getList();
|
||||||
|
// 导出 Excel
|
||||||
|
ExcelUtils.write(response, "${table.classComment}.xls", "数据", ${sceneEnum.prefixClass}${table.className}RespVO.class,
|
||||||
|
BeanUtils.toBean(list, ${sceneEnum.prefixClass}${table.className}RespVO.class));
|
||||||
|
}
|
||||||
|
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||||
|
#else
|
||||||
|
public void export${simpleClassName}Excel(@Valid ${sceneEnum.prefixClass}${table.className}ListReqVO listReqVO,
|
||||||
|
HttpServletResponse response) throws IOException {
|
||||||
|
List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}List(listReqVO);
|
||||||
|
// 导出 Excel
|
||||||
|
ExcelUtils.write(response, "${table.classComment}.xls", "数据", ${table.className}RespVO.class,
|
||||||
|
BeanUtils.toBean(list, ${table.className}RespVO.class));
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
#set ($subPrimaryColumn = $subPrimaryColumns.get($index))##当前 primary 字段
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
|
||||||
|
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||||
|
#set ($subSimpleClassName_strikeCase = $subSimpleClassName_strikeCases.get($index))
|
||||||
|
#set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||||
|
// ==================== 子表($subTable.classComment) ====================
|
||||||
|
|
||||||
|
## 情况一:MASTER_ERP 时,需要分查询页子表
|
||||||
|
#if ( $table.templateType == 11 )
|
||||||
|
@GetMapping("/${subSimpleClassName_strikeCase}/page")
|
||||||
|
@Operation(summary = "获得${subTable.classComment}分页")
|
||||||
|
@Parameter(name = "${subJoinColumn.javaField}", description = "${subJoinColumn.columnComment}")
|
||||||
|
#if ($sceneEnum.scene == 1)
|
||||||
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
|
||||||
|
#end
|
||||||
|
public CommonResult<PageResult<${subTable.className}DO>> get${subSimpleClassName}Page(PageParam pageReqVO,
|
||||||
|
@RequestParam("${subJoinColumn.javaField}") ${subJoinColumn.javaType} ${subJoinColumn.javaField}) {
|
||||||
|
return success(${classNameVar}Service.get${subSimpleClassName}Page(pageReqVO, ${subJoinColumn.javaField}));
|
||||||
|
}
|
||||||
|
|
||||||
|
## 情况二:非 MASTER_ERP 时,需要列表查询子表
|
||||||
|
#else
|
||||||
|
#if ( $subTable.subJoinMany )
|
||||||
|
@GetMapping("/${subSimpleClassName_strikeCase}/list-by-${subJoinColumn_strikeCase}")
|
||||||
|
@Operation(summary = "获得${subTable.classComment}列表")
|
||||||
|
@Parameter(name = "${subJoinColumn.javaField}", description = "${subJoinColumn.columnComment}")
|
||||||
|
#if ($sceneEnum.scene == 1)
|
||||||
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
|
||||||
|
#end
|
||||||
|
public CommonResult<List<${subTable.className}DO>> get${subSimpleClassName}ListBy${SubJoinColumnName}(@RequestParam("${subJoinColumn.javaField}") ${subJoinColumn.javaType} ${subJoinColumn.javaField}) {
|
||||||
|
return success(${classNameVar}Service.get${subSimpleClassName}ListBy${SubJoinColumnName}(${subJoinColumn.javaField}));
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@GetMapping("/${subSimpleClassName_strikeCase}/get-by-${subJoinColumn_strikeCase}")
|
||||||
|
@Operation(summary = "获得${subTable.classComment}")
|
||||||
|
@Parameter(name = "${subJoinColumn.javaField}", description = "${subJoinColumn.columnComment}")
|
||||||
|
#if ($sceneEnum.scene == 1)
|
||||||
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
|
||||||
|
#end
|
||||||
|
public CommonResult<${subTable.className}DO> get${subSimpleClassName}By${SubJoinColumnName}(@RequestParam("${subJoinColumn.javaField}") ${subJoinColumn.javaType} ${subJoinColumn.javaField}) {
|
||||||
|
return success(${classNameVar}Service.get${subSimpleClassName}By${SubJoinColumnName}(${subJoinColumn.javaField}));
|
||||||
|
}
|
||||||
|
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
## 特殊:MASTER_ERP 时,支持单个的新增、修改、删除操作
|
||||||
|
#if ( $table.templateType == 11 )
|
||||||
|
@PostMapping("/${subSimpleClassName_strikeCase}/create")
|
||||||
|
@Operation(summary = "创建${subTable.classComment}")
|
||||||
|
#if ($sceneEnum.scene == 1)
|
||||||
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:create')")
|
||||||
|
#end
|
||||||
|
public CommonResult<${subPrimaryColumn.javaType}> create${subSimpleClassName}(@Valid @RequestBody ${subTable.className}DO ${subClassNameVar}) {
|
||||||
|
return success(${classNameVar}Service.create${subSimpleClassName}(${subClassNameVar}));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/${subSimpleClassName_strikeCase}/update")
|
||||||
|
@Operation(summary = "更新${subTable.classComment}")
|
||||||
|
#if ($sceneEnum.scene == 1)
|
||||||
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:update')")
|
||||||
|
#end
|
||||||
|
public CommonResult<Boolean> update${subSimpleClassName}(@Valid @RequestBody ${subTable.className}DO ${subClassNameVar}) {
|
||||||
|
${classNameVar}Service.update${subSimpleClassName}(${subClassNameVar});
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/${subSimpleClassName_strikeCase}/delete")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true)
|
||||||
|
@Operation(summary = "删除${subTable.classComment}")
|
||||||
|
#if ($sceneEnum.scene == 1)
|
||||||
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')")
|
||||||
|
#end
|
||||||
|
public CommonResult<Boolean> delete${subSimpleClassName}(@RequestParam("id") ${subPrimaryColumn.javaType} id) {
|
||||||
|
${classNameVar}Service.delete${subSimpleClassName}(id);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/${subSimpleClassName_strikeCase}/get")
|
||||||
|
@Operation(summary = "获得${subTable.classComment}")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true)
|
||||||
|
#if ($sceneEnum.scene == 1)
|
||||||
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")
|
||||||
|
#end
|
||||||
|
public CommonResult<${subTable.className}DO> get${subSimpleClassName}(@RequestParam("id") ${subPrimaryColumn.javaType} id) {
|
||||||
|
return success(${classNameVar}Service.get${subSimpleClassName}(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
package ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import ${PageParamClassName};
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (${column.javaType} == "BigDecimal")
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
#break
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
## 处理 LocalDateTime 字段的引入
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (${column.listOperation} && ${column.javaType} == "LocalDateTime")
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import static ${DateUtilsClassName}.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||||
|
#break
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
## 字段模板
|
||||||
|
#macro(columnTpl $prefix $prefixStr)
|
||||||
|
@Schema(description = "${prefixStr}${column.columnComment}"#if ("$!column.example" != ""), example = "${column.example}"#end)
|
||||||
|
private ${column.javaType}#if ("$!prefix" != "") ${prefix}${JavaField}#else ${column.javaField}#end;
|
||||||
|
#end
|
||||||
|
|
||||||
|
@Schema(description = "${sceneEnum.name} - ${table.classComment}列表 Request VO")
|
||||||
|
@Data
|
||||||
|
public class ${sceneEnum.prefixClass}${table.className}ListReqVO {
|
||||||
|
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (${column.listOperation})##查询操作
|
||||||
|
#if (${column.listOperationCondition} == "BETWEEN")## 情况一,Between 的时候
|
||||||
|
@Schema(description = "${column.columnComment}"#if ("$!column.example" != ""), example = "${column.example}"#end)
|
||||||
|
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||||
|
private ${column.javaType}[] ${column.javaField};
|
||||||
|
#else##情况二,非 Between 的时间
|
||||||
|
#columnTpl('', '')
|
||||||
|
#end
|
||||||
|
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
package ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import ${PageParamClassName};
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (${column.javaType} == "BigDecimal")
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
#break
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
## 处理 LocalDateTime 字段的引入
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (${column.listOperationCondition} && ${column.javaType} == "LocalDateTime")
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import static ${DateUtilsClassName}.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||||
|
#break
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
## 字段模板
|
||||||
|
#macro(columnTpl $prefix $prefixStr)
|
||||||
|
@Schema(description = "${prefixStr}${column.columnComment}"#if ("$!column.example" != ""), example = "${column.example}"#end)
|
||||||
|
private ${column.javaType}#if ("$!prefix" != "") ${prefix}${JavaField}#else ${column.javaField}#end;
|
||||||
|
#end
|
||||||
|
|
||||||
|
@Schema(description = "${sceneEnum.name} - ${table.classComment}分页 Request VO")
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
public class ${sceneEnum.prefixClass}${table.className}PageReqVO extends PageParam {
|
||||||
|
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (${column.listOperation})##查询操作
|
||||||
|
#if (${column.listOperationCondition} == "BETWEEN")## 情况一,Between 的时候
|
||||||
|
@Schema(description = "${column.columnComment}"#if ("$!column.example" != ""), example = "${column.example}"#end)
|
||||||
|
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||||
|
private ${column.javaType}[] ${column.javaField};
|
||||||
|
#else##情况二,非 Between 的时间
|
||||||
|
#columnTpl('', '')
|
||||||
|
#end
|
||||||
|
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
package ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
## 处理 BigDecimal 字段的引入
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (${column.javaType} == "BigDecimal")
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
#break
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
## 处理 LocalDateTime 字段的引入
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (${column.listOperationResult} && ${column.javaType} == "LocalDateTime")
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
#break
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
## 处理 Excel 导出
|
||||||
|
import com.alibaba.excel.annotation.*;
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if ("$!column.dictType" != "")## 有设置数据字典
|
||||||
|
import ${DictFormatClassName};
|
||||||
|
import ${DictConvertClassName};
|
||||||
|
#break
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
|
||||||
|
@Schema(description = "${sceneEnum.name} - ${table.classComment} Response VO")
|
||||||
|
@Data
|
||||||
|
@ExcelIgnoreUnannotated
|
||||||
|
public class ${sceneEnum.prefixClass}${table.className}RespVO {
|
||||||
|
|
||||||
|
## 逐个处理字段
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (${column.listOperationResult})
|
||||||
|
## 1. 处理 Swagger 注解
|
||||||
|
@Schema(description = "${column.columnComment}"#if (!${column.nullable}), requiredMode = Schema.RequiredMode.REQUIRED#end#if ("$!column.example" != ""), example = "${column.example}"#end)
|
||||||
|
## 2. 处理 Excel 导出
|
||||||
|
#if ("$!column.dictType" != "")##处理枚举值
|
||||||
|
@ExcelProperty(value = "${column.columnComment}", converter = DictConvert.class)
|
||||||
|
@DictFormat("${column.dictType}") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
|
||||||
|
#else
|
||||||
|
@ExcelProperty("${column.columnComment}")
|
||||||
|
#end
|
||||||
|
## 3. 处理字段定义
|
||||||
|
private ${column.javaType} ${column.javaField};
|
||||||
|
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
package ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import ${jakartaPackage}.validation.constraints.*;
|
||||||
|
## 处理 BigDecimal 字段的引入
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (${column.javaType} == "BigDecimal")
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
#break
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
## 处理 LocalDateTime 字段的引入
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if ((${column.createOperation} || ${column.updateOperation}) && ${column.javaType} == "LocalDateTime")
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
#break
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
import ${basePackage}.module.${subTable.moduleName}.dal.dataobject.${subTable.businessName}.${subTable.className}DO;
|
||||||
|
#end
|
||||||
|
|
||||||
|
@Schema(description = "${sceneEnum.name} - ${table.classComment}新增/修改 Request VO")
|
||||||
|
@Data
|
||||||
|
public class ${sceneEnum.prefixClass}${table.className}SaveReqVO {
|
||||||
|
|
||||||
|
## 逐个处理字段
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (${column.createOperation} || ${column.updateOperation})
|
||||||
|
## 1. 处理 Swagger 注解
|
||||||
|
@Schema(description = "${column.columnComment}"#if (!${column.nullable}), requiredMode = Schema.RequiredMode.REQUIRED#end#if ("$!column.example" != ""), example = "${column.example}"#end)
|
||||||
|
## 2. 处理 Validator 参数校验
|
||||||
|
#if (!${column.nullable} && !${column.primaryKey})
|
||||||
|
#if (${column.javaType} == 'String')
|
||||||
|
@NotEmpty(message = "${column.columnComment}不能为空")
|
||||||
|
#else
|
||||||
|
@NotNull(message = "${column.columnComment}不能为空")
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
## 3. 处理字段定义
|
||||||
|
private ${column.javaType} ${column.javaField};
|
||||||
|
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
## 特殊:主子表专属逻辑(非 ERP 模式)
|
||||||
|
#if ( $subTables && $subTables.size() > 0 && $table.templateType != 11 )
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#if ( $subTable.subJoinMany)
|
||||||
|
@Schema(description = "${subTable.classComment}列表")
|
||||||
|
private List<${subTable.className}DO> ${subClassNameVars.get($index)}s;
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Schema(description = "${subTable.classComment}")
|
||||||
|
private ${subTable.className}DO ${subClassNameVars.get($index)};
|
||||||
|
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
package ${basePackage}.module.${table.moduleName}.dal.dataobject.${table.businessName};
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (${column.javaType} == "BigDecimal")
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
#end
|
||||||
|
#if (${column.javaType} == "LocalDateTime")
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import ${BaseDOClassName};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${table.classComment} DO
|
||||||
|
*
|
||||||
|
* @author ${table.author}
|
||||||
|
*/
|
||||||
|
@TableName("${table.tableName.toLowerCase()}")
|
||||||
|
@KeySequence("${table.tableName.toLowerCase()}_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class ${table.className}DO extends BaseDO {
|
||||||
|
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
public static final Long ${treeParentColumn_javaField_underlineCase.toUpperCase()}_ROOT = 0L;
|
||||||
|
|
||||||
|
#end
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (!${baseDOFields.contains(${column.javaField})})##排除 BaseDO 的字段
|
||||||
|
/**
|
||||||
|
* ${column.columnComment}
|
||||||
|
#if ("$!column.dictType" != "")##处理枚举值
|
||||||
|
*
|
||||||
|
* 枚举 {@link TODO ${column.dictType} 对应的类}
|
||||||
|
#end
|
||||||
|
*/
|
||||||
|
#if (${column.primaryKey})##处理主键
|
||||||
|
@TableId#if (${column.javaType} == 'String')(type = IdType.INPUT)#end
|
||||||
|
#end
|
||||||
|
private ${column.javaType} ${column.javaField};
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
#set ($subTable = $subTables.get($subIndex))##当前表
|
||||||
|
#set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组
|
||||||
|
package ${basePackage}.module.${subTable.moduleName}.dal.dataobject.${subTable.businessName};
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
#foreach ($column in $subColumns)
|
||||||
|
#if (${column.javaType} == "BigDecimal")
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
#end
|
||||||
|
#if (${column.javaType} == "LocalDateTime")
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import ${BaseDOClassName};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${subTable.classComment} DO
|
||||||
|
*
|
||||||
|
* @author ${subTable.author}
|
||||||
|
*/
|
||||||
|
@TableName("${subTable.tableName.toLowerCase()}")
|
||||||
|
@KeySequence("${subTable.tableName.toLowerCase()}_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class ${subTable.className}DO extends BaseDO {
|
||||||
|
|
||||||
|
#foreach ($column in $subColumns)
|
||||||
|
#if (!${baseDOFields.contains(${column.javaField})})##排除 BaseDO 的字段
|
||||||
|
/**
|
||||||
|
* ${column.columnComment}
|
||||||
|
#if ("$!column.dictType" != "")##处理枚举值
|
||||||
|
*
|
||||||
|
* 枚举 {@link TODO ${column.dictType} 对应的类}
|
||||||
|
#end
|
||||||
|
*/
|
||||||
|
#if (${column.primaryKey})##处理主键
|
||||||
|
@TableId#if (${column.javaType} == 'String')(type = IdType.INPUT)#end
|
||||||
|
#end
|
||||||
|
private ${column.javaType} ${column.javaField};
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,82 @@
|
|||||||
|
package ${basePackage}.module.${table.moduleName}.dal.mysql.${table.businessName};
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import ${PageResultClassName};
|
||||||
|
import ${QueryWrapperClassName};
|
||||||
|
import ${BaseMapperClassName};
|
||||||
|
import ${basePackage}.module.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo.*;
|
||||||
|
|
||||||
|
## 字段模板
|
||||||
|
#macro(listCondition)
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (${column.listOperation})
|
||||||
|
#set ($JavaField = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})##首字母大写
|
||||||
|
#if (${column.listOperationCondition} == "=")##情况一,= 的时候
|
||||||
|
.eqIfPresent(${table.className}DO::get${JavaField}, reqVO.get${JavaField}())
|
||||||
|
#end
|
||||||
|
#if (${column.listOperationCondition} == "!=")##情况二,!= 的时候
|
||||||
|
.neIfPresent(${table.className}DO::get${JavaField}, reqVO.get${JavaField}())
|
||||||
|
#end
|
||||||
|
#if (${column.listOperationCondition} == ">")##情况三,> 的时候
|
||||||
|
.gtIfPresent(${table.className}DO::get${JavaField}, reqVO.get${JavaField}())
|
||||||
|
#end
|
||||||
|
#if (${column.listOperationCondition} == ">=")##情况四,>= 的时候
|
||||||
|
.geIfPresent(${table.className}DO::get${JavaField}, reqVO.get${JavaField}())
|
||||||
|
#end
|
||||||
|
#if (${column.listOperationCondition} == "<")##情况五,< 的时候
|
||||||
|
.ltIfPresent(${table.className}DO::get${JavaField}, reqVO.get${JavaField}())
|
||||||
|
#end
|
||||||
|
#if (${column.listOperationCondition} == "<=")##情况五,<= 的时候
|
||||||
|
.leIfPresent(${table.className}DO::get${JavaField}, reqVO.get${JavaField}())
|
||||||
|
#end
|
||||||
|
#if (${column.listOperationCondition} == "LIKE")##情况七,Like 的时候
|
||||||
|
.likeIfPresent(${table.className}DO::get${JavaField}, reqVO.get${JavaField}())
|
||||||
|
#end
|
||||||
|
#if (${column.listOperationCondition} == "BETWEEN")##情况八,Between 的时候
|
||||||
|
.betweenIfPresent(${table.className}DO::get${JavaField}, reqVO.get${JavaField}())
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
/**
|
||||||
|
* ${table.classComment} Mapper
|
||||||
|
*
|
||||||
|
* @author ${table.author}
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface ${table.className}Mapper extends BaseMapperX<${table.className}DO> {
|
||||||
|
|
||||||
|
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||||
|
#if ( $table.templateType != 2 )
|
||||||
|
default PageResult<${table.className}DO> selectPage(${sceneEnum.prefixClass}${table.className}PageReqVO reqVO) {
|
||||||
|
return selectPage(reqVO, new LambdaQueryWrapperX<${table.className}DO>()
|
||||||
|
#listCondition()
|
||||||
|
.orderByDesc(${table.className}DO::getId));## 大多数情况下,id 倒序
|
||||||
|
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
default List<${table.className}DO> selectList(${sceneEnum.prefixClass}${table.className}ListReqVO reqVO) {
|
||||||
|
return selectList(new LambdaQueryWrapperX<${table.className}DO>()
|
||||||
|
#listCondition()
|
||||||
|
.orderByDesc(${table.className}DO::getId));## 大多数情况下,id 倒序
|
||||||
|
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
#set ($TreeParentJavaField = $treeParentColumn.javaField.substring(0,1).toUpperCase() + ${treeParentColumn.javaField.substring(1)})##首字母大写
|
||||||
|
#set ($TreeNameJavaField = $treeNameColumn.javaField.substring(0,1).toUpperCase() + ${treeNameColumn.javaField.substring(1)})##首字母大写
|
||||||
|
default ${table.className}DO selectBy${TreeParentJavaField}And${TreeNameJavaField}(Long ${treeParentColumn.javaField}, String ${treeNameColumn.javaField}) {
|
||||||
|
return selectOne(${table.className}DO::get${TreeParentJavaField}, ${treeParentColumn.javaField}, ${table.className}DO::get${TreeNameJavaField}, ${treeNameColumn.javaField});
|
||||||
|
}
|
||||||
|
|
||||||
|
default Long selectCountBy${TreeParentJavaField}(${treeParentColumn.javaType} ${treeParentColumn.javaField}) {
|
||||||
|
return selectCount(${table.className}DO::get${TreeParentJavaField}, ${treeParentColumn.javaField});
|
||||||
|
}
|
||||||
|
|
||||||
|
#end
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="${basePackage}.module.${table.moduleName}.dal.mysql.${table.businessName}.${table.className}Mapper">
|
||||||
|
|
||||||
|
<!--
|
||||||
|
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||||
|
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||||
|
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||||
|
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||||
|
-->
|
||||||
|
|
||||||
|
</mapper>
|
@ -0,0 +1,57 @@
|
|||||||
|
#set ($subTable = $subTables.get($subIndex))##当前表
|
||||||
|
#set ($subColumns = $subJoinColumnsList.get($subIndex))##当前字段数组
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
|
||||||
|
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||||
|
package ${basePackage}.module.${subTable.moduleName}.dal.mysql.${subTable.businessName};
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import ${PageResultClassName};
|
||||||
|
import ${PageParamClassName};
|
||||||
|
import ${QueryWrapperClassName};
|
||||||
|
import ${BaseMapperClassName};
|
||||||
|
import ${basePackage}.module.${subTable.moduleName}.dal.dataobject.${subTable.businessName}.${subTable.className}DO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${subTable.classComment} Mapper
|
||||||
|
*
|
||||||
|
* @author ${subTable.author}
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface ${subTable.className}Mapper extends BaseMapperX<${subTable.className}DO> {
|
||||||
|
|
||||||
|
## 情况一:MASTER_ERP 时,需要分查询页子表
|
||||||
|
#if ( $table.templateType == 11 )
|
||||||
|
default PageResult<${subTable.className}DO> selectPage(PageParam reqVO, ${subJoinColumn.javaType} ${subJoinColumn.javaField}) {
|
||||||
|
return selectPage(reqVO, new LambdaQueryWrapperX<${subTable.className}DO>()
|
||||||
|
.eq(${subTable.className}DO::get${SubJoinColumnName}, ${subJoinColumn.javaField})
|
||||||
|
.orderByDesc(${subTable.className}DO::getId));## 大多数情况下,id 倒序
|
||||||
|
|
||||||
|
}
|
||||||
|
## 主表与子表是一对一时
|
||||||
|
#if (!$subTable.subJoinMany)
|
||||||
|
default ${subTable.className}DO selectBy${SubJoinColumnName}(${subJoinColumn.javaType} ${subJoinColumn.javaField}) {
|
||||||
|
return selectOne(${subTable.className}DO::get${SubJoinColumnName}, ${subJoinColumn.javaField});
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
|
||||||
|
## 情况二:非 MASTER_ERP 时,需要列表查询子表
|
||||||
|
#else
|
||||||
|
#if ( $subTable.subJoinMany)
|
||||||
|
default List<${subTable.className}DO> selectListBy${SubJoinColumnName}(${subJoinColumn.javaType} ${subJoinColumn.javaField}) {
|
||||||
|
return selectList(${subTable.className}DO::get${SubJoinColumnName}, ${subJoinColumn.javaField});
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
default ${subTable.className}DO selectBy${SubJoinColumnName}(${subJoinColumn.javaType} ${subJoinColumn.javaField}) {
|
||||||
|
return selectOne(${subTable.className}DO::get${SubJoinColumnName}, ${subJoinColumn.javaField});
|
||||||
|
}
|
||||||
|
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
default int deleteBy${SubJoinColumnName}(${subJoinColumn.javaType} ${subJoinColumn.javaField}) {
|
||||||
|
return delete(${subTable.className}DO::get${SubJoinColumnName}, ${subJoinColumn.javaField});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
// TODO 待办:请将下面的错误码复制到 yudao-module-${table.moduleName}-api 模块的 ErrorCodeConstants 类中。注意,请给“TODO 补充编号”设置一个错误码编号!!!
|
||||||
|
// ========== ${table.classComment} TODO 补充编号 ==========
|
||||||
|
ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS = new ErrorCode(TODO 补充编号, "${table.classComment}不存在");
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_EXITS_CHILDREN = new ErrorCode(TODO 补充编号, "存在存在子${table.classComment},无法删除");
|
||||||
|
ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_PARENT_NOT_EXITS = new ErrorCode(TODO 补充编号,"父级${table.classComment}不存在");
|
||||||
|
ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_PARENT_ERROR = new ErrorCode(TODO 补充编号, "不能设置自己为父${table.classComment}");
|
||||||
|
ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_${treeNameColumn_javaField_underlineCase.toUpperCase()}_DUPLICATE = new ErrorCode(TODO 补充编号, "已经存在该${treeNameColumn.columnComment}的${table.classComment}");
|
||||||
|
ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_PARENT_IS_CHILD = new ErrorCode(TODO 补充编号, "不能设置自己的子${table.className}为父${table.className}");
|
||||||
|
#end
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 11 )## 特殊:ERP 情况
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($simpleClassNameUnderlineCase = $simpleClassNameUnderlineCases.get($index))
|
||||||
|
ErrorCode ${simpleClassNameUnderlineCase.toUpperCase()}_NOT_EXISTS = new ErrorCode(TODO 补充编号, "${subTable.classComment}不存在");
|
||||||
|
#if ( !$subTable.subJoinMany )
|
||||||
|
ErrorCode ${simpleClassNameUnderlineCase.toUpperCase()}_EXISTS = new ErrorCode(TODO 补充编号, "${subTable.classComment}已存在");
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
@ -0,0 +1,147 @@
|
|||||||
|
package ${basePackage}.module.${table.moduleName}.service.${table.businessName};
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import ${jakartaPackage}.validation.*;
|
||||||
|
import ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo.*;
|
||||||
|
import ${basePackage}.module.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO;
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
import ${basePackage}.module.${subTable.moduleName}.dal.dataobject.${subTable.businessName}.${subTable.className}DO;
|
||||||
|
#end
|
||||||
|
import ${PageResultClassName};
|
||||||
|
import ${PageParamClassName};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${table.classComment} Service 接口
|
||||||
|
*
|
||||||
|
* @author ${table.author}
|
||||||
|
*/
|
||||||
|
public interface ${table.className}Service {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建${table.classComment}
|
||||||
|
*
|
||||||
|
* @param createReqVO 创建信息
|
||||||
|
* @return 编号
|
||||||
|
*/
|
||||||
|
${primaryColumn.javaType} create${simpleClassName}(@Valid ${sceneEnum.prefixClass}${table.className}SaveReqVO createReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新${table.classComment}
|
||||||
|
*
|
||||||
|
* @param updateReqVO 更新信息
|
||||||
|
*/
|
||||||
|
void update${simpleClassName}(@Valid ${sceneEnum.prefixClass}${table.className}SaveReqVO updateReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除${table.classComment}
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
*/
|
||||||
|
void delete${simpleClassName}(${primaryColumn.javaType} id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得${table.classComment}
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
* @return ${table.classComment}
|
||||||
|
*/
|
||||||
|
${table.className}DO get${simpleClassName}(${primaryColumn.javaType} id);
|
||||||
|
|
||||||
|
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||||
|
#if ( $table.templateType != 2 )
|
||||||
|
/**
|
||||||
|
* 获得${table.classComment}分页
|
||||||
|
*
|
||||||
|
* @param pageReqVO 分页查询
|
||||||
|
* @return ${table.classComment}分页
|
||||||
|
*/
|
||||||
|
PageResult<${table.className}DO> get${simpleClassName}Page(${sceneEnum.prefixClass}${table.className}PageReqVO pageReqVO);
|
||||||
|
#else
|
||||||
|
/**
|
||||||
|
* 获得${table.classComment}列表
|
||||||
|
*
|
||||||
|
* @param listReqVO 查询条件
|
||||||
|
* @return ${table.classComment}列表
|
||||||
|
*/
|
||||||
|
List<${table.className}DO> get${simpleClassName}List(${sceneEnum.prefixClass}${table.className}ListReqVO listReqVO);
|
||||||
|
#end
|
||||||
|
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
#set ($subPrimaryColumn = $subPrimaryColumns.get($index))##当前 primary 字段
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
|
||||||
|
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||||
|
// ==================== 子表($subTable.classComment) ====================
|
||||||
|
|
||||||
|
## 情况一:MASTER_ERP 时,需要分查询页子表
|
||||||
|
#if ( $table.templateType == 11 )
|
||||||
|
/**
|
||||||
|
* 获得${subTable.classComment}分页
|
||||||
|
*
|
||||||
|
* @param pageReqVO 分页查询
|
||||||
|
* @param ${subJoinColumn.javaField} ${subJoinColumn.columnComment}
|
||||||
|
* @return ${subTable.classComment}分页
|
||||||
|
*/
|
||||||
|
PageResult<${subTable.className}DO> get${subSimpleClassName}Page(PageParam pageReqVO, ${subJoinColumn.javaType} ${subJoinColumn.javaField});
|
||||||
|
|
||||||
|
## 情况二:非 MASTER_ERP 时,需要列表查询子表
|
||||||
|
#else
|
||||||
|
#if ( $subTable.subJoinMany )
|
||||||
|
/**
|
||||||
|
* 获得${subTable.classComment}列表
|
||||||
|
*
|
||||||
|
* @param ${subJoinColumn.javaField} ${subJoinColumn.columnComment}
|
||||||
|
* @return ${subTable.classComment}列表
|
||||||
|
*/
|
||||||
|
List<${subTable.className}DO> get${subSimpleClassName}ListBy${SubJoinColumnName}(${subJoinColumn.javaType} ${subJoinColumn.javaField});
|
||||||
|
|
||||||
|
#else
|
||||||
|
/**
|
||||||
|
* 获得${subTable.classComment}
|
||||||
|
*
|
||||||
|
* @param ${subJoinColumn.javaField} ${subJoinColumn.columnComment}
|
||||||
|
* @return ${subTable.classComment}
|
||||||
|
*/
|
||||||
|
${subTable.className}DO get${subSimpleClassName}By${SubJoinColumnName}(${subJoinColumn.javaType} ${subJoinColumn.javaField});
|
||||||
|
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
## 特殊:MASTER_ERP 时,支持单个的新增、修改、删除操作
|
||||||
|
#if ( $table.templateType == 11 )
|
||||||
|
/**
|
||||||
|
* 创建${subTable.classComment}
|
||||||
|
*
|
||||||
|
* @param ${subClassNameVar} 创建信息
|
||||||
|
* @return 编号
|
||||||
|
*/
|
||||||
|
${subPrimaryColumn.javaType} create${subSimpleClassName}(@Valid ${subTable.className}DO ${subClassNameVar});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新${subTable.classComment}
|
||||||
|
*
|
||||||
|
* @param ${subClassNameVar} 更新信息
|
||||||
|
*/
|
||||||
|
void update${subSimpleClassName}(@Valid ${subTable.className}DO ${subClassNameVar});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除${subTable.classComment}
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
*/
|
||||||
|
void delete${subSimpleClassName}(${subPrimaryColumn.javaType} id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得${subTable.classComment}
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
* @return ${subTable.classComment}
|
||||||
|
*/
|
||||||
|
${subTable.className}DO get${subSimpleClassName}(${subPrimaryColumn.javaType} id);
|
||||||
|
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
@ -0,0 +1,350 @@
|
|||||||
|
package ${basePackage}.module.${table.moduleName}.service.${table.businessName};
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ${jakartaPackage}.annotation.Resource;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo.*;
|
||||||
|
import ${basePackage}.module.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO;
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
import ${basePackage}.module.${subTable.moduleName}.dal.dataobject.${subTable.businessName}.${subTable.className}DO;
|
||||||
|
#end
|
||||||
|
import ${PageResultClassName};
|
||||||
|
import ${PageParamClassName};
|
||||||
|
import ${BeanUtils};
|
||||||
|
|
||||||
|
import ${basePackage}.module.${table.moduleName}.dal.mysql.${table.businessName}.${table.className}Mapper;
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
import ${basePackage}.module.${subTable.moduleName}.dal.mysql.${subTable.businessName}.${subTable.className}Mapper;
|
||||||
|
#end
|
||||||
|
|
||||||
|
import static ${ServiceExceptionUtilClassName}.exception;
|
||||||
|
import static ${basePackage}.module.${table.moduleName}.enums.ErrorCodeConstants.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${table.classComment} Service 实现类
|
||||||
|
*
|
||||||
|
* @author ${table.author}
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Validated
|
||||||
|
public class ${table.className}ServiceImpl implements ${table.className}Service {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ${table.className}Mapper ${classNameVar}Mapper;
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
@Resource
|
||||||
|
private ${subTable.className}Mapper ${subClassNameVars.get($index)}Mapper;
|
||||||
|
#end
|
||||||
|
|
||||||
|
@Override
|
||||||
|
## 特殊:主子表专属逻辑(非 ERP 模式)
|
||||||
|
#if ( $subTables && $subTables.size() > 0 && $table.templateType != 11 )
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
#end
|
||||||
|
public ${primaryColumn.javaType} create${simpleClassName}(${sceneEnum.prefixClass}${table.className}SaveReqVO createReqVO) {
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
#set ($TreeParentJavaField = $treeParentColumn.javaField.substring(0,1).toUpperCase() + ${treeParentColumn.javaField.substring(1)})##首字母大写
|
||||||
|
#set ($TreeNameJavaField = $treeNameColumn.javaField.substring(0,1).toUpperCase() + ${treeNameColumn.javaField.substring(1)})##首字母大写
|
||||||
|
// 校验${treeParentColumn.columnComment}的有效性
|
||||||
|
validateParent${simpleClassName}(null, createReqVO.get${TreeParentJavaField}());
|
||||||
|
// 校验${treeNameColumn.columnComment}的唯一性
|
||||||
|
validate${simpleClassName}${TreeNameJavaField}Unique(null, createReqVO.get${TreeParentJavaField}(), createReqVO.get${TreeNameJavaField}());
|
||||||
|
|
||||||
|
#end
|
||||||
|
// 插入
|
||||||
|
${table.className}DO ${classNameVar} = BeanUtils.toBean(createReqVO, ${table.className}DO.class);
|
||||||
|
${classNameVar}Mapper.insert(${classNameVar});
|
||||||
|
## 特殊:主子表专属逻辑(非 ERP 模式)
|
||||||
|
#if ( $subTables && $subTables.size() > 0 && $table.templateType != 11 )
|
||||||
|
|
||||||
|
// 插入子表
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
|
||||||
|
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||||
|
#if ( $subTable.subJoinMany)
|
||||||
|
create${subSimpleClassName}List(${classNameVar}.getId(), createReqVO.get${subSimpleClassNames.get($index)}s());
|
||||||
|
#else
|
||||||
|
create${subSimpleClassName}(${classNameVar}.getId(), createReqVO.get${subSimpleClassNames.get($index)}());
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
// 返回
|
||||||
|
return ${classNameVar}.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
## 特殊:主子表专属逻辑(非 ERP 模式)
|
||||||
|
#if ( $subTables && $subTables.size() > 0 && $table.templateType != 11 )
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
#end
|
||||||
|
public void update${simpleClassName}(${sceneEnum.prefixClass}${table.className}SaveReqVO updateReqVO) {
|
||||||
|
// 校验存在
|
||||||
|
validate${simpleClassName}Exists(updateReqVO.getId());
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
#set ($TreeParentJavaField = $treeParentColumn.javaField.substring(0,1).toUpperCase() + ${treeParentColumn.javaField.substring(1)})##首字母大写
|
||||||
|
#set ($TreeNameJavaField = $treeNameColumn.javaField.substring(0,1).toUpperCase() + ${treeNameColumn.javaField.substring(1)})##首字母大写
|
||||||
|
// 校验${treeParentColumn.columnComment}的有效性
|
||||||
|
validateParent${simpleClassName}(updateReqVO.getId(), updateReqVO.get${TreeParentJavaField}());
|
||||||
|
// 校验${treeNameColumn.columnComment}的唯一性
|
||||||
|
validate${simpleClassName}${TreeNameJavaField}Unique(updateReqVO.getId(), updateReqVO.get${TreeParentJavaField}(), updateReqVO.get${TreeNameJavaField}());
|
||||||
|
|
||||||
|
#end
|
||||||
|
// 更新
|
||||||
|
${table.className}DO updateObj = BeanUtils.toBean(updateReqVO, ${table.className}DO.class);
|
||||||
|
${classNameVar}Mapper.updateById(updateObj);
|
||||||
|
## 特殊:主子表专属逻辑(非 ERP 模式)
|
||||||
|
#if ( $subTables && $subTables.size() > 0 && $table.templateType != 11)
|
||||||
|
|
||||||
|
// 更新子表
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
|
||||||
|
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||||
|
#if ( $subTable.subJoinMany)
|
||||||
|
update${subSimpleClassName}List(updateReqVO.getId(), updateReqVO.get${subSimpleClassNames.get($index)}s());
|
||||||
|
#else
|
||||||
|
update${subSimpleClassName}(updateReqVO.getId(), updateReqVO.get${subSimpleClassNames.get($index)}());
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $subTables && $subTables.size() > 0)
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
#end
|
||||||
|
public void delete${simpleClassName}(${primaryColumn.javaType} id) {
|
||||||
|
// 校验存在
|
||||||
|
validate${simpleClassName}Exists(id);
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
#set ($ParentJavaField = $treeParentColumn.javaField.substring(0,1).toUpperCase() + ${treeParentColumn.javaField.substring(1)})##首字母大写
|
||||||
|
// 校验是否有子${table.classComment}
|
||||||
|
if (${classNameVar}Mapper.selectCountBy${ParentJavaField}(id) > 0) {
|
||||||
|
throw exception(${simpleClassName_underlineCase.toUpperCase()}_EXITS_CHILDREN);
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
// 删除
|
||||||
|
${classNameVar}Mapper.deleteById(id);
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $subTables && $subTables.size() > 0)
|
||||||
|
|
||||||
|
// 删除子表
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
|
||||||
|
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||||
|
delete${subSimpleClassName}By${SubJoinColumnName}(id);
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validate${simpleClassName}Exists(${primaryColumn.javaType} id) {
|
||||||
|
if (${classNameVar}Mapper.selectById(id) == null) {
|
||||||
|
throw exception(${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
#set ($TreeParentJavaField = $treeParentColumn.javaField.substring(0,1).toUpperCase() + ${treeParentColumn.javaField.substring(1)})##首字母大写
|
||||||
|
#set ($TreeNameJavaField = $treeNameColumn.javaField.substring(0,1).toUpperCase() + ${treeNameColumn.javaField.substring(1)})##首字母大写
|
||||||
|
private void validateParent${simpleClassName}(Long id, Long ${treeParentColumn.javaField}) {
|
||||||
|
if (${treeParentColumn.javaField} == null || ${simpleClassName}DO.${treeParentColumn_javaField_underlineCase.toUpperCase()}_ROOT.equals(${treeParentColumn.javaField})) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 1. 不能设置自己为父${table.classComment}
|
||||||
|
if (Objects.equals(id, ${treeParentColumn.javaField})) {
|
||||||
|
throw exception(${simpleClassName_underlineCase.toUpperCase()}_PARENT_ERROR);
|
||||||
|
}
|
||||||
|
// 2. 父${table.classComment}不存在
|
||||||
|
${simpleClassName}DO parent${simpleClassName} = ${classNameVar}Mapper.selectById(${treeParentColumn.javaField});
|
||||||
|
if (parent${simpleClassName} == null) {
|
||||||
|
throw exception(${simpleClassName_underlineCase.toUpperCase()}_PARENT_NOT_EXITS);
|
||||||
|
}
|
||||||
|
// 3. 递归校验父${table.classComment},如果父${table.classComment}是自己的子${table.classComment},则报错,避免形成环路
|
||||||
|
if (id == null) { // id 为空,说明新增,不需要考虑环路
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < Short.MAX_VALUE; i++) {
|
||||||
|
// 3.1 校验环路
|
||||||
|
${treeParentColumn.javaField} = parent${simpleClassName}.get${TreeParentJavaField}();
|
||||||
|
if (Objects.equals(id, ${treeParentColumn.javaField})) {
|
||||||
|
throw exception(${simpleClassName_underlineCase.toUpperCase()}_PARENT_IS_CHILD);
|
||||||
|
}
|
||||||
|
// 3.2 继续递归下一级父${table.classComment}
|
||||||
|
if (${treeParentColumn.javaField} == null || ${simpleClassName}DO.${treeParentColumn_javaField_underlineCase.toUpperCase()}_ROOT.equals(${treeParentColumn.javaField})) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
parent${simpleClassName} = ${classNameVar}Mapper.selectById(${treeParentColumn.javaField});
|
||||||
|
if (parent${simpleClassName} == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validate${simpleClassName}${TreeNameJavaField}Unique(Long id, Long ${treeParentColumn.javaField}, String ${treeNameColumn.javaField}) {
|
||||||
|
${simpleClassName}DO ${classNameVar} = ${classNameVar}Mapper.selectBy${TreeParentJavaField}And${TreeNameJavaField}(${treeParentColumn.javaField}, ${treeNameColumn.javaField});
|
||||||
|
if (${classNameVar} == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 如果 id 为空,说明不用比较是否为相同 id 的${table.classComment}
|
||||||
|
if (id == null) {
|
||||||
|
throw exception(${simpleClassName_underlineCase.toUpperCase()}_${treeNameColumn_javaField_underlineCase.toUpperCase()}_DUPLICATE);
|
||||||
|
}
|
||||||
|
if (!Objects.equals(${classNameVar}.getId(), id)) {
|
||||||
|
throw exception(${simpleClassName_underlineCase.toUpperCase()}_${treeNameColumn_javaField_underlineCase.toUpperCase()}_DUPLICATE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#end
|
||||||
|
@Override
|
||||||
|
public ${table.className}DO get${simpleClassName}(${primaryColumn.javaType} id) {
|
||||||
|
return ${classNameVar}Mapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||||
|
#if ( $table.templateType != 2 )
|
||||||
|
@Override
|
||||||
|
public PageResult<${table.className}DO> get${simpleClassName}Page(${sceneEnum.prefixClass}${table.className}PageReqVO pageReqVO) {
|
||||||
|
return ${classNameVar}Mapper.selectPage(pageReqVO);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public List<${table.className}DO> get${simpleClassName}List(${sceneEnum.prefixClass}${table.className}ListReqVO listReqVO) {
|
||||||
|
return ${classNameVar}Mapper.selectList(listReqVO);
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
#set ($simpleClassNameUnderlineCase = $simpleClassNameUnderlineCases.get($index))
|
||||||
|
#set ($subPrimaryColumn = $subPrimaryColumns.get($index))##当前 primary 字段
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
|
||||||
|
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||||
|
// ==================== 子表($subTable.classComment) ====================
|
||||||
|
|
||||||
|
## 情况一:MASTER_ERP 时,需要分查询页子表
|
||||||
|
#if ( $table.templateType == 11 )
|
||||||
|
@Override
|
||||||
|
public PageResult<${subTable.className}DO> get${subSimpleClassName}Page(PageParam pageReqVO, ${subJoinColumn.javaType} ${subJoinColumn.javaField}) {
|
||||||
|
return ${subClassNameVars.get($index)}Mapper.selectPage(pageReqVO, ${subJoinColumn.javaField});
|
||||||
|
}
|
||||||
|
|
||||||
|
## 情况二:非 MASTER_ERP 时,需要列表查询子表
|
||||||
|
#else
|
||||||
|
#if ( $subTable.subJoinMany )
|
||||||
|
@Override
|
||||||
|
public List<${subTable.className}DO> get${subSimpleClassName}ListBy${SubJoinColumnName}(${subJoinColumn.javaType} ${subJoinColumn.javaField}) {
|
||||||
|
return ${subClassNameVars.get($index)}Mapper.selectListBy${SubJoinColumnName}(${subJoinColumn.javaField});
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public ${subTable.className}DO get${subSimpleClassName}By${SubJoinColumnName}(${subJoinColumn.javaType} ${subJoinColumn.javaField}) {
|
||||||
|
return ${subClassNameVars.get($index)}Mapper.selectBy${SubJoinColumnName}(${subJoinColumn.javaField});
|
||||||
|
}
|
||||||
|
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
## 情况一:MASTER_ERP 时,支持单个的新增、修改、删除操作
|
||||||
|
#if ( $table.templateType == 11 )
|
||||||
|
@Override
|
||||||
|
public ${subPrimaryColumn.javaType} create${subSimpleClassName}(${subTable.className}DO ${subClassNameVar}) {
|
||||||
|
## 特殊:一对一时,需要保证只有一条,不能重复插入
|
||||||
|
#if ( !$subTable.subJoinMany)
|
||||||
|
// 校验是否已经存在
|
||||||
|
if (${subClassNameVars.get($index)}Mapper.selectBy${SubJoinColumnName}(${subClassNameVar}.get${SubJoinColumnName}()) != null) {
|
||||||
|
throw exception(${simpleClassNameUnderlineCase.toUpperCase()}_EXISTS);
|
||||||
|
}
|
||||||
|
// 插入
|
||||||
|
#end
|
||||||
|
${subClassNameVars.get($index)}Mapper.insert(${subClassNameVar});
|
||||||
|
return ${subClassNameVar}.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update${subSimpleClassName}(${subTable.className}DO ${subClassNameVar}) {
|
||||||
|
// 校验存在
|
||||||
|
validate${subSimpleClassName}Exists(${subClassNameVar}.getId());
|
||||||
|
// 更新
|
||||||
|
${subClassNameVars.get($index)}Mapper.updateById(${subClassNameVar});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete${subSimpleClassName}(${subPrimaryColumn.javaType} id) {
|
||||||
|
// 校验存在
|
||||||
|
validate${subSimpleClassName}Exists(id);
|
||||||
|
// 删除
|
||||||
|
${subClassNameVars.get($index)}Mapper.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ${subTable.className}DO get${subSimpleClassName}(${subPrimaryColumn.javaType} id) {
|
||||||
|
return ${subClassNameVars.get($index)}Mapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validate${subSimpleClassName}Exists(${subPrimaryColumn.javaType} id) {
|
||||||
|
if (${subClassNameVar}Mapper.selectById(id) == null) {
|
||||||
|
throw exception(${simpleClassNameUnderlineCase.toUpperCase()}_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
## 情况二:非 MASTER_ERP 时,支持批量的新增、修改操作
|
||||||
|
#else
|
||||||
|
#if ( $subTable.subJoinMany)
|
||||||
|
private void create${subSimpleClassName}List(${primaryColumn.javaType} ${subJoinColumn.javaField}, List<${subTable.className}DO> list) {
|
||||||
|
list.forEach(o -> o.set$SubJoinColumnName(${subJoinColumn.javaField}));
|
||||||
|
${subClassNameVars.get($index)}Mapper.insertBatch(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void update${subSimpleClassName}List(${primaryColumn.javaType} ${subJoinColumn.javaField}, List<${subTable.className}DO> list) {
|
||||||
|
delete${subSimpleClassName}By${SubJoinColumnName}(${subJoinColumn.javaField});
|
||||||
|
list.forEach(o -> o.setId(null).setUpdater(null).setUpdateTime(null)); // 解决更新情况下:1)id 冲突;2)updateTime 不更新
|
||||||
|
create${subSimpleClassName}List(${subJoinColumn.javaField}, list);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
private void create${subSimpleClassName}(${primaryColumn.javaType} ${subJoinColumn.javaField}, ${subTable.className}DO ${subClassNameVar}) {
|
||||||
|
if (${subClassNameVar} == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
${subClassNameVar}.set$SubJoinColumnName(${subJoinColumn.javaField});
|
||||||
|
${subClassNameVars.get($index)}Mapper.insert(${subClassNameVar});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void update${subSimpleClassName}(${primaryColumn.javaType} ${subJoinColumn.javaField}, ${subTable.className}DO ${subClassNameVar}) {
|
||||||
|
if (${subClassNameVar} == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
${subClassNameVar}.set$SubJoinColumnName(${subJoinColumn.javaField});
|
||||||
|
${subClassNameVar}.setUpdater(null).setUpdateTime(null); // 解决更新情况下:updateTime 不更新
|
||||||
|
${subClassNameVars.get($index)}Mapper.insertOrUpdate(${subClassNameVar});
|
||||||
|
}
|
||||||
|
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
private void delete${subSimpleClassName}By${SubJoinColumnName}(${primaryColumn.javaType} ${subJoinColumn.javaField}) {
|
||||||
|
${subClassNameVars.get($index)}Mapper.deleteBy${SubJoinColumnName}(${subJoinColumn.javaField});
|
||||||
|
}
|
||||||
|
|
||||||
|
#end
|
||||||
|
}
|
@ -0,0 +1,168 @@
|
|||||||
|
package ${basePackage}.module.${table.moduleName}.service.${table.businessName};
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
|
|
||||||
|
import ${jakartaPackage}.annotation.Resource;
|
||||||
|
|
||||||
|
import ${baseFrameworkPackage}.test.core.ut.BaseDbUnitTest;
|
||||||
|
|
||||||
|
import ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo.*;
|
||||||
|
import ${basePackage}.module.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO;
|
||||||
|
import ${basePackage}.module.${table.moduleName}.dal.mysql.${table.businessName}.${table.className}Mapper;
|
||||||
|
import ${PageResultClassName};
|
||||||
|
|
||||||
|
import ${jakartaPackage}.annotation.Resource;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import java.util.*;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import static cn.hutool.core.util.RandomUtil.*;
|
||||||
|
import static ${basePackage}.module.${table.moduleName}.enums.ErrorCodeConstants.*;
|
||||||
|
import static ${baseFrameworkPackage}.test.core.util.AssertUtils.*;
|
||||||
|
import static ${baseFrameworkPackage}.test.core.util.RandomUtils.*;
|
||||||
|
import static ${LocalDateTimeUtilsClassName}.*;
|
||||||
|
import static ${ObjectUtilsClassName}.*;
|
||||||
|
import static ${DateUtilsClassName}.*;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
## 字段模板
|
||||||
|
#macro(getPageCondition $VO)
|
||||||
|
// mock 数据
|
||||||
|
${table.className}DO db${simpleClassName} = randomPojo(${table.className}DO.class, o -> { // 等会查询到
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (${column.listOperation})
|
||||||
|
#set ($JavaField = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})##首字母大写
|
||||||
|
o.set$JavaField(null);
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
});
|
||||||
|
${classNameVar}Mapper.insert(db${simpleClassName});
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (${column.listOperation})
|
||||||
|
#set ($JavaField = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})##首字母大写
|
||||||
|
// 测试 ${column.javaField} 不匹配
|
||||||
|
${classNameVar}Mapper.insert(cloneIgnoreId(db${simpleClassName}, o -> o.set$JavaField(null)));
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
// 准备参数
|
||||||
|
${sceneEnum.prefixClass}${table.className}${VO} reqVO = new ${sceneEnum.prefixClass}${table.className}${VO}();
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (${column.listOperation})
|
||||||
|
#set ($JavaField = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})##首字母大写
|
||||||
|
#if (${column.listOperationCondition} == "BETWEEN")## BETWEEN 的情况
|
||||||
|
reqVO.set${JavaField}(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||||
|
#else
|
||||||
|
reqVO.set$JavaField(null);
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
/**
|
||||||
|
* {@link ${table.className}ServiceImpl} 的单元测试类
|
||||||
|
*
|
||||||
|
* @author ${table.author}
|
||||||
|
*/
|
||||||
|
@Import(${table.className}ServiceImpl.class)
|
||||||
|
public class ${table.className}ServiceImplTest extends BaseDbUnitTest {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ${table.className}ServiceImpl ${classNameVar}Service;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ${table.className}Mapper ${classNameVar}Mapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreate${simpleClassName}_success() {
|
||||||
|
// 准备参数
|
||||||
|
${sceneEnum.prefixClass}${table.className}SaveReqVO createReqVO = randomPojo(${sceneEnum.prefixClass}${table.className}SaveReqVO.class).setId(null);
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
${primaryColumn.javaType} ${classNameVar}Id = ${classNameVar}Service.create${simpleClassName}(createReqVO);
|
||||||
|
// 断言
|
||||||
|
assertNotNull(${classNameVar}Id);
|
||||||
|
// 校验记录的属性是否正确
|
||||||
|
${table.className}DO ${classNameVar} = ${classNameVar}Mapper.selectById(${classNameVar}Id);
|
||||||
|
assertPojoEquals(createReqVO, ${classNameVar}, "id");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdate${simpleClassName}_success() {
|
||||||
|
// mock 数据
|
||||||
|
${table.className}DO db${simpleClassName} = randomPojo(${table.className}DO.class);
|
||||||
|
${classNameVar}Mapper.insert(db${simpleClassName});// @Sql: 先插入出一条存在的数据
|
||||||
|
// 准备参数
|
||||||
|
${sceneEnum.prefixClass}${table.className}SaveReqVO updateReqVO = randomPojo(${sceneEnum.prefixClass}${table.className}SaveReqVO.class, o -> {
|
||||||
|
o.setId(db${simpleClassName}.getId()); // 设置更新的 ID
|
||||||
|
});
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
${classNameVar}Service.update${simpleClassName}(updateReqVO);
|
||||||
|
// 校验是否更新正确
|
||||||
|
${table.className}DO ${classNameVar} = ${classNameVar}Mapper.selectById(updateReqVO.getId()); // 获取最新的
|
||||||
|
assertPojoEquals(updateReqVO, ${classNameVar});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdate${simpleClassName}_notExists() {
|
||||||
|
// 准备参数
|
||||||
|
${sceneEnum.prefixClass}${table.className}SaveReqVO updateReqVO = randomPojo(${sceneEnum.prefixClass}${table.className}SaveReqVO.class);
|
||||||
|
|
||||||
|
// 调用, 并断言异常
|
||||||
|
assertServiceException(() -> ${classNameVar}Service.update${simpleClassName}(updateReqVO), ${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDelete${simpleClassName}_success() {
|
||||||
|
// mock 数据
|
||||||
|
${table.className}DO db${simpleClassName} = randomPojo(${table.className}DO.class);
|
||||||
|
${classNameVar}Mapper.insert(db${simpleClassName});// @Sql: 先插入出一条存在的数据
|
||||||
|
// 准备参数
|
||||||
|
${primaryColumn.javaType} id = db${simpleClassName}.getId();
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
${classNameVar}Service.delete${simpleClassName}(id);
|
||||||
|
// 校验数据不存在了
|
||||||
|
assertNull(${classNameVar}Mapper.selectById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDelete${simpleClassName}_notExists() {
|
||||||
|
// 准备参数
|
||||||
|
${primaryColumn.javaType} id = random${primaryColumn.javaType}Id();
|
||||||
|
|
||||||
|
// 调用, 并断言异常
|
||||||
|
assertServiceException(() -> ${classNameVar}Service.delete${simpleClassName}(id), ${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||||
|
#if ( $table.templateType != 2 )
|
||||||
|
@Test
|
||||||
|
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||||
|
public void testGet${simpleClassName}Page() {
|
||||||
|
#getPageCondition("PageReqVO")
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
PageResult<${table.className}DO> pageResult = ${classNameVar}Service.get${simpleClassName}Page(reqVO);
|
||||||
|
// 断言
|
||||||
|
assertEquals(1, pageResult.getTotal());
|
||||||
|
assertEquals(1, pageResult.getList().size());
|
||||||
|
assertPojoEquals(db${simpleClassName}, pageResult.getList().get(0));
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
@Test
|
||||||
|
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||||
|
public void testGet${simpleClassName}List() {
|
||||||
|
#getPageCondition("ListReqVO")
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}List(reqVO);
|
||||||
|
// 断言
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
assertPojoEquals(db${simpleClassName}, list.get(0));
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
-- 将该建表 SQL 语句,添加到 yudao-module-${table.moduleName}-biz 模块的 test/resources/sql/create_tables.sql 文件里
|
||||||
|
CREATE TABLE IF NOT EXISTS "${table.tableName.toLowerCase()}" (
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (${column.javaType} == 'Long')
|
||||||
|
#set ($dataType='bigint')
|
||||||
|
#elseif (${column.javaType} == 'Integer')
|
||||||
|
#set ($dataType='int')
|
||||||
|
#elseif (${column.javaType} == 'Boolean')
|
||||||
|
#set ($dataType='bit')
|
||||||
|
#elseif (${column.javaType} == 'Date')
|
||||||
|
#set ($dataType='datetime')
|
||||||
|
#else
|
||||||
|
#set ($dataType='varchar')
|
||||||
|
#end
|
||||||
|
#if (${column.primaryKey})##处理主键
|
||||||
|
"${column.javaField}"#if (${column.javaType} == 'String') ${dataType} NOT NULL#else ${dataType} NOT NULL GENERATED BY DEFAULT AS IDENTITY#end,
|
||||||
|
#else
|
||||||
|
#if (${column.columnName} == 'create_time')
|
||||||
|
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
#elseif (${column.columnName} == 'update_time')
|
||||||
|
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
#elseif (${column.columnName} == 'creator' || ${column.columnName} == 'updater')
|
||||||
|
"${column.columnName}" ${dataType} DEFAULT '',
|
||||||
|
#elseif (${column.columnName} == 'deleted')
|
||||||
|
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||||
|
#elseif (${column.columnName} == 'tenantId')
|
||||||
|
"tenant_id" bigint NOT NULL DEFAULT 0,
|
||||||
|
#else
|
||||||
|
"${column.columnName.toLowerCase()}" ${dataType}#if (${column.nullable} == false) NOT NULL#end,
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
PRIMARY KEY ("${primaryColumn.columnName.toLowerCase()}")
|
||||||
|
) COMMENT '${table.tableComment}';
|
||||||
|
|
||||||
|
-- 将该删表 SQL 语句,添加到 yudao-module-${table.moduleName}-biz 模块的 test/resources/sql/clean.sql 文件里
|
||||||
|
DELETE FROM "${table.tableName}";
|
@ -0,0 +1,28 @@
|
|||||||
|
-- 菜单 SQL
|
||||||
|
INSERT INTO system_menu(
|
||||||
|
name, permission, type, sort, parent_id,
|
||||||
|
path, icon, component, status, component_name
|
||||||
|
)
|
||||||
|
VALUES (
|
||||||
|
'${table.classComment}管理', '', 2, 0, ${table.parentMenuId},
|
||||||
|
'${simpleClassName_strikeCase}', '', '${table.moduleName}/${table.businessName}/index', 0, '${table.className}'
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 按钮父菜单ID
|
||||||
|
-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码
|
||||||
|
SELECT @parentId := LAST_INSERT_ID();
|
||||||
|
|
||||||
|
-- 按钮 SQL
|
||||||
|
#set ($functionNames = ['查询', '创建', '更新', '删除', '导出'])
|
||||||
|
#set ($functionOps = ['query', 'create', 'update', 'delete', 'export'])
|
||||||
|
#foreach ($functionName in $functionNames)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
INSERT INTO system_menu(
|
||||||
|
name, permission, type, sort, parent_id,
|
||||||
|
path, icon, component, status
|
||||||
|
)
|
||||||
|
VALUES (
|
||||||
|
'${table.classComment}${functionName}', '${permissionPrefix}:${functionOps.get($index)}', 3, $foreach.count, @parentId,
|
||||||
|
'', '', '', 0
|
||||||
|
);
|
||||||
|
#end
|
@ -0,0 +1,141 @@
|
|||||||
|
import request from '@/utils/request'
|
||||||
|
#set ($baseURL = "/${table.moduleName}/${simpleClassName_strikeCase}")
|
||||||
|
|
||||||
|
// 创建${table.classComment}
|
||||||
|
export function create${simpleClassName}(data) {
|
||||||
|
return request({
|
||||||
|
url: '${baseURL}/create',
|
||||||
|
method: 'post',
|
||||||
|
data: data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新${table.classComment}
|
||||||
|
export function update${simpleClassName}(data) {
|
||||||
|
return request({
|
||||||
|
url: '${baseURL}/update',
|
||||||
|
method: 'put',
|
||||||
|
data: data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除${table.classComment}
|
||||||
|
export function delete${simpleClassName}(id) {
|
||||||
|
return request({
|
||||||
|
url: '${baseURL}/delete?id=' + id,
|
||||||
|
method: 'delete'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获得${table.classComment}
|
||||||
|
export function get${simpleClassName}(id) {
|
||||||
|
return request({
|
||||||
|
url: '${baseURL}/get?id=' + id,
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#if ( $table.templateType != 2 )
|
||||||
|
// 获得${table.classComment}分页
|
||||||
|
export function get${simpleClassName}Page(params) {
|
||||||
|
return request({
|
||||||
|
url: '${baseURL}/page',
|
||||||
|
method: 'get',
|
||||||
|
params
|
||||||
|
})
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
// 获得${table.classComment}列表
|
||||||
|
export function get${simpleClassName}List(params) {
|
||||||
|
return request({
|
||||||
|
url: '${baseURL}/list',
|
||||||
|
method: 'get',
|
||||||
|
params
|
||||||
|
})
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
// 导出${table.classComment} Excel
|
||||||
|
export function export${simpleClassName}Excel(params) {
|
||||||
|
return request({
|
||||||
|
url: '${baseURL}/export-excel',
|
||||||
|
method: 'get',
|
||||||
|
params,
|
||||||
|
responseType: 'blob'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
#set ($subPrimaryColumn = $subPrimaryColumns.get($index))##当前 primary 字段
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
|
||||||
|
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||||
|
#set ($subSimpleClassName_strikeCase = $subSimpleClassName_strikeCases.get($index))
|
||||||
|
#set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||||
|
|
||||||
|
// ==================== 子表($subTable.classComment) ====================
|
||||||
|
## 情况一:MASTER_ERP 时,需要分查询页子表
|
||||||
|
#if ($table.templateType == 11)
|
||||||
|
// 获得${subTable.classComment}分页
|
||||||
|
export function get${subSimpleClassName}Page(params) {
|
||||||
|
return request({
|
||||||
|
url: '${baseURL}/${subSimpleClassName_strikeCase}/page',
|
||||||
|
method: 'get',
|
||||||
|
params
|
||||||
|
})
|
||||||
|
}
|
||||||
|
## 情况二:非 MASTER_ERP 时,需要列表查询子表
|
||||||
|
#else
|
||||||
|
#if ($subTable.subJoinMany)
|
||||||
|
// 获得${subTable.classComment}列表
|
||||||
|
export function get${subSimpleClassName}ListBy${SubJoinColumnName}(${subJoinColumn.javaField}) {
|
||||||
|
return request({
|
||||||
|
url: '${baseURL}/${subSimpleClassName_strikeCase}/list-by-${subJoinColumn_strikeCase}?${subJoinColumn.javaField}=' + ${subJoinColumn.javaField},
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
// 获得${subTable.classComment}
|
||||||
|
export function get${subSimpleClassName}By${SubJoinColumnName}(${subJoinColumn.javaField}) {
|
||||||
|
return request({
|
||||||
|
url: '${baseURL}/${subSimpleClassName_strikeCase}/get-by-${subJoinColumn_strikeCase}?${subJoinColumn.javaField}=' + ${subJoinColumn.javaField},
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
## 特殊:MASTER_ERP 时,支持单个的新增、修改、删除操作
|
||||||
|
#if ($table.templateType == 11)
|
||||||
|
// 新增${subTable.classComment}
|
||||||
|
export function create${subSimpleClassName}(data) {
|
||||||
|
return request({
|
||||||
|
url: '${baseURL}/${subSimpleClassName_strikeCase}/create',
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// 修改${subTable.classComment}
|
||||||
|
export function update${subSimpleClassName}(data) {
|
||||||
|
return request({
|
||||||
|
url: '${baseURL}/${subSimpleClassName_strikeCase}/update',
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// 删除${subTable.classComment}
|
||||||
|
export function delete${subSimpleClassName}(id) {
|
||||||
|
return request({
|
||||||
|
url: '${baseURL}/${subSimpleClassName_strikeCase}/delete?id=' + id,
|
||||||
|
method: 'delete'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// 获得${subTable.classComment}
|
||||||
|
export function get${subSimpleClassName}(id) {
|
||||||
|
return request({
|
||||||
|
url: '${baseURL}/${subSimpleClassName_strikeCase}/get?id=' + id,
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
#end
|
@ -0,0 +1,205 @@
|
|||||||
|
#set ($subTable = $subTables.get($subIndex))##当前表
|
||||||
|
#set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($subIndex))
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
|
||||||
|
<template>
|
||||||
|
<div class="app-container">
|
||||||
|
<!-- 对话框(添加 / 修改) -->
|
||||||
|
<el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="45%" v-dialogDrag append-to-body>
|
||||||
|
<el-form ref="formRef" :model="formData" :rules="formRules" v-loading="formLoading" label-width="100px">
|
||||||
|
#foreach($column in $subColumns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#set ($dictType = $column.dictType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($javaType = $column.javaType)
|
||||||
|
#set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
#set ($comment = $column.columnComment)
|
||||||
|
#if ( $column.id == $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写
|
||||||
|
#elseif ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-input v-model="formData.${javaField}" placeholder="请输入${comment}" />
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "imageUpload")## 图片上传
|
||||||
|
#set ($hasImageUploadColumn = true)
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<ImageUpload v-model="formData.${javaField}"/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "fileUpload")## 文件上传
|
||||||
|
#set ($hasFileUploadColumn = true)
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<FileUpload v-model="formData.${javaField}"/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "editor")## 文本编辑器
|
||||||
|
#set ($hasEditorColumn = true)
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<editor v-model="formData.${javaField}" :min-height="192"/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "select")## 下拉框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-select v-model="formData.${javaField}" placeholder="请选择${comment}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<el-option v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value" :label="dict.label" #if ($column.javaType == "Integer" || $column.javaType == "Long"):value="parseInt(dict.value)"#else:value="dict.value"#end />
|
||||||
|
#else##没数据字典
|
||||||
|
<el-option label="请选择字典生成" value="" />
|
||||||
|
#end
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "checkbox")## 多选框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-checkbox-group v-model="formData.${javaField}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<el-checkbox v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value" #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.value)"#else:label="dict.value"#end>{{dict.label}}</el-checkbox>
|
||||||
|
#else##没数据字典
|
||||||
|
<el-checkbox>请选择字典生成</el-checkbox>
|
||||||
|
#end
|
||||||
|
</el-checkbox-group>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "radio")## 单选框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-radio-group v-model="formData.${javaField}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<el-radio v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value" #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.value)"
|
||||||
|
#else:label="dict.value"#end>{{dict.label}}</el-radio>
|
||||||
|
#else##没数据字典
|
||||||
|
<el-radio label="1">请选择字典生成</el-radio>
|
||||||
|
#end
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "datetime")## 时间框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-date-picker clearable v-model="formData.${javaField}" type="date" value-format="timestamp" placeholder="选择${comment}" />
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "textarea")## 文本框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-input v-model="formData.${javaField}" type="textarea" placeholder="请输入内容" />
|
||||||
|
</el-form-item>
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
</el-form>
|
||||||
|
<div slot="footer" class="dialog-footer">
|
||||||
|
<el-button type="primary" @click="submitForm" :disabled="formLoading">确 定</el-button>
|
||||||
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||||
|
</div>
|
||||||
|
</el-dialog>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}';
|
||||||
|
#if ($hasImageUploadColumn)
|
||||||
|
import ImageUpload from '@/components/ImageUpload';
|
||||||
|
#end
|
||||||
|
#if ($hasFileUploadColumn)
|
||||||
|
import FileUpload from '@/components/FileUpload';
|
||||||
|
#end
|
||||||
|
#if ($hasEditorColumn)
|
||||||
|
import Editor from '@/components/Editor';
|
||||||
|
#end
|
||||||
|
export default {
|
||||||
|
name: "${subSimpleClassName}Form",
|
||||||
|
components: {
|
||||||
|
#if ($hasImageUploadColumn)
|
||||||
|
ImageUpload,
|
||||||
|
#end
|
||||||
|
#if ($hasFileUploadColumn)
|
||||||
|
FileUpload,
|
||||||
|
#end
|
||||||
|
#if ($hasEditorColumn)
|
||||||
|
Editor,
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
// 弹出层标题
|
||||||
|
dialogTitle: "",
|
||||||
|
// 是否显示弹出层
|
||||||
|
dialogVisible: false,
|
||||||
|
// 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||||
|
formLoading: false,
|
||||||
|
// 表单参数
|
||||||
|
formData: {
|
||||||
|
#foreach ($column in $subColumns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#if ($column.htmlType == "checkbox")
|
||||||
|
$column.javaField: [],
|
||||||
|
#else
|
||||||
|
$column.javaField: undefined,
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
// 表单校验
|
||||||
|
formRules: {
|
||||||
|
#foreach ($column in $subColumns)
|
||||||
|
#if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键
|
||||||
|
#set($comment=$column.columnComment)
|
||||||
|
$column.javaField: [{ required: true, message: "${comment}不能为空", trigger: #if($column.htmlType == "select")"change"#else"blur"#end }],
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
/** 打开弹窗 */
|
||||||
|
async open(id, ${subJoinColumn.javaField}) {
|
||||||
|
this.dialogVisible = true;
|
||||||
|
this.reset();
|
||||||
|
this.formData.${subJoinColumn.javaField} = ${subJoinColumn.javaField};
|
||||||
|
// 修改时,设置数据
|
||||||
|
if (id) {
|
||||||
|
this.formLoading = true;
|
||||||
|
try {
|
||||||
|
const res = await ${simpleClassName}Api.get${subSimpleClassName}(id);
|
||||||
|
this.formData = res.data;
|
||||||
|
this.dialogTitle = "修改${subTable.classComment}";
|
||||||
|
} finally {
|
||||||
|
this.formLoading = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.dialogTitle = "新增${subTable.classComment}";
|
||||||
|
},
|
||||||
|
/** 提交按钮 */
|
||||||
|
async submitForm() {
|
||||||
|
await this.#[[$]]#refs["formRef"].validate();
|
||||||
|
this.formLoading = true;
|
||||||
|
try {
|
||||||
|
const data = this.formData;
|
||||||
|
// 修改的提交
|
||||||
|
if (data.${primaryColumn.javaField}) {
|
||||||
|
await ${simpleClassName}Api.update${subSimpleClassName}(data);
|
||||||
|
this.#[[$modal]]#.msgSuccess("修改成功");
|
||||||
|
this.dialogVisible = false;
|
||||||
|
this.#[[$]]#emit('success');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 添加的提交
|
||||||
|
await ${simpleClassName}Api.create${subSimpleClassName}(data);
|
||||||
|
this.#[[$modal]]#.msgSuccess("新增成功");
|
||||||
|
this.dialogVisible = false;
|
||||||
|
this.#[[$]]#emit('success');
|
||||||
|
}finally {
|
||||||
|
this.formLoading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/** 表单重置 */
|
||||||
|
reset() {
|
||||||
|
this.formData = {
|
||||||
|
#foreach ($column in $subColumns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#if ($column.htmlType == "checkbox")
|
||||||
|
$column.javaField: [],
|
||||||
|
#else
|
||||||
|
$column.javaField: undefined,
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
};
|
||||||
|
this.resetForm("formRef");
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
@ -0,0 +1,2 @@
|
|||||||
|
## 主表的 normal 和 inner 使用相同的 form 表单
|
||||||
|
#parse("codegen/vue/views/components/form_sub_normal.vue.vm")
|
@ -0,0 +1,347 @@
|
|||||||
|
#set ($subTable = $subTables.get($subIndex))##当前表
|
||||||
|
#set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($subIndex))
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
|
||||||
|
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||||
|
<template>
|
||||||
|
<div class="app-container">
|
||||||
|
#if ( $subTable.subJoinMany )## 情况一:一对多,table + form
|
||||||
|
<el-form
|
||||||
|
ref="formRef"
|
||||||
|
:model="formData"
|
||||||
|
:rules="formRules"
|
||||||
|
v-loading="formLoading"
|
||||||
|
label-width="0px"
|
||||||
|
:inline-message="true"
|
||||||
|
>
|
||||||
|
<el-table :data="formData" class="-mt-10px">
|
||||||
|
<el-table-column label="序号" type="index" width="100" />
|
||||||
|
#foreach($column in $subColumns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#set ($dictType = $column.dictType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($javaType = $column.javaType)
|
||||||
|
#set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
#set ($comment = $column.columnComment)
|
||||||
|
#if ( $column.id == $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写
|
||||||
|
#elseif ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里
|
||||||
|
<el-table-column label="${comment}" min-width="150">
|
||||||
|
<template v-slot="{ row, $index }">
|
||||||
|
<el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!">
|
||||||
|
<el-input v-model="row.${javaField}" placeholder="请输入${comment}" />
|
||||||
|
</el-form-item>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#elseif($column.htmlType == "imageUpload")## 图片上传
|
||||||
|
#set ($hasImageUploadColumn = true)
|
||||||
|
<el-table-column label="${comment}" min-width="200">
|
||||||
|
<template v-slot="{ row, $index }">
|
||||||
|
<el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!">
|
||||||
|
<ImageUpload v-model="row.${javaField}"/>
|
||||||
|
</el-form-item>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#elseif($column.htmlType == "fileUpload")## 文件上传
|
||||||
|
#set ($hasFileUploadColumn = true)
|
||||||
|
<el-table-column label="${comment}" min-width="200">
|
||||||
|
<template v-slot="{ row, $index }">
|
||||||
|
<el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!">
|
||||||
|
<FileUpload v-model="row.${javaField}"/>
|
||||||
|
</el-form-item>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#elseif($column.htmlType == "editor")## 文本编辑器
|
||||||
|
#set ($hasEditorColumn = true)
|
||||||
|
<el-table-column label="${comment}" min-width="400">
|
||||||
|
<template v-slot="{ row, $index }">
|
||||||
|
<el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!">
|
||||||
|
<Editor v-model="row.${javaField}" :min-height="192"/>
|
||||||
|
</el-form-item>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#elseif($column.htmlType == "select")## 下拉框
|
||||||
|
<el-table-column label="${comment}" min-width="150">
|
||||||
|
<template v-slot="{ row, $index }">
|
||||||
|
<el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!">
|
||||||
|
<el-select v-model="row.${javaField}" placeholder="请选择${comment}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<el-option v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value" :label="dict.label" #if ($column.javaType == "Integer" || $column.javaType == "Long"):value="parseInt(dict.value)"#else:value="dict.value"#end />
|
||||||
|
#else##没数据字典
|
||||||
|
<el-option label="请选择字典生成" value="" />
|
||||||
|
#end
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#elseif($column.htmlType == "checkbox")## 多选框
|
||||||
|
<el-table-column label="${comment}" min-width="150">
|
||||||
|
<template v-slot="{ row, $index }">
|
||||||
|
<el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!">
|
||||||
|
<el-checkbox-group v-model="row.${javaField}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<el-checkbox v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value" #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.value)"#else:label="dict.value"#end>{{dict.label}}</el-checkbox>
|
||||||
|
#else##没数据字典
|
||||||
|
<el-checkbox>请选择字典生成</el-checkbox>
|
||||||
|
#end
|
||||||
|
</el-checkbox-group>
|
||||||
|
</el-form-item>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#elseif($column.htmlType == "radio")## 单选框
|
||||||
|
<el-table-column label="${comment}" min-width="150">
|
||||||
|
<template v-slot="{ row, $index }">
|
||||||
|
<el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!">
|
||||||
|
<el-radio-group v-model="row.${javaField}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<el-radio v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value" #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.value)"
|
||||||
|
#else:label="dict.value"#end>{{dict.label}}</el-radio>
|
||||||
|
#else##没数据字典
|
||||||
|
<el-radio label="1">请选择字典生成</el-radio>
|
||||||
|
#end
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#elseif($column.htmlType == "datetime")## 时间框
|
||||||
|
<el-table-column label="${comment}" min-width="150">
|
||||||
|
<template v-slot="{ row, $index }">
|
||||||
|
<el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!">
|
||||||
|
<el-date-picker clearable v-model="row.${javaField}" type="date" value-format="timestamp" placeholder="选择${comment}" />
|
||||||
|
</el-form-item>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#elseif($column.htmlType == "textarea")## 文本框
|
||||||
|
<el-table-column label="${comment}" min-width="200">
|
||||||
|
<template v-slot="{ row, $index }">
|
||||||
|
<el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!">
|
||||||
|
<el-input v-model="row.${javaField}" type="textarea" placeholder="请输入${comment}" />
|
||||||
|
</el-form-item>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
<el-table-column align="center" fixed="right" label="操作" width="60">
|
||||||
|
<template v-slot="{ $index }">
|
||||||
|
<el-link @click="handleDelete($index)">—</el-link>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
</el-form>
|
||||||
|
<el-row justify="center" class="mt-3">
|
||||||
|
<el-button @click="handleAdd" round>+ 添加${subTable.classComment}</el-button>
|
||||||
|
</el-row>
|
||||||
|
#else## 情况二:一对一,form
|
||||||
|
<el-form
|
||||||
|
ref="formRef"
|
||||||
|
:model="formData"
|
||||||
|
:rules="formRules"
|
||||||
|
label-width="100px"
|
||||||
|
v-loading="formLoading"
|
||||||
|
>
|
||||||
|
#foreach($column in $subColumns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#set ($dictType = $column.dictType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($javaType = $column.javaType)
|
||||||
|
#set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
#set ($comment = $column.columnComment)
|
||||||
|
#if ( $column.id == $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写
|
||||||
|
#elseif ($column.htmlType == "input" && !$column.primaryKey)
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-input v-model="formData.${javaField}" placeholder="请输入${comment}" />
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "imageUpload")## 图片上传
|
||||||
|
#set ($hasImageUploadColumn = true)
|
||||||
|
<el-form-item label="${comment}">
|
||||||
|
<ImageUpload v-model="formData.${javaField}"/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "fileUpload")## 文件上传
|
||||||
|
#set ($hasFileUploadColumn = true)
|
||||||
|
<el-form-item label="${comment}">
|
||||||
|
<FileUpload v-model="formData.${javaField}"/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "editor")## 文本编辑器
|
||||||
|
#set ($hasEditorColumn = true)
|
||||||
|
<el-form-item label="${comment}">
|
||||||
|
<Editor v-model="formData.${javaField}" :min-height="192"/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "select")## 下拉框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-select v-model="formData.${javaField}" placeholder="请选择${comment}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<el-option v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value" :label="dict.label" #if ($column.javaType == "Integer" || $column.javaType == "Long"):value="parseInt(dict.value)"#else:value="dict.value"#end />
|
||||||
|
#else##没数据字典
|
||||||
|
<el-option label="请选择字典生成" value="" />
|
||||||
|
#end
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "checkbox")## 多选框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-checkbox-group v-model="formData.${javaField}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<el-checkbox v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value" #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.value)"#else:label="dict.value"#end>{{dict.label}}</el-checkbox>
|
||||||
|
#else##没数据字典
|
||||||
|
<el-checkbox>请选择字典生成</el-checkbox>
|
||||||
|
#end
|
||||||
|
</el-checkbox-group>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "radio")## 单选框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-radio-group v-model="formData.${javaField}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<el-radio v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value" #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.value)"
|
||||||
|
#else:label="dict.value"#end>{{dict.label}}</el-radio>
|
||||||
|
#else##没数据字典
|
||||||
|
<el-radio label="1">请选择字典生成</el-radio>
|
||||||
|
#end
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "datetime")## 时间框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-date-picker clearable v-model="formData.${javaField}" type="date" value-format="timestamp" placeholder="选择${comment}" />
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "textarea")## 文本框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-input v-model="formData.${javaField}" type="textarea" placeholder="请输入${comment}" />
|
||||||
|
</el-form-item>
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
</el-form>
|
||||||
|
#end
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}';
|
||||||
|
#if ($hasImageUploadColumn)
|
||||||
|
import ImageUpload from '@/components/ImageUpload';
|
||||||
|
#end
|
||||||
|
#if ($hasFileUploadColumn)
|
||||||
|
import FileUpload from '@/components/FileUpload';
|
||||||
|
#end
|
||||||
|
#if ($hasEditorColumn)
|
||||||
|
import Editor from '@/components/Editor';
|
||||||
|
#end
|
||||||
|
export default {
|
||||||
|
name: "${subSimpleClassName}Form",
|
||||||
|
components: {
|
||||||
|
#if ($hasImageUploadColumn)
|
||||||
|
ImageUpload,
|
||||||
|
#end
|
||||||
|
#if ($hasFileUploadColumn)
|
||||||
|
FileUpload,
|
||||||
|
#end
|
||||||
|
#if ($hasEditorColumn)
|
||||||
|
Editor,
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
props:[
|
||||||
|
'${subJoinColumn.javaField}'
|
||||||
|
],// ${subJoinColumn.columnComment}(主表的关联字段)
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
// 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||||
|
formLoading: false,
|
||||||
|
// 表单参数
|
||||||
|
formData: [],
|
||||||
|
// 表单校验
|
||||||
|
formRules: {
|
||||||
|
#foreach ($column in $subColumns)
|
||||||
|
#if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键
|
||||||
|
#set($comment=$column.columnComment)
|
||||||
|
$column.javaField: [{ required: true, message: "${comment}不能为空", trigger: #if($column.htmlType == "select")"change"#else"blur"#end }],
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
watch:{/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
||||||
|
${subJoinColumn.javaField}:{
|
||||||
|
handler(val) {
|
||||||
|
// 1. 重置表单
|
||||||
|
#if ( $subTable.subJoinMany )
|
||||||
|
this.formData = []
|
||||||
|
#else
|
||||||
|
this.formData = {
|
||||||
|
#foreach ($column in $subColumns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#if ($column.htmlType == "checkbox")
|
||||||
|
$column.javaField: [],
|
||||||
|
#else
|
||||||
|
$column.javaField: undefined,
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
// 2. val 非空,则加载数据
|
||||||
|
if (!val) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
this.formLoading = true;
|
||||||
|
// 这里还是需要获取一下 this 的不然取不到 formData
|
||||||
|
const that = this;
|
||||||
|
#if ( $subTable.subJoinMany )
|
||||||
|
${simpleClassName}Api.get${subSimpleClassName}ListBy${SubJoinColumnName}(val).then(function (res){
|
||||||
|
that.formData = res.data;
|
||||||
|
})
|
||||||
|
#else
|
||||||
|
${simpleClassName}Api.get${subSimpleClassName}By${SubJoinColumnName}(val).then(function (res){
|
||||||
|
const data = res.data;
|
||||||
|
if (!data) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
that.formData = data;
|
||||||
|
})
|
||||||
|
#end
|
||||||
|
} finally {
|
||||||
|
this.formLoading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
immediate: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
#if ( $subTable.subJoinMany )
|
||||||
|
/** 新增按钮操作 */
|
||||||
|
handleAdd() {
|
||||||
|
const row = {
|
||||||
|
#foreach ($column in $subColumns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#if ($column.htmlType == "checkbox")
|
||||||
|
$column.javaField: [],
|
||||||
|
#else
|
||||||
|
$column.javaField: undefined,
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
row.${subJoinColumn.javaField} = this.${subJoinColumn.javaField};
|
||||||
|
this.formData.push(row);
|
||||||
|
},
|
||||||
|
/** 删除按钮操作 */
|
||||||
|
handleDelete(index) {
|
||||||
|
this.formData.splice(index, 1);
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
/** 表单校验 */
|
||||||
|
validate(){
|
||||||
|
return this.#[[$]]#refs["formRef"].validate();
|
||||||
|
},
|
||||||
|
/** 表单值 */
|
||||||
|
getData(){
|
||||||
|
return this.formData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
@ -0,0 +1,165 @@
|
|||||||
|
#set ($subTable = $subTables.get($subIndex))##当前表
|
||||||
|
#set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($subIndex))
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
|
||||||
|
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||||
|
<template>
|
||||||
|
<div class="app-container">
|
||||||
|
#if ($table.templateType == 11)
|
||||||
|
<!-- 操作工具栏 -->
|
||||||
|
<el-row :gutter="10" class="mb8">
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)"
|
||||||
|
v-hasPermi="['${permissionPrefix}:create']">新增</el-button>
|
||||||
|
</el-col>
|
||||||
|
</el-row>
|
||||||
|
#end
|
||||||
|
## 列表
|
||||||
|
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
|
||||||
|
#foreach($column in $subColumns)
|
||||||
|
#if ($column.listOperationResult)
|
||||||
|
#set ($dictType=$column.dictType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
#set ($comment=$column.columnComment)
|
||||||
|
#if ( $column.id == $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写
|
||||||
|
#elseif ($column.javaType == "LocalDateTime")## 时间类型
|
||||||
|
<el-table-column label="${comment}" align="center" prop="${javaField}" width="180">
|
||||||
|
<template v-slot="scope">
|
||||||
|
<span>{{ parseTime(scope.row.${javaField}) }}</span>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#elseif($column.dictType && "" != $column.dictType)## 数据字典
|
||||||
|
<el-table-column label="${comment}" align="center" prop="${javaField}">
|
||||||
|
<template v-slot="scope">
|
||||||
|
<dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.${column.javaField}" />
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#else
|
||||||
|
<el-table-column label="${comment}" align="center" prop="${javaField}" />
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||||
|
<template v-slot="scope">
|
||||||
|
<el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.${primaryColumn.javaField})"
|
||||||
|
v-hasPermi="['${permissionPrefix}:update']">修改</el-button>
|
||||||
|
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
|
||||||
|
v-hasPermi="['${permissionPrefix}:delete']">删除</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
#if ($table.templateType == 11)
|
||||||
|
<!-- 分页组件 -->
|
||||||
|
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
|
||||||
|
@pagination="getList"/>
|
||||||
|
<!-- 对话框(添加 / 修改) -->
|
||||||
|
<${subSimpleClassName}Form ref="formRef" @success="getList" />
|
||||||
|
#end
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}';
|
||||||
|
#if ($table.templateType == 11)
|
||||||
|
import ${subSimpleClassName}Form from './${subSimpleClassName}Form.vue';
|
||||||
|
#end
|
||||||
|
export default {
|
||||||
|
name: "${subSimpleClassName}List",
|
||||||
|
#if ($table.templateType == 11)
|
||||||
|
components: {
|
||||||
|
${subSimpleClassName}Form
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
props:[
|
||||||
|
'${subJoinColumn.javaField}'
|
||||||
|
],// ${subJoinColumn.columnComment}(主表的关联字段)
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
// 遮罩层
|
||||||
|
loading: true,
|
||||||
|
// 列表的数据
|
||||||
|
list: [],
|
||||||
|
#if ($table.templateType == 11)
|
||||||
|
// 列表的总页数
|
||||||
|
total: 0,
|
||||||
|
// 查询参数
|
||||||
|
queryParams: {
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
${subJoinColumn.javaField}: undefined
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
};
|
||||||
|
},
|
||||||
|
#if ($table.templateType != 11)
|
||||||
|
created() {
|
||||||
|
this.getList();
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
watch:{/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
||||||
|
${subJoinColumn.javaField}:{
|
||||||
|
handler(val) {
|
||||||
|
this.queryParams.${subJoinColumn.javaField} = val;
|
||||||
|
if (val){
|
||||||
|
this.handleQuery();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
immediate: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
/** 查询列表 */
|
||||||
|
async getList() {
|
||||||
|
try {
|
||||||
|
this.loading = true;
|
||||||
|
#if ($table.templateType == 11)
|
||||||
|
const res = await ${simpleClassName}Api.get${subSimpleClassName}Page(this.queryParams);
|
||||||
|
this.list = res.data.list;
|
||||||
|
this.total = res.data.total;
|
||||||
|
#else
|
||||||
|
#if ( $subTable.subJoinMany )
|
||||||
|
const res = await ${simpleClassName}Api.get${subSimpleClassName}ListBy${SubJoinColumnName}(this.${subJoinColumn.javaField});
|
||||||
|
this.list = res.data;
|
||||||
|
#else
|
||||||
|
const res = await ${simpleClassName}Api.get${subSimpleClassName}By${SubJoinColumnName}(this.${subJoinColumn.javaField});
|
||||||
|
const data = res.data;
|
||||||
|
if (!data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.list.push(data);
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
} finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/** 搜索按钮操作 */
|
||||||
|
handleQuery() {
|
||||||
|
this.queryParams.pageNo = 1;
|
||||||
|
this.getList();
|
||||||
|
},
|
||||||
|
#if ($table.templateType == 11)
|
||||||
|
/** 添加/修改操作 */
|
||||||
|
openForm(id) {
|
||||||
|
if (!this.${subJoinColumn.javaField}) {
|
||||||
|
this.#[[$modal]]#.msgError('请选择一个${table.classComment}');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.#[[$]]#refs["formRef"].open(id, this.${subJoinColumn.javaField});
|
||||||
|
},
|
||||||
|
/** 删除按钮操作 */
|
||||||
|
async handleDelete(row) {
|
||||||
|
const ${primaryColumn.javaField} = row.${primaryColumn.javaField};
|
||||||
|
await this.#[[$modal]]#.confirm('是否确认删除${table.classComment}编号为"' + ${primaryColumn.javaField} + '"的数据项?');
|
||||||
|
try {
|
||||||
|
await ${simpleClassName}Api.delete${subSimpleClassName}(${primaryColumn.javaField});
|
||||||
|
await this.getList();
|
||||||
|
this.#[[$modal]]#.msgSuccess("删除成功");
|
||||||
|
} catch {}
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
@ -0,0 +1,4 @@
|
|||||||
|
## 子表的 erp 和 inner 使用相似的 list 列表,差异主要两点:
|
||||||
|
## 1)inner 使用 list 不分页,erp 使用 page 分页
|
||||||
|
## 2)erp 支持单个子表的新增、修改、删除,inner 不支持
|
||||||
|
#parse("codegen/vue/views/components/list_sub_erp.vue.vm")
|
@ -0,0 +1,320 @@
|
|||||||
|
<template>
|
||||||
|
<div class="app-container">
|
||||||
|
<!-- 对话框(添加 / 修改) -->
|
||||||
|
<el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="45%" v-dialogDrag append-to-body>
|
||||||
|
<el-form ref="formRef" :model="formData" :rules="formRules" v-loading="formLoading" label-width="100px">
|
||||||
|
#foreach($column in $columns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#set ($dictType = $column.dictType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
#set ($comment = $column.columnComment)
|
||||||
|
#if ( $table.templateType == 2 && $column.id == $treeParentColumn.id )
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<TreeSelect
|
||||||
|
v-model="formData.${javaField}"
|
||||||
|
:options="${classNameVar}Tree"
|
||||||
|
:normalizer="normalizer"
|
||||||
|
placeholder="请选择${comment}"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-input v-model="formData.${javaField}" placeholder="请输入${comment}" />
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "imageUpload")## 图片上传
|
||||||
|
#set ($hasImageUploadColumn = true)
|
||||||
|
<el-form-item label="${comment}">
|
||||||
|
<ImageUpload v-model="formData.${javaField}"/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "fileUpload")## 文件上传
|
||||||
|
#set ($hasFileUploadColumn = true)
|
||||||
|
<el-form-item label="${comment}">
|
||||||
|
<FileUpload v-model="formData.${javaField}"/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "editor")## 文本编辑器
|
||||||
|
#set ($hasEditorColumn = true)
|
||||||
|
<el-form-item label="${comment}">
|
||||||
|
<Editor v-model="formData.${javaField}" :min-height="192"/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "select")## 下拉框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-select v-model="formData.${javaField}" placeholder="请选择${comment}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<el-option v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value" :label="dict.label" #if ($column.javaType == "Integer" || $column.javaType == "Long"):value="parseInt(dict.value)"#else:value="dict.value"#end />
|
||||||
|
#else##没数据字典
|
||||||
|
<el-option label="请选择字典生成" value="" />
|
||||||
|
#end
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "checkbox")## 多选框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-checkbox-group v-model="formData.${javaField}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<el-checkbox v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value" #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.value)"#else:label="dict.value"#end>{{dict.label}}</el-checkbox>
|
||||||
|
#else##没数据字典
|
||||||
|
<el-checkbox>请选择字典生成</el-checkbox>
|
||||||
|
#end
|
||||||
|
</el-checkbox-group>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "radio")## 单选框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-radio-group v-model="formData.${javaField}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<el-radio v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value" #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.value)"
|
||||||
|
#else:label="dict.value"#end>{{dict.label}}</el-radio>
|
||||||
|
#else##没数据字典
|
||||||
|
<el-radio label="1">请选择字典生成</el-radio>
|
||||||
|
#end
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "datetime")## 时间框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-date-picker clearable v-model="formData.${javaField}" type="date" value-format="timestamp" placeholder="选择${comment}" />
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "textarea")## 文本框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-input v-model="formData.${javaField}" type="textarea" placeholder="请输入内容" />
|
||||||
|
</el-form-item>
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
</el-form>
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||||
|
<!-- 子表的表单 -->
|
||||||
|
<el-tabs v-model="subTabsName">
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
#set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
|
||||||
|
<el-tab-pane label="${subTable.classComment}" name="$subClassNameVar">
|
||||||
|
<${subSimpleClassName}Form ref="${subClassNameVar}FormRef" :${subJoinColumn_strikeCase}="formData.id" />
|
||||||
|
</el-tab-pane>
|
||||||
|
#end
|
||||||
|
</el-tabs>
|
||||||
|
#end
|
||||||
|
<div slot="footer" class="dialog-footer">
|
||||||
|
<el-button type="primary" @click="submitForm" :disabled="formLoading">确 定</el-button>
|
||||||
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||||
|
</div>
|
||||||
|
</el-dialog>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}';
|
||||||
|
#if ($hasImageUploadColumn)
|
||||||
|
import ImageUpload from '@/components/ImageUpload';
|
||||||
|
#end
|
||||||
|
#if ($hasFileUploadColumn)
|
||||||
|
import FileUpload from '@/components/FileUpload';
|
||||||
|
#end
|
||||||
|
#if ($hasEditorColumn)
|
||||||
|
import Editor from '@/components/Editor';
|
||||||
|
#end
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
import TreeSelect from "@riophae/vue-treeselect";
|
||||||
|
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
|
||||||
|
#end
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||||
|
#foreach ($subSimpleClassName in $subSimpleClassNames)
|
||||||
|
import ${subSimpleClassName}Form from './components/${subSimpleClassName}Form.vue'
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
export default {
|
||||||
|
name: "${simpleClassName}Form",
|
||||||
|
components: {
|
||||||
|
#if ($hasImageUploadColumn)
|
||||||
|
ImageUpload,
|
||||||
|
#end
|
||||||
|
#if ($hasFileUploadColumn)
|
||||||
|
FileUpload,
|
||||||
|
#end
|
||||||
|
#if ($hasEditorColumn)
|
||||||
|
Editor,
|
||||||
|
#end
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
TreeSelect,
|
||||||
|
#end
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||||
|
#foreach ($subSimpleClassName in $subSimpleClassNames)
|
||||||
|
${subSimpleClassName}Form,
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
// 弹出层标题
|
||||||
|
dialogTitle: "",
|
||||||
|
// 是否显示弹出层
|
||||||
|
dialogVisible: false,
|
||||||
|
// 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||||
|
formLoading: false,
|
||||||
|
// 表单参数
|
||||||
|
formData: {
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#if ($column.htmlType == "checkbox")
|
||||||
|
$column.javaField: [],
|
||||||
|
#else
|
||||||
|
$column.javaField: undefined,
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
// 表单校验
|
||||||
|
formRules: {
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键
|
||||||
|
#set($comment=$column.columnComment)
|
||||||
|
$column.javaField: [{ required: true, message: '${comment}不能为空', trigger: #if($column.htmlType == 'select')'change'#else'blur'#end }],
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
${classNameVar}Tree: [], // 树形结构
|
||||||
|
#end
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||||
|
#if ( $subTables && $subTables.size() > 0 )
|
||||||
|
/** 子表的表单 */
|
||||||
|
subTabsName: '$subClassNameVars.get(0)'
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
};
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
/** 打开弹窗 */
|
||||||
|
async open(id) {
|
||||||
|
this.dialogVisible = true;
|
||||||
|
this.reset();
|
||||||
|
// 修改时,设置数据
|
||||||
|
if (id) {
|
||||||
|
this.formLoading = true;
|
||||||
|
try {
|
||||||
|
const res = await ${simpleClassName}Api.get${simpleClassName}(id);
|
||||||
|
this.formData = res.data;
|
||||||
|
this.title = "修改${table.classComment}";
|
||||||
|
} finally {
|
||||||
|
this.formLoading = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.title = "新增${table.classComment}";
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
await this.get${simpleClassName}Tree();
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
/** 提交按钮 */
|
||||||
|
async submitForm() {
|
||||||
|
// 校验主表
|
||||||
|
await this.$refs["formRef"].validate();
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||||
|
#if ( $subTables && $subTables.size() > 0 )
|
||||||
|
// 校验子表
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||||
|
try {
|
||||||
|
## 代码生成后会替换为正确的 refs
|
||||||
|
await this.refs['${subClassNameVar}FormRef'].validate();
|
||||||
|
} catch (e) {
|
||||||
|
this.subTabsName = '${subClassNameVar}';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
this.formLoading = true;
|
||||||
|
try {
|
||||||
|
const data = this.formData;
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||||
|
#if ( $subTables && $subTables.size() > 0 )
|
||||||
|
// 拼接子表的数据
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||||
|
data.${subClassNameVar}#if ( $subTable.subJoinMany)s#end = this.refs['${subClassNameVar}FormRef'].getData();
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
// 修改的提交
|
||||||
|
if (data.${primaryColumn.javaField}) {
|
||||||
|
await ${simpleClassName}Api.update${simpleClassName}(data);
|
||||||
|
this.#[[$modal]]#.msgSuccess("修改成功");
|
||||||
|
this.dialogVisible = false;
|
||||||
|
this.#[[$]]#emit('success');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 添加的提交
|
||||||
|
await ${simpleClassName}Api.create${simpleClassName}(data);
|
||||||
|
this.#[[$modal]]#.msgSuccess("新增成功");
|
||||||
|
this.dialogVisible = false;
|
||||||
|
this.#[[$]]#emit('success');
|
||||||
|
} finally {
|
||||||
|
this.formLoading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
/** 获得${table.classComment}树 */
|
||||||
|
async get${simpleClassName}Tree() {
|
||||||
|
this.${classNameVar}Tree = [];
|
||||||
|
const res = await ${simpleClassName}Api.get${simpleClassName}List();
|
||||||
|
const root = { id: 0, name: '顶级${table.classComment}', children: [] };
|
||||||
|
root.children = this.handleTree(res.data, 'id', '${treeParentColumn.javaField}')
|
||||||
|
this.${classNameVar}Tree.push(root)
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
/** 转换${table.classComment}数据结构 */
|
||||||
|
normalizer(node) {
|
||||||
|
if (node.children && !node.children.length) {
|
||||||
|
delete node.children;
|
||||||
|
}
|
||||||
|
#if ($treeNameColumn.javaField == "name")
|
||||||
|
return {
|
||||||
|
id: node.id,
|
||||||
|
label: node.name,
|
||||||
|
children: node.children
|
||||||
|
};
|
||||||
|
#else
|
||||||
|
return {
|
||||||
|
id: node.id,
|
||||||
|
label: node['$treeNameColumn.javaField'],
|
||||||
|
children: node.children
|
||||||
|
};
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
/** 表单重置 */
|
||||||
|
reset() {
|
||||||
|
this.formData = {
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#if ($column.htmlType == "checkbox")
|
||||||
|
$column.javaField: [],
|
||||||
|
#else
|
||||||
|
$column.javaField: undefined,
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
};
|
||||||
|
this.resetForm("formRef");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
@ -0,0 +1,340 @@
|
|||||||
|
<template>
|
||||||
|
<div class="app-container">
|
||||||
|
<!-- 搜索工作栏 -->
|
||||||
|
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
|
||||||
|
#foreach($column in $columns)
|
||||||
|
#if ($column.listOperation)
|
||||||
|
#set ($dictType=$column.dictType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
#set ($comment=$column.columnComment)
|
||||||
|
#if ($column.htmlType == "input")
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-input v-model="queryParams.${javaField}" placeholder="请输入${comment}" clearable @keyup.enter.native="handleQuery"/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif ($column.htmlType == "select" || $column.htmlType == "radio")
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-select v-model="queryParams.${javaField}" placeholder="请选择${comment}" clearable size="small">
|
||||||
|
#if ("" != $dictType)## 设置了 dictType 数据字典的情况
|
||||||
|
<el-option v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value" :label="dict.label" :value="dict.value"/>
|
||||||
|
#else## 未设置 dictType 数据字典的情况
|
||||||
|
<el-option label="请选择字典生成" value="" />
|
||||||
|
#end
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "datetime")
|
||||||
|
#if ($column.listOperationCondition != "BETWEEN")## 非范围
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-date-picker clearable v-model="queryParams.${javaField}" type="date" value-format="yyyy-MM-dd" placeholder="选择${comment}" />
|
||||||
|
</el-form-item>
|
||||||
|
#else## 范围
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-date-picker v-model="queryParams.${javaField}" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange"
|
||||||
|
range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" />
|
||||||
|
</el-form-item>
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
<el-form-item>
|
||||||
|
<el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
|
||||||
|
<el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
|
||||||
|
<!-- 操作工具栏 -->
|
||||||
|
<el-row :gutter="10" class="mb8">
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)"
|
||||||
|
v-hasPermi="['${permissionPrefix}:create']">新增</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading"
|
||||||
|
v-hasPermi="['${permissionPrefix}:export']">导出</el-button>
|
||||||
|
</el-col>
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button type="danger" plain icon="el-icon-sort" size="mini" @click="toggleExpandAll">
|
||||||
|
展开/折叠
|
||||||
|
</el-button>
|
||||||
|
</el-col>
|
||||||
|
#end
|
||||||
|
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
||||||
|
</el-row>
|
||||||
|
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 )
|
||||||
|
<el-table
|
||||||
|
v-loading="loading"
|
||||||
|
:data="list"
|
||||||
|
:stripe="true"
|
||||||
|
:highlight-current-row="true"
|
||||||
|
:show-overflow-tooltip="true"
|
||||||
|
@current-change="handleCurrentChange"
|
||||||
|
>
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#elseif ( $table.templateType == 2 )
|
||||||
|
<el-table
|
||||||
|
v-loading="loading"
|
||||||
|
:data="list"
|
||||||
|
:stripe="true"
|
||||||
|
:show-overflow-tooltip="true"
|
||||||
|
v-if="refreshTable"
|
||||||
|
row-key="id"
|
||||||
|
:default-expand-all="isExpandAll"
|
||||||
|
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
|
||||||
|
>
|
||||||
|
#else
|
||||||
|
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
|
||||||
|
#end
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 12 && $subTables && $subTables.size() > 0 )
|
||||||
|
<!-- 子表的列表 -->
|
||||||
|
<el-table-column type="expand">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-tabs value="$subClassNameVars.get(0)">
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
#set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
|
||||||
|
<el-tab-pane label="${subTable.classComment}" name="$subClassNameVar">
|
||||||
|
<${subSimpleClassName}List :${subJoinColumn_strikeCase}="scope.row.id" />
|
||||||
|
</el-tab-pane>
|
||||||
|
#end
|
||||||
|
</el-tabs>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#end
|
||||||
|
#foreach($column in $columns)
|
||||||
|
#if ($column.listOperationResult)
|
||||||
|
#set ($dictType=$column.dictType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
#set ($comment=$column.columnComment)
|
||||||
|
#if ($column.javaType == "LocalDateTime")## 时间类型
|
||||||
|
<el-table-column label="${comment}" align="center" prop="${javaField}" width="180">
|
||||||
|
<template v-slot="scope">
|
||||||
|
<span>{{ parseTime(scope.row.${javaField}) }}</span>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#elseif("" != $column.dictType)## 数据字典
|
||||||
|
<el-table-column label="${comment}" align="center" prop="${javaField}">
|
||||||
|
<template v-slot="scope">
|
||||||
|
<dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.${column.javaField}" />
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#else
|
||||||
|
<el-table-column label="${comment}" align="center" prop="${javaField}" />
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||||
|
<template v-slot="scope">
|
||||||
|
<el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.${primaryColumn.javaField})"
|
||||||
|
v-hasPermi="['${permissionPrefix}:update']">修改</el-button>
|
||||||
|
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
|
||||||
|
v-hasPermi="['${permissionPrefix}:delete']">删除</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
## 特殊:树表专属逻辑(树不需要分页)
|
||||||
|
#if ( $table.templateType != 2 )
|
||||||
|
<!-- 分页组件 -->
|
||||||
|
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
|
||||||
|
@pagination="getList"/>
|
||||||
|
#end
|
||||||
|
<!-- 对话框(添加 / 修改) -->
|
||||||
|
<${simpleClassName}Form ref="formRef" @success="getList" />
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 )
|
||||||
|
<!-- 子表的列表 -->
|
||||||
|
<el-tabs v-model="subTabsName">
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
#set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
|
||||||
|
<el-tab-pane label="${subTable.classComment}" name="$subClassNameVar">
|
||||||
|
<${subSimpleClassName}List v-if="currentRow.id" :${subJoinColumn_strikeCase}="currentRow.id" />
|
||||||
|
</el-tab-pane>
|
||||||
|
#end
|
||||||
|
</el-tabs>
|
||||||
|
#end
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}';
|
||||||
|
import ${simpleClassName}Form from './${simpleClassName}Form.vue';
|
||||||
|
#if ($hasImageUploadColumn)
|
||||||
|
import ImageUpload from '@/components/ImageUpload';
|
||||||
|
#end
|
||||||
|
#if ($hasFileUploadColumn)
|
||||||
|
import FileUpload from '@/components/FileUpload';
|
||||||
|
#end
|
||||||
|
#if ($hasEditorColumn)
|
||||||
|
import Editor from '@/components/Editor';
|
||||||
|
#end
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType != 10 )
|
||||||
|
#if ( $subTables && $subTables.size() > 0 )
|
||||||
|
#foreach ($subSimpleClassName in $subSimpleClassNames)
|
||||||
|
import ${subSimpleClassName}List from './components/${subSimpleClassName}List.vue';
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
export default {
|
||||||
|
name: "${simpleClassName}",
|
||||||
|
components: {
|
||||||
|
${simpleClassName}Form,
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType != 10 )
|
||||||
|
#if ( $subTables && $subTables.size() > 0 )
|
||||||
|
#foreach ($subSimpleClassName in $subSimpleClassNames)
|
||||||
|
${subSimpleClassName}List,
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#if ($hasImageUploadColumn)
|
||||||
|
ImageUpload,
|
||||||
|
#end
|
||||||
|
#if ($hasFileUploadColumn)
|
||||||
|
FileUpload,
|
||||||
|
#end
|
||||||
|
#if ($hasEditorColumn)
|
||||||
|
Editor,
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
// 遮罩层
|
||||||
|
loading: true,
|
||||||
|
// 导出遮罩层
|
||||||
|
exportLoading: false,
|
||||||
|
// 显示搜索条件
|
||||||
|
showSearch: true,
|
||||||
|
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||||
|
#if ( $table.templateType != 2 )
|
||||||
|
// 总条数
|
||||||
|
total: 0,
|
||||||
|
#end
|
||||||
|
// ${table.classComment}列表
|
||||||
|
list: [],
|
||||||
|
// 是否展开,默认全部展开
|
||||||
|
isExpandAll: true,
|
||||||
|
// 重新渲染表格状态
|
||||||
|
refreshTable: true,
|
||||||
|
// 选中行
|
||||||
|
currentRow: {},
|
||||||
|
// 查询参数
|
||||||
|
queryParams: {
|
||||||
|
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||||
|
#if ( $table.templateType != 2 )
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
#end
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if ($column.listOperation)
|
||||||
|
#if ($column.listOperationCondition != 'BETWEEN')
|
||||||
|
$column.javaField: null,
|
||||||
|
#end
|
||||||
|
#if ($column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")
|
||||||
|
$column.javaField: [],
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
## 特殊:主子表专属逻辑-erp
|
||||||
|
#if ( $table.templateType == 11)
|
||||||
|
#if ( $subTables && $subTables.size() > 0 )
|
||||||
|
/** 子表的列表 */
|
||||||
|
subTabsName: '$subClassNameVars.get(0)'
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
};
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.getList();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
/** 查询列表 */
|
||||||
|
async getList() {
|
||||||
|
try {
|
||||||
|
this.loading = true;
|
||||||
|
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
const res = await ${simpleClassName}Api.get${simpleClassName}List(this.queryParams);
|
||||||
|
this.list = this.handleTree(res.data, 'id', '${treeParentColumn.javaField}');
|
||||||
|
#else
|
||||||
|
const res = await ${simpleClassName}Api.get${simpleClassName}Page(this.queryParams);
|
||||||
|
this.list = res.data.list;
|
||||||
|
this.total = res.data.total;
|
||||||
|
#end
|
||||||
|
} finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/** 搜索按钮操作 */
|
||||||
|
handleQuery() {
|
||||||
|
this.queryParams.pageNo = 1;
|
||||||
|
this.getList();
|
||||||
|
},
|
||||||
|
/** 重置按钮操作 */
|
||||||
|
resetQuery() {
|
||||||
|
this.resetForm("queryForm");
|
||||||
|
this.handleQuery();
|
||||||
|
},
|
||||||
|
/** 添加/修改操作 */
|
||||||
|
openForm(id) {
|
||||||
|
this.#[[$]]#refs["formRef"].open(id);
|
||||||
|
},
|
||||||
|
/** 删除按钮操作 */
|
||||||
|
async handleDelete(row) {
|
||||||
|
const ${primaryColumn.javaField} = row.${primaryColumn.javaField};
|
||||||
|
await this.#[[$modal]]#.confirm('是否确认删除${table.classComment}编号为"' + ${primaryColumn.javaField} + '"的数据项?')
|
||||||
|
try {
|
||||||
|
await ${simpleClassName}Api.delete${simpleClassName}(${primaryColumn.javaField});
|
||||||
|
await this.getList();
|
||||||
|
this.#[[$modal]]#.msgSuccess("删除成功");
|
||||||
|
} catch {}
|
||||||
|
},
|
||||||
|
/** 导出按钮操作 */
|
||||||
|
async handleExport() {
|
||||||
|
await this.#[[$modal]]#.confirm('是否确认导出所有${table.classComment}数据项?');
|
||||||
|
try {
|
||||||
|
this.exportLoading = true;
|
||||||
|
const res = await ${simpleClassName}Api.export${simpleClassName}Excel(this.queryParams);
|
||||||
|
this.#[[$]]#download.excel(res, '${table.classComment}.xls');
|
||||||
|
} catch {
|
||||||
|
} finally {
|
||||||
|
this.exportLoading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 11 )
|
||||||
|
/** 选中行操作 */
|
||||||
|
handleCurrentChange(row) {
|
||||||
|
this.currentRow = row;
|
||||||
|
#if ( $subTables && $subTables.size() > 0 )
|
||||||
|
/** 子表的列表 */
|
||||||
|
this.subTabsName = '$subClassNameVars.get(0)';
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
/** 展开/折叠操作 */
|
||||||
|
toggleExpandAll() {
|
||||||
|
this.refreshTable = false
|
||||||
|
this.isExpandAll = !this.isExpandAll
|
||||||
|
this.$nextTick(function () {
|
||||||
|
this.refreshTable = true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
@ -0,0 +1,115 @@
|
|||||||
|
import request from '@/config/axios'
|
||||||
|
#set ($baseURL = "/${table.moduleName}/${simpleClassName_strikeCase}")
|
||||||
|
|
||||||
|
// ${table.classComment} VO
|
||||||
|
export interface ${simpleClassName}VO {
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer" || ${column.javaType.toLowerCase()} == "short" || ${column.javaType.toLowerCase()} == "double" || ${column.javaType.toLowerCase()} == "bigdecimal")
|
||||||
|
${column.javaField}: number // ${column.columnComment}
|
||||||
|
#elseif(${column.javaType.toLowerCase()} == "date" || ${column.javaType.toLowerCase()} == "localdate" || ${column.javaType.toLowerCase()} == "localdatetime")
|
||||||
|
${column.javaField}: Date // ${column.columnComment}
|
||||||
|
#else
|
||||||
|
${column.javaField}: ${column.javaType.toLowerCase()} // ${column.columnComment}
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
|
||||||
|
// ${table.classComment} API
|
||||||
|
export const ${simpleClassName}Api = {
|
||||||
|
#if ( $table.templateType != 2 )
|
||||||
|
// 查询${table.classComment}分页
|
||||||
|
get${simpleClassName}Page: async (params: any) => {
|
||||||
|
return await request.get({ url: `${baseURL}/page`, params })
|
||||||
|
},
|
||||||
|
#else
|
||||||
|
// 查询${table.classComment}列表
|
||||||
|
get${simpleClassName}List: async (params) => {
|
||||||
|
return await request.get({ url: `${baseURL}/list`, params })
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
|
||||||
|
// 查询${table.classComment}详情
|
||||||
|
get${simpleClassName}: async (id: number) => {
|
||||||
|
return await request.get({ url: `${baseURL}/get?id=` + id })
|
||||||
|
},
|
||||||
|
|
||||||
|
// 新增${table.classComment}
|
||||||
|
create${simpleClassName}: async (data: ${simpleClassName}VO) => {
|
||||||
|
return await request.post({ url: `${baseURL}/create`, data })
|
||||||
|
},
|
||||||
|
|
||||||
|
// 修改${table.classComment}
|
||||||
|
update${simpleClassName}: async (data: ${simpleClassName}VO) => {
|
||||||
|
return await request.put({ url: `${baseURL}/update`, data })
|
||||||
|
},
|
||||||
|
|
||||||
|
// 删除${table.classComment}
|
||||||
|
delete${simpleClassName}: async (id: number) => {
|
||||||
|
return await request.delete({ url: `${baseURL}/delete?id=` + id })
|
||||||
|
},
|
||||||
|
|
||||||
|
// 导出${table.classComment} Excel
|
||||||
|
export${simpleClassName}: async (params) => {
|
||||||
|
return await request.download({ url: `${baseURL}/export-excel`, params })
|
||||||
|
},
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
#set ($subPrimaryColumn = $subPrimaryColumns.get($index))##当前 primary 字段
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
|
||||||
|
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||||
|
#set ($subSimpleClassName_strikeCase = $subSimpleClassName_strikeCases.get($index))
|
||||||
|
#set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||||
|
|
||||||
|
// ==================== 子表($subTable.classComment) ====================
|
||||||
|
## 情况一:MASTER_ERP 时,需要分查询页子表
|
||||||
|
#if ( $table.templateType == 11 )
|
||||||
|
|
||||||
|
// 获得${subTable.classComment}分页
|
||||||
|
get${subSimpleClassName}Page: async (params) => {
|
||||||
|
return await request.get({ url: `${baseURL}/${subSimpleClassName_strikeCase}/page`, params })
|
||||||
|
},
|
||||||
|
## 情况二:非 MASTER_ERP 时,需要列表查询子表
|
||||||
|
#else
|
||||||
|
#if ( $subTable.subJoinMany )
|
||||||
|
|
||||||
|
// 获得${subTable.classComment}列表
|
||||||
|
get${subSimpleClassName}ListBy${SubJoinColumnName}: async (${subJoinColumn.javaField}) => {
|
||||||
|
return await request.get({ url: `${baseURL}/${subSimpleClassName_strikeCase}/list-by-${subJoinColumn_strikeCase}?${subJoinColumn.javaField}=` + ${subJoinColumn.javaField} })
|
||||||
|
},
|
||||||
|
#else
|
||||||
|
|
||||||
|
// 获得${subTable.classComment}
|
||||||
|
get${subSimpleClassName}By${SubJoinColumnName}: async (${subJoinColumn.javaField}) => {
|
||||||
|
return await request.get({ url: `${baseURL}/${subSimpleClassName_strikeCase}/get-by-${subJoinColumn_strikeCase}?${subJoinColumn.javaField}=` + ${subJoinColumn.javaField} })
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
## 特殊:MASTER_ERP 时,支持单个的新增、修改、删除操作
|
||||||
|
#if ( $table.templateType == 11 )
|
||||||
|
// 新增${subTable.classComment}
|
||||||
|
create${subSimpleClassName}: async (data) => {
|
||||||
|
return await request.post({ url: `${baseURL}/${subSimpleClassName_strikeCase}/create`, data })
|
||||||
|
},
|
||||||
|
|
||||||
|
// 修改${subTable.classComment}
|
||||||
|
update${subSimpleClassName}: async (data) => {
|
||||||
|
return await request.put({ url: `${baseURL}/${subSimpleClassName_strikeCase}/update`, data })
|
||||||
|
},
|
||||||
|
|
||||||
|
// 删除${subTable.classComment}
|
||||||
|
delete${subSimpleClassName}: async (id: number) => {
|
||||||
|
return await request.delete({ url: `${baseURL}/${subSimpleClassName_strikeCase}/delete?id=` + id })
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获得${subTable.classComment}
|
||||||
|
get${subSimpleClassName}: async (id: number) => {
|
||||||
|
return await request.get({ url: `${baseURL}/${subSimpleClassName_strikeCase}/get?id=` + id })
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
@ -0,0 +1,205 @@
|
|||||||
|
#set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($subIndex))
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
|
||||||
|
<template>
|
||||||
|
<Dialog :title="dialogTitle" v-model="dialogVisible">
|
||||||
|
<el-form
|
||||||
|
ref="formRef"
|
||||||
|
:model="formData"
|
||||||
|
:rules="formRules"
|
||||||
|
label-width="100px"
|
||||||
|
v-loading="formLoading"
|
||||||
|
>
|
||||||
|
#foreach($column in $subColumns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#set ($dictType = $column.dictType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($javaType = $column.javaType)
|
||||||
|
#set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
#set ($comment = $column.columnComment)
|
||||||
|
#set ($dictMethod = "getDictOptions")## 计算使用哪个 dict 字典方法
|
||||||
|
#if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short")
|
||||||
|
#set ($dictMethod = "getIntDictOptions")
|
||||||
|
#elseif ($javaType == "String")
|
||||||
|
#set ($dictMethod = "getStrDictOptions")
|
||||||
|
#elseif ($javaType == "Boolean")
|
||||||
|
#set ($dictMethod = "getBoolDictOptions")
|
||||||
|
#end
|
||||||
|
#if ( $column.id == $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写
|
||||||
|
#elseif ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-input v-model="formData.${javaField}" placeholder="请输入${comment}" />
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "imageUpload")## 图片上传
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<UploadImg v-model="formData.${javaField}" />
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "fileUpload")## 文件上传
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<UploadFile v-model="formData.${javaField}" />
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "editor")## 文本编辑器
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<Editor v-model="formData.${javaField}" height="150px" />
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "select")## 下拉框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-select v-model="formData.${javaField}" placeholder="请选择${comment}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<el-option
|
||||||
|
v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.label"
|
||||||
|
:value="dict.value"
|
||||||
|
/>
|
||||||
|
#else##没数据字典
|
||||||
|
<el-option label="请选择字典生成" value="" />
|
||||||
|
#end
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "checkbox")## 多选框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-checkbox-group v-model="formData.${javaField}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<el-checkbox
|
||||||
|
v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.value"
|
||||||
|
>
|
||||||
|
{{ dict.label }}
|
||||||
|
</el-checkbox>
|
||||||
|
#else##没数据字典
|
||||||
|
<el-checkbox>请选择字典生成</el-checkbox>
|
||||||
|
#end
|
||||||
|
</el-checkbox-group>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "radio")## 单选框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-radio-group v-model="formData.${javaField}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<el-radio
|
||||||
|
v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.value"
|
||||||
|
>
|
||||||
|
{{ dict.label }}
|
||||||
|
</el-radio>
|
||||||
|
#else##没数据字典
|
||||||
|
<el-radio label="1">请选择字典生成</el-radio>
|
||||||
|
#end
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "datetime")## 时间框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-date-picker
|
||||||
|
v-model="formData.${javaField}"
|
||||||
|
type="date"
|
||||||
|
value-format="x"
|
||||||
|
placeholder="选择${comment}"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "textarea")## 文本框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-input v-model="formData.${javaField}" type="textarea" placeholder="请输入${comment}" />
|
||||||
|
</el-form-item>
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
|
||||||
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||||
|
</template>
|
||||||
|
</Dialog>
|
||||||
|
</template>
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict'
|
||||||
|
import { ${simpleClassName}Api } from '@/api/${table.moduleName}/${table.businessName}'
|
||||||
|
|
||||||
|
const { t } = useI18n() // 国际化
|
||||||
|
const message = useMessage() // 消息弹窗
|
||||||
|
|
||||||
|
const dialogVisible = ref(false) // 弹窗的是否展示
|
||||||
|
const dialogTitle = ref('') // 弹窗的标题
|
||||||
|
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||||
|
const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
||||||
|
const formData = ref({
|
||||||
|
#foreach ($column in $subColumns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#if ($column.htmlType == "checkbox")
|
||||||
|
$column.javaField: [],
|
||||||
|
#else
|
||||||
|
$column.javaField: undefined,
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
})
|
||||||
|
const formRules = reactive({
|
||||||
|
#foreach ($column in $subColumns)
|
||||||
|
#if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键
|
||||||
|
#set($comment=$column.columnComment)
|
||||||
|
$column.javaField: [{ required: true, message: '${comment}不能为空', trigger: #if($column.htmlType == 'select')'change'#else'blur'#end }],
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
})
|
||||||
|
const formRef = ref() // 表单 Ref
|
||||||
|
|
||||||
|
/** 打开弹窗 */
|
||||||
|
const open = async (type: string, id?: number, ${subJoinColumn.javaField}: number) => {
|
||||||
|
dialogVisible.value = true
|
||||||
|
dialogTitle.value = t('action.' + type)
|
||||||
|
formType.value = type
|
||||||
|
resetForm()
|
||||||
|
formData.value.${subJoinColumn.javaField} = ${subJoinColumn.javaField}
|
||||||
|
// 修改时,设置数据
|
||||||
|
if (id) {
|
||||||
|
formLoading.value = true
|
||||||
|
try {
|
||||||
|
formData.value = await ${simpleClassName}Api.get${subSimpleClassName}(id)
|
||||||
|
} finally {
|
||||||
|
formLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
||||||
|
|
||||||
|
/** 提交表单 */
|
||||||
|
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
||||||
|
const submitForm = async () => {
|
||||||
|
// 校验表单
|
||||||
|
await formRef.value.validate()
|
||||||
|
// 提交请求
|
||||||
|
formLoading.value = true
|
||||||
|
try {
|
||||||
|
const data = formData.value
|
||||||
|
if (formType.value === 'create') {
|
||||||
|
await ${simpleClassName}Api.create${subSimpleClassName}(data)
|
||||||
|
message.success(t('common.createSuccess'))
|
||||||
|
} else {
|
||||||
|
await ${simpleClassName}Api.update${subSimpleClassName}(data)
|
||||||
|
message.success(t('common.updateSuccess'))
|
||||||
|
}
|
||||||
|
dialogVisible.value = false
|
||||||
|
// 发送操作成功的事件
|
||||||
|
emit('success')
|
||||||
|
} finally {
|
||||||
|
formLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 重置表单 */
|
||||||
|
const resetForm = () => {
|
||||||
|
formData.value = {
|
||||||
|
#foreach ($column in $subColumns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#if ($column.htmlType == "checkbox")
|
||||||
|
$column.javaField: [],
|
||||||
|
#else
|
||||||
|
$column.javaField: undefined,
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
formRef.value?.resetFields()
|
||||||
|
}
|
||||||
|
</script>
|
@ -0,0 +1,2 @@
|
|||||||
|
## 主表的 normal 和 inner 使用相同的 form 表单
|
||||||
|
#parse("codegen/vue3/views/components/form_sub_normal.vue.vm")
|
@ -0,0 +1,362 @@
|
|||||||
|
#set ($subTable = $subTables.get($subIndex))##当前表
|
||||||
|
#set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($subIndex))
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
|
||||||
|
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||||
|
<template>
|
||||||
|
#if ( $subTable.subJoinMany )## 情况一:一对多,table + form
|
||||||
|
<el-form
|
||||||
|
ref="formRef"
|
||||||
|
:model="formData"
|
||||||
|
:rules="formRules"
|
||||||
|
v-loading="formLoading"
|
||||||
|
label-width="0px"
|
||||||
|
:inline-message="true"
|
||||||
|
>
|
||||||
|
<el-table :data="formData" class="-mt-10px">
|
||||||
|
<el-table-column label="序号" type="index" width="100" />
|
||||||
|
#foreach($column in $subColumns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#set ($dictType = $column.dictType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($javaType = $column.javaType)
|
||||||
|
#set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
#set ($comment = $column.columnComment)
|
||||||
|
#set ($dictMethod = "getDictOptions")## 计算使用哪个 dict 字典方法
|
||||||
|
#if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short")
|
||||||
|
#set ($dictMethod = "getIntDictOptions")
|
||||||
|
#elseif ($javaType == "String")
|
||||||
|
#set ($dictMethod = "getStrDictOptions")
|
||||||
|
#elseif ($javaType == "Boolean")
|
||||||
|
#set ($dictMethod = "getBoolDictOptions")
|
||||||
|
#end
|
||||||
|
#if ( $column.id == $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写
|
||||||
|
#elseif ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里
|
||||||
|
<el-table-column label="${comment}" min-width="150">
|
||||||
|
<template #default="{ row, $index }">
|
||||||
|
<el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!">
|
||||||
|
<el-input v-model="row.${javaField}" placeholder="请输入${comment}" />
|
||||||
|
</el-form-item>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#elseif($column.htmlType == "imageUpload")## 图片上传
|
||||||
|
<el-table-column label="${comment}" min-width="200">
|
||||||
|
<template #default="{ row, $index }">
|
||||||
|
<el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!">
|
||||||
|
<UploadImg v-model="row.${javaField}" />
|
||||||
|
</el-form-item>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#elseif($column.htmlType == "fileUpload")## 文件上传
|
||||||
|
<el-table-column label="${comment}" min-width="200">
|
||||||
|
<template #default="{ row, $index }">
|
||||||
|
<el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!">
|
||||||
|
<UploadFile v-model="row.${javaField}" />
|
||||||
|
</el-form-item>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#elseif($column.htmlType == "editor")## 文本编辑器
|
||||||
|
<el-table-column label="${comment}" min-width="400">
|
||||||
|
<template #default="{ row, $index }">
|
||||||
|
<el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!">
|
||||||
|
<Editor v-model="row.${javaField}" height="150px" />
|
||||||
|
</el-form-item>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#elseif($column.htmlType == "select")## 下拉框
|
||||||
|
<el-table-column label="${comment}" min-width="150">
|
||||||
|
<template #default="{ row, $index }">
|
||||||
|
<el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!">
|
||||||
|
<el-select v-model="row.${javaField}" placeholder="请选择${comment}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<el-option
|
||||||
|
v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.label"
|
||||||
|
:value="dict.value"
|
||||||
|
/>
|
||||||
|
#else##没数据字典
|
||||||
|
<el-option label="请选择字典生成" value="" />
|
||||||
|
#end
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#elseif($column.htmlType == "checkbox")## 多选框
|
||||||
|
<el-table-column label="${comment}" min-width="150">
|
||||||
|
<template #default="{ row, $index }">
|
||||||
|
<el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!">
|
||||||
|
<el-checkbox-group v-model="row.${javaField}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<el-checkbox
|
||||||
|
v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.value"
|
||||||
|
>
|
||||||
|
{{ dict.label }}
|
||||||
|
</el-checkbox>
|
||||||
|
#else##没数据字典
|
||||||
|
<el-checkbox>请选择字典生成</el-checkbox>
|
||||||
|
#end
|
||||||
|
</el-checkbox-group>
|
||||||
|
</el-form-item>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#elseif($column.htmlType == "radio")## 单选框
|
||||||
|
<el-table-column label="${comment}" min-width="150">
|
||||||
|
<template #default="{ row, $index }">
|
||||||
|
<el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!">
|
||||||
|
<el-radio-group v-model="row.${javaField}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<el-radio
|
||||||
|
v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.value"
|
||||||
|
>
|
||||||
|
{{ dict.label }}
|
||||||
|
</el-radio>
|
||||||
|
#else##没数据字典
|
||||||
|
<el-radio label="1">请选择字典生成</el-radio>
|
||||||
|
#end
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#elseif($column.htmlType == "datetime")## 时间框
|
||||||
|
<el-table-column label="${comment}" min-width="150">
|
||||||
|
<template #default="{ row, $index }">
|
||||||
|
<el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!">
|
||||||
|
<el-date-picker
|
||||||
|
v-model="row.${javaField}"
|
||||||
|
type="date"
|
||||||
|
value-format="x"
|
||||||
|
placeholder="选择${comment}"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#elseif($column.htmlType == "textarea")## 文本框
|
||||||
|
<el-table-column label="${comment}" min-width="200">
|
||||||
|
<template #default="{ row, $index }">
|
||||||
|
<el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!">
|
||||||
|
<el-input v-model="row.${javaField}" type="textarea" placeholder="请输入${comment}" />
|
||||||
|
</el-form-item>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
<el-table-column align="center" fixed="right" label="操作" width="60">
|
||||||
|
<template #default="{ $index }">
|
||||||
|
<el-button @click="handleDelete($index)" link>—</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
</el-form>
|
||||||
|
<el-row justify="center" class="mt-3">
|
||||||
|
<el-button @click="handleAdd" round>+ 添加${subTable.classComment}</el-button>
|
||||||
|
</el-row>
|
||||||
|
#else## 情况二:一对一,form
|
||||||
|
<el-form
|
||||||
|
ref="formRef"
|
||||||
|
:model="formData"
|
||||||
|
:rules="formRules"
|
||||||
|
label-width="100px"
|
||||||
|
v-loading="formLoading"
|
||||||
|
>
|
||||||
|
#foreach($column in $subColumns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#set ($dictType = $column.dictType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($javaType = $column.javaType)
|
||||||
|
#set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
#set ($comment = $column.columnComment)
|
||||||
|
#set ($dictMethod = "getDictOptions")## 计算使用哪个 dict 字典方法
|
||||||
|
#if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short")
|
||||||
|
#set ($dictMethod = "getIntDictOptions")
|
||||||
|
#elseif ($javaType == "String")
|
||||||
|
#set ($dictMethod = "getStrDictOptions")
|
||||||
|
#elseif ($javaType == "Boolean")
|
||||||
|
#set ($dictMethod = "getBoolDictOptions")
|
||||||
|
#end
|
||||||
|
#if ( $column.id == $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写
|
||||||
|
#elseif ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-input v-model="formData.${javaField}" placeholder="请输入${comment}" />
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "imageUpload")## 图片上传
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<UploadImg v-model="formData.${javaField}" />
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "fileUpload")## 文件上传
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<UploadFile v-model="formData.${javaField}" />
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "editor")## 文本编辑器
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<Editor v-model="formData.${javaField}" height="150px" />
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "select")## 下拉框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-select v-model="formData.${javaField}" placeholder="请选择${comment}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<el-option
|
||||||
|
v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.label"
|
||||||
|
:value="dict.value"
|
||||||
|
/>
|
||||||
|
#else##没数据字典
|
||||||
|
<el-option label="请选择字典生成" value="" />
|
||||||
|
#end
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "checkbox")## 多选框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-checkbox-group v-model="formData.${javaField}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<el-checkbox
|
||||||
|
v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.value"
|
||||||
|
>
|
||||||
|
{{ dict.label }}
|
||||||
|
</el-checkbox>
|
||||||
|
#else##没数据字典
|
||||||
|
<el-checkbox>请选择字典生成</el-checkbox>
|
||||||
|
#end
|
||||||
|
</el-checkbox-group>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "radio")## 单选框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-radio-group v-model="formData.${javaField}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<el-radio
|
||||||
|
v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.value"
|
||||||
|
>
|
||||||
|
{{ dict.label }}
|
||||||
|
</el-radio>
|
||||||
|
#else##没数据字典
|
||||||
|
<el-radio label="1">请选择字典生成</el-radio>
|
||||||
|
#end
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "datetime")## 时间框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-date-picker
|
||||||
|
v-model="formData.${javaField}"
|
||||||
|
type="date"
|
||||||
|
value-format="x"
|
||||||
|
placeholder="选择${comment}"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "textarea")## 文本框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-input v-model="formData.${javaField}" type="textarea" placeholder="请输入${comment}" />
|
||||||
|
</el-form-item>
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
</el-form>
|
||||||
|
#end
|
||||||
|
</template>
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict'
|
||||||
|
import { ${simpleClassName}Api } from '@/api/${table.moduleName}/${table.businessName}'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
${subJoinColumn.javaField}: undefined // ${subJoinColumn.columnComment}(主表的关联字段)
|
||||||
|
}>()
|
||||||
|
const formLoading = ref(false) // 表单的加载中
|
||||||
|
const formData = ref([])
|
||||||
|
const formRules = reactive({
|
||||||
|
#foreach ($column in $subColumns)
|
||||||
|
#if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键
|
||||||
|
#set($comment=$column.columnComment)
|
||||||
|
$column.javaField: [{ required: true, message: '${comment}不能为空', trigger: #if($column.htmlType == 'select')'change'#else'blur'#end }],
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
})
|
||||||
|
const formRef = ref() // 表单 Ref
|
||||||
|
|
||||||
|
/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
||||||
|
watch(
|
||||||
|
() => props.${subJoinColumn.javaField},
|
||||||
|
async (val) => {
|
||||||
|
// 1. 重置表单
|
||||||
|
#if ( $subTable.subJoinMany )
|
||||||
|
formData.value = []
|
||||||
|
#else
|
||||||
|
formData.value = {
|
||||||
|
#foreach ($column in $subColumns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#if ($column.htmlType == "checkbox")
|
||||||
|
$column.javaField: [],
|
||||||
|
#else
|
||||||
|
$column.javaField: undefined,
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
// 2. val 非空,则加载数据
|
||||||
|
if (!val) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
formLoading.value = true
|
||||||
|
#if ( $subTable.subJoinMany )
|
||||||
|
formData.value = await ${simpleClassName}Api.get${subSimpleClassName}ListBy${SubJoinColumnName}(val)
|
||||||
|
#else
|
||||||
|
const data = await ${simpleClassName}Api.get${subSimpleClassName}By${SubJoinColumnName}(val)
|
||||||
|
if (!data) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
formData.value = data
|
||||||
|
#end
|
||||||
|
} finally {
|
||||||
|
formLoading.value = false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ immediate: true }
|
||||||
|
)
|
||||||
|
#if ( $subTable.subJoinMany )
|
||||||
|
|
||||||
|
/** 新增按钮操作 */
|
||||||
|
const handleAdd = () => {
|
||||||
|
const row = {
|
||||||
|
#foreach ($column in $subColumns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#if ($column.htmlType == "checkbox")
|
||||||
|
$column.javaField: [],
|
||||||
|
#else
|
||||||
|
$column.javaField: undefined,
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
row.${subJoinColumn.javaField} = props.${subJoinColumn.javaField}
|
||||||
|
formData.value.push(row)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除按钮操作 */
|
||||||
|
const handleDelete = (index) => {
|
||||||
|
formData.value.splice(index, 1)
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
|
||||||
|
/** 表单校验 */
|
||||||
|
const validate = () => {
|
||||||
|
return formRef.value.validate()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 表单值 */
|
||||||
|
const getData = () => {
|
||||||
|
return formData.value
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({ validate, getData })
|
||||||
|
</script>
|
@ -0,0 +1,184 @@
|
|||||||
|
#set ($subTable = $subTables.get($subIndex))##当前表
|
||||||
|
#set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($subIndex))
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段
|
||||||
|
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||||
|
<template>
|
||||||
|
<!-- 列表 -->
|
||||||
|
<ContentWrap>
|
||||||
|
#if ($table.templateType == 11)
|
||||||
|
<el-button
|
||||||
|
type="primary"
|
||||||
|
plain
|
||||||
|
@click="openForm('create')"
|
||||||
|
v-hasPermi="['${permissionPrefix}:create']"
|
||||||
|
>
|
||||||
|
<Icon icon="ep:plus" class="mr-5px" /> 新增
|
||||||
|
</el-button>
|
||||||
|
#end
|
||||||
|
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
|
||||||
|
#foreach($column in $subColumns)
|
||||||
|
#if ($column.listOperationResult)
|
||||||
|
#set ($dictType=$column.dictType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
#set ($comment=$column.columnComment)
|
||||||
|
#if ( $column.id == $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写
|
||||||
|
#elseif ($column.javaType == "LocalDateTime")## 时间类型
|
||||||
|
<el-table-column
|
||||||
|
label="${comment}"
|
||||||
|
align="center"
|
||||||
|
prop="${javaField}"
|
||||||
|
:formatter="dateFormatter"
|
||||||
|
width="180px"
|
||||||
|
/>
|
||||||
|
#elseif($column.dictType && "" != $column.dictType)## 数据字典
|
||||||
|
<el-table-column label="${comment}" align="center" prop="${javaField}">
|
||||||
|
<template #default="scope">
|
||||||
|
<dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.${column.javaField}" />
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#else
|
||||||
|
<el-table-column label="${comment}" align="center" prop="${javaField}" />
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#if ($table.templateType == 11)
|
||||||
|
<el-table-column label="操作" align="center">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-button
|
||||||
|
link
|
||||||
|
type="primary"
|
||||||
|
@click="openForm('update', scope.row.id)"
|
||||||
|
v-hasPermi="['${permissionPrefix}:update']"
|
||||||
|
>
|
||||||
|
编辑
|
||||||
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
link
|
||||||
|
type="danger"
|
||||||
|
@click="handleDelete(scope.row.id)"
|
||||||
|
v-hasPermi="['${permissionPrefix}:delete']"
|
||||||
|
>
|
||||||
|
删除
|
||||||
|
</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#end
|
||||||
|
</el-table>
|
||||||
|
#if ($table.templateType == 11)
|
||||||
|
<!-- 分页 -->
|
||||||
|
<Pagination
|
||||||
|
:total="total"
|
||||||
|
v-model:page="queryParams.pageNo"
|
||||||
|
v-model:limit="queryParams.pageSize"
|
||||||
|
@pagination="getList"
|
||||||
|
/>
|
||||||
|
#end
|
||||||
|
</ContentWrap>
|
||||||
|
#if ($table.templateType == 11)
|
||||||
|
<!-- 表单弹窗:添加/修改 -->
|
||||||
|
<${subSimpleClassName}Form ref="formRef" @success="getList" />
|
||||||
|
#end
|
||||||
|
</template>
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict'
|
||||||
|
import { dateFormatter } from '@/utils/formatTime'
|
||||||
|
import { ${simpleClassName}Api } from '@/api/${table.moduleName}/${table.businessName}'
|
||||||
|
#if ($table.templateType == 11)
|
||||||
|
import ${subSimpleClassName}Form from './${subSimpleClassName}Form.vue'
|
||||||
|
#end
|
||||||
|
|
||||||
|
const { t } = useI18n() // 国际化
|
||||||
|
const message = useMessage() // 消息弹窗
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
${subJoinColumn.javaField}?: number // ${subJoinColumn.columnComment}(主表的关联字段)
|
||||||
|
}>()
|
||||||
|
const loading = ref(false) // 列表的加载中
|
||||||
|
const list = ref([]) // 列表的数据
|
||||||
|
#if ($table.templateType == 11)
|
||||||
|
const total = ref(0) // 列表的总页数
|
||||||
|
const queryParams = reactive({
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
${subJoinColumn.javaField}: undefined as unknown
|
||||||
|
})
|
||||||
|
|
||||||
|
/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
||||||
|
watch(
|
||||||
|
() => props.${subJoinColumn.javaField},
|
||||||
|
(val: number) => {
|
||||||
|
if (!val) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
queryParams.${subJoinColumn.javaField} = val
|
||||||
|
handleQuery()
|
||||||
|
},
|
||||||
|
{ immediate: true, deep: true }
|
||||||
|
)
|
||||||
|
#end
|
||||||
|
|
||||||
|
/** 查询列表 */
|
||||||
|
const getList = async () => {
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
#if ($table.templateType == 11)
|
||||||
|
const data = await ${simpleClassName}Api.get${subSimpleClassName}Page(queryParams)
|
||||||
|
list.value = data.list
|
||||||
|
total.value = data.total
|
||||||
|
#else
|
||||||
|
#if ( $subTable.subJoinMany )
|
||||||
|
list.value = await ${simpleClassName}Api.get${subSimpleClassName}ListBy${SubJoinColumnName}(props.${subJoinColumn.javaField})
|
||||||
|
#else
|
||||||
|
const data = await ${simpleClassName}Api.get${subSimpleClassName}By${SubJoinColumnName}(props.${subJoinColumn.javaField})
|
||||||
|
if (!data) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
list.value.push(data)
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 搜索按钮操作 */
|
||||||
|
const handleQuery = () => {
|
||||||
|
queryParams.pageNo = 1
|
||||||
|
getList()
|
||||||
|
}
|
||||||
|
#if ($table.templateType == 11)
|
||||||
|
|
||||||
|
/** 添加/修改操作 */
|
||||||
|
const formRef = ref()
|
||||||
|
const openForm = (type: string, id?: number) => {
|
||||||
|
if (!props.${subJoinColumn.javaField}) {
|
||||||
|
message.error('请选择一个${table.classComment}')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
formRef.value.open(type, id, props.${subJoinColumn.javaField})
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除按钮操作 */
|
||||||
|
const handleDelete = async (id: number) => {
|
||||||
|
try {
|
||||||
|
// 删除的二次确认
|
||||||
|
await message.delConfirm()
|
||||||
|
// 发起删除
|
||||||
|
await ${simpleClassName}Api.delete${subSimpleClassName}(id)
|
||||||
|
message.success(t('common.delSuccess'))
|
||||||
|
// 刷新列表
|
||||||
|
await getList()
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
#if ($table.templateType != 11)
|
||||||
|
|
||||||
|
/** 初始化 **/
|
||||||
|
onMounted(() => {
|
||||||
|
getList()
|
||||||
|
})
|
||||||
|
#end
|
||||||
|
</script>
|
@ -0,0 +1,4 @@
|
|||||||
|
## 子表的 erp 和 inner 使用相似的 list 列表,差异主要两点:
|
||||||
|
## 1)inner 使用 list 不分页,erp 使用 page 分页
|
||||||
|
## 2)erp 支持单个子表的新增、修改、删除,inner 不支持
|
||||||
|
#parse("codegen/vue3/views/components/list_sub_erp.vue.vm")
|
@ -0,0 +1,301 @@
|
|||||||
|
<template>
|
||||||
|
<Dialog :title="dialogTitle" v-model="dialogVisible">
|
||||||
|
<el-form
|
||||||
|
ref="formRef"
|
||||||
|
:model="formData"
|
||||||
|
:rules="formRules"
|
||||||
|
label-width="100px"
|
||||||
|
v-loading="formLoading"
|
||||||
|
>
|
||||||
|
#foreach($column in $columns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#set ($dictType = $column.dictType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($javaType = $column.javaType)
|
||||||
|
#set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
#set ($comment = $column.columnComment)
|
||||||
|
#set ($dictMethod = "getDictOptions")## 计算使用哪个 dict 字典方法
|
||||||
|
#if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short")
|
||||||
|
#set ($dictMethod = "getIntDictOptions")
|
||||||
|
#elseif ($javaType == "String")
|
||||||
|
#set ($dictMethod = "getStrDictOptions")
|
||||||
|
#elseif ($javaType == "Boolean")
|
||||||
|
#set ($dictMethod = "getBoolDictOptions")
|
||||||
|
#end
|
||||||
|
#if ( $table.templateType == 2 && $column.id == $treeParentColumn.id )
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-tree-select
|
||||||
|
v-model="formData.${javaField}"
|
||||||
|
:data="${classNameVar}Tree"
|
||||||
|
#if ($treeNameColumn.javaField == "name")
|
||||||
|
:props="defaultProps"
|
||||||
|
#else
|
||||||
|
:props="{...defaultProps, label: '$treeNameColumn.javaField'}"
|
||||||
|
#end
|
||||||
|
check-strictly
|
||||||
|
default-expand-all
|
||||||
|
placeholder="请选择${comment}"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-input v-model="formData.${javaField}" placeholder="请输入${comment}" />
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "imageUpload")## 图片上传
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<UploadImg v-model="formData.${javaField}" />
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "fileUpload")## 文件上传
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<UploadFile v-model="formData.${javaField}" />
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "editor")## 文本编辑器
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<Editor v-model="formData.${javaField}" height="150px" />
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "select")## 下拉框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-select v-model="formData.${javaField}" placeholder="请选择${comment}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<el-option
|
||||||
|
v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.label"
|
||||||
|
:value="dict.value"
|
||||||
|
/>
|
||||||
|
#else##没数据字典
|
||||||
|
<el-option label="请选择字典生成" value="" />
|
||||||
|
#end
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "checkbox")## 多选框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-checkbox-group v-model="formData.${javaField}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<el-checkbox
|
||||||
|
v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.value"
|
||||||
|
>
|
||||||
|
{{ dict.label }}
|
||||||
|
</el-checkbox>
|
||||||
|
#else##没数据字典
|
||||||
|
<el-checkbox>请选择字典生成</el-checkbox>
|
||||||
|
#end
|
||||||
|
</el-checkbox-group>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "radio")## 单选框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-radio-group v-model="formData.${javaField}">
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
<el-radio
|
||||||
|
v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.value"
|
||||||
|
>
|
||||||
|
{{ dict.label }}
|
||||||
|
</el-radio>
|
||||||
|
#else##没数据字典
|
||||||
|
<el-radio label="1">请选择字典生成</el-radio>
|
||||||
|
#end
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "datetime")## 时间框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-date-picker
|
||||||
|
v-model="formData.${javaField}"
|
||||||
|
type="date"
|
||||||
|
value-format="x"
|
||||||
|
placeholder="选择${comment}"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "textarea")## 文本框
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-input v-model="formData.${javaField}" type="textarea" placeholder="请输入${comment}" />
|
||||||
|
</el-form-item>
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
</el-form>
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||||
|
<!-- 子表的表单 -->
|
||||||
|
<el-tabs v-model="subTabsName">
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
#set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
|
||||||
|
<el-tab-pane label="${subTable.classComment}" name="$subClassNameVar">
|
||||||
|
<${subSimpleClassName}Form ref="${subClassNameVar}FormRef" :${subJoinColumn_strikeCase}="formData.id" />
|
||||||
|
</el-tab-pane>
|
||||||
|
#end
|
||||||
|
</el-tabs>
|
||||||
|
#end
|
||||||
|
<template #footer>
|
||||||
|
<el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
|
||||||
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||||
|
</template>
|
||||||
|
</Dialog>
|
||||||
|
</template>
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict'
|
||||||
|
import { ${simpleClassName}Api, ${simpleClassName}VO } from '@/api/${table.moduleName}/${table.businessName}'
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
import { defaultProps, handleTree } from '@/utils/tree'
|
||||||
|
#end
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||||
|
#foreach ($subSimpleClassName in $subSimpleClassNames)
|
||||||
|
import ${subSimpleClassName}Form from './components/${subSimpleClassName}Form.vue'
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
|
||||||
|
/** ${table.classComment} 表单 */
|
||||||
|
defineOptions({ name: '${simpleClassName}Form' })
|
||||||
|
|
||||||
|
const { t } = useI18n() // 国际化
|
||||||
|
const message = useMessage() // 消息弹窗
|
||||||
|
|
||||||
|
const dialogVisible = ref(false) // 弹窗的是否展示
|
||||||
|
const dialogTitle = ref('') // 弹窗的标题
|
||||||
|
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||||
|
const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
||||||
|
const formData = ref({
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#if ($column.htmlType == "checkbox")
|
||||||
|
$column.javaField: [],
|
||||||
|
#else
|
||||||
|
$column.javaField: undefined,
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
})
|
||||||
|
const formRules = reactive({
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键
|
||||||
|
#set($comment=$column.columnComment)
|
||||||
|
$column.javaField: [{ required: true, message: '${comment}不能为空', trigger: #if($column.htmlType == 'select')'change'#else'blur'#end }],
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
})
|
||||||
|
const formRef = ref() // 表单 Ref
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
const ${classNameVar}Tree = ref() // 树形结构
|
||||||
|
#end
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||||
|
#if ( $subTables && $subTables.size() > 0 )
|
||||||
|
|
||||||
|
/** 子表的表单 */
|
||||||
|
const subTabsName = ref('$subClassNameVars.get(0)')
|
||||||
|
#foreach ($subClassNameVar in $subClassNameVars)
|
||||||
|
const ${subClassNameVar}FormRef = ref()
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
|
||||||
|
/** 打开弹窗 */
|
||||||
|
const open = async (type: string, id?: number) => {
|
||||||
|
dialogVisible.value = true
|
||||||
|
dialogTitle.value = t('action.' + type)
|
||||||
|
formType.value = type
|
||||||
|
resetForm()
|
||||||
|
// 修改时,设置数据
|
||||||
|
if (id) {
|
||||||
|
formLoading.value = true
|
||||||
|
try {
|
||||||
|
formData.value = await ${simpleClassName}Api.get${simpleClassName}(id)
|
||||||
|
} finally {
|
||||||
|
formLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
await get${simpleClassName}Tree()
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
||||||
|
|
||||||
|
/** 提交表单 */
|
||||||
|
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
||||||
|
const submitForm = async () => {
|
||||||
|
// 校验表单
|
||||||
|
await formRef.value.validate()
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||||
|
#if ( $subTables && $subTables.size() > 0 )
|
||||||
|
// 校验子表单
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||||
|
try {
|
||||||
|
await ${subClassNameVar}FormRef.value.validate()
|
||||||
|
} catch (e) {
|
||||||
|
subTabsName.value = '${subClassNameVar}'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
// 提交请求
|
||||||
|
formLoading.value = true
|
||||||
|
try {
|
||||||
|
const data = formData.value as unknown as ${simpleClassName}VO
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||||
|
#if ( $subTables && $subTables.size() > 0 )
|
||||||
|
// 拼接子表的数据
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||||
|
data.${subClassNameVar}#if ( $subTable.subJoinMany)s#end = ${subClassNameVar}FormRef.value.getData()
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
if (formType.value === 'create') {
|
||||||
|
await ${simpleClassName}Api.create${simpleClassName}(data)
|
||||||
|
message.success(t('common.createSuccess'))
|
||||||
|
} else {
|
||||||
|
await ${simpleClassName}Api.update${simpleClassName}(data)
|
||||||
|
message.success(t('common.updateSuccess'))
|
||||||
|
}
|
||||||
|
dialogVisible.value = false
|
||||||
|
// 发送操作成功的事件
|
||||||
|
emit('success')
|
||||||
|
} finally {
|
||||||
|
formLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 重置表单 */
|
||||||
|
const resetForm = () => {
|
||||||
|
formData.value = {
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#if ($column.htmlType == "checkbox")
|
||||||
|
$column.javaField: [],
|
||||||
|
#else
|
||||||
|
$column.javaField: undefined,
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
formRef.value?.resetFields()
|
||||||
|
}
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
|
||||||
|
/** 获得${table.classComment}树 */
|
||||||
|
const get${simpleClassName}Tree = async () => {
|
||||||
|
${classNameVar}Tree.value = []
|
||||||
|
const data = await ${simpleClassName}Api.get${simpleClassName}List()
|
||||||
|
const root: Tree = { id: 0, name: '顶级${table.classComment}', children: [] }
|
||||||
|
root.children = handleTree(data, 'id', '${treeParentColumn.javaField}')
|
||||||
|
${classNameVar}Tree.value.push(root)
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
</script>
|
@ -0,0 +1,374 @@
|
|||||||
|
<template>
|
||||||
|
<ContentWrap>
|
||||||
|
<!-- 搜索工作栏 -->
|
||||||
|
<el-form
|
||||||
|
class="-mb-15px"
|
||||||
|
:model="queryParams"
|
||||||
|
ref="queryFormRef"
|
||||||
|
:inline="true"
|
||||||
|
label-width="68px"
|
||||||
|
>
|
||||||
|
#foreach($column in $columns)
|
||||||
|
#if ($column.listOperation)
|
||||||
|
#set ($dictType = $column.dictType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($javaType = $column.javaType)
|
||||||
|
#set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
#set ($comment = $column.columnComment)
|
||||||
|
#set ($dictMethod = "getDictOptions")## 计算使用哪个 dict 字典方法
|
||||||
|
#if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short")
|
||||||
|
#set ($dictMethod = "getIntDictOptions")
|
||||||
|
#elseif ($javaType == "String")
|
||||||
|
#set ($dictMethod = "getStrDictOptions")
|
||||||
|
#elseif ($javaType == "Boolean")
|
||||||
|
#set ($dictMethod = "getBoolDictOptions")
|
||||||
|
#end
|
||||||
|
#if ($column.htmlType == "input")
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-input
|
||||||
|
v-model="queryParams.${javaField}"
|
||||||
|
placeholder="请输入${comment}"
|
||||||
|
clearable
|
||||||
|
@keyup.enter="handleQuery"
|
||||||
|
class="!w-240px"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif ($column.htmlType == "select" || $column.htmlType == "radio")
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-select
|
||||||
|
v-model="queryParams.${javaField}"
|
||||||
|
placeholder="请选择${comment}"
|
||||||
|
clearable
|
||||||
|
class="!w-240px"
|
||||||
|
>
|
||||||
|
#if ("" != $dictType)## 设置了 dictType 数据字典的情况
|
||||||
|
<el-option
|
||||||
|
v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.label"
|
||||||
|
:value="dict.value"
|
||||||
|
/>
|
||||||
|
#else## 未设置 dictType 数据字典的情况
|
||||||
|
<el-option label="请选择字典生成" value="" />
|
||||||
|
#end
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "datetime")
|
||||||
|
#if ($column.listOperationCondition != "BETWEEN")## 非范围
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-date-picker
|
||||||
|
v-model="queryParams.${javaField}"
|
||||||
|
value-format="YYYY-MM-DD"
|
||||||
|
type="date"
|
||||||
|
placeholder="选择${comment}"
|
||||||
|
clearable
|
||||||
|
class="!w-240px"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
#else## 范围
|
||||||
|
<el-form-item label="${comment}" prop="${javaField}">
|
||||||
|
<el-date-picker
|
||||||
|
v-model="queryParams.${javaField}"
|
||||||
|
value-format="YYYY-MM-DD HH:mm:ss"
|
||||||
|
type="daterange"
|
||||||
|
start-placeholder="开始日期"
|
||||||
|
end-placeholder="结束日期"
|
||||||
|
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
|
||||||
|
class="!w-240px"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
<el-form-item>
|
||||||
|
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
|
||||||
|
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
|
||||||
|
<el-button
|
||||||
|
type="primary"
|
||||||
|
plain
|
||||||
|
@click="openForm('create')"
|
||||||
|
v-hasPermi="['${permissionPrefix}:create']"
|
||||||
|
>
|
||||||
|
<Icon icon="ep:plus" class="mr-5px" /> 新增
|
||||||
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
type="success"
|
||||||
|
plain
|
||||||
|
@click="handleExport"
|
||||||
|
:loading="exportLoading"
|
||||||
|
v-hasPermi="['${permissionPrefix}:export']"
|
||||||
|
>
|
||||||
|
<Icon icon="ep:download" class="mr-5px" /> 导出
|
||||||
|
</el-button>
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
<el-button type="danger" plain @click="toggleExpandAll">
|
||||||
|
<Icon icon="ep:sort" class="mr-5px" /> 展开/折叠
|
||||||
|
</el-button>
|
||||||
|
#end
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
</ContentWrap>
|
||||||
|
|
||||||
|
<!-- 列表 -->
|
||||||
|
<ContentWrap>
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 )
|
||||||
|
<el-table
|
||||||
|
v-loading="loading"
|
||||||
|
:data="list"
|
||||||
|
:stripe="true"
|
||||||
|
:show-overflow-tooltip="true"
|
||||||
|
highlight-current-row
|
||||||
|
@current-change="handleCurrentChange"
|
||||||
|
>
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#elseif ( $table.templateType == 2 )
|
||||||
|
<el-table
|
||||||
|
v-loading="loading"
|
||||||
|
:data="list"
|
||||||
|
:stripe="true"
|
||||||
|
:show-overflow-tooltip="true"
|
||||||
|
row-key="id"
|
||||||
|
:default-expand-all="isExpandAll"
|
||||||
|
v-if="refreshTable"
|
||||||
|
>
|
||||||
|
#else
|
||||||
|
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
|
||||||
|
#end
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 12 && $subTables && $subTables.size() > 0 )
|
||||||
|
<!-- 子表的列表 -->
|
||||||
|
<el-table-column type="expand">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-tabs model-value="$subClassNameVars.get(0)">
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
#set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
|
||||||
|
<el-tab-pane label="${subTable.classComment}" name="$subClassNameVar">
|
||||||
|
<${subSimpleClassName}List :${subJoinColumn_strikeCase}="scope.row.id" />
|
||||||
|
</el-tab-pane>
|
||||||
|
#end
|
||||||
|
</el-tabs>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#end
|
||||||
|
#foreach($column in $columns)
|
||||||
|
#if ($column.listOperationResult)
|
||||||
|
#set ($dictType=$column.dictType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
#set ($comment=$column.columnComment)
|
||||||
|
#if ($column.javaType == "LocalDateTime")## 时间类型
|
||||||
|
<el-table-column
|
||||||
|
label="${comment}"
|
||||||
|
align="center"
|
||||||
|
prop="${javaField}"
|
||||||
|
:formatter="dateFormatter"
|
||||||
|
width="180px"
|
||||||
|
/>
|
||||||
|
#elseif($column.dictType && "" != $column.dictType)## 数据字典
|
||||||
|
<el-table-column label="${comment}" align="center" prop="${javaField}">
|
||||||
|
<template #default="scope">
|
||||||
|
<dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.${column.javaField}" />
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#else
|
||||||
|
<el-table-column label="${comment}" align="center" prop="${javaField}" />
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
<el-table-column label="操作" align="center">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-button
|
||||||
|
link
|
||||||
|
type="primary"
|
||||||
|
@click="openForm('update', scope.row.id)"
|
||||||
|
v-hasPermi="['${permissionPrefix}:update']"
|
||||||
|
>
|
||||||
|
编辑
|
||||||
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
link
|
||||||
|
type="danger"
|
||||||
|
@click="handleDelete(scope.row.id)"
|
||||||
|
v-hasPermi="['${permissionPrefix}:delete']"
|
||||||
|
>
|
||||||
|
删除
|
||||||
|
</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
<!-- 分页 -->
|
||||||
|
<Pagination
|
||||||
|
:total="total"
|
||||||
|
v-model:page="queryParams.pageNo"
|
||||||
|
v-model:limit="queryParams.pageSize"
|
||||||
|
@pagination="getList"
|
||||||
|
/>
|
||||||
|
</ContentWrap>
|
||||||
|
|
||||||
|
<!-- 表单弹窗:添加/修改 -->
|
||||||
|
<${simpleClassName}Form ref="formRef" @success="getList" />
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 )
|
||||||
|
<!-- 子表的列表 -->
|
||||||
|
<ContentWrap>
|
||||||
|
<el-tabs model-value="$subClassNameVars.get(0)">
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
#set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
|
||||||
|
<el-tab-pane label="${subTable.classComment}" name="$subClassNameVar">
|
||||||
|
<${subSimpleClassName}List :${subJoinColumn_strikeCase}="currentRow.id" />
|
||||||
|
</el-tab-pane>
|
||||||
|
#end
|
||||||
|
</el-tabs>
|
||||||
|
</ContentWrap>
|
||||||
|
#end
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict'
|
||||||
|
import { dateFormatter } from '@/utils/formatTime'
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
import { handleTree } from '@/utils/tree'
|
||||||
|
#end
|
||||||
|
import download from '@/utils/download'
|
||||||
|
import { ${simpleClassName}Api, ${simpleClassName}VO } from '@/api/${table.moduleName}/${table.businessName}'
|
||||||
|
import ${simpleClassName}Form from './${simpleClassName}Form.vue'
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType != 10 )
|
||||||
|
#foreach ($subSimpleClassName in $subSimpleClassNames)
|
||||||
|
import ${subSimpleClassName}List from './components/${subSimpleClassName}List.vue'
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
|
||||||
|
/** ${table.classComment} 列表 */
|
||||||
|
defineOptions({ name: '${table.className}' })
|
||||||
|
|
||||||
|
const message = useMessage() // 消息弹窗
|
||||||
|
const { t } = useI18n() // 国际化
|
||||||
|
|
||||||
|
const loading = ref(true) // 列表的加载中
|
||||||
|
const list = ref<${simpleClassName}VO[]>([]) // 列表的数据
|
||||||
|
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||||
|
#if ( $table.templateType != 2 )
|
||||||
|
const total = ref(0) // 列表的总页数
|
||||||
|
#end
|
||||||
|
const queryParams = reactive({
|
||||||
|
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||||
|
#if ( $table.templateType != 2 )
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
#end
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if ($column.listOperation)
|
||||||
|
#if ($column.listOperationCondition != 'BETWEEN')
|
||||||
|
$column.javaField: undefined,
|
||||||
|
#end
|
||||||
|
#if ($column.htmlType == "datetime" || $column.listOperationCondition == "BETWEEN")
|
||||||
|
$column.javaField: [],
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
})
|
||||||
|
const queryFormRef = ref() // 搜索的表单
|
||||||
|
const exportLoading = ref(false) // 导出的加载中
|
||||||
|
|
||||||
|
/** 查询列表 */
|
||||||
|
const getList = async () => {
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
const data = await ${simpleClassName}Api.get${simpleClassName}List(queryParams)
|
||||||
|
list.value = handleTree(data, 'id', '${treeParentColumn.javaField}')
|
||||||
|
#else
|
||||||
|
const data = await ${simpleClassName}Api.get${simpleClassName}Page(queryParams)
|
||||||
|
list.value = data.list
|
||||||
|
total.value = data.total
|
||||||
|
#end
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 搜索按钮操作 */
|
||||||
|
const handleQuery = () => {
|
||||||
|
queryParams.pageNo = 1
|
||||||
|
getList()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 重置按钮操作 */
|
||||||
|
const resetQuery = () => {
|
||||||
|
queryFormRef.value.resetFields()
|
||||||
|
handleQuery()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 添加/修改操作 */
|
||||||
|
const formRef = ref()
|
||||||
|
const openForm = (type: string, id?: number) => {
|
||||||
|
formRef.value.open(type, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除按钮操作 */
|
||||||
|
const handleDelete = async (id: number) => {
|
||||||
|
try {
|
||||||
|
// 删除的二次确认
|
||||||
|
await message.delConfirm()
|
||||||
|
// 发起删除
|
||||||
|
await ${simpleClassName}Api.delete${simpleClassName}(id)
|
||||||
|
message.success(t('common.delSuccess'))
|
||||||
|
// 刷新列表
|
||||||
|
await getList()
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 导出按钮操作 */
|
||||||
|
const handleExport = async () => {
|
||||||
|
try {
|
||||||
|
// 导出的二次确认
|
||||||
|
await message.exportConfirm()
|
||||||
|
// 发起导出
|
||||||
|
exportLoading.value = true
|
||||||
|
const data = await ${simpleClassName}Api.export${simpleClassName}(queryParams)
|
||||||
|
download.excel(data, '${table.classComment}.xls')
|
||||||
|
} catch {
|
||||||
|
} finally {
|
||||||
|
exportLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $table.templateType == 11 )
|
||||||
|
|
||||||
|
/** 选中行操作 */
|
||||||
|
const currentRow = ref({}) // 选中行
|
||||||
|
const handleCurrentChange = (row) => {
|
||||||
|
currentRow.value = row
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
## 特殊:树表专属逻辑
|
||||||
|
#if ( $table.templateType == 2 )
|
||||||
|
|
||||||
|
/** 展开/折叠操作 */
|
||||||
|
const isExpandAll = ref(true) // 是否展开,默认全部展开
|
||||||
|
const refreshTable = ref(true) // 重新渲染表格状态
|
||||||
|
const toggleExpandAll = async () => {
|
||||||
|
refreshTable.value = false
|
||||||
|
isExpandAll.value = !isExpandAll.value
|
||||||
|
await nextTick()
|
||||||
|
refreshTable.value = true
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
|
||||||
|
/** 初始化 **/
|
||||||
|
onMounted(() => {
|
||||||
|
getList()
|
||||||
|
})
|
||||||
|
</script>
|
@ -0,0 +1,46 @@
|
|||||||
|
import request from '@/config/axios'
|
||||||
|
#set ($baseURL = "/${table.moduleName}/${simpleClassName_strikeCase}")
|
||||||
|
|
||||||
|
export interface ${simpleClassName}VO {
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if ($column.createOperation || $column.updateOperation)
|
||||||
|
#if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer" || ${column.javaType.toLowerCase()} == "double" || ${column.javaType.toLowerCase()} == "bigdecimal")
|
||||||
|
${column.javaField}: number
|
||||||
|
#elseif(${column.javaType.toLowerCase()} == "date" || ${column.javaType.toLowerCase()} == "localdatetime")
|
||||||
|
${column.javaField}: Date
|
||||||
|
#else
|
||||||
|
${column.javaField}: ${column.javaType.toLowerCase()}
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询${table.classComment}列表
|
||||||
|
export const get${simpleClassName}Page = async (params) => {
|
||||||
|
return await request.get({ url: '${baseURL}/page', params })
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询${table.classComment}详情
|
||||||
|
export const get${simpleClassName} = async (id: number) => {
|
||||||
|
return await request.get({ url: '${baseURL}/get?id=' + id })
|
||||||
|
}
|
||||||
|
|
||||||
|
// 新增${table.classComment}
|
||||||
|
export const create${simpleClassName} = async (data: ${simpleClassName}VO) => {
|
||||||
|
return await request.post({ url: '${baseURL}/create', data })
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改${table.classComment}
|
||||||
|
export const update${simpleClassName} = async (data: ${simpleClassName}VO) => {
|
||||||
|
return await request.put({ url: '${baseURL}/update', data })
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除${table.classComment}
|
||||||
|
export const delete${simpleClassName} = async (id: number) => {
|
||||||
|
return await request.delete({ url: '${baseURL}/delete?id=' + id })
|
||||||
|
}
|
||||||
|
|
||||||
|
// 导出${table.classComment} Excel
|
||||||
|
export const export${simpleClassName}Api = async (params) => {
|
||||||
|
return await request.download({ url: '${baseURL}/export-excel', params })
|
||||||
|
}
|
@ -0,0 +1,124 @@
|
|||||||
|
import type { CrudSchema } from '@/hooks/web/useCrudSchemas'
|
||||||
|
import { dateFormatter } from '@/utils/formatTime'
|
||||||
|
|
||||||
|
// 表单校验
|
||||||
|
export const rules = reactive({
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键
|
||||||
|
#set($comment=$column.columnComment)
|
||||||
|
$column.javaField: [required],
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
})
|
||||||
|
|
||||||
|
// CrudSchema https://doc.iocoder.cn/vue3/crud-schema/
|
||||||
|
const crudSchemas = reactive<CrudSchema[]>([
|
||||||
|
#foreach($column in $columns)
|
||||||
|
#if ($column.listOperation || $column.listOperationResult || $column.createOperation || $column.updateOperation)
|
||||||
|
#set ($dictType = $column.dictType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($javaType = $column.javaType)
|
||||||
|
{
|
||||||
|
label: '${column.columnComment}',
|
||||||
|
field: '${column.javaField}',
|
||||||
|
## ========= 字典部分 =========
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
dictType: DICT_TYPE.$dictType.toUpperCase(),
|
||||||
|
#if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short")
|
||||||
|
dictClass: 'number',
|
||||||
|
#elseif ($javaType == "String")
|
||||||
|
dictClass: 'string',
|
||||||
|
#elseif ($javaType == "Boolean")
|
||||||
|
dictClass: 'boolean',
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
## ========= Table 表格部分 =========
|
||||||
|
#if (!$column.listOperationResult)
|
||||||
|
isTable: false,
|
||||||
|
#else
|
||||||
|
#if ($column.htmlType == "datetime")
|
||||||
|
formatter: dateFormatter,
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
## ========= Search 表格部分 =========
|
||||||
|
#if ($column.listOperation)
|
||||||
|
isSearch: true,
|
||||||
|
#if ($column.htmlType == "datetime")
|
||||||
|
search: {
|
||||||
|
component: 'DatePicker',
|
||||||
|
componentProps: {
|
||||||
|
valueFormat: 'YYYY-MM-DD HH:mm:ss',
|
||||||
|
type: 'daterange',
|
||||||
|
defaultTime: [new Date('1 00:00:00'), new Date('1 23:59:59')]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
## ========= Form 表单部分 =========
|
||||||
|
#if ((!$column.createOperation && !$column.updateOperation) || $column.primaryKey)
|
||||||
|
isForm: false,
|
||||||
|
#else
|
||||||
|
#if($column.htmlType == "imageUpload")## 图片上传
|
||||||
|
form: {
|
||||||
|
component: 'UploadImg'
|
||||||
|
},
|
||||||
|
#elseif($column.htmlType == "fileUpload")## 文件上传
|
||||||
|
form: {
|
||||||
|
component: 'UploadFile'
|
||||||
|
},
|
||||||
|
#elseif($column.htmlType == "editor")## 文本编辑器
|
||||||
|
form: {
|
||||||
|
component: 'Editor',
|
||||||
|
componentProps: {
|
||||||
|
valueHtml: '',
|
||||||
|
height: 200
|
||||||
|
}
|
||||||
|
},
|
||||||
|
#elseif($column.htmlType == "select")## 下拉框
|
||||||
|
form: {
|
||||||
|
component: 'SelectV2'
|
||||||
|
},
|
||||||
|
#elseif($column.htmlType == "checkbox")## 多选框
|
||||||
|
form: {
|
||||||
|
component: 'Checkbox'
|
||||||
|
},
|
||||||
|
#elseif($column.htmlType == "radio")## 单选框
|
||||||
|
form: {
|
||||||
|
component: 'Radio'
|
||||||
|
},
|
||||||
|
#elseif($column.htmlType == "datetime")## 时间框
|
||||||
|
form: {
|
||||||
|
component: 'DatePicker',
|
||||||
|
componentProps: {
|
||||||
|
type: 'datetime',
|
||||||
|
valueFormat: 'x'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
#elseif($column.htmlType == "textarea")## 文本框
|
||||||
|
form: {
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
type: 'textarea',
|
||||||
|
rows: 4
|
||||||
|
},
|
||||||
|
colProps: {
|
||||||
|
span: 24
|
||||||
|
}
|
||||||
|
},
|
||||||
|
#elseif(${javaType.toLowerCase()} == "long" || ${javaType.toLowerCase()} == "integer")## 文本框
|
||||||
|
form: {
|
||||||
|
component: 'InputNumber',
|
||||||
|
value: 0
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
{
|
||||||
|
label: '操作',
|
||||||
|
field: 'action',
|
||||||
|
isForm: false
|
||||||
|
}
|
||||||
|
])
|
||||||
|
export const { allSchemas } = useCrudSchemas(crudSchemas)
|
@ -0,0 +1,65 @@
|
|||||||
|
<template>
|
||||||
|
<Dialog :title="dialogTitle" v-model="dialogVisible">
|
||||||
|
<Form ref="formRef" :schema="allSchemas.formSchema" :rules="rules" v-loading="formLoading" />
|
||||||
|
<template #footer>
|
||||||
|
<el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
|
||||||
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||||
|
</template>
|
||||||
|
</Dialog>
|
||||||
|
</template>
|
||||||
|
<script setup lang="ts">
|
||||||
|
import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}'
|
||||||
|
import { rules, allSchemas } from './${classNameVar}.data'
|
||||||
|
const { t } = useI18n() // 国际化
|
||||||
|
const message = useMessage() // 消息弹窗
|
||||||
|
|
||||||
|
const dialogVisible = ref(false) // 弹窗的是否展示
|
||||||
|
const dialogTitle = ref('') // 弹窗的标题
|
||||||
|
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||||
|
const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
||||||
|
const formRef = ref() // 表单 Ref
|
||||||
|
|
||||||
|
/** 打开弹窗 */
|
||||||
|
const open = async (type: string, id?: number) => {
|
||||||
|
dialogVisible.value = true
|
||||||
|
dialogTitle.value = t('action.' + type)
|
||||||
|
formType.value = type
|
||||||
|
// 修改时,设置数据
|
||||||
|
if (id) {
|
||||||
|
formLoading.value = true
|
||||||
|
try {
|
||||||
|
const data = await ${simpleClassName}Api.get${simpleClassName}(id)
|
||||||
|
formRef.value.setValues(data)
|
||||||
|
} finally {
|
||||||
|
formLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
||||||
|
|
||||||
|
/** 提交表单 */
|
||||||
|
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
||||||
|
const submitForm = async () => {
|
||||||
|
// 校验表单
|
||||||
|
if (!formRef) return
|
||||||
|
const valid = await formRef.value.getElFormRef().validate()
|
||||||
|
if (!valid) return
|
||||||
|
// 提交请求
|
||||||
|
formLoading.value = true
|
||||||
|
try {
|
||||||
|
const data = formRef.value.formModel as ${simpleClassName}Api.${simpleClassName}VO
|
||||||
|
if (formType.value === 'create') {
|
||||||
|
await ${simpleClassName}Api.create${simpleClassName}(data)
|
||||||
|
message.success(t('common.createSuccess'))
|
||||||
|
} else {
|
||||||
|
await ${simpleClassName}Api.update${simpleClassName}(data)
|
||||||
|
message.success(t('common.updateSuccess'))
|
||||||
|
}
|
||||||
|
dialogVisible.value = false
|
||||||
|
// 发送操作成功的事件
|
||||||
|
emit('success')
|
||||||
|
} finally {
|
||||||
|
formLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
@ -0,0 +1,85 @@
|
|||||||
|
<template>
|
||||||
|
<!-- 搜索工作栏 -->
|
||||||
|
<ContentWrap>
|
||||||
|
<Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams">
|
||||||
|
<!-- 新增等操作按钮 -->
|
||||||
|
<template #actionMore>
|
||||||
|
<el-button
|
||||||
|
type="primary"
|
||||||
|
plain
|
||||||
|
@click="openForm('create')"
|
||||||
|
v-hasPermi="['${permissionPrefix}:create']"
|
||||||
|
>
|
||||||
|
<Icon icon="ep:plus" class="mr-5px" /> 新增
|
||||||
|
</el-button>
|
||||||
|
</template>
|
||||||
|
</Search>
|
||||||
|
</ContentWrap>
|
||||||
|
|
||||||
|
<!-- 列表 -->
|
||||||
|
<ContentWrap>
|
||||||
|
<Table
|
||||||
|
:columns="allSchemas.tableColumns"
|
||||||
|
:data="tableObject.tableList"
|
||||||
|
:loading="tableObject.loading"
|
||||||
|
:pagination="{
|
||||||
|
total: tableObject.total
|
||||||
|
}"
|
||||||
|
v-model:pageSize="tableObject.pageSize"
|
||||||
|
v-model:currentPage="tableObject.currentPage"
|
||||||
|
>
|
||||||
|
<template #action="{ row }">
|
||||||
|
<el-button
|
||||||
|
link
|
||||||
|
type="primary"
|
||||||
|
@click="openForm('update', row.id)"
|
||||||
|
v-hasPermi="['${permissionPrefix}:update']"
|
||||||
|
>
|
||||||
|
编辑
|
||||||
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
link
|
||||||
|
type="danger"
|
||||||
|
v-hasPermi="['${permissionPrefix}:delete']"
|
||||||
|
@click="handleDelete(row.id)"
|
||||||
|
>
|
||||||
|
删除
|
||||||
|
</el-button>
|
||||||
|
</template>
|
||||||
|
</Table>
|
||||||
|
</ContentWrap>
|
||||||
|
|
||||||
|
<!-- 表单弹窗:添加/修改 -->
|
||||||
|
<${simpleClassName}Form ref="formRef" @success="getList" />
|
||||||
|
</template>
|
||||||
|
<script setup lang="ts" name="${table.className}">
|
||||||
|
import { allSchemas } from './${classNameVar}.data'
|
||||||
|
import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}'
|
||||||
|
import ${simpleClassName}Form from './${simpleClassName}Form.vue'
|
||||||
|
|
||||||
|
// tableObject:表格的属性对象,可获得分页大小、条数等属性
|
||||||
|
// tableMethods:表格的操作对象,可进行获得分页、删除记录等操作
|
||||||
|
// 详细可见:https://doc.iocoder.cn/vue3/crud-schema/
|
||||||
|
const { tableObject, tableMethods } = useTable({
|
||||||
|
getListApi: ${simpleClassName}Api.get${simpleClassName}Page, // 分页接口
|
||||||
|
delListApi: ${simpleClassName}Api.delete${simpleClassName} // 删除接口
|
||||||
|
})
|
||||||
|
// 获得表格的各种操作
|
||||||
|
const { getList, setSearchParams } = tableMethods
|
||||||
|
|
||||||
|
/** 添加/修改操作 */
|
||||||
|
const formRef = ref()
|
||||||
|
const openForm = (type: string, id?: number) => {
|
||||||
|
formRef.value.open(type, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除按钮操作 */
|
||||||
|
const handleDelete = (id: number) => {
|
||||||
|
tableMethods.delList(id, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 初始化 **/
|
||||||
|
onMounted(() => {
|
||||||
|
getList()
|
||||||
|
})
|
||||||
|
</script>
|
@ -0,0 +1,32 @@
|
|||||||
|
import { defHttp } from '@/utils/http/axios'
|
||||||
|
#set ($baseURL = "/${table.moduleName}/${simpleClassName_strikeCase}")
|
||||||
|
|
||||||
|
// 查询${table.classComment}列表
|
||||||
|
export function get${simpleClassName}Page(params) {
|
||||||
|
return defHttp.get({ url: '${baseURL}/page', params })
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询${table.classComment}详情
|
||||||
|
export function get${simpleClassName}(id: number) {
|
||||||
|
return defHttp.get({ url: `${baseURL}/get?id=${id}` })
|
||||||
|
}
|
||||||
|
|
||||||
|
// 新增${table.classComment}
|
||||||
|
export function create${simpleClassName}(data) {
|
||||||
|
return defHttp.post({ url: '${baseURL}/create', data })
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改${table.classComment}
|
||||||
|
export function update${simpleClassName}(data) {
|
||||||
|
return defHttp.put({ url: '${baseURL}/update', data })
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除${table.classComment}
|
||||||
|
export function delete${simpleClassName}(id: number) {
|
||||||
|
return defHttp.delete({ url: `${baseURL}/delete?id=${id}` })
|
||||||
|
}
|
||||||
|
|
||||||
|
// 导出${table.classComment} Excel
|
||||||
|
export function export${simpleClassName}(params) {
|
||||||
|
return defHttp.download({ url: '${baseURL}/export-excel', params }, '${table.classComment}.xls')
|
||||||
|
}
|
@ -0,0 +1,236 @@
|
|||||||
|
import type {BasicColumn, FormSchema} from '@/components/Table'
|
||||||
|
import {useRender} from '@/components/Table'
|
||||||
|
import {DICT_TYPE, getDictOptions} from '@/utils/dict'
|
||||||
|
|
||||||
|
export const columns: BasicColumn[] = [
|
||||||
|
#foreach($column in $columns)
|
||||||
|
#if ($column.listOperationResult)
|
||||||
|
#set ($dictType=$column.dictType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
#set ($comment=$column.columnComment)
|
||||||
|
#if ($column.javaType == "LocalDateTime")## 时间类型
|
||||||
|
{
|
||||||
|
title: '${comment}',
|
||||||
|
dataIndex: '${javaField}',
|
||||||
|
width: 180,
|
||||||
|
customRender: ({ text }) => {
|
||||||
|
return useRender.renderDate(text)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
#elseif("" != $column.dictType)## 数据字典
|
||||||
|
{
|
||||||
|
title: '${comment}',
|
||||||
|
dataIndex: '${javaField}',
|
||||||
|
width: 180,
|
||||||
|
customRender: ({ text }) => {
|
||||||
|
return useRender.renderDict(text, DICT_TYPE.$dictType.toUpperCase())
|
||||||
|
},
|
||||||
|
},
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
title: '${comment}',
|
||||||
|
dataIndex: '${javaField}',
|
||||||
|
width: 160,
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
]
|
||||||
|
|
||||||
|
export const searchFormSchema: FormSchema[] = [
|
||||||
|
#foreach($column in $columns)
|
||||||
|
#if ($column.listOperation)
|
||||||
|
#set ($dictType=$column.dictType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
#set ($comment=$column.columnComment)
|
||||||
|
{
|
||||||
|
label: '${comment}',
|
||||||
|
field: '${javaField}',
|
||||||
|
#if ($column.htmlType == "input")
|
||||||
|
component: 'Input',
|
||||||
|
#elseif ($column.htmlType == "select")
|
||||||
|
component: 'Select',
|
||||||
|
componentProps: {
|
||||||
|
#if ("" != $dictType)## 设置了 dictType 数据字典的情况
|
||||||
|
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase()),
|
||||||
|
#else## 未设置 dictType 数据字典的情况
|
||||||
|
options: [],
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
#elseif ($column.htmlType == "radio")
|
||||||
|
component: 'Radio',
|
||||||
|
componentProps: {
|
||||||
|
#if ("" != $dictType)## 设置了 dictType 数据字典的情况
|
||||||
|
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase()),
|
||||||
|
#else## 未设置 dictType 数据字典的情况
|
||||||
|
options: [],
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
#elseif($column.htmlType == "datetime")
|
||||||
|
component: 'RangePicker',
|
||||||
|
#end
|
||||||
|
colProps: { span: 8 },
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
]
|
||||||
|
|
||||||
|
export const createFormSchema: FormSchema[] = [
|
||||||
|
{
|
||||||
|
label: '编号',
|
||||||
|
field: 'id',
|
||||||
|
show: false,
|
||||||
|
component: 'Input',
|
||||||
|
},
|
||||||
|
#foreach($column in $columns)
|
||||||
|
#if ($column.createOperation)
|
||||||
|
#set ($dictType = $column.dictType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
#set ($comment = $column.columnComment)
|
||||||
|
#if (!$column.primaryKey)## 忽略主键,不用在表单里
|
||||||
|
{
|
||||||
|
label: '${comment}',
|
||||||
|
field: '${javaField}',
|
||||||
|
#if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键
|
||||||
|
required: true,
|
||||||
|
#end
|
||||||
|
#if ($column.htmlType == "input")
|
||||||
|
component: 'Input',
|
||||||
|
#elseif($column.htmlType == "imageUpload")## 图片上传
|
||||||
|
component: 'FileUpload',
|
||||||
|
componentProps: {
|
||||||
|
fileType: 'image',
|
||||||
|
maxCount: 1,
|
||||||
|
},
|
||||||
|
#elseif($column.htmlType == "fileUpload")## 文件上传
|
||||||
|
component: 'FileUpload',
|
||||||
|
componentProps: {
|
||||||
|
fileType: 'file',
|
||||||
|
maxCount: 1,
|
||||||
|
},
|
||||||
|
#elseif($column.htmlType == "editor")## 文本编辑器
|
||||||
|
component: 'Editor',
|
||||||
|
#elseif($column.htmlType == "select")## 下拉框
|
||||||
|
component: 'Select',
|
||||||
|
componentProps: {
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number'),
|
||||||
|
#else##没数据字典
|
||||||
|
options:[],
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
#elseif($column.htmlType == "checkbox")## 多选框
|
||||||
|
component: 'Checkbox',
|
||||||
|
componentProps: {
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number'),
|
||||||
|
#else##没数据字典
|
||||||
|
options:[],
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
#elseif($column.htmlType == "radio")## 单选框
|
||||||
|
component: 'RadioButtonGroup',
|
||||||
|
componentProps: {
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number'),
|
||||||
|
#else##没数据字典
|
||||||
|
options:[],
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
#elseif($column.htmlType == "datetime")## 时间框
|
||||||
|
component: 'DatePicker',
|
||||||
|
componentProps: {
|
||||||
|
showTime: true,
|
||||||
|
format: 'YYYY-MM-DD HH:mm:ss',
|
||||||
|
valueFormat: 'x',
|
||||||
|
},
|
||||||
|
#elseif($column.htmlType == "textarea")## 文本域
|
||||||
|
component: 'InputTextArea',
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
]
|
||||||
|
|
||||||
|
export const updateFormSchema: FormSchema[] = [
|
||||||
|
{
|
||||||
|
label: '编号',
|
||||||
|
field: 'id',
|
||||||
|
show: false,
|
||||||
|
component: 'Input',
|
||||||
|
},
|
||||||
|
#foreach($column in $columns)
|
||||||
|
#if ($column.updateOperation)
|
||||||
|
#set ($dictType = $column.dictType)
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
#set ($comment = $column.columnComment)
|
||||||
|
#if (!$column.primaryKey)## 忽略主键,不用在表单里
|
||||||
|
{
|
||||||
|
label: '${comment}',
|
||||||
|
field: '${javaField}',
|
||||||
|
#if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键
|
||||||
|
required: true,
|
||||||
|
#end
|
||||||
|
#if ($column.htmlType == "input")
|
||||||
|
component: 'Input',
|
||||||
|
#elseif($column.htmlType == "imageUpload")## 图片上传
|
||||||
|
component: 'FileUpload',
|
||||||
|
componentProps: {
|
||||||
|
fileType: 'image',
|
||||||
|
maxCount: 1,
|
||||||
|
},
|
||||||
|
#elseif($column.htmlType == "fileUpload")## 文件上传
|
||||||
|
component: 'FileUpload',
|
||||||
|
componentProps: {
|
||||||
|
fileType: 'file',
|
||||||
|
maxCount: 1,
|
||||||
|
},
|
||||||
|
#elseif($column.htmlType == "editor")## 文本编辑器
|
||||||
|
component: 'Editor',
|
||||||
|
#elseif($column.htmlType == "select")## 下拉框
|
||||||
|
component: 'Select',
|
||||||
|
componentProps: {
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number'),
|
||||||
|
#else##没数据字典
|
||||||
|
options:[],
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
#elseif($column.htmlType == "checkbox")## 多选框
|
||||||
|
component: 'Checkbox',
|
||||||
|
componentProps: {
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number'),
|
||||||
|
#else##没数据字典
|
||||||
|
options:[],
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
#elseif($column.htmlType == "radio")## 单选框
|
||||||
|
component: 'RadioButtonGroup',
|
||||||
|
componentProps: {
|
||||||
|
#if ("" != $dictType)## 有数据字典
|
||||||
|
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number'),
|
||||||
|
#else##没数据字典
|
||||||
|
options:[],
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
#elseif($column.htmlType == "datetime")## 时间框
|
||||||
|
component: 'DatePicker',
|
||||||
|
componentProps: {
|
||||||
|
showTime: true,
|
||||||
|
format: 'YYYY-MM-DD HH:mm:ss',
|
||||||
|
valueFormat: 'x',
|
||||||
|
},
|
||||||
|
#elseif($column.htmlType == "textarea")## 文本域
|
||||||
|
component: 'InputTextArea',
|
||||||
|
#end
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
]
|
@ -0,0 +1,58 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
import { ref, unref } from 'vue'
|
||||||
|
import { createFormSchema, updateFormSchema } from './${classNameVar}.data'
|
||||||
|
import { useI18n } from '@/hooks/web/useI18n'
|
||||||
|
import { useMessage } from '@/hooks/web/useMessage'
|
||||||
|
import { BasicForm, useForm } from '@/components/Form'
|
||||||
|
import { BasicModal, useModalInner } from '@/components/Modal'
|
||||||
|
import { create${simpleClassName}, get${simpleClassName}, update${simpleClassName} } from '@/api/${table.moduleName}/${table.businessName}'
|
||||||
|
|
||||||
|
defineOptions({ name: '${table.className}Modal' })
|
||||||
|
|
||||||
|
const emit = defineEmits(['success', 'register'])
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
const { createMessage } = useMessage()
|
||||||
|
const isUpdate = ref(true)
|
||||||
|
|
||||||
|
const [registerForm, { setFieldsValue, resetFields, resetSchema, validate }] = useForm({
|
||||||
|
labelWidth: 120,
|
||||||
|
baseColProps: { span: 24 },
|
||||||
|
schemas: createFormSchema,
|
||||||
|
showActionButtonGroup: false,
|
||||||
|
actionColOptions: { span: 23 },
|
||||||
|
})
|
||||||
|
|
||||||
|
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
|
||||||
|
resetFields()
|
||||||
|
setModalProps({ confirmLoading: false })
|
||||||
|
isUpdate.value = !!data?.isUpdate
|
||||||
|
if (unref(isUpdate)) {
|
||||||
|
resetSchema(updateFormSchema)
|
||||||
|
const res = await get${simpleClassName}(data.record.id)
|
||||||
|
setFieldsValue({ ...res })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
async function handleSubmit() {
|
||||||
|
try {
|
||||||
|
const values = await validate()
|
||||||
|
setModalProps({ confirmLoading: true })
|
||||||
|
if (unref(isUpdate))
|
||||||
|
await update${simpleClassName}(values)
|
||||||
|
else
|
||||||
|
await create${simpleClassName}(values)
|
||||||
|
|
||||||
|
closeModal()
|
||||||
|
emit('success')
|
||||||
|
createMessage.success(t('common.saveSuccessText'))
|
||||||
|
} finally {
|
||||||
|
setModalProps({ confirmLoading: false })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<BasicModal v-bind="$attrs" :title="isUpdate ? t('action.edit') : t('action.create')" @register="registerModal" @ok="handleSubmit">
|
||||||
|
<BasicForm @register="registerForm" />
|
||||||
|
</BasicModal>
|
||||||
|
</template>
|
@ -0,0 +1,91 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
import ${simpleClassName}Modal from './${simpleClassName}Modal.vue'
|
||||||
|
import { columns, searchFormSchema } from './${classNameVar}.data'
|
||||||
|
import { useI18n } from '@/hooks/web/useI18n'
|
||||||
|
import { useMessage } from '@/hooks/web/useMessage'
|
||||||
|
import { useModal } from '@/components/Modal'
|
||||||
|
import { useTable } from '@/components/Table'
|
||||||
|
import { delete${simpleClassName}, export${simpleClassName}, get${simpleClassName}Page } from '@/api/${table.moduleName}/${table.businessName}'
|
||||||
|
|
||||||
|
defineOptions({ name: '${table.className}' })
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
const { createConfirm, createMessage } = useMessage()
|
||||||
|
const [registerModal, { openModal }] = useModal()
|
||||||
|
|
||||||
|
const [registerTable, { getForm, reload }] = useTable({
|
||||||
|
title: '${table.classComment}列表',
|
||||||
|
api: get${simpleClassName}Page,
|
||||||
|
columns,
|
||||||
|
formConfig: { labelWidth: 120, schemas: searchFormSchema },
|
||||||
|
useSearchForm: true,
|
||||||
|
showTableSetting: true,
|
||||||
|
actionColumn: {
|
||||||
|
width: 140,
|
||||||
|
title: t('common.action'),
|
||||||
|
dataIndex: 'action',
|
||||||
|
fixed: 'right',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
function handleCreate() {
|
||||||
|
openModal(true, { isUpdate: false })
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleEdit(record: Recordable) {
|
||||||
|
openModal(true, { record, isUpdate: true })
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleExport() {
|
||||||
|
createConfirm({
|
||||||
|
title: t('common.exportTitle'),
|
||||||
|
iconType: 'warning',
|
||||||
|
content: t('common.exportMessage'),
|
||||||
|
async onOk() {
|
||||||
|
await export${simpleClassName}(getForm().getFieldsValue())
|
||||||
|
createMessage.success(t('common.exportSuccessText'))
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleDelete(record: Recordable) {
|
||||||
|
await delete${simpleClassName}(record.id)
|
||||||
|
createMessage.success(t('common.delSuccessText'))
|
||||||
|
reload()
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<BasicTable @register="registerTable">
|
||||||
|
<template #toolbar>
|
||||||
|
<a-button type="primary" v-auth="['${permissionPrefix}:create']" :preIcon="IconEnum.ADD" @click="handleCreate">
|
||||||
|
{{ t('action.create') }}
|
||||||
|
</a-button>
|
||||||
|
<a-button v-auth="['${permissionPrefix}:export']" :preIcon="IconEnum.EXPORT" @click="handleExport">
|
||||||
|
{{ t('action.export') }}
|
||||||
|
</a-button>
|
||||||
|
</template>
|
||||||
|
<template #bodyCell="{ column, record }">
|
||||||
|
<template v-if="column.key === 'action'">
|
||||||
|
<TableAction
|
||||||
|
:actions="[
|
||||||
|
{ icon: IconEnum.EDIT, label: t('action.edit'), auth: '${permissionPrefix}:update', onClick: handleEdit.bind(null, record) },
|
||||||
|
{
|
||||||
|
icon: IconEnum.DELETE,
|
||||||
|
danger: true,
|
||||||
|
label: t('action.delete'),
|
||||||
|
auth: '${permissionPrefix}:delete',
|
||||||
|
popConfirm: {
|
||||||
|
title: t('common.delMessage'),
|
||||||
|
placement: 'left',
|
||||||
|
confirm: handleDelete.bind(null, record),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</template>
|
||||||
|
</BasicTable>
|
||||||
|
<${simpleClassName}Modal @register="registerModal" @success="reload()" />
|
||||||
|
</div>
|
||||||
|
</template>
|
Loading…
Reference in New Issue
Block a user