| | |
| | | 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.module.hrm.enums.ErrorCodeConstants.SOCIAL_SECURITY_SCHEME_NOT_EXISTS; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; |
| | | import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.*; |
| | | |
| | | /** |
| | | * 社保公积金方案 Service 实现类 |
| | | * |
| | | * @author 芋道源码 |
| | | * @author 超级管理员 |
| | | */ |
| | | @Service |
| | | @Validated |
| | |
| | | } |
| | | } |
| | | |
| | | @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; |
| | | } |
| | | |
| | | } |