소스 검색

优化修改新增接口时期在其poTetherandcollections为空时只对套系进行操作

zhangyang 2 년 전
부모
커밋
4b2c3a1bb4

+ 2 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/PoTetherController.java

@@ -218,6 +218,8 @@ public class PoTetherController extends BaseController
             //已经上架只可以修改展示结束的时间
             poTetherService.updateShowTimeEnd(tetherVo);
         }else{
+            tetherVo.setUpdateBy(getUsername());
+            tetherVo.setUpdateTime(new Date());
             poTetherService.updatePoTetherWithCollection(tetherVo);
         }
         return success("修改成功");

+ 38 - 27
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/PoTetherServiceImpl.java

@@ -156,18 +156,25 @@ public class PoTetherServiceImpl extends ServiceImpl<PoTetherMapper,PoTether> im
     @Override
     @Transactional
     public void insertPoTetherWithCollection(TetherVo tetherVo) {
-        //保存套系的基本数据到套系表tether
-        this.poTetherMapper.insertPoTether(tetherVo);
-        //套系包含藏品
-        //保存藏品数据到中间表 批量增加
-        System.out.println(tetherVo.getPoTetherandcollections().size());
-        for (int i = 0 ; i < tetherVo.getPoTetherandcollections().size();i++) {
-            System.out.println(tetherVo.getPoTetherandcollections().get(i).getCollectionTitle());
-            PoTetherandcollection poTetherandcollection1 = new PoTetherandcollection();
-            poTetherandcollection1.setCollectionTitle(tetherVo.getPoTetherandcollections().get(i).getCollectionTitle());
-            poTetherandcollection1.setCollectionType(tetherVo.getPoTetherandcollections().get(i).getCollectionType());
-            poTetherandcollection1.setTetherId(tetherVo.getTetherId());
-            poTetherandcollectionService.insertPoTetherandcollection(poTetherandcollection1);
+        if (tetherVo.getPoTetherandcollections() == null){
+            //保存套系的基本数据到套系表tether
+            this.poTetherMapper.insertPoTether(tetherVo);
+        }else {
+
+            this.poTetherMapper.insertPoTether(tetherVo);
+            //套系包含藏品
+            //保存藏品数据到中间表 批量增加
+            System.out.println(tetherVo.getPoTetherandcollections().size());
+
+
+            for (int i = 0; i < tetherVo.getPoTetherandcollections().size(); i++) {
+                System.out.println(tetherVo.getPoTetherandcollections().get(i).getCollectionTitle());
+                PoTetherandcollection poTetherandcollection1 = new PoTetherandcollection();
+                poTetherandcollection1.setCollectionTitle(tetherVo.getPoTetherandcollections().get(i).getCollectionTitle());
+                poTetherandcollection1.setCollectionType(tetherVo.getPoTetherandcollections().get(i).getCollectionType());
+                poTetherandcollection1.setTetherId(tetherVo.getTetherId());
+                poTetherandcollectionService.insertPoTetherandcollection(poTetherandcollection1);
+            }
         }
     }
     /**
@@ -194,24 +201,28 @@ public class PoTetherServiceImpl extends ServiceImpl<PoTetherMapper,PoTether> im
     @Override
     @Transactional
     public void updatePoTetherWithCollection(TetherVo tetherVo) {
-        //更新po_tether表基本信息
-        this.poTetherMapper.updatePoTether(tetherVo);
-        //清理po_collection表数据
-        LambdaQueryWrapper<PoTetherandcollection> lambdaQueryWrapper = new LambdaQueryWrapper<>();
-        lambdaQueryWrapper.eq(PoTetherandcollection::getTetherId,tetherVo.getTetherId());
-        poTetherandcollectionService.remove(lambdaQueryWrapper);
-//        //添加当前提交过来的藏品数据--po_Tetherandcollection表的insert操作
+        if (tetherVo.getPoTetherandcollections() == null){
+            //更新po_tether表基本信息
+            this.poTetherMapper.updatePoTether(tetherVo);
+        }
+       else {
 
-        for (int i = 0 ; i < tetherVo.getPoTetherandcollections().size();i++) {
+            this.poTetherMapper.updatePoTether(tetherVo);
+            //清理po_collection表数据
+            LambdaQueryWrapper<PoTetherandcollection> lambdaQueryWrapper = new LambdaQueryWrapper<>();
+            lambdaQueryWrapper.eq(PoTetherandcollection::getTetherId, tetherVo.getTetherId());
+            poTetherandcollectionService.remove(lambdaQueryWrapper);
+//        //添加当前提交过来的藏品数据--po_Tetherandcollection表的insert操作
 
-            System.out.println(tetherVo.getPoTetherandcollections().get(i).getCollectionTitle());
-            PoTetherandcollection poTetherandcollection1 = new PoTetherandcollection();
-            poTetherandcollection1.setCollectionTitle(tetherVo.getPoTetherandcollections().get(i).getCollectionTitle());
-            poTetherandcollection1.setCollectionType(tetherVo.getPoTetherandcollections().get(i).getCollectionType());
-            poTetherandcollection1.setTetherId(tetherVo.getTetherId());
-            poTetherandcollectionService.insertPoTetherandcollection(poTetherandcollection1);
+            for (int i = 0; i < tetherVo.getPoTetherandcollections().size(); i++) {
+                System.out.println(tetherVo.getPoTetherandcollections().get(i).getCollectionTitle());
+                PoTetherandcollection poTetherandcollection1 = new PoTetherandcollection();
+                poTetherandcollection1.setCollectionTitle(tetherVo.getPoTetherandcollections().get(i).getCollectionTitle());
+                poTetherandcollection1.setCollectionType(tetherVo.getPoTetherandcollections().get(i).getCollectionType());
+                poTetherandcollection1.setTetherId(tetherVo.getTetherId());
+                poTetherandcollectionService.insertPoTetherandcollection(poTetherandcollection1);
+            }
         }
-
     }