| | |
| | | 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; |
| | |
| | | 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; |
| | | |
| | | /** |
| | |
| | | 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; |
| | | } |
| | | |
| | | } |