StudentInfoServiceImpl.java 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package com.smart.reader.service.impl;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.util.ObjectUtil;
  4. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  5. import com.github.pagehelper.PageHelper;
  6. import com.smart.reader.common.Page;
  7. import com.smart.reader.dao.StudentInfoMapper;
  8. import com.smart.reader.exception.CustomException;
  9. import com.smart.reader.model.bo.StudentInfoAddBo;
  10. import com.smart.reader.model.bo.StudentInfoUpdateBo;
  11. import com.smart.reader.model.po.StudentInfo;
  12. import com.smart.reader.model.vo.StudentInfoVo;
  13. import com.smart.reader.service.StudentInfoService;
  14. import org.springframework.stereotype.Service;
  15. import org.springframework.transaction.annotation.Transactional;
  16. import java.util.List;
  17. @Service
  18. public class StudentInfoServiceImpl extends ServiceImpl<StudentInfoMapper, StudentInfo> implements StudentInfoService {
  19. @Override
  20. public Page<StudentInfoVo> queryInfo(int pageNum, int pageSize) throws CustomException {
  21. try {
  22. PageHelper.startPage(pageNum, pageSize);
  23. List<StudentInfoVo> tableInfoVos = this.baseMapper.queryInfo();
  24. return new Page<>(pageNum, pageSize, tableInfoVos);
  25. } catch (Exception e) {
  26. throw new CustomException("学生信息查询失败");
  27. }
  28. }
  29. @Override
  30. @Transactional(rollbackFor = Exception.class)
  31. public Boolean add(StudentInfoAddBo studentInfo) throws CustomException {
  32. StudentInfo info = BeanUtil.copyProperties(studentInfo, StudentInfo.class);
  33. boolean save = this.save(info);
  34. if (!save) {
  35. throw new CustomException("学生数据添加失败");
  36. }
  37. return Boolean.TRUE;
  38. }
  39. @Override
  40. @Transactional(rollbackFor = Exception.class)
  41. public Boolean delete(Long id) throws CustomException {
  42. boolean remove = this.removeById(id);
  43. if (!remove) {
  44. throw new CustomException("学生数据删除失败");
  45. }
  46. return Boolean.TRUE;
  47. }
  48. @Override
  49. @Transactional(rollbackFor = Exception.class)
  50. public Boolean edit(StudentInfoUpdateBo studentInfo) throws CustomException {
  51. StudentInfo info = this.getById(studentInfo.getId());
  52. if (ObjectUtil.isEmpty(info)) {
  53. throw new CustomException("学生数据不存在");
  54. }
  55. BeanUtil.copyProperties(studentInfo, info);
  56. boolean update = this.updateById(info);
  57. if (!update) {
  58. throw new CustomException("学生数据修改失败");
  59. }
  60. return Boolean.TRUE;
  61. }
  62. @Override
  63. public StudentInfoVo detail(Long id) throws CustomException {
  64. StudentInfoVo vo = this.baseMapper.detail(id);
  65. if (ObjectUtil.isEmpty(vo)) {
  66. throw new CustomException("学生详情获取失败");
  67. }
  68. return vo;
  69. }
  70. @Override
  71. @Transactional(rollbackFor = Exception.class)
  72. public Boolean batchDelete(List<Long> ids) throws CustomException {
  73. boolean result = this.removeByIds(ids);
  74. if (!result) {
  75. throw new CustomException("学生批量删除失败");
  76. }
  77. return Boolean.TRUE;
  78. }
  79. }