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