Bladeren bron

codereview物料代码,并调整

v_HuilingDeng 4 jaren geleden
bovenliggende
commit
32f7f08f7c

+ 17 - 8
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/service/impl/MaterialServiceImpl.java

@@ -2,10 +2,8 @@ package com.abi.qms.platform.service.impl;
 
 import com.abi.qms.platform.dao.entity.BaseMaterial;
 import com.abi.qms.platform.dao.entity.BaseSku;
-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.mapper.BaseSkuMapper;
 import com.abi.qms.platform.dao.vo.result.MaterialVO;
@@ -23,16 +21,12 @@ import com.abi.task.common.excel.preperties.MaterialProperty;
 import com.abi.task.common.utils.PojoConverterUtils;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.fasterxml.jackson.databind.util.JSONPObject;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * <p>
@@ -59,6 +53,7 @@ public class MaterialServiceImpl implements MaterialService {
         //查询是否存在相同名称的物料
         QueryWrapper<BaseMaterial> materialQw = new QueryWrapper<>();
         materialQw.eq("material_name",req.getMaterialName());
+        materialQw.eq("is_delete", 0);
         List<BaseMaterial> materialList = baseMaterialMapper.selectList(materialQw);
         if(CollectionUtils.isNotEmpty(materialList)){
             throw new BusinessException("物料"+req.getMaterialName()+"已存在,请勿重复创建");
@@ -66,6 +61,7 @@ public class MaterialServiceImpl implements MaterialService {
         //查询是否存在物料号
         materialQw = new QueryWrapper<>();
         materialQw.eq("material_code",req.getMaterialCode());
+        materialQw.eq("is_delete", 0);
         materialList = baseMaterialMapper.selectList(materialQw);
         if(CollectionUtils.isNotEmpty(materialList)){
             throw new BusinessException("物料号"+req.getMaterialCode()+"已存在,请勿重复创建");
@@ -92,8 +88,21 @@ public class MaterialServiceImpl implements MaterialService {
         BaseMaterial material = baseMaterialMapper.selectById(req.getId());
         AssertUtil.isNull(material,"物料不存在");
 
+        //校验物料名称
+        if(Objects.nonNull(req.getMaterialName())){
+            if(!material.getMaterialName().equals(req.getMaterialName())){
+                QueryWrapper<BaseMaterial> materialQw = new QueryWrapper<>();
+                materialQw.eq("material_name",req.getMaterialName());
+                materialQw.eq("is_delete", 0);
+                List<BaseMaterial> materialList = baseMaterialMapper.selectList(materialQw);
+                if(CollectionUtils.isNotEmpty(materialList)){
+                    throw new BusinessException("物料"+req.getMaterialName()+"已存在,请勿重复创建");
+                }
+                material.setMaterialName(req.getMaterialName());
+            }
+        }
+
         //2-修改物料
-        material.setMaterialName(req.getMaterialName());
         material.setMaterialType(req.getMaterialType());
         material.setDescription(req.getDescription());
         material.setValid(req.getValid());

+ 3 - 3
abi-cloud-qr-platform-server/src/main/resources/dao/mapper/BaseMaterialMapper.xml

@@ -33,18 +33,18 @@
 
         <where>
             <if test="req.materialCode!=null and req.materialCode!=''">
-                and m.material_code regexp #{req.materialCode}
+                and m.material_code = #{req.materialCode}
             </if>
             <if test="req.materialName!=null and req.materialName!=''">
                 and m.material_name regexp #{req.materialName}
             </if>
-            <if test="req.materialType!=null and req.materialType!=''">
+            <if test="req.materialType!=null">
                 and m.material_type = #{req.materialType}
             </if>
             <if test="req.skuName != null and req.skuName != ''">
                 AND bs.sku_name LIKE CONCAT('%',#{req.skuName},'%')
             </if>
-            <if test="req.valid!=null and req.valid!=''">
+            <if test="req.valid!=null">
                 and m.valid = #{req.valid}
             </if>
         </where>