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