From e67a6a2fe9ae733ec97ba25d4cc79f4354743387 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 12 Nov 2023 19:50:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90=EF=BC=9A1?= =?UTF-8?q?=EF=BC=89=E5=A2=9E=E5=8A=A0=20one=20=E6=83=85=E5=86=B5=E4=B8=8B?= =?UTF-8?q?=E7=9A=84=E7=A4=BA=E4=BE=8B=E4=BB=A3=E7=A0=81=EF=BC=9B2?= =?UTF-8?q?=EF=BC=89=E4=BF=AE=E5=A4=8D=20vue3=20=E6=A8=A1=E7=89=88?= =?UTF-8?q?=E7=8E=B0=E6=9C=89=E7=9A=84=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infra/enums/ErrorCodeConstants.java | 5 +- .../demo01/InfraDemo01StudentController.java | 89 ++++++++ .../demo01/vo/InfraDemo01StudentBaseVO.java | 52 +++++ .../vo/InfraDemo01StudentCreateReqVO.java | 14 ++ .../demo01/vo/InfraDemo01StudentExcelVO.java | 55 +++++ .../vo/InfraDemo01StudentExportReqVO.java | 31 +++ .../vo/InfraDemo01StudentPageReqVO.java | 36 +++ .../demo01/vo/InfraDemo01StudentRespVO.java | 19 ++ .../vo/InfraDemo01StudentUpdateReqVO.java | 20 ++ .../demo01/InfraDemo01StudentConvert.java | 34 +++ .../demo01/InfraDemo01StudentDO.java | 68 ++++++ .../demo01/InfraDemo01StudentMapper.java | 40 ++++ .../codegen/CodegenColumnHtmlTypeEnum.java | 4 +- .../service/codegen/inner/CodegenBuilder.java | 4 +- .../service/codegen/inner/CodegenEngine.java | 16 +- .../demo01/InfraDemo01StudentService.java | 62 +++++ .../demo01/InfraDemo01StudentServiceImpl.java | 81 +++++++ .../src/main/resources/codegen/sql/sql.vm | 2 +- .../views/components/form_sub_normal.vue.vm | 8 +- .../resources/codegen/vue3/views/form.vue.vm | 6 +- .../resources/codegen/vue3/views/index.vue.vm | 4 +- .../demo01/InfraDemo01StudentMapper.xml | 12 + .../codegen/inner/CodegenEngineTest.java | 213 +++++++----------- .../{vue3_master_sub/1 => table/contact.json} | 0 .../resources/codegen/table/extension.json | 0 .../test/resources/codegen/table/student.json | 8 + .../codegen/vue3_master_normal/assert.json | 4 + 27 files changed, 736 insertions(+), 151 deletions(-) create mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/InfraDemo01StudentController.java create mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/vo/InfraDemo01StudentBaseVO.java create mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/vo/InfraDemo01StudentCreateReqVO.java create mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/vo/InfraDemo01StudentExcelVO.java create mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/vo/InfraDemo01StudentExportReqVO.java create mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/vo/InfraDemo01StudentPageReqVO.java create mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/vo/InfraDemo01StudentRespVO.java create mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/vo/InfraDemo01StudentUpdateReqVO.java create mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/demo01/InfraDemo01StudentConvert.java create mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo01/InfraDemo01StudentDO.java create mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo01/InfraDemo01StudentMapper.java create mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo01/InfraDemo01StudentService.java create mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo01/InfraDemo01StudentServiceImpl.java create mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/resources/mapper/demo01/InfraDemo01StudentMapper.xml rename yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/{vue3_master_sub/1 => table/contact.json} (100%) create mode 100644 yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/table/extension.json create mode 100644 yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/table/student.json create mode 100644 yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_master_normal/assert.json diff --git a/yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants.java b/yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants.java index 1046c3c60..d0afe6fb6 100644 --- a/yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants.java +++ b/yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants.java @@ -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, "学生不存在"); } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/InfraDemo01StudentController.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/InfraDemo01StudentController.java new file mode 100644 index 000000000..41c58a2b6 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/InfraDemo01StudentController.java @@ -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 createDemo01Student(@Valid @RequestBody InfraDemo01StudentCreateReqVO createReqVO) { + return success(demo01StudentService.createDemo01Student(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新学生") + @PreAuthorize("@ss.hasPermission('infra:demo01-student:update')") + public CommonResult 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 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 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> getDemo01StudentPage(@Valid InfraDemo01StudentPageReqVO pageVO) { + PageResult 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 list = demo01StudentService.getDemo01StudentList(exportReqVO); + // 导出 Excel + List datas = InfraDemo01StudentConvert.INSTANCE.convertList02(list); + ExcelUtils.write(response, "学生.xls", "数据", InfraDemo01StudentExcelVO.class, datas); + } + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/vo/InfraDemo01StudentBaseVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/vo/InfraDemo01StudentBaseVO.java new file mode 100644 index 000000000..e7334b80b --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/vo/InfraDemo01StudentBaseVO.java @@ -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; + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/vo/InfraDemo01StudentCreateReqVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/vo/InfraDemo01StudentCreateReqVO.java new file mode 100644 index 000000000..f4e20631a --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/vo/InfraDemo01StudentCreateReqVO.java @@ -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 { + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/vo/InfraDemo01StudentExcelVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/vo/InfraDemo01StudentExcelVO.java new file mode 100644 index 000000000..d9a15ddd9 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/vo/InfraDemo01StudentExcelVO.java @@ -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; + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/vo/InfraDemo01StudentExportReqVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/vo/InfraDemo01StudentExportReqVO.java new file mode 100644 index 000000000..de807fa22 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/vo/InfraDemo01StudentExportReqVO.java @@ -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; + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/vo/InfraDemo01StudentPageReqVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/vo/InfraDemo01StudentPageReqVO.java new file mode 100644 index 000000000..cee743430 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/vo/InfraDemo01StudentPageReqVO.java @@ -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; + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/vo/InfraDemo01StudentRespVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/vo/InfraDemo01StudentRespVO.java new file mode 100644 index 000000000..05f66df67 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/vo/InfraDemo01StudentRespVO.java @@ -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; + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/vo/InfraDemo01StudentUpdateReqVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/vo/InfraDemo01StudentUpdateReqVO.java new file mode 100644 index 000000000..8ec28c0c9 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo01/vo/InfraDemo01StudentUpdateReqVO.java @@ -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; + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/demo01/InfraDemo01StudentConvert.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/demo01/InfraDemo01StudentConvert.java new file mode 100644 index 000000000..e7252fa95 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/demo01/InfraDemo01StudentConvert.java @@ -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 convertList(List list); + + PageResult convertPage(PageResult page); + + List convertList02(List list); + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo01/InfraDemo01StudentDO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo01/InfraDemo01StudentDO.java new file mode 100644 index 000000000..c78f9626e --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo01/InfraDemo01StudentDO.java @@ -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; + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo01/InfraDemo01StudentMapper.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo01/InfraDemo01StudentMapper.java new file mode 100644 index 000000000..3f930feaf --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo01/InfraDemo01StudentMapper.java @@ -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 { + + default PageResult selectPage(InfraDemo01StudentPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .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 selectList(InfraDemo01StudentExportReqVO reqVO) { + return selectList(new LambdaQueryWrapperX() + .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)); + } + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/enums/codegen/CodegenColumnHtmlTypeEnum.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/enums/codegen/CodegenColumnHtmlTypeEnum.java index 5474ba1a8..2c0cdbb8a 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/enums/codegen/CodegenColumnHtmlTypeEnum.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/enums/codegen/CodegenColumnHtmlTypeEnum.java @@ -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"), // 富文本控件 ; diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenBuilder.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenBuilder.java index 775535791..9cccfac37 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenBuilder.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenBuilder.java @@ -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) diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java index ebcf729af..e43aa723f 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java @@ -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")) diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo01/InfraDemo01StudentService.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo01/InfraDemo01StudentService.java new file mode 100644 index 000000000..e0ce1161b --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo01/InfraDemo01StudentService.java @@ -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 getDemo01StudentPage(InfraDemo01StudentPageReqVO pageReqVO); + + /** + * 获得学生列表, 用于 Excel 导出 + * + * @param exportReqVO 查询条件 + * @return 学生列表 + */ + List getDemo01StudentList(InfraDemo01StudentExportReqVO exportReqVO); + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo01/InfraDemo01StudentServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo01/InfraDemo01StudentServiceImpl.java new file mode 100644 index 000000000..e6faa56a0 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo01/InfraDemo01StudentServiceImpl.java @@ -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 getDemo01StudentPage(InfraDemo01StudentPageReqVO pageReqVO) { + return demo01StudentMapper.selectPage(pageReqVO); + } + + @Override + public List getDemo01StudentList(InfraDemo01StudentExportReqVO exportReqVO) { + return demo01StudentMapper.selectList(exportReqVO); + } + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/sql/sql.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/sql/sql.vm index 2e78ceee8..41b107dba 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/sql/sql.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/sql/sql.vm @@ -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 diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/components/form_sub_normal.vue.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/components/form_sub_normal.vue.vm index 11152b03c..b8a299daf 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/components/form_sub_normal.vue.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/components/form_sub_normal.vue.vm @@ -179,15 +179,15 @@ #elseif($column.htmlType == "imageUpload")## 图片上传 - + #elseif($column.htmlType == "fileUpload")## 文件上传 - + #elseif($column.htmlType == "editor")## 文本编辑器 - + #elseif($column.htmlType == "select")## 下拉框 @@ -257,7 +257,7 @@