InfraStudentServiceImpl 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package com.jt.cloud.module.infra.service.demo;
  2. import org.springframework.stereotype.Service;
  3. import javax.annotation.Resource;
  4. import org.springframework.validation.annotation.Validated;
  5. import org.springframework.transaction.annotation.Transactional;
  6. import java.util.*;
  7. import com.jt.cloud.module.infra.controller.admin.demo.vo.*;
  8. import com.jt.cloud.module.infra.dal.dataobject.demo.InfraStudentDO;
  9. import com.jt.cloud.framework.common.pojo.PageResult;
  10. import com.jt.cloud.framework.common.pojo.PageParam;
  11. import com.jt.cloud.framework.common.util.object.BeanUtils;
  12. import com.jt.cloud.module.infra.dal.mysql.demo.InfraStudentMapper;
  13. import static com.jt.cloud.framework.common.exception.util.ServiceExceptionUtil.exception;
  14. import static com.jt.cloud.module.infra.enums.ErrorCodeConstants.*;
  15. /**
  16. * 学生 Service 实现类
  17. *
  18. * @author jt
  19. */
  20. @Service
  21. @Validated
  22. public class InfraStudentServiceImpl implements InfraStudentService {
  23. @Resource
  24. private InfraStudentMapper studentMapper;
  25. @Override
  26. public Long createStudent(InfraStudentSaveReqVO createReqVO) {
  27. // 插入
  28. InfraStudentDO student = BeanUtils.toBean(createReqVO, InfraStudentDO.class);
  29. studentMapper.insert(student);
  30. // 返回
  31. return student.getId();
  32. }
  33. @Override
  34. public void updateStudent(InfraStudentSaveReqVO updateReqVO) {
  35. // 校验存在
  36. validateStudentExists(updateReqVO.getId());
  37. // 更新
  38. InfraStudentDO updateObj = BeanUtils.toBean(updateReqVO, InfraStudentDO.class);
  39. studentMapper.updateById(updateObj);
  40. }
  41. @Override
  42. public void deleteStudent(Long id) {
  43. // 校验存在
  44. validateStudentExists(id);
  45. // 删除
  46. studentMapper.deleteById(id);
  47. }
  48. private void validateStudentExists(Long id) {
  49. if (studentMapper.selectById(id) == null) {
  50. throw exception(STUDENT_NOT_EXISTS);
  51. }
  52. }
  53. @Override
  54. public InfraStudentDO getStudent(Long id) {
  55. return studentMapper.selectById(id);
  56. }
  57. @Override
  58. public PageResult<InfraStudentDO> getStudentPage(InfraStudentPageReqVO pageReqVO) {
  59. return studentMapper.selectPage(pageReqVO);
  60. }
  61. }