소스 검색

[CODE]: 商品编号、名称唯一

maxianghua 4 년 전
부모
커밋
c83ac19d37

+ 9 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/warehouse/basicData/TGoodsController.java

@@ -1,8 +1,11 @@
 package com.ruoyi.web.controller.warehouse.basicData;
 
+import com.alibaba.fastjson.JSONArray;
 import com.ruoyi.basicData.domain.TGoods;
+import com.ruoyi.basicData.domain.TWarehouse;
 import com.ruoyi.basicData.service.ITGoodsService;
 import com.ruoyi.common.annotation.Log;
+import com.ruoyi.common.constant.UserConstants;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.page.TableDataInfo;
@@ -65,6 +68,12 @@ public class TGoodsController extends BaseController {
     @Log(title = "商品详情", businessType = BusinessType.INSERT)
     @PostMapping
     public AjaxResult add(@RequestBody TGoods tGoods) {
+        // 检验编号、名称、地址 唯一
+        if (UserConstants.NOT_UNIQUE.equals(tGoodsService.checkUFNoUnique(tGoods))) {
+            return AjaxResult.error("新增仓库'" + tGoods.getfNo() + "'失败,编号已存在");
+        } else if (UserConstants.NOT_UNIQUE.equals(tGoodsService.checkUFNnameUnique(tGoods))) {
+            return AjaxResult.error("新增仓库'" + tGoods.getfName() + "'失败,名称已存在");
+        }
         return toAjax(tGoodsService.insertTGoods(tGoods));
     }
 

+ 15 - 0
ruoyi-warehouse/src/main/java/com/ruoyi/basicData/mapper/TGoodsMapper.java

@@ -1,6 +1,7 @@
 package com.ruoyi.basicData.mapper;
 
 import com.ruoyi.basicData.domain.TGoods;
+import com.ruoyi.basicData.domain.TWarehouse;
 
 import java.util.List;
 
@@ -59,4 +60,18 @@ public interface TGoodsMapper {
      * @return 结果
      */
     public int deleteTGoodsByIds(Long[] fIds);
+
+    /**
+     *  检验编号唯一
+     * @param fNo
+     * @return
+     */
+    public TGoods checkFNoUnique(String fNo);
+
+    /**
+     *  检验名称
+     * @param fNname
+     * @return
+     */
+    public TGoods checkUFNnameUnique(String fNname);
 }

+ 12 - 0
ruoyi-warehouse/src/main/java/com/ruoyi/basicData/service/ITGoodsService.java

@@ -59,4 +59,16 @@ public interface ITGoodsService {
      * @return 结果
      */
     public int deleteTGoodsById(Long fId);
+
+    /**
+     *  检验编号唯一
+     * @return
+     */
+    public String checkUFNoUnique(TGoods tGoods);
+
+    /**
+     *  检验编号名称
+     * @return
+     */
+    public String checkUFNnameUnique(TGoods tGoods);
 }

+ 20 - 0
ruoyi-warehouse/src/main/java/com/ruoyi/basicData/service/impl/TGoodsServiceImpl.java

@@ -3,7 +3,9 @@ package com.ruoyi.basicData.service.impl;
 import com.ruoyi.basicData.domain.TGoods;
 import com.ruoyi.basicData.mapper.TGoodsMapper;
 import com.ruoyi.basicData.service.ITGoodsService;
+import com.ruoyi.common.constant.UserConstants;
 import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -87,4 +89,22 @@ public class TGoodsServiceImpl implements ITGoodsService {
     public int deleteTGoodsById(Long fId) {
         return tGoodsMapper.deleteTGoodsById(fId);
     }
+
+    @Override
+    public String checkUFNoUnique(TGoods tGoods) {
+        TGoods tGoods1 = tGoodsMapper.checkFNoUnique(tGoods.getfNo());
+        if (StringUtils.isNotNull(tGoods1) && tGoods1.getfId()!=tGoods.getfId()) {
+            return UserConstants.NOT_UNIQUE;
+        }
+        return UserConstants.UNIQUE;
+    }
+
+    @Override
+    public String checkUFNnameUnique(TGoods tGoods) {
+        TGoods tGoods1 = tGoodsMapper.checkUFNnameUnique(tGoods.getfName());
+        if (StringUtils.isNotNull(tGoods1) && tGoods1.getfId()!=tGoods.getfId()) {
+            return UserConstants.NOT_UNIQUE;
+        }
+        return UserConstants.UNIQUE;
+    }
 }

+ 9 - 0
ruoyi-warehouse/src/main/resources/mapper/basicData/TGoodsMapper.xml

@@ -123,4 +123,13 @@
         </foreach>
     </delete>
 
+    <select id="checkFNoUnique" parameterType="String" resultMap="TGoodsResult">
+	    select f_id,f_no from t_goods where f_no = #{fNo} limit 1
+    </select>
+
+    <select id="checkUFNnameUnique" parameterType="String" resultMap="TGoodsResult">
+        select f_id,f_name from t_goods where f_name = #{fAame} limit 1
+    </select>
+
+
 </mapper>