|
@@ -2,24 +2,27 @@ package com.abi.qms.platform.service.impl;
|
|
|
|
|
|
import com.abi.qms.platform.dao.entity.BaseBrand;
|
|
|
import com.abi.qms.platform.dao.entity.BaseMaterial;
|
|
|
+import com.abi.qms.platform.dao.enums.FactoryTypeEnum;
|
|
|
+import com.abi.qms.platform.dao.enums.MaterialTypeEnum;
|
|
|
import com.abi.qms.platform.dao.enums.ValidEnum;
|
|
|
import com.abi.qms.platform.dao.mapper.BaseBrandMapper;
|
|
|
import com.abi.qms.platform.dao.mapper.BaseMaterialMapper;
|
|
|
import com.abi.qms.platform.dao.vo.result.MaterialVO;
|
|
|
import com.abi.qms.platform.dto.req.*;
|
|
|
-import com.abi.qms.platform.dto.res.GetMaterialRes;
|
|
|
-import com.abi.qms.platform.dto.res.ListBrandForSelectRes;
|
|
|
-import com.abi.qms.platform.dto.res.ListMaterialForSelectRes;
|
|
|
-import com.abi.qms.platform.dto.res.ListMaterialRes;
|
|
|
+import com.abi.qms.platform.dto.res.*;
|
|
|
import com.abi.qms.platform.infrastructure.util.AssertUtil;
|
|
|
import com.abi.qms.platform.infrastructure.util.PageUtil;
|
|
|
import com.abi.qms.platform.service.MaterialService;
|
|
|
import com.abi.task.common.api.exception.BusinessException;
|
|
|
+import com.abi.task.common.api.exception.ErrorCodeEnum;
|
|
|
+import com.abi.task.common.excel.preperties.DepartmentProperty;
|
|
|
+import com.abi.task.common.excel.preperties.MaterialProperty;
|
|
|
import com.abi.task.common.utils.PojoConverterUtils;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.Query;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.redisson.misc.Hash;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -197,8 +200,70 @@ public class MaterialServiceImpl implements MaterialService {
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 批量导入物料
|
|
|
+ * @param materialPropertyList
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ExcelImportRes materialExcelImport(List<MaterialProperty> materialPropertyList) throws Exception {
|
|
|
+ List<ExcelImportRes.FailBean> failList = new ArrayList<>();
|
|
|
+
|
|
|
+ //1-循环导入,有异常则捕获
|
|
|
+ for (int i = 0; i < materialPropertyList.size(); i++) {
|
|
|
+ MaterialProperty materialProperty = materialPropertyList.get(i);
|
|
|
+ try {
|
|
|
+ //1-校验必填与枚举
|
|
|
+ String errorMessage = checkMaterialProperty(materialProperty);
|
|
|
+ if (StringUtils.isNotBlank(errorMessage)) {
|
|
|
+ throw new BusinessException(ErrorCodeEnum.ERROR_PARAM.getCode(), errorMessage);
|
|
|
+ }
|
|
|
+
|
|
|
+ //2-调用业务代码新增
|
|
|
+ AddMaterialReq req = new AddMaterialReq();
|
|
|
+ req.setMaterialCode(materialProperty.getMaterialCode());
|
|
|
+ req.setMaterialName(materialProperty.getMaterialName());
|
|
|
+ req.setMaterialType(FactoryTypeEnum.getCode(materialProperty.getMaterialType()));
|
|
|
+ req.setDescription(materialProperty.getDescription());
|
|
|
+
|
|
|
+ addMaterial(req);
|
|
|
+ } catch (BusinessException e) {
|
|
|
+ failList.add(new ExcelImportRes.FailBean(i + 2, e.getMessage()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //2-返回导入结果
|
|
|
+ ExcelImportRes res = new ExcelImportRes();
|
|
|
+ res.setFailedCount(failList.size());
|
|
|
+ res.setSuccessCount(materialPropertyList.size() - res.getFailedCount());
|
|
|
+ res.setFailBeanList(failList);
|
|
|
|
|
|
+ return res;
|
|
|
+ }
|
|
|
|
|
|
+ private String checkMaterialProperty(MaterialProperty materialProperty) {
|
|
|
+ StringBuffer errorMessage = new StringBuffer();
|
|
|
+ //逐个字段校验
|
|
|
+ if (StringUtils.isBlank(materialProperty.getMaterialType())) {
|
|
|
+ errorMessage.append("物料类型").append("为空,");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(materialProperty.getMaterialType())
|
|
|
+ && FactoryTypeEnum.getCode(materialProperty.getMaterialType()) == null) {
|
|
|
+ errorMessage.append("物料类型").append("枚举值不正确,");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(materialProperty.getMaterialCode())) {
|
|
|
+ errorMessage.append("物料号").append("为空,");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(materialProperty.getMaterialName())) {
|
|
|
+ errorMessage.append("物料名称").append("为空,");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(materialProperty.getDescription())) {
|
|
|
+ errorMessage.append("描述").append("为空,");
|
|
|
+ }
|
|
|
+
|
|
|
+ return errorMessage.toString();
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|