Explorar o código

增加新增合作方、申请产品时的非空约束

Danj0rr hai 11 meses
pai
achega
ccce441594

+ 6 - 0
src/main/java/com/kexun/controller/CooperatorController.java

@@ -96,6 +96,12 @@ public class CooperatorController {
     public Result cooperatorAdd(@RequestBody String json)
     {
         JSONObject req = JSON.parseObject(json);
+        String cooperator_name=req.getString("cooperator_name");
+        CooperatorInfo dupCooperatorInfo= CooperatorService.findByCooperatorNum(cooperator_name);
+        if (dupCooperatorInfo!=null){
+            return Result.error("合作方已存在!");
+        }
+
         CooperatorInfo cooperatorInfo = new CooperatorInfo();
         cooperatorInfo.setCooperatorName(req.getString("cooperator_name"));
         long time1 = System.currentTimeMillis();

+ 6 - 0
src/main/java/com/kexun/controller/CooperatorProductController.java

@@ -125,6 +125,12 @@ public class CooperatorProductController {
     public Result cooperatorProductApply(@RequestBody String json)
     {
         JSONObject req = JSON.parseObject(json);
+        List<CooperatorProduct> dupCooperatorProductInfo=CooperatorProductService.getProductByProductNum(req.getString("product_num"));
+        if(!dupCooperatorProductInfo.isEmpty()){
+            return Result.error("合作方产品编号重复!");
+        }
+
+
         CooperatorProduct cooperatorProduct = new CooperatorProduct();
 
         cooperatorProduct.setProductName(req.getString("product_name"));

+ 2 - 0
src/main/java/com/kexun/mapper/CooperatorProductMapper.java

@@ -26,6 +26,8 @@ public interface CooperatorProductMapper extends BaseMapper<CooperatorProduct> {
 
     List<CooperatorProduct> getCooperatorByModelQuery(@Param("modelNo") Long modelNo);
 
+    List<CooperatorProduct> getProductByProductNumQuery(@Param("productNum") String productNum);
+
     CooperatorProduct findProductByName(String product_name);
 
     List<CooperatorProduct> findCooperatorProductByNum(String cooperatorNum);

+ 2 - 0
src/main/java/com/kexun/service/CooperatorProductService.java

@@ -24,6 +24,8 @@ public interface CooperatorProductService extends IService<CooperatorProduct> {
 
     List<CooperatorProduct> getCooperatorByModel(Long modelNo);
 
+    List<CooperatorProduct> getProductByProductNum(String productNum);
+
     List<CooperatorProduct> findCooperatorProductByNum(String cooperatorNum);
     CooperatorProduct findProductByName(String product_name);
 }

+ 5 - 0
src/main/java/com/kexun/service/impl/CooperatorProductServiceImpl.java

@@ -68,6 +68,11 @@ public class CooperatorProductServiceImpl extends ServiceImpl<CooperatorProductM
         return cooperatorProductMapper.getCooperatorByModelQuery(modelNo);
     }
 
+    @Override
+    public List<CooperatorProduct> getProductByProductNum(String productNum){
+        return cooperatorProductMapper.getProductByProductNumQuery(productNum);
+    }
+
     public List<CooperatorProduct> findCooperatorProductByNum(String cooperatorNum) {
 //        System.out.println("aaa");
         List<CooperatorProduct> l = cooperatorProductMapper.findCooperatorProductByNum(cooperatorNum);

+ 4 - 0
src/main/resources/mapper/CooperatorProductMapper.xml

@@ -120,5 +120,9 @@
         WHERE model_id=#{modelNo}
     </select>
 
+    <select id="getProductByProductNumQuery" resultType="com.kexun.entity.CooperatorProduct">
+        SELECT * FROM prd_product
+        WHERE product_num=#{productNum}
+    </select>
 
 </mapper>