gaoluyang
2026-10-18 196ff11a9b7e514dabea8757de00259d9b7fea4d
yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/performanceappraise/HrmPerformanceAppraiseServiceImpl.java
@@ -4,6 +4,7 @@
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
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.framework.mybatis.core.query.LambdaQueryWrapperX;
@@ -31,6 +32,7 @@
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
/**
@@ -428,4 +430,57 @@
        return appraise;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public HrmPerformanceAppraiseImportRespVO importAppraiseList(
            List<HrmPerformanceAppraiseImportExcelVO> importList, HrmPerformanceAppraiseImportReqVO importReqVO) {
        // 1. 校验非空
        importList = filterList(importList, item -> StrUtil.isNotBlank(item.getName()));
        if (CollUtil.isEmpty(importList)) {
            throw exception(ErrorCodeConstants.PERFORMANCE_APPRAISE_IMPORT_LIST_IS_EMPTY);
        }
        // 2. 逐条处理
        HrmPerformanceAppraiseImportRespVO respVO = HrmPerformanceAppraiseImportRespVO.builder()
                .createNames(new ArrayList<>())
                .updateNames(new ArrayList<>())
                .failureNames(new LinkedHashMap<>())
                .build();
        importList.forEach(importAppraise -> {
            try {
                // 2.1 判断是否存在(按名称唯一)
                HrmPerformanceAppraiseDO existAppraise = appraiseMapper.selectByName(importAppraise.getName());
                if (existAppraise == null) {
                    // 2.1.1 新增(导入均为草稿)
                    HrmPerformanceAppraiseDO appraise = BeanUtils.toBean(importAppraise, HrmPerformanceAppraiseDO.class)
                            .setStatus(STATUS_DRAFT)
                            .setAuditStatus(HrmAuditStatusEnum.DRAFT.getStatus());
                    if (appraise.getScopeType() == null) {
                        appraise.setScopeType(SCOPE_ALL);
                    }
                    appraiseMapper.insert(appraise);
                    respVO.getCreateNames().add(importAppraise.getName());
                    return;
                }
                // 2.1.2 已存在,判断是否允许更新
                if (!importReqVO.getUpdateSupport()) {
                    respVO.getFailureNames().put(importAppraise.getName(),
                            StrUtil.format(ErrorCodeConstants.PERFORMANCE_APPRAISE_EXISTS.getMsg(), importAppraise.getName()));
                    return;
                }
                HrmPerformanceAppraiseDO updateAppraise = BeanUtils.toBean(importAppraise, HrmPerformanceAppraiseDO.class)
                        .setId(existAppraise.getId())
                        .setStatus(existAppraise.getStatus())
                        .setAuditStatus(existAppraise.getAuditStatus());
                if (updateAppraise.getScopeType() == null) {
                    updateAppraise.setScopeType(existAppraise.getScopeType());
                }
                appraiseMapper.updateById(updateAppraise);
                respVO.getUpdateNames().add(importAppraise.getName());
            } catch (ServiceException ex) {
                respVO.getFailureNames().put(importAppraise.getName(), ex.getMessage());
            }
        });
        return respVO;
    }
}