skyouc
2025-03-19 fac10dcb68a892be100960e267d0a1501f34e984
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/MatnrServiceImpl.java
@@ -4,8 +4,11 @@
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.vincent.rsf.framework.common.R;
import com.vincent.rsf.framework.common.SpringUtils;
import com.vincent.rsf.framework.exception.CoolException;
import com.vincent.rsf.server.common.utils.CommonUtil;
import com.vincent.rsf.server.common.utils.ExcelUtil;
import com.vincent.rsf.server.common.utils.FieldsUtils;
import com.vincent.rsf.server.manager.entity.MatnrGroup;
import com.vincent.rsf.server.manager.entity.excel.MatnrsTemplate;
import com.vincent.rsf.server.manager.mapper.MatnrMapper;
@@ -13,6 +16,8 @@
import com.vincent.rsf.server.manager.service.MatnrGroupService;
import com.vincent.rsf.server.manager.service.MatnrService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vincent.rsf.server.system.entity.Fields;
import com.vincent.rsf.server.system.service.FieldsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -20,6 +25,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@Service("matnrService")
@@ -39,38 +45,45 @@
    @Transactional(rollbackFor = Exception.class)
    public R importExcels(MultipartFile file) throws Exception {
        //读取上传文件内容
        ExcelImportResult<MatnrsTemplate> result = ExcelImportUtil.importExcelMore(file.getInputStream(), MatnrsTemplate.class, ExcelUtil.getDefaultImportParams());
        ExcelImportResult result = ExcelImportUtil.importExcelMore(file.getInputStream(), MatnrsTemplate.class, ExcelUtil.getDefaultImportParams());
        if (result.getList().isEmpty()) {
            throw new CoolException("物料导入失败!!");
        }
        List<Matnr> matnrs = new ArrayList<>();
        result.getList().forEach(template -> {
        List<Map<String, String>> list = result.getList();
        list.forEach(template -> {
            Matnr matnr = new Matnr();
            matnr.setBarcode(template.getBarcode())
                    .setCode(template.getErpCode())
                    .setDescrible(template.getDescrible())
                    .setColor(template.getColor())
                    .setFlagCheck(Short.parseShort(template.getFlagCheck()))
                    .setWeight(Double.parseDouble(template.getWeight()))
                    .setValidWarn(Integer.parseInt(template.getValidWarn()))
                    .setValid(Integer.parseInt(template.getValid()))
                    .setUnit(template.getUnit())
                    .setStockUnit(template.getPurUnit())
                    .setSpec(template.getSpec())
                    .setStagn(Integer.parseInt(template.getStagn()))
                    .setModel(template.getModel())
                    .setGroupCode(template.getGroupCode())
                    .setPurUnit(template.getPurUnit())
                    .setStockLevel(Short.parseShort(template.getStockLevel()))
                    .setSafeQty(Double.parseDouble(template.getSafeQty()))
                    .setMinQty(Double.parseDouble(template.getMinQty()));
            if (Objects.isNull(template.getGroupCode()) && Objects.isNull(template.getGroupName())) {
            matnr.setBarcode(template.get("barcode"))
                    .setCode(template.get("code"))
                    .setDescrible(template.get("describle"))
                    .setColor(template.get("color"))
                    .setFlagCheck(!Objects.isNull(template.get("flagCheck")) ? Short.parseShort(template.get("flagCheck")) : 0)
                    .setWeight(!Objects.isNull(template.get("weight")) ? Double.parseDouble(template.get("weight")) : 0.0)
                    .setValidWarn(!Objects.isNull(template.get("validWarn")) ? Integer.parseInt(template.get("validWarn")): 0)
                    .setValid(!Objects.isNull(template.get("valid")) ? Integer.parseInt( template.get("valid")) : 0)
                    .setUnit(template.get("unit"))
                    .setStockUnit(template.get("purUnit"))
                    .setSpec(template.get("spec"))
                    .setStagn(!Objects.isNull(template.get("stagn")) ? Integer.parseInt(template.get("stagn")) : 0)
                    .setModel(template.get("model"))
                    .setGroupCode(template.get("groupCode"))
                    .setPurUnit(template.get("purUnit"))
                    .setStockLevel(!Objects.isNull(template.get("stockLevel")) ? Short.parseShort(template.get("stockLevel")) : 0)
                    .setSafeQty(!Objects.isNull(template.get("safeQty")) ? Double.parseDouble(template.get("safeQty")) : 0)
                    .setMinQty(!Objects.isNull(template.get("safeQty")) ? Double.parseDouble(template.get("minQty")) : 0);
            if (Objects.isNull(template.get("groupCode")) && Objects.isNull(template.get("groupName"))) {
                MatnrGroup matnrGroups = matnrGroupService.getOne(new LambdaQueryWrapper<MatnrGroup>()
                        .eq(!Objects.isNull(template.getGroupCode()), MatnrGroup::getCode, template.getGroupCode())
                        .eq(!Objects.isNull(template.getGroupName()),MatnrGroup::getName, template.getName()));
                        .eq(!Objects.isNull(template.get("groupCode")), MatnrGroup::getCode, template.get("groupCode"))
                        .eq(!Objects.isNull(template.get("groupName")),MatnrGroup::getName, template.get("groupName")));
                matnr.setGroupId(matnrGroups.getId());
            }
            //获取动态字段,并保存明细内容
            if (!FieldsUtils.getFieldsSta().isEmpty()) {
                String uuid = CommonUtil.randomUUID16();
                matnr.setFieldsIndex(uuid);
                //保存物料扩展属性值
                FieldsUtils.saveFields(template, uuid);
            }
            matnrs.add(matnr);
        });