liu
9 天以前 f57a9de2dbe69e7f867b39c25abdab58b401a2df
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/productsales/MesWmProductSalesServiceImpl.java
@@ -2,10 +2,13 @@
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.productsales.vo.MesWmProductSalesImportExcelVO;
import cn.iocoder.yudao.module.mes.controller.admin.wm.productsales.vo.MesWmProductSalesImportRespVO;
import cn.iocoder.yudao.module.mes.controller.admin.wm.productsales.vo.MesWmProductSalesPageReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.wm.productsales.vo.MesWmProductSalesSaveReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.wm.productsales.vo.MesWmProductSalesShippingReqVO;
@@ -38,7 +41,10 @@
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.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;
@@ -47,7 +53,7 @@
/**
 * MES 销售出库单 Service 实现类
 *
 * @author 芋道源码
 * @author 超级管理员
 */
@Service
@Validated
@@ -441,4 +447,50 @@
        productSalesMapper.updateById(new MesWmProductSalesDO().setId(id).setStatus(status));
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public MesWmProductSalesImportRespVO importProductSalesList(List<MesWmProductSalesImportExcelVO> importList, boolean updateSupport) {
        if (CollUtil.isEmpty(importList)) {
            throw exception(WM_PRODUCT_SALES_IMPORT_LIST_IS_EMPTY);
        }
        MesWmProductSalesImportRespVO respVO = MesWmProductSalesImportRespVO.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;
            }
            MesWmProductSalesDO existing = productSalesMapper.selectByCode(code);
            if (existing != null && updateSupport) {
                if (!MesWmProductSalesStatusEnum.PREPARE.getStatus().equals(existing.getStatus())) {
                    respVO.getFailureCodes().put(key, "单据非草稿状态,不允许覆盖更新");
                    return;
                }
                MesWmProductSalesDO updateObj = BeanUtils.toBean(importItem, MesWmProductSalesDO.class);
                updateObj.setId(existing.getId());
                updateObj.setStatus(existing.getStatus());
                productSalesMapper.updateById(updateObj);
                respVO.getUpdateCodes().add(code);
            } else if (existing != null) {
                respVO.getFailureCodes().put(key, "单号已存在:" + code);
            } else {
                MesWmProductSalesDO createObj = BeanUtils.toBean(importItem, MesWmProductSalesDO.class);
                createObj.setId(null);
                createObj.setStatus(MesWmProductSalesStatusEnum.PREPARE.getStatus());
                productSalesMapper.insert(createObj);
                respVO.getCreateCodes().add(code);
            }
        });
        return respVO;
    }
}