From 7a3634d8c00a312c3f951b3267aea8d1d3ebfa6d Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 19 May 2025 11:02:03 +0800 Subject: [PATCH 01/10] perf: vben5 utils --- .../codegen/vue3_vben5_antd/schema/views/data.ts.vm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/data.ts.vm b/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/data.ts.vm index 5ca4c08d6e..e45fbcd28e 100644 --- a/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/data.ts.vm +++ b/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/data.ts.vm @@ -3,9 +3,11 @@ import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table'; import type { ${simpleClassName}Api } from '#/api/${table.moduleName}/${table.businessName}'; import { z } from '#/adapter/form'; -import { getRangePickerDefaultProps } from '#/utils/date'; -import { DICT_TYPE, getDictOptions } from '#/utils/dict'; - +import { + DICT_TYPE, + getDictOptions, + getRangePickerDefaultProps, +} from '#/utils'; #if(${table.templateType} == 2)## 树表需要导入这些 import { get${simpleClassName}List } from '#/api/${table.moduleName}/${table.businessName}'; import { handleTree } from '@vben/utils'; From 9295d610308d692caf698b27df053428e5e5b738 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 19 May 2025 11:50:07 +0800 Subject: [PATCH 02/10] =?UTF-8?q?feat:=E3=80=90INFRA=20=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E8=AE=BE=E6=96=BD=E3=80=91=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E5=8F=AF=E7=94=9F=E6=88=90=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../codegen/vo/table/CodegenTableRespVO.java | 4 ++ .../vo/table/CodegenTableSaveReqVO.java | 4 ++ .../demo/demo01/Demo01ContactController.java | 14 ++++++- .../demo01/vo/Demo01ContactPageReqVO.java | 8 ++-- .../demo/demo01/vo/Demo01ContactRespVO.java | 13 +++--- .../demo01/vo/Demo01ContactSaveReqVO.java | 4 +- .../dataobject/codegen/CodegenTableDO.java | 6 +++ .../demo/demo01/Demo01ContactMapper.java | 4 +- .../demo/demo01/Demo01ContactService.java | 17 +++++--- .../demo/demo01/Demo01ContactServiceImpl.java | 34 +++++++++++----- .../codegen/java/controller/controller.vm | 13 ++++++ .../resources/codegen/java/dal/mapper_sub.vm | 6 +++ .../resources/codegen/java/service/service.vm | 9 +++++ .../codegen/java/service/serviceImpl.vm | 40 +++++++++++++++++++ 14 files changed, 146 insertions(+), 30 deletions(-) diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/table/CodegenTableRespVO.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/table/CodegenTableRespVO.java index 8b438b2da6..a8a8fe108f 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/table/CodegenTableRespVO.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/table/CodegenTableRespVO.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.infra.controller.admin.codegen.vo.table; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; import lombok.Data; import java.time.LocalDateTime; @@ -45,6 +46,9 @@ public class CodegenTableRespVO { @Schema(description = "前端类型,参见 CodegenFrontTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "20") private Integer frontType; + @Schema(description = "是否生成批量删除接口", example = "true") + private Boolean deleteBatch; + @Schema(description = "父菜单编号", example = "1024") private Long parentMenuId; diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/table/CodegenTableSaveReqVO.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/table/CodegenTableSaveReqVO.java index 201d94d2e2..1fa2ba9278 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/table/CodegenTableSaveReqVO.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/table/CodegenTableSaveReqVO.java @@ -60,6 +60,10 @@ public class CodegenTableSaveReqVO { @NotNull(message = "前端类型不能为空") private Integer frontType; + @Schema(description = "是否生成批量删除接口", example = "true") + @NotNull(message = "是否生成批量删除接口不能为空") + private Boolean deleteBatch; + @Schema(description = "父菜单编号", example = "1024") private Long parentMenuId; diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo01/Demo01ContactController.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo01/Demo01ContactController.java index cf6935e505..c3c518db9c 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo01/Demo01ContactController.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo01/Demo01ContactController.java @@ -17,6 +17,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.Valid; +import jakarta.validation.constraints.Size; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -60,6 +61,15 @@ public class Demo01ContactController { return success(true); } + @DeleteMapping("/delete-batch") + @Parameter(name = "ids", description = "编号", required = true) + @Operation(summary = "批量删除示例联系人") + @PreAuthorize("@ss.hasPermission('infra:demo01-contact:delete')") + public CommonResult deleteDemo01Contact(@RequestParam("ids") @Size(max = 100, message = "最多允许100个") List ids) { + demo01ContactService.deleteDemo01ContactByIds(ids); + return success(true); + } + @GetMapping("/get") @Operation(summary = "获得示例联系人") @Parameter(name = "id", description = "编号", required = true, example = "1024") @@ -82,12 +92,12 @@ public class Demo01ContactController { @PreAuthorize("@ss.hasPermission('infra:demo01-contact:export')") @ApiAccessLog(operateType = EXPORT) public void exportDemo01ContactExcel(@Valid Demo01ContactPageReqVO pageReqVO, - HttpServletResponse response) throws IOException { + HttpServletResponse response) throws IOException { pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); List list = demo01ContactService.getDemo01ContactPage(pageReqVO).getList(); // 导出 Excel ExcelUtils.write(response, "示例联系人.xls", "数据", Demo01ContactRespVO.class, - BeanUtils.toBean(list, Demo01ContactRespVO.class)); + BeanUtils.toBean(list, Demo01ContactRespVO.class)); } } \ No newline at end of file diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo01/vo/Demo01ContactPageReqVO.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo01/vo/Demo01ContactPageReqVO.java index d337d2d7db..151813965c 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo01/vo/Demo01ContactPageReqVO.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo01/vo/Demo01ContactPageReqVO.java @@ -1,10 +1,12 @@ package cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo; -import lombok.*; -import java.util.*; -import io.swagger.v3.oas.annotations.media.Schema; 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; diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo01/vo/Demo01ContactRespVO.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo01/vo/Demo01ContactRespVO.java index 5d176c262a..17ee9fef84 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo01/vo/Demo01ContactRespVO.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo01/vo/Demo01ContactRespVO.java @@ -1,14 +1,13 @@ package cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; -import java.util.*; -import java.util.*; -import org.springframework.format.annotation.DateTimeFormat; -import java.time.LocalDateTime; -import com.alibaba.excel.annotation.*; import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDateTime; @Schema(description = "管理后台 - 示例联系人 Response VO") @Data diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo01/vo/Demo01ContactSaveReqVO.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo01/vo/Demo01ContactSaveReqVO.java index 352e43178a..15d2727663 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo01/vo/Demo01ContactSaveReqVO.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo01/vo/Demo01ContactSaveReqVO.java @@ -1,10 +1,10 @@ package cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; +import lombok.Data; + import java.time.LocalDateTime; @Schema(description = "管理后台 - 示例联系人新增/修改 Request VO") diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/codegen/CodegenTableDO.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/codegen/CodegenTableDO.java index b46cbe4fef..d8aa79b66a 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/codegen/CodegenTableDO.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/codegen/CodegenTableDO.java @@ -108,6 +108,12 @@ public class CodegenTableDO extends BaseDO { * 枚举 {@link CodegenFrontTypeEnum} */ private Integer frontType; + /** + * 是否生成批量删除接口 + * -true 是 + * -false 否 + */ + private Boolean deleteBatch; // ========== 菜单相关字段 ========== diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo01/Demo01ContactMapper.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo01/Demo01ContactMapper.java index f5f3cdbbe8..800f662afb 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo01/Demo01ContactMapper.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo01/Demo01ContactMapper.java @@ -1,9 +1,9 @@ package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo01; 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.controller.admin.demo.demo01.vo.Demo01ContactPageReqVO; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.*; import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo01.Demo01ContactDO; import org.apache.ibatis.annotations.Mapper; diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo01/Demo01ContactService.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo01/Demo01ContactService.java index efcb6e5d04..5d1d611559 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo01/Demo01ContactService.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo01/Demo01ContactService.java @@ -1,11 +1,11 @@ package cn.iocoder.yudao.module.infra.service.demo.demo01; -import jakarta.validation.*; - -import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.Demo01ContactPageReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.Demo01ContactSaveReqVO; -import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo01.Demo01ContactDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.*; +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo01.Demo01ContactDO; +import jakarta.validation.Valid; + +import java.util.List; /** * 示例联系人 Service 接口 @@ -36,6 +36,13 @@ public interface Demo01ContactService { */ void deleteDemo01Contact(Long id); + /** + * 批量删除示例联系人 + * + * @param ids 编号 + */ + void deleteDemo01ContactByIds(List ids); + /** * 获得示例联系人 * diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo01/Demo01ContactServiceImpl.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo01/Demo01ContactServiceImpl.java index f695e3dcb7..5f74253102 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo01/Demo01ContactServiceImpl.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo01/Demo01ContactServiceImpl.java @@ -1,19 +1,20 @@ package cn.iocoder.yudao.module.infra.service.demo.demo01; -import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.Demo01ContactPageReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.Demo01ContactSaveReqVO; -import org.springframework.stereotype.Service; -import jakarta.annotation.Resource; -import org.springframework.validation.annotation.Validated; - -import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo01.Demo01ContactDO; +import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; - +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.Demo01ContactPageReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.Demo01ContactSaveReqVO; +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo01.Demo01ContactDO; import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo01.Demo01ContactMapper; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.DEMO01_CONTACT_NOT_EXISTS; /** * 示例联系人 Service 实现类 @@ -53,6 +54,21 @@ public class Demo01ContactServiceImpl implements Demo01ContactService { demo01ContactMapper.deleteById(id); } + @Override + public void deleteDemo01ContactByIds(List ids) { + // 校验存在 + validateDemo01ContactExists(ids); + // 删除 + demo01ContactMapper.deleteByIds(ids); + } + + private void validateDemo01ContactExists(List ids) { + List list = demo01ContactMapper.selectByIds(ids); + if (CollUtil.isEmpty(list) || list.size() != ids.size()) { + throw exception(DEMO01_CONTACT_NOT_EXISTS); + } + } + private void validateDemo01ContactExists(Long id) { if (demo01ContactMapper.selectById(id) == null) { throw exception(DEMO01_CONTACT_NOT_EXISTS); diff --git a/yudao-module-infra/src/main/resources/codegen/java/controller/controller.vm b/yudao-module-infra/src/main/resources/codegen/java/controller/controller.vm index 5aa3baef83..0d607ced55 100644 --- a/yudao-module-infra/src/main/resources/codegen/java/controller/controller.vm +++ b/yudao-module-infra/src/main/resources/codegen/java/controller/controller.vm @@ -74,6 +74,19 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { return success(true); } +#if ( $table.templateType != 2 && $table.deleteBatch) + @DeleteMapping("/delete-batch") + @Parameter(name = "ids", description = "编号", required = true) + @Operation(summary = "批量删除${table.classComment}") + #if ($sceneEnum.scene == 1) + @PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')") + #end + public CommonResult delete${simpleClassName}(@RequestParam("ids") @Size(max = 100, message = "最多允许100个") List<${primaryColumn.javaType}> ids) { + ${classNameVar}Service.delete${simpleClassName}ByIds(ids); + return success(true); + } +#end + @GetMapping("/get") @Operation(summary = "获得${table.classComment}") @Parameter(name = "id", description = "编号", required = true, example = "1024") diff --git a/yudao-module-infra/src/main/resources/codegen/java/dal/mapper_sub.vm b/yudao-module-infra/src/main/resources/codegen/java/dal/mapper_sub.vm index 6ccaea79ea..88d1cd0745 100644 --- a/yudao-module-infra/src/main/resources/codegen/java/dal/mapper_sub.vm +++ b/yudao-module-infra/src/main/resources/codegen/java/dal/mapper_sub.vm @@ -54,4 +54,10 @@ public interface ${subTable.className}Mapper extends BaseMapperX<${subTable.clas return delete(${subTable.className}DO::get${SubJoinColumnName}, ${subJoinColumn.javaField}); } +#if ( $table.templateType != 2 && $table.deleteBatch) + default int deleteBy${SubJoinColumnName}s(List<${subJoinColumn.javaType}> ${subJoinColumn.javaField}s) { + return delete(${subTable.className}DO::get${SubJoinColumnName}, ${subJoinColumn.javaField}s); + } +#end + } diff --git a/yudao-module-infra/src/main/resources/codegen/java/service/service.vm b/yudao-module-infra/src/main/resources/codegen/java/service/service.vm index c4ee4f0f64..f99817c6ce 100644 --- a/yudao-module-infra/src/main/resources/codegen/java/service/service.vm +++ b/yudao-module-infra/src/main/resources/codegen/java/service/service.vm @@ -40,6 +40,15 @@ public interface ${table.className}Service { */ void delete${simpleClassName}(${primaryColumn.javaType} id); +#if ( $table.templateType != 2 && $table.deleteBatch) + /** + * 批量删除${table.classComment} + * + * @param ids 编号 + */ + void delete${simpleClassName}ByIds(List<${primaryColumn.javaType}> ids); +#end + /** * 获得${table.classComment} * diff --git a/yudao-module-infra/src/main/resources/codegen/java/service/serviceImpl.vm b/yudao-module-infra/src/main/resources/codegen/java/service/serviceImpl.vm index 80bc71b026..1680398909 100644 --- a/yudao-module-infra/src/main/resources/codegen/java/service/serviceImpl.vm +++ b/yudao-module-infra/src/main/resources/codegen/java/service/serviceImpl.vm @@ -1,5 +1,6 @@ package ${basePackage}.module.${table.moduleName}.service.${table.businessName}; +import cn.hutool.core.collection.CollUtil; import org.springframework.stereotype.Service; import ${jakartaPackage}.annotation.Resource; import org.springframework.validation.annotation.Validated; @@ -154,6 +155,39 @@ public class ${table.className}ServiceImpl implements ${table.className}Service #end } +#if ( $table.templateType != 2 && $table.deleteBatch) + @Override + ## 特殊:主子表专属逻辑 + #if ( $subTables && $subTables.size() > 0) + @Transactional(rollbackFor = Exception.class) + #end + public void delete${simpleClassName}ByIds(List<${primaryColumn.javaType}> ids) { + // 校验存在 + validate${simpleClassName}Exists(ids); + // 删除 + ${classNameVar}Mapper.deleteByIds(ids); + ## 特殊:主子表专属逻辑 + #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}s(ids); + #end + #end + } + + private void validate${simpleClassName}Exists(List<${primaryColumn.javaType}> ids) { + List<${table.className}DO> list = ${classNameVar}Mapper.selectByIds(ids); + if (CollUtil.isEmpty(list) || list.size() != ids.size()) { + throw exception(${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS); + } + } +#end + private void validate${simpleClassName}Exists(${primaryColumn.javaType} id) { if (${classNameVar}Mapper.selectById(id) == null) { throw exception(${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS); @@ -347,5 +381,11 @@ public class ${table.className}ServiceImpl implements ${table.className}Service ${subClassNameVars.get($index)}Mapper.deleteBy${SubJoinColumnName}(${subJoinColumn.javaField}); } +#if ( $table.templateType != 2 && $table.deleteBatch) + private void delete${subSimpleClassName}By${SubJoinColumnName}s(List<${primaryColumn.javaType}> ${subJoinColumn.javaField}s) { + ${subClassNameVars.get($index)}Mapper.deleteBy${SubJoinColumnName}s(${subJoinColumn.javaField}s); + } +#end + #end } \ No newline at end of file From 6dee926253c86790aa0ea88b2b27a981a7d49794 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 19 May 2025 12:55:07 +0800 Subject: [PATCH 03/10] =?UTF-8?q?feat:=E3=80=90INFRA=20=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E8=AE=BE=E6=96=BD=E3=80=91=E6=96=B0=E5=A2=9E=20vben5-antd-sche?= =?UTF-8?q?ma=20=E6=A8=A1=E6=9D=BF=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E5=8F=AF=E7=94=9F=E6=88=90=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vue3_vben5_antd/schema/api/api.ts.vm | 7 +++ .../vue3_vben5_antd/schema/views/data.ts.vm | 3 + .../vue3_vben5_antd/schema/views/index.vue.vm | 55 +++++++++++++++++-- 3 files changed, 59 insertions(+), 6 deletions(-) diff --git a/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/api/api.ts.vm b/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/api/api.ts.vm index d3342f1fc8..6b071bed07 100644 --- a/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/api/api.ts.vm +++ b/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/api/api.ts.vm @@ -89,6 +89,13 @@ export function delete${simpleClassName}(id: number) { return requestClient.delete(`${baseURL}/delete?id=${id}`); } +#if ( $table.templateType != 2 && $table.deleteBatch) +// 批量删除${table.classComment} +export function delete${simpleClassName}ByIds(ids: number[]) { + return requestClient.delete(`${baseURL}/delete-batch?ids=${ids.join(',')}`) +} +#end + /** 导出${table.classComment} */ export function export${simpleClassName}(params: any) { return requestClient.download('${baseURL}/export-excel', params); diff --git a/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/data.ts.vm b/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/data.ts.vm index e45fbcd28e..7daa12423f 100644 --- a/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/data.ts.vm +++ b/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/data.ts.vm @@ -193,6 +193,9 @@ export function useGridColumns( onActionClick?: OnActionClickFn<${simpleClassName}Api.${simpleClassName}>, ): VxeTableGridOptions<${simpleClassName}Api.${simpleClassName}>['columns'] { return [ +#if ($table.templateType != 2 && $table.deleteBatch) + { type: 'checkbox', width: 40 }, +#end #if ($table.templateType == 12) ## 内嵌情况 { type: 'expand', width: 80, slots: { content: 'expand_content' } }, #end diff --git a/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/index.vue.vm b/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/index.vue.vm index 1d8700eaa2..e1d79bc972 100644 --- a/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/index.vue.vm +++ b/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/index.vue.vm @@ -4,7 +4,7 @@ import type { ${simpleClassName}Api } from '#/api/${table.moduleName}/${table.bu import { Page, useVbenModal } from '@vben/common-ui'; import { Button, message,Tabs } from 'ant-design-vue'; -import { Download, Plus } from '@vben/icons'; +import { Download, Plus, Trash2 } from '@vben/icons'; import Form from './modules/form.vue'; ## 特殊:主子表专属逻辑 @@ -16,15 +16,15 @@ import Form from './modules/form.vue'; #end #end -import { ref, h } from 'vue'; +import { ref, h, computed } from 'vue'; import { $t } from '#/locales'; import { useVbenVxeGrid } from '#/adapter/vxe-table'; #if (${table.templateType} == 2)## 树表接口 import { get${simpleClassName}List, delete${simpleClassName}, export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}'; #else## 标准表接口 -import { get${simpleClassName}Page, delete${simpleClassName}, export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}'; +import { get${simpleClassName}Page, delete${simpleClassName},delete${simpleClassName}ByIds, export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}'; #end -import { downloadFileFromBlobPart } from '@vben/utils'; +import { downloadFileFromBlobPart, isEmpty } from '@vben/utils'; import { useGridColumns, useGridFormSchema } from './data'; @@ -87,11 +87,31 @@ async function onDelete(row: ${simpleClassName}Api.${simpleClassName}) { await delete${simpleClassName}(row.id as number); message.success( $t('ui.actionMessage.deleteSuccess', [row.id]) ); onRefresh(); - } catch { + } finally { hideLoading(); } } +#if ($table.templateType != 2 && $table.deleteBatch) +const deleteIds = ref([]) // 待删除${table.classComment} ID +const showDeleteBatchBtn = computed(() => isEmpty(deleteIds.value)); +/** 批量删除${table.classComment} */ +async function onDeleteBatch() { + const hideLoading = message.loading({ + content: $t('ui.actionMessage.deleting'), + duration: 0, + key: 'action_process_msg', + }); + try { + await delete${simpleClassName}ByIds(deleteIds.value); + message.success( $t('ui.actionMessage.deleteSuccess') ); + onRefresh(); + } finally { + hideLoading(); + } +} +#end + /** 导出表格 */ async function onExport() { const data = await export${simpleClassName}(await gridApi.formApi.getValues()); @@ -177,11 +197,21 @@ const [Grid, gridApi] = useVbenVxeGrid({ search: true, }, } as VxeTableGridOptions<${simpleClassName}Api.${simpleClassName}>, -#if (${table.templateType} == 11) +#if (${table.templateType} == 11 || $table.deleteBatch) gridEvents:{ + #if(${table.templateType} == 11) cellClick: ({ row }: { row: ${simpleClassName}Api.${simpleClassName}}) => { select${simpleClassName}.value = row; }, + #end + #if($table.deleteBatch) + checkboxAll: ({records,}: { records: ${simpleClassName}Api.${simpleClassName}[];}) => { + deleteIds.value = records.map((item) => item.id); + }, + checkboxChange: ({records,}: { records: ${simpleClassName}Api.${simpleClassName}[];}) => { + deleteIds.value = records.map((item) => item.id); + }, + #end } #end }); @@ -229,6 +259,19 @@ const [Grid, gridApi] = useVbenVxeGrid({ > {{ $t('ui.actionTitle.export') }} +#if ($table.templateType != 2 && $table.deleteBatch) + +#end From ef1e7b312bde4e653da3a7e4b40ef7ff5af04bba Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 19 May 2025 16:52:52 +0800 Subject: [PATCH 04/10] =?UTF-8?q?perf:=E3=80=90INFRA=20=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E8=AE=BE=E6=96=BD=E3=80=91vben5-antd-schema=20=E4=B8=BB?= =?UTF-8?q?=E4=B8=BB=E5=AD=90=E8=A1=A8erp=E4=BB=A3=E7=A0=81=E7=94=9F?= =?UTF-8?q?=E6=88=90=E6=97=B6=EF=BC=8C=E5=8F=AF=E7=94=9F=E6=88=90=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{ => erp}/Demo03StudentController.java | 59 ++++--- .../{ => erp}/vo/Demo03StudentPageReqVO.java | 2 +- .../{ => erp}/vo/Demo03StudentRespVO.java | 2 +- .../{ => erp}/vo/Demo03StudentSaveReqVO.java | 11 +- .../admin/demo/demo03/package-info.java | 1 - .../demo03/{ => erp}/Demo03CourseMapper.java | 16 +- .../demo03/{ => erp}/Demo03GradeMapper.java | 19 ++- .../demo03/{ => erp}/Demo03StudentMapper.java | 6 +- .../infra/enums/ErrorCodeConstants.java | 5 +- .../{ => erp}/Demo03StudentService.java | 70 ++++---- .../{ => erp}/Demo03StudentServiceImpl.java | 154 ++++++++++-------- .../service/demo/demo03/package-info.java | 1 + .../codegen/java/controller/controller.vm | 15 +- .../resources/codegen/java/service/service.vm | 9 + .../codegen/java/service/serviceImpl.vm | 19 +++ .../vue3_vben5_antd/schema/api/api.ts.vm | 7 + .../vue3_vben5_antd/schema/views/data.ts.vm | 3 + .../vue3_vben5_antd/schema/views/index.vue.vm | 2 +- .../schema/views/modules/list_sub_erp.vue.vm | 52 +++++- 19 files changed, 292 insertions(+), 161 deletions(-) rename yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/{ => erp}/Demo03StudentController.java (83%) rename yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/{ => erp}/vo/Demo03StudentPageReqVO.java (98%) rename yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/{ => erp}/vo/Demo03StudentRespVO.java (99%) rename yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/{ => erp}/vo/Demo03StudentSaveReqVO.java (80%) delete mode 100644 yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/package-info.java rename yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/{ => erp}/Demo03CourseMapper.java (72%) rename yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/{ => erp}/Demo03GradeMapper.java (69%) rename yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/{ => erp}/Demo03StudentMapper.java (93%) rename yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/{ => erp}/Demo03StudentService.java (80%) rename yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/{ => erp}/Demo03StudentServiceImpl.java (67%) create mode 100644 yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/package-info.java diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/Demo03StudentController.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/Demo03StudentController.java similarity index 83% rename from yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/Demo03StudentController.java rename to yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/Demo03StudentController.java index bee5984751..09c0c20b78 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/Demo03StudentController.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/Demo03StudentController.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03; +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp; import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; import cn.iocoder.yudao.framework.common.pojo.CommonResult; @@ -6,13 +6,13 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; -import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentPageReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentRespVO; -import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentSaveReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentPageReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentRespVO; +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentSaveReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; -import cn.iocoder.yudao.module.infra.service.demo.demo03.Demo03StudentService; +import cn.iocoder.yudao.module.infra.service.demo.demo03.erp.Demo03StudentService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -31,7 +31,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @Tag(name = "管理后台 - 学生") @RestController -@RequestMapping("/infra/demo03-student") +@RequestMapping("/infra/demo03-student-erp") @Validated public class Demo03StudentController { @@ -62,6 +62,15 @@ public class Demo03StudentController { return success(true); } + @DeleteMapping("/delete-batch") + @Parameter(name = "ids", description = "编号", required = true) + @Operation(summary = "批量删除学生") + @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") + public CommonResult deleteDemo03Student(@RequestParam("ids") List ids) { + demo03StudentService.deleteDemo03StudentByIds(ids); + return success(true); + } + @GetMapping("/get") @Operation(summary = "获得学生") @Parameter(name = "id", description = "编号", required = true, example = "1024") @@ -84,12 +93,12 @@ public class Demo03StudentController { @PreAuthorize("@ss.hasPermission('infra:demo03-student:export')") @ApiAccessLog(operateType = EXPORT) public void exportDemo03StudentExcel(@Valid Demo03StudentPageReqVO pageReqVO, - HttpServletResponse response) throws IOException { + HttpServletResponse response) throws IOException { pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); List list = demo03StudentService.getDemo03StudentPage(pageReqVO).getList(); // 导出 Excel ExcelUtils.write(response, "学生.xls", "数据", Demo03StudentRespVO.class, - BeanUtils.toBean(list, Demo03StudentRespVO.class)); + BeanUtils.toBean(list, Demo03StudentRespVO.class)); } // ==================== 子表(学生课程) ==================== @@ -127,6 +136,15 @@ public class Demo03StudentController { return success(true); } + @DeleteMapping("/demo03-course/delete-batch") + @Parameter(name = "ids", description = "编号", required = true) + @Operation(summary = "批量删除学生课程") + @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") + public CommonResult deleteDemo03Course(@RequestParam("ids") List ids) { + demo03StudentService.deleteDemo03CourseByIds(ids); + return success(true); + } + @GetMapping("/demo03-course/get") @Operation(summary = "获得学生课程") @Parameter(name = "id", description = "编号", required = true) @@ -135,14 +153,6 @@ public class Demo03StudentController { return success(demo03StudentService.getDemo03Course(id)); } - @GetMapping("/demo03-course/list-by-student-id") - @Operation(summary = "获得学生课程列表") - @Parameter(name = "studentId", description = "学生编号") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") - public CommonResult> getDemo03CourseListByStudentId(@RequestParam("studentId") Long studentId) { - return success(demo03StudentService.getDemo03CourseListByStudentId(studentId)); - } - // ==================== 子表(学生班级) ==================== @GetMapping("/demo03-grade/page") @@ -178,6 +188,15 @@ public class Demo03StudentController { return success(true); } + @DeleteMapping("/demo03-grade/delete-batch") + @Parameter(name = "ids", description = "编号", required = true) + @Operation(summary = "批量删除学生班级") + @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") + public CommonResult deleteDemo03Grade(@RequestParam("ids") List ids) { + demo03StudentService.deleteDemo03GradeByIds(ids); + return success(true); + } + @GetMapping("/demo03-grade/get") @Operation(summary = "获得学生班级") @Parameter(name = "id", description = "编号", required = true) @@ -186,12 +205,4 @@ public class Demo03StudentController { return success(demo03StudentService.getDemo03Grade(id)); } - @GetMapping("/demo03-grade/get-by-student-id") - @Operation(summary = "获得学生班级") - @Parameter(name = "studentId", description = "学生编号") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") - public CommonResult getDemo03GradeByStudentId(@RequestParam("studentId") Long studentId) { - return success(demo03StudentService.getDemo03GradeByStudentId(studentId)); - } - } \ No newline at end of file diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/vo/Demo03StudentPageReqVO.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentPageReqVO.java similarity index 98% rename from yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/vo/Demo03StudentPageReqVO.java rename to yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentPageReqVO.java index 6834991755..2845b324b8 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/vo/Demo03StudentPageReqVO.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentPageReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo; +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo; import lombok.*; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/vo/Demo03StudentRespVO.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentRespVO.java similarity index 99% rename from yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/vo/Demo03StudentRespVO.java rename to yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentRespVO.java index 5ae784fa04..8f60e3c660 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/vo/Demo03StudentRespVO.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentRespVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo; +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo; import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/vo/Demo03StudentSaveReqVO.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentSaveReqVO.java similarity index 80% rename from yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/vo/Demo03StudentSaveReqVO.java rename to yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentSaveReqVO.java index ec9f29cc9d..5bd8125e01 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/vo/Demo03StudentSaveReqVO.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentSaveReqVO.java @@ -1,12 +1,10 @@ -package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo; +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo; import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; -import java.util.*; import jakarta.validation.constraints.*; + import java.time.LocalDateTime; -import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; -import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; @Schema(description = "管理后台 - 学生新增/修改 Request VO") @Data @@ -31,9 +29,4 @@ public class Demo03StudentSaveReqVO { @NotEmpty(message = "简介不能为空") private String description; - - private List demo03Courses; - - private Demo03GradeDO demo03Grade; - } \ No newline at end of file diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/package-info.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/package-info.java deleted file mode 100644 index 79682e2034..0000000000 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03; \ No newline at end of file diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/Demo03CourseMapper.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03CourseMapper.java similarity index 72% rename from yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/Demo03CourseMapper.java rename to yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03CourseMapper.java index 3cb3aa5920..891586a7da 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/Demo03CourseMapper.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03CourseMapper.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03; +package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -19,16 +19,16 @@ public interface Demo03CourseMapper extends BaseMapperX { default PageResult selectPage(PageParam reqVO, Long studentId) { return selectPage(reqVO, new LambdaQueryWrapperX() - .eq(Demo03CourseDO::getStudentId, studentId) - .orderByDesc(Demo03CourseDO::getId)); - } - - default List selectListByStudentId(Long studentId) { - return selectList(Demo03CourseDO::getStudentId, studentId); + .eq(Demo03CourseDO::getStudentId, studentId) + .orderByDesc(Demo03CourseDO::getId)); } default int deleteByStudentId(Long studentId) { return delete(Demo03CourseDO::getStudentId, studentId); } -} \ No newline at end of file + default int deleteByStudentIds(List studentIds) { + return delete(Demo03CourseDO::getStudentId, studentIds); + } + +} diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/Demo03GradeMapper.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03GradeMapper.java similarity index 69% rename from yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/Demo03GradeMapper.java rename to yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03GradeMapper.java index 0440cc49e3..aec5474beb 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/Demo03GradeMapper.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03GradeMapper.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03; +package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -7,6 +7,8 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; import org.apache.ibatis.annotations.Mapper; +import java.util.List; + /** * 学生班级 Mapper * @@ -17,16 +19,19 @@ public interface Demo03GradeMapper extends BaseMapperX { default PageResult selectPage(PageParam reqVO, Long studentId) { return selectPage(reqVO, new LambdaQueryWrapperX() - .eq(Demo03GradeDO::getStudentId, studentId) - .orderByDesc(Demo03GradeDO::getId)); + .eq(Demo03GradeDO::getStudentId, studentId) + .orderByDesc(Demo03GradeDO::getId)); } - - default Demo03GradeDO selectByStudentId(Long studentId) { + default Demo03GradeDO selectByStudentId(Long studentId) { return selectOne(Demo03GradeDO::getStudentId, studentId); - } + } default int deleteByStudentId(Long studentId) { return delete(Demo03GradeDO::getStudentId, studentId); } -} \ No newline at end of file + default int deleteByStudentIds(List studentIds) { + return delete(Demo03GradeDO::getStudentId, studentIds); + } + +} diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/Demo03StudentMapper.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03StudentMapper.java similarity index 93% rename from yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/Demo03StudentMapper.java rename to yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03StudentMapper.java index 00659d0520..7d7628baaf 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/Demo03StudentMapper.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03StudentMapper.java @@ -1,11 +1,11 @@ -package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03; +package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp; 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.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.*; import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; import org.apache.ibatis.annotations.Mapper; -import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.*; /** * 学生 Mapper diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants.java index 4cce820b77..2233f353e7 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants.java @@ -65,7 +65,8 @@ public interface ErrorCodeConstants { ErrorCode DEMO02_CATEGORY_NAME_DUPLICATE = new ErrorCode(1_001_201_005, "已经存在该名字的示例分类"); ErrorCode DEMO02_CATEGORY_PARENT_IS_CHILD = new ErrorCode(1_001_201_006, "不能设置自己的子示例分类为父示例分类"); ErrorCode DEMO03_STUDENT_NOT_EXISTS = new ErrorCode(1_001_201_007, "学生不存在"); - ErrorCode DEMO03_GRADE_NOT_EXISTS = new ErrorCode(1_001_201_008, "学生班级不存在"); - ErrorCode DEMO03_GRADE_EXISTS = new ErrorCode(1_001_201_009, "学生班级已存在"); + ErrorCode DEMO03_COURSE_NOT_EXISTS = new ErrorCode(1_001_201_008, "学生课程不存在"); + ErrorCode DEMO03_GRADE_NOT_EXISTS = new ErrorCode(1_001_201_009, "学生班级不存在"); + ErrorCode DEMO03_GRADE_EXISTS = new ErrorCode(1_001_201_010, "学生班级已存在"); } diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/Demo03StudentService.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/erp/Demo03StudentService.java similarity index 80% rename from yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/Demo03StudentService.java rename to yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/erp/Demo03StudentService.java index 1e384a31f2..e4c97c68d9 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/Demo03StudentService.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/erp/Demo03StudentService.java @@ -1,15 +1,13 @@ -package cn.iocoder.yudao.module.infra.service.demo.demo03; +package cn.iocoder.yudao.module.infra.service.demo.demo03.erp; -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentPageReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentSaveReqVO; +import java.util.*; +import jakarta.validation.*; +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.*; +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; -import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; - -import jakarta.validation.Valid; -import java.util.List; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; /** * 学生 Service 接口 @@ -40,6 +38,13 @@ public interface Demo03StudentService { */ void deleteDemo03Student(Long id); + /** + * 批量删除学生 + * + * @param ids 编号 + */ + void deleteDemo03StudentByIds(List ids); + /** * 获得学生 * @@ -56,17 +61,8 @@ public interface Demo03StudentService { */ PageResult getDemo03StudentPage(Demo03StudentPageReqVO pageReqVO); - // ==================== 子表(学生课程) ==================== - /** - * 获得学生课程列表 - * - * @param studentId 学生编号 - * @return 学生课程列表 - */ - List getDemo03CourseListByStudentId(Long studentId); - /** * 获得学生课程分页 * @@ -99,23 +95,22 @@ public interface Demo03StudentService { void deleteDemo03Course(Long id); /** - * 获得学生课程 - * - * @param id 编号 + * 批量删除学生课程 + * + * @param ids 编号 + */ + void deleteDemo03CourseByIds(List ids); + + /** + * 获得学生课程 + * + * @param id 编号 * @return 学生课程 - */ + */ Demo03CourseDO getDemo03Course(Long id); // ==================== 子表(学生班级) ==================== - /** - * 获得学生班级 - * - * @param studentId 学生编号 - * @return 学生班级 - */ - Demo03GradeDO getDemo03GradeByStudentId(Long studentId); - /** * 获得学生班级分页 * @@ -148,11 +143,18 @@ public interface Demo03StudentService { void deleteDemo03Grade(Long id); /** - * 获得学生班级 - * - * @param id 编号 + * 批量删除学生班级 + * + * @param ids 编号 + */ + void deleteDemo03GradeByIds(List ids); + + /** + * 获得学生班级 + * + * @param id 编号 * @return 学生班级 - */ + */ Demo03GradeDO getDemo03Grade(Long id); } \ No newline at end of file diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/Demo03StudentServiceImpl.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/erp/Demo03StudentServiceImpl.java similarity index 67% rename from yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/Demo03StudentServiceImpl.java rename to yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/erp/Demo03StudentServiceImpl.java index 21f49490b6..a5f5eebab1 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/Demo03StudentServiceImpl.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/erp/Demo03StudentServiceImpl.java @@ -1,21 +1,22 @@ -package cn.iocoder.yudao.module.infra.service.demo.demo03; +package cn.iocoder.yudao.module.infra.service.demo.demo03.erp; +import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentPageReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentSaveReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentPageReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentSaveReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; -import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.Demo03CourseMapper; -import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.Demo03GradeMapper; -import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.Demo03StudentMapper; +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp.Demo03CourseMapper; +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp.Demo03GradeMapper; +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp.Demo03StudentMapper; +import jakarta.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; -import jakarta.annotation.Resource; import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -38,31 +39,21 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { private Demo03GradeMapper demo03GradeMapper; @Override - @Transactional(rollbackFor = Exception.class) public Long createDemo03Student(Demo03StudentSaveReqVO createReqVO) { // 插入 Demo03StudentDO demo03Student = BeanUtils.toBean(createReqVO, Demo03StudentDO.class); demo03StudentMapper.insert(demo03Student); - - // 插入子表 - createDemo03CourseList(demo03Student.getId(), createReqVO.getDemo03Courses()); - createDemo03Grade(demo03Student.getId(), createReqVO.getDemo03Grade()); // 返回 return demo03Student.getId(); } @Override - @Transactional(rollbackFor = Exception.class) public void updateDemo03Student(Demo03StudentSaveReqVO updateReqVO) { // 校验存在 validateDemo03StudentExists(updateReqVO.getId()); // 更新 Demo03StudentDO updateObj = BeanUtils.toBean(updateReqVO, Demo03StudentDO.class); demo03StudentMapper.updateById(updateObj); - - // 更新子表 - updateDemo03CourseList(updateReqVO.getId(), updateReqVO.getDemo03Courses()); - updateDemo03Grade(updateReqVO.getId(), updateReqVO.getDemo03Grade()); } @Override @@ -78,6 +69,26 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { deleteDemo03GradeByStudentId(id); } + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteDemo03StudentByIds(List ids) { + // 校验存在 + validateDemo03StudentExists(ids); + // 删除 + demo03StudentMapper.deleteByIds(ids); + + // 删除子表 + deleteDemo03CourseByStudentIds(ids); + deleteDemo03GradeByStudentIds(ids); + } + + private void validateDemo03StudentExists(List ids) { + List list = demo03StudentMapper.selectByIds(ids); + if (CollUtil.isEmpty(list) || list.size() != ids.size()) { + throw exception(DEMO03_STUDENT_NOT_EXISTS); + } + } + private void validateDemo03StudentExists(Long id) { if (demo03StudentMapper.selectById(id) == null) { throw exception(DEMO03_STUDENT_NOT_EXISTS); @@ -96,28 +107,6 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { // ==================== 子表(学生课程) ==================== - @Override - public List getDemo03CourseListByStudentId(Long studentId) { - return demo03CourseMapper.selectListByStudentId(studentId); - } - - private void createDemo03CourseList(Long studentId, List list) { - if (list != null) { - list.forEach(o -> o.setStudentId(studentId)); - } - demo03CourseMapper.insertBatch(list); - } - - private void updateDemo03CourseList(Long studentId, List list) { - deleteDemo03CourseByStudentId(studentId); - list.forEach(o -> o.setId(null).setUpdater(null).setUpdateTime(null)); // 解决更新情况下:1)id 冲突;2)updateTime 不更新 - createDemo03CourseList(studentId, list); - } - - private void deleteDemo03CourseByStudentId(Long studentId) { - demo03CourseMapper.deleteByStudentId(studentId); - } - @Override public PageResult getDemo03CoursePage(PageParam pageReqVO, Long studentId) { return demo03CourseMapper.selectPage(pageReqVO, studentId); @@ -131,47 +120,57 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { @Override public void updateDemo03Course(Demo03CourseDO demo03Course) { + // 校验存在 + validateDemo03CourseExists(demo03Course.getId()); + // 更新 + demo03Course.setUpdater(null).setUpdateTime(null); // 解决更新情况下:updateTime 不更新 demo03CourseMapper.updateById(demo03Course); } @Override public void deleteDemo03Course(Long id) { + // 校验存在 + validateDemo03CourseExists(id); + // 删除 demo03CourseMapper.deleteById(id); } + @Override + public void deleteDemo03CourseByIds(List ids) { + // 校验存在 + validateDemo03CourseExists(ids); + // 删除 + demo03CourseMapper.deleteByIds(ids); + } + @Override public Demo03CourseDO getDemo03Course(Long id) { return demo03CourseMapper.selectById(id); } + private void validateDemo03CourseExists(Long id) { + if (demo03CourseMapper.selectById(id) == null) { + throw exception(DEMO03_COURSE_NOT_EXISTS); + } + } + + private void validateDemo03CourseExists(List ids) { + List list = demo03CourseMapper.selectByIds(ids); + if (CollUtil.isEmpty(list) || list.size() != ids.size()) { + throw exception(DEMO03_COURSE_NOT_EXISTS); + } + } + + private void deleteDemo03CourseByStudentId(Long studentId) { + demo03CourseMapper.deleteByStudentId(studentId); + } + + private void deleteDemo03CourseByStudentIds(List studentIds) { + demo03CourseMapper.deleteByStudentIds(studentIds); + } + // ==================== 子表(学生班级) ==================== - @Override - public Demo03GradeDO getDemo03GradeByStudentId(Long studentId) { - return demo03GradeMapper.selectByStudentId(studentId); - } - - private void createDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) { - if (demo03Grade == null) { - return; - } - demo03Grade.setStudentId(studentId); - demo03GradeMapper.insert(demo03Grade); - } - - private void updateDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) { - if (demo03Grade == null) { - return; - } - demo03Grade.setStudentId(studentId); - demo03Grade.setUpdater(null).setUpdateTime(null); // 解决更新情况下:updateTime 不更新 - demo03GradeMapper.insertOrUpdate(demo03Grade); - } - - private void deleteDemo03GradeByStudentId(Long studentId) { - demo03GradeMapper.deleteByStudentId(studentId); - } - @Override public PageResult getDemo03GradePage(PageParam pageReqVO, Long studentId) { return demo03GradeMapper.selectPage(pageReqVO, studentId); @@ -183,6 +182,7 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { if (demo03GradeMapper.selectByStudentId(demo03Grade.getStudentId()) != null) { throw exception(DEMO03_GRADE_EXISTS); } + // 插入 demo03GradeMapper.insert(demo03Grade); return demo03Grade.getId(); } @@ -192,6 +192,7 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { // 校验存在 validateDemo03GradeExists(demo03Grade.getId()); // 更新 + demo03Grade.setUpdater(null).setUpdateTime(null); // 解决更新情况下:updateTime 不更新 demo03GradeMapper.updateById(demo03Grade); } @@ -203,6 +204,14 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { demo03GradeMapper.deleteById(id); } + @Override + public void deleteDemo03GradeByIds(List ids) { + // 校验存在 + validateDemo03GradeExists(ids); + // 删除 + demo03GradeMapper.deleteByIds(ids); + } + @Override public Demo03GradeDO getDemo03Grade(Long id) { return demo03GradeMapper.selectById(id); @@ -214,4 +223,19 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { } } + private void validateDemo03GradeExists(List ids) { + List list = demo03GradeMapper.selectByIds(ids); + if (CollUtil.isEmpty(list) || list.size() != ids.size()) { + throw exception(DEMO03_GRADE_NOT_EXISTS); + } + } + + private void deleteDemo03GradeByStudentId(Long studentId) { + demo03GradeMapper.deleteByStudentId(studentId); + } + + private void deleteDemo03GradeByStudentIds(List studentIds) { + demo03GradeMapper.deleteByStudentIds(studentIds); + } + } \ No newline at end of file diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/package-info.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/package-info.java new file mode 100644 index 0000000000..669c101d11 --- /dev/null +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/package-info.java @@ -0,0 +1 @@ +package cn.iocoder.yudao.module.infra.service.demo.demo03; \ No newline at end of file diff --git a/yudao-module-infra/src/main/resources/codegen/java/controller/controller.vm b/yudao-module-infra/src/main/resources/codegen/java/controller/controller.vm index 0d607ced55..36d860f7e9 100644 --- a/yudao-module-infra/src/main/resources/codegen/java/controller/controller.vm +++ b/yudao-module-infra/src/main/resources/codegen/java/controller/controller.vm @@ -81,7 +81,7 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { #if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')") #end - public CommonResult delete${simpleClassName}(@RequestParam("ids") @Size(max = 100, message = "最多允许100个") List<${primaryColumn.javaType}> ids) { + public CommonResult delete${simpleClassName}(@RequestParam("ids") List<${primaryColumn.javaType}> ids) { ${classNameVar}Service.delete${simpleClassName}ByIds(ids); return success(true); } @@ -231,6 +231,19 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { return success(true); } +#if ($table.deleteBatch) + @DeleteMapping("/${subSimpleClassName_strikeCase}/delete-batch") + @Parameter(name = "ids", description = "编号", required = true) + @Operation(summary = "批量删除${subTable.classComment}") +#if ($sceneEnum.scene == 1) + @PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')") +#end + public CommonResult delete${subSimpleClassName}(@RequestParam("ids") List<${subPrimaryColumn.javaType}> ids) { + ${classNameVar}Service.delete${subSimpleClassName}ByIds(ids); + return success(true); + } +#end + @GetMapping("/${subSimpleClassName_strikeCase}/get") @Operation(summary = "获得${subTable.classComment}") @Parameter(name = "id", description = "编号", required = true) diff --git a/yudao-module-infra/src/main/resources/codegen/java/service/service.vm b/yudao-module-infra/src/main/resources/codegen/java/service/service.vm index f99817c6ce..6770138c20 100644 --- a/yudao-module-infra/src/main/resources/codegen/java/service/service.vm +++ b/yudao-module-infra/src/main/resources/codegen/java/service/service.vm @@ -143,6 +143,15 @@ public interface ${table.className}Service { */ void delete${subSimpleClassName}(${subPrimaryColumn.javaType} id); +#if ($table.deleteBatch) + /** + * 批量删除${subTable.classComment} + * + * @param ids 编号 + */ + void delete${subSimpleClassName}ByIds(List<${subPrimaryColumn.javaType}> ids); +#end + /** * 获得${subTable.classComment} * diff --git a/yudao-module-infra/src/main/resources/codegen/java/service/serviceImpl.vm b/yudao-module-infra/src/main/resources/codegen/java/service/serviceImpl.vm index 1680398909..347049ecaf 100644 --- a/yudao-module-infra/src/main/resources/codegen/java/service/serviceImpl.vm +++ b/yudao-module-infra/src/main/resources/codegen/java/service/serviceImpl.vm @@ -332,6 +332,16 @@ public class ${table.className}ServiceImpl implements ${table.className}Service ${subClassNameVars.get($index)}Mapper.deleteById(id); } +#if ($table.deleteBatch) + @Override + public void delete${subSimpleClassName}ByIds(List<${subPrimaryColumn.javaType}> ids) { + // 校验存在 + validate${subSimpleClassName}Exists(ids); + // 删除 + ${subClassNameVars.get($index)}Mapper.deleteByIds(ids); + } +#end + @Override public ${subTable.className}DO get${subSimpleClassName}(${subPrimaryColumn.javaType} id) { return ${subClassNameVars.get($index)}Mapper.selectById(id); @@ -343,6 +353,15 @@ public class ${table.className}ServiceImpl implements ${table.className}Service } } +#if ($table.deleteBatch) + private void validate${subSimpleClassName}Exists(List<${subPrimaryColumn.javaType}> ids) { + List<${subTable.className}DO> list = ${subClassNameVar}Mapper.selectByIds(ids); + if (CollUtil.isEmpty(list) || list.size() != ids.size()) { + throw exception(${simpleClassNameUnderlineCase.toUpperCase()}_NOT_EXISTS); + } + } +#end + ## 情况二:非 MASTER_ERP 时,支持批量的新增、修改操作 #else #if ( $subTable.subJoinMany) diff --git a/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/api/api.ts.vm b/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/api/api.ts.vm index 6b071bed07..330a18ae18 100644 --- a/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/api/api.ts.vm +++ b/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/api/api.ts.vm @@ -151,6 +151,13 @@ export function delete${subSimpleClassName}(id: number) { return requestClient.delete(`${baseURL}/${subSimpleClassName_strikeCase}/delete?id=${id}`); } +#if ($table.deleteBatch) +// 批量删除${subTable.classComment} +export function delete${subSimpleClassName}ByIds(ids: number[]) { + return requestClient.delete(`${baseURL}/${subSimpleClassName_strikeCase}/delete-batch?ids=${ids.join(',')}`) +} +#end + /** 获得${subTable.classComment} */ export function get${subSimpleClassName}(id: number) { return requestClient.get<${simpleClassName}Api.${subSimpleClassName}>(`${baseURL}/${subSimpleClassName_strikeCase}/get?id=${id}`); diff --git a/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/data.ts.vm b/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/data.ts.vm index 7daa12423f..28039ea3b3 100644 --- a/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/data.ts.vm +++ b/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/data.ts.vm @@ -431,6 +431,9 @@ export function use${subSimpleClassName}GridColumns( onActionClick?: OnActionClickFn<${simpleClassName}Api.${subSimpleClassName}>, ): VxeTableGridOptions<${simpleClassName}Api.${subSimpleClassName}>['columns'] { return [ + #if ($table.templateType != 2 && $table.deleteBatch) + { type: 'checkbox', width: 40 }, + #end #foreach($column in $subColumns) #if ($column.listOperationResult) #set ($dictType = $column.dictType) diff --git a/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/index.vue.vm b/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/index.vue.vm index e1d79bc972..c9746e48f8 100644 --- a/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/index.vue.vm +++ b/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/index.vue.vm @@ -22,7 +22,7 @@ import { useVbenVxeGrid } from '#/adapter/vxe-table'; #if (${table.templateType} == 2)## 树表接口 import { get${simpleClassName}List, delete${simpleClassName}, export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}'; #else## 标准表接口 -import { get${simpleClassName}Page, delete${simpleClassName},delete${simpleClassName}ByIds, export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}'; +import { get${simpleClassName}Page, delete${simpleClassName},#if ($table.deleteBatch) delete${simpleClassName}ByIds,#end export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}'; #end import { downloadFileFromBlobPart, isEmpty } from '@vben/utils'; diff --git a/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/modules/list_sub_erp.vue.vm b/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/modules/list_sub_erp.vue.vm index 6246ff1b8f..d04f1aebf3 100644 --- a/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/modules/list_sub_erp.vue.vm +++ b/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/modules/list_sub_erp.vue.vm @@ -14,15 +14,16 @@ #end import { useVbenModal } from '@vben/common-ui'; import { Button, message } from 'ant-design-vue'; - import { Plus } from '@vben/icons'; - import { #if($table.templateType != 11)ref,#end h, nextTick,watch } from 'vue'; + import { Plus, Trash2 } from '@vben/icons'; + import { ref, computed, h, nextTick,watch } from 'vue'; import { $t } from '#/locales'; import { useVbenVxeGrid } from '#/adapter/vxe-table'; #if ($table.templateType == 11) ## erp - import { delete${subSimpleClassName}, get${subSimpleClassName}Page } from '#/api/${table.moduleName}/${table.businessName}'; + import { delete${subSimpleClassName},#if ($table.deleteBatch) delete${subSimpleClassName}ByIds,#end get${subSimpleClassName}Page } from '#/api/${table.moduleName}/${table.businessName}'; import { use${subSimpleClassName}GridFormSchema, use${subSimpleClassName}GridColumns } from '../data'; + import { isEmpty } from '@vben/utils'; #else #if ($subTable.subJoinMany) ## 一对多 import { get${subSimpleClassName}ListBy${SubJoinColumnName} } from '#/api/${table.moduleName}/${table.businessName}'; @@ -67,11 +68,31 @@ async function onDelete(row: ${simpleClassName}Api.${subSimpleClassName}) { await delete${subSimpleClassName}(row.id as number); message.success( $t('ui.actionMessage.deleteSuccess', [row.id]) ); onRefresh(); - } catch { + } finally { hideLoading(); } } +#if ($table.deleteBatch) +const deleteIds = ref([]) // 待删除${subTable.classComment} ID +const showDeleteBatchBtn = computed(() => isEmpty(deleteIds.value)); +/** 批量删除${subTable.classComment} */ +async function onDeleteBatch() { + const hideLoading = message.loading({ + content: $t('ui.actionMessage.deleting'), + duration: 0, + key: 'action_process_msg', + }); + try { + await delete${subSimpleClassName}ByIds(deleteIds.value); + message.success( $t('ui.actionMessage.deleteSuccess') ); + onRefresh(); + } finally { + hideLoading(); + } +} +#end + /** 表格操作按钮的回调函数 */ function onActionClick({ code, @@ -136,6 +157,16 @@ function onActionClick({ isHover: true, }, } as VxeTableGridOptions<${simpleClassName}Api.${subSimpleClassName}>, + #if (${table.templateType} == 11 && $table.deleteBatch) + gridEvents:{ + checkboxAll: ({records,}: { records: ${simpleClassName}Api.${subSimpleClassName}[];}) => { + deleteIds.value = records.map((item) => item.id); + }, + checkboxChange: ({records,}: { records: ${simpleClassName}Api.${subSimpleClassName}[];}) => { + deleteIds.value = records.map((item) => item.id); + }, + } + #end }); /** 刷新表格 */ @@ -173,6 +204,19 @@ const onRefresh = async ()=> { + #if ($table.templateType == 11 && $table.deleteBatch) + + #end #else From e10425e049daac247b77b4fc4b193d14298c9e11 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 19 May 2025 17:58:57 +0800 Subject: [PATCH 05/10] =?UTF-8?q?perf:=E3=80=90INFRA=20=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E8=AE=BE=E6=96=BD=E3=80=91vben5-antd-schema=20=E4=B8=BB?= =?UTF-8?q?=E4=B8=BB=E5=AD=90=E8=A1=A8normal=E4=BB=A3=E7=A0=81=E7=94=9F?= =?UTF-8?q?=E6=88=90=E6=97=B6=EF=BC=8C=E5=8F=AF=E7=94=9F=E6=88=90=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/demo01/Demo01ContactController.java | 3 +- ...r.java => Demo03StudentErpController.java} | 68 +++---- ...VO.java => Demo03StudentErpPageReqVO.java} | 2 +- ...espVO.java => Demo03StudentErpRespVO.java} | 2 +- ...VO.java => Demo03StudentErpSaveReqVO.java} | 2 +- .../normal/Demo03StudentNormalController.java | 125 +++++++++++++ .../vo/Demo03StudentNormalPageReqVO.java | 30 +++ .../normal/vo/Demo03StudentNormalRespVO.java | 41 ++++ .../vo/Demo03StudentNormalSaveReqVO.java | 41 ++++ ...Mapper.java => Demo03CourseErpMapper.java} | 2 +- ...eMapper.java => Demo03GradeErpMapper.java} | 2 +- ...apper.java => Demo03StudentErpMapper.java} | 4 +- .../normal/Demo03CourseNormalMapper.java | 29 +++ .../normal/Demo03GradeNormalMapper.java | 29 +++ .../normal/Demo03StudentNormalMapper.java | 27 +++ ...vice.java => Demo03StudentErpService.java} | 8 +- ....java => Demo03StudentErpServiceImpl.java} | 82 ++++---- .../normal/Demo03StudentNormalService.java | 83 +++++++++ .../Demo03StudentNormalServiceImpl.java | 175 ++++++++++++++++++ .../vue3_vben5_antd/schema/views/index.vue.vm | 15 +- .../schema/views/modules/list_sub_erp.vue.vm | 15 +- 21 files changed, 685 insertions(+), 100 deletions(-) rename yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/{Demo03StudentController.java => Demo03StudentErpController.java} (78%) rename yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/{Demo03StudentPageReqVO.java => Demo03StudentErpPageReqVO.java} (93%) rename yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/{Demo03StudentRespVO.java => Demo03StudentErpRespVO.java} (97%) rename yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/{Demo03StudentSaveReqVO.java => Demo03StudentErpSaveReqVO.java} (96%) create mode 100644 yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/normal/Demo03StudentNormalController.java create mode 100644 yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/normal/vo/Demo03StudentNormalPageReqVO.java create mode 100644 yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/normal/vo/Demo03StudentNormalRespVO.java create mode 100644 yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/normal/vo/Demo03StudentNormalSaveReqVO.java rename yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/{Demo03CourseMapper.java => Demo03CourseErpMapper.java} (93%) rename yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/{Demo03GradeMapper.java => Demo03GradeErpMapper.java} (94%) rename yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/{Demo03StudentMapper.java => Demo03StudentErpMapper.java} (91%) create mode 100644 yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/normal/Demo03CourseNormalMapper.java create mode 100644 yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/normal/Demo03GradeNormalMapper.java create mode 100644 yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/normal/Demo03StudentNormalMapper.java rename yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/erp/{Demo03StudentService.java => Demo03StudentErpService.java} (93%) rename yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/erp/{Demo03StudentServiceImpl.java => Demo03StudentErpServiceImpl.java} (72%) create mode 100644 yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/normal/Demo03StudentNormalService.java create mode 100644 yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/normal/Demo03StudentNormalServiceImpl.java diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo01/Demo01ContactController.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo01/Demo01ContactController.java index c3c518db9c..8574aef785 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo01/Demo01ContactController.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo01/Demo01ContactController.java @@ -17,7 +17,6 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.Valid; -import jakarta.validation.constraints.Size; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -65,7 +64,7 @@ public class Demo01ContactController { @Parameter(name = "ids", description = "编号", required = true) @Operation(summary = "批量删除示例联系人") @PreAuthorize("@ss.hasPermission('infra:demo01-contact:delete')") - public CommonResult deleteDemo01Contact(@RequestParam("ids") @Size(max = 100, message = "最多允许100个") List ids) { + public CommonResult deleteDemo01Contact(@RequestParam("ids") List ids) { demo01ContactService.deleteDemo01ContactByIds(ids); return success(true); } diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/Demo03StudentController.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/Demo03StudentErpController.java similarity index 78% rename from yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/Demo03StudentController.java rename to yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/Demo03StudentErpController.java index 09c0c20b78..361e7f5364 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/Demo03StudentController.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/Demo03StudentErpController.java @@ -6,13 +6,13 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; -import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentPageReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentRespVO; -import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentSaveReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpPageReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpRespVO; +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpSaveReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; -import cn.iocoder.yudao.module.infra.service.demo.demo03.erp.Demo03StudentService; +import cn.iocoder.yudao.module.infra.service.demo.demo03.erp.Demo03StudentErpService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -33,23 +33,23 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @RestController @RequestMapping("/infra/demo03-student-erp") @Validated -public class Demo03StudentController { +public class Demo03StudentErpController { @Resource - private Demo03StudentService demo03StudentService; + private Demo03StudentErpService demo03StudentErpService; @PostMapping("/create") @Operation(summary = "创建学生") @PreAuthorize("@ss.hasPermission('infra:demo03-student:create')") - public CommonResult createDemo03Student(@Valid @RequestBody Demo03StudentSaveReqVO createReqVO) { - return success(demo03StudentService.createDemo03Student(createReqVO)); + public CommonResult createDemo03Student(@Valid @RequestBody Demo03StudentErpSaveReqVO createReqVO) { + return success(demo03StudentErpService.createDemo03Student(createReqVO)); } @PutMapping("/update") @Operation(summary = "更新学生") @PreAuthorize("@ss.hasPermission('infra:demo03-student:update')") - public CommonResult updateDemo03Student(@Valid @RequestBody Demo03StudentSaveReqVO updateReqVO) { - demo03StudentService.updateDemo03Student(updateReqVO); + public CommonResult updateDemo03Student(@Valid @RequestBody Demo03StudentErpSaveReqVO updateReqVO) { + demo03StudentErpService.updateDemo03Student(updateReqVO); return success(true); } @@ -58,7 +58,7 @@ public class Demo03StudentController { @Parameter(name = "id", description = "编号", required = true) @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") public CommonResult deleteDemo03Student(@RequestParam("id") Long id) { - demo03StudentService.deleteDemo03Student(id); + demo03StudentErpService.deleteDemo03Student(id); return success(true); } @@ -67,7 +67,7 @@ public class Demo03StudentController { @Operation(summary = "批量删除学生") @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") public CommonResult deleteDemo03Student(@RequestParam("ids") List ids) { - demo03StudentService.deleteDemo03StudentByIds(ids); + demo03StudentErpService.deleteDemo03StudentByIds(ids); return success(true); } @@ -75,30 +75,30 @@ public class Demo03StudentController { @Operation(summary = "获得学生") @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") - public CommonResult getDemo03Student(@RequestParam("id") Long id) { - Demo03StudentDO demo03Student = demo03StudentService.getDemo03Student(id); - return success(BeanUtils.toBean(demo03Student, Demo03StudentRespVO.class)); + public CommonResult getDemo03Student(@RequestParam("id") Long id) { + Demo03StudentDO demo03Student = demo03StudentErpService.getDemo03Student(id); + return success(BeanUtils.toBean(demo03Student, Demo03StudentErpRespVO.class)); } @GetMapping("/page") @Operation(summary = "获得学生分页") @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") - public CommonResult> getDemo03StudentPage(@Valid Demo03StudentPageReqVO pageReqVO) { - PageResult pageResult = demo03StudentService.getDemo03StudentPage(pageReqVO); - return success(BeanUtils.toBean(pageResult, Demo03StudentRespVO.class)); + public CommonResult> getDemo03StudentPage(@Valid Demo03StudentErpPageReqVO pageReqVO) { + PageResult pageResult = demo03StudentErpService.getDemo03StudentPage(pageReqVO); + return success(BeanUtils.toBean(pageResult, Demo03StudentErpRespVO.class)); } @GetMapping("/export-excel") @Operation(summary = "导出学生 Excel") @PreAuthorize("@ss.hasPermission('infra:demo03-student:export')") @ApiAccessLog(operateType = EXPORT) - public void exportDemo03StudentExcel(@Valid Demo03StudentPageReqVO pageReqVO, + public void exportDemo03StudentExcel(@Valid Demo03StudentErpPageReqVO pageReqVO, HttpServletResponse response) throws IOException { pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); - List list = demo03StudentService.getDemo03StudentPage(pageReqVO).getList(); + List list = demo03StudentErpService.getDemo03StudentPage(pageReqVO).getList(); // 导出 Excel - ExcelUtils.write(response, "学生.xls", "数据", Demo03StudentRespVO.class, - BeanUtils.toBean(list, Demo03StudentRespVO.class)); + ExcelUtils.write(response, "学生.xls", "数据", Demo03StudentErpRespVO.class, + BeanUtils.toBean(list, Demo03StudentErpRespVO.class)); } // ==================== 子表(学生课程) ==================== @@ -109,21 +109,21 @@ public class Demo03StudentController { @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") public CommonResult> getDemo03CoursePage(PageParam pageReqVO, @RequestParam("studentId") Long studentId) { - return success(demo03StudentService.getDemo03CoursePage(pageReqVO, studentId)); + return success(demo03StudentErpService.getDemo03CoursePage(pageReqVO, studentId)); } @PostMapping("/demo03-course/create") @Operation(summary = "创建学生课程") @PreAuthorize("@ss.hasPermission('infra:demo03-student:create')") public CommonResult createDemo03Course(@Valid @RequestBody Demo03CourseDO demo03Course) { - return success(demo03StudentService.createDemo03Course(demo03Course)); + return success(demo03StudentErpService.createDemo03Course(demo03Course)); } @PutMapping("/demo03-course/update") @Operation(summary = "更新学生课程") @PreAuthorize("@ss.hasPermission('infra:demo03-student:update')") public CommonResult updateDemo03Course(@Valid @RequestBody Demo03CourseDO demo03Course) { - demo03StudentService.updateDemo03Course(demo03Course); + demo03StudentErpService.updateDemo03Course(demo03Course); return success(true); } @@ -132,7 +132,7 @@ public class Demo03StudentController { @Operation(summary = "删除学生课程") @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") public CommonResult deleteDemo03Course(@RequestParam("id") Long id) { - demo03StudentService.deleteDemo03Course(id); + demo03StudentErpService.deleteDemo03Course(id); return success(true); } @@ -141,7 +141,7 @@ public class Demo03StudentController { @Operation(summary = "批量删除学生课程") @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") public CommonResult deleteDemo03Course(@RequestParam("ids") List ids) { - demo03StudentService.deleteDemo03CourseByIds(ids); + demo03StudentErpService.deleteDemo03CourseByIds(ids); return success(true); } @@ -150,7 +150,7 @@ public class Demo03StudentController { @Parameter(name = "id", description = "编号", required = true) @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") public CommonResult getDemo03Course(@RequestParam("id") Long id) { - return success(demo03StudentService.getDemo03Course(id)); + return success(demo03StudentErpService.getDemo03Course(id)); } // ==================== 子表(学生班级) ==================== @@ -161,21 +161,21 @@ public class Demo03StudentController { @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") public CommonResult> getDemo03GradePage(PageParam pageReqVO, @RequestParam("studentId") Long studentId) { - return success(demo03StudentService.getDemo03GradePage(pageReqVO, studentId)); + return success(demo03StudentErpService.getDemo03GradePage(pageReqVO, studentId)); } @PostMapping("/demo03-grade/create") @Operation(summary = "创建学生班级") @PreAuthorize("@ss.hasPermission('infra:demo03-student:create')") public CommonResult createDemo03Grade(@Valid @RequestBody Demo03GradeDO demo03Grade) { - return success(demo03StudentService.createDemo03Grade(demo03Grade)); + return success(demo03StudentErpService.createDemo03Grade(demo03Grade)); } @PutMapping("/demo03-grade/update") @Operation(summary = "更新学生班级") @PreAuthorize("@ss.hasPermission('infra:demo03-student:update')") public CommonResult updateDemo03Grade(@Valid @RequestBody Demo03GradeDO demo03Grade) { - demo03StudentService.updateDemo03Grade(demo03Grade); + demo03StudentErpService.updateDemo03Grade(demo03Grade); return success(true); } @@ -184,7 +184,7 @@ public class Demo03StudentController { @Operation(summary = "删除学生班级") @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") public CommonResult deleteDemo03Grade(@RequestParam("id") Long id) { - demo03StudentService.deleteDemo03Grade(id); + demo03StudentErpService.deleteDemo03Grade(id); return success(true); } @@ -193,7 +193,7 @@ public class Demo03StudentController { @Operation(summary = "批量删除学生班级") @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") public CommonResult deleteDemo03Grade(@RequestParam("ids") List ids) { - demo03StudentService.deleteDemo03GradeByIds(ids); + demo03StudentErpService.deleteDemo03GradeByIds(ids); return success(true); } @@ -202,7 +202,7 @@ public class Demo03StudentController { @Parameter(name = "id", description = "编号", required = true) @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") public CommonResult getDemo03Grade(@RequestParam("id") Long id) { - return success(demo03StudentService.getDemo03Grade(id)); + return success(demo03StudentErpService.getDemo03Grade(id)); } } \ No newline at end of file diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentPageReqVO.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentErpPageReqVO.java similarity index 93% rename from yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentPageReqVO.java rename to yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentErpPageReqVO.java index 2845b324b8..3fb8dea979 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentPageReqVO.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentErpPageReqVO.java @@ -12,7 +12,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class Demo03StudentPageReqVO extends PageParam { +public class Demo03StudentErpPageReqVO extends PageParam { @Schema(description = "名字", example = "芋艿") private String name; diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentRespVO.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentErpRespVO.java similarity index 97% rename from yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentRespVO.java rename to yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentErpRespVO.java index 8f60e3c660..ed7cfca7ff 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentRespVO.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentErpRespVO.java @@ -11,7 +11,7 @@ import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; @Schema(description = "管理后台 - 学生 Response VO") @Data @ExcelIgnoreUnannotated -public class Demo03StudentRespVO { +public class Demo03StudentErpRespVO { @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525") @ExcelProperty("编号") diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentSaveReqVO.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentErpSaveReqVO.java similarity index 96% rename from yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentSaveReqVO.java rename to yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentErpSaveReqVO.java index 5bd8125e01..46c2504a4c 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentSaveReqVO.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentErpSaveReqVO.java @@ -8,7 +8,7 @@ import java.time.LocalDateTime; @Schema(description = "管理后台 - 学生新增/修改 Request VO") @Data -public class Demo03StudentSaveReqVO { +public class Demo03StudentErpSaveReqVO { @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525") private Long id; diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/normal/Demo03StudentNormalController.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/normal/Demo03StudentNormalController.java new file mode 100644 index 0000000000..58d11cf615 --- /dev/null +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/normal/Demo03StudentNormalController.java @@ -0,0 +1,125 @@ +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal; + +import org.springframework.web.bind.annotation.*; +import jakarta.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.security.access.prepost.PreAuthorize; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Operation; + +import jakarta.validation.*; +import jakarta.servlet.http.*; +import java.util.*; +import java.io.IOException; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; + +import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; +import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*; + +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.*; +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; +import cn.iocoder.yudao.module.infra.service.demo.demo03.normal.Demo03StudentNormalService; + +@Tag(name = "管理后台 - 学生") +@RestController +@RequestMapping("/infra/demo03-student-normal") +@Validated +public class Demo03StudentNormalController { + + @Resource + private Demo03StudentNormalService demo03StudentNormalService; + + @PostMapping("/create") + @Operation(summary = "创建学生") + @PreAuthorize("@ss.hasPermission('infra:demo03-student:create')") + public CommonResult createDemo03Student(@Valid @RequestBody Demo03StudentNormalSaveReqVO createReqVO) { + return success(demo03StudentNormalService.createDemo03Student(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新学生") + @PreAuthorize("@ss.hasPermission('infra:demo03-student:update')") + public CommonResult updateDemo03Student(@Valid @RequestBody Demo03StudentNormalSaveReqVO updateReqVO) { + demo03StudentNormalService.updateDemo03Student(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除学生") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") + public CommonResult deleteDemo03Student(@RequestParam("id") Long id) { + demo03StudentNormalService.deleteDemo03Student(id); + return success(true); + } + + @DeleteMapping("/delete-batch") + @Parameter(name = "ids", description = "编号", required = true) + @Operation(summary = "批量删除学生") + @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") + public CommonResult deleteDemo03Student(@RequestParam("ids") List ids) { + demo03StudentNormalService.deleteDemo03StudentByIds(ids); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得学生") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") + public CommonResult getDemo03Student(@RequestParam("id") Long id) { + Demo03StudentDO demo03Student = demo03StudentNormalService.getDemo03Student(id); + return success(BeanUtils.toBean(demo03Student, Demo03StudentNormalRespVO.class)); + } + + @GetMapping("/page") + @Operation(summary = "获得学生分页") + @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") + public CommonResult> getDemo03StudentPage(@Valid Demo03StudentNormalPageReqVO pageReqVO) { + PageResult pageResult = demo03StudentNormalService.getDemo03StudentPage(pageReqVO); + return success(BeanUtils.toBean(pageResult, Demo03StudentNormalRespVO.class)); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出学生 Excel") + @PreAuthorize("@ss.hasPermission('infra:demo03-student:export')") + @ApiAccessLog(operateType = EXPORT) + public void exportDemo03StudentExcel(@Valid Demo03StudentNormalPageReqVO pageReqVO, + HttpServletResponse response) throws IOException { + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = demo03StudentNormalService.getDemo03StudentPage(pageReqVO).getList(); + // 导出 Excel + ExcelUtils.write(response, "学生.xls", "数据", Demo03StudentNormalRespVO.class, + BeanUtils.toBean(list, Demo03StudentNormalRespVO.class)); + } + + // ==================== 子表(学生课程) ==================== + + @GetMapping("/demo03-course/list-by-student-id") + @Operation(summary = "获得学生课程列表") + @Parameter(name = "studentId", description = "学生编号") + @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") + public CommonResult> getDemo03CourseListByStudentId(@RequestParam("studentId") Long studentId) { + return success(demo03StudentNormalService.getDemo03CourseListByStudentId(studentId)); + } + + // ==================== 子表(学生班级) ==================== + + @GetMapping("/demo03-grade/get-by-student-id") + @Operation(summary = "获得学生班级") + @Parameter(name = "studentId", description = "学生编号") + @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") + public CommonResult getDemo03GradeByStudentId(@RequestParam("studentId") Long studentId) { + return success(demo03StudentNormalService.getDemo03GradeByStudentId(studentId)); + } + +} \ No newline at end of file diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/normal/vo/Demo03StudentNormalPageReqVO.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/normal/vo/Demo03StudentNormalPageReqVO.java new file mode 100644 index 0000000000..5511cb1ece --- /dev/null +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/normal/vo/Demo03StudentNormalPageReqVO.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo; + +import lombok.*; +import io.swagger.v3.oas.annotations.media.Schema; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +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 Demo03StudentNormalPageReqVO extends PageParam { + + @Schema(description = "名字", example = "芋艿") + private String name; + + @Schema(description = "性别") + private Integer sex; + + @Schema(description = "简介", example = "随便") + private String description; + + @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/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/normal/vo/Demo03StudentNormalRespVO.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/normal/vo/Demo03StudentNormalRespVO.java new file mode 100644 index 0000000000..84aa80031b --- /dev/null +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/normal/vo/Demo03StudentNormalRespVO.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; + +import java.time.LocalDateTime; +import com.alibaba.excel.annotation.*; +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; + +@Schema(description = "管理后台 - 学生 Response VO") +@Data +@ExcelIgnoreUnannotated +public class Demo03StudentNormalRespVO { + + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525") + @ExcelProperty("编号") + private Long id; + + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") + @ExcelProperty("名字") + private String name; + + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty(value = "性别", converter = DictConvert.class) + @DictFormat("system_user_sex") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 + private Integer sex; + + @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("出生日期") + private LocalDateTime birthday; + + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "随便") + @ExcelProperty("简介") + private String description; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") + private LocalDateTime createTime; + +} \ No newline at end of file diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/normal/vo/Demo03StudentNormalSaveReqVO.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/normal/vo/Demo03StudentNormalSaveReqVO.java new file mode 100644 index 0000000000..627e4db6bb --- /dev/null +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/normal/vo/Demo03StudentNormalSaveReqVO.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import jakarta.validation.constraints.*; + +import java.time.LocalDateTime; +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; + +@Schema(description = "管理后台 - 学生新增/修改 Request VO") +@Data +public class Demo03StudentNormalSaveReqVO { + + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525") + private Long id; + + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") + @NotEmpty(message = "名字不能为空") + private String name; + + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "性别不能为空") + private Integer sex; + + @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "出生日期不能为空") + private LocalDateTime birthday; + + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "随便") + @NotEmpty(message = "简介不能为空") + private String description; + + @Schema(description = "学生课程列表") + private List demo03Courses; + + @Schema(description = "学生班级") + private Demo03GradeDO demo03Grade; + +} \ No newline at end of file diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03CourseMapper.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03CourseErpMapper.java similarity index 93% rename from yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03CourseMapper.java rename to yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03CourseErpMapper.java index 891586a7da..b438a2fcb3 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03CourseMapper.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03CourseErpMapper.java @@ -15,7 +15,7 @@ import java.util.List; * @author 芋道源码 */ @Mapper -public interface Demo03CourseMapper extends BaseMapperX { +public interface Demo03CourseErpMapper extends BaseMapperX { default PageResult selectPage(PageParam reqVO, Long studentId) { return selectPage(reqVO, new LambdaQueryWrapperX() diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03GradeMapper.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03GradeErpMapper.java similarity index 94% rename from yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03GradeMapper.java rename to yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03GradeErpMapper.java index aec5474beb..6bdfcd1591 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03GradeMapper.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03GradeErpMapper.java @@ -15,7 +15,7 @@ import java.util.List; * @author 芋道源码 */ @Mapper -public interface Demo03GradeMapper extends BaseMapperX { +public interface Demo03GradeErpMapper extends BaseMapperX { default PageResult selectPage(PageParam reqVO, Long studentId) { return selectPage(reqVO, new LambdaQueryWrapperX() diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03StudentMapper.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03StudentErpMapper.java similarity index 91% rename from yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03StudentMapper.java rename to yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03StudentErpMapper.java index 7d7628baaf..ee600bd275 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03StudentMapper.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03StudentErpMapper.java @@ -13,9 +13,9 @@ import org.apache.ibatis.annotations.Mapper; * @author 芋道源码 */ @Mapper -public interface Demo03StudentMapper extends BaseMapperX { +public interface Demo03StudentErpMapper extends BaseMapperX { - default PageResult selectPage(Demo03StudentPageReqVO reqVO) { + default PageResult selectPage(Demo03StudentErpPageReqVO reqVO) { return selectPage(reqVO, new LambdaQueryWrapperX() .likeIfPresent(Demo03StudentDO::getName, reqVO.getName()) .eqIfPresent(Demo03StudentDO::getSex, reqVO.getSex()) diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/normal/Demo03CourseNormalMapper.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/normal/Demo03CourseNormalMapper.java new file mode 100644 index 0000000000..7617bb9a0b --- /dev/null +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/normal/Demo03CourseNormalMapper.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.normal; + +import java.util.*; + +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; +import org.apache.ibatis.annotations.Mapper; + +/** + * 学生课程 Mapper + * + * @author 芋道源码 + */ +@Mapper +public interface Demo03CourseNormalMapper extends BaseMapperX { + + default List selectListByStudentId(Long studentId) { + return selectList(Demo03CourseDO::getStudentId, studentId); + } + + default int deleteByStudentId(Long studentId) { + return delete(Demo03CourseDO::getStudentId, studentId); + } + + default int deleteByStudentIds(List studentIds) { + return delete(Demo03CourseDO::getStudentId, studentIds); + } + +} diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/normal/Demo03GradeNormalMapper.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/normal/Demo03GradeNormalMapper.java new file mode 100644 index 0000000000..c296c867fc --- /dev/null +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/normal/Demo03GradeNormalMapper.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.normal; + +import java.util.*; + +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; +import org.apache.ibatis.annotations.Mapper; + +/** + * 学生班级 Mapper + * + * @author 芋道源码 + */ +@Mapper +public interface Demo03GradeNormalMapper extends BaseMapperX { + + default Demo03GradeDO selectByStudentId(Long studentId) { + return selectOne(Demo03GradeDO::getStudentId, studentId); + } + + default int deleteByStudentId(Long studentId) { + return delete(Demo03GradeDO::getStudentId, studentId); + } + + default int deleteByStudentIds(List studentIds) { + return delete(Demo03GradeDO::getStudentId, studentIds); + } + +} diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/normal/Demo03StudentNormalMapper.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/normal/Demo03StudentNormalMapper.java new file mode 100644 index 0000000000..105812cb53 --- /dev/null +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/normal/Demo03StudentNormalMapper.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.normal; + +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.demo.demo03.Demo03StudentDO; +import org.apache.ibatis.annotations.Mapper; +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.*; + +/** + * 学生 Mapper + * + * @author 芋道源码 + */ +@Mapper +public interface Demo03StudentNormalMapper extends BaseMapperX { + + default PageResult selectPage(Demo03StudentNormalPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .likeIfPresent(Demo03StudentDO::getName, reqVO.getName()) + .eqIfPresent(Demo03StudentDO::getSex, reqVO.getSex()) + .eqIfPresent(Demo03StudentDO::getDescription, reqVO.getDescription()) + .betweenIfPresent(Demo03StudentDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(Demo03StudentDO::getId)); + } + +} \ No newline at end of file diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/erp/Demo03StudentService.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/erp/Demo03StudentErpService.java similarity index 93% rename from yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/erp/Demo03StudentService.java rename to yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/erp/Demo03StudentErpService.java index e4c97c68d9..a346116dc8 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/erp/Demo03StudentService.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/erp/Demo03StudentErpService.java @@ -14,7 +14,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam; * * @author 芋道源码 */ -public interface Demo03StudentService { +public interface Demo03StudentErpService { /** * 创建学生 @@ -22,14 +22,14 @@ public interface Demo03StudentService { * @param createReqVO 创建信息 * @return 编号 */ - Long createDemo03Student(@Valid Demo03StudentSaveReqVO createReqVO); + Long createDemo03Student(@Valid Demo03StudentErpSaveReqVO createReqVO); /** * 更新学生 * * @param updateReqVO 更新信息 */ - void updateDemo03Student(@Valid Demo03StudentSaveReqVO updateReqVO); + void updateDemo03Student(@Valid Demo03StudentErpSaveReqVO updateReqVO); /** * 删除学生 @@ -59,7 +59,7 @@ public interface Demo03StudentService { * @param pageReqVO 分页查询 * @return 学生分页 */ - PageResult getDemo03StudentPage(Demo03StudentPageReqVO pageReqVO); + PageResult getDemo03StudentPage(Demo03StudentErpPageReqVO pageReqVO); // ==================== 子表(学生课程) ==================== diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/erp/Demo03StudentServiceImpl.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/erp/Demo03StudentErpServiceImpl.java similarity index 72% rename from yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/erp/Demo03StudentServiceImpl.java rename to yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/erp/Demo03StudentErpServiceImpl.java index a5f5eebab1..2329f27ec9 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/erp/Demo03StudentServiceImpl.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/erp/Demo03StudentErpServiceImpl.java @@ -4,14 +4,14 @@ import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentPageReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentSaveReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpPageReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpSaveReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; -import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp.Demo03CourseMapper; -import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp.Demo03GradeMapper; -import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp.Demo03StudentMapper; +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp.Demo03CourseErpMapper; +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp.Demo03GradeErpMapper; +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp.Demo03StudentErpMapper; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -29,31 +29,31 @@ import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; */ @Service @Validated -public class Demo03StudentServiceImpl implements Demo03StudentService { +public class Demo03StudentErpServiceImpl implements Demo03StudentErpService { @Resource - private Demo03StudentMapper demo03StudentMapper; + private Demo03StudentErpMapper demo03StudentErpMapper; @Resource - private Demo03CourseMapper demo03CourseMapper; + private Demo03CourseErpMapper demo03CourseErpMapper; @Resource - private Demo03GradeMapper demo03GradeMapper; + private Demo03GradeErpMapper demo03GradeErpMapper; @Override - public Long createDemo03Student(Demo03StudentSaveReqVO createReqVO) { + public Long createDemo03Student(Demo03StudentErpSaveReqVO createReqVO) { // 插入 Demo03StudentDO demo03Student = BeanUtils.toBean(createReqVO, Demo03StudentDO.class); - demo03StudentMapper.insert(demo03Student); + demo03StudentErpMapper.insert(demo03Student); // 返回 return demo03Student.getId(); } @Override - public void updateDemo03Student(Demo03StudentSaveReqVO updateReqVO) { + public void updateDemo03Student(Demo03StudentErpSaveReqVO updateReqVO) { // 校验存在 validateDemo03StudentExists(updateReqVO.getId()); // 更新 Demo03StudentDO updateObj = BeanUtils.toBean(updateReqVO, Demo03StudentDO.class); - demo03StudentMapper.updateById(updateObj); + demo03StudentErpMapper.updateById(updateObj); } @Override @@ -62,7 +62,7 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { // 校验存在 validateDemo03StudentExists(id); // 删除 - demo03StudentMapper.deleteById(id); + demo03StudentErpMapper.deleteById(id); // 删除子表 deleteDemo03CourseByStudentId(id); @@ -75,7 +75,7 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { // 校验存在 validateDemo03StudentExists(ids); // 删除 - demo03StudentMapper.deleteByIds(ids); + demo03StudentErpMapper.deleteByIds(ids); // 删除子表 deleteDemo03CourseByStudentIds(ids); @@ -83,38 +83,38 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { } private void validateDemo03StudentExists(List ids) { - List list = demo03StudentMapper.selectByIds(ids); + List list = demo03StudentErpMapper.selectByIds(ids); if (CollUtil.isEmpty(list) || list.size() != ids.size()) { throw exception(DEMO03_STUDENT_NOT_EXISTS); } } private void validateDemo03StudentExists(Long id) { - if (demo03StudentMapper.selectById(id) == null) { + if (demo03StudentErpMapper.selectById(id) == null) { throw exception(DEMO03_STUDENT_NOT_EXISTS); } } @Override public Demo03StudentDO getDemo03Student(Long id) { - return demo03StudentMapper.selectById(id); + return demo03StudentErpMapper.selectById(id); } @Override - public PageResult getDemo03StudentPage(Demo03StudentPageReqVO pageReqVO) { - return demo03StudentMapper.selectPage(pageReqVO); + public PageResult getDemo03StudentPage(Demo03StudentErpPageReqVO pageReqVO) { + return demo03StudentErpMapper.selectPage(pageReqVO); } // ==================== 子表(学生课程) ==================== @Override public PageResult getDemo03CoursePage(PageParam pageReqVO, Long studentId) { - return demo03CourseMapper.selectPage(pageReqVO, studentId); + return demo03CourseErpMapper.selectPage(pageReqVO, studentId); } @Override public Long createDemo03Course(Demo03CourseDO demo03Course) { - demo03CourseMapper.insert(demo03Course); + demo03CourseErpMapper.insert(demo03Course); return demo03Course.getId(); } @@ -124,7 +124,7 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { validateDemo03CourseExists(demo03Course.getId()); // 更新 demo03Course.setUpdater(null).setUpdateTime(null); // 解决更新情况下:updateTime 不更新 - demo03CourseMapper.updateById(demo03Course); + demo03CourseErpMapper.updateById(demo03Course); } @Override @@ -132,7 +132,7 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { // 校验存在 validateDemo03CourseExists(id); // 删除 - demo03CourseMapper.deleteById(id); + demo03CourseErpMapper.deleteById(id); } @Override @@ -140,50 +140,50 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { // 校验存在 validateDemo03CourseExists(ids); // 删除 - demo03CourseMapper.deleteByIds(ids); + demo03CourseErpMapper.deleteByIds(ids); } @Override public Demo03CourseDO getDemo03Course(Long id) { - return demo03CourseMapper.selectById(id); + return demo03CourseErpMapper.selectById(id); } private void validateDemo03CourseExists(Long id) { - if (demo03CourseMapper.selectById(id) == null) { + if (demo03CourseErpMapper.selectById(id) == null) { throw exception(DEMO03_COURSE_NOT_EXISTS); } } private void validateDemo03CourseExists(List ids) { - List list = demo03CourseMapper.selectByIds(ids); + List list = demo03CourseErpMapper.selectByIds(ids); if (CollUtil.isEmpty(list) || list.size() != ids.size()) { throw exception(DEMO03_COURSE_NOT_EXISTS); } } private void deleteDemo03CourseByStudentId(Long studentId) { - demo03CourseMapper.deleteByStudentId(studentId); + demo03CourseErpMapper.deleteByStudentId(studentId); } private void deleteDemo03CourseByStudentIds(List studentIds) { - demo03CourseMapper.deleteByStudentIds(studentIds); + demo03CourseErpMapper.deleteByStudentIds(studentIds); } // ==================== 子表(学生班级) ==================== @Override public PageResult getDemo03GradePage(PageParam pageReqVO, Long studentId) { - return demo03GradeMapper.selectPage(pageReqVO, studentId); + return demo03GradeErpMapper.selectPage(pageReqVO, studentId); } @Override public Long createDemo03Grade(Demo03GradeDO demo03Grade) { // 校验是否已经存在 - if (demo03GradeMapper.selectByStudentId(demo03Grade.getStudentId()) != null) { + if (demo03GradeErpMapper.selectByStudentId(demo03Grade.getStudentId()) != null) { throw exception(DEMO03_GRADE_EXISTS); } // 插入 - demo03GradeMapper.insert(demo03Grade); + demo03GradeErpMapper.insert(demo03Grade); return demo03Grade.getId(); } @@ -193,7 +193,7 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { validateDemo03GradeExists(demo03Grade.getId()); // 更新 demo03Grade.setUpdater(null).setUpdateTime(null); // 解决更新情况下:updateTime 不更新 - demo03GradeMapper.updateById(demo03Grade); + demo03GradeErpMapper.updateById(demo03Grade); } @Override @@ -201,7 +201,7 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { // 校验存在 validateDemo03GradeExists(id); // 删除 - demo03GradeMapper.deleteById(id); + demo03GradeErpMapper.deleteById(id); } @Override @@ -209,33 +209,33 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { // 校验存在 validateDemo03GradeExists(ids); // 删除 - demo03GradeMapper.deleteByIds(ids); + demo03GradeErpMapper.deleteByIds(ids); } @Override public Demo03GradeDO getDemo03Grade(Long id) { - return demo03GradeMapper.selectById(id); + return demo03GradeErpMapper.selectById(id); } private void validateDemo03GradeExists(Long id) { - if (demo03GradeMapper.selectById(id) == null) { + if (demo03GradeErpMapper.selectById(id) == null) { throw exception(DEMO03_GRADE_NOT_EXISTS); } } private void validateDemo03GradeExists(List ids) { - List list = demo03GradeMapper.selectByIds(ids); + List list = demo03GradeErpMapper.selectByIds(ids); if (CollUtil.isEmpty(list) || list.size() != ids.size()) { throw exception(DEMO03_GRADE_NOT_EXISTS); } } private void deleteDemo03GradeByStudentId(Long studentId) { - demo03GradeMapper.deleteByStudentId(studentId); + demo03GradeErpMapper.deleteByStudentId(studentId); } private void deleteDemo03GradeByStudentIds(List studentIds) { - demo03GradeMapper.deleteByStudentIds(studentIds); + demo03GradeErpMapper.deleteByStudentIds(studentIds); } } \ No newline at end of file diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/normal/Demo03StudentNormalService.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/normal/Demo03StudentNormalService.java new file mode 100644 index 0000000000..c38b9ed6bc --- /dev/null +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/normal/Demo03StudentNormalService.java @@ -0,0 +1,83 @@ +package cn.iocoder.yudao.module.infra.service.demo.demo03.normal; + +import java.util.*; +import jakarta.validation.*; +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.*; +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +/** + * 学生 Service 接口 + * + * @author 芋道源码 + */ +public interface Demo03StudentNormalService { + + /** + * 创建学生 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createDemo03Student(@Valid Demo03StudentNormalSaveReqVO createReqVO); + + /** + * 更新学生 + * + * @param updateReqVO 更新信息 + */ + void updateDemo03Student(@Valid Demo03StudentNormalSaveReqVO updateReqVO); + + /** + * 删除学生 + * + * @param id 编号 + */ + void deleteDemo03Student(Long id); + + /** + * 批量删除学生 + * + * @param ids 编号 + */ + void deleteDemo03StudentByIds(List ids); + + /** + * 获得学生 + * + * @param id 编号 + * @return 学生 + */ + Demo03StudentDO getDemo03Student(Long id); + + /** + * 获得学生分页 + * + * @param pageReqVO 分页查询 + * @return 学生分页 + */ + PageResult getDemo03StudentPage(Demo03StudentNormalPageReqVO pageReqVO); + + // ==================== 子表(学生课程) ==================== + + /** + * 获得学生课程列表 + * + * @param studentId 学生编号 + * @return 学生课程列表 + */ + List getDemo03CourseListByStudentId(Long studentId); + + // ==================== 子表(学生班级) ==================== + + /** + * 获得学生班级 + * + * @param studentId 学生编号 + * @return 学生班级 + */ + Demo03GradeDO getDemo03GradeByStudentId(Long studentId); + +} \ No newline at end of file diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/normal/Demo03StudentNormalServiceImpl.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/normal/Demo03StudentNormalServiceImpl.java new file mode 100644 index 0000000000..cac883d4c7 --- /dev/null +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/normal/Demo03StudentNormalServiceImpl.java @@ -0,0 +1,175 @@ +package cn.iocoder.yudao.module.infra.service.demo.demo03.normal; + +import cn.hutool.core.collection.CollUtil; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalPageReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalSaveReqVO; +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.normal.Demo03CourseNormalMapper; +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.normal.Demo03GradeNormalMapper; +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.normal.Demo03StudentNormalMapper; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; + +import java.util.List; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.DEMO03_STUDENT_NOT_EXISTS; + +/** + * 学生 Service 实现类 + * + * @author 芋道源码 + */ +@Service +@Validated +public class Demo03StudentNormalServiceImpl implements Demo03StudentNormalService { + + @Resource + private Demo03StudentNormalMapper demo03StudentNormalMapper; + @Resource + private Demo03CourseNormalMapper demo03CourseNormalMapper; + @Resource + private Demo03GradeNormalMapper demo03GradeNormalMapper; + + @Override + @Transactional(rollbackFor = Exception.class) + public Long createDemo03Student(Demo03StudentNormalSaveReqVO createReqVO) { + // 插入 + Demo03StudentDO demo03Student = BeanUtils.toBean(createReqVO, Demo03StudentDO.class); + demo03StudentNormalMapper.insert(demo03Student); + + // 插入子表 + createDemo03CourseList(demo03Student.getId(), createReqVO.getDemo03Courses()); + createDemo03Grade(demo03Student.getId(), createReqVO.getDemo03Grade()); + // 返回 + return demo03Student.getId(); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void updateDemo03Student(Demo03StudentNormalSaveReqVO updateReqVO) { + // 校验存在 + validateDemo03StudentExists(updateReqVO.getId()); + // 更新 + Demo03StudentDO updateObj = BeanUtils.toBean(updateReqVO, Demo03StudentDO.class); + demo03StudentNormalMapper.updateById(updateObj); + + // 更新子表 + updateDemo03CourseList(updateReqVO.getId(), updateReqVO.getDemo03Courses()); + updateDemo03Grade(updateReqVO.getId(), updateReqVO.getDemo03Grade()); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteDemo03Student(Long id) { + // 校验存在 + validateDemo03StudentExists(id); + // 删除 + demo03StudentNormalMapper.deleteById(id); + + // 删除子表 + deleteDemo03CourseByStudentId(id); + deleteDemo03GradeByStudentId(id); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteDemo03StudentByIds(List ids) { + // 校验存在 + validateDemo03StudentExists(ids); + // 删除 + demo03StudentNormalMapper.deleteByIds(ids); + + // 删除子表 + deleteDemo03CourseByStudentIds(ids); + deleteDemo03GradeByStudentIds(ids); + } + + private void validateDemo03StudentExists(List ids) { + List list = demo03StudentNormalMapper.selectByIds(ids); + if (CollUtil.isEmpty(list) || list.size() != ids.size()) { + throw exception(DEMO03_STUDENT_NOT_EXISTS); + } + } + + private void validateDemo03StudentExists(Long id) { + if (demo03StudentNormalMapper.selectById(id) == null) { + throw exception(DEMO03_STUDENT_NOT_EXISTS); + } + } + + @Override + public Demo03StudentDO getDemo03Student(Long id) { + return demo03StudentNormalMapper.selectById(id); + } + + @Override + public PageResult getDemo03StudentPage(Demo03StudentNormalPageReqVO pageReqVO) { + return demo03StudentNormalMapper.selectPage(pageReqVO); + } + + // ==================== 子表(学生课程) ==================== + + @Override + public List getDemo03CourseListByStudentId(Long studentId) { + return demo03CourseNormalMapper.selectListByStudentId(studentId); + } + + private void createDemo03CourseList(Long studentId, List list) { + list.forEach(o -> o.setStudentId(studentId)); + demo03CourseNormalMapper.insertBatch(list); + } + + private void updateDemo03CourseList(Long studentId, List list) { + deleteDemo03CourseByStudentId(studentId); + list.forEach(o -> o.setId(null).setUpdater(null).setUpdateTime(null)); // 解决更新情况下:1)id 冲突;2)updateTime 不更新 + createDemo03CourseList(studentId, list); + } + + private void deleteDemo03CourseByStudentId(Long studentId) { + demo03CourseNormalMapper.deleteByStudentId(studentId); + } + + private void deleteDemo03CourseByStudentIds(List studentIds) { + demo03CourseNormalMapper.deleteByStudentIds(studentIds); + } + + // ==================== 子表(学生班级) ==================== + + @Override + public Demo03GradeDO getDemo03GradeByStudentId(Long studentId) { + return demo03GradeNormalMapper.selectByStudentId(studentId); + } + + private void createDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) { + if (demo03Grade == null) { + return; + } + demo03Grade.setStudentId(studentId); + demo03GradeNormalMapper.insert(demo03Grade); + } + + private void updateDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) { + if (demo03Grade == null) { + return; + } + demo03Grade.setStudentId(studentId); + demo03Grade.setUpdater(null).setUpdateTime(null); // 解决更新情况下:updateTime 不更新 + demo03GradeNormalMapper.insertOrUpdate(demo03Grade); + } + + private void deleteDemo03GradeByStudentId(Long studentId) { + demo03GradeNormalMapper.deleteByStudentId(studentId); + } + + private void deleteDemo03GradeByStudentIds(List studentIds) { + demo03GradeNormalMapper.deleteByStudentIds(studentIds); + } + +} \ No newline at end of file diff --git a/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/index.vue.vm b/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/index.vue.vm index c9746e48f8..4a4be13fc6 100644 --- a/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/index.vue.vm +++ b/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/index.vue.vm @@ -95,6 +95,13 @@ async function onDelete(row: ${simpleClassName}Api.${simpleClassName}) { #if ($table.templateType != 2 && $table.deleteBatch) const deleteIds = ref([]) // 待删除${table.classComment} ID const showDeleteBatchBtn = computed(() => isEmpty(deleteIds.value)); +function setDeleteIds({ + records, +}: { + records: ${simpleClassName}Api.${simpleClassName}[]; +}) { + deleteIds.value = records.map((item) => item.id); +} /** 批量删除${table.classComment} */ async function onDeleteBatch() { const hideLoading = message.loading({ @@ -205,12 +212,8 @@ const [Grid, gridApi] = useVbenVxeGrid({ }, #end #if($table.deleteBatch) - checkboxAll: ({records,}: { records: ${simpleClassName}Api.${simpleClassName}[];}) => { - deleteIds.value = records.map((item) => item.id); - }, - checkboxChange: ({records,}: { records: ${simpleClassName}Api.${simpleClassName}[];}) => { - deleteIds.value = records.map((item) => item.id); - }, + checkboxAll: setDeleteIds, + checkboxChange: setDeleteIds, #end } #end diff --git a/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/modules/list_sub_erp.vue.vm b/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/modules/list_sub_erp.vue.vm index d04f1aebf3..24c060597e 100644 --- a/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/modules/list_sub_erp.vue.vm +++ b/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/modules/list_sub_erp.vue.vm @@ -76,6 +76,13 @@ async function onDelete(row: ${simpleClassName}Api.${subSimpleClassName}) { #if ($table.deleteBatch) const deleteIds = ref([]) // 待删除${subTable.classComment} ID const showDeleteBatchBtn = computed(() => isEmpty(deleteIds.value)); +function setDeleteIds({ + records, +}: { + records: ${simpleClassName}Api.${subSimpleClassName}[]; +}) { + deleteIds.value = records.map((item) => item.id); +} /** 批量删除${subTable.classComment} */ async function onDeleteBatch() { const hideLoading = message.loading({ @@ -159,12 +166,8 @@ function onActionClick({ } as VxeTableGridOptions<${simpleClassName}Api.${subSimpleClassName}>, #if (${table.templateType} == 11 && $table.deleteBatch) gridEvents:{ - checkboxAll: ({records,}: { records: ${simpleClassName}Api.${subSimpleClassName}[];}) => { - deleteIds.value = records.map((item) => item.id); - }, - checkboxChange: ({records,}: { records: ${simpleClassName}Api.${subSimpleClassName}[];}) => { - deleteIds.value = records.map((item) => item.id); - }, + checkboxAll: setDeleteIds, + checkboxChange: setDeleteIds, } #end }); From 05bf229a3c91b9e74c11b380703ba5dd42e89fa2 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 19 May 2025 18:13:27 +0800 Subject: [PATCH 06/10] =?UTF-8?q?perf:=E3=80=90INFRA=20=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E8=AE=BE=E6=96=BD=E3=80=91vben5-antd-schema=20=E4=B8=BB?= =?UTF-8?q?=E4=B8=BB=E5=AD=90=E8=A1=A8inner=E4=BB=A3=E7=A0=81=E7=94=9F?= =?UTF-8?q?=E6=88=90=E6=97=B6=EF=BC=8C=E5=8F=AF=E7=94=9F=E6=88=90=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inner/Demo03StudentInnerController.java | 124 +++++++++++++ .../inner/vo/Demo03StudentInnerPageReqVO.java | 33 ++++ .../inner/vo/Demo03StudentInnerRespVO.java | 42 +++++ .../inner/vo/Demo03StudentInnerSaveReqVO.java | 42 +++++ .../demo03/inner/Demo03CourseInnerMapper.java | 29 +++ .../demo03/inner/Demo03GradeInnerMapper.java | 29 +++ .../inner/Demo03StudentInnerMapper.java | 27 +++ .../inner/Demo03StudentInnerService.java | 85 +++++++++ .../inner/Demo03StudentInnerServiceImpl.java | 175 ++++++++++++++++++ 9 files changed, 586 insertions(+) create mode 100644 yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/inner/Demo03StudentInnerController.java create mode 100644 yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/inner/vo/Demo03StudentInnerPageReqVO.java create mode 100644 yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/inner/vo/Demo03StudentInnerRespVO.java create mode 100644 yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/inner/vo/Demo03StudentInnerSaveReqVO.java create mode 100644 yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/inner/Demo03CourseInnerMapper.java create mode 100644 yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/inner/Demo03GradeInnerMapper.java create mode 100644 yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/inner/Demo03StudentInnerMapper.java create mode 100644 yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/inner/Demo03StudentInnerService.java create mode 100644 yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/inner/Demo03StudentInnerServiceImpl.java diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/inner/Demo03StudentInnerController.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/inner/Demo03StudentInnerController.java new file mode 100644 index 0000000000..214d1fe058 --- /dev/null +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/inner/Demo03StudentInnerController.java @@ -0,0 +1,124 @@ +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner; + +import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerPageReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerRespVO; +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerSaveReqVO; +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; +import cn.iocoder.yudao.module.infra.service.demo.demo03.inner.Demo03StudentInnerService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.validation.Valid; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.io.IOException; +import java.util.List; + +import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +@Tag(name = "管理后台 - 学生") +@RestController +@RequestMapping("/infra/demo03-student-inner") +@Validated +public class Demo03StudentInnerController { + + @Resource + private Demo03StudentInnerService demo03StudentInnerService; + + @PostMapping("/create") + @Operation(summary = "创建学生") + @PreAuthorize("@ss.hasPermission('infra:demo03-student:create')") + public CommonResult createDemo03Student(@Valid @RequestBody Demo03StudentInnerSaveReqVO createReqVO) { + return success(demo03StudentInnerService.createDemo03Student(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新学生") + @PreAuthorize("@ss.hasPermission('infra:demo03-student:update')") + public CommonResult updateDemo03Student(@Valid @RequestBody Demo03StudentInnerSaveReqVO updateReqVO) { + demo03StudentInnerService.updateDemo03Student(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除学生") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") + public CommonResult deleteDemo03Student(@RequestParam("id") Long id) { + demo03StudentInnerService.deleteDemo03Student(id); + return success(true); + } + + @DeleteMapping("/delete-batch") + @Parameter(name = "ids", description = "编号", required = true) + @Operation(summary = "批量删除学生") + @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") + public CommonResult deleteDemo03Student(@RequestParam("ids") List ids) { + demo03StudentInnerService.deleteDemo03StudentByIds(ids); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得学生") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") + public CommonResult getDemo03Student(@RequestParam("id") Long id) { + Demo03StudentDO demo03Student = demo03StudentInnerService.getDemo03Student(id); + return success(BeanUtils.toBean(demo03Student, Demo03StudentInnerRespVO.class)); + } + + @GetMapping("/page") + @Operation(summary = "获得学生分页") + @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") + public CommonResult> getDemo03StudentPage(@Valid Demo03StudentInnerPageReqVO pageReqVO) { + PageResult pageResult = demo03StudentInnerService.getDemo03StudentPage(pageReqVO); + return success(BeanUtils.toBean(pageResult, Demo03StudentInnerRespVO.class)); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出学生 Excel") + @PreAuthorize("@ss.hasPermission('infra:demo03-student:export')") + @ApiAccessLog(operateType = EXPORT) + public void exportDemo03StudentExcel(@Valid Demo03StudentInnerPageReqVO pageReqVO, + HttpServletResponse response) throws IOException { + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = demo03StudentInnerService.getDemo03StudentPage(pageReqVO).getList(); + // 导出 Excel + ExcelUtils.write(response, "学生.xls", "数据", Demo03StudentInnerRespVO.class, + BeanUtils.toBean(list, Demo03StudentInnerRespVO.class)); + } + + // ==================== 子表(学生课程) ==================== + + @GetMapping("/demo03-course/list-by-student-id") + @Operation(summary = "获得学生课程列表") + @Parameter(name = "studentId", description = "学生编号") + @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") + public CommonResult> getDemo03CourseListByStudentId(@RequestParam("studentId") Long studentId) { + return success(demo03StudentInnerService.getDemo03CourseListByStudentId(studentId)); + } + + // ==================== 子表(学生班级) ==================== + + @GetMapping("/demo03-grade/get-by-student-id") + @Operation(summary = "获得学生班级") + @Parameter(name = "studentId", description = "学生编号") + @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") + public CommonResult getDemo03GradeByStudentId(@RequestParam("studentId") Long studentId) { + return success(demo03StudentInnerService.getDemo03GradeByStudentId(studentId)); + } + +} \ No newline at end of file diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/inner/vo/Demo03StudentInnerPageReqVO.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/inner/vo/Demo03StudentInnerPageReqVO.java new file mode 100644 index 0000000000..d11fba7244 --- /dev/null +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/inner/vo/Demo03StudentInnerPageReqVO.java @@ -0,0 +1,33 @@ +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.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 Demo03StudentInnerPageReqVO extends PageParam { + + @Schema(description = "名字", example = "芋艿") + private String name; + + @Schema(description = "性别") + private Integer sex; + + @Schema(description = "简介", example = "随便") + private String description; + + @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/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/inner/vo/Demo03StudentInnerRespVO.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/inner/vo/Demo03StudentInnerRespVO.java new file mode 100644 index 0000000000..48d5e4889a --- /dev/null +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/inner/vo/Demo03StudentInnerRespVO.java @@ -0,0 +1,42 @@ +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo; + +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDateTime; + +@Schema(description = "管理后台 - 学生 Response VO") +@Data +@ExcelIgnoreUnannotated +public class Demo03StudentInnerRespVO { + + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525") + @ExcelProperty("编号") + private Long id; + + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") + @ExcelProperty("名字") + private String name; + + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty(value = "性别", converter = DictConvert.class) + @DictFormat("system_user_sex") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 + private Integer sex; + + @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("出生日期") + private LocalDateTime birthday; + + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "随便") + @ExcelProperty("简介") + private String description; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") + private LocalDateTime createTime; + +} \ No newline at end of file diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/inner/vo/Demo03StudentInnerSaveReqVO.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/inner/vo/Demo03StudentInnerSaveReqVO.java new file mode 100644 index 0000000000..e181eeaea9 --- /dev/null +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/inner/vo/Demo03StudentInnerSaveReqVO.java @@ -0,0 +1,42 @@ +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo; + +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +import java.time.LocalDateTime; +import java.util.List; + +@Schema(description = "管理后台 - 学生新增/修改 Request VO") +@Data +public class Demo03StudentInnerSaveReqVO { + + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525") + private Long id; + + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") + @NotEmpty(message = "名字不能为空") + private String name; + + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "性别不能为空") + private Integer sex; + + @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "出生日期不能为空") + private LocalDateTime birthday; + + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "随便") + @NotEmpty(message = "简介不能为空") + private String description; + + @Schema(description = "学生课程列表") + private List demo03Courses; + + @Schema(description = "学生班级") + private Demo03GradeDO demo03Grade; + +} \ No newline at end of file diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/inner/Demo03CourseInnerMapper.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/inner/Demo03CourseInnerMapper.java new file mode 100644 index 0000000000..225bd955fe --- /dev/null +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/inner/Demo03CourseInnerMapper.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.inner; + +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +/** + * 学生课程 Mapper + * + * @author 芋道源码 + */ +@Mapper +public interface Demo03CourseInnerMapper extends BaseMapperX { + + default List selectListByStudentId(Long studentId) { + return selectList(Demo03CourseDO::getStudentId, studentId); + } + + default int deleteByStudentId(Long studentId) { + return delete(Demo03CourseDO::getStudentId, studentId); + } + + default int deleteByStudentIds(List studentIds) { + return delete(Demo03CourseDO::getStudentId, studentIds); + } + +} diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/inner/Demo03GradeInnerMapper.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/inner/Demo03GradeInnerMapper.java new file mode 100644 index 0000000000..bedfd13d5f --- /dev/null +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/inner/Demo03GradeInnerMapper.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.inner; + +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +/** + * 学生班级 Mapper + * + * @author 芋道源码 + */ +@Mapper +public interface Demo03GradeInnerMapper extends BaseMapperX { + + default Demo03GradeDO selectByStudentId(Long studentId) { + return selectOne(Demo03GradeDO::getStudentId, studentId); + } + + default int deleteByStudentId(Long studentId) { + return delete(Demo03GradeDO::getStudentId, studentId); + } + + default int deleteByStudentIds(List studentIds) { + return delete(Demo03GradeDO::getStudentId, studentIds); + } + +} diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/inner/Demo03StudentInnerMapper.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/inner/Demo03StudentInnerMapper.java new file mode 100644 index 0000000000..6a329fd1c3 --- /dev/null +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/inner/Demo03StudentInnerMapper.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.inner; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerPageReqVO; +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; +import org.apache.ibatis.annotations.Mapper; + +/** + * 学生 Mapper + * + * @author 芋道源码 + */ +@Mapper +public interface Demo03StudentInnerMapper extends BaseMapperX { + + default PageResult selectPage(Demo03StudentInnerPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .likeIfPresent(Demo03StudentDO::getName, reqVO.getName()) + .eqIfPresent(Demo03StudentDO::getSex, reqVO.getSex()) + .eqIfPresent(Demo03StudentDO::getDescription, reqVO.getDescription()) + .betweenIfPresent(Demo03StudentDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(Demo03StudentDO::getId)); + } + +} \ No newline at end of file diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/inner/Demo03StudentInnerService.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/inner/Demo03StudentInnerService.java new file mode 100644 index 0000000000..cf1aa4f0f6 --- /dev/null +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/inner/Demo03StudentInnerService.java @@ -0,0 +1,85 @@ +package cn.iocoder.yudao.module.infra.service.demo.demo03.inner; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerPageReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerSaveReqVO; +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; +import jakarta.validation.Valid; + +import java.util.List; + +/** + * 学生 Service 接口 + * + * @author 芋道源码 + */ +public interface Demo03StudentInnerService { + + /** + * 创建学生 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createDemo03Student(@Valid Demo03StudentInnerSaveReqVO createReqVO); + + /** + * 更新学生 + * + * @param updateReqVO 更新信息 + */ + void updateDemo03Student(@Valid Demo03StudentInnerSaveReqVO updateReqVO); + + /** + * 删除学生 + * + * @param id 编号 + */ + void deleteDemo03Student(Long id); + + /** + * 批量删除学生 + * + * @param ids 编号 + */ + void deleteDemo03StudentByIds(List ids); + + /** + * 获得学生 + * + * @param id 编号 + * @return 学生 + */ + Demo03StudentDO getDemo03Student(Long id); + + /** + * 获得学生分页 + * + * @param pageReqVO 分页查询 + * @return 学生分页 + */ + PageResult getDemo03StudentPage(Demo03StudentInnerPageReqVO pageReqVO); + + // ==================== 子表(学生课程) ==================== + + /** + * 获得学生课程列表 + * + * @param studentId 学生编号 + * @return 学生课程列表 + */ + List getDemo03CourseListByStudentId(Long studentId); + + // ==================== 子表(学生班级) ==================== + + /** + * 获得学生班级 + * + * @param studentId 学生编号 + * @return 学生班级 + */ + Demo03GradeDO getDemo03GradeByStudentId(Long studentId); + +} \ No newline at end of file diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/inner/Demo03StudentInnerServiceImpl.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/inner/Demo03StudentInnerServiceImpl.java new file mode 100644 index 0000000000..52298e934a --- /dev/null +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/inner/Demo03StudentInnerServiceImpl.java @@ -0,0 +1,175 @@ +package cn.iocoder.yudao.module.infra.service.demo.demo03.inner; + +import cn.hutool.core.collection.CollUtil; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerPageReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerSaveReqVO; +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.inner.Demo03CourseInnerMapper; +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.inner.Demo03GradeInnerMapper; +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.inner.Demo03StudentInnerMapper; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; + +import java.util.List; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.DEMO03_STUDENT_NOT_EXISTS; + +/** + * 学生 Service 实现类 + * + * @author 芋道源码 + */ +@Service +@Validated +public class Demo03StudentInnerServiceImpl implements Demo03StudentInnerService { + + @Resource + private Demo03StudentInnerMapper demo03StudentInnerMapper; + @Resource + private Demo03CourseInnerMapper demo03CourseInnerMapper; + @Resource + private Demo03GradeInnerMapper demo03GradeInnerMapper; + + @Override + @Transactional(rollbackFor = Exception.class) + public Long createDemo03Student(Demo03StudentInnerSaveReqVO createReqVO) { + // 插入 + Demo03StudentDO demo03Student = BeanUtils.toBean(createReqVO, Demo03StudentDO.class); + demo03StudentInnerMapper.insert(demo03Student); + + // 插入子表 + createDemo03CourseList(demo03Student.getId(), createReqVO.getDemo03Courses()); + createDemo03Grade(demo03Student.getId(), createReqVO.getDemo03Grade()); + // 返回 + return demo03Student.getId(); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void updateDemo03Student(Demo03StudentInnerSaveReqVO updateReqVO) { + // 校验存在 + validateDemo03StudentExists(updateReqVO.getId()); + // 更新 + Demo03StudentDO updateObj = BeanUtils.toBean(updateReqVO, Demo03StudentDO.class); + demo03StudentInnerMapper.updateById(updateObj); + + // 更新子表 + updateDemo03CourseList(updateReqVO.getId(), updateReqVO.getDemo03Courses()); + updateDemo03Grade(updateReqVO.getId(), updateReqVO.getDemo03Grade()); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteDemo03Student(Long id) { + // 校验存在 + validateDemo03StudentExists(id); + // 删除 + demo03StudentInnerMapper.deleteById(id); + + // 删除子表 + deleteDemo03CourseByStudentId(id); + deleteDemo03GradeByStudentId(id); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteDemo03StudentByIds(List ids) { + // 校验存在 + validateDemo03StudentExists(ids); + // 删除 + demo03StudentInnerMapper.deleteByIds(ids); + + // 删除子表 + deleteDemo03CourseByStudentIds(ids); + deleteDemo03GradeByStudentIds(ids); + } + + private void validateDemo03StudentExists(List ids) { + List list = demo03StudentInnerMapper.selectByIds(ids); + if (CollUtil.isEmpty(list) || list.size() != ids.size()) { + throw exception(DEMO03_STUDENT_NOT_EXISTS); + } + } + + private void validateDemo03StudentExists(Long id) { + if (demo03StudentInnerMapper.selectById(id) == null) { + throw exception(DEMO03_STUDENT_NOT_EXISTS); + } + } + + @Override + public Demo03StudentDO getDemo03Student(Long id) { + return demo03StudentInnerMapper.selectById(id); + } + + @Override + public PageResult getDemo03StudentPage(Demo03StudentInnerPageReqVO pageReqVO) { + return demo03StudentInnerMapper.selectPage(pageReqVO); + } + + // ==================== 子表(学生课程) ==================== + + @Override + public List getDemo03CourseListByStudentId(Long studentId) { + return demo03CourseInnerMapper.selectListByStudentId(studentId); + } + + private void createDemo03CourseList(Long studentId, List list) { + list.forEach(o -> o.setStudentId(studentId)); + demo03CourseInnerMapper.insertBatch(list); + } + + private void updateDemo03CourseList(Long studentId, List list) { + deleteDemo03CourseByStudentId(studentId); + list.forEach(o -> o.setId(null).setUpdater(null).setUpdateTime(null)); // 解决更新情况下:1)id 冲突;2)updateTime 不更新 + createDemo03CourseList(studentId, list); + } + + private void deleteDemo03CourseByStudentId(Long studentId) { + demo03CourseInnerMapper.deleteByStudentId(studentId); + } + + private void deleteDemo03CourseByStudentIds(List studentIds) { + demo03CourseInnerMapper.deleteByStudentIds(studentIds); + } + + // ==================== 子表(学生班级) ==================== + + @Override + public Demo03GradeDO getDemo03GradeByStudentId(Long studentId) { + return demo03GradeInnerMapper.selectByStudentId(studentId); + } + + private void createDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) { + if (demo03Grade == null) { + return; + } + demo03Grade.setStudentId(studentId); + demo03GradeInnerMapper.insert(demo03Grade); + } + + private void updateDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) { + if (demo03Grade == null) { + return; + } + demo03Grade.setStudentId(studentId); + demo03Grade.setUpdater(null).setUpdateTime(null); // 解决更新情况下:updateTime 不更新 + demo03GradeInnerMapper.insertOrUpdate(demo03Grade); + } + + private void deleteDemo03GradeByStudentId(Long studentId) { + demo03GradeInnerMapper.deleteByStudentId(studentId); + } + + private void deleteDemo03GradeByStudentIds(List studentIds) { + demo03GradeInnerMapper.deleteByStudentIds(studentIds); + } + +} \ No newline at end of file From 61cfcc283b426dd69e3f479a5600be3c6e1f382b Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 19 May 2025 23:52:58 +0800 Subject: [PATCH 07/10] =?UTF-8?q?perf:=E3=80=90INFRA=20=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E8=AE=BE=E6=96=BD=E3=80=91=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=20delete-batch-enable:=20false=20#=20?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E7=94=9F=E6=88=90=E6=89=B9=E9=87=8F=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/codegen/vo/table/CodegenTableRespVO.java | 4 ---- .../admin/codegen/vo/table/CodegenTableSaveReqVO.java | 4 ---- .../infra/dal/dataobject/codegen/CodegenTableDO.java | 6 ------ .../framework/codegen/config/CodegenProperties.java | 6 ++++++ .../infra/service/codegen/inner/CodegenEngine.java | 2 +- .../resources/codegen/java/controller/controller.vm | 4 ++-- .../src/main/resources/codegen/java/dal/mapper_sub.vm | 2 +- .../src/main/resources/codegen/java/service/service.vm | 4 ++-- .../main/resources/codegen/java/service/serviceImpl.vm | 8 ++++---- .../codegen/vue3_vben5_antd/schema/api/api.ts.vm | 4 ++-- .../codegen/vue3_vben5_antd/schema/views/data.ts.vm | 4 ++-- .../codegen/vue3_vben5_antd/schema/views/index.vue.vm | 10 +++++----- .../schema/views/modules/list_sub_erp.vue.vm | 8 ++++---- yudao-server/src/main/resources/application.yaml | 1 + 14 files changed, 30 insertions(+), 37 deletions(-) diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/table/CodegenTableRespVO.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/table/CodegenTableRespVO.java index a8a8fe108f..8b438b2da6 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/table/CodegenTableRespVO.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/table/CodegenTableRespVO.java @@ -1,7 +1,6 @@ package cn.iocoder.yudao.module.infra.controller.admin.codegen.vo.table; import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotNull; import lombok.Data; import java.time.LocalDateTime; @@ -46,9 +45,6 @@ public class CodegenTableRespVO { @Schema(description = "前端类型,参见 CodegenFrontTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "20") private Integer frontType; - @Schema(description = "是否生成批量删除接口", example = "true") - private Boolean deleteBatch; - @Schema(description = "父菜单编号", example = "1024") private Long parentMenuId; diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/table/CodegenTableSaveReqVO.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/table/CodegenTableSaveReqVO.java index 1fa2ba9278..201d94d2e2 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/table/CodegenTableSaveReqVO.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/table/CodegenTableSaveReqVO.java @@ -60,10 +60,6 @@ public class CodegenTableSaveReqVO { @NotNull(message = "前端类型不能为空") private Integer frontType; - @Schema(description = "是否生成批量删除接口", example = "true") - @NotNull(message = "是否生成批量删除接口不能为空") - private Boolean deleteBatch; - @Schema(description = "父菜单编号", example = "1024") private Long parentMenuId; diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/codegen/CodegenTableDO.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/codegen/CodegenTableDO.java index d8aa79b66a..b46cbe4fef 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/codegen/CodegenTableDO.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/codegen/CodegenTableDO.java @@ -108,12 +108,6 @@ public class CodegenTableDO extends BaseDO { * 枚举 {@link CodegenFrontTypeEnum} */ private Integer frontType; - /** - * 是否生成批量删除接口 - * -true 是 - * -false 否 - */ - private Boolean deleteBatch; // ========== 菜单相关字段 ========== diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/framework/codegen/config/CodegenProperties.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/framework/codegen/config/CodegenProperties.java index cfa1fa2fbe..3ff03b3d4a 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/framework/codegen/config/CodegenProperties.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/framework/codegen/config/CodegenProperties.java @@ -40,4 +40,10 @@ public class CodegenProperties { @NotNull(message = "是否生成单元测试不能为空") private Boolean unitTestEnable; + /** + * 是否生成批量删除接口 + */ + @NotNull(message = "是否生成批量删除接口不能为空") + private Boolean deleteBatchEnable; + } diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java index bce07e0c1d..2d2a920551 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java @@ -380,7 +380,7 @@ public class CodegenEngine { bindingMap.put("columns", columns); bindingMap.put("primaryColumn", CollectionUtils.findFirst(columns, CodegenColumnDO::getPrimaryKey)); // 主键字段 bindingMap.put("sceneEnum", CodegenSceneEnum.valueOf(table.getScene())); - + bindingMap.put("deleteBatchEnable", codegenProperties.getDeleteBatchEnable()); // className 相关 // 去掉指定前缀,将 TestDictType 转换成 DictType. 因为在 create 等方法后,不需要带上 Test 前缀 String simpleClassName = equalsAnyIgnoreCase(table.getClassName(), table.getModuleName()) ? table.getClassName() diff --git a/yudao-module-infra/src/main/resources/codegen/java/controller/controller.vm b/yudao-module-infra/src/main/resources/codegen/java/controller/controller.vm index 36d860f7e9..d94eeaaf30 100644 --- a/yudao-module-infra/src/main/resources/codegen/java/controller/controller.vm +++ b/yudao-module-infra/src/main/resources/codegen/java/controller/controller.vm @@ -74,7 +74,7 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { return success(true); } -#if ( $table.templateType != 2 && $table.deleteBatch) +#if ( $table.templateType != 2 && $deleteBatchEnable) @DeleteMapping("/delete-batch") @Parameter(name = "ids", description = "编号", required = true) @Operation(summary = "批量删除${table.classComment}") @@ -231,7 +231,7 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { return success(true); } -#if ($table.deleteBatch) +#if ($deleteBatchEnable) @DeleteMapping("/${subSimpleClassName_strikeCase}/delete-batch") @Parameter(name = "ids", description = "编号", required = true) @Operation(summary = "批量删除${subTable.classComment}") diff --git a/yudao-module-infra/src/main/resources/codegen/java/dal/mapper_sub.vm b/yudao-module-infra/src/main/resources/codegen/java/dal/mapper_sub.vm index 88d1cd0745..950000ce0a 100644 --- a/yudao-module-infra/src/main/resources/codegen/java/dal/mapper_sub.vm +++ b/yudao-module-infra/src/main/resources/codegen/java/dal/mapper_sub.vm @@ -54,7 +54,7 @@ public interface ${subTable.className}Mapper extends BaseMapperX<${subTable.clas return delete(${subTable.className}DO::get${SubJoinColumnName}, ${subJoinColumn.javaField}); } -#if ( $table.templateType != 2 && $table.deleteBatch) +#if ( $table.templateType != 2 && $deleteBatchEnable) default int deleteBy${SubJoinColumnName}s(List<${subJoinColumn.javaType}> ${subJoinColumn.javaField}s) { return delete(${subTable.className}DO::get${SubJoinColumnName}, ${subJoinColumn.javaField}s); } diff --git a/yudao-module-infra/src/main/resources/codegen/java/service/service.vm b/yudao-module-infra/src/main/resources/codegen/java/service/service.vm index 6770138c20..37471365f7 100644 --- a/yudao-module-infra/src/main/resources/codegen/java/service/service.vm +++ b/yudao-module-infra/src/main/resources/codegen/java/service/service.vm @@ -40,7 +40,7 @@ public interface ${table.className}Service { */ void delete${simpleClassName}(${primaryColumn.javaType} id); -#if ( $table.templateType != 2 && $table.deleteBatch) +#if ( $table.templateType != 2 && $deleteBatchEnable) /** * 批量删除${table.classComment} * @@ -143,7 +143,7 @@ public interface ${table.className}Service { */ void delete${subSimpleClassName}(${subPrimaryColumn.javaType} id); -#if ($table.deleteBatch) +#if ($deleteBatchEnable) /** * 批量删除${subTable.classComment} * diff --git a/yudao-module-infra/src/main/resources/codegen/java/service/serviceImpl.vm b/yudao-module-infra/src/main/resources/codegen/java/service/serviceImpl.vm index 347049ecaf..1d7baa9629 100644 --- a/yudao-module-infra/src/main/resources/codegen/java/service/serviceImpl.vm +++ b/yudao-module-infra/src/main/resources/codegen/java/service/serviceImpl.vm @@ -155,7 +155,7 @@ public class ${table.className}ServiceImpl implements ${table.className}Service #end } -#if ( $table.templateType != 2 && $table.deleteBatch) +#if ( $table.templateType != 2 && $deleteBatchEnable) @Override ## 特殊:主子表专属逻辑 #if ( $subTables && $subTables.size() > 0) @@ -332,7 +332,7 @@ public class ${table.className}ServiceImpl implements ${table.className}Service ${subClassNameVars.get($index)}Mapper.deleteById(id); } -#if ($table.deleteBatch) +#if ($deleteBatchEnable) @Override public void delete${subSimpleClassName}ByIds(List<${subPrimaryColumn.javaType}> ids) { // 校验存在 @@ -353,7 +353,7 @@ public class ${table.className}ServiceImpl implements ${table.className}Service } } -#if ($table.deleteBatch) +#if ($deleteBatchEnable) private void validate${subSimpleClassName}Exists(List<${subPrimaryColumn.javaType}> ids) { List<${subTable.className}DO> list = ${subClassNameVar}Mapper.selectByIds(ids); if (CollUtil.isEmpty(list) || list.size() != ids.size()) { @@ -400,7 +400,7 @@ public class ${table.className}ServiceImpl implements ${table.className}Service ${subClassNameVars.get($index)}Mapper.deleteBy${SubJoinColumnName}(${subJoinColumn.javaField}); } -#if ( $table.templateType != 2 && $table.deleteBatch) +#if ( $table.templateType != 2 && $deleteBatchEnable) private void delete${subSimpleClassName}By${SubJoinColumnName}s(List<${primaryColumn.javaType}> ${subJoinColumn.javaField}s) { ${subClassNameVars.get($index)}Mapper.deleteBy${SubJoinColumnName}s(${subJoinColumn.javaField}s); } diff --git a/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/api/api.ts.vm b/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/api/api.ts.vm index 330a18ae18..4bf8148c94 100644 --- a/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/api/api.ts.vm +++ b/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/api/api.ts.vm @@ -89,7 +89,7 @@ export function delete${simpleClassName}(id: number) { return requestClient.delete(`${baseURL}/delete?id=${id}`); } -#if ( $table.templateType != 2 && $table.deleteBatch) +#if ( $table.templateType != 2 && $deleteBatchEnable) // 批量删除${table.classComment} export function delete${simpleClassName}ByIds(ids: number[]) { return requestClient.delete(`${baseURL}/delete-batch?ids=${ids.join(',')}`) @@ -151,7 +151,7 @@ export function delete${subSimpleClassName}(id: number) { return requestClient.delete(`${baseURL}/${subSimpleClassName_strikeCase}/delete?id=${id}`); } -#if ($table.deleteBatch) +#if ($deleteBatchEnable) // 批量删除${subTable.classComment} export function delete${subSimpleClassName}ByIds(ids: number[]) { return requestClient.delete(`${baseURL}/${subSimpleClassName_strikeCase}/delete-batch?ids=${ids.join(',')}`) diff --git a/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/data.ts.vm b/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/data.ts.vm index 28039ea3b3..46c19d96d5 100644 --- a/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/data.ts.vm +++ b/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/data.ts.vm @@ -193,7 +193,7 @@ export function useGridColumns( onActionClick?: OnActionClickFn<${simpleClassName}Api.${simpleClassName}>, ): VxeTableGridOptions<${simpleClassName}Api.${simpleClassName}>['columns'] { return [ -#if ($table.templateType != 2 && $table.deleteBatch) +#if ($table.templateType != 2 && $deleteBatchEnable) { type: 'checkbox', width: 40 }, #end #if ($table.templateType == 12) ## 内嵌情况 @@ -431,7 +431,7 @@ export function use${subSimpleClassName}GridColumns( onActionClick?: OnActionClickFn<${simpleClassName}Api.${subSimpleClassName}>, ): VxeTableGridOptions<${simpleClassName}Api.${subSimpleClassName}>['columns'] { return [ - #if ($table.templateType != 2 && $table.deleteBatch) + #if ($table.templateType != 2 && $deleteBatchEnable) { type: 'checkbox', width: 40 }, #end #foreach($column in $subColumns) diff --git a/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/index.vue.vm b/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/index.vue.vm index 4a4be13fc6..d0ae6e770e 100644 --- a/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/index.vue.vm +++ b/yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/index.vue.vm @@ -22,7 +22,7 @@ import { useVbenVxeGrid } from '#/adapter/vxe-table'; #if (${table.templateType} == 2)## 树表接口 import { get${simpleClassName}List, delete${simpleClassName}, export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}'; #else## 标准表接口 -import { get${simpleClassName}Page, delete${simpleClassName},#if ($table.deleteBatch) delete${simpleClassName}ByIds,#end export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}'; +import { get${simpleClassName}Page, delete${simpleClassName},#if ($deleteBatchEnable) delete${simpleClassName}ByIds,#end export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}'; #end import { downloadFileFromBlobPart, isEmpty } from '@vben/utils'; @@ -92,7 +92,7 @@ async function onDelete(row: ${simpleClassName}Api.${simpleClassName}) { } } -#if ($table.templateType != 2 && $table.deleteBatch) +#if ($table.templateType != 2 && $deleteBatchEnable) const deleteIds = ref([]) // 待删除${table.classComment} ID const showDeleteBatchBtn = computed(() => isEmpty(deleteIds.value)); function setDeleteIds({ @@ -204,14 +204,14 @@ const [Grid, gridApi] = useVbenVxeGrid({ search: true, }, } as VxeTableGridOptions<${simpleClassName}Api.${simpleClassName}>, -#if (${table.templateType} == 11 || $table.deleteBatch) +#if (${table.templateType} == 11 || $deleteBatchEnable) gridEvents:{ #if(${table.templateType} == 11) cellClick: ({ row }: { row: ${simpleClassName}Api.${simpleClassName}}) => { select${simpleClassName}.value = row; }, #end - #if($table.deleteBatch) + #if($deleteBatchEnable) checkboxAll: setDeleteIds, checkboxChange: setDeleteIds, #end @@ -262,7 +262,7 @@ const [Grid, gridApi] = useVbenVxeGrid({ > {{ $t('ui.actionTitle.export') }} -#if ($table.templateType != 2 && $table.deleteBatch) +#if ($table.templateType != 2 && $deleteBatchEnable) - #if ($table.templateType == 11 && $table.deleteBatch) + #if ($table.templateType == 11 && $deleteBatchEnable)