houjie
2023-09-04 a1f67e8727f7af3b3b472446616ab6c591caaebc
lxzn-module-eam/src/main/java/org/jeecg/modules/spare/controller/SparePartController.java
@@ -2,6 +2,7 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@@ -10,6 +11,10 @@
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.base.entity.Constructor;
import org.jeecg.modules.base.entity.Unit;
import org.jeecg.modules.base.service.IConstructorService;
import org.jeecg.modules.base.service.IUnitService;
import org.jeecg.modules.spare.entity.SparePart;
import org.jeecg.modules.spare.entity.SparesPartInventory;
import org.jeecg.modules.spare.service.ISparePartService;
@@ -47,6 +52,10 @@
    @Autowired
    private ISparesPartInventoryService sparesPartInventoryService;
    @Autowired
    private IConstructorService constructorService;
    @Autowired
    private IUnitService unitService;
    /**
     * 分页列表查询
@@ -222,6 +231,42 @@
            try {
                List<SparePart> list = ExcelImportUtil.importExcel(file.getInputStream(), SparePart.class, params);
                long start = System.currentTimeMillis();
                for (int i = 0; i < list.size(); i++) {
                    SparePart sparePart = list.get(i);
                    String constructorName = sparePart.getConstructorId();
                    String mainUnitName = sparePart.getMainUnitId();
                    String validityPeriodUnitName = sparePart.getValidityPeriodUnitId();
                    Constructor constructor = constructorService.getByName(constructorName);
                    Unit unit = unitService.getUnitByName(mainUnitName);
                    Unit validityPeriodUnit = unitService.getUnitByName(validityPeriodUnitName);
                    if (unit != null) {
                        if (!StringUtils.isNotEmpty(validityPeriodUnit.getId()))
                            return Result.error("文件导入失败: 第" + (i + 1) + "行有效期单位不存在");
                        list.get(i).setValidityPeriodUnitId(validityPeriodUnit.getId());
                    }
                    if (constructor != null) {
                        if (!StringUtils.isNotEmpty(constructor.getId()))
                            return Result.error("文件导入失败: 第" + (i + 1) + "行制造商不存在");
                        list.get(i).setConstructorId(constructor.getId());
                    }
                    if (unit != null) {
                        if (!StringUtils.isNotEmpty(unit.getId()))
                            return Result.error("文件导入失败: 第" + (i + 1) + "行单位不存在");
                        list.get(i).setMainUnitId(unit.getId());
                    }
                    if (!StringUtils.isNotEmpty(sparePart.getName()))
                        return Result.error("文件导入失败: 第" + (i + 1) + "行备件名称不能为空");
                    if (!StringUtils.isNotEmpty(sparePart.getNum()))
                        return Result.error("文件导入失败: 第" + (i + 1) + "行备件编码不能为空");
                    if (!StringUtils.isNotEmpty(sparePart.getSpecification()))
                        return Result.error("文件导入失败: 第" + (i + 1) + "行备件规格不能为空");
                    if (!StringUtils.isNotEmpty(sparePart.getModel()))
                        return Result.error("文件导入失败: 第" + (i + 1) + "行备件型号不能为空");
                }
                sparePartService.saveBatch(list);
                log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
                return Result.OK("文件导入成功!数据行数:" + list.size());