xiaoyi
3 天以前 abf1c0a35d85d38239ff5d2ed746a4e4b797c9d1
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
75
76
77
78
79
80
81
82
83
package cn.iocoder.yudao.module.hrm.service.certificate;
 
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.hrm.controller.admin.certificate.vo.HrmCertificatePageReqVO;
import cn.iocoder.yudao.module.hrm.controller.admin.certificate.vo.HrmCertificateSaveReqVO;
import cn.iocoder.yudao.module.hrm.dal.dataobject.certificate.HrmCertificateDO;
import cn.iocoder.yudao.module.hrm.dal.mysql.certificate.HrmCertificateMapper;
import cn.iocoder.yudao.module.hrm.service.employee.HrmEmployeeService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
 
import java.util.Collection;
 
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.HRM_CERTIFICATE_NOT_EXISTS;
import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.HRM_EMPLOYEE_NOT_EXISTS;
 
/**
 * HRM 证书资质 Service 实现类
 *
 * @author xiaoyi
 */
@Service
@Validated
public class HrmCertificateServiceImpl implements HrmCertificateService {
 
    @Resource
    private HrmCertificateMapper certificateMapper;
    @Resource
    private HrmEmployeeService employeeService;
 
    @Override
    public Long createCertificate(HrmCertificateSaveReqVO createReqVO) {
        validateEmployee(createReqVO.getEmployeeId());
        HrmCertificateDO certificate = BeanUtils.toBean(createReqVO, HrmCertificateDO.class);
        certificateMapper.insert(certificate);
        return certificate.getId();
    }
 
    @Override
    public void updateCertificate(HrmCertificateSaveReqVO updateReqVO) {
        validateCertificateExists(updateReqVO.getId());
        validateEmployee(updateReqVO.getEmployeeId());
        certificateMapper.updateById(BeanUtils.toBean(updateReqVO, HrmCertificateDO.class));
    }
 
    @Override
    public void deleteCertificate(Collection<Long> ids) {
        if (CollUtil.isEmpty(ids)) {
            return;
        }
        for (Long id : ids) {
            validateCertificateExists(id);
            certificateMapper.deleteById(id);
        }
    }
 
    @Override
    public HrmCertificateDO getCertificate(Long id) {
        return certificateMapper.selectById(id);
    }
 
    @Override
    public PageResult<HrmCertificateDO> getCertificatePage(HrmCertificatePageReqVO pageReqVO) {
        return certificateMapper.selectPage(pageReqVO);
    }
 
    private void validateEmployee(Long employeeId) {
        if (employeeService.getEmployee(employeeId) == null) {
            throw exception(HRM_EMPLOYEE_NOT_EXISTS);
        }
    }
 
    private void validateCertificateExists(Long id) {
        if (certificateMapper.selectById(id) == null) {
            throw exception(HRM_CERTIFICATE_NOT_EXISTS);
        }
    }
 
}