perf:【INFRA 基础设施】vben5-antd-schema 主主子表erp代码生成时,可生成批量删除

This commit is contained in:
puhui999
2025-05-19 16:52:52 +08:00
parent 6dee926253
commit ef1e7b312b
19 changed files with 292 additions and 161 deletions

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.Demo03StudentPageReqVO;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentRespVO;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentSaveReqVO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
import cn.iocoder.yudao.module.infra.service.demo.demo03.Demo03StudentService;
import cn.iocoder.yudao.module.infra.service.demo.demo03.erp.Demo03StudentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -31,7 +31,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 学生")
@RestController
@RequestMapping("/infra/demo03-student")
@RequestMapping("/infra/demo03-student-erp")
@Validated
public class Demo03StudentController {
@@ -62,6 +62,15 @@ public class Demo03StudentController {
return success(true);
}
@DeleteMapping("/delete-batch")
@Parameter(name = "ids", description = "编号", required = true)
@Operation(summary = "批量删除学生")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')")
public CommonResult<Boolean> deleteDemo03Student(@RequestParam("ids") List<Long> ids) {
demo03StudentService.deleteDemo03StudentByIds(ids);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得学生")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@@ -84,12 +93,12 @@ public class Demo03StudentController {
@PreAuthorize("@ss.hasPermission('infra:demo03-student:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportDemo03StudentExcel(@Valid Demo03StudentPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<Demo03StudentDO> list = demo03StudentService.getDemo03StudentPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "学生.xls", "数据", Demo03StudentRespVO.class,
BeanUtils.toBean(list, Demo03StudentRespVO.class));
BeanUtils.toBean(list, Demo03StudentRespVO.class));
}
// ==================== 子表学生课程 ====================
@@ -127,6 +136,15 @@ public class Demo03StudentController {
return success(true);
}
@DeleteMapping("/demo03-course/delete-batch")
@Parameter(name = "ids", description = "编号", required = true)
@Operation(summary = "批量删除学生课程")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')")
public CommonResult<Boolean> deleteDemo03Course(@RequestParam("ids") List<Long> ids) {
demo03StudentService.deleteDemo03CourseByIds(ids);
return success(true);
}
@GetMapping("/demo03-course/get")
@Operation(summary = "获得学生课程")
@Parameter(name = "id", description = "编号", required = true)
@@ -135,14 +153,6 @@ public class Demo03StudentController {
return success(demo03StudentService.getDemo03Course(id));
}
@GetMapping("/demo03-course/list-by-student-id")
@Operation(summary = "获得学生课程列表")
@Parameter(name = "studentId", description = "学生编号")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
public CommonResult<List<Demo03CourseDO>> getDemo03CourseListByStudentId(@RequestParam("studentId") Long studentId) {
return success(demo03StudentService.getDemo03CourseListByStudentId(studentId));
}
// ==================== 子表学生班级 ====================
@GetMapping("/demo03-grade/page")
@@ -178,6 +188,15 @@ public class Demo03StudentController {
return success(true);
}
@DeleteMapping("/demo03-grade/delete-batch")
@Parameter(name = "ids", description = "编号", required = true)
@Operation(summary = "批量删除学生班级")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')")
public CommonResult<Boolean> deleteDemo03Grade(@RequestParam("ids") List<Long> ids) {
demo03StudentService.deleteDemo03GradeByIds(ids);
return success(true);
}
@GetMapping("/demo03-grade/get")
@Operation(summary = "获得学生班级")
@Parameter(name = "id", description = "编号", required = true)
@@ -186,12 +205,4 @@ public class Demo03StudentController {
return success(demo03StudentService.getDemo03Grade(id));
}
@GetMapping("/demo03-grade/get-by-student-id")
@Operation(summary = "获得学生班级")
@Parameter(name = "studentId", description = "学生编号")
@PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
public CommonResult<Demo03GradeDO> getDemo03GradeByStudentId(@RequestParam("studentId") Long studentId) {
return success(demo03StudentService.getDemo03GradeByStudentId(studentId));
}
}

View File

@@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo;
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo;
import lombok.*;
import io.swagger.v3.oas.annotations.media.Schema;

View File

@@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo;
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;

View File

@@ -1,12 +1,10 @@
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo;
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import jakarta.validation.constraints.*;
import java.time.LocalDateTime;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
@Schema(description = "管理后台 - 学生新增/修改 Request VO")
@Data
@@ -31,9 +29,4 @@ public class Demo03StudentSaveReqVO {
@NotEmpty(message = "简介不能为空")
private String description;
private List<Demo03CourseDO> demo03Courses;
private Demo03GradeDO demo03Grade;
}

View File

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

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;
@@ -19,16 +19,16 @@ public interface Demo03CourseMapper extends BaseMapperX<Demo03CourseDO> {
default PageResult<Demo03CourseDO> selectPage(PageParam reqVO, Long studentId) {
return selectPage(reqVO, new LambdaQueryWrapperX<Demo03CourseDO>()
.eq(Demo03CourseDO::getStudentId, studentId)
.orderByDesc(Demo03CourseDO::getId));
}
default List<Demo03CourseDO> selectListByStudentId(Long studentId) {
return selectList(Demo03CourseDO::getStudentId, studentId);
.eq(Demo03CourseDO::getStudentId, studentId)
.orderByDesc(Demo03CourseDO::getId));
}
default int deleteByStudentId(Long studentId) {
return delete(Demo03CourseDO::getStudentId, studentId);
}
}
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,6 +7,8 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 学生班级 Mapper
*
@@ -17,16 +19,19 @@ public interface Demo03GradeMapper extends BaseMapperX<Demo03GradeDO> {
default PageResult<Demo03GradeDO> selectPage(PageParam reqVO, Long studentId) {
return selectPage(reqVO, new LambdaQueryWrapperX<Demo03GradeDO>()
.eq(Demo03GradeDO::getStudentId, studentId)
.orderByDesc(Demo03GradeDO::getId));
.eq(Demo03GradeDO::getStudentId, studentId)
.orderByDesc(Demo03GradeDO::getId));
}
default Demo03GradeDO selectByStudentId(Long studentId) {
default Demo03GradeDO selectByStudentId(Long studentId) {
return selectOne(Demo03GradeDO::getStudentId, studentId);
}
}
default int deleteByStudentId(Long studentId) {
return delete(Demo03GradeDO::getStudentId, studentId);
}
}
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.*;
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

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

@@ -1,15 +1,13 @@
package cn.iocoder.yudao.module.infra.service.demo.demo03;
package cn.iocoder.yudao.module.infra.service.demo.demo03.erp;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentPageReqVO;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentSaveReqVO;
import java.util.*;
import jakarta.validation.*;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.*;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
import jakarta.validation.Valid;
import java.util.List;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
/**
* 学生 Service 接口
@@ -40,6 +38,13 @@ public interface Demo03StudentService {
*/
void deleteDemo03Student(Long id);
/**
* 批量删除学生
*
* @param ids 编号
*/
void deleteDemo03StudentByIds(List<Long> ids);
/**
* 获得学生
*
@@ -56,17 +61,8 @@ public interface Demo03StudentService {
*/
PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentPageReqVO pageReqVO);
// ==================== 子表学生课程 ====================
/**
* 获得学生课程列表
*
* @param studentId 学生编号
* @return 学生课程列表
*/
List<Demo03CourseDO> getDemo03CourseListByStudentId(Long studentId);
/**
* 获得学生课程分页
*
@@ -99,23 +95,22 @@ public interface Demo03StudentService {
void deleteDemo03Course(Long id);
/**
* 获得学生课程
*
* @param id 编号
* 批量删除学生课程
*
* @param ids 编号
*/
void deleteDemo03CourseByIds(List<Long> ids);
/**
* 获得学生课程
*
* @param id 编号
* @return 学生课程
*/
*/
Demo03CourseDO getDemo03Course(Long id);
// ==================== 子表学生班级 ====================
/**
* 获得学生班级
*
* @param studentId 学生编号
* @return 学生班级
*/
Demo03GradeDO getDemo03GradeByStudentId(Long studentId);
/**
* 获得学生班级分页
*
@@ -148,11 +143,18 @@ public interface Demo03StudentService {
void deleteDemo03Grade(Long id);
/**
* 获得学生班级
*
* @param id 编号
* 批量删除学生班级
*
* @param ids 编号
*/
void deleteDemo03GradeByIds(List<Long> ids);
/**
* 获得学生班级
*
* @param id 编号
* @return 学生班级
*/
*/
Demo03GradeDO getDemo03Grade(Long id);
}

View File

@@ -1,21 +1,22 @@
package cn.iocoder.yudao.module.infra.service.demo.demo03;
package cn.iocoder.yudao.module.infra.service.demo.demo03.erp;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentPageReqVO;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentSaveReqVO;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentPageReqVO;
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentSaveReqVO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.Demo03CourseMapper;
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.Demo03GradeMapper;
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.Demo03StudentMapper;
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp.Demo03CourseMapper;
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp.Demo03GradeMapper;
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.erp.Demo03StudentMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import jakarta.annotation.Resource;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@@ -38,31 +39,21 @@ public class Demo03StudentServiceImpl implements Demo03StudentService {
private Demo03GradeMapper demo03GradeMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public Long createDemo03Student(Demo03StudentSaveReqVO createReqVO) {
// 插入
Demo03StudentDO demo03Student = BeanUtils.toBean(createReqVO, Demo03StudentDO.class);
demo03StudentMapper.insert(demo03Student);
// 插入子表
createDemo03CourseList(demo03Student.getId(), createReqVO.getDemo03Courses());
createDemo03Grade(demo03Student.getId(), createReqVO.getDemo03Grade());
// 返回
return demo03Student.getId();
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateDemo03Student(Demo03StudentSaveReqVO updateReqVO) {
// 校验存在
validateDemo03StudentExists(updateReqVO.getId());
// 更新
Demo03StudentDO updateObj = BeanUtils.toBean(updateReqVO, Demo03StudentDO.class);
demo03StudentMapper.updateById(updateObj);
// 更新子表
updateDemo03CourseList(updateReqVO.getId(), updateReqVO.getDemo03Courses());
updateDemo03Grade(updateReqVO.getId(), updateReqVO.getDemo03Grade());
}
@Override
@@ -78,6 +69,26 @@ public class Demo03StudentServiceImpl implements Demo03StudentService {
deleteDemo03GradeByStudentId(id);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteDemo03StudentByIds(List<Long> ids) {
// 校验存在
validateDemo03StudentExists(ids);
// 删除
demo03StudentMapper.deleteByIds(ids);
// 删除子表
deleteDemo03CourseByStudentIds(ids);
deleteDemo03GradeByStudentIds(ids);
}
private void validateDemo03StudentExists(List<Long> ids) {
List<Demo03StudentDO> list = demo03StudentMapper.selectByIds(ids);
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
throw exception(DEMO03_STUDENT_NOT_EXISTS);
}
}
private void validateDemo03StudentExists(Long id) {
if (demo03StudentMapper.selectById(id) == null) {
throw exception(DEMO03_STUDENT_NOT_EXISTS);
@@ -96,28 +107,6 @@ public class Demo03StudentServiceImpl implements Demo03StudentService {
// ==================== 子表学生课程 ====================
@Override
public List<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);
@@ -131,47 +120,57 @@ public class Demo03StudentServiceImpl implements Demo03StudentService {
@Override
public void updateDemo03Course(Demo03CourseDO demo03Course) {
// 校验存在
validateDemo03CourseExists(demo03Course.getId());
// 更新
demo03Course.setUpdater(null).setUpdateTime(null); // 解决更新情况下updateTime 不更新
demo03CourseMapper.updateById(demo03Course);
}
@Override
public void deleteDemo03Course(Long id) {
// 校验存在
validateDemo03CourseExists(id);
// 删除
demo03CourseMapper.deleteById(id);
}
@Override
public void deleteDemo03CourseByIds(List<Long> ids) {
// 校验存在
validateDemo03CourseExists(ids);
// 删除
demo03CourseMapper.deleteByIds(ids);
}
@Override
public Demo03CourseDO getDemo03Course(Long id) {
return demo03CourseMapper.selectById(id);
}
private void validateDemo03CourseExists(Long id) {
if (demo03CourseMapper.selectById(id) == null) {
throw exception(DEMO03_COURSE_NOT_EXISTS);
}
}
private void validateDemo03CourseExists(List<Long> ids) {
List<Demo03CourseDO> list = demo03CourseMapper.selectByIds(ids);
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
throw exception(DEMO03_COURSE_NOT_EXISTS);
}
}
private void deleteDemo03CourseByStudentId(Long studentId) {
demo03CourseMapper.deleteByStudentId(studentId);
}
private void deleteDemo03CourseByStudentIds(List<Long> studentIds) {
demo03CourseMapper.deleteByStudentIds(studentIds);
}
// ==================== 子表学生班级 ====================
@Override
public Demo03GradeDO getDemo03GradeByStudentId(Long studentId) {
return demo03GradeMapper.selectByStudentId(studentId);
}
private void createDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) {
if (demo03Grade == null) {
return;
}
demo03Grade.setStudentId(studentId);
demo03GradeMapper.insert(demo03Grade);
}
private void updateDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) {
if (demo03Grade == null) {
return;
}
demo03Grade.setStudentId(studentId);
demo03Grade.setUpdater(null).setUpdateTime(null); // 解决更新情况下updateTime 不更新
demo03GradeMapper.insertOrUpdate(demo03Grade);
}
private void deleteDemo03GradeByStudentId(Long studentId) {
demo03GradeMapper.deleteByStudentId(studentId);
}
@Override
public PageResult<Demo03GradeDO> getDemo03GradePage(PageParam pageReqVO, Long studentId) {
return demo03GradeMapper.selectPage(pageReqVO, studentId);
@@ -183,6 +182,7 @@ public class Demo03StudentServiceImpl implements Demo03StudentService {
if (demo03GradeMapper.selectByStudentId(demo03Grade.getStudentId()) != null) {
throw exception(DEMO03_GRADE_EXISTS);
}
// 插入
demo03GradeMapper.insert(demo03Grade);
return demo03Grade.getId();
}
@@ -192,6 +192,7 @@ public class Demo03StudentServiceImpl implements Demo03StudentService {
// 校验存在
validateDemo03GradeExists(demo03Grade.getId());
// 更新
demo03Grade.setUpdater(null).setUpdateTime(null); // 解决更新情况下updateTime 不更新
demo03GradeMapper.updateById(demo03Grade);
}
@@ -203,6 +204,14 @@ public class Demo03StudentServiceImpl implements Demo03StudentService {
demo03GradeMapper.deleteById(id);
}
@Override
public void deleteDemo03GradeByIds(List<Long> ids) {
// 校验存在
validateDemo03GradeExists(ids);
// 删除
demo03GradeMapper.deleteByIds(ids);
}
@Override
public Demo03GradeDO getDemo03Grade(Long id) {
return demo03GradeMapper.selectById(id);
@@ -214,4 +223,19 @@ public class Demo03StudentServiceImpl implements Demo03StudentService {
}
}
private void validateDemo03GradeExists(List<Long> ids) {
List<Demo03GradeDO> list = demo03GradeMapper.selectByIds(ids);
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
throw exception(DEMO03_GRADE_NOT_EXISTS);
}
}
private void deleteDemo03GradeByStudentId(Long studentId) {
demo03GradeMapper.deleteByStudentId(studentId);
}
private void deleteDemo03GradeByStudentIds(List<Long> studentIds) {
demo03GradeMapper.deleteByStudentIds(studentIds);
}
}

View File

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