| | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | |
| | | import cn.hutool.core.util.ObjUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.returnissue.vo.MesWmReturnIssueImportExcelVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.returnissue.vo.MesWmReturnIssueImportRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.returnissue.vo.MesWmReturnIssuePageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.returnissue.vo.MesWmReturnIssueSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.mdm.MesMdmItemDO; |
| | |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*; |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public MesWmReturnIssueImportRespVO importReturnIssueList(List<MesWmReturnIssueImportExcelVO> importList, boolean updateSupport) { |
| | | if (CollUtil.isEmpty(importList)) { |
| | | throw exception(WM_RETURN_ISSUE_IMPORT_LIST_IS_EMPTY); |
| | | } |
| | | MesWmReturnIssueImportRespVO respVO = MesWmReturnIssueImportRespVO.builder() |
| | | .createCodes(new ArrayList<>()).updateCodes(new ArrayList<>()) |
| | | .failureCodes(new LinkedHashMap<>()).build(); |
| | | AtomicInteger index = new AtomicInteger(1); |
| | | importList.forEach(importItem -> { |
| | | int currentIndex = index.getAndIncrement(); |
| | | String code = importItem.getCode(); |
| | | String key = StrUtil.blankToDefault(code, "第 " + currentIndex + " 行"); |
| | | if (StrUtil.isBlank(code)) { |
| | | respVO.getFailureCodes().put(key, "单号不能为空"); |
| | | return; |
| | | } |
| | | if (StrUtil.isBlank(importItem.getName())) { |
| | | respVO.getFailureCodes().put(key, "名称不能为空"); |
| | | return; |
| | | } |
| | | MesWmReturnIssueDO existing = issueMapper.selectByCode(code); |
| | | if (existing != null && updateSupport) { |
| | | if (!MesWmReturnIssueStatusEnum.PREPARE.getStatus().equals(existing.getStatus())) { |
| | | respVO.getFailureCodes().put(key, "单据非草稿状态,不允许覆盖更新"); |
| | | return; |
| | | } |
| | | MesWmReturnIssueDO updateObj = BeanUtils.toBean(importItem, MesWmReturnIssueDO.class); |
| | | updateObj.setId(existing.getId()); |
| | | updateObj.setStatus(existing.getStatus()); |
| | | issueMapper.updateById(updateObj); |
| | | respVO.getUpdateCodes().add(code); |
| | | } else if (existing != null) { |
| | | respVO.getFailureCodes().put(key, "单号已存在:" + code); |
| | | } else { |
| | | MesWmReturnIssueDO createObj = BeanUtils.toBean(importItem, MesWmReturnIssueDO.class); |
| | | createObj.setId(null); |
| | | createObj.setStatus(MesWmReturnIssueStatusEnum.PREPARE.getStatus()); |
| | | issueMapper.insert(createObj); |
| | | respVO.getCreateCodes().add(code); |
| | | } |
| | | }); |
| | | return respVO; |
| | | } |
| | | |
| | | } |