| | |
| | | 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.HrmTaxRateConfigImportExcelVO; |
| | | import cn.iocoder.yudao.module.hrm.controller.admin.salary.vo.HrmTaxRateConfigImportReqVO; |
| | | import cn.iocoder.yudao.module.hrm.controller.admin.salary.vo.HrmTaxRateConfigImportRespVO; |
| | | import cn.iocoder.yudao.module.hrm.dal.dataobject.salary.HrmTaxRateConfigDO; |
| | | import cn.iocoder.yudao.module.hrm.dal.mysql.salary.HrmTaxRateConfigMapper; |
| | | import jakarta.annotation.Resource; |
| | |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.time.LocalDate; |
| | | 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.TAX_RATE_CONFIG_NOT_EXISTS; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; |
| | | import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.*; |
| | | |
| | | /** |
| | | * 个税税率配置 Service 实现类 |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public HrmTaxRateConfigImportRespVO importTaxRateConfigList( |
| | | List<HrmTaxRateConfigImportExcelVO> importList, HrmTaxRateConfigImportReqVO importReqVO) { |
| | | // 1. 校验非空 |
| | | importList = filterList(importList, item -> item.getLevel() != null); |
| | | if (CollUtil.isEmpty(importList)) { |
| | | throw exception(TAX_RATE_CONFIG_IMPORT_LIST_IS_EMPTY); |
| | | } |
| | | // 2. 逐条处理 |
| | | HrmTaxRateConfigImportRespVO respVO = HrmTaxRateConfigImportRespVO.builder() |
| | | .createNames(new ArrayList<>()) |
| | | .updateNames(new ArrayList<>()) |
| | | .failureNames(new LinkedHashMap<>()) |
| | | .build(); |
| | | importList.forEach(importConfig -> { |
| | | String configKey = StrUtil.isNotBlank(importConfig.getName()) ? importConfig.getName() |
| | | : (importConfig.getEffectiveDate() + "-" + importConfig.getLevel()); |
| | | try { |
| | | // 2.1 生效日期与级数必填 |
| | | if (importConfig.getEffectiveDate() == null) { |
| | | respVO.getFailureNames().put(configKey, "生效日期不能为空"); |
| | | return; |
| | | } |
| | | // 2.2 判断是否存在(按生效日期+级数唯一) |
| | | HrmTaxRateConfigDO existConfig = taxRateConfigMapper.selectByEffectiveDateAndLevel( |
| | | importConfig.getEffectiveDate(), importConfig.getLevel()); |
| | | if (existConfig == null) { |
| | | // 2.2.1 新增 |
| | | HrmTaxRateConfigDO config = BeanUtils.toBean(importConfig, HrmTaxRateConfigDO.class); |
| | | if (config.getStatus() == null) { |
| | | config.setStatus(0); |
| | | } |
| | | taxRateConfigMapper.insert(config); |
| | | respVO.getCreateNames().add(configKey); |
| | | return; |
| | | } |
| | | // 2.2.2 已存在,判断是否允许更新 |
| | | if (!importReqVO.getUpdateSupport()) { |
| | | respVO.getFailureNames().put(configKey, |
| | | StrUtil.format(TAX_RATE_CONFIG_EXISTS.getMsg(), configKey)); |
| | | return; |
| | | } |
| | | HrmTaxRateConfigDO updateConfig = BeanUtils.toBean(importConfig, HrmTaxRateConfigDO.class) |
| | | .setId(existConfig.getId()); |
| | | if (updateConfig.getStatus() == null) { |
| | | updateConfig.setStatus(0); |
| | | } |
| | | taxRateConfigMapper.updateById(updateConfig); |
| | | respVO.getUpdateNames().add(configKey); |
| | | } catch (ServiceException ex) { |
| | | respVO.getFailureNames().put(configKey, ex.getMessage()); |
| | | } |
| | | }); |
| | | return respVO; |
| | | } |
| | | |
| | | } |