gaoluyang
2026-10-16 7081c41bc3beb0ab49a22974ea4b010ae6854afe
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package cn.iocoder.yudao.module.hrm.service.salary;
 
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.exception.ServiceException;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.hrm.controller.admin.salary.vo.HrmSocialSecuritySchemeImportExcelVO;
import cn.iocoder.yudao.module.hrm.controller.admin.salary.vo.HrmSocialSecuritySchemeImportReqVO;
import cn.iocoder.yudao.module.hrm.controller.admin.salary.vo.HrmSocialSecuritySchemeImportRespVO;
import cn.iocoder.yudao.module.hrm.dal.dataobject.salary.HrmSocialSecuritySchemeDO;
import cn.iocoder.yudao.module.hrm.dal.mysql.salary.HrmSocialSecuritySchemeMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
 
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
 
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList;
import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.*;
 
/**
 * 社保公积金方案 Service 实现类
 *
 * @author 超级管理员
 */
@Service
@Validated
public class HrmSocialSecuritySchemeServiceImpl implements HrmSocialSecuritySchemeService {
 
    @Resource
    private HrmSocialSecuritySchemeMapper schemeMapper;
 
    @Override
    public Long createScheme(HrmSocialSecuritySchemeDO scheme) {
        schemeMapper.insert(scheme);
        return scheme.getId();
    }
 
    @Override
    public void updateScheme(HrmSocialSecuritySchemeDO scheme) {
        validateSchemeExists(scheme.getId());
        schemeMapper.updateById(scheme);
    }
 
    @Override
    public void deleteScheme(Long id) {
        validateSchemeExists(id);
        schemeMapper.deleteById(id);
    }
 
    @Override
    public HrmSocialSecuritySchemeDO getScheme(Long id) {
        return schemeMapper.selectById(id);
    }
 
    @Override
    public List<HrmSocialSecuritySchemeDO> getSchemeList(Integer status) {
        return schemeMapper.selectListByStatus(status);
    }
 
    private void validateSchemeExists(Long id) {
        if (schemeMapper.selectById(id) == null) {
            throw exception(SOCIAL_SECURITY_SCHEME_NOT_EXISTS);
        }
    }
 
    @Override
    public HrmSocialSecuritySchemeImportRespVO importSchemeList(
            List<HrmSocialSecuritySchemeImportExcelVO> importList, HrmSocialSecuritySchemeImportReqVO importReqVO) {
        // 1. 校验非空
        importList = filterList(importList, item -> StrUtil.isNotBlank(item.getName()));
        if (CollUtil.isEmpty(importList)) {
            throw exception(SOCIAL_SECURITY_SCHEME_IMPORT_LIST_IS_EMPTY);
        }
        // 2. 逐条处理
        HrmSocialSecuritySchemeImportRespVO respVO = HrmSocialSecuritySchemeImportRespVO.builder()
                .createNames(new ArrayList<>())
                .updateNames(new ArrayList<>())
                .failureNames(new LinkedHashMap<>())
                .build();
        importList.forEach(importScheme -> {
            try {
                // 2.1 判断是否存在(按名称唯一)
                HrmSocialSecuritySchemeDO existScheme = schemeMapper.selectByName(importScheme.getName());
                if (existScheme == null) {
                    // 2.1.1 新增
                    HrmSocialSecuritySchemeDO scheme = BeanUtils.toBean(importScheme, HrmSocialSecuritySchemeDO.class);
                    if (scheme.getStatus() == null) {
                        scheme.setStatus(0);
                    }
                    schemeMapper.insert(scheme);
                    respVO.getCreateNames().add(importScheme.getName());
                    return;
                }
                // 2.1.2 已存在,判断是否允许更新
                if (!importReqVO.getUpdateSupport()) {
                    respVO.getFailureNames().put(importScheme.getName(),
                            StrUtil.format(SOCIAL_SECURITY_SCHEME_EXISTS.getMsg(), importScheme.getName()));
                    return;
                }
                HrmSocialSecuritySchemeDO updateScheme = BeanUtils.toBean(importScheme, HrmSocialSecuritySchemeDO.class)
                        .setId(existScheme.getId());
                if (updateScheme.getStatus() == null) {
                    updateScheme.setStatus(0);
                }
                schemeMapper.updateById(updateScheme);
                respVO.getUpdateNames().add(importScheme.getName());
            } catch (ServiceException ex) {
                respVO.getFailureNames().put(importScheme.getName(), ex.getMessage());
            }
        });
        return respVO;
    }
 
}