licailing 4 years ago
parent
commit
59e18d69dd

+ 5 - 0
src/main/java/com/izouma/nineth/repo/ShowCollectionRepo.java

@@ -22,4 +22,9 @@ public interface ShowCollectionRepo extends JpaRepository<ShowCollection, Long>,
 
     List<ShowCollection> findAllByShowroomId(Long showroomId);
 
+    @Query("update ShowCollection t set t.del = true where t.showroomId = ?1")
+    @Modifying
+    @Transactional
+    void softDeleteByRoom(Long showroomId);
+
 }

+ 9 - 1
src/main/java/com/izouma/nineth/service/ShowroomService.java

@@ -16,6 +16,7 @@ import com.izouma.nineth.repo.ShowroomRepo;
 import com.izouma.nineth.utils.JpaUtils;
 import com.izouma.nineth.utils.ObjUtils;
 import lombok.AllArgsConstructor;
+import org.apache.commons.beanutils.BeanUtils;
 import org.apache.commons.lang3.ObjectUtils;
 import org.springframework.data.domain.Page;
 import org.springframework.stereotype.Service;
@@ -117,6 +118,7 @@ public class ShowroomService {
                     .stream()
                     .collect(Collectors.toMap(Collection::getId, coll -> coll));
 
+
             room.getCollections().forEach(coll -> {
                 if (coll.getId() != null) {
                     ShowCollection showCollection = showCollectionMap.get(coll.getId());
@@ -124,7 +126,7 @@ public class ShowroomService {
                     showCollectionRepo.save(showCollection);
                 } else {
                     Collection collection = collectionMap.get(coll.getCollectionId());
-                    if (ObjectUtils.isNotEmpty(collection)){
+                    if (ObjectUtils.isNotEmpty(collection)) {
                         coll.setPic(collection.getPic().get(0).getUrl());
                         coll.setShowroomId(room.getId());
                         coll.setAssetId(collection.getAssetId());
@@ -132,6 +134,12 @@ public class ShowroomService {
                     }
                 }
             });
+        } else {
+            showCollectionRepo.softDeleteByRoom(room.getId());
         }
+
+        ObjUtils.merge(room, showroom);
+        showroomRepo.save(room);
     }
+
 }

+ 6 - 2
src/main/java/com/izouma/nineth/web/ShowroomController.java

@@ -1,5 +1,7 @@
 package com.izouma.nineth.web;
+
 import com.izouma.nineth.domain.Showroom;
+import com.izouma.nineth.repo.ShowCollectionRepo;
 import com.izouma.nineth.service.ShowroomService;
 import com.izouma.nineth.dto.PageQuery;
 import com.izouma.nineth.exception.BusinessException;
@@ -19,8 +21,9 @@ import java.util.List;
 @RequestMapping("/showroom")
 @AllArgsConstructor
 public class ShowroomController extends BaseController {
-    private ShowroomService showroomService;
-    private ShowroomRepo showroomRepo;
+    private ShowroomService    showroomService;
+    private ShowroomRepo       showroomRepo;
+    private ShowCollectionRepo showCollectionRepo;
 
     //@PreAuthorize("hasRole('ADMIN')")
     @PostMapping("/save")
@@ -47,6 +50,7 @@ public class ShowroomController extends BaseController {
 
     @PostMapping("/del/{id}")
     public void del(@PathVariable Long id) {
+        showCollectionRepo.softDeleteByRoom(id);
         showroomRepo.softDelete(id);
     }