| | |
| | | |
| | | 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.object.BeanUtils; |
| | | import cn.iocoder.yudao.module.crm.api.customer.CrmCustomerApi; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.packages.vo.MesWmPackageImportExcelVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.packages.vo.MesWmPackageImportRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.packages.vo.MesWmPackagePageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.packages.vo.MesWmPackageSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.packages.MesWmPackageDO; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | 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; |
| | |
| | | private CrmCustomerApi customerApi; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Long createPackage(MesWmPackageSaveReqVO createReqVO) { |
| | | // 校验编码唯一性 |
| | | validateCodeUnique(null, createReqVO.getCode()); |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updatePackage(MesWmPackageSaveReqVO updateReqVO) { |
| | | // 校验存在且为草稿 |
| | | validatePackageExistsAndDraft(updateReqVO.getId()); |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void finishPackage(Long id) { |
| | | // 校验存在且为草稿 |
| | | validatePackageExistsAndDraft(id); |
| | | |
| | | // 装箱单必须存在装箱明细 |
| | | if (packageLineService.getPackageLineCountByPackageId(id) == 0) { |
| | | throw exception(WM_PACKAGE_LINE_NOT_EXISTS); |
| | | } |
| | | |
| | | // 更新状态为已完成 |
| | | packageMapper.updateById(new MesWmPackageDO() |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void addChildPackage(Long parentId, Long childId) { |
| | | // 校验父箱存在且为草稿 |
| | | validatePackageExistsAndDraft(parentId); |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void removeChildPackage(Long childId) { |
| | | // 校验子箱存在 |
| | | MesWmPackageDO child = validatePackageExists(childId); |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public MesWmPackageImportRespVO importPackageList(List<MesWmPackageImportExcelVO> importList, boolean updateSupport) { |
| | | if (CollUtil.isEmpty(importList)) { |
| | | throw exception(WM_PACKAGE_IMPORT_LIST_IS_EMPTY); |
| | | } |
| | | MesWmPackageImportRespVO respVO = MesWmPackageImportRespVO.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; |
| | | } |
| | | MesWmPackageDO existing = packageMapper.selectByCode(code); |
| | | if (existing != null && updateSupport) { |
| | | if (!MesWmPackageStatusEnum.PREPARE.getStatus().equals(existing.getStatus())) { |
| | | respVO.getFailureCodes().put(key, "单据非草稿状态,不允许覆盖更新"); |
| | | return; |
| | | } |
| | | MesWmPackageDO updateObj = BeanUtils.toBean(importItem, MesWmPackageDO.class); |
| | | updateObj.setId(existing.getId()); |
| | | updateObj.setStatus(existing.getStatus()); |
| | | packageMapper.updateById(updateObj); |
| | | respVO.getUpdateCodes().add(code); |
| | | } else if (existing != null) { |
| | | respVO.getFailureCodes().put(key, "单号已存在:" + code); |
| | | } else { |
| | | MesWmPackageDO createObj = BeanUtils.toBean(importItem, MesWmPackageDO.class); |
| | | createObj.setId(null); |
| | | createObj.setStatus(MesWmPackageStatusEnum.PREPARE.getStatus()); |
| | | packageMapper.insert(createObj); |
| | | respVO.getCreateCodes().add(code); |
| | | } |
| | | }); |
| | | return respVO; |
| | | } |
| | | |
| | | } |