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