Commit d14aaae641f0b361e2a3b3c0d932e438d04017d0
Committed by
Gitee
!1348 feat:【INFRA 基础设施】vben5-antd-schema 代码生成时,可生成批量删除
Merge pull request !1348 from puhui999/vben5-antd-schema
Showing
54 changed files
with
1809 additions
and
254 deletions
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo01/Demo01ContactController.java
| ... | ... | @@ -60,6 +60,15 @@ public class Demo01ContactController { |
| 60 | 60 | return success(true); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | + @DeleteMapping("/delete-batch") | |
| 64 | + @Parameter(name = "ids", description = "编号", required = true) | |
| 65 | + @Operation(summary = "批量删除示例联系人") | |
| 66 | + @PreAuthorize("@ss.hasPermission('infra:demo01-contact:delete')") | |
| 67 | + public CommonResult<Boolean> deleteDemo01Contact(@RequestParam("ids") List<Long> ids) { | |
| 68 | + demo01ContactService.deleteDemo01ContactByIds(ids); | |
| 69 | + return success(true); | |
| 70 | + } | |
| 71 | + | |
| 63 | 72 | @GetMapping("/get") |
| 64 | 73 | @Operation(summary = "获得示例联系人") |
| 65 | 74 | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| ... | ... | @@ -82,12 +91,12 @@ public class Demo01ContactController { |
| 82 | 91 | @PreAuthorize("@ss.hasPermission('infra:demo01-contact:export')") |
| 83 | 92 | @ApiAccessLog(operateType = EXPORT) |
| 84 | 93 | public void exportDemo01ContactExcel(@Valid Demo01ContactPageReqVO pageReqVO, |
| 85 | - HttpServletResponse response) throws IOException { | |
| 94 | + HttpServletResponse response) throws IOException { | |
| 86 | 95 | pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); |
| 87 | 96 | List<Demo01ContactDO> list = demo01ContactService.getDemo01ContactPage(pageReqVO).getList(); |
| 88 | 97 | // 导出 Excel |
| 89 | 98 | ExcelUtils.write(response, "示例联系人.xls", "数据", Demo01ContactRespVO.class, |
| 90 | - BeanUtils.toBean(list, Demo01ContactRespVO.class)); | |
| 99 | + BeanUtils.toBean(list, Demo01ContactRespVO.class)); | |
| 91 | 100 | } |
| 92 | 101 | |
| 93 | 102 | } |
| 94 | 103 | \ No newline at end of file | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo01/vo/Demo01ContactPageReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo; |
| 2 | 2 | |
| 3 | -import lombok.*; | |
| 4 | -import java.util.*; | |
| 5 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 6 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 4 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 5 | +import lombok.Data; | |
| 6 | +import lombok.EqualsAndHashCode; | |
| 7 | +import lombok.ToString; | |
| 7 | 8 | import org.springframework.format.annotation.DateTimeFormat; |
| 9 | + | |
| 8 | 10 | import java.time.LocalDateTime; |
| 9 | 11 | |
| 10 | 12 | import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo01/vo/Demo01ContactRespVO.java
| 1 | 1 | package cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo; |
| 2 | 2 | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.*; | |
| 5 | -import java.util.*; | |
| 6 | -import java.util.*; | |
| 7 | -import org.springframework.format.annotation.DateTimeFormat; | |
| 8 | -import java.time.LocalDateTime; | |
| 9 | -import com.alibaba.excel.annotation.*; | |
| 10 | 3 | import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; |
| 11 | 4 | import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; |
| 5 | +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; | |
| 6 | +import com.alibaba.excel.annotation.ExcelProperty; | |
| 7 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 8 | +import lombok.Data; | |
| 9 | + | |
| 10 | +import java.time.LocalDateTime; | |
| 12 | 11 | |
| 13 | 12 | @Schema(description = "管理后台 - 示例联系人 Response VO") |
| 14 | 13 | @Data | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo01/vo/Demo01ContactSaveReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo; |
| 2 | 2 | |
| 3 | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | -import lombok.Data; | |
| 5 | - | |
| 6 | 4 | import jakarta.validation.constraints.NotEmpty; |
| 7 | 5 | import jakarta.validation.constraints.NotNull; |
| 6 | +import lombok.Data; | |
| 7 | + | |
| 8 | 8 | import java.time.LocalDateTime; |
| 9 | 9 | |
| 10 | 10 | @Schema(description = "管理后台 - 示例联系人新增/修改 Request VO") | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo02/Demo02CategoryController.java
| ... | ... | @@ -80,11 +80,11 @@ public class Demo02CategoryController { |
| 80 | 80 | @PreAuthorize("@ss.hasPermission('infra:demo02-category:export')") |
| 81 | 81 | @ApiAccessLog(operateType = EXPORT) |
| 82 | 82 | public void exportDemo02CategoryExcel(@Valid Demo02CategoryListReqVO listReqVO, |
| 83 | - HttpServletResponse response) throws IOException { | |
| 83 | + HttpServletResponse response) throws IOException { | |
| 84 | 84 | List<Demo02CategoryDO> list = demo02CategoryService.getDemo02CategoryList(listReqVO); |
| 85 | 85 | // 导出 Excel |
| 86 | 86 | ExcelUtils.write(response, "示例分类.xls", "数据", Demo02CategoryRespVO.class, |
| 87 | - BeanUtils.toBean(list, Demo02CategoryRespVO.class)); | |
| 87 | + BeanUtils.toBean(list, Demo02CategoryRespVO.class)); | |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | } |
| 91 | 91 | \ No newline at end of file | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo02/vo/Demo02CategorySaveReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.infra.controller.admin.demo.demo02.vo; |
| 2 | 2 | |
| 3 | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | -import lombok.Data; | |
| 5 | - | |
| 6 | 4 | import jakarta.validation.constraints.NotEmpty; |
| 7 | 5 | import jakarta.validation.constraints.NotNull; |
| 6 | +import lombok.Data; | |
| 8 | 7 | |
| 9 | 8 | @Schema(description = "管理后台 - 示例分类新增/修改 Request VO") |
| 10 | 9 | @Data | ... | ... |
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/Demo03StudentErpController.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 | 3 | import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| ... | ... | @@ -6,13 +6,13 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 6 | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | 7 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 8 | 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.Demo03StudentErpPageReqVO; | |
| 10 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpRespVO; | |
| 11 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpSaveReqVO; | |
| 12 | 12 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; |
| 13 | 13 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; |
| 14 | 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.Demo03StudentErpService; | |
| 16 | 16 | import io.swagger.v3.oas.annotations.Operation; |
| 17 | 17 | import io.swagger.v3.oas.annotations.Parameter; |
| 18 | 18 | import io.swagger.v3.oas.annotations.tags.Tag; |
| ... | ... | @@ -31,25 +31,25 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 31 | 31 | |
| 32 | 32 | @Tag(name = "管理后台 - 学生") |
| 33 | 33 | @RestController |
| 34 | -@RequestMapping("/infra/demo03-student") | |
| 34 | +@RequestMapping("/infra/demo03-student-erp") | |
| 35 | 35 | @Validated |
| 36 | -public class Demo03StudentController { | |
| 36 | +public class Demo03StudentErpController { | |
| 37 | 37 | |
| 38 | 38 | @Resource |
| 39 | - private Demo03StudentService demo03StudentService; | |
| 39 | + private Demo03StudentErpService demo03StudentErpService; | |
| 40 | 40 | |
| 41 | 41 | @PostMapping("/create") |
| 42 | 42 | @Operation(summary = "创建学生") |
| 43 | 43 | @PreAuthorize("@ss.hasPermission('infra:demo03-student:create')") |
| 44 | - public CommonResult<Long> createDemo03Student(@Valid @RequestBody Demo03StudentSaveReqVO createReqVO) { | |
| 45 | - return success(demo03StudentService.createDemo03Student(createReqVO)); | |
| 44 | + public CommonResult<Long> createDemo03Student(@Valid @RequestBody Demo03StudentErpSaveReqVO createReqVO) { | |
| 45 | + return success(demo03StudentErpService.createDemo03Student(createReqVO)); | |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | @PutMapping("/update") |
| 49 | 49 | @Operation(summary = "更新学生") |
| 50 | 50 | @PreAuthorize("@ss.hasPermission('infra:demo03-student:update')") |
| 51 | - public CommonResult<Boolean> updateDemo03Student(@Valid @RequestBody Demo03StudentSaveReqVO updateReqVO) { | |
| 52 | - demo03StudentService.updateDemo03Student(updateReqVO); | |
| 51 | + public CommonResult<Boolean> updateDemo03Student(@Valid @RequestBody Demo03StudentErpSaveReqVO updateReqVO) { | |
| 52 | + demo03StudentErpService.updateDemo03Student(updateReqVO); | |
| 53 | 53 | return success(true); |
| 54 | 54 | } |
| 55 | 55 | |
| ... | ... | @@ -58,7 +58,16 @@ public class Demo03StudentController { |
| 58 | 58 | @Parameter(name = "id", description = "编号", required = true) |
| 59 | 59 | @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") |
| 60 | 60 | public CommonResult<Boolean> deleteDemo03Student(@RequestParam("id") Long id) { |
| 61 | - demo03StudentService.deleteDemo03Student(id); | |
| 61 | + demo03StudentErpService.deleteDemo03Student(id); | |
| 62 | + return success(true); | |
| 63 | + } | |
| 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 | + demo03StudentErpService.deleteDemo03StudentByIds(ids); | |
| 62 | 71 | return success(true); |
| 63 | 72 | } |
| 64 | 73 | |
| ... | ... | @@ -66,30 +75,30 @@ public class Demo03StudentController { |
| 66 | 75 | @Operation(summary = "获得学生") |
| 67 | 76 | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| 68 | 77 | @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") |
| 69 | - public CommonResult<Demo03StudentRespVO> getDemo03Student(@RequestParam("id") Long id) { | |
| 70 | - Demo03StudentDO demo03Student = demo03StudentService.getDemo03Student(id); | |
| 71 | - return success(BeanUtils.toBean(demo03Student, Demo03StudentRespVO.class)); | |
| 78 | + public CommonResult<Demo03StudentErpRespVO> getDemo03Student(@RequestParam("id") Long id) { | |
| 79 | + Demo03StudentDO demo03Student = demo03StudentErpService.getDemo03Student(id); | |
| 80 | + return success(BeanUtils.toBean(demo03Student, Demo03StudentErpRespVO.class)); | |
| 72 | 81 | } |
| 73 | 82 | |
| 74 | 83 | @GetMapping("/page") |
| 75 | 84 | @Operation(summary = "获得学生分页") |
| 76 | 85 | @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") |
| 77 | - public CommonResult<PageResult<Demo03StudentRespVO>> getDemo03StudentPage(@Valid Demo03StudentPageReqVO pageReqVO) { | |
| 78 | - PageResult<Demo03StudentDO> pageResult = demo03StudentService.getDemo03StudentPage(pageReqVO); | |
| 79 | - return success(BeanUtils.toBean(pageResult, Demo03StudentRespVO.class)); | |
| 86 | + public CommonResult<PageResult<Demo03StudentErpRespVO>> getDemo03StudentPage(@Valid Demo03StudentErpPageReqVO pageReqVO) { | |
| 87 | + PageResult<Demo03StudentDO> pageResult = demo03StudentErpService.getDemo03StudentPage(pageReqVO); | |
| 88 | + return success(BeanUtils.toBean(pageResult, Demo03StudentErpRespVO.class)); | |
| 80 | 89 | } |
| 81 | 90 | |
| 82 | 91 | @GetMapping("/export-excel") |
| 83 | 92 | @Operation(summary = "导出学生 Excel") |
| 84 | 93 | @PreAuthorize("@ss.hasPermission('infra:demo03-student:export')") |
| 85 | 94 | @ApiAccessLog(operateType = EXPORT) |
| 86 | - public void exportDemo03StudentExcel(@Valid Demo03StudentPageReqVO pageReqVO, | |
| 87 | - HttpServletResponse response) throws IOException { | |
| 95 | + public void exportDemo03StudentExcel(@Valid Demo03StudentErpPageReqVO pageReqVO, | |
| 96 | + HttpServletResponse response) throws IOException { | |
| 88 | 97 | pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); |
| 89 | - List<Demo03StudentDO> list = demo03StudentService.getDemo03StudentPage(pageReqVO).getList(); | |
| 98 | + List<Demo03StudentDO> list = demo03StudentErpService.getDemo03StudentPage(pageReqVO).getList(); | |
| 90 | 99 | // 导出 Excel |
| 91 | - ExcelUtils.write(response, "学生.xls", "数据", Demo03StudentRespVO.class, | |
| 92 | - BeanUtils.toBean(list, Demo03StudentRespVO.class)); | |
| 100 | + ExcelUtils.write(response, "学生.xls", "数据", Demo03StudentErpRespVO.class, | |
| 101 | + BeanUtils.toBean(list, Demo03StudentErpRespVO.class)); | |
| 93 | 102 | } |
| 94 | 103 | |
| 95 | 104 | // ==================== 子表(学生课程) ==================== |
| ... | ... | @@ -100,21 +109,21 @@ public class Demo03StudentController { |
| 100 | 109 | @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") |
| 101 | 110 | public CommonResult<PageResult<Demo03CourseDO>> getDemo03CoursePage(PageParam pageReqVO, |
| 102 | 111 | @RequestParam("studentId") Long studentId) { |
| 103 | - return success(demo03StudentService.getDemo03CoursePage(pageReqVO, studentId)); | |
| 112 | + return success(demo03StudentErpService.getDemo03CoursePage(pageReqVO, studentId)); | |
| 104 | 113 | } |
| 105 | 114 | |
| 106 | 115 | @PostMapping("/demo03-course/create") |
| 107 | 116 | @Operation(summary = "创建学生课程") |
| 108 | 117 | @PreAuthorize("@ss.hasPermission('infra:demo03-student:create')") |
| 109 | 118 | public CommonResult<Long> createDemo03Course(@Valid @RequestBody Demo03CourseDO demo03Course) { |
| 110 | - return success(demo03StudentService.createDemo03Course(demo03Course)); | |
| 119 | + return success(demo03StudentErpService.createDemo03Course(demo03Course)); | |
| 111 | 120 | } |
| 112 | 121 | |
| 113 | 122 | @PutMapping("/demo03-course/update") |
| 114 | 123 | @Operation(summary = "更新学生课程") |
| 115 | 124 | @PreAuthorize("@ss.hasPermission('infra:demo03-student:update')") |
| 116 | 125 | public CommonResult<Boolean> updateDemo03Course(@Valid @RequestBody Demo03CourseDO demo03Course) { |
| 117 | - demo03StudentService.updateDemo03Course(demo03Course); | |
| 126 | + demo03StudentErpService.updateDemo03Course(demo03Course); | |
| 118 | 127 | return success(true); |
| 119 | 128 | } |
| 120 | 129 | |
| ... | ... | @@ -123,7 +132,16 @@ public class Demo03StudentController { |
| 123 | 132 | @Operation(summary = "删除学生课程") |
| 124 | 133 | @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") |
| 125 | 134 | public CommonResult<Boolean> deleteDemo03Course(@RequestParam("id") Long id) { |
| 126 | - demo03StudentService.deleteDemo03Course(id); | |
| 135 | + demo03StudentErpService.deleteDemo03Course(id); | |
| 136 | + return success(true); | |
| 137 | + } | |
| 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 | + demo03StudentErpService.deleteDemo03CourseByIds(ids); | |
| 127 | 145 | return success(true); |
| 128 | 146 | } |
| 129 | 147 | |
| ... | ... | @@ -132,15 +150,7 @@ public class Demo03StudentController { |
| 132 | 150 | @Parameter(name = "id", description = "编号", required = true) |
| 133 | 151 | @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") |
| 134 | 152 | public CommonResult<Demo03CourseDO> getDemo03Course(@RequestParam("id") Long id) { |
| 135 | - return success(demo03StudentService.getDemo03Course(id)); | |
| 136 | - } | |
| 137 | - | |
| 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)); | |
| 153 | + return success(demo03StudentErpService.getDemo03Course(id)); | |
| 144 | 154 | } |
| 145 | 155 | |
| 146 | 156 | // ==================== 子表(学生班级) ==================== |
| ... | ... | @@ -151,21 +161,21 @@ public class Demo03StudentController { |
| 151 | 161 | @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") |
| 152 | 162 | public CommonResult<PageResult<Demo03GradeDO>> getDemo03GradePage(PageParam pageReqVO, |
| 153 | 163 | @RequestParam("studentId") Long studentId) { |
| 154 | - return success(demo03StudentService.getDemo03GradePage(pageReqVO, studentId)); | |
| 164 | + return success(demo03StudentErpService.getDemo03GradePage(pageReqVO, studentId)); | |
| 155 | 165 | } |
| 156 | 166 | |
| 157 | 167 | @PostMapping("/demo03-grade/create") |
| 158 | 168 | @Operation(summary = "创建学生班级") |
| 159 | 169 | @PreAuthorize("@ss.hasPermission('infra:demo03-student:create')") |
| 160 | 170 | public CommonResult<Long> createDemo03Grade(@Valid @RequestBody Demo03GradeDO demo03Grade) { |
| 161 | - return success(demo03StudentService.createDemo03Grade(demo03Grade)); | |
| 171 | + return success(demo03StudentErpService.createDemo03Grade(demo03Grade)); | |
| 162 | 172 | } |
| 163 | 173 | |
| 164 | 174 | @PutMapping("/demo03-grade/update") |
| 165 | 175 | @Operation(summary = "更新学生班级") |
| 166 | 176 | @PreAuthorize("@ss.hasPermission('infra:demo03-student:update')") |
| 167 | 177 | public CommonResult<Boolean> updateDemo03Grade(@Valid @RequestBody Demo03GradeDO demo03Grade) { |
| 168 | - demo03StudentService.updateDemo03Grade(demo03Grade); | |
| 178 | + demo03StudentErpService.updateDemo03Grade(demo03Grade); | |
| 169 | 179 | return success(true); |
| 170 | 180 | } |
| 171 | 181 | |
| ... | ... | @@ -174,7 +184,16 @@ public class Demo03StudentController { |
| 174 | 184 | @Operation(summary = "删除学生班级") |
| 175 | 185 | @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") |
| 176 | 186 | public CommonResult<Boolean> deleteDemo03Grade(@RequestParam("id") Long id) { |
| 177 | - demo03StudentService.deleteDemo03Grade(id); | |
| 187 | + demo03StudentErpService.deleteDemo03Grade(id); | |
| 188 | + return success(true); | |
| 189 | + } | |
| 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 | + demo03StudentErpService.deleteDemo03GradeByIds(ids); | |
| 178 | 197 | return success(true); |
| 179 | 198 | } |
| 180 | 199 | |
| ... | ... | @@ -183,15 +202,7 @@ public class Demo03StudentController { |
| 183 | 202 | @Parameter(name = "id", description = "编号", required = true) |
| 184 | 203 | @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") |
| 185 | 204 | public CommonResult<Demo03GradeDO> getDemo03Grade(@RequestParam("id") Long id) { |
| 186 | - return success(demo03StudentService.getDemo03Grade(id)); | |
| 187 | - } | |
| 188 | - | |
| 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)); | |
| 205 | + return success(demo03StudentErpService.getDemo03Grade(id)); | |
| 195 | 206 | } |
| 196 | 207 | |
| 197 | 208 | } |
| 198 | 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/Demo03StudentErpPageReqVO.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 lombok.*; | |
| 4 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 5 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 4 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 5 | +import lombok.Data; | |
| 6 | +import lombok.EqualsAndHashCode; | |
| 7 | +import lombok.ToString; | |
| 6 | 8 | import org.springframework.format.annotation.DateTimeFormat; |
| 9 | + | |
| 7 | 10 | import java.time.LocalDateTime; |
| 8 | 11 | |
| 9 | 12 | import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; |
| ... | ... | @@ -12,7 +15,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ |
| 12 | 15 | @Data |
| 13 | 16 | @EqualsAndHashCode(callSuper = true) |
| 14 | 17 | @ToString(callSuper = true) |
| 15 | -public class Demo03StudentPageReqVO extends PageParam { | |
| 18 | +public class Demo03StudentErpPageReqVO extends PageParam { | |
| 16 | 19 | |
| 17 | 20 | @Schema(description = "名字", example = "芋艿") |
| 18 | 21 | private String name; | ... | ... |
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/Demo03StudentErpRespVO.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 cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | |
| 4 | +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | |
| 5 | +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; | |
| 6 | +import com.alibaba.excel.annotation.ExcelProperty; | |
| 3 | 7 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | -import lombok.*; | |
| 8 | +import lombok.Data; | |
| 5 | 9 | |
| 6 | 10 | import java.time.LocalDateTime; |
| 7 | -import com.alibaba.excel.annotation.*; | |
| 8 | -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | |
| 9 | -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | |
| 10 | 11 | |
| 11 | 12 | @Schema(description = "管理后台 - 学生 Response VO") |
| 12 | 13 | @Data |
| 13 | 14 | @ExcelIgnoreUnannotated |
| 14 | -public class Demo03StudentRespVO { | |
| 15 | +public class Demo03StudentErpRespVO { | |
| 15 | 16 | |
| 16 | 17 | @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525") |
| 17 | 18 | @ExcelProperty("编号") | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentErpSaveReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import jakarta.validation.constraints.NotEmpty; | |
| 5 | +import jakarta.validation.constraints.NotNull; | |
| 6 | +import lombok.Data; | |
| 7 | + | |
| 8 | +import java.time.LocalDateTime; | |
| 9 | + | |
| 10 | +@Schema(description = "管理后台 - 学生新增/修改 Request VO") | |
| 11 | +@Data | |
| 12 | +public class Demo03StudentErpSaveReqVO { | |
| 13 | + | |
| 14 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525") | |
| 15 | + private Long id; | |
| 16 | + | |
| 17 | + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") | |
| 18 | + @NotEmpty(message = "名字不能为空") | |
| 19 | + private String name; | |
| 20 | + | |
| 21 | + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 22 | + @NotNull(message = "性别不能为空") | |
| 23 | + private Integer sex; | |
| 24 | + | |
| 25 | + @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 26 | + @NotNull(message = "出生日期不能为空") | |
| 27 | + private LocalDateTime birthday; | |
| 28 | + | |
| 29 | + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "随便") | |
| 30 | + @NotEmpty(message = "简介不能为空") | |
| 31 | + private String description; | |
| 32 | + | |
| 33 | +} | |
| 0 | 34 | \ No newline at end of file | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/inner/Demo03StudentInnerController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; | |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 7 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 8 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | |
| 9 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerPageReqVO; | |
| 10 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerRespVO; | |
| 11 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerSaveReqVO; | |
| 12 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; | |
| 13 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; | |
| 14 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; | |
| 15 | +import cn.iocoder.yudao.module.infra.service.demo.demo03.inner.Demo03StudentInnerService; | |
| 16 | +import io.swagger.v3.oas.annotations.Operation; | |
| 17 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 18 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 19 | +import jakarta.annotation.Resource; | |
| 20 | +import jakarta.servlet.http.HttpServletResponse; | |
| 21 | +import jakarta.validation.Valid; | |
| 22 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 23 | +import org.springframework.validation.annotation.Validated; | |
| 24 | +import org.springframework.web.bind.annotation.*; | |
| 25 | + | |
| 26 | +import java.io.IOException; | |
| 27 | +import java.util.List; | |
| 28 | + | |
| 29 | +import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; | |
| 30 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 31 | + | |
| 32 | +@Tag(name = "管理后台 - 学生") | |
| 33 | +@RestController | |
| 34 | +@RequestMapping("/infra/demo03-student-inner") | |
| 35 | +@Validated | |
| 36 | +public class Demo03StudentInnerController { | |
| 37 | + | |
| 38 | + @Resource | |
| 39 | + private Demo03StudentInnerService demo03StudentInnerService; | |
| 40 | + | |
| 41 | + @PostMapping("/create") | |
| 42 | + @Operation(summary = "创建学生") | |
| 43 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:create')") | |
| 44 | + public CommonResult<Long> createDemo03Student(@Valid @RequestBody Demo03StudentInnerSaveReqVO createReqVO) { | |
| 45 | + return success(demo03StudentInnerService.createDemo03Student(createReqVO)); | |
| 46 | + } | |
| 47 | + | |
| 48 | + @PutMapping("/update") | |
| 49 | + @Operation(summary = "更新学生") | |
| 50 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:update')") | |
| 51 | + public CommonResult<Boolean> updateDemo03Student(@Valid @RequestBody Demo03StudentInnerSaveReqVO updateReqVO) { | |
| 52 | + demo03StudentInnerService.updateDemo03Student(updateReqVO); | |
| 53 | + return success(true); | |
| 54 | + } | |
| 55 | + | |
| 56 | + @DeleteMapping("/delete") | |
| 57 | + @Operation(summary = "删除学生") | |
| 58 | + @Parameter(name = "id", description = "编号", required = true) | |
| 59 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") | |
| 60 | + public CommonResult<Boolean> deleteDemo03Student(@RequestParam("id") Long id) { | |
| 61 | + demo03StudentInnerService.deleteDemo03Student(id); | |
| 62 | + return success(true); | |
| 63 | + } | |
| 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 | + demo03StudentInnerService.deleteDemo03StudentByIds(ids); | |
| 71 | + return success(true); | |
| 72 | + } | |
| 73 | + | |
| 74 | + @GetMapping("/get") | |
| 75 | + @Operation(summary = "获得学生") | |
| 76 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | |
| 77 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") | |
| 78 | + public CommonResult<Demo03StudentInnerRespVO> getDemo03Student(@RequestParam("id") Long id) { | |
| 79 | + Demo03StudentDO demo03Student = demo03StudentInnerService.getDemo03Student(id); | |
| 80 | + return success(BeanUtils.toBean(demo03Student, Demo03StudentInnerRespVO.class)); | |
| 81 | + } | |
| 82 | + | |
| 83 | + @GetMapping("/page") | |
| 84 | + @Operation(summary = "获得学生分页") | |
| 85 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") | |
| 86 | + public CommonResult<PageResult<Demo03StudentInnerRespVO>> getDemo03StudentPage(@Valid Demo03StudentInnerPageReqVO pageReqVO) { | |
| 87 | + PageResult<Demo03StudentDO> pageResult = demo03StudentInnerService.getDemo03StudentPage(pageReqVO); | |
| 88 | + return success(BeanUtils.toBean(pageResult, Demo03StudentInnerRespVO.class)); | |
| 89 | + } | |
| 90 | + | |
| 91 | + @GetMapping("/export-excel") | |
| 92 | + @Operation(summary = "导出学生 Excel") | |
| 93 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:export')") | |
| 94 | + @ApiAccessLog(operateType = EXPORT) | |
| 95 | + public void exportDemo03StudentExcel(@Valid Demo03StudentInnerPageReqVO pageReqVO, | |
| 96 | + HttpServletResponse response) throws IOException { | |
| 97 | + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | |
| 98 | + List<Demo03StudentDO> list = demo03StudentInnerService.getDemo03StudentPage(pageReqVO).getList(); | |
| 99 | + // 导出 Excel | |
| 100 | + ExcelUtils.write(response, "学生.xls", "数据", Demo03StudentInnerRespVO.class, | |
| 101 | + BeanUtils.toBean(list, Demo03StudentInnerRespVO.class)); | |
| 102 | + } | |
| 103 | + | |
| 104 | + // ==================== 子表(学生课程) ==================== | |
| 105 | + | |
| 106 | + @GetMapping("/demo03-course/list-by-student-id") | |
| 107 | + @Operation(summary = "获得学生课程列表") | |
| 108 | + @Parameter(name = "studentId", description = "学生编号") | |
| 109 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") | |
| 110 | + public CommonResult<List<Demo03CourseDO>> getDemo03CourseListByStudentId(@RequestParam("studentId") Long studentId) { | |
| 111 | + return success(demo03StudentInnerService.getDemo03CourseListByStudentId(studentId)); | |
| 112 | + } | |
| 113 | + | |
| 114 | + // ==================== 子表(学生班级) ==================== | |
| 115 | + | |
| 116 | + @GetMapping("/demo03-grade/get-by-student-id") | |
| 117 | + @Operation(summary = "获得学生班级") | |
| 118 | + @Parameter(name = "studentId", description = "学生编号") | |
| 119 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") | |
| 120 | + public CommonResult<Demo03GradeDO> getDemo03GradeByStudentId(@RequestParam("studentId") Long studentId) { | |
| 121 | + return success(demo03StudentInnerService.getDemo03GradeByStudentId(studentId)); | |
| 122 | + } | |
| 123 | + | |
| 124 | +} | |
| 0 | 125 | \ No newline at end of file | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/inner/vo/Demo03StudentInnerPageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 4 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 5 | +import lombok.Data; | |
| 6 | +import lombok.EqualsAndHashCode; | |
| 7 | +import lombok.ToString; | |
| 8 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 9 | + | |
| 10 | +import java.time.LocalDateTime; | |
| 11 | + | |
| 12 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 13 | + | |
| 14 | +@Schema(description = "管理后台 - 学生分页 Request VO") | |
| 15 | +@Data | |
| 16 | +@EqualsAndHashCode(callSuper = true) | |
| 17 | +@ToString(callSuper = true) | |
| 18 | +public class Demo03StudentInnerPageReqVO extends PageParam { | |
| 19 | + | |
| 20 | + @Schema(description = "名字", example = "芋艿") | |
| 21 | + private String name; | |
| 22 | + | |
| 23 | + @Schema(description = "性别") | |
| 24 | + private Integer sex; | |
| 25 | + | |
| 26 | + @Schema(description = "简介", example = "随便") | |
| 27 | + private String description; | |
| 28 | + | |
| 29 | + @Schema(description = "创建时间") | |
| 30 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 31 | + private LocalDateTime[] createTime; | |
| 32 | + | |
| 33 | +} | |
| 0 | 34 | \ No newline at end of file | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/inner/vo/Demo03StudentInnerRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | |
| 4 | +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | |
| 5 | +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; | |
| 6 | +import com.alibaba.excel.annotation.ExcelProperty; | |
| 7 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 8 | +import lombok.Data; | |
| 9 | + | |
| 10 | +import java.time.LocalDateTime; | |
| 11 | + | |
| 12 | +@Schema(description = "管理后台 - 学生 Response VO") | |
| 13 | +@Data | |
| 14 | +@ExcelIgnoreUnannotated | |
| 15 | +public class Demo03StudentInnerRespVO { | |
| 16 | + | |
| 17 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525") | |
| 18 | + @ExcelProperty("编号") | |
| 19 | + private Long id; | |
| 20 | + | |
| 21 | + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") | |
| 22 | + @ExcelProperty("名字") | |
| 23 | + private String name; | |
| 24 | + | |
| 25 | + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 26 | + @ExcelProperty(value = "性别", converter = DictConvert.class) | |
| 27 | + @DictFormat("system_user_sex") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 | |
| 28 | + private Integer sex; | |
| 29 | + | |
| 30 | + @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 31 | + @ExcelProperty("出生日期") | |
| 32 | + private LocalDateTime birthday; | |
| 33 | + | |
| 34 | + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "随便") | |
| 35 | + @ExcelProperty("简介") | |
| 36 | + private String description; | |
| 37 | + | |
| 38 | + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 39 | + @ExcelProperty("创建时间") | |
| 40 | + private LocalDateTime createTime; | |
| 41 | + | |
| 42 | +} | |
| 0 | 43 | \ No newline at end of file | ... | ... |
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/inner/vo/Demo03StudentInnerSaveReqVO.java
| 1 | -package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo; | |
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo; | |
| 2 | 2 | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.*; | |
| 5 | -import java.util.*; | |
| 6 | -import jakarta.validation.constraints.*; | |
| 7 | -import java.time.LocalDateTime; | |
| 8 | 3 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; |
| 9 | 4 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; |
| 5 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 6 | +import jakarta.validation.constraints.NotEmpty; | |
| 7 | +import jakarta.validation.constraints.NotNull; | |
| 8 | +import lombok.Data; | |
| 9 | + | |
| 10 | +import java.time.LocalDateTime; | |
| 11 | +import java.util.List; | |
| 10 | 12 | |
| 11 | 13 | @Schema(description = "管理后台 - 学生新增/修改 Request VO") |
| 12 | 14 | @Data |
| 13 | -public class Demo03StudentSaveReqVO { | |
| 15 | +public class Demo03StudentInnerSaveReqVO { | |
| 14 | 16 | |
| 15 | 17 | @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525") |
| 16 | 18 | private Long id; |
| ... | ... | @@ -31,9 +33,10 @@ public class Demo03StudentSaveReqVO { |
| 31 | 33 | @NotEmpty(message = "简介不能为空") |
| 32 | 34 | private String description; |
| 33 | 35 | |
| 34 | - | |
| 36 | + @Schema(description = "学生课程列表") | |
| 35 | 37 | private List<Demo03CourseDO> demo03Courses; |
| 36 | 38 | |
| 39 | + @Schema(description = "学生班级") | |
| 37 | 40 | private Demo03GradeDO demo03Grade; |
| 38 | 41 | |
| 39 | 42 | } |
| 40 | 43 | \ No newline at end of file | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/normal/Demo03StudentNormalController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; | |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 7 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 8 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | |
| 9 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalPageReqVO; | |
| 10 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalRespVO; | |
| 11 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalSaveReqVO; | |
| 12 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; | |
| 13 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; | |
| 14 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; | |
| 15 | +import cn.iocoder.yudao.module.infra.service.demo.demo03.normal.Demo03StudentNormalService; | |
| 16 | +import io.swagger.v3.oas.annotations.Operation; | |
| 17 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 18 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 19 | +import jakarta.annotation.Resource; | |
| 20 | +import jakarta.servlet.http.HttpServletResponse; | |
| 21 | +import jakarta.validation.Valid; | |
| 22 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 23 | +import org.springframework.validation.annotation.Validated; | |
| 24 | +import org.springframework.web.bind.annotation.*; | |
| 25 | + | |
| 26 | +import java.io.IOException; | |
| 27 | +import java.util.List; | |
| 28 | + | |
| 29 | +import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; | |
| 30 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 31 | + | |
| 32 | +@Tag(name = "管理后台 - 学生") | |
| 33 | +@RestController | |
| 34 | +@RequestMapping("/infra/demo03-student-normal") | |
| 35 | +@Validated | |
| 36 | +public class Demo03StudentNormalController { | |
| 37 | + | |
| 38 | + @Resource | |
| 39 | + private Demo03StudentNormalService demo03StudentNormalService; | |
| 40 | + | |
| 41 | + @PostMapping("/create") | |
| 42 | + @Operation(summary = "创建学生") | |
| 43 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:create')") | |
| 44 | + public CommonResult<Long> createDemo03Student(@Valid @RequestBody Demo03StudentNormalSaveReqVO createReqVO) { | |
| 45 | + return success(demo03StudentNormalService.createDemo03Student(createReqVO)); | |
| 46 | + } | |
| 47 | + | |
| 48 | + @PutMapping("/update") | |
| 49 | + @Operation(summary = "更新学生") | |
| 50 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:update')") | |
| 51 | + public CommonResult<Boolean> updateDemo03Student(@Valid @RequestBody Demo03StudentNormalSaveReqVO updateReqVO) { | |
| 52 | + demo03StudentNormalService.updateDemo03Student(updateReqVO); | |
| 53 | + return success(true); | |
| 54 | + } | |
| 55 | + | |
| 56 | + @DeleteMapping("/delete") | |
| 57 | + @Operation(summary = "删除学生") | |
| 58 | + @Parameter(name = "id", description = "编号", required = true) | |
| 59 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") | |
| 60 | + public CommonResult<Boolean> deleteDemo03Student(@RequestParam("id") Long id) { | |
| 61 | + demo03StudentNormalService.deleteDemo03Student(id); | |
| 62 | + return success(true); | |
| 63 | + } | |
| 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 | + demo03StudentNormalService.deleteDemo03StudentByIds(ids); | |
| 71 | + return success(true); | |
| 72 | + } | |
| 73 | + | |
| 74 | + @GetMapping("/get") | |
| 75 | + @Operation(summary = "获得学生") | |
| 76 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | |
| 77 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") | |
| 78 | + public CommonResult<Demo03StudentNormalRespVO> getDemo03Student(@RequestParam("id") Long id) { | |
| 79 | + Demo03StudentDO demo03Student = demo03StudentNormalService.getDemo03Student(id); | |
| 80 | + return success(BeanUtils.toBean(demo03Student, Demo03StudentNormalRespVO.class)); | |
| 81 | + } | |
| 82 | + | |
| 83 | + @GetMapping("/page") | |
| 84 | + @Operation(summary = "获得学生分页") | |
| 85 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") | |
| 86 | + public CommonResult<PageResult<Demo03StudentNormalRespVO>> getDemo03StudentPage(@Valid Demo03StudentNormalPageReqVO pageReqVO) { | |
| 87 | + PageResult<Demo03StudentDO> pageResult = demo03StudentNormalService.getDemo03StudentPage(pageReqVO); | |
| 88 | + return success(BeanUtils.toBean(pageResult, Demo03StudentNormalRespVO.class)); | |
| 89 | + } | |
| 90 | + | |
| 91 | + @GetMapping("/export-excel") | |
| 92 | + @Operation(summary = "导出学生 Excel") | |
| 93 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:export')") | |
| 94 | + @ApiAccessLog(operateType = EXPORT) | |
| 95 | + public void exportDemo03StudentExcel(@Valid Demo03StudentNormalPageReqVO pageReqVO, | |
| 96 | + HttpServletResponse response) throws IOException { | |
| 97 | + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | |
| 98 | + List<Demo03StudentDO> list = demo03StudentNormalService.getDemo03StudentPage(pageReqVO).getList(); | |
| 99 | + // 导出 Excel | |
| 100 | + ExcelUtils.write(response, "学生.xls", "数据", Demo03StudentNormalRespVO.class, | |
| 101 | + BeanUtils.toBean(list, Demo03StudentNormalRespVO.class)); | |
| 102 | + } | |
| 103 | + | |
| 104 | + // ==================== 子表(学生课程) ==================== | |
| 105 | + | |
| 106 | + @GetMapping("/demo03-course/list-by-student-id") | |
| 107 | + @Operation(summary = "获得学生课程列表") | |
| 108 | + @Parameter(name = "studentId", description = "学生编号") | |
| 109 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") | |
| 110 | + public CommonResult<List<Demo03CourseDO>> getDemo03CourseListByStudentId(@RequestParam("studentId") Long studentId) { | |
| 111 | + return success(demo03StudentNormalService.getDemo03CourseListByStudentId(studentId)); | |
| 112 | + } | |
| 113 | + | |
| 114 | + // ==================== 子表(学生班级) ==================== | |
| 115 | + | |
| 116 | + @GetMapping("/demo03-grade/get-by-student-id") | |
| 117 | + @Operation(summary = "获得学生班级") | |
| 118 | + @Parameter(name = "studentId", description = "学生编号") | |
| 119 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") | |
| 120 | + public CommonResult<Demo03GradeDO> getDemo03GradeByStudentId(@RequestParam("studentId") Long studentId) { | |
| 121 | + return success(demo03StudentNormalService.getDemo03GradeByStudentId(studentId)); | |
| 122 | + } | |
| 123 | + | |
| 124 | +} | |
| 0 | 125 | \ No newline at end of file | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/normal/vo/Demo03StudentNormalPageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 4 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 5 | +import lombok.Data; | |
| 6 | +import lombok.EqualsAndHashCode; | |
| 7 | +import lombok.ToString; | |
| 8 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 9 | + | |
| 10 | +import java.time.LocalDateTime; | |
| 11 | + | |
| 12 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 13 | + | |
| 14 | +@Schema(description = "管理后台 - 学生分页 Request VO") | |
| 15 | +@Data | |
| 16 | +@EqualsAndHashCode(callSuper = true) | |
| 17 | +@ToString(callSuper = true) | |
| 18 | +public class Demo03StudentNormalPageReqVO extends PageParam { | |
| 19 | + | |
| 20 | + @Schema(description = "名字", example = "芋艿") | |
| 21 | + private String name; | |
| 22 | + | |
| 23 | + @Schema(description = "性别") | |
| 24 | + private Integer sex; | |
| 25 | + | |
| 26 | + @Schema(description = "简介", example = "随便") | |
| 27 | + private String description; | |
| 28 | + | |
| 29 | + @Schema(description = "创建时间") | |
| 30 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 31 | + private LocalDateTime[] createTime; | |
| 32 | + | |
| 33 | +} | |
| 0 | 34 | \ No newline at end of file | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/normal/vo/Demo03StudentNormalRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | |
| 4 | +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | |
| 5 | +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; | |
| 6 | +import com.alibaba.excel.annotation.ExcelProperty; | |
| 7 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 8 | +import lombok.Data; | |
| 9 | + | |
| 10 | +import java.time.LocalDateTime; | |
| 11 | + | |
| 12 | +@Schema(description = "管理后台 - 学生 Response VO") | |
| 13 | +@Data | |
| 14 | +@ExcelIgnoreUnannotated | |
| 15 | +public class Demo03StudentNormalRespVO { | |
| 16 | + | |
| 17 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525") | |
| 18 | + @ExcelProperty("编号") | |
| 19 | + private Long id; | |
| 20 | + | |
| 21 | + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") | |
| 22 | + @ExcelProperty("名字") | |
| 23 | + private String name; | |
| 24 | + | |
| 25 | + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 26 | + @ExcelProperty(value = "性别", converter = DictConvert.class) | |
| 27 | + @DictFormat("system_user_sex") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 | |
| 28 | + private Integer sex; | |
| 29 | + | |
| 30 | + @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 31 | + @ExcelProperty("出生日期") | |
| 32 | + private LocalDateTime birthday; | |
| 33 | + | |
| 34 | + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "随便") | |
| 35 | + @ExcelProperty("简介") | |
| 36 | + private String description; | |
| 37 | + | |
| 38 | + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 39 | + @ExcelProperty("创建时间") | |
| 40 | + private LocalDateTime createTime; | |
| 41 | + | |
| 42 | +} | |
| 0 | 43 | \ No newline at end of file | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/normal/vo/Demo03StudentNormalSaveReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; | |
| 4 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; | |
| 5 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 6 | +import jakarta.validation.constraints.NotEmpty; | |
| 7 | +import jakarta.validation.constraints.NotNull; | |
| 8 | +import lombok.Data; | |
| 9 | + | |
| 10 | +import java.time.LocalDateTime; | |
| 11 | +import java.util.List; | |
| 12 | + | |
| 13 | +@Schema(description = "管理后台 - 学生新增/修改 Request VO") | |
| 14 | +@Data | |
| 15 | +public class Demo03StudentNormalSaveReqVO { | |
| 16 | + | |
| 17 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525") | |
| 18 | + private Long id; | |
| 19 | + | |
| 20 | + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") | |
| 21 | + @NotEmpty(message = "名字不能为空") | |
| 22 | + private String name; | |
| 23 | + | |
| 24 | + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 25 | + @NotNull(message = "性别不能为空") | |
| 26 | + private Integer sex; | |
| 27 | + | |
| 28 | + @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 29 | + @NotNull(message = "出生日期不能为空") | |
| 30 | + private LocalDateTime birthday; | |
| 31 | + | |
| 32 | + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "随便") | |
| 33 | + @NotEmpty(message = "简介不能为空") | |
| 34 | + private String description; | |
| 35 | + | |
| 36 | + @Schema(description = "学生课程列表") | |
| 37 | + private List<Demo03CourseDO> demo03Courses; | |
| 38 | + | |
| 39 | + @Schema(description = "学生班级") | |
| 40 | + private Demo03GradeDO demo03Grade; | |
| 41 | + | |
| 42 | +} | |
| 0 | 43 | \ 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/demo01/Demo01ContactMapper.java
| 1 | 1 | package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo01; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 5 | 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 6 | 6 | import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.Demo01ContactPageReqVO; |
| 7 | 7 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo01.Demo01ContactDO; |
| 8 | 8 | import org.apache.ibatis.annotations.Mapper; | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo02/Demo02CategoryMapper.java
| 1 | 1 | package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo02; |
| 2 | 2 | |
| 3 | -import java.util.*; | |
| 4 | - | |
| 5 | -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 6 | 3 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 7 | 5 | import cn.iocoder.yudao.module.infra.controller.admin.demo.demo02.vo.Demo02CategoryListReqVO; |
| 8 | 6 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo02.Demo02CategoryDO; |
| 9 | 7 | import org.apache.ibatis.annotations.Mapper; |
| 10 | 8 | |
| 9 | +import java.util.List; | |
| 10 | + | |
| 11 | 11 | /** |
| 12 | 12 | * 示例分类 Mapper |
| 13 | 13 | * |
| ... | ... | @@ -24,9 +24,9 @@ public interface Demo02CategoryMapper extends BaseMapperX<Demo02CategoryDO> { |
| 24 | 24 | .orderByDesc(Demo02CategoryDO::getId)); |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - default Demo02CategoryDO selectByParentIdAndName(Long parentId, String name) { | |
| 28 | - return selectOne(Demo02CategoryDO::getParentId, parentId, Demo02CategoryDO::getName, name); | |
| 29 | - } | |
| 27 | + default Demo02CategoryDO selectByParentIdAndName(Long parentId, String name) { | |
| 28 | + return selectOne(Demo02CategoryDO::getParentId, parentId, Demo02CategoryDO::getName, name); | |
| 29 | + } | |
| 30 | 30 | |
| 31 | 31 | default Long selectCountByParentId(Long parentId) { |
| 32 | 32 | return selectCount(Demo02CategoryDO::getParentId, parentId); | ... | ... |
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/Demo03CourseErpMapper.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 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| ... | ... | @@ -15,7 +15,7 @@ import java.util.List; |
| 15 | 15 | * @author 芋道源码 |
| 16 | 16 | */ |
| 17 | 17 | @Mapper |
| 18 | -public interface Demo03CourseMapper extends BaseMapperX<Demo03CourseDO> { | |
| 18 | +public interface Demo03CourseErpMapper extends BaseMapperX<Demo03CourseDO> { | |
| 19 | 19 | |
| 20 | 20 | default PageResult<Demo03CourseDO> selectPage(PageParam reqVO, Long studentId) { |
| 21 | 21 | return selectPage(reqVO, new LambdaQueryWrapperX<Demo03CourseDO>() |
| ... | ... | @@ -23,12 +23,12 @@ public interface Demo03CourseMapper extends BaseMapperX<Demo03CourseDO> { |
| 23 | 23 | .orderByDesc(Demo03CourseDO::getId)); |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | - default List<Demo03CourseDO> selectListByStudentId(Long studentId) { | |
| 27 | - return selectList(Demo03CourseDO::getStudentId, studentId); | |
| 28 | - } | |
| 29 | - | |
| 30 | 26 | default int deleteByStudentId(Long studentId) { |
| 31 | 27 | return delete(Demo03CourseDO::getStudentId, studentId); |
| 32 | 28 | } |
| 33 | 29 | |
| 34 | -} | |
| 35 | 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/Demo03GradeErpMapper.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 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| ... | ... | @@ -7,13 +7,15 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 7 | 7 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; |
| 8 | 8 | import org.apache.ibatis.annotations.Mapper; |
| 9 | 9 | |
| 10 | +import java.util.List; | |
| 11 | + | |
| 10 | 12 | /** |
| 11 | 13 | * 学生班级 Mapper |
| 12 | 14 | * |
| 13 | 15 | * @author 芋道源码 |
| 14 | 16 | */ |
| 15 | 17 | @Mapper |
| 16 | -public interface Demo03GradeMapper extends BaseMapperX<Demo03GradeDO> { | |
| 18 | +public interface Demo03GradeErpMapper extends BaseMapperX<Demo03GradeDO> { | |
| 17 | 19 | |
| 18 | 20 | default PageResult<Demo03GradeDO> selectPage(PageParam reqVO, Long studentId) { |
| 19 | 21 | return selectPage(reqVO, new LambdaQueryWrapperX<Demo03GradeDO>() |
| ... | ... | @@ -29,4 +31,8 @@ public interface Demo03GradeMapper extends BaseMapperX<Demo03GradeDO> { |
| 29 | 31 | return delete(Demo03GradeDO::getStudentId, studentId); |
| 30 | 32 | } |
| 31 | 33 | |
| 32 | -} | |
| 33 | 34 | \ No newline at end of file |
| 35 | + default int deleteByStudentIds(List<Long> studentIds) { | |
| 36 | + return delete(Demo03GradeDO::getStudentId, studentIds); | |
| 37 | + } | |
| 38 | + | |
| 39 | +} | ... | ... |
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/Demo03StudentErpMapper.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 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 5 | 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.Demo03StudentErpPageReqVO; | |
| 6 | 7 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; |
| 7 | 8 | import org.apache.ibatis.annotations.Mapper; |
| 8 | -import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.*; | |
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * 学生 Mapper |
| ... | ... | @@ -13,9 +13,9 @@ import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.*; |
| 13 | 13 | * @author 芋道源码 |
| 14 | 14 | */ |
| 15 | 15 | @Mapper |
| 16 | -public interface Demo03StudentMapper extends BaseMapperX<Demo03StudentDO> { | |
| 16 | +public interface Demo03StudentErpMapper extends BaseMapperX<Demo03StudentDO> { | |
| 17 | 17 | |
| 18 | - default PageResult<Demo03StudentDO> selectPage(Demo03StudentPageReqVO reqVO) { | |
| 18 | + default PageResult<Demo03StudentDO> selectPage(Demo03StudentErpPageReqVO reqVO) { | |
| 19 | 19 | return selectPage(reqVO, new LambdaQueryWrapperX<Demo03StudentDO>() |
| 20 | 20 | .likeIfPresent(Demo03StudentDO::getName, reqVO.getName()) |
| 21 | 21 | .eqIfPresent(Demo03StudentDO::getSex, reqVO.getSex()) | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/inner/Demo03CourseInnerMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.inner; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 4 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; | |
| 5 | +import org.apache.ibatis.annotations.Mapper; | |
| 6 | + | |
| 7 | +import java.util.List; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * 学生课程 Mapper | |
| 11 | + * | |
| 12 | + * @author 芋道源码 | |
| 13 | + */ | |
| 14 | +@Mapper | |
| 15 | +public interface Demo03CourseInnerMapper extends BaseMapperX<Demo03CourseDO> { | |
| 16 | + | |
| 17 | + default List<Demo03CourseDO> selectListByStudentId(Long studentId) { | |
| 18 | + return selectList(Demo03CourseDO::getStudentId, studentId); | |
| 19 | + } | |
| 20 | + | |
| 21 | + default int deleteByStudentId(Long studentId) { | |
| 22 | + return delete(Demo03CourseDO::getStudentId, studentId); | |
| 23 | + } | |
| 24 | + | |
| 25 | + default int deleteByStudentIds(List<Long> studentIds) { | |
| 26 | + return delete(Demo03CourseDO::getStudentId, studentIds); | |
| 27 | + } | |
| 28 | + | |
| 29 | +} | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/inner/Demo03GradeInnerMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.inner; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 4 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; | |
| 5 | +import org.apache.ibatis.annotations.Mapper; | |
| 6 | + | |
| 7 | +import java.util.List; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * 学生班级 Mapper | |
| 11 | + * | |
| 12 | + * @author 芋道源码 | |
| 13 | + */ | |
| 14 | +@Mapper | |
| 15 | +public interface Demo03GradeInnerMapper extends BaseMapperX<Demo03GradeDO> { | |
| 16 | + | |
| 17 | + default Demo03GradeDO selectByStudentId(Long studentId) { | |
| 18 | + return selectOne(Demo03GradeDO::getStudentId, studentId); | |
| 19 | + } | |
| 20 | + | |
| 21 | + default int deleteByStudentId(Long studentId) { | |
| 22 | + return delete(Demo03GradeDO::getStudentId, studentId); | |
| 23 | + } | |
| 24 | + | |
| 25 | + default int deleteByStudentIds(List<Long> studentIds) { | |
| 26 | + return delete(Demo03GradeDO::getStudentId, studentIds); | |
| 27 | + } | |
| 28 | + | |
| 29 | +} | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/inner/Demo03StudentInnerMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.inner; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 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.inner.vo.Demo03StudentInnerPageReqVO; | |
| 7 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; | |
| 8 | +import org.apache.ibatis.annotations.Mapper; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 学生 Mapper | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@Mapper | |
| 16 | +public interface Demo03StudentInnerMapper extends BaseMapperX<Demo03StudentDO> { | |
| 17 | + | |
| 18 | + default PageResult<Demo03StudentDO> selectPage(Demo03StudentInnerPageReqVO reqVO) { | |
| 19 | + return selectPage(reqVO, new LambdaQueryWrapperX<Demo03StudentDO>() | |
| 20 | + .likeIfPresent(Demo03StudentDO::getName, reqVO.getName()) | |
| 21 | + .eqIfPresent(Demo03StudentDO::getSex, reqVO.getSex()) | |
| 22 | + .eqIfPresent(Demo03StudentDO::getDescription, reqVO.getDescription()) | |
| 23 | + .betweenIfPresent(Demo03StudentDO::getCreateTime, reqVO.getCreateTime()) | |
| 24 | + .orderByDesc(Demo03StudentDO::getId)); | |
| 25 | + } | |
| 26 | + | |
| 27 | +} | |
| 0 | 28 | \ No newline at end of file | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/normal/Demo03CourseNormalMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.normal; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 4 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; | |
| 5 | +import org.apache.ibatis.annotations.Mapper; | |
| 6 | + | |
| 7 | +import java.util.List; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * 学生课程 Mapper | |
| 11 | + * | |
| 12 | + * @author 芋道源码 | |
| 13 | + */ | |
| 14 | +@Mapper | |
| 15 | +public interface Demo03CourseNormalMapper extends BaseMapperX<Demo03CourseDO> { | |
| 16 | + | |
| 17 | + default List<Demo03CourseDO> selectListByStudentId(Long studentId) { | |
| 18 | + return selectList(Demo03CourseDO::getStudentId, studentId); | |
| 19 | + } | |
| 20 | + | |
| 21 | + default int deleteByStudentId(Long studentId) { | |
| 22 | + return delete(Demo03CourseDO::getStudentId, studentId); | |
| 23 | + } | |
| 24 | + | |
| 25 | + default int deleteByStudentIds(List<Long> studentIds) { | |
| 26 | + return delete(Demo03CourseDO::getStudentId, studentIds); | |
| 27 | + } | |
| 28 | + | |
| 29 | +} | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/normal/Demo03GradeNormalMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.normal; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 4 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; | |
| 5 | +import org.apache.ibatis.annotations.Mapper; | |
| 6 | + | |
| 7 | +import java.util.List; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * 学生班级 Mapper | |
| 11 | + * | |
| 12 | + * @author 芋道源码 | |
| 13 | + */ | |
| 14 | +@Mapper | |
| 15 | +public interface Demo03GradeNormalMapper extends BaseMapperX<Demo03GradeDO> { | |
| 16 | + | |
| 17 | + default Demo03GradeDO selectByStudentId(Long studentId) { | |
| 18 | + return selectOne(Demo03GradeDO::getStudentId, studentId); | |
| 19 | + } | |
| 20 | + | |
| 21 | + default int deleteByStudentId(Long studentId) { | |
| 22 | + return delete(Demo03GradeDO::getStudentId, studentId); | |
| 23 | + } | |
| 24 | + | |
| 25 | + default int deleteByStudentIds(List<Long> studentIds) { | |
| 26 | + return delete(Demo03GradeDO::getStudentId, studentIds); | |
| 27 | + } | |
| 28 | + | |
| 29 | +} | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/normal/Demo03StudentNormalMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.normal; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 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.normal.vo.Demo03StudentNormalPageReqVO; | |
| 7 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; | |
| 8 | +import org.apache.ibatis.annotations.Mapper; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 学生 Mapper | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@Mapper | |
| 16 | +public interface Demo03StudentNormalMapper extends BaseMapperX<Demo03StudentDO> { | |
| 17 | + | |
| 18 | + default PageResult<Demo03StudentDO> selectPage(Demo03StudentNormalPageReqVO reqVO) { | |
| 19 | + return selectPage(reqVO, new LambdaQueryWrapperX<Demo03StudentDO>() | |
| 20 | + .likeIfPresent(Demo03StudentDO::getName, reqVO.getName()) | |
| 21 | + .eqIfPresent(Demo03StudentDO::getSex, reqVO.getSex()) | |
| 22 | + .eqIfPresent(Demo03StudentDO::getDescription, reqVO.getDescription()) | |
| 23 | + .betweenIfPresent(Demo03StudentDO::getCreateTime, reqVO.getCreateTime()) | |
| 24 | + .orderByDesc(Demo03StudentDO::getId)); | |
| 25 | + } | |
| 26 | + | |
| 27 | +} | |
| 0 | 28 | \ No newline at end of file | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants.java
| ... | ... | @@ -65,7 +65,8 @@ public interface ErrorCodeConstants { |
| 65 | 65 | ErrorCode DEMO02_CATEGORY_NAME_DUPLICATE = new ErrorCode(1_001_201_005, "已经存在该名字的示例分类"); |
| 66 | 66 | ErrorCode DEMO02_CATEGORY_PARENT_IS_CHILD = new ErrorCode(1_001_201_006, "不能设置自己的子示例分类为父示例分类"); |
| 67 | 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/framework/codegen/config/CodegenProperties.java
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java
| ... | ... | @@ -236,6 +236,7 @@ public class CodegenEngine { |
| 236 | 236 | + '.' + "framework"); // 用于后续获取测试类的 package 地址 |
| 237 | 237 | globalBindingMap.put("jakartaPackage", jakartaEnable ? "jakarta" : "javax"); |
| 238 | 238 | globalBindingMap.put("voType", codegenProperties.getVoType()); |
| 239 | + globalBindingMap.put("deleteBatchEnable", codegenProperties.getDeleteBatchEnable()); | |
| 239 | 240 | // 全局 Java Bean |
| 240 | 241 | globalBindingMap.put("CommonResultClassName", CommonResult.class.getName()); |
| 241 | 242 | globalBindingMap.put("PageResultClassName", PageResult.class.getName()); |
| ... | ... | @@ -257,6 +258,7 @@ public class CodegenEngine { |
| 257 | 258 | globalBindingMap.put("ApiAccessLogClassName", ApiAccessLog.class.getName()); |
| 258 | 259 | globalBindingMap.put("OperateTypeEnumClassName", OperateTypeEnum.class.getName()); |
| 259 | 260 | globalBindingMap.put("BeanUtils", BeanUtils.class.getName()); |
| 261 | + globalBindingMap.put("CollectionUtilsClassName", CollectionUtils.class.getName()); | |
| 260 | 262 | } |
| 261 | 263 | |
| 262 | 264 | /** |
| ... | ... | @@ -382,7 +384,6 @@ public class CodegenEngine { |
| 382 | 384 | bindingMap.put("columns", columns); |
| 383 | 385 | bindingMap.put("primaryColumn", CollectionUtils.findFirst(columns, CodegenColumnDO::getPrimaryKey)); // 主键字段 |
| 384 | 386 | bindingMap.put("sceneEnum", CodegenSceneEnum.valueOf(table.getScene())); |
| 385 | - | |
| 386 | 387 | // className 相关 |
| 387 | 388 | // 去掉指定前缀,将 TestDictType 转换成 DictType. 因为在 create 等方法后,不需要带上 Test 前缀 |
| 388 | 389 | String className = table.getClassName(); | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo01/Demo01ContactService.java
| 1 | 1 | package cn.iocoder.yudao.module.infra.service.demo.demo01; |
| 2 | 2 | |
| 3 | -import jakarta.validation.*; | |
| 4 | - | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 5 | 4 | import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.Demo01ContactPageReqVO; |
| 6 | 5 | import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.Demo01ContactSaveReqVO; |
| 7 | 6 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo01.Demo01ContactDO; |
| 8 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 7 | +import jakarta.validation.Valid; | |
| 8 | + | |
| 9 | +import java.util.List; | |
| 9 | 10 | |
| 10 | 11 | /** |
| 11 | 12 | * 示例联系人 Service 接口 |
| ... | ... | @@ -37,6 +38,13 @@ public interface Demo01ContactService { |
| 37 | 38 | void deleteDemo01Contact(Long id); |
| 38 | 39 | |
| 39 | 40 | /** |
| 41 | + * 批量删除示例联系人 | |
| 42 | + * | |
| 43 | + * @param ids 编号 | |
| 44 | + */ | |
| 45 | + void deleteDemo01ContactByIds(List<Long> ids); | |
| 46 | + | |
| 47 | + /** | |
| 40 | 48 | * 获得示例联系人 |
| 41 | 49 | * |
| 42 | 50 | * @param id 编号 | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo01/Demo01ContactServiceImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.infra.service.demo.demo01; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 5 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 3 | 6 | import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.Demo01ContactPageReqVO; |
| 4 | 7 | import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.Demo01ContactSaveReqVO; |
| 5 | -import org.springframework.stereotype.Service; | |
| 8 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo01.Demo01ContactDO; | |
| 9 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo01.Demo01ContactMapper; | |
| 6 | 10 | import jakarta.annotation.Resource; |
| 11 | +import org.springframework.stereotype.Service; | |
| 7 | 12 | import org.springframework.validation.annotation.Validated; |
| 8 | 13 | |
| 9 | -import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo01.Demo01ContactDO; | |
| 10 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 11 | -import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 12 | - | |
| 13 | -import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo01.Demo01ContactMapper; | |
| 14 | +import java.util.List; | |
| 14 | 15 | |
| 15 | 16 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 16 | -import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; | |
| 17 | +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.DEMO01_CONTACT_NOT_EXISTS; | |
| 17 | 18 | |
| 18 | 19 | /** |
| 19 | 20 | * 示例联系人 Service 实现类 |
| ... | ... | @@ -53,6 +54,21 @@ public class Demo01ContactServiceImpl implements Demo01ContactService { |
| 53 | 54 | demo01ContactMapper.deleteById(id); |
| 54 | 55 | } |
| 55 | 56 | |
| 57 | + @Override | |
| 58 | + public void deleteDemo01ContactByIds(List<Long> ids) { | |
| 59 | + // 校验存在 | |
| 60 | + validateDemo01ContactExists(ids); | |
| 61 | + // 删除 | |
| 62 | + demo01ContactMapper.deleteByIds(ids); | |
| 63 | + } | |
| 64 | + | |
| 65 | + private void validateDemo01ContactExists(List<Long> ids) { | |
| 66 | + List<Demo01ContactDO> list = demo01ContactMapper.selectByIds(ids); | |
| 67 | + if (CollUtil.isEmpty(list) || list.size() != ids.size()) { | |
| 68 | + throw exception(DEMO01_CONTACT_NOT_EXISTS); | |
| 69 | + } | |
| 70 | + } | |
| 71 | + | |
| 56 | 72 | private void validateDemo01ContactExists(Long id) { |
| 57 | 73 | if (demo01ContactMapper.selectById(id) == null) { |
| 58 | 74 | throw exception(DEMO01_CONTACT_NOT_EXISTS); | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo02/Demo02CategoryService.java
| 1 | 1 | package cn.iocoder.yudao.module.infra.service.demo.demo02; |
| 2 | 2 | |
| 3 | -import java.util.*; | |
| 4 | -import jakarta.validation.*; | |
| 5 | - | |
| 6 | 3 | import cn.iocoder.yudao.module.infra.controller.admin.demo.demo02.vo.Demo02CategoryListReqVO; |
| 7 | 4 | import cn.iocoder.yudao.module.infra.controller.admin.demo.demo02.vo.Demo02CategorySaveReqVO; |
| 8 | 5 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo02.Demo02CategoryDO; |
| 6 | +import jakarta.validation.Valid; | |
| 7 | + | |
| 8 | +import java.util.List; | |
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * 示例分类 Service 接口 | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo02/Demo02CategoryServiceImpl.java
| ... | ... | @@ -5,10 +5,10 @@ import cn.iocoder.yudao.module.infra.controller.admin.demo.demo02.vo.Demo02Categ |
| 5 | 5 | import cn.iocoder.yudao.module.infra.controller.admin.demo.demo02.vo.Demo02CategorySaveReqVO; |
| 6 | 6 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo02.Demo02CategoryDO; |
| 7 | 7 | import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo02.Demo02CategoryMapper; |
| 8 | +import jakarta.annotation.Resource; | |
| 8 | 9 | import org.springframework.stereotype.Service; |
| 9 | 10 | import org.springframework.validation.annotation.Validated; |
| 10 | 11 | |
| 11 | -import jakarta.annotation.Resource; | |
| 12 | 12 | import java.util.List; |
| 13 | 13 | import java.util.Objects; |
| 14 | 14 | ... | ... |
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/Demo03StudentErpService.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 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 4 | 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; | |
| 5 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpPageReqVO; | |
| 6 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpSaveReqVO; | |
| 7 | 7 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; |
| 8 | 8 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; |
| 9 | 9 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; |
| 10 | - | |
| 11 | 10 | import jakarta.validation.Valid; |
| 11 | + | |
| 12 | 12 | import java.util.List; |
| 13 | 13 | |
| 14 | 14 | /** |
| ... | ... | @@ -16,7 +16,7 @@ import java.util.List; |
| 16 | 16 | * |
| 17 | 17 | * @author 芋道源码 |
| 18 | 18 | */ |
| 19 | -public interface Demo03StudentService { | |
| 19 | +public interface Demo03StudentErpService { | |
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * 创建学生 |
| ... | ... | @@ -24,14 +24,14 @@ public interface Demo03StudentService { |
| 24 | 24 | * @param createReqVO 创建信息 |
| 25 | 25 | * @return 编号 |
| 26 | 26 | */ |
| 27 | - Long createDemo03Student(@Valid Demo03StudentSaveReqVO createReqVO); | |
| 27 | + Long createDemo03Student(@Valid Demo03StudentErpSaveReqVO createReqVO); | |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * 更新学生 |
| 31 | 31 | * |
| 32 | 32 | * @param updateReqVO 更新信息 |
| 33 | 33 | */ |
| 34 | - void updateDemo03Student(@Valid Demo03StudentSaveReqVO updateReqVO); | |
| 34 | + void updateDemo03Student(@Valid Demo03StudentErpSaveReqVO updateReqVO); | |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * 删除学生 |
| ... | ... | @@ -41,6 +41,13 @@ public interface Demo03StudentService { |
| 41 | 41 | void deleteDemo03Student(Long id); |
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | + * 批量删除学生 | |
| 45 | + * | |
| 46 | + * @param ids 编号 | |
| 47 | + */ | |
| 48 | + void deleteDemo03StudentByIds(List<Long> ids); | |
| 49 | + | |
| 50 | + /** | |
| 44 | 51 | * 获得学生 |
| 45 | 52 | * |
| 46 | 53 | * @param id 编号 |
| ... | ... | @@ -54,20 +61,11 @@ public interface Demo03StudentService { |
| 54 | 61 | * @param pageReqVO 分页查询 |
| 55 | 62 | * @return 学生分页 |
| 56 | 63 | */ |
| 57 | - PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentPageReqVO pageReqVO); | |
| 58 | - | |
| 64 | + PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentErpPageReqVO pageReqVO); | |
| 59 | 65 | |
| 60 | 66 | // ==================== 子表(学生课程) ==================== |
| 61 | 67 | |
| 62 | 68 | /** |
| 63 | - * 获得学生课程列表 | |
| 64 | - * | |
| 65 | - * @param studentId 学生编号 | |
| 66 | - * @return 学生课程列表 | |
| 67 | - */ | |
| 68 | - List<Demo03CourseDO> getDemo03CourseListByStudentId(Long studentId); | |
| 69 | - | |
| 70 | - /** | |
| 71 | 69 | * 获得学生课程分页 |
| 72 | 70 | * |
| 73 | 71 | * @param pageReqVO 分页查询 |
| ... | ... | @@ -99,6 +97,13 @@ public interface Demo03StudentService { |
| 99 | 97 | void deleteDemo03Course(Long id); |
| 100 | 98 | |
| 101 | 99 | /** |
| 100 | + * 批量删除学生课程 | |
| 101 | + * | |
| 102 | + * @param ids 编号 | |
| 103 | + */ | |
| 104 | + void deleteDemo03CourseByIds(List<Long> ids); | |
| 105 | + | |
| 106 | + /** | |
| 102 | 107 | * 获得学生课程 |
| 103 | 108 | * |
| 104 | 109 | * @param id 编号 |
| ... | ... | @@ -109,14 +114,6 @@ public interface Demo03StudentService { |
| 109 | 114 | // ==================== 子表(学生班级) ==================== |
| 110 | 115 | |
| 111 | 116 | /** |
| 112 | - * 获得学生班级 | |
| 113 | - * | |
| 114 | - * @param studentId 学生编号 | |
| 115 | - * @return 学生班级 | |
| 116 | - */ | |
| 117 | - Demo03GradeDO getDemo03GradeByStudentId(Long studentId); | |
| 118 | - | |
| 119 | - /** | |
| 120 | 117 | * 获得学生班级分页 |
| 121 | 118 | * |
| 122 | 119 | * @param pageReqVO 分页查询 |
| ... | ... | @@ -148,6 +145,13 @@ public interface Demo03StudentService { |
| 148 | 145 | void deleteDemo03Grade(Long id); |
| 149 | 146 | |
| 150 | 147 | /** |
| 148 | + * 批量删除学生班级 | |
| 149 | + * | |
| 150 | + * @param ids 编号 | |
| 151 | + */ | |
| 152 | + void deleteDemo03GradeByIds(List<Long> ids); | |
| 153 | + | |
| 154 | + /** | |
| 151 | 155 | * 获得学生班级 |
| 152 | 156 | * |
| 153 | 157 | * @param id 编号 | ... | ... |
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/Demo03StudentErpServiceImpl.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 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 4 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 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.Demo03StudentErpPageReqVO; | |
| 8 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpSaveReqVO; | |
| 8 | 9 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; |
| 9 | 10 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; |
| 10 | 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.Demo03CourseErpMapper; | |
| 13 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp.Demo03GradeErpMapper; | |
| 14 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp.Demo03StudentErpMapper; | |
| 15 | +import jakarta.annotation.Resource; | |
| 14 | 16 | import org.springframework.stereotype.Service; |
| 15 | 17 | import org.springframework.transaction.annotation.Transactional; |
| 16 | 18 | import org.springframework.validation.annotation.Validated; |
| 17 | 19 | |
| 18 | -import jakarta.annotation.Resource; | |
| 19 | 20 | import java.util.List; |
| 20 | 21 | |
| 21 | 22 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| ... | ... | @@ -28,41 +29,31 @@ import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; |
| 28 | 29 | */ |
| 29 | 30 | @Service |
| 30 | 31 | @Validated |
| 31 | -public class Demo03StudentServiceImpl implements Demo03StudentService { | |
| 32 | +public class Demo03StudentErpServiceImpl implements Demo03StudentErpService { | |
| 32 | 33 | |
| 33 | 34 | @Resource |
| 34 | - private Demo03StudentMapper demo03StudentMapper; | |
| 35 | + private Demo03StudentErpMapper demo03StudentErpMapper; | |
| 35 | 36 | @Resource |
| 36 | - private Demo03CourseMapper demo03CourseMapper; | |
| 37 | + private Demo03CourseErpMapper demo03CourseErpMapper; | |
| 37 | 38 | @Resource |
| 38 | - private Demo03GradeMapper demo03GradeMapper; | |
| 39 | + private Demo03GradeErpMapper demo03GradeErpMapper; | |
| 39 | 40 | |
| 40 | 41 | @Override |
| 41 | - @Transactional(rollbackFor = Exception.class) | |
| 42 | - public Long createDemo03Student(Demo03StudentSaveReqVO createReqVO) { | |
| 42 | + public Long createDemo03Student(Demo03StudentErpSaveReqVO createReqVO) { | |
| 43 | 43 | // 插入 |
| 44 | 44 | Demo03StudentDO demo03Student = BeanUtils.toBean(createReqVO, Demo03StudentDO.class); |
| 45 | - demo03StudentMapper.insert(demo03Student); | |
| 46 | - | |
| 47 | - // 插入子表 | |
| 48 | - createDemo03CourseList(demo03Student.getId(), createReqVO.getDemo03Courses()); | |
| 49 | - createDemo03Grade(demo03Student.getId(), createReqVO.getDemo03Grade()); | |
| 45 | + demo03StudentErpMapper.insert(demo03Student); | |
| 50 | 46 | // 返回 |
| 51 | 47 | return demo03Student.getId(); |
| 52 | 48 | } |
| 53 | 49 | |
| 54 | 50 | @Override |
| 55 | - @Transactional(rollbackFor = Exception.class) | |
| 56 | - public void updateDemo03Student(Demo03StudentSaveReqVO updateReqVO) { | |
| 51 | + public void updateDemo03Student(Demo03StudentErpSaveReqVO updateReqVO) { | |
| 57 | 52 | // 校验存在 |
| 58 | 53 | validateDemo03StudentExists(updateReqVO.getId()); |
| 59 | 54 | // 更新 |
| 60 | 55 | Demo03StudentDO updateObj = BeanUtils.toBean(updateReqVO, Demo03StudentDO.class); |
| 61 | - demo03StudentMapper.updateById(updateObj); | |
| 62 | - | |
| 63 | - // 更新子表 | |
| 64 | - updateDemo03CourseList(updateReqVO.getId(), updateReqVO.getDemo03Courses()); | |
| 65 | - updateDemo03Grade(updateReqVO.getId(), updateReqVO.getDemo03Grade()); | |
| 56 | + demo03StudentErpMapper.updateById(updateObj); | |
| 66 | 57 | } |
| 67 | 58 | |
| 68 | 59 | @Override |
| ... | ... | @@ -71,119 +62,128 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { |
| 71 | 62 | // 校验存在 |
| 72 | 63 | validateDemo03StudentExists(id); |
| 73 | 64 | // 删除 |
| 74 | - demo03StudentMapper.deleteById(id); | |
| 65 | + demo03StudentErpMapper.deleteById(id); | |
| 75 | 66 | |
| 76 | 67 | // 删除子表 |
| 77 | 68 | deleteDemo03CourseByStudentId(id); |
| 78 | 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 | + demo03StudentErpMapper.deleteByIds(ids); | |
| 79 | + | |
| 80 | + // 删除子表 | |
| 81 | + deleteDemo03CourseByStudentIds(ids); | |
| 82 | + deleteDemo03GradeByStudentIds(ids); | |
| 83 | + } | |
| 84 | + | |
| 85 | + private void validateDemo03StudentExists(List<Long> ids) { | |
| 86 | + List<Demo03StudentDO> list = demo03StudentErpMapper.selectByIds(ids); | |
| 87 | + if (CollUtil.isEmpty(list) || list.size() != ids.size()) { | |
| 88 | + throw exception(DEMO03_STUDENT_NOT_EXISTS); | |
| 89 | + } | |
| 90 | + } | |
| 91 | + | |
| 81 | 92 | private void validateDemo03StudentExists(Long id) { |
| 82 | - if (demo03StudentMapper.selectById(id) == null) { | |
| 93 | + if (demo03StudentErpMapper.selectById(id) == null) { | |
| 83 | 94 | throw exception(DEMO03_STUDENT_NOT_EXISTS); |
| 84 | 95 | } |
| 85 | 96 | } |
| 86 | 97 | |
| 87 | 98 | @Override |
| 88 | 99 | public Demo03StudentDO getDemo03Student(Long id) { |
| 89 | - return demo03StudentMapper.selectById(id); | |
| 100 | + return demo03StudentErpMapper.selectById(id); | |
| 90 | 101 | } |
| 91 | 102 | |
| 92 | 103 | @Override |
| 93 | - public PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentPageReqVO pageReqVO) { | |
| 94 | - return demo03StudentMapper.selectPage(pageReqVO); | |
| 104 | + public PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentErpPageReqVO pageReqVO) { | |
| 105 | + return demo03StudentErpMapper.selectPage(pageReqVO); | |
| 95 | 106 | } |
| 96 | 107 | |
| 97 | 108 | // ==================== 子表(学生课程) ==================== |
| 98 | 109 | |
| 99 | 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 | 111 | public PageResult<Demo03CourseDO> getDemo03CoursePage(PageParam pageReqVO, Long studentId) { |
| 123 | - return demo03CourseMapper.selectPage(pageReqVO, studentId); | |
| 112 | + return demo03CourseErpMapper.selectPage(pageReqVO, studentId); | |
| 124 | 113 | } |
| 125 | 114 | |
| 126 | 115 | @Override |
| 127 | 116 | public Long createDemo03Course(Demo03CourseDO demo03Course) { |
| 128 | - demo03CourseMapper.insert(demo03Course); | |
| 117 | + demo03CourseErpMapper.insert(demo03Course); | |
| 129 | 118 | return demo03Course.getId(); |
| 130 | 119 | } |
| 131 | 120 | |
| 132 | 121 | @Override |
| 133 | 122 | public void updateDemo03Course(Demo03CourseDO demo03Course) { |
| 134 | - demo03CourseMapper.updateById(demo03Course); | |
| 123 | + // 校验存在 | |
| 124 | + validateDemo03CourseExists(demo03Course.getId()); | |
| 125 | + // 更新 | |
| 126 | + demo03Course.setUpdater(null).setUpdateTime(null); // 解决更新情况下:updateTime 不更新 | |
| 127 | + demo03CourseErpMapper.updateById(demo03Course); | |
| 135 | 128 | } |
| 136 | 129 | |
| 137 | 130 | @Override |
| 138 | 131 | public void deleteDemo03Course(Long id) { |
| 139 | - demo03CourseMapper.deleteById(id); | |
| 132 | + // 校验存在 | |
| 133 | + validateDemo03CourseExists(id); | |
| 134 | + // 删除 | |
| 135 | + demo03CourseErpMapper.deleteById(id); | |
| 140 | 136 | } |
| 141 | 137 | |
| 142 | 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 | + demo03CourseErpMapper.deleteByIds(ids); | |
| 145 | 144 | } |
| 146 | 145 | |
| 147 | - // ==================== 子表(学生班级) ==================== | |
| 148 | - | |
| 149 | 146 | @Override |
| 150 | - public Demo03GradeDO getDemo03GradeByStudentId(Long studentId) { | |
| 151 | - return demo03GradeMapper.selectByStudentId(studentId); | |
| 147 | + public Demo03CourseDO getDemo03Course(Long id) { | |
| 148 | + return demo03CourseErpMapper.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 (demo03CourseErpMapper.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 = demo03CourseErpMapper.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 | + demo03CourseErpMapper.deleteByStudentId(studentId); | |
| 166 | + } | |
| 167 | + | |
| 168 | + private void deleteDemo03CourseByStudentIds(List<Long> studentIds) { | |
| 169 | + demo03CourseErpMapper.deleteByStudentIds(studentIds); | |
| 173 | 170 | } |
| 174 | 171 | |
| 172 | + // ==================== 子表(学生班级) ==================== | |
| 173 | + | |
| 175 | 174 | @Override |
| 176 | 175 | public PageResult<Demo03GradeDO> getDemo03GradePage(PageParam pageReqVO, Long studentId) { |
| 177 | - return demo03GradeMapper.selectPage(pageReqVO, studentId); | |
| 176 | + return demo03GradeErpMapper.selectPage(pageReqVO, studentId); | |
| 178 | 177 | } |
| 179 | 178 | |
| 180 | 179 | @Override |
| 181 | 180 | public Long createDemo03Grade(Demo03GradeDO demo03Grade) { |
| 182 | 181 | // 校验是否已经存在 |
| 183 | - if (demo03GradeMapper.selectByStudentId(demo03Grade.getStudentId()) != null) { | |
| 182 | + if (demo03GradeErpMapper.selectByStudentId(demo03Grade.getStudentId()) != null) { | |
| 184 | 183 | throw exception(DEMO03_GRADE_EXISTS); |
| 185 | 184 | } |
| 186 | - demo03GradeMapper.insert(demo03Grade); | |
| 185 | + // 插入 | |
| 186 | + demo03GradeErpMapper.insert(demo03Grade); | |
| 187 | 187 | return demo03Grade.getId(); |
| 188 | 188 | } |
| 189 | 189 | |
| ... | ... | @@ -192,7 +192,8 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { |
| 192 | 192 | // 校验存在 |
| 193 | 193 | validateDemo03GradeExists(demo03Grade.getId()); |
| 194 | 194 | // 更新 |
| 195 | - demo03GradeMapper.updateById(demo03Grade); | |
| 195 | + demo03Grade.setUpdater(null).setUpdateTime(null); // 解决更新情况下:updateTime 不更新 | |
| 196 | + demo03GradeErpMapper.updateById(demo03Grade); | |
| 196 | 197 | } |
| 197 | 198 | |
| 198 | 199 | @Override |
| ... | ... | @@ -200,18 +201,41 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { |
| 200 | 201 | // 校验存在 |
| 201 | 202 | validateDemo03GradeExists(id); |
| 202 | 203 | // 删除 |
| 203 | - demo03GradeMapper.deleteById(id); | |
| 204 | + demo03GradeErpMapper.deleteById(id); | |
| 205 | + } | |
| 206 | + | |
| 207 | + @Override | |
| 208 | + public void deleteDemo03GradeByIds(List<Long> ids) { | |
| 209 | + // 校验存在 | |
| 210 | + validateDemo03GradeExists(ids); | |
| 211 | + // 删除 | |
| 212 | + demo03GradeErpMapper.deleteByIds(ids); | |
| 204 | 213 | } |
| 205 | 214 | |
| 206 | 215 | @Override |
| 207 | 216 | public Demo03GradeDO getDemo03Grade(Long id) { |
| 208 | - return demo03GradeMapper.selectById(id); | |
| 217 | + return demo03GradeErpMapper.selectById(id); | |
| 209 | 218 | } |
| 210 | 219 | |
| 211 | 220 | private void validateDemo03GradeExists(Long id) { |
| 212 | - if (demo03GradeMapper.selectById(id) == null) { | |
| 221 | + if (demo03GradeErpMapper.selectById(id) == null) { | |
| 213 | 222 | throw exception(DEMO03_GRADE_NOT_EXISTS); |
| 214 | 223 | } |
| 215 | 224 | } |
| 216 | 225 | |
| 226 | + private void validateDemo03GradeExists(List<Long> ids) { | |
| 227 | + List<Demo03GradeDO> list = demo03GradeErpMapper.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 | + demo03GradeErpMapper.deleteByStudentId(studentId); | |
| 235 | + } | |
| 236 | + | |
| 237 | + private void deleteDemo03GradeByStudentIds(List<Long> studentIds) { | |
| 238 | + demo03GradeErpMapper.deleteByStudentIds(studentIds); | |
| 239 | + } | |
| 240 | + | |
| 217 | 241 | } |
| 218 | 242 | \ No newline at end of file | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/inner/Demo03StudentInnerService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo.demo03.inner; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerPageReqVO; | |
| 5 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerSaveReqVO; | |
| 6 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; | |
| 7 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; | |
| 8 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; | |
| 9 | +import jakarta.validation.Valid; | |
| 10 | + | |
| 11 | +import java.util.List; | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * 学生 Service 接口 | |
| 15 | + * | |
| 16 | + * @author 芋道源码 | |
| 17 | + */ | |
| 18 | +public interface Demo03StudentInnerService { | |
| 19 | + | |
| 20 | + /** | |
| 21 | + * 创建学生 | |
| 22 | + * | |
| 23 | + * @param createReqVO 创建信息 | |
| 24 | + * @return 编号 | |
| 25 | + */ | |
| 26 | + Long createDemo03Student(@Valid Demo03StudentInnerSaveReqVO createReqVO); | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * 更新学生 | |
| 30 | + * | |
| 31 | + * @param updateReqVO 更新信息 | |
| 32 | + */ | |
| 33 | + void updateDemo03Student(@Valid Demo03StudentInnerSaveReqVO updateReqVO); | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * 删除学生 | |
| 37 | + * | |
| 38 | + * @param id 编号 | |
| 39 | + */ | |
| 40 | + void deleteDemo03Student(Long id); | |
| 41 | + | |
| 42 | + /** | |
| 43 | + * 批量删除学生 | |
| 44 | + * | |
| 45 | + * @param ids 编号 | |
| 46 | + */ | |
| 47 | + void deleteDemo03StudentByIds(List<Long> ids); | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * 获得学生 | |
| 51 | + * | |
| 52 | + * @param id 编号 | |
| 53 | + * @return 学生 | |
| 54 | + */ | |
| 55 | + Demo03StudentDO getDemo03Student(Long id); | |
| 56 | + | |
| 57 | + /** | |
| 58 | + * 获得学生分页 | |
| 59 | + * | |
| 60 | + * @param pageReqVO 分页查询 | |
| 61 | + * @return 学生分页 | |
| 62 | + */ | |
| 63 | + PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentInnerPageReqVO pageReqVO); | |
| 64 | + | |
| 65 | + // ==================== 子表(学生课程) ==================== | |
| 66 | + | |
| 67 | + /** | |
| 68 | + * 获得学生课程列表 | |
| 69 | + * | |
| 70 | + * @param studentId 学生编号 | |
| 71 | + * @return 学生课程列表 | |
| 72 | + */ | |
| 73 | + List<Demo03CourseDO> getDemo03CourseListByStudentId(Long studentId); | |
| 74 | + | |
| 75 | + // ==================== 子表(学生班级) ==================== | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * 获得学生班级 | |
| 79 | + * | |
| 80 | + * @param studentId 学生编号 | |
| 81 | + * @return 学生班级 | |
| 82 | + */ | |
| 83 | + Demo03GradeDO getDemo03GradeByStudentId(Long studentId); | |
| 84 | + | |
| 85 | +} | |
| 0 | 86 | \ No newline at end of file | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/inner/Demo03StudentInnerServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo.demo03.inner; | |
| 2 | + | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 4 | +import cn.hutool.core.util.ObjectUtil; | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 7 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerPageReqVO; | |
| 8 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerSaveReqVO; | |
| 9 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; | |
| 10 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; | |
| 11 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; | |
| 12 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.inner.Demo03CourseInnerMapper; | |
| 13 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.inner.Demo03GradeInnerMapper; | |
| 14 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.inner.Demo03StudentInnerMapper; | |
| 15 | +import jakarta.annotation.Resource; | |
| 16 | +import org.springframework.stereotype.Service; | |
| 17 | +import org.springframework.transaction.annotation.Transactional; | |
| 18 | +import org.springframework.validation.annotation.Validated; | |
| 19 | + | |
| 20 | +import java.util.List; | |
| 21 | + | |
| 22 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 23 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; | |
| 24 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList; | |
| 25 | +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.DEMO03_STUDENT_NOT_EXISTS; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * 学生 Service 实现类 | |
| 29 | + * | |
| 30 | + * @author 芋道源码 | |
| 31 | + */ | |
| 32 | +@Service | |
| 33 | +@Validated | |
| 34 | +public class Demo03StudentInnerServiceImpl implements Demo03StudentInnerService { | |
| 35 | + | |
| 36 | + @Resource | |
| 37 | + private Demo03StudentInnerMapper demo03StudentInnerMapper; | |
| 38 | + @Resource | |
| 39 | + private Demo03CourseInnerMapper demo03CourseInnerMapper; | |
| 40 | + @Resource | |
| 41 | + private Demo03GradeInnerMapper demo03GradeInnerMapper; | |
| 42 | + | |
| 43 | + @Override | |
| 44 | + @Transactional(rollbackFor = Exception.class) | |
| 45 | + public Long createDemo03Student(Demo03StudentInnerSaveReqVO createReqVO) { | |
| 46 | + // 插入 | |
| 47 | + Demo03StudentDO demo03Student = BeanUtils.toBean(createReqVO, Demo03StudentDO.class); | |
| 48 | + demo03StudentInnerMapper.insert(demo03Student); | |
| 49 | + | |
| 50 | + // 插入子表 | |
| 51 | + createDemo03CourseList(demo03Student.getId(), createReqVO.getDemo03Courses()); | |
| 52 | + createDemo03Grade(demo03Student.getId(), createReqVO.getDemo03Grade()); | |
| 53 | + // 返回 | |
| 54 | + return demo03Student.getId(); | |
| 55 | + } | |
| 56 | + | |
| 57 | + @Override | |
| 58 | + @Transactional(rollbackFor = Exception.class) | |
| 59 | + public void updateDemo03Student(Demo03StudentInnerSaveReqVO updateReqVO) { | |
| 60 | + // 校验存在 | |
| 61 | + validateDemo03StudentExists(updateReqVO.getId()); | |
| 62 | + // 更新 | |
| 63 | + Demo03StudentDO updateObj = BeanUtils.toBean(updateReqVO, Demo03StudentDO.class); | |
| 64 | + demo03StudentInnerMapper.updateById(updateObj); | |
| 65 | + | |
| 66 | + // 更新子表 | |
| 67 | + updateDemo03CourseList(updateReqVO.getId(), updateReqVO.getDemo03Courses()); | |
| 68 | + updateDemo03Grade(updateReqVO.getId(), updateReqVO.getDemo03Grade()); | |
| 69 | + } | |
| 70 | + | |
| 71 | + @Override | |
| 72 | + @Transactional(rollbackFor = Exception.class) | |
| 73 | + public void deleteDemo03Student(Long id) { | |
| 74 | + // 校验存在 | |
| 75 | + validateDemo03StudentExists(id); | |
| 76 | + // 删除 | |
| 77 | + demo03StudentInnerMapper.deleteById(id); | |
| 78 | + | |
| 79 | + // 删除子表 | |
| 80 | + deleteDemo03CourseByStudentId(id); | |
| 81 | + deleteDemo03GradeByStudentId(id); | |
| 82 | + } | |
| 83 | + | |
| 84 | + @Override | |
| 85 | + @Transactional(rollbackFor = Exception.class) | |
| 86 | + public void deleteDemo03StudentByIds(List<Long> ids) { | |
| 87 | + // 校验存在 | |
| 88 | + validateDemo03StudentExists(ids); | |
| 89 | + // 删除 | |
| 90 | + demo03StudentInnerMapper.deleteByIds(ids); | |
| 91 | + | |
| 92 | + // 删除子表 | |
| 93 | + deleteDemo03CourseByStudentIds(ids); | |
| 94 | + deleteDemo03GradeByStudentIds(ids); | |
| 95 | + } | |
| 96 | + | |
| 97 | + private void validateDemo03StudentExists(List<Long> ids) { | |
| 98 | + List<Demo03StudentDO> list = demo03StudentInnerMapper.selectByIds(ids); | |
| 99 | + if (CollUtil.isEmpty(list) || list.size() != ids.size()) { | |
| 100 | + throw exception(DEMO03_STUDENT_NOT_EXISTS); | |
| 101 | + } | |
| 102 | + } | |
| 103 | + | |
| 104 | + private void validateDemo03StudentExists(Long id) { | |
| 105 | + if (demo03StudentInnerMapper.selectById(id) == null) { | |
| 106 | + throw exception(DEMO03_STUDENT_NOT_EXISTS); | |
| 107 | + } | |
| 108 | + } | |
| 109 | + | |
| 110 | + @Override | |
| 111 | + public Demo03StudentDO getDemo03Student(Long id) { | |
| 112 | + return demo03StudentInnerMapper.selectById(id); | |
| 113 | + } | |
| 114 | + | |
| 115 | + @Override | |
| 116 | + public PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentInnerPageReqVO pageReqVO) { | |
| 117 | + return demo03StudentInnerMapper.selectPage(pageReqVO); | |
| 118 | + } | |
| 119 | + | |
| 120 | + // ==================== 子表(学生课程) ==================== | |
| 121 | + | |
| 122 | + @Override | |
| 123 | + public List<Demo03CourseDO> getDemo03CourseListByStudentId(Long studentId) { | |
| 124 | + return demo03CourseInnerMapper.selectListByStudentId(studentId); | |
| 125 | + } | |
| 126 | + | |
| 127 | + private void createDemo03CourseList(Long studentId, List<Demo03CourseDO> list) { | |
| 128 | + list.forEach(o -> o.setStudentId(studentId)); | |
| 129 | + demo03CourseInnerMapper.insertBatch(list); | |
| 130 | + } | |
| 131 | + | |
| 132 | + private void updateDemo03CourseList(Long studentId, List<Demo03CourseDO> list) { | |
| 133 | + list.forEach(o -> o.setStudentId(studentId)); | |
| 134 | + List<Demo03CourseDO> oldList = demo03CourseInnerMapper.selectListByStudentId(studentId); | |
| 135 | + List<List<Demo03CourseDO>> diffList = diffList(oldList, list, (oldVal, newVal) -> { | |
| 136 | + boolean same = ObjectUtil.equal(oldVal.getId(), newVal.getId()); | |
| 137 | + if (same) { | |
| 138 | + newVal.setId(oldVal.getId()).setUpdater(null).setUpdateTime(null); // 解决更新情况下:updateTime 不更新 | |
| 139 | + } | |
| 140 | + return same; | |
| 141 | + }); | |
| 142 | + | |
| 143 | + // 第二步,批量添加、修改、删除 | |
| 144 | + if (CollUtil.isNotEmpty(diffList.get(0))) { | |
| 145 | + demo03CourseInnerMapper.insertBatch(diffList.get(0)); | |
| 146 | + } | |
| 147 | + if (CollUtil.isNotEmpty(diffList.get(1))) { | |
| 148 | + demo03CourseInnerMapper.updateBatch(diffList.get(1)); | |
| 149 | + } | |
| 150 | + if (CollUtil.isNotEmpty(diffList.get(2))) { | |
| 151 | + demo03CourseInnerMapper.deleteByIds(convertList(diffList.get(2), Demo03CourseDO::getId)); | |
| 152 | + } | |
| 153 | + } | |
| 154 | + | |
| 155 | + private void deleteDemo03CourseByStudentId(Long studentId) { | |
| 156 | + demo03CourseInnerMapper.deleteByStudentId(studentId); | |
| 157 | + } | |
| 158 | + | |
| 159 | + private void deleteDemo03CourseByStudentIds(List<Long> studentIds) { | |
| 160 | + demo03CourseInnerMapper.deleteByStudentIds(studentIds); | |
| 161 | + } | |
| 162 | + | |
| 163 | + // ==================== 子表(学生班级) ==================== | |
| 164 | + | |
| 165 | + @Override | |
| 166 | + public Demo03GradeDO getDemo03GradeByStudentId(Long studentId) { | |
| 167 | + return demo03GradeInnerMapper.selectByStudentId(studentId); | |
| 168 | + } | |
| 169 | + | |
| 170 | + private void createDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) { | |
| 171 | + if (demo03Grade == null) { | |
| 172 | + return; | |
| 173 | + } | |
| 174 | + demo03Grade.setStudentId(studentId); | |
| 175 | + demo03GradeInnerMapper.insert(demo03Grade); | |
| 176 | + } | |
| 177 | + | |
| 178 | + private void updateDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) { | |
| 179 | + if (demo03Grade == null) { | |
| 180 | + return; | |
| 181 | + } | |
| 182 | + demo03Grade.setStudentId(studentId); | |
| 183 | + demo03Grade.setUpdater(null).setUpdateTime(null); // 解决更新情况下:updateTime 不更新 | |
| 184 | + demo03GradeInnerMapper.insertOrUpdate(demo03Grade); | |
| 185 | + } | |
| 186 | + | |
| 187 | + private void deleteDemo03GradeByStudentId(Long studentId) { | |
| 188 | + demo03GradeInnerMapper.deleteByStudentId(studentId); | |
| 189 | + } | |
| 190 | + | |
| 191 | + private void deleteDemo03GradeByStudentIds(List<Long> studentIds) { | |
| 192 | + demo03GradeInnerMapper.deleteByStudentIds(studentIds); | |
| 193 | + } | |
| 194 | + | |
| 195 | +} | |
| 0 | 196 | \ No newline at end of file | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/normal/Demo03StudentNormalService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo.demo03.normal; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalPageReqVO; | |
| 5 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalSaveReqVO; | |
| 6 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; | |
| 7 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; | |
| 8 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; | |
| 9 | +import jakarta.validation.Valid; | |
| 10 | + | |
| 11 | +import java.util.List; | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * 学生 Service 接口 | |
| 15 | + * | |
| 16 | + * @author 芋道源码 | |
| 17 | + */ | |
| 18 | +public interface Demo03StudentNormalService { | |
| 19 | + | |
| 20 | + /** | |
| 21 | + * 创建学生 | |
| 22 | + * | |
| 23 | + * @param createReqVO 创建信息 | |
| 24 | + * @return 编号 | |
| 25 | + */ | |
| 26 | + Long createDemo03Student(@Valid Demo03StudentNormalSaveReqVO createReqVO); | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * 更新学生 | |
| 30 | + * | |
| 31 | + * @param updateReqVO 更新信息 | |
| 32 | + */ | |
| 33 | + void updateDemo03Student(@Valid Demo03StudentNormalSaveReqVO updateReqVO); | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * 删除学生 | |
| 37 | + * | |
| 38 | + * @param id 编号 | |
| 39 | + */ | |
| 40 | + void deleteDemo03Student(Long id); | |
| 41 | + | |
| 42 | + /** | |
| 43 | + * 批量删除学生 | |
| 44 | + * | |
| 45 | + * @param ids 编号 | |
| 46 | + */ | |
| 47 | + void deleteDemo03StudentByIds(List<Long> ids); | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * 获得学生 | |
| 51 | + * | |
| 52 | + * @param id 编号 | |
| 53 | + * @return 学生 | |
| 54 | + */ | |
| 55 | + Demo03StudentDO getDemo03Student(Long id); | |
| 56 | + | |
| 57 | + /** | |
| 58 | + * 获得学生分页 | |
| 59 | + * | |
| 60 | + * @param pageReqVO 分页查询 | |
| 61 | + * @return 学生分页 | |
| 62 | + */ | |
| 63 | + PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentNormalPageReqVO pageReqVO); | |
| 64 | + | |
| 65 | + // ==================== 子表(学生课程) ==================== | |
| 66 | + | |
| 67 | + /** | |
| 68 | + * 获得学生课程列表 | |
| 69 | + * | |
| 70 | + * @param studentId 学生编号 | |
| 71 | + * @return 学生课程列表 | |
| 72 | + */ | |
| 73 | + List<Demo03CourseDO> getDemo03CourseListByStudentId(Long studentId); | |
| 74 | + | |
| 75 | + // ==================== 子表(学生班级) ==================== | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * 获得学生班级 | |
| 79 | + * | |
| 80 | + * @param studentId 学生编号 | |
| 81 | + * @return 学生班级 | |
| 82 | + */ | |
| 83 | + Demo03GradeDO getDemo03GradeByStudentId(Long studentId); | |
| 84 | + | |
| 85 | +} | |
| 0 | 86 | \ No newline at end of file | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/normal/Demo03StudentNormalServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo.demo03.normal; | |
| 2 | + | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 4 | +import cn.hutool.core.util.ObjectUtil; | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 7 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalPageReqVO; | |
| 8 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalSaveReqVO; | |
| 9 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; | |
| 10 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; | |
| 11 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; | |
| 12 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.normal.Demo03CourseNormalMapper; | |
| 13 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.normal.Demo03GradeNormalMapper; | |
| 14 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.normal.Demo03StudentNormalMapper; | |
| 15 | +import jakarta.annotation.Resource; | |
| 16 | +import org.springframework.stereotype.Service; | |
| 17 | +import org.springframework.transaction.annotation.Transactional; | |
| 18 | +import org.springframework.validation.annotation.Validated; | |
| 19 | + | |
| 20 | +import java.util.List; | |
| 21 | + | |
| 22 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 23 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; | |
| 24 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList; | |
| 25 | +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.DEMO03_STUDENT_NOT_EXISTS; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * 学生 Service 实现类 | |
| 29 | + * | |
| 30 | + * @author 芋道源码 | |
| 31 | + */ | |
| 32 | +@Service | |
| 33 | +@Validated | |
| 34 | +public class Demo03StudentNormalServiceImpl implements Demo03StudentNormalService { | |
| 35 | + | |
| 36 | + @Resource | |
| 37 | + private Demo03StudentNormalMapper demo03StudentNormalMapper; | |
| 38 | + @Resource | |
| 39 | + private Demo03CourseNormalMapper demo03CourseNormalMapper; | |
| 40 | + @Resource | |
| 41 | + private Demo03GradeNormalMapper demo03GradeNormalMapper; | |
| 42 | + | |
| 43 | + @Override | |
| 44 | + @Transactional(rollbackFor = Exception.class) | |
| 45 | + public Long createDemo03Student(Demo03StudentNormalSaveReqVO createReqVO) { | |
| 46 | + // 插入 | |
| 47 | + Demo03StudentDO demo03Student = BeanUtils.toBean(createReqVO, Demo03StudentDO.class); | |
| 48 | + demo03StudentNormalMapper.insert(demo03Student); | |
| 49 | + | |
| 50 | + // 插入子表 | |
| 51 | + createDemo03CourseList(demo03Student.getId(), createReqVO.getDemo03Courses()); | |
| 52 | + createDemo03Grade(demo03Student.getId(), createReqVO.getDemo03Grade()); | |
| 53 | + // 返回 | |
| 54 | + return demo03Student.getId(); | |
| 55 | + } | |
| 56 | + | |
| 57 | + @Override | |
| 58 | + @Transactional(rollbackFor = Exception.class) | |
| 59 | + public void updateDemo03Student(Demo03StudentNormalSaveReqVO updateReqVO) { | |
| 60 | + // 校验存在 | |
| 61 | + validateDemo03StudentExists(updateReqVO.getId()); | |
| 62 | + // 更新 | |
| 63 | + Demo03StudentDO updateObj = BeanUtils.toBean(updateReqVO, Demo03StudentDO.class); | |
| 64 | + demo03StudentNormalMapper.updateById(updateObj); | |
| 65 | + | |
| 66 | + // 更新子表 | |
| 67 | + updateDemo03CourseList(updateReqVO.getId(), updateReqVO.getDemo03Courses()); | |
| 68 | + updateDemo03Grade(updateReqVO.getId(), updateReqVO.getDemo03Grade()); | |
| 69 | + } | |
| 70 | + | |
| 71 | + @Override | |
| 72 | + @Transactional(rollbackFor = Exception.class) | |
| 73 | + public void deleteDemo03Student(Long id) { | |
| 74 | + // 校验存在 | |
| 75 | + validateDemo03StudentExists(id); | |
| 76 | + // 删除 | |
| 77 | + demo03StudentNormalMapper.deleteById(id); | |
| 78 | + | |
| 79 | + // 删除子表 | |
| 80 | + deleteDemo03CourseByStudentId(id); | |
| 81 | + deleteDemo03GradeByStudentId(id); | |
| 82 | + } | |
| 83 | + | |
| 84 | + @Override | |
| 85 | + @Transactional(rollbackFor = Exception.class) | |
| 86 | + public void deleteDemo03StudentByIds(List<Long> ids) { | |
| 87 | + // 校验存在 | |
| 88 | + validateDemo03StudentExists(ids); | |
| 89 | + // 删除 | |
| 90 | + demo03StudentNormalMapper.deleteByIds(ids); | |
| 91 | + | |
| 92 | + // 删除子表 | |
| 93 | + deleteDemo03CourseByStudentIds(ids); | |
| 94 | + deleteDemo03GradeByStudentIds(ids); | |
| 95 | + } | |
| 96 | + | |
| 97 | + private void validateDemo03StudentExists(List<Long> ids) { | |
| 98 | + List<Demo03StudentDO> list = demo03StudentNormalMapper.selectByIds(ids); | |
| 99 | + if (CollUtil.isEmpty(list) || list.size() != ids.size()) { | |
| 100 | + throw exception(DEMO03_STUDENT_NOT_EXISTS); | |
| 101 | + } | |
| 102 | + } | |
| 103 | + | |
| 104 | + private void validateDemo03StudentExists(Long id) { | |
| 105 | + if (demo03StudentNormalMapper.selectById(id) == null) { | |
| 106 | + throw exception(DEMO03_STUDENT_NOT_EXISTS); | |
| 107 | + } | |
| 108 | + } | |
| 109 | + | |
| 110 | + @Override | |
| 111 | + public Demo03StudentDO getDemo03Student(Long id) { | |
| 112 | + return demo03StudentNormalMapper.selectById(id); | |
| 113 | + } | |
| 114 | + | |
| 115 | + @Override | |
| 116 | + public PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentNormalPageReqVO pageReqVO) { | |
| 117 | + return demo03StudentNormalMapper.selectPage(pageReqVO); | |
| 118 | + } | |
| 119 | + | |
| 120 | + // ==================== 子表(学生课程) ==================== | |
| 121 | + | |
| 122 | + @Override | |
| 123 | + public List<Demo03CourseDO> getDemo03CourseListByStudentId(Long studentId) { | |
| 124 | + return demo03CourseNormalMapper.selectListByStudentId(studentId); | |
| 125 | + } | |
| 126 | + | |
| 127 | + private void createDemo03CourseList(Long studentId, List<Demo03CourseDO> list) { | |
| 128 | + list.forEach(o -> o.setStudentId(studentId)); | |
| 129 | + demo03CourseNormalMapper.insertBatch(list); | |
| 130 | + } | |
| 131 | + | |
| 132 | + private void updateDemo03CourseList(Long studentId, List<Demo03CourseDO> list) { | |
| 133 | + list.forEach(o -> o.setStudentId(studentId)); | |
| 134 | + List<Demo03CourseDO> oldList = demo03CourseNormalMapper.selectListByStudentId(studentId); | |
| 135 | + List<List<Demo03CourseDO>> diffList = diffList(oldList, list, (oldVal, newVal) -> { | |
| 136 | + boolean same = ObjectUtil.equal(oldVal.getId(), newVal.getId()); | |
| 137 | + if (same) { | |
| 138 | + newVal.setId(oldVal.getId()).setUpdater(null).setUpdateTime(null); // 解决更新情况下:updateTime 不更新 | |
| 139 | + } | |
| 140 | + return same; | |
| 141 | + }); | |
| 142 | + | |
| 143 | + // 第二步,批量添加、修改、删除 | |
| 144 | + if (CollUtil.isNotEmpty(diffList.get(0))) { | |
| 145 | + demo03CourseNormalMapper.insertBatch(diffList.get(0)); | |
| 146 | + } | |
| 147 | + if (CollUtil.isNotEmpty(diffList.get(1))) { | |
| 148 | + demo03CourseNormalMapper.updateBatch(diffList.get(1)); | |
| 149 | + } | |
| 150 | + if (CollUtil.isNotEmpty(diffList.get(2))) { | |
| 151 | + demo03CourseNormalMapper.deleteByIds(convertList(diffList.get(2), Demo03CourseDO::getId)); | |
| 152 | + } | |
| 153 | + } | |
| 154 | + | |
| 155 | + private void deleteDemo03CourseByStudentId(Long studentId) { | |
| 156 | + demo03CourseNormalMapper.deleteByStudentId(studentId); | |
| 157 | + } | |
| 158 | + | |
| 159 | + private void deleteDemo03CourseByStudentIds(List<Long> studentIds) { | |
| 160 | + demo03CourseNormalMapper.deleteByStudentIds(studentIds); | |
| 161 | + } | |
| 162 | + | |
| 163 | + // ==================== 子表(学生班级) ==================== | |
| 164 | + | |
| 165 | + @Override | |
| 166 | + public Demo03GradeDO getDemo03GradeByStudentId(Long studentId) { | |
| 167 | + return demo03GradeNormalMapper.selectByStudentId(studentId); | |
| 168 | + } | |
| 169 | + | |
| 170 | + private void createDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) { | |
| 171 | + if (demo03Grade == null) { | |
| 172 | + return; | |
| 173 | + } | |
| 174 | + demo03Grade.setStudentId(studentId); | |
| 175 | + demo03GradeNormalMapper.insert(demo03Grade); | |
| 176 | + } | |
| 177 | + | |
| 178 | + private void updateDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) { | |
| 179 | + if (demo03Grade == null) { | |
| 180 | + return; | |
| 181 | + } | |
| 182 | + demo03Grade.setStudentId(studentId); | |
| 183 | + demo03Grade.setUpdater(null).setUpdateTime(null); // 解决更新情况下:updateTime 不更新 | |
| 184 | + demo03GradeNormalMapper.insertOrUpdate(demo03Grade); | |
| 185 | + } | |
| 186 | + | |
| 187 | + private void deleteDemo03GradeByStudentId(Long studentId) { | |
| 188 | + demo03GradeNormalMapper.deleteByStudentId(studentId); | |
| 189 | + } | |
| 190 | + | |
| 191 | + private void deleteDemo03GradeByStudentIds(List<Long> studentIds) { | |
| 192 | + demo03GradeNormalMapper.deleteByStudentIds(studentIds); | |
| 193 | + } | |
| 194 | + | |
| 195 | +} | |
| 0 | 196 | \ 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
| ... | ... | @@ -74,6 +74,19 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { |
| 74 | 74 | return success(true); |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | +#if ( $table.templateType != 2 && $deleteBatchEnable) | |
| 78 | + @DeleteMapping("/delete-batch") | |
| 79 | + @Parameter(name = "ids", description = "编号", required = true) | |
| 80 | + @Operation(summary = "批量删除${table.classComment}") | |
| 81 | + #if ($sceneEnum.scene == 1) | |
| 82 | + @PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')") | |
| 83 | + #end | |
| 84 | + public CommonResult<Boolean> delete${simpleClassName}(@RequestParam("ids") List<${primaryColumn.javaType}> ids) { | |
| 85 | + ${classNameVar}Service.delete${simpleClassName}ByIds(ids); | |
| 86 | + return success(true); | |
| 87 | + } | |
| 88 | +#end | |
| 89 | + | |
| 77 | 90 | @GetMapping("/get") |
| 78 | 91 | @Operation(summary = "获得${table.classComment}") |
| 79 | 92 | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| ... | ... | @@ -230,6 +243,19 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { |
| 230 | 243 | return success(true); |
| 231 | 244 | } |
| 232 | 245 | |
| 246 | +#if ($deleteBatchEnable) | |
| 247 | + @DeleteMapping("/${subSimpleClassName_strikeCase}/delete-batch") | |
| 248 | + @Parameter(name = "ids", description = "编号", required = true) | |
| 249 | + @Operation(summary = "批量删除${subTable.classComment}") | |
| 250 | +#if ($sceneEnum.scene == 1) | |
| 251 | + @PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')") | |
| 252 | +#end | |
| 253 | + public CommonResult<Boolean> delete${subSimpleClassName}(@RequestParam("ids") List<${subPrimaryColumn.javaType}> ids) { | |
| 254 | + ${classNameVar}Service.delete${subSimpleClassName}ByIds(ids); | |
| 255 | + return success(true); | |
| 256 | + } | |
| 257 | +#end | |
| 258 | + | |
| 233 | 259 | @GetMapping("/${subSimpleClassName_strikeCase}/get") |
| 234 | 260 | @Operation(summary = "获得${subTable.classComment}") |
| 235 | 261 | @Parameter(name = "id", description = "编号", required = true) | ... | ... |
yudao-module-infra/src/main/resources/codegen/java/dal/do.vm
| ... | ... | @@ -78,4 +78,19 @@ public class ${table.className}DO extends BaseDO { |
| 78 | 78 | #end |
| 79 | 79 | #end |
| 80 | 80 | |
| 81 | +## 特殊:主子表专属逻辑(非 ERP 模式) | |
| 82 | +#if ( $voType == 20 && $subTables && $subTables.size() > 0 && $table.templateType != 11 ) | |
| 83 | + #foreach ($subTable in $subTables) | |
| 84 | + #set ($index = $foreach.count - 1) | |
| 85 | + #if ( $subTable.subJoinMany) | |
| 86 | + @Schema(description = "${subTable.classComment}列表") | |
| 87 | + private List<${subTable.className}DO> ${subClassNameVars.get($index)}s; | |
| 88 | + | |
| 89 | + #else | |
| 90 | + @Schema(description = "${subTable.classComment}") | |
| 91 | + private ${subTable.className}DO ${subClassNameVars.get($index)}; | |
| 92 | + #end | |
| 93 | + #end | |
| 94 | +#end | |
| 95 | + | |
| 81 | 96 | } |
| 82 | 97 | \ No newline at end of file | ... | ... |
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 |
| 54 | 54 | return delete(${subTable.className}DO::get${SubJoinColumnName}, ${subJoinColumn.javaField}); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | +#if ( $table.templateType != 2 && $deleteBatchEnable) | |
| 58 | + default int deleteBy${SubJoinColumnName}s(List<${subJoinColumn.javaType}> ${subJoinColumn.javaField}s) { | |
| 59 | + return delete(${subTable.className}DO::get${SubJoinColumnName}, ${subJoinColumn.javaField}s); | |
| 60 | + } | |
| 61 | +#end | |
| 62 | + | |
| 57 | 63 | } | ... | ... |
yudao-module-infra/src/main/resources/codegen/java/service/service.vm
| ... | ... | @@ -40,6 +40,15 @@ public interface ${table.className}Service { |
| 40 | 40 | */ |
| 41 | 41 | void delete${simpleClassName}(${primaryColumn.javaType} id); |
| 42 | 42 | |
| 43 | +#if ( $table.templateType != 2 && $deleteBatchEnable) | |
| 44 | + /** | |
| 45 | + * 批量删除${table.classComment} | |
| 46 | + * | |
| 47 | + * @param ids 编号 | |
| 48 | + */ | |
| 49 | + void delete${simpleClassName}ByIds(List<${primaryColumn.javaType}> ids); | |
| 50 | +#end | |
| 51 | + | |
| 43 | 52 | /** |
| 44 | 53 | * 获得${table.classComment} |
| 45 | 54 | * |
| ... | ... | @@ -134,6 +143,15 @@ public interface ${table.className}Service { |
| 134 | 143 | */ |
| 135 | 144 | void delete${subSimpleClassName}(${subPrimaryColumn.javaType} id); |
| 136 | 145 | |
| 146 | +#if ($deleteBatchEnable) | |
| 147 | + /** | |
| 148 | + * 批量删除${subTable.classComment} | |
| 149 | + * | |
| 150 | + * @param ids 编号 | |
| 151 | + */ | |
| 152 | + void delete${subSimpleClassName}ByIds(List<${subPrimaryColumn.javaType}> ids); | |
| 153 | +#end | |
| 154 | + | |
| 137 | 155 | /** |
| 138 | 156 | * 获得${subTable.classComment} |
| 139 | 157 | * | ... | ... |
yudao-module-infra/src/main/resources/codegen/java/service/serviceImpl.vm
| 1 | 1 | package ${basePackage}.module.${table.moduleName}.service.${table.businessName}; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 3 | 4 | import org.springframework.stereotype.Service; |
| 4 | 5 | import ${jakartaPackage}.annotation.Resource; |
| 5 | 6 | import org.springframework.validation.annotation.Validated; |
| ... | ... | @@ -24,6 +25,8 @@ import ${basePackage}.module.${subTable.moduleName}.dal.mysql.${subTable.busines |
| 24 | 25 | #end |
| 25 | 26 | |
| 26 | 27 | import static ${ServiceExceptionUtilClassName}.exception; |
| 28 | +import static ${CollectionUtilsClassName}.convertList; | |
| 29 | +import static ${CollectionUtilsClassName}.diffList; | |
| 27 | 30 | import static ${basePackage}.module.${table.moduleName}.enums.ErrorCodeConstants.*; |
| 28 | 31 | |
| 29 | 32 | /** |
| ... | ... | @@ -55,9 +58,9 @@ public class ${table.className}ServiceImpl implements ${table.className}Service |
| 55 | 58 | #set ($TreeParentJavaField = $treeParentColumn.javaField.substring(0,1).toUpperCase() + ${treeParentColumn.javaField.substring(1)})##首字母大写 |
| 56 | 59 | #set ($TreeNameJavaField = $treeNameColumn.javaField.substring(0,1).toUpperCase() + ${treeNameColumn.javaField.substring(1)})##首字母大写 |
| 57 | 60 | // 校验${treeParentColumn.columnComment}的有效性 |
| 58 | - validateParent${simpleClassName}(null, ${createReqVOVar}.get${TreeParentJavaField}()); | |
| 61 | + validateParent${simpleClassName}(null, ${saveReqVOVar}.get${TreeParentJavaField}()); | |
| 59 | 62 | // 校验${treeNameColumn.columnComment}的唯一性 |
| 60 | - validate${simpleClassName}${TreeNameJavaField}Unique(null, ${createReqVOVar}.get${TreeParentJavaField}(), ${createReqVOVar}.get${TreeNameJavaField}()); | |
| 63 | + validate${simpleClassName}${TreeNameJavaField}Unique(null, ${saveReqVOVar}.get${TreeParentJavaField}(), ${saveReqVOVar}.get${TreeNameJavaField}()); | |
| 61 | 64 | |
| 62 | 65 | #end |
| 63 | 66 | // 插入 |
| ... | ... | @@ -75,9 +78,9 @@ public class ${table.className}ServiceImpl implements ${table.className}Service |
| 75 | 78 | #set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段 |
| 76 | 79 | #set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写 |
| 77 | 80 | #if ( $subTable.subJoinMany) |
| 78 | - create${subSimpleClassName}List(${classNameVar}.getId(), ${createReqVOVar}.get${subSimpleClassNames.get($index)}s()); | |
| 81 | + create${subSimpleClassName}List(${classNameVar}.getId(), ${saveReqVOVar}.get${subSimpleClassNames.get($index)}s()); | |
| 79 | 82 | #else |
| 80 | - create${subSimpleClassName}(${classNameVar}.getId(), ${createReqVOVar}.get${subSimpleClassNames.get($index)}()); | |
| 83 | + create${subSimpleClassName}(${classNameVar}.getId(), ${saveReqVOVar}.get${subSimpleClassNames.get($index)}()); | |
| 81 | 84 | #end |
| 82 | 85 | #end |
| 83 | 86 | #end |
| ... | ... | @@ -160,6 +163,39 @@ public class ${table.className}ServiceImpl implements ${table.className}Service |
| 160 | 163 | #end |
| 161 | 164 | } |
| 162 | 165 | |
| 166 | +#if ( $table.templateType != 2 && $deleteBatchEnable) | |
| 167 | + @Override | |
| 168 | + ## 特殊:主子表专属逻辑 | |
| 169 | + #if ( $subTables && $subTables.size() > 0) | |
| 170 | + @Transactional(rollbackFor = Exception.class) | |
| 171 | + #end | |
| 172 | + public void delete${simpleClassName}ByIds(List<${primaryColumn.javaType}> ids) { | |
| 173 | + // 校验存在 | |
| 174 | + validate${simpleClassName}Exists(ids); | |
| 175 | + // 删除 | |
| 176 | + ${classNameVar}Mapper.deleteByIds(ids); | |
| 177 | + ## 特殊:主子表专属逻辑 | |
| 178 | + #if ( $subTables && $subTables.size() > 0) | |
| 179 | + | |
| 180 | + // 删除子表 | |
| 181 | + #foreach ($subTable in $subTables) | |
| 182 | + #set ($index = $foreach.count - 1) | |
| 183 | + #set ($subSimpleClassName = $subSimpleClassNames.get($index)) | |
| 184 | + #set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段 | |
| 185 | + #set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写 | |
| 186 | + delete${subSimpleClassName}By${SubJoinColumnName}s(ids); | |
| 187 | + #end | |
| 188 | + #end | |
| 189 | + } | |
| 190 | + | |
| 191 | + private void validate${simpleClassName}Exists(List<${primaryColumn.javaType}> ids) { | |
| 192 | + List<${table.className}DO> list = ${classNameVar}Mapper.selectByIds(ids); | |
| 193 | + if (CollUtil.isEmpty(list) || list.size() != ids.size()) { | |
| 194 | + throw exception(${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS); | |
| 195 | + } | |
| 196 | + } | |
| 197 | +#end | |
| 198 | + | |
| 163 | 199 | private void validate${simpleClassName}Exists(${primaryColumn.javaType} id) { |
| 164 | 200 | if (${classNameVar}Mapper.selectById(id) == null) { |
| 165 | 201 | throw exception(${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS); |
| ... | ... | @@ -304,6 +340,16 @@ public class ${table.className}ServiceImpl implements ${table.className}Service |
| 304 | 340 | ${subClassNameVars.get($index)}Mapper.deleteById(id); |
| 305 | 341 | } |
| 306 | 342 | |
| 343 | +#if ($deleteBatchEnable) | |
| 344 | + @Override | |
| 345 | + public void delete${subSimpleClassName}ByIds(List<${subPrimaryColumn.javaType}> ids) { | |
| 346 | + // 校验存在 | |
| 347 | + validate${subSimpleClassName}Exists(ids); | |
| 348 | + // 删除 | |
| 349 | + ${subClassNameVars.get($index)}Mapper.deleteByIds(ids); | |
| 350 | + } | |
| 351 | +#end | |
| 352 | + | |
| 307 | 353 | @Override |
| 308 | 354 | public ${subTable.className}DO get${subSimpleClassName}(${subPrimaryColumn.javaType} id) { |
| 309 | 355 | return ${subClassNameVars.get($index)}Mapper.selectById(id); |
| ... | ... | @@ -315,18 +361,44 @@ public class ${table.className}ServiceImpl implements ${table.className}Service |
| 315 | 361 | } |
| 316 | 362 | } |
| 317 | 363 | |
| 364 | +#if ($deleteBatchEnable) | |
| 365 | + private void validate${subSimpleClassName}Exists(List<${subPrimaryColumn.javaType}> ids) { | |
| 366 | + List<${subTable.className}DO> list = ${subClassNameVar}Mapper.selectByIds(ids); | |
| 367 | + if (CollUtil.isEmpty(list) || list.size() != ids.size()) { | |
| 368 | + throw exception(${simpleClassNameUnderlineCase.toUpperCase()}_NOT_EXISTS); | |
| 369 | + } | |
| 370 | + } | |
| 371 | +#end | |
| 372 | + | |
| 318 | 373 | ## 情况二:非 MASTER_ERP 时,支持批量的新增、修改操作 |
| 319 | 374 | #else |
| 320 | 375 | #if ( $subTable.subJoinMany) |
| 321 | 376 | private void create${subSimpleClassName}List(${primaryColumn.javaType} ${subJoinColumn.javaField}, List<${subTable.className}DO> list) { |
| 322 | - list.forEach(o -> o.set$SubJoinColumnName(${subJoinColumn.javaField})); | |
| 377 | + list.forEach(o -> o.set${SubJoinColumnName}(${subJoinColumn.javaField})); | |
| 323 | 378 | ${subClassNameVars.get($index)}Mapper.insertBatch(list); |
| 324 | 379 | } |
| 325 | 380 | |
| 326 | 381 | private void update${subSimpleClassName}List(${primaryColumn.javaType} ${subJoinColumn.javaField}, List<${subTable.className}DO> list) { |
| 327 | - delete${subSimpleClassName}By${SubJoinColumnName}(${subJoinColumn.javaField}); | |
| 328 | - list.forEach(o -> o.setId(null).setUpdater(null).setUpdateTime(null)); // 解决更新情况下:1)id 冲突;2)updateTime 不更新 | |
| 329 | - create${subSimpleClassName}List(${subJoinColumn.javaField}, list); | |
| 382 | + list.forEach(o -> o.set${SubJoinColumnName}(${subJoinColumn.javaField})); | |
| 383 | + List<${subTable.className}DO> oldList = ${subClassNameVar}Mapper.selectListBy${SubJoinColumnName}(${subJoinColumn.javaField}); | |
| 384 | + List<List<${subTable.className}DO>> diffList = diffList(oldList, list, (oldVal, newVal) -> { | |
| 385 | + boolean same = ObjectUtil.equal(oldVal.getId(), newVal.getId()); | |
| 386 | + if (same) { | |
| 387 | + newVal.setId(oldVal.getId()).setUpdater(null).setUpdateTime(null); // 解决更新情况下:updateTime 不更新 | |
| 388 | + } | |
| 389 | + return same; | |
| 390 | + }); | |
| 391 | + | |
| 392 | + // 第二步,批量添加、修改、删除 | |
| 393 | + if (CollUtil.isNotEmpty(diffList.get(0))) { | |
| 394 | + ${subClassNameVar}Mapper.insertBatch(diffList.get(0)); | |
| 395 | + } | |
| 396 | + if (CollUtil.isNotEmpty(diffList.get(1))) { | |
| 397 | + ${subClassNameVar}Mapper.updateBatch(diffList.get(1)); | |
| 398 | + } | |
| 399 | + if (CollUtil.isNotEmpty(diffList.get(2))) { | |
| 400 | + ${subClassNameVar}Mapper.deleteByIds(convertList(diffList.get(2), ${subTable.className}DO::getId)); | |
| 401 | + } | |
| 330 | 402 | } |
| 331 | 403 | |
| 332 | 404 | #else |
| ... | ... | @@ -353,5 +425,11 @@ public class ${table.className}ServiceImpl implements ${table.className}Service |
| 353 | 425 | ${subClassNameVars.get($index)}Mapper.deleteBy${SubJoinColumnName}(${subJoinColumn.javaField}); |
| 354 | 426 | } |
| 355 | 427 | |
| 428 | +#if ( $table.templateType != 2 && $deleteBatchEnable) | |
| 429 | + private void delete${subSimpleClassName}By${SubJoinColumnName}s(List<${primaryColumn.javaType}> ${subJoinColumn.javaField}s) { | |
| 430 | + ${subClassNameVars.get($index)}Mapper.deleteBy${SubJoinColumnName}s(${subJoinColumn.javaField}s); | |
| 431 | + } | |
| 432 | +#end | |
| 433 | + | |
| 356 | 434 | #end |
| 357 | 435 | } |
| 358 | 436 | \ No newline at end of file | ... | ... |
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) { |
| 89 | 89 | return requestClient.delete(`${baseURL}/delete?id=${id}`); |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | +#if ( $table.templateType != 2 && $deleteBatchEnable) | |
| 93 | +// 批量删除${table.classComment} | |
| 94 | +export function delete${simpleClassName}ByIds(ids: number[]) { | |
| 95 | + return requestClient.delete(`${baseURL}/delete-batch?ids=${ids.join(',')}`) | |
| 96 | +} | |
| 97 | +#end | |
| 98 | + | |
| 92 | 99 | /** 导出${table.classComment} */ |
| 93 | 100 | export function export${simpleClassName}(params: any) { |
| 94 | 101 | return requestClient.download('${baseURL}/export-excel', params); |
| ... | ... | @@ -144,6 +151,13 @@ export function delete${subSimpleClassName}(id: number) { |
| 144 | 151 | return requestClient.delete(`${baseURL}/${subSimpleClassName_strikeCase}/delete?id=${id}`); |
| 145 | 152 | } |
| 146 | 153 | |
| 154 | +#if ($deleteBatchEnable) | |
| 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 | + | |
| 147 | 161 | /** 获得${subTable.classComment} */ |
| 148 | 162 | export function get${subSimpleClassName}(id: number) { |
| 149 | 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
| ... | ... | @@ -3,9 +3,11 @@ import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table'; |
| 3 | 3 | import type { ${simpleClassName}Api } from '#/api/${table.moduleName}/${table.businessName}'; |
| 4 | 4 | |
| 5 | 5 | import { z } from '#/adapter/form'; |
| 6 | -import { getRangePickerDefaultProps } from '#/utils/date'; | |
| 7 | -import { DICT_TYPE, getDictOptions } from '#/utils/dict'; | |
| 8 | - | |
| 6 | +import { | |
| 7 | + DICT_TYPE, | |
| 8 | + getDictOptions, | |
| 9 | + getRangePickerDefaultProps, | |
| 10 | +} from '#/utils'; | |
| 9 | 11 | #if(${table.templateType} == 2)## 树表需要导入这些 |
| 10 | 12 | import { get${simpleClassName}List } from '#/api/${table.moduleName}/${table.businessName}'; |
| 11 | 13 | import { handleTree } from '@vben/utils'; |
| ... | ... | @@ -191,6 +193,9 @@ export function useGridColumns( |
| 191 | 193 | onActionClick?: OnActionClickFn<${simpleClassName}Api.${simpleClassName}>, |
| 192 | 194 | ): VxeTableGridOptions<${simpleClassName}Api.${simpleClassName}>['columns'] { |
| 193 | 195 | return [ |
| 196 | +#if ($table.templateType != 2 && $deleteBatchEnable) | |
| 197 | + { type: 'checkbox', width: 40 }, | |
| 198 | +#end | |
| 194 | 199 | #if ($table.templateType == 12) ## 内嵌情况 |
| 195 | 200 | { type: 'expand', width: 80, slots: { content: 'expand_content' } }, |
| 196 | 201 | #end |
| ... | ... | @@ -426,6 +431,9 @@ export function use${subSimpleClassName}GridColumns( |
| 426 | 431 | onActionClick?: OnActionClickFn<${simpleClassName}Api.${subSimpleClassName}>, |
| 427 | 432 | ): VxeTableGridOptions<${simpleClassName}Api.${subSimpleClassName}>['columns'] { |
| 428 | 433 | return [ |
| 434 | + #if ($table.templateType != 2 && $deleteBatchEnable) | |
| 435 | + { type: 'checkbox', width: 40 }, | |
| 436 | + #end | |
| 429 | 437 | #foreach($column in $subColumns) |
| 430 | 438 | #if ($column.listOperationResult) |
| 431 | 439 | #set ($dictType = $column.dictType) | ... | ... |
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 |
| 4 | 4 | |
| 5 | 5 | import { Page, useVbenModal } from '@vben/common-ui'; |
| 6 | 6 | import { Button, message,Tabs } from 'ant-design-vue'; |
| 7 | -import { Download, Plus } from '@vben/icons'; | |
| 7 | +import { Download, Plus, Trash2 } from '@vben/icons'; | |
| 8 | 8 | import Form from './modules/form.vue'; |
| 9 | 9 | |
| 10 | 10 | ## 特殊:主子表专属逻辑 |
| ... | ... | @@ -16,15 +16,15 @@ import Form from './modules/form.vue'; |
| 16 | 16 | #end |
| 17 | 17 | #end |
| 18 | 18 | |
| 19 | -import { ref, h } from 'vue'; | |
| 19 | +import { ref, h, computed } from 'vue'; | |
| 20 | 20 | import { $t } from '#/locales'; |
| 21 | 21 | import { useVbenVxeGrid } from '#/adapter/vxe-table'; |
| 22 | 22 | #if (${table.templateType} == 2)## 树表接口 |
| 23 | 23 | import { get${simpleClassName}List, delete${simpleClassName}, export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}'; |
| 24 | 24 | #else## 标准表接口 |
| 25 | -import { get${simpleClassName}Page, delete${simpleClassName}, export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}'; | |
| 25 | +import { get${simpleClassName}Page, delete${simpleClassName},#if ($deleteBatchEnable) delete${simpleClassName}ByIds,#end export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}'; | |
| 26 | 26 | #end |
| 27 | -import { downloadFileFromBlobPart } from '@vben/utils'; | |
| 27 | +import { downloadFileFromBlobPart, isEmpty } from '@vben/utils'; | |
| 28 | 28 | |
| 29 | 29 | import { useGridColumns, useGridFormSchema } from './data'; |
| 30 | 30 | |
| ... | ... | @@ -87,11 +87,38 @@ async function onDelete(row: ${simpleClassName}Api.${simpleClassName}) { |
| 87 | 87 | await delete${simpleClassName}(row.id as number); |
| 88 | 88 | message.success( $t('ui.actionMessage.deleteSuccess', [row.id]) ); |
| 89 | 89 | onRefresh(); |
| 90 | - } catch { | |
| 90 | + } finally { | |
| 91 | 91 | hideLoading(); |
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | +#if ($table.templateType != 2 && $deleteBatchEnable) | |
| 96 | +const deleteIds = ref<number[]>([]) // 待删除${table.classComment} ID | |
| 97 | +const showDeleteBatchBtn = computed(() => isEmpty(deleteIds.value)); | |
| 98 | +function setDeleteIds({ | |
| 99 | + records, | |
| 100 | +}: { | |
| 101 | + records: ${simpleClassName}Api.${simpleClassName}[]; | |
| 102 | +}) { | |
| 103 | + deleteIds.value = records.map((item) => item.id); | |
| 104 | +} | |
| 105 | +/** 批量删除${table.classComment} */ | |
| 106 | +async function onDeleteBatch() { | |
| 107 | + const hideLoading = message.loading({ | |
| 108 | + content: $t('ui.actionMessage.deleting'), | |
| 109 | + duration: 0, | |
| 110 | + key: 'action_process_msg', | |
| 111 | + }); | |
| 112 | + try { | |
| 113 | + await delete${simpleClassName}ByIds(deleteIds.value); | |
| 114 | + message.success( $t('ui.actionMessage.deleteSuccess') ); | |
| 115 | + onRefresh(); | |
| 116 | + } finally { | |
| 117 | + hideLoading(); | |
| 118 | + } | |
| 119 | +} | |
| 120 | +#end | |
| 121 | + | |
| 95 | 122 | /** 导出表格 */ |
| 96 | 123 | async function onExport() { |
| 97 | 124 | const data = await export${simpleClassName}(await gridApi.formApi.getValues()); |
| ... | ... | @@ -177,11 +204,17 @@ const [Grid, gridApi] = useVbenVxeGrid({ |
| 177 | 204 | search: true, |
| 178 | 205 | }, |
| 179 | 206 | } as VxeTableGridOptions<${simpleClassName}Api.${simpleClassName}>, |
| 180 | -#if (${table.templateType} == 11) | |
| 207 | +#if (${table.templateType} == 11 || $deleteBatchEnable) | |
| 181 | 208 | gridEvents:{ |
| 209 | + #if(${table.templateType} == 11) | |
| 182 | 210 | cellClick: ({ row }: { row: ${simpleClassName}Api.${simpleClassName}}) => { |
| 183 | 211 | select${simpleClassName}.value = row; |
| 184 | 212 | }, |
| 213 | + #end | |
| 214 | + #if($deleteBatchEnable) | |
| 215 | + checkboxAll: setDeleteIds, | |
| 216 | + checkboxChange: setDeleteIds, | |
| 217 | + #end | |
| 185 | 218 | } |
| 186 | 219 | #end |
| 187 | 220 | }); |
| ... | ... | @@ -229,6 +262,19 @@ const [Grid, gridApi] = useVbenVxeGrid({ |
| 229 | 262 | > |
| 230 | 263 | {{ $t('ui.actionTitle.export') }} |
| 231 | 264 | </Button> |
| 265 | +#if ($table.templateType != 2 && $deleteBatchEnable) | |
| 266 | + <Button | |
| 267 | + :icon="h(Trash2)" | |
| 268 | + type="primary" | |
| 269 | + danger | |
| 270 | + class="ml-2" | |
| 271 | + :disabled="showDeleteBatchBtn" | |
| 272 | + @click="onDeleteBatch" | |
| 273 | + v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:delete']" | |
| 274 | + > | |
| 275 | + 批量删除 | |
| 276 | + </Button> | |
| 277 | +#end | |
| 232 | 278 | </template> |
| 233 | 279 | </Grid> |
| 234 | 280 | ... | ... |
yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/modules/list_sub_erp.vue.vm
| ... | ... | @@ -14,15 +14,16 @@ |
| 14 | 14 | #end |
| 15 | 15 | import { useVbenModal } from '@vben/common-ui'; |
| 16 | 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 | 19 | import { $t } from '#/locales'; |
| 20 | 20 | import { useVbenVxeGrid } from '#/adapter/vxe-table'; |
| 21 | 21 | |
| 22 | 22 | |
| 23 | 23 | #if ($table.templateType == 11) ## erp |
| 24 | - import { delete${subSimpleClassName}, get${subSimpleClassName}Page } from '#/api/${table.moduleName}/${table.businessName}'; | |
| 24 | + import { delete${subSimpleClassName},#if ($deleteBatchEnable) delete${subSimpleClassName}ByIds,#end get${subSimpleClassName}Page } from '#/api/${table.moduleName}/${table.businessName}'; | |
| 25 | 25 | import { use${subSimpleClassName}GridFormSchema, use${subSimpleClassName}GridColumns } from '../data'; |
| 26 | + import { isEmpty } from '@vben/utils'; | |
| 26 | 27 | #else |
| 27 | 28 | #if ($subTable.subJoinMany) ## 一对多 |
| 28 | 29 | import { get${subSimpleClassName}ListBy${SubJoinColumnName} } from '#/api/${table.moduleName}/${table.businessName}'; |
| ... | ... | @@ -67,11 +68,38 @@ async function onDelete(row: ${simpleClassName}Api.${subSimpleClassName}) { |
| 67 | 68 | await delete${subSimpleClassName}(row.id as number); |
| 68 | 69 | message.success( $t('ui.actionMessage.deleteSuccess', [row.id]) ); |
| 69 | 70 | onRefresh(); |
| 70 | - } catch { | |
| 71 | + } finally { | |
| 71 | 72 | hideLoading(); |
| 72 | 73 | } |
| 73 | 74 | } |
| 74 | 75 | |
| 76 | +#if ($deleteBatchEnable) | |
| 77 | +const deleteIds = ref<number[]>([]) // 待删除${subTable.classComment} ID | |
| 78 | +const showDeleteBatchBtn = computed(() => isEmpty(deleteIds.value)); | |
| 79 | +function setDeleteIds({ | |
| 80 | + records, | |
| 81 | +}: { | |
| 82 | + records: ${simpleClassName}Api.${subSimpleClassName}[]; | |
| 83 | +}) { | |
| 84 | + deleteIds.value = records.map((item) => item.id); | |
| 85 | +} | |
| 86 | +/** 批量删除${subTable.classComment} */ | |
| 87 | +async function onDeleteBatch() { | |
| 88 | + const hideLoading = message.loading({ | |
| 89 | + content: $t('ui.actionMessage.deleting'), | |
| 90 | + duration: 0, | |
| 91 | + key: 'action_process_msg', | |
| 92 | + }); | |
| 93 | + try { | |
| 94 | + await delete${subSimpleClassName}ByIds(deleteIds.value); | |
| 95 | + message.success( $t('ui.actionMessage.deleteSuccess') ); | |
| 96 | + onRefresh(); | |
| 97 | + } finally { | |
| 98 | + hideLoading(); | |
| 99 | + } | |
| 100 | +} | |
| 101 | +#end | |
| 102 | + | |
| 75 | 103 | /** 表格操作按钮的回调函数 */ |
| 76 | 104 | function onActionClick({ |
| 77 | 105 | code, |
| ... | ... | @@ -136,6 +164,12 @@ function onActionClick({ |
| 136 | 164 | isHover: true, |
| 137 | 165 | }, |
| 138 | 166 | } as VxeTableGridOptions<${simpleClassName}Api.${subSimpleClassName}>, |
| 167 | + #if (${table.templateType} == 11 && $deleteBatchEnable) | |
| 168 | + gridEvents:{ | |
| 169 | + checkboxAll: setDeleteIds, | |
| 170 | + checkboxChange: setDeleteIds, | |
| 171 | + } | |
| 172 | + #end | |
| 139 | 173 | }); |
| 140 | 174 | |
| 141 | 175 | /** 刷新表格 */ |
| ... | ... | @@ -173,6 +207,19 @@ const onRefresh = async ()=> { |
| 173 | 207 | <Button :icon="h(Plus)" type="primary" @click="onCreate" v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:create']"> |
| 174 | 208 | {{ $t('ui.actionTitle.create', ['${subTable.classComment}']) }} |
| 175 | 209 | </Button> |
| 210 | + #if ($table.templateType == 11 && $deleteBatchEnable) | |
| 211 | + <Button | |
| 212 | + :icon="h(Trash2)" | |
| 213 | + type="primary" | |
| 214 | + danger | |
| 215 | + class="ml-2" | |
| 216 | + :disabled="showDeleteBatchBtn" | |
| 217 | + @click="onDeleteBatch" | |
| 218 | + v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:delete']" | |
| 219 | + > | |
| 220 | + 批量删除 | |
| 221 | + </Button> | |
| 222 | + #end | |
| 176 | 223 | </template> |
| 177 | 224 | </Grid> |
| 178 | 225 | #else | ... | ... |
yudao-server/src/main/resources/application.yaml
| ... | ... | @@ -271,6 +271,7 @@ yudao: |
| 271 | 271 | front-type: 20 # 前端模版的类型,参见 CodegenFrontTypeEnum 枚举类 |
| 272 | 272 | vo-type: 10 # VO 的类型,参见 CodegenVOTypeEnum 枚举类 |
| 273 | 273 | unit-test-enable: false # 是否生成单元测试 |
| 274 | + delete-batch-enable: false # 是否生成批量删除接口 | |
| 274 | 275 | tenant: # 多租户相关配置项 |
| 275 | 276 | enable: true |
| 276 | 277 | ignore-urls: | ... | ... |