Commit ef1e7b312bde4e653da3a7e4b40ef7ff5af04bba
1 parent
6dee9262
perf:【INFRA 基础设施】vben5-antd-schema 主主子表erp代码生成时,可生成批量删除
Showing
19 changed files
with
285 additions
and
154 deletions
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/Demo03StudentController.java renamed to yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/Demo03StudentController.java
| 1 | -package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03; | 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; | 3 | import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| @@ -6,13 +6,13 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam; | @@ -6,13 +6,13 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||
| 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 7 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 8 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | 8 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| 9 | -import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentPageReqVO; | ||
| 10 | -import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentRespVO; | ||
| 11 | -import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentSaveReqVO; | 9 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentPageReqVO; |
| 10 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentRespVO; | ||
| 11 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentSaveReqVO; | ||
| 12 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; | 12 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; |
| 13 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; | 13 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; |
| 14 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; | 14 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; |
| 15 | -import cn.iocoder.yudao.module.infra.service.demo.demo03.Demo03StudentService; | 15 | +import cn.iocoder.yudao.module.infra.service.demo.demo03.erp.Demo03StudentService; |
| 16 | import io.swagger.v3.oas.annotations.Operation; | 16 | import io.swagger.v3.oas.annotations.Operation; |
| 17 | import io.swagger.v3.oas.annotations.Parameter; | 17 | import io.swagger.v3.oas.annotations.Parameter; |
| 18 | import io.swagger.v3.oas.annotations.tags.Tag; | 18 | import io.swagger.v3.oas.annotations.tags.Tag; |
| @@ -31,7 +31,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | @@ -31,7 +31,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 31 | 31 | ||
| 32 | @Tag(name = "管理后台 - 学生") | 32 | @Tag(name = "管理后台 - 学生") |
| 33 | @RestController | 33 | @RestController |
| 34 | -@RequestMapping("/infra/demo03-student") | 34 | +@RequestMapping("/infra/demo03-student-erp") |
| 35 | @Validated | 35 | @Validated |
| 36 | public class Demo03StudentController { | 36 | public class Demo03StudentController { |
| 37 | 37 | ||
| @@ -62,6 +62,15 @@ public class Demo03StudentController { | @@ -62,6 +62,15 @@ public class Demo03StudentController { | ||
| 62 | return success(true); | 62 | return success(true); |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | + @DeleteMapping("/delete-batch") | ||
| 66 | + @Parameter(name = "ids", description = "编号", required = true) | ||
| 67 | + @Operation(summary = "批量删除学生") | ||
| 68 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") | ||
| 69 | + public CommonResult<Boolean> deleteDemo03Student(@RequestParam("ids") List<Long> ids) { | ||
| 70 | + demo03StudentService.deleteDemo03StudentByIds(ids); | ||
| 71 | + return success(true); | ||
| 72 | + } | ||
| 73 | + | ||
| 65 | @GetMapping("/get") | 74 | @GetMapping("/get") |
| 66 | @Operation(summary = "获得学生") | 75 | @Operation(summary = "获得学生") |
| 67 | @Parameter(name = "id", description = "编号", required = true, example = "1024") | 76 | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| @@ -84,12 +93,12 @@ public class Demo03StudentController { | @@ -84,12 +93,12 @@ public class Demo03StudentController { | ||
| 84 | @PreAuthorize("@ss.hasPermission('infra:demo03-student:export')") | 93 | @PreAuthorize("@ss.hasPermission('infra:demo03-student:export')") |
| 85 | @ApiAccessLog(operateType = EXPORT) | 94 | @ApiAccessLog(operateType = EXPORT) |
| 86 | public void exportDemo03StudentExcel(@Valid Demo03StudentPageReqVO pageReqVO, | 95 | public void exportDemo03StudentExcel(@Valid Demo03StudentPageReqVO pageReqVO, |
| 87 | - HttpServletResponse response) throws IOException { | 96 | + HttpServletResponse response) throws IOException { |
| 88 | pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | 97 | pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); |
| 89 | List<Demo03StudentDO> list = demo03StudentService.getDemo03StudentPage(pageReqVO).getList(); | 98 | List<Demo03StudentDO> list = demo03StudentService.getDemo03StudentPage(pageReqVO).getList(); |
| 90 | // 导出 Excel | 99 | // 导出 Excel |
| 91 | ExcelUtils.write(response, "学生.xls", "数据", Demo03StudentRespVO.class, | 100 | ExcelUtils.write(response, "学生.xls", "数据", Demo03StudentRespVO.class, |
| 92 | - BeanUtils.toBean(list, Demo03StudentRespVO.class)); | 101 | + BeanUtils.toBean(list, Demo03StudentRespVO.class)); |
| 93 | } | 102 | } |
| 94 | 103 | ||
| 95 | // ==================== 子表(学生课程) ==================== | 104 | // ==================== 子表(学生课程) ==================== |
| @@ -127,6 +136,15 @@ public class Demo03StudentController { | @@ -127,6 +136,15 @@ public class Demo03StudentController { | ||
| 127 | return success(true); | 136 | return success(true); |
| 128 | } | 137 | } |
| 129 | 138 | ||
| 139 | + @DeleteMapping("/demo03-course/delete-batch") | ||
| 140 | + @Parameter(name = "ids", description = "编号", required = true) | ||
| 141 | + @Operation(summary = "批量删除学生课程") | ||
| 142 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") | ||
| 143 | + public CommonResult<Boolean> deleteDemo03Course(@RequestParam("ids") List<Long> ids) { | ||
| 144 | + demo03StudentService.deleteDemo03CourseByIds(ids); | ||
| 145 | + return success(true); | ||
| 146 | + } | ||
| 147 | + | ||
| 130 | @GetMapping("/demo03-course/get") | 148 | @GetMapping("/demo03-course/get") |
| 131 | @Operation(summary = "获得学生课程") | 149 | @Operation(summary = "获得学生课程") |
| 132 | @Parameter(name = "id", description = "编号", required = true) | 150 | @Parameter(name = "id", description = "编号", required = true) |
| @@ -135,14 +153,6 @@ public class Demo03StudentController { | @@ -135,14 +153,6 @@ public class Demo03StudentController { | ||
| 135 | return success(demo03StudentService.getDemo03Course(id)); | 153 | return success(demo03StudentService.getDemo03Course(id)); |
| 136 | } | 154 | } |
| 137 | 155 | ||
| 138 | - @GetMapping("/demo03-course/list-by-student-id") | ||
| 139 | - @Operation(summary = "获得学生课程列表") | ||
| 140 | - @Parameter(name = "studentId", description = "学生编号") | ||
| 141 | - @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") | ||
| 142 | - public CommonResult<List<Demo03CourseDO>> getDemo03CourseListByStudentId(@RequestParam("studentId") Long studentId) { | ||
| 143 | - return success(demo03StudentService.getDemo03CourseListByStudentId(studentId)); | ||
| 144 | - } | ||
| 145 | - | ||
| 146 | // ==================== 子表(学生班级) ==================== | 156 | // ==================== 子表(学生班级) ==================== |
| 147 | 157 | ||
| 148 | @GetMapping("/demo03-grade/page") | 158 | @GetMapping("/demo03-grade/page") |
| @@ -178,6 +188,15 @@ public class Demo03StudentController { | @@ -178,6 +188,15 @@ public class Demo03StudentController { | ||
| 178 | return success(true); | 188 | return success(true); |
| 179 | } | 189 | } |
| 180 | 190 | ||
| 191 | + @DeleteMapping("/demo03-grade/delete-batch") | ||
| 192 | + @Parameter(name = "ids", description = "编号", required = true) | ||
| 193 | + @Operation(summary = "批量删除学生班级") | ||
| 194 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") | ||
| 195 | + public CommonResult<Boolean> deleteDemo03Grade(@RequestParam("ids") List<Long> ids) { | ||
| 196 | + demo03StudentService.deleteDemo03GradeByIds(ids); | ||
| 197 | + return success(true); | ||
| 198 | + } | ||
| 199 | + | ||
| 181 | @GetMapping("/demo03-grade/get") | 200 | @GetMapping("/demo03-grade/get") |
| 182 | @Operation(summary = "获得学生班级") | 201 | @Operation(summary = "获得学生班级") |
| 183 | @Parameter(name = "id", description = "编号", required = true) | 202 | @Parameter(name = "id", description = "编号", required = true) |
| @@ -186,12 +205,4 @@ public class Demo03StudentController { | @@ -186,12 +205,4 @@ public class Demo03StudentController { | ||
| 186 | return success(demo03StudentService.getDemo03Grade(id)); | 205 | return success(demo03StudentService.getDemo03Grade(id)); |
| 187 | } | 206 | } |
| 188 | 207 | ||
| 189 | - @GetMapping("/demo03-grade/get-by-student-id") | ||
| 190 | - @Operation(summary = "获得学生班级") | ||
| 191 | - @Parameter(name = "studentId", description = "学生编号") | ||
| 192 | - @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") | ||
| 193 | - public CommonResult<Demo03GradeDO> getDemo03GradeByStudentId(@RequestParam("studentId") Long studentId) { | ||
| 194 | - return success(demo03StudentService.getDemo03GradeByStudentId(studentId)); | ||
| 195 | - } | ||
| 196 | - | ||
| 197 | } | 208 | } |
| 198 | \ No newline at end of file | 209 | \ No newline at end of file |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/vo/Demo03StudentPageReqVO.java renamed to yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentPageReqVO.java
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/vo/Demo03StudentRespVO.java renamed to yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentRespVO.java
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/vo/Demo03StudentSaveReqVO.java renamed to yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentSaveReqVO.java
| 1 | -package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo; | 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo; |
| 2 | 2 | ||
| 3 | import io.swagger.v3.oas.annotations.media.Schema; | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | import lombok.*; | 4 | import lombok.*; |
| 5 | -import java.util.*; | ||
| 6 | import jakarta.validation.constraints.*; | 5 | import jakarta.validation.constraints.*; |
| 6 | + | ||
| 7 | import java.time.LocalDateTime; | 7 | import java.time.LocalDateTime; |
| 8 | -import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; | ||
| 9 | -import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; | ||
| 10 | 8 | ||
| 11 | @Schema(description = "管理后台 - 学生新增/修改 Request VO") | 9 | @Schema(description = "管理后台 - 学生新增/修改 Request VO") |
| 12 | @Data | 10 | @Data |
| @@ -31,9 +29,4 @@ public class Demo03StudentSaveReqVO { | @@ -31,9 +29,4 @@ public class Demo03StudentSaveReqVO { | ||
| 31 | @NotEmpty(message = "简介不能为空") | 29 | @NotEmpty(message = "简介不能为空") |
| 32 | private String description; | 30 | private String description; |
| 33 | 31 | ||
| 34 | - | ||
| 35 | - private List<Demo03CourseDO> demo03Courses; | ||
| 36 | - | ||
| 37 | - private Demo03GradeDO demo03Grade; | ||
| 38 | - | ||
| 39 | } | 32 | } |
| 40 | \ No newline at end of file | 33 | \ No newline at end of file |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/package-info.java deleted
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/Demo03CourseMapper.java renamed to yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03CourseMapper.java
| 1 | -package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03; | 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageParam; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| @@ -19,16 +19,16 @@ public interface Demo03CourseMapper extends BaseMapperX<Demo03CourseDO> { | @@ -19,16 +19,16 @@ public interface Demo03CourseMapper extends BaseMapperX<Demo03CourseDO> { | ||
| 19 | 19 | ||
| 20 | default PageResult<Demo03CourseDO> selectPage(PageParam reqVO, Long studentId) { | 20 | default PageResult<Demo03CourseDO> selectPage(PageParam reqVO, Long studentId) { |
| 21 | return selectPage(reqVO, new LambdaQueryWrapperX<Demo03CourseDO>() | 21 | return selectPage(reqVO, new LambdaQueryWrapperX<Demo03CourseDO>() |
| 22 | - .eq(Demo03CourseDO::getStudentId, studentId) | ||
| 23 | - .orderByDesc(Demo03CourseDO::getId)); | ||
| 24 | - } | ||
| 25 | - | ||
| 26 | - default List<Demo03CourseDO> selectListByStudentId(Long studentId) { | ||
| 27 | - return selectList(Demo03CourseDO::getStudentId, studentId); | 22 | + .eq(Demo03CourseDO::getStudentId, studentId) |
| 23 | + .orderByDesc(Demo03CourseDO::getId)); | ||
| 28 | } | 24 | } |
| 29 | 25 | ||
| 30 | default int deleteByStudentId(Long studentId) { | 26 | default int deleteByStudentId(Long studentId) { |
| 31 | return delete(Demo03CourseDO::getStudentId, studentId); | 27 | return delete(Demo03CourseDO::getStudentId, studentId); |
| 32 | } | 28 | } |
| 33 | 29 | ||
| 34 | -} | ||
| 35 | \ No newline at end of file | 30 | \ No newline at end of file |
| 31 | + default int deleteByStudentIds(List<Long> studentIds) { | ||
| 32 | + return delete(Demo03CourseDO::getStudentId, studentIds); | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | +} |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/Demo03GradeMapper.java renamed to yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03GradeMapper.java
| 1 | -package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03; | 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageParam; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| @@ -7,6 +7,8 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | @@ -7,6 +7,8 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | ||
| 7 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; | 7 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; |
| 8 | import org.apache.ibatis.annotations.Mapper; | 8 | import org.apache.ibatis.annotations.Mapper; |
| 9 | 9 | ||
| 10 | +import java.util.List; | ||
| 11 | + | ||
| 10 | /** | 12 | /** |
| 11 | * 学生班级 Mapper | 13 | * 学生班级 Mapper |
| 12 | * | 14 | * |
| @@ -17,16 +19,19 @@ public interface Demo03GradeMapper extends BaseMapperX<Demo03GradeDO> { | @@ -17,16 +19,19 @@ public interface Demo03GradeMapper extends BaseMapperX<Demo03GradeDO> { | ||
| 17 | 19 | ||
| 18 | default PageResult<Demo03GradeDO> selectPage(PageParam reqVO, Long studentId) { | 20 | default PageResult<Demo03GradeDO> selectPage(PageParam reqVO, Long studentId) { |
| 19 | return selectPage(reqVO, new LambdaQueryWrapperX<Demo03GradeDO>() | 21 | return selectPage(reqVO, new LambdaQueryWrapperX<Demo03GradeDO>() |
| 20 | - .eq(Demo03GradeDO::getStudentId, studentId) | ||
| 21 | - .orderByDesc(Demo03GradeDO::getId)); | 22 | + .eq(Demo03GradeDO::getStudentId, studentId) |
| 23 | + .orderByDesc(Demo03GradeDO::getId)); | ||
| 22 | } | 24 | } |
| 23 | - | ||
| 24 | - default Demo03GradeDO selectByStudentId(Long studentId) { | 25 | + default Demo03GradeDO selectByStudentId(Long studentId) { |
| 25 | return selectOne(Demo03GradeDO::getStudentId, studentId); | 26 | return selectOne(Demo03GradeDO::getStudentId, studentId); |
| 26 | - } | 27 | + } |
| 27 | 28 | ||
| 28 | default int deleteByStudentId(Long studentId) { | 29 | default int deleteByStudentId(Long studentId) { |
| 29 | return delete(Demo03GradeDO::getStudentId, studentId); | 30 | return delete(Demo03GradeDO::getStudentId, studentId); |
| 30 | } | 31 | } |
| 31 | 32 | ||
| 32 | -} | ||
| 33 | \ No newline at end of file | 33 | \ No newline at end of file |
| 34 | + default int deleteByStudentIds(List<Long> studentIds) { | ||
| 35 | + return delete(Demo03GradeDO::getStudentId, studentIds); | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | +} |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/Demo03StudentMapper.java renamed to yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/erp/Demo03StudentMapper.java
| 1 | -package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03; | 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | ||
| 5 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | ||
| 6 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.*; | ||
| 6 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; | 7 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; |
| 7 | import org.apache.ibatis.annotations.Mapper; | 8 | import org.apache.ibatis.annotations.Mapper; |
| 8 | -import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.*; | ||
| 9 | 9 | ||
| 10 | /** | 10 | /** |
| 11 | * 学生 Mapper | 11 | * 学生 Mapper |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants.java
| @@ -65,7 +65,8 @@ public interface ErrorCodeConstants { | @@ -65,7 +65,8 @@ public interface ErrorCodeConstants { | ||
| 65 | ErrorCode DEMO02_CATEGORY_NAME_DUPLICATE = new ErrorCode(1_001_201_005, "已经存在该名字的示例分类"); | 65 | ErrorCode DEMO02_CATEGORY_NAME_DUPLICATE = new ErrorCode(1_001_201_005, "已经存在该名字的示例分类"); |
| 66 | ErrorCode DEMO02_CATEGORY_PARENT_IS_CHILD = new ErrorCode(1_001_201_006, "不能设置自己的子示例分类为父示例分类"); | 66 | ErrorCode DEMO02_CATEGORY_PARENT_IS_CHILD = new ErrorCode(1_001_201_006, "不能设置自己的子示例分类为父示例分类"); |
| 67 | ErrorCode DEMO03_STUDENT_NOT_EXISTS = new ErrorCode(1_001_201_007, "学生不存在"); | 67 | ErrorCode DEMO03_STUDENT_NOT_EXISTS = new ErrorCode(1_001_201_007, "学生不存在"); |
| 68 | - ErrorCode DEMO03_GRADE_NOT_EXISTS = new ErrorCode(1_001_201_008, "学生班级不存在"); | ||
| 69 | - ErrorCode DEMO03_GRADE_EXISTS = new ErrorCode(1_001_201_009, "学生班级已存在"); | 68 | + ErrorCode DEMO03_COURSE_NOT_EXISTS = new ErrorCode(1_001_201_008, "学生课程不存在"); |
| 69 | + ErrorCode DEMO03_GRADE_NOT_EXISTS = new ErrorCode(1_001_201_009, "学生班级不存在"); | ||
| 70 | + ErrorCode DEMO03_GRADE_EXISTS = new ErrorCode(1_001_201_010, "学生班级已存在"); | ||
| 70 | 71 | ||
| 71 | } | 72 | } |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/Demo03StudentService.java renamed to yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/erp/Demo03StudentService.java
| 1 | -package cn.iocoder.yudao.module.infra.service.demo.demo03; | 1 | +package cn.iocoder.yudao.module.infra.service.demo.demo03.erp; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||
| 4 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 5 | -import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentPageReqVO; | ||
| 6 | -import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentSaveReqVO; | 3 | +import java.util.*; |
| 4 | +import jakarta.validation.*; | ||
| 5 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.*; | ||
| 6 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; | ||
| 7 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; | 7 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; |
| 8 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; | 8 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; |
| 9 | -import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; | ||
| 10 | - | ||
| 11 | -import jakarta.validation.Valid; | ||
| 12 | -import java.util.List; | 9 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 10 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||
| 13 | 11 | ||
| 14 | /** | 12 | /** |
| 15 | * 学生 Service 接口 | 13 | * 学生 Service 接口 |
| @@ -41,6 +39,13 @@ public interface Demo03StudentService { | @@ -41,6 +39,13 @@ public interface Demo03StudentService { | ||
| 41 | void deleteDemo03Student(Long id); | 39 | void deleteDemo03Student(Long id); |
| 42 | 40 | ||
| 43 | /** | 41 | /** |
| 42 | + * 批量删除学生 | ||
| 43 | + * | ||
| 44 | + * @param ids 编号 | ||
| 45 | + */ | ||
| 46 | + void deleteDemo03StudentByIds(List<Long> ids); | ||
| 47 | + | ||
| 48 | + /** | ||
| 44 | * 获得学生 | 49 | * 获得学生 |
| 45 | * | 50 | * |
| 46 | * @param id 编号 | 51 | * @param id 编号 |
| @@ -56,18 +61,9 @@ public interface Demo03StudentService { | @@ -56,18 +61,9 @@ public interface Demo03StudentService { | ||
| 56 | */ | 61 | */ |
| 57 | PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentPageReqVO pageReqVO); | 62 | PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentPageReqVO pageReqVO); |
| 58 | 63 | ||
| 59 | - | ||
| 60 | // ==================== 子表(学生课程) ==================== | 64 | // ==================== 子表(学生课程) ==================== |
| 61 | 65 | ||
| 62 | /** | 66 | /** |
| 63 | - * 获得学生课程列表 | ||
| 64 | - * | ||
| 65 | - * @param studentId 学生编号 | ||
| 66 | - * @return 学生课程列表 | ||
| 67 | - */ | ||
| 68 | - List<Demo03CourseDO> getDemo03CourseListByStudentId(Long studentId); | ||
| 69 | - | ||
| 70 | - /** | ||
| 71 | * 获得学生课程分页 | 67 | * 获得学生课程分页 |
| 72 | * | 68 | * |
| 73 | * @param pageReqVO 分页查询 | 69 | * @param pageReqVO 分页查询 |
| @@ -99,24 +95,23 @@ public interface Demo03StudentService { | @@ -99,24 +95,23 @@ public interface Demo03StudentService { | ||
| 99 | void deleteDemo03Course(Long id); | 95 | void deleteDemo03Course(Long id); |
| 100 | 96 | ||
| 101 | /** | 97 | /** |
| 102 | - * 获得学生课程 | ||
| 103 | - * | ||
| 104 | - * @param id 编号 | 98 | + * 批量删除学生课程 |
| 99 | + * | ||
| 100 | + * @param ids 编号 | ||
| 101 | + */ | ||
| 102 | + void deleteDemo03CourseByIds(List<Long> ids); | ||
| 103 | + | ||
| 104 | + /** | ||
| 105 | + * 获得学生课程 | ||
| 106 | + * | ||
| 107 | + * @param id 编号 | ||
| 105 | * @return 学生课程 | 108 | * @return 学生课程 |
| 106 | - */ | 109 | + */ |
| 107 | Demo03CourseDO getDemo03Course(Long id); | 110 | Demo03CourseDO getDemo03Course(Long id); |
| 108 | 111 | ||
| 109 | // ==================== 子表(学生班级) ==================== | 112 | // ==================== 子表(学生班级) ==================== |
| 110 | 113 | ||
| 111 | /** | 114 | /** |
| 112 | - * 获得学生班级 | ||
| 113 | - * | ||
| 114 | - * @param studentId 学生编号 | ||
| 115 | - * @return 学生班级 | ||
| 116 | - */ | ||
| 117 | - Demo03GradeDO getDemo03GradeByStudentId(Long studentId); | ||
| 118 | - | ||
| 119 | - /** | ||
| 120 | * 获得学生班级分页 | 115 | * 获得学生班级分页 |
| 121 | * | 116 | * |
| 122 | * @param pageReqVO 分页查询 | 117 | * @param pageReqVO 分页查询 |
| @@ -148,11 +143,18 @@ public interface Demo03StudentService { | @@ -148,11 +143,18 @@ public interface Demo03StudentService { | ||
| 148 | void deleteDemo03Grade(Long id); | 143 | void deleteDemo03Grade(Long id); |
| 149 | 144 | ||
| 150 | /** | 145 | /** |
| 151 | - * 获得学生班级 | ||
| 152 | - * | ||
| 153 | - * @param id 编号 | 146 | + * 批量删除学生班级 |
| 147 | + * | ||
| 148 | + * @param ids 编号 | ||
| 149 | + */ | ||
| 150 | + void deleteDemo03GradeByIds(List<Long> ids); | ||
| 151 | + | ||
| 152 | + /** | ||
| 153 | + * 获得学生班级 | ||
| 154 | + * | ||
| 155 | + * @param id 编号 | ||
| 154 | * @return 学生班级 | 156 | * @return 学生班级 |
| 155 | - */ | 157 | + */ |
| 156 | Demo03GradeDO getDemo03Grade(Long id); | 158 | Demo03GradeDO getDemo03Grade(Long id); |
| 157 | 159 | ||
| 158 | } | 160 | } |
| 159 | \ No newline at end of file | 161 | \ No newline at end of file |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/Demo03StudentServiceImpl.java renamed to yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/erp/Demo03StudentServiceImpl.java
| 1 | -package cn.iocoder.yudao.module.infra.service.demo.demo03; | 1 | +package cn.iocoder.yudao.module.infra.service.demo.demo03.erp; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageParam; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 6 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 6 | -import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentPageReqVO; | ||
| 7 | -import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentSaveReqVO; | 7 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentPageReqVO; |
| 8 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentSaveReqVO; | ||
| 8 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; | 9 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; |
| 9 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; | 10 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; |
| 10 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; | 11 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; |
| 11 | -import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.Demo03CourseMapper; | ||
| 12 | -import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.Demo03GradeMapper; | ||
| 13 | -import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.Demo03StudentMapper; | 12 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp.Demo03CourseMapper; |
| 13 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp.Demo03GradeMapper; | ||
| 14 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp.Demo03StudentMapper; | ||
| 15 | +import jakarta.annotation.Resource; | ||
| 14 | import org.springframework.stereotype.Service; | 16 | import org.springframework.stereotype.Service; |
| 15 | import org.springframework.transaction.annotation.Transactional; | 17 | import org.springframework.transaction.annotation.Transactional; |
| 16 | import org.springframework.validation.annotation.Validated; | 18 | import org.springframework.validation.annotation.Validated; |
| 17 | 19 | ||
| 18 | -import jakarta.annotation.Resource; | ||
| 19 | import java.util.List; | 20 | import java.util.List; |
| 20 | 21 | ||
| 21 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 22 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| @@ -38,31 +39,21 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { | @@ -38,31 +39,21 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { | ||
| 38 | private Demo03GradeMapper demo03GradeMapper; | 39 | private Demo03GradeMapper demo03GradeMapper; |
| 39 | 40 | ||
| 40 | @Override | 41 | @Override |
| 41 | - @Transactional(rollbackFor = Exception.class) | ||
| 42 | public Long createDemo03Student(Demo03StudentSaveReqVO createReqVO) { | 42 | public Long createDemo03Student(Demo03StudentSaveReqVO createReqVO) { |
| 43 | // 插入 | 43 | // 插入 |
| 44 | Demo03StudentDO demo03Student = BeanUtils.toBean(createReqVO, Demo03StudentDO.class); | 44 | Demo03StudentDO demo03Student = BeanUtils.toBean(createReqVO, Demo03StudentDO.class); |
| 45 | demo03StudentMapper.insert(demo03Student); | 45 | demo03StudentMapper.insert(demo03Student); |
| 46 | - | ||
| 47 | - // 插入子表 | ||
| 48 | - createDemo03CourseList(demo03Student.getId(), createReqVO.getDemo03Courses()); | ||
| 49 | - createDemo03Grade(demo03Student.getId(), createReqVO.getDemo03Grade()); | ||
| 50 | // 返回 | 46 | // 返回 |
| 51 | return demo03Student.getId(); | 47 | return demo03Student.getId(); |
| 52 | } | 48 | } |
| 53 | 49 | ||
| 54 | @Override | 50 | @Override |
| 55 | - @Transactional(rollbackFor = Exception.class) | ||
| 56 | public void updateDemo03Student(Demo03StudentSaveReqVO updateReqVO) { | 51 | public void updateDemo03Student(Demo03StudentSaveReqVO updateReqVO) { |
| 57 | // 校验存在 | 52 | // 校验存在 |
| 58 | validateDemo03StudentExists(updateReqVO.getId()); | 53 | validateDemo03StudentExists(updateReqVO.getId()); |
| 59 | // 更新 | 54 | // 更新 |
| 60 | Demo03StudentDO updateObj = BeanUtils.toBean(updateReqVO, Demo03StudentDO.class); | 55 | Demo03StudentDO updateObj = BeanUtils.toBean(updateReqVO, Demo03StudentDO.class); |
| 61 | demo03StudentMapper.updateById(updateObj); | 56 | demo03StudentMapper.updateById(updateObj); |
| 62 | - | ||
| 63 | - // 更新子表 | ||
| 64 | - updateDemo03CourseList(updateReqVO.getId(), updateReqVO.getDemo03Courses()); | ||
| 65 | - updateDemo03Grade(updateReqVO.getId(), updateReqVO.getDemo03Grade()); | ||
| 66 | } | 57 | } |
| 67 | 58 | ||
| 68 | @Override | 59 | @Override |
| @@ -78,6 +69,26 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { | @@ -78,6 +69,26 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { | ||
| 78 | deleteDemo03GradeByStudentId(id); | 69 | deleteDemo03GradeByStudentId(id); |
| 79 | } | 70 | } |
| 80 | 71 | ||
| 72 | + @Override | ||
| 73 | + @Transactional(rollbackFor = Exception.class) | ||
| 74 | + public void deleteDemo03StudentByIds(List<Long> ids) { | ||
| 75 | + // 校验存在 | ||
| 76 | + validateDemo03StudentExists(ids); | ||
| 77 | + // 删除 | ||
| 78 | + demo03StudentMapper.deleteByIds(ids); | ||
| 79 | + | ||
| 80 | + // 删除子表 | ||
| 81 | + deleteDemo03CourseByStudentIds(ids); | ||
| 82 | + deleteDemo03GradeByStudentIds(ids); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + private void validateDemo03StudentExists(List<Long> ids) { | ||
| 86 | + List<Demo03StudentDO> list = demo03StudentMapper.selectByIds(ids); | ||
| 87 | + if (CollUtil.isEmpty(list) || list.size() != ids.size()) { | ||
| 88 | + throw exception(DEMO03_STUDENT_NOT_EXISTS); | ||
| 89 | + } | ||
| 90 | + } | ||
| 91 | + | ||
| 81 | private void validateDemo03StudentExists(Long id) { | 92 | private void validateDemo03StudentExists(Long id) { |
| 82 | if (demo03StudentMapper.selectById(id) == null) { | 93 | if (demo03StudentMapper.selectById(id) == null) { |
| 83 | throw exception(DEMO03_STUDENT_NOT_EXISTS); | 94 | throw exception(DEMO03_STUDENT_NOT_EXISTS); |
| @@ -97,28 +108,6 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { | @@ -97,28 +108,6 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { | ||
| 97 | // ==================== 子表(学生课程) ==================== | 108 | // ==================== 子表(学生课程) ==================== |
| 98 | 109 | ||
| 99 | @Override | 110 | @Override |
| 100 | - public List<Demo03CourseDO> getDemo03CourseListByStudentId(Long studentId) { | ||
| 101 | - return demo03CourseMapper.selectListByStudentId(studentId); | ||
| 102 | - } | ||
| 103 | - | ||
| 104 | - private void createDemo03CourseList(Long studentId, List<Demo03CourseDO> list) { | ||
| 105 | - if (list != null) { | ||
| 106 | - list.forEach(o -> o.setStudentId(studentId)); | ||
| 107 | - } | ||
| 108 | - demo03CourseMapper.insertBatch(list); | ||
| 109 | - } | ||
| 110 | - | ||
| 111 | - private void updateDemo03CourseList(Long studentId, List<Demo03CourseDO> list) { | ||
| 112 | - deleteDemo03CourseByStudentId(studentId); | ||
| 113 | - list.forEach(o -> o.setId(null).setUpdater(null).setUpdateTime(null)); // 解决更新情况下:1)id 冲突;2)updateTime 不更新 | ||
| 114 | - createDemo03CourseList(studentId, list); | ||
| 115 | - } | ||
| 116 | - | ||
| 117 | - private void deleteDemo03CourseByStudentId(Long studentId) { | ||
| 118 | - demo03CourseMapper.deleteByStudentId(studentId); | ||
| 119 | - } | ||
| 120 | - | ||
| 121 | - @Override | ||
| 122 | public PageResult<Demo03CourseDO> getDemo03CoursePage(PageParam pageReqVO, Long studentId) { | 111 | public PageResult<Demo03CourseDO> getDemo03CoursePage(PageParam pageReqVO, Long studentId) { |
| 123 | return demo03CourseMapper.selectPage(pageReqVO, studentId); | 112 | return demo03CourseMapper.selectPage(pageReqVO, studentId); |
| 124 | } | 113 | } |
| @@ -131,47 +120,57 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { | @@ -131,47 +120,57 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { | ||
| 131 | 120 | ||
| 132 | @Override | 121 | @Override |
| 133 | public void updateDemo03Course(Demo03CourseDO demo03Course) { | 122 | public void updateDemo03Course(Demo03CourseDO demo03Course) { |
| 123 | + // 校验存在 | ||
| 124 | + validateDemo03CourseExists(demo03Course.getId()); | ||
| 125 | + // 更新 | ||
| 126 | + demo03Course.setUpdater(null).setUpdateTime(null); // 解决更新情况下:updateTime 不更新 | ||
| 134 | demo03CourseMapper.updateById(demo03Course); | 127 | demo03CourseMapper.updateById(demo03Course); |
| 135 | } | 128 | } |
| 136 | 129 | ||
| 137 | @Override | 130 | @Override |
| 138 | public void deleteDemo03Course(Long id) { | 131 | public void deleteDemo03Course(Long id) { |
| 132 | + // 校验存在 | ||
| 133 | + validateDemo03CourseExists(id); | ||
| 134 | + // 删除 | ||
| 139 | demo03CourseMapper.deleteById(id); | 135 | demo03CourseMapper.deleteById(id); |
| 140 | } | 136 | } |
| 141 | 137 | ||
| 142 | @Override | 138 | @Override |
| 143 | - public Demo03CourseDO getDemo03Course(Long id) { | ||
| 144 | - return demo03CourseMapper.selectById(id); | 139 | + public void deleteDemo03CourseByIds(List<Long> ids) { |
| 140 | + // 校验存在 | ||
| 141 | + validateDemo03CourseExists(ids); | ||
| 142 | + // 删除 | ||
| 143 | + demo03CourseMapper.deleteByIds(ids); | ||
| 145 | } | 144 | } |
| 146 | 145 | ||
| 147 | - // ==================== 子表(学生班级) ==================== | ||
| 148 | - | ||
| 149 | @Override | 146 | @Override |
| 150 | - public Demo03GradeDO getDemo03GradeByStudentId(Long studentId) { | ||
| 151 | - return demo03GradeMapper.selectByStudentId(studentId); | 147 | + public Demo03CourseDO getDemo03Course(Long id) { |
| 148 | + return demo03CourseMapper.selectById(id); | ||
| 152 | } | 149 | } |
| 153 | 150 | ||
| 154 | - private void createDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) { | ||
| 155 | - if (demo03Grade == null) { | ||
| 156 | - return; | 151 | + private void validateDemo03CourseExists(Long id) { |
| 152 | + if (demo03CourseMapper.selectById(id) == null) { | ||
| 153 | + throw exception(DEMO03_COURSE_NOT_EXISTS); | ||
| 157 | } | 154 | } |
| 158 | - demo03Grade.setStudentId(studentId); | ||
| 159 | - demo03GradeMapper.insert(demo03Grade); | ||
| 160 | } | 155 | } |
| 161 | 156 | ||
| 162 | - private void updateDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) { | ||
| 163 | - if (demo03Grade == null) { | ||
| 164 | - return; | 157 | + private void validateDemo03CourseExists(List<Long> ids) { |
| 158 | + List<Demo03CourseDO> list = demo03CourseMapper.selectByIds(ids); | ||
| 159 | + if (CollUtil.isEmpty(list) || list.size() != ids.size()) { | ||
| 160 | + throw exception(DEMO03_COURSE_NOT_EXISTS); | ||
| 165 | } | 161 | } |
| 166 | - demo03Grade.setStudentId(studentId); | ||
| 167 | - demo03Grade.setUpdater(null).setUpdateTime(null); // 解决更新情况下:updateTime 不更新 | ||
| 168 | - demo03GradeMapper.insertOrUpdate(demo03Grade); | ||
| 169 | } | 162 | } |
| 170 | 163 | ||
| 171 | - private void deleteDemo03GradeByStudentId(Long studentId) { | ||
| 172 | - demo03GradeMapper.deleteByStudentId(studentId); | 164 | + private void deleteDemo03CourseByStudentId(Long studentId) { |
| 165 | + demo03CourseMapper.deleteByStudentId(studentId); | ||
| 173 | } | 166 | } |
| 174 | 167 | ||
| 168 | + private void deleteDemo03CourseByStudentIds(List<Long> studentIds) { | ||
| 169 | + demo03CourseMapper.deleteByStudentIds(studentIds); | ||
| 170 | + } | ||
| 171 | + | ||
| 172 | + // ==================== 子表(学生班级) ==================== | ||
| 173 | + | ||
| 175 | @Override | 174 | @Override |
| 176 | public PageResult<Demo03GradeDO> getDemo03GradePage(PageParam pageReqVO, Long studentId) { | 175 | public PageResult<Demo03GradeDO> getDemo03GradePage(PageParam pageReqVO, Long studentId) { |
| 177 | return demo03GradeMapper.selectPage(pageReqVO, studentId); | 176 | return demo03GradeMapper.selectPage(pageReqVO, studentId); |
| @@ -183,6 +182,7 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { | @@ -183,6 +182,7 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { | ||
| 183 | if (demo03GradeMapper.selectByStudentId(demo03Grade.getStudentId()) != null) { | 182 | if (demo03GradeMapper.selectByStudentId(demo03Grade.getStudentId()) != null) { |
| 184 | throw exception(DEMO03_GRADE_EXISTS); | 183 | throw exception(DEMO03_GRADE_EXISTS); |
| 185 | } | 184 | } |
| 185 | + // 插入 | ||
| 186 | demo03GradeMapper.insert(demo03Grade); | 186 | demo03GradeMapper.insert(demo03Grade); |
| 187 | return demo03Grade.getId(); | 187 | return demo03Grade.getId(); |
| 188 | } | 188 | } |
| @@ -192,6 +192,7 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { | @@ -192,6 +192,7 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { | ||
| 192 | // 校验存在 | 192 | // 校验存在 |
| 193 | validateDemo03GradeExists(demo03Grade.getId()); | 193 | validateDemo03GradeExists(demo03Grade.getId()); |
| 194 | // 更新 | 194 | // 更新 |
| 195 | + demo03Grade.setUpdater(null).setUpdateTime(null); // 解决更新情况下:updateTime 不更新 | ||
| 195 | demo03GradeMapper.updateById(demo03Grade); | 196 | demo03GradeMapper.updateById(demo03Grade); |
| 196 | } | 197 | } |
| 197 | 198 | ||
| @@ -204,6 +205,14 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { | @@ -204,6 +205,14 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { | ||
| 204 | } | 205 | } |
| 205 | 206 | ||
| 206 | @Override | 207 | @Override |
| 208 | + public void deleteDemo03GradeByIds(List<Long> ids) { | ||
| 209 | + // 校验存在 | ||
| 210 | + validateDemo03GradeExists(ids); | ||
| 211 | + // 删除 | ||
| 212 | + demo03GradeMapper.deleteByIds(ids); | ||
| 213 | + } | ||
| 214 | + | ||
| 215 | + @Override | ||
| 207 | public Demo03GradeDO getDemo03Grade(Long id) { | 216 | public Demo03GradeDO getDemo03Grade(Long id) { |
| 208 | return demo03GradeMapper.selectById(id); | 217 | return demo03GradeMapper.selectById(id); |
| 209 | } | 218 | } |
| @@ -214,4 +223,19 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { | @@ -214,4 +223,19 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { | ||
| 214 | } | 223 | } |
| 215 | } | 224 | } |
| 216 | 225 | ||
| 226 | + private void validateDemo03GradeExists(List<Long> ids) { | ||
| 227 | + List<Demo03GradeDO> list = demo03GradeMapper.selectByIds(ids); | ||
| 228 | + if (CollUtil.isEmpty(list) || list.size() != ids.size()) { | ||
| 229 | + throw exception(DEMO03_GRADE_NOT_EXISTS); | ||
| 230 | + } | ||
| 231 | + } | ||
| 232 | + | ||
| 233 | + private void deleteDemo03GradeByStudentId(Long studentId) { | ||
| 234 | + demo03GradeMapper.deleteByStudentId(studentId); | ||
| 235 | + } | ||
| 236 | + | ||
| 237 | + private void deleteDemo03GradeByStudentIds(List<Long> studentIds) { | ||
| 238 | + demo03GradeMapper.deleteByStudentIds(studentIds); | ||
| 239 | + } | ||
| 240 | + | ||
| 217 | } | 241 | } |
| 218 | \ No newline at end of file | 242 | \ No newline at end of file |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/package-info.java
0 → 100644
yudao-module-infra/src/main/resources/codegen/java/controller/controller.vm
| @@ -81,7 +81,7 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { | @@ -81,7 +81,7 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { | ||
| 81 | #if ($sceneEnum.scene == 1) | 81 | #if ($sceneEnum.scene == 1) |
| 82 | @PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')") | 82 | @PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')") |
| 83 | #end | 83 | #end |
| 84 | - public CommonResult<Boolean> delete${simpleClassName}(@RequestParam("ids") @Size(max = 100, message = "最多允许100个") List<${primaryColumn.javaType}> ids) { | 84 | + public CommonResult<Boolean> delete${simpleClassName}(@RequestParam("ids") List<${primaryColumn.javaType}> ids) { |
| 85 | ${classNameVar}Service.delete${simpleClassName}ByIds(ids); | 85 | ${classNameVar}Service.delete${simpleClassName}ByIds(ids); |
| 86 | return success(true); | 86 | return success(true); |
| 87 | } | 87 | } |
| @@ -231,6 +231,19 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { | @@ -231,6 +231,19 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { | ||
| 231 | return success(true); | 231 | return success(true); |
| 232 | } | 232 | } |
| 233 | 233 | ||
| 234 | +#if ($table.deleteBatch) | ||
| 235 | + @DeleteMapping("/${subSimpleClassName_strikeCase}/delete-batch") | ||
| 236 | + @Parameter(name = "ids", description = "编号", required = true) | ||
| 237 | + @Operation(summary = "批量删除${subTable.classComment}") | ||
| 238 | +#if ($sceneEnum.scene == 1) | ||
| 239 | + @PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')") | ||
| 240 | +#end | ||
| 241 | + public CommonResult<Boolean> delete${subSimpleClassName}(@RequestParam("ids") List<${subPrimaryColumn.javaType}> ids) { | ||
| 242 | + ${classNameVar}Service.delete${subSimpleClassName}ByIds(ids); | ||
| 243 | + return success(true); | ||
| 244 | + } | ||
| 245 | +#end | ||
| 246 | + | ||
| 234 | @GetMapping("/${subSimpleClassName_strikeCase}/get") | 247 | @GetMapping("/${subSimpleClassName_strikeCase}/get") |
| 235 | @Operation(summary = "获得${subTable.classComment}") | 248 | @Operation(summary = "获得${subTable.classComment}") |
| 236 | @Parameter(name = "id", description = "编号", required = true) | 249 | @Parameter(name = "id", description = "编号", required = true) |
yudao-module-infra/src/main/resources/codegen/java/service/service.vm
| @@ -143,6 +143,15 @@ public interface ${table.className}Service { | @@ -143,6 +143,15 @@ public interface ${table.className}Service { | ||
| 143 | */ | 143 | */ |
| 144 | void delete${subSimpleClassName}(${subPrimaryColumn.javaType} id); | 144 | void delete${subSimpleClassName}(${subPrimaryColumn.javaType} id); |
| 145 | 145 | ||
| 146 | +#if ($table.deleteBatch) | ||
| 147 | + /** | ||
| 148 | + * 批量删除${subTable.classComment} | ||
| 149 | + * | ||
| 150 | + * @param ids 编号 | ||
| 151 | + */ | ||
| 152 | + void delete${subSimpleClassName}ByIds(List<${subPrimaryColumn.javaType}> ids); | ||
| 153 | +#end | ||
| 154 | + | ||
| 146 | /** | 155 | /** |
| 147 | * 获得${subTable.classComment} | 156 | * 获得${subTable.classComment} |
| 148 | * | 157 | * |
yudao-module-infra/src/main/resources/codegen/java/service/serviceImpl.vm
| @@ -332,6 +332,16 @@ public class ${table.className}ServiceImpl implements ${table.className}Service | @@ -332,6 +332,16 @@ public class ${table.className}ServiceImpl implements ${table.className}Service | ||
| 332 | ${subClassNameVars.get($index)}Mapper.deleteById(id); | 332 | ${subClassNameVars.get($index)}Mapper.deleteById(id); |
| 333 | } | 333 | } |
| 334 | 334 | ||
| 335 | +#if ($table.deleteBatch) | ||
| 336 | + @Override | ||
| 337 | + public void delete${subSimpleClassName}ByIds(List<${subPrimaryColumn.javaType}> ids) { | ||
| 338 | + // 校验存在 | ||
| 339 | + validate${subSimpleClassName}Exists(ids); | ||
| 340 | + // 删除 | ||
| 341 | + ${subClassNameVars.get($index)}Mapper.deleteByIds(ids); | ||
| 342 | + } | ||
| 343 | +#end | ||
| 344 | + | ||
| 335 | @Override | 345 | @Override |
| 336 | public ${subTable.className}DO get${subSimpleClassName}(${subPrimaryColumn.javaType} id) { | 346 | public ${subTable.className}DO get${subSimpleClassName}(${subPrimaryColumn.javaType} id) { |
| 337 | return ${subClassNameVars.get($index)}Mapper.selectById(id); | 347 | return ${subClassNameVars.get($index)}Mapper.selectById(id); |
| @@ -343,6 +353,15 @@ public class ${table.className}ServiceImpl implements ${table.className}Service | @@ -343,6 +353,15 @@ public class ${table.className}ServiceImpl implements ${table.className}Service | ||
| 343 | } | 353 | } |
| 344 | } | 354 | } |
| 345 | 355 | ||
| 356 | +#if ($table.deleteBatch) | ||
| 357 | + private void validate${subSimpleClassName}Exists(List<${subPrimaryColumn.javaType}> ids) { | ||
| 358 | + List<${subTable.className}DO> list = ${subClassNameVar}Mapper.selectByIds(ids); | ||
| 359 | + if (CollUtil.isEmpty(list) || list.size() != ids.size()) { | ||
| 360 | + throw exception(${simpleClassNameUnderlineCase.toUpperCase()}_NOT_EXISTS); | ||
| 361 | + } | ||
| 362 | + } | ||
| 363 | +#end | ||
| 364 | + | ||
| 346 | ## 情况二:非 MASTER_ERP 时,支持批量的新增、修改操作 | 365 | ## 情况二:非 MASTER_ERP 时,支持批量的新增、修改操作 |
| 347 | #else | 366 | #else |
| 348 | #if ( $subTable.subJoinMany) | 367 | #if ( $subTable.subJoinMany) |
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) { | @@ -151,6 +151,13 @@ export function delete${subSimpleClassName}(id: number) { | ||
| 151 | return requestClient.delete(`${baseURL}/${subSimpleClassName_strikeCase}/delete?id=${id}`); | 151 | return requestClient.delete(`${baseURL}/${subSimpleClassName_strikeCase}/delete?id=${id}`); |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | +#if ($table.deleteBatch) | ||
| 155 | +// 批量删除${subTable.classComment} | ||
| 156 | +export function delete${subSimpleClassName}ByIds(ids: number[]) { | ||
| 157 | + return requestClient.delete(`${baseURL}/${subSimpleClassName_strikeCase}/delete-batch?ids=${ids.join(',')}`) | ||
| 158 | +} | ||
| 159 | +#end | ||
| 160 | + | ||
| 154 | /** 获得${subTable.classComment} */ | 161 | /** 获得${subTable.classComment} */ |
| 155 | export function get${subSimpleClassName}(id: number) { | 162 | export function get${subSimpleClassName}(id: number) { |
| 156 | return requestClient.get<${simpleClassName}Api.${subSimpleClassName}>(`${baseURL}/${subSimpleClassName_strikeCase}/get?id=${id}`); | 163 | return requestClient.get<${simpleClassName}Api.${subSimpleClassName}>(`${baseURL}/${subSimpleClassName_strikeCase}/get?id=${id}`); |
yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/data.ts.vm
| @@ -431,6 +431,9 @@ export function use${subSimpleClassName}GridColumns( | @@ -431,6 +431,9 @@ export function use${subSimpleClassName}GridColumns( | ||
| 431 | onActionClick?: OnActionClickFn<${simpleClassName}Api.${subSimpleClassName}>, | 431 | onActionClick?: OnActionClickFn<${simpleClassName}Api.${subSimpleClassName}>, |
| 432 | ): VxeTableGridOptions<${simpleClassName}Api.${subSimpleClassName}>['columns'] { | 432 | ): VxeTableGridOptions<${simpleClassName}Api.${subSimpleClassName}>['columns'] { |
| 433 | return [ | 433 | return [ |
| 434 | + #if ($table.templateType != 2 && $table.deleteBatch) | ||
| 435 | + { type: 'checkbox', width: 40 }, | ||
| 436 | + #end | ||
| 434 | #foreach($column in $subColumns) | 437 | #foreach($column in $subColumns) |
| 435 | #if ($column.listOperationResult) | 438 | #if ($column.listOperationResult) |
| 436 | #set ($dictType = $column.dictType) | 439 | #set ($dictType = $column.dictType) |
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'; | @@ -22,7 +22,7 @@ import { useVbenVxeGrid } from '#/adapter/vxe-table'; | ||
| 22 | #if (${table.templateType} == 2)## 树表接口 | 22 | #if (${table.templateType} == 2)## 树表接口 |
| 23 | import { get${simpleClassName}List, delete${simpleClassName}, export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}'; | 23 | import { get${simpleClassName}List, delete${simpleClassName}, export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}'; |
| 24 | #else## 标准表接口 | 24 | #else## 标准表接口 |
| 25 | -import { get${simpleClassName}Page, delete${simpleClassName},delete${simpleClassName}ByIds, export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}'; | 25 | +import { get${simpleClassName}Page, delete${simpleClassName},#if ($table.deleteBatch) delete${simpleClassName}ByIds,#end export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}'; |
| 26 | #end | 26 | #end |
| 27 | import { downloadFileFromBlobPart, isEmpty } from '@vben/utils'; | 27 | import { downloadFileFromBlobPart, isEmpty } from '@vben/utils'; |
| 28 | 28 |
yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/modules/list_sub_erp.vue.vm
| @@ -14,15 +14,16 @@ | @@ -14,15 +14,16 @@ | ||
| 14 | #end | 14 | #end |
| 15 | import { useVbenModal } from '@vben/common-ui'; | 15 | import { useVbenModal } from '@vben/common-ui'; |
| 16 | import { Button, message } from 'ant-design-vue'; | 16 | import { Button, message } from 'ant-design-vue'; |
| 17 | - import { Plus } from '@vben/icons'; | ||
| 18 | - import { #if($table.templateType != 11)ref,#end h, nextTick,watch } from 'vue'; | 17 | + import { Plus, Trash2 } from '@vben/icons'; |
| 18 | + import { ref, computed, h, nextTick,watch } from 'vue'; | ||
| 19 | import { $t } from '#/locales'; | 19 | import { $t } from '#/locales'; |
| 20 | import { useVbenVxeGrid } from '#/adapter/vxe-table'; | 20 | import { useVbenVxeGrid } from '#/adapter/vxe-table'; |
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | #if ($table.templateType == 11) ## erp | 23 | #if ($table.templateType == 11) ## erp |
| 24 | - import { delete${subSimpleClassName}, get${subSimpleClassName}Page } from '#/api/${table.moduleName}/${table.businessName}'; | 24 | + import { delete${subSimpleClassName},#if ($table.deleteBatch) delete${subSimpleClassName}ByIds,#end get${subSimpleClassName}Page } from '#/api/${table.moduleName}/${table.businessName}'; |
| 25 | import { use${subSimpleClassName}GridFormSchema, use${subSimpleClassName}GridColumns } from '../data'; | 25 | import { use${subSimpleClassName}GridFormSchema, use${subSimpleClassName}GridColumns } from '../data'; |
| 26 | + import { isEmpty } from '@vben/utils'; | ||
| 26 | #else | 27 | #else |
| 27 | #if ($subTable.subJoinMany) ## 一对多 | 28 | #if ($subTable.subJoinMany) ## 一对多 |
| 28 | import { get${subSimpleClassName}ListBy${SubJoinColumnName} } from '#/api/${table.moduleName}/${table.businessName}'; | 29 | import { get${subSimpleClassName}ListBy${SubJoinColumnName} } from '#/api/${table.moduleName}/${table.businessName}'; |
| @@ -67,11 +68,31 @@ async function onDelete(row: ${simpleClassName}Api.${subSimpleClassName}) { | @@ -67,11 +68,31 @@ async function onDelete(row: ${simpleClassName}Api.${subSimpleClassName}) { | ||
| 67 | await delete${subSimpleClassName}(row.id as number); | 68 | await delete${subSimpleClassName}(row.id as number); |
| 68 | message.success( $t('ui.actionMessage.deleteSuccess', [row.id]) ); | 69 | message.success( $t('ui.actionMessage.deleteSuccess', [row.id]) ); |
| 69 | onRefresh(); | 70 | onRefresh(); |
| 70 | - } catch { | 71 | + } finally { |
| 71 | hideLoading(); | 72 | hideLoading(); |
| 72 | } | 73 | } |
| 73 | } | 74 | } |
| 74 | 75 | ||
| 76 | +#if ($table.deleteBatch) | ||
| 77 | +const deleteIds = ref<number[]>([]) // 待删除${subTable.classComment} ID | ||
| 78 | +const showDeleteBatchBtn = computed(() => isEmpty(deleteIds.value)); | ||
| 79 | +/** 批量删除${subTable.classComment} */ | ||
| 80 | +async function onDeleteBatch() { | ||
| 81 | + const hideLoading = message.loading({ | ||
| 82 | + content: $t('ui.actionMessage.deleting'), | ||
| 83 | + duration: 0, | ||
| 84 | + key: 'action_process_msg', | ||
| 85 | + }); | ||
| 86 | + try { | ||
| 87 | + await delete${subSimpleClassName}ByIds(deleteIds.value); | ||
| 88 | + message.success( $t('ui.actionMessage.deleteSuccess') ); | ||
| 89 | + onRefresh(); | ||
| 90 | + } finally { | ||
| 91 | + hideLoading(); | ||
| 92 | + } | ||
| 93 | +} | ||
| 94 | +#end | ||
| 95 | + | ||
| 75 | /** 表格操作按钮的回调函数 */ | 96 | /** 表格操作按钮的回调函数 */ |
| 76 | function onActionClick({ | 97 | function onActionClick({ |
| 77 | code, | 98 | code, |
| @@ -136,6 +157,16 @@ function onActionClick({ | @@ -136,6 +157,16 @@ function onActionClick({ | ||
| 136 | isHover: true, | 157 | isHover: true, |
| 137 | }, | 158 | }, |
| 138 | } as VxeTableGridOptions<${simpleClassName}Api.${subSimpleClassName}>, | 159 | } as VxeTableGridOptions<${simpleClassName}Api.${subSimpleClassName}>, |
| 160 | + #if (${table.templateType} == 11 && $table.deleteBatch) | ||
| 161 | + gridEvents:{ | ||
| 162 | + checkboxAll: ({records,}: { records: ${simpleClassName}Api.${subSimpleClassName}[];}) => { | ||
| 163 | + deleteIds.value = records.map((item) => item.id); | ||
| 164 | + }, | ||
| 165 | + checkboxChange: ({records,}: { records: ${simpleClassName}Api.${subSimpleClassName}[];}) => { | ||
| 166 | + deleteIds.value = records.map((item) => item.id); | ||
| 167 | + }, | ||
| 168 | + } | ||
| 169 | + #end | ||
| 139 | }); | 170 | }); |
| 140 | 171 | ||
| 141 | /** 刷新表格 */ | 172 | /** 刷新表格 */ |
| @@ -173,6 +204,19 @@ const onRefresh = async ()=> { | @@ -173,6 +204,19 @@ const onRefresh = async ()=> { | ||
| 173 | <Button :icon="h(Plus)" type="primary" @click="onCreate" v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:create']"> | 204 | <Button :icon="h(Plus)" type="primary" @click="onCreate" v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:create']"> |
| 174 | {{ $t('ui.actionTitle.create', ['${subTable.classComment}']) }} | 205 | {{ $t('ui.actionTitle.create', ['${subTable.classComment}']) }} |
| 175 | </Button> | 206 | </Button> |
| 207 | + #if ($table.templateType == 11 && $table.deleteBatch) | ||
| 208 | + <Button | ||
| 209 | + :icon="h(Trash2)" | ||
| 210 | + type="primary" | ||
| 211 | + danger | ||
| 212 | + class="ml-2" | ||
| 213 | + :disabled="showDeleteBatchBtn" | ||
| 214 | + @click="onDeleteBatch" | ||
| 215 | + v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:delete']" | ||
| 216 | + > | ||
| 217 | + 批量删除 | ||
| 218 | + </Button> | ||
| 219 | + #end | ||
| 176 | </template> | 220 | </template> |
| 177 | </Grid> | 221 | </Grid> |
| 178 | #else | 222 | #else |