| | |
| | | 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.outsourceissue.vo.MesWmOutsourceIssueImportExcelVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.outsourceissue.vo.MesWmOutsourceIssueImportRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.outsourceissue.vo.MesWmOutsourceIssuePageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.outsourceissue.vo.MesWmOutsourceIssueSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.outsourceissue.MesWmOutsourceIssueDetailDO; |
| | |
| | | import cn.iocoder.yudao.module.mes.enums.wm.MesWmOutsourceIssueStatusEnum; |
| | | import cn.iocoder.yudao.module.mes.enums.wm.MesWmTransactionTypeEnum; |
| | | import cn.iocoder.yudao.module.mes.service.md.autocode.MesMdAutoCodeRecordService; |
| | | import cn.iocoder.yudao.module.erp.api.purchase.ErpSupplierApi; |
| | | import cn.iocoder.yudao.module.srm.api.supplier.SrmSupplierApi; |
| | | import cn.iocoder.yudao.module.mes.service.pro.workorder.MesProWorkOrderService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.transaction.MesWmTransactionService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.transaction.dto.MesWmTransactionSaveReqDTO; |
| | |
| | | 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.framework.common.util.collection.CollectionUtils.convertList; |
| | |
| | | /** |
| | | * MES 外协发料单 Service 实现类 |
| | | * |
| | | * @author 芋道源码 |
| | | * @author 超级管理员 |
| | | */ |
| | | @Service |
| | | @Validated |
| | |
| | | @Resource |
| | | private MesWmOutsourceIssueDetailService outsourceIssueDetailService; |
| | | @Resource |
| | | private ErpSupplierApi supplierApi; |
| | | private SrmSupplierApi srmSupplierApi; |
| | | @Resource |
| | | private MesProWorkOrderService workOrderService; |
| | | @Resource |
| | |
| | | validateCodeUnique(saveReqVO.getId(), saveReqVO.getCode()); |
| | | // 校验供应商存在 |
| | | if (saveReqVO.getVendorId() != null) { |
| | | supplierApi.validateSupplier(saveReqVO.getVendorId()); |
| | | srmSupplierApi.getSupplier(saveReqVO.getVendorId()); |
| | | } |
| | | // 校验工单存在且类型为外协(代工) |
| | | MesProWorkOrderDO workOrder = workOrderService.validateWorkOrderConfirmed(saveReqVO.getWorkOrderId()); |
| | |
| | | return outsourceIssueMapper.selectCountByVendorId(vendorId); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public MesWmOutsourceIssueImportRespVO importOutsourceIssueList(List<MesWmOutsourceIssueImportExcelVO> importList, boolean updateSupport) { |
| | | // 校验导入数据不能为空 |
| | | if (CollUtil.isEmpty(importList)) { |
| | | throw exception(WM_OUTSOURCE_ISSUE_IMPORT_LIST_IS_EMPTY); |
| | | } |
| | | MesWmOutsourceIssueImportRespVO respVO = MesWmOutsourceIssueImportRespVO.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; |
| | | } |
| | | MesWmOutsourceIssueDO existing = outsourceIssueMapper.selectByCode(code); |
| | | if (existing != null && updateSupport) { |
| | | if (!MesWmOutsourceIssueStatusEnum.PREPARE.getStatus().equals(existing.getStatus())) { |
| | | respVO.getFailureCodes().put(key, "单据非草稿状态,不允许覆盖更新"); |
| | | return; |
| | | } |
| | | MesWmOutsourceIssueDO updateObj = BeanUtils.toBean(importItem, MesWmOutsourceIssueDO.class); |
| | | updateObj.setId(existing.getId()); |
| | | updateObj.setStatus(existing.getStatus()); |
| | | outsourceIssueMapper.updateById(updateObj); |
| | | respVO.getUpdateCodes().add(code); |
| | | } else if (existing != null) { |
| | | respVO.getFailureCodes().put(key, "单号已存在:" + code); |
| | | } else { |
| | | MesWmOutsourceIssueDO createObj = BeanUtils.toBean(importItem, MesWmOutsourceIssueDO.class); |
| | | createObj.setId(null); |
| | | createObj.setStatus(MesWmOutsourceIssueStatusEnum.PREPARE.getStatus()); |
| | | outsourceIssueMapper.insert(createObj); |
| | | respVO.getCreateCodes().add(code); |
| | | } |
| | | }); |
| | | return respVO; |
| | | } |
| | | |
| | | } |