| | |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | 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.miscissue.vo.MesWmMiscIssueImportExcelVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.miscissue.vo.MesWmMiscIssueImportRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.miscissue.vo.MesWmMiscIssuePageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.miscissue.vo.MesWmMiscIssueSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.miscissue.MesWmMiscIssueDO; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; |
| | |
| | | List<MesWmMiscIssueLineDO> lines = miscIssueLineService.getMiscIssueLineListByIssueId(issue.getId()); |
| | | wmTransactionService.createTransactionList(convertList(lines, line -> new MesWmTransactionSaveReqDTO() |
| | | .setType(MesWmTransactionTypeEnum.OUT.getType()).setItemId(line.getItemId()) |
| | | .setQuantity(line.getQuantity().negate()) // 出库数量为负数 |
| | | .setQuantity(negateQuantity(line.getQuantity())) // 出库数量为负数 |
| | | .setBatchId(line.getBatchId()).setBatchCode(line.getBatchCode()) |
| | | .setWarehouseId(line.getWarehouseId()).setLocationId(line.getLocationId()).setAreaId(line.getAreaId()) |
| | | .setBizType(MesBizTypeConstants.WM_MISC_ISSUE).setBizId(issue.getId()).setBizCode(issue.getCode()).setBizLineId(line.getId()))); |
| | | } |
| | | |
| | | /** |
| | | * 出库数量取负:数量为空时抛出明确的业务异常,避免 NPE |
| | | */ |
| | | private BigDecimal negateQuantity(BigDecimal quantity) { |
| | | if (quantity == null) { |
| | | throw exception(WM_MISC_ISSUE_QUANTITY_INVALID); |
| | | } |
| | | return quantity.negate(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public MesWmMiscIssueImportRespVO importMiscIssueList(List<MesWmMiscIssueImportExcelVO> importList, boolean updateSupport) { |
| | | // 校验导入数据不能为空 |
| | | if (CollUtil.isEmpty(importList)) { |
| | | throw exception(WM_MISC_ISSUE_IMPORT_LIST_IS_EMPTY); |
| | | } |
| | | MesWmMiscIssueImportRespVO respVO = MesWmMiscIssueImportRespVO.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; |
| | | } |
| | | MesWmMiscIssueDO existing = miscIssueMapper.selectByCode(code); |
| | | if (existing != null && updateSupport) { |
| | | if (!MesWmMiscIssueStatusEnum.PREPARE.getStatus().equals(existing.getStatus())) { |
| | | respVO.getFailureCodes().put(key, "单据非草稿状态,不允许覆盖更新"); |
| | | return; |
| | | } |
| | | MesWmMiscIssueDO updateObj = BeanUtils.toBean(importItem, MesWmMiscIssueDO.class); |
| | | updateObj.setId(existing.getId()); |
| | | updateObj.setStatus(existing.getStatus()); |
| | | miscIssueMapper.updateById(updateObj); |
| | | respVO.getUpdateCodes().add(code); |
| | | } else if (existing != null) { |
| | | respVO.getFailureCodes().put(key, "单号已存在:" + code); |
| | | } else { |
| | | MesWmMiscIssueDO createObj = BeanUtils.toBean(importItem, MesWmMiscIssueDO.class); |
| | | createObj.setId(null); |
| | | createObj.setStatus(MesWmMiscIssueStatusEnum.PREPARE.getStatus()); |
| | | miscIssueMapper.insert(createObj); |
| | | respVO.getCreateCodes().add(code); |
| | | } |
| | | }); |
| | | return respVO; |
| | | } |
| | | |
| | | } |