package com.smart.reader.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.github.pagehelper.PageHelper; import com.smart.reader.common.Page; import com.smart.reader.dao.StudentInfoMapper; import com.smart.reader.exception.CustomException; import com.smart.reader.model.bo.StudentInfoAddBo; import com.smart.reader.model.bo.StudentInfoUpdateBo; import com.smart.reader.model.po.StudentInfo; import com.smart.reader.model.vo.StudentInfoVo; import com.smart.reader.service.StudentInfoService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; @Service public class StudentInfoServiceImpl extends ServiceImpl implements StudentInfoService { @Override public Page queryInfo(int pageNum, int pageSize) throws CustomException { try { PageHelper.startPage(pageNum, pageSize); List tableInfoVos = this.baseMapper.queryInfo(); return new Page<>(pageNum, pageSize, tableInfoVos); } catch (Exception e) { throw new CustomException("学生信息查询失败"); } } @Override @Transactional(rollbackFor = Exception.class) public Boolean add(StudentInfoAddBo studentInfo) throws CustomException { StudentInfo info = BeanUtil.copyProperties(studentInfo, StudentInfo.class); boolean save = this.save(info); if (!save) { throw new CustomException("学生数据添加失败"); } return Boolean.TRUE; } @Override @Transactional(rollbackFor = Exception.class) public Boolean delete(Long id) throws CustomException { boolean remove = this.removeById(id); if (!remove) { throw new CustomException("学生数据删除失败"); } return Boolean.TRUE; } @Override @Transactional(rollbackFor = Exception.class) public Boolean edit(StudentInfoUpdateBo studentInfo) throws CustomException { StudentInfo info = this.getById(studentInfo.getId()); if (ObjectUtil.isEmpty(info)) { throw new CustomException("学生数据不存在"); } BeanUtil.copyProperties(studentInfo, info); boolean update = this.updateById(info); if (!update) { throw new CustomException("学生数据修改失败"); } return Boolean.TRUE; } @Override public StudentInfoVo detail(Long id) throws CustomException { StudentInfoVo vo = this.baseMapper.detail(id); if (ObjectUtil.isEmpty(vo)) { throw new CustomException("学生详情获取失败"); } return vo; } @Override @Transactional(rollbackFor = Exception.class) public Boolean batchDelete(List ids) throws CustomException { boolean result = this.removeByIds(ids); if (!result) { throw new CustomException("学生批量删除失败"); } return Boolean.TRUE; } }