| | |
| | | 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.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.module.hrm.controller.admin.salary.vo.HrmEmployeeSocialSecurityImportExcelVO; |
| | | import cn.iocoder.yudao.module.hrm.controller.admin.salary.vo.HrmEmployeeSocialSecurityImportReqVO; |
| | | import cn.iocoder.yudao.module.hrm.controller.admin.salary.vo.HrmEmployeeSocialSecurityImportRespVO; |
| | | import cn.iocoder.yudao.module.hrm.controller.admin.salary.vo.HrmEmployeeSocialSecurityPageReqVO; |
| | | import cn.iocoder.yudao.module.hrm.dal.dataobject.employee.HrmEmployeeDO; |
| | | import cn.iocoder.yudao.module.hrm.dal.dataobject.salary.HrmEmployeeSocialSecurityDO; |
| | | import cn.iocoder.yudao.module.hrm.dal.dataobject.salary.HrmSocialSecuritySchemeDO; |
| | | import cn.iocoder.yudao.module.hrm.dal.mysql.employee.HrmEmployeeMapper; |
| | | import cn.iocoder.yudao.module.hrm.dal.mysql.salary.HrmEmployeeSocialSecurityMapper; |
| | | import cn.iocoder.yudao.module.hrm.dal.mysql.salary.HrmSocialSecuritySchemeMapper; |
| | | import jakarta.annotation.Resource; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | 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.EMPLOYEE_SOCIAL_SECURITY_NOT_EXISTS; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; |
| | | import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.*; |
| | | |
| | | /** |
| | | * 员工社保公积金档案 Service 实现类 |
| | |
| | | |
| | | @Resource |
| | | private HrmEmployeeSocialSecurityMapper employeeSocialSecurityMapper; |
| | | @Resource |
| | | private HrmEmployeeMapper employeeMapper; |
| | | @Resource |
| | | private HrmSocialSecuritySchemeMapper schemeMapper; |
| | | |
| | | @Override |
| | | public Long createEmployeeSocialSecurity(HrmEmployeeSocialSecurityDO socialSecurity) { |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public HrmEmployeeSocialSecurityImportRespVO importEmployeeSocialSecurityList( |
| | | List<HrmEmployeeSocialSecurityImportExcelVO> importList, HrmEmployeeSocialSecurityImportReqVO importReqVO) { |
| | | // 1. 校验非空 |
| | | importList = filterList(importList, item -> StrUtil.isNotBlank(item.getEmployeeName())); |
| | | if (CollUtil.isEmpty(importList)) { |
| | | throw exception(EMPLOYEE_SOCIAL_SECURITY_IMPORT_LIST_IS_EMPTY); |
| | | } |
| | | // 2. 逐条处理 |
| | | HrmEmployeeSocialSecurityImportRespVO respVO = HrmEmployeeSocialSecurityImportRespVO.builder() |
| | | .createNames(new ArrayList<>()) |
| | | .updateNames(new ArrayList<>()) |
| | | .failureNames(new LinkedHashMap<>()) |
| | | .build(); |
| | | importList.forEach(importSocialSecurity -> { |
| | | try { |
| | | // 2.1 解析员工 |
| | | HrmEmployeeDO employee = employeeMapper.selectByName(importSocialSecurity.getEmployeeName()); |
| | | if (employee == null) { |
| | | throw exception(EMPLOYEE_SOCIAL_SECURITY_EMPLOYEE_NOT_EXISTS, importSocialSecurity.getEmployeeName()); |
| | | } |
| | | // 2.2 解析方案 |
| | | Long schemeId = null; |
| | | if (StrUtil.isNotBlank(importSocialSecurity.getSchemeName())) { |
| | | HrmSocialSecuritySchemeDO scheme = schemeMapper.selectByName(importSocialSecurity.getSchemeName()); |
| | | if (scheme == null) { |
| | | throw exception(EMPLOYEE_SOCIAL_SECURITY_SCHEME_NOT_EXISTS, importSocialSecurity.getSchemeName()); |
| | | } |
| | | schemeId = scheme.getId(); |
| | | } |
| | | // 2.3 生效日期必填 |
| | | if (importSocialSecurity.getEffectiveDate() == null) { |
| | | respVO.getFailureNames().put(importSocialSecurity.getEmployeeName(), "生效日期不能为空"); |
| | | return; |
| | | } |
| | | // 2.4 判断是否存在(按员工+生效日期唯一) |
| | | HrmEmployeeSocialSecurityDO existSocialSecurity = employeeSocialSecurityMapper |
| | | .selectByUserIdAndEffectiveDate(employee.getId(), importSocialSecurity.getEffectiveDate()); |
| | | if (existSocialSecurity == null) { |
| | | // 2.4.1 新增 |
| | | HrmEmployeeSocialSecurityDO socialSecurity = BeanUtils.toBean(importSocialSecurity, HrmEmployeeSocialSecurityDO.class) |
| | | .setUserId(employee.getId()).setSocialSecuritySchemeId(schemeId); |
| | | if (socialSecurity.getStatus() == null) { |
| | | socialSecurity.setStatus(0); |
| | | } |
| | | employeeSocialSecurityMapper.insert(socialSecurity); |
| | | respVO.getCreateNames().add(importSocialSecurity.getEmployeeName()); |
| | | return; |
| | | } |
| | | // 2.4.2 已存在,判断是否允许更新 |
| | | if (!importReqVO.getUpdateSupport()) { |
| | | respVO.getFailureNames().put(importSocialSecurity.getEmployeeName(), |
| | | StrUtil.format(EMPLOYEE_SOCIAL_SECURITY_EXISTS.getMsg(), importSocialSecurity.getEmployeeName())); |
| | | return; |
| | | } |
| | | HrmEmployeeSocialSecurityDO updateSocialSecurity = BeanUtils.toBean(importSocialSecurity, HrmEmployeeSocialSecurityDO.class) |
| | | .setId(existSocialSecurity.getId()).setUserId(employee.getId()).setSocialSecuritySchemeId(schemeId); |
| | | if (updateSocialSecurity.getStatus() == null) { |
| | | updateSocialSecurity.setStatus(0); |
| | | } |
| | | employeeSocialSecurityMapper.updateById(updateSocialSecurity); |
| | | respVO.getUpdateNames().add(importSocialSecurity.getEmployeeName()); |
| | | } catch (ServiceException ex) { |
| | | respVO.getFailureNames().put(importSocialSecurity.getEmployeeName(), ex.getMessage()); |
| | | } |
| | | }); |
| | | return respVO; |
| | | } |
| | | |
| | | } |