mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 07:11:52 +08:00
代码生成:1)增加 one 情况下的示例代码;2)修复 vue3 模版现有的 bug
This commit is contained in:
parent
07e71e2ab0
commit
e67a6a2fe9
@ -43,9 +43,6 @@ public interface ErrorCodeConstants {
|
||||
ErrorCode CODEGEN_TABLE_INFO_TABLE_COMMENT_IS_NULL = new ErrorCode(1_003_001_008, "数据库的表注释未填写");
|
||||
ErrorCode CODEGEN_TABLE_INFO_COLUMN_COMMENT_IS_NULL = new ErrorCode(1_003_001_009, "数据库的表字段({})注释未填写");
|
||||
|
||||
// ========== 字典类型(测试)1-001-005-000 ==========
|
||||
ErrorCode TEST_DEMO_NOT_EXISTS = new ErrorCode(1_001_005_000, "测试示例不存在");
|
||||
|
||||
// ========== 文件配置 1-001-006-000 ==========
|
||||
ErrorCode FILE_CONFIG_NOT_EXISTS = new ErrorCode(1_001_006_000, "文件配置不存在");
|
||||
ErrorCode FILE_CONFIG_DELETE_FAIL_MASTER = new ErrorCode(1_001_006_001, "该文件配置不允许删除,原因:它是主配置,删除会导致无法上传文件");
|
||||
@ -57,4 +54,6 @@ public interface ErrorCodeConstants {
|
||||
// ========== 数据源配置 1-001-107-000 ==========
|
||||
ErrorCode DEMO_STUDENT_NOT_EXISTS = new ErrorCode(1_001_107_000, "学生不存在");
|
||||
|
||||
// ========== 学生(CodegenTemplateTypeEnum.ONE 示例) 1-001-200-000 ==========
|
||||
ErrorCode DEMO01_STUDENT_NOT_EXISTS = new ErrorCode(1_001_200_000, "学生不存在");
|
||||
}
|
||||
|
@ -0,0 +1,89 @@
|
||||
package cn.iocoder.yudao.module.infra.controller.admin.demo01;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo01.vo.*;
|
||||
import cn.iocoder.yudao.module.infra.convert.demo01.InfraDemo01StudentConvert;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo01.InfraDemo01StudentDO;
|
||||
import cn.iocoder.yudao.module.infra.service.demo01.InfraDemo01StudentService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
|
||||
@Tag(name = "管理后台 - 学生")
|
||||
@RestController
|
||||
@RequestMapping("/infra/demo01-student")
|
||||
@Validated
|
||||
public class InfraDemo01StudentController {
|
||||
|
||||
@Resource
|
||||
private InfraDemo01StudentService demo01StudentService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建学生")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo01-student:create')")
|
||||
public CommonResult<Long> createDemo01Student(@Valid @RequestBody InfraDemo01StudentCreateReqVO createReqVO) {
|
||||
return success(demo01StudentService.createDemo01Student(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新学生")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo01-student:update')")
|
||||
public CommonResult<Boolean> updateDemo01Student(@Valid @RequestBody InfraDemo01StudentUpdateReqVO updateReqVO) {
|
||||
demo01StudentService.updateDemo01Student(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除学生")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo01-student:delete')")
|
||||
public CommonResult<Boolean> deleteDemo01Student(@RequestParam("id") Long id) {
|
||||
demo01StudentService.deleteDemo01Student(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得学生")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo01-student:query')")
|
||||
public CommonResult<InfraDemo01StudentRespVO> getDemo01Student(@RequestParam("id") Long id) {
|
||||
InfraDemo01StudentDO demo01Student = demo01StudentService.getDemo01Student(id);
|
||||
return success(InfraDemo01StudentConvert.INSTANCE.convert(demo01Student));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得学生分页")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo01-student:query')")
|
||||
public CommonResult<PageResult<InfraDemo01StudentRespVO>> getDemo01StudentPage(@Valid InfraDemo01StudentPageReqVO pageVO) {
|
||||
PageResult<InfraDemo01StudentDO> pageResult = demo01StudentService.getDemo01StudentPage(pageVO);
|
||||
return success(InfraDemo01StudentConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出学生 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('infra:demo01-student:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportDemo01StudentExcel(@Valid InfraDemo01StudentExportReqVO exportReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
List<InfraDemo01StudentDO> list = demo01StudentService.getDemo01StudentList(exportReqVO);
|
||||
// 导出 Excel
|
||||
List<InfraDemo01StudentExcelVO> datas = InfraDemo01StudentConvert.INSTANCE.convertList02(list);
|
||||
ExcelUtils.write(response, "学生.xls", "数据", InfraDemo01StudentExcelVO.class, datas);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package cn.iocoder.yudao.module.infra.controller.admin.demo01.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
/**
|
||||
* 学生 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
|
||||
*/
|
||||
@Data
|
||||
public class InfraDemo01StudentBaseVO {
|
||||
|
||||
@Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋头")
|
||||
@NotEmpty(message = "名字不能为空")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是介绍")
|
||||
@NotEmpty(message = "简介不能为空")
|
||||
private String description;
|
||||
|
||||
@Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "出生日期不能为空")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime birthday;
|
||||
|
||||
@Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "性别不能为空")
|
||||
private Integer sex;
|
||||
|
||||
@Schema(description = "是否有效", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
|
||||
@NotNull(message = "是否有效不能为空")
|
||||
private Boolean enabled;
|
||||
|
||||
@Schema(description = "头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png")
|
||||
@NotEmpty(message = "头像不能为空")
|
||||
private String avatar;
|
||||
|
||||
@Schema(description = "附件", example = "https://www.iocoder.cn/1.mp4")
|
||||
private String video;
|
||||
|
||||
@Schema(description = "备注", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是备注")
|
||||
@NotEmpty(message = "备注不能为空")
|
||||
private String memo;
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package cn.iocoder.yudao.module.infra.controller.admin.demo01.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
@Schema(description = "管理后台 - 学生创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class InfraDemo01StudentCreateReqVO extends InfraDemo01StudentBaseVO {
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package cn.iocoder.yudao.module.infra.controller.admin.demo01.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
|
||||
/**
|
||||
* 学生 Excel VO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Data
|
||||
public class InfraDemo01StudentExcelVO {
|
||||
|
||||
@ExcelProperty("编号")
|
||||
private Long id;
|
||||
|
||||
@ExcelProperty("名字")
|
||||
private String name;
|
||||
|
||||
@ExcelProperty("简介")
|
||||
private String description;
|
||||
|
||||
@ExcelProperty("出生日期")
|
||||
private LocalDateTime birthday;
|
||||
|
||||
@ExcelProperty(value = "性别", converter = DictConvert.class)
|
||||
@DictFormat("system_user_sex") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中
|
||||
private Integer sex;
|
||||
|
||||
@ExcelProperty(value = "是否有效", converter = DictConvert.class)
|
||||
@DictFormat("infra_boolean_string") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中
|
||||
private Boolean enabled;
|
||||
|
||||
@ExcelProperty(value = "支付方式", converter = DictConvert.class)
|
||||
@DictFormat("pay_channel_code") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中
|
||||
private String payChannels;
|
||||
|
||||
@ExcelProperty("头像")
|
||||
private String avatar;
|
||||
|
||||
@ExcelProperty("附件")
|
||||
private String video;
|
||||
|
||||
@ExcelProperty("备注")
|
||||
private String memo;
|
||||
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package cn.iocoder.yudao.module.infra.controller.admin.demo01.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 学生 Excel 导出 Request VO,参数和 InfraDemo01StudentPageReqVO 是一致的")
|
||||
@Data
|
||||
public class InfraDemo01StudentExportReqVO {
|
||||
|
||||
@Schema(description = "名字", example = "芋头")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "出生日期")
|
||||
private LocalDateTime birthday;
|
||||
|
||||
@Schema(description = "性别", example = "1")
|
||||
private Integer sex;
|
||||
|
||||
@Schema(description = "是否有效", example = "true")
|
||||
private Boolean enabled;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package cn.iocoder.yudao.module.infra.controller.admin.demo01.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 学生分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class InfraDemo01StudentPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "名字", example = "芋头")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "出生日期")
|
||||
private LocalDateTime birthday;
|
||||
|
||||
@Schema(description = "性别", example = "1")
|
||||
private Integer sex;
|
||||
|
||||
@Schema(description = "是否有效", example = "true")
|
||||
private Boolean enabled;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package cn.iocoder.yudao.module.infra.controller.admin.demo01.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - 学生 Response VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class InfraDemo01StudentRespVO extends InfraDemo01StudentBaseVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package cn.iocoder.yudao.module.infra.controller.admin.demo01.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Schema(description = "管理后台 - 学生更新 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class InfraDemo01StudentUpdateReqVO extends InfraDemo01StudentBaseVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
@NotNull(message = "编号不能为空")
|
||||
private Long id;
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package cn.iocoder.yudao.module.infra.convert.demo01;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo01.vo.*;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo01.InfraDemo01StudentDO;
|
||||
|
||||
/**
|
||||
* 学生 Convert
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface InfraDemo01StudentConvert {
|
||||
|
||||
InfraDemo01StudentConvert INSTANCE = Mappers.getMapper(InfraDemo01StudentConvert.class);
|
||||
|
||||
InfraDemo01StudentDO convert(InfraDemo01StudentCreateReqVO bean);
|
||||
|
||||
InfraDemo01StudentDO convert(InfraDemo01StudentUpdateReqVO bean);
|
||||
|
||||
InfraDemo01StudentRespVO convert(InfraDemo01StudentDO bean);
|
||||
|
||||
List<InfraDemo01StudentRespVO> convertList(List<InfraDemo01StudentDO> list);
|
||||
|
||||
PageResult<InfraDemo01StudentRespVO> convertPage(PageResult<InfraDemo01StudentDO> page);
|
||||
|
||||
List<InfraDemo01StudentExcelVO> convertList02(List<InfraDemo01StudentDO> list);
|
||||
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package cn.iocoder.yudao.module.infra.dal.dataobject.demo01;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 学生 DO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@TableName("infra_demo01_student")
|
||||
@KeySequence("infra_demo01_student_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class InfraDemo01StudentDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 名字
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 简介
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 出生日期
|
||||
*/
|
||||
private LocalDateTime birthday;
|
||||
/**
|
||||
* 性别
|
||||
*
|
||||
* 枚举 {@link TODO system_user_sex 对应的类}
|
||||
*/
|
||||
private Integer sex;
|
||||
/**
|
||||
* 是否有效
|
||||
*
|
||||
* 枚举 {@link TODO infra_boolean_string 对应的类}
|
||||
*/
|
||||
private Boolean enabled;
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
private String avatar;
|
||||
/**
|
||||
* 附件
|
||||
*/
|
||||
private String video;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String memo;
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package cn.iocoder.yudao.module.infra.dal.mysql.demo01;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo01.InfraDemo01StudentDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo01.vo.*;
|
||||
|
||||
/**
|
||||
* 学生 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface InfraDemo01StudentMapper extends BaseMapperX<InfraDemo01StudentDO> {
|
||||
|
||||
default PageResult<InfraDemo01StudentDO> selectPage(InfraDemo01StudentPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<InfraDemo01StudentDO>()
|
||||
.likeIfPresent(InfraDemo01StudentDO::getName, reqVO.getName())
|
||||
.eqIfPresent(InfraDemo01StudentDO::getBirthday, reqVO.getBirthday())
|
||||
.eqIfPresent(InfraDemo01StudentDO::getSex, reqVO.getSex())
|
||||
.eqIfPresent(InfraDemo01StudentDO::getEnabled, reqVO.getEnabled())
|
||||
.betweenIfPresent(InfraDemo01StudentDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(InfraDemo01StudentDO::getId));
|
||||
}
|
||||
|
||||
default List<InfraDemo01StudentDO> selectList(InfraDemo01StudentExportReqVO reqVO) {
|
||||
return selectList(new LambdaQueryWrapperX<InfraDemo01StudentDO>()
|
||||
.likeIfPresent(InfraDemo01StudentDO::getName, reqVO.getName())
|
||||
.eqIfPresent(InfraDemo01StudentDO::getBirthday, reqVO.getBirthday())
|
||||
.eqIfPresent(InfraDemo01StudentDO::getSex, reqVO.getSex())
|
||||
.eqIfPresent(InfraDemo01StudentDO::getEnabled, reqVO.getEnabled())
|
||||
.betweenIfPresent(InfraDemo01StudentDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(InfraDemo01StudentDO::getId));
|
||||
}
|
||||
|
||||
}
|
@ -16,8 +16,8 @@ public enum CodegenColumnHtmlTypeEnum {
|
||||
RADIO("radio"), // 单选框
|
||||
CHECKBOX("checkbox"), // 复选框
|
||||
DATETIME("datetime"), // 日期控件
|
||||
UPLOAD_IMAGE("upload_image"), // 上传图片
|
||||
UPLOAD_FILE("upload_file"), // 上传文件
|
||||
IMAGE_UPLOAD("imageUpload"), // 上传图片
|
||||
FILE_UPLOAD("fileUpload"), // 上传文件
|
||||
EDITOR("editor"), // 富文本控件
|
||||
;
|
||||
|
||||
|
@ -49,8 +49,8 @@ public class CodegenBuilder {
|
||||
.put("status", CodegenColumnHtmlTypeEnum.RADIO)
|
||||
.put("sex", CodegenColumnHtmlTypeEnum.RADIO)
|
||||
.put("type", CodegenColumnHtmlTypeEnum.SELECT)
|
||||
.put("image", CodegenColumnHtmlTypeEnum.UPLOAD_IMAGE)
|
||||
.put("file", CodegenColumnHtmlTypeEnum.UPLOAD_FILE)
|
||||
.put("image", CodegenColumnHtmlTypeEnum.IMAGE_UPLOAD)
|
||||
.put("file", CodegenColumnHtmlTypeEnum.FILE_UPLOAD)
|
||||
.put("content", CodegenColumnHtmlTypeEnum.EDITOR)
|
||||
.put("description", CodegenColumnHtmlTypeEnum.EDITOR)
|
||||
.put("demo", CodegenColumnHtmlTypeEnum.EDITOR)
|
||||
|
@ -110,21 +110,21 @@ public class CodegenEngine {
|
||||
vueFilePath("api/${table.moduleName}/${classNameVar}.js"))
|
||||
// Vue3 标准模版
|
||||
.put(CodegenFrontTypeEnum.VUE3.getType(), vue3TemplatePath("views/index.vue"),
|
||||
vue3FilePath("views/${table.moduleName}/${classNameVar}/index.vue"))
|
||||
vue3FilePath("views/${table.moduleName}/${table.businessName}/index.vue"))
|
||||
.put(CodegenFrontTypeEnum.VUE3.getType(), vue3TemplatePath("views/form.vue"),
|
||||
vue3FilePath("views/${table.moduleName}/${classNameVar}/${simpleClassName}Form.vue"))
|
||||
vue3FilePath("views/${table.moduleName}/${table.businessName}/${simpleClassName}Form.vue"))
|
||||
.put(CodegenFrontTypeEnum.VUE3.getType(), vue3TemplatePath("views/components/form_sub_normal.vue"), // 特殊:主子表专属逻辑
|
||||
vue3FilePath("views/${table.moduleName}/${classNameVar}/components/${subSimpleClassName}Form.vue"))
|
||||
vue3FilePath("views/${table.moduleName}/${table.businessName}/components/${subSimpleClassName}Form.vue"))
|
||||
.put(CodegenFrontTypeEnum.VUE3.getType(), vue3TemplatePath("views/components/form_sub_inner.vue"), // 特殊:主子表专属逻辑
|
||||
vue3FilePath("views/${table.moduleName}/${classNameVar}/components/${subSimpleClassName}Form.vue"))
|
||||
vue3FilePath("views/${table.moduleName}/${table.businessName}/components/${subSimpleClassName}Form.vue"))
|
||||
.put(CodegenFrontTypeEnum.VUE3.getType(), vue3TemplatePath("views/components/form_sub_erp.vue"), // 特殊:主子表专属逻辑
|
||||
vue3FilePath("views/${table.moduleName}/${classNameVar}/components/${subSimpleClassName}Form.vue"))
|
||||
vue3FilePath("views/${table.moduleName}/${table.businessName}/components/${subSimpleClassName}Form.vue"))
|
||||
.put(CodegenFrontTypeEnum.VUE3.getType(), vue3TemplatePath("views/components/list_sub_inner.vue"), // 特殊:主子表专属逻辑
|
||||
vue3FilePath("views/${table.moduleName}/${classNameVar}/components/${subSimpleClassName}List.vue"))
|
||||
vue3FilePath("views/${table.moduleName}/${table.businessName}/components/${subSimpleClassName}List.vue"))
|
||||
.put(CodegenFrontTypeEnum.VUE3.getType(), vue3TemplatePath("views/components/list_sub_erp.vue"), // 特殊:主子表专属逻辑
|
||||
vue3FilePath("views/${table.moduleName}/${classNameVar}/components/${subSimpleClassName}List.vue"))
|
||||
vue3FilePath("views/${table.moduleName}/${table.businessName}/components/${subSimpleClassName}List.vue"))
|
||||
.put(CodegenFrontTypeEnum.VUE3.getType(), vue3TemplatePath("api/api.ts"),
|
||||
vue3FilePath("api/${table.moduleName}/${classNameVar}/index.ts"))
|
||||
vue3FilePath("api/${table.moduleName}/${table.businessName}/index.ts"))
|
||||
// Vue3 Schema 模版
|
||||
.put(CodegenFrontTypeEnum.VUE3_SCHEMA.getType(), vue3SchemaTemplatePath("views/data.ts"),
|
||||
vue3FilePath("views/${table.moduleName}/${classNameVar}/${classNameVar}.data.ts"))
|
||||
|
@ -0,0 +1,62 @@
|
||||
package cn.iocoder.yudao.module.infra.service.demo01;
|
||||
|
||||
import java.util.*;
|
||||
import javax.validation.*;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo01.vo.*;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo01.InfraDemo01StudentDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
/**
|
||||
* 学生 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface InfraDemo01StudentService {
|
||||
|
||||
/**
|
||||
* 创建学生
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createDemo01Student(@Valid InfraDemo01StudentCreateReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新学生
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateDemo01Student(@Valid InfraDemo01StudentUpdateReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除学生
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteDemo01Student(Long id);
|
||||
|
||||
/**
|
||||
* 获得学生
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 学生
|
||||
*/
|
||||
InfraDemo01StudentDO getDemo01Student(Long id);
|
||||
|
||||
/**
|
||||
* 获得学生分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 学生分页
|
||||
*/
|
||||
PageResult<InfraDemo01StudentDO> getDemo01StudentPage(InfraDemo01StudentPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 获得学生列表, 用于 Excel 导出
|
||||
*
|
||||
* @param exportReqVO 查询条件
|
||||
* @return 学生列表
|
||||
*/
|
||||
List<InfraDemo01StudentDO> getDemo01StudentList(InfraDemo01StudentExportReqVO exportReqVO);
|
||||
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package cn.iocoder.yudao.module.infra.service.demo01;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.demo01.vo.*;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo01.InfraDemo01StudentDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import cn.iocoder.yudao.module.infra.convert.demo01.InfraDemo01StudentConvert;
|
||||
import cn.iocoder.yudao.module.infra.dal.mysql.demo01.InfraDemo01StudentMapper;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
|
||||
/**
|
||||
* 学生 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class InfraDemo01StudentServiceImpl implements InfraDemo01StudentService {
|
||||
|
||||
@Resource
|
||||
private InfraDemo01StudentMapper demo01StudentMapper;
|
||||
|
||||
@Override
|
||||
public Long createDemo01Student(InfraDemo01StudentCreateReqVO createReqVO) {
|
||||
// 插入
|
||||
InfraDemo01StudentDO demo01Student = InfraDemo01StudentConvert.INSTANCE.convert(createReqVO);
|
||||
demo01StudentMapper.insert(demo01Student);
|
||||
// 返回
|
||||
return demo01Student.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDemo01Student(InfraDemo01StudentUpdateReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateDemo01StudentExists(updateReqVO.getId());
|
||||
// 更新
|
||||
InfraDemo01StudentDO updateObj = InfraDemo01StudentConvert.INSTANCE.convert(updateReqVO);
|
||||
demo01StudentMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDemo01Student(Long id) {
|
||||
// 校验存在
|
||||
validateDemo01StudentExists(id);
|
||||
// 删除
|
||||
demo01StudentMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateDemo01StudentExists(Long id) {
|
||||
if (demo01StudentMapper.selectById(id) == null) {
|
||||
throw exception(DEMO01_STUDENT_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InfraDemo01StudentDO getDemo01Student(Long id) {
|
||||
return demo01StudentMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<InfraDemo01StudentDO> getDemo01StudentPage(InfraDemo01StudentPageReqVO pageReqVO) {
|
||||
return demo01StudentMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<InfraDemo01StudentDO> getDemo01StudentList(InfraDemo01StudentExportReqVO exportReqVO) {
|
||||
return demo01StudentMapper.selectList(exportReqVO);
|
||||
}
|
||||
|
||||
}
|
@ -5,7 +5,7 @@ INSERT INTO system_menu(
|
||||
)
|
||||
VALUES (
|
||||
'${table.classComment}管理', '', 2, 0, ${table.parentMenuId},
|
||||
'${simpleClassName_strikeCase}', '', '${table.moduleName}/${classNameVar}/index', 0, '${table.className}'
|
||||
'${simpleClassName_strikeCase}', '', '${table.moduleName}/${table.businessName}/index', 0, '${table.className}'
|
||||
);
|
||||
|
||||
-- 按钮父菜单ID
|
||||
|
@ -179,15 +179,15 @@
|
||||
<el-input v-model="formData.${javaField}" placeholder="请输入${comment}" />
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "imageUpload")## 图片上传
|
||||
<el-form-item label="${comment}">
|
||||
<el-form-item label="${comment}" prop="${javaField}">
|
||||
<UploadImg v-model="formData.${javaField}" />
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "fileUpload")## 文件上传
|
||||
<el-form-item label="${comment}">
|
||||
<el-form-item label="${comment}" prop="${javaField}">
|
||||
<UploadFile v-model="formData.${javaField}" />
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "editor")## 文本编辑器
|
||||
<el-form-item label="${comment}">
|
||||
<el-form-item label="${comment}" prop="${javaField}">
|
||||
<Editor v-model="formData.${javaField}" height="150px" />
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "select")## 下拉框
|
||||
@ -257,7 +257,7 @@
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict'
|
||||
import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${classNameVar}'
|
||||
import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}'
|
||||
|
||||
const props = defineProps<{
|
||||
${subJoinColumn.javaField}: undefined // ${subJoinColumn.columnComment}(主表的关联字段)
|
||||
|
@ -31,11 +31,11 @@
|
||||
<UploadImg v-model="formData.${javaField}" />
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "fileUpload")## 文件上传
|
||||
<el-form-item label="${comment}">
|
||||
<el-form-item label="${comment}" prop="${javaField}">
|
||||
<UploadFile v-model="formData.${javaField}" />
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "editor")## 文本编辑器
|
||||
<el-form-item label="${comment}">
|
||||
<el-form-item label="${comment}" prop="${javaField}">
|
||||
<Editor v-model="formData.${javaField}" height="150px" />
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "select")## 下拉框
|
||||
@ -125,7 +125,7 @@
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict'
|
||||
import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${classNameVar}'
|
||||
import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}'
|
||||
## 特殊:主子表专属逻辑
|
||||
#foreach ($subSimpleClassName in $subSimpleClassNames)
|
||||
import ${subSimpleClassName}Form from './components/${subSimpleClassName}Form.vue'
|
||||
|
@ -122,7 +122,7 @@
|
||||
:formatter="dateFormatter"
|
||||
width="180px"
|
||||
/>
|
||||
#elseif("" != $column.dictType)## 数据字典
|
||||
#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}" />
|
||||
@ -171,7 +171,7 @@
|
||||
import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict'
|
||||
import { dateFormatter } from '@/utils/formatTime'
|
||||
import download from '@/utils/download'
|
||||
import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${classNameVar}'
|
||||
import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}'
|
||||
import ${simpleClassName}Form from './${simpleClassName}Form.vue'
|
||||
|
||||
defineOptions({ name: '${table.className}' })
|
||||
|
@ -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="cn.iocoder.yudao.module.infra.dal.mysql.demo01.InfraDemo01StudentMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
@ -1,6 +1,9 @@
|
||||
package cn.iocoder.yudao.module.infra.service.codegen.inner;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.hutool.core.util.ZipUtil;
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenColumnDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenTableDO;
|
||||
@ -12,8 +15,9 @@ import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Spy;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -41,84 +45,97 @@ public class CodegenEngineTest extends BaseMockitoUnitTest {
|
||||
@Test
|
||||
public void testExecute_vue3_crud() {
|
||||
// 准备请求参数
|
||||
CodegenTableDO table = new CodegenTableDO().setScene(CodegenSceneEnum.ADMIN.getScene())
|
||||
.setTableName("system_user").setTableComment("用户表")
|
||||
.setModuleName("system").setBusinessName("user").setClassName("SystemUser")
|
||||
.setClassComment("用户").setAuthor("芋道源码")
|
||||
CodegenTableDO table = new CodegenTableDO().setScene(CodegenSceneEnum.ADMIN.getScene()).setParentMenuId(888L)
|
||||
.setTableName("infra_demo01_student").setTableComment("学生表")
|
||||
.setModuleName("infra").setBusinessName("demo01").setClassName("InfraDemo01Student")
|
||||
.setClassComment("学生").setAuthor("芋道源码")
|
||||
.setTemplateType(CodegenTemplateTypeEnum.ONE.getType())
|
||||
.setFrontType(CodegenFrontTypeEnum.VUE3.getType())
|
||||
.setParentMenuId(10L);
|
||||
.setFrontType(CodegenFrontTypeEnum.VUE3.getType());
|
||||
CodegenColumnDO idColumn = new CodegenColumnDO().setColumnName("id").setDataType(JdbcType.BIGINT.name())
|
||||
.setColumnComment("编号").setNullable(false).setPrimaryKey(true).setAutoIncrement(true)
|
||||
.setOrdinalPosition(1).setJavaType("Long").setJavaField("id").setExample("1024")
|
||||
.setCreateOperation(false).setUpdateOperation(true).setListOperation(false)
|
||||
.setJavaType("Long").setJavaField("id").setExample("1024")
|
||||
.setCreateOperation(false).setUpdateOperation(true)
|
||||
.setListOperation(false)
|
||||
.setListOperationResult(true);
|
||||
CodegenColumnDO nameColumn = new CodegenColumnDO().setColumnName("name").setDataType(JdbcType.VARCHAR.name())
|
||||
.setColumnComment("名字").setNullable(false).setPrimaryKey(false)
|
||||
.setOrdinalPosition(2).setJavaType("String").setJavaField("name").setExample("芋头")
|
||||
.setCreateOperation(true).setUpdateOperation(true).setListOperation(true)
|
||||
.setListOperationCondition(CodegenColumnListConditionEnum.LIKE.getCondition()).setListOperationResult(true)
|
||||
.setColumnComment("名字").setNullable(false)
|
||||
.setJavaType("String").setJavaField("name").setExample("芋头")
|
||||
.setCreateOperation(true).setUpdateOperation(true)
|
||||
.setListOperation(true).setListOperationCondition(CodegenColumnListConditionEnum.LIKE.getCondition())
|
||||
.setListOperationResult(true)
|
||||
.setHtmlType(CodegenColumnHtmlTypeEnum.INPUT.getType());
|
||||
CodegenColumnDO avatarColumn = new CodegenColumnDO().setColumnName("avatar").setDataType(JdbcType.VARCHAR.name())
|
||||
.setColumnComment("头像").setNullable(true).setPrimaryKey(false)
|
||||
.setOrdinalPosition(3).setJavaType("String").setJavaField("avatar").setExample("https://www.iocoder.cn/1.png")
|
||||
.setCreateOperation(true).setUpdateOperation(true).setListOperation(false)
|
||||
.setListOperationResult(true)
|
||||
.setHtmlType(CodegenColumnHtmlTypeEnum.UPLOAD_IMAGE.getType());
|
||||
CodegenColumnDO videoColumn = new CodegenColumnDO().setColumnName("video").setDataType(JdbcType.VARCHAR.name())
|
||||
.setColumnComment("视频").setNullable(true).setPrimaryKey(false)
|
||||
.setOrdinalPosition(4).setJavaType("String").setJavaField("video").setExample("https://www.iocoder.cn/1.mp4")
|
||||
.setCreateOperation(true).setUpdateOperation(true).setListOperation(false)
|
||||
.setListOperationResult(true)
|
||||
.setHtmlType(CodegenColumnHtmlTypeEnum.UPLOAD_FILE.getType());
|
||||
CodegenColumnDO descriptionColumn = new CodegenColumnDO().setColumnName("description").setDataType(JdbcType.VARCHAR.name())
|
||||
.setColumnComment("个人简介").setNullable(true).setPrimaryKey(false)
|
||||
.setOrdinalPosition(5).setJavaType("String").setJavaField("description").setExample("我是介绍")
|
||||
.setCreateOperation(true).setUpdateOperation(true).setListOperation(false)
|
||||
.setListOperationResult(true)
|
||||
.setHtmlType(CodegenColumnHtmlTypeEnum.EDITOR.getType());
|
||||
CodegenColumnDO sex1Column = new CodegenColumnDO().setColumnName("sex1").setDataType(JdbcType.VARCHAR.name())
|
||||
.setColumnComment("性别 1").setNullable(true).setPrimaryKey(false)
|
||||
.setOrdinalPosition(6).setJavaType("String").setJavaField("sex1").setExample("男")
|
||||
.setCreateOperation(true).setUpdateOperation(true).setListOperation(true)
|
||||
.setListOperationCondition(CodegenColumnListConditionEnum.EQ.getCondition()).setListOperationResult(true)
|
||||
.setHtmlType(CodegenColumnHtmlTypeEnum.SELECT.getType()).setDictType("system_sex1");
|
||||
CodegenColumnDO sex2Column = new CodegenColumnDO().setColumnName("sex2").setDataType(JdbcType.INTEGER.name())
|
||||
.setColumnComment("性别 2").setNullable(true).setPrimaryKey(false)
|
||||
.setOrdinalPosition(7).setJavaType("Integer").setJavaField("sex2").setExample("1")
|
||||
.setCreateOperation(true).setUpdateOperation(true).setListOperation(true)
|
||||
.setListOperationCondition(CodegenColumnListConditionEnum.EQ.getCondition()).setListOperationResult(true)
|
||||
.setHtmlType(CodegenColumnHtmlTypeEnum.CHECKBOX.getType()).setDictType("system_sex2");
|
||||
CodegenColumnDO sex3Column = new CodegenColumnDO().setColumnName("sex3").setDataType(JdbcType.BOOLEAN.name())
|
||||
.setColumnComment("性别 3").setNullable(true).setPrimaryKey(false)
|
||||
.setOrdinalPosition(8).setJavaType("Boolean").setJavaField("sex3").setExample("true")
|
||||
.setCreateOperation(true).setUpdateOperation(true).setListOperation(true)
|
||||
.setListOperationResult(true)
|
||||
.setHtmlType(CodegenColumnHtmlTypeEnum.RADIO.getType()).setDictType("system_sex3");
|
||||
CodegenColumnDO birthdayColumn = new CodegenColumnDO().setColumnName("birthday").setDataType(JdbcType.DATE.name())
|
||||
.setColumnComment("出生日期").setNullable(true).setPrimaryKey(false)
|
||||
.setOrdinalPosition(9).setJavaType("LocalDateTime").setJavaField("birthday")
|
||||
.setCreateOperation(true).setUpdateOperation(true).setListOperation(true)
|
||||
.setListOperationCondition(CodegenColumnListConditionEnum.EQ.getCondition()).setListOperationResult(true)
|
||||
.setHtmlType(CodegenColumnHtmlTypeEnum.DATETIME.getType());
|
||||
CodegenColumnDO memoColumn = new CodegenColumnDO().setColumnName("memo").setDataType(JdbcType.VARCHAR.name())
|
||||
.setColumnComment("备注").setNullable(true).setPrimaryKey(false)
|
||||
.setOrdinalPosition(10).setJavaType("String").setJavaField("memo").setExample("我是备注")
|
||||
.setCreateOperation(true).setUpdateOperation(true).setListOperation(false)
|
||||
.setColumnComment("简介").setNullable(false)
|
||||
.setJavaType("String").setJavaField("description").setExample("我是介绍")
|
||||
.setCreateOperation(true).setUpdateOperation(true)
|
||||
.setListOperation(false)
|
||||
.setListOperationResult(true)
|
||||
.setHtmlType(CodegenColumnHtmlTypeEnum.TEXTAREA.getType());
|
||||
CodegenColumnDO createTimeColumn = new CodegenColumnDO().setColumnName("create_time").setDataType(JdbcType.DATE.name())
|
||||
.setColumnComment("创建时间").setNullable(true).setPrimaryKey(false)
|
||||
.setOrdinalPosition(11).setJavaType("LocalDateTime").setJavaField("createTime")
|
||||
.setCreateOperation(true).setUpdateOperation(true).setListOperation(true)
|
||||
.setListOperationCondition(CodegenColumnListConditionEnum.BETWEEN.getCondition()).setListOperationResult(true)
|
||||
CodegenColumnDO birthdayColumn = new CodegenColumnDO().setColumnName("birthday").setDataType(JdbcType.DATE.name())
|
||||
.setColumnComment("出生日期").setNullable(false)
|
||||
.setJavaType("LocalDateTime").setJavaField("birthday")
|
||||
.setCreateOperation(true).setUpdateOperation(true)
|
||||
.setListOperation(true).setListOperationCondition(CodegenColumnListConditionEnum.EQ.getCondition())
|
||||
.setListOperationResult(true)
|
||||
.setHtmlType(CodegenColumnHtmlTypeEnum.DATETIME.getType());
|
||||
List<CodegenColumnDO> columns = Arrays.asList(idColumn, nameColumn, avatarColumn, videoColumn, descriptionColumn,
|
||||
sex1Column, sex2Column, sex3Column, birthdayColumn, memoColumn, createTimeColumn);
|
||||
CodegenColumnDO sexColumn = new CodegenColumnDO().setColumnName("sex").setDataType(JdbcType.INTEGER.name())
|
||||
.setColumnComment("性别").setNullable(false)
|
||||
.setJavaType("Integer").setJavaField("sex").setExample("1")
|
||||
.setCreateOperation(true).setUpdateOperation(true)
|
||||
.setListOperation(true).setListOperationCondition(CodegenColumnListConditionEnum.EQ.getCondition())
|
||||
.setListOperationResult(true)
|
||||
.setHtmlType(CodegenColumnHtmlTypeEnum.SELECT.getType())
|
||||
.setDictType("system_user_sex");
|
||||
CodegenColumnDO enabledColumn = new CodegenColumnDO().setColumnName("enabled").setDataType(JdbcType.BOOLEAN.name())
|
||||
.setColumnComment("是否有效").setNullable(false)
|
||||
.setJavaType("Boolean").setJavaField("enabled").setExample("true")
|
||||
.setCreateOperation(true).setUpdateOperation(true)
|
||||
.setListOperation(true).setListOperationCondition(CodegenColumnListConditionEnum.EQ.getCondition())
|
||||
.setListOperationResult(true)
|
||||
.setHtmlType(CodegenColumnHtmlTypeEnum.RADIO.getType())
|
||||
.setDictType("infra_boolean_string");
|
||||
CodegenColumnDO avatarColumn = new CodegenColumnDO().setColumnName("avatar").setDataType(JdbcType.VARCHAR.name())
|
||||
.setColumnComment("头像").setNullable(false)
|
||||
.setJavaType("String").setJavaField("avatar").setExample("https://www.iocoder.cn/1.png")
|
||||
.setCreateOperation(true).setUpdateOperation(true)
|
||||
.setListOperation(false)
|
||||
.setListOperationResult(true)
|
||||
.setHtmlType(CodegenColumnHtmlTypeEnum.IMAGE_UPLOAD.getType());
|
||||
CodegenColumnDO videoColumn = new CodegenColumnDO().setColumnName("video").setDataType(JdbcType.VARCHAR.name())
|
||||
.setColumnComment("附件").setNullable(true)
|
||||
.setJavaType("String").setJavaField("video").setExample("https://www.iocoder.cn/1.mp4")
|
||||
.setCreateOperation(true).setUpdateOperation(true)
|
||||
.setListOperation(false)
|
||||
.setListOperationResult(true)
|
||||
.setHtmlType(CodegenColumnHtmlTypeEnum.FILE_UPLOAD.getType());
|
||||
CodegenColumnDO memoColumn = new CodegenColumnDO().setColumnName("memo").setDataType(JdbcType.VARCHAR.name())
|
||||
.setColumnComment("备注").setNullable(false)
|
||||
.setJavaType("String").setJavaField("memo").setExample("我是备注")
|
||||
.setCreateOperation(true).setUpdateOperation(true)
|
||||
.setListOperation(false)
|
||||
.setListOperationResult(true)
|
||||
.setHtmlType(CodegenColumnHtmlTypeEnum.EDITOR.getType());
|
||||
CodegenColumnDO createTimeColumn = new CodegenColumnDO().setColumnName("create_time").setDataType(JdbcType.DATE.name())
|
||||
.setColumnComment("创建时间").setNullable(true)
|
||||
.setJavaType("LocalDateTime").setJavaField("createTime")
|
||||
.setCreateOperation(false).setUpdateOperation(false)
|
||||
.setListOperation(true).setListOperationCondition(CodegenColumnListConditionEnum.BETWEEN.getCondition())
|
||||
.setListOperationResult(true)
|
||||
.setHtmlType(CodegenColumnHtmlTypeEnum.DATETIME.getType());
|
||||
List<CodegenColumnDO> columns = Arrays.asList(idColumn, nameColumn, descriptionColumn, birthdayColumn,
|
||||
sexColumn, enabledColumn, avatarColumn, videoColumn, memoColumn, createTimeColumn);
|
||||
|
||||
// 调用
|
||||
Map<String, String> result = codegenEngine.execute(table, columns, null, null);
|
||||
|
||||
// 构建 zip 包
|
||||
String[] paths = result.keySet().toArray(new String[0]);
|
||||
ByteArrayInputStream[] ins = result.values().stream().map(IoUtil::toUtf8Stream).toArray(ByteArrayInputStream[]::new);
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ZipUtil.zip(outputStream, paths, ins);
|
||||
|
||||
FileUtil.writeBytes(outputStream.toByteArray(), "/Users/yunai/test/demo01.zip");
|
||||
|
||||
// 断言
|
||||
assertEquals(21, result.size());
|
||||
// 断言 vo 类
|
||||
@ -169,20 +186,7 @@ public class CodegenEngineTest extends BaseMockitoUnitTest {
|
||||
public void testExecute_vue3_masterSub() {
|
||||
// 准备请求参数
|
||||
// 主表
|
||||
CodegenTableDO table = new CodegenTableDO().setScene(CodegenSceneEnum.ADMIN.getScene())
|
||||
.setTableName("infra_demo_student").setTableComment("学生表")
|
||||
.setModuleName("infra").setBusinessName("demo02").setClassName("InfraDemoStudent")
|
||||
.setClassComment("学生").setAuthor("芋道源码")
|
||||
.setTemplateType(CodegenTemplateTypeEnum.MASTER_NORMAL.getType())
|
||||
// .setTemplateType(CodegenTemplateTypeEnum.MASTER_ERP.getType())
|
||||
.setFrontType(CodegenFrontTypeEnum.VUE3.getType());
|
||||
CodegenColumnDO idColumn = new CodegenColumnDO().setColumnName("id").setDataType(JdbcType.BIGINT.name())
|
||||
.setColumnComment("编号").setNullable(false).setPrimaryKey(true).setAutoIncrement(true)
|
||||
.setOrdinalPosition(1).setJavaType("Long").setJavaField("id").setExample("1024")
|
||||
.setCreateOperation(false).setUpdateOperation(true).setListOperation(false)
|
||||
.setListOperationResult(true);
|
||||
|
||||
List<CodegenColumnDO> columns = Collections.singletonList(idColumn);
|
||||
// 子表(联系人)
|
||||
CodegenTableDO contactTable = new CodegenTableDO().setScene(CodegenSceneEnum.ADMIN.getScene())
|
||||
.setTableName("infra_demo_student_contact").setTableComment("学生联系人表")
|
||||
@ -213,13 +217,13 @@ public class CodegenEngineTest extends BaseMockitoUnitTest {
|
||||
.setOrdinalPosition(4).setJavaType("String").setJavaField("avatar").setExample("https://www.iocoder.cn/1.png")
|
||||
.setCreateOperation(true).setUpdateOperation(true).setListOperation(false)
|
||||
.setListOperationResult(true)
|
||||
.setHtmlType(CodegenColumnHtmlTypeEnum.UPLOAD_IMAGE.getType());
|
||||
.setHtmlType(CodegenColumnHtmlTypeEnum.IMAGE_UPLOAD.getType());
|
||||
CodegenColumnDO contactVideoColumn = new CodegenColumnDO().setColumnName("video").setDataType(JdbcType.VARCHAR.name())
|
||||
.setColumnComment("视频").setNullable(false).setPrimaryKey(false)
|
||||
.setOrdinalPosition(5).setJavaType("String").setJavaField("video").setExample("https://www.iocoder.cn/1.mp4")
|
||||
.setCreateOperation(true).setUpdateOperation(true).setListOperation(false)
|
||||
.setListOperationResult(true)
|
||||
.setHtmlType(CodegenColumnHtmlTypeEnum.UPLOAD_FILE.getType());
|
||||
.setHtmlType(CodegenColumnHtmlTypeEnum.FILE_UPLOAD.getType());
|
||||
CodegenColumnDO contactDescriptionColumn = new CodegenColumnDO().setColumnName("description").setDataType(JdbcType.VARCHAR.name())
|
||||
.setColumnComment("个人简介").setNullable(false).setPrimaryKey(false)
|
||||
.setOrdinalPosition(6).setJavaType("String").setJavaField("description").setExample("我是介绍")
|
||||
@ -295,13 +299,13 @@ public class CodegenEngineTest extends BaseMockitoUnitTest {
|
||||
.setOrdinalPosition(4).setJavaType("String").setJavaField("avatar").setExample("https://www.iocoder.cn/1.png")
|
||||
.setCreateOperation(true).setUpdateOperation(true).setListOperation(false)
|
||||
.setListOperationResult(true)
|
||||
.setHtmlType(CodegenColumnHtmlTypeEnum.UPLOAD_IMAGE.getType());
|
||||
.setHtmlType(CodegenColumnHtmlTypeEnum.IMAGE_UPLOAD.getType());
|
||||
CodegenColumnDO addressVideoColumn = new CodegenColumnDO().setColumnName("video").setDataType(JdbcType.VARCHAR.name())
|
||||
.setColumnComment("视频").setNullable(false).setPrimaryKey(false)
|
||||
.setOrdinalPosition(5).setJavaType("String").setJavaField("video").setExample("https://www.iocoder.cn/1.mp4")
|
||||
.setCreateOperation(true).setUpdateOperation(true).setListOperation(false)
|
||||
.setListOperationResult(true)
|
||||
.setHtmlType(CodegenColumnHtmlTypeEnum.UPLOAD_FILE.getType());
|
||||
.setHtmlType(CodegenColumnHtmlTypeEnum.FILE_UPLOAD.getType());
|
||||
CodegenColumnDO addressDescriptionColumn = new CodegenColumnDO().setColumnName("description").setDataType(JdbcType.VARCHAR.name())
|
||||
.setColumnComment("个人简介").setNullable(false).setPrimaryKey(false)
|
||||
.setOrdinalPosition(6).setJavaType("String").setJavaField("description").setExample("我是介绍")
|
||||
@ -349,7 +353,7 @@ public class CodegenEngineTest extends BaseMockitoUnitTest {
|
||||
addressSex1Column, addressSex2Column, addressSex3Column, addressBirthdayColumn, addressMemoColumn, addressCreateTimeColumn);
|
||||
|
||||
// 调用
|
||||
Map<String, String> result = codegenEngine.execute(table, columns,
|
||||
Map<String, String> result = codegenEngine.execute(null, null,
|
||||
Arrays.asList(contactTable, addressTable), Arrays.asList(contactColumns, addressColumns));
|
||||
|
||||
// 断言
|
||||
@ -362,49 +366,6 @@ public class CodegenEngineTest extends BaseMockitoUnitTest {
|
||||
System.out.println("");
|
||||
System.out.println("");
|
||||
}
|
||||
|
||||
// // 断言 vo 类
|
||||
// for (String vo : new String[]{"SystemUserBaseVO", "SystemUserCreateReqVO", "SystemUserUpdateReqVO", "SystemUserRespVO",
|
||||
// "SystemUserPageReqVO", "SystemUserExportReqVO", "SystemUserExcelVO"}) {
|
||||
// assertPathContentEquals("vue3_crud/java/" + vo,
|
||||
// result, "yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/" + vo + ".java");
|
||||
// }
|
||||
// // 断言 controller 类
|
||||
// assertPathContentEquals("vue3_crud/java/SystemUserController",
|
||||
// result, "yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/SystemUserController.java");
|
||||
// // 断言 service 类
|
||||
// assertPathContentEquals("vue3_crud/java/SystemUserService",
|
||||
// result, "yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/SystemUserService.java");
|
||||
// assertPathContentEquals("vue3_crud/java/SystemUserServiceImpl",
|
||||
// result, "yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/SystemUserServiceImpl.java");
|
||||
// // 断言 convert 类
|
||||
// assertPathContentEquals("vue3_crud/java/SystemUserConvert",
|
||||
// result, "yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/user/SystemUserConvert.java");
|
||||
// // 断言 enums 类
|
||||
// assertPathContentEquals("vue3_crud/java/ErrorCodeConstants",
|
||||
// result, "yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants_手动操作.java");
|
||||
// // 断言 dal 类
|
||||
// assertPathContentEquals("vue3_crud/java/SystemUserDO",
|
||||
// result, "yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/user/SystemUserDO.java");
|
||||
// assertPathContentEquals("vue3_crud/java/SystemUserMapper",
|
||||
// result, "yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/user/SystemUserMapper.java");
|
||||
// assertPathContentEquals("vue3_crud/java/SystemUserMapper_xml",
|
||||
// result, "yudao-module-system/yudao-module-system-biz/src/main/resources/mapper/user/SystemUserMapper.xml");
|
||||
// // 断言 test 类
|
||||
// assertPathContentEquals("vue3_crud/java/SystemUserServiceImplTest",
|
||||
// result, "yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/user/SystemUserServiceImplTest.java");
|
||||
// // 断言 sql 语句
|
||||
// assertPathContentEquals("vue3_crud/sql/h2",
|
||||
// result, "sql/h2.sql");
|
||||
// assertPathContentEquals("vue3_crud/sql/sql",
|
||||
// result, "sql/sql.sql");
|
||||
// // 断言 vue 语句
|
||||
// assertPathContentEquals("vue3_crud/vue/index",
|
||||
// result, "yudao-ui-admin-vue3/src/views/system/user/index.vue");
|
||||
// assertPathContentEquals("vue3_crud/vue/form",
|
||||
// result, "yudao-ui-admin-vue3/src/views/system/user/UserForm.vue");
|
||||
// assertPathContentEquals("vue3_crud/vue/api",
|
||||
// result, "yudao-ui-admin-vue3/src/api/system/user/index.ts");
|
||||
}
|
||||
|
||||
private void assertPathContentEquals(String path, Map<String, String> result, String key) {
|
||||
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"table": {
|
||||
|
||||
},
|
||||
"columns": [{
|
||||
|
||||
}]
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
[{
|
||||
"filePath": "",
|
||||
"contentPath": ""
|
||||
}]
|
Loading…
Reference in New Issue
Block a user