!1348 feat:【INFRA 基础设施】vben5-antd-schema 代码生成时,可生成批量删除

Merge pull request !1348 from puhui999/vben5-antd-schema
This commit is contained in:
芋道源码 2025-05-20 05:07:18 +00:00 committed by Gitee
commit d14aaae641
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
55 changed files with 1947 additions and 392 deletions

View File

@ -60,6 +60,15 @@ public class Demo01ContactController {
return success(true);
}
@DeleteMapping("/delete-batch")
@Parameter(name = "ids", description = "编号", required = true)
@Operation(summary = "批量删除示例联系人")
@PreAuthorize("@ss.hasPermission('infra:demo01-contact:delete')")
public CommonResult<Boolean> deleteDemo01Contact(@RequestParam("ids") List<Long> ids) {
demo01ContactService.deleteDemo01ContactByIds(ids);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得示例联系人")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@ -82,12 +91,12 @@ public class Demo01ContactController {
@PreAuthorize("@ss.hasPermission('infra:demo01-contact:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportDemo01ContactExcel(@Valid Demo01ContactPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<Demo01ContactDO> list = demo01ContactService.getDemo01ContactPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "示例联系人.xls", "数据", Demo01ContactRespVO.class,
BeanUtils.toBean(list, Demo01ContactRespVO.class));
BeanUtils.toBean(list, Demo01ContactRespVO.class));
}
}

View File

@ -1,10 +1,12 @@
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;

View File

@ -1,14 +1,13 @@
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import java.util.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 示例联系人 Response VO")
@Data

View File

@ -1,10 +1,10 @@
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 示例联系人新增/修改 Request VO")

View File

@ -80,11 +80,11 @@ public class Demo02CategoryController {
@PreAuthorize("@ss.hasPermission('infra:demo02-category:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportDemo02CategoryExcel(@Valid Demo02CategoryListReqVO listReqVO,
HttpServletResponse response) throws IOException {
HttpServletResponse response) throws IOException {
List<Demo02CategoryDO> list = demo02CategoryService.getDemo02CategoryList(listReqVO);
// 导出 Excel
ExcelUtils.write(response, "示例分类.xls", "数据", Demo02CategoryRespVO.class,
BeanUtils.toBean(list, Demo02CategoryRespVO.class));
BeanUtils.toBean(list, Demo02CategoryRespVO.class));
}
}

View File

@ -1,10 +1,9 @@
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo02.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
@Schema(description = "管理后台 - 示例分类新增/修改 Request VO")
@Data

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03;
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
@ -6,13 +6,13 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentPageReqVO;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentRespVO;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentSaveReqVO;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpPageReqVO;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpRespVO;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpSaveReqVO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
import cn.iocoder.yudao.module.infra.service.demo.demo03.Demo03StudentService;
import cn.iocoder.yudao.module.infra.service.demo.demo03.erp.Demo03StudentErpService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -31,25 +31,25 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 学生")
@RestController
@RequestMapping("/infra/demo03-student")
@RequestMapping("/infra/demo03-student-erp")
@Validated
public class Demo03StudentController {
public class Demo03StudentErpController {
@Resource
private Demo03StudentService demo03StudentService;
private Demo03StudentErpService demo03StudentErpService;
@PostMapping("/create")
@Operation(summary = "创建学生")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:create')")
public CommonResult<Long> createDemo03Student(@Valid @RequestBody Demo03StudentSaveReqVO createReqVO) {
return success(demo03StudentService.createDemo03Student(createReqVO));
public CommonResult<Long> createDemo03Student(@Valid @RequestBody Demo03StudentErpSaveReqVO createReqVO) {
return success(demo03StudentErpService.createDemo03Student(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新学生")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:update')")
public CommonResult<Boolean> updateDemo03Student(@Valid @RequestBody Demo03StudentSaveReqVO updateReqVO) {
demo03StudentService.updateDemo03Student(updateReqVO);
public CommonResult<Boolean> updateDemo03Student(@Valid @RequestBody Demo03StudentErpSaveReqVO updateReqVO) {
demo03StudentErpService.updateDemo03Student(updateReqVO);
return success(true);
}
@ -58,7 +58,16 @@ public class Demo03StudentController {
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')")
public CommonResult<Boolean> deleteDemo03Student(@RequestParam("id") Long id) {
demo03StudentService.deleteDemo03Student(id);
demo03StudentErpService.deleteDemo03Student(id);
return success(true);
}
@DeleteMapping("/delete-batch")
@Parameter(name = "ids", description = "编号", required = true)
@Operation(summary = "批量删除学生")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')")
public CommonResult<Boolean> deleteDemo03Student(@RequestParam("ids") List<Long> ids) {
demo03StudentErpService.deleteDemo03StudentByIds(ids);
return success(true);
}
@ -66,30 +75,30 @@ public class Demo03StudentController {
@Operation(summary = "获得学生")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
public CommonResult<Demo03StudentRespVO> getDemo03Student(@RequestParam("id") Long id) {
Demo03StudentDO demo03Student = demo03StudentService.getDemo03Student(id);
return success(BeanUtils.toBean(demo03Student, Demo03StudentRespVO.class));
public CommonResult<Demo03StudentErpRespVO> getDemo03Student(@RequestParam("id") Long id) {
Demo03StudentDO demo03Student = demo03StudentErpService.getDemo03Student(id);
return success(BeanUtils.toBean(demo03Student, Demo03StudentErpRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得学生分页")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
public CommonResult<PageResult<Demo03StudentRespVO>> getDemo03StudentPage(@Valid Demo03StudentPageReqVO pageReqVO) {
PageResult<Demo03StudentDO> pageResult = demo03StudentService.getDemo03StudentPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, Demo03StudentRespVO.class));
public CommonResult<PageResult<Demo03StudentErpRespVO>> getDemo03StudentPage(@Valid Demo03StudentErpPageReqVO pageReqVO) {
PageResult<Demo03StudentDO> pageResult = demo03StudentErpService.getDemo03StudentPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, Demo03StudentErpRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出学生 Excel")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportDemo03StudentExcel(@Valid Demo03StudentPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
public void exportDemo03StudentExcel(@Valid Demo03StudentErpPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<Demo03StudentDO> list = demo03StudentService.getDemo03StudentPage(pageReqVO).getList();
List<Demo03StudentDO> list = demo03StudentErpService.getDemo03StudentPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "学生.xls", "数据", Demo03StudentRespVO.class,
BeanUtils.toBean(list, Demo03StudentRespVO.class));
ExcelUtils.write(response, "学生.xls", "数据", Demo03StudentErpRespVO.class,
BeanUtils.toBean(list, Demo03StudentErpRespVO.class));
}
// ==================== 子表学生课程 ====================
@ -100,21 +109,21 @@ public class Demo03StudentController {
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
public CommonResult<PageResult<Demo03CourseDO>> getDemo03CoursePage(PageParam pageReqVO,
@RequestParam("studentId") Long studentId) {
return success(demo03StudentService.getDemo03CoursePage(pageReqVO, studentId));
return success(demo03StudentErpService.getDemo03CoursePage(pageReqVO, studentId));
}
@PostMapping("/demo03-course/create")
@Operation(summary = "创建学生课程")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:create')")
public CommonResult<Long> createDemo03Course(@Valid @RequestBody Demo03CourseDO demo03Course) {
return success(demo03StudentService.createDemo03Course(demo03Course));
return success(demo03StudentErpService.createDemo03Course(demo03Course));
}
@PutMapping("/demo03-course/update")
@Operation(summary = "更新学生课程")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:update')")
public CommonResult<Boolean> updateDemo03Course(@Valid @RequestBody Demo03CourseDO demo03Course) {
demo03StudentService.updateDemo03Course(demo03Course);
demo03StudentErpService.updateDemo03Course(demo03Course);
return success(true);
}
@ -123,7 +132,16 @@ public class Demo03StudentController {
@Operation(summary = "删除学生课程")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')")
public CommonResult<Boolean> deleteDemo03Course(@RequestParam("id") Long id) {
demo03StudentService.deleteDemo03Course(id);
demo03StudentErpService.deleteDemo03Course(id);
return success(true);
}
@DeleteMapping("/demo03-course/delete-batch")
@Parameter(name = "ids", description = "编号", required = true)
@Operation(summary = "批量删除学生课程")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')")
public CommonResult<Boolean> deleteDemo03Course(@RequestParam("ids") List<Long> ids) {
demo03StudentErpService.deleteDemo03CourseByIds(ids);
return success(true);
}
@ -132,15 +150,7 @@ public class Demo03StudentController {
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
public CommonResult<Demo03CourseDO> getDemo03Course(@RequestParam("id") Long id) {
return success(demo03StudentService.getDemo03Course(id));
}
@GetMapping("/demo03-course/list-by-student-id")
@Operation(summary = "获得学生课程列表")
@Parameter(name = "studentId", description = "学生编号")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
public CommonResult<List<Demo03CourseDO>> getDemo03CourseListByStudentId(@RequestParam("studentId") Long studentId) {
return success(demo03StudentService.getDemo03CourseListByStudentId(studentId));
return success(demo03StudentErpService.getDemo03Course(id));
}
// ==================== 子表学生班级 ====================
@ -151,21 +161,21 @@ public class Demo03StudentController {
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
public CommonResult<PageResult<Demo03GradeDO>> getDemo03GradePage(PageParam pageReqVO,
@RequestParam("studentId") Long studentId) {
return success(demo03StudentService.getDemo03GradePage(pageReqVO, studentId));
return success(demo03StudentErpService.getDemo03GradePage(pageReqVO, studentId));
}
@PostMapping("/demo03-grade/create")
@Operation(summary = "创建学生班级")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:create')")
public CommonResult<Long> createDemo03Grade(@Valid @RequestBody Demo03GradeDO demo03Grade) {
return success(demo03StudentService.createDemo03Grade(demo03Grade));
return success(demo03StudentErpService.createDemo03Grade(demo03Grade));
}
@PutMapping("/demo03-grade/update")
@Operation(summary = "更新学生班级")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:update')")
public CommonResult<Boolean> updateDemo03Grade(@Valid @RequestBody Demo03GradeDO demo03Grade) {
demo03StudentService.updateDemo03Grade(demo03Grade);
demo03StudentErpService.updateDemo03Grade(demo03Grade);
return success(true);
}
@ -174,7 +184,16 @@ public class Demo03StudentController {
@Operation(summary = "删除学生班级")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')")
public CommonResult<Boolean> deleteDemo03Grade(@RequestParam("id") Long id) {
demo03StudentService.deleteDemo03Grade(id);
demo03StudentErpService.deleteDemo03Grade(id);
return success(true);
}
@DeleteMapping("/demo03-grade/delete-batch")
@Parameter(name = "ids", description = "编号", required = true)
@Operation(summary = "批量删除学生班级")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')")
public CommonResult<Boolean> deleteDemo03Grade(@RequestParam("ids") List<Long> ids) {
demo03StudentErpService.deleteDemo03GradeByIds(ids);
return success(true);
}
@ -183,15 +202,7 @@ public class Demo03StudentController {
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
public CommonResult<Demo03GradeDO> getDemo03Grade(@RequestParam("id") Long id) {
return success(demo03StudentService.getDemo03Grade(id));
}
@GetMapping("/demo03-grade/get-by-student-id")
@Operation(summary = "获得学生班级")
@Parameter(name = "studentId", description = "学生编号")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
public CommonResult<Demo03GradeDO> getDemo03GradeByStudentId(@RequestParam("studentId") Long studentId) {
return success(demo03StudentService.getDemo03GradeByStudentId(studentId));
return success(demo03StudentErpService.getDemo03Grade(id));
}
}

View File

@ -1,9 +1,12 @@
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo;
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo;
import lombok.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@ -12,7 +15,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class Demo03StudentPageReqVO extends PageParam {
public class Demo03StudentErpPageReqVO extends PageParam {
@Schema(description = "名字", example = "芋艿")
private String name;

View File

@ -1,17 +1,18 @@
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo;
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 学生 Response VO")
@Data
@ExcelIgnoreUnannotated
public class Demo03StudentRespVO {
public class Demo03StudentErpRespVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525")
@ExcelProperty("编号")

View File

@ -0,0 +1,33 @@
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 学生新增/修改 Request VO")
@Data
public class Demo03StudentErpSaveReqVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525")
private Long id;
@Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
@NotEmpty(message = "名字不能为空")
private String name;
@Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "性别不能为空")
private Integer sex;
@Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "出生日期不能为空")
private LocalDateTime birthday;
@Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "随便")
@NotEmpty(message = "简介不能为空")
private String description;
}

View File

@ -0,0 +1,124 @@
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerPageReqVO;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerRespVO;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerSaveReqVO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
import cn.iocoder.yudao.module.infra.service.demo.demo03.inner.Demo03StudentInnerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.List;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 学生")
@RestController
@RequestMapping("/infra/demo03-student-inner")
@Validated
public class Demo03StudentInnerController {
@Resource
private Demo03StudentInnerService demo03StudentInnerService;
@PostMapping("/create")
@Operation(summary = "创建学生")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:create')")
public CommonResult<Long> createDemo03Student(@Valid @RequestBody Demo03StudentInnerSaveReqVO createReqVO) {
return success(demo03StudentInnerService.createDemo03Student(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新学生")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:update')")
public CommonResult<Boolean> updateDemo03Student(@Valid @RequestBody Demo03StudentInnerSaveReqVO updateReqVO) {
demo03StudentInnerService.updateDemo03Student(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除学生")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')")
public CommonResult<Boolean> deleteDemo03Student(@RequestParam("id") Long id) {
demo03StudentInnerService.deleteDemo03Student(id);
return success(true);
}
@DeleteMapping("/delete-batch")
@Parameter(name = "ids", description = "编号", required = true)
@Operation(summary = "批量删除学生")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')")
public CommonResult<Boolean> deleteDemo03Student(@RequestParam("ids") List<Long> ids) {
demo03StudentInnerService.deleteDemo03StudentByIds(ids);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得学生")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
public CommonResult<Demo03StudentInnerRespVO> getDemo03Student(@RequestParam("id") Long id) {
Demo03StudentDO demo03Student = demo03StudentInnerService.getDemo03Student(id);
return success(BeanUtils.toBean(demo03Student, Demo03StudentInnerRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得学生分页")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
public CommonResult<PageResult<Demo03StudentInnerRespVO>> getDemo03StudentPage(@Valid Demo03StudentInnerPageReqVO pageReqVO) {
PageResult<Demo03StudentDO> pageResult = demo03StudentInnerService.getDemo03StudentPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, Demo03StudentInnerRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出学生 Excel")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportDemo03StudentExcel(@Valid Demo03StudentInnerPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<Demo03StudentDO> list = demo03StudentInnerService.getDemo03StudentPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "学生.xls", "数据", Demo03StudentInnerRespVO.class,
BeanUtils.toBean(list, Demo03StudentInnerRespVO.class));
}
// ==================== 子表学生课程 ====================
@GetMapping("/demo03-course/list-by-student-id")
@Operation(summary = "获得学生课程列表")
@Parameter(name = "studentId", description = "学生编号")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
public CommonResult<List<Demo03CourseDO>> getDemo03CourseListByStudentId(@RequestParam("studentId") Long studentId) {
return success(demo03StudentInnerService.getDemo03CourseListByStudentId(studentId));
}
// ==================== 子表学生班级 ====================
@GetMapping("/demo03-grade/get-by-student-id")
@Operation(summary = "获得学生班级")
@Parameter(name = "studentId", description = "学生编号")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
public CommonResult<Demo03GradeDO> getDemo03GradeByStudentId(@RequestParam("studentId") Long studentId) {
return success(demo03StudentInnerService.getDemo03GradeByStudentId(studentId));
}
}

View File

@ -0,0 +1,33 @@
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 学生分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class Demo03StudentInnerPageReqVO extends PageParam {
@Schema(description = "名字", example = "芋艿")
private String name;
@Schema(description = "性别")
private Integer sex;
@Schema(description = "简介", example = "随便")
private String description;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@ -0,0 +1,42 @@
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 学生 Response VO")
@Data
@ExcelIgnoreUnannotated
public class Demo03StudentInnerRespVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525")
@ExcelProperty("编号")
private Long id;
@Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
@ExcelProperty("名字")
private String name;
@Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty(value = "性别", converter = DictConvert.class)
@DictFormat("system_user_sex") // TODO 代码优化建议设置到对应的 DictTypeConstants 枚举类中
private Integer sex;
@Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("出生日期")
private LocalDateTime birthday;
@Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "随便")
@ExcelProperty("简介")
private String description;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

View File

@ -1,16 +1,18 @@
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo;
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import jakarta.validation.constraints.*;
import java.time.LocalDateTime;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.List;
@Schema(description = "管理后台 - 学生新增/修改 Request VO")
@Data
public class Demo03StudentSaveReqVO {
public class Demo03StudentInnerSaveReqVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525")
private Long id;
@ -31,9 +33,10 @@ public class Demo03StudentSaveReqVO {
@NotEmpty(message = "简介不能为空")
private String description;
@Schema(description = "学生课程列表")
private List<Demo03CourseDO> demo03Courses;
@Schema(description = "学生班级")
private Demo03GradeDO demo03Grade;
}

View File

@ -0,0 +1,124 @@
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalPageReqVO;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalRespVO;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalSaveReqVO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
import cn.iocoder.yudao.module.infra.service.demo.demo03.normal.Demo03StudentNormalService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.List;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 学生")
@RestController
@RequestMapping("/infra/demo03-student-normal")
@Validated
public class Demo03StudentNormalController {
@Resource
private Demo03StudentNormalService demo03StudentNormalService;
@PostMapping("/create")
@Operation(summary = "创建学生")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:create')")
public CommonResult<Long> createDemo03Student(@Valid @RequestBody Demo03StudentNormalSaveReqVO createReqVO) {
return success(demo03StudentNormalService.createDemo03Student(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新学生")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:update')")
public CommonResult<Boolean> updateDemo03Student(@Valid @RequestBody Demo03StudentNormalSaveReqVO updateReqVO) {
demo03StudentNormalService.updateDemo03Student(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除学生")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')")
public CommonResult<Boolean> deleteDemo03Student(@RequestParam("id") Long id) {
demo03StudentNormalService.deleteDemo03Student(id);
return success(true);
}
@DeleteMapping("/delete-batch")
@Parameter(name = "ids", description = "编号", required = true)
@Operation(summary = "批量删除学生")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')")
public CommonResult<Boolean> deleteDemo03Student(@RequestParam("ids") List<Long> ids) {
demo03StudentNormalService.deleteDemo03StudentByIds(ids);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得学生")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
public CommonResult<Demo03StudentNormalRespVO> getDemo03Student(@RequestParam("id") Long id) {
Demo03StudentDO demo03Student = demo03StudentNormalService.getDemo03Student(id);
return success(BeanUtils.toBean(demo03Student, Demo03StudentNormalRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得学生分页")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
public CommonResult<PageResult<Demo03StudentNormalRespVO>> getDemo03StudentPage(@Valid Demo03StudentNormalPageReqVO pageReqVO) {
PageResult<Demo03StudentDO> pageResult = demo03StudentNormalService.getDemo03StudentPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, Demo03StudentNormalRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出学生 Excel")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportDemo03StudentExcel(@Valid Demo03StudentNormalPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<Demo03StudentDO> list = demo03StudentNormalService.getDemo03StudentPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "学生.xls", "数据", Demo03StudentNormalRespVO.class,
BeanUtils.toBean(list, Demo03StudentNormalRespVO.class));
}
// ==================== 子表学生课程 ====================
@GetMapping("/demo03-course/list-by-student-id")
@Operation(summary = "获得学生课程列表")
@Parameter(name = "studentId", description = "学生编号")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
public CommonResult<List<Demo03CourseDO>> getDemo03CourseListByStudentId(@RequestParam("studentId") Long studentId) {
return success(demo03StudentNormalService.getDemo03CourseListByStudentId(studentId));
}
// ==================== 子表学生班级 ====================
@GetMapping("/demo03-grade/get-by-student-id")
@Operation(summary = "获得学生班级")
@Parameter(name = "studentId", description = "学生编号")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
public CommonResult<Demo03GradeDO> getDemo03GradeByStudentId(@RequestParam("studentId") Long studentId) {
return success(demo03StudentNormalService.getDemo03GradeByStudentId(studentId));
}
}

View File

@ -0,0 +1,33 @@
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 学生分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class Demo03StudentNormalPageReqVO extends PageParam {
@Schema(description = "名字", example = "芋艿")
private String name;
@Schema(description = "性别")
private Integer sex;
@Schema(description = "简介", example = "随便")
private String description;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@ -0,0 +1,42 @@
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 学生 Response VO")
@Data
@ExcelIgnoreUnannotated
public class Demo03StudentNormalRespVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525")
@ExcelProperty("编号")
private Long id;
@Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
@ExcelProperty("名字")
private String name;
@Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty(value = "性别", converter = DictConvert.class)
@DictFormat("system_user_sex") // TODO 代码优化建议设置到对应的 DictTypeConstants 枚举类中
private Integer sex;
@Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("出生日期")
private LocalDateTime birthday;
@Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "随便")
@ExcelProperty("简介")
private String description;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

View File

@ -0,0 +1,42 @@
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.List;
@Schema(description = "管理后台 - 学生新增/修改 Request VO")
@Data
public class Demo03StudentNormalSaveReqVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525")
private Long id;
@Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
@NotEmpty(message = "名字不能为空")
private String name;
@Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "性别不能为空")
private Integer sex;
@Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "出生日期不能为空")
private LocalDateTime birthday;
@Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "随便")
@NotEmpty(message = "简介不能为空")
private String description;
@Schema(description = "学生课程列表")
private List<Demo03CourseDO> demo03Courses;
@Schema(description = "学生班级")
private Demo03GradeDO demo03Grade;
}

View File

@ -1 +0,0 @@
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03;

View File

@ -1,8 +1,8 @@
package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo01;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.Demo01ContactPageReqVO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo01.Demo01ContactDO;
import org.apache.ibatis.annotations.Mapper;

View File

@ -1,13 +1,13 @@
package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo02;
import java.util.*;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo02.vo.Demo02CategoryListReqVO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo02.Demo02CategoryDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 示例分类 Mapper
*
@ -24,9 +24,9 @@ public interface Demo02CategoryMapper extends BaseMapperX<Demo02CategoryDO> {
.orderByDesc(Demo02CategoryDO::getId));
}
default Demo02CategoryDO selectByParentIdAndName(Long parentId, String name) {
return selectOne(Demo02CategoryDO::getParentId, parentId, Demo02CategoryDO::getName, name);
}
default Demo02CategoryDO selectByParentIdAndName(Long parentId, String name) {
return selectOne(Demo02CategoryDO::getParentId, parentId, Demo02CategoryDO::getName, name);
}
default Long selectCountByParentId(Long parentId) {
return selectCount(Demo02CategoryDO::getParentId, parentId);

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03;
package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
@ -15,7 +15,7 @@ import java.util.List;
* @author 芋道源码
*/
@Mapper
public interface Demo03CourseMapper extends BaseMapperX<Demo03CourseDO> {
public interface Demo03CourseErpMapper extends BaseMapperX<Demo03CourseDO> {
default PageResult<Demo03CourseDO> selectPage(PageParam reqVO, Long studentId) {
return selectPage(reqVO, new LambdaQueryWrapperX<Demo03CourseDO>()
@ -23,12 +23,12 @@ public interface Demo03CourseMapper extends BaseMapperX<Demo03CourseDO> {
.orderByDesc(Demo03CourseDO::getId));
}
default List<Demo03CourseDO> selectListByStudentId(Long studentId) {
return selectList(Demo03CourseDO::getStudentId, studentId);
}
default int deleteByStudentId(Long studentId) {
return delete(Demo03CourseDO::getStudentId, studentId);
}
}
default int deleteByStudentIds(List<Long> studentIds) {
return delete(Demo03CourseDO::getStudentId, studentIds);
}
}

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03;
package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
@ -7,13 +7,15 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 学生班级 Mapper
*
* @author 芋道源码
*/
@Mapper
public interface Demo03GradeMapper extends BaseMapperX<Demo03GradeDO> {
public interface Demo03GradeErpMapper extends BaseMapperX<Demo03GradeDO> {
default PageResult<Demo03GradeDO> selectPage(PageParam reqVO, Long studentId) {
return selectPage(reqVO, new LambdaQueryWrapperX<Demo03GradeDO>()
@ -29,4 +31,8 @@ public interface Demo03GradeMapper extends BaseMapperX<Demo03GradeDO> {
return delete(Demo03GradeDO::getStudentId, studentId);
}
}
default int deleteByStudentIds(List<Long> studentIds) {
return delete(Demo03GradeDO::getStudentId, studentIds);
}
}

View File

@ -1,11 +1,11 @@
package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03;
package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpPageReqVO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.*;
/**
* 学生 Mapper
@ -13,9 +13,9 @@ import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.*;
* @author 芋道源码
*/
@Mapper
public interface Demo03StudentMapper extends BaseMapperX<Demo03StudentDO> {
public interface Demo03StudentErpMapper extends BaseMapperX<Demo03StudentDO> {
default PageResult<Demo03StudentDO> selectPage(Demo03StudentPageReqVO reqVO) {
default PageResult<Demo03StudentDO> selectPage(Demo03StudentErpPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<Demo03StudentDO>()
.likeIfPresent(Demo03StudentDO::getName, reqVO.getName())
.eqIfPresent(Demo03StudentDO::getSex, reqVO.getSex())

View File

@ -0,0 +1,29 @@
package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.inner;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 学生课程 Mapper
*
* @author 芋道源码
*/
@Mapper
public interface Demo03CourseInnerMapper extends BaseMapperX<Demo03CourseDO> {
default List<Demo03CourseDO> selectListByStudentId(Long studentId) {
return selectList(Demo03CourseDO::getStudentId, studentId);
}
default int deleteByStudentId(Long studentId) {
return delete(Demo03CourseDO::getStudentId, studentId);
}
default int deleteByStudentIds(List<Long> studentIds) {
return delete(Demo03CourseDO::getStudentId, studentIds);
}
}

View File

@ -0,0 +1,29 @@
package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.inner;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 学生班级 Mapper
*
* @author 芋道源码
*/
@Mapper
public interface Demo03GradeInnerMapper extends BaseMapperX<Demo03GradeDO> {
default Demo03GradeDO selectByStudentId(Long studentId) {
return selectOne(Demo03GradeDO::getStudentId, studentId);
}
default int deleteByStudentId(Long studentId) {
return delete(Demo03GradeDO::getStudentId, studentId);
}
default int deleteByStudentIds(List<Long> studentIds) {
return delete(Demo03GradeDO::getStudentId, studentIds);
}
}

View File

@ -0,0 +1,27 @@
package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.inner;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerPageReqVO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
import org.apache.ibatis.annotations.Mapper;
/**
* 学生 Mapper
*
* @author 芋道源码
*/
@Mapper
public interface Demo03StudentInnerMapper extends BaseMapperX<Demo03StudentDO> {
default PageResult<Demo03StudentDO> selectPage(Demo03StudentInnerPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<Demo03StudentDO>()
.likeIfPresent(Demo03StudentDO::getName, reqVO.getName())
.eqIfPresent(Demo03StudentDO::getSex, reqVO.getSex())
.eqIfPresent(Demo03StudentDO::getDescription, reqVO.getDescription())
.betweenIfPresent(Demo03StudentDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(Demo03StudentDO::getId));
}
}

View File

@ -0,0 +1,29 @@
package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.normal;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 学生课程 Mapper
*
* @author 芋道源码
*/
@Mapper
public interface Demo03CourseNormalMapper extends BaseMapperX<Demo03CourseDO> {
default List<Demo03CourseDO> selectListByStudentId(Long studentId) {
return selectList(Demo03CourseDO::getStudentId, studentId);
}
default int deleteByStudentId(Long studentId) {
return delete(Demo03CourseDO::getStudentId, studentId);
}
default int deleteByStudentIds(List<Long> studentIds) {
return delete(Demo03CourseDO::getStudentId, studentIds);
}
}

View File

@ -0,0 +1,29 @@
package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.normal;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 学生班级 Mapper
*
* @author 芋道源码
*/
@Mapper
public interface Demo03GradeNormalMapper extends BaseMapperX<Demo03GradeDO> {
default Demo03GradeDO selectByStudentId(Long studentId) {
return selectOne(Demo03GradeDO::getStudentId, studentId);
}
default int deleteByStudentId(Long studentId) {
return delete(Demo03GradeDO::getStudentId, studentId);
}
default int deleteByStudentIds(List<Long> studentIds) {
return delete(Demo03GradeDO::getStudentId, studentIds);
}
}

View File

@ -0,0 +1,27 @@
package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.normal;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalPageReqVO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
import org.apache.ibatis.annotations.Mapper;
/**
* 学生 Mapper
*
* @author 芋道源码
*/
@Mapper
public interface Demo03StudentNormalMapper extends BaseMapperX<Demo03StudentDO> {
default PageResult<Demo03StudentDO> selectPage(Demo03StudentNormalPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<Demo03StudentDO>()
.likeIfPresent(Demo03StudentDO::getName, reqVO.getName())
.eqIfPresent(Demo03StudentDO::getSex, reqVO.getSex())
.eqIfPresent(Demo03StudentDO::getDescription, reqVO.getDescription())
.betweenIfPresent(Demo03StudentDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(Demo03StudentDO::getId));
}
}

View File

@ -65,7 +65,8 @@ public interface ErrorCodeConstants {
ErrorCode DEMO02_CATEGORY_NAME_DUPLICATE = new ErrorCode(1_001_201_005, "已经存在该名字的示例分类");
ErrorCode DEMO02_CATEGORY_PARENT_IS_CHILD = new ErrorCode(1_001_201_006, "不能设置自己的子示例分类为父示例分类");
ErrorCode DEMO03_STUDENT_NOT_EXISTS = new ErrorCode(1_001_201_007, "学生不存在");
ErrorCode DEMO03_GRADE_NOT_EXISTS = new ErrorCode(1_001_201_008, "学生班级不存在");
ErrorCode DEMO03_GRADE_EXISTS = new ErrorCode(1_001_201_009, "学生班级已存在");
ErrorCode DEMO03_COURSE_NOT_EXISTS = new ErrorCode(1_001_201_008, "学生课程不存在");
ErrorCode DEMO03_GRADE_NOT_EXISTS = new ErrorCode(1_001_201_009, "学生班级不存在");
ErrorCode DEMO03_GRADE_EXISTS = new ErrorCode(1_001_201_010, "学生班级已存在");
}

View File

@ -49,4 +49,10 @@ public class CodegenProperties {
@NotNull(message = "是否生成单元测试不能为空")
private Boolean unitTestEnable;
/**
* 是否生成批量删除接口
*/
@NotNull(message = "是否生成批量删除接口不能为空")
private Boolean deleteBatchEnable;
}

View File

@ -236,6 +236,7 @@ public class CodegenEngine {
+ '.' + "framework"); // 用于后续获取测试类的 package 地址
globalBindingMap.put("jakartaPackage", jakartaEnable ? "jakarta" : "javax");
globalBindingMap.put("voType", codegenProperties.getVoType());
globalBindingMap.put("deleteBatchEnable", codegenProperties.getDeleteBatchEnable());
// 全局 Java Bean
globalBindingMap.put("CommonResultClassName", CommonResult.class.getName());
globalBindingMap.put("PageResultClassName", PageResult.class.getName());
@ -257,6 +258,7 @@ public class CodegenEngine {
globalBindingMap.put("ApiAccessLogClassName", ApiAccessLog.class.getName());
globalBindingMap.put("OperateTypeEnumClassName", OperateTypeEnum.class.getName());
globalBindingMap.put("BeanUtils", BeanUtils.class.getName());
globalBindingMap.put("CollectionUtilsClassName", CollectionUtils.class.getName());
}
/**
@ -382,7 +384,6 @@ public class CodegenEngine {
bindingMap.put("columns", columns);
bindingMap.put("primaryColumn", CollectionUtils.findFirst(columns, CodegenColumnDO::getPrimaryKey)); // 主键字段
bindingMap.put("sceneEnum", CodegenSceneEnum.valueOf(table.getScene()));
// className 相关
// 去掉指定前缀 TestDictType 转换成 DictType. 因为在 create 等方法后不需要带上 Test 前缀
String className = table.getClassName();

View File

@ -1,11 +1,12 @@
package cn.iocoder.yudao.module.infra.service.demo.demo01;
import jakarta.validation.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.Demo01ContactPageReqVO;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.Demo01ContactSaveReqVO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo01.Demo01ContactDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import jakarta.validation.Valid;
import java.util.List;
/**
* 示例联系人 Service 接口
@ -36,6 +37,13 @@ public interface Demo01ContactService {
*/
void deleteDemo01Contact(Long id);
/**
* 批量删除示例联系人
*
* @param ids 编号
*/
void deleteDemo01ContactByIds(List<Long> ids);
/**
* 获得示例联系人
*

View File

@ -1,19 +1,20 @@
package cn.iocoder.yudao.module.infra.service.demo.demo01;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.Demo01ContactPageReqVO;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.Demo01ContactSaveReqVO;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo01.Demo01ContactDO;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.Demo01ContactPageReqVO;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.Demo01ContactSaveReqVO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo01.Demo01ContactDO;
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo01.Demo01ContactMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.DEMO01_CONTACT_NOT_EXISTS;
/**
* 示例联系人 Service 实现类
@ -53,6 +54,21 @@ public class Demo01ContactServiceImpl implements Demo01ContactService {
demo01ContactMapper.deleteById(id);
}
@Override
public void deleteDemo01ContactByIds(List<Long> ids) {
// 校验存在
validateDemo01ContactExists(ids);
// 删除
demo01ContactMapper.deleteByIds(ids);
}
private void validateDemo01ContactExists(List<Long> ids) {
List<Demo01ContactDO> list = demo01ContactMapper.selectByIds(ids);
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
throw exception(DEMO01_CONTACT_NOT_EXISTS);
}
}
private void validateDemo01ContactExists(Long id) {
if (demo01ContactMapper.selectById(id) == null) {
throw exception(DEMO01_CONTACT_NOT_EXISTS);

View File

@ -1,11 +1,11 @@
package cn.iocoder.yudao.module.infra.service.demo.demo02;
import java.util.*;
import jakarta.validation.*;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo02.vo.Demo02CategoryListReqVO;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo02.vo.Demo02CategorySaveReqVO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo02.Demo02CategoryDO;
import jakarta.validation.Valid;
import java.util.List;
/**
* 示例分类 Service 接口

View File

@ -5,10 +5,10 @@ import cn.iocoder.yudao.module.infra.controller.admin.demo.demo02.vo.Demo02Categ
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo02.vo.Demo02CategorySaveReqVO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo02.Demo02CategoryDO;
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo02.Demo02CategoryMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import jakarta.annotation.Resource;
import java.util.List;
import java.util.Objects;

View File

@ -1,217 +0,0 @@
package cn.iocoder.yudao.module.infra.service.demo.demo03;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentPageReqVO;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentSaveReqVO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.Demo03CourseMapper;
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.Demo03GradeMapper;
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.Demo03StudentMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import jakarta.annotation.Resource;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*;
/**
* 学生 Service 实现类
*
* @author 芋道源码
*/
@Service
@Validated
public class Demo03StudentServiceImpl implements Demo03StudentService {
@Resource
private Demo03StudentMapper demo03StudentMapper;
@Resource
private Demo03CourseMapper demo03CourseMapper;
@Resource
private Demo03GradeMapper demo03GradeMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public Long createDemo03Student(Demo03StudentSaveReqVO createReqVO) {
// 插入
Demo03StudentDO demo03Student = BeanUtils.toBean(createReqVO, Demo03StudentDO.class);
demo03StudentMapper.insert(demo03Student);
// 插入子表
createDemo03CourseList(demo03Student.getId(), createReqVO.getDemo03Courses());
createDemo03Grade(demo03Student.getId(), createReqVO.getDemo03Grade());
// 返回
return demo03Student.getId();
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateDemo03Student(Demo03StudentSaveReqVO updateReqVO) {
// 校验存在
validateDemo03StudentExists(updateReqVO.getId());
// 更新
Demo03StudentDO updateObj = BeanUtils.toBean(updateReqVO, Demo03StudentDO.class);
demo03StudentMapper.updateById(updateObj);
// 更新子表
updateDemo03CourseList(updateReqVO.getId(), updateReqVO.getDemo03Courses());
updateDemo03Grade(updateReqVO.getId(), updateReqVO.getDemo03Grade());
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteDemo03Student(Long id) {
// 校验存在
validateDemo03StudentExists(id);
// 删除
demo03StudentMapper.deleteById(id);
// 删除子表
deleteDemo03CourseByStudentId(id);
deleteDemo03GradeByStudentId(id);
}
private void validateDemo03StudentExists(Long id) {
if (demo03StudentMapper.selectById(id) == null) {
throw exception(DEMO03_STUDENT_NOT_EXISTS);
}
}
@Override
public Demo03StudentDO getDemo03Student(Long id) {
return demo03StudentMapper.selectById(id);
}
@Override
public PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentPageReqVO pageReqVO) {
return demo03StudentMapper.selectPage(pageReqVO);
}
// ==================== 子表学生课程 ====================
@Override
public List<Demo03CourseDO> getDemo03CourseListByStudentId(Long studentId) {
return demo03CourseMapper.selectListByStudentId(studentId);
}
private void createDemo03CourseList(Long studentId, List<Demo03CourseDO> list) {
if (list != null) {
list.forEach(o -> o.setStudentId(studentId));
}
demo03CourseMapper.insertBatch(list);
}
private void updateDemo03CourseList(Long studentId, List<Demo03CourseDO> list) {
deleteDemo03CourseByStudentId(studentId);
list.forEach(o -> o.setId(null).setUpdater(null).setUpdateTime(null)); // 解决更新情况下1id 冲突2updateTime 不更新
createDemo03CourseList(studentId, list);
}
private void deleteDemo03CourseByStudentId(Long studentId) {
demo03CourseMapper.deleteByStudentId(studentId);
}
@Override
public PageResult<Demo03CourseDO> getDemo03CoursePage(PageParam pageReqVO, Long studentId) {
return demo03CourseMapper.selectPage(pageReqVO, studentId);
}
@Override
public Long createDemo03Course(Demo03CourseDO demo03Course) {
demo03CourseMapper.insert(demo03Course);
return demo03Course.getId();
}
@Override
public void updateDemo03Course(Demo03CourseDO demo03Course) {
demo03CourseMapper.updateById(demo03Course);
}
@Override
public void deleteDemo03Course(Long id) {
demo03CourseMapper.deleteById(id);
}
@Override
public Demo03CourseDO getDemo03Course(Long id) {
return demo03CourseMapper.selectById(id);
}
// ==================== 子表学生班级 ====================
@Override
public Demo03GradeDO getDemo03GradeByStudentId(Long studentId) {
return demo03GradeMapper.selectByStudentId(studentId);
}
private void createDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) {
if (demo03Grade == null) {
return;
}
demo03Grade.setStudentId(studentId);
demo03GradeMapper.insert(demo03Grade);
}
private void updateDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) {
if (demo03Grade == null) {
return;
}
demo03Grade.setStudentId(studentId);
demo03Grade.setUpdater(null).setUpdateTime(null); // 解决更新情况下updateTime 不更新
demo03GradeMapper.insertOrUpdate(demo03Grade);
}
private void deleteDemo03GradeByStudentId(Long studentId) {
demo03GradeMapper.deleteByStudentId(studentId);
}
@Override
public PageResult<Demo03GradeDO> getDemo03GradePage(PageParam pageReqVO, Long studentId) {
return demo03GradeMapper.selectPage(pageReqVO, studentId);
}
@Override
public Long createDemo03Grade(Demo03GradeDO demo03Grade) {
// 校验是否已经存在
if (demo03GradeMapper.selectByStudentId(demo03Grade.getStudentId()) != null) {
throw exception(DEMO03_GRADE_EXISTS);
}
demo03GradeMapper.insert(demo03Grade);
return demo03Grade.getId();
}
@Override
public void updateDemo03Grade(Demo03GradeDO demo03Grade) {
// 校验存在
validateDemo03GradeExists(demo03Grade.getId());
// 更新
demo03GradeMapper.updateById(demo03Grade);
}
@Override
public void deleteDemo03Grade(Long id) {
// 校验存在
validateDemo03GradeExists(id);
// 删除
demo03GradeMapper.deleteById(id);
}
@Override
public Demo03GradeDO getDemo03Grade(Long id) {
return demo03GradeMapper.selectById(id);
}
private void validateDemo03GradeExists(Long id) {
if (demo03GradeMapper.selectById(id) == null) {
throw exception(DEMO03_GRADE_NOT_EXISTS);
}
}
}

View File

@ -1,14 +1,14 @@
package cn.iocoder.yudao.module.infra.service.demo.demo03;
package cn.iocoder.yudao.module.infra.service.demo.demo03.erp;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentPageReqVO;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentSaveReqVO;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpPageReqVO;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpSaveReqVO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
import jakarta.validation.Valid;
import java.util.List;
/**
@ -16,7 +16,7 @@ import java.util.List;
*
* @author 芋道源码
*/
public interface Demo03StudentService {
public interface Demo03StudentErpService {
/**
* 创建学生
@ -24,14 +24,14 @@ public interface Demo03StudentService {
* @param createReqVO 创建信息
* @return 编号
*/
Long createDemo03Student(@Valid Demo03StudentSaveReqVO createReqVO);
Long createDemo03Student(@Valid Demo03StudentErpSaveReqVO createReqVO);
/**
* 更新学生
*
* @param updateReqVO 更新信息
*/
void updateDemo03Student(@Valid Demo03StudentSaveReqVO updateReqVO);
void updateDemo03Student(@Valid Demo03StudentErpSaveReqVO updateReqVO);
/**
* 删除学生
@ -40,6 +40,13 @@ public interface Demo03StudentService {
*/
void deleteDemo03Student(Long id);
/**
* 批量删除学生
*
* @param ids 编号
*/
void deleteDemo03StudentByIds(List<Long> ids);
/**
* 获得学生
*
@ -54,19 +61,10 @@ public interface Demo03StudentService {
* @param pageReqVO 分页查询
* @return 学生分页
*/
PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentPageReqVO pageReqVO);
PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentErpPageReqVO pageReqVO);
// ==================== 子表学生课程 ====================
/**
* 获得学生课程列表
*
* @param studentId 学生编号
* @return 学生课程列表
*/
List<Demo03CourseDO> getDemo03CourseListByStudentId(Long studentId);
/**
* 获得学生课程分页
*
@ -98,6 +96,13 @@ public interface Demo03StudentService {
*/
void deleteDemo03Course(Long id);
/**
* 批量删除学生课程
*
* @param ids 编号
*/
void deleteDemo03CourseByIds(List<Long> ids);
/**
* 获得学生课程
*
@ -108,14 +113,6 @@ public interface Demo03StudentService {
// ==================== 子表学生班级 ====================
/**
* 获得学生班级
*
* @param studentId 学生编号
* @return 学生班级
*/
Demo03GradeDO getDemo03GradeByStudentId(Long studentId);
/**
* 获得学生班级分页
*
@ -147,6 +144,13 @@ public interface Demo03StudentService {
*/
void deleteDemo03Grade(Long id);
/**
* 批量删除学生班级
*
* @param ids 编号
*/
void deleteDemo03GradeByIds(List<Long> ids);
/**
* 获得学生班级
*

View File

@ -0,0 +1,241 @@
package cn.iocoder.yudao.module.infra.service.demo.demo03.erp;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpPageReqVO;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpSaveReqVO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp.Demo03CourseErpMapper;
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp.Demo03GradeErpMapper;
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp.Demo03StudentErpMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*;
/**
* 学生 Service 实现类
*
* @author 芋道源码
*/
@Service
@Validated
public class Demo03StudentErpServiceImpl implements Demo03StudentErpService {
@Resource
private Demo03StudentErpMapper demo03StudentErpMapper;
@Resource
private Demo03CourseErpMapper demo03CourseErpMapper;
@Resource
private Demo03GradeErpMapper demo03GradeErpMapper;
@Override
public Long createDemo03Student(Demo03StudentErpSaveReqVO createReqVO) {
// 插入
Demo03StudentDO demo03Student = BeanUtils.toBean(createReqVO, Demo03StudentDO.class);
demo03StudentErpMapper.insert(demo03Student);
// 返回
return demo03Student.getId();
}
@Override
public void updateDemo03Student(Demo03StudentErpSaveReqVO updateReqVO) {
// 校验存在
validateDemo03StudentExists(updateReqVO.getId());
// 更新
Demo03StudentDO updateObj = BeanUtils.toBean(updateReqVO, Demo03StudentDO.class);
demo03StudentErpMapper.updateById(updateObj);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteDemo03Student(Long id) {
// 校验存在
validateDemo03StudentExists(id);
// 删除
demo03StudentErpMapper.deleteById(id);
// 删除子表
deleteDemo03CourseByStudentId(id);
deleteDemo03GradeByStudentId(id);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteDemo03StudentByIds(List<Long> ids) {
// 校验存在
validateDemo03StudentExists(ids);
// 删除
demo03StudentErpMapper.deleteByIds(ids);
// 删除子表
deleteDemo03CourseByStudentIds(ids);
deleteDemo03GradeByStudentIds(ids);
}
private void validateDemo03StudentExists(List<Long> ids) {
List<Demo03StudentDO> list = demo03StudentErpMapper.selectByIds(ids);
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
throw exception(DEMO03_STUDENT_NOT_EXISTS);
}
}
private void validateDemo03StudentExists(Long id) {
if (demo03StudentErpMapper.selectById(id) == null) {
throw exception(DEMO03_STUDENT_NOT_EXISTS);
}
}
@Override
public Demo03StudentDO getDemo03Student(Long id) {
return demo03StudentErpMapper.selectById(id);
}
@Override
public PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentErpPageReqVO pageReqVO) {
return demo03StudentErpMapper.selectPage(pageReqVO);
}
// ==================== 子表学生课程 ====================
@Override
public PageResult<Demo03CourseDO> getDemo03CoursePage(PageParam pageReqVO, Long studentId) {
return demo03CourseErpMapper.selectPage(pageReqVO, studentId);
}
@Override
public Long createDemo03Course(Demo03CourseDO demo03Course) {
demo03CourseErpMapper.insert(demo03Course);
return demo03Course.getId();
}
@Override
public void updateDemo03Course(Demo03CourseDO demo03Course) {
// 校验存在
validateDemo03CourseExists(demo03Course.getId());
// 更新
demo03Course.setUpdater(null).setUpdateTime(null); // 解决更新情况下updateTime 不更新
demo03CourseErpMapper.updateById(demo03Course);
}
@Override
public void deleteDemo03Course(Long id) {
// 校验存在
validateDemo03CourseExists(id);
// 删除
demo03CourseErpMapper.deleteById(id);
}
@Override
public void deleteDemo03CourseByIds(List<Long> ids) {
// 校验存在
validateDemo03CourseExists(ids);
// 删除
demo03CourseErpMapper.deleteByIds(ids);
}
@Override
public Demo03CourseDO getDemo03Course(Long id) {
return demo03CourseErpMapper.selectById(id);
}
private void validateDemo03CourseExists(Long id) {
if (demo03CourseErpMapper.selectById(id) == null) {
throw exception(DEMO03_COURSE_NOT_EXISTS);
}
}
private void validateDemo03CourseExists(List<Long> ids) {
List<Demo03CourseDO> list = demo03CourseErpMapper.selectByIds(ids);
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
throw exception(DEMO03_COURSE_NOT_EXISTS);
}
}
private void deleteDemo03CourseByStudentId(Long studentId) {
demo03CourseErpMapper.deleteByStudentId(studentId);
}
private void deleteDemo03CourseByStudentIds(List<Long> studentIds) {
demo03CourseErpMapper.deleteByStudentIds(studentIds);
}
// ==================== 子表学生班级 ====================
@Override
public PageResult<Demo03GradeDO> getDemo03GradePage(PageParam pageReqVO, Long studentId) {
return demo03GradeErpMapper.selectPage(pageReqVO, studentId);
}
@Override
public Long createDemo03Grade(Demo03GradeDO demo03Grade) {
// 校验是否已经存在
if (demo03GradeErpMapper.selectByStudentId(demo03Grade.getStudentId()) != null) {
throw exception(DEMO03_GRADE_EXISTS);
}
// 插入
demo03GradeErpMapper.insert(demo03Grade);
return demo03Grade.getId();
}
@Override
public void updateDemo03Grade(Demo03GradeDO demo03Grade) {
// 校验存在
validateDemo03GradeExists(demo03Grade.getId());
// 更新
demo03Grade.setUpdater(null).setUpdateTime(null); // 解决更新情况下updateTime 不更新
demo03GradeErpMapper.updateById(demo03Grade);
}
@Override
public void deleteDemo03Grade(Long id) {
// 校验存在
validateDemo03GradeExists(id);
// 删除
demo03GradeErpMapper.deleteById(id);
}
@Override
public void deleteDemo03GradeByIds(List<Long> ids) {
// 校验存在
validateDemo03GradeExists(ids);
// 删除
demo03GradeErpMapper.deleteByIds(ids);
}
@Override
public Demo03GradeDO getDemo03Grade(Long id) {
return demo03GradeErpMapper.selectById(id);
}
private void validateDemo03GradeExists(Long id) {
if (demo03GradeErpMapper.selectById(id) == null) {
throw exception(DEMO03_GRADE_NOT_EXISTS);
}
}
private void validateDemo03GradeExists(List<Long> ids) {
List<Demo03GradeDO> list = demo03GradeErpMapper.selectByIds(ids);
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
throw exception(DEMO03_GRADE_NOT_EXISTS);
}
}
private void deleteDemo03GradeByStudentId(Long studentId) {
demo03GradeErpMapper.deleteByStudentId(studentId);
}
private void deleteDemo03GradeByStudentIds(List<Long> studentIds) {
demo03GradeErpMapper.deleteByStudentIds(studentIds);
}
}

View File

@ -0,0 +1,85 @@
package cn.iocoder.yudao.module.infra.service.demo.demo03.inner;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerPageReqVO;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerSaveReqVO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
import jakarta.validation.Valid;
import java.util.List;
/**
* 学生 Service 接口
*
* @author 芋道源码
*/
public interface Demo03StudentInnerService {
/**
* 创建学生
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createDemo03Student(@Valid Demo03StudentInnerSaveReqVO createReqVO);
/**
* 更新学生
*
* @param updateReqVO 更新信息
*/
void updateDemo03Student(@Valid Demo03StudentInnerSaveReqVO updateReqVO);
/**
* 删除学生
*
* @param id 编号
*/
void deleteDemo03Student(Long id);
/**
* 批量删除学生
*
* @param ids 编号
*/
void deleteDemo03StudentByIds(List<Long> ids);
/**
* 获得学生
*
* @param id 编号
* @return 学生
*/
Demo03StudentDO getDemo03Student(Long id);
/**
* 获得学生分页
*
* @param pageReqVO 分页查询
* @return 学生分页
*/
PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentInnerPageReqVO pageReqVO);
// ==================== 子表学生课程 ====================
/**
* 获得学生课程列表
*
* @param studentId 学生编号
* @return 学生课程列表
*/
List<Demo03CourseDO> getDemo03CourseListByStudentId(Long studentId);
// ==================== 子表学生班级 ====================
/**
* 获得学生班级
*
* @param studentId 学生编号
* @return 学生班级
*/
Demo03GradeDO getDemo03GradeByStudentId(Long studentId);
}

View File

@ -0,0 +1,195 @@
package cn.iocoder.yudao.module.infra.service.demo.demo03.inner;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerPageReqVO;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerSaveReqVO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.inner.Demo03CourseInnerMapper;
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.inner.Demo03GradeInnerMapper;
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.inner.Demo03StudentInnerMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.DEMO03_STUDENT_NOT_EXISTS;
/**
* 学生 Service 实现类
*
* @author 芋道源码
*/
@Service
@Validated
public class Demo03StudentInnerServiceImpl implements Demo03StudentInnerService {
@Resource
private Demo03StudentInnerMapper demo03StudentInnerMapper;
@Resource
private Demo03CourseInnerMapper demo03CourseInnerMapper;
@Resource
private Demo03GradeInnerMapper demo03GradeInnerMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public Long createDemo03Student(Demo03StudentInnerSaveReqVO createReqVO) {
// 插入
Demo03StudentDO demo03Student = BeanUtils.toBean(createReqVO, Demo03StudentDO.class);
demo03StudentInnerMapper.insert(demo03Student);
// 插入子表
createDemo03CourseList(demo03Student.getId(), createReqVO.getDemo03Courses());
createDemo03Grade(demo03Student.getId(), createReqVO.getDemo03Grade());
// 返回
return demo03Student.getId();
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateDemo03Student(Demo03StudentInnerSaveReqVO updateReqVO) {
// 校验存在
validateDemo03StudentExists(updateReqVO.getId());
// 更新
Demo03StudentDO updateObj = BeanUtils.toBean(updateReqVO, Demo03StudentDO.class);
demo03StudentInnerMapper.updateById(updateObj);
// 更新子表
updateDemo03CourseList(updateReqVO.getId(), updateReqVO.getDemo03Courses());
updateDemo03Grade(updateReqVO.getId(), updateReqVO.getDemo03Grade());
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteDemo03Student(Long id) {
// 校验存在
validateDemo03StudentExists(id);
// 删除
demo03StudentInnerMapper.deleteById(id);
// 删除子表
deleteDemo03CourseByStudentId(id);
deleteDemo03GradeByStudentId(id);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteDemo03StudentByIds(List<Long> ids) {
// 校验存在
validateDemo03StudentExists(ids);
// 删除
demo03StudentInnerMapper.deleteByIds(ids);
// 删除子表
deleteDemo03CourseByStudentIds(ids);
deleteDemo03GradeByStudentIds(ids);
}
private void validateDemo03StudentExists(List<Long> ids) {
List<Demo03StudentDO> list = demo03StudentInnerMapper.selectByIds(ids);
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
throw exception(DEMO03_STUDENT_NOT_EXISTS);
}
}
private void validateDemo03StudentExists(Long id) {
if (demo03StudentInnerMapper.selectById(id) == null) {
throw exception(DEMO03_STUDENT_NOT_EXISTS);
}
}
@Override
public Demo03StudentDO getDemo03Student(Long id) {
return demo03StudentInnerMapper.selectById(id);
}
@Override
public PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentInnerPageReqVO pageReqVO) {
return demo03StudentInnerMapper.selectPage(pageReqVO);
}
// ==================== 子表学生课程 ====================
@Override
public List<Demo03CourseDO> getDemo03CourseListByStudentId(Long studentId) {
return demo03CourseInnerMapper.selectListByStudentId(studentId);
}
private void createDemo03CourseList(Long studentId, List<Demo03CourseDO> list) {
list.forEach(o -> o.setStudentId(studentId));
demo03CourseInnerMapper.insertBatch(list);
}
private void updateDemo03CourseList(Long studentId, List<Demo03CourseDO> list) {
list.forEach(o -> o.setStudentId(studentId));
List<Demo03CourseDO> oldList = demo03CourseInnerMapper.selectListByStudentId(studentId);
List<List<Demo03CourseDO>> diffList = diffList(oldList, list, (oldVal, newVal) -> {
boolean same = ObjectUtil.equal(oldVal.getId(), newVal.getId());
if (same) {
newVal.setId(oldVal.getId()).setUpdater(null).setUpdateTime(null); // 解决更新情况下updateTime 不更新
}
return same;
});
// 第二步批量添加修改删除
if (CollUtil.isNotEmpty(diffList.get(0))) {
demo03CourseInnerMapper.insertBatch(diffList.get(0));
}
if (CollUtil.isNotEmpty(diffList.get(1))) {
demo03CourseInnerMapper.updateBatch(diffList.get(1));
}
if (CollUtil.isNotEmpty(diffList.get(2))) {
demo03CourseInnerMapper.deleteByIds(convertList(diffList.get(2), Demo03CourseDO::getId));
}
}
private void deleteDemo03CourseByStudentId(Long studentId) {
demo03CourseInnerMapper.deleteByStudentId(studentId);
}
private void deleteDemo03CourseByStudentIds(List<Long> studentIds) {
demo03CourseInnerMapper.deleteByStudentIds(studentIds);
}
// ==================== 子表学生班级 ====================
@Override
public Demo03GradeDO getDemo03GradeByStudentId(Long studentId) {
return demo03GradeInnerMapper.selectByStudentId(studentId);
}
private void createDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) {
if (demo03Grade == null) {
return;
}
demo03Grade.setStudentId(studentId);
demo03GradeInnerMapper.insert(demo03Grade);
}
private void updateDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) {
if (demo03Grade == null) {
return;
}
demo03Grade.setStudentId(studentId);
demo03Grade.setUpdater(null).setUpdateTime(null); // 解决更新情况下updateTime 不更新
demo03GradeInnerMapper.insertOrUpdate(demo03Grade);
}
private void deleteDemo03GradeByStudentId(Long studentId) {
demo03GradeInnerMapper.deleteByStudentId(studentId);
}
private void deleteDemo03GradeByStudentIds(List<Long> studentIds) {
demo03GradeInnerMapper.deleteByStudentIds(studentIds);
}
}

View File

@ -0,0 +1,85 @@
package cn.iocoder.yudao.module.infra.service.demo.demo03.normal;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalPageReqVO;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalSaveReqVO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
import jakarta.validation.Valid;
import java.util.List;
/**
* 学生 Service 接口
*
* @author 芋道源码
*/
public interface Demo03StudentNormalService {
/**
* 创建学生
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createDemo03Student(@Valid Demo03StudentNormalSaveReqVO createReqVO);
/**
* 更新学生
*
* @param updateReqVO 更新信息
*/
void updateDemo03Student(@Valid Demo03StudentNormalSaveReqVO updateReqVO);
/**
* 删除学生
*
* @param id 编号
*/
void deleteDemo03Student(Long id);
/**
* 批量删除学生
*
* @param ids 编号
*/
void deleteDemo03StudentByIds(List<Long> ids);
/**
* 获得学生
*
* @param id 编号
* @return 学生
*/
Demo03StudentDO getDemo03Student(Long id);
/**
* 获得学生分页
*
* @param pageReqVO 分页查询
* @return 学生分页
*/
PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentNormalPageReqVO pageReqVO);
// ==================== 子表学生课程 ====================
/**
* 获得学生课程列表
*
* @param studentId 学生编号
* @return 学生课程列表
*/
List<Demo03CourseDO> getDemo03CourseListByStudentId(Long studentId);
// ==================== 子表学生班级 ====================
/**
* 获得学生班级
*
* @param studentId 学生编号
* @return 学生班级
*/
Demo03GradeDO getDemo03GradeByStudentId(Long studentId);
}

View File

@ -0,0 +1,195 @@
package cn.iocoder.yudao.module.infra.service.demo.demo03.normal;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalPageReqVO;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalSaveReqVO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.normal.Demo03CourseNormalMapper;
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.normal.Demo03GradeNormalMapper;
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.normal.Demo03StudentNormalMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.DEMO03_STUDENT_NOT_EXISTS;
/**
* 学生 Service 实现类
*
* @author 芋道源码
*/
@Service
@Validated
public class Demo03StudentNormalServiceImpl implements Demo03StudentNormalService {
@Resource
private Demo03StudentNormalMapper demo03StudentNormalMapper;
@Resource
private Demo03CourseNormalMapper demo03CourseNormalMapper;
@Resource
private Demo03GradeNormalMapper demo03GradeNormalMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public Long createDemo03Student(Demo03StudentNormalSaveReqVO createReqVO) {
// 插入
Demo03StudentDO demo03Student = BeanUtils.toBean(createReqVO, Demo03StudentDO.class);
demo03StudentNormalMapper.insert(demo03Student);
// 插入子表
createDemo03CourseList(demo03Student.getId(), createReqVO.getDemo03Courses());
createDemo03Grade(demo03Student.getId(), createReqVO.getDemo03Grade());
// 返回
return demo03Student.getId();
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateDemo03Student(Demo03StudentNormalSaveReqVO updateReqVO) {
// 校验存在
validateDemo03StudentExists(updateReqVO.getId());
// 更新
Demo03StudentDO updateObj = BeanUtils.toBean(updateReqVO, Demo03StudentDO.class);
demo03StudentNormalMapper.updateById(updateObj);
// 更新子表
updateDemo03CourseList(updateReqVO.getId(), updateReqVO.getDemo03Courses());
updateDemo03Grade(updateReqVO.getId(), updateReqVO.getDemo03Grade());
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteDemo03Student(Long id) {
// 校验存在
validateDemo03StudentExists(id);
// 删除
demo03StudentNormalMapper.deleteById(id);
// 删除子表
deleteDemo03CourseByStudentId(id);
deleteDemo03GradeByStudentId(id);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteDemo03StudentByIds(List<Long> ids) {
// 校验存在
validateDemo03StudentExists(ids);
// 删除
demo03StudentNormalMapper.deleteByIds(ids);
// 删除子表
deleteDemo03CourseByStudentIds(ids);
deleteDemo03GradeByStudentIds(ids);
}
private void validateDemo03StudentExists(List<Long> ids) {
List<Demo03StudentDO> list = demo03StudentNormalMapper.selectByIds(ids);
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
throw exception(DEMO03_STUDENT_NOT_EXISTS);
}
}
private void validateDemo03StudentExists(Long id) {
if (demo03StudentNormalMapper.selectById(id) == null) {
throw exception(DEMO03_STUDENT_NOT_EXISTS);
}
}
@Override
public Demo03StudentDO getDemo03Student(Long id) {
return demo03StudentNormalMapper.selectById(id);
}
@Override
public PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentNormalPageReqVO pageReqVO) {
return demo03StudentNormalMapper.selectPage(pageReqVO);
}
// ==================== 子表学生课程 ====================
@Override
public List<Demo03CourseDO> getDemo03CourseListByStudentId(Long studentId) {
return demo03CourseNormalMapper.selectListByStudentId(studentId);
}
private void createDemo03CourseList(Long studentId, List<Demo03CourseDO> list) {
list.forEach(o -> o.setStudentId(studentId));
demo03CourseNormalMapper.insertBatch(list);
}
private void updateDemo03CourseList(Long studentId, List<Demo03CourseDO> list) {
list.forEach(o -> o.setStudentId(studentId));
List<Demo03CourseDO> oldList = demo03CourseNormalMapper.selectListByStudentId(studentId);
List<List<Demo03CourseDO>> diffList = diffList(oldList, list, (oldVal, newVal) -> {
boolean same = ObjectUtil.equal(oldVal.getId(), newVal.getId());
if (same) {
newVal.setId(oldVal.getId()).setUpdater(null).setUpdateTime(null); // 解决更新情况下updateTime 不更新
}
return same;
});
// 第二步批量添加修改删除
if (CollUtil.isNotEmpty(diffList.get(0))) {
demo03CourseNormalMapper.insertBatch(diffList.get(0));
}
if (CollUtil.isNotEmpty(diffList.get(1))) {
demo03CourseNormalMapper.updateBatch(diffList.get(1));
}
if (CollUtil.isNotEmpty(diffList.get(2))) {
demo03CourseNormalMapper.deleteByIds(convertList(diffList.get(2), Demo03CourseDO::getId));
}
}
private void deleteDemo03CourseByStudentId(Long studentId) {
demo03CourseNormalMapper.deleteByStudentId(studentId);
}
private void deleteDemo03CourseByStudentIds(List<Long> studentIds) {
demo03CourseNormalMapper.deleteByStudentIds(studentIds);
}
// ==================== 子表学生班级 ====================
@Override
public Demo03GradeDO getDemo03GradeByStudentId(Long studentId) {
return demo03GradeNormalMapper.selectByStudentId(studentId);
}
private void createDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) {
if (demo03Grade == null) {
return;
}
demo03Grade.setStudentId(studentId);
demo03GradeNormalMapper.insert(demo03Grade);
}
private void updateDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) {
if (demo03Grade == null) {
return;
}
demo03Grade.setStudentId(studentId);
demo03Grade.setUpdater(null).setUpdateTime(null); // 解决更新情况下updateTime 不更新
demo03GradeNormalMapper.insertOrUpdate(demo03Grade);
}
private void deleteDemo03GradeByStudentId(Long studentId) {
demo03GradeNormalMapper.deleteByStudentId(studentId);
}
private void deleteDemo03GradeByStudentIds(List<Long> studentIds) {
demo03GradeNormalMapper.deleteByStudentIds(studentIds);
}
}

View File

@ -0,0 +1 @@
package cn.iocoder.yudao.module.infra.service.demo.demo03;

View File

@ -74,6 +74,19 @@ public class ${sceneEnum.prefixClass}${table.className}Controller {
return success(true);
}
#if ( $table.templateType != 2 && $deleteBatchEnable)
@DeleteMapping("/delete-batch")
@Parameter(name = "ids", description = "编号", required = true)
@Operation(summary = "批量删除${table.classComment}")
#if ($sceneEnum.scene == 1)
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')")
#end
public CommonResult<Boolean> delete${simpleClassName}(@RequestParam("ids") List<${primaryColumn.javaType}> ids) {
${classNameVar}Service.delete${simpleClassName}ByIds(ids);
return success(true);
}
#end
@GetMapping("/get")
@Operation(summary = "获得${table.classComment}")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@ -230,6 +243,19 @@ public class ${sceneEnum.prefixClass}${table.className}Controller {
return success(true);
}
#if ($deleteBatchEnable)
@DeleteMapping("/${subSimpleClassName_strikeCase}/delete-batch")
@Parameter(name = "ids", description = "编号", required = true)
@Operation(summary = "批量删除${subTable.classComment}")
#if ($sceneEnum.scene == 1)
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')")
#end
public CommonResult<Boolean> delete${subSimpleClassName}(@RequestParam("ids") List<${subPrimaryColumn.javaType}> ids) {
${classNameVar}Service.delete${subSimpleClassName}ByIds(ids);
return success(true);
}
#end
@GetMapping("/${subSimpleClassName_strikeCase}/get")
@Operation(summary = "获得${subTable.classComment}")
@Parameter(name = "id", description = "编号", required = true)

View File

@ -78,4 +78,19 @@ public class ${table.className}DO extends BaseDO {
#end
#end
## 特殊:主子表专属逻辑(非 ERP 模式)
#if ( $voType == 20 && $subTables && $subTables.size() > 0 && $table.templateType != 11 )
#foreach ($subTable in $subTables)
#set ($index = $foreach.count - 1)
#if ( $subTable.subJoinMany)
@Schema(description = "${subTable.classComment}列表")
private List<${subTable.className}DO> ${subClassNameVars.get($index)}s;
#else
@Schema(description = "${subTable.classComment}")
private ${subTable.className}DO ${subClassNameVars.get($index)};
#end
#end
#end
}

View File

@ -54,4 +54,10 @@ public interface ${subTable.className}Mapper extends BaseMapperX<${subTable.clas
return delete(${subTable.className}DO::get${SubJoinColumnName}, ${subJoinColumn.javaField});
}
#if ( $table.templateType != 2 && $deleteBatchEnable)
default int deleteBy${SubJoinColumnName}s(List<${subJoinColumn.javaType}> ${subJoinColumn.javaField}s) {
return delete(${subTable.className}DO::get${SubJoinColumnName}, ${subJoinColumn.javaField}s);
}
#end
}

View File

@ -40,6 +40,15 @@ public interface ${table.className}Service {
*/
void delete${simpleClassName}(${primaryColumn.javaType} id);
#if ( $table.templateType != 2 && $deleteBatchEnable)
/**
* 批量删除${table.classComment}
*
* @param ids 编号
*/
void delete${simpleClassName}ByIds(List<${primaryColumn.javaType}> ids);
#end
/**
* 获得${table.classComment}
*
@ -134,6 +143,15 @@ public interface ${table.className}Service {
*/
void delete${subSimpleClassName}(${subPrimaryColumn.javaType} id);
#if ($deleteBatchEnable)
/**
* 批量删除${subTable.classComment}
*
* @param ids 编号
*/
void delete${subSimpleClassName}ByIds(List<${subPrimaryColumn.javaType}> ids);
#end
/**
* 获得${subTable.classComment}
*

View File

@ -1,5 +1,6 @@
package ${basePackage}.module.${table.moduleName}.service.${table.businessName};
import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import ${jakartaPackage}.annotation.Resource;
import org.springframework.validation.annotation.Validated;
@ -24,6 +25,8 @@ import ${basePackage}.module.${subTable.moduleName}.dal.mysql.${subTable.busines
#end
import static ${ServiceExceptionUtilClassName}.exception;
import static ${CollectionUtilsClassName}.convertList;
import static ${CollectionUtilsClassName}.diffList;
import static ${basePackage}.module.${table.moduleName}.enums.ErrorCodeConstants.*;
/**
@ -55,9 +58,9 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
#set ($TreeParentJavaField = $treeParentColumn.javaField.substring(0,1).toUpperCase() + ${treeParentColumn.javaField.substring(1)})##首字母大写
#set ($TreeNameJavaField = $treeNameColumn.javaField.substring(0,1).toUpperCase() + ${treeNameColumn.javaField.substring(1)})##首字母大写
// 校验${treeParentColumn.columnComment}的有效性
validateParent${simpleClassName}(null, ${createReqVOVar}.get${TreeParentJavaField}());
validateParent${simpleClassName}(null, ${saveReqVOVar}.get${TreeParentJavaField}());
// 校验${treeNameColumn.columnComment}的唯一性
validate${simpleClassName}${TreeNameJavaField}Unique(null, ${createReqVOVar}.get${TreeParentJavaField}(), ${createReqVOVar}.get${TreeNameJavaField}());
validate${simpleClassName}${TreeNameJavaField}Unique(null, ${saveReqVOVar}.get${TreeParentJavaField}(), ${saveReqVOVar}.get${TreeNameJavaField}());
#end
// 插入
@ -75,9 +78,9 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
#set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
#if ( $subTable.subJoinMany)
create${subSimpleClassName}List(${classNameVar}.getId(), ${createReqVOVar}.get${subSimpleClassNames.get($index)}s());
create${subSimpleClassName}List(${classNameVar}.getId(), ${saveReqVOVar}.get${subSimpleClassNames.get($index)}s());
#else
create${subSimpleClassName}(${classNameVar}.getId(), ${createReqVOVar}.get${subSimpleClassNames.get($index)}());
create${subSimpleClassName}(${classNameVar}.getId(), ${saveReqVOVar}.get${subSimpleClassNames.get($index)}());
#end
#end
#end
@ -160,6 +163,39 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
#end
}
#if ( $table.templateType != 2 && $deleteBatchEnable)
@Override
## 特殊:主子表专属逻辑
#if ( $subTables && $subTables.size() > 0)
@Transactional(rollbackFor = Exception.class)
#end
public void delete${simpleClassName}ByIds(List<${primaryColumn.javaType}> ids) {
// 校验存在
validate${simpleClassName}Exists(ids);
// 删除
${classNameVar}Mapper.deleteByIds(ids);
## 特殊:主子表专属逻辑
#if ( $subTables && $subTables.size() > 0)
// 删除子表
#foreach ($subTable in $subTables)
#set ($index = $foreach.count - 1)
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
#set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
delete${subSimpleClassName}By${SubJoinColumnName}s(ids);
#end
#end
}
private void validate${simpleClassName}Exists(List<${primaryColumn.javaType}> ids) {
List<${table.className}DO> list = ${classNameVar}Mapper.selectByIds(ids);
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
throw exception(${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS);
}
}
#end
private void validate${simpleClassName}Exists(${primaryColumn.javaType} id) {
if (${classNameVar}Mapper.selectById(id) == null) {
throw exception(${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS);
@ -304,6 +340,16 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
${subClassNameVars.get($index)}Mapper.deleteById(id);
}
#if ($deleteBatchEnable)
@Override
public void delete${subSimpleClassName}ByIds(List<${subPrimaryColumn.javaType}> ids) {
// 校验存在
validate${subSimpleClassName}Exists(ids);
// 删除
${subClassNameVars.get($index)}Mapper.deleteByIds(ids);
}
#end
@Override
public ${subTable.className}DO get${subSimpleClassName}(${subPrimaryColumn.javaType} id) {
return ${subClassNameVars.get($index)}Mapper.selectById(id);
@ -315,18 +361,44 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
}
}
#if ($deleteBatchEnable)
private void validate${subSimpleClassName}Exists(List<${subPrimaryColumn.javaType}> ids) {
List<${subTable.className}DO> list = ${subClassNameVar}Mapper.selectByIds(ids);
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
throw exception(${simpleClassNameUnderlineCase.toUpperCase()}_NOT_EXISTS);
}
}
#end
## 情况二:非 MASTER_ERP 时,支持批量的新增、修改操作
#else
#if ( $subTable.subJoinMany)
private void create${subSimpleClassName}List(${primaryColumn.javaType} ${subJoinColumn.javaField}, List<${subTable.className}DO> list) {
list.forEach(o -> o.set$SubJoinColumnName(${subJoinColumn.javaField}));
list.forEach(o -> o.set${SubJoinColumnName}(${subJoinColumn.javaField}));
${subClassNameVars.get($index)}Mapper.insertBatch(list);
}
private void update${subSimpleClassName}List(${primaryColumn.javaType} ${subJoinColumn.javaField}, List<${subTable.className}DO> list) {
delete${subSimpleClassName}By${SubJoinColumnName}(${subJoinColumn.javaField});
list.forEach(o -> o.setId(null).setUpdater(null).setUpdateTime(null)); // 解决更新情况下1id 冲突2updateTime 不更新
create${subSimpleClassName}List(${subJoinColumn.javaField}, list);
list.forEach(o -> o.set${SubJoinColumnName}(${subJoinColumn.javaField}));
List<${subTable.className}DO> oldList = ${subClassNameVar}Mapper.selectListBy${SubJoinColumnName}(${subJoinColumn.javaField});
List<List<${subTable.className}DO>> diffList = diffList(oldList, list, (oldVal, newVal) -> {
boolean same = ObjectUtil.equal(oldVal.getId(), newVal.getId());
if (same) {
newVal.setId(oldVal.getId()).setUpdater(null).setUpdateTime(null); // 解决更新情况下updateTime 不更新
}
return same;
});
// 第二步,批量添加、修改、删除
if (CollUtil.isNotEmpty(diffList.get(0))) {
${subClassNameVar}Mapper.insertBatch(diffList.get(0));
}
if (CollUtil.isNotEmpty(diffList.get(1))) {
${subClassNameVar}Mapper.updateBatch(diffList.get(1));
}
if (CollUtil.isNotEmpty(diffList.get(2))) {
${subClassNameVar}Mapper.deleteByIds(convertList(diffList.get(2), ${subTable.className}DO::getId));
}
}
#else
@ -353,5 +425,11 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
${subClassNameVars.get($index)}Mapper.deleteBy${SubJoinColumnName}(${subJoinColumn.javaField});
}
#if ( $table.templateType != 2 && $deleteBatchEnable)
private void delete${subSimpleClassName}By${SubJoinColumnName}s(List<${primaryColumn.javaType}> ${subJoinColumn.javaField}s) {
${subClassNameVars.get($index)}Mapper.deleteBy${SubJoinColumnName}s(${subJoinColumn.javaField}s);
}
#end
#end
}

View File

@ -89,6 +89,13 @@ export function delete${simpleClassName}(id: number) {
return requestClient.delete(`${baseURL}/delete?id=${id}`);
}
#if ( $table.templateType != 2 && $deleteBatchEnable)
// 批量删除${table.classComment}
export function delete${simpleClassName}ByIds(ids: number[]) {
return requestClient.delete(`${baseURL}/delete-batch?ids=${ids.join(',')}`)
}
#end
/** 导出${table.classComment} */
export function export${simpleClassName}(params: any) {
return requestClient.download('${baseURL}/export-excel', params);
@ -144,6 +151,13 @@ export function delete${subSimpleClassName}(id: number) {
return requestClient.delete(`${baseURL}/${subSimpleClassName_strikeCase}/delete?id=${id}`);
}
#if ($deleteBatchEnable)
// 批量删除${subTable.classComment}
export function delete${subSimpleClassName}ByIds(ids: number[]) {
return requestClient.delete(`${baseURL}/${subSimpleClassName_strikeCase}/delete-batch?ids=${ids.join(',')}`)
}
#end
/** 获得${subTable.classComment} */
export function get${subSimpleClassName}(id: number) {
return requestClient.get<${simpleClassName}Api.${subSimpleClassName}>(`${baseURL}/${subSimpleClassName_strikeCase}/get?id=${id}`);

View File

@ -3,9 +3,11 @@ import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
import type { ${simpleClassName}Api } from '#/api/${table.moduleName}/${table.businessName}';
import { z } from '#/adapter/form';
import { getRangePickerDefaultProps } from '#/utils/date';
import { DICT_TYPE, getDictOptions } from '#/utils/dict';
import {
DICT_TYPE,
getDictOptions,
getRangePickerDefaultProps,
} from '#/utils';
#if(${table.templateType} == 2)## 树表需要导入这些
import { get${simpleClassName}List } from '#/api/${table.moduleName}/${table.businessName}';
import { handleTree } from '@vben/utils';
@ -191,6 +193,9 @@ export function useGridColumns(
onActionClick?: OnActionClickFn<${simpleClassName}Api.${simpleClassName}>,
): VxeTableGridOptions<${simpleClassName}Api.${simpleClassName}>['columns'] {
return [
#if ($table.templateType != 2 && $deleteBatchEnable)
{ type: 'checkbox', width: 40 },
#end
#if ($table.templateType == 12) ## 内嵌情况
{ type: 'expand', width: 80, slots: { content: 'expand_content' } },
#end
@ -426,6 +431,9 @@ export function use${subSimpleClassName}GridColumns(
onActionClick?: OnActionClickFn<${simpleClassName}Api.${subSimpleClassName}>,
): VxeTableGridOptions<${simpleClassName}Api.${subSimpleClassName}>['columns'] {
return [
#if ($table.templateType != 2 && $deleteBatchEnable)
{ type: 'checkbox', width: 40 },
#end
#foreach($column in $subColumns)
#if ($column.listOperationResult)
#set ($dictType = $column.dictType)

View File

@ -4,7 +4,7 @@ import type { ${simpleClassName}Api } from '#/api/${table.moduleName}/${table.bu
import { Page, useVbenModal } from '@vben/common-ui';
import { Button, message,Tabs } from 'ant-design-vue';
import { Download, Plus } from '@vben/icons';
import { Download, Plus, Trash2 } from '@vben/icons';
import Form from './modules/form.vue';
## 特殊:主子表专属逻辑
@ -16,15 +16,15 @@ import Form from './modules/form.vue';
#end
#end
import { ref, h } from 'vue';
import { ref, h, computed } from 'vue';
import { $t } from '#/locales';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
#if (${table.templateType} == 2)## 树表接口
import { get${simpleClassName}List, delete${simpleClassName}, export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}';
#else## 标准表接口
import { get${simpleClassName}Page, delete${simpleClassName}, export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}';
import { get${simpleClassName}Page, delete${simpleClassName},#if ($deleteBatchEnable) delete${simpleClassName}ByIds,#end export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}';
#end
import { downloadFileFromBlobPart } from '@vben/utils';
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
import { useGridColumns, useGridFormSchema } from './data';
@ -87,11 +87,38 @@ async function onDelete(row: ${simpleClassName}Api.${simpleClassName}) {
await delete${simpleClassName}(row.id as number);
message.success( $t('ui.actionMessage.deleteSuccess', [row.id]) );
onRefresh();
} catch {
} finally {
hideLoading();
}
}
#if ($table.templateType != 2 && $deleteBatchEnable)
const deleteIds = ref<number[]>([]) // 待删除${table.classComment} ID
const showDeleteBatchBtn = computed(() => isEmpty(deleteIds.value));
function setDeleteIds({
records,
}: {
records: ${simpleClassName}Api.${simpleClassName}[];
}) {
deleteIds.value = records.map((item) => item.id);
}
/** 批量删除${table.classComment} */
async function onDeleteBatch() {
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting'),
duration: 0,
key: 'action_process_msg',
});
try {
await delete${simpleClassName}ByIds(deleteIds.value);
message.success( $t('ui.actionMessage.deleteSuccess') );
onRefresh();
} finally {
hideLoading();
}
}
#end
/** 导出表格 */
async function onExport() {
const data = await export${simpleClassName}(await gridApi.formApi.getValues());
@ -177,11 +204,17 @@ const [Grid, gridApi] = useVbenVxeGrid({
search: true,
},
} as VxeTableGridOptions<${simpleClassName}Api.${simpleClassName}>,
#if (${table.templateType} == 11)
#if (${table.templateType} == 11 || $deleteBatchEnable)
gridEvents:{
#if(${table.templateType} == 11)
cellClick: ({ row }: { row: ${simpleClassName}Api.${simpleClassName}}) => {
select${simpleClassName}.value = row;
},
#end
#if($deleteBatchEnable)
checkboxAll: setDeleteIds,
checkboxChange: setDeleteIds,
#end
}
#end
});
@ -229,6 +262,19 @@ const [Grid, gridApi] = useVbenVxeGrid({
>
{{ $t('ui.actionTitle.export') }}
</Button>
#if ($table.templateType != 2 && $deleteBatchEnable)
<Button
:icon="h(Trash2)"
type="primary"
danger
class="ml-2"
:disabled="showDeleteBatchBtn"
@click="onDeleteBatch"
v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:delete']"
>
批量删除
</Button>
#end
</template>
</Grid>

View File

@ -14,15 +14,16 @@
#end
import { useVbenModal } from '@vben/common-ui';
import { Button, message } from 'ant-design-vue';
import { Plus } from '@vben/icons';
import { #if($table.templateType != 11)ref,#end h, nextTick,watch } from 'vue';
import { Plus, Trash2 } from '@vben/icons';
import { ref, computed, h, nextTick,watch } from 'vue';
import { $t } from '#/locales';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
#if ($table.templateType == 11) ## erp
import { delete${subSimpleClassName}, get${subSimpleClassName}Page } from '#/api/${table.moduleName}/${table.businessName}';
import { delete${subSimpleClassName},#if ($deleteBatchEnable) delete${subSimpleClassName}ByIds,#end get${subSimpleClassName}Page } from '#/api/${table.moduleName}/${table.businessName}';
import { use${subSimpleClassName}GridFormSchema, use${subSimpleClassName}GridColumns } from '../data';
import { isEmpty } from '@vben/utils';
#else
#if ($subTable.subJoinMany) ## 一对多
import { get${subSimpleClassName}ListBy${SubJoinColumnName} } from '#/api/${table.moduleName}/${table.businessName}';
@ -67,11 +68,38 @@ async function onDelete(row: ${simpleClassName}Api.${subSimpleClassName}) {
await delete${subSimpleClassName}(row.id as number);
message.success( $t('ui.actionMessage.deleteSuccess', [row.id]) );
onRefresh();
} catch {
} finally {
hideLoading();
}
}
#if ($deleteBatchEnable)
const deleteIds = ref<number[]>([]) // 待删除${subTable.classComment} ID
const showDeleteBatchBtn = computed(() => isEmpty(deleteIds.value));
function setDeleteIds({
records,
}: {
records: ${simpleClassName}Api.${subSimpleClassName}[];
}) {
deleteIds.value = records.map((item) => item.id);
}
/** 批量删除${subTable.classComment} */
async function onDeleteBatch() {
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting'),
duration: 0,
key: 'action_process_msg',
});
try {
await delete${subSimpleClassName}ByIds(deleteIds.value);
message.success( $t('ui.actionMessage.deleteSuccess') );
onRefresh();
} finally {
hideLoading();
}
}
#end
/** 表格操作按钮的回调函数 */
function onActionClick({
code,
@ -136,6 +164,12 @@ function onActionClick({
isHover: true,
},
} as VxeTableGridOptions<${simpleClassName}Api.${subSimpleClassName}>,
#if (${table.templateType} == 11 && $deleteBatchEnable)
gridEvents:{
checkboxAll: setDeleteIds,
checkboxChange: setDeleteIds,
}
#end
});
/** 刷新表格 */
@ -173,6 +207,19 @@ const onRefresh = async ()=> {
<Button :icon="h(Plus)" type="primary" @click="onCreate" v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:create']">
{{ $t('ui.actionTitle.create', ['${subTable.classComment}']) }}
</Button>
#if ($table.templateType == 11 && $deleteBatchEnable)
<Button
:icon="h(Trash2)"
type="primary"
danger
class="ml-2"
:disabled="showDeleteBatchBtn"
@click="onDeleteBatch"
v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:delete']"
>
批量删除
</Button>
#end
</template>
</Grid>
#else

View File

@ -271,6 +271,7 @@ yudao:
front-type: 20 # 前端模版的类型,参见 CodegenFrontTypeEnum 枚举类
vo-type: 10 # VO 的类型,参见 CodegenVOTypeEnum 枚举类
unit-test-enable: false # 是否生成单元测试
delete-batch-enable: false # 是否生成批量删除接口
tenant: # 多租户相关配置项
enable: true
ignore-urls: